mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
完善
This commit is contained in:
@@ -9,6 +9,7 @@ import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@@ -38,7 +39,23 @@ public class CreateDeviceDto extends OrgCommonDto {
|
||||
|
||||
private List<DevicePartVo> parts;
|
||||
|
||||
private Double dReserve1;
|
||||
private Double dReserve2;
|
||||
private Double dReserve3;
|
||||
private Double dReserve4;
|
||||
private Double dReserve5;
|
||||
|
||||
private String sReserve1;
|
||||
private String sReserve2;
|
||||
private String sReserve3;
|
||||
private String sReserve4;
|
||||
private String sReserve5;
|
||||
|
||||
private LocalDateTime dtReserve1;
|
||||
private LocalDateTime dtReserve2;
|
||||
private LocalDateTime dtReserve3;
|
||||
private LocalDateTime dtReserve4;
|
||||
private LocalDateTime dtReserve5;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import lombok.Data;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@@ -56,4 +57,23 @@ public class DeviceDto extends OrgCommonDto {
|
||||
|
||||
@DictTranslate(dictKey = DictCode.ARCHIVESTATUS)
|
||||
private String archiveStatusName;
|
||||
|
||||
|
||||
private Double dReserve1;
|
||||
private Double dReserve2;
|
||||
private Double dReserve3;
|
||||
private Double dReserve4;
|
||||
private Double dReserve5;
|
||||
|
||||
private String sReserve1;
|
||||
private String sReserve2;
|
||||
private String sReserve3;
|
||||
private String sReserve4;
|
||||
private String sReserve5;
|
||||
|
||||
private LocalDateTime dtReserve1;
|
||||
private LocalDateTime dtReserve2;
|
||||
private LocalDateTime dtReserve3;
|
||||
private LocalDateTime dtReserve4;
|
||||
private LocalDateTime dtReserve5;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@@ -35,4 +36,22 @@ public class UpdateDeviceDto extends OrgCommonDto {
|
||||
private String location;
|
||||
|
||||
private List<DevicePartVo> parts;
|
||||
|
||||
private Double dReserve1;
|
||||
private Double dReserve2;
|
||||
private Double dReserve3;
|
||||
private Double dReserve4;
|
||||
private Double dReserve5;
|
||||
|
||||
private String sReserve1;
|
||||
private String sReserve2;
|
||||
private String sReserve3;
|
||||
private String sReserve4;
|
||||
private String sReserve5;
|
||||
|
||||
private LocalDateTime dtReserve1;
|
||||
private LocalDateTime dtReserve2;
|
||||
private LocalDateTime dtReserve3;
|
||||
private LocalDateTime dtReserve4;
|
||||
private LocalDateTime dtReserve5;
|
||||
}
|
||||
|
||||
@@ -14,52 +14,49 @@ import lombok.Data;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class DeviceEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
@Comment("设备型号")
|
||||
private String model;
|
||||
|
||||
|
||||
@Comment("设备参数")
|
||||
|
||||
private String parameter;
|
||||
|
||||
@ManyToOne
|
||||
|
||||
private DeviceSupplierEntity supplier;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private DeviceCategoryEntity category;
|
||||
|
||||
@ManyToOne private DeviceSupplierEntity supplier;
|
||||
|
||||
@ManyToOne private DeviceCategoryEntity category;
|
||||
|
||||
@Comment("设备位置")
|
||||
private String location;
|
||||
|
||||
@ManyToOne private UserEntity manager;
|
||||
|
||||
@ManyToOne
|
||||
|
||||
private UserEntity manager;
|
||||
|
||||
|
||||
|
||||
@ElementCollection
|
||||
private List<DevicePartVo> parts;
|
||||
|
||||
|
||||
|
||||
|
||||
@ElementCollection private List<DevicePartVo> parts;
|
||||
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
private Double dReserve1;
|
||||
private Double dReserve2;
|
||||
private Double dReserve3;
|
||||
private Double dReserve4;
|
||||
private Double dReserve5;
|
||||
|
||||
private String sReserve1;
|
||||
private String sReserve2;
|
||||
private String sReserve3;
|
||||
private String sReserve4;
|
||||
private String sReserve5;
|
||||
|
||||
private LocalDateTime dtReserve1;
|
||||
private LocalDateTime dtReserve2;
|
||||
private LocalDateTime dtReserve3;
|
||||
private LocalDateTime dtReserve4;
|
||||
private LocalDateTime dtReserve5;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class WeightDeviceDataController {
|
||||
|
||||
|
||||
@PostMapping("/checkLocalData")
|
||||
public Object checkLocalData(@RequestBody ReSyncRequest request) {
|
||||
public Object checkLocalData(@RequestBody CheckLocalDataRequest request) {
|
||||
|
||||
return this.service.checkLocalData(request);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.lihongjie.coal.weightDeviceData.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class CheckLocalDataRequest {
|
||||
|
||||
|
||||
@Comment("开始时间")
|
||||
private LocalDateTime start;
|
||||
|
||||
@Comment("结束时间")
|
||||
private LocalDateTime end;
|
||||
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package cn.lihongjie.coal.weightDeviceData.service;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.common.FreeMakerUtils;
|
||||
import cn.lihongjie.coal.common.JpaUtils;
|
||||
import cn.lihongjie.coal.dataCollector.service.DataCollectorService;
|
||||
@@ -11,6 +12,7 @@ import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.rabbitmq.RabbitMQService;
|
||||
import cn.lihongjie.coal.weightDevice.entity.WeightDeviceEntity;
|
||||
import cn.lihongjie.coal.weightDevice.mapper.WeightDeviceMapper;
|
||||
import cn.lihongjie.coal.weightDevice.service.WeightDeviceService;
|
||||
import cn.lihongjie.coal.weightDeviceData.dto.*;
|
||||
import cn.lihongjie.coal.weightDeviceData.entity.WeightDeviceDataEntity;
|
||||
@@ -73,11 +75,14 @@ public class WeightDeviceDataService
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
@Autowired WeightDeviceService weightDeviceService;
|
||||
@Autowired private ObjectMapper jacksonObjectMapper;
|
||||
|
||||
@Autowired WeightDeviceMapper weightDeviceMapper;
|
||||
|
||||
@SneakyThrows
|
||||
public List<Map> checkLocalData(ReSyncRequest requst) {
|
||||
public List<Map> checkLocalData(CheckLocalDataRequest requst) {
|
||||
|
||||
TypedQuery<String> query =
|
||||
em.createQuery(
|
||||
@@ -87,9 +92,6 @@ public class WeightDeviceDataService
|
||||
|
||||
from WeightDeviceDataEntity d where 1=1
|
||||
|
||||
<#if ids??>
|
||||
and d.id in (:ids)
|
||||
</#if>
|
||||
|
||||
<#if start??>
|
||||
|
||||
@@ -103,11 +105,7 @@ public class WeightDeviceDataService
|
||||
|
||||
</#if>
|
||||
|
||||
<#if flowNumbers??>
|
||||
|
||||
and d.flowNumber in (:flowNumbers)
|
||||
|
||||
</#if>
|
||||
|
||||
|
||||
|
||||
@@ -125,22 +123,22 @@ public class WeightDeviceDataService
|
||||
|
||||
WeightDeviceEntity device = weightDeviceService.getDeviceByAppKey(appKey);
|
||||
|
||||
TypedQuery<Tuple> sysSum = em.createQuery(
|
||||
"""
|
||||
TypedQuery<Tuple> sysSum =
|
||||
em.createQuery(
|
||||
"""
|
||||
|
||||
select sum(d.mz) as mz,
|
||||
select round(sum(d.mz),2) as mz,
|
||||
|
||||
sum(d.pz) as pz,
|
||||
sum(d.jz) as jz,
|
||||
sum(d.kz) as kz,
|
||||
sum(d.sz) as sz,
|
||||
round(sum(d.pz), 2) as pz,
|
||||
round(sum(d.jz), 2) as jz,
|
||||
round(sum(d.kz), 2) as kz,
|
||||
round(sum(d.sz), 2) as sz,
|
||||
count(1) as cnt
|
||||
|
||||
from WeightDeviceDataEntity d where d.dataUpdateTime >= :start and d.dataUpdateTime <= :end and d.device.id = :deviceId
|
||||
|
||||
""", Tuple.class);
|
||||
|
||||
from WeightDeviceDataEntity d where not d.invalid and d.dataUpdateTime >= :start and d.dataUpdateTime <= :end and d.device.id = :deviceId
|
||||
|
||||
""",
|
||||
Tuple.class);
|
||||
|
||||
sysSum.setParameter("start", requst.getStart());
|
||||
sysSum.setParameter("end", requst.getEnd());
|
||||
@@ -148,21 +146,18 @@ public class WeightDeviceDataService
|
||||
|
||||
List<Tuple> resultList = sysSum.getResultList();
|
||||
|
||||
|
||||
java.util.Map<String, Object> sysSumResult = JpaUtils.convertTuplesToMap(resultList).get(0);
|
||||
|
||||
|
||||
|
||||
java.util.Map<String, Object> sysSumResult =
|
||||
JpaUtils.convertTuplesToMap(resultList).get(0);
|
||||
|
||||
var sql =
|
||||
"""
|
||||
|
||||
select
|
||||
sum(毛重) as mz
|
||||
sum(皮重) as pz
|
||||
sum(净重) as jz
|
||||
sum(扣重) as kz
|
||||
sum(实重) as sz,
|
||||
round(sum(毛重), 2) as mz,
|
||||
round(sum(皮重), 2) as pz,
|
||||
round(sum(净重), 2) as jz,
|
||||
round(sum(扣重), 2) as kz,
|
||||
round(sum(实重), 2) as sz,
|
||||
count(1) as cnt
|
||||
from 称重信息
|
||||
where 更新时间>='%s' and 更新时间<='%s'
|
||||
@@ -186,7 +181,16 @@ where 更新时间>='%s' and 更新时间<='%s'
|
||||
|
||||
Object resp = rabbitTemplate.convertSendAndReceive("weight20." + appKey, req);
|
||||
|
||||
Map<String, Object> resultData = Map.of("appKey", appKey, "device", device, "bf", resp, "sys", sysSumResult);
|
||||
Map<String, Object> resultData =
|
||||
Map.of(
|
||||
"appKey",
|
||||
appKey,
|
||||
"device",
|
||||
weightDeviceMapper.toDto(device),
|
||||
"bf",
|
||||
resp,
|
||||
"sys",
|
||||
sysSumResult);
|
||||
log.info("check result: {}", jacksonObjectMapper.writeValueAsString(resultData));
|
||||
|
||||
result.add(resultData);
|
||||
@@ -198,6 +202,10 @@ where 更新时间>='%s' and 更新时间<='%s'
|
||||
@SneakyThrows
|
||||
public List<Map> reSync(ReSyncRequest requst) {
|
||||
|
||||
if (requst.getFlowNumbers() == null){
|
||||
requst.setFlowNumbers(new ArrayList<>());
|
||||
}
|
||||
|
||||
requst.setFlowNumbers(
|
||||
Stream.ofAll(requst.getFlowNumbers())
|
||||
.filter(x -> StringUtils.isNotBlank(x))
|
||||
@@ -215,76 +223,25 @@ where 更新时间>='%s' and 更新时间<='%s'
|
||||
requst.setEnd(LocalDateTime.now());
|
||||
}
|
||||
|
||||
TypedQuery<WeightDeviceDataEntity> query =
|
||||
|
||||
List<WeightDeviceEntity> devices =
|
||||
em.createQuery(
|
||||
FreeMakerUtils.render(
|
||||
"""
|
||||
" from WeightDeviceEntity d where d.organizationId = :organizationId",
|
||||
WeightDeviceEntity.class)
|
||||
.setParameter("organizationId", Ctx.currentUser().getOrganizationId())
|
||||
.getResultList();
|
||||
|
||||
|
||||
from WeightDeviceDataEntity d where 1=1
|
||||
|
||||
<#if ids??>
|
||||
and d.id in (:ids)
|
||||
</#if>
|
||||
|
||||
<#if start??>
|
||||
|
||||
and d.minTime >= :start
|
||||
|
||||
</#if>
|
||||
|
||||
<#if end??>
|
||||
|
||||
and d.minTime <= :end
|
||||
|
||||
</#if>
|
||||
|
||||
<#if flowNumbers?? >
|
||||
|
||||
and d.flowNumber in (:flowNumbers)
|
||||
|
||||
</#if>
|
||||
|
||||
|
||||
|
||||
""",
|
||||
requst),
|
||||
WeightDeviceDataEntity.class);
|
||||
|
||||
JpaUtils.setQueryParameter(query, requst);
|
||||
|
||||
List<WeightDeviceDataEntity> datas = query.getResultList();
|
||||
|
||||
Map<String, List<WeightDeviceDataEntity>> groupByDc =
|
||||
datas.stream()
|
||||
.collect(
|
||||
Collectors.groupingBy(
|
||||
e -> e.getDevice().getDataCollector().getAppKey()));
|
||||
List<Map> result = new ArrayList<>();
|
||||
for (Map.Entry<String, List<WeightDeviceDataEntity>> entry : groupByDc.entrySet()) {
|
||||
for (var d : devices) {
|
||||
|
||||
LocalDateTime minTime =
|
||||
Stream.ofAll(entry.getValue())
|
||||
.minBy(x -> x.getMinTime())
|
||||
.map(WeightDeviceDataEntity::getMinTime)
|
||||
.get()
|
||||
.minusHours(1);
|
||||
LocalDateTime minTime = requst.getStart();
|
||||
|
||||
LocalDateTime maxTime =
|
||||
Stream.ofAll(entry.getValue())
|
||||
.maxBy(x -> x.getMinTime())
|
||||
.map(WeightDeviceDataEntity::getMinTime)
|
||||
.get()
|
||||
.plusHours(1);
|
||||
LocalDateTime maxTime = requst.getEnd();
|
||||
|
||||
List<String> flowNumbers =
|
||||
requst.getFlowNumbers() == null
|
||||
? new ArrayList<>()
|
||||
: Stream.ofAll(entry.getValue())
|
||||
.map(WeightDeviceDataEntity::getFlowNumber)
|
||||
.toJavaList();
|
||||
ObjectUtils.defaultIfNull(requst.getFlowNumbers(), new ArrayList<>());
|
||||
|
||||
for (Stream<String> flowNumber : Stream.ofAll(flowNumbers).grouped(1000).toJavaList()) {
|
||||
if (flowNumbers.isEmpty()) {
|
||||
|
||||
Map<String, Object> req =
|
||||
Map.of(
|
||||
@@ -297,14 +254,57 @@ where 更新时间>='%s' and 更新时间<='%s'
|
||||
"end",
|
||||
maxTime,
|
||||
"flowNumbers",
|
||||
flowNumber.toJavaList()));
|
||||
new ArrayList<>()));
|
||||
Object resp =
|
||||
rabbitTemplate.convertSendAndReceive("weight20." + entry.getKey(), req);
|
||||
rabbitTemplate.convertSendAndReceive(
|
||||
"weight20." + d.getDataCollector().getAppKey(), req);
|
||||
|
||||
Map<String, Object> resultData =
|
||||
Map.of("appKey", entry.getKey(), "resp", resp, "req", req);
|
||||
log.info("reSync result: {}", jacksonObjectMapper.writeValueAsString(resultData));
|
||||
Map.of(
|
||||
"appKey",
|
||||
d.getDataCollector().getAppKey(),
|
||||
"resp",
|
||||
resp,
|
||||
"req",
|
||||
req);
|
||||
log.info(
|
||||
"reSync result: {}",
|
||||
jacksonObjectMapper.writeValueAsString(resultData));
|
||||
result.add(resultData);
|
||||
} else {
|
||||
|
||||
for (Stream<String> flowNumber :
|
||||
Stream.ofAll(flowNumbers).grouped(1000).toJavaList()) {
|
||||
|
||||
Map<String, Object> req =
|
||||
Map.of(
|
||||
"action",
|
||||
"reSync",
|
||||
"data",
|
||||
Map.of(
|
||||
"start",
|
||||
minTime,
|
||||
"end",
|
||||
maxTime,
|
||||
"flowNumbers",
|
||||
flowNumber.toJavaList()));
|
||||
Object resp =
|
||||
rabbitTemplate.convertSendAndReceive(
|
||||
"weight20." + d.getDataCollector().getAppKey(), req);
|
||||
|
||||
Map<String, Object> resultData =
|
||||
Map.of(
|
||||
"appKey",
|
||||
d.getDataCollector().getAppKey(),
|
||||
"resp",
|
||||
resp,
|
||||
"req",
|
||||
req);
|
||||
log.info(
|
||||
"reSync result: {}",
|
||||
jacksonObjectMapper.writeValueAsString(resultData));
|
||||
result.add(resultData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user