mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善报表
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
package cn.lihongjie.coal.device.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.device.entity.DeviceEntity;
|
||||
import cn.lihongjie.coal.errorMsg.ErrorMsgCode;
|
||||
import cn.lihongjie.coal.validator.OrgUniq;
|
||||
import cn.lihongjie.coal.validator.RequireCode;
|
||||
import cn.lihongjie.coal.validator.RequireName;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
@@ -9,6 +14,10 @@ import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@RequireName
|
||||
@RequireCode
|
||||
@OrgUniq(fields = {"code"}, message = ErrorMsgCode.UNIQ_CODE, entityClass = DeviceEntity.class)
|
||||
@OrgUniq(fields = {"name"}, message = ErrorMsgCode.UNIQ_NAME, entityClass = DeviceEntity.class)
|
||||
public class CreateDeviceDto extends OrgCommonDto {
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package cn.lihongjie.coal.device.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.device.entity.DeviceEntity;
|
||||
import cn.lihongjie.coal.errorMsg.ErrorMsgCode;
|
||||
import cn.lihongjie.coal.validator.OrgUniq;
|
||||
import cn.lihongjie.coal.validator.RequireCode;
|
||||
import cn.lihongjie.coal.validator.RequireName;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
@@ -9,6 +14,10 @@ import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@RequireName
|
||||
@RequireCode
|
||||
@OrgUniq(fields = {"code"}, message = ErrorMsgCode.UNIQ_CODE, entityClass = DeviceEntity.class)
|
||||
@OrgUniq(fields = {"name"}, message = ErrorMsgCode.UNIQ_NAME, entityClass = DeviceEntity.class)
|
||||
public class UpdateDeviceDto extends OrgCommonDto {
|
||||
@Comment("设备型号")
|
||||
private String model;
|
||||
|
||||
@@ -7,4 +7,6 @@ import lombok.Data;
|
||||
@Data
|
||||
public class UpdateWeightColumnConfigDto extends OrgCommonDto {
|
||||
private Integer width;
|
||||
|
||||
private String displayName;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WeightColumnConfigDto extends OrgCommonDto {
|
||||
|
||||
private String displayName;
|
||||
private Integer width;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import lombok.Data;
|
||||
@Entity
|
||||
public class WeightColumnConfigEntity extends OrgCommonEntity {
|
||||
|
||||
private String displayName;
|
||||
|
||||
|
||||
private Integer width;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.weightDeviceData.dto.CreateWeightDeviceDataDto;
|
||||
import cn.lihongjie.coal.weightDeviceData.dto.UpdateWeightDeviceDataDto;
|
||||
import cn.lihongjie.coal.weightDeviceData.dto.WeightDeviceDataDto;
|
||||
import cn.lihongjie.coal.weightDeviceData.dto.WeightDeviceDataReportRequest;
|
||||
import cn.lihongjie.coal.weightDeviceData.service.WeightDeviceDataService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -52,6 +53,12 @@ public class WeightDeviceDataController {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/report")
|
||||
public Page report(@RequestBody WeightDeviceDataReportRequest request) {
|
||||
return this.service.report(request);
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
public Object archive(@RequestBody IdRequest request) {
|
||||
this.service.archive(request);
|
||||
|
||||
@@ -12,7 +12,8 @@ import java.util.*;
|
||||
@Data
|
||||
public class WeightDeviceDataReportRequest extends CommonQuery {
|
||||
|
||||
@Comment("""
|
||||
@Comment(
|
||||
"""
|
||||
时间维度
|
||||
year
|
||||
month
|
||||
@@ -21,37 +22,34 @@ day
|
||||
hour
|
||||
""")
|
||||
private String timeDimension;
|
||||
@Comment("""
|
||||
|
||||
@Comment(
|
||||
"""
|
||||
统计字段
|
||||
|
||||
|
||||
""")
|
||||
private List<String> reportFields;
|
||||
|
||||
private List<FieldInfo> fieldInfos;
|
||||
private LocalDateTime startTime;
|
||||
private LocalDateTime endTime;
|
||||
/**
|
||||
* 过滤条件
|
||||
*/
|
||||
|
||||
private String plateNo;
|
||||
private String sendOrganization;
|
||||
/** 过滤条件 */
|
||||
private String plateNo;
|
||||
|
||||
private String sendOrganization;
|
||||
private String receiveOrganization;
|
||||
private String goods;
|
||||
private String goods;
|
||||
private String specification;
|
||||
private String mzUser;
|
||||
private String mzUser;
|
||||
private String pzUser;
|
||||
|
||||
@Data
|
||||
public static class FieldInfo {
|
||||
private String fieldName;
|
||||
|
||||
@Comment("sum avg count max min")
|
||||
private String function;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import jakarta.persistence.Tuple;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
@@ -50,8 +51,7 @@ public class WeightDeviceDataService
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
@PersistenceContext private EntityManager em;
|
||||
|
||||
public WeightDeviceDataDto create(CreateWeightDeviceDataDto request) {
|
||||
WeightDeviceDataEntity entity = mapper.toEntity(request);
|
||||
@@ -138,7 +138,7 @@ public class WeightDeviceDataService
|
||||
|
||||
public Page report(WeightDeviceDataReportRequest request) {
|
||||
|
||||
if (StringUtils.isEmpty(request.getTimeDimension())){
|
||||
if (StringUtils.isEmpty(request.getTimeDimension())) {
|
||||
request.setTimeDimension("day");
|
||||
}
|
||||
|
||||
@@ -146,24 +146,37 @@ public class WeightDeviceDataService
|
||||
CollectionUtils.isEmpty(request.getReportFields())
|
||||
? " 1 "
|
||||
: request.getReportFields().stream()
|
||||
.map(x -> CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, x))
|
||||
.map(s -> "d." + s)
|
||||
.collect(Collectors.joining(","));
|
||||
.map(x -> CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, x))
|
||||
.map(s -> "d." + s)
|
||||
.collect(Collectors.joining(","));
|
||||
|
||||
String fieldSql =
|
||||
CollectionUtils.isEmpty(request.getFieldInfos())
|
||||
? " "
|
||||
? " 1 "
|
||||
: request.getFieldInfos().stream()
|
||||
.map(
|
||||
x ->
|
||||
x.getFunction()
|
||||
+ "( d."
|
||||
+ CaseFormat.UPPER_CAMEL.to(
|
||||
CaseFormat.LOWER_UNDERSCORE,
|
||||
x.getFieldName())
|
||||
+ ") "
|
||||
+ " as "
|
||||
+ x.getFieldName())
|
||||
x -> {
|
||||
String s =
|
||||
x.getFunction()
|
||||
+ "( d."
|
||||
+ CaseFormat.UPPER_CAMEL.to(
|
||||
CaseFormat.LOWER_UNDERSCORE,
|
||||
x.getFieldName())
|
||||
+ ") ";
|
||||
|
||||
if (ObjectUtils.notEqual(x.getFunction(), "count")) {
|
||||
|
||||
s = "round(cast(" + s + " as numeric), 2)";
|
||||
}
|
||||
|
||||
s +=
|
||||
(" as "
|
||||
+ x.getFieldName()
|
||||
+ StringUtils.capitalize(
|
||||
x.getFunction()));
|
||||
|
||||
return s;
|
||||
})
|
||||
.collect(Collectors.joining(","));
|
||||
|
||||
String where = "where 1 = 1 ";
|
||||
@@ -198,26 +211,32 @@ public class WeightDeviceDataService
|
||||
|
||||
var sql =
|
||||
"select DATE_TRUNC('"
|
||||
+ request.getTimeDimension()
|
||||
+ "', d.pass_time) as time,\n"
|
||||
+ groupSql
|
||||
+ ",\n"
|
||||
+ fieldSql
|
||||
+ "\n from t_weight_device_data d\n"
|
||||
+ " "
|
||||
+ where
|
||||
+ " "
|
||||
+ "\n"
|
||||
+ "group by DATE_TRUNC('"
|
||||
+ request.getTimeDimension()
|
||||
+ "', d.pass_time), "
|
||||
+ groupSql
|
||||
+ "\n"
|
||||
+ "order by time desc , cnt desc";
|
||||
+ request.getTimeDimension()
|
||||
+ "', d.mz_time) as time,\n"
|
||||
+ groupSql
|
||||
+ ",\n"
|
||||
+ fieldSql
|
||||
+ "\n from t_weight_device_data d\n"
|
||||
+ " "
|
||||
+ where
|
||||
+ " "
|
||||
+ "\n"
|
||||
+ "group by DATE_TRUNC('"
|
||||
+ request.getTimeDimension()
|
||||
+ "', d.mz_time), "
|
||||
+ groupSql
|
||||
+ "\n"
|
||||
+ "order by time desc ";
|
||||
|
||||
var countSql = "select count(1) from (" + sql + ") as t";
|
||||
|
||||
var selectSql = "select * from (" + sql + ") as t limit " + request.getPageSize() + " offset " + request.getPageNo() * request.getPageSize();
|
||||
var selectSql =
|
||||
"select * from ("
|
||||
+ sql
|
||||
+ ") as t limit "
|
||||
+ request.getPageSize()
|
||||
+ " offset "
|
||||
+ request.getPageNo() * request.getPageSize();
|
||||
|
||||
Query selectQuery = em.createNativeQuery(selectSql, Tuple.class);
|
||||
Query countQuery = em.createNativeQuery(countSql, Integer.class);
|
||||
@@ -232,7 +251,6 @@ public class WeightDeviceDataService
|
||||
countQuery.setParameter("endTime", request.getEndTime());
|
||||
}
|
||||
|
||||
|
||||
if (StringUtils.isNotEmpty(request.getPlateNo())) {
|
||||
selectQuery.setParameter("plateNo", "%" + request.getPlateNo() + "%");
|
||||
countQuery.setParameter("plateNo", "%" + request.getPlateNo() + "%");
|
||||
@@ -244,8 +262,10 @@ public class WeightDeviceDataService
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(request.getReceiveOrganization())) {
|
||||
selectQuery.setParameter("receiveOrganization", "%" + request.getReceiveOrganization() + "%");
|
||||
countQuery.setParameter("receiveOrganization", "%" + request.getReceiveOrganization() + "%");
|
||||
selectQuery.setParameter(
|
||||
"receiveOrganization", "%" + request.getReceiveOrganization() + "%");
|
||||
countQuery.setParameter(
|
||||
"receiveOrganization", "%" + request.getReceiveOrganization() + "%");
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(request.getGoods())) {
|
||||
@@ -259,7 +279,6 @@ public class WeightDeviceDataService
|
||||
countQuery.setParameter("specification", "%" + request.getSpecification() + "%");
|
||||
}
|
||||
|
||||
|
||||
var resultList = JpaUtils.convertTuplesToMap(selectQuery.getResultList());
|
||||
|
||||
var ans =
|
||||
@@ -268,21 +287,22 @@ public class WeightDeviceDataService
|
||||
x ->
|
||||
((Map) x)
|
||||
.entrySet().stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
(Map.Entry e) ->
|
||||
CaseFormat
|
||||
.LOWER_UNDERSCORE
|
||||
.to(
|
||||
CaseFormat
|
||||
.LOWER_CAMEL,
|
||||
e.getKey()
|
||||
.toString()),
|
||||
e -> e.getValue())))
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
(Map.Entry e) ->
|
||||
CaseFormat
|
||||
.LOWER_UNDERSCORE
|
||||
.to(
|
||||
CaseFormat
|
||||
.LOWER_CAMEL,
|
||||
e.getKey()
|
||||
.toString()),
|
||||
e -> e.getValue())))
|
||||
.toList();
|
||||
|
||||
|
||||
|
||||
return new PageImpl<>(ans, PageRequest.of(0, request.getPageSize()), Integer.parseInt(countQuery.getSingleResult().toString()));
|
||||
return new PageImpl<>(
|
||||
ans,
|
||||
PageRequest.of(0, request.getPageSize()),
|
||||
Integer.parseInt(countQuery.getSingleResult().toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user