|
|
@@ -0,0 +1,210 @@
|
|
|
+<?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="cn.iocoder.yudao.module.makeplan.dal.mysql.WorkOrderScheduleMapper">
|
|
|
+
|
|
|
+ <!-- 工单排产列表查询 -->
|
|
|
+ <select id="selectSchedulePage"
|
|
|
+ parameterType="cn.iocoder.yudao.module.makeplan.controller.admin.workorder.vo.WorkOrderSchedulePageReqVO"
|
|
|
+ resultType="cn.iocoder.yudao.module.makeplan.controller.admin.workorder.vo.WorkOrderScheduleRespVO">
|
|
|
+ SELECT
|
|
|
+ a.RecID AS id,
|
|
|
+ exm.checktime,
|
|
|
+ a.Batch AS batch,
|
|
|
+ a.Drawing AS drawing,
|
|
|
+ a.Typed AS typed,
|
|
|
+ a.WorkOrd AS workOrd,
|
|
|
+ a.OrdDate AS ordDate,
|
|
|
+ a.DueDate AS dueDate,
|
|
|
+ a.ItemNum AS itemNum,
|
|
|
+ a.Project AS project,
|
|
|
+ a.QtyOrded AS qtyOrded,
|
|
|
+ a.QtyCompleted AS qtyCompleted,
|
|
|
+ a.Remark AS remark,
|
|
|
+ LOWER(a.Status) AS status,
|
|
|
+ a.WoTyped AS woTyped,
|
|
|
+ b.Descr AS descr,
|
|
|
+ b.Descr1 AS descr1,
|
|
|
+ a.lbrvar,
|
|
|
+ r.Area AS area,
|
|
|
+ se.custom_no AS customNo,
|
|
|
+ cm.Terms AS terms,
|
|
|
+ a.IsInitial AS isInitial,
|
|
|
+ CASE
|
|
|
+ WHEN cm.Terms = '' OR cm.Terms IS NULL THEN
|
|
|
+ CASE r.Area
|
|
|
+ WHEN '中国' THEN DATE_ADD(a.DueDate, INTERVAL 15 DAY)
|
|
|
+ WHEN '海外' THEN DATE_ADD(a.DueDate, INTERVAL 8 DAY)
|
|
|
+ ELSE NULL
|
|
|
+ END
|
|
|
+ ELSE
|
|
|
+ CASE
|
|
|
+ WHEN cm.Terms = '海外' THEN DATE_ADD(a.DueDate, INTERVAL 8 DAY)
|
|
|
+ ELSE DATE_ADD(a.DueDate, INTERVAL 15 DAY)
|
|
|
+ END
|
|
|
+ END AS mjtime,
|
|
|
+ a.LotSerial AS lotSerial,
|
|
|
+ CASE WHEN a.CreateGLforLaborVar = 1 THEN '是' ELSE '否' END AS createGLforLaborVar,
|
|
|
+ a.QtyOrded - a.QtyCompleted AS zz,
|
|
|
+ s.PlanDate AS planDate,
|
|
|
+ s.ProdDate AS prodDate,
|
|
|
+ CASE
|
|
|
+ WHEN s.PlanDate IS NULL THEN ''
|
|
|
+ WHEN s.PlanDate IS NOT NULL AND s.ProdDate IS NULL THEN
|
|
|
+ CASE
|
|
|
+ WHEN DATEDIFF(CURDATE(), s.PlanDate) <= 2 AND DATEDIFF(CURDATE(), s.PlanDate) > 0 THEN '低'
|
|
|
+ WHEN DATEDIFF(CURDATE(), s.PlanDate) <= 5 AND DATEDIFF(CURDATE(), s.PlanDate) > 2 THEN '中'
|
|
|
+ WHEN DATEDIFF(CURDATE(), s.PlanDate) > 5 THEN '高'
|
|
|
+ END
|
|
|
+ WHEN s.PlanDate IS NOT NULL AND s.ProdDate IS NOT NULL THEN
|
|
|
+ CASE
|
|
|
+ WHEN DATEDIFF(s.ProdDate, s.PlanDate) <= 2 AND DATEDIFF(s.ProdDate, s.PlanDate) > 0 THEN '低'
|
|
|
+ WHEN DATEDIFF(s.ProdDate, s.PlanDate) <= 5 AND DATEDIFF(s.ProdDate, s.PlanDate) > 2 THEN '中'
|
|
|
+ WHEN DATEDIFF(s.ProdDate, s.PlanDate) > 5 THEN '高'
|
|
|
+ END
|
|
|
+ END AS level,
|
|
|
+ a.IssueSite AS issueSite,
|
|
|
+ IFNULL(ins.WorkOrd, '') AS insWorkOrd,
|
|
|
+ CASE
|
|
|
+ WHEN a.DispatchWeek = '' OR a.DispatchWeek IS NULL THEN
|
|
|
+ CASE
|
|
|
+ WHEN a.LotSerial != '' AND a.LotSerial IS NOT NULL THEN
|
|
|
+ CONCAT('WK', WEEK(STR_TO_DATE(SUBSTRING(a.LotSerial, 1, 6), '%y%m%d')))
|
|
|
+ ELSE ''
|
|
|
+ END
|
|
|
+ ELSE a.DispatchWeek
|
|
|
+ END AS checkweek,
|
|
|
+ a.Priority AS priority,
|
|
|
+ IFNULL(a.LocationStock, 0) + IFNULL(a.OpQtyCompleted, 0) AS locationStock
|
|
|
+ FROM WorkOrdMaster a
|
|
|
+ LEFT JOIN ItemMaster b ON a.ItemNum = b.ItemNum AND b.Domain = a.Domain
|
|
|
+ LEFT JOIN ReplenishmentWeekPlan r ON a.WorkOrd = r.ProductionOrder AND a.Domain = r.factory_id
|
|
|
+ LEFT JOIN crm_seorder se ON se.bill_no = a.SalesJob
|
|
|
+ LEFT JOIN CustMaster cm ON cm.Cust = se.custom_no
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT Domain, WorkOrds, MIN(PlanDate) AS PlanDate, MIN(ProdDate) AS ProdDate
|
|
|
+ FROM PeriodSequenceDet
|
|
|
+ GROUP BY Domain, WorkOrds
|
|
|
+ ) s ON a.Domain = s.Domain AND a.WorkOrd = s.WorkOrds
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT morder_no, create_time AS checktime
|
|
|
+ FROM (
|
|
|
+ SELECT morder_no, create_time,
|
|
|
+ ROW_NUMBER() OVER (PARTITION BY morder_no ORDER BY create_time DESC) AS rn
|
|
|
+ FROM b_examine_result
|
|
|
+ ) ranked
|
|
|
+ WHERE rn = 1
|
|
|
+ ) exm ON exm.morder_no = a.WorkOrd
|
|
|
+ LEFT JOIN WorkOrdInStorage ins ON a.WorkOrd = ins.WorkOrd AND ins.Remark = '工单预留'
|
|
|
+ <where>
|
|
|
+ a.Status != ''
|
|
|
+ <if test="reqVO.workOrd != null and reqVO.workOrd != ''">
|
|
|
+ AND a.WorkOrd LIKE CONCAT('%', #{reqVO.workOrd}, '%')
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.itemNum != null and reqVO.itemNum != ''">
|
|
|
+ AND a.ItemNum LIKE CONCAT('%', #{reqVO.itemNum}, '%')
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.status != null and reqVO.status != ''">
|
|
|
+ AND LOWER(a.Status) = #{reqVO.status}
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.woTyped != null and reqVO.woTyped != ''">
|
|
|
+ AND a.WoTyped = #{reqVO.woTyped}
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.batch != null and reqVO.batch != ''">
|
|
|
+ AND a.Batch = #{reqVO.batch}
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.drawing != null and reqVO.drawing != ''">
|
|
|
+ AND a.Drawing = #{reqVO.drawing}
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.customNo != null and reqVO.customNo != ''">
|
|
|
+ AND se.custom_no = #{reqVO.customNo}
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.ordDateStart != null">
|
|
|
+ AND a.OrdDate >= #{reqVO.ordDateStart}
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.ordDateEnd != null">
|
|
|
+ AND a.OrdDate <= #{reqVO.ordDateEnd}
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.dueDateStart != null">
|
|
|
+ AND a.DueDate >= #{reqVO.dueDateStart}
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.dueDateEnd != null">
|
|
|
+ AND a.DueDate <= #{reqVO.dueDateEnd}
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.priority != null">
|
|
|
+ AND a.Priority = #{reqVO.priority}
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.urgent != null">
|
|
|
+ AND a.Urgent = #{reqVO.urgent}
|
|
|
+ </if>
|
|
|
+ <if test="reqVO.isInitial != null">
|
|
|
+ AND a.IsInitial = #{reqVO.isInitial}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ ORDER BY a.UpdateTime DESC, a.Priority DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 根据ID查询工单详情 -->
|
|
|
+ <select id="selectScheduleById" resultType="cn.iocoder.yudao.module.makeplan.controller.admin.workorder.vo.WorkOrderScheduleRespVO">
|
|
|
+ SELECT
|
|
|
+ a.RecID AS id,
|
|
|
+ a.Batch AS batch,
|
|
|
+ a.Drawing AS drawing,
|
|
|
+ a.Typed AS typed,
|
|
|
+ a.WorkOrd AS workOrd,
|
|
|
+ a.OrdDate AS ordDate,
|
|
|
+ a.DueDate AS dueDate,
|
|
|
+ a.ItemNum AS itemNum,
|
|
|
+ a.Project AS project,
|
|
|
+ a.QtyOrded AS qtyOrded,
|
|
|
+ a.QtyCompleted AS qtyCompleted,
|
|
|
+ a.Remark AS remark,
|
|
|
+ LOWER(a.Status) AS status,
|
|
|
+ a.WoTyped AS woTyped,
|
|
|
+ b.Descr AS descr,
|
|
|
+ b.Descr1 AS descr1,
|
|
|
+ a.lbrvar,
|
|
|
+ a.IsInitial AS isInitial,
|
|
|
+ a.LotSerial AS lotSerial,
|
|
|
+ CASE WHEN a.CreateGLforLaborVar = 1 THEN '是' ELSE '否' END AS createGLforLaborVar,
|
|
|
+ a.QtyOrded - a.QtyCompleted AS zz,
|
|
|
+ a.IssueSite AS issueSite,
|
|
|
+ a.Priority AS priority,
|
|
|
+ IFNULL(a.LocationStock, 0) + IFNULL(a.OpQtyCompleted, 0) AS locationStock
|
|
|
+ FROM WorkOrdMaster a
|
|
|
+ LEFT JOIN ItemMaster b ON a.ItemNum = b.ItemNum AND b.Domain = a.Domain
|
|
|
+ WHERE a.RecID = #{id}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 调用存储过程关闭工单 -->
|
|
|
+ <select id="callCloseWorkOrders" statementType="CALLABLE">
|
|
|
+ {CALL pr_MES_CloseWorkOrders(#{ids})}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 同步工艺路线 -->
|
|
|
+ <update id="syncRoutingByWorkOrd">
|
|
|
+ DELETE FROM WorkOrdRouting WHERE WorkOrd = #{workOrd};
|
|
|
+
|
|
|
+ INSERT INTO WorkOrdRouting(
|
|
|
+ Domain, Descr, MilestoneOp, WorkOrd, OP, ParentOp, RunTime, ItemNum,
|
|
|
+ QtyOrded, OverlapUnits, Status, IsActive, CommentIndex, CreateTime,
|
|
|
+ StdOp, PackingQty, WorkOrdMasterRecID
|
|
|
+ )
|
|
|
+ SELECT
|
|
|
+ w.Domain, r.Descr, r.MilestoneOp, w.WorkOrd, r.OP, r.ParentOp, r.RunTime,
|
|
|
+ w.ItemNum, w.QtyOrded, r.OverlapUnits, w.Status, 1, r.CommentIndex, NOW(),
|
|
|
+ r.StdOp, r.PackingQty, w.RecID
|
|
|
+ FROM WorkOrdMaster w
|
|
|
+ LEFT JOIN RoutingOpDetail r ON w.ItemNum = r.RoutingCode
|
|
|
+ WHERE w.WorkOrd = #{workOrd} AND r.MilestoneOp IS NOT NULL
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <!-- 批量查询工单信息 -->
|
|
|
+ <select id="selectBatchByIds" resultType="cn.iocoder.yudao.module.makeplan.dal.dataobject.WorkOrderScheduleDO">
|
|
|
+ SELECT * FROM WorkOrdMaster
|
|
|
+ WHERE RecID IN
|
|
|
+ <foreach collection="ids" item="id" open="(" separator="," close=")">
|
|
|
+ #{id}
|
|
|
+ </foreach>
|
|
|
+ </select>
|
|
|
+
|
|
|
+</mapper>
|