浏览代码

aps-自动调度

guoqu1919 6 月之前
父节点
当前提交
8cd59a401f

+ 6 - 0
cx-aps/cx-aps-common/src/main/java/com/rongwei/bscommon/sys/dao/ApsBlankOrderDao.java

@@ -153,4 +153,10 @@ public interface ApsBlankOrderDao extends BaseMapper<ApsBlankOrderDo> {
     String selectIsWaitGetMaterialById(@Param("id") String id);
 
     String selectPlanEndProductionWorkshopsById(@Param("productionorderid") String productionorderid);
+
+    void updateFinishDateAboutProcessEqu();
+
+    void removeLockNextDayProcessEqu(@Param("needScheduleDate") String needScheduleDate);
+
+    void removeLockNextTwoDayProcessEqu(@Param("needScheduleDate") String needScheduleDate);
 }

+ 2 - 0
cx-aps/cx-aps-common/src/main/java/com/rongwei/bscommon/sys/service/ApsBlankOrderService.java

@@ -66,4 +66,6 @@ public interface ApsBlankOrderService extends IService<ApsBlankOrderDo> {
     R addMaterial(AddMaterialReq req);
 
     R checkAddMaterial(AddMaterialReq req);
+
+    void apsScheduleRestart();
 }

+ 30 - 0
cx-aps/cx-aps-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ApsBlankOrderServiceImpl.java

@@ -3,6 +3,7 @@ package com.rongwei.bscommon.sys.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateField;
+import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.date.StopWatch;
 import cn.hutool.core.util.ObjectUtil;
@@ -3939,4 +3940,33 @@ public class ApsBlankOrderServiceImpl extends ServiceImpl<ApsBlankOrderDao, ApsB
         }
         return R.ok(res);
     }
+
+    @Override
+    public void apsScheduleRestart() {
+        String needScheduleDate = "";
+        DateTime nowDate = DateUtil.date();
+        String time1 = DateUtil.format(nowDate, "yyyy-MM-dd 00:00:00");
+        String time2 = DateUtil.format(nowDate, "yyyy-MM-dd 12:00:00");
+        String time3 = DateUtil.format(nowDate, "yyyy-MM-dd 23:59:59");
+        String now = DateUtil.format(nowDate, "yyyy-MM-dd HH:mm:ss");
+        //如果当前时间在0-12点,重排明天的
+        //如果当前时间在12-24点,重排后天的
+        if (now.compareTo(time1) >= 0 && now.compareTo(time2) < 0) {
+            needScheduleDate = DateUtil.format(DateUtil.offsetDay(nowDate, 1), "yyyy-MM-dd");
+        }
+        if (now.compareTo(time2) >= 0 && now.compareTo(time3) <= 0) {
+            needScheduleDate = DateUtil.format(DateUtil.offsetDay(nowDate, 2), "yyyy-MM-dd");
+        }
+
+        if (ObjectUtil.isNotEmpty(needScheduleDate)) {
+            //将实际完工时间大于明天的作业挪到实际完工时间
+            this.baseMapper.updateFinishDateAboutProcessEqu();
+            //解锁明天有开工作业明细的坯料计划的所有作业明细
+            this.baseMapper.removeLockNextDayProcessEqu(needScheduleDate);
+            //解锁后天开工的所有作业明细
+            this.baseMapper.removeLockNextTwoDayProcessEqu(needScheduleDate);
+            //重新排程
+            apsService.apsSchedule(new ArrayList<>(), null, null);
+        }
+    }
 }

+ 39 - 0
cx-aps/cx-aps-common/src/main/resources/mybatis/ApsBlankOrderDao.xml

@@ -189,6 +189,45 @@
             </foreach>
         </where>
     </update>
+    <update id="updateFinishDateAboutProcessEqu">
+        update
+            aps_process_operation_process_equ apope
+            join aps_process_operation apo on apo.id = apope.PROCESSID
+            set
+                apope.PLANSTARTDATE=DATE_SUB(apope.ACTUALFINISHDATE,INTERVAL TIMESTAMPdiff(SECOND, apope.PLANSTARTDATE, apope.PLANENDDATE) SECOND),
+                apope.PLANENDDATE=apope.ACTUALFINISHDATE
+        where
+            apo.DELETED='0' and apope.deleted='0'
+          and apope.ACTUALFINISHDATE > DATE_ADD(CURRENT_DATE,INTERVAL 1 DAY)
+          and apo.PROCESS != '铸轧'
+    </update>
+    <update id="removeLockNextDayProcessEqu">
+        with tomorroworder as(
+            select DISTINCT apope.blankid
+            from aps_process_operation_process_equ apope
+            where apope.deleted='0'
+              and DATE(apope.PLANSTARTDATE) = #{needScheduleDate}
+            )
+        update
+            aps_process_operation_process_equ apope
+            join aps_process_operation apo on apo.id = apope.PROCESSID
+            join aps_blank_order abo on apo.BLANKID = abo.id
+            join tomorroworder on apope.blankid=tomorroworder.blankid
+            set apope.LOCKMARKDETAIL = 'n',apo.LOCKMARK='n',abo.SCHEDULINGSTATUS = '20'
+        where apope.deleted='0' and apo.deleted='0'
+          and apo.PROCESS != '铸轧' and apope.WORKSTATUS = '待开工'
+          and apope.PLANSTARTDATE > #{needScheduleDate}
+    </update>
+    <update id="removeLockNextTwoDayProcessEqu">
+        update
+        aps_process_operation_process_equ apope
+        join aps_process_operation apo on apo.id = apope.PROCESSID
+        join aps_blank_order abo on apo.BLANKID = abo.id
+        set apope.LOCKMARKDETAIL = 'n',apo.LOCKMARK='n',abo.SCHEDULINGSTATUS = '20'
+        where apope.deleted='0' and apo.deleted='0'
+        and apo.PROCESS != '铸轧' and apope.WORKSTATUS = '待开工'
+        and apope.PLANSTARTDATE >= DATE_ADD(#{needScheduleDate},INTERVAL 2 DAY) and apope.PLANSTARTDATE &lt; DATE_ADD(#{needScheduleDate},INTERVAL 3 DAY)
+    </update>
     <select id="checkConflictByBlankId" resultType="java.lang.Integer">
         select count(*) from aps_process_operation_process_equ
             <where>

+ 9 - 0
cx-aps/cx-aps-server/src/main/java/com/rongwei/bsserver/controller/ApsBlankOrderController.java

@@ -57,6 +57,15 @@ public class ApsBlankOrderController {
         return R.ok();
     }
 
+    /**
+     * 自动调度
+     */
+    @GetMapping("/apsScheduleRestart")
+    public R apsScheduleRestart() throws Exception {
+        apsBlankOrderService.apsScheduleRestart();
+        return R.ok();
+    }
+
     /**
      * 坯料计划锁定解锁
      *