Browse Source

优化PLC,及任务完成后库位转移逻辑

zhifei 1 year ago
parent
commit
c83152c3ff

+ 11 - 2
ruoyi-admin/src/main/resources/application-dev.yml

@@ -6,7 +6,7 @@ spring:
         druid:
             # 主库数据源
             master:
-                url: jdbc:mysql://47.100.220.92:3306/wareams_tianao?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
+                url: jdbc:mysql://localhost:3306/wareams_tianao?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
                 username: warewms
                 password: warewms123
             # 从库数据源
@@ -64,6 +64,15 @@ logging:
 
 # 是否开启服务
 init-task:
-    autosend: false # 自动下发任务
+    autosend: true # 自动下发任务
     aciservice: false # ndc通讯
 
+ # plc连接配置
+plc:
+    plcList[0]:
+        ip: 192.168.60.151
+        enable: false
+        name: conveyorBeltsPlc
+        ePlcType: S1200
+        heartbeat: DB1054.0.0
+        confirmTheStatus: DB1055.0.0

+ 1 - 1
ruoyi-admin/src/main/resources/application-prod.yml

@@ -6,7 +6,7 @@ spring:
         druid:
             # 主库数据源
             master:
-                url: jdbc:mysql://192.168.62.51:3306/warewms-tianao?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
+                url: jdbc:mysql://localhost:3306/warewms-tianao?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
                 username: warewms
                 password: warewms123
             # 从库数据源

+ 2 - 10
ruoyi-admin/src/main/resources/application.yml

@@ -37,7 +37,7 @@ spring:
     # 国际化资源文件路径
     basename: i18n/messages
   profiles:
-    active: dev
+    active: test
   # 文件上传
   servlet:
     multipart:
@@ -124,12 +124,4 @@ tianao:
   taskBackUrl: http://192.168.60.50:7225/Api_Changlian/ForksUpdateTask
   AGVStatusBackUrl: http://192.168.60.50:7225/Api_Changlian/ForksUpdateAgvAxis
 
-# plc连接配置
-plc:
-  plcList[0]:
-    ip: 192.168.60.151
-    enable: true
-    name: conveyorBeltsPlc
-    ePlcType: S1200
-    heartbeat: DB1054.0.0
-    confirmTheStatus: DB1055.0.0
+

File diff suppressed because it is too large
+ 93 - 34
ruoyi-admin/src/test/java/com/ruoyi/admin/test/base/WarehouseTest.java


+ 15 - 6
ruoyi-system/src/main/java/com/ruoyi/system/init/PlcConnectServiceRunner.java

@@ -19,6 +19,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -48,6 +49,8 @@ public class PlcConnectServiceRunner implements CommandLineRunner {
 
     private HashMap<String, S7PLC> plcToolsMap = new HashMap<>();
 
+    private HashMap<String, ScheduledFuture<?>> heartbeatThreads = new HashMap<>();
+
     private ArrayList<String> reTryPlc = new ArrayList<>();
 
     /**
@@ -63,6 +66,7 @@ public class PlcConnectServiceRunner implements CommandLineRunner {
                     if (s7PLC.checkConnected()){
                         plcToolsMap.put(plcConfig.getName(),s7PLC);
                         log.info("plc:{},ip:{},The connection was successful",plcConfig.getName(),plcConfig.getIp());
+                        plcConnectsTheHeartbeat(plcConfig,s7PLC);
                     }
                 }catch (Exception e){
                     log.info("plc:{},ip:{},Connection failed",plcConfig.getName(),plcConfig.getIp());
@@ -75,6 +79,10 @@ public class PlcConnectServiceRunner implements CommandLineRunner {
 
     public void retry(PlcConfig plcConfig) {
         reTryPlc.add(plcConfig.getName());
+        ScheduledFuture<?> scheduledFuture = heartbeatThreads.get(plcConfig.getName());
+        if (ObjectUtil.isNotNull(scheduledFuture)){
+            scheduledFuture.cancel(true);
+        }
         threadPoolTaskExecutor.execute (() -> {
             Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder()
                     .retryIfResult(Boolean.FALSE::equals)
@@ -115,17 +123,18 @@ public class PlcConnectServiceRunner implements CommandLineRunner {
     private void plcConnectsTheHeartbeat(PlcConfig plcConfig,S7PLC s7PLC){
         String heartbeatAdd = plcConfig.getHeartbeat();
         if (StringUtils.isNotEmpty(heartbeatAdd)){
-            scheduledExecutorService.scheduleWithFixedDelay(()->{
-                if (!reTryPlc.contains(plcConfig.getName())){
+            ScheduledFuture<?> scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> {
+                if (!reTryPlc.contains(plcConfig.getName())) {
                     try {
                         byte b = s7PLC.readByte(plcConfig.getHeartbeat());
-                        s7PLC.writeByte(plcConfig.getConfirmTheStatus(),b);
-                    }catch (Exception e){
-                        log.error("device:{},The connection is lost",plcConfig.getName());
+                        s7PLC.writeByte(plcConfig.getConfirmTheStatus(), b);
+                    } catch (Exception e) {
+                        log.error("device:{},The connection is lost", plcConfig.getName());
                         retry(plcConfig);
                     }
                 }
-            },0,3,TimeUnit.SECONDS);
+            }, 0, 3, TimeUnit.SECONDS);
+            heartbeatThreads.put(plcConfig.getName(),scheduledFuture);
         }
     }
 

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/init/PublishAGVInfo.java

@@ -31,7 +31,7 @@ public class PublishAGVInfo implements CommandLineRunner {
 
     @Override
     public void run(String... args) throws Exception {
-        initConnect();
+//        initConnect();
     }
 
     private void initConnect(){

+ 6 - 1
warewms-ams/src/main/java/com/ruoyi/ams/task/service/impl/WcsTaskServiceImpl.java

@@ -449,7 +449,12 @@ public class WcsTaskServiceImpl implements IWcsTaskService {
                         baseLocationInfoService.unLockLocationStockStatus(Long.parseLong(wcsTask.getLocationTo())
                                 , Constant.WAREHOUSE_ID, updateBy);
                         // 将中间缓存位库存移动到终点
-                        moveMiddleCacheToDestination(wcsTask);
+                        if (zoneList.contains(wcsTask.getAreaTo())) {
+                            baseLocationInfoService.updateLocationIdleAndEmpty(Long.parseLong(wcsTask.getLocationTo()),1L , "NDC");
+                        } else {
+                            // 将中间缓存位库存移动到终点
+                            moveMiddleCacheToDestination(wcsTask);
+                        }
                         //释放redis锁
                         if (!StringUtils.isEmpty(wcsTask.getExt8())) {
                             redisCache.unlockCacheObject(Long.parseLong(wcsTask.getExt8()));