Administrator
2023-08-19 99698ab94184436c6b3c6f20d4562ef1fac8e7de
ard-work/src/main/java/com/ruoyi/app/patrolplan/service/impl/ArdAppPatrolpointRecordServiceImpl.java
@@ -2,6 +2,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -71,7 +72,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 +81,7 @@
            recordImg.setId(imgId);
            recordImg.setAppPatrolponitRecordId(id);
            recordImg.setImg(list.get(i));
            recordImgMapper.insert(recordImg);
            recordImgMapper.insertArdAppPatrolpointRecordImg(recordImg);
        }
        if(num>0){
            return Results.succeed("打卡成功!");
@@ -112,7 +114,6 @@
            monthZero = String.valueOf(month);
        }
        JSONArray jsonArray = new JSONArray();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 1; i <= day; i++) {
            String di;
            if(i<10){
@@ -124,24 +125,20 @@
            Boolean planBoolean = false;
            //循环每一天
            String ymd = year+"-"+monthZero+"-"+di;
//            Date ymdDate = dateFormat.parse(ymd);
            //匹配计划时间
            String cycle = ardAppPatrolplan.getCycle();
            if(cycle.equals("day")){
                String createTime = ardAppPatrolplan.getCreateTime();
//                Date beginCreateDate = dateFormat.parse(createTime);
                int d = ymd.compareTo(createTime);
                String st = createTime.substring(0,10);
                int d = ymd.compareTo(st);
                if(d>=0){
                    planBoolean = true;
                }
            }else if(cycle.equals("once")){
                String onceBegin = ardAppPatrolplan.getPatroBeginTime();
//                Date onceBeginDate = dateFormat.parse(onceBegin);
                String onceEnd = ardAppPatrolplan.getPatroEndTime();
//                Date onceEndDate = dateFormat.parse(onceEnd);
                int bd = ymd.compareTo(onceBegin);
                int ed = ymd.compareTo(onceEnd);
                if(bd>=0 && ed<=0){
                String onceT = onceBegin.substring(0,10);
                int num = ymd.compareTo(onceT);
                if(num==0){
                    planBoolean = true;
                }
            }
@@ -149,31 +146,49 @@
            Boolean or = false;
            if(planBoolean){
                for (int j = 0; j < list.size(); j++) {
                    //打卡时间拆分
                    String recordTime = list.get(j).getRecordTime();
                    String[] part = recordTime.split("[-\\s:]");
                    int recordYear = Integer.parseInt(part[0]);
                    int recordMonth = Integer.parseInt(part[1]);
                    String recordMonthZero;
                    if(recordMonth<10){
                        recordMonthZero = String.format("%02d", recordMonth);
                    }else {
                        recordMonthZero = String.valueOf(recordMonth);
                    }
                    int recordDay = Integer.parseInt(part[2]);
                    String recordDayZero;
                    if(recordDay<10){
                        recordDayZero = String.format("%02d", recordDay);
                    }else {
                        recordDayZero = String.valueOf(recordDay);
                    }
                    String recordDate = recordYear+"-"+recordMonthZero+"-"+recordDayZero;
                    //如果相等说明这天有打卡记录记录
                    if(ymd.equals(recordDate)){
                        or = true;
                        break;
                    //获取打卡时间
                    String toDayRecord = list.get(j).getRecordTime();
                    String dr = toDayRecord.substring(0,10);
                    //如果打开日期和这天相同
                    if(ymd.equals(dr)){
                        //查询该计划的所有兴趣点
                        List<ArdAlarmpointsWell> wellList = wellMapper.wellByPlanId(planId);
                        //查询该计划的所有执行人
                        List<SysUser> userList = sysUserMapper.userByPlanId(planId);
                        //满勤多少条打卡记录
                        int maxNum = wellList.size()*userList.size();
                        //对比应打卡记录相等则true
                        if(list.size()==maxNum){
                            or = true;
                        }
                    }
                }
//                for (int j = 0; j < list.size(); j++) {
//                    //打卡时间拆分
//                    String recordTime = list.get(j).getRecordTime();
//                    String[] part = recordTime.split("[-\\s:]");
//                    int recordYear = Integer.parseInt(part[0]);
//                    int recordMonth = Integer.parseInt(part[1]);
//                    String recordMonthZero;
//                    if(recordMonth<10){
//                        recordMonthZero = String.format("%02d", recordMonth);
//                    }else {
//                        recordMonthZero = String.valueOf(recordMonth);
//                    }
//                    int recordDay = Integer.parseInt(part[2]);
//                    String recordDayZero;
//                    if(recordDay<10){
//                        recordDayZero = String.format("%02d", recordDay);
//                    }else {
//                        recordDayZero = String.valueOf(recordDay);
//                    }
//                    String recordDate = recordYear+"-"+recordMonthZero+"-"+recordDayZero;
//                    //如果相等说明这天有打卡记录记录
//                    if(ymd.equals(recordDate)){
//                        or = true;
//                        break;
//                    }
//                }
            }
            jsonObject.put("toDay",ymd );
            jsonObject.put("plan",planBoolean);
@@ -186,7 +201,7 @@
    @Override
    public Results recordDetails(RecordDetailsParam recordDetailsParam) throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dateFormatTime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        SimpleDateFormat dateFormatTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //获取参数
        String planId = recordDetailsParam.getPlanId();
        String toDay = recordDetailsParam.getToDay();
@@ -237,8 +252,9 @@
                    //小于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{
                    String u = dateFormatTime.format(new Date());
                    //等于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");;
                    recordQueryWrapper.select("max(points_num) pointsNum","user_id","user_name").eq("plan_id", planId).le("record_time", u).groupBy("user_id","user_name");
                }
                List<ArdAppPatrolpointRecord> list = ardAppPatrolpointRecordMapper.selectList(recordQueryWrapper);
                //选中这天该计划下没有任何打卡记录
@@ -462,7 +478,7 @@
    @Override
    public Results executeDetailsOld(RecordDetailsParam recordDetailsParam) throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dateFormatTime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        SimpleDateFormat dateFormatTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String userId = SecurityUtils.getUserId();
        //获取参数
        String planId = recordDetailsParam.getPlanId();
@@ -769,4 +785,37 @@
        }
        return Results.succeed(jsonArray);
    }
    @Override
    public Results son() {
        SimpleDateFormat dateFormatTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //获取用户执行人
        String userId = SecurityUtils.getUserId();
        // 减少 10 秒
        LocalDateTime now = LocalDateTime.now(); // 获取当前日期时间
        LocalDateTime earlier = now.minusSeconds(10); // 减少30秒
        System.out.println("当前日期时间:" + now);
        System.out.println("减少10秒后的日期时间:" + earlier);
        RecordSonParam recordSonParam = new RecordSonParam();
        recordSonParam.setUserId(userId);
        recordSonParam.setTime(dateFormatTime.format(now));
        recordSonParam.setBeforeTime(dateFormatTime.format(earlier));
        //根据姓名ID为执行人获取所有对应的计划名称
        List<ArdAppPatrolplan> list = patrolplanMapper.planUser(recordSonParam);
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        if(list.size()>0){
            jsonObject.put("plan",true);
            jsonObject.put("user",list.get(0).getNickName());
            jsonObject.put("name",list.get(0).getPlanName());
//            list.get(0).setSon("已通知");
//            patrolplanMapper.updateById(list.get(0));
        }else {
            jsonObject.put("plan",false);
            jsonObject.put("user",null);
            jsonObject.put("name",null);
        }
        jsonArray.add(jsonObject);
        return Results.succeed(jsonArray);
    }
}