| | |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | 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.mapper.ArdAlarmpointsWellMapper; |
| | | import com.ruoyi.app.patrolplan.domain.ArdAppPatrolplan; |
| | | import com.ruoyi.app.patrolplan.domain.ArdAppPatrolpointRecordImg; |
| | | import com.ruoyi.app.patrolplan.domain.ArdAppPatroluser; |
| | | import com.ruoyi.app.patrolplan.domain.param.ArdAppPatrolpointRecordParam; |
| | | import com.ruoyi.app.patrolplan.mapper.ArdAppPatrolplanMapper; |
| | | import com.ruoyi.app.patrolplan.mapper.ArdAppPatrolpointRecordImgMapper; |
| | | import com.ruoyi.app.patrolplan.mapper.ArdAppPatroluserMapper; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | 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.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | @Resource |
| | | private ArdAppPatrolplanMapper patrolplanMapper; |
| | | |
| | | @Resource |
| | | private ArdAppPatroluserMapper userMapper; |
| | | |
| | | @Resource |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Resource |
| | | private ArdAlarmpointsWellMapper wellMapper; |
| | | |
| | | /** |
| | | * 查询app巡检计划记录 |
| | |
| | | public Results record(ArdAppPatrolpointRecord ardAppPatrolpointRecord) { |
| | | String id = IdUtils.simpleUUID(); |
| | | ardAppPatrolpointRecord.setId(id); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | //查询该用户今天的打卡数据 |
| | | QueryWrapper<ArdAppPatrolpointRecord> recordQueryWrapper = new QueryWrapper<>(); |
| | | recordQueryWrapper.eq("plan_id", ardAppPatrolpointRecord.getPlanId()) |
| | | .like("record_time", dateFormat.format(new Date())) |
| | | .eq("user_id",ardAppPatrolpointRecord.getUserId()); |
| | | List<ArdAppPatrolpointRecord> recordList = ardAppPatrolpointRecordMapper.selectList(recordQueryWrapper); |
| | | ardAppPatrolpointRecord.setPointsNum(recordList.size()+1); |
| | | int num = ardAppPatrolpointRecordMapper.insert(ardAppPatrolpointRecord); |
| | | List<String> list = ardAppPatrolpointRecord.getImg(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | |
| | | @Override |
| | | public Results recordDetails(ArdAppPatrolpointRecordParam ardAppPatrolpointRecordParam) throws ParseException { |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat dateFormatTime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); |
| | | //获取参数 |
| | | String planId = ardAppPatrolpointRecordParam.getPlanId(); |
| | | String toDay = ardAppPatrolpointRecordParam.getToDay(); |
| | | Date toDayDate = dateFormat.parse(toDay); |
| | | //查询计划表 |
| | | ArdAppPatrolplan ardAppPatrolplan = patrolplanMapper.selectById(planId); |
| | | String cycle = ardAppPatrolplan.getCycle(); |
| | | String begin = ardAppPatrolplan.getPatroBeginTime(); |
| | | Date beginDate = dateFormat.parse(begin); |
| | | String end = ardAppPatrolplan.getPatroEndTime(); |
| | | Date endDate = dateFormat.parse(end); |
| | | String create = ardAppPatrolplan.getCreateTime(); |
| | | Date createDate = dateFormat.parse(create); |
| | | JSONArray jsonArray = new JSONArray(); |
| | | int c = 0; |
| | | if(cycle.equals("day")){ |
| | | |
| | | //每天计划取创建时间 |
| | | c = toDay.compareTo(create.substring(0,10)); |
| | | }else if(cycle.equals("once")){ |
| | | int bd = toDayDate.compareTo(beginDate); |
| | | int en = toDayDate.compareTo(endDate); |
| | | if(bd>=0 && en<=0){ |
| | | //传入时间为该计划内时间 |
| | | String date = dateFormat.format(new Date()); |
| | | Date dateDate = dateFormat.parse(date); |
| | | int d = toDayDate.compareTo(dateDate); |
| | | if(d < 0) { |
| | | //查询计划内的历史数据 |
| | | QueryWrapper<ArdAppPatrolpointRecord> recordQueryWrapper = new QueryWrapper<>(); |
| | | recordQueryWrapper.eq("plan_id", planId).like("record_time", toDay).groupBy("user_id"); |
| | | List<ArdAppPatrolpointRecord> list = ardAppPatrolpointRecordMapper.selectList(recordQueryWrapper); |
| | | return Results.succeed(list); |
| | | }else if(d > 0){ |
| | | //查询计划内的未来数据 |
| | | QueryWrapper<ArdAppPatroluser> appPatroluserQueryWrapper = new QueryWrapper<>(); |
| | | appPatroluserQueryWrapper.eq("patrolplan_id",planId).groupBy("app_user_id"); |
| | | |
| | | //单次计划取开始时间 |
| | | c = toDay.compareTo(begin.substring(0,10)); |
| | | } |
| | | if(cycle.equals("once") && c>0){ |
| | | //单次计划大于开始时间==跨天,在计划时间外 |
| | | return Results.succeed("[]"); |
| | | } |
| | | if(c<0){ |
| | | //每日计划小于创建时间或单次计划小于开始时间,在计划时间外 |
| | | return Results.succeed("[]"); |
| | | }else{ |
| | | //在每日计划的时间范围内 |
| | | String date = dateFormat.format(new Date()); |
| | | //比较选中的日期和今天日期 |
| | | int d = toDay.compareTo(date); |
| | | //查询该计划的所有人员 |
| | | List<SysUser> users = sysUserMapper.userByPlanId(planId); |
| | | //大于0代表查询以后的记录 |
| | | if(d>0){ |
| | | //查询计划内的每日未来数据 |
| | | for (int i = 0; i < users.size(); i++) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("userId",users.get(i).getUserId()); |
| | | jsonObject.put("userName",users.get(i).getNickName()); |
| | | jsonObject.put("type",false); |
| | | jsonArray.add(jsonObject); |
| | | } |
| | | }else { |
| | | return Results.succeed("[]"); |
| | | return Results.succeed(jsonArray); |
| | | }else{ |
| | | //查询计划内的实际历史打卡数据 |
| | | QueryWrapper<ArdAppPatrolpointRecord> recordQueryWrapper = new QueryWrapper<>(); |
| | | if(d<0){ |
| | | //小于0是历史 |
| | | recordQueryWrapper.select("max(points_num) pointsNum","user_id","user_name").eq("plan_id", planId).like("record_time", toDay).groupBy("user_id","user_name"); |
| | | }else{ |
| | | //等于0选中的日期就是今天,需要进一步判断小于当前时分秒的记录 |
| | | recordQueryWrapper.select("max(points_num) pointsNum","user_id","user_name").eq("plan_id", planId).le("record_time", dateFormatTime.format(new Date())).groupBy("user_id","user_name");; |
| | | } |
| | | List<ArdAppPatrolpointRecord> list = ardAppPatrolpointRecordMapper.selectList(recordQueryWrapper); |
| | | //选中这天该计划下没有任何打卡记录 |
| | | if(list.size()==0){ |
| | | for (int i = 0; i < users.size(); i++) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("userId",users.get(i).getUserId()); |
| | | jsonObject.put("userName",users.get(i).getNickName()); |
| | | jsonObject.put("type",false); |
| | | jsonArray.add(jsonObject); |
| | | } |
| | | return Results.succeed(jsonArray); |
| | | } |
| | | //查询该计划的所有兴趣点 |
| | | List<ArdAlarmpointsWell> wellList = wellMapper.wellByPlanId(planId); |
| | | Integer wellNum = wellList.size(); |
| | | //取出所有打了卡的userId |
| | | List<String> userIdList = new ArrayList<>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | userIdList.add(list.get(i).getUserId()); |
| | | } |
| | | //有打卡记录时的打卡情况查出一次都没打卡的人员 |
| | | for (int i = 0; i < users.size(); i++) { |
| | | String userId = users.get(i).getUserId(); |
| | | String userName = users.get(i).getNickName(); |
| | | //如果该计划的所有人员userId不在所有打了卡的userId中 |
| | | if (!userIdList.contains(userId)) { |
| | | //记录该人员未完成打卡 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("userId", userId); |
| | | jsonObject.put("userName", userName); |
| | | jsonObject.put("type", false); |
| | | jsonArray.add(jsonObject); |
| | | continue; |
| | | } |
| | | } |
| | | //全部打完卡或打了部分卡的人员 |
| | | for (ArdAppPatrolpointRecord ardAppPatrolpointRecord : list) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("userId", ardAppPatrolpointRecord.getUserId()); |
| | | jsonObject.put("userName", ardAppPatrolpointRecord.getUserName()); |
| | | if (ardAppPatrolpointRecord.getPointsNum().equals(wellNum)) { |
| | | jsonObject.put("type", true); |
| | | } else { |
| | | jsonObject.put("type", false); |
| | | } |
| | | jsonArray.add(jsonObject); |
| | | } |
| | | return Results.succeed(jsonArray); |
| | | } |
| | | } |
| | | return Results.succeed(); |
| | | } |
| | | |
| | | } |