Search in sources :

Example 16 with MessageTemplate

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;
}
Also used : MessageTemplate(com.itrus.portal.db.MessageTemplate) DynamicCodeExample(com.itrus.portal.db.DynamicCodeExample) HashMap(java.util.HashMap) Calendar(java.util.Calendar) DynamicCode(com.itrus.portal.db.DynamicCode) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Date(java.util.Date)

Example 17 with MessageTemplate

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);
    }
}
Also used : MessageTemplate(com.itrus.portal.db.MessageTemplate) SimpleDateFormat(java.text.SimpleDateFormat) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Date(java.util.Date)

Example 18 with MessageTemplate

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;
    }
}
Also used : MessageTemplate(com.itrus.portal.db.MessageTemplate) MessageTemplateExample(com.itrus.portal.db.MessageTemplateExample)

Aggregations

MessageTemplate (com.itrus.portal.db.MessageTemplate)18 Date (java.util.Date)10 HashMap (java.util.HashMap)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)6 Calendar (java.util.Calendar)5 DynamicCode (com.itrus.portal.db.DynamicCode)4 DynamicCodeExample (com.itrus.portal.db.DynamicCodeExample)4 ExtraBill (com.itrus.portal.db.ExtraBill)4 Project (com.itrus.portal.db.Project)4 Map (java.util.Map)4 Bill (com.itrus.portal.db.Bill)3 Enterprise (com.itrus.portal.db.Enterprise)3 MessageTemplateExample (com.itrus.portal.db.MessageTemplateExample)3 UserInfo (com.itrus.portal.db.UserInfo)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ExtraProduct (com.itrus.portal.db.ExtraProduct)2 Courier (com.itrus.portal.db.Courier)1 CourierExample (com.itrus.portal.db.CourierExample)1 CourierInfo (com.itrus.portal.db.CourierInfo)1