|
|
@ -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<String,String> 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<String,Object> 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");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|