package com.miniframe.bisiness.system; import com.miniframe.constant.XIConstant; import com.miniframe.core.ExecProcessFlow; import com.miniframe.core.exception.BusinessException; import com.miniframe.core.ext.UtilTools; import com.miniframe.generate.appcode.MessageChannel; import com.miniframe.generate.business.system.model.A00001BaseModel; import com.miniframe.model.system.SysUser; import com.miniframe.model.system.SysUserSQLBuilder; import com.miniframe.model.system.dao.SysUserMapper; import com.miniframe.tools.msg.IdentifyingCodeUtil; import com.miniframe.utils.MFServiceUtils; import org.springframework.boot.autoconfigure.mail.MailProperties; import org.springframework.util.CollectionUtils; import java.util.HashMap; import java.util.List; import java.util.Map; import static com.miniframe.constant.XIConstant.IDENTIFYING_CODE; /** * 基础系统,“获取验证码”逻辑处理(重新生成不覆盖)。 */ public class A00001Service extends A00001BaseModel implements ExecProcessFlow { private static final long serialVersionUID = -7051358269847459502L; /** * 基础系统,“获取验证码”业务核心处理 */ public void transExecute() throws Exception { String verifyTokenKey = XIConstant.VERIFYTOKEN_PRE + this.getA_systemhead().getClientToken() +this.getA_a00001().getMailOrPhone(); // 唯一标识 UtilTools.removeUserCache(verifyTokenKey); Integer codesendNum=0; String verifyNumKey = XIConstant.VERIFYTOKEN_PRE+this.getA_a00001().getMailOrPhone(); Object oldnum=UtilTools.getCache(XIConstant.CODESENDNUM,verifyNumKey); if(oldnum!=null){ codesendNum=(Integer)oldnum; } if(codesendNum+1>3){ //throw new BusinessException("EB2200011"); } String type = this.getA_a00001().getType(); //本地是否存在 SysUserMapper dao = UtilTools.getBean(SysUserMapper.class); SysUserSQLBuilder sb = new SysUserSQLBuilder(); sb.createCriteria().andUseremailEqualTo(this.getA_a00001().getMailOrPhone()); List userList = dao.selectByExample(sb); if (CollectionUtils.isEmpty(userList)) { sb.clear(); sb.createCriteria().andUsermobnubEqualTo(this.getA_a00001().getMailOrPhone()); userList = dao.selectByExample(sb); if (CollectionUtils.isEmpty(userList)) { // throw new BusinessException("EB8000029"); } } if(type.equals("1")) {//注册 if (userList != null && userList.size() > 0) { throw new BusinessException("EB8000020"); } }else if(type.equals("2")) { //找回密码 if (CollectionUtils.isEmpty(userList)) { throw new BusinessException("EB8000029"); } }else if(type.equals("3")) {//登录 if (CollectionUtils.isEmpty(userList)) { throw new BusinessException("EB8000029"); } }else if(type.equals("4")) {//修改手机号 认证 if (userList != null && userList.size() > 0) { throw new BusinessException("EB8000020"); } }else if(type.equals("5")) {// 5 - 子账号验证 if (CollectionUtils.isEmpty(userList)) { throw new BusinessException("EB8000029"); } }else if(type.equals("6")) {// 6 - 无手机号验证 if (userList != null && userList.size() > 0) { throw new BusinessException("EB8000020"); } } try { String code = IdentifyingCodeUtil.createCode(); // 唯一标识 String ID = IDENTIFYING_CODE + UtilTools.getBaseCode() + "_" + this.getA_a00001().getMailOrPhone(); // 保存到cache中 UtilTools.putUserCache(ID, code); UtilTools.putCache(XIConstant.CODESENDNUM,verifyNumKey,++codesendNum); if(this.getA_a00001().getChannel().equals(MessageChannel.email.getIndex())){ System.out.println("您的邮箱验证码:"+code); // MFServiceUtils.getMailService() // .sendSimpleMail(this.getA_a00001().getMailOrPhone(), "验证码", "您的邮箱验证码:" + code); Map var3 =new HashMap<>(); var3.put("username","用户"); var3.put("verification_code",code); MFServiceUtils.getMailService() .sendTemplateMail(this.getA_a00001().getMailOrPhone(), this.getA_a00001().getMailOrPhone(), var3,"mail_script"); }else if(this.getA_a00001().getChannel().equals(MessageChannel.phone.getIndex())){ IdentifyingCodeUtil.sendSMSAli(this.getA_a00001().getMailOrPhone(),code); } } catch (Exception e) { throw new BusinessException("EB8000030"); } } /** * 基础系统,“获取验证码”业务前处理 */ public void preTransFlow() throws Exception { this.validater(); } /** * 基础系统,“获取验证码”业务后处理 */ public void afterTransFlow() throws Exception { } /** * 基础系统,“获取验证码”逻辑入口处理方法 */ @SuppressWarnings("rawtypes") @Override public Map execute(Map vars) throws Exception { this.setTransMap(vars); preTransFlow();// 执行业务开始的规则检查和校验 transExecute();// 执行核心业务段 afterTransFlow();// 执行核心逻辑完成后的收尾逻辑 return this.getTransMap(); } }