Administrator
2023-08-19 7cbb0422ec68c5b2254a4dab449218ea2ca32c76
ard-work/src/main/java/com/ruoyi/app/patrolplan/service/impl/ArdAppPatrolpointRecordServiceImpl.java
@@ -71,7 +71,8 @@
                .eq("user_id",ardAppPatrolpointRecord.getUserId());
        List<ArdAppPatrolpointRecord> recordList = ardAppPatrolpointRecordMapper.selectList(recordQueryWrapper);
        ardAppPatrolpointRecord.setPointsNum(recordList.size()+1);
        int num = ardAppPatrolpointRecordMapper.insert(ardAppPatrolpointRecord);
//        int num = ardAppPatrolpointRecordMapper.insert(ardAppPatrolpointRecord);
        int num = ardAppPatrolpointRecordMapper.insertArdAppPatrolpointRecord(ardAppPatrolpointRecord);
        List<String> list = ardAppPatrolpointRecord.getImg();
        for (int i = 0; i < list.size(); i++) {
            ArdAppPatrolpointRecordImg recordImg = new ArdAppPatrolpointRecordImg();
@@ -79,7 +80,7 @@
            recordImg.setId(imgId);
            recordImg.setAppPatrolponitRecordId(id);
            recordImg.setImg(list.get(i));
            recordImgMapper.insert(recordImg);
            recordImgMapper.insertArdAppPatrolpointRecordImg(recordImg);
        }
        if(num>0){
            return Results.succeed("打卡成功!");
@@ -299,10 +300,20 @@
        String userId = recordSoloParam.getUserId();
        String planName = recordSoloParam.getPlanName();
        String userName = recordSoloParam.getUserName();
        //根据计划ID获取制定人ID
        ArdAppPatrolplan ardAppPatrolplan = patrolplanMapper.selectById(planId);
        //根据姓名ID查询计划制定人的姓名
        String planUserId = ardAppPatrolplan.getUserId();
        SysUser sysUser = sysUserMapper.selectById(planUserId);
        String nikeName = sysUser.getNickName();
        QueryWrapper<ArdAppPatrolpointRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("plan_id", planId).eq("user_id",userId).like("record_time", toDay);
        //当前计划选中时间里此用户的打卡记录
        List<ArdAppPatrolpointRecord> list = ardAppPatrolpointRecordMapper.selectList(queryWrapper);
        for (int i = 0; i < list.size(); i++) {
            ArdAppPatrolpointRecord ardAppPatrolpointRecord = list.get(i);
            ardAppPatrolpointRecord.setPlanUserName(nikeName);
        }
        //查询该计划的所有兴趣点
        List<ArdAlarmpointsWell> wellList = wellMapper.wellByPlanId(planId);
        if(list.size()==0){
@@ -316,6 +327,7 @@
                ardAppPatrolpointRecord.setUserName(userName);
                ardAppPatrolpointRecord.setLatitude(String.valueOf(ardAlarmpointsWell.getLatitude()));
                ardAppPatrolpointRecord.setLongitude(String.valueOf(ardAlarmpointsWell.getLongitude().toString()));
                ardAppPatrolpointRecord.setPlanUserName(nikeName);
                list.add(ardAppPatrolpointRecord);
            }
            return Results.succeed(list);
@@ -349,6 +361,7 @@
                ardAppPatrolpointRecord.setUserName(userName);
                ardAppPatrolpointRecord.setLatitude(String.valueOf(ardAlarmpointsWell.getLatitude()));
                ardAppPatrolpointRecord.setLongitude(String.valueOf(ardAlarmpointsWell.getLongitude().toString()));
                ardAppPatrolpointRecord.setPlanUserName(nikeName);
                list.add(ardAppPatrolpointRecord);
            }
        }
@@ -448,7 +461,7 @@
    }
    @Override
    public Results executeDetails(RecordDetailsParam recordDetailsParam) throws ParseException {
    public Results executeDetailsOld(RecordDetailsParam recordDetailsParam) throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dateFormatTime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String userId = SecurityUtils.getUserId();
@@ -650,4 +663,117 @@
        }
        return Results.succeed(jsonArray);
    }
    @Override
    public Results executeDetails(RecordDetailsExParam recordDetailsExParam) throws ParseException {
        String userId = SecurityUtils.getUserId();
        //获取参数
        Boolean plan = recordDetailsExParam.getPlan();
        String toDay = recordDetailsExParam.getToDay();
        JSONArray jsonArray = new JSONArray();
        if(plan){
            //查询这个用户下为执行人的所有巡检计划
            ArdAppPatrolplan ardAppPatrolplan = new ArdAppPatrolplan();
            ardAppPatrolplan.setUserId(SecurityUtils.getUserId());
            List<ArdAppPatrolplan> list = patrolplanMapper.executeList(ardAppPatrolplan);
            //找出今天的单次和每日计划
            List<ArdAppPatrolplan> patrolplanList = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                String cycle = list.get(i).getCycle();
                //如果是单次任务
                if(cycle.equals("once")){
                    String begin = list.get(i).getPatroBeginTime();
                    String b = begin.substring(0,10);
                    if(b.equals(toDay)){
                        //是今天的计划
                        patrolplanList.add(list.get(i));
                    }
                }
                //如果是每日任务
                else if(cycle.equals("day")){
                    String create = list.get(i).getCreateTime();
                    String c = create.substring(0,10);
                    if(c.compareTo(toDay)<=0){
                        //有今天的计划
                        patrolplanList.add(list.get(i));
                    }
                }
            }
            if(patrolplanList.size()>0){
                //遍历今天的计划
                for (int i = 0; i < patrolplanList.size(); i++) {
                    String planId = patrolplanList.get(i).getId();
                    String planName = patrolplanList.get(i).getPlanName();
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("planId",planId);
                    jsonObject.put("planName",planName);
                    //查询这天有多少点
                    List<ArdAlarmpointsWell> dayWells = wellMapper.wellByPlanId(planId);
                    int dayWellNum = dayWells.size();
                    //查询这个用户的这个计划在今天打卡的条数
                    QueryWrapper<ArdAppPatrolpointRecord> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("user_id",userId).eq("plan_id",planId).like("record_time",toDay);
                    List<ArdAppPatrolpointRecord> recordList = ardAppPatrolpointRecordMapper.selectList(queryWrapper);
                    int recordNum = recordList.size();
                    //如果相等那这条今天的计划就是全部完成了
                    if(recordNum==dayWellNum){
                        jsonObject.put("type",true);
                    }else {
                        jsonObject.put("type",false);
                    }
                    jsonArray.add(jsonObject);
                }
            }
        }else {
            //没有计划
            return Results.succeed("[]");
        }
        return Results.succeed(jsonArray);
    }
    @Override
    public Results recordBefore(RecordBeforeParam recordBeforeParam) {
        String planId = recordBeforeParam.getPlanId();
        String wellId = recordBeforeParam.getWellId();
        String toDay = recordBeforeParam.getToDay();
        String userId = SecurityUtils.getUserId();
        JSONArray jsonArray = new JSONArray();
        ArdAppPatrolplan plan = patrolplanMapper.selectById(planId);
        jsonArray.add(plan);
        QueryWrapper<ArdAppPatrolpointRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("plan_id",planId).eq("app_patrolpoints_id",wellId).eq("user_id",userId).like("record_time",toDay);
        ArdAppPatrolpointRecord record = ardAppPatrolpointRecordMapper.selectOne(queryWrapper);
        //根据姓名ID查询计划制定人的姓名
        String planUserId = plan.getUserId();
        SysUser sysUser = sysUserMapper.selectById(planUserId);
        String nikeName = sysUser.getNickName();
        if(record==null){
            //根据姓名ID查询执行人姓名
            SysUser user = sysUserMapper.selectById(userId);
            String userName = user.getNickName();
            //查询该计划的所有兴趣点
            ArdAlarmpointsWell ardAlarmpointsWell = wellMapper.selectById(wellId);
            //没打卡的数据
            ArdAppPatrolpointRecord record1 = new ArdAppPatrolpointRecord();
            record1.setAppPatrolpointsId(ardAlarmpointsWell.getId());
            record1.setAppPatrolpointsName(ardAlarmpointsWell.getWellId());
            record1.setPlanId(planId);
            record1.setPlanName(plan.getPlanName());
            record1.setUserId(userId);
            record1.setUserName(userName);
            record1.setLatitude(String.valueOf(ardAlarmpointsWell.getLatitude()));
            record1.setLongitude(String.valueOf(ardAlarmpointsWell.getLongitude().toString()));
            record1.setPlanUserName(nikeName);
            jsonArray.add(record1);
        }else {
            jsonArray.add(record);
        }
        return Results.succeed(jsonArray);
    }
    @Override
    public Results son() {
        return null;
    }
}