Sfoglia il codice sorgente

fix:修改mes任务接受数据

wang.sq@aliyun.com 1 mese fa
parent
commit
483e4b5c14

+ 46 - 13
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/externalApi/service/impl/MesNoticeServiceImpl.java

@@ -36,10 +36,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -168,22 +165,56 @@ public class MesNoticeServiceImpl extends SuperServiceImpl<MesNoticeMapper, MesN
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public boolean addNoticeMore(List<MesNotice> models) {
-        baseMapper.insertBatchSomeColumn(models);
-        
-        List<MesNoticeLog> mesNoticeLogs = new ArrayList<>();
+    public String addNoticeMore(List<MesNotice> models) {
+        StringBuffer existMsg = new StringBuffer();
+        List<MesNotice> needAddMesNotice = new ArrayList<>();
+
         for (MesNotice model : models) {
-            MesNoticeLog build = MesNoticeLog.builder().build();
+            MesNotice mesNotice = baseMapper.selectOne(Wraps.<MesNotice>lbQ().eq(MesNotice::getCheckPar, model.getCheckPar()));
+            if(mesNotice ==null){
+                MesNotice newModel = new MesNotice();
+                BeanUtils.copyProperties(model, newModel);
+                needAddMesNotice.add(newModel);
+            }else if("1".equals(mesNotice.getStatus())) {
+                model.setId(mesNotice.getId());
+                existMsg.append("\n此订单已存在:"+ model.getOrderNo());
+            }else {
+                existMsg.append("\n此订单已存在:"+ model.getOrderNo());
+            }
+        }
 
+        // 新增
+        if(!needAddMesNotice.isEmpty()){
+            baseMapper.insertBatchSomeColumn(needAddMesNotice);
+        }
+
+        List<MesNoticeLog> mesNoticeLogs = new ArrayList<>();
+        // 新增的数据添加日志
+        for (MesNotice  model: needAddMesNotice) {
+            MesNoticeLog build = MesNoticeLog.builder().build();
             BeanUtils.copyProperties(model, build);
             build.setNoticeId(model.getId());
             build.setId(null);
+            mesNoticeLogs.add(build);
+        }
 
+        // 已存在只增加日志
+        for (MesNotice model : models) {
+            if(model.getId()==null){
+                continue;
+            }
+            MesNoticeLog build = MesNoticeLog.builder().build();
+            BeanUtils.copyProperties(model, build);
+            build.setNoticeId(model.getId());
+            build.setId(null);
+            build.setStatus("6");// 对已经接受过的,只增加日志,
             mesNoticeLogs.add(build);
         }
-        mesNoticeLogMapper.insertBatchSomeColumn(mesNoticeLogs);
-        
-        return true;
+
+        if(!mesNoticeLogs.isEmpty()){
+            mesNoticeLogMapper.insertBatchSomeColumn(mesNoticeLogs);
+        }
+        return (existMsg==null || existMsg.toString().isEmpty())? "成功": ("部分成功;"+existMsg);
     }
 
 
@@ -191,7 +222,8 @@ public class MesNoticeServiceImpl extends SuperServiceImpl<MesNoticeMapper, MesN
     @Override
     public boolean addNotice(MesNotice model, double plmenge) {
         BaseContextHandler.setTenant("0000");
-        if (checkExists(model)) {
+        MesNotice mesNotice = baseMapper.selectOne(Wraps.<MesNotice>lbQ().eq(MesNotice::getCheckPar, model.getCheckPar()));
+        if (!Objects.isNull(mesNotice)) {
             MesNotice data = baseMapper.selectOne(new LbqWrapper<MesNotice>().eq(MesNotice::getOrderNo, model.getOrderNo()).ne(MesNotice::getStatus, "3").eq(MesNotice::getBuType, model.getBuType()).last("limit 1"));
             if(data == null) throw new BizException("数据有误,此任务已经为完成状态");
             String num = null;
@@ -252,6 +284,7 @@ public class MesNoticeServiceImpl extends SuperServiceImpl<MesNoticeMapper, MesN
         return true;
     }
 
+
     @Override
     public boolean checkExists(MesNotice model){
         Integer integer = baseMapper.selectCount(Wraps.<MesNotice>lbQ().eq(MesNotice::getOrderNo, model.getOrderNo()).eq(MesNotice::getBuType, model.getBuType()));

+ 19 - 1
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/impl/TaskNodeServiceImpl.java

@@ -1564,6 +1564,8 @@ public class TaskNodeServiceImpl extends SuperServiceImpl<TaskNodeMapper, TaskNo
         // 当前任务节点
         TaskNode taskNode = null;
 
+        R returnMsg = null;
+
         try {
             log.info("[CCS指令回调]回调参数======================" + JSONObject.toJSONString(bean));
             //取出参数
@@ -1739,7 +1741,23 @@ public class TaskNodeServiceImpl extends SuperServiceImpl<TaskNodeMapper, TaskNo
             }
             msgUtil.redis_del(repeatKey);
 
+            returnMsg = R.success();
+        }catch (NullPointerException nullex){
+            returnMsg = R.fail("回调时出错:"+nullex.getMessage());
+            nullex.printStackTrace();
+            // 删除重复调用,日志修改位异常状态
+            msgUtil.redis_del(repeatKey);
+            lg.setExeStatus("2");
+            lg.setExeResult("0");
+            lg.setFeedback("回调时出错"+ nullex);
+            autoNodeLogMapper.updateAllById(lg);
+
+            taskNode.setExeStatus("2").setExeResult("0").setEndTime(new Date());
+            updateAllById(taskNode);
+
+            throw new Exception(nullex);
         }catch (Exception e){
+            returnMsg = R.fail("回调时出错:"+e.getMessage());
             e.printStackTrace();
             // 删除重复调用,日志修改位异常状态
             msgUtil.redis_del(repeatKey);
@@ -1753,7 +1771,7 @@ public class TaskNodeServiceImpl extends SuperServiceImpl<TaskNodeMapper, TaskNo
 
             throw new Exception(e);
         }
-        return R.success();
+        return returnMsg;
     }
 
 

+ 1 - 1
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/MesNoticeService.java

@@ -26,7 +26,7 @@ public interface MesNoticeService extends SuperService<MesNotice> {
     IPage<MesNotice> pageList(IPage page, @Param(Constants.WRAPPER) Wrapper<MesNotice> queryWrapper);
 
     //批量新增
-   boolean addNoticeMore(List<MesNotice> models);
+   String addNoticeMore(List<MesNotice> models);
    boolean addNotice(MesNotice model, double plmenge);
 
 

+ 77 - 54
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/externalApi/MesController.java

@@ -109,35 +109,90 @@ public class MesController extends SuperController<MesNoticeService, Long, MesNo
     @Value("${mes-auto-post.enabled:false}")
     private Boolean autoPostEnable;
 
+    @ApiOperation(value = "任务下发通知接口", notes = "任务下发通知接口")
+    @PostMapping("/externalApi/order/addMes")
+    public R addNotice(@RequestBody List<JSONObject> list) {
+        log.info("================接受外部系统任务开始================{}", JSONObject.toJSONString(list));
+        for (JSONObject jsonObject : list) {
+            jsonObject.put("taskType","MES");
+        }
+        R r = this.uniformlyHandleTasks(list);
+        log.info("================接受外部系统任务结束================{}", JSONObject.toJSONString(r));
+        return r;
+    }
 
     @ApiOperation(value = "接受质检任务下发通知接口", notes = "接受质检任务下发通知接口")
     @PostMapping("/externalApi/measuringTaskReceive")
     public R addQualityToNotice(@RequestBody String data) {
         log.info("==============接受质检任务下发通知接口开始================={}", data);
-        ThreeCoordinateDto threeCoordinateDto = JSONObject.parseObject(data, ThreeCoordinateDto.class);
+        List<JSONObject> list = new ArrayList<>();
+        list.add(JSONObject.parseObject(data));
+        for (JSONObject jsonObject : list) {
+            jsonObject.put("taskType","SQ");
+        }
+        R r = this.uniformlyHandleTasks(list);
+        log.info("================接受外部系统任务结束================{}", JSONObject.toJSONString(r));
+        return r;
+    }
 
+    @ApiOperation(value = "外部接口统一处理", notes = "外部接口统一处理")
+    @PostMapping("/externalApi/uniformlyHandleTasks")
+    public R uniformlyHandleTasks(List<JSONObject> listPar){
+        R<Boolean> returnMsg = null;
+        BaseContextHandler.setTenant("0000");
+        if(listPar.size()==0){
+            returnMsg = R.fail("数据不能为空");
+        }
 
-        MesNotice mesNotice = MesNotice.builder().orderNo(threeCoordinateDto.getTaskCode()+"_"+threeCoordinateDto.getProcessCode()+"_"+threeCoordinateDto.getPartOrder()).
-                buType("TASKDISTRIBUTE").
-                apiType("QUALITYTASK").
-                lineCode("407109").
-                status("1").
-                userCode(threeCoordinateDto.getUserCode()).
-                batchNo(threeCoordinateDto.getBatchNo()).
-                source("数字化检测系统").
-                targetSource("产线管控单元").
-                acceptPar(data).build();
-        try {
-            boolean b = baseService.addNotice(mesNotice, 1.0);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return R.fail(e.getMessage());
+        // 重复数据校验
+        List<MesNotice> dataList = Lists.newArrayList();
+        try{
+            JSONObject checkJson = listPar.get(0);
+            switch (checkJson.getString("taskType")){
+                case "MES":
+                    for (JSONObject jsonObject : listPar) {
+                        String checkPar = "407109&TASKDISTRIBUTE&MESTASK&"+jsonObject.getString("auidnr")+"&"+jsonObject.getString("afonr")+"&"+jsonObject.getString("sno");
+                        MesNotice mesNotice = MesNotice.builder().orderNo(jsonObject.getString("auidnr")).userCode(jsonObject.getString("userno")).batchNo(jsonObject.getString("batchno")).
+                                buType("TASKDISTRIBUTE").lineCode("407109").status("1").source("智能总控系统").apiType("MESTASK").apiSort(jsonObject.getInteger("prio"))
+                                .targetSource("产线管控单元").acceptPar(jsonObject.toJSONString()).checkPar(checkPar).build();
+                        dataList.add(mesNotice);
+                    }
+                    break;
+                case "SQ":
+                    for (JSONObject jsonObject : listPar) {
+                        ThreeCoordinateDto threeCoordinateDto = JSONObject.parseObject(JSONObject.toJSONString(jsonObject), ThreeCoordinateDto.class);
+                        String checkPar = "407109&TASKDISTRIBUTE&QUALITYTASK&"+threeCoordinateDto.getOrderNumber()+"&"+threeCoordinateDto.getProcessCode()+"&"+threeCoordinateDto.getPartOrder();
+
+                        MesNotice mesNotice = MesNotice.builder().orderNo(threeCoordinateDto.getTaskCode()+"_"+threeCoordinateDto.getProcessCode()+"_"+threeCoordinateDto.getPartOrder()).
+                                buType("TASKDISTRIBUTE").apiType("QUALITYTASK"). lineCode("407109"). status("1").  userCode(threeCoordinateDto.getUserCode()).
+                                batchNo(threeCoordinateDto.getBatchNo()). source("数字化检测系统"). targetSource("产线管控单元").
+                                acceptPar(JSONObject.toJSONString(jsonObject)).checkPar(checkPar).build();
+
+                        dataList.add(mesNotice);
+                    }
+                    break;
+                default:
+                    returnMsg = R.fail("没有识别到对应类型的业务");
+            }
+
+            if(!dataList.isEmpty() && dataList.size()>0){
+                // 新增
+                String s = baseService.addNoticeMore(dataList);
+                returnMsg = R.success(null,s);
+            }
+
+        }catch (Exception ex){
+            ex.printStackTrace();
+            log.info("处理外部任务报错,{}", ex);
+            returnMsg = R.fail("处理任务失败:"+ ex.getMessage());
         }
 
-        log.info("==============接受质检任务下发通知接口结束=================");
-        return R.success();
+        return returnMsg;
     }
 
+
+
+
     @ApiOperation(value = "质检结果上报", notes = "质检结果上报")
     @PostMapping("/externalApi/qualityResultReport")
     public R QualityResultReport(@RequestBody JSONObject params) {
@@ -331,41 +386,7 @@ public class MesController extends SuperController<MesNoticeService, Long, MesNo
 
     }
 
-    @ApiOperation(value = "任务下发通知接口", notes = "任务下发通知接口")
-    @PostMapping("/externalApi/order/addMes")
-    public R addNotice(@RequestBody JSONArray jsonArray) {
-        log.info("================addMes接受上游系统的任务================");
-        BaseContextHandler.setTenant("0000");
-        log.info("任务数据{}", jsonArray.toJSONString());
-        try {
-            //JSONArray jsonArray = JSONArray.parseArray(data.toString());
-            List<MesNotice> dataList = Lists.newArrayList();
-            StringBuilder stringBuilder = new StringBuilder();
-            jsonArray.stream().forEach(item -> {
-                JSONObject jsonObject = (JSONObject) JSONObject.toJSON(item);
-                MesNotice mesNotice = MesNotice.builder().orderNo(jsonObject.getString("auidnr")).userCode(jsonObject.getString("userno")).batchNo(jsonObject.getString("batchno")).
-                        buType("TASKDISTRIBUTE").lineCode("407109").status("1").source("智能总控系统").apiType("MESTASK").apiSort(jsonObject.getInteger("prio"))
-                        .targetSource("产线管控单元").acceptPar(jsonObject.toJSONString()).build();
-                if (!baseService.checkExists(mesNotice)) {
-                    dataList.add(mesNotice);
-                } else {
-                    stringBuilder.append("订单号:" + jsonObject.getString("auidnr"));
-                }
-            });
 
-            if (dataList != null && dataList.size() > 0) {
-                boolean b = baseService.addNoticeMore(dataList);
-            }
-            if (stringBuilder.length() > 0) {
-                throw new BizException(stringBuilder.toString() + "订单已存在");
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-            return R.fail(e.getMessage());
-        }
-        log.info("================接受上游系统的任务结束================");
-        return R.success();
-    }
 
     @ApiOperation(value = "工序报工接口", notes = "工序报工接口")
     @PostMapping("/externalApi/order/mesProcessReport")
@@ -992,6 +1013,7 @@ public class MesController extends SuperController<MesNoticeService, Long, MesNo
         String partsNo = null;
         String batchNo = null;
         String partName = null; // 零件名称
+        String processName = null;
         String externalTaskCode = null;
         List<Object> taskList = null;
         List<Object> workPieceList = null;
@@ -1000,6 +1022,7 @@ public class MesController extends SuperController<MesNoticeService, Long, MesNo
             //处理质检任务信息
             JSONObject dataInfo = (qualityInfo != null) ? qualityInfo : mesInfo;
             processNo = (qualityInfo != null) ? dataInfo.getString("ProcessCode") : dataInfo.getString("afonr");
+            processName = (qualityInfo != null) ? dataInfo.getString("bez") : dataInfo.getString("bez");
             workOrderNo = (qualityInfo != null) ? dataInfo.getString("OrderNumber") : dataInfo.getString("auidnr");
             batchNo = (qualityInfo != null) ? dataInfo.getString("BatchNo") : dataInfo.getString("batchno");
             partName = (qualityInfo != null) ? dataInfo.getString("teilebez") : dataInfo.getString("teilebez");
@@ -1022,7 +1045,7 @@ public class MesController extends SuperController<MesNoticeService, Long, MesNo
             materialCode = StringUtil.isNotEmpty(idnr) ? idnr : mMeterial.getMeterialCode();
             BBom bom = bBomService.getOne(new LambdaQueryWrapper<BBom>().eq(BBom::getPartsNo, drawingNo + "_V" + processNo).eq(BBom::getDrawingNo, drawingNo).eq(BBom::getSynFlag, "1"));
             if (bom == null) {
-                materialName = partName==null?  mMeterial.getTradeMark() : partName;
+                materialName = partName==null ? (processName==null ? mMeterial.getTradeMark() :processName) : partName;
                 partsNo = drawingNo + "_V" + processNo;
                 bom = BBom.builder().synFlag("1").name(materialName + "V" + processNo).batchNo(batchNo).partsNo(partsNo).partsAlias(materialCode).no(processNo).brand(workOrderNo).status("1").importantFlag("0").keyFlag("0").zoneId(zone.getId()).drawingNo(drawingNo).build();
                 bom.setMeterialId(1L);
@@ -1232,7 +1255,7 @@ public class MesController extends SuperController<MesNoticeService, Long, MesNo
                 .setStatus("1").setSingleTaskFlag(0).setOrderStatus("1").setBatchNo(workOrder.getString("batchNo")).setExternalTaskCode(workOrder.getString("externalTaskCode"));
         //产品编码+ 密级编码 + 批次号 + 工艺版本
         String orderName = "MES_" + workOrder.getString("materialCode") + "_" + workOrder.getString("planSecretLevel").toUpperCase() + "_" + workOrder.getString("batchNo") + "_" + workOrder.getString("processRouteVersion");
-        orderName = partName==null? orderName : partName +"_"+ processNo;
+        orderName = partName==null? (processName==null ? orderName :processName+"_"+processNo) : (partName +"_"+ processNo);
         order.setCustId(0L).setOrderName(orderName).setZoneId(zone.getId()).setAuditStatus("0");
         orderService.save(order);
 

+ 9 - 2
imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/externalApi/entity/MesNotice.java

@@ -99,7 +99,7 @@ public class MesNotice extends Entity<Long> {
      * 订单编号
      */
     @ApiModelProperty(value = "通知状态")
-    @Length(max = 64, message = "订单编号长度不能超过64, 0进行中,1未处理,2已下载,3完成,4暂停,5手动,99异常")
+    @Length(max = 64, message = "订单编号长度不能超过64, 0进行中,1未处理,2已下载,3完成,4暂停,5手动,6重复接受,99异常")
     @TableField(value = "status", condition = LIKE)
     @Excel(name = "通知状态")
     private String status;
@@ -149,9 +149,15 @@ public class MesNotice extends Entity<Long> {
     @Excel(name = "批次号")
     private String batchNo;
 
+    @ApiModelProperty(value = "校验参数,比对外部任务是否重复下发,如果存在则入库进行提示,并增加相关的日志")
+    @TableField(value = "check_par", condition = LIKE)
+    @Excel(name = "校验参数")
+    private String checkPar;
+
+
 
     @Builder
-    public MesNotice(Long id, LocalDateTime createTime, Long createUser, LocalDateTime updateTime, Long updateUser, String buType, String lineCode, String apiAddress, String apiType, int apiSort, String orderNo, String status, String orderInfo,String source, String targetSource, String acceptPar, String  userCode, String batchNo, String workReport) {
+    public MesNotice(Long id, LocalDateTime createTime, Long createUser, LocalDateTime updateTime, Long updateUser, String buType, String lineCode, String apiAddress, String apiType, int apiSort, String orderNo, String status, String orderInfo,String source, String targetSource, String acceptPar, String  userCode, String batchNo, String workReport, String checkPar) {
         super(id, createTime, createUser, updateTime, updateUser);
         this.id = id;
         this.buType = buType;
@@ -168,5 +174,6 @@ public class MesNotice extends Entity<Long> {
         this.userCode = userCode;
         this.batchNo = batchNo;
         this.workReport = workReport;
+        this.checkPar = checkPar;
     }
 }

+ 6 - 1
imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/externalApi/entity/MesNoticeLog.java

@@ -106,8 +106,8 @@ public class MesNoticeLog extends Entity<Long> {
      * 订单编号
      */
     @ApiModelProperty(value = "通知状态")
-    @Length(max = 64, message = "订单编号长度不能超过64")
     @TableField(value = "status", condition = LIKE)
+    @Length(max = 64, message = "订单编号长度不能超过64, 0进行中,1未处理,2已下载,3完成,4暂停,5手动,6重复接受,99异常")
     @Excel(name = "通知状态")
     private String status;
 
@@ -152,4 +152,9 @@ public class MesNoticeLog extends Entity<Long> {
     @Excel(name = "报工班表ID")
     private Long parentId;
 
+    @ApiModelProperty(value = "校验参数,比对外部任务是否重复下发,如果存在则入库进行提示,并增加相关的日志")
+    @TableField(value = "check_par", condition = LIKE)
+    @Excel(name = "校验参数")
+    private String checkPar;
+
 }