You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
327 lines
15 KiB
XML
327 lines
15 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="org.dromara.mes.mapper.ProdMixTraceReportMapper">
|
|
|
|
<sql id="routerMasterDataCte">
|
|
WITH router_master_data AS (
|
|
SELECT
|
|
MAX(CASE WHEN REPLACE(sm.query_param, ' ', '') LIKE '%"router":"act"%' THEN sm.master_data_id END) AS act_master_data_id,
|
|
MAX(CASE WHEN REPLACE(sm.query_param, ' ', '') LIKE '%"router":"term"%' THEN sm.master_data_id END) AS term_master_data_id,
|
|
MAX(CASE WHEN REPLACE(sm.query_param, ' ', '') LIKE '%"router":"jar"%' THEN sm.master_data_id END) AS jar_master_data_id
|
|
FROM sys_master_data sm
|
|
WHERE sm.del_flag = '0'
|
|
AND sm.active_flag = '1'
|
|
)
|
|
</sql>
|
|
|
|
<!-- trace list -->
|
|
<select id="selectTraceList" resultType="org.dromara.mes.domain.vo.MixTraceListVo">
|
|
SELECT
|
|
ri.recipe_id AS recipeId,
|
|
ri.recipe_code AS recipeCode,
|
|
ri.machine_id AS machineId,
|
|
bm.machine_name AS machineName,
|
|
ri.material_id AS materialId,
|
|
bmi.material_name AS materialName,
|
|
ri.edt_code AS edtCode,
|
|
ri.user_edt_code AS userEdtCode,
|
|
ri.recipe_state AS recipeState,
|
|
ri.recipe_type AS recipeType,
|
|
ri.recipe_typecode AS recipeTypecode,
|
|
ri.rub_type AS rubType,
|
|
ri.rub_typecode AS rubTypecode,
|
|
ri.total_weight AS totalWeight,
|
|
ri.fill_coefficient AS fillCoefficient,
|
|
ri.oper_code AS operCode,
|
|
ri.audit_flag AS auditFlag,
|
|
ri.done_time AS doneTime,
|
|
ri.create_time AS createTime,
|
|
(SELECT COUNT(1) FROM prod_recipe_weight w
|
|
WHERE w.recipe_id = ri.recipe_id AND w.del_flag = '0') AS weightCount,
|
|
(SELECT COUNT(1) FROM prod_recipe_mixing m
|
|
WHERE m.recipe_id = ri.recipe_id AND m.del_flag = '0') AS mixingCount
|
|
FROM prod_recipe_info ri
|
|
LEFT JOIN prod_base_machine_info bm ON bm.machine_id = ri.machine_id
|
|
LEFT JOIN base_material_info bmi ON bmi.material_id = ri.material_id
|
|
WHERE ri.del_flag = '0'
|
|
<if test="map.recipeCode != null and map.recipeCode != ''">
|
|
AND ri.recipe_code LIKE CONCAT('%', #{map.recipeCode}, '%')
|
|
</if>
|
|
<if test="map.machineId != null and map.machineId != ''">
|
|
AND ri.machine_id = #{map.machineId}
|
|
</if>
|
|
<if test="map.machineName != null and map.machineName != ''">
|
|
AND bm.machine_name LIKE CONCAT('%', #{map.machineName}, '%')
|
|
</if>
|
|
<if test="map.materialId != null and map.materialId != ''">
|
|
AND ri.material_id = #{map.materialId}
|
|
</if>
|
|
<if test="map.recipeState != null and map.recipeState != ''">
|
|
AND ri.recipe_state = #{map.recipeState}
|
|
</if>
|
|
<if test="map.rubType != null and map.rubType != ''">
|
|
AND ri.rub_type LIKE CONCAT('%', #{map.rubType}, '%')
|
|
</if>
|
|
<if test="map.rubTypecode != null and map.rubTypecode != ''">
|
|
AND ri.rub_typecode LIKE CONCAT('%', #{map.rubTypecode}, '%')
|
|
</if>
|
|
<if test="map.recipeTypecode != null and map.recipeTypecode != ''">
|
|
AND ri.recipe_typecode = #{map.recipeTypecode}
|
|
</if>
|
|
<if test="map.operCode != null and map.operCode != ''">
|
|
AND ri.oper_code LIKE CONCAT('%', #{map.operCode}, '%')
|
|
</if>
|
|
<if test="map.auditFlag != null and map.auditFlag != ''">
|
|
AND ri.audit_flag = #{map.auditFlag}
|
|
</if>
|
|
<if test="map.materialName != null and map.materialName != ''">
|
|
AND bmi.material_name LIKE CONCAT('%', #{map.materialName}, '%')
|
|
</if>
|
|
<if test="map.beginDate != null and map.beginDate != '' and map.endDate != null and map.endDate != ''">
|
|
AND ri.create_time >= CAST(CONCAT(#{map.beginDate}, ' 00:00:00') AS DATETIME)
|
|
AND ri.create_time < DATEADD(DAY, 1, CAST(#{map.endDate} AS DATE))
|
|
</if>
|
|
ORDER BY ri.create_time DESC
|
|
</select>
|
|
|
|
<!-- trace detail recipe info -->
|
|
<select id="selectTraceRecipeInfo" resultType="org.dromara.mes.domain.vo.MixTraceListVo">
|
|
SELECT
|
|
ri.recipe_id AS recipeId,
|
|
ri.recipe_code AS recipeCode,
|
|
ri.machine_id AS machineId,
|
|
bm.machine_name AS machineName,
|
|
ri.material_id AS materialId,
|
|
bmi.material_name AS materialName,
|
|
ri.edt_code AS edtCode,
|
|
ri.user_edt_code AS userEdtCode,
|
|
ri.recipe_state AS recipeState,
|
|
ri.recipe_type AS recipeType,
|
|
ri.recipe_typecode AS recipeTypecode,
|
|
ri.rub_type AS rubType,
|
|
ri.rub_typecode AS rubTypecode,
|
|
ri.total_weight AS totalWeight,
|
|
ri.fill_coefficient AS fillCoefficient,
|
|
ri.oper_code AS operCode,
|
|
ri.audit_flag AS auditFlag,
|
|
ri.done_time AS doneTime,
|
|
ri.create_time AS createTime,
|
|
(SELECT COUNT(1) FROM prod_recipe_weight w
|
|
WHERE w.recipe_id = ri.recipe_id AND w.del_flag = '0') AS weightCount,
|
|
(SELECT COUNT(1) FROM prod_recipe_mixing m
|
|
WHERE m.recipe_id = ri.recipe_id AND m.del_flag = '0') AS mixingCount
|
|
FROM prod_recipe_info ri
|
|
LEFT JOIN prod_base_machine_info bm ON bm.machine_id = ri.machine_id
|
|
LEFT JOIN base_material_info bmi ON bmi.material_id = ri.material_id
|
|
WHERE ri.del_flag = '0'
|
|
AND ri.recipe_id = #{recipeId}
|
|
</select>
|
|
|
|
<!-- trace detail weight list -->
|
|
<select id="selectWeightListByRecipeId" resultType="org.dromara.mes.domain.vo.ProdRecipeWeightVo">
|
|
<include refid="routerMasterDataCte"/>
|
|
SELECT
|
|
w.weight_id AS weightId,
|
|
w.recipe_id AS recipeId,
|
|
w.weight_seq AS weightSeq,
|
|
w.machine_id AS machineId,
|
|
w.edt_code AS edtCode,
|
|
w.weight_type AS weightType,
|
|
w.scale_code AS scaleCode,
|
|
CASE
|
|
WHEN act_detail.data_detail_name IS NULL OR LTRIM(RTRIM(act_detail.data_detail_name)) = '' THEN RTRIM(LTRIM(COALESCE(w.act_code, '')))
|
|
ELSE RTRIM(LTRIM(act_detail.data_detail_name))
|
|
END AS actCode,
|
|
w.set_weight AS setWeight,
|
|
w.error_allow AS errorAllow,
|
|
w.father_code AS fatherCode,
|
|
w.unit_id AS unitId,
|
|
w.child_code AS childCode,
|
|
w.if_use_bat AS ifUseBat,
|
|
w.max_rate AS maxRate
|
|
FROM prod_recipe_weight w
|
|
CROSS JOIN router_master_data rmd
|
|
OUTER APPLY (
|
|
SELECT TOP 1 d.data_detail_name
|
|
FROM sys_master_data_detail d
|
|
WHERE d.del_flag = '0'
|
|
AND d.active_flag = '1'
|
|
AND d.master_data_id = rmd.act_master_data_id
|
|
AND RTRIM(LTRIM(COALESCE(d.data_detail_code, ''))) = RTRIM(LTRIM(COALESCE(w.act_code, '')))
|
|
ORDER BY d.master_data_detail_id DESC
|
|
) act_detail
|
|
WHERE w.del_flag = '0'
|
|
AND w.recipe_id = #{recipeId}
|
|
ORDER BY w.weight_seq ASC
|
|
</select>
|
|
|
|
<!-- trace detail mixing list -->
|
|
<select id="selectMixingListByRecipeId" resultType="org.dromara.mes.domain.vo.ProdRecipeMixingVo">
|
|
<include refid="routerMasterDataCte"/>
|
|
SELECT
|
|
m.mixing_id AS mixingId,
|
|
m.recipe_id AS recipeId,
|
|
m.mix_id AS mixId,
|
|
m.machine_id AS machineId,
|
|
m.edt_code AS edtCode,
|
|
CASE
|
|
WHEN cond_detail.data_detail_name IS NULL OR LTRIM(RTRIM(cond_detail.data_detail_name)) = '' THEN RTRIM(LTRIM(COALESCE(m.cond_code, '')))
|
|
ELSE RTRIM(LTRIM(cond_detail.data_detail_name))
|
|
END AS condCode,
|
|
m.mixing_time AS mixingTime,
|
|
m.mixing_temp AS mixingTemp,
|
|
m.mixing_energy AS mixingEnergy,
|
|
m.mixing_power AS mixingPower,
|
|
m.mixing_press AS mixingPress,
|
|
m.mixing_speed AS mixingSpeed,
|
|
CASE
|
|
WHEN act_detail.data_detail_name IS NULL OR LTRIM(RTRIM(act_detail.data_detail_name)) = '' THEN RTRIM(LTRIM(COALESCE(m.act_code, '')))
|
|
ELSE RTRIM(LTRIM(act_detail.data_detail_name))
|
|
END AS actCode,
|
|
m.father_code AS fatherCode,
|
|
m.child_code AS childCode,
|
|
CASE
|
|
WHEN term_detail.data_detail_name IS NULL OR LTRIM(RTRIM(term_detail.data_detail_name)) = '' THEN RTRIM(LTRIM(COALESCE(m.term_code, '')))
|
|
ELSE RTRIM(LTRIM(term_detail.data_detail_name))
|
|
END AS termCode,
|
|
m.set_time AS setTime,
|
|
m.set_temp AS setTemp,
|
|
m.set_energy AS setEnergy,
|
|
m.set_power AS setPower,
|
|
m.set_pres AS setPres,
|
|
m.set_rota AS setRota
|
|
FROM prod_recipe_mixing m
|
|
CROSS JOIN router_master_data rmd
|
|
OUTER APPLY (
|
|
SELECT TOP 1 d.data_detail_name
|
|
FROM sys_master_data_detail d
|
|
WHERE d.del_flag = '0'
|
|
AND d.active_flag = '1'
|
|
AND d.master_data_id = rmd.term_master_data_id
|
|
AND RTRIM(LTRIM(COALESCE(d.data_detail_code, ''))) = RTRIM(LTRIM(COALESCE(m.cond_code, '')))
|
|
ORDER BY d.master_data_detail_id DESC
|
|
) cond_detail
|
|
OUTER APPLY (
|
|
SELECT TOP 1 d.data_detail_name
|
|
FROM sys_master_data_detail d
|
|
WHERE d.del_flag = '0'
|
|
AND d.active_flag = '1'
|
|
AND d.master_data_id = rmd.act_master_data_id
|
|
AND RTRIM(LTRIM(COALESCE(d.data_detail_code, ''))) = RTRIM(LTRIM(COALESCE(m.act_code, '')))
|
|
ORDER BY d.master_data_detail_id DESC
|
|
) act_detail
|
|
OUTER APPLY (
|
|
SELECT TOP 1 d.data_detail_name
|
|
FROM sys_master_data_detail d
|
|
WHERE d.del_flag = '0'
|
|
AND d.active_flag = '1'
|
|
AND d.master_data_id = rmd.term_master_data_id
|
|
AND RTRIM(LTRIM(COALESCE(d.data_detail_code, ''))) = RTRIM(LTRIM(COALESCE(m.term_code, '')))
|
|
ORDER BY d.master_data_detail_id DESC
|
|
) term_detail
|
|
WHERE m.del_flag = '0'
|
|
AND m.recipe_id = #{recipeId}
|
|
ORDER BY m.mix_id ASC
|
|
</select>
|
|
|
|
<!-- spc samples -->
|
|
<select id="selectSpcSamples" resultType="org.dromara.mes.domain.vo.MixTraceSpcSampleVo">
|
|
<include refid="routerMasterDataCte"/>
|
|
SELECT
|
|
ri.recipe_id AS recipeId,
|
|
ri.recipe_code AS recipeCode,
|
|
ri.machine_id AS machineId,
|
|
bm.machine_name AS machineName,
|
|
rm.mix_id AS mixId,
|
|
CASE
|
|
WHEN term_detail.data_detail_name IS NULL OR LTRIM(RTRIM(term_detail.data_detail_name)) = '' THEN RTRIM(LTRIM(COALESCE(rm.term_code, '')))
|
|
ELSE RTRIM(LTRIM(term_detail.data_detail_name))
|
|
END AS termCode,
|
|
CASE
|
|
WHEN act_detail.data_detail_name IS NULL OR LTRIM(RTRIM(act_detail.data_detail_name)) = '' THEN RTRIM(LTRIM(COALESCE(rm.act_code, '')))
|
|
ELSE RTRIM(LTRIM(act_detail.data_detail_name))
|
|
END AS actCode,
|
|
CASE
|
|
WHEN cond_detail.data_detail_name IS NULL OR LTRIM(RTRIM(cond_detail.data_detail_name)) = '' THEN RTRIM(LTRIM(COALESCE(rm.cond_code, '')))
|
|
ELSE RTRIM(LTRIM(cond_detail.data_detail_name))
|
|
END AS condCode,
|
|
rm.mixing_time AS mixingTime,
|
|
rm.mixing_temp AS mixingTemp,
|
|
rm.mixing_energy AS mixingEnergy,
|
|
rm.mixing_power AS mixingPower,
|
|
rm.mixing_press AS mixingPress,
|
|
rm.mixing_speed AS mixingSpeed,
|
|
rm.set_time AS setTime,
|
|
rm.set_temp AS setTemp,
|
|
rm.set_energy AS setEnergy,
|
|
rm.set_power AS setPower,
|
|
rm.set_pres AS setPres,
|
|
rm.set_rota AS setRota,
|
|
ri.create_time AS createTime
|
|
FROM prod_recipe_mixing rm
|
|
INNER JOIN prod_recipe_info ri ON ri.recipe_id = rm.recipe_id AND ri.del_flag = '0'
|
|
LEFT JOIN prod_base_machine_info bm ON bm.machine_id = ri.machine_id
|
|
CROSS JOIN router_master_data rmd
|
|
OUTER APPLY (
|
|
SELECT TOP 1 d.data_detail_name
|
|
FROM sys_master_data_detail d
|
|
WHERE d.del_flag = '0'
|
|
AND d.active_flag = '1'
|
|
AND d.master_data_id = rmd.act_master_data_id
|
|
AND RTRIM(LTRIM(COALESCE(d.data_detail_code, ''))) = RTRIM(LTRIM(COALESCE(rm.act_code, '')))
|
|
ORDER BY d.master_data_detail_id DESC
|
|
) act_detail
|
|
OUTER APPLY (
|
|
SELECT TOP 1 d.data_detail_name
|
|
FROM sys_master_data_detail d
|
|
WHERE d.del_flag = '0'
|
|
AND d.active_flag = '1'
|
|
AND d.master_data_id = rmd.term_master_data_id
|
|
AND RTRIM(LTRIM(COALESCE(d.data_detail_code, ''))) = RTRIM(LTRIM(COALESCE(rm.cond_code, '')))
|
|
ORDER BY d.master_data_detail_id DESC
|
|
) cond_detail
|
|
OUTER APPLY (
|
|
SELECT TOP 1 d.data_detail_name
|
|
FROM sys_master_data_detail d
|
|
WHERE d.del_flag = '0'
|
|
AND d.active_flag = '1'
|
|
AND d.master_data_id = rmd.term_master_data_id
|
|
AND RTRIM(LTRIM(COALESCE(d.data_detail_code, ''))) = RTRIM(LTRIM(COALESCE(rm.term_code, '')))
|
|
ORDER BY d.master_data_detail_id DESC
|
|
) term_detail
|
|
WHERE rm.del_flag = '0'
|
|
<if test="map.machineId != null and map.machineId != ''">
|
|
AND ri.machine_id = #{map.machineId}
|
|
</if>
|
|
<if test="map.machineName != null and map.machineName != ''">
|
|
AND bm.machine_name LIKE CONCAT('%', #{map.machineName}, '%')
|
|
</if>
|
|
<if test="map.materialId != null and map.materialId != ''">
|
|
AND ri.material_id = #{map.materialId}
|
|
</if>
|
|
<if test="map.recipeCode != null and map.recipeCode != ''">
|
|
AND ri.recipe_code LIKE CONCAT('%', #{map.recipeCode}, '%')
|
|
</if>
|
|
<if test="map.rubTypecode != null and map.rubTypecode != ''">
|
|
AND ri.rub_typecode LIKE CONCAT('%', #{map.rubTypecode}, '%')
|
|
</if>
|
|
<if test="map.rubType != null and map.rubType != ''">
|
|
AND ri.rub_type LIKE CONCAT('%', #{map.rubType}, '%')
|
|
</if>
|
|
<if test="map.mixId != null and map.mixId != ''">
|
|
AND rm.mix_id = #{map.mixId}
|
|
</if>
|
|
<if test="map.termCode != null and map.termCode != ''">
|
|
AND rm.term_code = #{map.termCode}
|
|
</if>
|
|
<if test="map.beginDate != null and map.beginDate != '' and map.endDate != null and map.endDate != ''">
|
|
AND ri.create_time >= CAST(CONCAT(#{map.beginDate}, ' 00:00:00') AS DATETIME)
|
|
AND ri.create_time < DATEADD(DAY, 1, CAST(#{map.endDate} AS DATE))
|
|
</if>
|
|
ORDER BY ri.create_time ASC, rm.mix_id ASC
|
|
</select>
|
|
|
|
</mapper>
|