Browse Source

相机出库统计

lyhzzz 2 years ago
parent
commit
400266e5ae

+ 10 - 0
src/main/java/com/fdkankan/manage/controller/DataController.java

@@ -80,6 +80,16 @@ public class DataController {
                                  @RequestParam(required = false) String endTime){
         return ResultData.ok(dataService.sceneTrend(type,dataType,startTime,endTime));
     }
+    /**
+     *相机出库数量统计
+     * @param type  0:日 ,1:周,2:月
+     */
+    @GetMapping("/cameraTrend")
+    public ResultData sceneTrend(@RequestParam(required = false,defaultValue = "0") Integer type,
+                                 @RequestParam(required = false) String startTime,
+                                 @RequestParam(required = false) String endTime){
+        return ResultData.ok(dataService.cameraTrend(type,startTime,endTime));
+    }
 
 
 

+ 1 - 0
src/main/java/com/fdkankan/manage/service/IDataService.java

@@ -19,4 +19,5 @@ public interface IDataService {
 
     HashMap<String, List<DataGroupByCount>> sceneTrend(Integer type,Integer dataType,String startTime,String endTime);
 
+    HashMap<String, Object> cameraTrend(Integer type, String startTime, String endTime);
 }

+ 65 - 6
src/main/java/com/fdkankan/manage/service/impl/DataService.java

@@ -74,8 +74,8 @@ public class DataService implements IDataService {
 
     @Override
     public List<DataGroupByCount> userTrend(Integer type,Integer dataType,String startTime,String endTime) {
-        startTime = Dateutils.formatStartTime(startTime,type);
-        endTime = Dateutils.formatEndTime(endTime,type);
+        startTime = Dateutils.formatStartTime(startTime);
+        endTime = Dateutils.formatEndTime(endTime);
 
         List<DataGroupByCount> dataList = new ArrayList<>();
         List<DataGroupByCount> result = new ArrayList<>();
@@ -115,8 +115,9 @@ public class DataService implements IDataService {
 
     @Override
     public HashMap<String, Object> orderTrend(Integer type,Integer dataType,String startTime,String endTime) {
-        startTime = Dateutils.formatStartTime(startTime,type);
-        endTime = Dateutils.formatEndTime(endTime,type);
+        startTime = Dateutils.formatStartTime(startTime);
+        endTime = Dateutils.formatEndTime(endTime);
+
         HashMap<String,Object> map = new HashMap<>();
         if(dataType == 1){
             return getAmountSumOrder(map,type,startTime,endTime);
@@ -220,8 +221,8 @@ public class DataService implements IDataService {
 
     @Override
     public HashMap<String, List<DataGroupByCount>> sceneTrend(Integer type,Integer dataType,String startTime,String endTime) {
-        startTime = Dateutils.formatStartTime(startTime,type);
-        endTime = Dateutils.formatEndTime(endTime,type);
+        startTime = Dateutils.formatStartTime(startTime);
+        endTime = Dateutils.formatEndTime(endTime);
 
         HashMap<String,List<DataGroupByCount>> map = new HashMap<>();
         List<DataGroupByCount> kkList = new ArrayList<>();
@@ -310,4 +311,62 @@ public class DataService implements IDataService {
             kkList.add(newCount);
         }
     }
+    private void setListData(List<DataGroupByCount> kkList, HashMap<String, Long> kkMap, List<String> dates) {
+        for (String key : dates) {
+            DataGroupByCount newCount = new DataGroupByCount();
+            newCount.setGroupKey(key);
+            Long count = kkMap.get(key) == null ? 0L : kkMap.get(key);
+            newCount.setCount(count);
+            kkList.add(newCount);
+        }
+    }
+
+    @Override
+    public HashMap<String, Object> cameraTrend(Integer type, String startTime, String endTime) {
+        startTime = Dateutils.formatStartTime(startTime);
+        endTime = Dateutils.formatEndTime(endTime);
+
+        HashMap<String,Object> map = new HashMap<>();
+        List<DataGroupByCount> allList = new ArrayList<>();
+        List<DataGroupByCount> kkList = new ArrayList<>();
+        List<DataGroupByCount> kjList = new ArrayList<>();
+        List<DataGroupByCount> ssList = new ArrayList<>();
+        int rule = Dateutils.DAY;
+        switch (type){
+            case 0 :
+                allList = dataMapper.sceneGroupBy("t_camera_detail",dayFormat,startTime,endTime);
+                break;
+            case 1 :
+                rule = Dateutils.WEEK;
+                allList = dataMapper.sceneGroupByWeek("t_camera_detail",startTime,endTime);
+                break;
+            case 2 :
+                rule = Dateutils.MONTH;
+                allList = dataMapper.sceneGroupBy("t_camera_detail",mouthFormat,startTime,endTime);
+                break;
+        }
+        HashMap<String, Long> kkMap = new HashMap<>();
+        HashMap<String, Long> kjMap = new HashMap<>();
+        HashMap<String, Long> ssMap = new HashMap<>();
+        for (DataGroupByCount dataGroupByCount : allList) {
+            if(dataGroupByCount.getGroupKey2().equals("9")){    //看见
+                kjMap.merge(dataGroupByCount.getGroupKey(),dataGroupByCount.getCount(), Long:: sum);
+            }
+            if(dataGroupByCount.getGroupKey2().equals("10")){    //深时
+                ssMap.merge(dataGroupByCount.getGroupKey(),dataGroupByCount.getCount(), Long:: sum);
+            }
+            if(Arrays.asList("0","1","2","5").contains(dataGroupByCount.getGroupKey2())){    //看看
+                kkMap.merge(dataGroupByCount.getGroupKey(),dataGroupByCount.getCount(), Long:: sum);
+            }
+        }
+        List<String> dates = Dateutils.findDatesStr(Dateutils.getDate(startTime), Dateutils.getDate(endTime),rule );
+        setListData(kkList,kkMap,dates);
+        setListData(kjList,kjMap,dates);
+        setListData(ssList,ssMap,dates);
+
+        map.put("kkList",kkList);
+        map.put("kjList",kjList);
+        map.put("ssList",ssList);
+        return map;
+    }
 }

+ 6 - 16
src/main/java/com/fdkankan/manage/util/Dateutils.java

@@ -117,31 +117,21 @@ public class Dateutils {
         return new SimpleDateFormat("yyyy-MM-dd").format(ca.getTime()) +" 23:59:59";
     }
 
-    public static String formatStartTime(String startTime,Integer type) {
+    public static String formatStartTime(String startTime) {
         if(StringUtils.isBlank(startTime)){
             startTime = Dateutils.getHalfYearStr();
-            if(type == 2){  //月,开始时间到1号 0点
-                Date date = Dateutils.getDate(startTime);
-                startTime =  Dateutils.getDate(Dateutils.getMonthDate( Dateutils.getMonthDate(date)));
-            }
-        }
-        if(type == 1){  //周,开始时间到周一 0点
-            Date date = Dateutils.getDate(startTime);
-            Date monday = Dateutils.getMonday(date);
-            startTime = Dateutils.getDayZeroDate(monday);
         }
-        if(type == 2 && startTime.length() <10 ){  //月,开始时间到1号 0点
-            Date date = Dateutils.getMonthDate(startTime);
-            startTime =  Dateutils.getDate(date);
+        if(startTime.length() <10 ){  //月,开始时间到1号 0点
+            startTime +=  "00:00:00";
         }
         return startTime;
     }
-    public static String formatEndTime(String endTime,Integer type) {
+    public static String formatEndTime(String endTime) {
         if(StringUtils.isBlank(endTime)){
             endTime = Dateutils.getDate(new Date());
         }
-        if(type == 2 && endTime.length() <10 ){  //月,开始时间到月最后一天 0点
-            endTime =  getLastMonTh(Dateutils.getDate(endTime));
+        if(endTime.length() <10 ){  //月,开始时间到1号 0点
+            endTime +=  "23:59:59";
         }
         return endTime;
     }

+ 22 - 4
src/main/resources/mapper/manage/DataMapper.xml

@@ -73,7 +73,13 @@
     </select>
 
     <select id="sceneGroupBy" resultType="com.fdkankan.manage.vo.response.DataGroupByCount">
-        SELECT DATE_FORMAT(create_time,#{dateFormat}) AS groupKey, count(id) AS count ,scene_source as groupKey2
+        SELECT DATE_FORMAT(create_time,#{dateFormat}) AS groupKey, count(id) AS count ,
+        <if test="tb == 't_scene_pro'">
+            scene_source as groupKey2
+        </if>
+        <if test="tb == 't_camera_detail'">
+            type as groupKey2
+        </if>
         FROM ${tb}
         WHERE rec_status = 'A'
           <if test="tb == 't_scene_pro'">
@@ -84,9 +90,21 @@
     </select>
 
     <select id="sceneGroupByWeek" resultType="com.fdkankan.manage.vo.response.DataGroupByCount">
-        SELECT groupKey ,scene_source as groupKey2,count(1) as count FROM (
-        select date_format(date_add(create_time,interval-(weekday(create_time ))day),'%Y-%m-%d')  as groupKey
-        ,scene_source
+        SELECT groupKey ,count(1) as count,
+        <if test="tb == 't_scene_pro'">
+            scene_source as groupKey2
+        </if>
+        <if test="tb == 't_camera_detail'">
+            type as groupKey2
+        </if>
+        FROM (
+        select date_format(date_add(create_time,interval-(weekday(create_time ))day),'%Y-%m-%d')  as groupKey,
+        <if test="tb == 't_scene_pro'">
+            scene_source
+        </if>
+        <if test="tb == 't_camera_detail'">
+            type
+        </if>
         from ${tb}
         WHERE rec_status = 'A'
         <if test="tb == 't_scene_pro'">