Browse Source

后台功能处理

oyq28 5 months ago
parent
commit
a1f116852b

+ 3 - 1
imcs-admin-boot/imcs-authority-server/src/main/java/com/github/zuihou/AuthorityApplication.java

@@ -10,6 +10,7 @@ import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.core.env.Environment;
+import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
 import java.net.InetAddress;
@@ -23,7 +24,7 @@ import java.net.UnknownHostException;
  * @author zuihou
  * @createTime 2018-01-13 1:34
  */
-@SpringBootApplication
+@SpringBootApplication(scanBasePackages = "com.github.zuihou")
 @Configuration
 @EnableScheduling
 @Slf4j
@@ -31,6 +32,7 @@ import java.net.UnknownHostException;
 @EnableFormValidator
 @EnableLoginArgResolver
 @EnableFeignClients("com.github.zuihou")
+@EnableAsync
 public class AuthorityApplication {
     public static void main(String[] args) throws UnknownHostException {
         ConfigurableApplicationContext application = SpringApplication.run(AuthorityApplication.class, args);

+ 12 - 40
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/mq/TaskWorkNode.java

@@ -48,6 +48,7 @@ import com.github.zuihou.business.productionResourceCenter.service.impl.RobotNod
 import com.github.zuihou.business.util.DynamicRabbitMq;
 import com.github.zuihou.business.util.MsgUtil;
 import com.github.zuihou.common.constant.*;
+import com.github.zuihou.common.util.DateUtil;
 import com.github.zuihou.common.util.StringUtil;
 import com.github.zuihou.context.BaseContextHandler;
 import com.github.zuihou.database.mybatis.conditions.Wraps;
@@ -69,6 +70,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 import org.springframework.web.client.AsyncRestTemplate;
 import org.springframework.web.client.RestClientException;
@@ -170,6 +172,9 @@ public class TaskWorkNode {
     @Autowired
     private TrayService trayService;
 
+    @Autowired
+    private AsyncService asyncService;
+
     @Value("${zuihou.file.storage-path}")
     private String storagePath;
 
@@ -1166,15 +1171,7 @@ public class TaskWorkNode {
                 Object applyFeeding = msgUtil.redis_get("ApplyFeeding_"+ taskNode.getId());
                 if(returnMap.containsKey("preUpLoadFlag") && ObjectUtil.isEmpty(applyFeeding)){
                     // 发送请求上料cnc程序。并启动
-                    boolean bool = this.asyncPredictUploadFile(task,taskNode);
-                    if(!bool){
-                        dataMap.put("resultmsg","申请上料条件不满足");
-                        msgUtil.redis_del("ApplyFeeding_"+ taskNode.getId());
-                    }else{
-                        dataMap.put("resultmsg","申请上料程序等待");
-                    }
-                    dataMap.put("result", false);
-                    return;
+                    this.asyncPredictUploadFile(task,taskNode);
                 }
 
                 //锁定机械手
@@ -1258,13 +1255,13 @@ public class TaskWorkNode {
     }
 
     // 预上传,发送上料请求
-    public boolean asyncPredictUploadFile(TTask task,TaskNode taskNode){
+    public void asyncPredictUploadFile(TTask task,TaskNode taskNode){
         // 根据设备节点需求的设备id获取资源设备信息
         Productionresource productionresource =  productionresourceBizMapper.selectOne(Wraps.<Productionresource>lbQ().eq(Productionresource::getId,taskNode.getTargetResourceId()));
         TWorkpiece workpiece = workpieceService.getOne(new LbqWrapper<TWorkpiece>().eq(TWorkpiece::getCompleteBatchNo, task.getCompleteBatchNo()).last("limit 1"));
         BBom bom = bBomMapper.selectById(workpiece.getBomId());
         if(workpiece.getStorgeId()==null) {
-            return false;
+            return;
         }
         StockInfo stockInfo = stockInfoMapper.selectOne(new LbqWrapper<StockInfo>().eq(StockInfo::getStorgeId, workpiece.getStorgeId()).eq(StockInfo::getGoodsType, "1").last("limit 1"));
         Tray tray = trayService.getById(stockInfo.getGoodsId());
@@ -1278,7 +1275,7 @@ public class TaskWorkNode {
 
         List<BomProcedureProgram>procedureProgramList = bomProcedureProgramMapper.selectList(Wraps.<BomProcedureProgram>lbQ().eq(BomProcedureProgram::getProcedureId,task.getProcedureId()));
         if(procedureProgramList==null || procedureProgramList.size() == 0){
-            return false;
+            return;
         }
 
         List<Map<String, String>> fileList = new ArrayList<Map<String, String>>();
@@ -1303,7 +1300,8 @@ public class TaskWorkNode {
             uploadInfo.put("port", productionresource.getPort());
             uploadInfo.put("data", data);
 
-        return this.asyncPredictUploadFilePost(uploadInfo, taskNode.getId());
+        msgUtil.redis_set("ApplyFeeding_"+ taskNode.getId(), DateUtil.formatTime(new Date()), 1, TimeUnit.HOURS);
+        asyncService.asyncPredictUploadFilePost(uploadInfo, taskNode.getId());
     }
 
 
@@ -1794,6 +1792,7 @@ public class TaskWorkNode {
         Mono mono = webClient.post().uri("/api/UploadFile").contentType(MediaType.APPLICATION_JSON)
                 .syncBody(jsonObject).retrieve().bodyToMono(String.class);
 
+
         // 当上传不成功进行抛错处理
         if(!JSONObject.parseObject(mono.block().toString()).getBoolean("result")){
             //先不抛出异常
@@ -1805,32 +1804,5 @@ public class TaskWorkNode {
         return true;
     }
 
-    /**
-     *
-     * 发送异步请求
-     * @param jsonObject
-     * @return
-     */
-    public Boolean asyncPredictUploadFilePost(JSONObject jsonObject, long taskNodeId){
-        logger.warn("====发送异步请求,允许上料请求====》"+ jsonObject);
-        System.out.println("====发送异步请求,允许上料请求====》"+ jsonObject);
-
-        String hostSystemUrl = parameterService.getValue(ParameterKey.HOSTSYSTEMURL, null);
-        WebClient webClient = WebClient.create(hostSystemUrl);
-        jsonObject.put("taskId", "1");
-        jsonObject.put("taskNodeId", "1");
-        Mono mono = webClient.post().uri("/api/PredictUploadFile").contentType(MediaType.APPLICATION_JSON)
-                .syncBody(jsonObject).retrieve().bodyToMono(String.class);
-        msgUtil.redis_set("ApplyFeeding_"+ taskNodeId, "1", 1, TimeUnit.HOURS);
-        // 当上传不成功进行抛错处理
-        if(!JSONObject.parseObject(mono.block().toString()).getBoolean("result")){
-//            throw new RuntimeException("上传nc,接受异步请求结果,上传失败:" + mono.block());
-            return false;
-        }
-
-        logger.info("====发送异步请求,允许上料请求====》" + mono.block());
-        System.out.println("====发送异步请求,允许上料请求====》" + mono.block());
-        return true;
-    }
 }
 

+ 8 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionResourceCenter/service/AsyncService.java

@@ -0,0 +1,8 @@
+package com.github.zuihou.business.productionResourceCenter.service;
+
+import com.alibaba.fastjson.JSONObject;
+
+public interface AsyncService {
+
+    Boolean asyncPredictUploadFilePost(JSONObject jsonObject, long taskNodeId);
+}

+ 45 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionResourceCenter/service/impl/AsyncServiceImpl.java

@@ -0,0 +1,45 @@
+package com.github.zuihou.business.productionResourceCenter.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.github.zuihou.authority.service.common.ParameterService;
+import com.github.zuihou.business.productionResourceCenter.service.AsyncService;
+import com.github.zuihou.business.util.MsgUtil;
+import com.github.zuihou.common.constant.ParameterKey;
+import com.github.zuihou.common.util.DateUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+import org.springframework.web.reactive.function.client.WebClient;
+import reactor.core.publisher.Mono;
+
+import java.util.Date;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+@Service
+public class AsyncServiceImpl  implements AsyncService {
+
+    @Autowired
+    private MsgUtil msgUtil;
+
+    @Override
+    @Async
+    public Boolean asyncPredictUploadFilePost(JSONObject jsonObject, long taskNodeId) {
+        String hostSystemUrl = (null == msgUtil.redis_get(ParameterKey.PARAMETERS)? "": ((Map<String,String>)msgUtil.redis_get(ParameterKey.PARAMETERS)).get(ParameterKey.HOSTSYSTEMURL).toString());
+        WebClient webClient = WebClient.create(hostSystemUrl);
+        jsonObject.put("taskId", "1");
+        jsonObject.put("taskNodeId", "1");
+        Mono mono = webClient.post().uri("/api/PredictUploadFile").contentType(MediaType.APPLICATION_JSON)
+                .syncBody(jsonObject).retrieve().bodyToMono(String.class);
+
+        // 当上传不成功进行抛错处理
+        if(!JSONObject.parseObject(mono.block().toString()).getBoolean("result")){
+            msgUtil.redis_del("ApplyFeeding_"+ taskNodeId);
+            return Boolean.FALSE;
+        }
+        return Boolean.TRUE;
+    }
+}

+ 11 - 40
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionResourceCenter/service/impl/RobotNodeServiceImpl.java

@@ -31,10 +31,7 @@ import com.github.zuihou.business.productionReadyCenter.service.MToolClampServic
 import com.github.zuihou.business.productionReadyCenter.service.TrayService;
 import com.github.zuihou.business.productionResourceCenter.dao.*;
 import com.github.zuihou.business.productionResourceCenter.entity.*;
-import com.github.zuihou.business.productionResourceCenter.service.NodeOperationService;
-import com.github.zuihou.business.productionResourceCenter.service.ProductionresourcePositionService;
-import com.github.zuihou.business.productionResourceCenter.service.ZZoneProductionresourceService;
-import com.github.zuihou.business.productionResourceCenter.service.ZZoneService;
+import com.github.zuihou.business.productionResourceCenter.service.*;
 import com.github.zuihou.business.util.MsgUtil;
 import com.github.zuihou.common.constant.BizConstant;
 import com.github.zuihou.common.constant.CacheKey;
@@ -54,6 +51,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.MediaType;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.reactive.function.client.WebClient;
@@ -200,6 +198,9 @@ public class RobotNodeServiceImpl implements NodeOperationService {
 
     private Plan orderPlan;
 
+    @Autowired
+    private AsyncService asyncService;
+
     @Override
     public void initResource(TaskNode taskNode, TTask task, Map dataMap) {
         //productionresourcePosition = getResourcePosition(taskNode);
@@ -982,15 +983,7 @@ public class RobotNodeServiceImpl implements NodeOperationService {
                 //判断是否为机床上料
                 if(returnMap.containsKey("preUpLoadFlag") && targetxbk.equals("0") && ObjectUtil.isEmpty(applyFeeding)){
                     // 发送请求上料cnc程序。并启动
-                    boolean bool = this.asyncPredictUploadFile(task, taskNode);
-                    if(!bool){
-                        dataMap.put("resultmsg","申请上料条件不满足");
-                        msgUtil.redis_del("ApplyFeeding_"+ taskNode.getId());
-                    }else{
-                        dataMap.put("resultmsg","申请上料程序等待");
-                    }
-                    dataMap.put("result", false);
-                    return;
+                    this.asyncPredictUploadFile(task, taskNode);
                 }
 
                 jqrStorge = storgeService.getById(jqrMap.get(DemoLineConstant.DEMOLINE_RJQR_ZS).get(0).getStorgeId());
@@ -1087,7 +1080,7 @@ public class RobotNodeServiceImpl implements NodeOperationService {
     }
 
     // 预上传,发送上料请求
-    public boolean asyncPredictUploadFile(TTask task,TaskNode taskNode){
+    public void asyncPredictUploadFile(TTask task,TaskNode taskNode){
         // 根据设备节点需求的设备id获取资源设备信息
         Productionresource productionresource =  productionresourceBizMapper.selectOne(Wraps.<Productionresource>lbQ().eq(Productionresource::getId,taskNode.getTargetResourceId()));
         TWorkpiece workpiece = workpieceService.getOne(new LbqWrapper<TWorkpiece>().eq(TWorkpiece::getCompleteBatchNo, task.getCompleteBatchNo()).last("limit 1"));
@@ -1095,7 +1088,7 @@ public class RobotNodeServiceImpl implements NodeOperationService {
 
         if(workpiece.getStorgeId()==null) {
             msgUtil.createWarnLog("上料申请节点库位地址为空", "DataException");
-            return false;
+            return;
         }
         StockInfo stockInfo = stockInfoMapper.selectOne(new LbqWrapper<StockInfo>().eq(StockInfo::getStorgeId, workpiece.getStorgeId()).eq(StockInfo::getGoodsType, "1").last("limit 1"));
         Tray tray = trayService.getById(stockInfo.getGoodsId());
@@ -1110,7 +1103,7 @@ public class RobotNodeServiceImpl implements NodeOperationService {
         List<BomProcedureProgram>procedureProgramList = bomProcedureProgramMapper.selectList(Wraps.<BomProcedureProgram>lbQ().eq(BomProcedureProgram::getProcedureId,task.getProcedureId()));
         if(procedureProgramList==null || procedureProgramList.size() == 0){
             msgUtil.createWarnLog("上料申请配置上传文件为空", "DataException");
-            return false;
+            return;
         }
 
         List<Map<String, String>> fileList = new ArrayList<Map<String, String>>();
@@ -1134,32 +1127,10 @@ public class RobotNodeServiceImpl implements NodeOperationService {
             uploadInfo.put("port", productionresource.getPort());
             uploadInfo.put("data", data);
 
-           return this.asyncPredictUploadFilePost(uploadInfo, taskNode.getId());
+        msgUtil.redis_set("ApplyFeeding_"+ taskNode.getId(), DateUtil.formatTime(new Date()), 1, TimeUnit.HOURS);
+        asyncService.asyncPredictUploadFilePost(uploadInfo, taskNode.getId());
     }
-    /**
-     *
-     * 发送异步请求
-     * @param jsonObject
-     * @return
-     */
-    public boolean asyncPredictUploadFilePost(JSONObject jsonObject, long taskNodeId){
-        logger.warn("====发送异步请求,允许上料请求====》"+ jsonObject +"==="+ DateUtil.formatTime(new Date()));
 
-        msgUtil.redis_set("ApplyFeeding_"+ taskNodeId, DateUtil.formatTime(new Date()), 1, TimeUnit.HOURS);
-        String hostSystemUrl = parameterService.getValue(ParameterKey.HOSTSYSTEMURL, null);
-        WebClient webClient = WebClient.create(hostSystemUrl);
-        jsonObject.put("taskId", "1");
-        jsonObject.put("taskNodeId", "1");
-        Mono mono = webClient.post().uri("/api/PredictUploadFile").contentType(MediaType.APPLICATION_JSON)
-                .syncBody(jsonObject).retrieve().bodyToMono(String.class);
-        // 当上传不成功进行抛错处理
-        if(!JSONObject.parseObject(mono.block().toString()).getBoolean("result")){
-            logger.warn("======发送异步请求,请求失败======:"+mono.block() + "===" + DateUtil.formatTime(new Date()));
-            return false;
-        }
-        logger.warn("======发送异步请求,允许上料请求返回结果======:"+mono.block() + "===" + DateUtil.formatTime(new Date()));
-        return true;
-    }
     /**
      * 线内单独运行直接查找线边库上的子盘夹具毛料齐全的库位信息
      * @param task