<?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.op.quality.mapper.QcCheckTaskInventoryMapper" >
<resultMap type= "QcCheckTaskInventory" id= "QcCheckTaskInventoryResult" >
<result property= "recordId" column= "record_id" />
<result property= "checkNo" column= "check_no" />
<result property= "incomeBatchNo" column= "income_batch_no" />
<result property= "orderNo" column= "order_no" />
<result property= "materialCode" column= "material_code" />
<result property= "materialName" column= "material_name" />
<result property= "quality" column= "quality" />
<result property= "unit" column= "unit" />
<result property= "supplierCode" column= "supplier_code" />
<result property= "supplierName" column= "supplier_name" />
<result property= "incomeTime" column= "income_time" />
<result property= "checkLoc" column= "check_loc" />
<result property= "checkStatus" column= "check_status" />
<result property= "checkManCode" column= "check_man_code" />
<result property= "checkManName" column= "check_man_name" />
<result property= "checkTime" column= "check_time" />
<result property= "checkResult" column= "check_result" />
<result property= "status" column= "status" />
<result property= "attr1" column= "attr1" />
<result property= "attr2" column= "attr2" />
<result property= "attr3" column= "attr3" />
<result property= "attr4" column= "attr4" />
<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= "factoryCode" column= "factory_code" />
<result property= "delFlag" column= "del_flag" />
<result property= "checkType" column= "check_type" />
<result property= "noOkQuality" column= "noOk_quality" />
<result property= "sampleQuality" column= "sample_quality" />
<result property= "aNoOkquality" column= "aNoOkquality" />
<result property= "bNoOkquality" column= "bNoOkquality" />
<result property= "cNoOkquality" column= "cNoOkquality" />
<result property= "typeCode" column= "type_code" />
<result property= "orderType" column= "order_type" />
<result property= "workorderCodeSap" column= "workorderCodeSap" />
</resultMap>
<sql id= "selectQcCheckTaskInventoryVo" >
select record_id, check_no, income_batch_no, order_no, material_code, material_name, quality, unit, supplier_code,
supplier_name, income_time, check_loc, check_status, check_man_code, check_man_name, check_time, check_result,
status, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time, factory_code, del_flag,
check_type, noOk_quality, sample_quality, aNoOkquality, bNoOkquality, cNoOkquality, type_code, order_type
from qc_check_task
</sql>
<select id= "selectQcCheckTaskInventoryList" parameterType= "QcCheckTaskInventory"
resultMap="QcCheckTaskInventoryResult">
select qct.record_id, qct.check_no, qct.income_batch_no,
case when pow.workorder_code_sap is null then qct.order_no else SUBSTRING(pow.workorder_code_sap,4,10) end order_no,
qct.material_code, qct.material_name, qct.quality, qct.unit,
qct.supplier_code, qct.supplier_name, qct.income_time, qct.check_loc, qct.check_status,
qct.check_man_code, qct.check_man_name,qct.check_time, qct.check_result, qct.status,
qct.create_by,qct.create_time, qct.update_by, qct.update_time,
qct.check_type,qct.sample_quality,qct.noOk_quality,
q.type_code
from qc_check_task qct
left join qc_check_type q on q.id = qct.check_type
left join pro_order_workorder pow on pow.workorder_code = qct.order_no and pow.del_flag = '0'
<where >
<if test= "checkNo != null and checkNo != ''" > and qct.check_no = #{checkNo}</if>
<if test= "incomeBatchNo != null and incomeBatchNo != ''" > and qct.income_batch_no = #{incomeBatchNo}</if>
<if test= "orderNo != null and orderNo != ''" > and (
qct.order_no like concat('%', #{orderNo},'%') or
pow.workorder_code_sap like concat('%',#{orderNo},'%')
)</if>
<if test= "materialCode != null and materialCode != ''" >
and qct.material_code like concat('%',#{materialCode}, '%')
</if>
<if test= "materialName != null and materialName != ''" >
and qct.material_name like concat('%',#{materialName}, '%')
</if>
<if test= "supplierCode != null and supplierCode != ''" > and qct.supplier_code like concat('%',#{supplierCode}, '%')</if>
<if test= "supplierName != null and supplierName != ''" > and qct.supplier_name like concat('%',#{supplierName}, '%')</if>
<if test= "incomeTime != null " > and qct.income_time = #{incomeTime}</if>
<if test= "checkLoc != null and checkLoc != ''" > and qct.check_loc = #{checkLoc}</if>
<if test= "checkStatus != null and checkStatus != ''" > and qct.check_status = #{checkStatus}</if>
<if test= "checkManCode != null and checkManCode != ''" > and qct.check_man_code = #{checkManCode}</if>
<if test= "checkManName != null and checkManName != ''" > and qct.check_man_name like concat('%',
#{checkManName}, '%')
</if>
<if test= "checkResult != null and checkResult != ''" > and qct.check_result = #{checkResult}</if>
<if test= "status != null and status != ''" > and qct.status = #{status}</if>
<if test= "delFlag != null and delFlag != ''" > and qct.del_flag = #{delFlag}</if>
<if test= "factoryCode != null and factoryCode != ''" > and qct.factory_code = #{factoryCode}</if>
<if test= "incomeTimeStart != null " > and CONVERT(varchar(30),qct.income_time, 120) >= #{incomeTimeStart}</if>
<if test= "incomeTimeEnd != null " > and #{incomeTimeEnd} > CONVERT(varchar(30),qct.income_time, 120)</if>
<if test= "checkTimeStart != null " > and CONVERT(varchar(30),qct.create_time, 120) >= #{checkTimeStart}</if>
<if test= "checkTimeEnd != null " > and #{checkTimeEnd} > CONVERT(varchar(30),qct.create_time, 120)</if>
<if test= "checkType != null " > and qct.check_type = #{checkType}</if>
<if test= "typeCode != null " > and q.type_code = #{typeCode}</if>
and qct.del_flag = '0'
</where>
order by qct.create_time desc
</select>
<select id= "selectQcCheckTaskInventoryByRecordId" parameterType= "String" resultMap= "QcCheckTaskInventoryResult" >
<include refid= "selectQcCheckTaskInventoryVo" />
where record_id = #{recordId}
</select>
<insert id= "insertQcCheckTaskInventory" parameterType= "QcCheckTaskInventory" >
insert into qc_check_task
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "recordId != null" > record_id,</if>
<if test= "checkNo != null" > check_no,</if>
<if test= "incomeBatchNo != null" > income_batch_no,</if>
<if test= "orderNo != null" > order_no,</if>
<if test= "materialCode != null" > material_code,</if>
<if test= "materialName != null" > material_name,</if>
<if test= "quality != null" > quality,</if>
<if test= "unit != null" > unit,</if>
<if test= "supplierCode != null" > supplier_code,</if>
<if test= "supplierName != null" > supplier_name,</if>
<if test= "incomeTime != null" > income_time,</if>
<if test= "checkLoc != null" > check_loc,</if>
<if test= "checkStatus != null" > check_status,</if>
<if test= "checkManCode != null" > check_man_code,</if>
<if test= "checkManName != null" > check_man_name,</if>
<if test= "checkTime != null" > check_time,</if>
<if test= "checkResult != null" > check_result,</if>
<if test= "status != null" > status,</if>
<if test= "attr1 != null" > attr1,</if>
<if test= "attr2 != null" > attr2,</if>
<if test= "attr3 != null" > attr3,</if>
<if test= "attr4 != null" > attr4,</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= "factoryCode != null and factoryCode != ''" > factory_code,</if>
<if test= "delFlag != null" > del_flag,</if>
<if test= "checkType != null" > check_type,</if>
<if test= "noOkQuality != null" > noOk_quality,</if>
<if test= "sampleQuality != null" > sample_quality,</if>
<if test= "aNoOkquality != null" > aNoOkquality,</if>
<if test= "bNoOkquality != null" > bNoOkquality,</if>
<if test= "cNoOkquality != null" > cNoOkquality,</if>
<if test= "typeCode != null" > type_code,</if>
<if test= "orderType != null" > order_type,</if>
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "recordId != null" > #{recordId},</if>
<if test= "checkNo != null" > #{checkNo},</if>
<if test= "incomeBatchNo != null" > #{incomeBatchNo},</if>
<if test= "orderNo != null" > #{orderNo},</if>
<if test= "materialCode != null" > #{materialCode},</if>
<if test= "materialName != null" > #{materialName},</if>
<if test= "quality != null" > #{quality},</if>
<if test= "unit != null" > #{unit},</if>
<if test= "supplierCode != null" > #{supplierCode},</if>
<if test= "supplierName != null" > #{supplierName},</if>
<if test= "incomeTime != null" > #{incomeTime},</if>
<if test= "checkLoc != null" > #{checkLoc},</if>
<if test= "checkStatus != null" > #{checkStatus},</if>
<if test= "checkManCode != null" > #{checkManCode},</if>
<if test= "checkManName != null" > #{checkManName},</if>
<if test= "checkTime != null" > #{checkTime},</if>
<if test= "checkResult != null" > #{checkResult},</if>
<if test= "status != null" > #{status},</if>
<if test= "attr1 != null" > #{attr1},</if>
<if test= "attr2 != null" > #{attr2},</if>
<if test= "attr3 != null" > #{attr3},</if>
<if test= "attr4 != null" > #{attr4},</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= "factoryCode != null and factoryCode != ''" > #{factoryCode},</if>
<if test= "delFlag != null" > #{delFlag},</if>
<if test= "checkType != null" > #{checkType},</if>
<if test= "noOkQuality != null" > #{noOkQuality},</if>
<if test= "sampleQuality != null" > #{sampleQuality},</if>
<if test= "aNoOkquality != null" > #{aNoOkquality},</if>
<if test= "bNoOkquality != null" > #{bNoOkquality},</if>
<if test= "cNoOkquality != null" > #{cNoOkquality},</if>
<if test= "typeCode != null" > #{typeCode},</if>
<if test= "orderType != null" > #{orderType},</if>
</trim>
</insert>
<update id= "updateQcCheckTaskInventory" parameterType= "QcCheckTaskInventory" >
update qc_check_task
<trim prefix= "SET" suffixOverrides= "," >
<if test= "checkNo != null" > check_no = #{checkNo},</if>
<if test= "incomeBatchNo != null" > income_batch_no = #{incomeBatchNo},</if>
<if test= "orderNo != null" > order_no = #{orderNo},</if>
<if test= "materialCode != null" > material_code = #{materialCode},</if>
<if test= "materialName != null" > material_name = #{materialName},</if>
<if test= "quality != null" > quality = #{quality},</if>
<if test= "unit != null" > unit = #{unit},</if>
<if test= "supplierCode != null" > supplier_code = #{supplierCode},</if>
<if test= "supplierName != null" > supplier_name = #{supplierName},</if>
<if test= "incomeTime != null" > income_time = #{incomeTime},</if>
<if test= "checkLoc != null" > check_loc = #{checkLoc},</if>
<if test= "checkStatus != null" > check_status = #{checkStatus},</if>
<if test= "checkManCode != null" > check_man_code = #{checkManCode},</if>
<if test= "checkManName != null" > check_man_name = #{checkManName},</if>
<if test= "checkTime != null" > check_time = #{checkTime},</if>
<if test= "checkResult != null" > check_result = #{checkResult},</if>
<if test= "status != null" > status = #{status},</if>
<if test= "attr1 != null" > attr1 = #{attr1},</if>
<if test= "attr2 != null" > attr2 = #{attr2},</if>
<if test= "attr3 != null" > attr3 = #{attr3},</if>
<if test= "attr4 != null" > attr4 = #{attr4},</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= "factoryCode != null and factoryCode != ''" > factory_code = #{factoryCode},</if>
<if test= "delFlag != null" > del_flag = #{delFlag},</if>
<if test= "checkType != null" > check_type = #{checkType},</if>
<if test= "noOkQuality != null" > noOk_quality = #{noOkQuality},</if>
<if test= "sampleQuality != null" > sample_quality = #{sampleQuality},</if>
<if test= "aNoOkquality != null" > aNoOkquality = #{aNoOkquality},</if>
<if test= "bNoOkquality != null" > bNoOkquality = #{bNoOkquality},</if>
<if test= "cNoOkquality != null" > cNoOkquality = #{cNoOkquality},</if>
<if test= "typeCode != null" > type_code = #{typeCode},</if>
<if test= "orderType != null" > order_type = #{orderType},</if>
</trim>
where record_id = #{recordId}
</update>
<update id= "deleteQcCheckTaskInventoryByRecordId" parameterType= "String" >
update qc_check_task
set del_flag = '1'
where record_id = #{recordId}
</update>
<delete id= "deleteQcCheckTaskInventoryByRecordIds" parameterType= "String" >
delete from qc_check_task where record_id in
<foreach item= "recordId" collection= "array" open= "(" separator= "," close= ")" >
#{recordId}
</foreach>
</delete>
<select id= "getTodayMaxNum" resultType= "java.lang.Integer" >
select count(0)+1
from qc_check_task
where CONVERT(varchar(10),create_time, 120) = CONVERT(varchar(10),GETDATE(), 120)
</select>
<select id= "getPutInOrder" resultType= "com.op.quality.domain.QcCheckTaskIncome" >
select * from(
SELECT
wms_raw_order_in_sn.user_defined5 AS orderNo,
wms_raw_order_in_sn.material_code AS materialCode,
wms_raw_order_in_sn.material_desc AS materialName,
COUNT ( wms_raw_order_in_sn.amount ) AS quality,
wms_raw_order_in.gmt_create incomeTime,
wms_raw_order_in_sn.wh_code supplierCode,
base_warehouse.warehouse_name supplierName,
wms_raw_order_in_sn.user_defined4 unit
FROM
wms_raw_order_in_sn
LEFT JOIN base_warehouse ON base_warehouse.warehouse_code= wms_raw_order_in_sn.wh_code
LEFT JOIN wms_raw_order_in ON wms_raw_order_in.dn_no= wms_raw_order_in_sn.user_defined5 and wms_raw_order_in.material_code=wms_raw_order_in_sn.material_code
WHERE
wms_raw_order_in_sn.active_flag = '1' and wms_raw_order_in_sn.user_defined5 is not null
GROUP BY
wms_raw_order_in_sn.wh_code,
wms_raw_order_in_sn.user_defined5,
wms_raw_order_in_sn.material_code,
wms_raw_order_in_sn.material_desc,
wms_raw_order_in_sn.user_defined4,
base_warehouse.warehouse_code,
base_warehouse.warehouse_name,
wms_raw_order_in.gmt_create UNION ALL
SELECT
wms_fp_storage_news_sn.order_no,
wms_fp_storage_news_sn.product_name,
wms_fp_storage_news_sn.product_code,
SUM ( wms_fp_storage_news_sn.amount ) AS total_amount,
wms_fp_storage_news_sn.gmt_create,
wms_fp_storage_news_sn.wh_code ,
base_warehouse.warehouse_name,
wms_fp_storage_news_sn.user_defined3
FROM
wms_fp_storage_news_sn
LEFT JOIN base_warehouse ON base_warehouse.warehouse_code= wms_fp_storage_news_sn.wh_code
WHERE
wms_fp_storage_news_sn.active_flag = '1' and wms_fp_storage_news_sn.order_no is not null
GROUP BY
wms_fp_storage_news_sn.order_no,
wms_fp_storage_news_sn.product_name,
wms_fp_storage_news_sn.product_code,
wms_fp_storage_news_sn.gmt_create,
wms_fp_storage_news_sn.user_defined3,
base_warehouse.warehouse_code,
base_warehouse.warehouse_name,
wms_fp_storage_news_sn.wh_code
) t
where 1=1
<if test= "materialCode != null" > and t.materialCode like concat('%',#{materialCode}, '%')</if>
<if test= "materialName != null" > and t.materialName like concat('%',#{materialName}, '%')</if>
<if test= "supplierCode != null" > and t.supplierCode like concat('%',#{supplierCode}, '%')</if>
<if test= "supplierName != null " > and t.supplierName like concat('%',#{supplierName},'%')</if>
<if test= "incomeTimeStart != null " > and CONVERT(varchar(10),t.incomeTime, 120) >= #{incomeTimeStart}</if>
<if test= "incomeTimeEnd != null " > and #{incomeTimeEnd} > CONVERT(varchar(10),t.incomeTime, 120)</if>
order by t.incomeTime desc,t.materialCode
</select>
<select id= "getPutInOrderList" resultType= "com.op.quality.domain.QcCheckTaskInventory" >
<!--
select t0.orderNo,
t0.materialCode,
t0.materialName,
t0.quality,
t0.incomeTime,
t0.supplierCode,
t0.supplierName,
t0.check_Type
from (
select t.order_no orderNo,
t.material_code materialCode,
t.material_name materialName,
t.quality quality,
t.income_time incomeTime,
t.supplier_code supplierCode,
t.supplier_name supplierName,
t.check_type check_Type,
bp.warehouse_cycle,
case when qct.create_time is not null then DATEDIFF(day, qct.create_time, GETDATE())
else DATEDIFF(day, t.income_time, GETDATE()) end days
from qc_check_task t
left join base_product_attached bp on t.material_code = concat('0000000',bp.product_code)
left join (
select order_no,material_code,max(create_time) create_time
from qc_check_task where check_type='checkTypeCC' and del_flag = '0' GROUP BY order_no,material_code
) qct on qct.order_no = t.order_no
and t.material_code = qct.material_code
where bp.warehouse_cycle is not null and t.check_type in('checkTypeLL','checkTypeCP') and t.del_flag = '0'
)t0
where t0.days >= t0.warehouse_cycle
-->
select t0.orderNo,
t0.materialCode,
t0.materialName,
t0.quality,
t0.incomeTime,
t0.supplierCode,
t0.supplierName,
bp.warehouse_cycle,
DATEDIFF(day, t0.incomeTime, GETDATE()) days
from (
SELECT
wms_raw_order_in_sn.user_defined5 AS orderNo,
wms_raw_order_in_sn.material_code AS materialCode,
wms_raw_order_in_sn.material_desc AS materialName,
COUNT ( wms_raw_order_in_sn.amount ) AS quality,
wms_raw_order_in.gmt_create incomeTime,
wms_raw_order_in_sn.wh_code supplierCode,
base_warehouse.warehouse_name supplierName,
wms_raw_order_in_sn.user_defined4 unit
FROM
wms_raw_order_in_sn
LEFT JOIN base_warehouse ON base_warehouse.warehouse_code= wms_raw_order_in_sn.wh_code
LEFT JOIN wms_raw_order_in ON wms_raw_order_in.dn_no= wms_raw_order_in_sn.user_defined5 and wms_raw_order_in.material_code=wms_raw_order_in_sn.material_code
WHERE
wms_raw_order_in_sn.active_flag = '1' and wms_raw_order_in_sn.user_defined5 is not null and wms_raw_order_in.gmt_create is not null
GROUP BY
wms_raw_order_in_sn.wh_code,
wms_raw_order_in_sn.user_defined5,
wms_raw_order_in_sn.material_code,
wms_raw_order_in_sn.material_desc,
wms_raw_order_in_sn.user_defined4,
base_warehouse.warehouse_code,
base_warehouse.warehouse_name,
wms_raw_order_in.gmt_create UNION ALL
SELECT
wms_fp_storage_news_sn.order_no,
wms_fp_storage_news_sn.product_name,
wms_fp_storage_news_sn.product_code,
SUM ( wms_fp_storage_news_sn.amount ) AS total_amount,
wms_fp_storage_news_sn.gmt_create,
wms_fp_storage_news_sn.wh_code ,
base_warehouse.warehouse_name,
wms_fp_storage_news_sn.user_defined3
FROM
wms_fp_storage_news_sn
LEFT JOIN base_warehouse ON base_warehouse.warehouse_code= wms_fp_storage_news_sn.wh_code
WHERE
wms_fp_storage_news_sn.active_flag = '1' and wms_fp_storage_news_sn.order_no is not null and wms_fp_storage_news_sn.gmt_create is not null
GROUP BY
wms_fp_storage_news_sn.order_no,
wms_fp_storage_news_sn.product_name,
wms_fp_storage_news_sn.product_code,
wms_fp_storage_news_sn.gmt_create,
wms_fp_storage_news_sn.user_defined3,
base_warehouse.warehouse_code,
base_warehouse.warehouse_name,
wms_fp_storage_news_sn.wh_code
)t0
left join base_product_attached bp on t0.materialCode = concat('0000000',bp.product_code)
where DATEDIFF(day, t0.incomeTime, GETDATE()) >= bp.warehouse_cycle
</select>
<insert id= "insertQcCheckOaTask" parameterType= "OACheckTaskDTO" >
insert into qc_check_oa_task
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "recordId != null" > record_id,</if>
<if test= "applyNo != null" > apply_no,</if>
<if test= "applicant != null" > applicant,</if>
<if test= "applyDepartment != null" > apply_department,</if>
<if test= "applyDate != null" > apply_date,</if>
<if test= "storeAddress != null" > store_address,</if>
<if test= "type != null" > type,</if>
<if test= "checkManCode != null" > check_man_code,</if>
<if test= "checkManName != null" > check_man_name,</if>
<if test= "qcManager != null" > qc_manager,</if>
<if test= "zlManager != null" > zl_manager,</if>
<if test= "treatmentMan != null" > treatment_man,</if>
<if test= "taskNum != null" > task_num,</if>
status,
<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= "factoryCode != null" > factory_code,</if>
<if test= "delFlag != null" > del_flag,</if>
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "recordId != null" > #{recordId},</if>
<if test= "applyNo != null" > #{applyNo},</if>
<if test= "applicant != null" > #{applicant},</if>
<if test= "applyDepartment != null" > #{applyDepartment},</if>
<if test= "applyDate != null" > #{applyDate},</if>
<if test= "storeAddress != null" > #{storeAddress},</if>
<if test= "type != null" > #{type},</if>
<if test= "checkManCode != null" > #{checkManCode},</if>
<if test= "checkManName != null" > #{checkManName},</if>
<if test= "qcManager != null" > #{qcManager},</if>
<if test= "zlManager != null" > #{zlManager},</if>
<if test= "treatmentMan != null" > #{treatmentMan},</if>
<if test= "taskNum != null" > #{taskNum},</if>
'0',
<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= "factoryCode != null and factoryCode != ''" > #{factoryCode},</if>
<if test= "delFlag != null" > #{delFlag},</if>
</trim>
</insert>
</mapper>