From 4c7b7b434763ff7b72788ed8ef12230cb70679fb Mon Sep 17 00:00:00 2001 From: cuizhibin Date: Mon, 23 Jun 2025 13:36:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=A2=9E=E5=8A=A0=E9=83=A8=E4=BB=B6id=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E7=9B=B4=E6=8E=A5=E4=B8=8A=E4=BC=A0=E5=B9=B6=E5=85=B3?= =?UTF-8?q?=E8=81=94=E9=83=A8=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/entity/VideoFileInfoEntity.java | 4 +- .../com/dite/znpt/domain/vo/ImageWorkReq.java | 3 ++ .../dite/znpt/domain/vo/VideoFileInfoReq.java | 12 ++--- .../service/impl/ImageCollectServiceImpl.java | 3 +- .../znpt/service/impl/ImageServiceImpl.java | 44 ++++++++++++++++--- .../znpt/web/controller/CommonController.java | 25 +---------- 6 files changed, 54 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/com/dite/znpt/domain/entity/VideoFileInfoEntity.java b/core/src/main/java/com/dite/znpt/domain/entity/VideoFileInfoEntity.java index 8cdb713..442e47a 100644 --- a/core/src/main/java/com/dite/znpt/domain/entity/VideoFileInfoEntity.java +++ b/core/src/main/java/com/dite/znpt/domain/entity/VideoFileInfoEntity.java @@ -32,8 +32,8 @@ public class VideoFileInfoEntity extends AuditableEntity implements Serializable @TableId(value = "id", type = IdType.ASSIGN_ID) private String id; - @ExcelProperty("机组id") - @ApiModelProperty(value = "机组id",required = true) + @ExcelProperty("部件id") + @ApiModelProperty(value = "部件id",required = true) @TableField("part_id") private String partId; diff --git a/core/src/main/java/com/dite/znpt/domain/vo/ImageWorkReq.java b/core/src/main/java/com/dite/znpt/domain/vo/ImageWorkReq.java index 4581c1b..2b02b44 100644 --- a/core/src/main/java/com/dite/znpt/domain/vo/ImageWorkReq.java +++ b/core/src/main/java/com/dite/znpt/domain/vo/ImageWorkReq.java @@ -29,4 +29,7 @@ public class ImageWorkReq implements Serializable { @ApiModelProperty("海拔") private String altitude; + + @ApiModelProperty("部件id") + private String partId; } diff --git a/core/src/main/java/com/dite/znpt/domain/vo/VideoFileInfoReq.java b/core/src/main/java/com/dite/znpt/domain/vo/VideoFileInfoReq.java index 2dd861a..4743eee 100644 --- a/core/src/main/java/com/dite/znpt/domain/vo/VideoFileInfoReq.java +++ b/core/src/main/java/com/dite/znpt/domain/vo/VideoFileInfoReq.java @@ -10,18 +10,18 @@ import java.io.Serializable; import java.time.LocalDateTime; /** - * @author Bear.G - * @date 2025/5/27/周二 15:25 - * @description + * @author cuizhibin + * @date 2025/06/23 11:04 + * @description 视频文件信息要求 */ @Data -@ApiModel("人员资质请求实体") +@ApiModel("视频文件请求实体") public class VideoFileInfoReq implements Serializable { @Serial private static final long serialVersionUID = 1737569842748352413L; - @NotBlank(message = "机组id不能为空") - @ApiModelProperty(value = "机组id",required = true) + @NotBlank(message = "部件id不能为空") + @ApiModelProperty(value = "部件id",required = true) private String partId; @ApiModelProperty("测试点") diff --git a/core/src/main/java/com/dite/znpt/service/impl/ImageCollectServiceImpl.java b/core/src/main/java/com/dite/znpt/service/impl/ImageCollectServiceImpl.java index cb8f22c..8188df1 100644 --- a/core/src/main/java/com/dite/znpt/service/impl/ImageCollectServiceImpl.java +++ b/core/src/main/java/com/dite/znpt/service/impl/ImageCollectServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.dite.znpt.constant.Constants; import com.dite.znpt.constant.Message; import com.dite.znpt.converts.Converts; import com.dite.znpt.domain.entity.ImageCollectEntity; @@ -67,7 +68,7 @@ public class ImageCollectServiceImpl extends ServiceImpl impl String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); String path_prefix = permPath.concat(imageSource).concat(FileUtil.FILE_SEPARATOR).concat(dateStr).concat(FileUtil.FILE_SEPARATOR); if (Objects.nonNull(imageWorkReq)) { - path_prefix = path_prefix.concat(StrUtil.nullToDefault(imageWorkReq.getUploadUser(), "默认用户")).concat(FileUtil.FILE_SEPARATOR) - .concat(StrUtil.nullToDefault(imageWorkReq.getLongitude(), "0")) - .concat(" ").concat(StrUtil.nullToDefault(imageWorkReq.getLatitude(), "0")) - .concat(" ").concat(StrUtil.nullToDefault(imageWorkReq.getAltitude(), "0")) + path_prefix = path_prefix.concat(StrUtil.emptyToDefault(imageWorkReq.getUploadUser(), "默认用户")).concat(FileUtil.FILE_SEPARATOR) + .concat(StrUtil.emptyToDefault(imageWorkReq.getLongitude(), "0")) + .concat(" ").concat(StrUtil.emptyToDefault(imageWorkReq.getLatitude(), "0")) + .concat(" ").concat(StrUtil.emptyToDefault(imageWorkReq.getAltitude(), "0")) .concat(FileUtil.FILE_SEPARATOR); } if (!FileUtil.exist(path_prefix)) { @@ -183,6 +184,39 @@ public class ImageServiceImpl extends ServiceImpl impl FileUtil.writeBytes(multipartFile.getBytes(),path); result.add(getImageDownPath(StrUtil.removePrefix(path, permPath))); } + String partId = imageWorkReq.getPartId(); + if (Objects.nonNull(partId)) { + ImageCollectEntity imageCollect = new ImageCollectEntity(); + imageCollect.setCollectId(IdUtil.simpleUUID()); + imageCollect.setCollectorName(imageWorkReq.getUploadUser()); + PartEntity part = partService.getById(partId); + if (Objects.isNull(part)) { + throw new ServiceException(Message.PART_ID_IS_NOT_EXIST); + } + List imageList = new ArrayList<>(); + result.forEach(path -> { + ImageEntity imageEntity = new ImageEntity(); + String absolutePath = permPath + StrUtil.removePrefix(path, Constants.PERM_IMAGE_PATH); + try { + ImageReq imageReq = imageRespBuilder(absolutePath); + BeanUtil.copyProperties(imageReq, imageEntity); + } catch (Exception e) { + log.debug("读取文件信息失败:{}", path); + imageEntity.setImageName(FileUtil.getName(absolutePath)); + BigDecimal imageSize = new BigDecimal(FileUtil.size(FileUtil.file(absolutePath))).divide(new BigDecimal(1024*1024), 4, RoundingMode.HALF_UP); + imageEntity.setImageSize(imageSize.toString().concat("M")); + } + imageEntity.setLongitude(imageWorkReq.getLongitude()); + imageEntity.setLatitude(imageWorkReq.getLatitude()); + imageEntity.setAltitude(imageWorkReq.getAltitude()); + imageEntity.setImagePath(path); + imageEntity.setPartId(partId); + imageEntity.setCollectId(imageCollect.getCollectId()); + imageList.add(imageEntity); + }); + imageCollectService.save(imageCollect); + baseMapper.insert(imageList); + } return result; } @@ -392,7 +426,7 @@ public class ImageServiceImpl extends ServiceImpl impl List newImageList = new ArrayList<>(); partReq.getImagePaths().forEach(path -> { ImageEntity imageEntity = new ImageEntity(); - String absolutePath = permPath + StrUtil.removePrefix(path, "/static/image/"); + String absolutePath = permPath + StrUtil.removePrefix(path, Constants.PERM_IMAGE_PATH); try { ImageReq imageReq = imageRespBuilder(absolutePath); BeanUtil.copyProperties(imageReq, imageEntity); diff --git a/web/src/main/java/com/dite/znpt/web/controller/CommonController.java b/web/src/main/java/com/dite/znpt/web/controller/CommonController.java index 04d75dd..8933223 100644 --- a/web/src/main/java/com/dite/znpt/web/controller/CommonController.java +++ b/web/src/main/java/com/dite/znpt/web/controller/CommonController.java @@ -2,20 +2,17 @@ package com.dite.znpt.web.controller; import com.dite.znpt.constant.Message; import com.dite.znpt.domain.Result; -import com.dite.znpt.domain.vo.AppImageResp; import com.dite.znpt.domain.vo.ImageWorkReq; import com.dite.znpt.enums.*; import com.dite.znpt.exception.ServiceException; import com.dite.znpt.service.ImageService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import io.swagger.v3.oas.annotations.Parameter; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.IOException; -import java.util.List; /** * @Author: gaoxiong @@ -110,36 +107,18 @@ public class CommonController { @ApiOperation(value = "上传图片", httpMethod = "POST") @PostMapping("/upload-image/{imageSource}") - public Result uploadImage(@PathVariable String imageSource, - @Parameter(description = "上传用户")@RequestParam(required = false) String uploadUser, - @Parameter(description = "经度")@RequestParam(required = false) String longitude, - @Parameter(description = "纬度")@RequestParam(required = false) String latitude, - @Parameter(description = "海拔")@RequestParam(required = false) String altitude, + public Result uploadImage(@PathVariable String imageSource, ImageWorkReq workReq, MultipartFile file) throws IOException { if(null == file){ throw new ServiceException(Message.IMAGE_IS_EMPTY); } - ImageWorkReq workReq = new ImageWorkReq(); - workReq.setUploadUser(uploadUser); - workReq.setLongitude(longitude); - workReq.setLatitude(latitude); - workReq.setAltitude(altitude); return Result.ok(imageService.batchUploadCommonImage(imageSource, workReq, new MultipartFile[]{file}).get(0)); } @ApiOperation(value = "批量上传图片", httpMethod = "POST") @PostMapping("/batch-upload-image/{imageSource}") - public Result batchUploadImage(@PathVariable String imageSource, - @Parameter(description = "上传用户") @RequestParam(required = false) String uploadUser, - @Parameter(description = "经度") @RequestParam(required = false) String longitude, - @Parameter(description = "纬度") @RequestParam(required = false) String latitude, - @Parameter(description = "海拔") @RequestParam(required = false) String altitude, + public Result batchUploadImage(@PathVariable String imageSource, ImageWorkReq workReq, @RequestParam("file") MultipartFile[] files) throws IOException { - ImageWorkReq workReq = new ImageWorkReq(); - workReq.setUploadUser(uploadUser); - workReq.setLongitude(longitude); - workReq.setLatitude(latitude); - workReq.setAltitude(altitude); return Result.ok(imageService.batchUploadCommonImage(imageSource, workReq, files)); }