jiazx0107@163.com
2023-10-31 e95de698a8a0619ede3d5b672ebaf24cac321297
四川省网关接口相关10
已修改15个文件
已添加6个文件
653 ■■■■■ 文件已修改
pom.xml 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/data/GatewayDeviceType.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/data/GatewayProtocol.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/Fzzy40CommonService.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1302Rep.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/conf/MyPartitionTemplate.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/api/DeviceReportService.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/data/QueryParam.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/entity/GatewayDevice.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/ScConstant.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/controller/GatewayController.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/data/GrainData.java 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/data/GrainDataDetail.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReport.java 62 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/kafka/package-info.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java 194 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/view/GatewayConf.view.xml 80 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-dev.yml 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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>
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", "地磅-耀华TCP协议"),
    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()));
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;
    }
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;
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);
    }
}
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);
}
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;
    }
}
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);
}
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;
}
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)
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) + "";
    }
}
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;
/**
 *
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;
    //检测时间-格式:yyyy-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;
}
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;
    }
}
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 -> {
            // æ¶ˆæ¯å‘送到的topic
            String topic = success.getRecordMetadata().topic();
            // æ¶ˆæ¯å‘送到的分区
            int partition = success.getRecordMetadata().partition();
            // æ¶ˆæ¯åœ¨åˆ†åŒºå†…çš„offset
            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());
    }
}
src/main/java/com/fzzy/gateway/hx2023/kafka/package-info.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1 @@
package com.fzzy.gateway.hx2023.kafka;
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);
    }
}
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;
    }
}
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(&quot;#dsMain&quot;).flushAsync();&#xD;
</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(&quot;#dgMain&quot;).getCurrentItem();&#xD;
@@ -144,6 +152,13 @@
        <Property name="width">90</Property>
        <Property name="exClassName">toolbar-button-warn</Property>
      </ToolBarButton>
      <Separator/>
      <ToolBarButton>
        <ClientEvent name="onClick">view.get(&quot;#dialogGrain&quot;).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(&quot;#dsQuery.data&quot;);&#xD;
view.get(&quot;#ajaxTestGrain&quot;).set(&quot;parameter&quot;,data.toJSON()).execute(function(result){&#xD;
    self.get(&quot;parent&quot;).hide();&#xD;
    $alert(result);&#xD;
});</ClientEvent>
          <Property name="caption">确定执行</Property>
        </Button>
        <Button>
          <ClientEvent name="onClick">view.get(&quot;parent&quot;).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>
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(&quot;apiTriggerService#triggerGatewayDeviceType&quot;).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(&quot;apiTriggerService#triggerPushProtocol&quot;).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(&quot;apiTriggerService#triggerGatewayProtocol&quot;).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>
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 # åº”答级别:多少个分区副本备份完成时向生产者发送ack确认(可选0、1、all/-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时,从offset后开始消费;只要有一个分区不存在已提交的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