WS
2023-08-14 c110b50500f6446c7471fd4e413c563067381de9
V4.0版本温湿度 虫情 气体数据同步
已修改2个文件
已添加12个文件
996 ■■■■■ 文件已修改
src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService11.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService13.java 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/entity/Fz40Gas.java 117 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/entity/Fz40GasKey.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/entity/Fz40Grain.java 107 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/entity/Fz40GrainKey.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/entity/Fz40Pest.java 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/entity/Fz40PestKey.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1302.java 246 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1303.java 152 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1304.java 126 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1302Rep.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1303Rep.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1304Rep.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService11.java
@@ -27,7 +27,7 @@
    @Override
    public String getProtocol() {
        return SyncProtocol.FZZY_V35_GB.getCode();
        return SyncProtocol.FZZY_V40_GB.getCode();
    }
    @Override
src/main/java/com/fzzy/async/fzzy40/Fzzy40SyncService13.java
@@ -3,6 +3,10 @@
import com.fzzy.api.data.ApiParam;
import com.fzzy.api.data.SyncProtocol;
import com.fzzy.api.service.SyncService13;
import com.fzzy.async.fzzy40.impl.Fzzy40Sync1302;
import com.fzzy.async.fzzy40.impl.Fzzy40Sync1303;
import com.fzzy.async.fzzy40.impl.Fzzy40Sync1304;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -15,23 +19,29 @@
@Component
public class Fzzy40SyncService13 implements SyncService13 {
    @Autowired
    private Fzzy40Sync1302 fzzySync1302;
    @Autowired
    private Fzzy40Sync1303 fzzySync1303;
    @Autowired
    private Fzzy40Sync1304 fzzySync1304;
    @Override
    public String getProtocol() {
        return SyncProtocol.FZZY_V35_GB.getCode();
        return SyncProtocol.FZZY_V40_GB.getCode();
    }
    @Override
    public void syncData(ApiParam param) {
        //温湿度检测数据同步 TODO
        fzzySync1302.syncData(param.getDeptId(), param.getStart(), param.getEnd());
        //虫害检测同步  TODO
        fzzySync1303.syncData(param.getDeptId(), param.getStart(), param.getEnd());
        //气体检测同步  TODO
        fzzySync1304.syncData(param.getDeptId(), param.getStart(), param.getEnd());
        //质检同步  TODO
src/main/java/com/fzzy/async/fzzy40/entity/Fz40Gas.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,117 @@
package com.fzzy.async.fzzy40.entity;
import com.bstek.dorado.annotation.PropertyDef;
import com.fzzy.async.fzzy35.entity.Fz35GrainKey;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
 * æ°”体业务数据信息包括浓度,氮气,压力信息 æ°”体模块:包括气体浓度
 *
 * @author Andy
 *
 */
@Data
@Entity
@Table(name = "D_GAS")
@IdClass(Fz40GasKey.class)
public class Fz40Gas implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "BATCH_ID_", length = 40)
    @PropertyDef(label = "批次ID")
    private String batchId;
    @Id
    @Column(name = "COMPANY_ID_", length = 10)
    @PropertyDef(label = "组织编码", description = "")
    private String companyId;
    @Id
    @Column(name = "DEPOT_ID_", length = 50)
    @PropertyDef(label = "仓库ID", description = "仓库编号")
    private String depotId;
    @Column(name = "PER_CO2_")
    @PropertyDef(label = "二氧化碳浓度", description = "平均二氧化碳浓度(PPM)")
    private Double perCo2 = 0.0;
    @Column(name = "PER_O2_")
    @PropertyDef(label = "氧气浓度", description = "平均氧气浓度(%)")
    private Double perO2 = 0.0;
    @Column(name = "PER_PH3_")
    @PropertyDef(label = "磷化氢浓度", description = "平均磷化氢浓度(PPM)")
    private Double perPh3 = 0.0;
    @Column(name = "PER_N2_")
    @PropertyDef(label = "氮气浓度", description = "氮气浓度(%)")
    private Double perN2 = 0.0;
    @Column(name = "PER_CO2_MAX_")
    @PropertyDef(label = "二氧化碳浓度-最大", description = "二氧化碳浓度(PPM)")
    private Double perCo2Max = 0.0;
    @Column(name = "PER_O2_MAX_")
    @PropertyDef(label = "氧气浓度-最大", description = "氧气浓度(%)")
    private Double perO2Max = 0.0;
    @Column(name = "PER_PH3_MAX_")
    @PropertyDef(label = "磷化氢浓度-最大", description = "磷化氢浓度(PPM)")
    private Double perPh3Max = 0.0;
    @Column(name = "PER_N2_MAX_")
    @PropertyDef(label = "氮气浓度-最大")
    private Double perN2Max = 0.0;
    @Column(name = "PER_CO2_MIN_")
    @PropertyDef(label = "二氧化碳浓度-最小", description = "二氧化碳浓度(PPM)")
    private Double perCo2Min = 0.0;
    @Column(name = "PER_O2_MIN_")
    @PropertyDef(label = "氧气浓度-最小", description = "氧气浓度(%)")
    private Double perO2Min = 0.0;
    @Column(name = "PER_PH3_MIN_")
    @PropertyDef(label = "磷化氢浓度-最小", description = "磷化氢浓度(PPM)")
    private Double perPh3Min = 0.0;
    @Column(name = "PER_N2_MIN_")
    @PropertyDef(label = "氮气浓度-最小")
    private Double perN2Min = 0.0;
    @Column(name = "RECEIVE_DATE_")
    @PropertyDef(label = "检测时间")
    private Date receiveDate;
    @Column(name = "GAS_START_")
    @PropertyDef(label = "气体采集点开始", description = "气体配置信息")
    private int gasStart;
    @Column(name = "GAS_END_")
    @PropertyDef(label = "气体采集点截至", description = "气体配置信息")
    private int gasEnd;
    @Column(name = "CHECK_NUM_")
    @PropertyDef(label = "采集通道个数")
    private int checkNum = 0;
    @Column(name = "POINTS_", length = 2000)
    @PropertyDef(label = "采集点信息", description = "固定为:passCode,co2,o2,ph3,n2;passCode,co2,o2,ph3,n2;")
    private String points;
    @Column(name = "CHECK_USER_", length = 30)
    @PropertyDef(label = "检测人")
    private String checkUser;
    @Column(name = "REMARK_", length = 200)
    @PropertyDef(label = "备注信息")
    private String remark;
}
src/main/java/com/fzzy/async/fzzy40/entity/Fz40GasKey.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,17 @@
package com.fzzy.async.fzzy40.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.Serializable;
@Data
@AllArgsConstructor
public class Fz40GasKey implements Serializable {
        private String batchId;
        private String companyId;
        private String depotId;
        public Fz40GasKey(){
            super();
        }
    }
src/main/java/com/fzzy/async/fzzy40/entity/Fz40Grain.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,107 @@
package com.fzzy.async.fzzy40.entity;
import com.bstek.dorado.annotation.PropertyDef;
import com.fzzy.async.fzzy35.entity.Fz35GrainKey;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
/**
 * ç²®æƒ…数据-主表
 * <p>
 * æ›´æ–°è®°å½•:
 * 1,删除行数据的表记录,调整为数据直接文本保存主表中
 * 2,保留点位坐标信息,便于以后点位走势图查看
 *
 * @author Andy
 */
@Entity
@Table(name = "D_GRAIN")
@Data
@IdClass(Fz40GrainKey.class)
public class Fz40Grain implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "BATCH_ID_", length = 30)
    @PropertyDef(label = "批次编号")
    private String batchId;
    @Id
    @Column(name = "COMPANY_ID_", length = 10)
    @PropertyDef(label = "组织编码", description = "")
    private String companyId;
    @Id
    @Column(name = "DEPOT_ID_", length = 50)
    @PropertyDef(label = "所属仓库", description = "仓库编号")
    private String depotId;
    @Column(name = "TEMP_MIN_")
    @PropertyDef(label = "最低温粮温", description = "单位℃,粮情最低温")
    private Double tempMin = 0.0;
    @Column(name = "TEMP_MAX_")
    @PropertyDef(label = "最高粮温", description = "单位℃,粮情最高温")
    private Double tempMax = 0.0;
    @Column(name = "TEMP_AVE_")
    @PropertyDef(label = "平均粮温", description = "单位℃,粮情平均温度")
    private Double tempAve = 0.0;
    @Column(name = "HUMIDITY_IN_")
    @PropertyDef(label = "仓内湿度")
    private Double humidityIn;
    @Column(name = "TEMP_IN_")
    @PropertyDef(label = "仓内温度")
    private Double tempIn;
    @Column(name = "HUMIDITY_OUT_")
    @PropertyDef(label = "仓外湿度")
    private Double humidityOut;
    @Column(name = "TEMP_OUT_")
    @PropertyDef(label = "仓外温度")
    private Double tempOut;
    @Column(name = "CABLE_", length = 20)
    @PropertyDef(label = "层行列", description = "用逗号隔开的配置信息,层-行-列")
    private String cable;
    @PropertyDef(label = "筒仓层配置", description = "用-隔开的配置信息")
    @Column(name = "CABLE_CIR_", length = 20)
    private String cableCir;
    @PropertyDef(label = "油面高度", description = "用-隔开的两个值,油面高度-建筑高度")
    @Column(name = "OIL_HEIGHT_", length = 20)
    private String oilHeight;
    @Column(name = "WEATHER_", length = 20)
    @PropertyDef(label = "天气", description = "直接填写中文信息,晴,阴雨天")
    private String weather = "";
    @Column(name = "RECEIVE_DATE_")
    @PropertyDef(label = "接收时间")
    private Date receiveDate;
    @Column(name = "CHECK_USER_", length = 30)
    @PropertyDef(label = "检测人")
    private String checkUser;
    @Column(name = "REMARK_", length = 500)
    @PropertyDef(label = "备注", description = "备注")
    private String remark;
    @Column(name = "POINTS_", length = 2000)
    @PropertyDef(label = "采集点信息", description = "用逗号隔开的温度信息信息")
    private String points;
    @Transient
    @PropertyDef(label = "所属分库", description = "分库编码,非数据库字段")
    private String deptId;
}
src/main/java/com/fzzy/async/fzzy40/entity/Fz40GrainKey.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,17 @@
package com.fzzy.async.fzzy40.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.Serializable;
@Data
@AllArgsConstructor
public class Fz40GrainKey implements Serializable {
        private String batchId;
        private String companyId;
        private String depotId;
        public Fz40GrainKey(){
            super();
        }
    }
src/main/java/com/fzzy/async/fzzy40/entity/Fz40Pest.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,94 @@
package com.fzzy.async.fzzy40.entity;
import com.bstek.dorado.annotation.PropertyDef;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
 * è™«å®³ç»Ÿè®¡
 *
 * @author: andy.jia
 * @description:
 * @version:
 * @data:2019å¹´12月25日
 *
 */
@Data
@Entity
@Table(name = "D_PEST")
@IdClass(Fz40PestKey.class)
public class Fz40Pest implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "BATCH_ID_", length = 40)
    @PropertyDef(label = "批次ID")
    private String batchId;
    @Id
    @Column(name = "COMPANY_ID_", length = 10)
    @PropertyDef(label = "组织编码", description = "")
    private String companyId;
    @Id
    @Column(name = "DEPOT_ID_", length = 50)
    @PropertyDef(label = "仓库ID", description = "仓库编号")
    private String depotId;
    @Column(name = "PEST_MAX_")
    @PropertyDef(label = "最多数量")
    private int pestMax = 0;
    @Column(name = "METHOD_", length = 10)
    @PropertyDef(label = "虫害检测方法", description = "0-粮堆扦样;1-墙面粮面检查")
    private String method;
    @Column(name = "POSITION_", length =30)
    @PropertyDef(label = "发生部位")
    private String position;
    @Column(name = "PEST_TYPE_", length =30)
    @PropertyDef(label = "虫害种类")
    private String pestType;
    @Column(name = "PEST_LEVEL_", length =30)
    @PropertyDef(label = "虫粮等级判定")
    private String pestLevel;
    @Column(name = "PEST_ANALYSIS_", length =60)
    @PropertyDef(label = "害虫抗药性分析")
    private String pestAnalysis;
    @Column(name = "PEST_START_")
    @PropertyDef(label = "虫害采集点开始", description = "气体配置信息")
    private int pestStart;
    @Column(name = "PEST_END_")
    @PropertyDef(label = "虫害采集点截至", description = "气体配置信息")
    private int pestEnd;
    @Column(name = "CHECK_NUM_")
    @PropertyDef(label = "采集通道个数")
    private int checkNum = 0;
    @Column(name = "RECEIVE_DATE_")
    @PropertyDef(label = "检测时间")
    private Date receiveDate;
    @Column(name = "POINTS_", length = 2000)
    @PropertyDef(label = "采集点信息", description = "固定为:passCode,num;passCode,num;")
    private String points;
    @Column(name = "CHECK_USER_", length = 30)
    @PropertyDef(label = "检测人")
    private String checkUser;
    @Column(name = "REMARK_", length = 200)
    @PropertyDef(label = "备注信息")
    private String remark;
}
src/main/java/com/fzzy/async/fzzy40/entity/Fz40PestKey.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,17 @@
package com.fzzy.async.fzzy40.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.Serializable;
@Data
@AllArgsConstructor
public class Fz40PestKey implements Serializable {
        private String batchId;
        private String companyId;
        private String depotId;
        public Fz40PestKey(){
            super();
        }
    }
src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1302.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,246 @@
package com.fzzy.async.fzzy40.impl;
import com.alibaba.fastjson.JSONObject;
import com.bstek.dorado.util.DateUtils;
import com.fzzy.api.Constant;
import com.fzzy.api.entity.Api1105;
import com.fzzy.api.entity.Api1302;
import com.fzzy.api.entity.ApiLog;
import com.fzzy.api.service.ApiCommonService;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.view.repository.Api1302Rep;
import com.fzzy.api.view.repository.ApiLogRep;
import com.fzzy.async.fzzy40.entity.Fz40Grain;
import com.fzzy.async.fzzy40.repository.Fzzy40Sync1302Rep;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
/**
 * æ¸©æ¹¿åº¦æ£€æµ‹æ•°æ®åŒæ­¥
 *
 * @author chen
 * @date 2022-09-07 14:41
 */
@Slf4j
@Component
public class Fzzy40Sync1302 {
    @Autowired
    private Fzzy40Sync1302Rep fzzySync1302Rep;
    @Autowired
    private ApiCommonService commonService;
    @Autowired
    private Api1302Rep api1302Rep;
    @Autowired
    private ApiLogRep apiLogRep;
    /**
     * åŒæ­¥å¹¶å°è£…保存温湿度检测数据
     *
     * @param deptId ç³»ç»Ÿå¯¹åº”库区编码
     * @param start  èµ·å§‹æ—¶é—´
     * @param end    æˆªæ­¢æ—¶é—´
     */
    public void syncData(String deptId, Date start, Date end) {
        log.info("-------------1302接口数据开始同步------------------");
        //同步数据,只记录失败的信息
        ApiLog apiLog = new ApiLog();
        apiLog.setType(ApiLog.TYPE_SYNC);
        apiLog.setKqdm(deptId);
        apiLog.setUploadTime(new Date());
        apiLog.setInteId(Constant.API_CODE_1302);
        apiLog.setStatus(99);
        apiLog.setId(ContextUtil.getUUID());
        try {
            List<Fz40Grain> list = fzzySync1302Rep.findByReceiveDate(start, end);
            log.info(DateUtils.format("yyyy-MM-dd HH:mm:ss",start));
            log.info(DateUtils.format("yyyy-MM-dd HH:mm:ss",end));
            if (null == list || list.isEmpty()) {
                log.info("1302---同步数据:没有查询到需要同步的数据");
                return;
            }
            log.info(JSONObject.toJSONString(list));
            Date syncTime = new Date();
            Api1302 api1302;
            Api1105 api1105;
            List<Api1302> api1302List;
            for (Fz40Grain fz40Grain : list) {
                //获取货位信息
                api1105 = commonService.getApi1105Cache(fz40Grain.getDepotId());
                if (null == api1105) {
                    continue;
                }
                //由货位代码+检测日期     ï¼ˆyyyyMMdd) +4 ä½é¡ºåºå·ç»„成  --2019 1128 0819
                api1302 = new Api1302();
                //api1302.setWsdjcdh(api1105.getHwdm() + DateFormatUtils.format(grain.getReceiveDate(), "yyyyMMdd") + String.valueOf(index).substring(1));
                api1302.setWsdjcdh(api1105.getHwdm() + fz40Grain.getBatchId());
                api1302.setJcsj(fz40Grain.getReceiveDate());
                api1302.setHwdm(api1105.getHwdm());
                api1302.setCfww(fz40Grain.getTempOut() == null ? 0.00: fz40Grain.getTempOut());
                if(null == fz40Grain.getHumidityOut() || fz40Grain.getHumidityOut() < 0){
                    api1302.setCfws(-1);
                }else {
                    api1302.setCfws(fz40Grain.getHumidityOut());
                }
                api1302.setCfnw(fz40Grain.getTempIn() == null ? 0.00: fz40Grain.getTempIn());
                if(null == fz40Grain.getHumidityIn() || fz40Grain.getHumidityIn() < 0){
                    api1302.setCfns(-1);
                }else {
                    api1302.setCfns(fz40Grain.getHumidityIn());
                }
                api1302.setLszgw(fz40Grain.getTempMax() == null ? 0.00: fz40Grain.getTempMax());
                api1302.setLspjw(fz40Grain.getTempAve() == null ? 0.00: fz40Grain.getTempAve());
                api1302.setLszdw(fz40Grain.getTempMin() == null ? 0.00: fz40Grain.getTempMin());
                //温度集合
                if (StringUtils.isEmpty(fz40Grain.getCableCir())) {
                    api1302.setLswdzjh(getTempPointList1(fz40Grain.getPoints(), fz40Grain.getCable()));
                    api1302.setLssdzjh(getHumPointList1(fz40Grain.getPoints(), fz40Grain.getCable()));
                } else {
                    api1302.setLswdzjh(getTempPointList2(fz40Grain.getPoints(), fz40Grain.getCable(), fz40Grain.getCableCir()));
                    api1302.setLssdzjh(getHumPointList2(fz40Grain.getPoints(), fz40Grain.getCable(), fz40Grain.getCableCir()));
                }
                api1302.setZhgxsj(syncTime);
                api1302.setBizId(fz40Grain.getBatchId());
                api1302.setKqdm(api1105.getKqdm());
                api1302.setSyncTime(syncTime);
                api1302List = api1302Rep.getDataByWsdjcdh(api1302.getWsdjcdh());
                if(null == api1302List || api1302List.isEmpty()){
                    api1302.setCzbz(Constant.CZBZ_I);
                }else {
                    api1302.setCzbz(api1302List.get(0).getCzbz());
                }
                log.info("1302---同步数据:" + api1302.toString());
                api1302Rep.save(api1302);
            }
        } catch (Exception e) {
            log.error("---同步失败----{}", e);
            apiLog.setResult("同步失败:" + e.getMessage());
            apiLogRep.save(apiLog);
        }
    }
    /**
     * èŽ·å–å¹³æ–¹ä»“çš„æ¸©åº¦å€¼é›†åˆï¼Œæ ¼å¼ï¼šæ¸©åº¦å€¼,层数,行数,列数|温度值,层数,行数,列数|温度值,层数,行数,列数
     *
     * @return
     */
    private String getTempPointList1(String point, String cable) {
        String[] cab = cable.split("-");
        int c = Integer.valueOf(cab[0]);
        int h = Integer.valueOf(cab[1]);
        int l = Integer.valueOf(cab[2]);
        String[] points = point.split(",");
        String result = "";
        for (int i = 1; i <= l; i++) {
            for (int j = 1; j <= h; j++) {
                for (int z = 1; z <= c; z++) {
                    result += ("|" + points[(i * j - 1) * c + z - 1] + "," + z + "," + j + "," + i);
                }
            }
        }
        return result.substring(1);
    }
    /**
     * èŽ·å–ç­’ä»“çš„æ¸©åº¦å€¼é›†åˆï¼Œæ ¼å¼ï¼šæ¸©åº¦å€¼,圈数,点数,层数|温度值,圈数,点数,层数|温度值,圈数,点数,层数
     *
     * @return
     */
    private String getTempPointList2(String point, String cable, String cableCir) {
        String[] cab = cable.split("-");
        String[] cabCir = cableCir.split("-");
        int q = cab.length;  //圈数
        int c = Integer.valueOf(cabCir[0]);  //层数
        int g = 0;  //圈根数
        int g1 = 1;  //圈起始根数
        int g2 = 0;  //圈截止根数
        String[] points = point.split(",");
        String result = "";
        for (int i = 1; i <= q; i++) {
            g1 += g2;
            g = Integer.valueOf(cab[i - 1]);
            g2 += g;
            for (int j = g1; j <= g2; j++) {
                for (int z = 1; z <= c; z++) {
                    result += ("|" + points[(j - 1) * c + z - 1] + "," + i + "," + j + "," + z);
                }
            }
        }
        return result.substring(1);
    }
    /**
     * èŽ·å–å¹³æ–¹ä»“çš„æ¹¿åº¦å€¼é›†åˆï¼Œæ ¼å¼ï¼šæ¹¿åº¦,层数,行数,列数|湿度,层数,行数,列数|湿度,层数,行数,列数
     *
     * @return
     */
    private String getHumPointList1(String point, String cable) {
        String[] cab = cable.split("-");
        int c = Integer.valueOf(cab[0]);
        int h = Integer.valueOf(cab[1]);
        int l = Integer.valueOf(cab[2]);
       // String[] points = point.split(",");
        String result = "";
        for (int i = 1; i <= l; i++) {
            for (int j = 1; j <= h; j++) {
                for (int z = 1; z <= c; z++) {
                    result += ("|" + "-1" + "," + z + "," + j + "," + i);
                }
            }
        }
        return result.substring(1);
    }
    /**
     * èŽ·å–ç­’ä»“çš„æ¹¿åº¦å€¼é›†åˆï¼Œæ ¼å¼ï¼šæ¹¿åº¦,圈数,点数,层数|湿度,圈数,点数,层数|湿度,圈数,点数,层数
     *
     * @return
     */
    private String getHumPointList2(String point, String cable, String cableCir) {
        String[] cab = cable.split("-");
        String[] cabCir = cableCir.split("-");
        int q = cab.length;  //圈数
        int c = Integer.valueOf(cabCir[0]);  //层数
        int g = 0;  //圈根数
        int g1 = 1;  //圈起始根数
        int g2 = 0;  //圈截止根数
      //  String[] points = point.split(",");
        String result = "";
        for (int i = 1; i <= q; i++) {
            g1 += g2;
            g = Integer.valueOf(cab[i - 1]);
            g2 += g;
            for (int j = g1; j <= g2; j++) {
                for (int z = 1; z <= c; z++) {
                    result += ("|" + "-1" + "," + i + "," + j + "," + z);
                }
            }
        }
        return result.substring(1);
    }
}
src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1303.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,152 @@
package com.fzzy.async.fzzy40.impl;
import com.fzzy.api.Constant;
import com.fzzy.api.entity.Api1105;
import com.fzzy.api.entity.Api1303;
import com.fzzy.api.entity.ApiLog;
import com.fzzy.api.service.ApiCommonService;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.view.repository.Api1303Rep;
import com.fzzy.api.view.repository.ApiLogRep;
import com.fzzy.async.fzzy40.entity.Fz40Pest;
import com.fzzy.async.fzzy40.repository.Fzzy40Sync1303Rep;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
/**
 * è™«å®³æ£€æµ‹æ•°æ®åŒæ­¥
 *
 * @author chen
 * @date 2022-09-08 09:51
 */
@Slf4j
@Component
public class Fzzy40Sync1303 {
    @Autowired
    private Fzzy40Sync1303Rep fzzy40Sync1303Rep;
    @Autowired
    private ApiCommonService commonService;
    @Autowired
    private Api1303Rep api1303Rep;
    @Autowired
    private ApiLogRep apiLogRep;
    /**
     * åŒæ­¥å¹¶å°è£…保存虫害检测数据
     *
     * @param deptId ç³»ç»Ÿå¯¹åº”库区编码
     * @param start  èµ·å§‹æ—¶é—´
     * @param end    æˆªæ­¢æ—¶é—´
     */
    public void syncData(String deptId, Date start, Date end) {
        log.info("-------------1303接口数据开始同步------------------");
        //同步数据,只记录失败的信息
        ApiLog apiLog = new ApiLog();
        apiLog.setType(ApiLog.TYPE_SYNC);
        apiLog.setKqdm(deptId);
        apiLog.setUploadTime(new Date());
        apiLog.setInteId(Constant.API_CODE_1303);
        apiLog.setStatus(99);
        apiLog.setId(ContextUtil.getUUID());
        try {
            List<Fz40Pest> list = fzzy40Sync1303Rep.findPestByReceiveDate(start, end);
            if (null == list || list.isEmpty()) {
                return;
            }
            Date syncTime = new Date();
            Api1303 api1303;
            Api1105 api1105;
            List<Api1303> api1303List;
            for (Fz40Pest fz40Pest : list) {
                //获取货位信息
                api1105 = commonService.getApi1105Cache(fz40Pest.getDepotId());
                if (null == api1105) {
                    continue;
                }
                api1303 = new Api1303();
                api1303.setHcjcdh(api1105.getHwdm() + fz40Pest.getBatchId());
                api1303.setJcsj(fz40Pest.getReceiveDate());
                api1303.setHwdm(api1105.getHwdm());
                //检查害虫方法,0-远程、1-人工、2-其他
                api1303.setJchcff("0");
                //发生部位,坐标填写:x,y,z
                api1303.setFsbw(null);//非必填字段
                //害虫种类。多个用#隔开#TODO >> å¾…优化调整
                api1303.setHczl("21212");
                //虫口密度值集合
                String ckmdzjh = this.geeCkmdzjh(fz40Pest.getPestMax(), fz40Pest.getPoints());
                api1303.setCkmdzjh(ckmdzjh);
                //虫粮等级判定,531-基本无虫粮、532-一般虫粮、533严重虫粮、534危害虫粮
                api1303.setCldjpd("531");
                if (fz40Pest.getPestMax() > 5) {
                    api1303.setCldjpd("532");
                }
                if (fz40Pest.getPestMax() > 30) {
                    api1303.setCldjpd("533");
                }
                api1303.setZhgxsj(syncTime);
                api1303.setBizId(fz40Pest.getBatchId());
                api1303.setKqdm(api1105.getKqdm());
                api1303.setSyncTime(syncTime);
                api1303List = api1303Rep.getDataByHcjcdh(api1303.getHcjcdh());
                if(null == api1303List || api1303List.isEmpty()){
                    api1303.setCzbz(Constant.CZBZ_I);
                }else {
                    api1303.setCzbz(api1303List.get(0).getCzbz());
                }
                api1303Rep.save(api1303);
            }
        } catch (Exception e) {
            log.error("---同步失败----{}", e);
            apiLog.setResult("同步失败:" + e.getMessage());
            apiLogRep.save(apiLog);
        }
    }
    /**
     * å¤´/kg,指粮食害虫值集合,与
     * å®³è™«ç§ç±»é¡ºåºå¯¹åº”,用“|”分
     * éš”,多个取样点用英文半角“,”
     * åˆ†éš”,按照取样点示意图标识顺
     * åºæŽ’列。
     *
     * @param pestMax
     * @param points
     * @return
     */
    private String geeCkmdzjh(int pestMax, String points) {
        if (StringUtils.isEmpty(points)) return "0";
        String[] attr = points.split(";");
        String result = "";
        for (String str : attr) {
            result += str.split(",")[1] + ",";
        }
        return result.substring(0, result.length() - 1);
    }
}
src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1304.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,126 @@
package com.fzzy.async.fzzy40.impl;
import com.fzzy.api.Constant;
import com.fzzy.api.entity.Api1105;
import com.fzzy.api.entity.Api1304;
import com.fzzy.api.entity.ApiLog;
import com.fzzy.api.service.ApiCommonService;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.view.repository.Api1304Rep;
import com.fzzy.api.view.repository.ApiLogRep;
import com.fzzy.async.fzzy40.entity.Fz40Gas;
import com.fzzy.async.fzzy40.repository.Fzzy40Sync1304Rep;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
/**
 * è™«å®³æ£€æµ‹æ•°æ®åŒæ­¥
 *
 * @author chen
 * @date 2022-09-08 09:51
 */
@Slf4j
@Component
public class Fzzy40Sync1304 {
    @Autowired
    private Fzzy40Sync1304Rep fzzySync1304Rep;
    @Autowired
    private ApiCommonService commonService;
    @Autowired
    private Api1304Rep api1304Rep;
    @Autowired
    private ApiLogRep apiLogRep;
    /**
     * åŒæ­¥å¹¶å°è£…保存气体检测数据
     *
     * @param deptId ç³»ç»Ÿå¯¹åº”库区编码
     * @param start  èµ·å§‹æ—¶é—´
     * @param end    æˆªæ­¢æ—¶é—´
     */
    public void syncData(String deptId, Date start, Date end) {
        log.info("-------------1304接口数据开始同步------------------");
        //同步数据,只记录失败的信息
        ApiLog apiLog = new ApiLog();
        apiLog.setType(ApiLog.TYPE_SYNC);
        apiLog.setKqdm(deptId);
        apiLog.setUploadTime(new Date());
        apiLog.setInteId(Constant.API_CODE_1304);
        apiLog.setStatus(99);
        apiLog.setId(ContextUtil.getUUID());
        try {
            List<Fz40Gas> list = fzzySync1304Rep.findByReceiveDate(start, end);
            if (null == list || list.isEmpty()) {
                return;
            }
            Date syncTime = new Date();
            Api1304 api1304;
            Api1105 api1105;
            List<Api1304> api1304List;
            for (Fz40Gas fz40Gas : list) {
                //获取货位信息
                api1105 = commonService.getApi1105Cache(fz40Gas.getDepotId());
                if (null == api1105) {
                    continue;
                }
                api1304 = new Api1304();
                // api1304.setQtndjcdh(api1105.getHwdm() + DateFormatUtils.format(gas.getReceiveDate(), "yyyyMMdd") + String.valueOf(index).substring(1));
                api1304.setQtndjcdh(api1105.getHwdm() + fz40Gas.getBatchId());
                api1304.setJcsj(fz40Gas.getReceiveDate());
                api1304.setHwdm(api1105.getHwdm());
                api1304 = updateGasInfo(api1304, fz40Gas.getPoints());
                api1304.setZhgxsj(syncTime);
                api1304.setBizId(fz40Gas.getBatchId());
                api1304.setKqdm(api1105.getKqdm());
                api1304.setSyncTime(syncTime);
                api1304List = api1304Rep.getDataByQtndjcdh(api1304.getQtndjcdh());
                if(null == api1304List || api1304List.isEmpty()){
                    api1304.setCzbz(Constant.CZBZ_I);
                }else {
                    api1304.setCzbz(api1304List.get(0).getCzbz());
                }
                api1304Rep.save(api1304);
            }
        } catch (Exception e) {
            log.error("---同步失败----{}", e);
            apiLog.setResult("同步失败:" + e.getMessage());
            apiLogRep.save(apiLog);
        }
    }
    /**
     * èŽ·å–å¯¹åº”æ°”ä½“æµ“åº¦é›†åˆï¼špassCode,co2,o2,ph3,n2;passCode,co2,o2,ph3,n2;
     *
     * @param points
     * @return
     */
    private Api1304 updateGasInfo(Api1304 api1304, String points) {
        String[] attr = points.split(";");
        String[] arrt2;
        String o2 = "", co2 = "", ph3 = "";
        for (String temp : attr) {
            arrt2 = temp.split(",");
            o2 += arrt2[2] + ",";
            co2 += arrt2[1] + ",";
            ph3 += arrt2[3] + ",";
        }
        api1304.setYqhlzjh(o2);
        api1304.setEyhthlzjh(co2);
        api1304.setLhqndzjh(ph3);
        return api1304;
    }
}
src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1302Rep.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,28 @@
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;
import org.springframework.data.repository.query.Param;
import java.util.Date;
import java.util.List;
/**
 * æŸ¥è¯¢ç²®æƒ…检测数据
 *
 * @author chen
 * @date 2022-09-07 14:35
 */
public interface Fzzy40Sync1302Rep extends JpaRepository<Fz40Grain, String> {
    /**
     * æ ¹æ®æ—¶é—´æ®µæŸ¥è¯¢ç²®æƒ…数据
     * @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);
}
src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1303Rep.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,28 @@
package com.fzzy.async.fzzy40.repository;
import com.fzzy.async.fzzy40.entity.Fz40Pest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.Date;
import java.util.List;
/**
 * æŸ¥è¯¢è™«å®³æ£€æµ‹æ•°æ®
 *
 * @author chen
 * @date 2022-09-08 09:51
 */
public interface Fzzy40Sync1303Rep extends JpaRepository<Fz40Pest, String> {
    /**
     * æ ¹æ®æ—¶é—´æ®µæŸ¥è¯¢ç²®æƒ…数据
     *
     * @param start
     * @param end
     * @return
     */
    @Query("from Fz40Pest where receiveDate >=:start and receiveDate <:end order by receiveDate ")
    List<Fz40Pest> findPestByReceiveDate(@Param("start") Date start, @Param("end") Date end);
}
src/main/java/com/fzzy/async/fzzy40/repository/Fzzy40Sync1304Rep.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,27 @@
package com.fzzy.async.fzzy40.repository;
import com.fzzy.async.fzzy40.entity.Fz40Gas;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.Date;
import java.util.List;
/**
 * æŸ¥è¯¢æ°”体检测数据
 *
 * @author chen
 * @date 2022-09-08 10:42
 */
public interface Fzzy40Sync1304Rep extends JpaRepository<Fz40Gas, String> {
    /**
     * æ ¹æ®æ—¶é—´æ®µæŸ¥è¯¢ç²®æƒ…数据
     * @param start
     * @param end
     * @return
     */
    @Query("from Fz40Gas where receiveDate >=:start and receiveDate <:end order by receiveDate ")
    List<Fz40Gas> findByReceiveDate(@Param("start") Date start, @Param("end") Date end);
}