潘志宝
2024-09-09 bbc1eeba9c29032add5175f2739782fd204de715
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
package com.iailab.module.model.mcs.sche.controller;
 
import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.framework.common.pojo.PageParam;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.framework.excel.core.util.ExcelUtils;
import com.iailab.module.model.mcs.sche.entity.StScheduleSchemeEntity;
import com.iailab.module.model.mcs.sche.service.StScheduleSchemeService;
import com.iailab.module.model.mcs.sche.vo.StScheduleSchemePageReqVO;
import com.iailab.module.model.mcs.sche.vo.StScheduleSchemeRespVO;
import com.iailab.module.model.mcs.sche.vo.StScheduleSchemeSaveReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
 
import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.iailab.framework.common.pojo.CommonResult.success;
 
/**
 * @author PanZhibao
 * @Description
 * @createTime 2024年09月06日
 */
@Tag(name = "模型服务 - 调度方案")
@RestController
@RequestMapping("/model/sche/scheme")
public class StScheduleSchemeController {
 
    @Autowired
    private StScheduleSchemeService stScheduleSchemeService;
 
    @PostMapping("/create")
    @Operation(summary = "创建调度方案")
    @PreAuthorize("@ss.hasPermission('sche:scheme:create')")
    public CommonResult<Boolean> create(@Valid @RequestBody StScheduleSchemeSaveReqVO createReqVO) {
        stScheduleSchemeService.create(createReqVO);
        return success(true);
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新调度方案")
    @PreAuthorize("@ss.hasPermission('sche:scheme:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody StScheduleSchemeSaveReqVO updateReqVO) {
        stScheduleSchemeService.update(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除调度方案")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('sche:scheme:delete')")
    public CommonResult<Boolean> deleteTenant(@RequestParam("id") String id) {
        stScheduleSchemeService.delete(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得调度方案")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('sche:scheme:query')")
    public CommonResult<StScheduleSchemeRespVO> getInfo(@RequestParam("id") String id) {
        StScheduleSchemeEntity entity = stScheduleSchemeService.getInfo(id);
        return success(BeanUtils.toBean(entity, StScheduleSchemeRespVO.class));
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得调度方案分页")
    @PreAuthorize("@ss.hasPermission('sche:scheme:query')")
    public CommonResult<PageResult<StScheduleSchemeRespVO>> getTenantPage(@Valid StScheduleSchemePageReqVO pageVO) {
        PageResult<StScheduleSchemeEntity> pageResult = stScheduleSchemeService.page(pageVO);
        return success(BeanUtils.toBean(pageResult, StScheduleSchemeRespVO.class));
    }
 
    @GetMapping("/export-excel")
    @Operation(summary = "导出调度方案 Excel")
    @PreAuthorize("@ss.hasPermission('system:tenant:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportTenantExcel(@Valid StScheduleSchemePageReqVO exportReqVO,
                                  HttpServletResponse response) throws IOException {
        exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<StScheduleSchemeEntity> list = stScheduleSchemeService.page(exportReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "调度方案.xls", "数据", StScheduleSchemeEntity.class,
                BeanUtils.toBean(list, StScheduleSchemeEntity.class));
    }
}