117 lines
4.6 KiB
Java
117 lines
4.6 KiB
Java
|
|
package com.nis.web.service;
|
|||
|
|
|
|||
|
|
import java.util.Date;
|
|||
|
|
import java.util.List;
|
|||
|
|
import java.util.Map;
|
|||
|
|
|
|||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|||
|
|
import org.springframework.stereotype.Service;
|
|||
|
|
import org.springframework.transaction.annotation.Transactional;
|
|||
|
|
|
|||
|
|
import com.nis.domain.ScheduleCfg;
|
|||
|
|
import com.nis.domain.ScheduleExceInfo;
|
|||
|
|
import com.nis.domain.configuration.BaseCfg;
|
|||
|
|
import com.nis.util.SchedulerTaskUtil;
|
|||
|
|
import com.nis.util.ServiceConfigTemplateUtil;
|
|||
|
|
import com.nis.web.dao.SchedulerDao;
|
|||
|
|
import com.nis.web.dao.configuration.ConfigSynchronizationDao;
|
|||
|
|
|
|||
|
|
@Service
|
|||
|
|
public class ScheduleService extends BaseService{
|
|||
|
|
@Autowired
|
|||
|
|
private SchedulerDao dao ;
|
|||
|
|
@Autowired
|
|||
|
|
private ConfigSynchronizationDao configSynchronizationDao;
|
|||
|
|
|
|||
|
|
@SuppressWarnings("rawtypes")
|
|||
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|||
|
|
public void issueCompileInfo(ScheduleCfg cfg,Integer isValid) {
|
|||
|
|
Integer compileId = cfg.getCompileId();
|
|||
|
|
BaseCfg baseCfg = dao.getCfgTableInfo(cfg.getTableName(),compileId);//查询当前配置的最新状态
|
|||
|
|
Integer curIsValid = baseCfg.getIsValid();//当前配置的最新 是否有效信息
|
|||
|
|
if(curIsValid == isValid) {
|
|||
|
|
logger.info(String.format("当前isValid状态没有变化,不需执行,compileId:%s,isValid : %s", compileId,isValid));
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
//1、根据 compileId isvalid 查找new 判断是否已经下发过
|
|||
|
|
ScheduleExceInfo se = new ScheduleExceInfo();
|
|||
|
|
se.setCompileId(compileId);
|
|||
|
|
se.setIsValid(isValid);
|
|||
|
|
ScheduleExceInfo exceNew = dao.findScheduleExceNew(se);
|
|||
|
|
//2、如果已经下发,直接下发状态,否则下发配置
|
|||
|
|
Integer issueResult = 1;
|
|||
|
|
String errorInfo = null;
|
|||
|
|
String tableName = cfg.getTableName();
|
|||
|
|
SchedulerTaskUtil scheduler = new SchedulerTaskUtil();
|
|||
|
|
boolean udpateConfigStatus = false;
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
if(isValid == 1 && (exceNew == null || exceNew.getIsIssue() == 1)) {//生效配置需要下发
|
|||
|
|
udpateConfigStatus = scheduler.updateConfigByServiceAndCompile(cfg.getServiceId(), compileId, isValid, 1,configSynchronizationDao);
|
|||
|
|
logger.info(String.format("定时器下发配置内容,compileId:%s,isValid:%s,issueResult:%s,errorInfo:%s",compileId,isValid,issueResult,errorInfo));
|
|||
|
|
}else{//只需修改状态
|
|||
|
|
udpateConfigStatus = scheduler.updateConfigByServiceAndCompile(cfg.getServiceId(), compileId, isValid, 0,configSynchronizationDao);
|
|||
|
|
logger.info(String.format("定时器修改配置状态,compileId:%s,isValid:%s,issueResult:%s,errorInfo:%s",compileId,isValid,issueResult,errorInfo));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} catch (NoSuchFieldException e) {
|
|||
|
|
udpateConfigStatus = false;
|
|||
|
|
e.printStackTrace();
|
|||
|
|
} catch (SecurityException e) {
|
|||
|
|
udpateConfigStatus = false;
|
|||
|
|
e.printStackTrace();
|
|||
|
|
} catch (IllegalArgumentException e) {
|
|||
|
|
udpateConfigStatus = false;
|
|||
|
|
e.printStackTrace();
|
|||
|
|
} catch (IllegalAccessException e) {
|
|||
|
|
udpateConfigStatus = false;
|
|||
|
|
e.printStackTrace();
|
|||
|
|
}
|
|||
|
|
// logger.info(String.format("配置状态更新,compileId:%s,isValid:%s,issueResult:%s,errorInfo:%s",compileId,isValid,issueResult,errorInfo));
|
|||
|
|
|
|||
|
|
|
|||
|
|
if(udpateConfigStatus){//配置更新成功
|
|||
|
|
if(exceNew == null) {
|
|||
|
|
//新增exce_new 表状态
|
|||
|
|
exceNew = new ScheduleExceInfo();
|
|||
|
|
exceNew.setCompileId(compileId);
|
|||
|
|
exceNew.setIssueStatus(isValid);
|
|||
|
|
exceNew.setExceTime(new Date());
|
|||
|
|
exceNew.setIssueResult(issueResult);
|
|||
|
|
exceNew.setErrorInfo(errorInfo);
|
|||
|
|
exceNew.setIsIssue(0);
|
|||
|
|
exceNew.setScheduleId(cfg.getId());
|
|||
|
|
dao.insertScheduleExceNew(exceNew);
|
|||
|
|
}else {
|
|||
|
|
//修改 exce_new 表状态
|
|||
|
|
exceNew.setExceTime(new Date());
|
|||
|
|
exceNew.setIssueResult(issueResult);
|
|||
|
|
exceNew.setErrorInfo(errorInfo);
|
|||
|
|
exceNew.setScheduleId(cfg.getId());
|
|||
|
|
dao.updateScheduleExceNew(exceNew);
|
|||
|
|
}
|
|||
|
|
ServiceConfigTemplateUtil serviceTemplate = new ServiceConfigTemplateUtil();
|
|||
|
|
List<Map<String,Object>> serviceList = serviceTemplate.getServiceListByServiceId(cfg.getServiceId());
|
|||
|
|
//根据编译ID查询配置表中的配置信息
|
|||
|
|
for(Map<String,Object> service:serviceList){
|
|||
|
|
//获取业务下的配置域
|
|||
|
|
List<Map<String,Object>> cfgList = (List<Map<String, Object>>) service.get("cfgList");
|
|||
|
|
//查询子域配置详情
|
|||
|
|
if(cfgList!=null){
|
|||
|
|
for(Map<String,Object> m:cfgList){
|
|||
|
|
String regionTable = m.get("tableName").toString();
|
|||
|
|
//更新配置域表的isValid字段
|
|||
|
|
dao.updateCfgTableStatus(regionTable, compileId, isValid);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//3、更新 配置表的 isValid 字段,添加 exce_log 记录
|
|||
|
|
dao.insertScheduleExceLog(exceNew);
|
|||
|
|
dao.updateCfgTableStatus(tableName, compileId, isValid);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|