A00001Service.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package com.miniframe.bisiness.system;
  2. import com.miniframe.constant.XIConstant;
  3. import com.miniframe.core.ExecProcessFlow;
  4. import com.miniframe.core.exception.BusinessException;
  5. import com.miniframe.core.ext.UtilTools;
  6. import com.miniframe.generate.appcode.MessageChannel;
  7. import com.miniframe.generate.business.system.model.A00001BaseModel;
  8. import com.miniframe.model.system.SysUser;
  9. import com.miniframe.model.system.SysUserSQLBuilder;
  10. import com.miniframe.model.system.dao.SysUserMapper;
  11. import com.miniframe.tools.msg.IdentifyingCodeUtil;
  12. import com.miniframe.utils.MFServiceUtils;
  13. import org.springframework.boot.autoconfigure.mail.MailProperties;
  14. import org.springframework.util.CollectionUtils;
  15. import java.util.HashMap;
  16. import java.util.List;
  17. import java.util.Map;
  18. import static com.miniframe.constant.XIConstant.IDENTIFYING_CODE;
  19. /**
  20. * 基础系统,“获取验证码”逻辑处理(重新生成不覆盖)。
  21. */
  22. public class A00001Service extends A00001BaseModel implements ExecProcessFlow {
  23. private static final long serialVersionUID = -7051358269847459502L;
  24. /**
  25. * 基础系统,“获取验证码”业务核心处理
  26. */
  27. public void transExecute() throws Exception {
  28. String verifyTokenKey = XIConstant.VERIFYTOKEN_PRE + this.getA_systemhead().getClientToken()
  29. +this.getA_a00001().getMailOrPhone(); // 唯一标识
  30. UtilTools.removeUserCache(verifyTokenKey);
  31. Integer codesendNum=0;
  32. String verifyNumKey = XIConstant.VERIFYTOKEN_PRE+this.getA_a00001().getMailOrPhone();
  33. Object oldnum=UtilTools.getCache(XIConstant.CODESENDNUM,verifyNumKey);
  34. if(oldnum!=null){
  35. codesendNum=(Integer)oldnum;
  36. }
  37. if(codesendNum+1>3){
  38. //throw new BusinessException("EB2200011");
  39. }
  40. String type = this.getA_a00001().getType();
  41. //本地是否存在
  42. SysUserMapper dao = UtilTools.getBean(SysUserMapper.class);
  43. SysUserSQLBuilder sb = new SysUserSQLBuilder();
  44. sb.createCriteria().andUseremailEqualTo(this.getA_a00001().getMailOrPhone());
  45. List<SysUser> userList = dao.selectByExample(sb);
  46. if (CollectionUtils.isEmpty(userList)) {
  47. sb.clear();
  48. sb.createCriteria().andUsermobnubEqualTo(this.getA_a00001().getMailOrPhone());
  49. userList = dao.selectByExample(sb);
  50. if (CollectionUtils.isEmpty(userList)) {
  51. // throw new BusinessException("EB8000029");
  52. }
  53. }
  54. if(type.equals("1")) {//注册
  55. if (userList != null && userList.size() > 0) {
  56. throw new BusinessException("EB8000020");
  57. }
  58. }else if(type.equals("2")) { //找回密码
  59. if (CollectionUtils.isEmpty(userList)) {
  60. throw new BusinessException("EB8000029");
  61. }
  62. }else if(type.equals("3")) {//登录
  63. if (CollectionUtils.isEmpty(userList)) {
  64. throw new BusinessException("EB8000029");
  65. }
  66. }else if(type.equals("4")) {//修改手机号 认证
  67. if (userList != null && userList.size() > 0) {
  68. throw new BusinessException("EB8000020");
  69. }
  70. }else if(type.equals("5")) {// 5 - 子账号验证
  71. if (CollectionUtils.isEmpty(userList)) {
  72. throw new BusinessException("EB8000029");
  73. }
  74. }else if(type.equals("6")) {// 6 - 无手机号验证
  75. if (userList != null && userList.size() > 0) {
  76. throw new BusinessException("EB8000020");
  77. }
  78. }
  79. try {
  80. String code = IdentifyingCodeUtil.createCode();
  81. // 唯一标识
  82. String ID = IDENTIFYING_CODE + UtilTools.getBaseCode() + "_" + this.getA_a00001().getMailOrPhone();
  83. // 保存到cache中
  84. UtilTools.putUserCache(ID, code);
  85. UtilTools.putCache(XIConstant.CODESENDNUM,verifyNumKey,++codesendNum);
  86. if(this.getA_a00001().getChannel().equals(MessageChannel.email.getIndex())){
  87. System.out.println("您的邮箱验证码:"+code);
  88. // MFServiceUtils.getMailService()
  89. // .sendSimpleMail(this.getA_a00001().getMailOrPhone(), "验证码", "您的邮箱验证码:" + code);
  90. Map<String, Object> var3 =new HashMap<>();
  91. var3.put("username","用户");
  92. var3.put("verification_code",code);
  93. MFServiceUtils.getMailService()
  94. .sendTemplateMail(this.getA_a00001().getMailOrPhone(), this.getA_a00001().getMailOrPhone(), var3,"mail_script");
  95. }else if(this.getA_a00001().getChannel().equals(MessageChannel.phone.getIndex())){
  96. IdentifyingCodeUtil.sendSMSAli(this.getA_a00001().getMailOrPhone(),code);
  97. }
  98. } catch (Exception e) {
  99. throw new BusinessException("EB8000030");
  100. }
  101. }
  102. /**
  103. * 基础系统,“获取验证码”业务前处理
  104. */
  105. public void preTransFlow() throws Exception {
  106. this.validater();
  107. }
  108. /**
  109. * 基础系统,“获取验证码”业务后处理
  110. */
  111. public void afterTransFlow() throws Exception {
  112. }
  113. /**
  114. * 基础系统,“获取验证码”逻辑入口处理方法
  115. */
  116. @SuppressWarnings("rawtypes")
  117. @Override
  118. public Map execute(Map vars) throws Exception {
  119. this.setTransMap(vars);
  120. preTransFlow();// 执行业务开始的规则检查和校验
  121. transExecute();// 执行核心业务段
  122. afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
  123. return this.getTransMap();
  124. }
  125. }