cqdevicemgt/sgzb-modules/sgzb-material/src/main/resources/mapper/material/EquipmentToRepairMapper.xml

214 lines
8.6 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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.material.mapper.EquipmentToRepairMapper">
<select id="getMaCodeSelect" resultType="com.bonus.sgzb.material.domain.equipmentMaCodeInfo">
select
ma_id as maId,
ma_code as maCode
from
ma_machine
where ma_status in (15,16)
and type_id = #{typeId}
</select>
<select id="getEquipmentList" resultType="com.bonus.sgzb.material.domain.EquipmentTask">
select
red.id as id,
red.type_id as typeId,
red.ma_id as maId,
mt2.type_name as typeName,
mt.type_name as typeModelName,
mm.ma_code as maCode,
red.repair_num as repairNum,
red.status as repairStatus,
su.nick_name as repairer,
red.repair_type as repairType,
DATE_FORMAT(red.repair_time,'%Y-%m-%d') as repairTime
from repair_equipment_record red
left join ma_type mt on red.type_id = mt.type_id
left join ma_machine mm on mm.ma_id = red.ma_id
left join sys_user su on red.repairer = su.user_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
LEFT JOIN ma_type_repair mtr on mtr.type_id = red.type_id
where 1=1
<if test="userId != null and userId != ''">
and mtr.user_id = #{userId}
</if>
<if test="keyword != null and keyword != ''">
AND (locate(#{keyword}, mm.ma_code) > 0
or locate(#{keyword}, su.nick_name) > 0
or locate(#{keyword}, mt2.type_name) > 0
or locate(#{keyword}, mt.type_name) > 0)
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name like concat('%',#{typeModelName},'%')
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name like concat('%',#{typeName},'%')
</if>
<if test="repairStatus != null">
AND red.status = #{repairStatus}
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
<![CDATA[and DATE_FORMAT( red.repair_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime} ]]>
</if>
order by red.create_time desc
</select>
<insert id="addEquipmentNew" keyColumn="id" keyProperty="id" useGeneratedKeys="true" >
insert into repair_equipment_record (ma_id,type_id,repair_num,status,repair_type,create_by,create_time,repairer,repair_time)
values (#{maId},#{typeId},#{repairNum},#{repairStatus},#{repairType},#{createBy},now(),#{repairer},#{repairTime});
</insert>
<insert id="addEquipmentDetailsNew" keyColumn="id" keyProperty="id" useGeneratedKeys="true" >
insert into repair_equipment_details (parent_id,type_id,ma_id,part_id,part_name,part_num,part_price,repair_remark,repair_content,repair_content_before,part_change,part_change_num,create_by,create_time)
values (#{parentId},#{typeId},#{maId},#{partId},#{partName},#{partNum},#{partPrice},#{repairRemark},#{repairContent},#{repairContentBefore},#{partChange},#{partChangeNum},#{createBy},now());
</insert>
<select id="getEquipmentInfo" resultType="com.bonus.sgzb.material.domain.EquipmentRecord">
select
id,
ma_id as maId,
type_id as typeId,
repairer as repairer,
repair_num AS repairNum,
repair_type as repairType,
DATE_FORMAT(repair_time, '%Y-%m-%d') as repairTime
from repair_equipment_record rer
where rer.id = #{id}
</select>
<select id="getPartList" resultType="com.bonus.sgzb.material.domain.EquipmentPartDetails">
select
red.id as id,
red.parent_id as parentId,
red.ma_id as maId,
red.part_id as partId,
part_num as partNum,
part_name as partName,
part_price as partCost,
repair_content as repairContent,
repair_content_before as repairContentBefore,
repair_remark as repairRemark,
part_change as partChange,
part_change_num as partChangeNum
from repair_equipment_details red
left join ma_part_type mpt on red.part_id = mpt.pa_id
where red.parent_id = #{id}
order by red.create_time desc
</select>
<select id="getFileEquipmentList" resultType="com.bonus.sgzb.base.api.domain.FileInfo">
select
id,
model_id as modelId,
file_name as fileName,
file_url as fileUrl
from
sys_file_info sfi
where model_id = #{id} and repair_status = 2
</select>
<delete id="deleteEquipmentDetails">
delete from repair_equipment_details where parent_id = #{id}
</delete>
<delete id="deleteFileEquipmentList">
delete from sys_file_info
where type_id = #{typeId} and repair_status = 2
<if test="maId != null and maId != ''">
and ma_id = #{maId}
</if>
</delete>
<update id="editEquipmentNew">
update repair_equipment_record
<set>
<if test="maId != null">
ma_id = #{maId},
</if>
<if test="typeId != null ">
type_id = #{typeId},
</if>
<if test="repairNum != null">
repair_num = #{repairNum},
</if>
<if test="repairer != null and repairer != ''">
repairer = #{repairer},
</if>
<if test="repairTime != null">
repair_time = #{repairTime},
</if>
<if test="repairType != null">
repair_type = #{repairType},
</if>
update_by = #{updateBy},
update_time = now()
</set>
where id = #{id}
</update>
<update id="submitStatusNew">
update repair_equipment_record
<set>
status = 1
</set>
where id = #{id}
</update>
<select id="getMaintenanceEquipment" resultType="com.bonus.sgzb.material.domain.EquipmentRecord">
select
red.parent_id as parentId,
red.create_time,
red.type_id,
mm.ma_id as maId,
mm.ma_code as maCode,
rer.repair_num as repairNum,
rer.status as repairStatus,
DATE_FORMAT(rer.repair_time, '%Y-%m-%d') as repairTime,
mt2.type_name as typeName,
mt.type_name as typeModelName,
su.nick_name as repairerName,
(
SELECT GROUP_CONCAT(DISTINCT red2.repair_remark SEPARATOR ';')
FROM repair_equipment_details red2
WHERE red2.parent_id = rer.id
) as repairRemark,
-- 使用子查询获取 repairRemarkBefore
(
SELECT GROUP_CONCAT(DISTINCT red3.repair_content_before SEPARATOR ';')
FROM repair_equipment_details red3
WHERE red3.parent_id = rer.id
) as repairContentBefore,
(
SELECT GROUP_CONCAT(
CASE
-- 当 part_id 存在时,关联表获取 pa_name
WHEN red4.part_id IS NOT NULL THEN CONCAT(mpt.pa_name, '','数量为',red4.part_num,' ', red4.repair_content)
WHEN red4.part_name IS NOT NULL THEN CONCAT(red4.part_name, '','数量为',red4.part_num,' ', red4.repair_content)
WHEN (red4.part_id IS NULL and red4.part_name IS NULL) THEN CONCAT( red4.repair_content)
ELSE NULL
END
SEPARATOR '; '
)
FROM repair_equipment_details red4
LEFT JOIN ma_part_type mpt ON red4.part_id = mpt.pa_id
WHERE red4.parent_id = rer.id
) as repairContent
from
repair_equipment_details red
left join repair_equipment_record rer on red.parent_id = rer.id
left join ma_machine mm on mm.ma_id = rer.ma_id
left join ma_type mt on rer.type_id = mt.type_id
left join sys_user su on rer.repairer = su.user_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
where
red.parent_id = #{id}
group by red.parent_id,red.type_id
</select>
<delete id="deleteRecord">
delete from repair_equipment_record where id = #{id}
</delete>
</mapper>