浏览代码

bug修复

andy 3 年之前
父节点
当前提交
c5bd25db68

+ 226 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/uuid/SnowflakeIdWorker.java

@@ -0,0 +1,226 @@
+package com.ruoyi.common.utils.uuid;
+
+import org.apache.commons.lang3.RandomUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.SystemUtils;
+
+import java.net.Inet4Address;
+import java.net.UnknownHostException;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: andy.qu
+ * Date: 2020/9/17
+ */
+public class SnowflakeIdWorker {
+    // ==============================Fields===========================================
+    /**
+     * 开始时间截 (2015-01-01)
+     */
+    private final long twepoch = 1489111610226L;
+
+    /**
+     * 机器id所占的位数
+     */
+    private final long workerIdBits = 5L;
+
+    /**
+     * 数据标识id所占的位数
+     */
+    private final long dataCenterIdBits = 5L;
+
+    /**
+     * 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数)
+     */
+    private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
+
+    /**
+     * 支持的最大数据标识id,结果是31
+     */
+    private final long maxDataCenterId = -1L ^ (-1L << dataCenterIdBits);
+
+    /**
+     * 序列在id中占的位数
+     */
+    private final long sequenceBits = 12L;
+
+    /**
+     * 机器ID向左移12位
+     */
+    private final long workerIdShift = sequenceBits;
+
+    /**
+     * 数据标识id向左移17位(12+5)
+     */
+    private final long dataCenterIdShift = sequenceBits + workerIdBits;
+
+    /**
+     * 时间截向左移22位(5+5+12)
+     */
+    private final long timestampLeftShift = sequenceBits + workerIdBits + dataCenterIdBits;
+
+    /**
+     * 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095)
+     */
+    private final long sequenceMask = -1L ^ (-1L << sequenceBits);
+
+    /**
+     * 工作机器ID(0~31)
+     */
+    private long workerId;
+
+    /**
+     * 数据中心ID(0~31)
+     */
+    private long dataCenterId;
+
+    /**
+     * 毫秒内序列(0~4095)
+     */
+    private long sequence = 0L;
+
+    /**
+     * 上次生成ID的时间截
+     */
+    private long lastTimestamp = -1L;
+
+    private static SnowflakeIdWorker idWorker;
+
+    static {
+        idWorker = new SnowflakeIdWorker(getWorkId(), getDataCenterId());
+    }
+
+    //==============================Constructors=====================================
+
+    /**
+     * 构造函数
+     *
+     * @param workerId     工作ID (0~31)
+     * @param dataCenterId 数据中心ID (0~31)
+     */
+    public SnowflakeIdWorker(long workerId, long dataCenterId) {
+        if (workerId > maxWorkerId || workerId < 0) {
+            throw new IllegalArgumentException(String.format("workerId can't be greater than %d or less than 0", maxWorkerId));
+        }
+        if (dataCenterId > maxDataCenterId || dataCenterId < 0) {
+            throw new IllegalArgumentException(String.format("dataCenterId can't be greater than %d or less than 0", maxDataCenterId));
+        }
+        this.workerId = workerId;
+        this.dataCenterId = dataCenterId;
+    }
+
+    // ==============================Methods==========================================
+
+    /**
+     * 获得下一个ID (该方法是线程安全的)
+     *
+     * @return SnowflakeId
+     */
+    public synchronized long nextId() {
+        long timestamp = timeGen();
+
+        //如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
+        if (timestamp < lastTimestamp) {
+            throw new RuntimeException(
+                    String.format("Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
+        }
+
+        //如果是同一时间生成的,则进行毫秒内序列
+        if (lastTimestamp == timestamp) {
+            sequence = (sequence + 1) & sequenceMask;
+            //毫秒内序列溢出
+            if (sequence == 0) {
+                //阻塞到下一个毫秒,获得新的时间戳
+                timestamp = tilNextMillis(lastTimestamp);
+            }
+        }
+        //时间戳改变,毫秒内序列重置
+        else {
+            sequence = 0L;
+        }
+
+        //上次生成ID的时间截
+        lastTimestamp = timestamp;
+
+        //移位并通过或运算拼到一起组成64位的ID
+        return ((timestamp - twepoch) << timestampLeftShift)
+                | (dataCenterId << dataCenterIdShift)
+                | (workerId << workerIdShift)
+                | sequence;
+    }
+
+    /**
+     * 阻塞到下一个毫秒,直到获得新的时间戳
+     *
+     * @param lastTimestamp 上次生成ID的时间截
+     * @return 当前时间戳
+     */
+    protected long tilNextMillis(long lastTimestamp) {
+        long timestamp = timeGen();
+        while (timestamp <= lastTimestamp) {
+            timestamp = timeGen();
+        }
+        return timestamp;
+    }
+
+    /**
+     * 返回以毫秒为单位的当前时间
+     *
+     * @return 当前时间(毫秒)
+     */
+    protected long timeGen() {
+        return System.currentTimeMillis();
+    }
+
+    private static Long getWorkId() {
+        try {
+            String hostAddress = Inet4Address.getLocalHost().getHostAddress();
+            int[] ints = StringUtils.toCodePoints(hostAddress);
+            int sums = 0;
+            for (int b : ints) {
+                sums += b;
+            }
+            return (long) (sums % 32);
+        } catch (UnknownHostException e) {
+            // 如果获取失败,则使用随机数备用
+            return RandomUtils.nextLong(0, 31);
+        }
+    }
+
+    private static Long getDataCenterId() {
+        int[] ints = StringUtils.toCodePoints("www.warewms.com");
+        int sums = 0;
+        for (int i : ints) {
+            sums += i;
+        }
+        return (long) (sums % 32);
+    }
+
+
+    /**
+     * 静态工具类
+     *
+     * @return
+     */
+    public static synchronized Long generateId() {
+        long id = idWorker.nextId();
+        return id;
+    }
+
+    //==============================Test=============================================
+
+    /**
+     * 测试
+     */
+    public static void main(String[] args) {
+        /*System.out.println(System.currentTimeMillis());
+        long startTime = System.nanoTime();
+        for (int i = 0; i < 50000; i++) {
+            long id = SnowflakeIdWorker.generateId();
+            System.out.println(id);
+        }
+        System.out.println((System.nanoTime() - startTime) / 1000000 + "ms");*/
+        //System.out.println(SnowflakeIdWorker.generateId());
+    }
+
+}

+ 10 - 8
ruoyi-ui/src/views/ams/lineCall/index.vue

@@ -337,6 +337,7 @@
       handleUpdate(row) {
         this.reset();
         const id = row.id || this.ids
+        this.subData = []
         // 加载批次属性明细
         flowConfigLotatt(id).then(response => {
           this.flowConfigDetailsList = response.data;
@@ -457,17 +458,9 @@
               }
             }
 
-            let lineCallDetailsFormList = new Array();
-            for (let i = 0; i < this.flowConfigDetailsList.length; i++) {
-              let obj = new Object();
-              obj.lotattId = this.flowConfigDetailsList[i].lotattId
-              obj.lotattValue = this.flowConfigDetailsList[i].lotattValue
-              lineCallDetailsFormList.push(obj)
-            }
             if(this.subData.length == 0) {
               this.addDetail()
             }
-            this.form.lineCallDetailsFormList = lineCallDetailsFormList
             exec(this.subData).then(response => {
               if (response.code === 200) {
                 this.$modal.msgSuccess("执行成功");
@@ -584,6 +577,15 @@
                   }
                 }
               }
+
+              let lineCallDetailsFormList = new Array();
+              for (let i = 0; i < this.flowConfigDetailsList.length; i++) {
+                let obj = new Object();
+                obj.lotattId = this.flowConfigDetailsList[i].lotattId
+                obj.lotattValue = this.flowConfigDetailsList[i].lotattValue
+                lineCallDetailsFormList.push(obj)
+              }
+              this.form.lineCallDetailsFormList = lineCallDetailsFormList
             }
             let obj = JSON.parse(JSON.stringify(this.form))
             this.subData.push(obj)

+ 43 - 5
warewms-ams/src/main/java/com/ruoyi/ams/business/BusinessServiceImpl.java

@@ -26,6 +26,7 @@ import com.ruoyi.base.service.IBaseSkuService;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.uuid.SnowflakeIdWorker;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -107,11 +108,11 @@ public class BusinessServiceImpl implements IBusinessService {
             locationTo = this.zoneLocationAllocation(locationToList, "locationTo", "MV", asnSoStrategy, agvCallDTO);
         }
 
-        List<WcsTask> wcsTaskList = this.genTask(locationFrom,locationTo,flowConfigHeaderVO);
-        for(WcsTask wcsTask : wcsTaskList) {
+        List<WcsTask> wcsTaskList = this.genTask(locationFrom, locationTo, flowConfigHeaderVO);
+        for (WcsTask wcsTask : wcsTaskList) {
             this.addTask(wcsTask);
         }
-        return AjaxResult.error("任务下发成功");
+        return AjaxResult.success("任务下发成功");
     }
 
     @Transactional
@@ -340,8 +341,45 @@ public class BusinessServiceImpl implements IBusinessService {
         } else {
             //获取对应的流程
             List<FlowConfigHeader> headerVOList = flowConfigHeaderService.sortFlowConfigHeader(Long.parseLong(flowConfigHeaderVO.getRootFlow()));
-            for(FlowConfigHeader flowConfigHeader : headerVOList) {
-
+            AsnSoStrategy asnSoStrategy = asnSoStrategyMapper.selectAsnSoStrategy();
+            String taskNo = System.currentTimeMillis() + "";
+            WcsTask wcsTask = new WcsTask();
+            wcsTask.setTaskNo(taskNo);
+            wcsTask.setAreaFrom(locationFrom.getZoneId().toString());
+            wcsTask.setLocationFrom(locationFrom.getId().toString());
+            wcsTask.setAreaTo(locationTo.getZoneId() + "");
+            wcsTask.setLocationTo(locationTo.getId().toString());
+            wcsTask.setState(9L);
+            wcsTask.setPriority(1L);
+            wcsTask.setCreateDate(new Date());
+            wcsTask.setBusinessType("01");
+            wcsTask.setTaskType("");
+            wcsTaskList.add(wcsTask);
+            String beforeTaskNo = taskNo;
+            for (FlowConfigHeader flowConfigHeader : headerVOList) {
+                if (StringUtils.isEmpty(flowConfigHeader.getRelFlow()) && flowConfigHeader.getRootFlow().equals(flowConfigHeader.getId().toString())) {
+                    continue;
+                }
+                List<BaseLocationInfo> locationFromList = this.convertLocation(flowConfigHeader.getLocationFrom(), 1L);
+                List<BaseLocationInfo> locationToList = this.convertLocation(flowConfigHeader.getLocationTo(), 1L);
+                locationFrom = this.zoneLocationAllocation(locationFromList, "locationFrom", "MV", null, null);
+                locationTo = this.zoneLocationAllocation(locationToList, "locationTo", "MV", null, null);
+                String currentNo = SnowflakeIdWorker.generateId().toString();
+                WcsTask child = new WcsTask();
+                child.setTaskNo(currentNo);
+                child.setParentTask(taskNo);
+                child.setBeforeTask(beforeTaskNo);
+                child.setAreaFrom(locationFrom.getZoneId().toString());
+                child.setLocationFrom(locationFrom.getId().toString());
+                child.setAreaTo(locationTo.getZoneId() + "");
+                child.setLocationTo(locationTo.getId().toString());
+                child.setState(9L);
+                child.setPriority(1L);
+                child.setCreateDate(new Date());
+                child.setBusinessType("01");
+                child.setTaskType("");
+                wcsTaskList.add(child);
+                beforeTaskNo = currentNo;
             }
         }
         return wcsTaskList;

+ 12 - 4
warewms-ams/src/main/java/com/ruoyi/ams/task/service/impl/WcsTaskServiceImpl.java

@@ -120,6 +120,7 @@ public class WcsTaskServiceImpl implements IWcsTaskService {
     @Override
     public void callBackTaskComplete(WcsTask wcsTask) {
         BaseLocationInfo bt = null;
+        BaseLocationInfo bf = null;
 
         //设置目标库位为占用状态
         if (!StringUtils.isEmpty(wcsTask.getLocationTo())) {
@@ -131,6 +132,17 @@ public class WcsTaskServiceImpl implements IWcsTaskService {
             }
         }
 
+        // 释放起始库位
+        if (!StringUtils.isEmpty(wcsTask.getLocationFrom())) {
+            bf = baseLocationInfoService.selectBaseLocationInfoById(Long.parseLong(wcsTask.getLocationFrom()));
+            if (bf != null) {
+                bf.setIsEmpty("N");
+                bf.setStockStatus("00");
+                baseLocationInfoService.updateBaseLocationInfo(bf);
+            }
+            baseLocationInfoService.updateLocationStockStatus(Long.parseLong(wcsTask.getLocationFrom()), "00");
+        }
+
         if (!StringUtils.isEmpty(wcsTask.getLocationFrom()) && !StringUtils.isEmpty(wcsTask.getLocationTo())) {
             invLotLocIdMapper.updateInvLotLocIdLocationId(Long.parseLong(wcsTask.getLocationFrom()), Long.parseLong(wcsTask.getLocationTo()));
         }
@@ -139,10 +151,6 @@ public class WcsTaskServiceImpl implements IWcsTaskService {
         wcsTask.setState(2L);
         wcsTaskMapper.updateWcsTask(wcsTask);
 
-        // 释放起始库位
-        if (!StringUtils.isEmpty(wcsTask.getLocationFrom())) {
-            baseLocationInfoService.updateLocationStockStatus(Long.parseLong(wcsTask.getLocationFrom()), "00");
-        }
     }
 
     @Transactional