郑永安
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package com.gkhy.safePlatform.safeCheck.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
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.SafeCheckTask;
import com.gkhy.safePlatform.safeCheck.entity.SafeCheckWork;
import com.gkhy.safePlatform.safeCheck.model.dto.req.*;
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckPointPageRespDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckPointRespDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckTaskUnitPageRespDTO;
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckTaskUnitRespDTO;
import com.gkhy.safePlatform.safeCheck.service.SafeCheckTaskManagerService;
import com.gkhy.safePlatform.safeCheck.service.baseService.SafeCheckWorkService;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
 
import java.util.HashMap;
 
@RestController
@RequestMapping("/SafeCheckTaskUnit")
public class SafeCheckTaskUnitController {
 
    @Autowired
    private SafeCheckTaskManagerService safeCheckTaskManagerService;
 
    @Autowired
    private SafeCheckWorkService safeCheckWorkService;
 
    /**
     * @description 新建一个任务单元
     */
    @RequestMapping("/insert/saveTaskUnit")
    public ResultVO<String> saveTaskUnit(Authentication authentication, @RequestBody SafeCheckTaskUnitReqDTO safeCheckTaskUnitReqDTO){
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        safeCheckTaskManagerService.saveTaskUnit(currentUser,safeCheckTaskUnitReqDTO);
        return new ResultVO<>("200","巡检任务单元新建成功");
    }
 
    /***
     * @description 根据任务单元id删除任务单元
     */
    @PostMapping("/delete/deleteTaskUnit")
    public ResultVO<String> deleteTaskUnit(Authentication authentication,@RequestBody SafeCheckTaskUnitReqDTO safeCheckTaskUnitReqDTO){
        Long id = safeCheckTaskUnitReqDTO.getId();
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        safeCheckTaskManagerService.deleteTaskUnit(currentUser, id);
        ResultVO resultVO = new ResultVO<>("200","删除巡检任务单元成功");
        return resultVO;
    }
 
    /**
     * @description 根据巡检点的id和任务单元id删除巡检链中的巡检点
     */
    @PostMapping("/delete/deleteTaskUnitPoint")
    public ResultVO<String> deleteTaskUnitPoint(Authentication authentication,@RequestBody SafeCheckUnitAndQuotaReqDTO safeCheckUnitAndQuotaReqDTO){
        HashMap<String, Object> taskUnitAndPointId = new HashMap<>();
        taskUnitAndPointId.put("taskUnitId",safeCheckUnitAndQuotaReqDTO.getUnitId());
        taskUnitAndPointId.put("id",safeCheckUnitAndQuotaReqDTO.getId());
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        safeCheckTaskManagerService.deleteTaskUnitPoint(currentUser, taskUnitAndPointId);
        ResultVO resultVO = new ResultVO<>("200","删除巡检点成功");
        return resultVO;
    }
 
    /**
     * @description 根据巡检任务单元的id及巡检单元与巡检指标关联表的id对巡检点信息内容进行修改
     */
    @PostMapping("/update/updateTaskUnitPointById")
    public ResultVO<String> updateTaskUnitPointById(Authentication authentication, @RequestBody SafeCheckUnitAndQuotaReqDTO safeCheckUnitAndQuotaReqDTO){
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        safeCheckTaskManagerService.updateTaskUnitPointById(currentUser,safeCheckUnitAndQuotaReqDTO);
        ResultVO resultVO = new ResultVO<>("200","修改巡检点信息成功");
        return resultVO;
    }
 
 
    /**
     * @description 往巡检链中新增一个巡检点
     */
    @RequestMapping("/insert/saveTaskUnitPoint")
    public ResultVO<String> saveTaskUnitPoint(Authentication authentication, @RequestBody SafeCheckUnitAndQuotaReqDTO safeCheckUnitAndQuotaReqDTO){
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        safeCheckTaskManagerService.saveTaskUnitPoint(currentUser,safeCheckUnitAndQuotaReqDTO);
        return new ResultVO<>("200","巡检点新增成功");
    }
 
 
 
    /**
     * @description 根据id更新巡检任务单元状态
     */
    @PostMapping("/update/updateTaskUnitStatusById")
    public ResultVO<String> updateTaskUnitStatusById(Authentication authentication, @RequestBody SafeCheckTaskUnitReqDTO safeCheckTaskUnitReqDTO){
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        String TaskUnitStatus = safeCheckTaskManagerService.updateTaskUnitStatusById(currentUser, safeCheckTaskUnitReqDTO);
        ResultVO resultVO = new ResultVO<>("200",TaskUnitStatus+"巡检任务单元成功");
        return resultVO;
    }
 
 
    /**
     * @description 根据id更新巡检任务单元信息
     */
    @PostMapping("/update/updateTaskUnitMainById")
    public ResultVO<String> updateTaskUnitMainById(Authentication authentication, @RequestBody SafeCheckTaskUnitReqDTO safeCheckTaskUnitReqDTO){
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        safeCheckTaskManagerService.updateTaskUnitMainById(currentUser, safeCheckTaskUnitReqDTO);
        ResultVO resultVO = new ResultVO<>("200","更新巡检任务单元成功");
        return resultVO;
    }
 
 
 
 
    /**
     * @description 根据任务单元id查询任务单元
     */
    @PostMapping("/select/getTaskUnitById")
    public ResultVO<SafeCheckTaskUnitRespDTO> getTaskUnitById(@RequestBody SafeCheckTaskUnitReqDTO safeCheckTaskUnitReqDTO){
        Long id = safeCheckTaskUnitReqDTO.getId();
        SafeCheckTaskUnitRespDTO taskUnitRespDTO = safeCheckTaskManagerService.getTaskUnitById(id);
        ResultVO resultVO = new ResultVO<>(ResultCodes.OK,taskUnitRespDTO);
        return resultVO;
    }
 
    /**
     * @description 查询所有巡检任务单元数据并进行分页(包含条件查询)
     */
    @PostMapping("/select/listTaskUnitByPage")
    public ResultVO<IPage<SafeCheckTaskUnitPageRespDTO>> listTaskUnitByPage(Authentication authentication,@RequestBody SafeCheckTaskUnitPageReqDTO safeCheckTaskUnitPageReqDTO){
        ContextCacheUser currentUser = (ContextCacheUser)authentication.getPrincipal();
        Integer pageIndex = safeCheckTaskUnitPageReqDTO.getPageIndex();
        Integer pageSize = safeCheckTaskUnitPageReqDTO.getPageSize();
        if (pageIndex == 0 || pageSize == 0){
            throw new AusinessException(E.DATA_PARAM_NULL,"当前页码或当前页显示数不能为0");
        }
        Page pageInfo = new Page(pageIndex, pageSize);
        //连表查询后再统计总数
        pageInfo.setOptimizeCountSql(false);
        IPage iPage = safeCheckTaskManagerService.listTaskUnitByPage(pageInfo, safeCheckTaskUnitPageReqDTO,currentUser);
        return new ResultVO<>(ResultCodes.OK,iPage);
    }
}