From 8b34279deea241025e328ae24355bcbc93e9fba7 Mon Sep 17 00:00:00 2001
From: Josez <1123010482@qq.com>
Date: Fri, 20 Sep 2024 11:23:57 +0800
Subject: [PATCH] =?UTF-8?q?lng=E6=97=A5=E6=8A=A5=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E6=8B=89=E5=8F=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../pom.xml | 16 +-
.../config/StationV3CollectorJobConfig.java | 3 +
.../stationv3/jobhandler/LngCollectorJob.java | 159 ++++++++++++++++++
3 files changed, 176 insertions(+), 2 deletions(-)
create mode 100644 wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/src/main/java/com/wanhua/frameless/stationv3/jobhandler/LngCollectorJob.java
diff --git a/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/pom.xml b/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/pom.xml
index b929b2a5..31cb9085 100644
--- a/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/pom.xml
+++ b/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/pom.xml
@@ -20,7 +20,7 @@
org.slf4j
- slf4j-log4j12
+ slf4j-reload4j
${slf4j-api.version}
@@ -38,6 +38,18 @@
${project.parent.version}
+
+ com.wanhua
+ stationv3-http-data-collector
+ 1.0-SNAPSHOT
+
+
+
+ com.wanhua
+ stationv3-base-dao-service
+ 1.0-SNAPSHOT
+
+
@@ -84,4 +96,4 @@
-
\ No newline at end of file
+
diff --git a/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/src/main/java/com/wanhua/frameless/stationv3/config/StationV3CollectorJobConfig.java b/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/src/main/java/com/wanhua/frameless/stationv3/config/StationV3CollectorJobConfig.java
index 87a38807..31048816 100644
--- a/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/src/main/java/com/wanhua/frameless/stationv3/config/StationV3CollectorJobConfig.java
+++ b/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/src/main/java/com/wanhua/frameless/stationv3/config/StationV3CollectorJobConfig.java
@@ -1,6 +1,7 @@
package com.wanhua.frameless.stationv3.config;
+import com.wanhua.frameless.stationv3.jobhandler.LngCollectorJob;
import com.xxl.job.core.executor.impl.XxlJobSimpleExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,6 +49,8 @@ public class StationV3CollectorJobConfig {
// registry job bean
xxlJobExecutor.setXxlJobBeanList(Arrays.asList(new StationV3CollectorJob()));
+ xxlJobExecutor.setXxlJobBeanList(Arrays.asList(new LngCollectorJob()));
+
// start executor
try {
xxlJobExecutor.start();
diff --git a/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/src/main/java/com/wanhua/frameless/stationv3/jobhandler/LngCollectorJob.java b/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/src/main/java/com/wanhua/frameless/stationv3/jobhandler/LngCollectorJob.java
new file mode 100644
index 00000000..4f4f359b
--- /dev/null
+++ b/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/src/main/java/com/wanhua/frameless/stationv3/jobhandler/LngCollectorJob.java
@@ -0,0 +1,159 @@
+package com.wanhua.frameless.stationv3.jobhandler;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.wanhua.lng.daySale.model.SaleDaily;
+import com.wanhua.lng.daySale.model.SaleDailyInfo;
+import com.wanhua.lng.daySale.service.impl.SaleDailyInfoServiceImpl;
+import com.wanhua.lng.daySale.service.impl.SaleDailyServiceImpl;
+import com.wanhua.stationservice.baseDaoService.service.impl.PumpServiceImpl;
+import com.wanhua.stationservice.baseutils.security.CommonBasedAESUtil;
+import com.wanhua.stationv3.data.collector.CollectorTest;
+import com.wanhua.stationv3.data.collector.LngCollector;
+import com.wanhua.stationv3.data.collector.TokenUtil;
+import com.xxl.job.core.context.XxlJobHelper;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import io.netty.util.internal.StringUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * XxlJob开发示例(Bean模式)
+ *
+ * 开发步骤:
+ * 1、任务开发:在Spring Bean实例中,开发Job方法;
+ * 2、注解配置:为Job方法添加注解 "@XxlJob(value="自定义jobhandler名称", init = "JobHandler初始化方法", destroy = "JobHandler销毁方法")",注解value值对应的是调度中心新建任务的JobHandler属性的值。
+ * 3、执行日志:需要通过 "XxlJobHelper.log" 打印执行日志;
+ * 4、任务结果:默认任务结果为 "成功" 状态,不需要主动设置;如有诉求,比如设置任务结果为失败,可以通过 "XxlJobHelper.handleFail/handleSuccess" 自主设置任务结果;
+ *
+ * @author xuxueli 2019-12-11 21:52:51
+ */
+public class LngCollectorJob {
+ private static Logger logger = LoggerFactory.getLogger(LngCollectorJob.class);
+
+ SaleDailyServiceImpl dailyServiceImpl = new SaleDailyServiceImpl();
+ SaleDailyInfoServiceImpl dailyInfoServiceImpl = new SaleDailyInfoServiceImpl();
+
+
+ /**
+ * 1、简单任务示例(Bean模式)
+ */
+ @XxlJob("getSaleDaily")
+ public void demoJobHandler() throws Exception {
+ XxlJobHelper.log("XXL-JOB,begin start ");
+
+ String param = XxlJobHelper.getJobParam();
+ Map params = JSONObject.parseObject(param,Map.class);
+ //{"time":"2024-01-01/2024-01-03","code":"1-A6201-C001-S085,1-A6201-C001-S084"}
+ LocalDate yesterday = LocalDate.now().minusDays(1);
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ String formattedDate = yesterday.format(formatter);
+
+ String code = params.get("code");
+
+ String fullToken = TokenUtil.getTokenFromServer("xieke");
+ XxlJobHelper.log("token: "+ fullToken);
+ String secondsFormat = fullToken.substring(0,15);
+ Long sinceSeconds = Long.parseLong(secondsFormat);
+ XxlJobHelper.log("since seconds: "+ sinceSeconds);
+ String tokenFormat = fullToken.substring(15);
+ String newToken = CommonBasedAESUtil.decrypt("12345678900abcde", "78945612300abcde", tokenFormat);
+ newToken = newToken.substring(0, newToken.indexOf("SALT1234567890"));
+ XxlJobHelper.log("realtoken "+ newToken);
+ String token = newToken;
+
+
+ if(!StringUtil.isNullOrEmpty(params.get("time"))){
+ String times = params.get("time");
+ String start = times.split("/")[0];
+ String end = times.split("/")[1];
+
+
+ }else{
+ String[] codes = code.split(",");
+ for (String codeParam : codes){
+ XxlJobHelper.log("start get data:"+codeParam+",time:"+formattedDate);
+ Map dataMap = LngCollector.getTankGunInfo(codeParam,formattedDate,token);
+
+ String businessDay = dataMap.get("businessDay").toString();
+
+ // 期初库存、本期进货、加气机发出量、数量、单价、本期损溢处理、期末库存
+ JSONArray gasSoldList =(JSONArray) dataMap.get("gasSoldList");
+
+
+
+ if(gasSoldList.size()>0){
+ JSONObject sold = gasSoldList.getJSONObject(0);
+ SaleDaily daily = new SaleDaily();
+ daily.setBusinessDay(businessDay);
+ daily.setStationCode(code);
+ daily.setStartVolume(sold.get("startVolume").toString());
+ daily.setEndVolume(sold.get("endVolume").toString());
+ daily.setPurchaseVolume(sold.get("purchaseVolume").toString());
+ daily.setIssuedVolume(sold.get("issuedVolume").toString());
+ daily.setProfitLossVolume(sold.get("profitLossVolume").toString());
+
+ JSONArray gasSoldItemList = sold.getJSONArray("gasSoldItemList");
+ if(gasSoldItemList.size()>0){
+ JSONObject gasSold = gasSoldItemList.getJSONObject(0);
+ daily.setUnitPrice(gasSold.get("unitPrice").toString());
+ daily.setSalesVolume(gasSold.get("salesVolume").toString());
+ }
+
+ dailyServiceImpl.saveOne(daily);
+ }
+
+
+ //不同支付类型销售数据统计
+ JSONArray gasPaymentList =(JSONArray) dataMap.get("gasPaymentList");
+ if(gasSoldList.size()>0){
+// for(Object info : gasPaymentList) {
+// JSONObject sold = (JSONObject) JSONObject.toJSON(info);
+// SaleDailyInfo daily = new SaleDailyInfo();
+// daily.setBusinessDay(businessDay);
+// daily.setStationCode(code);
+// daily.setUnitPrice(sold.get("unitPrice"));
+// daily.setEndVolume(sold.get("endVolume").toString());
+// daily.setPurchaseVolume(sold.get("purchaseVolume").toString());
+// daily.setIssuedVolume(sold.get("issuedVolume").toString());
+// daily.setProfitLossVolume(sold.get("profitLossVolume").toString());
+//
+// JSONArray gasSoldItemList = sold.getJSONArray("gasSoldItemList");
+// if (gasSoldItemList.size() > 0) {
+// JSONObject gasSold = gasSoldItemList.getJSONObject(0);
+// daily.setUnitPrice(gasSold.get("unitPrice").toString());
+// daily.setSalesVolume(gasSold.get("salesVolume").toString());
+// }
+//
+// dailyInfoServiceImpl.saveOne(daily);
+// }
+ }
+ XxlJobHelper.log("start get data:"+codeParam+" end");
+ }
+ }
+
+
+ }
+
+
+ /**
+ * 5、生命周期任务示例:任务初始化与销毁时,支持自定义相关逻辑;
+ */
+ @XxlJob(value = "demoJobHandler2", init = "init", destroy = "destroy")
+ public void demoJobHandler2() throws Exception {
+ XxlJobHelper.log("XXL-JOB, Hello World.");
+ }
+ public void init(){
+ logger.info("init");
+ }
+ public void destroy(){
+ logger.info("destroy");
+ }
+
+
+}