zxl
2025-04-02 01c29b4b6cfb1a3223cf9e322f33ead42093e77c
business/src/main/java/com/ycl/controller/ProjectInfoController.java
@@ -1,25 +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.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;
/**
 * 项目管理基础信息表 前端控制器
@@ -35,6 +50,36 @@
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());
                // 处理业主单位、主管部门id
                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 = "添加")
@@ -42,12 +87,14 @@
    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')")
@@ -82,12 +129,14 @@
    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')")
    @ApiOperation(value = "列表", notes = "列表")
@@ -97,12 +146,18 @@
    /**
     * 生成项目编号
     *
     * @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) {
@@ -111,14 +166,53 @@
    /**
     * 导出模板
     *
     * @param response
     * @return
     */
    @PostMapping("/export/template")
    public void exportTemplate(HttpServletResponse response,
                               @RequestBody List<String> fieldList
    ) throws IOException {
        OutputExcelUtils.export(response, "导入模板", "项目信息", null, ProjectExcelTemplate.class ,fieldList);
    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);
    }
}