From 64c5c8459856207d55081fcb96569b934888360e Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Mon, 8 Apr 2024 12:21:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A3=85=E6=88=BF=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/AcDeviceDataService.java | 18 +- .../cn/lihongjie/coal/common/JpaUtils.java | 20 + .../coal/common/MessageSignUtils.java | 58 +++ .../listener/WeightListener.java | 370 ++++++++++++++ .../service/DataCollectorService.java | 29 +- .../controller/WeightDeviceController.java | 54 ++ .../dto/CreateWeightDeviceDto.java | 21 + .../dto/UpdateWeightDeviceDto.java | 21 + .../weightDevice/dto/WeightDeviceDto.java | 23 + .../entity/ReserveFieldConfig.java | 29 ++ .../entity/WeightDeviceEntity.java | 31 ++ .../mapper/WeightDeviceMapper.java | 23 + .../repository/WeightDeviceRepository.java | 9 + .../service/WeightDeviceService.java | 73 +++ .../WeightDeviceDataController.java | 66 +++ .../dto/CreateWeightDeviceDataDto.java | 8 + .../dto/UpdateWeightDeviceDataDto.java | 8 + .../dto/WeightDeviceDataDto.java | 12 + .../dto/WeightDeviceDataReportRequest.java | 57 +++ .../entity/WeightDeviceDataEntity.java | 471 ++++++++++++++++++ .../mapper/WeightDeviceDataMapper.java | 23 + .../WeightDeviceDataRepository.java | 9 + .../service/WeightDeviceDataService.java | 288 +++++++++++ .../WeightDeviceSupplierController.java | 54 ++ .../dto/CreateWeightDeviceSupplierDto.java | 14 + .../dto/UpdateWeightDeviceSupplierDto.java | 14 + .../dto/WeightDeviceSupplierDto.java | 15 + .../entity/WeightDeviceSupplierEntity.java | 19 + .../mapper/WeightDeviceSupplierMapper.java | 23 + .../WeightDeviceSupplierRepository.java | 10 + .../service/WeightDeviceSupplierService.java | 74 +++ .../dict/enum/weightDeviceDataDict.groovy | 17 + .../scripts/dict/enum/weightDeviceDict.groovy | 17 + .../dict/enum/weightDeviceSupplierDict.groovy | 17 + 34 files changed, 1975 insertions(+), 20 deletions(-) create mode 100644 src/main/java/cn/lihongjie/coal/common/JpaUtils.java create mode 100644 src/main/java/cn/lihongjie/coal/common/MessageSignUtils.java create mode 100644 src/main/java/cn/lihongjie/coal/dataCollector/listener/WeightListener.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDevice/controller/WeightDeviceController.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDevice/dto/CreateWeightDeviceDto.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDevice/dto/UpdateWeightDeviceDto.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDevice/dto/WeightDeviceDto.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDevice/entity/ReserveFieldConfig.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDevice/entity/WeightDeviceEntity.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDevice/mapper/WeightDeviceMapper.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDevice/repository/WeightDeviceRepository.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDevice/service/WeightDeviceService.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceData/controller/WeightDeviceDataController.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceData/dto/CreateWeightDeviceDataDto.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceData/dto/UpdateWeightDeviceDataDto.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceData/dto/WeightDeviceDataDto.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceData/dto/WeightDeviceDataReportRequest.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceData/entity/WeightDeviceDataEntity.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceData/mapper/WeightDeviceDataMapper.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceData/repository/WeightDeviceDataRepository.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceData/service/WeightDeviceDataService.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceSupplier/controller/WeightDeviceSupplierController.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceSupplier/dto/CreateWeightDeviceSupplierDto.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceSupplier/dto/UpdateWeightDeviceSupplierDto.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceSupplier/dto/WeightDeviceSupplierDto.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceSupplier/entity/WeightDeviceSupplierEntity.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceSupplier/mapper/WeightDeviceSupplierMapper.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceSupplier/repository/WeightDeviceSupplierRepository.java create mode 100644 src/main/java/cn/lihongjie/coal/weightDeviceSupplier/service/WeightDeviceSupplierService.java create mode 100644 src/main/resources/scripts/dict/enum/weightDeviceDataDict.groovy create mode 100644 src/main/resources/scripts/dict/enum/weightDeviceDict.groovy create mode 100644 src/main/resources/scripts/dict/enum/weightDeviceSupplierDict.groovy diff --git a/src/main/java/cn/lihongjie/coal/acDeviceData/service/AcDeviceDataService.java b/src/main/java/cn/lihongjie/coal/acDeviceData/service/AcDeviceDataService.java index e018b95d..68fe2be2 100644 --- a/src/main/java/cn/lihongjie/coal/acDeviceData/service/AcDeviceDataService.java +++ b/src/main/java/cn/lihongjie/coal/acDeviceData/service/AcDeviceDataService.java @@ -10,6 +10,7 @@ import cn.lihongjie.coal.acDeviceData.repository.AcDeviceDataRepository; 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.JpaUtils; import cn.lihongjie.coal.dbFunctions.DbFunctionService; import com.google.common.base.CaseFormat; @@ -29,9 +30,6 @@ import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -84,17 +82,7 @@ public class AcDeviceDataService extends BaseService> convertTuplesToMap(List tuples) { - List> result = new ArrayList<>(); - for (Tuple single : tuples) { - Map tempMap = new HashMap<>(); - for (TupleElement key : single.getElements()) { - tempMap.put(key.getAlias(), single.get(key)); - } - result.add(tempMap); - } - return result; - } + @PersistenceContext private EntityManager em; public Page report(AcDeviceDataReportRequest request) { @@ -201,7 +189,7 @@ public class AcDeviceDataService extends BaseService> convertTuplesToMap(List tuples) { + List> result = new ArrayList<>(); + for (Tuple single : tuples) { + Map tempMap = new HashMap<>(); + for (TupleElement key : single.getElements()) { + tempMap.put(key.getAlias(), single.get(key)); + } + result.add(tempMap); + } + return result; + } +} diff --git a/src/main/java/cn/lihongjie/coal/common/MessageSignUtils.java b/src/main/java/cn/lihongjie/coal/common/MessageSignUtils.java new file mode 100644 index 00000000..63bf3007 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/common/MessageSignUtils.java @@ -0,0 +1,58 @@ +package cn.lihongjie.coal.common; + +import lombok.experimental.UtilityClass; +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 java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.function.Function; + +@UtilityClass +@Slf4j +public class MessageSignUtils { + + public static boolean isValid(Message message, Function appSecretProvider) { + + var body = new String(message.getBody(), StandardCharsets.UTF_8); + + Map headers = message.getMessageProperties().getHeaders(); + + Object key = headers.get("appKey"); + + if (key == null || StringUtils.isEmpty(key.toString())) { + log.error("appKey is null"); + return false; + } + String appSecret; + + try { + + appSecret = appSecretProvider.apply(key.toString()); + } catch (Exception e) { + log.error("appSecretProvider error", e); + return false; + } + + if (StringUtils.isEmpty(appSecret)) { + + log.error("appSecret is null"); + return false; + } + + var sign = + new HmacUtils(HmacAlgorithms.HMAC_SHA_256, appSecret) + .hmacHex(body.getBytes(StandardCharsets.UTF_8)); + + if (!StringUtils.equals(sign, headers.get("sign").toString())) { + log.error("sign not match {} {}", sign, headers.get("sign")); + return false; + } + + return true; + } +} diff --git a/src/main/java/cn/lihongjie/coal/dataCollector/listener/WeightListener.java b/src/main/java/cn/lihongjie/coal/dataCollector/listener/WeightListener.java new file mode 100644 index 00000000..b69d7b43 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/dataCollector/listener/WeightListener.java @@ -0,0 +1,370 @@ +package cn.lihongjie.coal.dataCollector.listener; + +import cn.lihongjie.coal.acDevice.entity.AcDeviceEntity; +import cn.lihongjie.coal.acDevice.service.AcDeviceService; +import cn.lihongjie.coal.acDeviceData.service.AcDeviceDataService; +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.rabbitmq.RabbitMQConfiguration; +import cn.lihongjie.coal.weightDeviceData.entity.WeightDeviceDataEntity; +import cn.lihongjie.coal.weightDeviceData.service.WeightDeviceDataService; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; + +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.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +@Component +@Slf4j +public class WeightListener { + + @Autowired DataCollectorService dataCollectorService; + + @Autowired DataCollectorLogService dataCollectorLogService; + + @Autowired ObjectMapper objectMapper; + + @Autowired AcDeviceDataService acDeviceDataService; + + @Autowired AcDeviceService acDeviceService; + + @Autowired WeightDeviceDataService weightDeviceDataService; + + + + @SneakyThrows + @RabbitListener( + bindings = { + @QueueBinding( + value = + @org.springframework.amqp.rabbit.annotation.Queue( + value = "weight20.data", + durable = "true"), + exchange = + @Exchange( + value = RabbitMQConfiguration.SYS_EXCHANGE, + declare = Exchange.FALSE), + key = "weight20.*") + }) + @Transactional + public void handleWeightMessage(Message message) { + + var body = new String(message.getBody(), StandardCharsets.UTF_8); + + Map 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; + } + + List devices = + acDeviceService.findAll( + new Specification() { + @Override + public Predicate toPredicate( + Root 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; + } + + var device = devices.get(0); + + 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 "weight20.weightinfo" -> { + ArrayNode nodes = (ArrayNode) jsonNode; + var flowNumbers = + StreamSupport.stream(nodes.spliterator(), false) + .map(x -> x.get("流水号").asText()) + .toList(); + logEntity.setContent(StringUtils.join(flowNumbers, ",")); + + Map flowNumberMap = + weightDeviceDataService + .findAll( + (Specification) + (root, query, criteriaBuilder) -> + criteriaBuilder.and( + criteriaBuilder.equal( + root.get("device") + .get("id"), + device.getId()), + root.get("flowNumber").in(flowNumbers))) + .stream() + .collect( + Collectors.toMap( + WeightDeviceDataEntity::getFlowNumber, e -> e)); + + nodes.forEach( + x -> { + var flowNumber = x.get("流水号").asText(); + if (flowNumberMap.containsKey(flowNumber)) { + log.info("data already exists: {} {}", flowNumber, device.getId()); + return; + } +// log.info(x.toPrettyString()); + + WeightDeviceDataEntity deviceData = new WeightDeviceDataEntity(); + + deviceData.setSequenceNumber(toInteger(x.get("序号"))); + deviceData.setFlowNumber(toString(x.get("流水号"))); + deviceData.setPlateNo(toString(x.get("车号"))); + deviceData.setWeighType(toString(x.get("过磅类型"))); + deviceData.setSendOrganization(toString(x.get("发货单位"))); + deviceData.setReceiveOrganization(toString(x.get("收货单位"))); + deviceData.setGoods(toString(x.get("货名"))); + deviceData.setSpecification(toString(x.get("规格"))); + deviceData.setMz(toDouble(x.get("毛重"))); + deviceData.setPz(toDouble(x.get("皮重"))); + deviceData.setJz(toDouble(x.get("净重"))); + deviceData.setKz(toDouble(x.get("扣重"))); + deviceData.setSz(toDouble(x.get("实重"))); + deviceData.setPrice(toDouble(x.get("单价"))); + deviceData.setAmount(toDouble(x.get("金额"))); + deviceData.setZfxs(toDouble(x.get("折方系数"))); + deviceData.setFl(toDouble(x.get("方量"))); + deviceData.setWeightFee(toDouble(x.get("过磅费"))); + deviceData.setMzUser(toString(x.get("毛重司磅员"))); + deviceData.setPzUser(toString(x.get("皮重司磅员"))); + deviceData.setMzbh(toString(x.get("毛重磅号"))); + deviceData.setPzbh(toString(x.get("皮重磅号"))); + deviceData.setMzTime(toLocalDateTime(x.get("毛重时间"))); + deviceData.setPzTime(toLocalDateTime(x.get("皮重时间"))); + deviceData.setYcgbTIme(toLocalDateTime(x.get("一次过磅时间"))); + deviceData.setEcgbTime(toLocalDateTime(x.get("二次过磅时间"))); + deviceData.setUpdateUser(toString(x.get("更新人"))); + deviceData.setUpdateTime(toLocalDateTime(x.get("更新时间"))); + deviceData.setRemark(toString(x.get("备注"))); + deviceData.setPrintCount(toInteger(x.get("打印次数"))); + deviceData.setUpload(toBoolean(x.get("上传否"))); + deviceData.setReserve1(toString(x.get("备用1"))); + deviceData.setReserve2(toString(x.get("备用2"))); + deviceData.setReserve3(toString(x.get("备用3"))); + deviceData.setReserve4(toString(x.get("备用4"))); + deviceData.setReserve5(toString(x.get("备用5"))); + deviceData.setReserve6(toDouble(x.get("备用6"))); + deviceData.setReserve7(toDouble(x.get("备用7"))); + deviceData.setReserve8(toDouble(x.get("备用8"))); + deviceData.setReserve9(toDouble(x.get("备用9"))); + deviceData.setReserve10(toString(x.get("备用10"))); + deviceData.setReserve11(toString(x.get("备用11"))); + deviceData.setReserve12(toString(x.get("备用12"))); + deviceData.setReserve13(toString(x.get("备用13"))); + deviceData.setReserve14(toString(x.get("备用14"))); + deviceData.setReserve15(toDouble(x.get("备用15"))); + deviceData.setReserve16(toDouble(x.get("备用16"))); + deviceData.setReserve17(toDouble(x.get("备用17"))); + deviceData.setReserve18(toDouble(x.get("备用18"))); + deviceData.setClientType(toInteger(x.get("客户类型"))); + deviceData.setYcgbWeight(toDouble(x.get("一次过磅重"))); + deviceData.setEcgbWeight(toDouble(x.get("二次过磅重"))); + deviceData.setB0(toString(x.get("b0"))); + deviceData.setAguid(toString(x.get("aguid"))); + deviceData.setPlanNumber(toString(x.get("PlanNumber"))); + deviceData.setRecordCreateMode(toInteger(x.get("RecordCreateMode"))); + deviceData.setRecordFinish(toInteger(x.get("RecordFinish"))); + deviceData.setNetPriceSyncTime(toLocalDateTime(x.get("网价同步时间"))); + deviceData.setNetPriceModifyUser(toString(x.get("网价修改人"))); + deviceData.setCTime(toLocalDateTime(x.get("CTime"))); + deviceData.setModifyOnnet(toString(x.get("modify_onnet"))); + deviceData.setModifyTime(toLocalDateTime(x.get("modify_time"))); + deviceData.setModifyBy(toString(x.get("modify_by"))); + deviceData.setAuditFlag(toString(x.get("audit_flag"))); + deviceData.setAuditTime(toLocalDateTime(x.get("audit_time"))); + deviceData.setAuditBy(toString(x.get("audit_by"))); + deviceData.setEUpimg(toString(x.get("e_upimg"))); + deviceData.setReserve19(toString(x.get("备用19"))); + deviceData.setReserve20(toString(x.get("备用20"))); + deviceData.setReserve21(toString(x.get("备用21"))); + deviceData.setReserve22(toString(x.get("备用22"))); + deviceData.setReserve23(toString(x.get("备用23"))); + deviceData.setReserve24(toString(x.get("备用24"))); + deviceData.setReserve25(toString(x.get("备用25"))); + deviceData.setReserve26(toString(x.get("备用26"))); + deviceData.setReserve27(toString(x.get("备用27"))); + deviceData.setReserve28(toString(x.get("备用28"))); + deviceData.setDriverInfo(toString(x.get("driver_info"))); + deviceData.setHqbUpImgG1(toInteger(x.get("HQB_UpImg_G1"))); + deviceData.setHqbUpImgG2(toInteger(x.get("HQB_UpImg_G2"))); + deviceData.setHqbUpImgG3(toInteger(x.get("HQB_UpImg_G3"))); + deviceData.setHqbUpImgG4(toInteger(x.get("HQB_UpImg_G4"))); + deviceData.setHqbUpImgT1(toInteger(x.get("HQB_UpImg_T1"))); + deviceData.setHqbUpImgT2(toInteger(x.get("HQB_UpImg_T2"))); + deviceData.setHqbUpImgT3(toInteger(x.get("HQB_UpImg_T3"))); + deviceData.setHqbUpImgT4(toInteger(x.get("HQB_UpImg_T4"))); + + weightDeviceDataService.save(deviceData); + }); + } + default -> { + log.warn("unknown message type: {}", rk); + } + } + + dataCollectorLogService.save(logEntity); + + // log.info("new message from pms: {}", body); + } + + private Integer toBoolean(JsonNode node) { + + + if (node== null || node.isNull()){ + return null; + } + + if (node.isIntegralNumber()){ + return node.asInt(); + } + + if (node.isBoolean()){ + return node.asBoolean() ? 1 : 0; + } + + return Integer.parseInt(node.asText()); + + + } + + private String toString(JsonNode node) { + + if (node== null || node.isNull()){ + return null; + } + + return node.asText(); + + } + + + private Integer toInteger(JsonNode node) { + + if (node== null || node.isNull()){ + return null; + } + + + if (node.isFloatingPointNumber()){ + return node.asInt(); + } + + if (node.isIntegralNumber()){ + return node.asInt(); + } + + String text = node.asText(); + + + if (StringUtils.isBlank(text)){ + return null; + } + + return Integer.parseInt(text); + } + + private Double toDouble(JsonNode node) { + + if (node== null || node.isNull()){ + return null; + } + + + if (node.isFloatingPointNumber()){ + return node.asDouble(); + } + + if (node.isIntegralNumber()){ + return node.asDouble(); + } + + String text = node.asText(); + + + if (StringUtils.isBlank(text)){ + return null; + } + + return Double.parseDouble(text); + } + + + private LocalDateTime toLocalDateTime(JsonNode node) { + + if (node== null || node.isNull()){ + return null; + } + + + + String text = node.asText(); + + + if (StringUtils.isBlank(text)){ + return null; + } + + return LocalDateTime.parse(text, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + } +} diff --git a/src/main/java/cn/lihongjie/coal/dataCollector/service/DataCollectorService.java b/src/main/java/cn/lihongjie/coal/dataCollector/service/DataCollectorService.java index 4b30f585..f5180d2e 100644 --- a/src/main/java/cn/lihongjie/coal/dataCollector/service/DataCollectorService.java +++ b/src/main/java/cn/lihongjie/coal/dataCollector/service/DataCollectorService.java @@ -18,6 +18,7 @@ import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.Nullable; import org.springframework.amqp.core.AmqpAdmin; import org.springframework.amqp.core.Queue; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.convert.ConversionService; import org.springframework.data.domain.Page; @@ -44,12 +45,14 @@ public class DataCollectorService @Autowired AmqpAdmin amqpAdmin; + @Autowired RabbitTemplate rabbitTemplate; + @PostConstruct public void init() { -// findAll().stream() -// .filter(x -> StringUtils.isNotEmpty(x.getAppKey())) -// .forEach(this::createQueue); + // findAll().stream() + // .filter(x -> StringUtils.isNotEmpty(x.getAppKey())) + // .forEach(this::createQueue); } public DataCollectorDto create(CreateDataCollectorDto request) { @@ -64,10 +67,24 @@ public class DataCollectorService return getById(entity.getId()); } + + public Object getLocalStatus(String appKey){ + // + // rabbitTemplate.convertSendAndReceive( + // "dataCollector." + appKey, + // (Object) "getLocalStatus", + // new CorrelationData(UUID.randomUUID().toString())); + return null; + } + @Nullable - private String createQueue(DataCollectorEntity entity) { - return amqpAdmin.declareQueue( + private void createQueue(DataCollectorEntity entity) { + amqpAdmin.declareQueue( new Queue("pms.client." + entity.getAppKey(), true, false, false, new HashMap<>())); + + amqpAdmin.declareQueue( + new Queue("weight20.client." + entity.getAppKey(), true, false, false, new HashMap<>())); + } public DataCollectorDto update(UpdateDataCollectorDto request) { @@ -110,4 +127,6 @@ public class DataCollectorService return repository.findByAppKey(appKey); } + + } diff --git a/src/main/java/cn/lihongjie/coal/weightDevice/controller/WeightDeviceController.java b/src/main/java/cn/lihongjie/coal/weightDevice/controller/WeightDeviceController.java new file mode 100644 index 00000000..cc214b6c --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDevice/controller/WeightDeviceController.java @@ -0,0 +1,54 @@ +package cn.lihongjie.coal.weightDevice.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.weightDevice.dto.CreateWeightDeviceDto; +import cn.lihongjie.coal.weightDevice.dto.UpdateWeightDeviceDto; +import cn.lihongjie.coal.weightDevice.dto.WeightDeviceDto; +import cn.lihongjie.coal.weightDevice.service.WeightDeviceService; + +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("/weightDevice") +@SysLog(module = "地磅设备") +@Slf4j +@OrgScope +public class WeightDeviceController { + @Autowired private WeightDeviceService service; + + @PostMapping("/create") + public WeightDeviceDto create(@RequestBody CreateWeightDeviceDto request) { + return this.service.create(request); + } + + @PostMapping("/update") + public WeightDeviceDto update(@RequestBody UpdateWeightDeviceDto request) { + return this.service.update(request); + } + + @PostMapping("/delete") + public Object delete(@RequestBody IdRequest request) { + this.service.delete(request); + return true; + } + + @PostMapping("/getById") + public WeightDeviceDto getById(@RequestBody IdRequest request) { + return this.service.getById(request.getId()); + } + + @PostMapping("/list") + public Page list(@RequestBody CommonQuery request) { + return this.service.list(request); + } +} diff --git a/src/main/java/cn/lihongjie/coal/weightDevice/dto/CreateWeightDeviceDto.java b/src/main/java/cn/lihongjie/coal/weightDevice/dto/CreateWeightDeviceDto.java new file mode 100644 index 00000000..f4d1346f --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDevice/dto/CreateWeightDeviceDto.java @@ -0,0 +1,21 @@ +package cn.lihongjie.coal.weightDevice.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import jakarta.persistence.ManyToOne; + +import lombok.Data; + +@Data +public class CreateWeightDeviceDto extends OrgCommonDto { + @ManyToOne + String supplier; + + @ManyToOne + String dataCollector; + + + + private String location; + +} diff --git a/src/main/java/cn/lihongjie/coal/weightDevice/dto/UpdateWeightDeviceDto.java b/src/main/java/cn/lihongjie/coal/weightDevice/dto/UpdateWeightDeviceDto.java new file mode 100644 index 00000000..fd9227b9 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDevice/dto/UpdateWeightDeviceDto.java @@ -0,0 +1,21 @@ +package cn.lihongjie.coal.weightDevice.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import jakarta.persistence.ManyToOne; + +import lombok.Data; + +@Data +public class UpdateWeightDeviceDto extends OrgCommonDto { + + @ManyToOne + String supplier; + + @ManyToOne + String dataCollector; + + + + private String location; +} diff --git a/src/main/java/cn/lihongjie/coal/weightDevice/dto/WeightDeviceDto.java b/src/main/java/cn/lihongjie/coal/weightDevice/dto/WeightDeviceDto.java new file mode 100644 index 00000000..10ebcecc --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDevice/dto/WeightDeviceDto.java @@ -0,0 +1,23 @@ +package cn.lihongjie.coal.weightDevice.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; +import cn.lihongjie.coal.dataCollector.dto.DataCollectorDto; + +import jakarta.persistence.ManyToOne; + +import lombok.Data; + +@Data +public class WeightDeviceDto extends OrgCommonDto { + + @ManyToOne + DataCollectorDto supplier; + + @ManyToOne + DataCollectorDto dataCollector; + + + + private String location; + +} diff --git a/src/main/java/cn/lihongjie/coal/weightDevice/entity/ReserveFieldConfig.java b/src/main/java/cn/lihongjie/coal/weightDevice/entity/ReserveFieldConfig.java new file mode 100644 index 00000000..67866d21 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDevice/entity/ReserveFieldConfig.java @@ -0,0 +1,29 @@ +package cn.lihongjie.coal.weightDevice.entity; + +import jakarta.persistence.Embeddable; + +import lombok.Getter; +import lombok.Setter; + +import org.hibernate.annotations.Comment; + +@Getter +@Setter +@Embeddable +public class ReserveFieldConfig { + + @Comment("字段名称") + private String name; + + @Comment("字段编码") + private String code; + + @Comment("字段显示名称") + private String displayName; + + @Comment("字段排序值") + private Integer columnSortKey; + + @Comment("是否启用") + private Boolean enable; +} diff --git a/src/main/java/cn/lihongjie/coal/weightDevice/entity/WeightDeviceEntity.java b/src/main/java/cn/lihongjie/coal/weightDevice/entity/WeightDeviceEntity.java new file mode 100644 index 00000000..5d996b11 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDevice/entity/WeightDeviceEntity.java @@ -0,0 +1,31 @@ +package cn.lihongjie.coal.weightDevice.entity; + +import cn.lihongjie.coal.base.entity.OrgCommonEntity; +import cn.lihongjie.coal.dataCollector.entity.DataCollectorEntity; +import cn.lihongjie.coal.weightDeviceSupplier.entity.WeightDeviceSupplierEntity; + +import jakarta.persistence.*; + +import lombok.Data; + +import java.util.List; + +@Data +@Entity +public class WeightDeviceEntity extends OrgCommonEntity { + + + @ManyToOne(fetch = FetchType.LAZY) + WeightDeviceSupplierEntity supplier; + + @ManyToOne(fetch = FetchType.LAZY) + DataCollectorEntity dataCollector; + + + + private String location; + + + @ElementCollection + private List reserveFieldConfigList; +} diff --git a/src/main/java/cn/lihongjie/coal/weightDevice/mapper/WeightDeviceMapper.java b/src/main/java/cn/lihongjie/coal/weightDevice/mapper/WeightDeviceMapper.java new file mode 100644 index 00000000..4108a6bc --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDevice/mapper/WeightDeviceMapper.java @@ -0,0 +1,23 @@ +package cn.lihongjie.coal.weightDevice.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.weightDevice.dto.CreateWeightDeviceDto; +import cn.lihongjie.coal.weightDevice.dto.UpdateWeightDeviceDto; +import cn.lihongjie.coal.weightDevice.dto.WeightDeviceDto; +import cn.lihongjie.coal.weightDevice.entity.WeightDeviceEntity; + +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 WeightDeviceMapper + extends BaseMapper< + WeightDeviceEntity, + WeightDeviceDto, + CreateWeightDeviceDto, + UpdateWeightDeviceDto> {} diff --git a/src/main/java/cn/lihongjie/coal/weightDevice/repository/WeightDeviceRepository.java b/src/main/java/cn/lihongjie/coal/weightDevice/repository/WeightDeviceRepository.java new file mode 100644 index 00000000..538ebc49 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDevice/repository/WeightDeviceRepository.java @@ -0,0 +1,9 @@ +package cn.lihongjie.coal.weightDevice.repository; + +import cn.lihongjie.coal.base.dao.BaseRepository; +import cn.lihongjie.coal.weightDevice.entity.WeightDeviceEntity; + +import org.springframework.stereotype.Repository; + +@Repository +public interface WeightDeviceRepository extends BaseRepository {} diff --git a/src/main/java/cn/lihongjie/coal/weightDevice/service/WeightDeviceService.java b/src/main/java/cn/lihongjie/coal/weightDevice/service/WeightDeviceService.java new file mode 100644 index 00000000..43082e3e --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDevice/service/WeightDeviceService.java @@ -0,0 +1,73 @@ +package cn.lihongjie.coal.weightDevice.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.weightDevice.dto.CreateWeightDeviceDto; +import cn.lihongjie.coal.weightDevice.dto.UpdateWeightDeviceDto; +import cn.lihongjie.coal.weightDevice.dto.WeightDeviceDto; +import cn.lihongjie.coal.weightDevice.entity.WeightDeviceEntity; +import cn.lihongjie.coal.weightDevice.mapper.WeightDeviceMapper; +import cn.lihongjie.coal.weightDevice.repository.WeightDeviceRepository; + +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 WeightDeviceService extends BaseService { + @Autowired private WeightDeviceRepository repository; + + @Autowired private WeightDeviceMapper mapper; + + @Autowired private ConversionService conversionService; + + @Autowired private DbFunctionService dbFunctionService; + + public WeightDeviceDto create(CreateWeightDeviceDto request) { + WeightDeviceEntity entity = mapper.toEntity(request); + + this.repository.save(entity); + return getById(entity.getId()); + } + + public WeightDeviceDto update(UpdateWeightDeviceDto request) { + WeightDeviceEntity 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 WeightDeviceDto getById(String id) { + WeightDeviceEntity entity = repository.get(id); + + return mapper.toDto(entity); + } + + public Page list(CommonQuery query) { + Page page = + repository.findAll( + query.specification(conversionService), + PageRequest.of( + query.getPageNo(), + query.getPageSize(), + Sort.by(query.getOrders()))); + + return page.map(this.mapper::toDto); + } +} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceData/controller/WeightDeviceDataController.java b/src/main/java/cn/lihongjie/coal/weightDeviceData/controller/WeightDeviceDataController.java new file mode 100644 index 00000000..801a503d --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceData/controller/WeightDeviceDataController.java @@ -0,0 +1,66 @@ +package cn.lihongjie.coal.weightDeviceData.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.weightDeviceData.dto.CreateWeightDeviceDataDto; +import cn.lihongjie.coal.weightDeviceData.dto.UpdateWeightDeviceDataDto; +import cn.lihongjie.coal.weightDeviceData.dto.WeightDeviceDataDto; +import cn.lihongjie.coal.weightDeviceData.service.WeightDeviceDataService; + +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("/weightDeviceData") +@SysLog(module = "地磅数据") +@Slf4j +@OrgScope +public class WeightDeviceDataController { + @Autowired private WeightDeviceDataService service; + + @PostMapping("/create") + public WeightDeviceDataDto create(@RequestBody CreateWeightDeviceDataDto request) { + return this.service.create(request); + } + + @PostMapping("/update") + public WeightDeviceDataDto update(@RequestBody UpdateWeightDeviceDataDto request) { + return this.service.update(request); + } + + @PostMapping("/delete") + public Object delete(@RequestBody IdRequest request) { + this.service.delete(request); + return true; + } + + @PostMapping("/getById") + public WeightDeviceDataDto getById(@RequestBody IdRequest request) { + return this.service.getById(request.getId()); + } + + @PostMapping("/list") + public Page 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; + } +} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceData/dto/CreateWeightDeviceDataDto.java b/src/main/java/cn/lihongjie/coal/weightDeviceData/dto/CreateWeightDeviceDataDto.java new file mode 100644 index 00000000..877211de --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceData/dto/CreateWeightDeviceDataDto.java @@ -0,0 +1,8 @@ +package cn.lihongjie.coal.weightDeviceData.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class CreateWeightDeviceDataDto extends OrgCommonDto {} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceData/dto/UpdateWeightDeviceDataDto.java b/src/main/java/cn/lihongjie/coal/weightDeviceData/dto/UpdateWeightDeviceDataDto.java new file mode 100644 index 00000000..ab183c32 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceData/dto/UpdateWeightDeviceDataDto.java @@ -0,0 +1,8 @@ +package cn.lihongjie.coal.weightDeviceData.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class UpdateWeightDeviceDataDto extends OrgCommonDto {} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceData/dto/WeightDeviceDataDto.java b/src/main/java/cn/lihongjie/coal/weightDeviceData/dto/WeightDeviceDataDto.java new file mode 100644 index 00000000..80dccb59 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceData/dto/WeightDeviceDataDto.java @@ -0,0 +1,12 @@ +package cn.lihongjie.coal.weightDeviceData.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class WeightDeviceDataDto extends OrgCommonDto { + private String archiveStatus; + + private String archiveStatusName; +} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceData/dto/WeightDeviceDataReportRequest.java b/src/main/java/cn/lihongjie/coal/weightDeviceData/dto/WeightDeviceDataReportRequest.java new file mode 100644 index 00000000..36b7d173 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceData/dto/WeightDeviceDataReportRequest.java @@ -0,0 +1,57 @@ +package cn.lihongjie.coal.weightDeviceData.dto; + +import cn.lihongjie.coal.base.dto.CommonQuery; + +import lombok.Data; + +import org.hibernate.annotations.Comment; + +import java.time.LocalDateTime; +import java.util.*; + +@Data +public class WeightDeviceDataReportRequest extends CommonQuery { + + @Comment(""" +时间维度 +year +month +week +day +hour +""") + private String timeDimension; + @Comment(""" +统计字段 + + +""") + private List reportFields; + private List fieldInfos; + private LocalDateTime startTime; + private LocalDateTime endTime; + /** + * 过滤条件 + */ + + private String plateNo; + private String sendOrganization; + private String receiveOrganization; + private String goods; + private String specification; + private String mzUser; + private String pzUser; + + @Data + public static class FieldInfo { + private String fieldName; + @Comment("sum avg count max min") + private String function; + + } + + + + + +} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceData/entity/WeightDeviceDataEntity.java b/src/main/java/cn/lihongjie/coal/weightDeviceData/entity/WeightDeviceDataEntity.java new file mode 100644 index 00000000..b9db00c4 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceData/entity/WeightDeviceDataEntity.java @@ -0,0 +1,471 @@ +package cn.lihongjie.coal.weightDeviceData.entity; + +import cn.lihongjie.coal.base.entity.OrgCommonEntity; +import cn.lihongjie.coal.weightDevice.entity.WeightDeviceEntity; + +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.ManyToOne; + +import lombok.Data; + +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.Comment; +import org.hibernate.annotations.Formula; + +import java.time.LocalDateTime; + +/** + * create table dbo.称重信息 (
+ *
+ * 序号 Integer identity (10) identity,
+ *
+ * 流水号 String(50) not null primary key nonclustered,
+ *
+ * 车号 String(50),
+ *
+ * 过磅类型 String(5),
+ *
+ * 发货单位 String(50),
+ *
+ * 收货单位 String(50),
+ *
+ * 货名 String(50),
+ *
+ * 规格 String(50),
+ *
+ * 毛重 Double(18, 3),
+ *
+ * 皮重 Double(18, 3),
+ *
+ * 净重 Double(18, 3),
+ *
+ * 扣重 Double(18, 3),
+ *
+ * 实重 Double(18, 3),
+ *
+ * 单价 Double(18, 3),
+ *
+ * 金额 Double(18, 3),
+ *
+ * 折方系数 Double(18, 3),
+ *
+ * 方量 Double(18, 3),
+ *
+ * 过磅费 Double(18, 3),
+ *
+ * 毛重司磅员 String(50),
+ *
+ * 皮重司磅员 String(50),
+ *
+ * 毛重磅号 String(10),
+ *
+ * 皮重磅号 String(10),
+ *
+ * 毛重时间 java.time.LocalDateTime(23, 3),
+ *
+ * 皮重时间 java.time.LocalDateTime(23, 3),
+ *
+ * 一次过磅时间 java.time.LocalDateTime(23, 3),
+ *
+ * 二次过磅时间 java.time.LocalDateTime(23, 3),
+ *
+ * 更新人 String(50),
+ *
+ * 更新时间 java.time.LocalDateTime(23, 3),
+ *
+ * 备注 String(50),
+ *
+ * 打印次数 Integer,
+ *
+ * 上传否 bit not null,
+ *
+ * 备用1 String(50),
+ *
+ * 备用2 String(50),
+ *
+ * 备用3 String(50),
+ *
+ * 备用4 String(50),
+ *
+ * 备用5 String(50),
+ *
+ * 备用6 Double(18, 3),
+ *
+ * 备用7 Double(18, 3),
+ *
+ * 备用8 Double(18, 3),
+ *
+ * 备用9 Double(18, 3),
+ *
+ * 备用10 String(50),
+ *
+ * 备用11 String(50),
+ *
+ * 备用12 String(50),
+ *
+ * 备用13 String(50),
+ *
+ * 备用14 String(50),
+ *
+ * 备用15 Double(18, 3),
+ *
+ * 备用16 Double(18, 3),
+ *
+ * 备用17 Double(18, 3),
+ *
+ * 备用18 Double(18, 3),
+ *
+ * 客户类型 Integer,
+ *
+ * 一次过磅重 Double(18, 3),
+ *
+ * 二次过磅重 Double(18, 3),
+ *
+ * b0 String,
+ *
+ * aguid String(36),
+ *
+ * PlanNumber String(50),
+ *
+ * RecordCreateMode Integer default (0),
+ *
+ * RecordFinish Integer default (0),
+ *
+ * 网价同步时间 java.time.LocalDateTime(23, 3),
+ *
+ * 网价修改人 String(50),
+ *
+ * CTime java.time.LocalDateTime(23, 3),
+ *
+ * modify_onnet String,
+ *
+ * modify_time java.time.LocalDateTime(23, 3),
+ *
+ * modify_by String(50),
+ *
+ * audit_flag String,
+ *
+ * audit_time java.time.LocalDateTime(23, 3),
+ *
+ * audit_by String(50),
+ *
+ * e_upimg String(8),
+ *
+ * 备用19 String(50),
+ *
+ * 备用20 String(50),
+ *
+ * 备用21 String(50),
+ *
+ * 备用22 String(50),
+ *
+ * 备用23 String(50),
+ *
+ * 备用24 String(50),
+ *
+ * 备用25 String(50),
+ *
+ * 备用26 String(50),
+ *
+ * 备用27 String(50),
+ *
+ * 备用28 String(50),
+ *
+ * driver_info String(36),
+ *
+ * HQB_UpImg_G1 Integer default (0),
+ *
+ * HQB_UpImg_G2 Integer default (0),
+ *
+ * HQB_UpImg_G3 Integer default (0),
+ *
+ * HQB_UpImg_G4 Integer default (0),
+ *
+ * HQB_UpImg_T1 Integer default (0),
+ *
+ * HQB_UpImg_T2 Integer default (0),
+ *
+ * HQB_UpImg_T3 Integer default (0),
+ *
+ * HQB_UpImg_T4 Integer default (0) ) + */ +@Data +@Entity +public class WeightDeviceDataEntity extends OrgCommonEntity { + + + @ManyToOne(fetch = FetchType.LAZY) + private WeightDeviceEntity device; + + @Comment("序号") + private Integer sequenceNumber; + + @Comment("流水号") + private String flowNumber; + + @Comment("车号") + private String plateNo; + + @Comment("过磅类型") + private String weighType; + + @Comment("发货单位") + private String sendOrganization; + + @Comment("收货单位") + private String receiveOrganization; + + @Comment("货名") + private String goods; + + @Comment("规格") + private String specification; + + @Comment("毛重") + private Double mz; + + @Comment("皮重") + private Double pz; + + @Comment("净重") + private Double jz; + + @Comment("扣重") + private Double kz; + + @Comment("实重") + private Double sz; + + @Comment("单价") + private Double price; + + @Comment("金额") + private Double amount; + + @Comment("折方系数") + private Double zfxs; + + @Comment("方量") + private Double fl; + + @Comment("过磅费") + private Double weightFee; + + @Comment("毛重司磅员") + private String mzUser; + + @Comment("皮重司磅员") + private String pzUser; + + @Comment("毛重磅号") + private String mzbh; + + @Comment("皮重磅号") + private String pzbh; + + @Comment("毛重时间") + private LocalDateTime mzTime; + + @Comment("皮重时间") + private LocalDateTime pzTime; + + @Comment("一次过磅时间") + private LocalDateTime ycgbTIme; + + @Comment("二次过磅时间") + private LocalDateTime ecgbTime; + + @Comment("更新人") + private String updateUser; + + @Comment("更新时间") + private LocalDateTime updateTime; + + @Comment("备注") + private String remark; + + @Comment("打印次数") + private Integer printCount; + + @Comment("上传否") + private Integer upload; + + @Comment("备用1") + private String reserve1; + + @Comment("备用2") + private String reserve2; + + @Comment("备用3") + private String reserve3; + + @Comment("备用4") + private String reserve4; + + @Comment("备用5") + private String reserve5; + + @Comment("备用6") + private Double reserve6; + + @Comment("备用7") + private Double reserve7; + + @Comment("备用8") + private Double reserve8; + + @Comment("备用9") + private Double reserve9; + + @Comment("备用10") + private String reserve10; + + @Comment("备用11") + private String reserve11; + + @Comment("备用12") + private String reserve12; + + @Comment("备用13") + private String reserve13; + + @Comment("备用14") + private String reserve14; + + @Comment("备用15") + private Double reserve15; + + @Comment("备用16") + private Double reserve16; + + @Comment("备用17") + private Double reserve17; + + @Comment("备用18") + private Double reserve18; + + @Comment("客户类型") + private Integer clientType; + + @Comment("一次过磅重") + private Double ycgbWeight; + + @Comment("二次过磅重") + private Double ecgbWeight; + + @Comment("b0") + private String b0; + + @Comment("aguid") + private String aguid; + + @Comment("PlanNumber") + private String planNumber; + + @Comment("RecordCreateMode") + private Integer recordCreateMode; + + @Comment("RecordFinish") + private Integer recordFinish; + + @Comment("网价同步时间") + private LocalDateTime netPriceSyncTime; + + @Comment("网价修改人") + private String netPriceModifyUser; + + @Comment("CTime") + private LocalDateTime cTime; + + @Comment("modify_onnet") + private String modifyOnnet; + + @Comment("modify_time") + private LocalDateTime modifyTime; + + @Comment("modify_by") + private String modifyBy; + + @Comment("audit_flag") + private String auditFlag; + + @Comment("audit_time") + private LocalDateTime auditTime; + + @Comment("audit_by") + private String auditBy; + + @Comment("e_upimg") + private String eUpimg; + + @Comment("备用19") + private String reserve19; + + @Comment("备用20") + private String reserve20; + + @Comment("备用21") + private String reserve21; + + @Comment("备用22") + private String reserve22; + + @Comment("备用23") + private String reserve23; + + @Comment("备用24") + private String reserve24; + + @Comment("备用25") + private String reserve25; + + @Comment("备用26") + private String reserve26; + + @Comment("备用27") + private String reserve27; + + @Comment("备用28") + private String reserve28; + + @Comment("driver_info") + private String driverInfo; + + @Comment("HQB_UpImg_G1") + private Integer hqbUpImgG1; + + @Comment("HQB_UpImg_G2") + private Integer hqbUpImgG2; + + @Comment("HQB_UpImg_G3") + private Integer hqbUpImgG3; + + @Comment("HQB_UpImg_G4") + private Integer hqbUpImgG4; + + @Comment("HQB_UpImg_T1") + private Integer hqbUpImgT1; + + @Comment("HQB_UpImg_T2") + private Integer hqbUpImgT2; + + @Comment("HQB_UpImg_T3") + private Integer hqbUpImgT3; + + @Comment("HQB_UpImg_T4") + private Integer hqbUpImgT4; + + @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; +} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceData/mapper/WeightDeviceDataMapper.java b/src/main/java/cn/lihongjie/coal/weightDeviceData/mapper/WeightDeviceDataMapper.java new file mode 100644 index 00000000..4208ff31 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceData/mapper/WeightDeviceDataMapper.java @@ -0,0 +1,23 @@ +package cn.lihongjie.coal.weightDeviceData.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.weightDeviceData.dto.CreateWeightDeviceDataDto; +import cn.lihongjie.coal.weightDeviceData.dto.UpdateWeightDeviceDataDto; +import cn.lihongjie.coal.weightDeviceData.dto.WeightDeviceDataDto; +import cn.lihongjie.coal.weightDeviceData.entity.WeightDeviceDataEntity; + +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 WeightDeviceDataMapper + extends BaseMapper< + WeightDeviceDataEntity, + WeightDeviceDataDto, + CreateWeightDeviceDataDto, + UpdateWeightDeviceDataDto> {} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceData/repository/WeightDeviceDataRepository.java b/src/main/java/cn/lihongjie/coal/weightDeviceData/repository/WeightDeviceDataRepository.java new file mode 100644 index 00000000..a755f8d2 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceData/repository/WeightDeviceDataRepository.java @@ -0,0 +1,9 @@ +package cn.lihongjie.coal.weightDeviceData.repository; + +import cn.lihongjie.coal.base.dao.BaseRepository; +import cn.lihongjie.coal.weightDeviceData.entity.WeightDeviceDataEntity; + +import org.springframework.stereotype.Repository; + +@Repository +public interface WeightDeviceDataRepository extends BaseRepository {} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceData/service/WeightDeviceDataService.java b/src/main/java/cn/lihongjie/coal/weightDeviceData/service/WeightDeviceDataService.java new file mode 100644 index 00000000..384919f5 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceData/service/WeightDeviceDataService.java @@ -0,0 +1,288 @@ +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.ArchiveUtils; +import cn.lihongjie.coal.common.JpaUtils; +import cn.lihongjie.coal.dbFunctions.DbFunctionService; +import cn.lihongjie.coal.exception.BizException; +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.entity.WeightDeviceDataEntity; +import cn.lihongjie.coal.weightDeviceData.mapper.WeightDeviceDataMapper; +import cn.lihongjie.coal.weightDeviceData.repository.WeightDeviceDataRepository; + +import com.google.common.base.CaseFormat; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import jakarta.persistence.Query; +import jakarta.persistence.Tuple; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.convert.ConversionService; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +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.util.Map; +import java.util.stream.Collectors; + +@Service +@Slf4j +@Transactional +public class WeightDeviceDataService + extends BaseService { + @Autowired private WeightDeviceDataRepository repository; + + @Autowired private WeightDeviceDataMapper mapper; + + @Autowired private ConversionService conversionService; + + @Autowired private DbFunctionService dbFunctionService; + @PersistenceContext + private EntityManager em; + + public WeightDeviceDataDto create(CreateWeightDeviceDataDto request) { + WeightDeviceDataEntity entity = mapper.toEntity(request); + + this.repository.save(entity); + return getById(entity.getId()); + } + + public WeightDeviceDataDto update(UpdateWeightDeviceDataDto request) { + WeightDeviceDataEntity entity = this.repository.get(request.getId()); + ArchiveUtils.checkArchiveStatus( + entity, + WeightDeviceDataEntity::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(), + WeightDeviceDataEntity::getArchiveStatus, + x -> "0", + (e, actual, expected) -> { + throw new BizException("数据 " + "已归档,无法删除"); + }); + this.repository.deleteAllById(request.getIds()); + } + + public WeightDeviceDataDto getById(String id) { + WeightDeviceDataEntity entity = repository.get(id); + + return mapper.toDto(entity); + } + + public Page list(CommonQuery query) { + Page 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, + WeightDeviceDataEntity::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, + WeightDeviceDataEntity::getArchiveStatus, + y -> "1", + (e, actual, expected) -> { + throw new BizException("数据" + "未归档,无法取消归档"); + })) + .peek(x -> x.setArchiveStatus("0")) + .forEach(this.repository::save); + } + + public Page report(WeightDeviceDataReportRequest request) { + + if (StringUtils.isEmpty(request.getTimeDimension())){ + request.setTimeDimension("day"); + } + + String groupSql = + 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(",")); + + String fieldSql = + CollectionUtils.isEmpty(request.getFieldInfos()) + ? " " + : request.getFieldInfos().stream() + .map( + x -> + x.getFunction() + + "( d." + + CaseFormat.UPPER_CAMEL.to( + CaseFormat.LOWER_UNDERSCORE, + x.getFieldName()) + + ") " + + " as " + + x.getFieldName()) + .collect(Collectors.joining(",")); + + String where = "where 1 = 1 "; + + if (request.getStartTime() != null) { + where += " and d.mz_time >= :startTime "; + } + + if (request.getEndTime() != null) { + where += " and d.mz_time <= :endTime "; + } + + if (StringUtils.isNotEmpty(request.getPlateNo())) { + where += " and d.plate_no like :plateNo "; + } + + if (StringUtils.isNotEmpty(request.getSendOrganization())) { + where += " and d.send_organization like :sendOrganization "; + } + + if (StringUtils.isNotEmpty(request.getReceiveOrganization())) { + where += " and d.receive_organization like :receiveOrganization "; + } + + if (StringUtils.isNotEmpty(request.getGoods())) { + where += " and d.goods like :goods "; + } + + if (StringUtils.isNotEmpty(request.getSpecification())) { + where += " and d.specification = :specification "; + } + + 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"; + + var countSql = "select count(1) from (" + sql + ") as t"; + + 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); + + if (request.getStartTime() != null) { + selectQuery.setParameter("startTime", request.getStartTime()); + countQuery.setParameter("startTime", request.getStartTime()); + } + + if (request.getEndTime() != null) { + selectQuery.setParameter("endTime", request.getEndTime()); + countQuery.setParameter("endTime", request.getEndTime()); + } + + + if (StringUtils.isNotEmpty(request.getPlateNo())) { + selectQuery.setParameter("plateNo", "%" + request.getPlateNo() + "%"); + countQuery.setParameter("plateNo", "%" + request.getPlateNo() + "%"); + } + + if (StringUtils.isNotEmpty(request.getSendOrganization())) { + selectQuery.setParameter("sendOrganization", "%" + request.getSendOrganization() + "%"); + countQuery.setParameter("sendOrganization", "%" + request.getSendOrganization() + "%"); + } + + if (StringUtils.isNotEmpty(request.getReceiveOrganization())) { + selectQuery.setParameter("receiveOrganization", "%" + request.getReceiveOrganization() + "%"); + countQuery.setParameter("receiveOrganization", "%" + request.getReceiveOrganization() + "%"); + } + + if (StringUtils.isNotEmpty(request.getGoods())) { + + selectQuery.setParameter("goods", "%" + request.getGoods() + "%"); + countQuery.setParameter("goods", "%" + request.getGoods() + "%"); + } + + if (StringUtils.isNotEmpty(request.getSpecification())) { + selectQuery.setParameter("specification", "%" + request.getSpecification() + "%"); + countQuery.setParameter("specification", "%" + request.getSpecification() + "%"); + } + + + var resultList = JpaUtils.convertTuplesToMap(selectQuery.getResultList()); + + var ans = + resultList.stream() + .map( + x -> + ((Map) x) + .entrySet().stream() + .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())); + } +} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/controller/WeightDeviceSupplierController.java b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/controller/WeightDeviceSupplierController.java new file mode 100644 index 00000000..489cb69e --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/controller/WeightDeviceSupplierController.java @@ -0,0 +1,54 @@ +package cn.lihongjie.coal.weightDeviceSupplier.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.weightDeviceSupplier.dto.CreateWeightDeviceSupplierDto; +import cn.lihongjie.coal.weightDeviceSupplier.dto.UpdateWeightDeviceSupplierDto; +import cn.lihongjie.coal.weightDeviceSupplier.dto.WeightDeviceSupplierDto; +import cn.lihongjie.coal.weightDeviceSupplier.service.WeightDeviceSupplierService; + +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("/weightDeviceSupplier") +@SysLog(module = "地磅厂家") +@Slf4j +@OrgScope +public class WeightDeviceSupplierController { + @Autowired private WeightDeviceSupplierService service; + + @PostMapping("/create") + public WeightDeviceSupplierDto create(@RequestBody CreateWeightDeviceSupplierDto request) { + return this.service.create(request); + } + + @PostMapping("/update") + public WeightDeviceSupplierDto update(@RequestBody UpdateWeightDeviceSupplierDto request) { + return this.service.update(request); + } + + @PostMapping("/delete") + public Object delete(@RequestBody IdRequest request) { + this.service.delete(request); + return true; + } + + @PostMapping("/getById") + public WeightDeviceSupplierDto getById(@RequestBody IdRequest request) { + return this.service.getById(request.getId()); + } + + @PostMapping("/list") + public Page list(@RequestBody CommonQuery request) { + return this.service.list(request); + } +} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/dto/CreateWeightDeviceSupplierDto.java b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/dto/CreateWeightDeviceSupplierDto.java new file mode 100644 index 00000000..a89afc0e --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/dto/CreateWeightDeviceSupplierDto.java @@ -0,0 +1,14 @@ +package cn.lihongjie.coal.weightDeviceSupplier.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class CreateWeightDeviceSupplierDto extends OrgCommonDto { + private String contact; + + private String contactPhone; + + private String address; +} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/dto/UpdateWeightDeviceSupplierDto.java b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/dto/UpdateWeightDeviceSupplierDto.java new file mode 100644 index 00000000..a2b0415f --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/dto/UpdateWeightDeviceSupplierDto.java @@ -0,0 +1,14 @@ +package cn.lihongjie.coal.weightDeviceSupplier.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class UpdateWeightDeviceSupplierDto extends OrgCommonDto { + private String contact; + + private String contactPhone; + + private String address; +} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/dto/WeightDeviceSupplierDto.java b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/dto/WeightDeviceSupplierDto.java new file mode 100644 index 00000000..ba4e8c80 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/dto/WeightDeviceSupplierDto.java @@ -0,0 +1,15 @@ +package cn.lihongjie.coal.weightDeviceSupplier.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +@Data +public class WeightDeviceSupplierDto extends OrgCommonDto { + + private String contact; + + private String contactPhone; + + private String address; +} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/entity/WeightDeviceSupplierEntity.java b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/entity/WeightDeviceSupplierEntity.java new file mode 100644 index 00000000..364092f1 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/entity/WeightDeviceSupplierEntity.java @@ -0,0 +1,19 @@ +package cn.lihongjie.coal.weightDeviceSupplier.entity; + +import cn.lihongjie.coal.base.entity.OrgCommonEntity; + +import jakarta.persistence.Entity; + +import lombok.Data; + +@Data +@Entity +public class WeightDeviceSupplierEntity extends OrgCommonEntity { + + private String contact; + + private String contactPhone; + + private String address; + +} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/mapper/WeightDeviceSupplierMapper.java b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/mapper/WeightDeviceSupplierMapper.java new file mode 100644 index 00000000..2e95d442 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/mapper/WeightDeviceSupplierMapper.java @@ -0,0 +1,23 @@ +package cn.lihongjie.coal.weightDeviceSupplier.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.weightDeviceSupplier.dto.CreateWeightDeviceSupplierDto; +import cn.lihongjie.coal.weightDeviceSupplier.dto.UpdateWeightDeviceSupplierDto; +import cn.lihongjie.coal.weightDeviceSupplier.dto.WeightDeviceSupplierDto; +import cn.lihongjie.coal.weightDeviceSupplier.entity.WeightDeviceSupplierEntity; + +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 WeightDeviceSupplierMapper + extends BaseMapper< + WeightDeviceSupplierEntity, + WeightDeviceSupplierDto, + CreateWeightDeviceSupplierDto, + UpdateWeightDeviceSupplierDto> {} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/repository/WeightDeviceSupplierRepository.java b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/repository/WeightDeviceSupplierRepository.java new file mode 100644 index 00000000..f8a1a27f --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/repository/WeightDeviceSupplierRepository.java @@ -0,0 +1,10 @@ +package cn.lihongjie.coal.weightDeviceSupplier.repository; + +import cn.lihongjie.coal.base.dao.BaseRepository; +import cn.lihongjie.coal.weightDeviceSupplier.entity.WeightDeviceSupplierEntity; + +import org.springframework.stereotype.Repository; + +@Repository +public interface WeightDeviceSupplierRepository + extends BaseRepository {} diff --git a/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/service/WeightDeviceSupplierService.java b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/service/WeightDeviceSupplierService.java new file mode 100644 index 00000000..439f46e2 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/weightDeviceSupplier/service/WeightDeviceSupplierService.java @@ -0,0 +1,74 @@ +package cn.lihongjie.coal.weightDeviceSupplier.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.weightDeviceSupplier.dto.CreateWeightDeviceSupplierDto; +import cn.lihongjie.coal.weightDeviceSupplier.dto.UpdateWeightDeviceSupplierDto; +import cn.lihongjie.coal.weightDeviceSupplier.dto.WeightDeviceSupplierDto; +import cn.lihongjie.coal.weightDeviceSupplier.entity.WeightDeviceSupplierEntity; +import cn.lihongjie.coal.weightDeviceSupplier.mapper.WeightDeviceSupplierMapper; +import cn.lihongjie.coal.weightDeviceSupplier.repository.WeightDeviceSupplierRepository; + +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 WeightDeviceSupplierService + extends BaseService { + @Autowired private WeightDeviceSupplierRepository repository; + + @Autowired private WeightDeviceSupplierMapper mapper; + + @Autowired private ConversionService conversionService; + + @Autowired private DbFunctionService dbFunctionService; + + public WeightDeviceSupplierDto create(CreateWeightDeviceSupplierDto request) { + WeightDeviceSupplierEntity entity = mapper.toEntity(request); + + this.repository.save(entity); + return getById(entity.getId()); + } + + public WeightDeviceSupplierDto update(UpdateWeightDeviceSupplierDto request) { + WeightDeviceSupplierEntity 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 WeightDeviceSupplierDto getById(String id) { + WeightDeviceSupplierEntity entity = repository.get(id); + + return mapper.toDto(entity); + } + + public Page list(CommonQuery query) { + Page page = + repository.findAll( + query.specification(conversionService), + PageRequest.of( + query.getPageNo(), + query.getPageSize(), + Sort.by(query.getOrders()))); + + return page.map(this.mapper::toDto); + } +} diff --git a/src/main/resources/scripts/dict/enum/weightDeviceDataDict.groovy b/src/main/resources/scripts/dict/enum/weightDeviceDataDict.groovy new file mode 100644 index 00000000..7a38d2b7 --- /dev/null +++ b/src/main/resources/scripts/dict/enum/weightDeviceDataDict.groovy @@ -0,0 +1,17 @@ + +package scripts.dict + +import cn.lihongjie.coal.base.dto.CommonQuery +import cn.lihongjie.coal.weightDeviceData.controller.WeightDeviceDataController +import org.springframework.context.ApplicationContext + +ApplicationContext ioc = ioc + +def controller = ioc.getBean(WeightDeviceDataController.class) + + + + +return controller.list(new CommonQuery()) + + diff --git a/src/main/resources/scripts/dict/enum/weightDeviceDict.groovy b/src/main/resources/scripts/dict/enum/weightDeviceDict.groovy new file mode 100644 index 00000000..d16a18ca --- /dev/null +++ b/src/main/resources/scripts/dict/enum/weightDeviceDict.groovy @@ -0,0 +1,17 @@ + +package scripts.dict + +import cn.lihongjie.coal.base.dto.CommonQuery +import cn.lihongjie.coal.weightDevice.controller.WeightDeviceController +import org.springframework.context.ApplicationContext + +ApplicationContext ioc = ioc + +def controller = ioc.getBean(WeightDeviceController.class) + + + + +return controller.list(new CommonQuery()) + + diff --git a/src/main/resources/scripts/dict/enum/weightDeviceSupplierDict.groovy b/src/main/resources/scripts/dict/enum/weightDeviceSupplierDict.groovy new file mode 100644 index 00000000..0883addc --- /dev/null +++ b/src/main/resources/scripts/dict/enum/weightDeviceSupplierDict.groovy @@ -0,0 +1,17 @@ + +package scripts.dict + +import cn.lihongjie.coal.base.dto.CommonQuery +import cn.lihongjie.coal.weightDeviceSupplier.controller.WeightDeviceSupplierController +import org.springframework.context.ApplicationContext + +ApplicationContext ioc = ioc + +def controller = ioc.getBean(WeightDeviceSupplierController.class) + + + + +return controller.list(new CommonQuery()) + +