1
zhang
2 天以前 b78572fb09a2c63398e8d87bd19d5d3f92f5aa58
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.zy.acs.conveyor.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.acs.common.utils.RedisSupport;
import com.zy.acs.conveyor.controller.vo.SiteTableVo;
import com.zy.acs.conveyor.core.constant.RedisConveyorConstant;
import com.zy.acs.conveyor.core.model.StaProtocol;
import com.zy.acs.conveyor.core.properties.DevpSlave;
import com.zy.acs.conveyor.core.properties.OutputQueue;
import com.zy.acs.conveyor.core.properties.SlaveProperties;
import com.zy.acs.conveyor.core.service.StationService;
import com.zy.acs.conveyor.entity.Devp;
import com.zy.acs.conveyor.service.DevpService;
import com.zy.acs.framework.annotations.ManagerAuth;
import com.zy.acs.framework.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 输送设备接口
 * Created by vincent on 2020-06-01
 */
@RestController
@RequestMapping("/site")
public class SiteController {
 
    @Autowired
    private SlaveProperties slaveProperties;
 
 
    @Autowired
    private DevpService devpService;
 
    @Autowired
    private StationService stationService;
 
 
    private final RedisSupport redis = RedisSupport.defaultRedisSupport;
 
 
    @PostMapping("/table/site")
    @ManagerAuth(memo = "站点信息表")
    public R siteTable() {
        List<SiteTableVo> list = new ArrayList<>();
        // 内存数据
        Map<Integer, StaProtocol> station = new HashMap<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            Map<Integer, StaProtocol> stationMap = stationService.getStationMap(devp.getId());
            station.putAll(stationMap);
        }
        // 持久数据
        List<Devp> devps = devpService.selectList(new EntityWrapper<Devp>().orderBy("dev_no"));
        for (Devp devp : devps) {
            SiteTableVo vo = new SiteTableVo();
            vo.setDevNo(devp.getDevNo());    // 站点编号
 
            list.add(vo);
            StaProtocol staProtocol = station.get(devp.getDevNo());
            if (null == staProtocol) {
                continue;
            }
            vo.setWorkNo(staProtocol.getWorkNo());
            vo.setAutoing(staProtocol.isAutoing() ? "Y" : "N");     //  自动
            vo.setLoading(staProtocol.isLoading() ? "Y" : "N");     // 有物
            vo.setInEnable(staProtocol.isInEnable() ? "Y" : "N");   // 可入
            vo.setOutEnable(staProtocol.isOutEnable() ? "Y" : "N"); // 可出
            vo.setEmptyMk(staProtocol.isEmptyMk() ? "Y" : "N");     // 空板信号
            vo.setStaNo(staProtocol.getStaNo());                // 目标站
//            vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "低" : "高");     //高低库位
            vo.setLocType1(devp.getDevNo() == 102 ? "高" : "低");
        }
 
        return R.ok().add(list);
    }
 
 
    @PostMapping("/output/site")
    @ManagerAuth(memo = "站点设备报文日志输出")
    public R siteOutput() {
        StringBuilder str = new StringBuilder();
        String s;
        int i = 0;
        while ((s = OutputQueue.DEVP.poll()) != null && i <= 10) {
            str.append("\n").append(s);
            i++;
        }
        return R.ok().add(str.toString());
    }
 
    /****************************************************************/
    /************************** 详情操作 ******************************/
    /****************************************************************/
 
    @GetMapping("/detl/{siteId}")
    public R siteDetl(@PathVariable("siteId") Integer siteId) {
        SiteTableVo vo = new SiteTableVo();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            Map<Integer, StaProtocol> station = stationService.getStationMap(devp.getId());
            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                if (siteId.equals(entry.getKey())) {
                    StaProtocol staProtocol = entry.getValue();
                    vo.setDevNo(entry.getKey());    // 站点编号
                    vo.setWorkNo(staProtocol.getWorkNo());   //  工作号
                    vo.setAutoing(staProtocol.isAutoing() ? "Y" : "N");     //  自动
                    vo.setLoading(staProtocol.isLoading() ? "Y" : "N");     // 有物
                    vo.setInEnable(staProtocol.isInEnable() ? "Y" : "N");   // 可入
                    vo.setOutEnable(staProtocol.isOutEnable() ? "Y" : "N"); // 可出
                    vo.setEmptyMk(staProtocol.isEmptyMk() ? "Y" : "N");     // 空板信号
                    vo.setStaNo(staProtocol.getStaNo());                // 目标站
                    vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "低" : "高");     //高低库位
                    return R.ok().add(vo);
                }
            }
        }
        return R.error("plc已掉线");
    }
 
    @PostMapping("/detl/update")
    @ManagerAuth(memo = "修改站点数据")
    public R siteDetlUpdate(@RequestParam Integer siteId,
                            @RequestParam Integer workNo,
                            @RequestParam Integer staNo,
                            @RequestParam String pakMk) {
        for (DevpSlave devp : slaveProperties.getDevp()) {
            Map<Integer, StaProtocol> station = stationService.getStationMap(devp.getId());
            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                if (siteId.equals(entry.getKey())) {
                    StaProtocol staProtocol = entry.getValue();
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    if (workNo != null) {
                        staProtocol.setWorkNo(workNo);
                    }
                    if (staNo != null) {
                        staProtocol.setStaNo(staNo);
                    }
                    redis.push(RedisConveyorConstant.CONVEYOR_TASK_FLAG, staProtocol);
                    return R.ok();
 
                }
            }
        }
        return R.error("plc已掉线");
    }
 
 
}