#
Junjie
2026-02-05 54790321365355fa8007a920e8ccea7d50677354
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
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.R;
import com.core.controller.AbstractBaseController;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.BasStationTv;
import com.zy.asrs.entity.TvDevice;
import com.zy.asrs.service.BasStationService;
import com.zy.asrs.service.BasStationTvService;
import com.zy.asrs.service.TvDeviceService;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 站台与电视机绑定配置 Controller
 */
@RestController
@RequestMapping("/basStationTv")
public class BasStationTvController extends AbstractBaseController {
 
    @Autowired
    private BasStationService basStationService;
 
    @Autowired
    private TvDeviceService tvDeviceService;
 
    @Autowired
    private BasStationTvService basStationTvService;
 
    /**
     * 获取配置数据 (站点、电视机、绑定关系)
     */
    @RequestMapping(value = "/data/auth", method = RequestMethod.GET)
    @ManagerAuth
    public R getData() {
        // 1. 获取所有站点
        List<BasStation> stations = basStationService
                .selectList(new EntityWrapper<BasStation>().orderBy("station_id", true));
 
        // 2. 获取所有电视机 (按名称排序)
        List<TvDevice> tvs = tvDeviceService.selectList(new EntityWrapper<TvDevice>().orderBy("name", true));
 
        // 3. 获取所有绑定关系
        List<BasStationTv> relations = basStationTvService.selectList(new EntityWrapper<>());
 
        Map<String, Object> data = new HashMap<>();
        data.put("stations", stations);
        data.put("tvs", tvs);
        data.put("relations", relations);
 
        return R.ok(data);
    }
 
    /**
     * 保存配置
     */
    @RequestMapping(value = "/save/auth", method = RequestMethod.POST)
    @ManagerAuth
    public R save(@RequestBody JSONObject params) {
        try {
            // 获取提交的关系列表
            List<BasStationTv> relations = params.getJSONArray("relations").toJavaList(BasStationTv.class);
 
            // 全量替换策略:先删除所有旧关系,再插入新关系
            // 注意:这里没有事务控制,如果要求严格一致性,建议在Service层加@Transactional
            basStationTvService.delete(new EntityWrapper<>());
 
            if (relations != null && !relations.isEmpty()) {
                basStationTvService.insertBatch(relations);
            }
 
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("保存失败:" + e.getMessage());
        }
    }
}