Administrator
2023-08-08 85681b3f89d2287b948870f79a2eef780480b6a7
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package com.ruoyi.app.patrolplan.service.impl;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell;
import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWellVo;
import com.ruoyi.alarmpoints.well.mapper.ArdAlarmpointsWellMapper;
import com.ruoyi.app.patrolplan.domain.ArdAppPatrolpoint;
import com.ruoyi.app.patrolplan.domain.ArdAppPatroluser;
import com.ruoyi.app.patrolplan.mapper.ArdAppPatrolpointMapper;
import com.ruoyi.app.patrolplan.mapper.ArdAppPatroluserMapper;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.SysUserVo;
import com.ruoyi.common.utils.DateUtils;
 
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.utils.result.Results;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.app.patrolplan.mapper.ArdAppPatrolplanMapper;
import com.ruoyi.app.patrolplan.domain.ArdAppPatrolplan;
import com.ruoyi.app.patrolplan.service.IArdAppPatrolplanService;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
 
/**
 * app巡检计划Service业务层处理
 *
 * @author ard
 * @date 2023-08-02
 */
@Service
public class ArdAppPatrolplanServiceImpl implements IArdAppPatrolplanService {
    @Resource
    private ArdAppPatrolplanMapper ardAppPatrolplanMapper;
 
    @Resource
    private ArdAppPatrolpointMapper ardAppPatrolpointMapper;
 
    @Resource
    private ArdAppPatroluserMapper ardAppPatroluserMapper;
 
    @Resource
    private ArdAlarmpointsWellMapper ardAlarmpointsWellMapper;
 
    @Resource
    private SysUserMapper sysUserMapper;
 
    /**
     * 查询app巡检计划
     *
     * @param patroEndTime app巡检计划主键
     * @return app巡检计划
     */
    @Override
    public ArdAppPatrolplan selectArdAppPatrolplanByPatroEndTime(String patroEndTime) {
        return ardAppPatrolplanMapper.selectArdAppPatrolplanByPatroEndTime(patroEndTime);
    }
 
    /**
     * 查询app巡检计划列表
     *
     * @param ardAppPatrolplan app巡检计划
     * @return app巡检计划
     */
    @Override
    public List<ArdAppPatrolplan> selectArdAppPatrolplanList(ArdAppPatrolplan ardAppPatrolplan) {
        return ardAppPatrolplanMapper.selectArdAppPatrolplanList(ardAppPatrolplan);
    }
 
    /**
     * 新增app巡检计划
     *
     * @param ardAppPatrolplan app巡检计划
     * @return 结果
     */
    @Override
    public int insertArdAppPatrolplan(ArdAppPatrolplan ardAppPatrolplan) {
                ardAppPatrolplan.setUserId(SecurityUtils.getUserId());
                ardAppPatrolplan.setCreateTime(DateUtils.getNowDate());
            return ardAppPatrolplanMapper.insertArdAppPatrolplan(ardAppPatrolplan);
    }
 
    /**
     * 修改app巡检计划
     *
     * @return 结果
     */
    @Override
    public Results updateArdAppPatrolplan(Map<String,Object> para) {
        if(para.get("id").toString().isEmpty()){
            return Results.error("ID无效!");
        }
        //修改主表
        ArdAppPatrolplan ardAppPatrolplan = new ArdAppPatrolplan();
        ardAppPatrolplan.setId(para.get("id").toString());
        ardAppPatrolplan.setUserId(para.get("userId").toString());
        ardAppPatrolplan.setCycle(para.get("cycle").toString());
        ardAppPatrolplan.setPatroBeginTime(para.get("patroBeginTime").toString());
        ardAppPatrolplan.setPatroEndTime(para.get("patroEndTime").toString());
        ardAppPatrolplan.setPlanName(para.get("planName").toString());
        int num = ardAppPatrolplanMapper.updateById(ardAppPatrolplan);
        //修改兴趣点
        ardAppPatrolpointMapper.deleteArdAppPatrolpointByPlanId(para.get("id").toString());//删除巡检计划下挂点位
        List<String> alarmpointIdList = (List<String>) para.get("alarmpointIdList");
        List<ArdAppPatrolpoint> ardAppPatrolpointList = new ArrayList();
        for(String  alarmpointId : alarmpointIdList){
            String patrolpointId = IdUtils.simpleUUID();
            ArdAppPatrolpoint ardAppPatrolpoint = new ArdAppPatrolpoint();
            ardAppPatrolpoint.setId(patrolpointId);
            ardAppPatrolpoint.setPatrolplanId(para.get("id").toString());
            ardAppPatrolpoint.setAlarmpointsId(alarmpointId);
            ardAppPatrolpoint.setType((String) para.get("type"));
            ardAppPatrolpointList.add(ardAppPatrolpoint);
        }
        ardAppPatrolpointMapper.insertArdAppPatrolpointList(ardAppPatrolpointList);//新增关联兴趣点
        //修改用户
        ardAppPatroluserMapper.deleteArdAppPatroluserByPlanId(para.get("id").toString());//删除巡检计划下挂用户
        List<String> appUserIdList = (List<String>) para.get("appUserIdList");
        List<ArdAppPatroluser> ardAppPatroluserList = new ArrayList();
        for(String appUserId : appUserIdList){
            String patroluserId = IdUtils.simpleUUID();
            ArdAppPatroluser ardAppPatroluser = new ArdAppPatroluser();
            ardAppPatroluser.setId(patroluserId);
            ardAppPatroluser.setPatrolplanId(para.get("id").toString());
            ardAppPatroluser.setAppUserId(appUserId);
            ardAppPatroluserList.add(ardAppPatroluser);
        }
        ardAppPatroluserMapper.insertArdAppPatroluserList(ardAppPatroluserList);//新增关联人员
        if(num>0){
            return Results.succeed("修改成功!");
        }else {
            return Results.error("修改失败!");
        }
    }
 
 
    /**
     * 删除app巡检计划信息
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteArdApp(String id) {
        //ardAppPatroluserMapper.deleteArdAppPatroluserByReserved1(id);
        /*ardAppPatrolpointMapper.deleteArdAppPatrolpointById(id);
        if(ardAppPatrolplanMapper.deleteArdAppPatrolplanByPatroEndTime(id)>0){
            return Results.succeed("删除成功!");
        }else {
            return Results.error("删除失败!");
        }*/
        try {
            int result = ardAppPatrolplanMapper.deleteArdAppPatrolplanById(id);//删除巡检计划
            ardAppPatrolpointMapper.deleteArdAppPatrolpointByPlanId(id);//删除巡检计划下挂点位
            ardAppPatroluserMapper.deleteArdAppPatroluserByPlanId(id);//删除巡检计划下挂用户
            return result;
        } catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }
 
    @Override
    @Transactional
    public int insertArdAppPatrolplan(Map<String, Object> para) {
        String id = IdUtils.simpleUUID();
        ArdAppPatrolplan ardAppPatrolplan = new ArdAppPatrolplan();
        ardAppPatrolplan.setId(id);
        ardAppPatrolplan.setPlanName((String) para.get("planName"));
        ardAppPatrolplan.setPatroBeginTime((String) para.get("patroBeginTime"));
        ardAppPatrolplan.setPatroEndTime((String) para.get("patroEndTime"));
        String userId = SecurityUtils.getUserId();
        ardAppPatrolplan.setUserId(userId);
        ardAppPatrolplan.setCycle((String) para.get("cycle"));
        ardAppPatrolplan.setCreateTime(new Date());
        int result = ardAppPatrolplanMapper.insertArdAppPatrolplan(ardAppPatrolplan);//新增主表
        List<String> alarmpointIdList = (List<String>) para.get("alarmpointIdList");
        List<ArdAppPatrolpoint> ardAppPatrolpointList = new ArrayList();
        for(String  alarmpointId : alarmpointIdList){
            String patrolpointId = IdUtils.simpleUUID();
            ArdAppPatrolpoint ardAppPatrolpoint = new ArdAppPatrolpoint();
            ardAppPatrolpoint.setId(patrolpointId);
            ardAppPatrolpoint.setPatrolplanId(id);
            ardAppPatrolpoint.setAlarmpointsId(alarmpointId);
            ardAppPatrolpoint.setType((String) para.get("type"));
            ardAppPatrolpointList.add(ardAppPatrolpoint);
        }
        ardAppPatrolpointMapper.insertArdAppPatrolpointList(ardAppPatrolpointList);//新增关联兴趣点
        List<String> appUserIdList = (List<String>) para.get("appUserIdList");
        List<ArdAppPatroluser> ardAppPatroluserList = new ArrayList();
        for(String appUserId : appUserIdList){
            String patroluserId = IdUtils.simpleUUID();
            ArdAppPatroluser ardAppPatroluser = new ArdAppPatroluser();
            ardAppPatroluser.setId(patroluserId);
            ardAppPatroluser.setPatrolplanId(id);
            ardAppPatroluser.setAppUserId(appUserId);
            ardAppPatroluserList.add(ardAppPatroluser);
        }
        ardAppPatroluserMapper.insertArdAppPatroluserList(ardAppPatroluserList);//新增关联人员
        return result;
    }
 
    @Override
    public Results oneById(String id) {
        JSONObject jsonObject = new JSONObject();
        ArdAppPatrolplan ardAppPatrolplan = ardAppPatrolplanMapper.selectById(id);
        jsonObject.put("plan",ardAppPatrolplan);
        List<ArdAlarmpointsWell> ardAlarmpointsWellList = ardAlarmpointsWellMapper.wellByPlanId(id);
        List<ArdAlarmpointsWellVo> wellVos = new ArrayList<>();
        for (ArdAlarmpointsWell ardAlarmpointsWell : ardAlarmpointsWellList) {
            ArdAlarmpointsWellVo wellVo = new ArdAlarmpointsWellVo();
            wellVo.setId(ardAlarmpointsWell.getId());
            wellVo.setType(ardAlarmpointsWell.getType());
            wellVo.setWellId(ardAlarmpointsWell.getWellId());
            wellVos.add(wellVo);
        }
        jsonObject.put("well",wellVos);
        List<SysUser> sysUserList = sysUserMapper.userByPlanId(id);
        List<SysUserVo> sysUserVos = new ArrayList<>();
        for (int i = 0; i < sysUserList.size(); i++) {
            SysUserVo sysUserVo = new SysUserVo();
            sysUserVo.setUserId(sysUserList.get(i).getUserId());
            sysUserVo.setNickName(sysUserList.get(i).getNickName());
            sysUserVos.add(sysUserVo);
        }
        jsonObject.put("user",sysUserVos);
        return Results.succeed(jsonObject);
    }
 
}