CZT
2023-11-22 2c08948a713f834f3a6b033495291bfddcbc0c50
上海接口新增温湿度数据封装
已修改4个文件
已添加1个文件
272 ■■■■ 文件已修改
src/main/java/com/fzzy/api/entity/Api1302.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/utils/NumberUtil.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1302.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/push/sh2023/SH2023ApiRemoteService.java 174 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-pro5306.yml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/entity/Api1302.java
@@ -2,12 +2,9 @@
import com.alibaba.fastjson.annotation.JSONField;
import com.bstek.dorado.annotation.PropertyDef;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@@ -32,48 +29,48 @@
    @Id
    @PropertyDef(label = "温湿度检测单号" )
    @Column(name = "wsdjcdh", length = 42, nullable = false)
    @Column(name = "wsdjcdh", length = 42)
    private String wsdjcdh;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @PropertyDef(label = "检测时间")
    @Column(name = "jcsj", nullable = false)
    @Column(name = "jcsj")
    private Date jcsj;
    @PropertyDef(label = "货位代码" )
    @Column(name = "hwdm", length = 30, nullable = false)
    @Column(name = "hwdm", length = 30)
    private String hwdm;
    @PropertyDef(label = "仓房外温" )
    @Column(name = "cfww", precision = 20, scale = 6, nullable = false)
    @Column(name = "cfww", precision = 20)
    private double cfww;
    @PropertyDef(label = "仓房外湿" )
    @Column(name = "cfws", precision = 20, scale = 6, nullable = false)
    @Column(name = "cfws", precision = 20)
    private double cfws;
    @PropertyDef(label = "仓房内温" )
    @Column(name = "cfnw", precision = 20, scale = 6, nullable = false)
    @Column(name = "cfnw", precision = 20)
    private double cfnw;
    @PropertyDef(label = "仓房内湿" )
    @Column(name = "cfns", precision = 20, scale = 6, nullable = false)
    @Column(name = "cfns", precision = 20)
    private double cfns;
    @PropertyDef(label = "粮食最高温" )
    @Column(name = "lszgw", precision = 20, scale = 6, nullable = false)
    @Column(name = "lszgw", precision = 20)
    private double lszgw;
    @PropertyDef(label = "粮食最低温" )
    @Column(name = "lszdw", precision = 20, scale = 6, nullable = false)
    @Column(name = "lszdw", precision = 20)
    private double lszdw;
    @PropertyDef(label = "粮食平均温" )
    @Column(name = "lspjw", precision = 20, scale = 6, nullable = false)
    @Column(name = "lspjw", precision = 20)
    private double lspjw;
    @PropertyDef(label = "粮食温度值集合" )
    @Column(name = "lswdzjh", length = 8000, nullable = false)
    @Column(name = "lswdzjh", length = 8000)
    private String lswdzjh;
    @PropertyDef(label = "粮食湿度值集合" )
@@ -81,12 +78,12 @@
    private String lssdzjh;
    @PropertyDef(label = "操作标志")
    @Column(name = "czbz", length = 1, nullable = false)
    @Column(name = "czbz", length = 1)
    private String czbz;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @PropertyDef(label = "最后更新时间" )
    @Column(name = "zhgxsj", nullable = false)
    @Column(name = "zhgxsj")
    private Date zhgxsj;
}
src/main/java/com/fzzy/api/utils/NumberUtil.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,49 @@
package com.fzzy.api.utils;
import java.math.BigDecimal;
import java.text.DecimalFormat;
/**
 * æ•°å­—格式化工具类
 */
public class NumberUtil {
    /**
     * å¯¹double类型的数值保留指定位数的小数。<br>
     * è¯¥æ–¹æ³•舍入模式:向“最接近的”数字舍入,如果与两个相邻数字的距离相等,则为向上舍入的舍入模式。<br>
     * <b>注意:</b>如果精度要求比较精确请使用 keepPrecision(String number, int precision)方法
     * @param number  è¦ä¿ç•™å°æ•°çš„æ•°å­—
     * @param precision å°æ•°ä½æ•°
     * @return double å¦‚果数值较大,则使用科学计数法表示
     */
    public static double keepPrecision(Double number, int precision) {
        if(null == number || 0.0 == number ) return 0.0;
        BigDecimal bg = new BigDecimal(number);
        return bg.setScale(precision, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
    /**
     * å¯¹float类型的数值保留指定位数的小数。<br>
     * è¯¥æ–¹æ³•舍入模式:向“最接近的”数字舍入,如果与两个相邻数字的距离相等,则为向上舍入的舍入模式。<br>
     * <b>注意:</b>如果精度要求比较精确请使用 keepPrecision(String number, int precision)方法
     * @param number  è¦ä¿ç•™å°æ•°çš„æ•°å­—
     * @param precision å°æ•°ä½æ•°
     * @return float å¦‚果数值较大,则使用科学计数法表示
     */
    public static float keepPrecision(Float number, int precision) {
        if(null == number) return 0f;
        BigDecimal bg = new BigDecimal(number);
        return bg.setScale(precision, BigDecimal.ROUND_HALF_UP).floatValue();
    }
    /**
     * double转字符串,避免出现科学计数法
     * @param d
     * @return
     */
    public static String doubleToStr(Double d) {
        if(null == d) return "";
        DecimalFormat df = new DecimalFormat("0.0");
        return df.format(d);
    }
}
src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1302.java
@@ -115,9 +115,21 @@
                if (StringUtils.isEmpty(fz40Grain.getCableCir())) {
                    api1302.setLswdzjh(getTempPointList1(fz40Grain.getPoints(), fz40Grain.getCable()));
                    api1302.setLssdzjh(getHumPointList1(fz40Grain.getPoints(), fz40Grain.getCable()));
                    if(StringUtils.isEmpty(api1302.getLswdzjh())){
                        continue;
                    }
                    if(StringUtils.isEmpty(api1302.getLssdzjh())){
                        continue;
                    }
                } else {
                    api1302.setLswdzjh(getTempPointList2(fz40Grain.getPoints(), fz40Grain.getCable(), fz40Grain.getCableCir()));
                    api1302.setLssdzjh(getHumPointList2(fz40Grain.getPoints(), fz40Grain.getCable(), fz40Grain.getCableCir()));
                    if(StringUtils.isEmpty(api1302.getLswdzjh())){
                        continue;
                    }
                    if(StringUtils.isEmpty(api1302.getLssdzjh())){
                        continue;
                    }
                }
                api1302.setZhgxsj(new Date());
src/main/java/com/fzzy/push/sh2023/SH2023ApiRemoteService.java
@@ -16,6 +16,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import com.fzzy.api.utils.NumberUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -596,16 +597,14 @@
            Api1302 apiData = (Api1302) data;
            BeanUtils.copyProperties(apiData, api1302);
            api1302.setBjw(ShAreaBjw.getBjw(code));
            api1302.setCpjw(String.valueOf(apiData.getLspjw()));
            api1302.setCzgw(String.valueOf(apiData.getLspjw()));
            api1302.setCzdw(String.valueOf(apiData.getLspjw()));
            api1302.setGfwjw(String.valueOf(apiData.getLspjw()));
            api1302.setLwmx(apiData.getLswdzjh());
            api1302.setLqjs("1");
            //批次号
            List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1302.getHwdm());
            if (null != api1208List && api1208List.size() > 0) {
                api1302.setPch(apiData.getHwdm() + api1208List.get(0).getShnd());
            }
            //统计层高、层低、层均温等信息
            api1302 = packageData1302(api1302);
            //设置空属性为默认值
            changeObject(api1302);
@@ -837,16 +836,124 @@
        return data;
    }
    private String getWjmc(String wjlx, String wjmc) {
        if ("2".equals(wjlx) || "3".equals(wjlx) || "4".equals(wjlx) || "5".equals(wjlx)) {
            if (wjmc.endsWith(".jpg")) {
                wjmc = wjmc.replaceAll(".jpg", "_00.jpg");
    /**
     * æ ¹æ®ä¸Šæµ·æ•°æ®æ ¼å¼è¿›è¡Œå°è£…
     * å±‚均温:
     * å±‚高温:
     * å±‚低温:
     * å„范围均温:
     * ç²®æ¸©æ˜Žç»†ï¼š
     * ç²®æ¸©çŠ¶æ€ï¼š
     * å¼‚常点个数:
     *
     * @param data
     * @return
     */
    private SH2023Api1302 packageData1302(SH2023Api1302 data) {
        if (StringUtils.isEmpty(data.getLswdzjh())) {
            return data;
            }
            if (wjmc.endsWith(".png")) {
                wjmc = wjmc.replaceAll(".png", "_00.png");
        String lswdzjh = data.getLswdzjh();
        String[] split = lswdzjh.split("\\|");
        Map<Integer, List<Double>> map = new HashMap<>();
        Integer ceng;
        Integer errorNum = 0;  //异常点个数
        String lwmx = "";   //粮温明细
        String lwzt = "0";  //粮温状态
        String gfwjw = "";  //各范围均温
        for (String s : split) {
            String[] grain = s.split(",");
            ceng = Integer.valueOf(grain[1]);
            if (null == map.get(ceng)) {
                map.put(ceng, new ArrayList<>());
            }
            map.get(ceng).add(Double.valueOf(grain[0]));
            lwmx += grain[1] + ":" + grain[2] + ":" + grain[3] + "$" + grain[0];
            if (Double.valueOf(grain[0]) <= -100) {
                lwmx += "$" + "1" + "#";
                errorNum++;
            } else {
                lwmx += "$" + "5" + "#";
            }
        }
        return wjmc;
        String cpjw = "";  //层平均温
        String czgw = "";  //层最高温
        String czdw = "";  //层最低温
        List<Double> payPoints;
        Double sum;
        int num;
        Double tempH;
        Double tempL;
        Double tempA;
        Double tempValue1 = 0.0; //范围均温1
        Double tempValue2 = 0.0; //范围均温2
        Double tempValue3 = 0.0; //范围均温3
        Integer numValue = 0; //计算范围均温
        for (Integer cengNum : map.keySet()) {
            payPoints = map.get(cengNum);
            sum = 0.0;
            num = 0;
            tempH = null;
            tempL = null;
            tempA = 0.0;
            for (Double point : payPoints) {
                if(point > -100){
                    sum += point;
                    num++;
                    if (tempH == null) {
                        tempH = point;
                    }
                    if (tempL == null) {
                        tempL = point;
                    }
                    if (tempH < point) {
                        tempH = point;
                    }
                    if (tempL > point) {
                        tempL = point;
                    }
                }
            }
            if (num > 0) {
                tempA = sum / num;
            }
            cpjw += cengNum + "$" + NumberUtil.keepPrecision(tempA, 1) + "#";
            czgw += cengNum + "$" + tempH + "#";
            czdw += cengNum + "$" + tempL + "#";
            //范围均温封装
            if (cengNum == 1) {
                tempValue1 = NumberUtil.keepPrecision(tempA, 1);
            } else if (cengNum == map.keySet().size()) {
                tempValue3 = NumberUtil.keepPrecision(tempA, 1);
            } else {
                tempValue2 += tempA;
                numValue++;
            }
        }
        if (errorNum > 0) {
            lwzt = "2";
        }
        if (numValue > 0) {
            tempValue2 = NumberUtil.keepPrecision(tempValue2 / numValue, 1);
        }
        gfwjw += tempValue1 + "#";
        if (map.keySet().size() == 2) {
            gfwjw += tempValue3 + "#";
        }
        if (map.keySet().size() > 3) {
            gfwjw += tempValue2 + "#" + tempValue3 + "#";
        }
        data.setCpjw(cpjw);
        data.setCzgw(czgw);
        data.setCzdw(czdw);
        data.setGfwjw(gfwjw);
        data.setLwmx(lwmx);
        data.setLwzt(lwzt);
        data.setYcdgs(errorNum);
        return data;
    }
    /**
@@ -867,28 +974,7 @@
        }
    }
    /**
     * Object类型转变为List
     *
     * @param obj
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> List<T> castList(Object obj, Class<T> clazz) {
        List<T> result = new ArrayList<T>();
        if (obj instanceof List<?>) {
            for (Object o : (List<?>) obj) {
                result.add(clazz.cast(o));
            }
            return result;
        }
        return null;
    }
    private List<SHFinanceDto> copyApi1503(Api1503 data) {
        Api1503 api1503 = data;
    private List<SHFinanceDto> copyApi1503(Api1503 api1503) {
        List<SHFinanceDto> list = new ArrayList<>();
        SHFinanceDto shFinanceDto = new SHFinanceDto();
        shFinanceDto.setDwdm(api1503.getDwdm());
@@ -938,8 +1024,7 @@
        return list;
    }
    private List<SHFinanceDto> copyApi1502(Api1502 data) {
        Api1502 api1502 = data;
    private List<SHFinanceDto> copyApi1502(Api1502 api1502) {
        List<SHFinanceDto> list = new ArrayList<>();
        SHFinanceDto shFinanceDto = new SHFinanceDto();
        shFinanceDto.setDwdm(api1502.getDwdm());
@@ -991,8 +1076,7 @@
        return list;
    }
    private List<SHFinanceDto> copyApi1501(Api1501 data) {
        Api1501 api1501 = data;
    private List<SHFinanceDto> copyApi1501(Api1501 api1501) {
        List<SHFinanceDto> list = new ArrayList<>();
        SHFinanceDto shFinanceDto = new SHFinanceDto();
        shFinanceDto.setDwdm(api1501.getDwdm());
@@ -1089,6 +1173,18 @@
        list.add(shFinanceDto);
    }
    private String getWjmc(String wjlx, String wjmc) {
        if ("2".equals(wjlx) || "3".equals(wjlx) || "4".equals(wjlx) || "5".equals(wjlx)) {
            if (wjmc.endsWith(".jpg")) {
                wjmc = wjmc.replaceAll(".jpg", "_00.jpg");
            }
            if (wjmc.endsWith(".png")) {
                wjmc = wjmc.replaceAll(".png", "_00.png");
            }
        }
        return wjmc;
    }
    private Object changeObject(Object object) {
        // ä½¿ç”¨åå°„获取属性列表 vo为实体对象名
        Field[] fields = object.getClass().getDeclaredFields();
src/main/resources/application-pro5306.yml
@@ -9,16 +9,16 @@
  datasource:
    #主数据源
    primary:
      url: jdbc:mysql://127.0.0.1:3306/igds_api?useUnicode=true&characterEncoding=utf-8&useSSL=false
      url: jdbc:mysql://127.0.0.1:3306/igds_api?useUnicode=true&characterEncoding=utf-8
      driver-class-name: com.mysql.jdbc.Driver
      username: root
      password: root
      password: Abc123..
    #次数据源
    secondary:
      url: jdbc:mysql://127.0.0.1:3306/igds_master?useUnicode=true&characterEncoding=utf-8&useSSL=false
      url: jdbc:mysql://127.0.0.1:3306/igds_master?useUnicode=true&characterEncoding=utf-8
      driver-class-name: com.mysql.jdbc.Driver
      username: root
      password: root
      password: Abc123..
  jpa:
    #主jpa配置
    primary: