1
0

4 Commits 6798216d09 ... 1a3826bf7e

Autor SHA1 Nachricht Datum
  zhifei 1a3826bf7e 优化PDA补码接口 vor 1 Jahr
  zhifei dead61c572 完善报警 vor 1 Jahr
  zhifei c3265dc571 添加PDA补码接口 vor 1 Jahr
  zhifei 65d9cb5be0 websocket添加心跳 vor 1 Jahr

+ 11 - 7
warewms-system/src/main/java/com/warewms/hailiang/config/DeviceMessageSocket.java

@@ -1,5 +1,6 @@
 package com.warewms.hailiang.config;
 
+import cn.hutool.json.JSONObject;
 import com.warewms.common.annotation.Anonymous;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
@@ -13,13 +14,13 @@ import java.util.concurrent.CopyOnWriteArraySet;
 @Component
 @Slf4j
 @Anonymous
-@ServerEndpoint("/websocket/device/{userName}")  // 接口路径 ws://localhost:8080/device/userName;
+@ServerEndpoint("/websocket/device/{index}")  // 接口路径 ws://localhost:8080/device/userName;
 public class DeviceMessageSocket {
     //与某个客户端的连接会话,需要通过它来给客户端发送数据
     private Session session;
 
 
-    private String userName;
+    private String index;
 
 
     private static CopyOnWriteArraySet<DeviceMessageSocket> webSockets =new CopyOnWriteArraySet<>();
@@ -31,12 +32,12 @@ public class DeviceMessageSocket {
      * 链接成功调用的方法
      */
     @OnOpen
-    public void onOpen(Session session, @PathParam(value="userName")String userName) {
+    public void onOpen(Session session, @PathParam(value="index")String index) {
         try {
             this.session = session;
-            this.userName = userName;
+            this.index = index;
             webSockets.add(this);
-            sessionPool.put(userName, session);
+            sessionPool.put(index, session);
             log.info("【websocket消息】有新的连接,总数为:"+webSockets.size());
         } catch (Exception e) {
         }
@@ -49,7 +50,7 @@ public class DeviceMessageSocket {
     public void onClose() {
         try {
             webSockets.remove(this);
-            sessionPool.remove(this.userName);
+            sessionPool.remove(this.index);
         } catch (Exception e) {
         }
     }
@@ -62,6 +63,10 @@ public class DeviceMessageSocket {
     @OnMessage
     public void onMessage(String message) {
         log.info("【websocket消息】收到客户端消息:"+message);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.set("type","heartbeat");
+        jsonObject.set("content","ok");
+        sendOneMessage(message,jsonObject.toString());
     }
 
     /** 发送错误时的处理
@@ -70,7 +75,6 @@ public class DeviceMessageSocket {
      */
     @OnError
     public void onError(Session session, Throwable error) {
-
         log.error("用户错误,原因:"+error.getMessage());
         error.printStackTrace();
     }

+ 8 - 5
warewms-system/src/main/java/com/warewms/hailiang/contoller/RetroactiveNowController.java

@@ -11,10 +11,8 @@ import com.warewms.hailiang.domain.RetroactiveNow;
 import com.warewms.hailiang.service.DeviceLogService;
 import com.warewms.hailiang.service.RetroactiveNowService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -52,8 +50,13 @@ public class RetroactiveNowController {
         return R.ok(retroactiveNowService.selectTheOneByParameter(retroactiveNow));
     }
 
+    /**
+     * PDA补码接口
+     * @param retroactiveNow
+     * @return
+     */
     @PostMapping("/pda/complement")
-    public R complement(RetroactiveNow retroactiveNow){
+    public R complement(@Validated @RequestBody RetroactiveNow retroactiveNow){
         return retroactiveNowService.complement(retroactiveNow);
     }
 }

+ 24 - 0
warewms-system/src/main/java/com/warewms/hailiang/contoller/TestContoller.java

@@ -1,5 +1,11 @@
 package com.warewms.hailiang.contoller;
 
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.warewms.common.annotation.Anonymous;
+import com.warewms.common.core.domain.R;
+import com.warewms.hailiang.config.DeviceMessageSocket;
+import com.warewms.hailiang.domain.DeviceLog;
 import com.warewms.hailiang.init.PlcConnectServiceRunner;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -22,6 +28,9 @@ public class TestContoller {
     @Autowired
     PlcConnectServiceRunner plcConnectServiceRunner;
 
+    @Autowired
+    DeviceMessageSocket deviceMessageSocket;
+
     @GetMapping("/pclTest")
     public Object testPlc(String plcName,String db,String type,String value){
         if (type.equals("1")){
@@ -70,4 +79,19 @@ public class TestContoller {
     public Object getStatus(String plcName){
         return plcConnectServiceRunner.getPlcServer(plcName).checkConnected();
     }
+
+    @GetMapping("/testNotify")
+    @Anonymous
+    public R testNotify(String content,String status) throws InterruptedException {
+        Thread.sleep(3000);
+        DeviceLog deviceLog = new DeviceLog("1","倒角读码器",content,status);
+        deviceLog.setCreateBy("system");
+        deviceLog.setUpdateBy("system");
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.set("type","notify");
+        jsonObject.set("content",JSONUtil.parse(deviceLog));
+        //推送消息
+        deviceMessageSocket.sendAllMessage(jsonObject.toString());
+        return R.ok();
+    }
 }

+ 5 - 0
warewms-system/src/main/java/com/warewms/hailiang/domain/RetroactiveNow.java

@@ -10,6 +10,8 @@ import com.warewms.common.core.domain.base.BaseEntity;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import javax.validation.constraints.NotBlank;
+
 /**
  * 生产追溯表
  * @TableName retroactive_now
@@ -27,6 +29,7 @@ public class RetroactiveNow extends BaseEntity {
     /**
      * 产线
      */
+    @NotBlank(message = "产线不能为空!")
     private String productionLine;
 
     /**
@@ -47,11 +50,13 @@ public class RetroactiveNow extends BaseEntity {
     /**
      * 生产状态
      */
+    @NotBlank(message = "生产状态不能为空!")
     private String status;
 
     /**
      * 设备编号
      */
+    @NotBlank(message = "设备编号不能为空!")
     private String deviceId;
 
 

+ 17 - 1
warewms-system/src/main/java/com/warewms/hailiang/service/impl/DeviceLogServiceImpl.java

@@ -1,6 +1,9 @@
 package com.warewms.hailiang.service.impl;
 
 
+import cn.hutool.json.JSON;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -8,9 +11,11 @@ import com.warewms.common.core.domain.base.page.PageDomain;
 import com.warewms.common.core.domain.base.page.TableDataInfo;
 import com.warewms.common.utils.StringUtils;
 import com.warewms.hailiang.config.DeviceMessageSocket;
+import com.warewms.hailiang.domain.Device;
 import com.warewms.hailiang.domain.DeviceLog;
 import com.warewms.hailiang.mapper.DeviceLogMapper;
 import com.warewms.hailiang.service.DeviceLogService;
+import com.warewms.hailiang.service.DeviceService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.event.EventListener;
 import org.springframework.scheduling.annotation.Async;
@@ -31,6 +36,9 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
     @Autowired
     DeviceLogMapper deviceLogMapper;
 
+    @Autowired
+    DeviceService deviceService;
+
     @Autowired
     DeviceMessageSocket deviceMessageSocket;
 
@@ -56,7 +64,15 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
         deviceLog.setUpdateBy("system");
         deviceLogMapper.insert(deviceLog);
         //推送消息
-        deviceMessageSocket.sendAllMessage(deviceLog.toString());
+        for (Device device : deviceService.getList()) {
+            if (device.getDeviceId().equals(deviceLog.getDeviceId())){
+                deviceLog.setDeviceName(device.getAbbreviation());
+            }
+        }
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.set("type","notify");
+        jsonObject.set("content",JSONUtil.parse(deviceLog));
+        deviceMessageSocket.sendAllMessage(jsonObject.toString());
     }
 
 }

+ 50 - 21
warewms-system/src/main/java/com/warewms/hailiang/service/impl/RetroactiveNowServiceImpl.java

@@ -7,8 +7,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.warewms.common.core.domain.R;
 import com.warewms.common.core.domain.base.page.PageDomain;
 import com.warewms.common.core.domain.base.page.TableDataInfo;
+import com.warewms.common.core.domain.model.LoginUser;
 import com.warewms.common.exception.ServiceException;
+import com.warewms.common.utils.SecurityUtils;
 import com.warewms.common.utils.StringUtils;
+import com.warewms.hailiang.MES.MesService;
 import com.warewms.hailiang.domain.RetroactiveHistory;
 import com.warewms.hailiang.domain.RetroactiveNow;
 import com.warewms.hailiang.mapper.RetroactiveHistoryMapper;
@@ -39,6 +42,9 @@ public class RetroactiveNowServiceImpl extends ServiceImpl<RetroactiveNowMapper,
     @Autowired
     private RetroactiveHistoryMapper retroactiveHistoryMapper;
 
+    @Autowired
+    private MesService mesService;
+
     @Override
     public TableDataInfo<RetroactiveNow> getList(RetroactiveNow retroactiveNow, PageDomain pageDomain, List<String> inStatus) {
         Map<String, Object> params = retroactiveNow.getParams();
@@ -75,16 +81,7 @@ public class RetroactiveNowServiceImpl extends ServiceImpl<RetroactiveNowMapper,
     @Override
     @Transactional
     public int updateData(RetroactiveNow retroactiveNow) {
-        RetroactiveNow baseData = retroactiveNowMapper.selectOne(new LambdaQueryWrapper<RetroactiveNow>()
-                .eq(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
-                .eq(StringUtils.isNotEmpty(retroactiveNow.getLotNo()), RetroactiveNow::getLotNo, retroactiveNow.getLotNo())
-        );
-        if (ObjectUtil.isNull(baseData)) {
-            throw new ServiceException("数据库中不存在该批次号或托盘号," + retroactiveNow.getBatchNo() + "," + retroactiveNow.getLotNo());
-        }
-        if (baseData.getStatus().equals(retroactiveNow.getStatus())) {
-            throw new ServiceException("数据库存在该状态相同批次号或托盘号的数据");
-        }
+        RetroactiveNow baseData = confirmTheDataByIndex(retroactiveNow);
         baseData.setStatus(retroactiveNow.getStatus());
         baseData.setDeviceId(retroactiveNow.getDeviceId());
         baseData.setUpdateBy("system");
@@ -98,16 +95,7 @@ public class RetroactiveNowServiceImpl extends ServiceImpl<RetroactiveNowMapper,
     @Override
     @Transactional
     public int finishProduce(RetroactiveNow retroactiveNow) {
-        RetroactiveNow baseData = retroactiveNowMapper.selectOne(new LambdaQueryWrapper<RetroactiveNow>()
-                .eq(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
-                .eq(StringUtils.isNotEmpty(retroactiveNow.getLotNo()), RetroactiveNow::getLotNo, retroactiveNow.getLotNo())
-        );
-        if (ObjectUtil.isNull(baseData)) {
-            throw new ServiceException("数据库中不存在该批次号或托盘号," + retroactiveNow.getBatchNo() + "," + retroactiveNow.getLotNo());
-        }
-        if (baseData.getStatus().equals(retroactiveNow.getStatus())) {
-            throw new ServiceException("数据库存在该状态相同批次号或托盘号的数据");
-        }
+        RetroactiveNow baseData = confirmTheDataByIndex(retroactiveNow);
         baseData.setStatus(retroactiveNow.getStatus());
         baseData.setDeviceId(retroactiveNow.getDeviceId());
         baseData.setUpdateBy("system");
@@ -118,8 +106,49 @@ public class RetroactiveNowServiceImpl extends ServiceImpl<RetroactiveNowMapper,
     }
 
     @Override
+    @Transactional
     public R complement(RetroactiveNow retroactiveNow) {
-        return null;
+        RetroactiveNow baseData = confirmTheDataByIndex(retroactiveNow);
+        if ("2".equals(baseData.getStatus())){
+            mesService.getBatchNoResult(retroactiveNow.getBatchNo(), true);
+        }
+        if ("3".equals(baseData.getStatus())){
+            mesService.processFeedback(retroactiveNow.getBatchNo(),"1");
+        }
+        if ("4".equals(baseData.getStatus())){
+            mesService.processFeedback(retroactiveNow.getBatchNo(),"2");
+        }
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        baseData.setStatus(retroactiveNow.getStatus());
+        baseData.setDeviceId("PDA");
+        baseData.setUpdateBy(loginUser.getUsername());
+        baseData.setRemark("PDA手动补码");
+        if(Integer.parseInt(retroactiveNow.getStatus())>Integer.parseInt(baseData.getStatus())){
+            retroactiveNowMapper.updateById(baseData);
+        }
+        baseData.setCreateBy(loginUser.getUsername());
+        if (ObjectUtil.isNull(retroactiveNow.getCreateTime())){
+            throw new ServiceException("工序完成时间为空!");
+        }
+        baseData.setCreateTime(retroactiveNow.getCreateTime());
+        RetroactiveHistory retroactiveHistory = BeanUtil.copyProperties(baseData, RetroactiveHistory.class);
+        retroactiveHistory.setCreateTime(baseData.getUpdateTime());
+        retroactiveHistoryMapper.insert(retroactiveHistory);
+        return R.ok();
+    }
+
+    private RetroactiveNow confirmTheDataByIndex(RetroactiveNow retroactiveNow) {
+        RetroactiveNow baseData = retroactiveNowMapper.selectOne(new LambdaQueryWrapper<RetroactiveNow>()
+                .eq(StringUtils.isNotEmpty(retroactiveNow.getBatchNo()), RetroactiveNow::getBatchNo, retroactiveNow.getBatchNo())
+                .eq(StringUtils.isNotEmpty(retroactiveNow.getLotNo()), RetroactiveNow::getLotNo, retroactiveNow.getLotNo())
+        );
+        if (ObjectUtil.isNull(baseData)) {
+            throw new ServiceException("数据库中不存在该批次号或托盘号," + retroactiveNow.getBatchNo() + "," + retroactiveNow.getLotNo());
+        }
+        if (baseData.getStatus().equals(retroactiveNow.getStatus())) {
+            throw new ServiceException("数据库存在该状态相同批次号或托盘号的数据");
+        }
+        return baseData;
     }
 }