| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | |
| | | @Value("${app.version-type:stable}") |
| | | private String appVersionType; |
| | | |
| | | @Value("${file.upload-path}") |
| | | private String uploadPath; |
| | | |
| | | @PostMapping("/uploadLogo") |
| | | public R uploadLogo(@RequestParam("file") MultipartFile file) { |
| | | if (file.isEmpty()) { |
| | | return R.error("上传文件不能为空"); |
| | | } |
| | | try { |
| | | File dir = new File(uploadPath); |
| | | if (!dir.exists()) { |
| | | dir.mkdirs(); |
| | | } |
| | | |
| | | String originalFilename = file.getOriginalFilename(); |
| | | String extension = ""; |
| | | if (originalFilename != null && originalFilename.lastIndexOf(".") > 0) { |
| | | extension = originalFilename.substring(originalFilename.lastIndexOf(".")); |
| | | } |
| | | |
| | | // 删除旧的logo文件 |
| | | File[] files = dir.listFiles((d, name) -> name.startsWith("logo.")); |
| | | if (files != null) { |
| | | for (File f : files) { |
| | | f.delete(); |
| | | } |
| | | } |
| | | |
| | | String fileName = "logo" + extension; |
| | | File dest = new File(dir, fileName); |
| | | file.transferTo(dest); |
| | | |
| | | return R.ok(); |
| | | } catch (IOException e) { |
| | | log.error("上传Logo失败", e); |
| | | return R.error("上传失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/getLogo") |
| | | public void getLogo(HttpServletResponse response) { |
| | | try { |
| | | File dir = new File(uploadPath); |
| | | if (!dir.exists()) { |
| | | response.sendError(HttpServletResponse.SC_NOT_FOUND, "Logo directory not found"); |
| | | return; |
| | | } |
| | | |
| | | File[] files = dir.listFiles((d, name) -> name.startsWith("logo.")); |
| | | if (files == null || files.length == 0) { |
| | | response.sendError(HttpServletResponse.SC_NOT_FOUND, "Logo not found"); |
| | | return; |
| | | } |
| | | |
| | | File logoFile = files[0]; |
| | | String filename = logoFile.getName(); |
| | | String contentType = "image/jpeg"; |
| | | if (filename.toLowerCase().endsWith(".png")) { |
| | | contentType = "image/png"; |
| | | } else if (filename.toLowerCase().endsWith(".gif")) { |
| | | contentType = "image/gif"; |
| | | } |
| | | response.setContentType(contentType); |
| | | |
| | | try (FileInputStream fis = new FileInputStream(logoFile); |
| | | OutputStream os = response.getOutputStream()) { |
| | | byte[] buffer = new byte[1024]; |
| | | int len; |
| | | while ((len = fis.read(buffer)) != -1) { |
| | | os.write(buffer, 0, len); |
| | | } |
| | | os.flush(); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("获取Logo失败", e); |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/systemStatus") |
| | | public R systemStatus() { |
| | | return R.ok(); |
| | |
| | | |
| | | @GetMapping("/getLedInfos") |
| | | public R getLedInfos(HttpServletRequest request) { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | String remoteAddr = request.getRemoteAddr(); |
| | | TvDevice tvDevice = tvDeviceService.selectOne( |
| | | new EntityWrapper<TvDevice>().eq("ip", remoteAddr)); |
| | | if (tvDevice == null) { |
| | | return R.error("未找到IP对应的电视机设备: " + remoteAddr); |
| | | } |
| | | map.put("deviceName", tvDevice.getName()); |
| | | |
| | | 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; |
| | | map.put("data", new ArrayList<>()); |
| | | return R.ok().add(map); |
| | | } |
| | | |
| | | |
| | |
| | | list.add(tvDataDto); |
| | | } |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | |
| | | map.put("data", list); |
| | | map.put("deviceName", tvDevice.getName()); |
| | | return R.ok().add(map); |
| | | } |
| | | |