parent
9ad736dfdb
commit
43af7a16f6
@ -1,115 +1,115 @@
|
||||
package com.ssf.mysqloracletest.task;
|
||||
|
||||
import com.ssf.mysqloracletest.domain.JcjJjxxViewMysql;
|
||||
import com.ssf.mysqloracletest.domain.JcjJjxxViewOracle;
|
||||
import com.ssf.mysqloracletest.service.JcjJjxxViewMysqlService;
|
||||
import com.ssf.mysqloracletest.service.JcjJjxxViewOracleService;
|
||||
import com.ssf.mysqloracletest.utils.ConfigParam;
|
||||
import com.ssf.mysqloracletest.utils.NumKit;
|
||||
import com.ssf.mysqloracletest.utils.StringKit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* 用户数据接入
|
||||
*/
|
||||
@Component
|
||||
public class JcjJjxxTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(JcjJjxxTask.class);
|
||||
|
||||
@Resource
|
||||
private JcjJjxxViewMysqlService jcjJjxxViewMysqlService;
|
||||
|
||||
@Resource
|
||||
private JcjJjxxViewOracleService jcjJjxxViewOracleService;
|
||||
|
||||
final int oncesCounts = NumKit.checkInt(ConfigParam.oncesCounts) == 0 ? 1000 : NumKit.checkInt(ConfigParam.oncesCounts);
|
||||
|
||||
private boolean JjxxTag = false;
|
||||
|
||||
/**
|
||||
* 连云港 对接海康平台获取人员基础数据
|
||||
* //
|
||||
*/
|
||||
@Scheduled(initialDelay = 100, fixedDelay = 3000)
|
||||
public void transJjxx() {
|
||||
|
||||
if (JjxxTag) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!"true".equals(ConfigParam.JjxxSwitch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
int countJjxx = jcjJjxxViewOracleService.countJjxx();
|
||||
logger.info("countJjxx:" + countJjxx);
|
||||
|
||||
logger.info("countJjxx:" + countJjxx);
|
||||
if (countJjxx > 0) {
|
||||
|
||||
JjxxTag = true;
|
||||
|
||||
int count = countJjxx / oncesCounts;
|
||||
CountDownLatch latch = new CountDownLatch(count);
|
||||
ExecutorService JjxxPool = Executors.newFixedThreadPool(50);
|
||||
|
||||
for (int i = 0; i <= count; i++) {
|
||||
Map JjxxMap = new HashMap();
|
||||
JjxxMap.put("rowStart", i * oncesCounts);
|
||||
JjxxMap.put("rowEnd", (i + 1) * oncesCounts);
|
||||
JjxxPool.submit(() -> {
|
||||
try {
|
||||
List<JcjJjxxViewOracle> Jjxxs = jcjJjxxViewOracleService.getJjxxList(JjxxMap);
|
||||
for (JcjJjxxViewOracle Jjxx : Jjxxs) {
|
||||
JcjJjxxViewMysql sBean = new JcjJjxxViewMysql();
|
||||
BeanUtils.copyProperties(Jjxx, sBean);
|
||||
//确定一个数据是否唯一
|
||||
JcjJjxxViewMysql checkJjxx = jcjJjxxViewMysqlService.selectJcjJxxByJJBH(Jjxx.getJJBH());
|
||||
if (checkJjxx == null) {
|
||||
jcjJjxxViewMysqlService.insertJjxx(sBean);
|
||||
logger.info("Jjxx-" + Jjxx.getJJBH() + ":插入成功");
|
||||
} else {
|
||||
jcjJjxxViewMysqlService.updateJjxxByJJBH(sBean);
|
||||
logger.info("Jjxx-" + Jjxx.getJJBH() + ":更新成功");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("Jjxxs:" + StringKit.getTrace(e));
|
||||
}
|
||||
latch.countDown();
|
||||
});
|
||||
logger.info("JjxxMap数据总量:" + countJjxx + "," + "当前处理下标:" + JjxxMap.get("rowStart") + "/" + JjxxMap.get("rowEnd"));
|
||||
}
|
||||
|
||||
try {
|
||||
// Wait for all threads to complete
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 关闭线程池
|
||||
JjxxPool.shutdown();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.info(StringKit.getTrace(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//package com.ssf.mysqloracletest.task;
|
||||
//
|
||||
//import com.ssf.mysqloracletest.domain.JcjJjxxViewMysql;
|
||||
//import com.ssf.mysqloracletest.domain.JcjJjxxViewOracle;
|
||||
//import com.ssf.mysqloracletest.service.JcjJjxxViewMysqlService;
|
||||
//import com.ssf.mysqloracletest.service.JcjJjxxViewOracleService;
|
||||
//import com.ssf.mysqloracletest.utils.ConfigParam;
|
||||
//import com.ssf.mysqloracletest.utils.NumKit;
|
||||
//import com.ssf.mysqloracletest.utils.StringKit;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.beans.BeanUtils;
|
||||
//import org.springframework.scheduling.annotation.Scheduled;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.concurrent.CountDownLatch;
|
||||
//import java.util.concurrent.ExecutorService;
|
||||
//import java.util.concurrent.Executors;
|
||||
//
|
||||
///**
|
||||
// * 用户数据接入
|
||||
// */
|
||||
//@Component
|
||||
//public class JcjJjxxTask {
|
||||
//
|
||||
// private static final Logger logger = LoggerFactory.getLogger(JcjJjxxTask.class);
|
||||
//
|
||||
// @Resource
|
||||
// private JcjJjxxViewMysqlService jcjJjxxViewMysqlService;
|
||||
//
|
||||
// @Resource
|
||||
// private JcjJjxxViewOracleService jcjJjxxViewOracleService;
|
||||
//
|
||||
// final int oncesCounts = NumKit.checkInt(ConfigParam.oncesCounts) == 0 ? 1000 : NumKit.checkInt(ConfigParam.oncesCounts);
|
||||
//
|
||||
// private boolean JjxxTag = false;
|
||||
//
|
||||
// /**
|
||||
// * 连云港 对接海康平台获取人员基础数据
|
||||
// * //
|
||||
// */
|
||||
// @Scheduled(initialDelay = 100, fixedDelay = 3000)
|
||||
// public void transJjxx() {
|
||||
//
|
||||
// if (JjxxTag) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (!"true".equals(ConfigParam.JjxxSwitch)) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// try {
|
||||
// int countJjxx = jcjJjxxViewOracleService.countJjxx();
|
||||
// logger.info("countJjxx:" + countJjxx);
|
||||
//
|
||||
// logger.info("countJjxx:" + countJjxx);
|
||||
// if (countJjxx > 0) {
|
||||
//
|
||||
// JjxxTag = true;
|
||||
//
|
||||
// int count = countJjxx / oncesCounts;
|
||||
// CountDownLatch latch = new CountDownLatch(count);
|
||||
// ExecutorService JjxxPool = Executors.newFixedThreadPool(50);
|
||||
//
|
||||
// for (int i = 0; i <= count; i++) {
|
||||
// Map JjxxMap = new HashMap();
|
||||
// JjxxMap.put("rowStart", i * oncesCounts);
|
||||
// JjxxMap.put("rowEnd", (i + 1) * oncesCounts);
|
||||
// JjxxPool.submit(() -> {
|
||||
// try {
|
||||
// List<JcjJjxxViewOracle> Jjxxs = jcjJjxxViewOracleService.getJjxxList(JjxxMap);
|
||||
// for (JcjJjxxViewOracle Jjxx : Jjxxs) {
|
||||
// JcjJjxxViewMysql sBean = new JcjJjxxViewMysql();
|
||||
// BeanUtils.copyProperties(Jjxx, sBean);
|
||||
// //确定一个数据是否唯一
|
||||
// JcjJjxxViewMysql checkJjxx = jcjJjxxViewMysqlService.selectJcjJxxByJJBH(Jjxx.getJJBH());
|
||||
// if (checkJjxx == null) {
|
||||
// jcjJjxxViewMysqlService.insertJjxx(sBean);
|
||||
// logger.info("Jjxx-" + Jjxx.getJJBH() + ":插入成功");
|
||||
// } else {
|
||||
// jcjJjxxViewMysqlService.updateJjxxByJJBH(sBean);
|
||||
// logger.info("Jjxx-" + Jjxx.getJJBH() + ":更新成功");
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// logger.info("Jjxxs:" + StringKit.getTrace(e));
|
||||
// }
|
||||
// latch.countDown();
|
||||
// });
|
||||
// logger.info("JjxxMap数据总量:" + countJjxx + "," + "当前处理下标:" + JjxxMap.get("rowStart") + "/" + JjxxMap.get("rowEnd"));
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// // Wait for all threads to complete
|
||||
// latch.await();
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// // 关闭线程池
|
||||
// JjxxPool.shutdown();
|
||||
// }
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// logger.info(StringKit.getTrace(e));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
Loading…
Reference in new issue