云
2026-10-25 d54fbc9d4f8981fa0f7f613b33a28a8cd4f764ea
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.maintenancecalendar;
 
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.maintenancecalendar.vo.MesProMaintenanceCalendarImportExcelVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.maintenancecalendar.vo.MesProMaintenanceCalendarImportRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.maintenancecalendar.vo.MesProMaintenanceCalendarPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.maintenancecalendar.vo.MesProMaintenanceCalendarRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.maintenancecalendar.vo.MesProMaintenanceCalendarSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.maintenancecalendar.MesProMaintenanceCalendarDO;
import cn.iocoder.yudao.module.mes.service.pro.maintenancecalendar.MesProMaintenanceCalendarService;
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/maintenance-calendar")
@Validated
public class MesProMaintenanceCalendarController {
 
    @Resource
    private MesProMaintenanceCalendarService calendarService;
 
    @PostMapping("/create")
    @Operation(summary = "创建电力运维日历")
    @PreAuthorize("@ss.hasPermission('mes:pro-maintenance-calendar:create')")
    public CommonResult<Long> createCalendar(@Valid @RequestBody MesProMaintenanceCalendarSaveReqVO createReqVO) {
        return success(calendarService.createCalendar(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新电力运维日历")
    @PreAuthorize("@ss.hasPermission('mes:pro-maintenance-calendar:update')")
    public CommonResult<Boolean> updateCalendar(@Valid @RequestBody MesProMaintenanceCalendarSaveReqVO updateReqVO) {
        calendarService.updateCalendar(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除电力运维日历")
    @Parameter(name = "ids", description = "编号数组", required = true)
    @PreAuthorize("@ss.hasPermission('mes:pro-maintenance-calendar:delete')")
    public CommonResult<Boolean> deleteCalendar(@RequestParam("ids") List<Long> ids) {
        calendarService.deleteCalendar(ids);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得电力运维日历")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:pro-maintenance-calendar:query')")
    public CommonResult<MesProMaintenanceCalendarRespVO> getCalendar(@RequestParam("id") Long id) {
        MesProMaintenanceCalendarDO calendar = calendarService.getCalendar(id);
        return success(calendar != null ? BeanUtils.toBean(calendar, MesProMaintenanceCalendarRespVO.class) : null);
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得电力运维日历分页")
    @PreAuthorize("@ss.hasPermission('mes:pro-maintenance-calendar:query')")
    public CommonResult<PageResult<MesProMaintenanceCalendarRespVO>> getCalendarPage(@Valid MesProMaintenanceCalendarPageReqVO pageReqVO) {
        PageResult<MesProMaintenanceCalendarDO> pageResult = calendarService.getCalendarPage(pageReqVO);
        if (CollUtil.isEmpty(pageResult.getList())) {
            return success(PageResult.empty(pageResult.getTotal()));
        }
        return success(BeanUtils.toBean(pageResult, MesProMaintenanceCalendarRespVO.class));
    }
 
    @PutMapping("/publish")
    @Operation(summary = "发布电力运维日历")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:pro-maintenance-calendar:update')")
    public CommonResult<Boolean> publishCalendar(@RequestParam("id") Long id) {
        calendarService.publishCalendar(id);
        return success(true);
    }
 
    @GetMapping("/get-import-template")
    @Operation(summary = "获得电力运维日历导入模板")
    public void importTemplate(HttpServletResponse response) throws IOException {
        List<MesProMaintenanceCalendarImportExcelVO> list = Collections.singletonList(
                MesProMaintenanceCalendarImportExcelVO.builder()
                        .name("8月变电运维排班").workDate(java.time.LocalDate.of(2026, 8, 20)).shift(1).workType(1)
                        .region("110kV 城区线").teamName("变电运维一班").personnel("张三,李四").remark("").build()
        );
        ExcelUtils.write(response, "电力运维日历导入模板.xls", "电力运维日历列表", MesProMaintenanceCalendarImportExcelVO.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-maintenance-calendar:import')")
    public CommonResult<MesProMaintenanceCalendarImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
                                                                           @RequestParam(value = "updateSupport", required = false,
                                                                                   defaultValue = "false") Boolean updateSupport) throws Exception {
        List<MesProMaintenanceCalendarImportExcelVO> list = ExcelUtils.read(file, MesProMaintenanceCalendarImportExcelVO.class);
        return success(calendarService.importCalendarList(list, updateSupport));
    }
 
}