From 99698ab94184436c6b3c6f20d4562ef1fac8e7de Mon Sep 17 00:00:00 2001
From: Administrator <1144154118@qq.com>
Date: 星期六, 19 八月 2023 15:59:40 +0800
Subject: [PATCH] 巡检通知

---
 ard-work/src/main/java/com/ruoyi/app/patrolplan/service/impl/ArdAppPatrolpointRecordServiceImpl.java |  752 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 672 insertions(+), 80 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/app/patrolplan/service/impl/ArdAppPatrolpointRecordServiceImpl.java b/ard-work/src/main/java/com/ruoyi/app/patrolplan/service/impl/ArdAppPatrolpointRecordServiceImpl.java
index c09b1fd..d5589a2 100644
--- a/ard-work/src/main/java/com/ruoyi/app/patrolplan/service/impl/ArdAppPatrolpointRecordServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/app/patrolplan/service/impl/ArdAppPatrolpointRecordServiceImpl.java
@@ -2,6 +2,8 @@
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -9,13 +11,19 @@
 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.param.ArdAppPatrolpointRecordParam;
+import com.ruoyi.app.patrolplan.domain.ArdAppPatroluser;
+import com.ruoyi.app.patrolplan.domain.param.*;
 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;
@@ -43,78 +51,29 @@
     @Resource
     private ArdAppPatrolplanMapper patrolplanMapper;
 
-    /**
-     * 鏌ヨapp宸℃璁″垝璁板綍
-     *
-     * @param id app宸℃璁″垝璁板綍涓婚敭
-     * @return app宸℃璁″垝璁板綍
-     */
-    @Override
-    public ArdAppPatrolpointRecord selectArdAppPatrolpointRecordById(String id) {
-        return ardAppPatrolpointRecordMapper.selectArdAppPatrolpointRecordById(id);
-    }
+    @Resource
+    private ArdAppPatroluserMapper userMapper;
 
-    /**
-     * 鏌ヨapp宸℃璁″垝璁板綍鍒楄〃
-     *
-     * @param ardAppPatrolpointRecord app宸℃璁″垝璁板綍
-     * @return app宸℃璁″垝璁板綍
-     */
-    @Override
-    public List<ArdAppPatrolpointRecord> selectArdAppPatrolpointRecordList(ArdAppPatrolpointRecord ardAppPatrolpointRecord) {
-        return ardAppPatrolpointRecordMapper.selectArdAppPatrolpointRecordList(ardAppPatrolpointRecord);
-    }
+    @Resource
+    private SysUserMapper sysUserMapper;
 
-    /**
-     * 鏂板app宸℃璁″垝璁板綍
-     *
-     * @param ardAppPatrolpointRecord app宸℃璁″垝璁板綍
-     * @return 缁撴灉
-     */
-    @Override
-    public int insertArdAppPatrolpointRecord(ArdAppPatrolpointRecord ardAppPatrolpointRecord) {
-                ardAppPatrolpointRecord.setUserId(SecurityUtils.getUserId());
-            return ardAppPatrolpointRecordMapper.insertArdAppPatrolpointRecord(ardAppPatrolpointRecord);
-    }
-
-    /**
-     * 淇敼app宸℃璁″垝璁板綍
-     *
-     * @param ardAppPatrolpointRecord app宸℃璁″垝璁板綍
-     * @return 缁撴灉
-     */
-    @Override
-    public int updateArdAppPatrolpointRecord(ArdAppPatrolpointRecord ardAppPatrolpointRecord) {
-        return ardAppPatrolpointRecordMapper.updateArdAppPatrolpointRecord(ardAppPatrolpointRecord);
-    }
-
-    /**
-     * 鎵归噺鍒犻櫎app宸℃璁″垝璁板綍
-     *
-     * @param ids 闇�瑕佸垹闄ょ殑app宸℃璁″垝璁板綍涓婚敭
-     * @return 缁撴灉
-     */
-    @Override
-    public int deleteArdAppPatrolpointRecordByIds(String[] ids) {
-        return ardAppPatrolpointRecordMapper.deleteArdAppPatrolpointRecordByIds(ids);
-    }
-
-    /**
-     * 鍒犻櫎app宸℃璁″垝璁板綍淇℃伅
-     *
-     * @param id app宸℃璁″垝璁板綍涓婚敭
-     * @return 缁撴灉
-     */
-    @Override
-    public int deleteArdAppPatrolpointRecordById(String id) {
-        return ardAppPatrolpointRecordMapper.deleteArdAppPatrolpointRecordById(id);
-    }
+    @Resource
+    private ArdAlarmpointsWellMapper wellMapper;
 
     @Override
     public Results record(ArdAppPatrolpointRecord ardAppPatrolpointRecord) {
         String id = IdUtils.simpleUUID();
         ardAppPatrolpointRecord.setId(id);
-        int num = ardAppPatrolpointRecordMapper.insert(ardAppPatrolpointRecord);
+        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);
+        int num = ardAppPatrolpointRecordMapper.insertArdAppPatrolpointRecord(ardAppPatrolpointRecord);
         List<String> list = ardAppPatrolpointRecord.getImg();
         for (int i = 0; i < list.size(); i++) {
             ArdAppPatrolpointRecordImg recordImg = new ArdAppPatrolpointRecordImg();
@@ -122,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("鎵撳崱鎴愬姛锛�");
@@ -132,16 +91,310 @@
     }
 
     @Override
-    public Results recordMonth(ArdAppPatrolpointRecordParam ardAppPatrolpointRecordParam) throws ParseException {
+    public Results recordMonth(RecordMonthParam recordMonthParam) throws ParseException {
         //鑾峰彇鍓嶇鍙傛暟
-        String begin = ardAppPatrolpointRecordParam.getBegin();
-        String end = ardAppPatrolpointRecordParam.getEnd();
-        String planId = ardAppPatrolpointRecordParam.getPlanId();
+        String begin = recordMonthParam.getBegin();
+        String end = recordMonthParam.getEnd();
+        String planId = recordMonthParam.getPlanId();
         //鏌ヨ璁″垝琛�
         ArdAppPatrolplan ardAppPatrolplan = patrolplanMapper.selectById(planId);
         //鏌ヨ鍑烘湁鏁堟墦鍗℃暟鎹�
         QueryWrapper<ArdAppPatrolpointRecord> queryWrapper = new QueryWrapper<>();
         queryWrapper.between("record_time",begin,end).eq("plan_id",planId);
+        List<ArdAppPatrolpointRecord> list = ardAppPatrolpointRecordMapper.selectList(queryWrapper);
+        //鏃堕棿鎷嗗垎
+        String[] parts = end.split("[-\\s:]");
+        int year = Integer.parseInt(parts[0]);
+        int month = Integer.parseInt(parts[1]);
+        int day = Integer.parseInt(parts[2]);
+        String monthZero;
+        if(month<10){
+            monthZero = String.format("%02d", month);
+        }else {
+            monthZero = String.valueOf(month);
+        }
+        JSONArray jsonArray = new JSONArray();
+        for (int i = 1; i <= day; i++) {
+            String di;
+            if(i<10){
+                di = String.format("%02d", i);
+            }else {
+                di = String.valueOf(i);
+            }
+            JSONObject jsonObject = new JSONObject();
+            Boolean planBoolean = false;
+            //寰幆姣忎竴澶�
+            String ymd = year+"-"+monthZero+"-"+di;
+            //鍖归厤璁″垝鏃堕棿
+            String cycle = ardAppPatrolplan.getCycle();
+            if(cycle.equals("day")){
+                String createTime = ardAppPatrolplan.getCreateTime();
+                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();
+                String onceT = onceBegin.substring(0,10);
+                int num = ymd.compareTo(onceT);
+                if(num==0){
+                    planBoolean = true;
+                }
+            }
+            //鍖归厤鎵撳崱鏃堕棿
+            Boolean or = false;
+            if(planBoolean){
+                for (int j = 0; j < list.size(); j++) {
+                    //鑾峰彇鎵撳崱鏃堕棿
+                    String toDayRecord = list.get(j).getRecordTime();
+                    String dr = toDayRecord.substring(0,10);
+                    //濡傛灉鎵撳紑鏃ユ湡鍜岃繖澶╃浉鍚�
+                    if(ymd.equals(dr)){
+                        //鏌ヨ璇ヨ鍒掔殑鎵�鏈夊叴瓒g偣
+                        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);
+            jsonObject.put("record",or);
+            jsonArray.add(jsonObject);
+        }
+        return Results.succeed(jsonArray);
+    }
+
+    @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");
+        //鑾峰彇鍙傛暟
+        String planId = recordDetailsParam.getPlanId();
+        String toDay = recordDetailsParam.getToDay();
+        //鏌ヨ璁″垝琛�
+        ArdAppPatrolplan ardAppPatrolplan = patrolplanMapper.selectById(planId);
+        String cycle = ardAppPatrolplan.getCycle();
+        String begin = ardAppPatrolplan.getPatroBeginTime();
+        String end = ardAppPatrolplan.getPatroEndTime();
+        String create = ardAppPatrolplan.getCreateTime();
+        JSONArray jsonArray = new JSONArray();
+        int c = 0;
+        if(cycle.equals("day")){
+            //姣忓ぉ璁″垝鍙栧垱寤烘椂闂�
+            c = toDay.compareTo(create.substring(0,10));
+        }else if(cycle.equals("once")){
+            //鍗曟璁″垝鍙栧紑濮嬫椂闂�
+            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浠h〃鏌ヨ浠ュ悗鐨勮褰�
+            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);
+                }
+                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{
+                    String u = dateFormatTime.format(new Date());
+                    //绛変簬0閫変腑鐨勬棩鏈熷氨鏄粖澶╋紝闇�瑕佽繘涓�姝ュ垽鏂皬浜庡綋鍓嶆椂鍒嗙鐨勮褰�
+                    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);
+                //閫変腑杩欏ぉ璇ヨ鍒掍笅娌℃湁浠讳綍鎵撳崱璁板綍
+                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);
+                }
+                //鏌ヨ璇ヨ鍒掔殑鎵�鏈夊叴瓒g偣
+                List<ArdAlarmpointsWell> wellList = wellMapper.wellByPlanId(planId);
+                Integer wellNum = wellList.size();
+                //鍙栧嚭鎵�鏈夋墦浜嗗崱鐨剈serId
+                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();
+                    //濡傛灉璇ヨ鍒掔殑鎵�鏈変汉鍛榰serId涓嶅湪鎵�鏈夋墦浜嗗崱鐨剈serId涓�
+                    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);
+            }
+        }
+    }
+
+    @Override
+    public Results recordSolo(RecordSoloParam recordSoloParam) {
+        String toDay = recordSoloParam.getToDay();
+        String planId = recordSoloParam.getPlanId();
+        String userId = recordSoloParam.getUserId();
+        String planName = recordSoloParam.getPlanName();
+        String userName = recordSoloParam.getUserName();
+        //鏍规嵁璁″垝ID鑾峰彇鍒跺畾浜篒D
+        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);
+        }
+        //鏌ヨ璇ヨ鍒掔殑鎵�鏈夊叴瓒g偣
+        List<ArdAlarmpointsWell> wellList = wellMapper.wellByPlanId(planId);
+        if(list.size()==0){
+            for (ArdAlarmpointsWell ardAlarmpointsWell : wellList) {
+                ArdAppPatrolpointRecord ardAppPatrolpointRecord = new ArdAppPatrolpointRecord();
+                ardAppPatrolpointRecord.setAppPatrolpointsId(ardAlarmpointsWell.getId());
+                ardAppPatrolpointRecord.setAppPatrolpointsName(ardAlarmpointsWell.getWellId());
+                ardAppPatrolpointRecord.setPlanId(planId);
+                ardAppPatrolpointRecord.setPlanName(planName);
+                ardAppPatrolpointRecord.setUserId(userId);
+                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);
+        }
+        for (ArdAppPatrolpointRecord appPatrolpointRecord : list) {
+            QueryWrapper<ArdAppPatrolpointRecordImg> queryWrapper1 = new QueryWrapper<>();
+            queryWrapper1.eq("app_patrolponit_record_id", appPatrolpointRecord.getId());
+            List<ArdAppPatrolpointRecordImg> list1 = recordImgMapper.selectList(queryWrapper1);
+            List<String> strings = new ArrayList<>();
+            for (ArdAppPatrolpointRecordImg ardAppPatrolpointRecordImg : list1) {
+                strings.add(ardAppPatrolpointRecordImg.getImg());
+            }
+            appPatrolpointRecord.setImg(strings);
+        }
+        //鎵撹繃鍗$殑鍦扮偣
+        List<String> pointList = new ArrayList<>();
+        for (ArdAppPatrolpointRecord appPatrolpointRecord : list) {
+            pointList.add(appPatrolpointRecord.getAppPatrolpointsId());
+        }
+        for (ArdAlarmpointsWell ardAlarmpointsWell : wellList) {
+            //鎵�鏈夊簲璇ユ墦鍗$殑鍦扮偣ID
+            String well = ardAlarmpointsWell.getId();
+            //濡傛灉鎵撳崱鍦扮偣涓嶅寘鍚簲鎵撳崱鍦扮偣锛岄偅璇村悕杩欏潡鍎挎病鎵撳崱
+            if (!pointList.contains(well)) {
+                ArdAppPatrolpointRecord ardAppPatrolpointRecord = new ArdAppPatrolpointRecord();
+                ardAppPatrolpointRecord.setAppPatrolpointsId(well);
+                ardAppPatrolpointRecord.setAppPatrolpointsName(ardAlarmpointsWell.getWellId());
+                ardAppPatrolpointRecord.setPlanId(planId);
+                ardAppPatrolpointRecord.setPlanName(planName);
+                ardAppPatrolpointRecord.setUserId(userId);
+                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);
+    }
+
+    @Override
+    public Results executeMonthOld(RecordMonthParam RecordMonthParam) throws ParseException {
+        //鑾峰彇鍓嶇鍙傛暟
+        String begin = RecordMonthParam.getBegin();
+        String end = RecordMonthParam.getEnd();
+        String planId = RecordMonthParam.getPlanId();
+        //鏌ヨ璁″垝琛�
+        ArdAppPatrolplan ardAppPatrolplan = patrolplanMapper.selectById(planId);
+        //鏌ヨ鍑烘湁鏁堟墦鍗℃暟鎹�
+        String userId = SecurityUtils.getUserId();
+        QueryWrapper<ArdAppPatrolpointRecord> queryWrapper = new QueryWrapper<>();
+        queryWrapper.between("record_time",begin,end).eq("plan_id",planId).eq("user_id",userId);
         List<ArdAppPatrolpointRecord> list = ardAppPatrolpointRecordMapper.selectList(queryWrapper);
         //鏃堕棿鎷嗗垎
         String[] parts = end.split("[-\\s:]");
@@ -167,23 +420,19 @@
             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 = ymdDate.compareTo(beginCreateDate);
+                int d = ymd.compareTo(createTime);
                 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 = ymdDate.compareTo(onceBeginDate);
-                int ed = ymdDate.compareTo(onceEndDate);
+                int bd = ymd.compareTo(onceBegin);
+                int ed = ymd.compareTo(onceEnd);
                 if(bd>=0 && ed<=0){
                     planBoolean = true;
                 }
@@ -198,14 +447,14 @@
                     int recordYear = Integer.parseInt(part[0]);
                     int recordMonth = Integer.parseInt(part[1]);
                     String recordMonthZero;
-                    if(i<10){
+                    if(recordMonth<10){
                         recordMonthZero = String.format("%02d", recordMonth);
                     }else {
                         recordMonthZero = String.valueOf(recordMonth);
                     }
                     int recordDay = Integer.parseInt(part[2]);
                     String recordDayZero;
-                    if(i<10){
+                    if(recordDay<10){
                         recordDayZero = String.format("%02d", recordDay);
                     }else {
                         recordDayZero = String.valueOf(recordDay);
@@ -226,4 +475,347 @@
         return Results.succeed(jsonArray);
     }
 
+    @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");
+        String userId = SecurityUtils.getUserId();
+        //鑾峰彇鍙傛暟
+        String planId = recordDetailsParam.getPlanId();
+        String toDay = recordDetailsParam.getToDay();
+        //鏌ヨ璁″垝琛�
+        ArdAppPatrolplan ardAppPatrolplan = patrolplanMapper.selectById(planId);
+        String cycle = ardAppPatrolplan.getCycle();
+        String begin = ardAppPatrolplan.getPatroBeginTime();
+        String end = ardAppPatrolplan.getPatroEndTime();
+        String create = ardAppPatrolplan.getCreateTime();
+        JSONArray jsonArray = new JSONArray();
+        int c = 0;
+        if(cycle.equals("day")){
+            //姣忓ぉ璁″垝鍙栧垱寤烘椂闂�
+            c = toDay.compareTo(create.substring(0,10));
+        }else if(cycle.equals("once")){
+            //鍗曟璁″垝鍙栧紑濮嬫椂闂�
+            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);
+            //鏌ヨ璇ヨ鍒掔殑鎵�鏈夊叴瓒g偣
+            List<ArdAlarmpointsWell> wellList = wellMapper.wellByPlanId(planId);
+            //澶т簬0浠h〃鏌ヨ浠ュ悗鐨勮褰�
+            if(d>0){
+                //鏌ヨ璁″垝鍐呯殑姣忔棩鏈潵鏁版嵁
+                for (int i = 0; i < users.size(); i++) {
+                    JSONObject jsonObject = new JSONObject();
+                    jsonObject.put("wellId",wellList.get(i).getId());
+                    jsonObject.put("wellName",wellList.get(i).getWellId());
+                    jsonObject.put("type",false);
+                    jsonArray.add(jsonObject);
+                }
+                return Results.succeed(jsonArray);
+            }else{
+                //鏌ヨ璁″垝鍐呯殑瀹為檯鍘嗗彶鎵撳崱鏁版嵁
+                QueryWrapper<ArdAppPatrolpointRecord> recordQueryWrapper = new QueryWrapper<>();
+                if(d<0){
+                    //灏忎簬0鏄巻鍙�
+                    recordQueryWrapper.select("app_patrolpoints_id","app_patrolpoints_name").eq("plan_id", planId).eq("user_id",userId).like("record_time", toDay);
+                }else{
+                    //绛変簬0閫変腑鐨勬棩鏈熷氨鏄粖澶╋紝闇�瑕佽繘涓�姝ュ垽鏂皬浜庡綋鍓嶆椂鍒嗙鐨勮褰�
+                    recordQueryWrapper.select("app_patrolpoints_id","app_patrolpoints_name").eq("plan_id", planId).eq("user_id",userId).le("record_time", dateFormatTime.format(new Date()));
+                }
+                List<ArdAppPatrolpointRecord> list = ardAppPatrolpointRecordMapper.selectList(recordQueryWrapper);
+                //寰幆鎵撳崱鍦扮偣
+                for (int i = 0; i < wellList.size(); i++) {
+                    String id = wellList.get(i).getId();
+                    JSONObject jsonObject = new JSONObject();
+                    jsonObject.put("wellId",wellList.get(i).getId());
+                    jsonObject.put("wellName",wellList.get(i).getWellId());
+                    if(list.size()>0){
+                        for (int j = 0; j < list.size(); j++) {
+                            if(id.equals(list.get(j).getAppPatrolpointsId())){
+                                jsonObject.put("type",true);
+                                break;
+                            }
+                            if(j==list.size()-1){
+                                jsonObject.put("type",false);
+                            }
+                        }
+                    }else {
+                        jsonObject.put("type",false);
+                    }
+                    jsonArray.add(jsonObject);
+                }
+                return Results.succeed(jsonArray);
+            }
+        }
+    }
+
+    @Override
+    public Results executeSolo(RecordSoloExParam recordSoloExParam) {
+        QueryWrapper<ArdAppPatrolpointRecord> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("plan_id",recordSoloExParam.getPlanId())
+                .eq("app_patrolpoints_id",recordSoloExParam.getWellId())
+                .eq("user_id",recordSoloExParam.getUserId())
+                .like("record_time",recordSoloExParam.getToDay());
+        List<ArdAppPatrolpointRecord> list = ardAppPatrolpointRecordMapper.selectList(queryWrapper);
+        for (ArdAppPatrolpointRecord appPatrolpointRecord : list) {
+            QueryWrapper<ArdAppPatrolpointRecordImg> queryWrapper1 = new QueryWrapper<>();
+            queryWrapper1.eq("app_patrolponit_record_id", appPatrolpointRecord.getId());
+            List<ArdAppPatrolpointRecordImg> list1 = recordImgMapper.selectList(queryWrapper1);
+            List<String> strings = new ArrayList<>();
+            for (ArdAppPatrolpointRecordImg ardAppPatrolpointRecordImg : list1) {
+                strings.add(ardAppPatrolpointRecordImg.getImg());
+            }
+            appPatrolpointRecord.setImg(strings);
+        }
+        return Results.succeed(list);
+    }
+
+    @Override
+    public Results executeMonth(RecordMonthExParam recordMonthExParam) throws ParseException {
+        //鑾峰彇鍓嶇鍙傛暟
+        String begin = recordMonthExParam.getBegin();
+        String end = recordMonthExParam.getEnd();
+        //杩斿洖杩欎釜
+        JSONArray jsonArray = new JSONArray();
+        //鏃堕棿鎷嗗垎
+        String[] parts = end.split("[-\\s:]");
+        int year = Integer.parseInt(parts[0]);
+        int month = Integer.parseInt(parts[1]);
+        int day = Integer.parseInt(parts[2]);
+        String monthZero;
+        if(month<10){
+            monthZero = String.format("%02d", month);
+        }else {
+            monthZero = String.valueOf(month);
+        }
+        String userId = SecurityUtils.getUserId();
+        recordMonthExParam.setUserId(userId);
+        //鏌ヨ璇ョ敤鎴蜂笅闇�瑕佹墽琛岀殑鍗曟璁″垝
+        List<ArdAppPatrolplan> onceList = patrolplanMapper.oncePlan(recordMonthExParam);
+        //鏌ヨ璇ョ敤鎴蜂笅闇�瑕佹墽琛岀殑姣忔棩璁″垝
+        List<ArdAppPatrolplan> dayList = patrolplanMapper.dayPlan(recordMonthExParam);
+        //寰幆涓�涓湀涓殑姣忎竴澶�
+        for (int i = 1; i <= day; i++) {
+            String di;
+            Boolean planBoolean = false;
+            Boolean recordBoolean = false;
+            //璁板綍杩欏ぉ璁″垝鏉℃暟
+            int dayNum = 0;
+            int onceNum = 0;
+            //璁板綍杩欏ぉ鐨勬墦寮�鍦扮偣鏁�
+            int dayWell = 0;
+            int onceWell = 0;
+            if (i < 10) {
+                di = String.format("%02d", i);
+            } else {
+                di = String.valueOf(i);
+            }
+            //姣忎竴澶�
+            String ymd = year + "-" + monthZero + "-" + di;
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("toDay",ymd );
+            //濡傛灉姣忔棩璁″垝鏈夋暟鎹�
+            if (dayList.size() > 0) {
+                for (int j = 0; j < dayList.size(); j++) {
+                    String dayTime = dayList.get(j).getCreateTime();
+                    String dt = dayTime.substring(0,10);
+                    //濡傛灉姣忔棩璁″垝鏃ユ湡绛変簬杩欎竴澶╋紝閭d粠杩欎竴澶╀箣鍚庣殑姣忎竴澶╅兘鏄湁璁″垝鐨�
+                    if(dt.compareTo(ymd)<=0){
+                        planBoolean =true;
+                        dayNum+=1;
+                        String id = dayList.get(j).getId();
+                        List<ArdAlarmpointsWell> dayWells = wellMapper.wellByPlanId(id);
+                        dayWell = dayWells.size();
+                    }
+                }
+            }
+            //濡傛灉鍗曟璁″垝鏈夋暟鎹�
+            if(onceList.size()>0){
+                for (int j = 0; j < onceList.size(); j++) {
+                    String beginTime = onceList.get(j).getPatroBeginTime();
+                    String bt = beginTime.substring(0,10);
+                    if(bt.equals(ymd)){
+                        planBoolean = true;
+                        onceNum+=1;
+                        List<ArdAlarmpointsWell> onceWells = wellMapper.wellByPlanId(onceList.get(j).getId());
+                        onceWell = onceWells.size();
+                    }
+                }
+            }
+            if(planBoolean){
+                //杩欏ぉ鎬讳换鍔℃潯鏁�
+                int planNum = dayNum+onceNum;
+                //杩欏ぉ鎬诲叴瓒g偣鏁�
+                int wellNum = dayWell+onceWell;
+                QueryWrapper<ArdAppPatrolpointRecord> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("user_id",userId).like("record_time",ymd);
+                List<ArdAppPatrolpointRecord> list = ardAppPatrolpointRecordMapper.selectList(queryWrapper);
+                //宸叉墦鍗℃�绘潯鏁�
+                int num = list.size();
+                //搴旀墦鍗℃�绘潯鏁�
+                int record = planNum*wellNum;
+                if(num==record){
+                    recordBoolean = true;
+                }
+            }
+            jsonObject.put("toDay",ymd );
+            jsonObject.put("plan",planBoolean);
+            jsonObject.put("record",recordBoolean);
+            jsonArray.add(jsonObject);
+        }
+        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();
+                    //濡傛灉鐩哥瓑閭h繖鏉′粖澶╃殑璁″垝灏辨槸鍏ㄩ儴瀹屾垚浜�
+                    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();
+            //鏌ヨ璇ヨ鍒掔殑鎵�鏈夊叴瓒g偣
+            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() {
+        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);
+    }
 }

--
Gitblit v1.9.3