#
Junjie
3 天以前 706eabba4750cf92282378ae5d2414f497a4578c
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
package com.zy.asrs.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.BasDualCrnp;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.BasStationDevice;
import com.zy.asrs.service.BasCrnpService;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.BasDualCrnpService;
import com.zy.asrs.service.BasStationDeviceService;
import com.zy.asrs.service.BasStationService;
import com.core.annotations.ManagerAuth;
import com.core.common.R;
import com.zy.common.web.BaseController;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.StationObjModel;
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;
 
@RestController
@RequestMapping("/basStationDevice")
public class BasStationDeviceController extends BaseController {
 
    @Autowired
    private BasStationDeviceService basStationDeviceService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private BasStationService basStationService;
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
    private BasDualCrnpService basDualCrnpService;
 
    @RequestMapping("/list/auth")
    @ManagerAuth
    public R list() {
        return R.ok(basStationDeviceService.selectList(new EntityWrapper<>()));
    }
 
    @RequestMapping("/save/auth")
    @ManagerAuth
    public R save(@RequestBody List<BasStationDevice> list) {
        // Full replacement logic for simplicity in this specific UI case
        // First delete all existing, then insert new ones. 
        // Note: In a production environment with high concurrency, this should be transactional and more granular.
        // But for a configuration page, this is acceptable.
        
        // However, to be safer, we should probably only delete for the stations involved or delete all if it's a full save.
        // Let's assume the UI sends the full current state of configuration.
        basStationDeviceService.delete(new EntityWrapper<>());
        if (list != null && !list.isEmpty()) {
            basStationDeviceService.insertBatch(list);
        }
        return R.ok();
    }
    
    @RequestMapping("/data/auth")
    @ManagerAuth
    public R getData() {
        Map<String, Object> data = new HashMap<>();
        
        List<Integer> stationList = new ArrayList<>();
        List<BasDevp> devps = basDevpService.selectList(new EntityWrapper<BasDevp>().eq("status", 1));
        for (BasDevp devp : devps) {
            for (StationObjModel stationObjModel : devp.getBarcodeStationList$()) {
                stationList.add(stationObjModel.getStationId());
            }
        }
 
        List<BasStation> stations = basStationService.selectList(new EntityWrapper<BasStation>().in("station_id", stationList));
        data.put("stations", stations);
        
        // Get Devices (Crn and DualCrn)
        List<Map<String, Object>> devices = new ArrayList<>();
        
        List<BasCrnp> crns = basCrnpService.selectList(new EntityWrapper<BasCrnp>().eq("status", 1));
        for (BasCrnp crn : crns) {
            Map<String, Object> d = new HashMap<>();
            d.put("deviceNo", crn.getCrnNo());
            d.put("type", SlaveType.Crn.toString());
            d.put("name", "堆垛机 " + crn.getCrnNo());
            devices.add(d);
        }
        
        List<BasDualCrnp> dualCrns = basDualCrnpService.selectList(new EntityWrapper<BasDualCrnp>().eq("status", 1));
        for (BasDualCrnp dualCrn : dualCrns) {
            Map<String, Object> d = new HashMap<>();
            d.put("deviceNo", dualCrn.getCrnNo());
            d.put("type", SlaveType.DualCrn.toString());
            d.put("name", "双工位堆垛机 " + dualCrn.getCrnNo());
            devices.add(d);
        }
        
        data.put("devices", devices);
        
        // Get existing relations
        List<BasStationDevice> relations = basStationDeviceService.selectList(new EntityWrapper<>());
        data.put("relations", relations);
        
        return R.ok(data);
    }
}