zss
2025-02-20 a465f67fdd32f818f35938eded708b166b1cc1f7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.ruoyi.manage.controller;
 
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.alibaba.excel.read.listener.PageReadListener;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.exception.ErrorException;
import com.ruoyi.manage.pojo.ManageControlPlanList;
import com.ruoyi.manage.service.ManageControlPlanListService;
import com.ruoyi.manage.vo.ManageControlPlanListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
 
/**
 * <p>
 * 重大风险因素分析及控制计划清单 前端控制器
 * </p>
 *
 * @author 芯导软件(江苏)有限公司
 * @since 2024-11-15 02:58:30
 */
@Api(tags = "重大风险因素分析及控制计划清单")
@RestController
@RequestMapping("/manageControlPlanList")
public class ManageControlPlanListController {
 
 
    @Resource
    private ManageControlPlanListService manageControlPlanListService;
 
 
 
    @ApiOperation(value = "分页查询")
    @GetMapping("/getPageList")
    public Result<IPage<ManageControlPlanListVo>> getPageList(Page page) {
        return Result.success(manageControlPlanListService.getPageList(page));
    }
 
    @ApiOperation(value = "批准")
    @GetMapping("/approvalOfControlPlanChecklist")
    public Result<?> approvalOfControlPlanChecklist(Integer approve, Integer status){
        manageControlPlanListService.update(Wrappers.<ManageControlPlanList>lambdaUpdate()
                .set(ManageControlPlanList::getApprove, approve)
                .set(ManageControlPlanList::getApproveStatus, status)
                .set(ManageControlPlanList::getApproveDate, LocalDateTime.now()));
        return Result.success();
    }
 
    @ApiOperation(value = "审批")
    @GetMapping("/riskAnalysisApprovalOfControlPlanChecklist")
    public Result<?> riskAnalysisApprovalOfControlPlanChecklist(Integer approval, Integer status){
        manageControlPlanListService.update(Wrappers.<ManageControlPlanList>lambdaUpdate()
                .set(ManageControlPlanList::getApproval, approval)
                .set(ManageControlPlanList::getApprovalStatus, status)
                .set(ManageControlPlanList::getApprovalDate, LocalDateTime.now()));
        return Result.success();
    }
 
    @PostMapping("/importControlPlanList")
    public void importControlPlanList(MultipartFile file) throws IOException {
        boolean excelFile = isExcelFile(file);
        if (!excelFile) {
            throw new ErrorException("请导入excel文件!");
        }
        EasyExcel.read(file.getInputStream(), ManageControlPlanList.class, new PageReadListener<ManageControlPlanList>(dataList -> {
            Integer userId = SecurityUtils.getUserId().intValue();
            dataList.forEach(i -> {
                i.setEditor(userId);
                i.setEditorDate(LocalDateTime.now());
                i.setApproveStatus(0);
                i.setApprovalStatus(0);
            });
            manageControlPlanListService.saveOrUpdateBatch(dataList);
        })).sheet().doRead();
    }
 
    @ApiOperation(value = "新增")
    @PostMapping("/analysisOfMajorRiskFactorsAdded")
    public void analysisOfMajorRiskFactorsAdded(@RequestBody ManageControlPlanList manageControlPlanList) throws IOException {
        Integer userId = SecurityUtils.getUserId().intValue();
        manageControlPlanList.setEditor(userId);
        manageControlPlanList.setEditorDate(LocalDateTime.now());
        manageControlPlanListService.saveOrUpdate(manageControlPlanList);
    }
 
    @ApiOperation(value = "删除")
    @GetMapping("/deleteSignificantRiskFactorAnalysis")
    public void deleteSignificantRiskFactorAnalysis(Integer id) throws IOException {
        manageControlPlanListService.removeById(id);
    }
 
    /**
     *
     * @return
     */
 
    @ApiOperation(value = "重大风险因素分析及控制计划清单")
    @GetMapping("/exportSignificantRiskFactors")
    public void exportSignificantRiskFactors(HttpServletResponse response){
        manageControlPlanListService.exportPersonTraining(response);
    }
 
    public static boolean isExcelFile(MultipartFile file) {
        if (file.isEmpty()) {
            return false;
        }
        String originalFilename = file.getOriginalFilename();
        if (originalFilename == null) {
            return false;
        }
        String[] parts = originalFilename.split("\\.");
        if (parts.length == 0) {
            return false;
        }
        String fileExtension = parts[parts.length - 1].toLowerCase();
        return fileExtension.equals("xls") || fileExtension.equals("xlsx");
    }
}