| | |
| | | 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.HashMap; |
| | | |
| | | 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; |
| | |
| | | return R.ok().add(map); |
| | | } |
| | | |
| | | // @GetMapping("/getLedInfos") |
| | | // public R getLedInfos(HttpServletRequest request) { |
| | | // String remoteAddr = request.getRemoteAddr(); |
| | | // for (LedSlave slave : slaveProperties.getLed()) { |
| | | // if (slave.getIp().equals(remoteAddr)) { |
| | | // return R.ok().add(slave); |
| | | // } |
| | | // } |
| | | // return R.ok(); |
| | | // } |
| | | @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]) |
| | | ); |
| | | } |
| | | |
| | | } |