From 05aba0d74b6324a7d7b5e276ab898617334de021 Mon Sep 17 00:00:00 2001 From: Josez <1123010482@qq.com> Date: Thu, 26 Sep 2024 09:44:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E9=94=80=E5=94=AE=E6=8A=A5=E8=A1=A8?= =?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 | 6 + .../stationv3/jobhandler/LngCollectorJob.java | 147 ++++++++++++------ xxl-job-core/pom.xml | 4 +- 3 files changed, 105 insertions(+), 52 deletions(-) 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 9247cff6..14a96fb6 100644 --- a/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/pom.xml +++ b/wanhua-executor-plugins/wanhua-frameless-stationv3-collector-plugin/pom.xml @@ -23,6 +23,11 @@ slf4j-reload4j ${slf4j-api.version} + + org.slf4j + slf4j-api + ${slf4j-api.version} + org.junit.jupiter @@ -70,6 +75,7 @@ org.apache.maven.plugins maven-jar-plugin + 3.4.2 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 index 4f4f359b..0b6e1bb3 100644 --- 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 @@ -6,6 +6,7 @@ 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.lng.daySale.utils.PaymentMethod; import com.wanhua.stationservice.baseDaoService.service.impl.PumpServiceImpl; import com.wanhua.stationservice.baseutils.security.CommonBasedAESUtil; import com.wanhua.stationv3.data.collector.CollectorTest; @@ -19,6 +20,8 @@ import org.slf4j.LoggerFactory; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -73,71 +76,115 @@ public class LngCollectorJob { String start = times.split("/")[0]; String end = times.split("/")[1]; + List timeList = getDatesBetween(start,end); + for(String time : timeList){ + String[] codes = code.split(","); + for (String codeParam : codes){ + getInfo(codeParam,time,token); + } + } }else{ String[] codes = code.split(","); for (String codeParam : codes){ - XxlJobHelper.log("start get data:"+codeParam+",time:"+formattedDate); - Map dataMap = LngCollector.getTankGunInfo(codeParam,formattedDate,token); + getInfo(codeParam,formattedDate,token); + } + } + } - String businessDay = dataMap.get("businessDay").toString(); - // 期初库存、本期进货、加气机发出量、数量、单价、本期损溢处理、期末库存 - JSONArray gasSoldList =(JSONArray) dataMap.get("gasSoldList"); + private static List getDatesBetween(String startDateStr, String endDateStr) { + // 定义日期格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + // 将字符串转换为 LocalDate + LocalDate startDate = LocalDate.parse(startDateStr, formatter); + LocalDate endDate = LocalDate.parse(endDateStr, formatter); - 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); - } + List datesInRange = new ArrayList<>(); + // 使用 while 循环获取范围内的所有日期 + while (!startDate.isAfter(endDate)) { + // 将每个日期格式化为字符串并添加到列表中 + datesInRange.add(startDate.format(formatter)); + // 日期递增一天 + startDate = startDate.plusDays(1); + } + return datesInRange; + } - //不同支付类型销售数据统计 - 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"); + private void getInfo(String codeParam,String formattedDate,String token){ + + + XxlJobHelper.log("start get data:"+codeParam+",time:"+formattedDate); + Map dataMap = LngCollector.getTankGunInfo(codeParam,formattedDate,token); + + XxlJobHelper.log("get data info :"+JSONObject.toJSONString(dataMap)); + + + 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(codeParam); + daily.setStartVolume(sold.get("startVolume").toString()); + daily.setFuelShortName(sold.get("fuelName").toString()); + daily.setFuelNo(sold.get("fuelNo").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); + + + JSONArray gasPaymentItemList =(JSONArray) sold.get("gasPaymentItemList"); + + XxlJobHelper.log("gasPaymentList get data info :"+JSONObject.toJSONString(sold)); + + for(Object item : gasPaymentItemList) { + + JSONObject gasItem = (JSONObject) JSONObject.toJSON(item); + XxlJobHelper.log("gasPaymentItemList get data info :"+JSONObject.toJSONString(gasItem)); + + SaleDailyInfo daily = new SaleDailyInfo(); + daily.setBusinessDay(businessDay); + daily.setStationCode(codeParam); + daily.setUnitPrice(gasItem.get("unitPrice").toString()); + daily.setSalesVolume(gasItem.get("salesVolume").toString()); + daily.setFuelNo(gasItem.get("fuelNo").toString()); + daily.setFuelShortName(gasItem.get("fuelName").toString()); + daily.setPaymentMethod(PaymentMethod.getName(sold.get("paymentMethod").toString())); + daily.setReceivedAmount(gasItem.get("receivedAmount").toString()); + daily.setTotalPaymentAmount(sold.get("totalPaymentAmount").toString()); + dailyInfoServiceImpl.saveOne(daily); + } + } + } + XxlJobHelper.log("start get data:"+codeParam+" end"); } diff --git a/xxl-job-core/pom.xml b/xxl-job-core/pom.xml index df93c522..5afda271 100644 --- a/xxl-job-core/pom.xml +++ b/xxl-job-core/pom.xml @@ -7,7 +7,7 @@ 2.4.2-SNAPSHOT xxl-job-core - pom + jar ${project.artifactId} A distributed task scheduling framework. @@ -72,4 +72,4 @@ https://public.hidotcom.cn/libabc/repository/fdrepo/ - \ No newline at end of file +