|
|
@@ -0,0 +1,93 @@
|
|
|
+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.core.util.JacksonUtil;
|
|
|
+import com.lc.ibps.base.core.util.string.StringUtil;
|
|
|
+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.quartz.JobDataMap;
|
|
|
+import org.quartz.JobExecutionContext;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+public class CommonInsertJob extends BaseJob2 {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(EquipmentMaintenancePlanJob.class);
|
|
|
+ public static final String PLAN_DATE = "plan-date";
|
|
|
+ public static final String SQL_CODE = "sql_code_";
|
|
|
+ private ICommonDao<?> commonDao = AppUtil.getBean(ICommonDao.class);
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void executeJob(JobExecutionContext context) throws Exception {
|
|
|
+
|
|
|
+ JobDataMap dataMap = context.getMergedJobDataMap();
|
|
|
+ logger.warn("group={} job={} trigger={} is running.",
|
|
|
+ context.getJobDetail().getKey().getGroup(),
|
|
|
+ context.getJobDetail().getKey().getName(),
|
|
|
+ context.getTrigger().getKey().getName());
|
|
|
+ logger.warn("jobDataMap=is {}.", JacksonUtil.toJsonString(dataMap.getWrappedMap()));
|
|
|
+ LocalDate localDate = LocalDate.now();
|
|
|
+ String planDateParam = dataMap.getString(PLAN_DATE);
|
|
|
+ if(StringUtil.isNotBlank(planDateParam)){
|
|
|
+ localDate = LocalDate.parse(planDateParam);
|
|
|
+ }
|
|
|
+ String planDate = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ String tableName = dataMap.getString("table_name_");
|
|
|
+ if (BeanUtils.isEmpty(tableName)){
|
|
|
+ throw new Exception("未配置添加数据对应的表名参数table_name_");
|
|
|
+ }
|
|
|
+
|
|
|
+ String code = dataMap.getString(SQL_CODE);
|
|
|
+ Map<String, Object> sqlMap = commonDao.queryOne("select ren_wu_ming_cheng,cha_xun_yu_ju_ from t_ptdsrwpzb where ren_wu_bian_ma_ = '"+code+"' limit 1");
|
|
|
+ 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);
|
|
|
+
|
|
|
+ if (BeanUtils.isEmpty(list)) {
|
|
|
+ logger.warn("未查询到需要添加<<"+taskName+">>的数据");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ logger.warn("添加<<"+taskName+">>数据总数:{}",list.size());
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ map.put("id_", UniqueIdUtil.getId());
|
|
|
+ map.put("create_time_", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
+ }
|
|
|
+
|
|
|
+ int success = 0;
|
|
|
+ int error = 0;
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ try {
|
|
|
+ commonDao.execute(this.buildInsertSql(map,tableName));
|
|
|
+ success = success + 1;
|
|
|
+ }catch (Exception e){
|
|
|
+ error = error + 1;
|
|
|
+ logger.error(taskName+"任务添加数据异常,异常数据map:{} with error message {}", map ,e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String msg = taskName+":任务添加数据完毕,正常数:"+success+",异常数:"+error;
|
|
|
+ logger.warn(msg);
|
|
|
+ if (error>0){
|
|
|
+ throw new Exception(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|