From e95de698a8a0619ede3d5b672ebaf24cac321297 Mon Sep 17 00:00:00 2001 From: jiazx0107@163.com <jiazx0107@163.com> Date: 星期二, 31 十月 2023 04:08:38 +0800 Subject: [PATCH] 四川省网关接口相关10 --- src/main/java/com/fzzy/gateway/hx2023/data/GrainData.java | 24 + src/main/java/com/fzzy/gateway/hx2023/kafka/package-info.java | 1 src/main/java/com/fzzy/gateway/api/DeviceReportService.java | 9 src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java | 194 +++++++++++++++++ src/main/java/com/fzzy/async/fzzy40/Fzzy40CommonService.java | 35 +++ src/main/java/com/fzzy/gateway/hx2023/ScConstant.java | 5 src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml | 46 ++- src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1302Rep.java | 14 + pom.xml | 11 src/main/java/com/fzzy/api/data/GatewayDeviceType.java | 4 src/main/java/com/fzzy/conf/MyPartitionTemplate.java | 65 +++++ src/main/java/com/fzzy/gateway/entity/GatewayDevice.java | 14 src/main/java/com/fzzy/api/data/GatewayProtocol.java | 2 src/main/java/com/fzzy/gateway/data/QueryParam.java | 16 + src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReport.java | 62 +++++ src/main/java/com/fzzy/gateway/hx2023/controller/GatewayController.java | 2 src/main/java/com/fzzy/gateway/hx2023/data/GrainDataDetail.java | 32 ++ src/main/java/com/fzzy/gateway/view/GatewayConf.view.xml | 80 ++++++- src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java | 2 src/main/resources/application-dev.yml | 25 ++ src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java | 10 21 files changed, 598 insertions(+), 55 deletions(-) diff --git a/pom.xml b/pom.xml index ed3c9be..d5e0c5b 100644 --- a/pom.xml +++ b/pom.xml @@ -145,11 +145,12 @@ <version>${spring.boot.version}</version> </dependency> -<!-- <dependency>--> -<!-- <groupId>org.springframework.kafka</groupId>--> -<!-- <artifactId>spring-kafka</artifactId>--> -<!-- <version>${spring.boot.version}</version>--> -<!-- </dependency>--> + <!-- kafka --> + <dependency> + <groupId>org.springframework.kafka</groupId> + <artifactId>spring-kafka</artifactId> + <version>2.2.1.RELEASE</version> + </dependency> <dependency> <groupId>net.sourceforge.nekohtml</groupId> diff --git a/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java b/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java index e87c538..3b8b65c 100644 --- a/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java +++ b/src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java @@ -12,6 +12,7 @@ public enum GatewayDeviceProtocol { GRAIN_FZZY_ZH_2023("GRAIN_FZZY_ZH_2023", "绮儏-椋庢鑷磋繙鎺у埗鏌滃崗璁�2023"), + GRAIN_FZZY_IGDS_V40("GRAIN_FZZY_IGDS_V40", "绮儏-椋庢鑷磋繙绯荤粺V40"), DEVICE_WEIGHT_HTTP("DEVICE_WEIGHT_HTTP", "鍦扮-HTTP鍗忚"), DEVICE_WEIGHT_TCP_YH("DEVICE_WEIGHT_TCP_YH", "鍦扮-鑰�鍗嶵CP鍗忚"), DEVICE_IDCARD_HTTP("DEVICE_IDCARD_HTTP", "韬唤璇�-HTTP鍗忚"), @@ -26,6 +27,7 @@ public static List<ApiTrigger> listTrigger() { List<ApiTrigger> list = new ArrayList<>(); list.add(new ApiTrigger(GRAIN_FZZY_ZH_2023.getCode(), GRAIN_FZZY_ZH_2023.getName())); + list.add(new ApiTrigger(GRAIN_FZZY_IGDS_V40.getCode(), GRAIN_FZZY_IGDS_V40.getName())); list.add(new ApiTrigger(DEVICE_WEIGHT_HTTP.getCode(), DEVICE_WEIGHT_HTTP.getName())); list.add(new ApiTrigger(DEVICE_WEIGHT_TCP_YH.getCode(), DEVICE_WEIGHT_TCP_YH.getName())); list.add(new ApiTrigger(DEVICE_IDCARD_HTTP.getCode(), DEVICE_IDCARD_HTTP.getName())); diff --git a/src/main/java/com/fzzy/api/data/GatewayDeviceType.java b/src/main/java/com/fzzy/api/data/GatewayDeviceType.java index afbafce..41243a7 100644 --- a/src/main/java/com/fzzy/api/data/GatewayDeviceType.java +++ b/src/main/java/com/fzzy/api/data/GatewayDeviceType.java @@ -16,8 +16,9 @@ TYPE_03("TYPE_03", "閬撻椄"), TYPE_04("TYPE_04", "LED"), TYPE_05("TYPE_05", "鎵︽牱鏈�"), - TYPE_06("TYPE_06", "鎽勫儚澶�"), + TYPE_06("TYPE_06", "瑙嗛瀹夐槻鎽勫儚澶�"), TYPE_07("TYPE_07", "绮儏鍒嗘満"), + TYPE_08("TYPE_08", "妗岄潰鎶撴媿鎽勫儚澶�"), TYPE_99("TYPE_99", "鐙珛IOT"); @@ -34,6 +35,7 @@ list.add(new ApiTrigger(TYPE_05.getCode(), TYPE_05.getName())); list.add(new ApiTrigger(TYPE_06.getCode(), TYPE_06.getName())); list.add(new ApiTrigger(TYPE_07.getCode(), TYPE_07.getName())); + list.add(new ApiTrigger(TYPE_08.getCode(), TYPE_08.getName())); list.add(new ApiTrigger(TYPE_99.getCode(), TYPE_99.getName())); return list; } diff --git a/src/main/java/com/fzzy/api/data/GatewayProtocol.java b/src/main/java/com/fzzy/api/data/GatewayProtocol.java index 44e65ba..a0debc9 100644 --- a/src/main/java/com/fzzy/api/data/GatewayProtocol.java +++ b/src/main/java/com/fzzy/api/data/GatewayProtocol.java @@ -14,7 +14,7 @@ GATE_WEBSOCKET("GATE_WEBSOCKET", "webSocket"), GATE_MQTT("GATE_MQTT", "MQTT"), GATE_HTTP("GATE_HTTP", "HTTP"), - GATE_TEST("GATE_TEST", "娴嬭瘯"); + GATE_TEST("GATE_TEST", "婕旂ず娴嬭瘯"); private String code; diff --git a/src/main/java/com/fzzy/async/fzzy40/Fzzy40CommonService.java b/src/main/java/com/fzzy/async/fzzy40/Fzzy40CommonService.java new file mode 100644 index 0000000..41e8bef --- /dev/null +++ b/src/main/java/com/fzzy/async/fzzy40/Fzzy40CommonService.java @@ -0,0 +1,35 @@ +package com.fzzy.async.fzzy40; + +import com.fzzy.async.fzzy40.entity.Fz40Grain; +import com.fzzy.async.fzzy40.repository.Fzzy40Sync1302Rep; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * 2023骞�10鏈�31鏃� 02:28:21 ANDY澧炲姞鐢ㄤ簬鑷敱鎺ュ彛璋冪敤锛屽鍏朵粬妯″潡璋冪敤 + */ +@Component +public class Fzzy40CommonService { + + + @Resource + private Fzzy40Sync1302Rep fzzy40Sync1302Rep; + + + /** + * 鏍规嵁寮�鏃堕棿鍜屾埅鑷虫椂闂磋幏鍙栫伯鎯呬俊鎭� + * + * @param depotId 绯荤粺涓殑浠撳簱缂栫爜 + * @param start + * @param end + * @return + */ + public List<Fz40Grain> listGrain(String depotId, Date start, Date end) { + return fzzy40Sync1302Rep.findByReceiveDate(depotId, start, end); + } + + +} diff --git a/src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1302Rep.java b/src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1302Rep.java index 7508ff8..5c2adf2 100644 --- a/src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1302Rep.java +++ b/src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1302Rep.java @@ -1,6 +1,5 @@ package com.fzzy.async.fzzy40.repository; -import com.fzzy.async.fzzy35.entity.Fz35Grain; import com.fzzy.async.fzzy40.entity.Fz40Grain; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -19,10 +18,23 @@ /** * 鏍规嵁鏃堕棿娈垫煡璇㈢伯鎯呮暟鎹� + * * @param start * @param end * @return */ @Query("from Fz40Grain where receiveDate >=:start and receiveDate <:end order by receiveDate ") List<Fz40Grain> findByReceiveDate(@Param("start") Date start, @Param("end") Date end); + + + /** + * 鏍规嵁鏃堕棿娈垫煡璇㈢伯鎯呮暟鎹� + * + * @param depotId + * @param start + * @param end + * @return + */ + @Query("from Fz40Grain where depotId =:depotId and receiveDate >=:start and receiveDate <:end order by receiveDate ") + List<Fz40Grain> findByReceiveDate(@Param("depotId") String depotId, @Param("start") Date start, @Param("end") Date end); } diff --git a/src/main/java/com/fzzy/conf/MyPartitionTemplate.java b/src/main/java/com/fzzy/conf/MyPartitionTemplate.java new file mode 100644 index 0000000..de6e212 --- /dev/null +++ b/src/main/java/com/fzzy/conf/MyPartitionTemplate.java @@ -0,0 +1,65 @@ +package com.fzzy.conf; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.core.DefaultKafkaProducerFactory; +import org.springframework.kafka.core.KafkaTemplate; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +/** + * 鑷畾涔夐厤缃被 + */ +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "spring.kafka") +public class MyPartitionTemplate { + + private String bootstrapServers; + + + private String securityProtocol; + + + private String saslMechanism; + + + private String saslJaasConfig; + + + private String saslUsername; + + + private String saslPassword; + + KafkaTemplate<String, String> kafkaTemplate; + + @PostConstruct + public void setKafkaTemplate() { + Map<String, Object> props = new HashMap<>(); + + props.put("bootstrap.servers", bootstrapServers); + props.put("security.protocol", securityProtocol); + props.put("sasl.mechanism", saslMechanism); + + if (StringUtils.isNotEmpty(saslUsername) && StringUtils.isNotEmpty(saslPassword)) { + saslJaasConfig = saslJaasConfig.replace("{username}", saslUsername) + .replace("{password}", saslPassword); + props.put("sasl.jaas.config", saslJaasConfig); + + log.debug("----sasl.jaas.config---{}", saslJaasConfig); + } + + this.kafkaTemplate = new KafkaTemplate<>(new DefaultKafkaProducerFactory<>(props)); + } + + public KafkaTemplate<String, String> getKafkaTemplate() { + return kafkaTemplate; + } + +} diff --git a/src/main/java/com/fzzy/gateway/api/DeviceReportService.java b/src/main/java/com/fzzy/gateway/api/DeviceReportService.java index 0481757..a5e5aaf 100644 --- a/src/main/java/com/fzzy/gateway/api/DeviceReportService.java +++ b/src/main/java/com/fzzy/gateway/api/DeviceReportService.java @@ -1,6 +1,7 @@ package com.fzzy.gateway.api; import com.fzzy.gateway.entity.GatewayDevice; +import com.fzzy.gateway.hx2023.data.GrainData; public interface DeviceReportService { @@ -21,4 +22,12 @@ */ String report2GatewayBySn(double weigh, GatewayDevice device); + + /** + * 绮儏鏁版嵁鎺ㄥ姩鍒颁簯绔郴缁� + * @param data + * @return + */ + String pushGrainData2Cloud(GrainData data); + } diff --git a/src/main/java/com/fzzy/gateway/data/QueryParam.java b/src/main/java/com/fzzy/gateway/data/QueryParam.java new file mode 100644 index 0000000..39e8fe0 --- /dev/null +++ b/src/main/java/com/fzzy/gateway/data/QueryParam.java @@ -0,0 +1,16 @@ +package com.fzzy.gateway.data; + +import java.util.Date; + +import lombok.Data; + +@Data +public class QueryParam { + + private Date start; + + private Date end; + + private Date dayTime; + +} diff --git a/src/main/java/com/fzzy/gateway/entity/GatewayDevice.java b/src/main/java/com/fzzy/gateway/entity/GatewayDevice.java index 1e9c529..32531b0 100644 --- a/src/main/java/com/fzzy/gateway/entity/GatewayDevice.java +++ b/src/main/java/com/fzzy/gateway/entity/GatewayDevice.java @@ -25,7 +25,7 @@ @PropertyDef(label = "绯荤粺ID") private String id; - @Column(name = "DEVICE_SN_", length = 50) + @Column(name = "DEVICE_SN_", length = 100) @PropertyDef(label = "璁惧搴忓垪鍙�") private String deviceSn; @@ -42,12 +42,16 @@ private String type; @Column(name = "DEPOT_ID_", length = 30) - @PropertyDef(label = "鎵�灞炰粨搴�") + @PropertyDef(label = "浠撳簱缂栫爜") private String depotId; @Column(name = "DEPOT_NAME_", length = 50) - @PropertyDef(label = "鎵�灞炰粨搴�") + @PropertyDef(label = "浠撳簱鍚嶇О") private String depotName; + + @Column(name = "DEPOT_ID_SYS_", length = 30) + @PropertyDef(label = "搴撳尯绯荤粺浠撳簱缂栫爜") + private String depotIdSys; @Column(name = "IP_", length = 20) @PropertyDef(label = "閫氳IP") @@ -58,11 +62,11 @@ private Integer port; @PropertyDef(label = "璁惧鐢ㄦ埛鍚�") - @Column(name = "username", length = 50) + @Column(name = "USERNAME_", length = 50) private String userName; @PropertyDef(label = "璁惧瀵嗙爜") - @Column(name = "password", length = 50) + @Column(name = "PASSWORD_", length = 50) private String password; @Column(name = "RTSP_", length = 100) diff --git a/src/main/java/com/fzzy/gateway/hx2023/ScConstant.java b/src/main/java/com/fzzy/gateway/hx2023/ScConstant.java index 7582ed4..11c5db1 100644 --- a/src/main/java/com/fzzy/gateway/hx2023/ScConstant.java +++ b/src/main/java/com/fzzy/gateway/hx2023/ScConstant.java @@ -1,5 +1,7 @@ package com.fzzy.gateway.hx2023; +import org.apache.commons.lang.math.RandomUtils; + /** * 甯搁噺 */ @@ -11,4 +13,7 @@ public static String MESSAGE_TYPE_REPORT_PROPERTY = "REPORT_PROPERTY"; + public static String getMessageId() { + return System.currentTimeMillis() + RandomUtils.nextInt(1000) + ""; + } } diff --git a/src/main/java/com/fzzy/gateway/hx2023/controller/GatewayController.java b/src/main/java/com/fzzy/gateway/hx2023/controller/GatewayController.java index a5692e3..a6d3166 100644 --- a/src/main/java/com/fzzy/gateway/hx2023/controller/GatewayController.java +++ b/src/main/java/com/fzzy/gateway/hx2023/controller/GatewayController.java @@ -7,11 +7,9 @@ import com.fzzy.gateway.hx2023.data.GatewayAuthData; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; -import org.springframework.stereotype.Repository; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; /** * diff --git a/src/main/java/com/fzzy/gateway/hx2023/data/GrainData.java b/src/main/java/com/fzzy/gateway/hx2023/data/GrainData.java index 3593f17..c51084a 100644 --- a/src/main/java/com/fzzy/gateway/hx2023/data/GrainData.java +++ b/src/main/java/com/fzzy/gateway/hx2023/data/GrainData.java @@ -2,36 +2,48 @@ import lombok.Data; +import java.util.List; + /** * 绮儏淇℃伅 */ @Data public class GrainData { + //娑堟伅 ID private String messageId; + //璁惧缂栫爜 private String deviceId; + //鏁翠粨骞冲潎娓╁害 private String avgTemperature; + //鏁翠粨鏈�浣庢俯搴� private String minTemperature; + //鏁翠粨鏈�楂樻俯搴� private String maxTemperature; + //妫�娴嬫椂闂�-鏍煎紡锛歽yyy-MM-dd HH:mm:ss private String collectTime; - private String minX; + private String minX = "0"; - private String minY; + private String minY = "0"; - private String minZ; + private String minZ = "0"; - private String maxX; + private String maxX = "0"; - private String maxY; + private String maxY = "0"; - private String maxZ; + private String maxZ = "0"; + //妯″潡璇嗗埆鐮�-甯搁噺锛屽浐瀹氫紶 apiTemperature private String apISource = "apiTemperature"; + //绮俯璇︾粏 + private List<GrainDataDetail> temperature; + } diff --git a/src/main/java/com/fzzy/gateway/hx2023/data/GrainDataDetail.java b/src/main/java/com/fzzy/gateway/hx2023/data/GrainDataDetail.java new file mode 100644 index 0000000..f28ab6e --- /dev/null +++ b/src/main/java/com/fzzy/gateway/hx2023/data/GrainDataDetail.java @@ -0,0 +1,32 @@ +package com.fzzy.gateway.hx2023.data; + +import lombok.Data; + +/** + * 绮儏淇℃伅璇︾粏 + */ +@Data +public class GrainDataDetail { + + //鏍瑰彿 + private int cableNum; + + //灞傚彿 + private int layerNumber; + + //绱㈠紩 + private int position; + + //娓╁害鍊� + private String temperature; + + public GrainDataDetail() { + } + + public GrainDataDetail(int cableNum, int layerNumber, int position, String temperature) { + this.cableNum = cableNum; + this.layerNumber = layerNumber; + this.position = position; + this.temperature = temperature; + } +} diff --git a/src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReport.java b/src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReport.java new file mode 100644 index 0000000..92d1ed7 --- /dev/null +++ b/src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReport.java @@ -0,0 +1,62 @@ +package com.fzzy.gateway.hx2023.kafka; + +import com.alibaba.fastjson2.JSONObject; +import com.fzzy.gateway.hx2023.data.GrainData; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + + +/** + * 浣跨敤KAFKA鎺ㄥ姩杩斿洖淇℃伅瀹炵幇锛岄拡瀵瑰綋鍓嶇綉鍏� + */ +@Slf4j +@Component +public class KafkaDeviceReport { + + + @Resource + private KafkaTemplate<String, Object> kafkaTemplate; + + /** + * 鎺ㄥ姩绮儏鍒颁簯绔郴缁� + * + * @param data + * @return + */ + public String sendGrainData2Cloud(GrainData data) { + + + log.debug("----鎺ㄩ�佺伯鎯呬俊鎭埌浜戠---{}",data); + + //鎺ㄩ�佷俊鎭� + kafkaTemplate.send("TOPIC_ZLJ_GRAIN_TEMPERATURE",JSONObject.toJSONString(data)).addCallback(success -> { + // 娑堟伅鍙戦�佸埌鐨則opic + String topic = success.getRecordMetadata().topic(); + // 娑堟伅鍙戦�佸埌鐨勫垎鍖� + int partition = success.getRecordMetadata().partition(); + // 娑堟伅鍦ㄥ垎鍖哄唴鐨刼ffset + long offset = success.getRecordMetadata().offset(); + + log.info("绮儏鎺ㄩ�佹垚鍔�:" + topic + "-" + partition + "-" + offset); + }, failure -> { + log.error("绮儏鎺ㄩ�佸け璐�:" + failure.getMessage()); + }); + + + return "SUCCESS"; + + } + + @KafkaListener(topics = {"TOPIC_ZLJ_GRAIN_TEMPERATURE"}) + public void onMessage1(ConsumerRecord<?, ?> record) { + log.info("鑾峰彇娑堣垂淇℃伅锛�" + record.topic() + "-" + record.partition() + "-" + record.value()); + } + +} diff --git a/src/main/java/com/fzzy/gateway/hx2023/kafka/package-info.java b/src/main/java/com/fzzy/gateway/hx2023/kafka/package-info.java new file mode 100644 index 0000000..a6362c0 --- /dev/null +++ b/src/main/java/com/fzzy/gateway/hx2023/kafka/package-info.java @@ -0,0 +1 @@ +package com.fzzy.gateway.hx2023.kafka; \ No newline at end of file diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java b/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java index 4cca0c6..6051cb7 100644 --- a/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java +++ b/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java @@ -6,9 +6,11 @@ import com.fzzy.gateway.api.DeviceReportService; import com.fzzy.gateway.entity.GatewayDevice; import com.fzzy.gateway.hx2023.ScConstant; +import com.fzzy.gateway.hx2023.data.GrainData; import com.fzzy.gateway.hx2023.data.WebSocketPacket; import com.fzzy.gateway.hx2023.data.WebSocketPacketHeader; import com.fzzy.gateway.hx2023.data.WeightInfo; +import com.fzzy.gateway.hx2023.kafka.KafkaDeviceReport; import com.fzzy.gateway.hx2023.websocket.WebSocketDeviceReport; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -22,6 +24,8 @@ @Resource private WebSocketDeviceReport webSocketDeviceReport; + @Resource + private KafkaDeviceReport kafkaDeviceReport; @Override public String getProvinceProtocol() { @@ -71,4 +75,10 @@ return null; } + + @Override + public String pushGrainData2Cloud(GrainData data) { + + return kafkaDeviceReport.sendGrainData2Cloud(data); + } } diff --git a/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java b/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java index fd196ab..32656b2 100644 --- a/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java +++ b/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java @@ -4,24 +4,44 @@ import com.bstek.dorado.annotation.DataResolver; import com.bstek.dorado.annotation.Expose; import com.fzzy.api.utils.ContextUtil; -import com.fzzy.api.utils.RedisConst; -import com.fzzy.api.utils.RedisUtil; +import com.fzzy.api.utils.DateUtil; +import com.fzzy.async.fzzy40.Fzzy40CommonService; +import com.fzzy.async.fzzy40.entity.Fz40Grain; import com.fzzy.gateway.GatewayUtils; +import com.fzzy.gateway.api.DeviceReportService; +import com.fzzy.gateway.api.GatewayRemoteManager; +import com.fzzy.gateway.data.QueryParam; import com.fzzy.gateway.entity.GatewayDevice; +import com.fzzy.gateway.hx2023.ScConstant; +import com.fzzy.gateway.hx2023.data.GrainData; +import com.fzzy.gateway.hx2023.data.GrainDataDetail; import com.fzzy.gateway.service.repository.GatewayDeviceRep; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.time.DateFormatUtils; import org.springframework.beans.BeanUtils; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Component; import javax.annotation.Resource; -import java.util.HashMap; + +import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; +@Slf4j @Component public class GatewayDeviceService { @Resource private GatewayDeviceRep gatewayDeviceRep; + @Resource + private Fzzy40CommonService fzzy40CommonService; + @Resource + private GatewayRemoteManager gatewayRemoteManager; /** * gatewayDeviceService#listAll @@ -30,7 +50,8 @@ */ @DataProvider public List<GatewayDevice> listAll() { - return gatewayDeviceRep.findAll(); + Sort sort = new Sort(Sort.Direction.ASC, "deviceId"); + return gatewayDeviceRep.findAll(sort); } /** @@ -90,4 +111,169 @@ GatewayUtils.add2Cache(device); } } + + + /** + * gatewayDeviceService#ajaxTestGrain + * 绮儏鎺ㄩ�佹祴璇� + * + * @param param + * @return + */ + @Expose + public String ajaxTestGrain(Map<String,Object> parameter) { + + //鑾峰彇璁惧閰嶇疆锛屽彧閽堝绮儏璁惧杩涜鎵ц + + List<GatewayDevice> list = this.listAll(); + + if (null == list || list.isEmpty()) { + return "ERROR锛氫负鑾峰彇鍒扮郴缁熶腑璁惧閰嶇疆锛屽彇娑堟墽琛�"; + } + + Date dayTime = (Date) parameter.get("dayTime"); + if (null == dayTime) dayTime = new Date(); + QueryParam param = new QueryParam(); + param.setDayTime(dayTime); + param.setStart(DateUtil.getCurZero(dayTime)); + param.setEnd(DateUtil.getNextZero(dayTime)); + + + //濡傛灉閮ㄧ讲FZZY-IGDS-V40鐗堟湰绯荤粺 + return this.pushByV40(list, param); + + } + + private String pushByV40(List<GatewayDevice> list, QueryParam param) { + + String depotIdSys; + List<Fz40Grain> listGrain; + + Fz40Grain lastData; + + GrainData pushData; + + DeviceReportService deviceReportService = null; + for (GatewayDevice device : list) { + depotIdSys = device.getDepotIdSys(); + + if (StringUtils.isEmpty(depotIdSys)) { + log.info("--------璁惧--{}-鏈厤缃郴缁熺浉鍏充粨搴撶紪鐮侊紝鏃犳硶鎵ц褰撳墠鎿嶄綔",device.getDeviceName()); + continue; + } + + listGrain = fzzy40CommonService.listGrain(depotIdSys, param.getStart(), param.getEnd()); + + if (null == listGrain || listGrain.isEmpty()) { + log.info("---------璁惧---{}--鏈悓姝ュ埌绮儏淇℃伅锛岃纭褰撳墠鏉′欢涓嬫槸鍚︽湁鏁版嵁",device.getDeviceName()); + continue; + } + + + //鑾峰彇鏈�鍚庝竴鏉$伯鎯呬綔涓哄綋鍓嶆暟鎹� + lastData = listGrain.get(listGrain.size() - 1); + + pushData = this.lastData2PushData(lastData, device); + + + if (null == deviceReportService) { + deviceReportService = gatewayRemoteManager.getDeviceReportService(device.getProvinceProtocol()); + } + + + deviceReportService.pushGrainData2Cloud(pushData); + + } + + return "SUCCESS"; + } + + /** + * 灏嗙伯鎯呮暟鎹浆鎹负鎺ㄩ�侀渶瑕佺殑鏁版嵁鏍煎紡 + * + * @param lastData + * @return + */ + private GrainData lastData2PushData(Fz40Grain lastData, GatewayDevice device) { + GrainData result = new GrainData(); + + result.setMessageId(ScConstant.getMessageId()); + result.setDeviceId(device.getDeviceId()); + result.setAvgTemperature(lastData.getTempAve() + ""); + result.setMinTemperature(lastData.getTempMin() + ""); + result.setMaxTemperature(lastData.getTempMax() + ""); + result.setCollectTime(DateFormatUtils.format(lastData.getReceiveDate(), "yyyy-MM-dd HH:mm:ss")); + + //灞�-琛�-鍒� + String[] attrCable = lastData.getCable().split("-"); + + //灞傞厤缃� + int layMax = Integer.valueOf(attrCable[0]); + + //閽堝绛掍粨閰嶇疆 + String[] cableCirAtt = new String[0]; + if (StringUtils.isNotEmpty(lastData.getCableCir())) { + cableCirAtt = lastData.getCableCir().split("-"); + } + + //娓╁害闆嗗悎 + String[] attr = lastData.getPoints().split(","); + + //鏍瑰彿 + int cableNum = 1, layerNumber = 1, position = 0; + + int curCir = 1;//鎵�鍦ㄥ湀 + int cirLay = 1;//褰撳墠鍦堢殑灞� + String curTemp; + List<GrainDataDetail> details = new ArrayList<>(); + for (int i = 0; i < attr.length; i++) { + position = i; + curTemp = attr[i]; + //鏍瑰彿 + cableNum = (i / layMax) + 1; + layerNumber = (i % layMax) + 1; + + if (cableCirAtt.length > 0) { + curCir = getCurCir(cableNum, attrCable); + cirLay = Integer.valueOf(cableCirAtt[curCir - 1]); + + details.add(new GrainDataDetail(cableNum, cirLay, position, curTemp)); + } else { + + //鍒ゆ柇鏈�澶� TODO 寰呬紭鍖� + if (curTemp.equals(result.getMaxTemperature())) { + result.setMaxX(cableNum + ""); + result.setMaxZ(curTemp); + } + + + //鍒ゆ柇鏈�灏� TODO 寰呬紭鍖� + if (curTemp.equals(result.getMinTemperature())) { + result.setMinX(cableNum + ""); + result.setMinZ(curTemp); + } + + + + details.add(new GrainDataDetail(cableNum, layerNumber, position, curTemp)); + } + + } + + result.setTemperature(details); + + return result; + } + + private int getCurCir(int curRoot, String[] cableRuleAtt) { + + int sum = 0; + for (int i = 0; i < cableRuleAtt.length; i++) { + sum += Integer.valueOf(cableRuleAtt[i]); + if (curRoot <= sum) return i + 1; + } + + return 1; + } + } diff --git a/src/main/java/com/fzzy/gateway/view/GatewayConf.view.xml b/src/main/java/com/fzzy/gateway/view/GatewayConf.view.xml index 131ebaa..fb93759 100644 --- a/src/main/java/com/fzzy/gateway/view/GatewayConf.view.xml +++ b/src/main/java/com/fzzy/gateway/view/GatewayConf.view.xml @@ -24,11 +24,11 @@ <Property name="label">缃戝叧ID</Property> </PropertyDef> <PropertyDef name="gatewayUsername"> - <Property/> + <Property></Property> <Property name="label">缃戝叧鐢ㄦ埛鍚�</Property> </PropertyDef> <PropertyDef name="gatewayPassword"> - <Property/> + <Property></Property> <Property name="label">缃戝叧瀵嗙爜</Property> </PropertyDef> <PropertyDef name="gatewayIp"> @@ -86,12 +86,28 @@ <Property name="label">绮簱绯荤粺涓簱鍖虹紪鐮�</Property> </PropertyDef> </DataType> + <DataType name="dtParam" parent="Map"> + <PropertyDef name="start"> + <Property name="dataType">Date</Property> + </PropertyDef> + <PropertyDef name="end"> + <Property name="dataType">Date</Property> + </PropertyDef> + <PropertyDef name="dayTime"> + <Property name="dataType">Date</Property> + <Property name="label">閫夋嫨鏃堕棿</Property> + </PropertyDef> + </DataType> </Model> <View layout="regionPadding:10"> <Property name="packages">font-awesome,css-common</Property> <DataSet id="dsMain"> <Property name="dataType">[dtMain]</Property> <Property name="dataProvider">gatewayConfService#listAll</Property> + </DataSet> + <DataSet id="dsQuery"> + <ClientEvent name="onReady">self.insert({});</ClientEvent> + <Property name="dataType">dtParam</Property> </DataSet> <ToolBar> <ToolBarLabel> @@ -107,14 +123,6 @@ <Property name="iconClass">fa fa-plus</Property> <Property name="width">90</Property> <Property name="exClassName">toolbar-button</Property> - </ToolBarButton> - <ToolBarButton> - <ClientEvent name="onClick">view.get("#dsMain").flushAsync();
 -</ClientEvent> - <Property name="caption">鍒锋柊</Property> - <Property name="iconClass">fa fa-search</Property> - <Property name="width">100</Property> - <Property name="exClassName">toolbar-button-push</Property> </ToolBarButton> <ToolBarButton> <ClientEvent name="onClick">var cur = view.get("#dgMain").getCurrentItem();
 @@ -144,6 +152,13 @@ <Property name="width">90</Property> <Property name="exClassName">toolbar-button-warn</Property> </ToolBarButton> + <Separator/> + <ToolBarButton> + <ClientEvent name="onClick">view.get("#dialogGrain").show();</ClientEvent> + <Property name="caption">绮儏鎺ㄩ�佹祴璇�</Property> + <Property name="iconClass">fa fa-search</Property> + <Property name="exClassName">toolbar-button-push</Property> + </ToolBarButton> </ToolBar> <DataGrid id="dgMain"> <Property name="dataSet">dsMain</Property> @@ -162,6 +177,13 @@ <Property name="name">grade</Property> <Property name="width">200</Property> </DataColumn> + <DataColumn name="gatewayId"> + <Property name="property">gatewayId</Property> + <Property name="width">300</Property> + </DataColumn> + <DataColumn name="gatewayUsername"> + <Property name="property">gatewayUsername</Property> + </DataColumn> <DataColumn name="userName"> <Property name="property">userName</Property> </DataColumn> @@ -170,9 +192,6 @@ </DataColumn> <DataColumn name="exeTag"> <Property name="property">exeTag</Property> - </DataColumn> - <DataColumn name="deptId"> - <Property name="property">deptId</Property> </DataColumn> </DataGrid> <Dialog id="dialogMain"> @@ -321,5 +340,40 @@ <Property name="service">gatewayConfService#pushData</Property> <Property name="confirmMessage">纭畾瑕佷笂鎶ヤ箞锛�</Property> </AjaxAction> + <Dialog id="dialogGrain"> + <Property name="width">400</Property> + <Property name="height">300</Property> + <Property name="caption">閫夋嫨鏉′欢</Property> + <Buttons> + <Button> + <ClientEvent name="onClick">var data = view.get("#dsQuery.data");
 +view.get("#ajaxTestGrain").set("parameter",data.toJSON()).execute(function(result){
 + self.get("parent").hide();
 + $alert(result);
 +});</ClientEvent> + <Property name="caption">纭畾鎵ц</Property> + </Button> + <Button> + <ClientEvent name="onClick">view.get("parent").hide();</ClientEvent> + <Property name="caption">鍙栨秷鎵ц</Property> + </Button> + </Buttons> + <Children> + <AutoForm> + <Property name="dataSet">dsQuery</Property> + <Property name="cols">*</Property> + <AutoFormElement> + <Property name="name">dayTime</Property> + <Property name="property">dayTime</Property> + <Editor/> + </AutoFormElement> + </AutoForm> + </Children> + <Tools/> + </Dialog> + <AjaxAction id="ajaxTestGrain"> + <Property name="service">gatewayDeviceService#ajaxTestGrain</Property> + <Property name="executingMessage">鍦ㄥ姫鍔涙墽琛屼腑鈥︹��</Property> + </AjaxAction> </View> </ViewConfig> diff --git a/src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml b/src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml index 5be2641..fc41c88 100644 --- a/src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml +++ b/src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml @@ -16,8 +16,16 @@ </PropertyDef> <PropertyDef name="deviceName"> <Property></Property> - <Property name="label">鍚嶇О</Property> + <Property name="label">璁惧鍚嶇О</Property> <Property name="required">true</Property> + </PropertyDef> + <PropertyDef name="depotName"> + <Property></Property> + <Property name="label">浠撳簱鍚嶇О</Property> + </PropertyDef> + <PropertyDef name="depotId"> + <Property></Property> + <Property name="label">鎵�灞炰粨搴撶紪鐮�</Property> </PropertyDef> <PropertyDef name="type"> <Property></Property> @@ -27,10 +35,6 @@ <Property name="valueProperty">name</Property> <Property name="mapValues">${dorado.getDataProvider("apiTriggerService#triggerGatewayDeviceType").getResult()}</Property> </Property> - </PropertyDef> - <PropertyDef name="depotId"> - <Property></Property> - <Property name="label">鎵�灞炰粨搴撶紪鐮�</Property> </PropertyDef> <PropertyDef name="ip"> <Property></Property> @@ -45,7 +49,7 @@ <Property name="label">瑙嗛RTSP</Property> </PropertyDef> <PropertyDef name="provinceProtocol"> - <Property/> + <Property></Property> <Property name="label">鐪佸钩鍙板崗璁�</Property> <Property name="mapping"> <Property name="mapValues">${dorado.getDataProvider("apiTriggerService#triggerPushProtocol").getResult()}</Property> @@ -56,7 +60,7 @@ </PropertyDef> <PropertyDef name="pushProtocol"> <Property></Property> - <Property name="label">绯荤粺缃戝叧閫氳鍗忚</Property> + <Property name="label">涓庣郴缁熼�氳鍗忚</Property> <Property name="mapping"> <Property name="mapValues">${dorado.getDataProvider("apiTriggerService#triggerGatewayProtocol").getResult()}</Property> <Property name="keyProperty">code</Property> @@ -66,7 +70,7 @@ </PropertyDef> <PropertyDef name="syncProtocol"> <Property></Property> - <Property name="label">缃戝叧璁惧閫氳鍗忚</Property> + <Property name="label">涓庤澶囬�氳鍗忚</Property> <Property name="mapping"> <Property name="keyProperty">code</Property> <Property name="valueProperty">name</Property> @@ -95,16 +99,16 @@ <Property name="label">TCP鏈嶅姟绔彛</Property> </PropertyDef> <PropertyDef name="userName"> - <Property/> + <Property></Property> <Property name="label">璁惧鐢ㄦ埛鍚�</Property> </PropertyDef> <PropertyDef name="password"> - <Property/> + <Property></Property> <Property name="label">璁惧瀵嗙爜</Property> </PropertyDef> - <PropertyDef name="depotName"> + <PropertyDef name="depotIdSys"> <Property/> - <Property name="label">鎵�灞炰粨搴�</Property> + <Property name="label">搴撳尯绯荤粺浠撳簱缂栫爜</Property> </PropertyDef> </DataType> </Model> @@ -176,15 +180,20 @@ </DataColumn> <DataColumn name="type"> <Property name="property">type</Property> + <Property name="align">center</Property> + </DataColumn> + <DataColumn name="deviceId"> + <Property name="property">deviceId</Property> + <Property name="align">center</Property> + <Property name="width">550</Property> </DataColumn> <DataColumn name="syncProtocol"> <Property name="property">syncProtocol</Property> + <Property name="align">center</Property> </DataColumn> <DataColumn name="pushProtocol"> <Property name="property">pushProtocol</Property> - </DataColumn> - <DataColumn name="remark"> - <Property name="property">remark</Property> + <Property name="align">center</Property> </DataColumn> </DataGrid> <Dialog id="dialogMain"> @@ -278,13 +287,11 @@ <AutoFormElement> <Property name="name">pushProtocol</Property> <Property name="property">pushProtocol</Property> - <Property name="labelWidth">150</Property> <Editor/> </AutoFormElement> <AutoFormElement> <Property name="name">syncProtocol</Property> <Property name="property">syncProtocol</Property> - <Property name="labelWidth">150</Property> <Editor/> </AutoFormElement> <AutoFormElement> @@ -303,6 +310,11 @@ <Property name="property">httpUrl</Property> <Editor/> </AutoFormElement> + <AutoFormElement> + <Property name="name">depotIdSys</Property> + <Property name="property">depotIdSys</Property> + <Editor/> + </AutoFormElement> <AutoFormElement layoutConstraint="colSpan:3"> <Property name="name">remark</Property> <Property name="property">remark</Property> diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 16306b2..e1c3216 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -75,6 +75,31 @@ max-idle: 10 min-idle: 0 timeout: 6000 + kafka: + bootstrap-servers: 103.203.217.42:9092 + security-protocol: SASL_PLAINTEXT + sasl-mechanism: PLAIN + sasl-jaas-config: org.apache.kafka.common.security.scram.ScramLoginModule required username=\"{username}\" password=\"{password}\";" + sasl-username: sc001 + sasl-password: wCV0ISwmoKwbx1lpBKMW + producer: # producer 鐢熶骇鑰� + retries: 0 # 閲嶈瘯娆℃暟 + acks: 1 # 搴旂瓟绾у埆:澶氬皯涓垎鍖哄壇鏈浠藉畬鎴愭椂鍚戠敓浜ц�呭彂閫乤ck纭(鍙��0銆�1銆乤ll/-1) + batch-size: 16384 # 鎵归噺澶у皬 + buffer-memory: 33554432 # 鐢熶骇绔紦鍐插尯澶у皬 + key-serializer: org.apache.kafka.common.serialization.StringSerializer + value-serializer: org.apache.kafka.common.serialization.StringSerializer + consumer: # consumer娑堣垂鑰� + group-id: fzzygroup # 榛樿鐨勬秷璐圭粍ID + enable-auto-commit: true # 鏄惁鑷姩鎻愪氦offset + auto-commit-interval: 100 # 鎻愪氦offset寤舵椂(鎺ユ敹鍒版秷鎭悗澶氫箙鎻愪氦offset) + + # earliest:褰撳悇鍒嗗尯涓嬫湁宸叉彁浜ょ殑offset鏃讹紝浠庢彁浜ょ殑offset寮�濮嬫秷璐癸紱鏃犳彁浜ょ殑offset鏃讹紝浠庡ご寮�濮嬫秷璐� + # latest:褰撳悇鍒嗗尯涓嬫湁宸叉彁浜ょ殑offset鏃讹紝浠庢彁浜ょ殑offset寮�濮嬫秷璐癸紱鏃犳彁浜ょ殑offset鏃讹紝娑堣垂鏂颁骇鐢熺殑璇ュ垎鍖轰笅鐨勬暟鎹� + # none:topic鍚勫垎鍖洪兘瀛樺湪宸叉彁浜ょ殑offset鏃讹紝浠巓ffset鍚庡紑濮嬫秷璐癸紱鍙鏈変竴涓垎鍖轰笉瀛樺湪宸叉彁浜ょ殑offset锛屽垯鎶涘嚭寮傚父 + auto-offset-reset: latest + key-deserializer: org.apache.kafka.common.serialization.StringDeserializer + value-deserializer: org.apache.kafka.common.serialization.StringDeserializer mqtt: host: tcp://10.13.4.84:11883 -- Gitblit v1.9.3