|
|
@@ -1,157 +1,103 @@
|
|
|
<?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.jeesite.modules.mes.dao.MesProcessCntDao">
|
|
|
+ <sql id="processNo">CONCAT('OP', LPAD(CAST(SUBSTRING(TRIM(${station}), 3, GREATEST(0, CHAR_LENGTH(TRIM(${station})) - 2 - IF(RIGHT(TRIM(${station}), 1) REGEXP '[0-9]', 0, 1))) AS UNSIGNED), 3, '0'))</sql>
|
|
|
|
|
|
- <!--
|
|
|
- 工序件数统计(口径说明)
|
|
|
- 1) mes_product_record 里每个产品建档时会预生成整条工艺路线的空记录(content='UDF',update_date=create_date),
|
|
|
- 所以 COUNT(*) 恒等于建档件数(本月 2850),不是产量。件数一律按"有判定结果"的去重产品数统计:
|
|
|
- 件数 = content IN ('OK','NG') 的去重 sn;未判定 = 仍为 UDF 的去重 sn(数据缺口)。
|
|
|
- 2) 真实过站时间取 update_date(判定写回时间),create_date 只是建档时间(同一产品 49 行完全相同)。
|
|
|
- 3) 工序名称必须限定在产品所属产线:CZ060 / CZ061 存在同名工序号但名称不同的情况(如 OP100),
|
|
|
- 不限定产线会取到另一条线的名称。本线无维护时才回退到其它线的名称。
|
|
|
- -->
|
|
|
- <sql id="statFrom">
|
|
|
- FROM mes_product_record r
|
|
|
- LEFT JOIN (
|
|
|
- SELECT ml.sn AS line_sn, LEFT(lp.oprno, 5) AS oprno, MAX(lp.title) AS title
|
|
|
- FROM mes_line_process lp
|
|
|
- INNER JOIN mes_line ml ON ml.id = lp.line_id
|
|
|
- GROUP BY ml.sn, LEFT(lp.oprno, 5)
|
|
|
- ) p ON p.oprno = LEFT(r.oprno, 5) AND p.line_sn = r.line_sn
|
|
|
- LEFT JOIN (
|
|
|
- SELECT LEFT(oprno, 5) AS oprno, MAX(title) AS title
|
|
|
- FROM mes_line_process GROUP BY LEFT(oprno, 5)
|
|
|
- ) pf ON pf.oprno = LEFT(r.oprno, 5)
|
|
|
- </sql>
|
|
|
+ <select id="findRepairLine" resultType="string">
|
|
|
+ SELECT COALESCE(IF(COUNT(DISTINCT line_sn) = 1, MAX(line_sn), NULL),
|
|
|
+ IF(COUNT(DISTINCT CASE WHEN <include refid="processNo"><property name="station" value="oprno"/></include>
|
|
|
+ = #{process} THEN line_sn END) = 1,
|
|
|
+ MAX(CASE WHEN <include refid="processNo"><property name="station" value="oprno"/></include>
|
|
|
+ = #{process} THEN line_sn END), NULL))
|
|
|
+ FROM mes_product_record WHERE sn = #{sn} AND craft = '100000' AND NULLIF(line_sn,'') IS NOT NULL
|
|
|
+ </select>
|
|
|
|
|
|
- <sql id="statWhere">
|
|
|
- <where>
|
|
|
- r.craft = '100000'
|
|
|
- <if test="q.oprno != null and q.oprno != ''">
|
|
|
- AND r.oprno LIKE CONCAT(#{q.oprno}, '%')
|
|
|
- </if>
|
|
|
- <if test="q.processTitle != null and q.processTitle != ''">
|
|
|
- AND COALESCE(p.title, pf.title) LIKE CONCAT('%', #{q.processTitle}, '%')
|
|
|
- </if>
|
|
|
- <if test="q.lineSn != null and q.lineSn != ''">
|
|
|
- AND r.line_sn = #{q.lineSn}
|
|
|
- </if>
|
|
|
- <if test="q.startDate != null and q.startDate != ''">
|
|
|
- AND r.create_date >= CONCAT(#{q.startDate}, ' 00:00:00')
|
|
|
- </if>
|
|
|
- <if test="q.endDate != null and q.endDate != ''">
|
|
|
- AND r.create_date <= CONCAT(#{q.endDate}, ' 23:59:59')
|
|
|
- </if>
|
|
|
- </where>
|
|
|
- </sql>
|
|
|
+ <insert id="confirmRepairs">
|
|
|
+ INSERT INTO mes_process_piecework (line_sn, sn, process_no, repair_key, oprno, cate_sn, result, completed_at)
|
|
|
+ SELECT #{r.lineSn}, r.sn, #{process}, r.id, #{r.oprno}, #{r.cateSn}, 'OK', #{at}
|
|
|
+ FROM mes_product_repair r
|
|
|
+ JOIN mes_product_repair_quality q ON q.repair_id = r.id
|
|
|
+ WHERE r.sn = #{r.sn} AND r.line_sn = #{r.lineSn} AND r.state = '2' AND r.result = '1'
|
|
|
+ AND q.result = '1' AND q.back_oprno = r.back_oprno AND UPPER(q.back_oprno) REGEXP '^OP[0-9]{2,3}[A-Z]?$'
|
|
|
+ AND <include refid="processNo"><property name="station" value="q.back_oprno"/></include> = #{process}
|
|
|
+ GROUP BY r.id, r.sn HAVING MAX(q.update_date) < #{at}
|
|
|
+ ON DUPLICATE KEY UPDATE completed_at = mes_process_piecework.completed_at
|
|
|
+ </insert>
|
|
|
|
|
|
- <!-- 明细:按工序号前缀取该工序下所有工位的记录,名称取"本产线"的工位配置(避免取到另一条线同名工位) -->
|
|
|
- <sql id="detailFrom">
|
|
|
- FROM mes_product_record r
|
|
|
- LEFT JOIN (
|
|
|
- SELECT ml.sn AS line_sn, lp.oprno AS oprno, MAX(lp.title) AS title
|
|
|
- FROM mes_line_process lp
|
|
|
- INNER JOIN mes_line ml ON ml.id = lp.line_id
|
|
|
- GROUP BY ml.sn, lp.oprno
|
|
|
- ) p ON p.oprno = r.oprno AND p.line_sn = r.line_sn
|
|
|
- LEFT JOIN (
|
|
|
- SELECT oprno, MAX(title) AS title FROM mes_line_process GROUP BY oprno
|
|
|
- ) pf ON pf.oprno = r.oprno
|
|
|
- </sql>
|
|
|
+ <insert id="insertFirstCompletion">
|
|
|
+ INSERT INTO mes_process_piecework (line_sn, sn, process_no, repair_key, oprno, cate_sn, result, completed_at)
|
|
|
+ SELECT #{r.lineSn}, #{r.sn}, #{process}, '', #{r.oprno}, #{r.cateSn}, #{r.content}, #{at}
|
|
|
+ FROM DUAL WHERE NOT EXISTS (
|
|
|
+ SELECT 1 FROM mes_process_piecework p WHERE p.line_sn = #{r.lineSn} AND p.sn = #{r.sn}
|
|
|
+ AND p.process_no = #{process} AND p.repair_key <> ''
|
|
|
+ )
|
|
|
+ ON DUPLICATE KEY UPDATE completed_at = mes_process_piecework.completed_at
|
|
|
+ </insert>
|
|
|
+
|
|
|
+ <update id="setFirstCompletionDate">
|
|
|
+ UPDATE mes_product_record r JOIN mes_process_piecework p
|
|
|
+ ON p.line_sn = r.line_sn AND p.sn = r.sn AND p.process_no = #{process} AND p.repair_key = ''
|
|
|
+ SET r.first_completed_at = p.completed_at
|
|
|
+ WHERE r.sn = #{r.sn} AND r.line_sn = #{r.lineSn} AND r.craft = '100000'
|
|
|
+ AND r.first_completed_at IS NULL AND UPPER(r.oprno) REGEXP '^OP[0-9]{2,3}[A-Z]?$'
|
|
|
+ AND <include refid="processNo"><property name="station" value="r.oprno"/></include> = #{process}
|
|
|
+ </update>
|
|
|
|
|
|
- <sql id="detailWhere">
|
|
|
+ <sql id="workWhere">
|
|
|
+ WHERE w.line_sn = #{q.lineSn}
|
|
|
+ <if test="q.startDate != null and q.startDate != ''">AND w.completed_at >= #{q.startDate}</if>
|
|
|
+ <if test="q.endDate != null and q.endDate != ''">AND w.completed_at < DATE_ADD(#{q.endDate}, INTERVAL 1 DAY)</if>
|
|
|
+ <if test="q.oprno != null and q.oprno != ''">AND w.process_no LIKE CONCAT(#{q.oprno}, '%')</if>
|
|
|
+ </sql>
|
|
|
+ <sql id="stationNames">
|
|
|
+ SELECT <include refid="processNo"><property name="station" value="lp.oprno"/></include> AS process_no,
|
|
|
+ MAX(lp.title) AS title
|
|
|
+ FROM mes_line_process lp JOIN mes_line l ON l.id = lp.line_id AND l.sn = #{q.lineSn}
|
|
|
+ WHERE UPPER(lp.oprno) REGEXP '^OP[0-9]{2,3}[A-Z]?$'
|
|
|
+ GROUP BY process_no
|
|
|
+ </sql>
|
|
|
+ <sql id="stationFilter">
|
|
|
<where>
|
|
|
- r.craft = '100000'
|
|
|
- <if test="q.oprno != null and q.oprno != ''">
|
|
|
- AND r.oprno LIKE CONCAT(#{q.oprno}, '%')
|
|
|
- </if>
|
|
|
- <if test="q.sn != null and q.sn != ''">
|
|
|
- AND r.sn LIKE CONCAT('%', #{q.sn}, '%')
|
|
|
- </if>
|
|
|
- <if test="q.content != null and q.content != ''">
|
|
|
- AND r.content = #{q.content}
|
|
|
- </if>
|
|
|
- <!-- 未指定结果时默认只看有判定的记录,保证与列表"件数"一致;要看未判定请在下拉里选 UDF -->
|
|
|
- <if test="q.content == null or q.content == ''">
|
|
|
- AND r.content IN ('OK','NG')
|
|
|
- </if>
|
|
|
- <if test="q.lineSn != null and q.lineSn != ''">
|
|
|
- AND r.line_sn = #{q.lineSn}
|
|
|
- </if>
|
|
|
- <if test="q.startDate != null and q.startDate != ''">
|
|
|
- AND r.create_date >= CONCAT(#{q.startDate}, ' 00:00:00')
|
|
|
- </if>
|
|
|
- <if test="q.endDate != null and q.endDate != ''">
|
|
|
- AND r.create_date <= CONCAT(#{q.endDate}, ' 23:59:59')
|
|
|
- </if>
|
|
|
+ <if test="q.oprno != null and q.oprno != ''">AND p.process_no LIKE CONCAT(#{q.oprno}, '%')</if>
|
|
|
+ <if test="q.processTitle != null and q.processTitle != ''">AND p.title LIKE CONCAT('%',#{q.processTitle},'%')</if>
|
|
|
</where>
|
|
|
</sql>
|
|
|
-
|
|
|
- <!-- 汇总列(件数=有判定的去重件数,时间=判定写回时间) -->
|
|
|
- <sql id="statCols">
|
|
|
- LEFT(r.oprno, 5) AS oprno,
|
|
|
- MAX(COALESCE(p.title, pf.title)) AS processTitle,
|
|
|
- MAX(r.line_sn) AS lineSn,
|
|
|
- COUNT(DISTINCT CASE WHEN r.content IN ('OK','NG') THEN r.sn END) AS cnt,
|
|
|
- COUNT(DISTINCT CASE WHEN r.content = 'OK' THEN r.sn END) AS okCount,
|
|
|
- COUNT(DISTINCT CASE WHEN r.content = 'NG' THEN r.sn END) AS ngCount,
|
|
|
- COUNT(DISTINCT CASE WHEN r.content IS NULL OR r.content NOT IN ('OK','NG') THEN r.sn END) AS otherCount,
|
|
|
- MIN(CASE WHEN r.content IN ('OK','NG') THEN r.update_date END) AS firstTime,
|
|
|
- MAX(CASE WHEN r.content IN ('OK','NG') THEN r.update_date END) AS lastTime
|
|
|
+ <sql id="summary">
|
|
|
+ SELECT p.process_no AS oprno, p.title AS processTitle, #{q.lineSn} AS lineSn,
|
|
|
+ COALESCE(a.cnt,0) AS cnt, COALESCE(a.firstCount,0) AS firstCount,
|
|
|
+ COALESCE(a.repairCount,0) AS repairCount, COALESCE(a.okCount,0) AS okCount,
|
|
|
+ COALESCE(a.ngCount,0) AS ngCount
|
|
|
+ FROM (<include refid="stationNames"/>) p
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT w.process_no, COUNT(*) AS cnt, SUM(w.repair_key = '') AS firstCount,
|
|
|
+ SUM(w.repair_key <> '') AS repairCount, SUM(w.result = 'OK') AS okCount,
|
|
|
+ SUM(w.result = 'NG') AS ngCount
|
|
|
+ FROM mes_process_piecework w <include refid="workWhere"/> GROUP BY w.process_no
|
|
|
+ ) a ON a.process_no = p.process_no
|
|
|
+ <include refid="stationFilter"/> ORDER BY p.process_no
|
|
|
</sql>
|
|
|
-
|
|
|
- <!-- 按工序汇总件数 -->
|
|
|
<select id="findStatList" resultType="com.jeesite.modules.mes.entity.MesProcessCnt">
|
|
|
- SELECT
|
|
|
- <include refid="statCols"/>
|
|
|
- <include refid="statFrom"/>
|
|
|
- <include refid="statWhere"/>
|
|
|
- GROUP BY LEFT(r.oprno, 5), r.line_sn
|
|
|
- ORDER BY LEFT(r.oprno, 5) ASC, r.line_sn ASC
|
|
|
- LIMIT #{offset}, #{limit}
|
|
|
+ <include refid="summary"/> LIMIT #{offset}, #{limit}
|
|
|
</select>
|
|
|
-
|
|
|
<select id="findStatListAll" resultType="com.jeesite.modules.mes.entity.MesProcessCnt">
|
|
|
- SELECT
|
|
|
- <include refid="statCols"/>
|
|
|
- <include refid="statFrom"/>
|
|
|
- <include refid="statWhere"/>
|
|
|
- GROUP BY LEFT(r.oprno, 5), r.line_sn
|
|
|
- ORDER BY LEFT(r.oprno, 5) ASC, r.line_sn ASC
|
|
|
+ <include refid="summary"/>
|
|
|
</select>
|
|
|
-
|
|
|
<select id="findStatCount" resultType="long">
|
|
|
- SELECT COUNT(*) FROM (
|
|
|
- SELECT LEFT(r.oprno, 5) AS oprno, r.line_sn
|
|
|
- <include refid="statFrom"/>
|
|
|
- <include refid="statWhere"/>
|
|
|
- GROUP BY LEFT(r.oprno, 5), r.line_sn
|
|
|
- ) t
|
|
|
+ SELECT COUNT(*) FROM (<include refid="stationNames"/>) p <include refid="stationFilter"/>
|
|
|
</select>
|
|
|
-
|
|
|
- <!-- 指定工序的件数明细(每行一个实际工位) -->
|
|
|
+ <sql id="detailFilter">
|
|
|
+ <include refid="workWhere"/>
|
|
|
+ <if test="q.sn != null and q.sn != ''">AND w.sn LIKE CONCAT('%',#{q.sn},'%')</if>
|
|
|
+ <if test="q.content != null and q.content != ''">AND w.result = #{q.content}</if>
|
|
|
+ </sql>
|
|
|
<select id="findDetailList" resultType="com.jeesite.modules.mes.entity.MesProcessCnt">
|
|
|
- SELECT
|
|
|
- r.sn AS sn,
|
|
|
- r.oprno AS oprno,
|
|
|
- COALESCE(p.title, pf.title) AS processTitle,
|
|
|
- r.cate_sn AS cateSn,
|
|
|
- r.line_sn AS lineSn,
|
|
|
- r.content AS content,
|
|
|
- r.craft AS craft,
|
|
|
- r.remark AS remark,
|
|
|
- COALESCE(r.update_date, r.create_date) AS workTime
|
|
|
- <include refid="detailFrom"/>
|
|
|
- <include refid="detailWhere"/>
|
|
|
- ORDER BY COALESCE(r.update_date, r.create_date) DESC, r.sn ASC
|
|
|
- LIMIT #{offset}, #{limit}
|
|
|
+ SELECT w.sn, w.oprno, p.title AS processTitle, w.cate_sn AS cateSn, w.line_sn AS lineSn,
|
|
|
+ w.result AS content, w.completed_at AS workTime, NULLIF(w.repair_key,'') AS repairId
|
|
|
+ FROM mes_process_piecework w LEFT JOIN (<include refid="stationNames"/>) p ON p.process_no = w.process_no
|
|
|
+ <include refid="detailFilter"/>
|
|
|
+ ORDER BY w.completed_at DESC, w.sn, w.process_no, w.repair_key LIMIT #{offset}, #{limit}
|
|
|
</select>
|
|
|
-
|
|
|
<select id="findDetailCount" resultType="long">
|
|
|
- SELECT COUNT(*)
|
|
|
- <include refid="detailFrom"/>
|
|
|
- <include refid="detailWhere"/>
|
|
|
+ SELECT COUNT(*) FROM mes_process_piecework w <include refid="detailFilter"/>
|
|
|
</select>
|
|
|
-
|
|
|
</mapper>
|