#
Junjie
2026-01-21 f03d761f318fd9c0a2ee5036a7bcce1c29cfd5c5
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
package com.zy.asrs.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.BasStationTv;
import com.zy.asrs.entity.TvDevice;
 
import com.zy.asrs.utils.Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
 
import javax.servlet.http.HttpServletRequest;
 
import java.util.*;
import java.util.stream.Collectors;
 
@Slf4j
@RestController
@RequestMapping("/openapi")
public class OpenController {
 
    private static final String[] WEEK = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
 
    @Autowired
    private com.zy.asrs.service.TvDeviceService tvDeviceService;
    @Autowired
    private com.zy.asrs.service.BasStationTvService basStationTvService;
    @Autowired
    private com.zy.asrs.service.BasStationService basStationService;
 
    @Value("${app.version:1.0.0}")
    private String appVersion;
    @Value("${app.version-type:stable}")
    private String appVersionType;
 
    @GetMapping("/systemStatus")
    public R systemStatus() {
        return R.ok();
    }
 
    @GetMapping("/getSystemVersion")
    public R getSystemVersion() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("version", appVersion);
        map.put("versionType", appVersionType);
        return R.ok().add(map);
    }
 
    @GetMapping("/getLedInfos")
    public R getLedInfos(HttpServletRequest request) {
        String remoteAddr = request.getRemoteAddr();
        // 1. 根据IP查询电视机
        TvDevice tvDevice = tvDeviceService.selectOne(
                new EntityWrapper<TvDevice>().eq("ip", remoteAddr));
        if (tvDevice == null) {
            return R.error("未找到IP对应的电视机设备: " + remoteAddr);
        }
 
        // 2. 查询绑定的站台ID
        List<BasStationTv> relations = basStationTvService
                .selectList(new EntityWrapper<BasStationTv>().eq("tv_id", tvDevice.getId()));
        if (relations == null || relations.isEmpty()) {
            R r = R.ok();
            r.put("data", new ArrayList<>());
            return r;
        }
 
        // 3. 获取站台详情
        List<Integer> stationIds = relations.stream().map(BasStationTv::getStationId)
                .collect(Collectors.toList());
        List<BasStation> stations = basStationService.selectBatchIds(stationIds);
 
        R r = R.ok();
        r.put("data", stations);
        return r;
    }
 
    /**
     * 获取当前时间
     */
    @GetMapping("/monitor/date")
    public R monitorDate() {
        Date now = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(now);
        return R.ok(
                Cools.add("year", calendar.get(Calendar.YEAR))
                        .add("month", Utils.zerofill(String.valueOf(calendar.get(Calendar.MONTH)+1), 2))
                        .add("day", Utils.zerofill(String.valueOf(calendar.get(Calendar.DATE)), 2))
                        .add("hour", Utils.zerofill(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)), 2))
                        .add("minute", Utils.zerofill(String.valueOf(calendar.get(Calendar.MINUTE)), 2))
                        .add("second", Utils.zerofill(String.valueOf(calendar.get(Calendar.SECOND)) , 2))
                        .add("week", WEEK[calendar.get(Calendar.DAY_OF_WEEK)-1])
        );
    }
 
}