郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
package com.gkhy.safePlatform.safeCheck.controller;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.enums.E;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.exception.AusinessException;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckQuotaPageReqDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckQuotaReqDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.resp.ListQuotasRespDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckQuotaRespDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckQuotaUpdateRespDTO;
import com.gkhy.safePlatform.safeCheck.service.SafeCheckBaseManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
@RestController
@RequestMapping("/safeCheckQuota")
public class SafeCheckQuotaController {
 
    @Autowired
    private SafeCheckBaseManagerService safeCheckBaseManagerService;
 
    /**
     * 获取所有的巡检指标
     */
    @PostMapping("/select/listQuotas")
    public ResultVO<List<ListQuotasRespDTO>> listQuotas(Authentication authentication){
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        List<ListQuotasRespDTO> list = safeCheckBaseManagerService.listQuotas(currentUser);
        ResultVO resultVO = new ResultVO<>(ResultCodes.OK,list);
        return resultVO;
    }
 
 
    /**
     * @description 新增巡检指标
     */
    @PostMapping("/insert/saveQuota")
    public ResultVO<String> saveQuota(Authentication authentication, @RequestBody SafeCheckQuotaReqDTO safeCheckQuotaReqDTO){
 
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        int saveResult = safeCheckBaseManagerService.saveQuota(currentUser, safeCheckQuotaReqDTO);
        ResultVO resultVO = new ResultVO<>("200","新增巡检指标成功");
        resultVO.setCount(saveResult);
        return resultVO;
    }
 
 
    /***
     * @description 根据巡检指标id删除指标
     */
    @PostMapping("/delete/deleteQuotaById")
    public ResultVO<String> deleteQuota(Authentication authentication, @RequestBody SafeCheckQuotaReqDTO safeCheckQuotaReqDTO){
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        Long quotaId = safeCheckQuotaReqDTO.getId();
        safeCheckBaseManagerService.deleteQuotaById(currentUser, quotaId);
        ResultVO resultVO = new ResultVO<>("200","删除巡检指标成功");
        return resultVO;
    }
 
    /**
     * @description 根据巡检指标id更新巡检指标
     */
    @PostMapping("/update/updateQuotaById")
    public ResultVO<String> updateQuota(Authentication authentication, @RequestBody SafeCheckQuotaReqDTO safeCheckQuotaReqDTO){
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        safeCheckBaseManagerService.updateQuotaById(currentUser,safeCheckQuotaReqDTO);
        ResultVO resultVO = new ResultVO<>("200","更新巡检指标成功");
        return resultVO;
    }
 
 
 
    /**
     * @description 根据巡检指标id查询巡检指标(有效状态)
     */
    @GetMapping("/select/getQuotaById")
    public ResultVO<SafeCheckQuotaUpdateRespDTO> getQuataById(Long id){
        SafeCheckQuotaUpdateRespDTO safeCheckQuota = safeCheckBaseManagerService.getQuataById(id);
        ResultVO resultVO = new ResultVO<>(ResultCodes.OK,safeCheckQuota);
        return resultVO;
    }
 
    /**
     * @description 根据巡检指标名称查询巡检指标(有效状态)
     */
    @GetMapping("/select/getQuotaByName")
    public ResultVO<SafeCheckQuotaRespDTO> getQuotaByName(String quotaName){
        if (quotaName == null){
            throw new AusinessException(E.DATA_PARAM_NULL,"查询条件不能为空");
        }
        SafeCheckQuotaRespDTO safeCheckQuota = safeCheckBaseManagerService.getQuotaByName(quotaName);
        if (safeCheckQuota == null){
            return new ResultVO<>("200","查询不到相关数据");
        }
        return new ResultVO<>(ResultCodes.OK,safeCheckQuota);
    }
 
    /**
     * @description 查询所有数据并进行分页展示
     */
    @PostMapping("/select/listQuotaByPage")
    public ResultVO<Page<SafeCheckQuotaRespDTO>> listQuotaByPage(@RequestBody SafeCheckQuotaPageReqDTO safeCheckQuotaPageReqDTO){
        Integer pageIndex = safeCheckQuotaPageReqDTO.getPageIndex();
        Integer pageSize = safeCheckQuotaPageReqDTO.getPageSize();
        String quotaName = safeCheckQuotaPageReqDTO.getQuotaName();
        if (pageIndex == 0 || pageSize == 0){
            throw new AusinessException(E.DATA_PARAM_NULL,"当前页码或当前页显示数不能为0");
        }
        Page pageInfo = new Page(pageIndex, pageSize);
        pageInfo = safeCheckBaseManagerService.listQuotaByPage(pageInfo,quotaName);
        return new ResultVO<>(ResultCodes.OK,pageInfo);
    }
}