|
@@ -0,0 +1,86 @@
|
|
|
+package com.usky.iot.service.job;
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.usky.iot.domain.DmpDeviceInfo;
|
|
|
+import com.usky.iot.domain.DmpDeviceStatus;
|
|
|
+import com.usky.iot.service.DmpDataOverviewService;
|
|
|
+import com.usky.iot.service.DmpDeviceInfoService;
|
|
|
+import com.usky.iot.service.DmpDeviceStatusService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class DmpDataOverviewJob {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DmpDeviceInfoService dmpDeviceInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DmpDeviceStatusService dmpDeviceStatusService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DmpDataOverviewService dmpDataOverviewService;
|
|
|
+
|
|
|
+ public void execute(){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备量分析
|
|
|
+ */
|
|
|
+ public void deviceCount(){
|
|
|
+ //月活跃
|
|
|
+
|
|
|
+ List<Map<String, Object>> maps = deviceCount(null, null, null, "DATE(created_time)");
|
|
|
+ List<Map<String, Object>> maps1 = deviceStatusCount(null, null, null);
|
|
|
+ maps.forEach(s -> {
|
|
|
+ s.put("dayCount",0);
|
|
|
+ s.put("serviceCount",0);
|
|
|
+ maps1.stream()
|
|
|
+ .filter(s1 -> s1.get("productId").toString().equals(s.get("productId").toString()))
|
|
|
+ .findAny()
|
|
|
+ .ifPresent(s2 -> {
|
|
|
+ s.putAll(s2);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备总数
|
|
|
+ * @param productId
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Map<String, Object>> deviceCount(Integer productId, Date startTime, Date endTime,String reportDate){
|
|
|
+ QueryWrapper<DmpDeviceInfo> query = Wrappers.query();
|
|
|
+ query.select(reportDate + " as time","product_id as productId","count(*) as deviceCount")
|
|
|
+ .eq(null != productId,"product_id",productId)
|
|
|
+ .between(null != startTime && null != endTime,"created_time",startTime,endTime)
|
|
|
+ .groupBy("productId","time");
|
|
|
+ return dmpDeviceInfoService.listMaps(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统计产品日活跃数
|
|
|
+ * @param productId
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Map<String, Object>> deviceStatusCount(Integer productId, Date startTime, Date endTime){
|
|
|
+ QueryWrapper<DmpDeviceStatus> query = Wrappers.query();
|
|
|
+ query.select("product_id as productId","COUNT(to_days(last_online_time) = to_days(now())) as dayCount","count(service_status = 3 or null) as serviceCount")
|
|
|
+ .eq(null != productId,"product_id",productId)
|
|
|
+ .between(null != startTime && null != endTime,"last_online_time",startTime,endTime)
|
|
|
+ .groupBy("productId");
|
|
|
+ return dmpDeviceStatusService.listMaps(query);
|
|
|
+ }
|
|
|
+}
|