Compare commits
4 Commits
4fbd5f7dcb
...
e490462195
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e490462195 | ||
![]() |
eb580beee0 | ||
![]() |
c6afd8b4c4 | ||
![]() |
e0291782bc |
@ -201,4 +201,5 @@ public interface ErrorCodeConstants {
|
||||
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 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失败");
|
||||
}
|
||||
|
@ -81,11 +81,12 @@ public class PositionMapController {
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/downloadPng")
|
||||
@GetMapping("/downloadPngBase64")
|
||||
@Operation(summary = "下载png文件")
|
||||
@PermitAll
|
||||
public void downloadPng(@RequestParam Integer floor, @RequestParam String area, HttpServletResponse response) throws IOException {
|
||||
positionMapService.downloadPng(floor, area, response);
|
||||
public CommonResult<String> downloadPngBase64(@RequestParam Integer floor, @RequestParam String area) {
|
||||
String base64 = positionMapService.downloadPngBase64(floor, area);
|
||||
return CommonResult.success(base64);
|
||||
}
|
||||
|
||||
@GetMapping("/download")
|
||||
|
@ -14,7 +14,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
||||
@ToString(callSuper = true)
|
||||
public class RobotInformationPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "车辆类型表id", example = "26319")
|
||||
@Schema(description = "车辆类型表id", example = "28234")
|
||||
private Long robotModelId;
|
||||
|
||||
@Schema(description = "车辆类型")
|
||||
@ -32,9 +32,12 @@ public class RobotInformationPageReqVO extends PageParam {
|
||||
@Schema(description = "上传图片附件", example = "https://www.iocoder.cn")
|
||||
private String url;
|
||||
|
||||
@Schema(description = "AGV状态(0:暂停且无任务、1:暂停(有处理中的任务)、2:任务中、3:待命)", example = "1")
|
||||
@Schema(description = "AGV状态(0:暂停且无任务、1:暂停(有处理中的任务)、2:任务中、3:待命)", example = "2")
|
||||
private Integer robotStatus;
|
||||
|
||||
@Schema(description = "楼层/区域(json)")
|
||||
private String floorAreaJson;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.controller.admin.robot.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@ -11,11 +10,11 @@ import com.alibaba.excel.annotation.*;
|
||||
@ExcelIgnoreUnannotated
|
||||
public class RobotInformationRespVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24068")
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "21881")
|
||||
@ExcelProperty("主键ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "车辆类型表id", example = "26319")
|
||||
@Schema(description = "车辆类型表id", example = "28234")
|
||||
@ExcelProperty("车辆类型表id")
|
||||
private Long robotModelId;
|
||||
|
||||
@ -39,10 +38,14 @@ public class RobotInformationRespVO {
|
||||
@ExcelProperty("上传图片附件")
|
||||
private String url;
|
||||
|
||||
@Schema(description = "AGV状态(0:暂停且无任务、1:暂停(有处理中的任务)、2:任务中、3:待命)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@Schema(description = "AGV状态(0:暂停且无任务、1:暂停(有处理中的任务)、2:任务中、3:待命)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("AGV状态(0:暂停且无任务、1:暂停(有处理中的任务)、2:任务中、3:待命)")
|
||||
private Integer robotStatus;
|
||||
|
||||
@Schema(description = "楼层/区域(json)")
|
||||
@ExcelProperty("楼层/区域(json)")
|
||||
private String floorAreaJson;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
@ -3,34 +3,43 @@ package cn.iocoder.yudao.module.system.controller.admin.robot.vo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
@Schema(description = "管理后台 - 车辆信息新增/修改 Request VO")
|
||||
@Data
|
||||
public class RobotInformationSaveReqVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24068")
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "21881")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "车辆类型表id", example = "26319")
|
||||
@Schema(description = "车辆类型表id", example = "28234")
|
||||
@NotEmpty(message = "车辆类型不能为空")
|
||||
private Long robotModelId;
|
||||
|
||||
@Schema(description = "车辆类型")
|
||||
@NotEmpty(message = "车辆类型不能为空")
|
||||
private String robotModelNumber;
|
||||
|
||||
@Schema(description = "AGV编号")
|
||||
@NotEmpty(message = "AGV编号不能为空")
|
||||
private String robotNo;
|
||||
|
||||
@Schema(description = "任务模式(0:拒收任务、1:正常)", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "任务模式不能为空")
|
||||
private Integer robotTaskModel;
|
||||
|
||||
@Schema(description = "mac地址")
|
||||
@NotEmpty(message = "mac地址不能为空")
|
||||
private String macAddress;
|
||||
|
||||
@Schema(description = "上传图片附件", example = "https://www.iocoder.cn")
|
||||
private String url;
|
||||
|
||||
@Schema(description = "AGV状态(0:暂停且无任务、1:暂停(有处理中的任务)、2:任务中、3:待命)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@Schema(description = "AGV状态(0:暂停且无任务、1:暂停(有处理中的任务)、2:任务中、3:待命)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Integer robotStatus;
|
||||
|
||||
@Schema(description = "楼层/区域(json)")
|
||||
@NotEmpty(message = "楼层/区域不能为空")
|
||||
private String floorAreaJson;
|
||||
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.robot;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
@ -55,5 +52,9 @@ public class RobotInformationDO extends BaseDO {
|
||||
* AGV状态(0:暂停且无任务、1:暂停(有处理中的任务)、2:任务中、3:待命)
|
||||
*/
|
||||
private Integer robotStatus;
|
||||
/**
|
||||
* 楼层/区域(json)
|
||||
*/
|
||||
private String floorAreaJson;
|
||||
|
||||
}
|
@ -85,7 +85,6 @@ public interface PositionMapService extends IService<PositionMapDO> {
|
||||
*
|
||||
* @param floor
|
||||
* @param area
|
||||
* @param response
|
||||
*/
|
||||
void downloadPng(Integer floor, String area, HttpServletResponse response) throws IOException;
|
||||
String downloadPngBase64(Integer floor, String area);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -28,6 +29,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@ -47,6 +49,8 @@ public class PositionMapServiceImpl extends ServiceImpl<PositionMapMapper, Posit
|
||||
private PositionMapMapper positionMapMapper;
|
||||
@Value("${map.file.upload-path}")
|
||||
private String UPLOAD_DIR;
|
||||
@Override
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Override
|
||||
public Long createPositionMap(PositionMapSaveReqVO createReqVO) {
|
||||
@ -253,13 +257,17 @@ public class PositionMapServiceImpl extends ServiceImpl<PositionMapMapper, Posit
|
||||
|
||||
|
||||
@Override
|
||||
public void downloadPng(Integer floor, String area, HttpServletResponse response) throws IOException {
|
||||
public String downloadPngBase64(Integer floor, String area) {
|
||||
String key = "pngBase64" + "_" + floor + "_" + area;
|
||||
Boolean b = stringRedisTemplate.hasKey(key);
|
||||
if (b) {
|
||||
return stringRedisTemplate.opsForValue().get(key);
|
||||
}
|
||||
// 根据楼层和区域查找对应的PNG文件路径
|
||||
String basePath = UPLOAD_DIR + floor + "/" + area + "/";
|
||||
File directory = new File(basePath);
|
||||
if (!directory.exists() || !directory.isDirectory()) {
|
||||
response.sendError(HttpStatus.NOT_FOUND.value(), "Directory not found for the given floor and area.");
|
||||
return;
|
||||
throw exception(AGV_MAP_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 查找PNG文件
|
||||
@ -270,18 +278,21 @@ public class PositionMapServiceImpl extends ServiceImpl<PositionMapMapper, Posit
|
||||
}
|
||||
|
||||
if (pngFile == null || !pngFile.exists()) {
|
||||
response.sendError(HttpStatus.NOT_FOUND.value(), "PNG file not found for the given floor and area.");
|
||||
return;
|
||||
throw exception(AGV_MAP_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 设置响应头以指示浏览器下载文件
|
||||
response.setContentType("image/png");
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + pngFile.getName() + "\"");
|
||||
|
||||
// 将PNG文件写入HTTP响应输出流
|
||||
try (FileInputStream fis = new FileInputStream(pngFile)) {
|
||||
IOUtils.copy(fis, response.getOutputStream());
|
||||
String encodedString = null;
|
||||
try {
|
||||
// 读取文件内容
|
||||
byte[] fileContent = Files.readAllBytes(pngFile.toPath());
|
||||
// 将文件内容转换为Base64字符串
|
||||
encodedString = Base64.getEncoder().encodeToString(fileContent);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw exception(AGV_IMAGE_CONVERSION_TO_BASE64_FAILED);
|
||||
}
|
||||
// -- 缓存30分钟
|
||||
stringRedisTemplate.opsForValue().set(key, encodedString, 30, TimeUnit.MINUTES);
|
||||
return encodedString;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user