Compare commits

..

No commits in common. "e490462195eded87a84fcc4781014e9d073efe3d" and "4fbd5f7dcbb268f1af4e2863130d11357d76f4d8" have entirely different histories.

8 changed files with 31 additions and 59 deletions

View File

@ -201,5 +201,4 @@ public interface ErrorCodeConstants {
ErrorCode AGV_FILE_UPLOAD_CONTENT_IS_EMPTY = new ErrorCode(1_002_038_002, "AGV文件上传内容为空"); ErrorCode AGV_FILE_UPLOAD_CONTENT_IS_EMPTY = new ErrorCode(1_002_038_002, "AGV文件上传内容为空");
ErrorCode PLEASE_UPLOAD_PNG_AND_YAML_FILES = new ErrorCode(1_002_038_003, "请上传png和yaml两个文件并且文件内容不为空"); ErrorCode PLEASE_UPLOAD_PNG_AND_YAML_FILES = new ErrorCode(1_002_038_003, "请上传png和yaml两个文件并且文件内容不为空");
ErrorCode AGV_MAP_NOT_FOUND = new ErrorCode(1_002_038_004, "找不到AGV地图信息"); ErrorCode AGV_MAP_NOT_FOUND = new ErrorCode(1_002_038_004, "找不到AGV地图信息");
ErrorCode AGV_IMAGE_CONVERSION_TO_BASE64_FAILED = new ErrorCode(1_002_038_005, "AGV图片转base64失败");
} }

View File

@ -81,12 +81,11 @@ public class PositionMapController {
return CommonResult.success(true); return CommonResult.success(true);
} }
@GetMapping("/downloadPngBase64") @GetMapping("/downloadPng")
@Operation(summary = "下载png文件") @Operation(summary = "下载png文件")
@PermitAll @PermitAll
public CommonResult<String> downloadPngBase64(@RequestParam Integer floor, @RequestParam String area) { public void downloadPng(@RequestParam Integer floor, @RequestParam String area, HttpServletResponse response) throws IOException {
String base64 = positionMapService.downloadPngBase64(floor, area); positionMapService.downloadPng(floor, area, response);
return CommonResult.success(base64);
} }
@GetMapping("/download") @GetMapping("/download")

View File

@ -14,7 +14,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@ToString(callSuper = true) @ToString(callSuper = true)
public class RobotInformationPageReqVO extends PageParam { public class RobotInformationPageReqVO extends PageParam {
@Schema(description = "车辆类型表id", example = "28234") @Schema(description = "车辆类型表id", example = "26319")
private Long robotModelId; private Long robotModelId;
@Schema(description = "车辆类型") @Schema(description = "车辆类型")
@ -32,12 +32,9 @@ public class RobotInformationPageReqVO extends PageParam {
@Schema(description = "上传图片附件", example = "https://www.iocoder.cn") @Schema(description = "上传图片附件", example = "https://www.iocoder.cn")
private String url; private String url;
@Schema(description = "AGV状态0暂停且无任务、1暂停(有处理中的任务)、2任务中、3待命", example = "2") @Schema(description = "AGV状态0暂停且无任务、1暂停(有处理中的任务)、2任务中、3待命", example = "1")
private Integer robotStatus; private Integer robotStatus;
@Schema(description = "楼层/区域(json)")
private String floorAreaJson;
@Schema(description = "创建时间") @Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime; private LocalDateTime[] createTime;

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.system.controller.admin.robot.vo;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*; import lombok.*;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*; import com.alibaba.excel.annotation.*;
@ -10,11 +11,11 @@ import com.alibaba.excel.annotation.*;
@ExcelIgnoreUnannotated @ExcelIgnoreUnannotated
public class RobotInformationRespVO { public class RobotInformationRespVO {
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "21881") @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24068")
@ExcelProperty("主键ID") @ExcelProperty("主键ID")
private Long id; private Long id;
@Schema(description = "车辆类型表id", example = "28234") @Schema(description = "车辆类型表id", example = "26319")
@ExcelProperty("车辆类型表id") @ExcelProperty("车辆类型表id")
private Long robotModelId; private Long robotModelId;
@ -38,14 +39,10 @@ public class RobotInformationRespVO {
@ExcelProperty("上传图片附件") @ExcelProperty("上传图片附件")
private String url; private String url;
@Schema(description = "AGV状态0暂停且无任务、1暂停(有处理中的任务)、2任务中、3待命", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "AGV状态0暂停且无任务、1暂停(有处理中的任务)、2任务中、3待命", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty("AGV状态0暂停且无任务、1暂停(有处理中的任务)、2任务中、3待命") @ExcelProperty("AGV状态0暂停且无任务、1暂停(有处理中的任务)、2任务中、3待命")
private Integer robotStatus; private Integer robotStatus;
@Schema(description = "楼层/区域(json)")
@ExcelProperty("楼层/区域(json)")
private String floorAreaJson;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间") @ExcelProperty("创建时间")
private LocalDateTime createTime; private LocalDateTime createTime;

View File

@ -3,43 +3,34 @@ package cn.iocoder.yudao.module.system.controller.admin.robot.vo;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*; import lombok.*;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.*;
@Schema(description = "管理后台 - 车辆信息新增/修改 Request VO") @Schema(description = "管理后台 - 车辆信息新增/修改 Request VO")
@Data @Data
public class RobotInformationSaveReqVO { public class RobotInformationSaveReqVO {
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "21881") @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24068")
private Long id; private Long id;
@Schema(description = "车辆类型表id", example = "28234") @Schema(description = "车辆类型表id", example = "26319")
@NotEmpty(message = "车辆类型不能为空")
private Long robotModelId; private Long robotModelId;
@Schema(description = "车辆类型") @Schema(description = "车辆类型")
@NotEmpty(message = "车辆类型不能为空")
private String robotModelNumber; private String robotModelNumber;
@Schema(description = "AGV编号") @Schema(description = "AGV编号")
@NotEmpty(message = "AGV编号不能为空")
private String robotNo; private String robotNo;
@Schema(description = "任务模式0拒收任务、1正常", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "任务模式0拒收任务、1正常", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "任务模式不能为空")
private Integer robotTaskModel; private Integer robotTaskModel;
@Schema(description = "mac地址") @Schema(description = "mac地址")
@NotEmpty(message = "mac地址不能为空")
private String macAddress; private String macAddress;
@Schema(description = "上传图片附件", example = "https://www.iocoder.cn") @Schema(description = "上传图片附件", example = "https://www.iocoder.cn")
private String url; private String url;
@Schema(description = "AGV状态0暂停且无任务、1暂停(有处理中的任务)、2任务中、3待命", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "AGV状态0暂停且无任务、1暂停(有处理中的任务)、2任务中、3待命", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer robotStatus; private Integer robotStatus;
@Schema(description = "楼层/区域(json)")
@NotEmpty(message = "楼层/区域不能为空")
private String floorAreaJson;
} }

View File

@ -1,6 +1,9 @@
package cn.iocoder.yudao.module.system.dal.dataobject.robot; package cn.iocoder.yudao.module.system.dal.dataobject.robot;
import lombok.*; import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
@ -52,9 +55,5 @@ public class RobotInformationDO extends BaseDO {
* AGV状态0暂停且无任务1暂停(有处理中的任务)2任务中3待命 * AGV状态0暂停且无任务1暂停(有处理中的任务)2任务中3待命
*/ */
private Integer robotStatus; private Integer robotStatus;
/**
* 楼层/区域(json)
*/
private String floorAreaJson;
} }

View File

@ -85,6 +85,7 @@ public interface PositionMapService extends IService<PositionMapDO> {
* *
* @param floor * @param floor
* @param area * @param area
* @param response
*/ */
String downloadPngBase64(Integer floor, String area); void downloadPng(Integer floor, String area, HttpServletResponse response) throws IOException;
} }

View File

@ -13,7 +13,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -29,7 +28,6 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@ -49,8 +47,6 @@ public class PositionMapServiceImpl extends ServiceImpl<PositionMapMapper, Posit
private PositionMapMapper positionMapMapper; private PositionMapMapper positionMapMapper;
@Value("${map.file.upload-path}") @Value("${map.file.upload-path}")
private String UPLOAD_DIR; private String UPLOAD_DIR;
@Override
private StringRedisTemplate stringRedisTemplate;
@Override @Override
public Long createPositionMap(PositionMapSaveReqVO createReqVO) { public Long createPositionMap(PositionMapSaveReqVO createReqVO) {
@ -257,17 +253,13 @@ public class PositionMapServiceImpl extends ServiceImpl<PositionMapMapper, Posit
@Override @Override
public String downloadPngBase64(Integer floor, String area) { public void downloadPng(Integer floor, String area, HttpServletResponse response) throws IOException {
String key = "pngBase64" + "_" + floor + "_" + area;
Boolean b = stringRedisTemplate.hasKey(key);
if (b) {
return stringRedisTemplate.opsForValue().get(key);
}
// 根据楼层和区域查找对应的PNG文件路径 // 根据楼层和区域查找对应的PNG文件路径
String basePath = UPLOAD_DIR + floor + "/" + area + "/"; String basePath = UPLOAD_DIR + floor + "/" + area + "/";
File directory = new File(basePath); File directory = new File(basePath);
if (!directory.exists() || !directory.isDirectory()) { if (!directory.exists() || !directory.isDirectory()) {
throw exception(AGV_MAP_NOT_FOUND); response.sendError(HttpStatus.NOT_FOUND.value(), "Directory not found for the given floor and area.");
return;
} }
// 查找PNG文件 // 查找PNG文件
@ -278,21 +270,18 @@ public class PositionMapServiceImpl extends ServiceImpl<PositionMapMapper, Posit
} }
if (pngFile == null || !pngFile.exists()) { if (pngFile == null || !pngFile.exists()) {
throw exception(AGV_MAP_NOT_FOUND); response.sendError(HttpStatus.NOT_FOUND.value(), "PNG file not found for the given floor and area.");
return;
} }
String encodedString = null;
try { // 设置响应头以指示浏览器下载文件
// 读取文件内容 response.setContentType("image/png");
byte[] fileContent = Files.readAllBytes(pngFile.toPath()); response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + pngFile.getName() + "\"");
// 将文件内容转换为Base64字符串
encodedString = Base64.getEncoder().encodeToString(fileContent); // 将PNG文件写入HTTP响应输出流
} catch (IOException e) { try (FileInputStream fis = new FileInputStream(pngFile)) {
e.printStackTrace(); IOUtils.copy(fis, response.getOutputStream());
throw exception(AGV_IMAGE_CONVERSION_TO_BASE64_FAILED);
} }
// -- 缓存30分钟
stringRedisTemplate.opsForValue().set(key, encodedString, 30, TimeUnit.MINUTES);
return encodedString;
} }
} }