|
@@ -3,9 +3,13 @@ package com.fjhx.mes.service.production.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.alibaba.fastjson2.JSONWriter;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.common.enums.PushBusinessTypeEnum;
|
|
|
import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.customer.entity.customer.po.Customer;
|
|
@@ -33,19 +37,25 @@ import com.fjhx.mes.service.work.WorkOrderProductionProcessesService;
|
|
|
import com.fjhx.mes.service.work.WorkOrderService;
|
|
|
import com.fjhx.socket.core.PushTypeEnum;
|
|
|
import com.fjhx.socket.core.WebSocketPush;
|
|
|
+import com.fjhx.socket.core.WebSocketServer;
|
|
|
+import com.fjhx.socket.core.event.WebSocketOnMessageEvent;
|
|
|
+import com.fjhx.socket.core.event.WebSocketOnOpenEvent;
|
|
|
import com.fjhx.wms.entity.stock.emums.StockWaitType;
|
|
|
import com.fjhx.wms.entity.stock.po.StockWait;
|
|
|
import com.fjhx.wms.entity.stock.po.StockWaitDetails;
|
|
|
import com.fjhx.wms.service.stock.StockWaitDetailsService;
|
|
|
import com.fjhx.wms.service.stock.StockWaitService;
|
|
|
+import com.ruoyi.common.annotation.TenantIgnore;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.common.utils.wrapper.SqlField;
|
|
|
import com.ruoyi.system.utils.UserUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
@@ -648,4 +658,52 @@ public class ProductionTaskDetailServiceImpl extends ServiceImpl<ProductionTaskD
|
|
|
return productionTaskDetailVo;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户连接websock监听
|
|
|
+ */
|
|
|
+ @EventListener
|
|
|
+ @TenantIgnore
|
|
|
+ public void webSocketOnOpenEvent(WebSocketOnOpenEvent webSocketOnOpenEvent) {
|
|
|
+ WebSocketServer webSocketServer = webSocketOnOpenEvent.getWebSocketServer();
|
|
|
+ sendTaskCount(webSocketServer);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户收到websock消息监听
|
|
|
+ */
|
|
|
+ @EventListener
|
|
|
+ @TenantIgnore
|
|
|
+ public void webSocketOnMessageEvent(WebSocketOnMessageEvent webSocketOnMessageEvent) {
|
|
|
+ WebSocketServer webSocketServer = webSocketOnMessageEvent.getWebSocketServer();
|
|
|
+ String message = webSocketOnMessageEvent.getMessage();
|
|
|
+ JSONObject json = JSONObject.parseObject(message);
|
|
|
+ if (ObjectUtil.isNotEmpty(json.get("getTaskCount"))) {
|
|
|
+ sendTaskCount(webSocketServer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送用户任务数
|
|
|
+ */
|
|
|
+ void sendTaskCount(WebSocketServer webSocketServer) {
|
|
|
+ Long userId = webSocketServer.getUserId();
|
|
|
+
|
|
|
+ IWrapper<ProductionTaskDetail> wrapper = IWrapper.getWrapper();
|
|
|
+ wrapper.eq("ptpd.user_id", userId);
|
|
|
+ wrapper.eq("ptd.finish_status", 0);
|
|
|
+
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.MES);
|
|
|
+ Long userTaskCount = baseMapper.getUserTaskCount(wrapper);
|
|
|
+ DynamicDataSourceContextHolder.clear();
|
|
|
+
|
|
|
+ JSONObject msg = new JSONObject();
|
|
|
+ msg.put("taskCount", userTaskCount);
|
|
|
+ try {
|
|
|
+ webSocketServer.getSession().getBasicRemote().sendText(msg.toJSONString(JSONWriter.Feature.WriteLongAsString));
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|