devicesmgt/sgzb-modules/sgzb-base/src/main/resources/mapper/base/RepairMapper.xml

264 lines
11 KiB
XML
Raw Normal View History

2023-12-14 16:01:48 +08:00
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.bonus.sgzb.base.mapper.RepairMapper">
2023-12-16 21:12:55 +08:00
<insert id="addRecord">
2023-12-18 17:59:46 +08:00
insert into repair_apply_record (task_id,ma_id,type_id,repair_num,scrap_num,repair_type,create_by,create_time,repair_content,company_id,scrap_reason,scrap_type,supplier_id,part_num,part_price,part_type,part_name,repairer,file_ids,remark)
values (#{taskId},#{maId},#{typeId},#{repairNum},#{scrapNum},#{repairType},#{createBy},now(),#{repairContent},#{companyId},#{scrapReason},#{scrapType},#{supplierId},#{partNum},#{partPrice},#{partType},#{partName},#{repairer},#{fileIds},#{remark});
2023-12-16 21:12:55 +08:00
</insert>
<insert id="addPart">
insert into repair_part_details (task_id,ma_id,type_id,part_id,part_num,part_cost,part_type,create_by,create_time,company_id,repair_content)
values (#{taskId},#{maId},#{typeId},#{partId},#{partNum},#{partCost},#{partType},#{createBy},now(),#{companyId},#{repairContent});
</insert>
<insert id="addTask" useGeneratedKeys="true" keyProperty="taskId">
insert into tm_task (task_status,task_type,code,create_by,create_time,company_id)
2023-12-18 16:20:21 +08:00
values (46,45,#{repairCode},#{createBy},now(),#{companyId});
2023-12-16 21:12:55 +08:00
</insert>
<insert id="createAgreementTask">
insert into tm_task_agreement (task_id,agreement_id,create_by,create_time,company_id)
values (#{taskId},#{agreementId},#{createBy},now(),#{companyId});
</insert>
2023-12-18 17:59:46 +08:00
<insert id="addAuditDetails">
insert into repair_audit_details (task_id,repair_id,ma_id,type_id,repair_num,repaired_num,scrap_num,status,create_by,create_time,company_id)
values (#{taskId},#{id},#{maId},#{typeId},#{repairNum},#{repairedNum},#{scrapNum},'0',#{createBy},now(),#{companyId});
</insert>
2023-12-16 21:12:55 +08:00
<update id="updateRepairedNum">
update repair_apply_details
set repaired_num = #{repairNum},
repairer = #{repairer},
update_by = #{userId},
update_time = now()
where id = #{id}
</update>
<update id="updateScrapNum">
update repair_apply_details
set scrap_num = #{scrapNum},
update_by = #{userId},
update_time = now()
where id = #{id}
</update>
<update id="completeRepair">
update repair_apply_details
set status = '1',
update_by = #{userId},
update_time = now()
where id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<update id="updateTaskStatus">
update tm_task
set task_status = '44',
update_by = #{userId},
update_time = now()
where task_id in
<foreach item="task" collection="taskList" open="(" separator="," close=")">
#{task.taskId}
</foreach>
</update>
<update id="updateRepairedNumTwo">
update repair_apply_details
set repaired_num = #{repairNum},
update_by = #{userId},
update_time = now()
where id = #{id}
</update>
2023-12-14 16:01:48 +08:00
2023-12-14 17:25:17 +08:00
<select id="getRepairTaskList" resultType="com.bonus.sgzb.base.domain.RepairTask">
SELECT
2023-12-17 18:50:22 +08:00
rd.task_id,
tt.CODE AS repairCode,
bui.unit_name AS backUnit,
2023-12-25 11:54:12 +08:00
bpi.lot_name AS backPro,
2023-12-18 21:30:04 +08:00
su.user_name AS createName,
2023-12-17 18:50:22 +08:00
tt.create_time AS createTime,
bai.CODE AS backCode,
sd.name AS repairStatus,
2023-12-18 17:59:46 +08:00
tt.task_status AS repairStatusCode,
2023-12-17 18:50:22 +08:00
tt.company_id AS companyId,
GROUP_CONCAT(DISTINCT mt2.type_name) as type
2023-12-14 17:25:17 +08:00
FROM
2023-12-17 18:50:22 +08:00
repair_apply_details rd
LEFT JOIN ma_type mt on rd.type_id = mt.type_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
LEFT JOIN tm_task tt on rd.task_id = tt.task_id
LEFT JOIN back_apply_info bai ON rd.back_id = bai.id
LEFT JOIN tm_task_agreement tta ON bai.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai2 ON tta.agreement_id = bai2.agreement_id
LEFT JOIN bm_unit_info bui ON bai2.unit_id = bui.unit_id
2023-12-25 11:54:12 +08:00
LEFT JOIN bm_project_lot bpi ON bai2.project_id = bpi.lot_id and bpi.status = '0' and bpi.del_flag = '0'
2023-12-17 18:50:22 +08:00
left join sys_user su on rd.create_by = su.user_id
left join sys_dic sd on sd.id = tt.task_status
2023-12-18 16:20:21 +08:00
where 1=1
2023-12-16 21:12:55 +08:00
<if test="keyword != null and keyword != ''">
AND (locate(#{keyword}, su.user_name) > 0
2023-12-17 18:50:22 +08:00
or locate(#{keyword}, tt.CODE) > 0)
2023-12-16 21:12:55 +08:00
</if>
<if test="backUnit != null and backUnit != ''">
AND bui.unit_id = #{backUnit}
</if>
<if test="backPro != null and backPro != ''">
2024-01-15 16:42:18 +08:00
AND bpi.lot_id = #{backPro}
2023-12-16 21:12:55 +08:00
</if>
2023-12-18 16:20:21 +08:00
<if test="type != null and type != ''">
AND mt2.type_id = #{type}
</if>
2023-12-16 21:12:55 +08:00
<if test="backCode != null and backCode != ''">
2023-12-18 16:20:21 +08:00
AND locate(#{backCode}, bai.CODE) > 0
2023-12-16 21:12:55 +08:00
</if>
<if test="repairStatus != null and repairStatus != ''">
2023-12-17 18:50:22 +08:00
AND tt.task_status = #{repairStatus}
2023-12-16 21:12:55 +08:00
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND ts.create_time between #{startTime} and #{endTime}
</if>
2023-12-25 11:54:12 +08:00
GROUP BY rd.task_id,bui.unit_name,bpi.lot_name,bai.code,su.user_name
2023-12-24 13:26:21 +08:00
order by tt.create_time desc
2023-12-14 17:25:17 +08:00
</select>
2024-01-08 16:32:49 +08:00
<select id="exportRepairTaskList" resultType="com.bonus.sgzb.base.domain.RepairTask">
SELECT
rd.task_id,
tt.CODE AS repairCode,
bui.unit_name AS backUnit,
bpi.lot_name AS backPro,
su.user_name AS createName,
tt.create_time AS createTime,
bai.CODE AS backCode,
sd.NAME AS repairStatus,
tt.task_status AS repairStatusCode,
tt.company_id AS companyId,
mt2.type_name AS type,
mt.type_name AS typeName,
mm.ma_code AS CODE,
rd.repair_num AS repairNum,
rd.repaired_num AS repairedNum,
rd.scrap_num AS scrapNum,
case rd.status when '0' then '未完成' when '1' then '已完成' else '' end as status,
su2.user_name as repairer,
rd.update_time as updateTime
FROM
repair_apply_details rd
LEFT JOIN ma_type mt ON rd.type_id = mt.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
LEFT JOIN tm_task tt ON rd.task_id = tt.task_id
LEFT JOIN back_apply_info bai ON rd.back_id = bai.id
LEFT JOIN tm_task_agreement tta ON bai.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai2 ON tta.agreement_id = bai2.agreement_id
LEFT JOIN bm_unit_info bui ON bai2.unit_id = bui.unit_id
LEFT JOIN bm_project_lot bpi ON bai2.project_id = bpi.lot_id AND bpi.STATUS = '0' AND bpi.del_flag = '0'
LEFT JOIN sys_user su ON rd.create_by = su.user_id
left join sys_user su2 on rd.repairer = su2.user_id
LEFT JOIN sys_dic sd ON sd.id = tt.task_status
LEFT JOIN ma_machine mm ON mm.ma_id = rd.ma_id
where 1=1
<if test="keyword != null and keyword != ''">
AND (locate(#{keyword}, su.user_name) > 0
or locate(#{keyword}, tt.CODE) > 0)
</if>
<if test="backUnit != null and backUnit != ''">
AND bui.unit_id = #{backUnit}
</if>
<if test="backPro != null and backPro != ''">
AND bpi.pro_id = #{backPro}
</if>
<if test="type != null and type != ''">
AND mt2.type_id = #{type}
</if>
<if test="backCode != null and backCode != ''">
AND locate(#{backCode}, bai.CODE) > 0
</if>
<if test="repairStatus != null and repairStatus != ''">
AND tt.task_status = #{repairStatus}
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND ts.create_time between #{startTime} and #{endTime}
</if>
ORDER BY
tt.create_time DESC
</select>
2024-01-24 16:13:32 +08:00
<select id="getRepairMaTypeList" resultType="com.bonus.sgzb.base.domain.RepairTaskDetails">
2023-12-16 21:12:55 +08:00
select rad.id as id,
rad.task_id as taskId,
rad.ma_id as maId,
2023-12-17 18:50:22 +08:00
mt2.type_name as typeName,
2023-12-16 21:12:55 +08:00
mt.type_name as type,
mm.ma_code as code,
rad.repair_num as repairNum,
rad.repaired_num as repairedNum,
rad.scrap_num as scrapNum,
rad.status as status,
su.user_name as repairer,
2023-12-17 18:50:22 +08:00
rad.update_time as updateTime,
rad.type_id as typeId
2023-12-16 21:12:55 +08:00
from repair_apply_details rad
2023-12-17 18:50:22 +08:00
left join ma_type mt on rad.type_id = mt.type_id
left join ma_machine mm on mm.ma_id = rad.ma_id
left join sys_user su on rad.repairer = su.user_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
2023-12-18 16:20:21 +08:00
where rad.task_id = #{taskId}
<if test="keyword != null and keyword != ''">
AND (locate(#{keyword}, mm.ma_code) > 0
2024-01-15 16:42:18 +08:00
or locate(#{keyword}, su.user_name) > 0
or locate(#{keyword}, mt2.type_name) > 0
or locate(#{keyword}, mt.type_name) > 0)
2023-12-18 16:20:21 +08:00
</if>
<if test="type != null and type != ''">
AND mt.type_id = #{type}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_id = #{typeName}
</if>
2023-12-24 13:26:21 +08:00
order by rad.create_time desc
2023-12-16 21:12:55 +08:00
</select>
2023-12-18 16:20:21 +08:00
2024-01-24 16:13:32 +08:00
<select id="getById" resultType="com.bonus.sgzb.base.domain.RepairTaskDetails">
2023-12-16 21:12:55 +08:00
select rad.id as id,
rad.repair_num as repairNum,
rad.repaired_num as repairedNum,
rad.scrap_num as scrapNum
from repair_apply_details rad
where rad.id = #{id}
</select>
<select id="selectUserList" resultType="com.bonus.sgzb.system.api.domain.SysUser">
2024-01-15 10:51:41 +08:00
SELECT
su.user_id AS userId,
su.nick_name AS nickName
FROM
sys_user su
LEFT JOIN sys_user_role sur on su.user_id = sur.user_id
LEFT JOIN sys_role sr on sur.role_id = sr.role_id
WHERE sr.role_key = 'wx'
2023-12-16 21:12:55 +08:00
</select>
<select id="getAgreementId" resultType="java.lang.Long">
select agreement_id
from tm_task_agreement
where task_id = #{taskId}
</select>
2023-12-17 18:50:22 +08:00
<select id="getUnFinish" resultType="java.lang.Integer">
select count(*)
from repair_apply_details
where task_id = #{taskId} and status = '0'
</select>
2024-01-22 14:46:44 +08:00
<select id="getDicSelect" resultType="com.bonus.sgzb.base.domain.vo.DictVo">
2023-12-17 18:50:22 +08:00
select s2.id,
s2.name
from sys_dic s1
left join sys_dic s2 on s2.p_id = s1.id
where s1.value = #{value} and s2.status = 0
</select>
2024-01-24 16:13:32 +08:00
<select id="getDetailsListByTaskId" resultType="com.bonus.sgzb.base.domain.RepairTaskDetails">
2023-12-18 17:59:46 +08:00
select id,
ma_id as maId,
type_id as typeId,
repair_num as repairNum,
repaired_num as repairedNum,
scrap_num as scrapNum
from repair_apply_details
where task_id = #{taskId}
</select>
2023-12-16 21:12:55 +08:00
2024-01-08 16:32:49 +08:00
2023-12-14 16:01:48 +08:00
</mapper>