张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
package com.thhy.screen.modules.biz.bigscreen.controller;
 
import com.alibaba.fastjson.JSON;
import com.thhy.general.common.BasicResult;
import com.thhy.general.common.enums.ProListenType;
import com.thhy.general.common.enums.TopicConstant;
import com.thhy.general.config.GlobalConfig;
import com.thhy.screen.modules.biz.bigscreen.entity.*;
import com.thhy.screen.modules.biz.bigscreen.mapper.BigScreenMapper;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.websocket.Session;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArraySet;
 
@Component
@RocketMQMessageListener(topic = "prolistenexc",consumerGroup = TopicConstant.PROLISTENEXC_GROUP)
public class ExecProListen implements RocketMQListener<String> {
 
    @Autowired
    private RedissonClient redissonClient;
 
    @Autowired
    private GlobalConfig globalConfig;
 
    @Autowired
    private BigScreenMapper bigScreenMapper;
 
    private Logger logger = LoggerFactory.getLogger("ExecProListen");
 
    @Override
    public void onMessage(String s) {
        logger.info("生产监控终端处理收到消息"+s);
        System.out.println("需要更新的模块"+s);
        CopyOnWriteArraySet<Session> SESSIONS = ProListenSocketServer.SESSIONS;
        SESSIONS.forEach(session ->{
            try {
                List<Map<String,Object>> mapList = getData(session,s);
 
                if (session.isOpen()) {
                    session.getBasicRemote().sendText(JSON.toJSONString(BasicResult.success(mapList)));
                    logger.info("成功推送消息到生产监控大屏"+session.getId()+"___"+session.getRequestURI().getHost());
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
    }
 
    public List<Map<String,Object>> getData(Session session,String dataType){
        RBucket<String> companyRBucket = redissonClient.getBucket(globalConfig.getKeyPrefix()+":ws:company:"+session.getId());
        String companyId = companyRBucket.get();
        List<Map<String,Object>> mapList = new ArrayList<>();
        Map<String,Object> map = new HashMap<>();
        map.put("mod",dataType);
        if(dataType.equals(ProListenType.PIPEYEARMONTH)){
            //管片年度和月度
            Map<String,Object> map1 = new HashMap<>();
            PipePlanActual pipePlanActual = bigScreenMapper.pipePlanActual(companyId);
            map1.put("mod",ProListenType.PIPEPLANACTUAL);
            map1.put("pipePlanActual",pipePlanActual);
            mapList.add(map1);
            Map<String,Object> map2 = new HashMap<>();
            List<PipeMonthPlanActual> pipeMonthPlanActuals = bigScreenMapper.pipeMonthPlanActual(companyId);
            map2.put("mod",ProListenType.PIPEMONTHPLANACTUAL);
            map2.put("pipeMonthPlanActual",pipeMonthPlanActuals);
            mapList.add(map2);
            return mapList;
        }else if(dataType.equals(ProListenType.MATERIALWEEKANDMONTHS)){
            //原料消耗 周月
            List<MaterialWeekAndMonth> materialWeekAndMonths = bigScreenMapper.materialWeekAndMonth(companyId);
            map.put("materialWeekAndMonths",materialWeekAndMonths);
        }else if (dataType.equals(ProListenType.PIPEPLANACTUAL)){
            //年度生产计划和实际完成
            PipePlanActual pipePlanActual = bigScreenMapper.pipePlanActual(companyId);
            map.put("pipePlanActual",pipePlanActual);
        }else if (dataType.equals(ProListenType.PIPEMONTHPLANACTUAL)){
            //月度生产计划和实际完成
            List<PipeMonthPlanActual> pipeMonthPlanActuals = bigScreenMapper.pipeMonthPlanActual(companyId);
            map.put("pipeMonthPlanActual",pipeMonthPlanActuals);
        }else if (dataType.equals(ProListenType.WATERCULINFO)){
            //水养池
            List<WaterCulInfo> culInfoList = bigScreenMapper.WaterCulInfo(companyId);
            map.put("waterCulInfo",culInfoList);
        }else if (dataType.equals(ProListenType.REPOINFO)){
            //堆场
            List<RepoInfo> repoInfoList = bigScreenMapper.repoInfo(companyId);
            map.put("repoInfo",repoInfoList);
        }else if (dataType.equals(ProListenType.SENDINFO)){
            //发运
            Map<String,Object> map1 = new HashMap<>();
            List<SendInfo> sendInfoList = bigScreenMapper.sendInfo(companyId);
            map1.put("mod",ProListenType.SENDINFO);
            map1.put("sendInfo",sendInfoList);
 
            Map<String,Object> map2 = new HashMap<>();
            List<RepoInfo> repoInfoList = bigScreenMapper.repoInfo(companyId);
            map2.put("mod",ProListenType.REPOINFO);
            map2.put("repoInfo",repoInfoList);
            mapList.add(map1);
            mapList.add(map2);
            return mapList;
        }
        mapList.add(map);
        return mapList;
    }
}
*/