gaoluyang
2026-10-18 6e3d8e950e7dec3551bee3512673e1fc2d384d2b
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
package cn.iocoder.yudao.module.mes.controller.admin.pro.alternativeplan;
 
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.mes.controller.admin.pro.alternativeplan.vo.MesProAlternativePlanImportExcelVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.alternativeplan.vo.MesProAlternativePlanImportRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.alternativeplan.vo.MesProAlternativePlanPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.alternativeplan.vo.MesProAlternativePlanRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.alternativeplan.vo.MesProAlternativePlanSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.alternativeplan.MesProAlternativePlanDO;
import cn.iocoder.yudao.module.mes.service.pro.alternativeplan.MesProAlternativePlanService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
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 java.io.IOException;
import java.util.Collections;
import java.util.List;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
@Tag(name = "管理后台 - MES 作业替代方案")
@RestController
@RequestMapping("/mes/pro/alternative-plan")
@Validated
public class MesProAlternativePlanController {
 
    @Resource
    private MesProAlternativePlanService planService;
 
    @PostMapping("/create")
    @Operation(summary = "创建作业替代方案")
    @PreAuthorize("@ss.hasPermission('mes:pro-alternative-plan:create')")
    public CommonResult<Long> createPlan(@Valid @RequestBody MesProAlternativePlanSaveReqVO createReqVO) {
        return success(planService.createPlan(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新作业替代方案")
    @PreAuthorize("@ss.hasPermission('mes:pro-alternative-plan:update')")
    public CommonResult<Boolean> updatePlan(@Valid @RequestBody MesProAlternativePlanSaveReqVO updateReqVO) {
        planService.updatePlan(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除作业替代方案")
    @Parameter(name = "ids", description = "编号数组", required = true)
    @PreAuthorize("@ss.hasPermission('mes:pro-alternative-plan:delete')")
    public CommonResult<Boolean> deletePlan(@RequestParam("ids") List<Long> ids) {
        planService.deletePlan(ids);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得作业替代方案")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:pro-alternative-plan:query')")
    public CommonResult<MesProAlternativePlanRespVO> getPlan(@RequestParam("id") Long id) {
        MesProAlternativePlanDO plan = planService.getPlan(id);
        return success(plan != null ? BeanUtils.toBean(plan, MesProAlternativePlanRespVO.class) : null);
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得作业替代方案分页")
    @PreAuthorize("@ss.hasPermission('mes:pro-alternative-plan:query')")
    public CommonResult<PageResult<MesProAlternativePlanRespVO>> getPlanPage(@Valid MesProAlternativePlanPageReqVO pageReqVO) {
        PageResult<MesProAlternativePlanDO> pageResult = planService.getPlanPage(pageReqVO);
        if (CollUtil.isEmpty(pageResult.getList())) {
            return success(PageResult.empty(pageResult.getTotal()));
        }
        return success(BeanUtils.toBean(pageResult, MesProAlternativePlanRespVO.class));
    }
 
    @PutMapping("/publish")
    @Operation(summary = "发布作业替代方案")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:pro-alternative-plan:update')")
    public CommonResult<Boolean> publishPlan(@RequestParam("id") Long id) {
        planService.publishPlan(id);
        return success(true);
    }
 
    @GetMapping("/get-import-template")
    @Operation(summary = "获得作业替代方案导入模板")
    public void importTemplate(HttpServletResponse response) throws IOException {
        List<MesProAlternativePlanImportExcelVO> list = Collections.singletonList(
                MesProAlternativePlanImportExcelVO.builder()
                        .name("线路巡检替代方案").mainProcessName("线路巡检").altProcessName("无人机巡检")
                        .altCondition("设备故障/负荷受限/人员不足").scope("110kV 线路").remark("").build()
        );
        ExcelUtils.write(response, "作业替代方案导入模板.xls", "作业替代方案列表", MesProAlternativePlanImportExcelVO.class, list);
    }
 
    @PostMapping("/import")
    @Operation(summary = "导入作业替代方案")
    @Parameters({
            @Parameter(name = "file", description = "Excel 文件", required = true),
            @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
    })
    @PreAuthorize("@ss.hasPermission('mes:pro-alternative-plan:import')")
    public CommonResult<MesProAlternativePlanImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
                                                                       @RequestParam(value = "updateSupport", required = false,
                                                                               defaultValue = "false") Boolean updateSupport) throws Exception {
        List<MesProAlternativePlanImportExcelVO> list = ExcelUtils.read(file, MesProAlternativePlanImportExcelVO.class);
        return success(planService.importPlanList(list, updateSupport));
    }
 
}