@@ -0,0 +1,51 @@ | |||
package cn.com.taiji.iasq.manager; | |||
import java.util.concurrent.*; | |||
import org.springframework.context.annotation.Configuration; | |||
/** | |||
* @author lihao | |||
* @description 线程池 | |||
* @createTime 2022/6/1 21:54 | |||
*/ | |||
@Configuration | |||
public class ThreadPoolTools { | |||
/** | |||
* 线程池维护线程的最少数量 | |||
*/ | |||
private int minPoolSize = 10; | |||
/** | |||
* 线程池维护线程的最大数量 | |||
*/ | |||
private int maxPoolSize = 50; | |||
/** | |||
* 线程池维护线程所允许的空闲时间 | |||
*/ | |||
private int idleSeconds = 1800; | |||
/** | |||
* 线程池所使用的缓冲队列 | |||
*/ | |||
private int queueBlockSize = 50; | |||
private ThreadPoolExecutor executor; | |||
public ThreadPoolTools() { | |||
this.executor = new ThreadPoolExecutor(minPoolSize, maxPoolSize, idleSeconds, | |||
TimeUnit.SECONDS, /* 时间单位,秒 */ | |||
new ArrayBlockingQueue<Runnable>(queueBlockSize), | |||
new ThreadPoolExecutor.CallerRunsPolicy()); /* 重试添加当前加入失败的任务 */ | |||
} | |||
public void execute(Runnable task) { | |||
executor.execute(task); | |||
} | |||
public <T> Future<T> submit(Callable<T> task) { | |||
return executor.submit(task); | |||
} | |||
} |
@@ -0,0 +1,5 @@ | |||
package cn.com.taiji.iasq.manager.quartz.msgw; | |||
public interface MsgwPushAlertsManager { | |||
void execute(); | |||
} |
@@ -0,0 +1,99 @@ | |||
package cn.com.taiji.iasq.manager.quartz.msgw; | |||
import java.time.LocalDateTime; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
import cn.com.taiji.core.entity.dict.msgw.MessageResult; | |||
import cn.com.taiji.core.entity.dict.msgw.MessageType; | |||
import cn.com.taiji.core.entity.dict.user.IsEnable; | |||
import cn.com.taiji.core.entity.msgw.MsgwAlarmConfig; | |||
import cn.com.taiji.core.entity.msgw.MsgwAlarmLog; | |||
import cn.com.taiji.core.model.comm.protocol.ias.message.HltSendShortRequest; | |||
import cn.com.taiji.core.repo.jpa.msgw.MsgwAlarmConfigRepo; | |||
import cn.com.taiji.core.repo.jpa.msgw.MsgwAlarmLogRepo; | |||
import cn.com.taiji.core.repo.jpa.msgw.MsgwSendDetailsRepo; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import cn.com.taiji.common.manager.ManagerException; | |||
import cn.com.taiji.core.entity.invw.InvwQryObus; | |||
import cn.com.taiji.core.model.comm.protocol.inss.VfjQueryGmobusRequest; | |||
import cn.com.taiji.core.model.comm.protocol.inss.VfjQueryGmobusResponse; | |||
import cn.com.taiji.core.repo.jpa.invw.InvwQryObusRepo; | |||
import cn.com.taiji.iasq.manager.AbstractCommManager; | |||
import cn.com.taiji.iasq.manager.quartz.vfj.VfjQueryGmobusManager; | |||
@Service | |||
public class MsgwPushAlertsManagerImpl extends AbstractCommManager implements MsgwPushAlertsManager { | |||
@Autowired | |||
private MsgwSendDetailsRepo sendDetailsRepo; | |||
@Autowired | |||
private MsgwAlarmConfigRepo alarmConfigRepo; | |||
@Autowired | |||
private MsgwAlarmLogRepo alarmLogRepo; | |||
LocalDateTime startDateTime = LocalDateTime.now().minusHours(1); | |||
LocalDateTime endDateTime = LocalDateTime.now(); | |||
@Override | |||
public void execute() { | |||
logger.info("-------消息推送-消息发送失败告警开始-------"); | |||
// 查询时间段内是否有需要告警的数据 | |||
Long failNum = sendDetailsRepo.countStatistics(null, MessageResult.FAIL, startDateTime, endDateTime); | |||
boolean isAlerts = failNum.equals(0); | |||
// 如果有,查询是哪个的,触发告警发送 | |||
while (!isAlerts) { | |||
for (MessageType type : MessageType.values()) { | |||
Long failTotalNum = sendDetailsRepo.countStatistics(type, MessageResult.FAIL, startDateTime, endDateTime); | |||
// 如果不为空,发送告警 | |||
if (failTotalNum != 0){ | |||
try { | |||
sendAlerts(type, failTotalNum); | |||
} catch (ManagerException e) { | |||
logger.error("--消息推送-消息发送失败告警失败:", e); | |||
} | |||
} | |||
} | |||
} | |||
logger.info("-------消息推送-消息发送失败告警结束-------"); | |||
} | |||
public void sendAlerts(MessageType type, Long num) throws ManagerException{ | |||
List<MsgwAlarmConfig> configs = alarmConfigRepo.findConfigByCondition(type, IsEnable.ENABLE); | |||
MsgwAlarmLog alarmLog = new MsgwAlarmLog(); | |||
alarmLog.setInsertTime(endDateTime); | |||
alarmLog.setMessageType(type); | |||
if (configs.isEmpty()){ | |||
//告警配置内容 | |||
alarmLog.setSendResult(0);//默认失败 告警结果(0-失败,1-成功) | |||
String failReason = "未找到可用的告警配置!原因:没有配置【" + ",消息类型为:" + type.name() + "】的告警配置。"; | |||
alarmLog.setAlarmReason(failReason); | |||
alarmLogRepo.persist(alarmLog); | |||
return; | |||
} | |||
// 循环发送告警人 | |||
for (MsgwAlarmConfig config : configs){ | |||
HltSendShortRequest request = new HltSendShortRequest(); | |||
String message = "类型" + type.getValue() + "发送错误,共计" + num + "个。"; | |||
request.setTitle("告警提醒"); | |||
request.setMessage(message); | |||
request.setMobile(config.getMobile()); | |||
alarmLog.setAlarmConfigId(config.getId()); | |||
alarmLog.setStaffName(config.getStaffName()); | |||
alarmLog.setMobile(config.getMobile()); | |||
alarmLog.setAlarmMessage(message); | |||
try { | |||
jsonPostRepeat(request); | |||
// 记录日志 | |||
alarmLog.setSendResult(1); | |||
alarmLogRepo.persist(alarmLog); | |||
} catch (ManagerException e) { | |||
alarmLog.setSendResult(0); | |||
alarmLog.setAlarmReason("告警短信发送失败!"); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,23 @@ | |||
package cn.com.taiji.iasq.manager.quartz.msgw; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import cn.com.taiji.common.manager.quartz.AbstractCronTask; | |||
import cn.com.taiji.iasq.manager.quartz.vfj.VfjQueryTriDesObusManager; | |||
import cn.com.taiji.iasq.model.TaskInfo; | |||
@Service | |||
public class MsgwPushAlertsTask extends AbstractCronTask { | |||
public MsgwPushAlertsTask() { | |||
super(TaskInfo.MSGW_PUSH_ALERTS); | |||
} | |||
@Autowired | |||
private MsgwPushAlertsManager manager; | |||
@Override | |||
public void run() { | |||
manager.execute(); | |||
} | |||
} |
@@ -38,6 +38,9 @@ public class CronPara extends AbstractSysConf { | |||
private String vfjQryCsObus = "0 34 1 * * ?"; | |||
private String vfjQryTriDesObus = "0 35 1 * * ?"; | |||
// MSGW | |||
private String msgwPushAlerts = "0 0 * * * ?"; | |||
private String msgwPush = "0 0/5 * * * ? "; | |||
public CronPara() { |
@@ -15,6 +15,7 @@ public enum TaskGroup { | |||
SYSTEM("系统内置") {}, | |||
SAMPLE("示例") {}, | |||
VFJ("省联网中心") {}, | |||
MSGW("消息推送系统"){}, | |||
; | |||
private final String value; | |||
@@ -20,17 +20,19 @@ import cn.com.taiji.common.manager.quartz.PriorityTaskDefinition; | |||
*/ | |||
public enum TaskInfo implements PriorityTaskDefinition { | |||
SAMPLE("示例", TaskGroup.SYSTEM, "sample", 60, true, List.of(1, 2)), | |||
TIME_STEP("按时间段执行的任务", TaskGroup.SYSTEM, "timeStep", 600, true, List.of(1, 2,3)), | |||
TIME_STEP("按时间段执行的任务", TaskGroup.SYSTEM, "timeStep", 600, true, List.of(1, 2, 3)), | |||
// VFJ | |||
VFJ_QRY_CARD_BATCH("卡片发行批次列表查询", TaskGroup.VFJ, "vfjQryCardBatch", 3600*2, true, List.of(1, 2)), | |||
VFJ_QRY_CARDS("卡片一发查询", TaskGroup.VFJ, "vfjQryCards", 3600*2, true, List.of(1, 2)), | |||
VFJ_QRY_SM_OBU_BATCH("OBU发行批次列表查询", TaskGroup.VFJ, "vfjQrySmObuBatch", 3600*2, true, List.of(1, 2)), | |||
VFJ_QRY_GM_OBUS("双片国密OBU一次发行明细查询", TaskGroup.VFJ, "vfjQryGmObus", 3600*2, true, List.of(1, 2)), | |||
VFJ_QRY_CS_OBUS("单片OBU一次发行明细查询", TaskGroup.VFJ, "vfjQryCsObus", 3600*2, true, List.of(1, 2)), | |||
VFJ_QRY_TRI_DES_OBUS("单片OBU一次发行明细查询", TaskGroup.VFJ, "vfjQryTriDesObus", 3600*2, true, List.of(1, 2)), | |||
; | |||
VFJ_QRY_CARD_BATCH("卡片发行批次列表查询", TaskGroup.VFJ, "vfjQryCardBatch", 3600 * 2, true, List.of(1, 2)), | |||
VFJ_QRY_CARDS("卡片一发查询", TaskGroup.VFJ, "vfjQryCards", 3600 * 2, true, List.of(1, 2)), | |||
VFJ_QRY_SM_OBU_BATCH("OBU发行批次列表查询", TaskGroup.VFJ, "vfjQrySmObuBatch", 3600 * 2, true, List.of(1, 2)), | |||
VFJ_QRY_GM_OBUS("双片国密OBU一次发行明细查询", TaskGroup.VFJ, "vfjQryGmObus", 3600 * 2, true, List.of(1, 2)), | |||
VFJ_QRY_CS_OBUS("单片OBU一次发行明细查询", TaskGroup.VFJ, "vfjQryCsObus", 3600 * 2, true, List.of(1, 2)), | |||
VFJ_QRY_TRI_DES_OBUS("单片OBU一次发行明细查询", TaskGroup.VFJ, "vfjQryTriDesObus", 3600 * 2, true, List.of(1, 2)), | |||
// MSGW | |||
MSGW_PUSH_ALERTS("消息推送告警", TaskGroup.MSGW, "msgwPushAlerts", 3600 * 2, true, List.of(1, 2)), | |||
MSGW_PUSH("消息推送", TaskGroup.MSGW, "msgwPush", 3600 * 2, true, List.of(1, 2)),; | |||
private String info; | |||
private final String cronParaPropertyName; |