yq 3 gadi atpakaļ
vecāks
revīzija
4785f5407d
18 mainītis faili ar 371 papildinājumiem un 40 dzēšanām
  1. 26 7
      mhfire-controller/src/main/java/com/bizmatics/mhfire/controller/web/DeviceAjController.java
  2. 4 7
      mhfire-controller/src/main/java/com/bizmatics/mhfire/controller/web/DeviceAlertController.java
  3. 51 5
      mhfire-controller/src/main/java/com/bizmatics/mhfire/controller/web/DeviceController.java
  4. 26 6
      mhfire-controller/src/main/java/com/bizmatics/mhfire/controller/web/DeviceInfoController.java
  5. 9 1
      mhfire-mapping/src/main/java/com/bizmatics/mhfire/persistence/mapper/DeviceMapper.java
  6. 52 0
      mhfire-mapping/src/main/java/com/bizmatics/mhfire/persistence/mapper/vo/DeviceCollectVO.java
  7. 41 0
      mhfire-mapping/src/main/resources/mapper/mysql/DeviceMapper.xml
  8. 3 2
      mhfire-model/src/main/java/com/bizmatics/mhfire/model/Device.java
  9. 7 2
      mhfire-model/src/main/java/com/bizmatics/mhfire/model/DeviceAj.java
  10. 7 3
      mhfire-model/src/main/java/com/bizmatics/mhfire/model/DeviceAlert.java
  11. 7 2
      mhfire-model/src/main/java/com/bizmatics/mhfire/model/DeviceInfo.java
  12. 9 1
      mhfire-service/src/main/java/com/bizmatics/mhfire/service/DeviceAjService.java
  13. 14 0
      mhfire-service/src/main/java/com/bizmatics/mhfire/service/DeviceInfoService.java
  14. 19 1
      mhfire-service/src/main/java/com/bizmatics/mhfire/service/DeviceService.java
  15. 12 1
      mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/DeviceAjServiceImpl.java
  16. 37 1
      mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/DeviceInfoServiceImpl.java
  17. 24 1
      mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/DeviceServiceImpl.java
  18. 23 0
      mhfire-service/src/main/java/com/bizmatics/mhfire/service/vo/DeviceMapVO.java

+ 26 - 7
mhfire-controller/src/main/java/com/bizmatics/mhfire/controller/web/DeviceAjController.java

@@ -1,21 +1,40 @@
 package com.bizmatics.mhfire.controller.web;
 
 
+import com.bizmatics.common.core.bean.ApiResult;
+import com.bizmatics.common.core.bean.CommonPage;
+import com.bizmatics.mhfire.model.DeviceAj;
+import com.bizmatics.mhfire.service.DeviceAjService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 设备案件 前端控制器
- * </p>
- *
+
+ * 设备案件
  * @author ya
  * @since 2021-11-25
  */
-@Controller
+@RestController
 @RequestMapping("/deviceAj")
 public class DeviceAjController {
 
+
+    @Autowired
+    public DeviceAjService deviceAjService;
+
+
+    /**
+     * 分页
+     * @param deviceType 设备类型
+     * @param current 页数
+     * @param size 条数
+     * @return
+     */
+    @GetMapping("/page")
+    public ApiResult<CommonPage<DeviceAj>> page(String deviceType,Integer current,Integer size){
+        return ApiResult.success(deviceAjService.page(deviceType,current,size));
+    }
 }
 

+ 4 - 7
mhfire-controller/src/main/java/com/bizmatics/mhfire/controller/web/DeviceAlertController.java

@@ -2,18 +2,15 @@ package com.bizmatics.mhfire.controller.web;
 
 
 import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RestController;
 
 /**
- * <p>
- * 设备告警 前端控制器
- * </p>
- *
+
+ * 设备告警
  * @author ya
  * @since 2021-11-25
  */
-@Controller
+@RestController
 @RequestMapping("/deviceAlert")
 public class DeviceAlertController {
 

+ 51 - 5
mhfire-controller/src/main/java/com/bizmatics/mhfire/controller/web/DeviceController.java

@@ -1,21 +1,67 @@
 package com.bizmatics.mhfire.controller.web;
 
 
+import com.bizmatics.common.core.bean.ApiResult;
+import com.bizmatics.common.core.bean.CommonPage;
+import com.bizmatics.mhfire.model.Device;
+import com.bizmatics.mhfire.persistence.mapper.vo.DeviceCollectVO;
+import com.bizmatics.mhfire.service.DeviceService;
+import com.bizmatics.mhfire.service.vo.DeviceMapVO;
+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.RestController;
 
-import org.springframework.stereotype.Controller;
+import java.util.List;
 
 /**
- * <p>
- * 设备信息表 前端控制器
- * </p>
  *
+ * 设备信息表
  * @author ya
  * @since 2021-11-25
  */
-@Controller
+@RestController
 @RequestMapping("/device")
 public class DeviceController {
 
+
+    @Autowired
+    public DeviceService deviceService;
+
+
+
+    /**
+     * 地图撒点
+     * @return
+     */
+    @GetMapping("/mapList")
+    public ApiResult<List<DeviceMapVO>> getMapList(){
+        return ApiResult.success(deviceService.getMapList());
+    }
+
+
+    /**
+     * 设备类型统计信息
+     * @param current 页数
+     * @param size 条数
+     * @param deviceType 设备类型
+     * @param deviceCode 设备编码
+     * @return
+     */
+    @GetMapping("collect")
+    public ApiResult<CommonPage<DeviceCollectVO>> getCollect(Integer current, Integer size, String deviceType, String deviceCode){
+        return ApiResult.success(deviceService.getCollect(current,size,deviceType,deviceCode));
+    }
+
+    /**
+     * 查看设备详情
+     * @param id 主键id
+     * @return
+     */
+    @GetMapping("/one")
+    public ApiResult<Device> one(Long id){
+        return ApiResult.success(deviceService.getById(id));
+    }
+
 }
 

+ 26 - 6
mhfire-controller/src/main/java/com/bizmatics/mhfire/controller/web/DeviceInfoController.java

@@ -1,21 +1,41 @@
 package com.bizmatics.mhfire.controller.web;
 
 
+import com.bizmatics.common.core.bean.ApiResult;
+import com.bizmatics.mhfire.service.DeviceInfoService;
+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.RestController;
 
-import org.springframework.stereotype.Controller;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 /**
- * <p>
- * 设备心跳 前端控制器
- * </p>
- *
+
+ *设备心跳
  * @author ya
  * @since 2021-11-25
  */
-@Controller
+@RestController
 @RequestMapping("/deviceInfo")
 public class DeviceInfoController {
 
+    @Autowired
+    public DeviceInfoService deviceInfoService;
+
+
+    /**
+     * 电量趋势
+     * @param deviceCode 设备编号
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @return
+     */
+    @GetMapping("/elIco")
+    public ApiResult<List<Map<String,Object>>> elIco(String deviceCode, Date startTime, Date endTime){
+        return ApiResult.success(deviceInfoService.elIco(deviceCode,startTime,endTime));
+    }
 }
 

+ 9 - 1
mhfire-mapping/src/main/java/com/bizmatics/mhfire/persistence/mapper/DeviceMapper.java

@@ -1,7 +1,11 @@
 package com.bizmatics.mhfire.persistence.mapper;
 
-import com.bizmatics.mhfire.model.Device;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.bizmatics.common.mvc.base.CrudMapper;
+import com.bizmatics.mhfire.model.Device;
+import com.bizmatics.mhfire.persistence.mapper.vo.DeviceCollectVO;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * <p>
@@ -13,4 +17,8 @@ import com.bizmatics.common.mvc.base.CrudMapper;
  */
 public interface DeviceMapper extends CrudMapper<Device> {
 
+
+    Page<DeviceCollectVO> selectCollect(IPage<DeviceCollectVO> page,
+                                        @Param("deviceType") String deviceType,
+                                        @Param("deviceCode") String deviceCode);
 }

+ 52 - 0
mhfire-mapping/src/main/java/com/bizmatics/mhfire/persistence/mapper/vo/DeviceCollectVO.java

@@ -0,0 +1,52 @@
+package com.bizmatics.mhfire.persistence.mapper.vo;
+
+import lombok.Data;
+
+/**
+ * 设备汇总信息
+ * @author yq
+ * @date 2021/11/25 15:50
+ */
+@Data
+public class DeviceCollectVO {
+    /**
+     * 设备类型
+     */
+    private String deviceType;
+    /**
+     * 设备总数
+     */
+    private Integer deviceCount;
+    /**
+     * 告警数
+     */
+    private Integer alertCount;
+    /**
+     * 离线数
+     */
+    private Integer lineCount;
+    /**
+     * 离线率
+     */
+    private Double lineRate;
+    /**
+     * 告警率
+     */
+    private Double alertRate;
+
+    /**
+     * 上线率
+     */
+    private Double onRate;
+
+    /**
+     * 接单率
+     */
+    private Double taskOrderRate;
+    /**
+     * 处置率
+     */
+    private Double checkRate;
+
+
+}

+ 41 - 0
mhfire-mapping/src/main/resources/mapper/mysql/DeviceMapper.xml

@@ -19,5 +19,46 @@
         <result column="device_duty" property="deviceDuty" />
         <result column="property" property="property" />
     </resultMap>
+    <select id="selectCollect" resultType="com.bizmatics.mhfire.persistence.mapper.vo.DeviceCollectVO">
+        select d.device_type as deviceType,count(d.id) as deviceCount,count(da.id) as alertCount,
+        count(if(d.device_flag = 1, 1, null)) as lineCount,
+        (
+        select
+        ROUND(COUNT(CASE WHEN dd.device_flag=1 THEN dd.device_flag END)/COUNT(*),2) AS rate_a
+        FROM device as dd
+        where dd.device_type = d.device_type
+        ) as lineRate,
+
+        (
+        select
+        ROUND(COUNT(CASE WHEN dan.id != null THEN dan.id END)/COUNT(*),2) AS rate_a
+        FROM device as dd
+        left join device_alert as dan
+        on dd.`code` = dan.device_code
+        where dd.device_type = d.device_type
+        ) as alertRate,
+
+        (
+        select
+        ROUND(COUNT(CASE WHEN dan.aj_flag=3 THEN dan.aj_flag END)/COUNT(*),2)
+        FROM device_aj as dan
+        where dan.device_type = d.device_type
+        ) as checkRate
+
+        from device as d
+        left join device_alert as da
+        on d.code = da.device_code
+        left join device_aj as aj
+        on d.code = aj.device_code
+        <where>
+            <if test="deviceType != null and deviceType != ''">
+                and d.device_type = #{deviceType}
+            </if>
+            <if test="deviceCode != null and deviceCode != ''">
+                and d.code = #{deviceCode}
+            </if>
+        </where>
+        GROUP BY d.device_type
+    </select>
 
 </mapper>

+ 3 - 2
mhfire-model/src/main/java/com/bizmatics/mhfire/model/Device.java

@@ -1,11 +1,12 @@
 package com.bizmatics.mhfire.model;
 
-import java.time.LocalDateTime;
-import java.io.Serializable;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
 /**
  * <p>
  * 设备信息表

+ 7 - 2
mhfire-model/src/main/java/com/bizmatics/mhfire/model/DeviceAj.java

@@ -1,11 +1,12 @@
 package com.bizmatics.mhfire.model;
 
-import java.time.LocalDateTime;
-import java.io.Serializable;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
 /**
  * <p>
  * 设备案件
@@ -106,5 +107,9 @@ public class DeviceAj implements Serializable {
      */
     private String chargePhone;
 
+    /**
+     * 设备类型
+      */
+    private String deviceType;
 
 }

+ 7 - 3
mhfire-model/src/main/java/com/bizmatics/mhfire/model/DeviceAlert.java

@@ -1,11 +1,12 @@
 package com.bizmatics.mhfire.model;
 
-import java.time.LocalDateTime;
-import java.io.Serializable;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
 /**
  * <p>
  * 设备告警
@@ -65,5 +66,8 @@ public class DeviceAlert implements Serializable {
 
     private Integer delFlag;
 
-
+    /**
+     * 剩余电量
+     */
+    private Double electric;
 }

+ 7 - 2
mhfire-model/src/main/java/com/bizmatics/mhfire/model/DeviceInfo.java

@@ -1,11 +1,12 @@
 package com.bizmatics.mhfire.model;
 
-import java.time.LocalDateTime;
-import java.io.Serializable;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
 /**
  * <p>
  * 设备心跳
@@ -64,6 +65,10 @@ public class DeviceInfo implements Serializable {
     private String sendContent;
 
     private Integer delFlag;
+    /**
+     * 剩余电量
+     */
+    private Double electric;
 
 
 }

+ 9 - 1
mhfire-service/src/main/java/com/bizmatics/mhfire/service/DeviceAjService.java

@@ -1,7 +1,8 @@
 package com.bizmatics.mhfire.service;
 
-import com.bizmatics.mhfire.model.DeviceAj;
+import com.bizmatics.common.core.bean.CommonPage;
 import com.bizmatics.common.mvc.base.CrudService;
+import com.bizmatics.mhfire.model.DeviceAj;
 
 /**
  * <p>
@@ -13,4 +14,11 @@ import com.bizmatics.common.mvc.base.CrudService;
  */
 public interface DeviceAjService extends CrudService<DeviceAj> {
 
+    /**
+     * 分页
+      * @param current 页数
+     * @param size 条数
+     * @return
+     */
+    CommonPage<DeviceAj> page(String deviceType,Integer current,Integer size);
 }

+ 14 - 0
mhfire-service/src/main/java/com/bizmatics/mhfire/service/DeviceInfoService.java

@@ -3,6 +3,10 @@ package com.bizmatics.mhfire.service;
 import com.bizmatics.mhfire.model.DeviceInfo;
 import com.bizmatics.common.mvc.base.CrudService;
 
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * 设备心跳 服务类
@@ -13,4 +17,14 @@ import com.bizmatics.common.mvc.base.CrudService;
  */
 public interface DeviceInfoService extends CrudService<DeviceInfo> {
 
+
+    /**
+     * 电量趋势
+     * @param deviceCode 设备编号
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @return
+     */
+    List<Map<String,Object>> elIco(String deviceCode, Date startTime,Date endTime);
+
 }

+ 19 - 1
mhfire-service/src/main/java/com/bizmatics/mhfire/service/DeviceService.java

@@ -1,7 +1,12 @@
 package com.bizmatics.mhfire.service;
 
-import com.bizmatics.mhfire.model.Device;
+import com.bizmatics.common.core.bean.CommonPage;
 import com.bizmatics.common.mvc.base.CrudService;
+import com.bizmatics.mhfire.model.Device;
+import com.bizmatics.mhfire.persistence.mapper.vo.DeviceCollectVO;
+import com.bizmatics.mhfire.service.vo.DeviceMapVO;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +18,17 @@ import com.bizmatics.common.mvc.base.CrudService;
  */
 public interface DeviceService extends CrudService<Device> {
 
+
+    /**
+     * 地图撒点
+      * @return
+     */
+    List<DeviceMapVO> getMapList();
+
+
+    /**
+     * 设备汇总信息
+     * @return
+     */
+    CommonPage<DeviceCollectVO> getCollect(Integer current, Integer size, String deviceType, String deviceCode);
 }

+ 12 - 1
mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/DeviceAjServiceImpl.java

@@ -1,9 +1,13 @@
 package com.bizmatics.mhfire.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.bizmatics.common.core.bean.CommonPage;
+import com.bizmatics.common.mvc.base.AbstractCrudService;
 import com.bizmatics.mhfire.model.DeviceAj;
 import com.bizmatics.mhfire.persistence.mapper.DeviceAjMapper;
 import com.bizmatics.mhfire.service.DeviceAjService;
-import com.bizmatics.common.mvc.base.AbstractCrudService;
 import org.springframework.stereotype.Service;
 
 /**
@@ -17,4 +21,11 @@ import org.springframework.stereotype.Service;
 @Service
 public class DeviceAjServiceImpl extends AbstractCrudService<DeviceAjMapper, DeviceAj> implements DeviceAjService {
 
+    @Override
+    public CommonPage<DeviceAj> page(String deviceType,Integer current, Integer size) {
+        LambdaQueryWrapper<DeviceAj> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(DeviceAj::getDeviceType,deviceType);
+        Page<DeviceAj> page = new Page<>(current, size);
+        return this.ToCommonPage(this.page(page,queryWrapper));
+    }
 }

+ 37 - 1
mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/DeviceInfoServiceImpl.java

@@ -1,11 +1,15 @@
 package com.bizmatics.mhfire.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.bizmatics.common.mvc.base.AbstractCrudService;
 import com.bizmatics.mhfire.model.DeviceInfo;
 import com.bizmatics.mhfire.persistence.mapper.DeviceInfoMapper;
 import com.bizmatics.mhfire.service.DeviceInfoService;
-import com.bizmatics.common.mvc.base.AbstractCrudService;
 import org.springframework.stereotype.Service;
 
+import java.util.*;
+import java.util.stream.Collectors;
+
 /**
  * <p>
  * 设备心跳 服务实现类
@@ -17,4 +21,36 @@ import org.springframework.stereotype.Service;
 @Service
 public class DeviceInfoServiceImpl extends AbstractCrudService<DeviceInfoMapper, DeviceInfo> implements DeviceInfoService {
 
+    @Override
+    public List<Map<String, Object>> elIco(String deviceCode, Date startTime, Date endTime) {
+        QueryWrapper<DeviceInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("HOUR(lasj) createTime","sum(electric) as elCount")
+                .between("create_time",startTime,endTime)
+                .eq("device_code",deviceCode)
+                .groupBy("createTime");
+        List<Map<String, Object>> list = this.listMaps(queryWrapper);
+        perfectDate(list,24,0);
+        list = list.stream()
+                .sorted(Comparator.comparing(map -> Integer.valueOf(map.get("createTime").toString())))
+                .collect(Collectors.toList());
+        return list;
+    }
+
+
+
+    public void perfectDate(List<Map<String,Object>> list,Integer times,Integer defaultTime){
+        for (int i = defaultTime; i < times; i++) {
+            int finalI = i;
+            list.stream()
+                    .filter(parkDTO -> Integer.parseInt(parkDTO.get("createTime").toString()) == finalI)
+                    .findFirst()
+                    .orElseGet(() -> {
+                        Map<String,Object> map  = new HashMap<>();
+                        map.put("elCount",0);
+                        map.put("createTime",finalI);
+                        list.add(map);
+                        return map;
+                    });
+        }
+    }
 }

+ 24 - 1
mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/DeviceServiceImpl.java

@@ -1,11 +1,20 @@
 package com.bizmatics.mhfire.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.bizmatics.common.core.bean.CommonPage;
+import com.bizmatics.common.core.util.BeanMapperUtils;
+import com.bizmatics.common.mvc.base.AbstractCrudService;
 import com.bizmatics.mhfire.model.Device;
 import com.bizmatics.mhfire.persistence.mapper.DeviceMapper;
+import com.bizmatics.mhfire.persistence.mapper.vo.DeviceCollectVO;
 import com.bizmatics.mhfire.service.DeviceService;
-import com.bizmatics.common.mvc.base.AbstractCrudService;
+import com.bizmatics.mhfire.service.vo.DeviceMapVO;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  * 设备信息表 服务实现类
@@ -17,4 +26,18 @@ import org.springframework.stereotype.Service;
 @Service
 public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device> implements DeviceService {
 
+    @Override
+    public List<DeviceMapVO> getMapList() {
+        LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.select(Device::getId,Device::getLatitude,Device::getLongitude);
+        List<Device> list = this.list(queryWrapper);
+        return BeanMapperUtils.mapList(list,Device.class,DeviceMapVO.class);
+    }
+
+    @Override
+    public CommonPage<DeviceCollectVO> getCollect(Integer current, Integer size, String deviceType, String deviceCode) {
+        Page<DeviceCollectVO> page = new Page<>(current, size);
+        page = baseMapper.selectCollect(page,deviceType,deviceCode);
+        return new CommonPage<>(page.getRecords(),page.getTotal(),page.getSize(),page.getCurrent());
+    }
 }

+ 23 - 0
mhfire-service/src/main/java/com/bizmatics/mhfire/service/vo/DeviceMapVO.java

@@ -0,0 +1,23 @@
+package com.bizmatics.mhfire.service.vo;
+
+import lombok.Data;
+
+/**
+ * @author yq
+ * @date 2021/11/25 15:26
+ */
+@Data
+public class DeviceMapVO {
+    /**
+     * 精度
+     */
+    private String longitude;
+    /**
+     * 维度
+     */
+    private String latitude;
+    /**
+     * id
+     */
+    private Long id;
+}