From ac09cde37432059dacaedfe296168eaeb0ae198a Mon Sep 17 00:00:00 2001 From: xjm Date: Wed, 14 Aug 2024 15:22:06 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E8=A6=81=E6=B2=BF=E6=B2=B3=E6=9D=91?= =?UTF-8?q?=E8=90=BD=E5=B1=85=E6=B0=91=E6=88=B7=E6=96=B0=E5=A2=9E=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0,=E8=B4=A3=E4=BB=BB=E4=BD=93?= =?UTF-8?q?=E7=B3=BB=E4=B8=BB=E9=94=AE=E5=BA=8F=E5=88=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xyt/controller/IaCFlrvvlgController.java | 46 ++++++++++++++++++- .../project/xyt/model/ResSafePersonB.java | 3 ++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gunshi/project/xyt/controller/IaCFlrvvlgController.java b/src/main/java/com/gunshi/project/xyt/controller/IaCFlrvvlgController.java index 3da5241..abc8ffd 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/IaCFlrvvlgController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/IaCFlrvvlgController.java @@ -1,18 +1,24 @@ package com.gunshi.project.xyt.controller; +import com.google.common.collect.Lists; import com.gunshi.core.result.R; +import com.gunshi.file.model.FileDescriptor; import com.gunshi.project.xyt.entity.vo.HomeIaCFlrvvlgVo; +import com.gunshi.project.xyt.model.FileAssociations; import com.gunshi.project.xyt.model.IaCFlrvvlg; +import com.gunshi.project.xyt.service.FileAssociationsService; import com.gunshi.project.xyt.service.IaCFlrvvlgService; import com.gunshi.project.xyt.service.StAddvcdDService; import com.gunshi.project.xyt.validate.markers.Insert; import com.gunshi.project.xyt.validate.markers.Update; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.io.Serializable; import java.util.List; @@ -26,7 +32,7 @@ import java.util.Objects; @Tag(name = "重要沿河村落居民户调查成果表") @RestController @RequestMapping(value="/iaCFlrvvlg") -public class IaCFlrvvlgController { +public class IaCFlrvvlgController extends AbstractCommonFileController{ @Autowired private IaCFlrvvlgService service; @@ -34,6 +40,8 @@ public class IaCFlrvvlgController { @Autowired private StAddvcdDService stAddvcdDService; + @Autowired + private FileAssociationsService fileService; @Operation(summary = "新增") @PostMapping("/insert") @@ -87,4 +95,40 @@ public class IaCFlrvvlgController { return R.ok(service.getDetailsAndMonitoringDataLis()); } + + + @Operation(summary = "上传相关图片文件") + @PostMapping(path = "/setImgFile", consumes = "multipart/form-data") + public R setImgFile(@Parameter(description = "文件") @RequestPart("files") MultipartFile[] files) throws Exception { + + for (MultipartFile file : files) { + + String fileName = file.getOriginalFilename(); + String eicd = fileName.split("\\.")[0]; + + FileDescriptor fd = new FileDescriptor(); + fd.setBusinessType(getBusinessType()); + fd.setGroupId(getGroupId()); + fd.setUserId(1L); + fd.setAccessGroup(getService().getAccessGroup()); + fd.setFilePath(generateFilePath(getProperty().getAppCode(), getBusinessType(), 1L, getGroupId(), fileName)); + fd.setFileName(fileName); + fd.setFileLength(file.getSize()); + + getService().upload(fd, file.getInputStream()); + + FileAssociations fileAssociations = new FileAssociations(); + fileAssociations.setFileId(fd.getFileId()); + + fileService.saveFile(Lists.newArrayList(fileAssociations), getGroupId(), eicd); + } + + + return R.ok(); + } + + @Override + public String getGroupId() { + return "iaCFlrvvlg"; + } } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/model/ResSafePersonB.java b/src/main/java/com/gunshi/project/xyt/model/ResSafePersonB.java index 5d6dcb0..8467138 100644 --- a/src/main/java/com/gunshi/project/xyt/model/ResSafePersonB.java +++ b/src/main/java/com/gunshi/project/xyt/model/ResSafePersonB.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.gunshi.core.dateformat.DateFormatString; import com.gunshi.project.xyt.validate.markers.Update; import io.swagger.v3.oas.annotations.media.Schema; @@ -37,6 +39,7 @@ public class ResSafePersonB implements Serializable { @Schema(description="主键") // @Size(max = 0,message = "主键最大长度要小于 0") @NotNull(message = "主键不能为空",groups = {Update.class}) + @JsonSerialize(using = ToStringSerializer.class) private Long id; /**