From 7b1da9b7db15333148fbf12a6ac3f1122238b2ab Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期四, 05 六月 2025 09:05:11 +0800
Subject: [PATCH] 数据库备份

---
 business/src/main/java/com/ycl/controller/ProjectInfoController.java |  156 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 146 insertions(+), 10 deletions(-)

diff --git a/business/src/main/java/com/ycl/controller/ProjectInfoController.java b/business/src/main/java/com/ycl/controller/ProjectInfoController.java
index d0144ee..9d8b913 100644
--- a/business/src/main/java/com/ycl/controller/ProjectInfoController.java
+++ b/business/src/main/java/com/ycl/controller/ProjectInfoController.java
@@ -1,20 +1,40 @@
 package com.ycl.controller;
 
+import com.alibaba.excel.EasyExcel;
 import com.ycl.common.base.Result;
+import com.ycl.common.exception.base.BaseException;
 import com.ycl.common.group.Add;
 import com.ycl.common.group.Update;
+import com.ycl.common.utils.ProjectCodeGenerator;
+import com.ycl.common.utils.bean.BeanUtils;
+import com.ycl.common.utils.excel.OutputExcelUtils;
+import com.ycl.domain.entity.ProjectInfo;
+import com.ycl.domain.excel.ProjectExcelTemplate;
+import com.ycl.domain.excel.ProjectTempImport;
+import com.ycl.domain.form.DocumentInfoForm;
+import com.ycl.domain.form.ProjectForm;
 import com.ycl.domain.form.ProjectInfoForm;
+import com.ycl.domain.query.ProjectExportQuery;
 import com.ycl.domain.query.ProjectInfoQuery;
+import com.ycl.listener.excel.CurrencyDataListener;
 import com.ycl.service.ProjectInfoService;
+import com.ycl.system.mapper.SysDeptMapper;
+import com.ycl.system.service.ISysDeptService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.constraints.NotEmpty;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
+import java.util.function.Consumer;
 
 /**
  * 椤圭洰绠$悊鍩虹淇℃伅琛� 鍓嶇鎺у埗鍣�
@@ -26,57 +46,173 @@
 @RequiredArgsConstructor
 @Api(value = "椤圭洰绠$悊鍩虹淇℃伅琛�", tags = "椤圭洰绠$悊鍩虹淇℃伅琛ㄧ鐞�")
 @RestController
-@RequestMapping("/api/project-info")
+@RequestMapping("/project/info")
 public class ProjectInfoController {
 
     private final ProjectInfoService projectInfoService;
+    private final SysDeptMapper deptMapper;
+
+    @PostMapping("/import/temp")
+    @ApiOperation(value = "涓存椂瀵煎叆", notes = "涓存椂瀵煎叆")
+//    @PreAuthorize("hasAuthority('projectInfo:add')")
+    public Result importTemp(@RequestPart("file") MultipartFile file) throws IOException {
+        Consumer<List<ProjectTempImport>> consumer = (data) -> {
+            for (ProjectTempImport project : data) {
+                ProjectInfo projectInfo = new ProjectInfo();
+                BeanUtils.copyProperties(project, projectInfo);
+                projectInfo.setYearInvestAmount(project.getTzje());
+                // 澶勭悊涓氫富鍗曚綅銆佷富绠¢儴闂╥d
+                Long yzId = deptMapper.selectByName(project.getProjectOwnerUnit());
+                if (Objects.nonNull(yzId)) {
+                    projectInfo.setProjectOwnerUnit(yzId);
+                }
+                Long zgId = deptMapper.selectByName(project.getCompetentDepartment());
+                if (Objects.nonNull(zgId)) {
+                    projectInfo.setCompetentDepartment(zgId + "");
+                }
+                projectInfo.setArea(project.getArea());
+                projectInfo.setYear("2025");
+                // 璁剧疆涓哄鏍稿凡閫氳繃
+                projectInfo.setUsedStatus(2);
+                projectInfoService.save(projectInfo);
+            }
+        };
+        EasyExcel.read(file.getInputStream(), ProjectTempImport.class, new CurrencyDataListener(consumer)).headRowNumber(1).doReadAll();
+        return Result.ok();
+    }
 
     @PostMapping
     @ApiOperation(value = "娣诲姞", notes = "娣诲姞")
-    @PreAuthorize("hasAuthority('projectInfo:add')")
+//    @PreAuthorize("hasAuthority('projectInfo:add')")
     public Result add(@RequestBody @Validated(Add.class) ProjectInfoForm form) {
         return projectInfoService.add(form);
     }
 
+    @PostMapping("/document")
+    @ApiOperation(value = "娣诲姞鐩稿叧鏂囦欢", notes = "娣诲姞鐩稿叧鏂囦欢")
+//    @PreAuthorize("hasAuthority('projectInfo:add')")
+    public Result addDoc(@RequestBody @Validated(Add.class) DocumentInfoForm form) {
+        return projectInfoService.addDoc(form);
+    }
+
     @PutMapping
     @ApiOperation(value = "淇敼", notes = "淇敼")
-    @PreAuthorize("hasAuthority('projectInfo:edit')")
+//    @PreAuthorize("hasAuthority('projectInfo:edit')")
     public Result update(@RequestBody @Validated(Update.class) ProjectInfoForm form) {
         return projectInfoService.update(form);
     }
 
     @DeleteMapping("/{id}")
     @ApiOperation(value = "ID鍒犻櫎", notes = "ID鍒犻櫎")
-    @PreAuthorize("hasAuthority('projectInfo:del')")
-    public Result removeById(@PathVariable("id") String id) {
+//    @PreAuthorize("hasAuthority('projectInfo:del')")
+    public Result removeById(@PathVariable("id") Long id) {
         return projectInfoService.removeById(id);
     }
 
     @DeleteMapping("/batch")
     @ApiOperation(value = "鎵归噺鍒犻櫎", notes = "鎵归噺鍒犻櫎")
-    @PreAuthorize("hasAuthority('projectInfo:del:batch')")
+//    @PreAuthorize("hasAuthority('projectInfo:del:batch')")
     public Result remove(@RequestBody @NotEmpty(message = "璇烽�夋嫨鏁版嵁") List<String> ids) {
         return projectInfoService.remove(ids);
     }
 
     @GetMapping("/page")
     @ApiOperation(value = "鍒嗛〉", notes = "鍒嗛〉")
-    @PreAuthorize("hasAuthority('projectInfo:page')")
+//    @PreAuthorize("hasAuthority('projectInfo:page')")
     public Result page(ProjectInfoQuery query) {
         return projectInfoService.page(query);
     }
 
     @GetMapping("/{id}")
     @ApiOperation(value = "璇︽儏", notes = "璇︽儏")
-    @PreAuthorize("hasAuthority('projectInfo:detail')")
+//    @PreAuthorize("hasAuthority('projectInfo:detail')")
     public Result detail(@PathVariable("id") Integer id) {
         return projectInfoService.detail(id);
     }
 
+    @GetMapping("/document/{id}")
+    @ApiOperation(value = "鐩稿叧鏂囦欢璇︽儏", notes = "鐩稿叧鏂囦欢璇︽儏")
+//    @PreAuthorize("hasAuthority('projectInfo:detail')")
+    public Result docDetail(@PathVariable("id") Integer id) {
+        return projectInfoService.docDetail(id);
+    }
+
     @GetMapping("/list")
-    @PreAuthorize("hasAuthority('projectInfo:list')")
+//    @PreAuthorize("hasAuthority('projectInfo:list')")
     @ApiOperation(value = "鍒楄〃", notes = "鍒楄〃")
     public Result list() {
         return projectInfoService.all();
     }
+
+    /**
+     * 鐢熸垚椤圭洰缂栧彿
+     *
+     * @return 椤圭洰缂栧彿
+     */
+    @GetMapping("/getProjectCode")
+    public Result generateProjectCode() {
+        return Result.ok().data(ProjectCodeGenerator.generateProjectCode());
+    }
+
+    @GetMapping("/searchByKey")
+    public Result searchByKey(@RequestParam(required = false) String wordKey) {
+        return projectInfoService.searchByKey(wordKey);
+    }
+
+    @GetMapping("/getManagerFlag/{recordId}")
+    public Result getManagerFlag(@PathVariable("recordId") Integer recordId) {
+        return projectInfoService.getManagerFlag(recordId);
+    }
+
+    /**
+     * 瀵煎嚭妯℃澘
+     *
+     * @param response
+     * @return
+     */
+    @PostMapping("/export/template")
+    public void exportTemplate(HttpServletResponse response) throws IOException {
+        List<String> fieldList = new ArrayList<>();
+        OutputExcelUtils.export(response, "瀵煎叆妯℃澘", "椤圭洰淇℃伅", null, ProjectExcelTemplate.class, fieldList);
+    }
+
+    /**
+     * 椤圭洰瀵煎嚭
+     *
+     * @param response
+     * @throws IOException
+     */
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, ProjectExportQuery query) throws IOException {
+        projectInfoService.export(response, query);
+    }
+
+    @PutMapping("usedStatus/{id}/{usedStatus}")
+    @ApiOperation(value = "淇敼浣跨敤鐘舵��", notes = "淇敼浣跨敤鐘舵��")
+//    @PreAuthorize("hasAuthority('projectInfo:edit')")
+    public Result updateUsedStatus(@PathVariable Integer id, @PathVariable Integer usedStatus) {
+        return projectInfoService.updateUsedStatus(id, usedStatus);
+    }
+
+    /**
+     * 椤圭洰瀵煎叆
+     * @param file
+     * @return
+     */
+    @PostMapping("/import")
+    public Result importProject(MultipartFile file) {
+        if (file.getSize() > 100 * 1024 * 1024) {
+            throw new BaseException("鏂囦欢杩囧ぇ锛屾枃浠朵笉寰楄秴杩�100MB");
+        }
+        projectInfoService.importProject(file);
+        return Result.ok();
+    }
+
+    @PostMapping("/editProject")
+    public Result editProject(@RequestBody ProjectForm form) {
+        return projectInfoService.editProject(form);
+    }
+
+
+
 }

--
Gitblit v1.8.0