Просмотр исходного кода

Merge branch 'master' into 'master'

指标文件上传

See merge request lighter/web-server!137
huangshuhua 6 месяцев назад
Родитель
Сommit
674901c8ab

+ 16 - 0
src/main/java/thyyxxk/webserver/controller/targetmanagement/TargetManagementController.java

@@ -262,4 +262,20 @@ public class TargetManagementController {
         return service.selectTargetDictConstantData(dto);
     }
 
+    @PostMapping("/uploadTargetFile")
+    public ResultVo<Map<String, Object>> uploadTargetFile(@Validated ZbReportResult result){
+        return service.uploadTargetFile(result);
+    }
+
+    @PostMapping("/selectTargetFileById")
+    public ResultVo<Map<String, Object>> selectTargetFileById(@RequestBody @Validated ZbReportResult result){
+        return service.selectTargetFileById(result);
+    }
+
+    @GetMapping("/deleteTargetFileByFileId")
+    public ResultVo<Map<String, Object>> deleteTargetFileByFileId(@RequestParam("fileId") String fileId, @RequestParam("id") String id,
+                                                                  @RequestParam("pid") String pid, @RequestParam("year") String year) {
+        return service.deleteTargetFileByFileId(fileId, id, pid, year);
+    }
+
 }

+ 4 - 0
src/main/java/thyyxxk/webserver/dao/his/highreport/HighReportDao.java

@@ -278,4 +278,8 @@ public interface HighReportDao {
             " order by sort " +
             "</script> ")
     List<ReportBaseInfo> selectTargetDictConstantData(TargetManagement dto);
+
+    @Update(" update zb_report_result set file_id = #{fileId} " +
+            "  where id = #{id} and pid = #{pid} and year = #{year} ")
+    void updateZbReportResultFileIdById(ZbReportResult result);
 }

+ 4 - 1
src/main/java/thyyxxk/webserver/dao/his/targetmanagement/ZbZdBaseInfoDao.java

@@ -5,7 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
-import thyyxxk.webserver.entity.highreport.ZbReportCycleScore;
+import thyyxxk.webserver.entity.archive.ArchiveUpload;
 import thyyxxk.webserver.entity.targetmanagement.TargetDictTree;
 import thyyxxk.webserver.entity.targetmanagement.TargetManagement;
 import thyyxxk.webserver.entity.targetmanagement.ZbZdBaseInfo;
@@ -153,4 +153,7 @@ public interface ZbZdBaseInfoDao {
     @Select(" select * from zb_zd_base_info where pid = #{pid} order by id ")
     List<ZbZdBaseInfo> selectTargetDictScoreBySecond(@Param("pid") String pid);
 
+    @Select(" select * from archive_upload where id = #{id} ")
+    ArchiveUpload selectTargetFileById(@Param("id") String id);
+
 }

+ 6 - 1
src/main/java/thyyxxk/webserver/entity/highreport/ZbReportResult.java

@@ -1,9 +1,11 @@
 package thyyxxk.webserver.entity.highreport;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * @Description: 指标报表结果表
@@ -31,5 +33,8 @@ public class ZbReportResult {
     private String opTime;
     // 年度周期
     private String reportCycle;
-
+    // 文件上传地址的id
+    private String fileId;
+    @TableField(exist = false)
+    private MultipartFile file;
 }

+ 106 - 1
src/main/java/thyyxxk/webserver/service/targetmanagement/TargetManagementService.java

@@ -3,6 +3,7 @@ package thyyxxk.webserver.service.targetmanagement;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.jetbrains.annotations.NotNull;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.dao.his.highreport.HighReportDao;
@@ -13,6 +14,7 @@ import thyyxxk.webserver.dao.his.targetmanagement.ZbReportCycleDao;
 import thyyxxk.webserver.dao.his.targetmanagement.ZbReportCycleScoreDao;
 import thyyxxk.webserver.dao.his.targetmanagement.ZbZdBaseInfoDao;
 import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.archive.ArchiveUpload;
 import thyyxxk.webserver.entity.highreport.HighReportDto;
 import thyyxxk.webserver.entity.highreport.ReportBaseInfo;
 import thyyxxk.webserver.entity.highreport.ReportType;
@@ -28,6 +30,7 @@ import thyyxxk.webserver.entity.login.UserInfo;
 import thyyxxk.webserver.entity.targetmanagement.TargetDictTree;
 import thyyxxk.webserver.entity.targetmanagement.TargetManagement;
 import thyyxxk.webserver.entity.targetmanagement.ZbZdBaseInfo;
+import thyyxxk.webserver.service.archive.ArchiveServer;
 import thyyxxk.webserver.service.hutoolcache.UserCache;
 import thyyxxk.webserver.utils.DateUtil;
 import thyyxxk.webserver.utils.DecimalUtil;
@@ -74,7 +77,11 @@ public class TargetManagementService {
 
     private final ZbReportCycleScoreDao scoreDao;
 
- 
+    private final ArchiveServer archiveServer;
+
+    @Value("${is-prod}")
+    private boolean isProd;
+    private static final String TARGET_PATH = "/testZb";
 
     /**
      * @description: 查询指标字典基本信息
@@ -1413,4 +1420,102 @@ public class TargetManagementService {
         return ResultVoUtil.success(list);
     }
 
+    /**
+     * @Description 上传指标文件
+     * @Author hsh
+     * @param result 指标结果信息
+     * @return map
+     * @Date 2025/5/10 0010 15:48
+     */
+    public ResultVo<Map<String, Object>> uploadTargetFile(ZbReportResult result){
+        Map<String, Object> map = new HashMap<>();
+        ZbReportResult re = reportDao.selectReportResultByYear(result.getId(), result.getPid(), result.getYear());
+        if(null == re){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到对应的指标结果,请检查!");
+        }
+        ArchiveServer.UploadResult uploadResult = archiveServer.uploadFile(result.getFile(), TARGET_PATH);
+        String url = uploadResult.getPath();
+        map.put("url", url);
+        String fileId = re.getFileId();
+        if(StringUtil.isEmpty(fileId)){
+            result.setFileId(uploadResult.getId());
+        } else {
+            fileId = fileId + "," + uploadResult.getId();
+            result.setFileId(fileId);
+        }
+        reportDao.updateZbReportResultFileIdById(result);
+        return ResultVoUtil.success(map);
+    }
+
+    /**
+     * @Description 查询指标文件
+     * @Author hsh
+     * @param result 指标信息
+     * @return map
+     * @Date 2025/5/12 0012 19:29
+     */
+    public ResultVo<Map<String, Object>> selectTargetFileById(ZbReportResult result){
+        Map<String, Object> map = new HashMap<>();
+        List<ArchiveUpload> list = new ArrayList<>();
+        if(!StringUtil.isEmpty(result.getFileId())){
+            String[] f = result.getFileId().split(",");
+            for(String id : f){
+                if(!StringUtil.isEmpty(id)){
+                    ArchiveUpload pu = zbZdDao.selectTargetFileById(id);
+                    if(null != pu){
+                        pu.setPath(pu.getPath().replace("/mnt/archive", "/thyyarchive"));
+                        list.add(pu);
+                    }
+                }
+            }
+        }
+        if(isProd){
+            map.put("targetPath", "/thyyarchive/archive" + TARGET_PATH);
+        } else {
+            map.put("targetPath", "/thyyarchive/archive-test" + TARGET_PATH);
+        }
+        map.put("fileList", list);
+        return ResultVoUtil.success(map);
+    }
+
+    /**
+     * @Description 根据文件路径删除文件
+     * @Author hsh
+     * @param id 文件id
+     * @return map
+     * @Date 2025/5/13 0013 15:31
+     */
+    public ResultVo<Map<String, Object>> deleteTargetFileByFileId(String fileId, String id, String pid, String year){
+        if(StringUtil.isEmpty(fileId)){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到删除的文件id,请检查!");
+        }
+        if(StringUtil.isEmpty(id) || StringUtil.isEmpty(pid) || StringUtil.isEmpty(year)){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到删除的文件id,请检查!");
+        }
+        ZbReportResult re = reportDao.selectReportResultByYear(id, pid, year);
+        if(null == re){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到对应的指标结果,请检查!");
+        }
+        Map<String, Object> map = new HashMap<>();
+        try {
+            archiveServer.delUploadById(fileId);
+
+            if(null != re.getFileId() && re.getFileId().contains(fileId)){
+                // 删除对应指标的fileId
+                ZbReportResult result = new ZbReportResult();
+                result.setId(id);
+                result.setPid(pid);
+                result.setYear(year);
+                String str = re.getFileId().replace(fileId + ",", "")
+                        .replace("," + fileId, "").replace(fileId, "");
+                result.setFileId(",".equals(str) ? "" : str);
+                reportDao.updateZbReportResultFileIdById(result);
+            }
+        } catch(Exception e){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "根据【" + fileId + "】删除的文件失败,请检查!");
+        }
+        map.put("cg", "删除指标文件成功!");
+        return ResultVoUtil.success(map);
+    }
+
 }