@ -6,6 +6,7 @@
<resultMap type= "com.op.quality.domain.QcCheckSampleTask" id= "QcCheckSampleDefectResult" >
<result property= "materialName" column= "material_name" />
<result property= "materialCode" column= "product_code" />
<result property= "incomeBatchNo" column= "income_batch_no" />
<result property= "workOrderCodeSap" column= "work_order_code_sap" />
<result property= "sampleTime" column= "sample_time" />
@ -34,25 +35,18 @@
<select id= "selectQcCheckSampleTaskList" parameterType= "com.op.quality.domain.query.QcCheckSampleTaskQuery"
resultMap="QcCheckSampleDefectResult">
SELECT
id,
material_name,
income_batch_no,
sample_time,
sample_num,
sample_address,
first_check_user_code,
first_check_user_name,
first_check_result,
first_check_time,
second_check_user_code,
second_check_user_name,
second_check_result,
second_check_time,
third_check_user_code,
third_check_user_name,
third_check_result,
third_check_time
from qc_check_sample_task task
task.id,
task.material_name,
task.income_batch_no,
task.sample_time,
task.sample_num,
task.sample_address,
task.work_order_code_sap,
task.sample_user_code,
u.nick_name sample_user_name
FROM
qc_check_sample_task task
LEFT JOIN lanju_op_cloud.dbo.sys_user u ON task.sample_user_code = u.user_name
<where >
<if test= "queryDate != null and queryDate != ''" >
and CONVERT(VARCHAR(10), task.create_time ,23) <![CDATA[ = ]]> #{queryDate}
@ -67,7 +61,10 @@
and task.material_name like concat('%', #{materialName}, '%')
</if>
<if test= "workOrderCodeSap != null and workOrderCodeSap != ''" >
and task.work_order_code_sap = #{workOrderCodeSap}
and task.work_order_code_sap like concat('%', #{workOrderCodeSap}, '%')
</if>
<if test= "intervalDate != null and intervalDate != ''" >
and FORMAT ( task.sample_time, 'yyyy-MM' ) = #{intervalDate}
</if>
</where>
order by task.sample_time desc,task.create_time desc
@ -81,11 +78,13 @@
task.income_batch_no incomeBatchNo,
task.sample_time sampleTime,
task.sample_num sampleNum,
task.sample_user _name sampleUserName,
u.nick _name sampleUserName,
o.workorder_name gainSampleAddress
FROM
qc_check_sample_task task
LEFT JOIN pro_order_workorder o ON o.workorder_code_sap = task.work_order_code_sap
LEFT JOIN lanju_op_cloud.dbo.sys_user u ON task.sample_user_code = u.user_name
<where >
<if test= "queryDate != null and queryDate != ''" >
and CONVERT(VARCHAR(10), task.create_time ,23) <![CDATA[ = ]]> #{queryDate}
@ -110,45 +109,64 @@
<select id= "selectQcWaitCheckSampleTaskList" parameterType= "com.op.quality.domain.query.QcCheckSampleTaskQuery"
resultMap="QcCheckSampleDefectResult">
select
id, material_name, income_batch_no, work_order_code_sap, sample_time,
first_check_user_code, first_check_user_name, first_check_result, first_check_time,
second_check_user_code, second_check_user_name, second_check_result, second_check_time,
third_check_user_code, third_check_user_name, third_check_result, third_check_time
from qc_check_sample_task
SELECT
t.id,
t.material_name,
t.income_batch_no,
t.work_order_code_sap,
t.sample_time
FROM (
SELECT
t.id,
t.material_name,
t.income_batch_no,
t.work_order_code_sap ,
FORMAT ( t.sample_time, 'yyyy-MM' ) AS sample_date,
t.sample_time,
COALESCE ( r.check_times, 0 ) check_times
FROM qc_check_sample_task t
LEFT JOIN qc_check_sample_result r ON t.id = r.sample_task_id
) t
<where >
<if test= "firstDate != null and firstDate != ''" >
and CONVERT(VARCHAR(10), sample_time ,23) <![CDATA[ <= ]]> #{firstDate}
and first_check_result is null
t.sample_date is not null
<if test= "searchFlag == 1" >
AND sample_date <![CDATA[ < ]]> CASE WHEN DAY(GETDATE()) <![CDATA[ <= ]]> 14 THEN FORMAT(DATEADD(MONTH, -1, GETDATE()), 'yyyy-MM') ELSE FORMAT(GETDATE(), 'yyyy-MM') END
</if>
<if test= "searchFlag == 2" >
AND sample_date <![CDATA[ < ]]> CASE WHEN DAY(GETDATE()) <![CDATA[ <= ]]> 14 THEN FORMAT(DATEADD(MONTH, -2, GETDATE()), 'yyyy-MM') ELSE FORMAT(DATEADD(MONTH, -1, GETDATE()), 'yyyy-MM') END
</if>
<if test= "searchFlag == 3" >
AND sample_date <![CDATA[ < ]]> CASE WHEN DAY(GETDATE()) <![CDATA[ <= ]]> 14 THEN FORMAT(DATEADD(MONTH, -3, GETDATE()), 'yyyy-MM') ELSE FORMAT(DATEADD(MONTH, -2, GETDATE()), 'yyyy-MM') END
</if>
<if test= "searchFlag == 6" >
AND FORMAT(DATEADD(mm, -6, GETDATE()), 'yyyy-MM') >= t.sample_date
</if>
<if test= "searchFlag == 12" >
AND FORMAT(DATEADD(mm, -12, GETDATE()), 'yyyy-MM') >= t.sample_date
</if>
</where>
UNION
select
id, material_name, income_batch_no, work_order_code_sap, sample_time,
first_check_user_code, first_check_user_name, first_check_result, first_check_time,
second_check_user_code, second_check_user_name, second_check_result, second_check_time,
third_check_user_code, third_check_user_name, third_check_result, third_check_time
from qc_check_sample_task
<where >
<if test= "secondDate != null and secondDate != ''" >
and CONVERT(VARCHAR(10), sample_time ,23) <![CDATA[ <= ]]> #{secondDate}
and second_check_result is null
</if>
</where>
UNION
select
id, material_name, income_batch_no, work_order_code_sap, sample_time,
first_check_user_code, first_check_user_name, first_check_result, first_check_time,
second_check_user_code, second_check_user_name, second_check_result, second_check_time,
third_check_user_code, third_check_user_name, third_check_result, third_check_time
from qc_check_sample_task
<where >
<if test= "thirdDate != null and thirdDate != ''" >
and CONVERT(VARCHAR(10), sample_time ,23) <![CDATA[ <= ]]> #{thirdDate}
and third_check_result is null
<if test= "workOrderCodeSap != null and workOrderCodeSap != ''" >
and t.work_order_code_sap like concat('%', #{workOrderCodeSap}, '%')
</if>
</where>
GROUP BY t.id, t.material_name, t.income_batch_no, t.work_order_code_sap, t.sample_time
<if test= "searchFlag == 1 " >
HAVING SUM(t.check_times) <![CDATA[ < ]]> 1
</if>
<if test= "searchFlag == 2 " >
HAVING SUM(t.check_times) <![CDATA[ < ]]> 3
</if>
<if test= "searchFlag == 3 " >
HAVING SUM(t.check_times) <![CDATA[ < ]]> 6
</if>
<if test= "searchFlag == 6 " >
HAVING SUM(t.check_times) <![CDATA[ < ]]> 12
</if>
<if test= "searchFlag == 12 " >
HAVING SUM(t.check_times) <![CDATA[ < ]]> 24
</if>
ORDER BY t.sample_time desc
</select>
@ -173,6 +191,9 @@
<if test= "firstCheckResult != null and firstCheckResult != ''" >
first_check_result = #{firstCheckResult},
</if>
<if test= "firstCheckReason != null and firstCheckReason != ''" >
first_check_reason = #{firstCheckReason},
</if>
<if test= "firstCheckTime != null and firstCheckTime != ''" >
first_check_time = #{firstCheckTime},
</if>
@ -185,6 +206,9 @@
<if test= "secondCheckResult != null and secondCheckResult != ''" >
second_check_result = #{secondCheckResult},
</if>
<if test= "secondCheckReason != null and secondCheckReason != ''" >
second_check_reason = #{secondCheckReason},
</if>
<if test= "secondCheckTime != null and secondCheckTime != ''" >
second_check_time = #{secondCheckTime},
</if>
@ -197,6 +221,9 @@
<if test= "thirdCheckResult != null and thirdCheckResult != ''" >
third_check_result = #{thirdCheckResult},
</if>
<if test= "thirdCheckReason != null and thirdCheckReason != ''" >
third_check_reason = #{thirdCheckReason},
</if>
<if test= "thirdCheckTime != null and thirdCheckTime != ''" >
third_check_time = #{thirdCheckTime},
</if>
@ -298,5 +325,77 @@
WHERE material_name = #{materialName} AND work_order_code_sap = #{workOrderCodeSap}
</select>
<select id= "selectQcCheckSampleTaskResultByTaskId" parameterType= "String" resultType= "com.op.quality.domain.QcCheckSampleTaskResult" >
SELECT
id,
check_times checkTimes,
qualified,
reason,
remark,
create_by createBy,
create_time createTime,
create_user_name createUserName
FROM qc_check_sample_result
WHERE sample_task_id = #{taskId}
</select>
<select id= "selectQcCheckSampleTaskById" parameterType= "com.op.quality.domain.query.QcCheckSampleTaskQuery"
resultType="com.op.quality.domain.QcCheckSampleTask">
SELECT
task.id,
task.material_name materialName,
STUFF(pow.product_code, 1, 7, '') materialCode,
task.income_batch_no incomeBatchNo
FROM qc_check_sample_task task
LEFT JOIN pro_order_workorder pow ON task.work_order_code_sap = pow.workorder_code_sap
WHERE
id = #{id}
</select>
<select id= "selectQcCheckSampleTaskResultId" parameterType= "com.op.quality.domain.query.QcCheckSampleTaskQuery" resultType= "Long" >
SELECT COUNT(0) + 1 id
FROM qc_check_sample_result
</select>
<insert id= "insertQcCheckSampleTaskResult" parameterType= "com.op.quality.domain.QcCheckSampleTaskResult" >
insert into qc_check_sample_result (
id,sample_task_id,check_times,quantity,qualified,apply_dept,find_place,supplier_issue,
exc_range,workshop,need_audit,qc_manager,qt_manager,reason,request_id,remark,create_by,create_user_name,create_time,is_apply_oa
)
VALUES
(
#{id},#{sampleTaskId},#{checkTimes},#{quantity},#{qualified},#{applyDept},#{findPlace},#{isSupplierIssue},
#{excRange},#{workshop},#{isNeedAudit},#{qcManager},#{qtManager},#{reason},#{requestId},#{remark},#{createBy},#{createUserName},GETDATE(),#{isApplyOa}
)
</insert>
<insert id= "insertQcCheckSampleSignTask" parameterType= "com.op.quality.domain.QcCheckSampleSignTask" >
INSERT INTO qc_check_sample_task (
id,
material_name,
income_batch_no,
work_order_code_sap,
sample_num,
sample_user_code,
sample_user_name,
sample_time,
create_time
)
VALUES
(
#{id},
#{materialName},
#{incomeBatchNo},
#{workOrderCodeSap},
#{sampleNum},
#{sampleUserCode},
#{sampleUserName},
#{sampleTime},
#{createTime}
)
</insert>
</mapper>