@@ -0,0 +1,55 @@ | |||
package cn.com.taiji.core.entity.msgw; | |||
import java.time.LocalDateTime; | |||
import java.time.format.DateTimeFormatter; | |||
import javax.persistence.*; | |||
import javax.validation.constraints.NotBlank; | |||
import javax.validation.constraints.NotNull; | |||
import javax.validation.constraints.Size; | |||
import cn.com.taiji.common.entity.StringPropertyUUIDEntity; | |||
import cn.com.taiji.core.entity.dict.EnableStatus; | |||
import cn.com.taiji.core.entity.dict.msgw.MessageType; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
/** | |||
* 上行信息记录表 | |||
* | |||
*/ | |||
@Getter | |||
@Setter | |||
@Entity | |||
@Table(name = "MSGW_UPWARD_SHORT") | |||
public class MsgwUpwardShort extends StringPropertyUUIDEntity { | |||
@NotBlank | |||
@Column(name = "BATCH_ID") | |||
private String batchId; | |||
@NotBlank | |||
@Column(name = "MOBILE") | |||
private String mobile; | |||
@NotBlank | |||
@Column(name = "MSG_ID") | |||
private String msgId; | |||
@NotBlank | |||
@Column(name = "CUSTOM_MSG_ID") | |||
private String customMsgId; | |||
@NotBlank | |||
@Column(name = "STATE") | |||
private String state; | |||
@NotNull | |||
@Column(name = "SUBMIT_TIME") | |||
private LocalDateTime submitTime; | |||
@Column(name = "DONE_TIME") | |||
private LocalDateTime doneTime; | |||
@NotBlank | |||
@Column(name = "ORIGIN_RESULT") | |||
private String originResult; | |||
@Size(max = 100) | |||
@Column(name = "RESERVE") | |||
private String reserve; | |||
} |
@@ -0,0 +1,28 @@ | |||
package cn.com.taiji.core.model.comm.protocol.ats.sendShort; | |||
import javax.validation.constraints.NotBlank; | |||
import cn.com.taiji.common.model.BaseModel; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
/** | |||
* @ClassName InterfaceRequest | |||
* @Description 公共请求参数实体 | |||
*/ | |||
@Setter | |||
@Getter | |||
public class MTReport extends BaseModel { | |||
private String id; | |||
private String batchID;// 批次号 | |||
private String phone;// 手机号码 | |||
private String msgID;// 消息ID | |||
private String customMsgID;// 用户自定义消息ID | |||
private Integer state;// 状态 | |||
private Integer submitTime;// 提交时间 | |||
private Integer doneTime;// 完成时间 | |||
private String originResult; | |||
private String reserve; | |||
} |
@@ -8,6 +8,8 @@ import cn.com.taiji.core.model.comm.protocol.ats.AtsServiceType; | |||
public enum SendShortServiceCmd implements SignServiceCommand { | |||
SENDSHORT("短信发送",SendShortRequest.class), | |||
UPWARDSHORT("上行短信获取",UpwardShortQueryRequest.class), | |||
; | |||
@@ -0,0 +1,25 @@ | |||
package cn.com.taiji.core.model.comm.protocol.ats.sendShort; | |||
import cn.com.taiji.core.model.comm.protocol.ats.AbstractAtsRequest; | |||
import cn.com.taiji.core.model.comm.protocol.valid.ErrorMsgBuilder; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
/*** | |||
* 汇联通-上行信息获取 | |||
*/ | |||
@Getter | |||
@Setter | |||
public class UpwardShortQueryRequest extends AbstractAtsRequest<UpwardShortQueryResponse> { | |||
public UpwardShortQueryRequest() { | |||
super(SendShortServiceCmd.UPWARDSHORT); | |||
} | |||
private Integer fetchSize; | |||
@Override | |||
protected void validate(ErrorMsgBuilder builder) { | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
package cn.com.taiji.core.model.comm.protocol.ats.sendShort; | |||
import cn.com.taiji.core.model.comm.protocol.ats.AbstractAtsResponse; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
import java.util.List; | |||
/*** | |||
* 汇联通-上行信息获取 | |||
*/ | |||
@Getter | |||
@Setter | |||
public class UpwardShortQueryResponse extends AbstractAtsResponse { | |||
List<MTReport> MTReports; | |||
} |
@@ -0,0 +1,8 @@ | |||
package cn.com.taiji.core.repo.jpa.msgw; | |||
import cn.com.taiji.common.repo.jpa.AbstractJpaRepo; | |||
import cn.com.taiji.core.entity.msgw.MsgwUpwardShort; | |||
public interface MsgwUpwardShortRepo extends AbstractJpaRepo<MsgwUpwardShort, String>{ | |||
} |
@@ -0,0 +1,26 @@ | |||
package cn.com.taiji.core.repo.request.msgw; | |||
import cn.com.taiji.common.pub.dao.HqlBuilder; | |||
import cn.com.taiji.common.repo.request.jpa.JpaDateTimePageableDataRequest; | |||
import cn.com.taiji.core.entity.msgw.MsgwUpwardShort; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
@Getter | |||
@Setter | |||
public class MsgwUpwardShortPageRequest extends JpaDateTimePageableDataRequest<MsgwUpwardShort>{ | |||
public MsgwUpwardShortPageRequest() { | |||
this.orderBy="submitTime"; | |||
this.desc=true; | |||
} | |||
@Override | |||
public HqlBuilder toSelectHql(){ | |||
HqlBuilder hql = new HqlBuilder("from MsgwUpwardShort where 1=1 "); | |||
hql.append(" and submitTime>=:startTime", startTime); | |||
hql.append(" and submitTime<=:endTime", endTime); | |||
return hql; | |||
} | |||
} |
@@ -1,8 +1,15 @@ | |||
package cn.com.taiji.iasq.manager.quartz.msgw; | |||
import java.time.Instant; | |||
import java.time.LocalDateTime; | |||
import java.time.ZoneOffset; | |||
import java.util.List; | |||
import cn.com.taiji.core.entity.msgw.MsgwUpwardShort; | |||
import cn.com.taiji.core.model.comm.protocol.ats.sendShort.MTReport; | |||
import cn.com.taiji.core.model.comm.protocol.ats.sendShort.UpwardShortQueryRequest; | |||
import cn.com.taiji.core.model.comm.protocol.ats.sendShort.UpwardShortQueryResponse; | |||
import cn.com.taiji.core.repo.jpa.msgw.MsgwUpwardShortRepo; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
@@ -22,71 +29,36 @@ import cn.com.taiji.iasq.manager.AbstractCommManager; | |||
public class MsgwUpwardManagerImpl extends AbstractCommManager implements MsgwUpwardManager { | |||
@Autowired | |||
private MsgwSendDetailsRepo sendDetailsRepo; | |||
@Autowired | |||
private MsgwAlarmConfigRepo alarmConfigRepo; | |||
@Autowired | |||
private MsgwAlarmLogRepo alarmLogRepo; | |||
LocalDateTime startDateTime = LocalDateTime.now().minusHours(1); | |||
LocalDateTime endDateTime = LocalDateTime.now(); | |||
private MsgwUpwardShortRepo sendDetailsRepo; | |||
@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("-------消息推送-消息发送失败告警结束-------"); | |||
logger.info("-------消息系统-获取上行短信任务开始-------"); | |||
// 查询数据,循环查询 | |||
try { | |||
upwardShortQuery(100); | |||
} catch (ManagerException e) { | |||
logger.error("--消息系统-获取上行短信任务失败:", e); | |||
} | |||
logger.info("-------消息系统-获取上行短信任务结束-------"); | |||
} | |||
// public void sendAlerts(MessageType type, Long num) throws ManagerException{ | |||
// List<MsgwAlarmConfig> configs = alarmConfigRepo.findConfigByCondition(type, EnableStatus.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("告警短信发送失败!"); | |||
// } | |||
// } | |||
// } | |||
public void upwardShortQuery(Integer num) throws ManagerException{ | |||
UpwardShortQueryRequest req = new UpwardShortQueryRequest(); | |||
req.setFetchSize(num); | |||
UpwardShortQueryResponse upwardShortQueryResponse = jsonPostRepeat(req); | |||
if (upwardShortQueryResponse.getMTReports().size() == 0){ | |||
return; | |||
}else { | |||
for (MTReport mtReport : upwardShortQueryResponse.getMTReports()){ | |||
MsgwUpwardShort msgwUpwardShort = new MsgwUpwardShort(); | |||
copyProperties(mtReport, msgwUpwardShort); | |||
msgwUpwardShort.setMobile(mtReport.getPhone()); | |||
msgwUpwardShort.setSubmitTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(mtReport.getSubmitTime()), ZoneOffset.of("+8"))); | |||
msgwUpwardShort.setDoneTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(mtReport.getDoneTime()), ZoneOffset.of("+8"))); | |||
sendDetailsRepo.save(msgwUpwardShort); | |||
} | |||
} | |||
} | |||
} |
@@ -1,5 +1,6 @@ | |||
package cn.com.taiji.ats.manager.handler; | |||
import cn.com.taiji.core.model.comm.protocol.ats.sendShort.UpwardShortQueryRequest; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
@@ -41,6 +42,8 @@ public class SendShortServiceHandler extends AbstractAtsServiceHandler<SendShort | |||
switch (cmd) { | |||
case SENDSHORT: | |||
return sendShortManager.send((SendShortRequest) request); | |||
case UPWARDSHORT: | |||
return sendShortManager.upwardShort((UpwardShortQueryRequest) request); | |||
default: | |||
throw FileProtocolSystemError.NOT_SUPPORT.toHandleException(jsonReq.getIfCode()); | |||
} |
@@ -5,8 +5,11 @@ import static org.springframework.util.StringUtils.hasText; | |||
import java.io.IOException; | |||
import java.nio.charset.StandardCharsets; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.UUID; | |||
import cn.com.taiji.core.model.comm.protocol.ats.sendShort.*; | |||
import org.springframework.stereotype.Service; | |||
import cn.com.taiji.ats.manager.request.HltSmsSendRequest; | |||
@@ -14,8 +17,6 @@ import cn.com.taiji.ats.manager.tools.MD5Util; | |||
import cn.com.taiji.ats.tools.DesUtil; | |||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||
import cn.com.taiji.common.pub.json.JsonTools; | |||
import cn.com.taiji.core.model.comm.protocol.ats.sendShort.SendShortRequest; | |||
import cn.com.taiji.core.model.comm.protocol.ats.sendShort.SendShortResponse; | |||
import okhttp3.*; | |||
@Service | |||
@@ -80,4 +81,21 @@ public class SendShortManager { | |||
return MD5Util.MD5(str, "UTF-8"); | |||
} | |||
public UpwardShortQueryResponse upwardShort(UpwardShortQueryRequest request) throws ServiceHandleException { | |||
MTReport mtReport = new MTReport(); | |||
mtReport.setId("f97f1629be7e4363b1f109bc447ad594"); | |||
mtReport.setBatchID("123"); | |||
mtReport.setPhone("13888889999"); | |||
mtReport.setMsgID("测试"); | |||
mtReport.setCustomMsgID("13888889999"); | |||
mtReport.setState(1); | |||
mtReport.setSubmitTime(1755484481); | |||
mtReport.setDoneTime(1755484492); | |||
List<MTReport> list = new ArrayList<>(); | |||
list.add(mtReport); | |||
UpwardShortQueryResponse response = new UpwardShortQueryResponse(); | |||
response.setMTReports(list); | |||
return response; | |||
} | |||
} |