Sfoglia il codice sorgente

事件统计查询

李进 1 anno fa
parent
commit
cf0591eb4f

+ 22 - 0
device-api-service/src/main/java/com/xy/service/DeviceEventMsgServiceImpl.java

@@ -15,9 +15,11 @@ import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
+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.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -110,6 +112,26 @@ public class DeviceEventMsgServiceImpl extends ServiceImpl<DeviceEventMsgMapper,
         return R.ok(vos);
     }
 
+    @PostMapping("count")
+    @ApiOperation("统计查询")
+    public R<List<DeviceEventMsgDto.CountVo>> count(@RequestBody @Validated DeviceEventMsgDto.Count count) {
+        List<String> codes = count.getCodes();
+        List<DeviceEventMsgDto.CountVo> countVos = new ArrayList<>(codes.size());
+        codes.forEach(code -> {
+            LambdaQueryWrapper<DeviceEventMsg> queryWrapper = new LambdaQueryWrapper<DeviceEventMsg>()
+                    .eq(DeviceEventMsg::getCode, code)
+                    .ge(Emptys.check(count.getCreateTimeBegin()), DeviceEventMsg::getCreateTime, count.getCreateTimeBegin())
+                    .le(Emptys.check(count.getCreateTimeEnd()), DeviceEventMsg::getCreateTime, count.getCreateTimeEnd());
+            long countNum = count(queryWrapper);
+            DeviceEventMsgDto.CountVo countVo = new DeviceEventMsgDto.CountVo()
+                    .setCode(code)
+                    .setCount(countNum);
+            countVos.add(countVo);
+        });
+        return R.ok(countVos);
+    }
+
+
     /**
      * 递归获取子编码
      *

+ 29 - 0
device-api/src/main/java/com/xy/dto/DeviceEventMsgDto.java

@@ -7,6 +7,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.experimental.Accessors;
 
+import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -58,6 +59,23 @@ public class DeviceEventMsgDto {
         private List<Long> deviceIds;
     }
 
+    @Data
+    @Accessors(chain = true)
+    public static class Count {
+
+        @NotEmpty(message = "codes不能为空")
+        @ApiModelProperty(value = "编码")
+        private List<String> codes;
+
+        @ApiModelProperty(value = "创建时间-起")
+        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+        private LocalDateTime createTimeBegin;
+
+        @ApiModelProperty(value = "创建时间-始")
+        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+        private LocalDateTime createTimeEnd;
+    }
+
     @Data
     @Accessors(chain = true)
     public static class Vo {
@@ -89,4 +107,15 @@ public class DeviceEventMsgDto {
 
     }
 
+    @Data
+    @Accessors(chain = true)
+    public static class CountVo {
+
+        @ApiModelProperty(value = "消息编码")
+        private String code;
+
+        @ApiModelProperty(value = "条数")
+        private Long count;
+    }
+
 }