use of com.itrus.portal.db.MessageTemplate in project portal by ixinportal.
the class DynamicCodeServiceImpl method sendCodeZSJS.
public boolean sendCodeZSJS(String mPhone, Long project, String smsType) throws UserInfoServiceException {
// 同一手机号指定时间内不能重发
DynamicCodeExample dynamicCodeExample = new DynamicCodeExample();
DynamicCodeExample.Criteria criteria = dynamicCodeExample.or();
Calendar c = Calendar.getInstance();
c.add(Calendar.SECOND, -RESEND_TIME);
criteria.andMPhoneEqualTo(mPhone);
// 发送时间大于等于当前时间减去1分钟
criteria.andSendTimeGreaterThanOrEqualTo(c.getTime());
List<DynamicCode> dynamicCodes = sqlSession.selectList("com.itrus.portal.db.DynamicCodeMapper.selectByExample", dynamicCodeExample);
if (null != dynamicCodes && !dynamicCodes.isEmpty()) {
throw new UserInfoServiceException("此手机号" + RESEND_TIME + "秒内不能连续发送,请稍后重试");
}
// 产生动态码
DynamicCode code = genCode();
if (null == code) {
throw new UserInfoServiceException("发送动态码失败,请稍后重试");
}
// 发送动态码,获取发送的短信内容
MessageTemplate messageTemplate = messageTemplateService.getMsgTemp(project, smsType);
if (null == messageTemplate) {
throw new UserInfoServiceException("未找到对应的短信模版,请联系管理员配置");
}
String content = messageTemplate.getMessageContent();
content = content.replaceAll("code", code.getCode());
if (smsType.equals("ZSJS")) {
smsType = "证书解锁";
}
if (!smsSendService.sendDynamicCodeSms(mPhone, content, smsType, project)) {
// 发送失败
throw new UserInfoServiceException("动态码发送失败,请联系管理员查看原因");
} else {
// 记录动态码之前将该手机号关联的有效验证码设置为无效
dynamicCodeExample.clear();
criteria = dynamicCodeExample.createCriteria();
criteria.andMPhoneEqualTo(mPhone);
criteria.andCodeStatusEqualTo(ComNames.DYNAMIC_CODE_ENROLL);
DynamicCode updateCode = new DynamicCode();
updateCode.setCodeStatus(ComNames.DYNAMIC_CODE_USED);
updateCode.setFailTime(new Date());
Map<String, Object> map = new HashMap<String, Object>();
map.put("record", updateCode);
map.put("example", dynamicCodeExample);
sqlSession.update("com.itrus.portal.db.DynamicCodeMapper.updateByExampleSelective", map);
// 发送成功: 记录动态码
Calendar calendar = Calendar.getInstance();
code.setSendTime(calendar.getTime());
// 失效时间为7天后
calendar.add(Calendar.DATE, FAIL_TIME_ZSJS);
// 设置失效时间
code.setFailTime(calendar.getTime());
code.setmPhone(mPhone);
if (code.getId() == null) {
sqlSession.insert("com.itrus.portal.db.DynamicCodeMapper.insert", code);
} else {
sqlSession.update("com.itrus.portal.db.DynamicCodeMapper.updateByPrimaryKey", code);
}
}
return true;
}
use of com.itrus.portal.db.MessageTemplate in project portal by ixinportal.
the class MakeCerServiceImpl method sendReNewInfo.
/**
* 向用户发送待更新证书短信通知
*
* @param mPhone
* 手机
* @param project
* 项目id
* @param smsType
* 短信模版类型(ZSGX:证书更新)
*
* @throws UserInfoServiceException
*/
public void sendReNewInfo(Bill bill, String mPhone, Long project, String smsType, String keySn, String enterpriseName, Date endTime, String productName) throws UserInfoServiceException {
// 发送动态码,获取发送的短信内容
MessageTemplate messageTemplate = messageTemplateService.getMsgTemp(project, smsType);
if (null == messageTemplate) {
throw new UserInfoServiceException("未找到对应的短信模版,请联系管理员配置");
}
String content = messageTemplate.getMessageContent();
String end = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(endTime);
// 进行替换
content = content.replaceAll("enterpriseName", enterpriseName);
content = content.replaceAll("keySn", keySn);
content = content.replaceAll("endTime", end);
content = content.replaceAll("productName", productName);
// TODO 接口欠费,成功应该改回true,但是现在是欠费的,所以是false,为了通过,先改成这样,正确的应该是:!smsSendService.sendReNewInfoSms(mPhone, content, "更新证书", project)
if (!smsSendService.sendReNewInfoSms(mPhone, content, "更新证书", project)) {
// 发送失败
throw new UserInfoServiceException("更新证书通知送失败,请联系管理员查看原因");
} else {
// 发送成功: 记录信息
bill.setRenewSms(true);
bill.setRenewSendTime(new Date());
sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKey", bill);
}
}
use of com.itrus.portal.db.MessageTemplate in project portal by ixinportal.
the class MessageTemplateService method getMsgTemp.
public MessageTemplate getMsgTemp(Long projectId, String smsType) {
MessageTemplate messageTemplate = null;
MessageTemplateExample example = new MessageTemplateExample();
MessageTemplateExample.Criteria criteria = example.or();
criteria.andProjectEqualTo(projectId);
criteria.andMessageTypeEqualTo(smsType);
messageTemplate = sqlSession.selectOne("com.itrus.portal.db.MessageTemplateMapper.selectByExample", example);
if (null != messageTemplate) {
return messageTemplate;
} else {
MessageTemplateExample example1 = new MessageTemplateExample();
MessageTemplateExample.Criteria criteria1 = example1.or();
criteria1.andProjectEqualTo((long) 0);
criteria1.andMessageTypeEqualTo(smsType);
messageTemplate = sqlSession.selectOne("com.itrus.portal.db.MessageTemplateMapper.selectByExample", example1);
return messageTemplate;
}
}
Aggregations