处警数据新增字段

develop
hanrenchun 11 months ago
parent a3cae3ee78
commit 6cb1e9f03b

@ -21,6 +21,10 @@ public class MetaHandleAlarmInfo implements Serializable {
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO)
private Long id; private Long id;
/**
*
*/
private String alarmCode;
/** /**
* *
*/ */

@ -0,0 +1,122 @@
package com.ssf.mysqloracletest.task;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ssf.mysqloracletest.domain.JcjCjxxViewMysql;
import com.ssf.mysqloracletest.domain.MetaHandleAlarmInfo;
import com.ssf.mysqloracletest.service.JcjCjxxViewMysqlService;
import com.ssf.mysqloracletest.service.MetaHandleAlarmInfoService;
import com.ssf.mysqloracletest.service.MetaImpUserInfoService;
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.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 MetaHandleAlarmTask {
private static final Logger logger = LoggerFactory.getLogger(MetaHandleAlarmTask.class);
@Resource
private MetaHandleAlarmInfoService metaHandleAlarmInfoService;
@Resource
private JcjCjxxViewMysqlService jcjCjxxViewMysqlService;
final int oncesCounts = NumKit.checkInt(ConfigParam.oncesCounts) == 0 ? 1000 : NumKit.checkInt(ConfigParam.oncesCounts);
private boolean cjxxTag = false;
/**
*
* //
*/
@Scheduled(initialDelay = 100, fixedDelay = 3000)
public void transcjxx() {
if (cjxxTag) {
return;
}
if (!"true".equals(ConfigParam.metaHandleAlarmSwitch)) {
return;
}
try {
int countcjxx = jcjCjxxViewMysqlService.count();
logger.info("countcjxx:" + countcjxx);
if (countcjxx > 0) {
cjxxTag = true;
int count = countcjxx / oncesCounts;
CountDownLatch latch = new CountDownLatch(count);
ExecutorService cjxxPool = Executors.newFixedThreadPool(50);
for (int i = 0; i <= count; i++) {
Map cjxxMap = new HashMap();
cjxxMap.put("rowStart", i * oncesCounts);
cjxxMap.put("rowEnd", (i + 1) * oncesCounts);
cjxxPool.submit(() -> {
try {
List<JcjCjxxViewMysql> list = jcjCjxxViewMysqlService.lambdaQuery().list();
for (JcjCjxxViewMysql cjxx : list) {
MetaHandleAlarmInfo metaHandleAlarmInfo = new MetaHandleAlarmInfo();
metaHandleAlarmInfo.setAlarmCode(cjxx.getCJBH());
metaHandleAlarmInfo.setHandleAlarmUnit(cjxx.getCJDWMC());
metaHandleAlarmInfo.setHandleAlarmTime(cjxx.getCJSJ());
metaHandleAlarmInfo.setHandleAlarmContent(cjxx.getCLJGNR());
metaHandleAlarmInfo.setHandleAlarmAddress(cjxx.getCJXXDD());
metaHandleAlarmInfo.setHandleAlarmUser(cjxx.getCJRHZXS());
metaHandleAlarmInfo.setHandleAlarmUserCode(cjxx.getCJR());
metaHandleAlarmInfo.setHandleAlarmResult(cjxx.getCJJGMC());
//确定一个数据是否唯一
MetaHandleAlarmInfo one = metaHandleAlarmInfoService.lambdaQuery().eq(MetaHandleAlarmInfo::getAlarmCode, cjxx.getCJBH()).one();
if (one == null) {
metaHandleAlarmInfoService.save(metaHandleAlarmInfo);
logger.info("cjxx-" + cjxx.getCJBH() + ":插入成功");
} else {
metaHandleAlarmInfoService.update(metaHandleAlarmInfo,new UpdateWrapper<>(metaHandleAlarmInfo));
logger.info("cjxx-" + cjxx.getCJBH() + ":更新成功");
}
}
} catch (Exception e) {
logger.info("cjxxs:" + e.getMessage());
}
latch.countDown();
});
logger.info("cjxxMap数据总量:" + countcjxx + "," + "当前处理下标:" + cjxxMap.get("rowStart") + "/" + cjxxMap.get("rowEnd"));
}
try {
// Wait for all threads to complete
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
// 关闭线程池
cjxxPool.shutdown();
}
} catch (Exception e) {
logger.info(StringKit.getTrace(e));
}
}
}
Loading…
Cancel
Save