From 54790321365355fa8007a920e8ccea7d50677354 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期四, 05 二月 2026 13:38:15 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/asrs/controller/OpenController.java | 195 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 190 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/zy/asrs/controller/OpenController.java b/src/main/java/com/zy/asrs/controller/OpenController.java
index d53c898..41b3835 100644
--- a/src/main/java/com/zy/asrs/controller/OpenController.java
+++ b/src/main/java/com/zy/asrs/controller/OpenController.java
@@ -1,7 +1,9 @@
package com.zy.asrs.controller;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.entity.BasStationTv;
@@ -16,14 +18,24 @@
import com.zy.asrs.utils.StationUtils;
import com.zy.asrs.utils.Utils;
import com.zy.common.utils.RedisUtil;
+import com.zy.system.entity.Announcement;
+import com.zy.system.service.AnnouncementService;
import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.ss.usermodel.charts.LineChartData;
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
@@ -41,11 +53,91 @@
private StationUtils stationUtils;
@Autowired
private RedisUtil redisUtil;
+ @Autowired
+ private AnnouncementService announcementService;
@Value("${app.version:1.0.0}")
private String appVersion;
@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() {
@@ -62,21 +154,28 @@
@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("鏈壘鍒癐P瀵瑰簲鐨勭數瑙嗘満璁惧: " + 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);
}
+
+ String manualError = "";
+ Object manualErrorObj = redisUtil.get(RedisKeyType.TV_MANUAL_ERROR_MSG.key);
+ if (manualErrorObj != null) {
+ manualError = String.valueOf(manualErrorObj);
+ }
List<TvDataDto> list = new ArrayList<>();
for (BasStationTv relation : relations) {
@@ -98,6 +197,12 @@
if (!Cools.isEmpty(wcsStationDto.getSystemWarning())) {
errorMsg += wcsStationDto.getSystemWarning();
}
+ if (!Cools.isEmpty(manualError)) {
+ if (!Cools.isEmpty(errorMsg)) {
+ errorMsg += "锛�";
+ }
+ errorMsg += manualError;
+ }
TvDataDto tvDataDto = new TvDataDto();
tvDataDto.setStationId(wcsStationDto.getStationId());
@@ -116,7 +221,87 @@
list.add(tvDataDto);
}
- return R.ok().add(list);
+
+ map.put("data", list);
+ return R.ok().add(map);
+ }
+
+ @GetMapping("/getError")
+ public R getError(HttpServletRequest request) {
+ Set<String> errors = new LinkedHashSet<>();
+ Object manualErrorObj = redisUtil.get(RedisKeyType.TV_MANUAL_ERROR_MSG.key);
+ String manualError = manualErrorObj == null ? "" : String.valueOf(manualErrorObj);
+ if (!Cools.isEmpty(manualError)) {
+ errors.add(manualError);
+ }
+
+ String remoteAddr = request.getRemoteAddr();
+ TvDevice tvDevice = tvDeviceService.selectOne(
+ new EntityWrapper<TvDevice>().eq("ip", remoteAddr));
+ if (tvDevice != null) {
+ List<BasStationTv> relations = basStationTvService
+ .selectList(new EntityWrapper<BasStationTv>().eq("tv_id", tvDevice.getId()));
+ if (relations != null && !relations.isEmpty()) {
+ for (BasStationTv relation : relations) {
+ WcsStationDto wcsStationDto = stationUtils.stationMap.get(relation.getStationId());
+ if (wcsStationDto == null) {
+ continue;
+ }
+ if (wcsStationDto.getLoading() != 1) {
+ continue;
+ }
+ String deviceError = "";
+ if (!Cools.isEmpty(wcsStationDto.getErrorMsg())) {
+ deviceError += wcsStationDto.getErrorMsg();
+ }
+ if (!Cools.isEmpty(wcsStationDto.getSystemWarning())) {
+ if (!Cools.isEmpty(deviceError)) {
+ deviceError += "锛�";
+ }
+ deviceError += wcsStationDto.getSystemWarning();
+ }
+ if (!Cools.isEmpty(deviceError)) {
+ errors.add(deviceError);
+ }
+ }
+ }
+ }
+
+ String errorMsg = String.join("锛�", errors);
+ Map<String, Object> result = new HashMap<>();
+ result.put("errorMsg", errorMsg);
+ return R.ok(result);
+ }
+
+ @GetMapping("/manualError/auth")
+ @ManagerAuth
+ public R getManualErrorAuth() {
+ Object manualErrorObj = redisUtil.get(RedisKeyType.TV_MANUAL_ERROR_MSG.key);
+ String manualError = manualErrorObj == null ? "" : String.valueOf(manualErrorObj);
+ Map<String, Object> result = new HashMap<>();
+ result.put("manualError", manualError);
+ return R.ok(result);
+ }
+
+ @PostMapping("/manualError/auth")
+ @ManagerAuth
+ public R setManualError(@RequestBody JSONObject param) {
+ String manualError = param.getString("manualError");
+ if (Cools.isEmpty(manualError)) {
+ redisUtil.del(RedisKeyType.TV_MANUAL_ERROR_MSG.key);
+ return R.ok();
+ }
+ redisUtil.set(RedisKeyType.TV_MANUAL_ERROR_MSG.key, manualError);
+ return R.ok();
+ }
+
+ @GetMapping("/announcement")
+ public R top5(){
+ EntityWrapper<Announcement> wrapper = new EntityWrapper<>();
+ wrapper.eq("status", 1);
+ wrapper.orderBy("create_time", false);
+ wrapper.last("limit 5");
+ return R.ok(announcementService.selectList(wrapper));
}
/**
--
Gitblit v1.9.1