From 2c08948a713f834f3a6b033495291bfddcbc0c50 Mon Sep 17 00:00:00 2001
From: CZT <czt18638530771@163.com>
Date: 星期三, 22 十一月 2023 19:26:14 +0800
Subject: [PATCH] 上海接口新增温湿度数据封装
---
src/main/java/com/fzzy/api/entity/Api1302.java | 29 ++---
src/main/resources/application-pro5306.yml | 8
src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1302.java | 12 ++
src/main/java/com/fzzy/api/utils/NumberUtil.java | 49 +++++++++
src/main/java/com/fzzy/push/sh2023/SH2023ApiRemoteService.java | 174 +++++++++++++++++++++++++++-------
5 files changed, 213 insertions(+), 59 deletions(-)
diff --git a/src/main/java/com/fzzy/api/entity/Api1302.java b/src/main/java/com/fzzy/api/entity/Api1302.java
index 6935d4d..783715c 100644
--- a/src/main/java/com/fzzy/api/entity/Api1302.java
+++ b/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 = "璐т綅浠g爜" )
- @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;
}
diff --git a/src/main/java/com/fzzy/api/utils/NumberUtil.java b/src/main/java/com/fzzy/api/utils/NumberUtil.java
new file mode 100644
index 0000000..4582084
--- /dev/null
+++ b/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 {
+
+ /**
+ * 瀵筪ouble绫诲瀷鐨勬暟鍊间繚鐣欐寚瀹氫綅鏁扮殑灏忔暟銆�<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();
+ }
+
+ /**
+ * 瀵筬loat绫诲瀷鐨勬暟鍊间繚鐣欐寚瀹氫綅鏁扮殑灏忔暟銆�<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);
+ }
+
+}
diff --git a/src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1302.java b/src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1302.java
index 4defff4..bf19ffb 100644
--- a/src/main/java/com/fzzy/async/fzzy40/impl/Fzzy40Sync1302.java
+++ b/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());
diff --git a/src/main/java/com/fzzy/push/sh2023/SH2023ApiRemoteService.java b/src/main/java/com/fzzy/push/sh2023/SH2023ApiRemoteService.java
index 6870ad1..7bee33f 100644
--- a/src/main/java/com/fzzy/push/sh2023/SH2023ApiRemoteService.java
+++ b/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;
+ }
+ 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<>());
}
- if (wjmc.endsWith(".png")) {
- wjmc = wjmc.replaceAll(".png", "_00.png");
+ 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绫诲瀷杞彉涓篖ist
- *
- * @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();
diff --git a/src/main/resources/application-pro5306.yml b/src/main/resources/application-pro5306.yml
index 72304b3..3625350 100644
--- a/src/main/resources/application-pro5306.yml
+++ b/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:
#涓籮pa閰嶇疆
primary:
--
Gitblit v1.9.3