瀏覽代碼

后端性能优化

oyq28 2 月之前
父節點
當前提交
325431ca13

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

@@ -5,12 +5,12 @@ import com.github.zuihou.validator.annotation.EnableFormValidator;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 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;
@@ -32,7 +32,7 @@ import java.net.UnknownHostException;
 @EnableFormValidator
 @EnableLoginArgResolver
 @EnableFeignClients("com.github.zuihou")
-@EnableCaching
+@EnableAsync
 public class AuthorityApplication {
     public static void main(String[] args) throws UnknownHostException {
         ConfigurableApplicationContext application = SpringApplication.run(AuthorityApplication.class, args);

+ 2 - 2
imcs-admin-boot/imcs-authority-server/src/main/java/com/github/zuihou/http/RestTemplateConfig.java

@@ -22,8 +22,8 @@ public class RestTemplateConfig {
     @Bean
     public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
         SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
-        factory.setReadTimeout(6000000);//单位为ms
-        factory.setConnectTimeout(6000000);//单位为ms
+        factory.setReadTimeout(5000);//单位为ms
+        factory.setConnectTimeout(10000);//单位为ms
         return factory;
     }
 

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

@@ -177,6 +177,9 @@ public class TaskWorkNode {
     @Autowired
     private OrderTaskService orderTaskService;
 
+    @Value("${zuihou.file.storage-path}")
+    private String storagePath;
+
     //总控端口
     private final String ZK_port = "120";
 
@@ -549,11 +552,11 @@ public class TaskWorkNode {
                                        String jsonParam = getRequestParam(conMap);
                                        specialCallBackMyselfFlag = true;
                                     }else{
-                                           try {
-                                               Thread.sleep(1000);
-                                           } catch (InterruptedException e) {
-                                               e.printStackTrace();
-                                           }
+//                                           try {
+//                                               Thread.sleep(1000);
+//                                           } catch (InterruptedException e) {
+//                                               e.printStackTrace();
+//                                           }
 
                                            //组装接口参数
                                         HttpHeaders headers = new HttpHeaders();
@@ -1296,10 +1299,20 @@ public class TaskWorkNode {
                 dataMap.put("data", locationMap);
 
                 String uploadInfo = msgUtil.redis_get(DemoLineConstant.DEMOLINE_HEIDENHAIN_FILE_URL+"_"+task.getId())!=null? msgUtil.redis_get(DemoLineConstant.DEMOLINE_HEIDENHAIN_FILE_URL+"_"+task.getId()).toString(): null;
+                Productionresource productionresource =  productionresourceBizMapper.selectOne(Wraps.<Productionresource>lbQ().eq(Productionresource::getId,taskNode.getTargetResourceId()));
+                TTask tTask = taskMapper.selectById(taskNode.getTaskId());
+                Order currentOrder = orderMapper.selectById(tTask.getOrderId());
                 if(StringUtils.isNotEmpty(uploadInfo)){
                     JSONObject jsonObject  = JSONObject.parseObject(uploadInfo);
                     //异步发送哈默预处理编号
                     this.asyncPost(jsonObject);
+                }else if(currentOrder.getSingleTaskFlag().equals("1") && productionresource.getModeSpecification().equals("HEIDENHAIN")){
+                    JSONObject jsonObject = new JSONObject();
+                    jsonObject.put("url", productionresource.getIp());
+                    jsonObject.put("port", productionresource.getPort());
+                    String defaultFileName = this.storagePath+"/common/2.h";
+                    jsonObject.put("fileName", defaultFileName.replace("/", "\\"));
+                    boolean bool = this.asyncPost(jsonObject);
                 }
 
                 dataMap.put("fromStorge", hcwStorge);
@@ -1332,6 +1345,8 @@ public class TaskWorkNode {
                                 fileList.add(m);
                             });
                             locationMap.put("fileName",fileList.get(0).get("fileName"));
+                        }else{
+                            locationMap.put("fileName", "1");
                         }
                     }
                 }

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

@@ -24,6 +24,7 @@ import com.github.zuihou.business.productionResourceCenter.service.Productionres
 import com.github.zuihou.business.util.MsgUtil;
 import com.github.zuihou.common.constant.DictionaryKey;
 import com.github.zuihou.common.util.DateUtil;
+import com.github.zuihou.context.BaseContextHandler;
 import com.github.zuihou.database.mybatis.conditions.Wraps;
 import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
 import com.google.common.collect.Maps;
@@ -74,6 +75,7 @@ public class AsyncServiceImpl implements AsyncService {
     @Async
     public Boolean asyncTaskSchedule() {
         log.warn("[线边库加工设备重调度]");
+        BaseContextHandler.setTenant("0000");
         LbqWrapper<Productionresource> lbqWrapper = new LbqWrapper<Productionresource>();
         lbqWrapper.eq(Productionresource::getStatus, "1").eq(Productionresource::getOnlineStatus, "1").isNotNull(Productionresource::getModeSpecification);
         //获取当前处于空闲状态的设备(排除正在加工以及报错的机床)
@@ -94,7 +96,7 @@ public class AsyncServiceImpl implements AsyncService {
             //获取线边库加工零件批次号
             List<String> completeBatchNos = stockInfoService.list(new LbqWrapper<StockInfo>().eq(StockInfo::getGoodsType, "4").in(StockInfo::getStorgeId, storgeIds)).stream().map(StockInfo::getCompleteBatchNo).collect(Collectors.toList());
 
-            List<TaskNode> taskNodeList = completeBatchNos.size() > 0 ? taskNodeService.list(new LbqWrapper<TaskNode>().eq(TaskNode::getExeStatus, "2").in(TaskNode::getTargetResourceId, macResourceIds).in(TaskNode::getCompleteBatchNo, completeBatchNos).eq(TaskNode::getNodeName, "放本序设备").orderByAsc(TaskNode::getStartTime)) : Lists.newArrayList();
+            List<TaskNode> taskNodeList = completeBatchNos.size() > 0 ? taskNodeService.list(new LbqWrapper<TaskNode>().eq(TaskNode::getExeStatus, "2").in(TaskNode::getCompleteBatchNo, completeBatchNos).eq(TaskNode::getNodeName, "放本序设备").orderByAsc(TaskNode::getStartTime)) : Lists.newArrayList();
             // 2. 判断线边库任务节点是否存在
             if (taskNodeList != null && taskNodeList.size() > 0) {
                 List<Long> ids = taskNodeList.stream().map(TaskNode::getTaskId).distinct().collect(Collectors.toList());
@@ -103,19 +105,26 @@ public class AsyncServiceImpl implements AsyncService {
                 List<Long> procedureIdList = taskList.stream().map(TTask::getProcedureId).collect(Collectors.toList());
                 Map<Long, List<BomProcedureProductionresource>> procedureCntMap = bomProcedureProductionresourceService.list(new LambdaQueryWrapper<BomProcedureProductionresource>().in(BomProcedureProductionresource::getProcedureId, procedureIdList)).stream().collect(Collectors.groupingBy(BomProcedureProductionresource::getProcedureId));
                 //获取工艺配置中允许变换加工设备的任务
-                final List<Long> procedureIdFinalList = procedureCntMap.entrySet().stream().filter(item->item.getValue().size()>1).map(Map.Entry::getKey).collect(Collectors.toList());
-                if(procedureIdList.size()>1){
+                final List<Long> procedureIdFinalList = procedureCntMap.entrySet().stream().filter(item->{
+                    List<Long> tempIds = item.getValue().stream().map(BomProcedureProductionresource::getResourceId).filter(item2->macResourceIds.contains(item2)).collect(Collectors.toList());
+                    return item.getValue().size()>1 && tempIds.size()>0;
+                }).map(Map.Entry::getKey).collect(Collectors.toList());
+                if(procedureIdFinalList.size()>0){
                     taskList = taskList.stream().filter(item->procedureIdFinalList.contains(item.getProcedureId())).collect(Collectors.toList());
                 }
                 //3. 判断自动调度任务是否存在
                 if(taskList.size()>0){
                     //以加工机床分类判断是否某类线边库任务已经执行动态调度
                     Map<Integer, List<TTask>> taskMaps = taskList.stream().collect(Collectors.groupingBy(item->{
-                        String deviceType = devicesMap.get(item.getResourceId());
-                        return DictionaryKey.YJ_DEVICE_TYPE.get(deviceType);
+                        Productionresource productionresource = productionresourceBizMapper.selectById(item.getResourceId());
+                        return  DictionaryKey.YJ_DEVICE_TYPE.get(productionresource.getModeSpecification());
                     }));
                     //过滤已经执行动态调度
-                    List<Integer> upDeviceTypes = DictionaryKey.YJ_DEVICE_TYPE.entrySet().stream().filter(map -> !taskMaps.containsKey(map.getValue())).distinct().map(Map.Entry::getValue).collect(Collectors.toList());
+                    List<Integer> upDeviceTypes = DictionaryKey.YJ_DEVICE_TYPE.entrySet().stream().filter(map -> {
+                       if(!taskMaps.containsKey(map.getValue())) return true;
+                       List<TTask> dataList = taskMaps.get(map.getValue()).stream().filter(tTask->tTask.getIsReload()>0).collect(Collectors.toList());
+                       return dataList.size() == 0? true : false;
+                    }).distinct().map(Map.Entry::getValue).collect(Collectors.toList());
                     //3.判断是否有品牌机床可以执行调度 =0表明所有品牌机床都已执行了动态调度
                     if(upDeviceTypes.size()>0){
                         //获取可以去允许机床品牌的任务,并按时间升序获取等待时间最长任务
@@ -164,7 +173,6 @@ public class AsyncServiceImpl implements AsyncService {
                                     dyChangedInfo.put("time", DateUtil.formatTime(new Date()));
 
                                     msgUtil.redis_set(DemoLineConstant.DEMOLINE_RESOURCE_DY_CHANGE + "_" + runTask.getId(), dyChangedInfo.toJSONString(), 1, TimeUnit.DAYS);
-                                    msgUtil.redis_del(YunjianConstant.YUNJIAN_XBK_SCHEDULE);
                                 }
                             });
                         }
@@ -173,8 +181,8 @@ public class AsyncServiceImpl implements AsyncService {
                 }
             }
 
-
         }
+        msgUtil.redis_del(YunjianConstant.YUNJIAN_XBK_SCHEDULE);
         return true;
     }
 }

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

@@ -842,13 +842,18 @@ public class RobotNodeServiceImpl implements NodeOperationService {
                         Storge hcwStorge = (Storge)msgUtil.redis_get(DemoCacheKey.YUNJIAN_CAMP + "_" + YunjianConstant.YUNJIAN_HCW + taskNode.getId());
 
                         String uploadInfo = msgUtil.redis_get(DemoLineConstant.DEMOLINE_HEIDENHAIN_FILE_URL+"_"+task.getId())!=null? msgUtil.redis_get(DemoLineConstant.DEMOLINE_HEIDENHAIN_FILE_URL+"_"+task.getId()).toString(): null;
+                        Productionresource productionresource =  productionresourceBizMapper.selectOne(Wraps.<Productionresource>lbQ().eq(Productionresource::getId,taskNode.getTargetResourceId()));
                         if(StringUtils.isNotEmpty(uploadInfo)){
                             JSONObject jsonObject  = JSONObject.parseObject(uploadInfo);
                             //异步发送哈默预处理编号
                             boolean bool = this.asyncPost(jsonObject);
-                            //if(bool){
-                            //    msgUtil.redis_del(DemoLineConstant.DEMOLINE_HEIDENHAIN_FILE_URL+"_"+task.getId());
-                            //}
+                        }else if(currentOrder.getSingleTaskFlag().equals("1") && productionresource.getModeSpecification().equals("HEIDENHAIN")){
+                            JSONObject jsonObject = new JSONObject();
+                            jsonObject.put("url", productionresource.getIp());
+                            jsonObject.put("port", productionresource.getPort());
+                            String defaultFileName = this.storagePath+"/common/2.h";
+                            jsonObject.put("fileName", defaultFileName.replace("/", "\\"));
+                            boolean bool = this.asyncPost(jsonObject);
                         }
 
                         Map locationMap = new HashMap();
@@ -885,6 +890,9 @@ public class RobotNodeServiceImpl implements NodeOperationService {
                                         fileList.add(m);
                                     });
                                     locationMap.put("fileName",fileList.get(0).get("fileName"));
+                                }else{
+                                    //线内自定义订单执行默认程序
+                                    locationMap.put("fileName","1");
                                 }
                             }
                         }

+ 7 - 1
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/externalApi/SynProductionStatus.java

@@ -26,6 +26,7 @@ import com.github.zuihou.business.productionReadyCenter.service.AAutoNodeLogServ
 import com.github.zuihou.business.productionReadyCenter.service.BomProcedureProductionresourceService;
 import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourceBizMapper;
 import com.github.zuihou.business.productionResourceCenter.entity.ProductionresourcePosition;
+import com.github.zuihou.business.productionResourceCenter.service.AsyncService;
 import com.github.zuihou.business.productionResourceCenter.service.ProductionresourcePositionService;
 import com.github.zuihou.business.util.CommonUtil;
 import com.github.zuihou.business.util.MsgUtil;
@@ -45,6 +46,7 @@ import org.apache.commons.compress.utils.Lists;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.time.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -96,6 +98,8 @@ public class SynProductionStatus {
     private MsgUtil msgUtil;
     @Autowired
     private BomProcedureProductionresourceService bomProcedureProductionresourceService;
+    @Autowired
+    private AsyncService asyncService;
 
     @ApiOperation(value = "设备状态同步", notes = "设备状态同步")
     @PostMapping("/synProductionStatus")
@@ -162,6 +166,7 @@ public class SynProductionStatus {
             String xbkSchedule = msgUtil.redis_get(YunjianConstant.YUNJIAN_XBK_SCHEDULE)!=null? msgUtil.redis_get(YunjianConstant.YUNJIAN_XBK_SCHEDULE).toString() : null;
             if(StringUtils.isEmpty(xbkSchedule)){
                 msgUtil.redis_set(YunjianConstant.YUNJIAN_XBK_SCHEDULE, YunjianConstant.YUNJIAN_XBK_SCHEDULE);
+                asyncService.asyncTaskSchedule();
             }
         }
         return R.success();
@@ -171,7 +176,7 @@ public class SynProductionStatus {
      * 处理线边库设备调度
      *
      */
-    @Scheduled(cron="0 0/1 * * * ?")
+    //@Scheduled(cron="0 0/1 * * * ?")
     public void runTaskSchedule(){
         String xbkSchedule = msgUtil.redis_get(YunjianConstant.YUNJIAN_XBK_SCHEDULE)!=null? msgUtil.redis_get(YunjianConstant.YUNJIAN_XBK_SCHEDULE).toString() : null;
         if(StringUtils.isNotEmpty(xbkSchedule)){
@@ -184,6 +189,7 @@ public class SynProductionStatus {
      * 上下料站任务权限自动调整
      *
      */
+    @Async
     public void taskSchedule(){
         log.warn("[线边库加工设备重调度]");
         LbqWrapper<com.github.zuihou.business.productionResourceCenter.entity.Productionresource> lbqWrapper = new LbqWrapper<com.github.zuihou.business.productionResourceCenter.entity.Productionresource>();