郑永安
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
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.entity.SafeCheckRegion;
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckQuotaPageReqDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckRegionPageReqDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckRegionReqDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckRfidReqDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.resp.*;
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.security.Principal;
import java.util.HashMap;
import java.util.List;
 
 
@RestController
@RequestMapping("/safeCheckRegion")
public class SafeCheckRegionController {
 
    @Autowired
    private SafeCheckBaseManagerService safeCheckBaseManagerService;
 
    /**
     * @description 获取所有有效的区域名称
     */
    @GetMapping("/select/listRegionName")
    public ResultVO<List<SafeCheckRegionNameRespDTO>> listRegionName(){
        List<SafeCheckRegionNameRespDTO> safeCheckRegionNameRespDTOS = safeCheckBaseManagerService.listRegionName();
        return new ResultVO<>(ResultCodes.OK, safeCheckRegionNameRespDTOS);
    }
 
 
    /**
     * @description 新增巡检区域
     */
    @PostMapping("/insert/saveRegion")
    public ResultVO<String> saveRegion(Authentication authentication, @RequestBody SafeCheckRegionReqDTO safeCheckRegionReqDTO){
 
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
 
        int saveResult = safeCheckBaseManagerService.saveRegion(currentUser, safeCheckRegionReqDTO);
        ResultVO resultVO = new ResultVO<>("200","新增巡检区域成功");
        resultVO.setCount(saveResult);
        return resultVO;
    }
 
    /**
     * @description 根据id删除巡检区域
     */
    @PostMapping("/delete/deleteRegionById")
    public ResultVO<String> deleteRegionById(Authentication authentication, @RequestBody SafeCheckRegionReqDTO safeCheckRegionReqDTO){
        Long id = safeCheckRegionReqDTO.getId();
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
 
        int deleteResult = safeCheckBaseManagerService.deleteRegionById(currentUser,id);
 
        ResultVO resultVO = new ResultVO<>("200","删除巡检区域成功");
        resultVO.setCount(deleteResult);
        return resultVO;
    }
 
 
    /**
     * @description 根据id更新巡检区域
     */
    @PostMapping("/update/updateRegionById")
    public ResultVO<String> updateRegionById(Authentication authentication, @RequestBody SafeCheckRegionReqDTO safeCheckRegionReqDTO){
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        safeCheckBaseManagerService.updateRegionById(currentUser, safeCheckRegionReqDTO);
        ResultVO resultVO = new ResultVO<>("200","更新巡检区域成功");
        return resultVO;
    }
 
 
    /**
     * @description 根据巡检区域id查询数据
     */
    @PostMapping("/select/getRegionById")
    public ResultVO<SafeCheckRegionRespDTO> getRegionById(@RequestBody SafeCheckRegionReqDTO safeCheckRegionReqDTO){
        Long id = safeCheckRegionReqDTO.getId();
        SafeCheckRegionRespDTO regionByIdAndUuid = safeCheckBaseManagerService.getRegionById(id);
        ResultVO resultVO = new ResultVO<>(ResultCodes.OK,regionByIdAndUuid);
        return resultVO;
    }
 
 
    /**
     * @description 查询所有数据并进行分页展示
     */
    @PostMapping("/select/listRegionByPage")
    public ResultVO<Page<SafeCheckRegionPageRespDTO>> listRegionByPage(Authentication authentication,@RequestBody SafeCheckRegionPageReqDTO safeCheckRegionPageReqDTO){
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        Integer pageIndex = safeCheckRegionPageReqDTO.getPageIndex();
        Integer pageSize = safeCheckRegionPageReqDTO.getPageSize();
        if (pageIndex == 0 || pageSize == 0){
            throw new AusinessException(E.DATA_PARAM_NULL,"当前页码或当前页显示数不能为0");
        }
        HashMap<String, Object> selectCondition = new HashMap<>();
        selectCondition.put("regionName",safeCheckRegionPageReqDTO.getRegionName());
        selectCondition.put("regionTypeId",safeCheckRegionPageReqDTO.getRegionTypeId());
        Page pageInfo = new Page(pageIndex, pageSize);
        pageInfo = safeCheckBaseManagerService.listRegionByPage(pageInfo,selectCondition,currentUser);
        return new ResultVO<>(ResultCodes.OK,pageInfo);
    }
 
}