|
|
@@ -0,0 +1,80 @@
|
|
|
+package com.lc.ibps.platform.plan.job;
|
|
|
+
|
|
|
+import com.lc.ibps.base.core.util.AppUtil;
|
|
|
+import com.lc.ibps.base.core.util.BeanUtils;
|
|
|
+import com.lc.ibps.base.framework.id.UniqueIdUtil;
|
|
|
+import com.lc.ibps.base.framework.table.ICommonDao;
|
|
|
+import com.lc.ibps.components.quartz.BaseJob2;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+public abstract class AbstractJob extends BaseJob2 {
|
|
|
+
|
|
|
+ protected static final Logger logger = LoggerFactory.getLogger(AbstractJob.class);
|
|
|
+ protected ICommonDao<?> commonDao = AppUtil.getBean(ICommonDao.class);
|
|
|
+
|
|
|
+
|
|
|
+ public List<Map<String, Object>> fetchRecords(String code,String[] param){
|
|
|
+ String fetchSql = "select ren_wu_ming_cheng,cha_xun_yu_ju_ from t_ptdsrwpzb where ren_wu_bian_ma_ = '%s' limit 1";
|
|
|
+ Map<String, Object> sqlMap = commonDao.queryOne(String.format(fetchSql,code));
|
|
|
+ if(sqlMap == null){
|
|
|
+ throw new RuntimeException("未查询到<<"+code+">>的SQL数据");
|
|
|
+ }
|
|
|
+ String sql = sqlMap.get("cha_xun_yu_ju_").toString();
|
|
|
+ String taskName = sqlMap.get("ren_wu_ming_cheng").toString();
|
|
|
+ List<Map<String, Object>> list = (List<Map<String, Object>>) commonDao.query(sql,param);
|
|
|
+
|
|
|
+ if (BeanUtils.isEmpty(list)) {
|
|
|
+ logger.warn("未查询到需要添加<<"+taskName+">>的数据");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void insertRecordsFromTemplate(String code) {
|
|
|
+ List<Map<String, Object>> list = fetchRecords(code);
|
|
|
+ if(list == null) return ;
|
|
|
+ String fetchSql = "select guan_lian_biao_ from t_ptdsrwpzb where ren_wu_bian_ma_ = '%s' limit 1";
|
|
|
+ Map<String, Object> sqlMap = commonDao.queryOne(String.format(fetchSql,code));
|
|
|
+ String tableName = sqlMap.get("guan_lian_biao_").toString();
|
|
|
+ try {
|
|
|
+ generateRecords(list,tableName);
|
|
|
+ } catch (Exception e) {
|
|
|
+ //ignore it.
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Map<String, Object>> fetchRecords(String code){
|
|
|
+ return fetchRecords(code, new String[0]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void generateRecords(List<Map<String, Object>> list, String tableName) throws Exception {
|
|
|
+ int success = 0;
|
|
|
+ int error = 0;
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ try {
|
|
|
+ map.put("id_", UniqueIdUtil.getId());
|
|
|
+ map.put("create_time_", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
+ commonDao.execute(this.buildInsertSql(map, tableName));
|
|
|
+ success = success + 1;
|
|
|
+ } catch (Exception e) {
|
|
|
+ error = error + 1;
|
|
|
+ logger.error("添加数据异常,异常信息 {}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String msg = "添加数据正常数:" + success + ",添加数据异常数:" + error;
|
|
|
+ logger.info(msg);
|
|
|
+ if (error > 0) {
|
|
|
+ throw new Exception(msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|