소스 검색

修改园区总览问题

nahida 1 년 전
부모
커밋
4672310b7a

+ 6 - 7
park-overview-service/src/main/java/com/zksy/park/controller/FileController.java

@@ -26,10 +26,10 @@ public class FileController {
     @Log(title = "文件信息-文件上传")
     @RequestMapping(path = "/filePath",method = RequestMethod.POST)
     @ApiOperation(value = "文件上传",notes = "文件上传")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "file", value = "文件", required = true, paramType = "path", allowMultiple = false, dataType = "file"),
-            @ApiImplicitParam(name = "businessType", value = "文件夹名称", required = true, paramType = "path", allowMultiple = false, dataType = "String")
-    })
+//    @ApiImplicitParams({
+//            @ApiImplicitParam(name = "file", value = "文件", required = true, paramType = "path", allowMultiple = false, dataType = "file"),
+//            @ApiImplicitParam(name = "businessType", value = "文件夹名称", required = true, paramType = "path", allowMultiple = false, dataType = "String")
+//    })
     public Result minioUploadResUrl(MultipartFile file,String businessType) throws Exception {
         String result = minioFileStorageService.uploadFile(file,businessType);
         return Result.ok(result);
@@ -72,10 +72,9 @@ public class FileController {
     @ApiOperation(value = "查询文件")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "formId", value = "对应表单id", required = true, paramType = "path", allowMultiple = false, dataType = "String"),
-            @ApiImplicitParam(name = "businessType", value = "业务类型", required = true, paramType = "path", allowMultiple = false, dataType = "String")
     })
-    public Result selectFile(@RequestParam String formId,@RequestParam String businessType){
-        return Result.ok(service.selectFile(formId,businessType));
+    public Result selectFile(@RequestParam String formId){
+        return Result.ok(service.selectFile(formId));
     }
 }
 

+ 16 - 14
park-overview-service/src/main/java/com/zksy/park/controller/ParkInfoController.java

@@ -6,6 +6,7 @@ import com.zksy.common.core.domain.Result;
 import com.zksy.common.enums.BusinessType;
 import com.zksy.common.utils.SearchUtil;
 import com.zksy.park.domain.ParkInfo;
+import com.zksy.park.domain.dto.PackInfoDto;
 import com.zksy.park.service.ParkInfoService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -27,10 +28,10 @@ public class ParkInfoController {
     @Autowired
     private ParkInfoService service;
 
-    @GetMapping("/getById/{borrowId}")
+    @GetMapping("/getById/{id}")
     @ApiOperation(value = "园区信息搜索getById")
-    public Result getById(@PathVariable String borrowId) {
-        return Result.ok(service.getById(borrowId));
+    public Result getById(@PathVariable String id) {
+        return service.getByIdWithFile(id);
     }
 
     @GetMapping("/findByPage")
@@ -45,24 +46,25 @@ public class ParkInfoController {
         return Result.ok(service.list(SearchUtil.parseWhereSql(conditionJson)));
     }
 
-    /**
-     * 新增经营异常名录
-     */
     @PostMapping("/save")
     @ApiOperation(value = "园区信息新增")
     @Log(title = "新增园区信息", businessType = BusinessType.INSERT)
-    public boolean save(@RequestBody ParkInfo entity) {
-        return service.saveParkInfo(entity);
+    public Result<Object> save(@ModelAttribute PackInfoDto dto) {
+        return service.saveParkInfo(dto);
     }
 
-    /**
-     * 修改经营异常名录
-     */
-    @PostMapping("/updateById")
+    @PutMapping("/updateById")
     @ApiOperation(value = "园区信息修改")
     @Log(title = "修改园区信息", businessType = BusinessType.UPDATE)
-    public boolean updateById(@RequestBody ParkInfo entity) {
-        return service.updateById(entity);
+    public Result<String> updateById(@ModelAttribute PackInfoDto dto) {
+        return service.updateByParkInfoId(dto);
+    }
+
+    @DeleteMapping("/deleteById")
+    @ApiOperation(value = "园区信息删除")
+    @Log(title = "修改园区信息", businessType = BusinessType.DELETE)
+    public Result<String> deleteById(String id) {
+        return service.deleteById(id);
     }
 
 }

+ 0 - 5
park-overview-service/src/main/java/com/zksy/park/domain/FileGeneral.java

@@ -35,9 +35,4 @@ import lombok.experimental.Accessors;
     @ApiModelProperty(value = "文件路径")
     private String filePath;
 
-    @ApiModelProperty(value = "业务类型")
-    private String businessType;
-
-
-
 }

+ 6 - 1
park-overview-service/src/main/java/com/zksy/park/domain/ParkInfo.java

@@ -10,6 +10,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
+import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.time.LocalDateTime;
@@ -74,9 +75,11 @@ public class ParkInfo extends Model<ParkInfo> {
     private String developmentArea;
 
     @ApiModelProperty(value = "创建时间")
+    @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
     private LocalDateTime createTime;
 
     @ApiModelProperty(value = "修改时间")
+    @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
     private LocalDateTime updateTime;
 
     @ApiModelProperty(value = "文件路径")
@@ -84,6 +87,8 @@ public class ParkInfo extends Model<ParkInfo> {
     private String filePath;
 
     @ApiModelProperty(value = "业务类型")
-    @TableField(exist = false)
     private String businessType;
+
+    @ApiModelProperty(value = "是否启用")
+    private Integer isEnable;
 }

+ 17 - 0
park-overview-service/src/main/java/com/zksy/park/domain/dto/PackInfoDto.java

@@ -0,0 +1,17 @@
+package com.zksy.park.domain.dto;
+
+import com.zksy.park.domain.ParkInfo;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.web.multipart.MultipartFile;
+
+@AllArgsConstructor
+@NoArgsConstructor
+@Data
+public class PackInfoDto extends ParkInfo {
+    //前端传一个文件过来(非路径)
+    @ApiModelProperty(value = "文件")
+    private MultipartFile file;
+}

+ 1 - 1
park-overview-service/src/main/java/com/zksy/park/service/FileGeneralService.java

@@ -13,5 +13,5 @@ import java.util.List;
  * @date 2024/12/23 15:38:12
  */
 public interface FileGeneralService extends IService<FileGeneral> {
-    List<FileGeneral> selectFile(String formId, String businessType);
+    List<FileGeneral> selectFile(String formId);
 }

+ 10 - 2
park-overview-service/src/main/java/com/zksy/park/service/ParkInfoService.java

@@ -1,15 +1,23 @@
 package com.zksy.park.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.zksy.common.core.domain.Result;
 import com.zksy.park.domain.ParkInfo;
+import com.zksy.park.domain.dto.PackInfoDto;
 
 /**
- * @author Administrator
+ * @author nahida
  * @version 1.0
  * @project dh-server-micro
  * @description 园区信息
  * @date 2024/12/23 08:54:28
  */
 public interface ParkInfoService extends IService<ParkInfo> {
-    boolean saveParkInfo(ParkInfo entity);
+    Result<Object> saveParkInfo(PackInfoDto dto);
+
+    Result<String> updateByParkInfoId(PackInfoDto dto);
+
+    Result<String> deleteById(String id);
+
+    Result<ParkInfo> getByIdWithFile(String id);
 }

+ 1 - 2
park-overview-service/src/main/java/com/zksy/park/service/imp/FileGeneralServiceImpl.java

@@ -22,10 +22,9 @@ import java.util.List;
 @Service
 public class FileGeneralServiceImpl extends ServiceImpl<FileGeneralMapper, FileGeneral> implements FileGeneralService {
     @Override
-    public List<FileGeneral> selectFile(String formId, String businessType) {
+    public List<FileGeneral> selectFile(String formId) {
         QueryWrapper<FileGeneral> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("form_id", formId);
-        queryWrapper.eq("business_type", businessType);
         return list(queryWrapper);
     }
 }

+ 80 - 11
park-overview-service/src/main/java/com/zksy/park/service/imp/ParkInfoServiceImpl.java

@@ -1,18 +1,26 @@
 package com.zksy.park.service.imp;
 
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zksy.common.core.domain.Result;
 import com.zksy.park.domain.FileGeneral;
 import com.zksy.park.domain.ParkInfo;
+import com.zksy.park.domain.dto.PackInfoDto;
 import com.zksy.park.mapper.ParkInfoMapper;
 import com.zksy.park.service.FileGeneralService;
 import com.zksy.park.service.ParkInfoService;
 import com.zksy.service.MinioFileStorageService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDateTime;
 
 /**
  * 经营异常名录Service业务层处理
- * 
+ *
  * @author sy
  * @date 2024-05-08
  */
@@ -20,25 +28,86 @@ import org.springframework.stereotype.Service;
 public class ParkInfoServiceImpl extends ServiceImpl<ParkInfoMapper, ParkInfo> implements ParkInfoService {
     @Autowired
     private FileGeneralService fileGeneralService;
+    @Autowired
+    private MinioFileStorageService minioFileStorageService;
 
     @Override
-    public boolean saveParkInfo(ParkInfo entity) {
+    @Transactional
+    public Result<Object> saveParkInfo(PackInfoDto dto) {
         try {
-            int entityResult = baseMapper.insert(entity);
-            boolean fileGeneralResult = false;
-            if(!"".equals(entity.getFilePath())){
+            if (dto.getFile() != null) {
+                String filePath = minioFileStorageService.uploadFile(dto.getFile(), dto.getBusinessType());
+                dto.setFilePath(filePath);
+            }
+            ParkInfo entity = BeanUtil.copyProperties(dto, ParkInfo.class);
+            entity.setCreateTime(LocalDateTime.now());
+            entity.setUpdateTime(LocalDateTime.now());
+            baseMapper.insert(entity);
+            if (StrUtil.isNotBlank(dto.getFilePath())) {
                 FileGeneral fileGeneral = new FileGeneral();
                 fileGeneral.setFormId(entity.getId());
-                fileGeneral.setBusinessType(entity.getBusinessType());
-                fileGeneral.setFilePath(entity.getFilePath());
-                fileGeneralResult = fileGeneralService.save(fileGeneral);
+                fileGeneral.setFilePath(dto.getFilePath());
+                fileGeneralService.save(fileGeneral);
             }
-            if (entityResult >= 1 && fileGeneralResult == true){
-                return true;
+            return Result.ok("新增成功");
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    @Transactional
+    public Result<String> updateByParkInfoId(PackInfoDto dto) {
+        try {
+            if (dto.getFile() != null) {
+                LambdaQueryWrapper<FileGeneral> wrapper = new LambdaQueryWrapper<>();
+                wrapper.eq(FileGeneral::getFormId, dto.getId());
+                fileGeneralService.remove(wrapper);
+                String filePath = minioFileStorageService.uploadFile(dto.getFile(), dto.getBusinessType());
+                dto.setFilePath(filePath);
+                FileGeneral fileGeneral = new FileGeneral();
+                fileGeneral.setFormId(dto.getId());
+                fileGeneral.setFilePath(dto.getFilePath());
+                fileGeneralService.save(fileGeneral);
             }
+            ParkInfo entity = BeanUtil.copyProperties(dto, ParkInfo.class);
+            entity.setUpdateTime(LocalDateTime.now());
+            this.updateById(entity);
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
-        return false;
+        return Result.ok("更新成功");
+    }
+
+    @Override
+    @Transactional
+    public Result<String> deleteById(String id) {
+        if (StrUtil.isNotBlank(id)) {
+            LambdaQueryWrapper<FileGeneral> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(FileGeneral::getFormId, id);
+            FileGeneral one = fileGeneralService.getOne(wrapper);
+            if(one!=null){
+                minioFileStorageService.deleteFile(one.getFilePath());
+                fileGeneralService.remove(wrapper);
+            }
+            this.removeById(id);
+            return Result.ok("删除成功");
+        }
+        return Result.error("删除失败");
+    }
+
+    @Override
+    public Result<ParkInfo> getByIdWithFile(String id) {
+        if (StrUtil.isNotBlank(id)) {
+            ParkInfo parkInfo = this.getById(id);
+            LambdaQueryWrapper<FileGeneral> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(FileGeneral::getFormId, id);
+            FileGeneral one = fileGeneralService.getOne(wrapper);
+            if(one!=null){
+                parkInfo.setFilePath(one.getFilePath());
+            }
+            return Result.ok(parkInfo);
+        }
+        return Result.error("获取失败");
     }
 }

+ 4 - 0
park-overview-service/src/main/resources/bootstrap.yaml

@@ -3,6 +3,10 @@ spring:
     name: park-service
   profiles:
     active: dev
+  servlet:
+    multipart:
+      max-file-size: 100MB
+      max-request-size: 100MB
   main:
     allow-bean-definition-overriding: true
   cloud: