yangys
2024-04-01 86cdd920b68274185233383f69ddb974052b6b6f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.qianwen.smartman.common.websocket.fms;
 
import cn.hutool.core.collection.ListUtil;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.qianwen.smartman.common.cache.ParamCache;
import com.qianwen.smartman.common.constant.FmsConstant;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.core.websocket.config.WebSocketMessageSender;
import com.qianwen.core.websocket.distribute.MessageDO;
import com.qianwen.core.websocket.distribute.RedisMessageDistributor;
import com.qianwen.core.websocket.handler.JsonMessageHandler;
import com.qianwen.smartman.modules.cps.service.IWarehouseAreaService;
import com.qianwen.smartman.modules.cps.service.IWorkstationService;
import com.qianwen.smartman.modules.fms.entity.FmsRealTimeTray;
import com.qianwen.smartman.modules.fms.service.IFmsRealTimeTrayService;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;
 
@Component
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/common/websocket/fms/FmsVisualDataMessageHandler.class */
public class FmsVisualDataMessageHandler implements JsonMessageHandler<FmsVisualDataRequestMessage> {
    private static String fmsCarryTest = " {\"id\": 333, \"code\": \"003\", \"name\": \"搬运\", \"color\": \"#3e607c\", \"workBenchList\": [{\"name\": \"10\", \"id\": \"bench3\", \"color\": \"#0FC015\"}] }";
    private static String fmsManualStationTest = "{\"id\": 444, \"code\": \"004\", \"name\": \"人工卸货站\", \"color\": \"#3e607c\", \"workBenchList\": [{\"name\": \"18\", \"id\": \"bench4\", \"color\": \"#0FC015\"}] }";
    private final IWarehouseAreaService warehouseAreaService;
    private final IWorkstationService workstationService;
    private final IFmsRealTimeTrayService realTimeTrayService;
    private final FmsVisualDataFilter fmsVisualDataFilter;
    private final RedisMessageDistributor messageDistributor;
 
    public FmsVisualDataMessageHandler(final IWarehouseAreaService warehouseAreaService, final IWorkstationService workstationService, final IFmsRealTimeTrayService realTimeTrayService, final FmsVisualDataFilter fmsVisualDataFilter, final RedisMessageDistributor messageDistributor) {
        this.warehouseAreaService = warehouseAreaService;
        this.workstationService = workstationService;
        this.realTimeTrayService = realTimeTrayService;
        this.fmsVisualDataFilter = fmsVisualDataFilter;
        this.messageDistributor = messageDistributor;
    }
 
    public void handle(WebSocketSession session, FmsVisualDataRequestMessage message) {
        WebSocketMessageSender.send(session, getResponseMessage(message));
    }
 
    public String type() {
        return "fmsVisualData";
    }
 
    public Class<FmsVisualDataRequestMessage> getMessageClass() {
        return FmsVisualDataRequestMessage.class;
    }
 
    public void pushData() {
        this.fmsVisualDataFilter.dataMap.forEach((sessionId, message) -> {
            MessageDO messageDO = new MessageDO();
            messageDO.setSessionIds(ListUtil.toList(new String[]{sessionId}));
            messageDO.setNeedBroadcast(false);
            messageDO.setMessageText(JSONObject.toJSONString(getResponseMessage(message)));
            this.messageDistributor.distribute(messageDO);
        });
    }
 
    public FmsVisualDataResponseMessage getResponseMessage(FmsVisualDataRequestMessage message) {
        List<String> fmsAreaListStr = message.getFmsAreaList();
        List<String> fmsCarryListStr = message.getFmsCarryList();
        List<String> fmsWorkstationListStr = message.getFmsWorkstationList();
        List<String> fmsManualStationList = message.getFmsManualStationList();
        FmsVisualDataResponseMessage responseMessage = new FmsVisualDataResponseMessage();
        List<FmsRealTimeTray> realTimeTrayList = this.realTimeTrayService.list();
        List<String> positionList = (List) realTimeTrayList.stream().map((v0) -> {
            return v0.getCurrentPosition();
        }).filter(currentPosition -> {
            return Func.isNotEmpty(currentPosition);
        }).collect(Collectors.toList());
        Map<String, FmsRealTimeTray> realTimeTrayMap = (Map) realTimeTrayList.stream().filter(c -> {
            return Func.isNotEmpty(c.getTrayCode()) && Func.isNotEmpty(c.getCurrentPosition());
        }).collect(Collectors.toMap((v0) -> {
            return v0.getTrayCode();
        }, r -> {
            return r;
        }));
        if (Func.isNotEmpty(fmsAreaListStr)) {
            responseMessage.setFmsAreaList(this.warehouseAreaService.assembleAreaData(fmsAreaListStr, realTimeTrayMap));
        }
        if (Func.isNotEmpty(fmsCarryListStr)) {
            responseMessage.setFmsCarryList(this.workstationService.assemblyWorkstationData(fmsCarryListStr, realTimeTrayMap, realTimeTrayList, positionList));
        }
        if (Func.isNotEmpty(fmsWorkstationListStr)) {
            responseMessage.setFmsWorkstationList(this.workstationService.assemblyWorkstationData(fmsWorkstationListStr, realTimeTrayMap, realTimeTrayList, positionList));
        }
        if (Func.isNotEmpty(fmsManualStationList)) {
            responseMessage.setFmsManualStationList(this.workstationService.assemblyWorkstationData(fmsManualStationList, realTimeTrayMap, realTimeTrayList, positionList));
        }
        responseMessage.setIsAuto(ParamCache.getValue(FmsConstant.PARAM_KEY));
        return responseMessage;
    }
}