fuliqi
2024-12-23 deb49773f332f83dafb78788bc3d9b2b39fa421c
business/src/main/java/com/ycl/controller/ProjectInfoController.java
@@ -1,20 +1,28 @@
package com.ycl.controller;
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.excel.OutputExcelUtils;
import com.ycl.domain.excel.ProjectExcelTemplate;
import com.ycl.domain.form.DocumentInfoForm;
import com.ycl.domain.form.ProjectInfoForm;
import com.ycl.domain.query.ProjectExportQuery;
import com.ycl.domain.query.ProjectInfoQuery;
import com.ycl.service.ProjectInfoService;
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.util.ArrayList;
import java.util.List;
/**
@@ -39,6 +47,13 @@
        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')")
@@ -49,7 +64,7 @@
    @DeleteMapping("/{id}")
    @ApiOperation(value = "ID删除", notes = "ID删除")
//    @PreAuthorize("hasAuthority('projectInfo:del')")
    public Result removeById(@PathVariable("id") String id) {
    public Result removeById(@PathVariable("id") Long id) {
        return projectInfoService.removeById(id);
    }
@@ -74,6 +89,13 @@
        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 = "列表")
@@ -83,10 +105,62 @@
    /**
     * 生成项目编号
     *
     * @return 项目编号
     */
    @GetMapping("/getProjectCode")
    public Result generateProjectCode() {
        return Result.ok().data(ProjectCodeGenerator.generateProjectCode());
    };
    }
    ;
    @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();
    }
}