A00001Service.java 5.0 KB

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