Explorar o código

任务表增加设备id,定时调度根据设备id跑

wudingsheng hai 1 ano
pai
achega
b662a04096

+ 17 - 0
src/main/java/com/imcs/admin/business/dao/WDeviceShelfDao.java

@@ -0,0 +1,17 @@
+package com.imcs.admin.business.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.imcs.admin.entity.WDeviceShelf;
+
+/**
+ * 设备绑定货架(WDeviceShelf)表数据库访问层
+ *
+ * @author makejava
+ * @since 2024-06-28 15:23:51
+ */
+public interface WDeviceShelfDao extends BaseMapper<WDeviceShelf> {
+
+    Long getDeviceByStorage(String storage);
+
+}
+

+ 1 - 1
src/main/java/com/imcs/admin/business/dao/WInventoryTransactionTaskDao.java

@@ -75,7 +75,7 @@ public interface WInventoryTransactionTaskDao extends BaseMapper<WInventoryTrans
      */
     int deleteById(Long id);
 
-    WInventoryTransactionTask selectOne();
+    List<WInventoryTransactionTask> selectOne();
     List<WInventoryTransactionTask> dailyTaskStatistics(@Param(value = "minDate") Date minDate,@Param(value = "maxDate")  Date maxDate);
 
 }

+ 17 - 14
src/main/java/com/imcs/admin/business/job/ScheduledTask.java

@@ -62,23 +62,26 @@ public class ScheduledTask extends BaseServiceImpl {
         //查出task表id最小的一条status= 0 1 的数据
         //查这条数据任务,按照子任务顺序id最小开始依次执行
         //如果任务状态是 未开始 或 异常,则调C#接口
-        Object jobLock = redisTemplate.opsForValue().get("JOB_LOCK");
-        if (!Objects.isNull(jobLock)) {
-            return;
-        }
-        WInventoryTransactionTask wInventoryTransactionTask = taskDao.selectOne();
+
+        List<WInventoryTransactionTask> wInventoryTransactionTask = taskDao.selectOne();
         Assert.notNull(wInventoryTransactionTask);
-        List<WInventoryTransactionChildTask> wInventoryTransactionTaskDetails = childTaskDao.selectListByTaskId(wInventoryTransactionTask);
-        if (CollectionUtils.isNotEmpty(wInventoryTransactionTaskDetails)) {
-            WInventoryTransactionChildTask wInventoryTransactionChildTask = wInventoryTransactionTaskDetails.get(0);
-            if (wInventoryTransactionChildTask.getStatus() == Status.NOT_STARTED.getCode() || wInventoryTransactionChildTask.getStatus() == Status.EXCEPTION.getCode()) {
-                redisTemplate.opsForValue().set("JOB_LOCK", true);
-                httpHandler(wInventoryTransactionChildTask);
+        wInventoryTransactionTask.stream().parallel().forEach(vo->{
+            Object jobLock = redisTemplate.opsForValue().get("JOB_LOCK_"+vo.getDeviceId());
+            if (!Objects.isNull(jobLock)) {
+                return;
             }
-        }
+            List<WInventoryTransactionChildTask> wInventoryTransactionTaskDetails = childTaskDao.selectListByTaskId(vo);
+            if (CollectionUtils.isNotEmpty(wInventoryTransactionTaskDetails)) {
+                WInventoryTransactionChildTask wInventoryTransactionChildTask = wInventoryTransactionTaskDetails.get(0);
+                if (wInventoryTransactionChildTask.getStatus() == Status.NOT_STARTED.getCode() || wInventoryTransactionChildTask.getStatus() == Status.EXCEPTION.getCode()) {
+                    redisTemplate.opsForValue().set("JOB_LOCK_"+vo.getDeviceId(), true);
+                    httpHandler(wInventoryTransactionChildTask,vo.getDeviceId());
+                }
+            }
+        });
     }
 
-    private void httpHandler(WInventoryTransactionChildTask item) {
+    private void httpHandler(WInventoryTransactionChildTask item,Long deviceId) {
         String responseBody = null;
         Date responseTime = null;
         String url = "http://127.0.0.1:8081";
@@ -140,7 +143,7 @@ public class ScheduledTask extends BaseServiceImpl {
             e.printStackTrace(pw);
             responseBody = sw.toString();
         } finally {
-            redisTemplate.opsForValue().getAndDelete("JOB_LOCK");
+            redisTemplate.opsForValue().getAndDelete("JOB_LOCK_"+deviceId);
             log.error("释放定时任务调度锁");
             insertApiLog(json, responseBody, url, requestTime, responseTime, item);
         }

+ 7 - 0
src/main/java/com/imcs/admin/business/service/impl/BaseServiceImpl.java

@@ -86,6 +86,8 @@ public class BaseServiceImpl {
 
     @Resource
     public WPInventoryCountTaskDao wPInventoryCountTaskDao;
+    @Resource
+    public WDeviceShelfDao wDeviceShelfDao;
 
 
     /**
@@ -245,4 +247,9 @@ public class BaseServiceImpl {
         policyQuery.setLocationCode(locationCode);
         return policyQuery;
     }
+
+
+    public Long getDeviceByStorage(String storage){
+        return wDeviceShelfDao.getDeviceByStorage(storage);
+    }
 }

+ 1 - 1
src/main/java/com/imcs/admin/business/service/impl/OrderServiceImpl.java

@@ -152,7 +152,7 @@ public class OrderServiceImpl extends BaseServiceImpl implements OrderService {
         wInventoryTransactionTask.setStartPosition(orders.getStartPosition());
         wInventoryTransactionTask.setEndPosition(orders.getEndPosition());
         wInventoryTransactionTask.setVectorCode(orders.getVectorCode());
-        wInventoryTransactionTask.setEntryPoint(orders.getStartPosition());
+        wInventoryTransactionTask.setDeviceId(getDeviceByStorage(orders.getStartPosition()));
         wInventoryTransactionTask.setStatus(0);
         wInventoryTransactionTask.setTaskType(2);
         wInventoryTransactionTask.setWInventoryTransactionOrdersId(orderId);

+ 1 - 1
src/main/java/com/imcs/admin/business/service/impl/WInventoryTransactionTaskServiceImpl.java

@@ -77,7 +77,7 @@ public class WInventoryTransactionTaskServiceImpl extends BaseServiceImpl implem
         }
         PolicyInputResult policyResult = (PolicyInputResult)importPolicy.getData();
         String locationCode = policyResult.getLocationCode();
-        wInventoryTransactionTask.setEntryPoint(wInventoryTransactionTask.getStartPosition());
+        wInventoryTransactionTask.setDeviceId(getDeviceByStorage(wInventoryTransactionTask.getStartPosition()));
         wInventoryTransactionTask.setEndPosition(locationCode);
         wInventoryTransactionTask.setTaskCode(generateSerial.generateSerialNumber("outTask"));
         wInventoryTransactionTask.setCreatedAt(new Date());

+ 1 - 1
src/main/java/com/imcs/admin/business/service/impl/WPInventoryCountPalletServiceImpl.java

@@ -142,7 +142,7 @@ public class WPInventoryCountPalletServiceImpl extends BaseServiceImpl implement
         wInventoryTransactionTask.setTaskCode(generateSerial.generateSerialNumber("inTask"));
         wInventoryTransactionTask.setStartPosition(wPInventoryCountPallet.getEntryPoint());
         wInventoryTransactionTask.setEndPosition(locationCode);
-        wInventoryTransactionTask.setEntryPoint(wPInventoryCountPallet.getEntryPoint());
+        wInventoryTransactionTask.setDeviceId(getDeviceByStorage(wPInventoryCountPallet.getEntryPoint()));
         wInventoryTransactionTask.setVectorCode(wPInventoryCountPallet.getPalletCode());
         wInventoryTransactionTask.setStatus(0);
         wInventoryTransactionTask.setTaskType(2);

+ 1 - 1
src/main/java/com/imcs/admin/business/service/impl/WStorageLocationManagementServiceImpl.java

@@ -71,7 +71,7 @@ public class WStorageLocationManagementServiceImpl extends BaseServiceImpl imple
         wInventoryTransactionTask.setStartPosition(startPosition);
 
         wInventoryTransactionTask.setEndPosition(endPosition);
-        wInventoryTransactionTask.setEntryPoint(endPosition);
+        wInventoryTransactionTask.setDeviceId(getDeviceByStorage(endPosition));
         wInventoryTransactionTask.setVectorCode(palletCode);
         wInventoryTransactionTask.setStatus(0);
         wInventoryTransactionTask.setTaskType(1);

+ 101 - 0
src/main/java/com/imcs/admin/entity/WDeviceShelf.java

@@ -0,0 +1,101 @@
+package com.imcs.admin.entity;
+
+import java.util.Date;
+import java.io.Serializable;
+
+/**
+ * 设备绑定货架(WDeviceShelf)实体类
+ *
+ * @author makejava
+ * @since 2024-06-28 15:23:37
+ */
+public class WDeviceShelf implements Serializable {
+    private static final long serialVersionUID = -48410200290811527L;
+/**
+     * 主键
+     */
+    private Long id;
+/**
+     * 货架id
+     */
+    private Long deviceId;
+/**
+     * 货架id
+     */
+    private String shelfId;
+/**
+     * 创建时间
+     */
+    private Date createdAt;
+/**
+     * 创建人
+     */
+    private Integer createdBy;
+/**
+     * 修改时间
+     */
+    private Date updatedAt;
+/**
+     * 修改人
+     */
+    private Integer updatedBy;
+
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(Long deviceId) {
+        this.deviceId = deviceId;
+    }
+
+    public String getShelfId() {
+        return shelfId;
+    }
+
+    public void setShelfId(String shelfId) {
+        this.shelfId = shelfId;
+    }
+
+    public Date getCreatedAt() {
+        return createdAt;
+    }
+
+    public void setCreatedAt(Date createdAt) {
+        this.createdAt = createdAt;
+    }
+
+    public Integer getCreatedBy() {
+        return createdBy;
+    }
+
+    public void setCreatedBy(Integer createdBy) {
+        this.createdBy = createdBy;
+    }
+
+    public Date getUpdatedAt() {
+        return updatedAt;
+    }
+
+    public void setUpdatedAt(Date updatedAt) {
+        this.updatedAt = updatedAt;
+    }
+
+    public Integer getUpdatedBy() {
+        return updatedBy;
+    }
+
+    public void setUpdatedBy(Integer updatedBy) {
+        this.updatedBy = updatedBy;
+    }
+
+}
+

+ 1 - 1
src/main/java/com/imcs/admin/entity/WInventoryTransactionTask.java

@@ -90,7 +90,7 @@ public class WInventoryTransactionTask extends PageSize implements Serializable
     /**
      * 任务运行的出入库口
      */
-    private String entryPoint;
+    private Long deviceId;
 
     @TableField(exist = false)
     private List<WInventoryTransactionTaskDetail> detailList;

+ 10 - 0
src/main/resources/mapper/WDeviceShelfDao.xml

@@ -0,0 +1,10 @@
+<?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.imcs.admin.business.dao.WDeviceShelfDao">
+
+   <select id="getDeviceByStorage" resultType="java.lang.Long">
+       select device_id from w_device_shelf where shelf_id = (select shelf_management_id from w_storage_location_management where location_code=#{storage})
+   </select>
+
+</mapper>
+

+ 7 - 1
src/main/resources/mapper/WInventoryTransactionTaskDao.xml

@@ -214,7 +214,13 @@
     </delete>
 
     <select id="selectOne" resultType="com.imcs.admin.entity.WInventoryTransactionTask">
-        select * from w_inventory_transaction_task where status in(0,1) order by id asc limit 1
+        SELECT
+            *
+        FROM
+            w_inventory_transaction_task
+        WHERE
+                id IN ( SELECT MIN( id ) FROM w_inventory_transaction_task GROUP BY device_id )
+          AND status in (0,1)
     </select>
 
     <select id="dailyTaskStatistics" resultType="com.imcs.admin.entity.WInventoryTransactionTask">

+ 8 - 0
src/main/resources/static/wms/in/index.html

@@ -517,6 +517,14 @@
 
             },toDo(row){
                 window.location.href = "edit.html?id="+row.id;
+            },handleDelete(row) {
+                // 从 migrationResultList 中删除当前行
+                const index = this.detailList.indexOf(row);
+                if (index !== -1) {
+                    this.detailList.splice(index, 1);
+                }
+
+                //this.locationList = this.locationList.filter(item => item.outMaterialCode !== row.materialCode);
             }
         }