浏览代码

Mes订单请求处理

oyq28 2 周之前
父节点
当前提交
0964b7f4a6

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

@@ -75,15 +75,19 @@ public class MesNoticeServiceImpl extends SuperServiceImpl<MesNoticeMapper, MesN
     @Override
     public boolean addNotice(MesNotice model) {
         BaseContextHandler.setTenant("0000");
-        Integer integer = baseMapper.selectCount(Wraps.<MesNotice>lbQ().eq(MesNotice::getOrderNo, model.getOrderNo()).eq(MesNotice::getBuType, model.getBuType()));
-        if (integer > 0) {
+        if (checkExists(model)) {
             throw new BizException("此订单已存在");
         }
-
         baseMapper.insert(model);
         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()));
+        return integer>0? true : false;
+    }
+
     @Override
     public boolean modify(MesNotice model) {
         BaseContextHandler.setTenant("0000");

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

@@ -23,6 +23,7 @@ public interface MesNoticeService extends SuperService<MesNotice> {
     //批量新增
    boolean addNotice(MesNotice model);
 
+   boolean checkExists(MesNotice model);
 
    boolean modify(MesNotice model);
 

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

@@ -2,12 +2,14 @@ package com.github.zuihou.business.controller.externalApi;
 
 
 import cn.hutool.core.bean.BeanUtil;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baidubce.services.tsdb.model.GroupBy;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.fasterxml.jackson.databind.JsonNode;
 import com.github.zuihou.authority.service.auth.UserService;
 import com.github.zuihou.base.R;
 import com.github.zuihou.base.controller.SuperController;
@@ -38,6 +40,7 @@ import com.github.zuihou.common.util.StringUtil;
 import com.github.zuihou.context.BaseContextHandler;
 import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
 import com.github.zuihou.database.mybatis.conditions.query.QueryWrap;
+import com.github.zuihou.exception.BizException;
 import com.github.zuihou.file.biz.FileBiz;
 import com.github.zuihou.file.service.AttachmentService;
 import com.github.zuihou.log.annotation.SysLog;
@@ -249,22 +252,33 @@ public class MesController extends SuperController<MesNoticeService, Long, MesNo
 
     @ApiOperation(value = "任务下发通知接口", notes = "任务下发通知接口")
     @PostMapping("/externalApi/order/addMes")
-    public R addNotice(@RequestBody String data) {
+    public R addNotice(@RequestBody JSONArray jsonArray) {
         log.info("================addMes接受上游系统的任务================");
-
-        log.info("任务数据{}", data);
+        BaseContextHandler.setTenant("0000");
+        log.info("任务数据{}", jsonArray.toJSONString());
         try {
-           JSONObject jsonObject = JSONObject.parseObject(data);
-
-            MesNotice mesNotice = MesNotice.builder().orderNo(jsonObject.getString("auidnr")).userCode(jsonObject.getString("usercode")).
-                    buType("TASKDISTRIBUTE").lineCode("407109").status("1").source("智能总控系统").apiType("MESTASK")
-                    .targetSource("产线管控单元").acceptPar(data).build();
-            boolean b = baseService.addNotice(mesNotice);
+            //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("usercode")).
+                        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")).append("");
+                }
+            });
+            boolean b = baseService.saveBatch(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();
     }