devicesmgt/sgzb-modules/sgzb-material/src/main/resources/mapper/material/ScrapApplyDetailsMapper.xml

1182 lines
44 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.sgzb.material.mapper.ScrapApplyDetailsMapper">
<resultMap type="com.bonus.sgzb.material.domain.ScrapApplyDetails" id="ScrapApplyDetailsResult">
<result property="id" column="id" />
<result property="taskId" column="task_id" />
<result property="parentId" column="parent_id" />
<result property="maId" column="ma_id" />
<result property="typeId" column="type_id" />
<result property="scrapNum" column="scrap_num" />
<result property="scrapSource" column="scrap_source" />
<result property="scrapType" column="scrap_type" />
<result property="status" column="status" />
<result property="auditBy" column="audit_by" />
<result property="auditTime" column="audit_time" />
<result property="auditRemark" column="audit_remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="fileUrl" column="file_url" />
<result property="companyId" column="company_id" />
<result property="fileName" column="file_name" />
</resultMap>
<sql id="selectScrapApplyDetailsVo">
select id, task_id, parent_id, ma_id, type_id, scrap_num, scrap_source, scrap_type, status, audit_by, audit_time, audit_remark, create_by, create_time, update_by, update_time, remark, file_url, company_id, file_name from scrap_apply_details
</sql>
<select id="selectScrapApplyDetailsList" parameterType="com.bonus.sgzb.material.domain.ScrapApplyDetails" resultType="com.bonus.sgzb.material.vo.ScrapApplyDetailsVO">
SELECT
tk.CODE scrapNum,
tk.task_status taskStatus,
dic.NAME taskStatusName,
bui.unit_name unitName,
bpl.lot_name projectName,
su.nick_name createBy,
tk.create_time createTime,
tk.remark,
tk1.CODE repairNum,
sad.scrap_num as scrapNum2,
sad.scrap_source as scrapSource,
sad.file_url as fileUrl,
tk.is_commit as commit,
tk.task_id taskId
FROM
tm_task tk
LEFT JOIN tm_task_agreement tta ON tk.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai ON tta.agreement_id = bai.agreement_id
LEFT JOIN bm_project_lot bpl ON bai.project_id = bpl.lot_id
LEFT JOIN bm_unit_info bui ON bai.unit_id = bui.unit_id
LEFT JOIN scrap_apply_details sad ON tk.task_id = sad.task_id
/* LEFT JOIN repair_audit_details rad ON sad.parent_id = rad.id
LEFT JOIN repair_apply_details rad2 ON rad.repair_id = rad2.id*/
LEFT JOIN scrap_apply_details sad1 ON sad.parent_id = sad1.id
LEFT JOIN tm_task tk1 ON sad1.task_id = tk1.task_id
LEFT JOIN (
SELECT
id,
p_id,
NAME
FROM
sys_dic
WHERE
p_id IN ( SELECT id FROM sys_dic WHERE VALUE = 'bf_task' )) dic ON tk.task_status = dic.id
LEFT JOIN ma_type mt ON sad.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
LEFT JOIN sys_user su ON su.user_id = tk.create_by
WHERE
sad.scrap_source IN ( '1', '2' )
AND tk.task_type = 57
<if test="keyword != null and keyword != ''">
AND (locate(#{keyword}, tk.create_by) > 0
or locate(#{keyword}, tk.CODE) > 0
or locate(#{keyword}, bui.unit_name) > 0
or locate(#{keyword}, bpl.lot_name) > 0
or locate(#{keyword}, tk1.CODE) > 0)
</if>
<if test="backUnit != null and backUnit != ''">
and bui.unit_id = #{backUnit}
</if>
<if test="backPro != null and backPro != ''">
and bpl.lot_id = #{backPro}
</if>
<if test="scrapCode != null and scrapCode != ''">
and tk.CODE like concat('%', #{scrapCode}, '%')
</if>
<if test="taskStatus != null and taskStatus != ''">
and tk.task_status = #{taskStatus}
</if>
<if test="scrapSource != null and scrapSource != ''">
and sad.scrap_source = #{scrapSource}
</if>
<if test="type != null and type != ''">
and mt1.type_id = #{type}
</if>
<if test="backCode != null and backCode != ''">
and locate(#{backCode}, tk.code) > 0
</if>
<if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
and DATE(tk.create_time) between #{beginTime} and #{endTime}
</if>
GROUP BY tk.CODE
order by tk.create_time desc
</select>
<select id="exportScrapApplyDetailsList" resultType="com.bonus.sgzb.material.vo.ScrapApplyDetailsVO">
SELECT
tk.CODE scrapNum,
tk.task_status taskStatus,
dic.NAME taskStatusName,
bui.unit_name unitName,
bpl.lot_name projectName,
su.nick_name createBy,
tk.create_time createTime,
tk.remark,
tk1.CODE repairNum,
tk.task_id taskId,
mt1.type_name AS type,
mt.type_name AS typeName,
mma.ma_code AS maCode,
sad.scrap_num AS scrapNum2
FROM
tm_task tk
LEFT JOIN tm_task_agreement tta ON tk.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai ON tta.agreement_id = bai.agreement_id
LEFT JOIN bm_project_lot bpl ON bai.project_id = bpl.lot_id
LEFT JOIN bm_unit_info bui ON bai.unit_id = bui.unit_id
LEFT JOIN scrap_apply_details sad ON tk.task_id = sad.task_id
LEFT JOIN tm_task tk1 ON sad.parent_id = tk1.task_id
LEFT JOIN (
SELECT
id,
p_id,
NAME
FROM
sys_dic
WHERE
p_id IN ( SELECT id FROM sys_dic WHERE VALUE = 'bf_task' )) dic ON tk.task_status = dic.id
LEFT JOIN ma_type mt ON sad.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
left join ma_machine mma on sad.ma_id= mma.ma_id
LEFT JOIN sys_user su ON su.user_id = tk.create_by
WHERE
sad.scrap_source IN ( '1', '2' )
AND tk.task_type = 57
<if test="keyword != null and keyword != ''">
AND (locate(#{keyword}, tk.create_by) > 0
or locate(#{keyword}, tk.CODE) > 0
or locate(#{keyword}, bui.unit_name) > 0
or locate(#{keyword}, bpl.lot_name) > 0
or locate(#{keyword}, tk1.CODE) > 0)
</if>
<if test="backUnit != null and backUnit != ''">
and bui.unit_id = #{backUnit}
</if>
<if test="repairStatus != null and repairStatus != ''">
and tk.task_status = #{repairStatus}
</if>
<if test="backPro != null and backPro != ''">
and bpl.lot_id = #{backPro}
</if>
<if test="type != null and type != ''">
and mt1.type_id = #{type}
</if>
<if test="backCode != null and backCode != ''">
and locate(#{backCode}, tk.code) > 0
</if>
<if test="params.beginTime != null and params.beginTime != '' and params.endTime != null and params.endTime != ''">
and tk.create_time between #{params.beginTime} and #{params.endTime}
</if>
GROUP BY tk.CODE
order by tk.create_time desc
</select>
<select id="selectScrapApplyDetailsById" parameterType="Long" resultMap="ScrapApplyDetailsResult">
<include refid="selectScrapApplyDetailsVo"/>
where id = #{id}
</select>
<insert id="insertScrapApplyDetails" parameterType="com.bonus.sgzb.material.domain.ScrapApplyDetails">
insert into scrap_apply_details
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="taskId != null">task_id,</if>
<if test="parentId != null">parent_id,</if>
<if test="maId != null">ma_id,</if>
<if test="typeId != null">type_id,</if>
<if test="scrapNum != null">scrap_num,</if>
<if test="scrapSource != null">scrap_source,</if>
<if test="scrapType != null">scrap_type,</if>
<if test="status != null">status,</if>
<if test="auditBy != null">audit_by,</if>
<if test="auditTime != null">audit_time,</if>
<if test="auditRemark != null">audit_remark,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
<if test="fileUrl != null">file_url,</if>
<if test="companyId != null">company_id,</if>
<if test="fileName != null">file_name,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="taskId != null">#{taskId},</if>
<if test="parentId != null">#{parentId},</if>
<if test="maId != null">#{maId},</if>
<if test="typeId != null">#{typeId},</if>
<if test="scrapNum != null">#{scrapNum},</if>
<if test="scrapSource != null">#{scrapSource},</if>
<if test="scrapType != null">#{scrapType},</if>
<if test="status != null">#{status},</if>
<if test="auditBy != null">#{auditBy},</if>
<if test="auditTime != null">#{auditTime},</if>
<if test="auditRemark != null">#{auditRemark},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
<if test="fileUrl != null">#{fileUrl},</if>
<if test="companyId != null">#{companyId},</if>
<if test="fileName != null">#{fileName},</if>
</trim>
</insert>
<insert id="addBackDetails">
insert into back_apply_details (parent_id,type_id,pre_num,audit_num,status,create_by,create_time,update_by,update_time,company_id)
values (#{parentId},#{typeId},#{scrapNum},#{scrapNum},#{status},#{createBy},now(),#{updateBy},now(),#{companyId});
</insert>
<insert id="addBackInfo" useGeneratedKeys="true" keyProperty="id">
insert into back_apply_info (code,task_id,back_person,phone,direct_audit_by,direct_audit_time,direct_audit_remark,create_by,create_time,update_by,update_time,company_id,back_time,status)
values (#{code},#{taskId},#{backPerson},#{phone},#{directAuditBy},#{directAuditTime},#{directAuditRemark},#{createBy},now(),#{updateBy},now(),#{companyId},#{backTime},#{status});
</insert>
<insert id="addRepaieAudit">
insert into repair_audit_details (task_id,repair_id,ma_id,type_id,repair_num,repaired_num,scrap_num,status,create_by,create_time,update_by,update_time,company_id)
values (#{taskId},#{repairId},#{maId},#{typeId},#{repairNum},#{repairedNum},#{scrapNum},#{status},#{createBy},now(),#{updateBy},now(),#{companyId});
</insert>
<insert id="insertCheckDetails">
insert into scrap_check_details
(
<if test="parentId != null">
parent_id,
</if>
<if test="typeId != null">
type_id,
</if>
<if test="maId != null">
ma_id,
</if>
<if test="backNum != null">
back_num,
</if>
<if test="backStatus != null">
back_status,
</if>
<if test="createBy != null and createBy != ''">
create_by,
</if>
<if test="createBy != null and createBy != ''">
update_by,
</if>
update_time,
<if test="remark != null and remark != ''">
remark,
</if>
<if test="scrapReason != null and scrapReason != ''">
scrap_reason,
</if>
<if test="scrapType != null">
scrap_type,
</if>
<if test="fileUrl != null and fileUrl != ''">
file_url,
</if>
<if test="companyId != null">
company_id,
</if>
<if test="taskId != null">
old_task_id,
</if>
create_time
)
values (
<if test="parentId != null">
#{parentId},
</if>
<if test="typeId != null">
#{typeId},
</if>
<if test="maId != null">
#{maId},
</if>
<if test="backNum != null">
#{backNum},
</if>
<if test="backStatus != null">
#{backStatus},
</if>
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
NOW(),
<if test="remark != null and remark != ''">
#{remark},
</if>
<if test="scrapReason != null and scrapReason != ''">
#{scrapReason},
</if>
<if test="scrapType != null">
#{scrapType},
</if>
<if test="fileUrl != null and fileUrl != ''">
#{fileUrl},
</if>
<if test="companyId != null">
#{companyId},
</if>
<if test="taskId != null">
#{taskId},
</if>
NOW()
)
</insert>
<insert id="insertIad">
insert into input_apply_details
(
<if test="taskId != null">
task_id,
</if>
<if test="maId != null">
ma_id,
</if>
<if test="typeId != null">
type_id,
</if>
<if test="parentId != null">
parent_id,
</if>
<if test="backNum != null">
input_num,
</if>
input_type,
<if test="createBy != null and createBy != ''">
create_by,
</if>
<if test="createBy != null and createBy != ''">
update_by,
</if>
update_time,
<if test="remark != null and remark != ''">
remark,
</if>
<if test="companyId != null">
company_id,
</if>
create_time
)
values (
<if test="taskId != null">
#{taskId},
</if>
<if test="maId != null">
#{maId},
</if>
<if test="typeId != null">
#{typeId},
</if>
<if test="parentId != null">
#{parentId},
</if>
<if test="backNum != null">
#{backNum},
</if>
'2',
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
NOW(),
<if test="remark != null and remark != ''">
#{remark},
</if>
<if test="companyId != null">
#{companyId},
</if>
NOW()
)
</insert>
<insert id="insertTta">
insert into tm_task_agreement
(
<if test="taskId != null">
task_id,
</if>
<if test="agreementId != null">
agreement_id,
</if>
create_time
) values (
<if test="taskId != null">
#{taskId},
</if>
<if test="agreementId != null">
#{agreementId},
</if>
NOW()
)
</insert>
<insert id="insertRad">
insert into repair_apply_details
(
<if test="taskId != null">
task_id,
</if>
<if test="maId != null">
ma_id,
</if>
<if test="typeId != null">
type_id,
</if>
<if test="backNum != null">
repair_num,
</if>
<if test="status != null">
status,
</if>
<if test="createBy != null and createBy != ''">
create_by,
</if>
<if test="createBy != null and createBy != ''">
update_by,
</if>
update_time,
<if test="remark != null and remark != ''">
remark,
</if>
<if test="companyId != null">
company_id,
</if>
<if test="id != null">
back_id,
</if>
back_source,
create_time
)
values (
<if test="taskId != null">
#{taskId},
</if>
<if test="maId != null">
#{maId},
</if>
<if test="typeId != null">
#{typeId},
</if>
<if test="backNum != null">
#{backNum},
</if>
<if test="status != null">
#{status},
</if>
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
NOW(),
<if test="remark != null and remark != ''">
#{remark},
</if>
<if test="companyId != null">
#{companyId},
</if>
<if test="id != null">
#{id},
</if>
1,
NOW()
)
</insert>
<insert id="insertSad">
insert into scrap_apply_details
(
<if test="taskId != null">
task_id,
</if>
<if test="parentId != null">
parent_id,
</if>
<if test="maId != null">
ma_id,
</if>
<if test="typeId != null">
type_id,
</if>
<if test="backNum != null">
scrap_num,
</if>
scrap_source,
status,
<if test="createBy != null and createBy != ''">
create_by,
</if>
<if test="companyId != null">
company_id,
</if>
<if test="scrapReason != null and scrapReason != ''">
remark,
</if>
<if test="scrapType != null">
scrap_type,
</if>
<if test="fileUrl != null and fileUrl != ''">
file_url,
</if>
create_time
)
values (
<if test="taskId != null">
#{taskId},
</if>
<if test="parentId != null">
#{parentId},
</if>
<if test="maId != null">
#{maId},
</if>
<if test="typeId != null">
#{typeId},
</if>
<if test="backNum != null">
#{backNum},
</if>
'1',
'0',
<if test="createBy != null and createBy != ''">
#{createBy},
</if>
<if test="companyId != null">
#{companyId},
</if>
<if test="scrapReason != null and scrapReason != ''">
#{scrapReason},
</if>
<if test="scrapType != null">
#{scrapType},
</if>
<if test="fileUrl != null and fileUrl != ''">
#{fileUrl},
</if>
NOW()
)
</insert>
<update id="updateScrapApplyDetails" parameterType="com.bonus.sgzb.material.domain.ScrapApplyDetails">
update scrap_apply_details
<trim prefix="SET" suffixOverrides=",">
<if test="taskId != null">task_id = #{taskId},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="maId != null">ma_id = #{maId},</if>
<if test="typeId != null">type_id = #{typeId},</if>
<if test="scrapNum != null">scrap_num = #{scrapNum},</if>
<if test="scrapSource != null">scrap_source = #{scrapSource},</if>
<if test="scrapType != null">scrap_type = #{scrapType},</if>
<if test="status != null">status = #{status},</if>
<if test="auditBy != null">audit_by = #{auditBy},</if>
<if test="auditTime != null">audit_time = #{auditTime},</if>
<if test="auditRemark != null">audit_remark = #{auditRemark},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="fileUrl != null">file_url = #{fileUrl},</if>
<if test="companyId != null">company_id = #{companyId},</if>
<if test="fileName != null">file_name = #{fileName},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteScrapApplyDetailsById" parameterType="Long">
delete from scrap_apply_details where id = #{id}
</delete>
<delete id="deleteScrapApplyDetailsByIds" parameterType="String">
delete from scrap_apply_details where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="deleteCheckDetails">
delete from scrap_check_details where parent_id = #{parentId} and type_id = #{typeId} and old_task_id = #{taskId}
<if test="maId != null and maId != ''">
and ma_id = #{maId}
</if>
</delete>
<select id="selectScrapAuditList" resultMap="ScrapApplyDetailsResult">
select sad.* ,mt.type_name specificationType, mt1.type_name machineTypeName, mma.ma_code maCode
from scrap_apply_details sad
left join ma_type mt on sad.type_id = mt.type_id
left join ma_type mt1 on mt.parent_id = mt1.type_id
left join ma_machine mma on sad.ma_id= mma.ma_id
where sad.task_id = #{taskId}
<if test="keyword != null and keyword != ''">
AND (locate(#{keyword}, mma.ma_code) > 0
or locate(#{keyword}, mt.type_name) > 0
or locate(#{keyword}, mt1.type_name) > 0)
</if>
<if test="type != null and type != ''">
AND mt.type_id = #{type}
</if>
<if test="typeName != null and typeName != ''">
AND mt1.type_id = #{typeName}
</if>
<if test="status != null and status != ''">
AND sad.status = #{status}
</if>
<if test="scrapSource != null and scrapSource != ''">
AND sad.scrap_source = #{scrapSource}
</if>
order by sad.create_time desc
</select>
<select id="selectScrapDetailsByTaskId" resultMap="ScrapApplyDetailsResult">
<include refid="selectScrapApplyDetailsVo"/>
where task_id = #{taskId}
</select>
<update id="updateMachine">
update ma_machine set ma_status = 22 where ma_id = #{maId}
</update>
<update id="updateStatus">
update scrap_apply_details
set audit_by = #{auditBy},
audit_time = now(),
status = #{status},
update_by = #{updateBy},
update_time = now(),
audit_remark = #{auditRemark}
where id = #{id}
</update>
<update id="updateMaStatus">
update ma_machine
set ma_status=#{maStatus}
where ma_id = #{maId}
</update>
<update id="updateMt">
UPDATE ma_type
SET num = (IFNULL(num, 0)) + #{backNum}
WHERE type_id = #{typeId}
</update>
<update id="updateStatusThree">
update scrap_apply_details
set status = #{status}
where task_id = #{taskId}
</update>
<select id="selectTypeNameByTaskId" resultType="java.lang.String">
select GROUP_CONCAT(type_name) typeName from
(select distinct sad.task_id, mt1.type_name
from scrap_apply_details sad
left join ma_type mt on sad.type_id = mt.type_id
left join ma_type mt1 on mt.parent_id = mt1.type_id
where sad.task_id = #{taskId}
) t
GROUP BY task_id
</select>
<select id="selectnotScrapByTaskId" resultType="com.bonus.sgzb.material.domain.ScrapApplyDetails">
<include refid="selectScrapApplyDetailsVo"/>
where task_id = #{taskId} and status = '0'
</select>
<select id="getBackApplyInfo" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
select id,
code,
task_id as taskId,
back_person as backPerson,
phone,
direct_audit_by as directAuditBy,
direct_audit_time as directAuditTime,
direct_audit_remark as directAuditRemark,
company_id as companyId,
back_time as backTime,
status
from back_apply_info
where id = #{parentId}
</select>
<select id="getRepairAudit" resultType="com.bonus.sgzb.material.domain.RepairAuditDetails">
select id,
task_id as taskId,
repair_id as repairId,
ma_id as maId,
type_id as typeId,
repair_num as repairNum,
scrap_num as scrapNum,
company_id as companyId
from repair_audit_details
where id = #{parentId}
</select>
<select id="getRepairId" resultType="java.lang.String">
select repair_id
from repair_audit_details
where id = #{parentId}
</select>
<select id="getByRepairId" resultType="com.bonus.sgzb.material.domain.RepairAuditDetails">
select task_id as taskId,
ma_id as maId,
type_id as typeId
from repair_apply_details
where id = #{repairId}
</select>
<select id="getRepairRecord" resultType="com.bonus.sgzb.material.domain.RepairRecord">
select scrap_num as scrapNum,
scrap_reason as scrapReason,
scrap_type as scrapType,
file_ids as fileIds
from repair_apply_record rar
where repair_type = '3'
<if test="taskId != null and taskId != ''">
and rar.task_id = #{taskId}
</if>
<if test="maId != null and maId != ''">
and rar.ma_id = #{maId}
</if>
<if test="typeId != null and typeId != ''">
and rar.type_id = #{typeId}
</if>
</select>
<select id="getFileUrl" resultType="java.lang.String">
select file_url
from sys_file_info
where id = #{s}
</select>
<select id="getGyoupRepairRecord" resultType="com.bonus.sgzb.material.domain.RepairRecord">
select sum(scrap_num) as scrapNum,
scrap_reason as scrapReason,
scrap_type as scrapType,
file_ids as fileIds
from repair_apply_record rar
where repair_type = '3'
<if test="taskId != null and taskId != ''">
and rar.task_id = #{taskId}
</if>
<if test="maId != null and maId != ''">
and rar.ma_id = #{maId}
</if>
<if test="typeId != null and typeId != ''">
and rar.type_id = #{typeId}
</if>
group by scrap_type
</select>
<select id="getScrapApplyList" resultType="com.bonus.sgzb.material.vo.ScrapApplyDetailsVO">
SELECT
tk.CODE scrapNum,
tk.task_status taskStatus,
dic.NAME taskStatusName,
bui.unit_id unitId,
bui.unit_name unitName,
bpl.lot_id projectId,
bpl.lot_name projectName,
su.nick_name createBy,
tk.create_time createTime,
tk.remark,
tk1.CODE repairNum,
sad.scrap_num as scrapNum2,
sad.scrap_source as scrapSource,
rad3.CODE repairCode,
tk.task_id taskId
FROM
tm_task tk
LEFT JOIN tm_task_agreement tta ON tk.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai ON tta.agreement_id = bai.agreement_id
LEFT JOIN bm_project_lot bpl ON bai.project_id = bpl.lot_id
LEFT JOIN bm_unit_info bui ON bai.unit_id = bui.unit_id
LEFT JOIN scrap_apply_details sad ON tk.task_id = sad.task_id
LEFT JOIN repair_audit_details rad ON sad.parent_id = rad.id
LEFT JOIN back_apply_info rad3 ON sad.parent_id = rad3.id
LEFT JOIN tm_task tk1 ON rad.task_id = tk1.task_id
LEFT JOIN (
SELECT
id,
p_id,
NAME
FROM
sys_dic
WHERE
p_id = '20') dic ON tk.task_status = dic.id
LEFT JOIN ma_type mt ON sad.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
LEFT JOIN sys_user su ON su.user_id = tk.create_by
WHERE
sad.scrap_source IN ( '1', '2' )
AND tk.task_type IN ('20' , '21')
<if test="keyword != null and keyword != ''">
AND (locate(#{keyword}, tk.create_by) > 0
or locate(#{keyword}, tk.CODE) > 0
or locate(#{keyword}, bui.unit_name) > 0
or locate(#{keyword}, bpl.lot_name) > 0
or locate(#{keyword}, tk1.CODE) > 0)
</if>
<if test="backUnit != null and backUnit != ''">
and bui.unit_id = #{backUnit}
</if>
<if test="taskStatus != null and taskStatus != ''">
and tk.task_status = #{taskStatus}
</if>
<if test="taskIdList != null and taskIdList != ''">
and tk.task_id in #{taskIdList}
</if>
<if test="backPro != null and backPro != ''">
and bpl.lot_id = #{backPro}
</if>
<if test="scrapSource != null and scrapSource != ''">
and sad.scrap_source = #{scrapSource}
</if>
<if test="type != null and type != ''">
and mt1.type_id = #{type}
</if>
<if test="backCode != null and backCode != ''">
and locate(#{backCode}, tk.code) > 0
</if>
<if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
and DATE(tk.create_time) between #{beginTime} and #{endTime}
</if>
<if test="dataCondition != null and dataCondition.size()>0">
AND tk.task_id in
<foreach collection="dataCondition" item="taskId" index="index" open="(" separator="," close=")">
#{taskId}
</foreach>
</if>
GROUP BY tk.CODE
order by tk.create_time desc
</select>
<select id="scrapTaskReviewList" resultType="com.bonus.sgzb.material.vo.ScrapApplyDetailsVO">
SELECT
tk.CODE scrapNum,
tk.task_status taskStatus,
dic.NAME taskStatusName,
bui.unit_name unitName,
bpl.lot_name projectName,
su.nick_name createBy,
tk.create_time createTime,
tk.remark,
tk1.CODE repairNum,
sad.scrap_num as scrapNum2,
sad.scrap_source as scrapSource,
sad.file_url as fileUrl,
tk.task_id taskId
FROM
tm_task tk
LEFT JOIN tm_task_agreement tta ON tk.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai ON tta.agreement_id = bai.agreement_id
LEFT JOIN bm_project_lot bpl ON bai.project_id = bpl.lot_id
LEFT JOIN bm_unit_info bui ON bai.unit_id = bui.unit_id
LEFT JOIN scrap_apply_details sad ON tk.task_id = sad.task_id
/* LEFT JOIN repair_audit_details rad ON sad.parent_id = rad.id
LEFT JOIN repair_apply_details rad2 ON rad.repair_id = rad2.id*/
LEFT JOIN scrap_apply_details sad1 ON sad.parent_id = sad1.id
LEFT JOIN tm_task tk1 ON sad1.task_id = tk1.task_id
LEFT JOIN (
SELECT
id,
p_id,
NAME
FROM
sys_dic
WHERE
p_id IN ( SELECT id FROM sys_dic WHERE VALUE = 'bf_task' )) dic ON tk.task_status = dic.id
LEFT JOIN ma_type mt ON sad.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
LEFT JOIN sys_user su ON su.user_id = tk.create_by
WHERE
sad.scrap_source IN ( '1', '2' )
AND tk.task_type = 57 AND tk.task_status in ('58','59','61')
<if test="keyword != null and keyword != ''">
AND (locate(#{keyword}, tk.create_by) > 0
or locate(#{keyword}, tk.CODE) > 0
or locate(#{keyword}, bui.unit_name) > 0
or locate(#{keyword}, bpl.lot_name) > 0
or locate(#{keyword}, tk1.CODE) > 0)
</if>
<if test="backUnit != null and backUnit != ''">
and bui.unit_id = #{backUnit}
</if>
<if test="repairStatus != null and repairStatus != ''">
and tk.task_status = #{repairStatus}
</if>
<if test="backPro != null and backPro != ''">
and bpl.lot_id = #{backPro}
</if>
<if test="type != null and type != ''">
and mt1.type_id = #{type}
</if>
<if test="taskStatus != null and taskStatus != ''">
and dic.id = #{taskStatus}
</if>
<if test="scrapSource != null and scrapSource != ''">
and sad.scrap_source = #{scrapSource}
</if>
<if test="backCode != null and backCode != ''">
and locate(#{backCode}, tk.code) > 0
</if>
<if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
and tk.create_time between #{beginTime} and #{endTime}
</if>
GROUP BY tk.CODE
order by tk.create_time desc
</select>
<select id="getScrapRefuseList" resultType="com.bonus.sgzb.material.domain.ScrapApplyDetails">
SELECT
sum( sad.scrap_num ) AS preNum,
sum( sad.scrap_num ) - IFNULL( sum( aa.back_num ), 0 ) AS num,
mt.type_name specificationType,
mt1.type_name machineTypeName,
mt.manage_type,
sad.parent_id,
GROUP_CONCAT( sad.parent_id ) parentIds,
mt.type_id
FROM
scrap_apply_details sad
LEFT JOIN (
SELECT
sum( scd1.back_num ) back_num,
scd1.parent_id,
sad1.type_id
FROM
scrap_check_details scd1
LEFT JOIN scrap_apply_details sad1 ON scd1.parent_id = sad1.parent_id
AND scd1.type_id = sad1.type_id and scd1.old_task_id = sad1.task_id
WHERE sad1.task_id = #{taskId}
GROUP BY
scd1.parent_id, sad1.type_id
) aa ON sad.parent_id = aa.parent_id AND sad.type_id = aa.type_id
LEFT JOIN ma_type mt ON sad.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
WHERE
sad.task_id = #{taskId}
GROUP BY
sad.type_id
ORDER BY
sad.create_time DESC
</select>
<select id="getScrapRefuseMaCodeList" resultType="com.bonus.sgzb.material.domain.ScrapApplyDetails">
SELECT
mt.type_name specificationType,
mt1.type_name machineTypeName,
mma.ma_code maCode,
mma.ma_id,
sad.type_id,
sad.parent_id,
sd.`name` maStatus
FROM
scrap_apply_details sad
LEFT JOIN ma_type mt ON sad.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
LEFT JOIN ma_machine mma ON sad.ma_id = mma.ma_id
LEFT JOIN sys_dic sd ON mma.ma_status = sd.id
WHERE
sad.task_id = #{taskId}
AND sad.type_id = #{typeId}
ORDER BY
sad.create_time DESC
</select>
<select id="selectNumByTypeId" resultType="java.lang.Integer">
SELECT
ROUND(SUM( res.auditNum )- SUM( res.backNum ),0) AS backNum
FROM
(
SELECT
bad.scrap_num AS auditNum,
0 AS backNum
FROM
scrap_apply_details bad
WHERE
bad.parent_id = #{parentId}
AND bad.type_id = #{typeId} and bad.task_id = #{taskId} UNION
SELECT
0 AS auditNum,
SUM(
IFNULL( bcd.back_num, 0 )) AS backNum
FROM
scrap_check_details bcd
WHERE
bcd.parent_id = #{parentId}
AND bcd.type_id = #{typeId} and bcd.old_task_id = #{taskId}
) res
HAVING backNum > -1
</select>
<select id="selectCodeByMaIdAndTaskId" resultType="java.lang.Integer">
SELECT
COUNT(*)
FROM
scrap_check_details bcd
LEFT JOIN scrap_apply_details sad ON bcd.parent_id = sad.parent_id and bcd.old_task_id = sad.task_id
WHERE
bcd.ma_id = #{maId}
AND sad.task_id = #{taskId}
</select>
<select id="getMaId" resultType="java.lang.Integer">
select ma_id from scrap_check_details where parent_id = #{parentId} and type_id = #{typeId}
</select>
<select id="scrapReceiveRecordWeb" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
SELECT
mt2.type_name AS typeName,
mt1.type_name AS typeCode,
ifnull(sum( scd.back_num ), 0) AS backNum,
SUM( CASE WHEN scd.back_status = 1 THEN scd.back_num ELSE 0 END ) AS hgNum,
SUM( CASE WHEN scd.back_status = 2 THEN scd.back_num ELSE 0 END ) AS wxNum,
SUM( CASE WHEN scd.back_status = 3 THEN scd.back_num ELSE 0 END ) AS bfNum,
mm.ma_code AS maCode,
scd.create_time AS backTime,
scd.type_id as modelId,
scd.back_status AS backStatus
FROM
scrap_check_details scd
LEFT JOIN ma_type mt1 ON mt1.type_id = scd.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
LEFT JOIN ma_machine mm ON mm.ma_id = scd.ma_id
WHERE
scd.parent_id = #{parentId}
AND scd.type_id = #{typeId}
AND scd.old_task_id = #{taskId}
GROUP BY
scd.type_id
ORDER BY
scd.create_time DESC
</select>
<select id="scrapReceiveRecordWebPt" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
SELECT
mt2.type_name AS typeName,
mt1.type_name AS typeCode,
ifnull( scd.back_num, 0 ) AS backNum,
mm.ma_code AS maCode,
scd.create_time AS backTime,
scd.type_id AS modelId,
scd.back_status AS backStatus
FROM
scrap_check_details scd
LEFT JOIN ma_type mt1 ON mt1.type_id = scd.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
LEFT JOIN ma_machine mm ON mm.ma_id = scd.ma_id
WHERE
scd.parent_id = #{parentId}
AND scd.type_id = #{typeId}
AND scd.old_task_id = #{taskId}
<if test="maCode != null and maCode != ''">
and mm.ma_code like concat('%', #{maCode}, '%')
</if>
ORDER BY
scd.create_time DESC
</select>
<select id="getScrapRefuseIsSuc" resultType="com.bonus.sgzb.material.domain.ScrapApplyDetails">
SELECT
sum( sad.scrap_num ) AS preNum,
sum( sad.scrap_num ) - IFNULL( sum( aa.back_num ), 0 ) AS num,
mt.type_name specificationType,
mt1.type_name machineTypeName,
mt.manage_type,
sad.parent_id,
GROUP_CONCAT( sad.parent_id ) parentIds,
mt.type_id
FROM
scrap_apply_details sad
LEFT JOIN (
SELECT
sum( scd1.back_num ) back_num,
scd1.parent_id,
sad1.type_id
FROM
scrap_check_details scd1
LEFT JOIN scrap_apply_details sad1 ON scd1.parent_id = sad1.parent_id
AND scd1.type_id = sad1.type_id and scd1.old_task_id = sad1.task_id
WHERE sad1.task_id = #{taskId}
GROUP BY
scd1.parent_id,
sad1.type_id
) aa ON sad.parent_id = aa.parent_id
AND sad.type_id = aa.type_id
LEFT JOIN ma_type mt ON sad.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
WHERE
sad.task_id = #{taskId}
GROUP BY
sad.type_id
ORDER BY
sad.create_time DESC
</select>
<select id="selectTaskStatus" resultType="java.lang.Integer">
select task_status from tm_task where task_id = #{taskId}
</select>
<select id="getHgList" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
SELECT
tta.agreement_id AS agreementId,
bai.id,
bai.task_id AS taskId,
bcd.type_id AS typeId,
bcd.back_num AS backNum,
bcd.parent_id AS parentId,
bcd.create_by AS createBy,
bcd.ma_id AS maId,
bai.company_id AS companyId
FROM
scrap_check_details bcd
LEFT JOIN scrap_apply_details bai ON bai.parent_id = bcd.parent_id
LEFT JOIN scrap_apply_details bai1 ON bai.parent_id = bai1.id
LEFT JOIN tm_task_agreement tta ON tta.task_id = bai.task_id
WHERE
bai.task_id = #{taskId}
AND bcd.old_task_id = bai.task_id
AND bcd.back_status = '1'
</select>
<select id="getWxList" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
SELECT
tta.agreement_id AS agreementId,
bai.id,
bai.task_id AS taskId,
bcd.type_id AS typeId,
bcd.back_num AS backNum,
bcd.parent_id AS parentId,
bcd.create_by AS createBy,
bcd.ma_id AS maId,
bai.company_id AS companyId
FROM
scrap_check_details bcd
LEFT JOIN scrap_apply_details bai ON bai.parent_id = bcd.parent_id
LEFT JOIN scrap_apply_details bai1 ON bai.parent_id = bai1.id
LEFT JOIN tm_task_agreement tta ON tta.task_id = bai.task_id
WHERE
bai.task_id = #{taskId}
AND bcd.old_task_id = bai.task_id
AND bcd.back_status = '2'
</select>
<select id="getBfList" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
SELECT
tta.agreement_id AS agreementId,
bai.id,
bai.task_id AS taskId,
bcd.type_id AS typeId,
bcd.back_num AS backNum,
bcd.file_url AS fileUrl,
bcd.parent_id AS parentId,
bcd.create_by AS createBy,
bcd.scrap_type AS scrapType,
bcd.ma_id AS maId,
bai.company_id AS companyId
FROM
scrap_check_details bcd
LEFT JOIN scrap_apply_details bai ON bai.parent_id = bcd.parent_id
LEFT JOIN scrap_apply_details bai1 ON bai.parent_id = bai1.id
LEFT JOIN tm_task_agreement tta ON tta.task_id = bai.task_id
WHERE
bai.task_id = #{taskId}
AND bcd.old_task_id = bai.task_id
AND bcd.back_status = '3'
</select>
<select id="selectTaskNumByMonthWx" resultType="java.lang.Integer">
select count(*) from tm_task where DATE_FORMAT(create_time,'%y%m') = DATE_FORMAT(#{date},'%y%m') and task_type = #{taskType}
</select>
<select id="getscrapCheckDetails" resultType="java.lang.Integer">
select count(*) from scrap_check_details where parent_id = #{parentId} and back_status = '3'
</select>
</mapper>