|  |  | 
 |  |  | package com.ruoyi.app.patrolplan.service.impl; | 
 |  |  |  | 
 |  |  | import java.io.Serializable; | 
 |  |  | import java.text.SimpleDateFormat; | 
 |  |  | import java.time.LocalDate; | 
 |  |  | import java.time.format.DateTimeFormatter; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  |  | 
 |  |  | 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.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.*; | 
 |  |  | import com.ruoyi.app.patrolplan.mapper.*; | 
 |  |  | 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; | 
 |  |  |  | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private ArdAppPatroluserMapper ardAppPatroluserMapper; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private ArdAlarmpointsWellMapper ardAlarmpointsWellMapper; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private SysUserMapper sysUserMapper; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private ArdAppPatrolpointRecordMapper recordMapper; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private ArdAppPatrolpointRecordImgMapper recordImgMapper; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 查询app巡检计划 | 
 |  |  | 
 |  |  |     @Override | 
 |  |  |     public int insertArdAppPatrolplan(ArdAppPatrolplan ardAppPatrolplan) { | 
 |  |  |                 ardAppPatrolplan.setUserId(SecurityUtils.getUserId()); | 
 |  |  |                 ardAppPatrolplan.setCreateTime(DateUtils.getNowDate()); | 
 |  |  |                 Date date = new Date(); | 
 |  |  |                 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
 |  |  |                 ardAppPatrolplan.setCreateTime(sdf.format(date)); | 
 |  |  |             return ardAppPatrolplanMapper.insertArdAppPatrolplan(ardAppPatrolplan); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 修改app巡检计划 | 
 |  |  |      * | 
 |  |  |      * @param ardAppPatrolplan app巡检计划 | 
 |  |  |      * @return 结果 | 
 |  |  |      */ | 
 |  |  |     @Override | 
 |  |  |     public int updateArdAppPatrolplan(ArdAppPatrolplan ardAppPatrolplan) { | 
 |  |  |         return ardAppPatrolplanMapper.updateArdAppPatrolplan(ardAppPatrolplan); | 
 |  |  |     public Results BeforeUpdateArdAppPatrolplan(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("修改失败!"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | 
 |  |  |     @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; | 
 |  |  |             Boolean del = false; | 
 |  |  |             //查询计划时间是否结束 | 
 |  |  |             ArdAppPatrolplan planList = ardAppPatrolplanMapper.selectById(id); | 
 |  |  |             String cycle = planList.getCycle(); | 
 |  |  |             String end = planList.getPatroEndTime(); | 
 |  |  |             if(cycle.equals("day")){ | 
 |  |  |                 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | 
 |  |  |                 String date = dateFormat.format(new Date()); | 
 |  |  |                 end = date +" "+end; | 
 |  |  |             } | 
 |  |  |             SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
 |  |  |             String toDay = dateFormat.format(new Date()); | 
 |  |  |             int once = toDay.compareTo(end); | 
 |  |  |             if(once<0){ | 
 |  |  |                 del = true; | 
 |  |  |             } | 
 |  |  |             if(!del){ | 
 |  |  |                 //查询是否有打卡记录 | 
 |  |  |                 QueryWrapper<ArdAppPatrolpointRecord> recordQueryWrapper = new QueryWrapper<>(); | 
 |  |  |                 recordQueryWrapper.eq("plan_id",id); | 
 |  |  |                 List<ArdAppPatrolpointRecord> recordList = recordMapper.selectList(recordQueryWrapper); | 
 |  |  |                 if(recordList.size()>0){ | 
 |  |  |                     del = true; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             if(del){ | 
 |  |  |                 int result = ardAppPatrolplanMapper.deleteArdAppPatrolplanById(id);//删除巡检计划 | 
 |  |  |                 ardAppPatrolpointMapper.deleteArdAppPatrolpointByPlanId(id);//删除巡检计划下挂点位 | 
 |  |  |                 ardAppPatroluserMapper.deleteArdAppPatroluserByPlanId(id);//删除巡检计划下挂用户 | 
 |  |  |                 return result; | 
 |  |  |             }else { | 
 |  |  |                 String userId = SecurityUtils.getUserId(); | 
 |  |  |                 SysUser sysUser = sysUserMapper.selectUserById(userId); | 
 |  |  |                 String userName = sysUser.getNickName(); | 
 |  |  |                 planList.setDelName(userName); | 
 |  |  |                 planList.setDelTime(dateFormat.format(new Date())); | 
 |  |  |                 int result = ardAppPatrolplanMapper.updateById(planList); | 
 |  |  |                 return result; | 
 |  |  |             } | 
 |  |  |         } catch (Exception e){ | 
 |  |  |             e.printStackTrace(); | 
 |  |  |             return 0; | 
 |  |  | 
 |  |  |         String userId = SecurityUtils.getUserId(); | 
 |  |  |         ardAppPatrolplan.setUserId(userId); | 
 |  |  |         ardAppPatrolplan.setCycle((String) para.get("cycle")); | 
 |  |  |         ardAppPatrolplan.setCreateTime(new Date()); | 
 |  |  |         Date date = new Date(); | 
 |  |  |         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
 |  |  |         ardAppPatrolplan.setCreateTime(sdf.format(date)); | 
 |  |  |         int result = ardAppPatrolplanMapper.insertArdAppPatrolplan(ardAppPatrolplan);//新增主表 | 
 |  |  |         List<String> alarmpointIdList = (List<String>) para.get("alarmpointIdList"); | 
 |  |  |         List<ArdAppPatrolpoint> ardAppPatrolpointList = new ArrayList(); | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Results oneById(String id) { | 
 |  |  |         return null; | 
 |  |  |         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); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Results allPlanUser(String id) { | 
 |  |  |         return null; | 
 |  |  |     public Results updateArdAppPatrolplan(Map<String,Object> para){ | 
 |  |  |         if(para.get("id").toString().isEmpty()){ | 
 |  |  |             return Results.error("ID无效!"); | 
 |  |  |         } | 
 |  |  |         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
 |  |  |         //查询该条记录 | 
 |  |  |         ArdAppPatrolplan planList = ardAppPatrolplanMapper.selectById(para.get("id").toString()); | 
 |  |  |         String userId = SecurityUtils.getUserId(); | 
 |  |  |         SysUser sysUser = sysUserMapper.selectUserById(userId); | 
 |  |  |         String userName = sysUser.getNickName(); | 
 |  |  |         planList.setDelName(userName); | 
 |  |  |         planList.setDelTime(dateFormat.format(new Date())); | 
 |  |  |         int result = ardAppPatrolplanMapper.updateById(planList); | 
 |  |  |         if(result<1){ | 
 |  |  |             return Results.error("修改失败,原数据停用出错!"); | 
 |  |  |         } | 
 |  |  |         String planId = planList.getId(); | 
 |  |  |         QueryWrapper<ArdAppPatrolpointRecord> patrolpointRecordQueryWrapper = new QueryWrapper<>(); | 
 |  |  |         patrolpointRecordQueryWrapper.eq("plan_id",planId); | 
 |  |  |         List<ArdAppPatrolpointRecord> records = recordMapper.selectList(patrolpointRecordQueryWrapper); | 
 |  |  |         if(records.size()>0){ | 
 |  |  |             for (int i = 0; i < records.size(); i++) { | 
 |  |  |                 ArdAppPatrolpointRecord record = records.get(i); | 
 |  |  |                 record.setDel(1); | 
 |  |  |                 recordMapper.updateById(record); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         int num = insertArdAppPatrolplan(para); | 
 |  |  |         if(num==1){ | 
 |  |  |             return Results.succeed("修改成功,已重新部署任务!"); | 
 |  |  |         }else { | 
 |  |  |             return Results.error("修改失败,重新部署任务失败!"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public List<ArdAppPatrolplan> executeList(ArdAppPatrolplan ardAppPatrolplan) { | 
 |  |  |         return ardAppPatrolplanMapper.executeList(ardAppPatrolplan); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Results executeOneById(String id) { | 
 |  |  |         return Results.succeed(ardAppPatrolplanMapper.selectById(id)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |