Bladeren bron

上传表格

yq 2 jaren geleden
bovenliggende
commit
ca0ee9a7c3

+ 26 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/DmpDataOverviewController.java

@@ -1,12 +1,19 @@
 package com.usky.iot.controller.web;
 
 
+import com.usky.common.core.bean.ApiResult;
+import com.usky.iot.domain.DmpDataOverview;
+import com.usky.iot.service.DmpDataOverviewService;
 import com.usky.iot.service.job.DmpDataOverviewJob;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Date;
+import java.util.List;
+
 /**
  * 数据概览
  *
@@ -20,9 +27,28 @@ public class DmpDataOverviewController {
     @Autowired
     private DmpDataOverviewJob dmpDataOverviewJob;
 
+    @Autowired
+    private DmpDataOverviewService dmpDataOverviewService;
+
     @GetMapping
     public void get(){
         dmpDataOverviewJob.execute();
     }
+
+    /**
+     * 集合
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @param productId 产品id
+     * @param type 类型1日2月
+     * @return
+     */
+    @GetMapping("/list")
+    public ApiResult<List<DmpDataOverview>> list(@RequestParam(required = false) Date startTime,
+                                      @RequestParam(required = false) Date endTime,
+                                      @RequestParam(required = false) Integer productId,
+                                      @RequestParam(required = false) Integer type){
+        return ApiResult.success(dmpDataOverviewService.list(startTime, endTime, productId, type));
+    }
 }
 

+ 12 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/DmpProductInfoController.java

@@ -11,6 +11,9 @@ import com.usky.iot.service.vo.DmpProductInfoRequest;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * 产品信息表
  *
@@ -72,6 +75,15 @@ public class DmpProductInfoController {
         return ApiResult.success();
     }
 
+    /**
+     * 汇总
+     * @return
+     */
+    @GetMapping("/collect")
+    public ApiResult<List<Map<String,Object>>> collect(){
+        return ApiResult.success(dmpProductInfoService.collect());
+    }
+
 
 
 

+ 6 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/mapper/DmpProductInfoMapper.java

@@ -3,6 +3,9 @@ package com.usky.iot.mapper;
 import com.usky.common.mybatis.core.CrudMapper;
 import com.usky.iot.domain.DmpProductInfo;
 
+import java.util.List;
+import java.util.Map;
+
 
 /**
  * <p>
@@ -14,4 +17,7 @@ import com.usky.iot.domain.DmpProductInfo;
  */
 public interface DmpProductInfoMapper extends CrudMapper<DmpProductInfo> {
 
+
+
+    List<Map<String,Object>> selectCollect();
 }

+ 5 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/DmpDataOverviewService.java

@@ -3,6 +3,9 @@ package com.usky.iot.service;
 import com.usky.iot.domain.DmpDataOverview;
 import com.usky.common.mybatis.core.CrudService;
 
+import java.util.Date;
+import java.util.List;
+
 /**
  * <p>
  * 数据概览 服务类
@@ -13,4 +16,6 @@ import com.usky.common.mybatis.core.CrudService;
  */
 public interface DmpDataOverviewService extends CrudService<DmpDataOverview> {
 
+    List<DmpDataOverview> list(Date startTime,Date endTime,Integer productId,Integer type);
+
 }

+ 5 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/DmpProductInfoService.java

@@ -5,6 +5,9 @@ import com.usky.common.mybatis.core.CrudService;
 import com.usky.iot.domain.DmpProductInfo;
 import com.usky.iot.service.vo.DmpProductInfoRequest;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * 产品信息表 服务类
@@ -25,4 +28,6 @@ public interface DmpProductInfoService extends CrudService<DmpProductInfo> {
     CommonPage<DmpProductInfo> page(DmpProductInfoRequest dmpProductInfoRequest);
 
     boolean remove(Integer id);
+
+    List<Map<String,Object>> collect();
 }

+ 15 - 3
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpDataOverviewServiceImpl.java

@@ -1,15 +1,18 @@
 package com.usky.iot.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.usky.iot.domain.DmpDataOverview;
 import com.usky.iot.mapper.DmpDataOverviewMapper;
 import com.usky.iot.service.DmpDataOverviewService;
 import com.usky.common.mybatis.core.AbstractCrudService;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
+import java.util.List;
+
 /**
- * <p>
- * 数据概览 服务实现类
- * </p>
+ * 数据概览
  *
  * @author ya
  * @since 2022-10-14
@@ -17,4 +20,13 @@ import org.springframework.stereotype.Service;
 @Service
 public class DmpDataOverviewServiceImpl extends AbstractCrudService<DmpDataOverviewMapper, DmpDataOverview> implements DmpDataOverviewService {
 
+
+    @Override
+    public List<DmpDataOverview> list(Date startTime, Date endTime, Integer productId, Integer type) {
+        LambdaQueryWrapper<DmpDataOverview> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.between(null != startTime && null != endTime,DmpDataOverview::getCreatedTime,startTime,endTime)
+                .eq(null != productId,DmpDataOverview::getProductId,productId)
+                .eq(null != type,DmpDataOverview::getCycleType,type);
+        return this.list(queryWrapper);
+    }
 }

+ 5 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpProductInfoServiceImpl.java

@@ -114,4 +114,9 @@ public class DmpProductInfoServiceImpl extends AbstractCrudService<DmpProductInf
         dmpProductInfo.setDeleteFlag(1);
         return this.updateById(dmpProductInfo);
     }
+
+    @Override
+    public List<Map<String, Object>> collect() {
+        return baseMapper.selectCollect();
+    }
 }

+ 21 - 11
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/job/DmpDataOverviewJob.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.usky.common.core.util.Arith;
 import com.usky.common.core.util.DateUtils;
 import com.usky.iot.domain.DmpDataOverview;
 import com.usky.iot.mapper.DmpDeviceStatusMapper;
@@ -47,6 +48,8 @@ public class DmpDataOverviewJob {
         //产品日
         List<DmpDataOverview> dmpDataOverviews = new ArrayList<>();
         List<DmpDataOverviewVO> list = getListMap(null, dayStartTime, dayEndTime);
+        //计算产品活跃占比
+        checkRadio(list);
         for (DmpDataOverviewVO dvo : list) {
             DmpDataOverview dmpDataOverview = new DmpDataOverview();
             dmpDataOverview.setCreatedTime(date3);
@@ -64,9 +67,14 @@ public class DmpDataOverviewJob {
                     .findFirst()
                     .ifPresent(hy -> dmpDataOverviewVO.setHyCount(hy.getHyCount()));
         }
+        //统计全部时间数据
+        List<DmpDataOverviewVO> allList = getListMap(null, null, null);
+        //计算占比
+        checkRadio(monthList);
+        //查看对应月份数据是否存在
         List<DmpDataOverview> listByTimeAndIds = getListByTimeAndIds(monthList, firstDayOfMonth,lastDayOfMonth);
         for (DmpDataOverviewVO dmpDataOverviewVO : monthList) {
-            listByTimeAndIds.stream()
+            DmpDataOverview dd = listByTimeAndIds.stream()
                     .filter(dm -> dmpDataOverviewVO.getProductId().equals(dm.getProductId()) && DateUtils.isSameDay(dm.getCreatedTime(),date4))
                     .findAny()
                     .map(dm -> {
@@ -82,20 +90,14 @@ public class DmpDataOverviewJob {
                         listByTimeAndIds.add(dmpDataOverview);
                         return dmpDataOverview;
                     });
+            allList.stream()
+                    .filter(dvo -> dvo.getProductId().equals(dd.getProductId()))
+                    .findAny()
+                    .ifPresent(dvo -> dd.setMiddleStatistic(JSON.toJSONString(dvo)));
         }
         dmpDataOverviewService.saveOrUpdateBatch(listByTimeAndIds);
     }
 
-
-    public static void main(String[] args) {
-        Date date = new Date();
-        Date date1 = DateUtils.setHours(date, 0);
-        Date date2 = DateUtils.setMinutes(date1, 0);
-        Date date3 = DateUtils.setSeconds(date2, 0);
-        Date date4 = DateUtils.setDays(date3, 1);
-        System.out.println(DateUtils.isSameDay(date4, date4));
-    }
-
     /**
      * 统计月信息
      * @param productIds
@@ -139,4 +141,12 @@ public class DmpDataOverviewJob {
     }
 
 
+    public void checkRadio(List<DmpDataOverviewVO> list){
+        list.forEach(dmpDataOverviewVO -> {
+            dmpDataOverviewVO.setJhRadioCount((null == dmpDataOverviewVO.getDeviceCount() || 0 == dmpDataOverviewVO.getDeviceCount())?0.00: Arith.div(dmpDataOverviewVO.getJhCount(),dmpDataOverviewVO.getDeviceCount()));
+            dmpDataOverviewVO.setHyRadioCount((null == dmpDataOverviewVO.getDeviceCount() || 0 == dmpDataOverviewVO.getDeviceCount())?0.00:Arith.div(dmpDataOverviewVO.getHyCount(),dmpDataOverviewVO.getDeviceCount()));
+        });
+    }
+
+
 }

+ 13 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/DmpDataOverviewVO.java

@@ -9,6 +9,11 @@ public class DmpDataOverviewVO {
      * 设备编号
      */
     private Integer productId;
+
+    /**
+     * 设备总数
+     */
+    private Integer deviceCount;
     /**
      * 活跃数
      */
@@ -30,4 +35,12 @@ public class DmpDataOverviewVO {
      * 离线数据
      */
     private Integer dlxCount;
+    /**
+     * 激活率
+     */
+    private Double jhRadioCount;
+    /**
+     * 活跃率
+     */
+    private Double hyRadioCount;
 }

+ 2 - 0
service-iot/service-iot-biz/src/main/resources/mapper/iot/DmpDeviceStatusMapper.xml

@@ -15,6 +15,7 @@
 
     <select id="getAllCollect" resultType="com.usky.iot.service.vo.DmpDataOverviewVO">
         select ddi.product_id as productId,
+        count(*) as deviceCount,
         COUNT(to_days(last_online_time) = to_days(now()) or null) as hyCount,
         count(service_status = 3 or null) as jhCount,
         count(service_status = 1 or null) as zcCount,
@@ -68,6 +69,7 @@
     </select>
     <select id="getDeviceStatusCollect" resultType="com.usky.iot.service.vo.DmpDataOverviewVO">
         select ddi.product_id as productId,
+        count(*) as deviceCount,
         COUNT(to_days(last_online_time) = to_days(now()) or null) as hyCount,
         count(service_status = 3 or null) as jhCount,
         count(service_status = 1 or null) as zcCount,

+ 8 - 0
service-iot/service-iot-biz/src/main/resources/mapper/iot/DmpProductInfoMapper.xml

@@ -27,5 +27,13 @@
         <result column="updated_time" property="updatedTime" />
         <result column="tenant_id" property="tenantId" />
     </resultMap>
+    <select id="selectCollect" resultType="java.util.Map">
+        select product_name as productName,count(*) as totalCount
+        from dmp_product as dp
+        inner join dmp_device as dd
+        on dp.id = dd.product_id
+        where dp.delete_flag = 0
+        group by product_name
+    </select>
 
 </mapper>