eight
2024-10-11 111ded437886aa10072434f8b0a459da24f8545a
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
package cn.lihu.jh.module.ecg.controller.admin.checktype;
 
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
 
import java.util.*;
import java.io.IOException;
 
import cn.lihu.jh.framework.common.pojo.PageParam;
import cn.lihu.jh.framework.common.pojo.PageResult;
import cn.lihu.jh.framework.common.pojo.CommonResult;
import cn.lihu.jh.framework.common.util.object.BeanUtils;
import static cn.lihu.jh.framework.common.pojo.CommonResult.success;
 
import cn.lihu.jh.framework.excel.core.util.ExcelUtils;
 
import cn.lihu.jh.framework.apilog.core.annotation.ApiAccessLog;
import static cn.lihu.jh.framework.apilog.core.enums.OperateTypeEnum.*;
 
import cn.lihu.jh.module.ecg.controller.admin.checktype.vo.*;
import cn.lihu.jh.module.ecg.dal.dataobject.checktype.CheckTypeDO;
import cn.lihu.jh.module.ecg.service.checktype.CheckTypeService;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
 
@Tag(name = "管理后台 - 检查类型")
@RestController
@RequestMapping("/ecg/check-type")
@Validated
public class CheckTypeController {
 
    @Resource
    private CheckTypeService checkTypeService;
 
    @PostMapping("/create")
    @Operation(summary = "创建检查类型")
    @PreAuthorize("@ss.hasPermission('ecg:check-type:create')")
    public CommonResult<Integer> createCheckType(@Valid @RequestBody CheckTypeSaveReqVO createReqVO) {
        return success(checkTypeService.createCheckType(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新检查类型")
    @PreAuthorize("@ss.hasPermission('ecg:check-type:update')")
    public CommonResult<Boolean> updateCheckType(@Valid @RequestBody CheckTypeSaveReqVO updateReqVO) {
        checkTypeService.updateCheckType(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除检查类型")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('ecg:check-type:delete')")
    public CommonResult<Boolean> deleteCheckType(@RequestParam("id") Integer id) {
        checkTypeService.deleteCheckType(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得检查类型")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('ecg:check-type:query')")
    public CommonResult<CheckTypeRespVO> getCheckType(@RequestParam("id") Integer id) {
        CheckTypeDO checkType = checkTypeService.getCheckType(id);
        return success(BeanUtils.toBean(checkType, CheckTypeRespVO.class));
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得检查类型分页")
    @PreAuthorize("@ss.hasPermission('ecg:check-type:query')")
    public CommonResult<PageResult<CheckTypeRespVO>> getCheckTypePage(@Valid CheckTypePageReqVO pageReqVO) {
        PageResult<CheckTypeDO> pageResult = checkTypeService.getCheckTypePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CheckTypeRespVO.class));
    }
 
    @GetMapping("/export-excel")
    @Operation(summary = "导出检查类型 Excel")
    @PreAuthorize("@ss.hasPermission('ecg:check-type:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportCheckTypeExcel(@Valid CheckTypePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<CheckTypeDO> list = checkTypeService.getCheckTypePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "检查类型.xls", "数据", CheckTypeRespVO.class,
                        BeanUtils.toBean(list, CheckTypeRespVO.class));
    }
 
}