Jelajahi Sumber

卡包数量接口

李进 1 tahun lalu
induk
melakukan
99bd3ec189

+ 31 - 0
device-api-service/src/main/java/com/xy/service/DeviceAlgorithmChargingServiceImpl.java

@@ -31,6 +31,7 @@ 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;
@@ -63,6 +64,36 @@ public class DeviceAlgorithmChargingServiceImpl extends ServiceImpl<DeviceAlgori
 
     private AlipayDeviceService alipayDeviceService;
 
+    @PostMapping("count")
+    @ApiOperation("查询条数")
+    public R<List<DeviceAlgorithmChargingDto.CountVo>> count(@RequestBody @Validated DeviceAlgorithmChargingDto.Count count) {
+        //默认值
+        List<Long> deviceIds = count.getDeviceIds();
+        JList<DeviceAlgorithmChargingDto.CountVo> countVos = new JArrayList<>(deviceIds.size());
+        deviceIds.forEach(deviceId -> {
+            DeviceAlgorithmChargingDto.CountVo countVo = new DeviceAlgorithmChargingDto.CountVo()
+                    .setDeviceId(deviceId)
+                    .setCount(0);
+            countVos.add(countVo);
+        });
+        JMap<Long, DeviceAlgorithmChargingDto.CountVo> cover = countVos.toMap(DeviceAlgorithmChargingDto.CountVo::getDeviceId).cover();
+        //查询数据
+        String thisTime = DataTime.getSring("yyyyMMdd");
+        List<DeviceAlgorithmCharging> list = list(new LambdaQueryWrapper<DeviceAlgorithmCharging>()
+                .in(DeviceAlgorithmCharging::getDeviceId, deviceIds)
+                .gt(DeviceAlgorithmCharging::getUnusedSize, 0)
+                .and(deviceAlgorithmChargingLambdaQueryWrapper -> deviceAlgorithmChargingLambdaQueryWrapper
+                        .eq(DeviceAlgorithmCharging::getTimeout, -1)
+                        .or()
+                        .ge(DeviceAlgorithmCharging::getTimeout, thisTime)
+                )
+                .le(DeviceAlgorithmCharging::getBeginTime, thisTime)
+        );
+        JMap<Long, List<DeviceAlgorithmCharging>> group = new JArrayList<>(list).toMap(DeviceAlgorithmCharging::getDeviceId).group();
+        group.forEach((deviceId, deviceAlgorithmChargings) -> cover.get(deviceId).setCount(deviceAlgorithmChargings.size()));
+        return R.ok(countVos);
+    }
+
     @PostMapping("page")
     @ApiOperation("分页查询")
     public R<PageBean<DeviceAlgorithmChargingDto.Vo>> page(@RequestBody @Validated DeviceAlgorithmChargingDto.Page page) {

+ 21 - 1
device-api/src/main/java/com/xy/dto/DeviceAlgorithmChargingDto.java

@@ -22,6 +22,26 @@ import java.util.List;
  */
 public class DeviceAlgorithmChargingDto {
 
+    @Data
+    @Accessors(chain = true)
+    public static class Count {
+
+        @NotEmpty(message = "设备id不能为空")
+        @ApiModelProperty(value = "设备id")
+        private List<Long> deviceIds;
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class CountVo {
+
+        @ApiModelProperty(value = "设备id")
+        private Long deviceId;
+
+        @ApiModelProperty(value = "卡包数")
+        private Integer count;
+    }
+
     @Data
     @Accessors(chain = true)
     public static class Page extends Vo {
@@ -35,7 +55,7 @@ public class DeviceAlgorithmChargingDto {
     @Accessors(chain = true)
     public static class Check {
 
-        @NotEmpty(message = "设备id不能为空")
+        @NotNull(message = "设备id不能为空")
         @ApiModelProperty(value = "设备id")
         private Long deviceId;
     }