|
@@ -1,23 +1,24 @@
|
|
|
package com.util;
|
|
|
|
|
|
import com.business.domain.ImputationData;
|
|
|
+import com.business.mapper.ImputationDataMapper;
|
|
|
import com.business.service.ImputationDataService;
|
|
|
import com.sooka.common.utils.DateUtils;
|
|
|
import com.sooka.common.utils.StringUtils;
|
|
|
+import com.sooka.system.domain.TUInterfaceinfo;
|
|
|
+import com.sooka.system.mapper.TUInterfaceinfoMapper;
|
|
|
import com.sooka.system.service.ITULogService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author limeng
|
|
@@ -35,6 +36,115 @@ public class StaticScheduleTask {
|
|
|
@Autowired
|
|
|
private ImputationDataService imputationDataService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private TUInterfaceinfoMapper tUInterfaceinfoMapper;
|
|
|
+ @Resource
|
|
|
+ private ImputationDataMapper imputationDataMapper;
|
|
|
+
|
|
|
+ /**添加定时任务 每天凌晨1点**/
|
|
|
+ /**
|
|
|
+ * 刷新归集数据分析 更新当月数据
|
|
|
+ */
|
|
|
+ @Scheduled(cron = "0 0 1 * * ?")
|
|
|
+ private void imputationData() {
|
|
|
+ System.out.println("按照年份每年新增一批新数据");
|
|
|
+ imputationDataByYear();//按照年份每年新增一批新数据
|
|
|
+ System.out.println("按照月份每日更新当月数据");
|
|
|
+ imputationDataByMonth();//按照月份每日更新当月数据
|
|
|
+ }
|
|
|
+
|
|
|
+ private void imputationDataByMonth() {
|
|
|
+ String year = new SimpleDateFormat("yyyy").format(new Date());//String year = "2022";
|
|
|
+ String month = new SimpleDateFormat("M").format(new Date());
|
|
|
+ TUInterfaceinfo param = new TUInterfaceinfo();
|
|
|
+ param.setShareType("share_type_2");//市归集
|
|
|
+// param.setNeedRefresh("1");
|
|
|
+ //(164-57) t_guiji_gas_zenner_gas_purchase_center_infor - 归集-市燃气(真兰收费系统)-中心计费购气信息 - 237962 ms
|
|
|
+ //(164-70) t_guiji_gas_zenner_meter_reading_infor - 归集-市燃气(真兰收费系统)-抄表信息 - 352968 ms
|
|
|
+ List<TUInterfaceinfo> tuInterfaceinfoList = tUInterfaceinfoMapper.selectTUInterfaceinfoList(param);
|
|
|
+ for (int i = 0; i < tuInterfaceinfoList.size(); i++) {
|
|
|
+ TUInterfaceinfo tuInterfaceinfo = tuInterfaceinfoList.get(i);
|
|
|
+ String tableName = tuInterfaceinfo.getTableName();
|
|
|
+ if (tableName == null || tableName.equals("") || tableName.equals("t_u_interfaceinfo_emptytable")) {
|
|
|
+ System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + 0 + " ms");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ ImputationData imputationDataParam = new ImputationData();
|
|
|
+ imputationDataParam.setYear(year);
|
|
|
+ imputationDataParam.setTableName(tableName);
|
|
|
+ boolean isExist = !(imputationDataMapper.selectImputationInterface(imputationDataParam).size() == 0);
|
|
|
+ if(!isExist){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("year", year);
|
|
|
+ map.put("month", month);
|
|
|
+ map.put("tableName", tableName);
|
|
|
+ System.out.println(tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + "updating database... id = " + tuInterfaceinfo.getId());
|
|
|
+ Date dateBegin = new Date();
|
|
|
+ ImputationData imputationData = tUInterfaceinfoMapper.imputationDataByMonth(map);
|
|
|
+ Long interval = new Date().getTime() - dateBegin.getTime();//接口查询总数所用时间
|
|
|
+ ImputationData imputationDataInsert = new ImputationData();
|
|
|
+ imputationDataInsert.setYear(year);
|
|
|
+ imputationDataInsert.setMonth(month);
|
|
|
+ imputationDataInsert.setTableName(tableName);
|
|
|
+// imputationDataInsert.setInterfaceName(tuInterfaceinfo.getInterfaceName());//接口名称可能会变
|
|
|
+ imputationDataInsert.setCount(imputationData.getCount());
|
|
|
+ imputationDataMapper.updateImputationInterfaceByYearMonthTableName(imputationDataInsert);
|
|
|
+ System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + interval + " ms");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void imputationDataByYear() {
|
|
|
+ String year = new SimpleDateFormat("yyyy").format(new Date());//String year = "2022";
|
|
|
+ TUInterfaceinfo param = new TUInterfaceinfo();
|
|
|
+ param.setShareType("share_type_2");//市归集
|
|
|
+// param.setNeedRefresh("1");
|
|
|
+ //(164-57) t_guiji_gas_zenner_gas_purchase_center_infor - 归集-市燃气(真兰收费系统)-中心计费购气信息 - 237962 ms
|
|
|
+ //(164-70) t_guiji_gas_zenner_meter_reading_infor - 归集-市燃气(真兰收费系统)-抄表信息 - 352968 ms
|
|
|
+ List<TUInterfaceinfo> tuInterfaceinfoList = tUInterfaceinfoMapper.selectTUInterfaceinfoList(param);
|
|
|
+ for (int i = 0; i < tuInterfaceinfoList.size(); i++) {
|
|
|
+ TUInterfaceinfo tuInterfaceinfo = tuInterfaceinfoList.get(i);
|
|
|
+ String tableName = tuInterfaceinfo.getTableName();
|
|
|
+ if (tableName == null || tableName.equals("") || tableName.equals("t_u_interfaceinfo_emptytable")) {
|
|
|
+ System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + 0 + " ms");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ ImputationData imputationDataParam = new ImputationData();
|
|
|
+ imputationDataParam.setYear(year);
|
|
|
+ imputationDataParam.setTableName(tableName);
|
|
|
+ boolean isExist = !(imputationDataMapper.selectImputationInterface(imputationDataParam).size() == 0);
|
|
|
+ if(isExist){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("year", year);
|
|
|
+ map.put("tableName", tableName);
|
|
|
+ System.out.println(tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + "updating database... id = " + tuInterfaceinfo.getId());
|
|
|
+ Date dateBegin = new Date();
|
|
|
+ ImputationData imputationData = tUInterfaceinfoMapper.imputationData(map);
|
|
|
+ Long interval = new Date().getTime() - dateBegin.getTime();//接口查询总数所用时间
|
|
|
+ ImputationData imputationDataInsert = new ImputationData();
|
|
|
+ imputationDataInsert.setYear(year);
|
|
|
+ imputationDataInsert.setTableName(tableName);
|
|
|
+ imputationDataInsert.setInterfaceName(tuInterfaceinfo.getInterfaceName());
|
|
|
+ imputationDataInsert.setJan(imputationData.getJan());
|
|
|
+ imputationDataInsert.setFeb(imputationData.getFeb());
|
|
|
+ imputationDataInsert.setMar(imputationData.getMar());
|
|
|
+ imputationDataInsert.setApr(imputationData.getApr());
|
|
|
+ imputationDataInsert.setMay(imputationData.getMay());
|
|
|
+ imputationDataInsert.setJun(imputationData.getJun());
|
|
|
+ imputationDataInsert.setJul(imputationData.getJul());
|
|
|
+ imputationDataInsert.setAug(imputationData.getAug());
|
|
|
+ imputationDataInsert.setSep(imputationData.getSep());
|
|
|
+ imputationDataInsert.setOct(imputationData.getOct());
|
|
|
+ imputationDataInsert.setNov(imputationData.getNov());
|
|
|
+ imputationDataInsert.setDecb(imputationData.getDecb());
|
|
|
+ imputationDataMapper.insertImputationInterface(imputationDataInsert);
|
|
|
+ System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + interval + " ms");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**添加定时任务 每天凌晨1点**/
|
|
|
//@Scheduled(cron = "0 0 1 * * ?")
|
|
|
private void configureTasks() {
|