Bonus-Cloud-Material-Mall/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/device/MaDevQcMapper.xml

195 lines
7.9 KiB
XML

<?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.material.device.mapper.MaDevQcMapper">
<update id="updateById">
update ma_dev_qc
<set>
<if test="qcUser != null and qcUser != ''">qc_user = #{qcUser},</if>
<if test="qcTime != null ">qc_time = #{qcTime},</if>
<if test="nextCheckTime != null ">next_check_time = #{nextCheckTime},</if>
</set>
where id = #{id}
</update>
<update id="updateFileId">
update ma_dev_qc set file_id = #{fileId} where id = #{id}
</update>
<delete id="deleteDevQcByFileId">
delete from ma_dev_qc where file_id = #{fileId}
</delete>
<insert id="insertDevQc" useGeneratedKeys="true" keyProperty="id">
insert into ma_dev_qc
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="maId != null">ma_id,</if>
<if test="nextCheckTime != null">next_check_time,</if>
<if test="qcCode != null and qcCode != ''">qc_code,</if>
<if test="qcUser != null and qcUser != ''">qc_user,</if>
<if test="qcCom != null and qcCom != ''">qc_com,</if>
<if test="qcTime != null">qc_time,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="maId != null">#{maId},</if>
<if test="nextCheckTime != null">#{nextCheckTime},</if>
<if test="qcCode != null and qcCode != ''">#{qcCode},</if>
<if test="qcUser != null and qcUser != ''">#{qcUser},</if>
<if test="qcCom != null and qcCom != ''">#{qcCom},</if>
<if test="qcTime != null">#{qcTime},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<select id="selectTaskNumByMonth" resultType="java.lang.String">
SELECT SUBSTRING(qc_code, - 4) as code
FROM ma_dev_qc
WHERE DATE_FORMAT(create_time, '%y%m') = DATE_FORMAT(#{date}, '%y%m')
ORDER BY create_time DESC LIMIT 1
</select>
<select id="selectDevQcList" resultType="com.bonus.material.device.domain.MaDevQc">
SELECT
m1.id,
m2.ma_id AS maId,
m2.CODE AS deviceCode,
m2.device_name AS deviceName,
m2.item_type_model AS itemTypeModel,
m1.qc_code AS qcCode,
m1.qc_user AS qcUser,
m1.qc_time AS qcTime,
m3.maintenance_alarm_day,
su.nick_name AS createBy,
m1.next_check_time AS nextCheckTime,
m1.create_time AS updateTime,
aa.create_time AS createTime,
su.phonenumber AS phonenumber,
CASE
WHEN DATEDIFF(m1.next_check_time, CURDATE()) &lt; 0 THEN '已超期'
WHEN DATEDIFF(m1.next_check_time, CURDATE()) &lt;= 30 THEN '一月内到期'
ELSE '正常'
END AS alert
FROM
ma_dev_info m2
LEFT JOIN ma_dev_qc m1 ON m1.ma_id = m2.ma_id
LEFT JOIN ma_type m3 ON m2.type_id = m3.type_id
LEFT JOIN sys_user su ON su.user_id = m1.create_by
LEFT JOIN ( SELECT count(*) as num, ma_id, MAX( qc_time ) AS max_qc_time FROM ma_dev_qc GROUP BY ma_id )
latest_qc ON m1.ma_id = latest_qc.ma_id
LEFT JOIN ( SELECT ma_id, min( create_time ) AS create_time FROM ma_dev_qc GROUP BY ma_id ) aa ON m1.ma_id =
aa.ma_id
LEFT JOIN jj_sing_project jsp ON m2.on_project = jsp.pro_code
LEFT JOIN sys_dept sd ON sd.dept_id = m2.on_company
LEFT JOIN ma_supplier ms ON ms.supplier_id = m2.supplier_id
LEFT JOIN sys_cnarea sc ON sc.area_code = m2.province_id
<where>
m2.is_active = '1' and m2.entry_status = '1'
<if test="deviceCode != null and deviceCode != ''">
and m2.code like concat('%',#{deviceCode},'%')
</if>
<if test="qcUser != null and qcUser != ''">
and m1.qc_user like concat('%',#{qcUser},'%')
</if>
<if test="minNum != null and maxNum != null">
and latest_qc.num BETWEEN #{minNum} AND #{maxNum}
</if>
<if test="qcCode != null and qcCode != ''">
and m1.qc_code like concat('%',#{qcCode},'%')
</if>
<if test="qcStartTime != null and qcStartTime != '' and qcEndTime != null and qcEndTime != ''">
and DATE_FORMAT(m1.qc_time,'%Y-%m-%d') between #{qcStartTime} and #{qcEndTime}
</if>
<if test="createStartTime != null and createStartTime != '' and createEndTime != null and createEndTime != ''">
and DATE_FORMAT(m1.create_time,'%Y-%m-%d') between #{createStartTime} and #{createEndTime}
</if>
<if test="qcCom != null and qcCom != ''">
and m2.on_company = #{qcCom}
</if>
</where>
GROUP BY m2.ma_id
</select>
<select id="selectQcList" resultType="com.bonus.material.device.domain.MaDevQc">
SELECT
mdq.*,
su.nick_name AS nickName,
bfi.url AS url
FROM
ma_dev_qc mdq
LEFT JOIN bm_file_info bfi ON bfi.model_id = mdq.ma_id and bfi.task_id = mdq.id
LEFT JOIN sys_user su ON mdq.create_by = su.user_id
WHERE
bfi.task_type = 17
AND bfi.file_type = 4
AND bfi.model_id = #{maId}
<if test="qcCode != null and qcCode != ''">
and mdq.qc_code like concat('%',#{qcCode},'%')
</if>
<if test="qcStartTime != null and qcStartTime != '' and qcEndTime != null and qcEndTime != ''">
and DATE_FORMAT(mdq.qc_time,'%Y-%m-%d') between #{qcStartTime} and #{qcEndTime}
</if>
<if test="createStartTime != null and createStartTime != '' and createEndTime != null and createEndTime != ''">
and DATE_FORMAT(mdq.create_time,'%Y-%m-%d') between #{createStartTime} and #{createEndTime}
</if>
</select>
<select id="getQcList" resultType="com.bonus.material.device.domain.MaDevQc">
SELECT
mdc.qc_time,
mdc.id,
mdc.ma_id,
mt.maintenance_alarm_day,
sd.dept_name comName
FROM
ma_dev_qc mdc
LEFT JOIN ma_dev_info mdi ON mdc.ma_id = mdi.ma_id
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
LEFT JOIN sys_dept sd ON mdc.qc_com = sd.dept_id
WHERE
mdc.ma_id = #{maId}
LIMIT 10
</select>
<select id="getQcListByOne" resultType="com.bonus.material.device.domain.MaDevQc">
SELECT
mdc.id,
mdc.qc_time,
mdc.ma_id,
mt.maintenance_alarm_day,
mdc.qc_user,
mdc.next_check_time,
sd.dept_name comName
FROM
ma_dev_qc mdc
LEFT JOIN ma_dev_info mdi ON mdc.ma_id = mdi.ma_id
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
LEFT JOIN sys_dept sd ON mdc.qc_com = sd.dept_id
WHERE
mdc.ma_id = #{maId}
order by mdc.qc_time desc
LIMIT 1
</select>
<select id="checkQcTime" resultType="com.bonus.material.device.domain.MaDevQc">
SELECT
mdc.create_time,
mdc.qc_com,
mdc.ma_id,
mdi.device_name,
mdi.creator as own_id,
sd.dept_name as comName,
mdc.next_check_time
FROM
ma_dev_qc mdc
left join ma_dev_info mdi on mdi.ma_id = mdc.ma_id
left join sys_dept sd on mdc.qc_com = sd.dept_id
where mdc.next_check_time &lt; now()
</select>
<select id="selectDevQcListByMaId" resultType="java.lang.Integer">
select count(*) from ma_dev_qc where ma_id = #{maId}
</select>
</mapper>