mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
添加皮带秤管理
This commit is contained in:
16
README.md
16
README.md
@@ -89,7 +89,19 @@ cd /data/backup && sudo -u postgres pg_dumpall | gzip > /data/backup/$(date +"%
|
||||
|
||||
|
||||
```
|
||||
rabbitmqctl add_user datacollector datacollector
|
||||
rabbitmqctl set_permissions --vhost /coal/test datacollector '' 'sysExchange' 'pms\.client.*'
|
||||
|
||||
docker compose exec -it rabbitmq bash
|
||||
|
||||
rabbitmqctl add_user datacollector datacollector
|
||||
rabbitmqctl set_permissions --vhost /coal/test datacollector '' 'sysExchange' 'pms\.client\.*|dataCollector\.*'
|
||||
|
||||
```
|
||||
|
||||
|
||||
本地端口映射
|
||||
|
||||
|
||||
```
|
||||
|
||||
gost-windows-amd64.exe -L=tcp://:5672/192.168.59.128:5672
|
||||
```
|
||||
@@ -44,6 +44,9 @@ public abstract class BaseService<
|
||||
dao.deleteAllById(id);
|
||||
}
|
||||
|
||||
public Entity findOne(Specification<Entity> spec) {
|
||||
return dao.findOne(spec).orElse(null);
|
||||
}
|
||||
public Page<Entity> findAll(Specification<Entity> spec, Pageable page) {
|
||||
return dao.findAll(spec, page);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,38 @@
|
||||
package cn.lihongjie.coal.common;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.TupleElement;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class JpaUtils {
|
||||
|
||||
public static Function<String, String> underscoreToCamelCase =
|
||||
(String name) -> CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
|
||||
|
||||
public static List<Map<String, Object>> convertTuplesToMap(List<Tuple> tuples) {
|
||||
return convertTuplesToMap(tuples, Function.identity(), Function.identity());
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> convertTuplesToMap(List<Tuple> tuples, Function<String, String> keyMapper) {
|
||||
return convertTuplesToMap(tuples, keyMapper, Function.identity());
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> convertTuplesToMap(List<Tuple> tuples, Function<String, String> keyMapper, Function<Object, Object> valueMapper) {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
for (Tuple single : tuples) {
|
||||
Map<String, Object> tempMap = new HashMap<>();
|
||||
for (TupleElement<?> key : single.getElements()) {
|
||||
tempMap.put(key.getAlias(), single.get(key));
|
||||
tempMap.put(keyMapper.apply(key.getAlias()), valueMapper.apply(single.get(key)));
|
||||
}
|
||||
result.add(tempMap);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
42
src/main/java/cn/lihongjie/coal/common/NumberUtils.java
Normal file
42
src/main/java/cn/lihongjie/coal/common/NumberUtils.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package cn.lihongjie.coal.common;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
|
||||
@UtilityClass
|
||||
public class NumberUtils {
|
||||
|
||||
public Double toDouble(String value) {
|
||||
try {
|
||||
|
||||
return Double.valueOf(value);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Double round2(Double value) {
|
||||
return round(value, 2);
|
||||
}
|
||||
public Double round3(Double value) {
|
||||
return round(value, 3);
|
||||
}
|
||||
|
||||
public Double round4(Double value) {
|
||||
return round(value, 4);
|
||||
}
|
||||
public Double round(Double value, int scale) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
||||
return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP).doubleValue();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,321 @@
|
||||
package cn.lihongjie.coal.dataCollector.listener;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.BaseEntity;
|
||||
import cn.lihongjie.coal.common.NumberUtils;
|
||||
import cn.lihongjie.coal.dataCollector.entity.DataCollectorEntity;
|
||||
import cn.lihongjie.coal.dataCollector.service.DataCollectorService;
|
||||
import cn.lihongjie.coal.dataCollectorLog.entity.DataCollectorLogEntity;
|
||||
import cn.lihongjie.coal.dataCollectorLog.service.DataCollectorLogService;
|
||||
import cn.lihongjie.coal.pdcDevice.entity.PdcDeviceEntity;
|
||||
import cn.lihongjie.coal.pdcDevice.service.PdcDeviceService;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.entity.PdcDeviceRealTimeDataEntity;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.service.PdcDeviceRealTimeDataService;
|
||||
import cn.lihongjie.coal.rabbitmq.RabbitMQConfiguration;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.codec.digest.HmacAlgorithms;
|
||||
import org.apache.commons.codec.digest.HmacUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class PdcListener {
|
||||
|
||||
@Autowired DataCollectorService dataCollectorService;
|
||||
|
||||
@Autowired DataCollectorLogService dataCollectorLogService;
|
||||
|
||||
@Autowired ObjectMapper objectMapper;
|
||||
|
||||
@Autowired PdcDeviceRealTimeDataService pdcDeviceRealTimeDataService;
|
||||
|
||||
@Autowired PdcDeviceService pdcDeviceService;
|
||||
|
||||
public static String buildFaultInfo(Long faultData) {
|
||||
String faultInfo = "";
|
||||
|
||||
/**
|
||||
* 0x00000001:通讯故障 0x00000002:重量超限 0x00000004:AD通道故障
|
||||
*
|
||||
* <p>0x00000008:SP通道故障 0x00000008:SP通道故障 0x00000010:皮带跑偏
|
||||
*
|
||||
* <p>0x00000020:流量超限 0x00000040:速度超限 0x00000080:缺料故障
|
||||
*
|
||||
* <p>0x00000100:加料太久 0x00000200:AD溢出故障 0x00000400:定量超差
|
||||
*
|
||||
* <p>0x00010000:定量停止 0x00020000:主运行(配料/皮带) 0x00040000:辅运行(加料)
|
||||
*
|
||||
* <p>0x00080000: 手动标志
|
||||
*/
|
||||
if ((faultData & 0x00000001) != 0) {
|
||||
faultInfo += "通讯故障;";
|
||||
}
|
||||
if ((faultData & 0x00000002) != 0) {
|
||||
faultInfo += "重量超限;";
|
||||
}
|
||||
if ((faultData & 0x00000004) != 0) {
|
||||
faultInfo += "AD通道故障;";
|
||||
}
|
||||
if ((faultData & 0x00000008) != 0) {
|
||||
faultInfo += "SP通道故障;";
|
||||
}
|
||||
if ((faultData & 0x00000010) != 0) {
|
||||
faultInfo += "皮带跑偏;";
|
||||
}
|
||||
if ((faultData & 0x00000020) != 0) {
|
||||
faultInfo += "流量超限;";
|
||||
}
|
||||
if ((faultData & 0x00000040) != 0) {
|
||||
faultInfo += "速度超限;";
|
||||
}
|
||||
if ((faultData & 0x00000080) != 0) {
|
||||
faultInfo += "缺料故障;";
|
||||
}
|
||||
if ((faultData & 0x00000100) != 0) {
|
||||
faultInfo += "加料太久;";
|
||||
}
|
||||
if ((faultData & 0x00000200) != 0) {
|
||||
faultInfo += "AD溢出故障;";
|
||||
}
|
||||
if ((faultData & 0x00000400) != 0) {
|
||||
faultInfo += "定量超差;";
|
||||
}
|
||||
if ((faultData & 0x00010000) != 0) {
|
||||
faultInfo += "定量停止;";
|
||||
}
|
||||
if ((faultData & 0x00020000) != 0) {
|
||||
faultInfo += "主运行(配料/皮带);";
|
||||
}
|
||||
if ((faultData & 0x00040000) != 0) {
|
||||
faultInfo += "辅运行(加料);";
|
||||
}
|
||||
if ((faultData & 0x00080000) != 0) {
|
||||
faultInfo += "手动标志;";
|
||||
}
|
||||
|
||||
return faultInfo;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RabbitListener(
|
||||
bindings = {
|
||||
@QueueBinding(
|
||||
value =
|
||||
@org.springframework.amqp.rabbit.annotation.Queue(
|
||||
value = "pdc.data",
|
||||
durable = "true"),
|
||||
exchange =
|
||||
@Exchange(
|
||||
value = RabbitMQConfiguration.SYS_EXCHANGE,
|
||||
declare = Exchange.FALSE),
|
||||
key = "pdc.*")
|
||||
})
|
||||
@Transactional
|
||||
public void handlePdcMessage(Message message) {
|
||||
|
||||
var body = new String(message.getBody(), StandardCharsets.UTF_8);
|
||||
|
||||
Map<String, Object> headers = message.getMessageProperties().getHeaders();
|
||||
|
||||
Object key = headers.get("appKey");
|
||||
|
||||
if (key == null) {
|
||||
log.error("appKey is null");
|
||||
return;
|
||||
}
|
||||
|
||||
DataCollectorEntity dataCollector = dataCollectorService.findByAppKey(key.toString());
|
||||
|
||||
var sign =
|
||||
new HmacUtils(HmacAlgorithms.HMAC_SHA_256, dataCollector.getAppSecret())
|
||||
.hmacHex(body.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
if (!StringUtils.equals(sign, headers.get("sign").toString())) {
|
||||
log.error("sign not match {} {}", sign, headers.get("sign"));
|
||||
return;
|
||||
}
|
||||
|
||||
var devices =
|
||||
pdcDeviceService.findAll(
|
||||
new Specification<PdcDeviceEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<PdcDeviceEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(
|
||||
root.get("dataCollector").get("id"),
|
||||
dataCollector.getId()));
|
||||
}
|
||||
});
|
||||
|
||||
if (devices.isEmpty()) {
|
||||
log.error("no device found for data collector: {}", dataCollector.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Map<String, PdcDeviceEntity> deviceIdMap = devices.stream().collect(Collectors.toMap(BaseEntity::getId, e -> e));
|
||||
|
||||
|
||||
Map<String, PdcDeviceEntity> deviceUidMap = devices.stream().collect(Collectors.toMap(PdcDeviceEntity::getModbusUId, e -> e));
|
||||
|
||||
|
||||
JsonNode jsonNode = objectMapper.readTree(body);
|
||||
|
||||
DataCollectorLogEntity logEntity = new DataCollectorLogEntity();
|
||||
logEntity.setOrganizationId(dataCollector.getOrganizationId());
|
||||
logEntity.setDataCollector(dataCollector);
|
||||
|
||||
Object rk = message.getMessageProperties().getReceivedRoutingKey();
|
||||
|
||||
logEntity.setLogTime(LocalDateTime.now());
|
||||
logEntity.setType(rk.toString());
|
||||
|
||||
switch (rk.toString()) {
|
||||
case "pdc.realtime" -> {
|
||||
ArrayNode nodes = (ArrayNode) jsonNode;
|
||||
var ids =
|
||||
StreamSupport.stream(nodes.spliterator(), false)
|
||||
.map(x -> x.get("uid").asText())
|
||||
.toList();
|
||||
logEntity.setContent(StringUtils.join(ids, ","));
|
||||
|
||||
Map<String, PdcDeviceRealTimeDataEntity> realTimeDataEntityMap =
|
||||
pdcDeviceRealTimeDataService
|
||||
.findAll(
|
||||
(Specification<PdcDeviceRealTimeDataEntity>) (root, query, criteriaBuilder) -> criteriaBuilder.and(
|
||||
root.get("device")
|
||||
.get("id")
|
||||
.in(
|
||||
devices.stream()
|
||||
.map(
|
||||
BaseEntity
|
||||
::getId)
|
||||
.collect(
|
||||
Collectors
|
||||
.toList())),
|
||||
root.get("modbusUId").in(ids)))
|
||||
.stream()
|
||||
.collect(Collectors.toMap(e -> e.getDevice().getId(), e -> e));
|
||||
|
||||
nodes.forEach(
|
||||
x -> {
|
||||
var uid = x.get("uid").asText();
|
||||
|
||||
|
||||
|
||||
if (!deviceUidMap.containsKey(uid)) {
|
||||
|
||||
log.warn(
|
||||
"device not found for uid: {} {}",
|
||||
dataCollector.getAppKey(),
|
||||
uid);
|
||||
return;
|
||||
}
|
||||
|
||||
PdcDeviceEntity pdcDeviceEntity = deviceUidMap.get(uid);
|
||||
|
||||
var data = realTimeDataEntityMap.getOrDefault(pdcDeviceEntity.getId(), new PdcDeviceRealTimeDataEntity());
|
||||
|
||||
|
||||
ObjectNode node = (ObjectNode) x;
|
||||
|
||||
// 0.001(t/kg)
|
||||
Double totalData = node.get("totalData").asLong(0) * 0.001;
|
||||
// 0.001(t/kg)
|
||||
Double monthData = node.get("monthData").asLong(0) * 0.001;
|
||||
// 0.001(t/kg)
|
||||
Double dayData = node.get("dayData").asLong(0) * 0.001;
|
||||
// 0.001(t/kg)
|
||||
Double classData = node.get("classData").asLong(0) * 0.001;
|
||||
// 0.001(t/kg)
|
||||
Double batchData = node.get("batchData").asLong(0) * 0.001;
|
||||
// 0.001(t/kg)
|
||||
Double fixedData = node.get("fixedData").asLong(0) * 0.001;
|
||||
// 0.1(t/kg)/h
|
||||
Double flowData = node.get("flowData").asLong(0) * 0.1;
|
||||
// 0.001m/s
|
||||
Double speedData = node.get("speedData").asLong(0) * 0.001;
|
||||
// 0.01%
|
||||
Double loadData = node.get("loadData").asLong(0) * 0.01;
|
||||
// 0.01mA
|
||||
Double outputData = node.get("outputData").asLong(0) * 0.01;
|
||||
// 无(注1)
|
||||
Long faultData = node.get("faultData").asLong(0);
|
||||
String faultInfo = buildFaultInfo(faultData);
|
||||
|
||||
// 0.001(t/kg)
|
||||
Double netData = node.get("netData").asLong(0) * 0.001;
|
||||
// 无(注2)
|
||||
Double process1Data = node.get("process1Data").asLong(0) * 1.0;
|
||||
// 无(注3)
|
||||
Double process2Data = node.get("process2Data").asLong(0) * 1.0;
|
||||
|
||||
data.setDevice(pdcDeviceEntity);
|
||||
data.setTime(
|
||||
Instant.ofEpochMilli(node.get("time").asLong())
|
||||
.atZone(java.time.ZoneOffset.of("+8"))
|
||||
.toLocalDateTime());
|
||||
data.setModbusUId(uid);
|
||||
data.setTotalData(NumberUtils.round3(totalData));
|
||||
data.setMonthData(NumberUtils.round3(monthData));
|
||||
data.setDayData(NumberUtils.round3(dayData));
|
||||
data.setClassData(NumberUtils.round3(classData));
|
||||
data.setBatchData(NumberUtils.round3(batchData));
|
||||
data.setFixedData(NumberUtils.round3(fixedData));
|
||||
data.setFlowData(NumberUtils.round3(flowData));
|
||||
data.setSpeedData(NumberUtils.round3(speedData));
|
||||
data.setLoadData(NumberUtils.round3(loadData));
|
||||
data.setOutputData(NumberUtils.round3(outputData));
|
||||
data.setFaultData(NumberUtils.round3(Double.valueOf(faultData)));
|
||||
data.setFaultInfo((faultInfo));
|
||||
data.setNetData(NumberUtils.round3(netData));
|
||||
data.setProcess1Data(NumberUtils.round3(process1Data));
|
||||
data.setProcess2Data(NumberUtils.round3(process2Data));
|
||||
data.setOrganizationId(dataCollector.getOrganizationId());
|
||||
if (data.getLastSaveTime() == null) {
|
||||
data.setLastSaveTime(LocalDateTime.now().minusDays(1));
|
||||
}
|
||||
this.pdcDeviceRealTimeDataService.save(data);
|
||||
});
|
||||
}
|
||||
default -> {
|
||||
log.warn("unknown message type: {}", rk);
|
||||
}
|
||||
}
|
||||
|
||||
// 数据量太大, 不写日志了
|
||||
// dataCollectorLogService.save(logEntity);
|
||||
|
||||
// log.info("new message from pms: {}", body);
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class DataCollectorService
|
||||
|
||||
amqpAdmin.declareQueue(
|
||||
new Queue(
|
||||
"dataCollector.client." + entity.getAppKey(),
|
||||
"dataCollector." + entity.getAppKey(),
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package cn.lihongjie.coal.pdcDevice.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.pdcDevice.dto.CreatePdcDeviceDto;
|
||||
import cn.lihongjie.coal.pdcDevice.dto.PdcDeviceDto;
|
||||
import cn.lihongjie.coal.pdcDevice.dto.UpdatePdcDeviceDto;
|
||||
import cn.lihongjie.coal.pdcDevice.service.PdcDeviceService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/pdcDevice")
|
||||
@SysLog(module = "皮带秤")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class PdcDeviceController {
|
||||
@Autowired private PdcDeviceService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public PdcDeviceDto create(@RequestBody CreatePdcDeviceDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public PdcDeviceDto update(@RequestBody UpdatePdcDeviceDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public PdcDeviceDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<PdcDeviceDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
@PostMapping("/deviceGroups")
|
||||
public List<String> deviceGroups() {
|
||||
return this.service.deviceGroups();
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
public Object archive(@RequestBody IdRequest request) {
|
||||
this.service.archive(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/unarchive")
|
||||
public Object unarchive(@RequestBody IdRequest request) {
|
||||
this.service.unarchive(request);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cn.lihongjie.coal.pdcDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class CreatePdcDeviceDto extends OrgCommonDto {
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private String supplier;
|
||||
|
||||
|
||||
|
||||
@ManyToOne
|
||||
@NotEmpty
|
||||
@NotNull
|
||||
private String dataCollector;
|
||||
|
||||
|
||||
|
||||
@Comment("设备分组")
|
||||
@NotEmpty
|
||||
@NotNull
|
||||
private String deviceGroup = "默认分组";
|
||||
|
||||
|
||||
@Comment("煤类型")
|
||||
@NotEmpty
|
||||
@NotNull
|
||||
private String coalType;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Comment("MODBUS地址")
|
||||
@NotEmpty
|
||||
@NotNull
|
||||
private String modbusUId;
|
||||
|
||||
@Comment("数据保存间隔(分钟)")
|
||||
@NotNull
|
||||
private Integer dataSaveInterval;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package cn.lihongjie.coal.pdcDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.dataCollector.dto.DataCollectorDto;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.dto.PdcDeviceSupplierDto;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class PdcDeviceDto extends OrgCommonDto {
|
||||
private String archiveStatus;
|
||||
|
||||
private String archiveStatusName;
|
||||
|
||||
@ManyToOne
|
||||
private PdcDeviceSupplierDto supplier;
|
||||
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private DataCollectorDto dataCollector;
|
||||
|
||||
|
||||
|
||||
@Comment("设备分组")
|
||||
private String deviceGroup;
|
||||
|
||||
|
||||
|
||||
@Comment("煤类型")
|
||||
private String coalType;
|
||||
|
||||
|
||||
private String coalTypeName;
|
||||
|
||||
|
||||
|
||||
|
||||
@Comment("MODBUS地址")
|
||||
private String modbusUId;
|
||||
|
||||
@Comment("数据保存间隔(分钟)")
|
||||
private Integer dataSaveInterval;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package cn.lihongjie.coal.pdcDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class UpdatePdcDeviceDto extends OrgCommonDto {
|
||||
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private String supplier;
|
||||
|
||||
|
||||
|
||||
@ManyToOne
|
||||
@NotEmpty
|
||||
@NotNull
|
||||
private String dataCollector;
|
||||
|
||||
|
||||
|
||||
@Comment("设备分组")
|
||||
@NotEmpty
|
||||
@NotNull
|
||||
private String deviceGroup = "默认分组";
|
||||
|
||||
|
||||
@Comment("煤类型")
|
||||
@NotEmpty
|
||||
@NotNull
|
||||
private String coalType;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Comment("MODBUS地址")
|
||||
@NotEmpty
|
||||
@NotNull
|
||||
private String modbusUId;
|
||||
|
||||
@Comment("数据保存间隔(分钟)")
|
||||
@NotEmpty
|
||||
@NotNull
|
||||
private Integer dataSaveInterval;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package cn.lihongjie.coal.pdcDevice.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.dataCollector.entity.DataCollectorEntity;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.entity.PdcDeviceSupplierEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class PdcDeviceEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private PdcDeviceSupplierEntity supplier;
|
||||
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private DataCollectorEntity dataCollector;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Comment("煤类型")
|
||||
private String coalType;
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'coal.type'\n"
|
||||
+ " and i.code = coal_type)")
|
||||
private String coalTypeName;
|
||||
|
||||
|
||||
|
||||
|
||||
@Comment("MODBUS地址")
|
||||
private String modbusUId;
|
||||
|
||||
@Comment("数据保存间隔(分钟)")
|
||||
private Integer dataSaveInterval;
|
||||
|
||||
|
||||
@Comment("设备分组")
|
||||
private String deviceGroup;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'archiveStatus'\n"
|
||||
+ " and i.code = archive_status)")
|
||||
private String archiveStatusName;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.pdcDevice.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.pdcDevice.dto.CreatePdcDeviceDto;
|
||||
import cn.lihongjie.coal.pdcDevice.dto.PdcDeviceDto;
|
||||
import cn.lihongjie.coal.pdcDevice.dto.UpdatePdcDeviceDto;
|
||||
import cn.lihongjie.coal.pdcDevice.entity.PdcDeviceEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface PdcDeviceMapper
|
||||
extends BaseMapper<PdcDeviceEntity, PdcDeviceDto, CreatePdcDeviceDto, UpdatePdcDeviceDto> {}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.lihongjie.coal.pdcDevice.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.pdcDevice.entity.PdcDeviceEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface PdcDeviceRepository extends BaseRepository<PdcDeviceEntity> {
|
||||
|
||||
@Query("select distinct deviceGroup from PdcDeviceEntity where organizationId = ?1")
|
||||
List<String> deviceGroups(String organizationId);
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package cn.lihongjie.coal.pdcDevice.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.ArchiveUtils;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.pdcDevice.dto.CreatePdcDeviceDto;
|
||||
import cn.lihongjie.coal.pdcDevice.dto.PdcDeviceDto;
|
||||
import cn.lihongjie.coal.pdcDevice.dto.UpdatePdcDeviceDto;
|
||||
import cn.lihongjie.coal.pdcDevice.entity.PdcDeviceEntity;
|
||||
import cn.lihongjie.coal.pdcDevice.mapper.PdcDeviceMapper;
|
||||
import cn.lihongjie.coal.pdcDevice.repository.PdcDeviceRepository;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class PdcDeviceService extends BaseService<PdcDeviceEntity, PdcDeviceRepository> {
|
||||
@Autowired private PdcDeviceRepository repository;
|
||||
|
||||
@Autowired private PdcDeviceMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public PdcDeviceDto create(CreatePdcDeviceDto request) {
|
||||
PdcDeviceEntity entity = mapper.toEntity(request);
|
||||
|
||||
long count =
|
||||
this.repository.count(
|
||||
new Specification<PdcDeviceEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<PdcDeviceEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(
|
||||
root.get("modbusUId"), request.getModbusUId()),
|
||||
criteriaBuilder.equal(
|
||||
root.get("dataCollector").get("id"),
|
||||
request.getDataCollector()));
|
||||
}
|
||||
});
|
||||
|
||||
if (count > 0) {
|
||||
throw new BizException("同一个数据采集器下MODBUS地址不能重复");
|
||||
}
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public PdcDeviceDto update(UpdatePdcDeviceDto request) {
|
||||
PdcDeviceEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
PdcDeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
|
||||
long count =
|
||||
this.repository.count(
|
||||
new Specification<PdcDeviceEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<PdcDeviceEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(
|
||||
root.get("modbusUId"), request.getModbusUId()),
|
||||
criteriaBuilder.equal(
|
||||
root.get("dataCollector").get("id"),
|
||||
request.getDataCollector()),
|
||||
criteriaBuilder.notEqual(root.get("id"), request.getId()));
|
||||
}
|
||||
});
|
||||
|
||||
if (count > 0) {
|
||||
throw new BizException("同一个数据采集器下MODBUS地址不能重复");
|
||||
}
|
||||
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
PdcDeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public PdcDeviceDto getById(String id) {
|
||||
PdcDeviceEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<PdcDeviceDto> list(CommonQuery query) {
|
||||
Page<PdcDeviceEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
PdcDeviceEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
PdcDeviceEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
|
||||
public List<String> deviceGroups() {
|
||||
|
||||
return repository.deviceGroups(Ctx.currentUser().getOrganizationId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cn.lihongjie.coal.pdcDeviceData.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.pdcDeviceData.dto.CreatePdcDeviceDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceData.dto.PdcDeviceDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceData.dto.UpdatePdcDeviceDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceData.service.PdcDeviceDataService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/pdcDeviceData")
|
||||
@SysLog(module = "皮带秤数据")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class PdcDeviceDataController {
|
||||
@Autowired private PdcDeviceDataService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public PdcDeviceDataDto create(@RequestBody CreatePdcDeviceDataDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public PdcDeviceDataDto update(@RequestBody UpdatePdcDeviceDataDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public PdcDeviceDataDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<PdcDeviceDataDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.pdcDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreatePdcDeviceDataDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.pdcDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PdcDeviceDataDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.pdcDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdatePdcDeviceDataDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,78 @@
|
||||
package cn.lihongjie.coal.pdcDeviceData.entity;
|
||||
|
||||
import cn.lihongjie.coal.annotation.HyperTable;
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.pdcDevice.entity.PdcDeviceEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@HyperTable
|
||||
public class PdcDeviceDataEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private PdcDeviceEntity device;
|
||||
|
||||
private LocalDateTime time;
|
||||
|
||||
@Comment("modbus地址")
|
||||
private String modbusUId;
|
||||
|
||||
@Comment("总累计量")
|
||||
private Double totalData;
|
||||
|
||||
@Comment("月累计量")
|
||||
private Double monthData;
|
||||
|
||||
@Comment("日累计量")
|
||||
private Double dayData;
|
||||
|
||||
@Comment("班累计量")
|
||||
private Double classData;
|
||||
|
||||
@Comment(" 批累计量")
|
||||
private Double batchData;
|
||||
|
||||
@Comment("定值累计量")
|
||||
private Double fixedData;
|
||||
|
||||
@Comment("瞬时流量")
|
||||
private Double flowData;
|
||||
|
||||
@Comment("瞬时速度")
|
||||
private Double speedData;
|
||||
|
||||
@Comment("当前负荷")
|
||||
private Double loadData;
|
||||
|
||||
@Comment("控制输出")
|
||||
private Double outputData;
|
||||
|
||||
@Comment("故障状态")
|
||||
private Double faultData;
|
||||
|
||||
@Comment("故障信息")
|
||||
private String faultInfo;
|
||||
|
||||
@Comment("净重")
|
||||
private Double netData;
|
||||
|
||||
@Comment("过程数据1")
|
||||
private Double process1Data;
|
||||
|
||||
@Comment("过程数据2")
|
||||
private Double process2Data;
|
||||
|
||||
|
||||
private Boolean saved;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.pdcDeviceData.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.pdcDeviceData.dto.CreatePdcDeviceDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceData.dto.PdcDeviceDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceData.dto.UpdatePdcDeviceDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceData.entity.PdcDeviceDataEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface PdcDeviceDataMapper
|
||||
extends BaseMapper<
|
||||
PdcDeviceDataEntity,
|
||||
PdcDeviceDataDto,
|
||||
CreatePdcDeviceDataDto,
|
||||
UpdatePdcDeviceDataDto> {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.pdcDeviceData.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.pdcDeviceData.entity.PdcDeviceDataEntity;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PdcDeviceDataRepository extends BaseRepository<PdcDeviceDataEntity> {}
|
||||
@@ -0,0 +1,74 @@
|
||||
package cn.lihongjie.coal.pdcDeviceData.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.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.pdcDeviceData.dto.CreatePdcDeviceDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceData.dto.PdcDeviceDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceData.dto.UpdatePdcDeviceDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceData.entity.PdcDeviceDataEntity;
|
||||
import cn.lihongjie.coal.pdcDeviceData.mapper.PdcDeviceDataMapper;
|
||||
import cn.lihongjie.coal.pdcDeviceData.repository.PdcDeviceDataRepository;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class PdcDeviceDataService
|
||||
extends BaseService<PdcDeviceDataEntity, PdcDeviceDataRepository> {
|
||||
@Autowired private PdcDeviceDataRepository repository;
|
||||
|
||||
@Autowired private PdcDeviceDataMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public PdcDeviceDataDto create(CreatePdcDeviceDataDto request) {
|
||||
PdcDeviceDataEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public PdcDeviceDataDto update(UpdatePdcDeviceDataDto request) {
|
||||
PdcDeviceDataEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public PdcDeviceDataDto getById(String id) {
|
||||
PdcDeviceDataEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<PdcDeviceDataDto> list(CommonQuery query) {
|
||||
Page<PdcDeviceDataEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package cn.lihongjie.coal.pdcDeviceRealTimeData.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.dto.*;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.service.PdcDeviceRealTimeDataService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/pdcDeviceRealTimeData")
|
||||
@SysLog(module = "皮带秤实时数据")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class PdcDeviceRealTimeDataController {
|
||||
@Autowired private PdcDeviceRealTimeDataService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public PdcDeviceRealTimeDataDto create(@RequestBody CreatePdcDeviceRealTimeDataDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public PdcDeviceRealTimeDataDto update(@RequestBody UpdatePdcDeviceRealTimeDataDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public PdcDeviceRealTimeDataDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<PdcDeviceRealTimeDataDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getRealTimeReport")
|
||||
public List<PdcDeviceRealTimeDataReportDto> getRealTimeReport(@RequestBody GetRealTImeReportRequest request) {
|
||||
return this.service.getRealTimeReport(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.pdcDeviceRealTimeData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreatePdcDeviceRealTimeDataDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.lihongjie.coal.pdcDeviceRealTimeData.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
public class GetRealTImeReportRequest {
|
||||
|
||||
private String deviceGroup;
|
||||
|
||||
private LocalDateTime startTime;
|
||||
|
||||
private LocalDateTime endTime;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package cn.lihongjie.coal.pdcDeviceRealTimeData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.pdcDevice.dto.PdcDeviceDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
public class PdcDeviceRealTimeDataDto extends OrgCommonDto {
|
||||
|
||||
private PdcDeviceDto device;
|
||||
|
||||
|
||||
@Comment("modbus地址")
|
||||
private String modbusUId;
|
||||
|
||||
@Comment("总累计量")
|
||||
private Double totalData;
|
||||
|
||||
@Comment("月累计量")
|
||||
private Double monthData;
|
||||
|
||||
@Comment("日累计量")
|
||||
private Double dayData;
|
||||
|
||||
@Comment("班累计量")
|
||||
private Double classData;
|
||||
|
||||
@Comment("批累计量")
|
||||
private Double batchData;
|
||||
|
||||
@Comment("定值累计量")
|
||||
private Double fixedData;
|
||||
|
||||
@Comment("瞬时流量")
|
||||
private Double flowData;
|
||||
|
||||
@Comment("瞬时速度")
|
||||
private Double speedData;
|
||||
|
||||
@Comment("当前负荷")
|
||||
private Double loadData;
|
||||
|
||||
@Comment("控制输出")
|
||||
private Double outputData;
|
||||
|
||||
@Comment("故障状态")
|
||||
private Double faultData;
|
||||
|
||||
@Comment("故障信息")
|
||||
private String faultInfo;
|
||||
|
||||
@Comment("净重")
|
||||
private Double netData;
|
||||
|
||||
@Comment("过程数据1")
|
||||
private Double process1Data;
|
||||
|
||||
@Comment("过程数据2")
|
||||
private Double process2Data;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package cn.lihongjie.coal.pdcDeviceRealTimeData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class PdcDeviceRealTimeDataReportDto extends OrgCommonDto {
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private String deviceCode;
|
||||
|
||||
private String deviceName;
|
||||
|
||||
private String deviceGroup;
|
||||
|
||||
private String deviceCoalType;
|
||||
|
||||
@Comment("当前时间范围内的回收")
|
||||
private Double timePercent;
|
||||
|
||||
@Comment("当前时间范围内的产量")
|
||||
private Double timeTotal;
|
||||
|
||||
|
||||
private LocalDateTime time;
|
||||
|
||||
|
||||
private LocalDateTime serverTime;
|
||||
|
||||
|
||||
private Long timeDiff;
|
||||
|
||||
|
||||
@Comment("modbus地址")
|
||||
private String modbusUId;
|
||||
|
||||
@Comment("总累计量")
|
||||
private Double totalData;
|
||||
|
||||
@Comment("月累计量")
|
||||
private Double monthData;
|
||||
|
||||
@Comment("日累计量")
|
||||
private Double dayData;
|
||||
|
||||
@Comment("班累计量")
|
||||
private Double classData;
|
||||
|
||||
@Comment("批累计量")
|
||||
private Double batchData;
|
||||
|
||||
@Comment("定值累计量")
|
||||
private Double fixedData;
|
||||
|
||||
@Comment("瞬时流量")
|
||||
private Double flowData;
|
||||
|
||||
@Comment("瞬时速度")
|
||||
private Double speedData;
|
||||
|
||||
@Comment("当前负荷")
|
||||
private Double loadData;
|
||||
|
||||
@Comment("控制输出")
|
||||
private Double outputData;
|
||||
|
||||
@Comment("故障状态")
|
||||
private Double faultData;
|
||||
|
||||
@Comment("故障信息")
|
||||
private String faultInfo;
|
||||
|
||||
@Comment("净重")
|
||||
private Double netData;
|
||||
|
||||
@Comment("过程数据1")
|
||||
private Double process1Data;
|
||||
|
||||
@Comment("过程数据2")
|
||||
private Double process2Data;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.pdcDeviceRealTimeData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdatePdcDeviceRealTimeDataDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,105 @@
|
||||
package cn.lihongjie.coal.pdcDeviceRealTimeData.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.pdcDevice.entity.PdcDeviceEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <br>
|
||||
* 总累计量 0000H 30001 4字节 uint32 0.001(t/kg) <br>
|
||||
* 月累计量 0002H 30003 4字节 uint32 0.001(t/kg) <br>
|
||||
* 日累计量 0004H 30005 4字节 uint32 0.001(t/kg) <br>
|
||||
* 班累计量 0006H 30007 4字节 uint32 0.001(t/kg) <br>
|
||||
* 批累计量 0008H 30009 4字节 uint32 0.001(t/kg) <br>
|
||||
* 定值累计量 000aH 30011 4字节 uint32 0.001(t/kg) <br>
|
||||
* 瞬时流量 000cH 30013 4字节 uint32 0.1(t/kg)/h <br>
|
||||
* 瞬时速度 000eH 30015 4字节 uint32 0.001m/s <br>
|
||||
* 当前负荷 0010H 30017 4字节 uint32 0.01% <br>
|
||||
* 控制输出 0012H 30019 4字节 uint32 0.01mA <br>
|
||||
* 故障状态 0014H 30021 4字节 uint32 无(注1) <br>
|
||||
* 净重 0016H 30023 4字节 uint32 0.001(t/kg) <br>
|
||||
* 过程数据1 0018H 30025 4字节 uint32 无(注2) <br>
|
||||
* 过程数据2 001aH 30027 4字节 uint32 无(注3) <br>
|
||||
* 0x00000001:通讯故障 <br>
|
||||
* 0x00000002:重量超限 <br>
|
||||
* 0x00000004:AD通道故障 <br>
|
||||
* 0x00000008:SP通道故障 <br>
|
||||
* 0x00000008:SP通道故障 <br>
|
||||
* 0x00000010:皮带跑偏 <br>
|
||||
* 0x00000020:流量超限 <br>
|
||||
* 0x00000040:速度超限 <br>
|
||||
* 0x00000080:缺料故障 <br>
|
||||
* 0x00000100:加料太久 <br>
|
||||
* 0x00000200:AD溢出故障 <br>
|
||||
* 0x00000400:定量超差 <br>
|
||||
* 0x00010000:定量停止 <br>
|
||||
* 0x00020000:主运行(配料/皮带) <br>
|
||||
* 0x00040000:辅运行(加料) <br>
|
||||
* 0x00080000: 手动标志
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
public class PdcDeviceRealTimeDataEntity extends OrgCommonEntity {
|
||||
|
||||
@ManyToOne private PdcDeviceEntity device;
|
||||
|
||||
private LocalDateTime time;
|
||||
|
||||
@Comment("modbus地址")
|
||||
private String modbusUId;
|
||||
|
||||
@Comment("总累计量")
|
||||
private Double totalData;
|
||||
|
||||
@Comment("月累计量")
|
||||
private Double monthData;
|
||||
|
||||
@Comment("日累计量")
|
||||
private Double dayData;
|
||||
|
||||
@Comment("班累计量")
|
||||
private Double classData;
|
||||
|
||||
@Comment(" 批累计量")
|
||||
private Double batchData;
|
||||
|
||||
@Comment("定值累计量")
|
||||
private Double fixedData;
|
||||
|
||||
@Comment("瞬时流量")
|
||||
private Double flowData;
|
||||
|
||||
@Comment("瞬时速度")
|
||||
private Double speedData;
|
||||
|
||||
@Comment("当前负荷")
|
||||
private Double loadData;
|
||||
|
||||
@Comment("控制输出")
|
||||
private Double outputData;
|
||||
|
||||
@Comment("故障状态")
|
||||
private Double faultData;
|
||||
|
||||
@Comment("故障信息")
|
||||
private String faultInfo;
|
||||
|
||||
@Comment("净重")
|
||||
private Double netData;
|
||||
|
||||
@Comment("过程数据1")
|
||||
private Double process1Data;
|
||||
|
||||
@Comment("过程数据2")
|
||||
private Double process2Data;
|
||||
|
||||
private LocalDateTime lastSaveTime;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.lihongjie.coal.pdcDeviceRealTimeData.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.pdcDeviceData.entity.PdcDeviceDataEntity;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.dto.CreatePdcDeviceRealTimeDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.dto.PdcDeviceRealTimeDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.dto.UpdatePdcDeviceRealTimeDataDto;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.entity.PdcDeviceRealTimeDataEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface PdcDeviceRealTimeDataMapper
|
||||
extends BaseMapper<
|
||||
PdcDeviceRealTimeDataEntity,
|
||||
PdcDeviceRealTimeDataDto,
|
||||
CreatePdcDeviceRealTimeDataDto,
|
||||
UpdatePdcDeviceRealTimeDataDto> {
|
||||
PdcDeviceDataEntity toDataEntity(PdcDeviceRealTimeDataEntity x);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.lihongjie.coal.pdcDeviceRealTimeData.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.entity.PdcDeviceRealTimeDataEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface PdcDeviceRealTimeDataRepository
|
||||
extends BaseRepository<PdcDeviceRealTimeDataEntity> {
|
||||
|
||||
@Query(
|
||||
value =
|
||||
"select id from t_pdc_device_real_time_data dd inner join t_pdc_device d on dd.device_id = d.id where d.id in :deviceIds and (extract(epoch from (now() - dd.last_save_time)) / 60) >= d.data_save_interval ",
|
||||
nativeQuery = true)
|
||||
List<String> findNeedToSaveData(List<String> deviceIds);
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package cn.lihongjie.coal.pdcDeviceRealTimeData.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.JpaUtils;
|
||||
import cn.lihongjie.coal.dataCollectorLog.repository.DataCollectorLogRepository;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.pdcDevice.entity.PdcDeviceEntity;
|
||||
import cn.lihongjie.coal.pdcDevice.service.PdcDeviceService;
|
||||
import cn.lihongjie.coal.pdcDeviceData.entity.PdcDeviceDataEntity;
|
||||
import cn.lihongjie.coal.pdcDeviceData.repository.PdcDeviceDataRepository;
|
||||
import cn.lihongjie.coal.pdcDeviceData.service.PdcDeviceDataService;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.dto.*;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.entity.PdcDeviceRealTimeDataEntity;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.mapper.PdcDeviceRealTimeDataMapper;
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.repository.PdcDeviceRealTimeDataRepository;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Query;
|
||||
import jakarta.persistence.Tuple;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class PdcDeviceRealTimeDataService
|
||||
extends BaseService<PdcDeviceRealTimeDataEntity, PdcDeviceRealTimeDataRepository> {
|
||||
@Autowired PdcDeviceDataService pdcDeviceDataService;
|
||||
@Autowired PdcDeviceService pdcDeviceService;
|
||||
@PersistenceContext EntityManager em;
|
||||
@Autowired private PdcDeviceDataRepository pdcDeviceDataRepository;
|
||||
@Autowired private DataCollectorLogRepository dataCollectorLogRepository;
|
||||
@Autowired private PdcDeviceRealTimeDataRepository repository;
|
||||
@Autowired private PdcDeviceRealTimeDataMapper mapper;
|
||||
@Autowired private ConversionService conversionService;
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public PdcDeviceRealTimeDataDto create(CreatePdcDeviceRealTimeDataDto request) {
|
||||
PdcDeviceRealTimeDataEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public PdcDeviceRealTimeDataDto update(UpdatePdcDeviceRealTimeDataDto request) {
|
||||
PdcDeviceRealTimeDataEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public PdcDeviceRealTimeDataDto getById(String id) {
|
||||
PdcDeviceRealTimeDataEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<PdcDeviceRealTimeDataDto> list(CommonQuery query) {
|
||||
Page<PdcDeviceRealTimeDataEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public void saveRealTimeDataToData() {
|
||||
saveRealTimeDataToData(pdcDeviceService.findAll());
|
||||
}
|
||||
|
||||
public void saveRealTimeDataToData(List<PdcDeviceEntity> devices) {
|
||||
|
||||
List<String> ids =
|
||||
this.repository.findNeedToSaveData(
|
||||
devices.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
||||
|
||||
this.repository
|
||||
.findAllById(ids)
|
||||
.forEach(
|
||||
x -> {
|
||||
PdcDeviceDataEntity dataEntity = this.mapper.toDataEntity(x);
|
||||
|
||||
pdcDeviceDataService.save(dataEntity);
|
||||
|
||||
x.setLastSaveTime(LocalDateTime.now());
|
||||
this.repository.save(x);
|
||||
});
|
||||
}
|
||||
|
||||
public List<PdcDeviceRealTimeDataReportDto> getRealTimeReport(
|
||||
GetRealTImeReportRequest request) {
|
||||
|
||||
Query nativeQuery =
|
||||
em.createNativeQuery(
|
||||
"""
|
||||
|
||||
|
||||
with tmp1 as (
|
||||
|
||||
select d.device_id as device_id, max(coal_type) as coal_type, max(total_data) - min(total_data) as time_total from t_pdc_device_data d
|
||||
where d.organization_id = :organizationId
|
||||
and d.time >= :startTime
|
||||
and d.time <= :endTime
|
||||
group by d.device_id
|
||||
|
||||
)
|
||||
|
||||
|
||||
select rtd.*, d.id as device_id, d.name as device_name, d.device_group as device_group, d.coal_type as device_coal_type,
|
||||
sum(t1.time_total ) as time_total,
|
||||
sum(t1.time_total) / (select sum(time_total) from tmp1 where tmp1.coal_type = '0') as time_percent
|
||||
|
||||
|
||||
from t_pdc_device_real_time_data rtd
|
||||
inner join t_pdc_device d on rtd.device_id = d.id
|
||||
left join tmp1 t1 on rtd.device_id = t1.device_id
|
||||
|
||||
|
||||
where d.device_group = :deviceGroup and d.organization_id = :organizationId
|
||||
|
||||
|
||||
|
||||
""",
|
||||
Tuple.class);
|
||||
|
||||
nativeQuery.setParameter("deviceGroup", request.getDeviceGroup());
|
||||
nativeQuery.setParameter("organizationId", Ctx.currentUser().getOrganizationId());
|
||||
nativeQuery.setParameter(
|
||||
"startTime",
|
||||
request.getStartTime() != null
|
||||
? request.getStartTime()
|
||||
: LocalDateTime.now().toLocalDate().atStartOfDay());
|
||||
nativeQuery.setParameter(
|
||||
"endTime",
|
||||
request.getEndTime() != null
|
||||
? request.getEndTime()
|
||||
: LocalDateTime.now().toLocalDate().atTime(23, 59, 59));
|
||||
|
||||
List list =
|
||||
JpaUtils.convertTuplesToMap(
|
||||
nativeQuery.getResultList(), JpaUtils.underscoreToCamelCase);
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package cn.lihongjie.coal.pdcDeviceSupplier.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.dto.CreatePdcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.dto.PdcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.dto.UpdatePdcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.service.PdcDeviceSupplierService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/pdcDeviceSupplier")
|
||||
@SysLog(module = "")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class PdcDeviceSupplierController {
|
||||
@Autowired private PdcDeviceSupplierService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public PdcDeviceSupplierDto create(@RequestBody CreatePdcDeviceSupplierDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public PdcDeviceSupplierDto update(@RequestBody UpdatePdcDeviceSupplierDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public PdcDeviceSupplierDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<PdcDeviceSupplierDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
public Object archive(@RequestBody IdRequest request) {
|
||||
this.service.archive(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/unarchive")
|
||||
public Object unarchive(@RequestBody IdRequest request) {
|
||||
this.service.unarchive(request);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.pdcDeviceSupplier.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreatePdcDeviceSupplierDto extends OrgCommonDto {
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
private String address;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.lihongjie.coal.pdcDeviceSupplier.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PdcDeviceSupplierDto extends OrgCommonDto {
|
||||
private String archiveStatus;
|
||||
|
||||
private String archiveStatusName;
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
private String address;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.pdcDeviceSupplier.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdatePdcDeviceSupplierDto extends OrgCommonDto {
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
private String address;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.lihongjie.coal.pdcDeviceSupplier.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class PdcDeviceSupplierEntity extends OrgCommonEntity {
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'archiveStatus'\n"
|
||||
+ " and i.code = archive_status)")
|
||||
private String archiveStatusName;
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
private String address;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.pdcDeviceSupplier.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.dto.CreatePdcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.dto.PdcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.dto.UpdatePdcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.entity.PdcDeviceSupplierEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface PdcDeviceSupplierMapper
|
||||
extends BaseMapper<
|
||||
PdcDeviceSupplierEntity,
|
||||
PdcDeviceSupplierDto,
|
||||
CreatePdcDeviceSupplierDto,
|
||||
UpdatePdcDeviceSupplierDto> {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.pdcDeviceSupplier.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.entity.PdcDeviceSupplierEntity;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PdcDeviceSupplierRepository extends BaseRepository<PdcDeviceSupplierEntity> {}
|
||||
@@ -0,0 +1,121 @@
|
||||
package cn.lihongjie.coal.pdcDeviceSupplier.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.ArchiveUtils;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.dto.CreatePdcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.dto.PdcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.dto.UpdatePdcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.entity.PdcDeviceSupplierEntity;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.mapper.PdcDeviceSupplierMapper;
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.repository.PdcDeviceSupplierRepository;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class PdcDeviceSupplierService
|
||||
extends BaseService<PdcDeviceSupplierEntity, PdcDeviceSupplierRepository> {
|
||||
@Autowired private PdcDeviceSupplierRepository repository;
|
||||
|
||||
@Autowired private PdcDeviceSupplierMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public PdcDeviceSupplierDto create(CreatePdcDeviceSupplierDto request) {
|
||||
PdcDeviceSupplierEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public PdcDeviceSupplierDto update(UpdatePdcDeviceSupplierDto request) {
|
||||
PdcDeviceSupplierEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
PdcDeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
PdcDeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public PdcDeviceSupplierDto getById(String id) {
|
||||
PdcDeviceSupplierEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<PdcDeviceSupplierDto> list(CommonQuery query) {
|
||||
Page<PdcDeviceSupplierEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
PdcDeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
PdcDeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
}
|
||||
38
src/main/resources/db/migration/V39__pdcDataTrigger.sql
Normal file
38
src/main/resources/db/migration/V39__pdcDataTrigger.sql
Normal file
@@ -0,0 +1,38 @@
|
||||
create or replace function move_pdc_realtime_data() returns trigger as
|
||||
$$
|
||||
|
||||
begin
|
||||
insert into t_pdc_device_data (id, create_time, create_user_id, file_ids, update_time, update_user_id, code, name,
|
||||
remarks, sort_key, status, organization_id, batch_data, class_data, day_data,
|
||||
fault_data,
|
||||
fault_info, fixed_data, flow_data, load_data, modbusuid, month_data, net_data,
|
||||
output_data, process1data, process2data, speed_data, "time", total_data,
|
||||
device_id)
|
||||
values (new.id, new.create_time, new.create_user_id, new.file_ids, new.update_time, new.update_user_id, new.code,
|
||||
new.name,
|
||||
new.remarks, new.sort_key, new.status, new.organization_id, new.batch_data, new.class_data, new.day_data,
|
||||
new.fault_data,
|
||||
new.fault_info, new.fixed_data, new.flow_data, new.load_data, new.modbusuid, new.month_data, new.net_data,
|
||||
new.output_data, new.process1data, new.process2data, new.speed_data, new."time", new.total_data,
|
||||
new.device_id);
|
||||
|
||||
return new;
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
$$
|
||||
language plpgsql;
|
||||
|
||||
|
||||
--添加触发器
|
||||
|
||||
create or replace trigger move_pdc_realtime_data_trigger
|
||||
|
||||
after insert or update
|
||||
on t_pdc_device_real_time_data
|
||||
|
||||
for each row
|
||||
|
||||
execute procedure move_pdc_realtime_data();
|
||||
38
src/main/resources/db/migration/V40__pdcDataTrigger.sql
Normal file
38
src/main/resources/db/migration/V40__pdcDataTrigger.sql
Normal file
@@ -0,0 +1,38 @@
|
||||
create or replace function move_pdc_realtime_data() returns trigger as
|
||||
$$
|
||||
|
||||
begin
|
||||
insert into t_pdc_device_data (id, create_time, create_user_id, file_ids, update_time, update_user_id, code, name,
|
||||
remarks, sort_key, status, organization_id, batch_data, class_data, day_data,
|
||||
fault_data,
|
||||
fault_info, fixed_data, flow_data, load_data, modbusuid, month_data, net_data,
|
||||
output_data, process1data, process2data, speed_data, "time", total_data,
|
||||
device_id)
|
||||
values (gen_random_uuid()::text, new.create_time, new.create_user_id, new.file_ids, new.update_time, new.update_user_id, new.code,
|
||||
new.name,
|
||||
new.remarks, new.sort_key, new.status, new.organization_id, new.batch_data, new.class_data, new.day_data,
|
||||
new.fault_data,
|
||||
new.fault_info, new.fixed_data, new.flow_data, new.load_data, new.modbusuid, new.month_data, new.net_data,
|
||||
new.output_data, new.process1data, new.process2data, new.speed_data, new."time", new.total_data,
|
||||
new.device_id);
|
||||
|
||||
return new;
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
$$
|
||||
language plpgsql;
|
||||
|
||||
|
||||
--添加触发器
|
||||
|
||||
create or replace trigger move_pdc_realtime_data_trigger
|
||||
|
||||
after insert or update
|
||||
on t_pdc_device_real_time_data
|
||||
|
||||
for each row
|
||||
|
||||
execute procedure move_pdc_realtime_data();
|
||||
9
src/main/resources/scripts/cronJob/savePdcData.groovy
Normal file
9
src/main/resources/scripts/cronJob/savePdcData.groovy
Normal file
@@ -0,0 +1,9 @@
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.service.PdcDeviceRealTimeDataService
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def service = ioc.getBean(PdcDeviceRealTimeDataService.class)
|
||||
|
||||
service.saveRealTimeDataToData()
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.pdcDeviceData.controller.PdcDeviceDataController
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(PdcDeviceDataController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
17
src/main/resources/scripts/dict/enum/pdcDeviceDict.groovy
Normal file
17
src/main/resources/scripts/dict/enum/pdcDeviceDict.groovy
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.pdcDevice.controller.PdcDeviceController
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(PdcDeviceController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.pdcDeviceRealTimeData.controller.PdcDeviceRealTimeDataController
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(PdcDeviceRealTimeDataController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.pdcDeviceSuplier.controller.PdcDeviceSuplierController
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(PdcDeviceSuplierController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.pdcDeviceSupplier.controller.PdcDeviceSupplierController
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(PdcDeviceSupplierController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user