#
Junjie
2026-01-14 664d9030efca22edd8e43b4db4b2c0700fff44af
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
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.R;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.BasOutArea;
import com.zy.asrs.entity.BasOutStationArea;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.BasOutAreaService;
import com.zy.asrs.service.BasOutStationAreaService;
import com.zy.asrs.service.BasStationService;
import com.zy.common.web.BaseController;
import com.zy.core.model.StationObjModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@RestController
@RequestMapping("/basOutStationArea")
public class BasOutStationAreaController extends BaseController {
 
    @Autowired
    private BasOutAreaService basOutAreaService;
    @Autowired
    private BasOutStationAreaService basOutStationAreaService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private BasStationService basStationService;
 
    @RequestMapping("/data/auth")
    @ManagerAuth
    public R data() {
        Map<String, Object> data = new HashMap<>();
 
        List<Integer> stationIds = new ArrayList<>();
        List<BasDevp> devps = basDevpService.selectList(new EntityWrapper<BasDevp>().eq("status", 1));
        for (BasDevp devp : devps) {
            for (StationObjModel stationObjModel : devp.getOutStationList$()) {
                stationIds.add(stationObjModel.getStationId());
            }
        }
        List<BasStation> stations = stationIds.isEmpty()
                ? new ArrayList<>()
                : basStationService.selectList(new EntityWrapper<BasStation>().in("station_id", stationIds));
        data.put("stations", stations);
 
        List<BasOutArea> areas = basOutAreaService.selectList(new EntityWrapper<>());
        data.put("areas", areas);
 
        List<BasOutStationArea> relations = basOutStationAreaService.selectList(new EntityWrapper<>());
        data.put("relations", relations);
 
        return R.ok(data);
    }
 
    @RequestMapping("/save/auth")
    @ManagerAuth
    public R save(@RequestBody JSONObject payload) {
        JSONArray areas = payload.getJSONArray("areas");
        JSONArray relations = payload.getJSONArray("relations");
 
        basOutAreaService.delete(new EntityWrapper<>());
        basOutStationAreaService.delete(new EntityWrapper<>());
 
        if (areas != null && !areas.isEmpty()) {
            List<BasOutArea> areaList = new ArrayList<>();
            for (int i = 0; i < areas.size(); i++) {
                JSONObject o = areas.getJSONObject(i);
                BasOutArea a = new BasOutArea();
                a.setAreaCode(o.getString("areaCode"));
                a.setAreaName(o.getString("areaName"));
                areaList.add(a);
            }
            if (!areaList.isEmpty()) {
                basOutAreaService.insertBatch(areaList);
            }
        }
 
        if (relations != null && !relations.isEmpty()) {
            List<BasOutStationArea> relList = new ArrayList<>();
            for (int i = 0; i < relations.size(); i++) {
                JSONObject o = relations.getJSONObject(i);
                BasOutStationArea r = new BasOutStationArea();
                r.setStationId(o.getInteger("stationId"));
                r.setAreaCode(o.getString("areaCode"));
                relList.add(r);
            }
            if (!relList.isEmpty()) {
                basOutStationAreaService.insertBatch(relList);
            }
        }
 
        return R.ok();
    }
}