|
@@ -1,10 +1,11 @@
|
|
|
package cn.com.taiji.mqcrj.task;
|
|
|
|
|
|
import cn.com.taiji.mqcrj.config.RequestDataHelper;
|
|
|
+import cn.com.taiji.mqcrj.entity.AjxxBean;
|
|
|
import cn.com.taiji.mqcrj.entity.AjxyrBean;
|
|
|
import cn.com.taiji.mqcrj.entity.MqwgrBean;
|
|
|
import cn.com.taiji.mqcrj.mapper.BaseCreateNewTableMapper;
|
|
|
-import cn.com.taiji.mqcrj.mapper.MqwgrMapper;
|
|
|
+import cn.com.taiji.mqcrj.service.AjxxService;
|
|
|
import cn.com.taiji.mqcrj.service.AjxyrService;
|
|
|
import cn.com.taiji.mqcrj.service.MqwgrService;
|
|
|
import cn.com.taiji.mqcrj.utils.JDBCUtils;
|
|
@@ -37,10 +38,13 @@ public class OracleScheduleTask {
|
|
|
private AjxyrService ajxyrService;
|
|
|
|
|
|
@Resource
|
|
|
+ private AjxxService ajxxService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
private MqwgrService mqwgrService;
|
|
|
|
|
|
@Scheduled(cron = "2 55 2 * * ?")
|
|
|
- public void AjxyrTask() {
|
|
|
+ public void ajxyrTask() {
|
|
|
log.info("执行定时任务 AjxyrTask -{}",DateUtil.date());
|
|
|
Connection connection = JDBCUtils.getConnection();
|
|
|
String sqlCount = "select count(*) from hndmc.v_ajxyr";
|
|
@@ -87,7 +91,7 @@ public class OracleScheduleTask {
|
|
|
AjxyrBean objectBean = JSONObject.parseObject(jsonStr, AjxyrBean.class);
|
|
|
objectBeanList.add(objectBean);
|
|
|
}
|
|
|
- RequestDataHelper.setRequestData(new HashMap<String, Object>() {{
|
|
|
+ RequestDataHelper.setRequestData(new HashMap<String, Object>(16) {{
|
|
|
put("v_sg_", "v_sg_ajxyr_"+DateUtil.format(DateUtil.yesterday(), "YYYYMMdd"));
|
|
|
}});
|
|
|
ajxyrService.saveBatch(objectBeanList);
|
|
@@ -111,7 +115,7 @@ public class OracleScheduleTask {
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "25 53 1 * * ?")
|
|
|
- public void MqwgrTask() {
|
|
|
+ public void mqwgrTask() {
|
|
|
log.info("执行定时任务 MqwgrTask -{}",DateUtil.date());
|
|
|
Connection connection = JDBCUtils.getConnection();
|
|
|
String sqlCount = "select count(*) from hndmc.v_sg_mqwgr";
|
|
@@ -157,7 +161,7 @@ public class OracleScheduleTask {
|
|
|
MqwgrBean objectBean = JSONObject.parseObject(jsonStr, MqwgrBean.class);
|
|
|
mqwgrBeans.add(objectBean);
|
|
|
}
|
|
|
- RequestDataHelper.setRequestData(new HashMap<String, Object>() {{
|
|
|
+ RequestDataHelper.setRequestData(new HashMap<String, Object>(16) {{
|
|
|
put("v_sg_", "v_sg_mqwgr_" + DateUtil.format(DateUtil.yesterday(), "YYYYMMdd"));
|
|
|
}});
|
|
|
mqwgrService.saveBatch(mqwgrBeans);
|
|
@@ -178,4 +182,74 @@ public class OracleScheduleTask {
|
|
|
JDBCUtils.closeResource(connection,preparedStatement,resultSet);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Scheduled(cron = "25 23 1 * * ?")
|
|
|
+ public void ajxxTask() {
|
|
|
+ log.info("执行定时任务 AjxxTask -{}",DateUtil.date());
|
|
|
+ Connection connection = JDBCUtils.getConnection();
|
|
|
+ String sqlCount = "select count(*) from hndmc.v_sg_ajxx";
|
|
|
+ PreparedStatement ps = null;
|
|
|
+ ResultSet rs = null;
|
|
|
+ PreparedStatement preparedStatement = null;
|
|
|
+ ResultSet resultSet = null;
|
|
|
+ try {
|
|
|
+ ps = connection.prepareStatement(sqlCount);
|
|
|
+ rs = ps.executeQuery();
|
|
|
+ int count;
|
|
|
+ if(rs.next()){
|
|
|
+ count = rs.getInt(1);
|
|
|
+ log.info("AjxxTask-数据总量是:{}",count);
|
|
|
+ if(count>0){
|
|
|
+ //创建新表
|
|
|
+ String format = DateUtil.format(DateUtil.yesterday(), "YYYYMMdd");
|
|
|
+ baseCreateNewTableMapper.createTableAjxx("v_sg_ajxx_"+format);
|
|
|
+ }else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for(int x = 0;x<count/10000+1;x++) {
|
|
|
+ int max = (x + 1) * 10000;
|
|
|
+ int min = x * 10000;
|
|
|
+ String sql = "select * from (select v.*,rownum rn from hndmc.v_sg_ajxx v where ROWNUM <= "+max+") where rn>"+min;
|
|
|
+ preparedStatement = connection.prepareStatement(sql);
|
|
|
+ resultSet = preparedStatement.executeQuery();
|
|
|
+
|
|
|
+ // 获取ResultSet对象的列的数量、类型和属性。
|
|
|
+ ResultSetMetaData md = resultSet.getMetaData();
|
|
|
+ int columnCount = md.getColumnCount();
|
|
|
+ // 将ResultSet对象的列名和值存到map中,再将map转换为json字符串,最后将json字符串转换为实体类对象
|
|
|
+ List<AjxxBean> ajxxBeans = new ArrayList<>();
|
|
|
+ Map<String, Object> rowData = new HashMap<>(16);
|
|
|
+ while (resultSet.next()) {
|
|
|
+ for (int i = 1; i <= columnCount; i++) {
|
|
|
+ rowData.put(md.getColumnLabel(i), resultSet.getObject(i));
|
|
|
+ }
|
|
|
+ String jsonStr = JSONObject.toJSONString(rowData);
|
|
|
+ AjxxBean objectBean = JSONObject.parseObject(jsonStr, AjxxBean.class);
|
|
|
+ ajxxBeans.add(objectBean);
|
|
|
+ }
|
|
|
+ RequestDataHelper.setRequestData(new HashMap<String, Object>(16) {{
|
|
|
+ put("v_sg_", "v_sg_ajxx_" + DateUtil.format(DateUtil.yesterday(), "YYYYMMdd"));
|
|
|
+ }});
|
|
|
+ ajxxService.saveBatch(ajxxBeans);
|
|
|
+ preparedStatement.close();
|
|
|
+ resultSet.close();
|
|
|
+ }
|
|
|
+ log.info("数据导入结束后表名修改");
|
|
|
+ //数据导入结束后表名修改
|
|
|
+ baseCreateNewTableMapper.modifyTableName("v_sg_ajxx_his"+DateUtil.format(DateUtil.yesterday(), "YYYYMMdd"),"v_sg_ajxx");
|
|
|
+ baseCreateNewTableMapper.modifyTableName("v_sg_ajxx","v_sg_ajxx_"+DateUtil.format(DateUtil.yesterday(), "YYYYMMdd"));
|
|
|
+
|
|
|
+ //删除七天前的数据表
|
|
|
+ baseCreateNewTableMapper.dropTable("v_sg_ajxx_his"+DateUtil.format(DateUtil.offsetDay(DateUtil.date(),-8), "YYYYMMdd"));
|
|
|
+ } catch (SQLException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }finally {
|
|
|
+ JDBCUtils.closeResource(connection,ps,rs);
|
|
|
+ JDBCUtils.closeResource(connection,preparedStatement,resultSet);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|