白名单增加各个操作的定时任务处理;

各种批量操作增加定时任务的处理;
This commit is contained in:
段冬梅
2019-04-19 18:35:20 +08:00
parent 1191db5fbe
commit c716cb1fc3
10 changed files with 135 additions and 115 deletions

View File

@@ -20,14 +20,14 @@ public interface SchedulerDao extends CrudDao<ScheduleCfg> {
* @param size
* @return
*/
List<ScheduleCfg> findNewlyCfg(@Param("id")Long id,@Param("limit")Long limit,@Param("type")int type);
List<ScheduleCfg> findNewlyCfg(@Param("id")Long id,@Param("limit")Long limit,@Param("type")int type,@Param("delFlag")Integer delFlag);
/**
* 更新 del_flag 字段为删除标识
* @param cfg
* @return
*/
int deleteByCompileId(ScheduleCfg cfg);
int deleteByCompileIds(String compileIds);
/**
* 查找 配置 下发 最新记录

View File

@@ -24,6 +24,7 @@
<result property="userRegion4" column="user_region4"/>
<result property="userRegion5" column="user_region5"/>
<result property="delFlag" column="del_flag"/>
<result property="type" column="type"/>
</resultMap>
@@ -123,6 +124,36 @@
order by a.id
</select>
<!-- 查找最新的更新数据 -->
<select id="get" resultType="com.nis.domain.ScheduleCfg">
select
a.ID,
a.NAME,
a.cron_valid,
a.cron_invalid,
a.SERVICE_ID,
a.COMPILE_ID,
a.CFG_ID,
a.IS_VALID,
a.IS_AUDIT,
a.function_id,
a.CREATOR_ID,
a.CREATE_TIME,
a.EDITOR_ID,
a.EDIT_TIME,
a.table_name,
a.user_region1,
a.user_region2,
a.user_region3,
a.user_region4,
a.user_region5,
a.del_flag,
a.type
from schedule_cfg a
<where>
and id = #{id}
</where>
</select>
<!-- 查找最新的更新数据 -->
<select id="findNewlyCfg" resultMap="scheduleCfgMap">
select
@@ -145,12 +176,16 @@
a.user_region2,
a.user_region3,
a.user_region4,
a.user_region5
a.user_region5,
a.del_flag,
a.type
from schedule_cfg a
<where>
del_Flag = 1
and id > #{id}
and type=#{type}
<if test=" delFlag != null">
and del_flag = #{delFlag}
</if>
</where>
order by a.id
limit #{limit}
@@ -179,6 +214,7 @@
user_region3,
user_region4,
user_region5,
del_flag,
type
) values (
#{name,jdbcType=VARCHAR},
@@ -200,23 +236,18 @@
#{userRegion3,jdbcType=VARCHAR},
#{userRegion4,jdbcType=VARCHAR},
#{userRegion5,jdbcType=VARCHAR},
#{delFlag,jdbcType=INTEGER},
#{type,jdbcType=INTEGER}
)
</insert>
<!-- 根据 compileId 将定时任务失效,定时任务的修改策略为:删除之前的所有配置,新增 -->
<update id="deleteByCompileId" parameterType="com.nis.domain.ScheduleCfg">
<!-- 根据 compileIds 将定时任务失效,定时任务的修改策略为:删除之前的所有配置,新增 -->
<update id="deleteByCompileIds" parameterType="com.nis.domain.ScheduleCfg">
update schedule_cfg
<set>
<if test="editorId != null ">
editor_Id = #{editorId,jdbcType=VARCHAR},
</if>
<if test="editTime != null ">
edit_Time = #{editTime,jdbcType=TIMESTAMP},
</if>
del_flag = #{DEL_FLAG_DELETE}
del_flag = 0
</set>
WHERE compile_Id = #{compileId} and del_flag =1
WHERE compile_Id in (#{compileIds}) and del_flag =1
</update>

View File

@@ -25,56 +25,31 @@ public class ScheduleService extends BaseService{
@SuppressWarnings("rawtypes")
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void issueCompileInfo(ScheduleCfg cfg,Integer isValid) {
public void issueCompileInfo(ScheduleCfg cfg,Integer isValid)throws Exception {
Integer compileId = cfg.getCompileId();
BaseCfg baseCfg = dao.getCfgTableInfo(cfg.getTableName(),compileId);//查询当前配置的最新状态
ScheduleCfg curSchedule = dao.get(cfg.getId());//查询当前任务的最新状态
Integer curIsValid = baseCfg.getIsValid();//当前配置的最新 是否有效信息
Integer curScheduleFlag = curSchedule.getDelFlag();//当前任务最新状态是否有效
if(curScheduleFlag == 0) {
logger.info(String.format("当前任务已失效 : id:%s,delFlag:%s", cfg.getId(),curScheduleFlag));
return;
}
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;
//是否下发内容
//下发内容
Integer isIssueContent = 1;
String errorInfo = null;
String tableName = cfg.getTableName();
SchedulerTaskUtil scheduler = new SchedulerTaskUtil();
boolean udpateConfigStatus = false;
//生效配置需要下发
if(isValid == 1 && (exceNew == null || exceNew.getIsIssue() == 1)) {
isIssueContent=1;
}else {
//之下发状态
isIssueContent=1;
if(isValid == 0) {
isIssueContent=0;
}
//首先对数据库操作
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查询配置表中的配置信息
@@ -90,30 +65,21 @@ public class ScheduleService extends BaseService{
}
}
}
//3、更新 配置表的 isValid 字段,添加 exce_log 记录
dao.insertScheduleExceLog(exceNew);
dao.updateCfgTableStatus(tableName, compileId, isValid);
//3、更新 配置表的 isValid 字段,添加 exce_log 记录
ScheduleExceInfo exceNew = new ScheduleExceInfo();
exceNew.setCompileId(compileId);
exceNew.setIssueStatus(isValid);
exceNew.setExceTime(new Date());
exceNew.setIssueResult(1);
exceNew.setErrorInfo(errorInfo);
exceNew.setIsIssue(0);
exceNew.setScheduleId(cfg.getId());
dao.insertScheduleExceLog(exceNew);
//数据库操作完成后与服务端交互
try {
udpateConfigStatus = scheduler.updateConfigByServiceAndCompile(cfg.getServiceId(), compileId, isValid, isIssueContent,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));
scheduler.updateConfigByServiceAndCompile(cfg.getServiceId(), compileId, isValid, isIssueContent,configSynchronizationDao);
logger.info(String.format("定时器下发配置内容compileId:%s,isValid:%s,errorInfo:%s",compileId,isValid,errorInfo));
}

View File

@@ -128,6 +128,8 @@ public class CommonPolicyService extends CrudService<WebsiteCfgDao, CfgIndexInfo
}
}
}
//更新各配置定时任务信息
handelScheduleCfg(httpUrlCfgs, entity.getTableName());
}
if(!StringUtil.isEmpty(auditHttpCompileIds)) {
commonPolicyDao.auditCfgBatch("cfg_index_info", entity,auditHttpCompileIds,null);
@@ -138,6 +140,8 @@ public class CommonPolicyService extends CrudService<WebsiteCfgDao, CfgIndexInfo
commonPolicyDao.deleteHttpUrlCfg("http_url_cfg", entity,deleteHttpCompileIds);
}
commonPolicyDao.auditCfgBatch( entity.getTableName(), entity,compileIds,null);
//更新各配置定时任务信息
handelScheduleCfg(list, entity.getTableName());
}
if(cfgList!=null){
@@ -269,14 +273,26 @@ public class CommonPolicyService extends CrudService<WebsiteCfgDao, CfgIndexInfo
* @param isUpdateCfg
* @throws ClassNotFoundException
*/
public void auditCallBackData(List auditList,List compileIds,List ids,BaseCfg entity){
public void auditCallBackData(List auditList,List notAuditList,List compileIds,List ids,BaseCfg entity){
long start=System.currentTimeMillis();
long end=System.currentTimeMillis();
if(!StringUtil.isEmpty(compileIds) && !StringUtil.isEmpty(entity.getTableName())) {
commonPolicyDao.auditCfgBatch( "cfg_index_info", entity,compileIds,null);
if(entity.getIsAudit()!=1) {
//更新各配置定时任务信息
handelScheduleCfg(auditList, entity.getTableName());
//更新各配置定时任务信息
handelScheduleCfg(notAuditList, entity.getTableName());
}
}
if(!StringUtil.isEmpty(ids) && !StringUtil.isEmpty(entity.getTableName())) {
commonPolicyDao.auditCfgBatch( entity.getTableName(), entity,ids,null);
if(entity.getIsAudit()!=1) {
//更新各配置定时任务信息
handelScheduleCfg(auditList, entity.getTableName());
//更新各配置定时任务信息
handelScheduleCfg(notAuditList, entity.getTableName());
}
if(entity.getTableName().equals("pxy_obj_trusted_ca_cert")) {
commonPolicyDao.auditCfgBatch("pxy_obj_trusted_ca_crl", entity,ids,null);
}
@@ -334,6 +350,8 @@ public class CommonPolicyService extends CrudService<WebsiteCfgDao, CfgIndexInfo
// 2.更新配置审核状态(主表)
if(!StringUtil.isEmpty(compileIds) && !StringUtil.isEmpty(entity.getTableName())) {
commonPolicyDao.auditCfgBatch( entity.getTableName(), entity,compileIds,null); // 批量审核并修改配置审核状态(主表)
//更新各配置定时任务信息
handelScheduleCfg(list, entity.getTableName());
}
// 3.更新域配置审核状态(子表)
@@ -364,11 +382,15 @@ public class CommonPolicyService extends CrudService<WebsiteCfgDao, CfgIndexInfo
}else {
compileIds.add(cfg.getCompileId());
}
cfg.setIsValid(-1);
cfg.setIsAudit(0);
}
// 2.更新配置状态(主表)
if(!StringUtil.isEmpty(compileIds) && !StringUtil.isEmpty(entity.getTableName())) {
commonPolicyDao.deleteCfgBatch(entity.getTableName(), entity,compileIds); // 批量修改配置状态(主表)
//更新各配置定时任务信息
handelScheduleCfg(list, entity.getTableName());
}
// 3.更新域配置状态(子表)