Explorar o código

Merge branch 'master' into prod

李进 hai 1 ano
pai
achega
638b2ed904

+ 11 - 0
device-api-service/src/main/java/com/xy/mapper/DeviceNetRecordMapper.java

@@ -1,8 +1,11 @@
 package com.xy.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.xy.dto.DeviceNetRecordDto;
 import com.xy.entity.DeviceNetRecord;
 
+import java.util.List;
+
 /**
  * <p>
  * 机器-联网记录 Mapper 接口
@@ -13,4 +16,12 @@ import com.xy.entity.DeviceNetRecord;
  */
 public interface DeviceNetRecordMapper extends BaseMapper<DeviceNetRecord> {
 
+    /**
+     * 离线设备列表
+     *
+     * @param offLineDevice
+     * @return
+     */
+    List<DeviceNetRecordDto.OffLineDeviceVo> offLineDevice(DeviceNetRecordDto.OffLineDevice offLineDevice);
+
 }

+ 27 - 0
device-api-service/src/main/java/com/xy/mapper/mapper/DeviceNetRecordMapper.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.xy.mapper.DeviceNetRecordMapper">
+
+    <!-- 离线设备列表 -->
+    <select id="offLineDevice" resultType="com.xy.dto.DeviceNetRecordDto$OffLineDeviceVo">
+        SELECT nd.device_id deviceId, nd.create_time createTime, di.device_name deviceName, di.merc_id mercId, di.merc_name mercName FROM (
+        SELECT a.device_id, a.create_time
+        FROM (
+                SELECT device_id, MAX(create_time) AS create_time
+                FROM device_net_record
+                WHERE net_status = 2 and create_time >= #{beginTime} and create_time &lt;= #{endTime}
+                GROUP BY device_id
+        ) a
+        LEFT JOIN (
+                SELECT device_id
+                FROM device_net_record
+                WHERE net_status = 1 and create_time >= #{beginTime} and create_time &lt;= #{endTime}
+                GROUP BY device_id
+        ) b ON a.device_id = b.device_id
+        WHERE b.device_id IS NULL
+        ORDER BY a.create_time DESC
+    ) nd
+    join device_info di on(nd.device_id = di.device_id)
+    </select>
+
+</mapper>

+ 67 - 22
device-api-service/src/main/java/com/xy/service/DeviceAlgorithmChargingServiceImpl.java

@@ -17,7 +17,10 @@ import com.xy.device.EnumDeviceAlgorithmChargingType;
 import com.xy.device.EnumDeviceType;
 import com.xy.dto.*;
 import com.xy.dto.be.MercDto;
-import com.xy.entity.*;
+import com.xy.entity.DeviceAlgorithmCharging;
+import com.xy.entity.DeviceAlgorithmChargingHistory;
+import com.xy.entity.DeviceInfo;
+import com.xy.entity.SysDictRedis;
 import com.xy.mapper.DeviceAlgorithmChargingMapper;
 import com.xy.mapper.entity.DeviceAlgorithmChargingChargingQueryParams;
 import com.xy.service.be.MercService;
@@ -32,7 +35,6 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 
-import javax.validation.constraints.NotEmpty;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
@@ -65,42 +67,85 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
 
     private AlipayDeviceService alipayDeviceService;
 
+    private MercDeviceAlgorithmChargingService mercDeviceAlgorithmChargingService;
+
     @PostMapping("count")
     @ApiOperation("查询条数")
     public R<List<DeviceAlgorithmChargingDto.CountVo>> count(@RequestBody @Validated DeviceAlgorithmChargingDto.Count count) {
+        MercDto.Vo merc = mercService.obj(new MercDto.Vo().setId(count.getMercId())).getData();
         //默认值
-        List<Long> deviceIds = count.getDeviceIds();
+        JList<Long> deviceIds = new JArrayList<>(count.getDeviceIds());
         JList<DeviceAlgorithmChargingDto.CountVo> countVos = new JArrayList<>(deviceIds.size());
         deviceIds.forEach(deviceId -> {
             DeviceAlgorithmChargingDto.CountVo countVo = new DeviceAlgorithmChargingDto.CountVo()
                     .setDeviceId(deviceId)
-                    .setCount(0)
-                    .setSize(0)
+                    .setUnusedCount(0)
+                    .setUnusedSize(0)
+                    .setMakeSize(0)
                     .setArrearageBalance(0);
             countVos.add(countVo);
         });
         JMap<Long, DeviceAlgorithmChargingDto.CountVo> cover = countVos.toMap(DeviceAlgorithmChargingDto.CountVo::getDeviceId).cover();
-        //查询数据
+        //查询全部
+        JList<JList<Long>> partition = deviceIds.partition(100);
+        JList<DeviceAlgorithmCharging> deviceAlgorithmChargings = new JArrayList<>();
+        partition.forEach(longs -> {
+            List<DeviceAlgorithmCharging> list = list(new LambdaQueryWrapper<DeviceAlgorithmCharging>()
+                    .select(DeviceAlgorithmCharging::getDeviceId, DeviceAlgorithmCharging::getMakeSize, DeviceAlgorithmCharging::getUnusedSize, DeviceAlgorithmCharging::getTimeout, DeviceAlgorithmCharging::getBeginTime)
+                    .in(DeviceAlgorithmCharging::getDeviceId, longs)
+                    .eq(DeviceAlgorithmCharging::getMercCode, merc.getMercCode())
+            );
+            deviceAlgorithmChargings.addAll(list);
+        });
+        JMap<Long, List<DeviceAlgorithmCharging>> allGroup = deviceAlgorithmChargings.toMap(DeviceAlgorithmCharging::getDeviceId).group();
+        //查询未使用
         String thisTime = DataTime.getSring("yyyyMMdd");
-        List<DeviceAlgorithmCharging> list = list(new LambdaQueryWrapper<DeviceAlgorithmCharging>()
-                .in(DeviceAlgorithmCharging::getDeviceId, deviceIds)
+        JList<DeviceAlgorithmCharging> unuseds = deviceAlgorithmChargings.filter()
                 .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
-                .and(deviceAlgorithmChargingLambdaQueryWrapper -> deviceAlgorithmChargingLambdaQueryWrapper
-                        .eq(DeviceAlgorithmCharging::getTimeout, -1)
-                        .or()
-                        .ge(DeviceAlgorithmCharging::getTimeout, thisTime)
-                )
+                .eq(DeviceAlgorithmCharging::getTimeout, -1)
                 .le(DeviceAlgorithmCharging::getBeginTime, thisTime)
-        );
-        JMap<Long, List<DeviceAlgorithmCharging>> group = new JArrayList<>(list).toMap(DeviceAlgorithmCharging::getDeviceId).group();
-        group.forEach((deviceId, deviceAlgorithmChargings) -> {
-            DeviceAlgorithmChargingDto.CountVo countVo = cover.get(deviceId);
-            countVo.setCount(deviceAlgorithmChargings.size());
-            int size = 0;
-            for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings) {
-                size += deviceAlgorithmCharging.getUnusedSize();
+                .list();
+        JList<DeviceAlgorithmCharging> unuseds2 = deviceAlgorithmChargings.filter()
+                .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
+                .ge(DeviceAlgorithmCharging::getTimeout, thisTime)
+                .le(DeviceAlgorithmCharging::getBeginTime, thisTime)
+                .list();
+        if (Emptys.check(unuseds2)) {
+            unuseds.addAll(unuseds2);
+        }
+        JMap<Long, List<DeviceAlgorithmCharging>> unusedGroup = unuseds.toMap(DeviceAlgorithmCharging::getDeviceId).group();
+        //统计设备欠费金额
+        List<MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo> countArrearageBalanceVos = mercDeviceAlgorithmChargingService.countArrearageBalance(new MercDeviceAlgorithmChargingDto.CountArrearageBalance()
+                .setDeviceIds(deviceIds)
+                .setMercId(merc.getId())
+        ).getData();
+        JMap<Long, MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo> countArrearageBalanceVosJMaps = new JArrayList<>(countArrearageBalanceVos).toMap(MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo::getDeviceId).cover();
+        //封装数据
+        cover.forEach((deviceId, countVo) -> {
+            //未使用
+            List<DeviceAlgorithmCharging> deviceAlgorithmChargings1 = unusedGroup.get(deviceId);
+            if (Emptys.check(deviceAlgorithmChargings1)) {
+                countVo.setUnusedCount(deviceAlgorithmChargings1.size());
+                int unusedSize = 0;
+                for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings1) {
+                    unusedSize += deviceAlgorithmCharging.getUnusedSize();
+                }
+                countVo.setUnusedSize(unusedSize);
+            }
+            //已使用
+            List<DeviceAlgorithmCharging> deviceAlgorithmChargings2 = allGroup.get(deviceId);
+            if (Emptys.check(deviceAlgorithmChargings2)) {
+                int makeSize = 0;
+                for (DeviceAlgorithmCharging deviceAlgorithmCharging : deviceAlgorithmChargings2) {
+                    makeSize += deviceAlgorithmCharging.getMakeSize();
+                }
+                countVo.setMakeSize(makeSize);
+            }
+            //欠费金额
+            MercDeviceAlgorithmChargingDto.CountArrearageBalanceVo countArrearageBalanceVo = countArrearageBalanceVosJMaps.get(deviceId);
+            if (Emptys.check(countArrearageBalanceVo)) {
+                countVo.setArrearageBalance(countArrearageBalanceVo.getArrearageBalance());
             }
-            countVo.setSize(size);
         });
         return R.ok(countVos);
     }

+ 11 - 18
device-api-service/src/main/java/com/xy/service/DeviceChargingServiceImpl.java

@@ -32,6 +32,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static com.xy.utils.Beans.copy;
 import static com.xy.utils.PlusBeans.toIPage;
 import static com.xy.utils.PlusBeans.toPageBean;
 
@@ -66,24 +67,6 @@ public class DeviceChargingServiceImpl extends ServiceImpl<DeviceChargingMapper,
 
     private AlipayDeviceService alipayDeviceService;
 
-    @PostMapping("init")
-    @ApiOperation("初始化")
-    public R init() {
-        String timeout = DataTime.getStringAround(0, 0, 365, 0, 0, 0);
-        LocalDateTime localDateTime = LocalDateTime.now();
-        List<DeviceInfo> list = deviceInfoService.list(new LambdaQueryWrapper<DeviceInfo>().eq(DeviceInfo::getActiveState, 1));
-        List<DeviceCharging> deviceChargings = new ArrayList<>(list.size());
-        for (DeviceInfo deviceInfo : list) {
-            DeviceCharging deviceCharging = new DeviceCharging()
-                    .setDeviceId(deviceInfo.getDeviceId())
-                    .setTimeout(DataTime.toLocal(timeout))
-                    .setCreateTime(localDateTime);
-            deviceChargings.add(deviceCharging);
-        }
-        saveBatch(deviceChargings);
-        return R.ok();
-    }
-
     @PostMapping("del")
     @ApiOperation("删除")
     public R del(@RequestBody @Validated DeviceChargingDto.Del del) {
@@ -400,4 +383,14 @@ public class DeviceChargingServiceImpl extends ServiceImpl<DeviceChargingMapper,
         }
         return R.ok();
     }
+
+    @Override
+    @ApiOperation("集合查询")
+    public R<List<DeviceChargingDto.Vo>> list(DeviceChargingDto.SelectList selectList) {
+        LambdaQueryWrapper<DeviceCharging> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceCharging>()
+                .in(DeviceCharging::getDeviceId, selectList.getDeviceIds());
+        List<DeviceCharging> list = list(lambdaQueryWrapper);
+        List<DeviceChargingDto.Vo> copy = copy(DeviceChargingDto.Vo.class, list);
+        return R.ok(copy);
+    }
 }

+ 7 - 5
device-api-service/src/main/java/com/xy/service/DeviceInfoServiceImpl.java

@@ -112,8 +112,8 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
         return R.ok(baseMapper.placeDeviceNum(dto));
     }
 
+    @Override
     @ApiOperation("设备列表带卡包数")
-    @PostMapping("algorithmChargingDevice")
     public R<PageBean<DeviceInfoDto.AlgorithmChargingVo>> algorithmChargingDevice(@RequestBody @Validated DeviceInfoDto.AlgorithmCharging algorithmCharging) {
         PageBean pageBean = algorithmCharging.getPage();
         //查询设备
@@ -121,6 +121,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
         LambdaUpdateWrapper<DeviceInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper<DeviceInfo>()
                 .eq(DeviceInfo::getMercId, algorithmCharging.getMercId())
                 .eq(DeviceInfo::getActiveState, value)
+                .in(Emptys.check(algorithmCharging.getDeviceIds()), DeviceInfo::getDeviceId, algorithmCharging.getDeviceIds())
                 .orderByDesc(DeviceInfo::getCreateTime);
         IPage<DeviceInfo> page = page(toIPage(pageBean), lambdaUpdateWrapper);
         PageBean<DeviceInfoDto.AlgorithmChargingVo> algorithmChargingVoPageBean = toPageBean(DeviceInfoDto.AlgorithmChargingVo.class, page);
@@ -129,13 +130,14 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
             return R.ok(algorithmChargingVoPageBean);
         }
         //查询卡包数量
-        List<DeviceAlgorithmChargingDto.CountVo> data = deviceAlgorithmChargingService.count(new DeviceAlgorithmChargingDto.Count().setDeviceIds(new JArrayList<>(algorithmChargingVos).getProperty(DeviceInfoDto.AlgorithmChargingVo::getDeviceId))).getData();
+        List<DeviceAlgorithmChargingDto.CountVo> data = deviceAlgorithmChargingService.count(new DeviceAlgorithmChargingDto.Count()
+                .setDeviceIds(new JArrayList<>(algorithmChargingVos).getProperty(DeviceInfoDto.AlgorithmChargingVo::getDeviceId))
+                .setMercId(algorithmCharging.getMercId())
+        ).getData();
         JMap<Long, DeviceAlgorithmChargingDto.CountVo> cover = new JArrayList<>(data).toMap(DeviceAlgorithmChargingDto.CountVo::getDeviceId).cover();
         algorithmChargingVos.forEach(algorithmChargingVo -> {
             DeviceAlgorithmChargingDto.CountVo countVo = cover.get(algorithmChargingVo.getDeviceId());
-            algorithmChargingVo.setAlgorithmChargingSize(countVo.getCount())
-                    .setAlgorithmChargingLength(countVo.getSize())
-                    .setArrearageBalance(countVo.getArrearageBalance());
+            Beans.copy(algorithmChargingVo, countVo);
         });
         return R.ok(algorithmChargingVoPageBean);
     }

+ 7 - 1
device-api-service/src/main/java/com/xy/service/DeviceNetRecordServiceImpl.java

@@ -47,7 +47,6 @@ public class DeviceNetRecordServiceImpl extends ServiceImpl<DeviceNetRecordMappe
         return R.ok();
     }
 
-
     @Override
     @ApiOperation("分页查询")
     public R<PageBean<DeviceNetRecordDto.Vo>> page(@RequestBody DeviceNetRecordDto.Page page) {
@@ -73,4 +72,11 @@ public class DeviceNetRecordServiceImpl extends ServiceImpl<DeviceNetRecordMappe
         List<DeviceNetRecord> list = list(lambdaQueryWrapper);
         return R.ok(copy(DeviceNetRecordDto.Vo.class, list));
     }
+
+    @PostMapping("offLineDevice")
+    @ApiOperation("离线设备列表")
+    public R<List<DeviceNetRecordDto.OffLineDeviceVo>> offLineDevice(@RequestBody @Validated DeviceNetRecordDto.OffLineDevice offLineDevice) {
+        List<DeviceNetRecordDto.OffLineDeviceVo> offLineDeviceVos = baseMapper.offLineDevice(offLineDevice);
+        return R.ok(offLineDeviceVos);
+    }
 }

+ 10 - 4
device-api/src/main/java/com/xy/dto/DeviceAlgorithmChargingDto.java

@@ -29,6 +29,9 @@ public class DeviceAlgorithmChargingDto {
         @NotEmpty(message = "设备id不能为空")
         @ApiModelProperty(value = "设备id")
         private List<Long> deviceIds;
+
+        @ApiModelProperty(value = "商户ID")
+        private Long mercId;
     }
 
     @Data
@@ -38,11 +41,14 @@ public class DeviceAlgorithmChargingDto {
         @ApiModelProperty(value = "设备id")
         private Long deviceId;
 
-        @ApiModelProperty(value = "卡包个数")
-        private Integer count;
+        @ApiModelProperty(value = "剩余个数")
+        private Integer unusedCount;
 
-        @ApiModelProperty(value = "卡包条数")
-        private Integer size;
+        @ApiModelProperty(value = "剩余条数")
+        private Integer unusedSize;
+
+        @ApiModelProperty(value = "已用条数")
+        private Integer makeSize;
 
         @ApiModelProperty(value = "欠费金额")
         private Integer arrearageBalance;

+ 9 - 0
device-api/src/main/java/com/xy/dto/DeviceChargingDto.java

@@ -22,6 +22,15 @@ import java.util.List;
  */
 public class DeviceChargingDto {
 
+    @Data
+    @Accessors(chain = true)
+    public static class SelectList {
+
+        @NotEmpty(message = "设备id不能为空")
+        @ApiModelProperty(value = "设备id")
+        private List<Long> deviceIds;
+    }
+
     @Data
     @Accessors(chain = true)
     public static class Del {

+ 10 - 4
device-api/src/main/java/com/xy/dto/DeviceInfoDto.java

@@ -48,6 +48,9 @@ public class DeviceInfoDto {
 
         @ApiModelProperty(value = "商户ID", hidden = true)
         private Long mercId;
+
+        @ApiModelProperty(value = "设备ID")
+        private List<Long> deviceIds;
     }
 
     @Data
@@ -427,11 +430,14 @@ public class DeviceInfoDto {
     @Accessors(chain = true)
     public static class AlgorithmChargingVo extends Vo {
 
-        @ApiModelProperty(value = "卡包个数")
-        private Integer algorithmChargingSize;
+        @ApiModelProperty(value = "剩余个数")
+        private Integer unusedCount;
+
+        @ApiModelProperty(value = "剩余条数")
+        private Integer unusedSize;
 
-        @ApiModelProperty(value = "卡包条数")
-        private Integer algorithmChargingLength;
+        @ApiModelProperty(value = "已用条数")
+        private Integer makeSize;
 
         @ApiModelProperty(value = "欠费金额")
         private Integer arrearageBalance;

+ 11 - 0
device-api/src/main/java/com/xy/service/DeviceChargingService.java

@@ -3,9 +3,12 @@ package com.xy.service;
 import com.xy.annotate.RestMappingController;
 import com.xy.dto.DeviceChargingDto;
 import com.xy.utils.R;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 
+import java.util.List;
+
 /**
  * <p>
  * 设备计费表 服务类
@@ -34,4 +37,12 @@ public interface DeviceChargingService {
      */
     @PostMapping("payNotice")
     R payNotice(@RequestBody DeviceChargingDto.PayNotice payNotice);
+
+    /**
+     * 集合查询
+     *
+     * @return
+     */
+    @PostMapping("list")
+    R<List<DeviceChargingDto.Vo>> list(@RequestBody @Validated DeviceChargingDto.SelectList selectList);
 }

+ 12 - 1
device-api/src/main/java/com/xy/service/DeviceInfoService.java

@@ -24,7 +24,8 @@ import java.util.Map;
 public interface DeviceInfoService {
 
     @PostMapping("netStateCount")
-    R<Map<Long,DeviceInfoDto.NetStateCountVo>> netStateCount(@RequestBody DeviceInfoDto.NetStateCountDto dto);
+    R<Map<Long, DeviceInfoDto.NetStateCountVo>> netStateCount(@RequestBody DeviceInfoDto.NetStateCountDto dto);
+
     /**
      * 查询对象
      *
@@ -98,6 +99,7 @@ public interface DeviceInfoService {
 
     @PostMapping("page")
     R<PageBean<DeviceInfoDto.Vo2>> page(@RequestBody DeviceInfoDto.Page page);
+
     /**
      * 更新商户点位
      *
@@ -182,4 +184,13 @@ public interface DeviceInfoService {
      */
     @PostMapping("placeDeviceNum")
     R<List<DeviceInfoDto.PlaceDeviceNumVo>> placeDeviceNum(@RequestBody @Validated DeviceInfoDto.PlaceDeviceNumDto dto);
+
+    /**
+     * 设备列表带卡包数
+     *
+     * @param algorithmCharging
+     * @return
+     */
+    @PostMapping("algorithmChargingDevice")
+    R<PageBean<DeviceInfoDto.AlgorithmChargingVo>> algorithmChargingDevice(@RequestBody @Validated DeviceInfoDto.AlgorithmCharging algorithmCharging);
 }