|
@@ -7,8 +7,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.rongwei.bscommon.sys.feign.RwCommonServerFeignService;
|
|
|
import com.rongwei.bscommon.sys.service.ZhcxRegisterService;
|
|
|
import com.rongwei.bscommon.sys.service.ZhcxSupervisionCustomUserManageService;
|
|
|
+import com.rongwei.bscommon.sys.utils.CxConstants;
|
|
|
import com.rongwei.bscommon.sys.utils.HwSmsUtil;
|
|
|
import com.rongwei.bscommon.sys.utils.PasswordGenerator;
|
|
|
+import com.rongwei.bscommon.sys.utils.SmsCodeGenerateUtils;
|
|
|
import com.rongwei.bsentity.domain.ZhcxSupervisionCustomUserManageDo;
|
|
|
import com.rongwei.commonservice.service.RedisService;
|
|
|
import com.rongwei.rwadmincommon.system.domain.SysUserDo;
|
|
@@ -20,11 +22,10 @@ import com.rongwei.rwcommon.vo.MailDo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Random;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
@Service
|
|
@@ -39,11 +40,10 @@ public class ZhcxRegisterServiceImpl implements ZhcxRegisterService {
|
|
|
@Autowired
|
|
|
private RwCommonServerFeignService rwCommonServerFeignService;
|
|
|
|
|
|
- public static final String PY_NEWS_MAIL_CONTENT = "您好,有新的监理账号注册,请您及时登录系统审批,地址:https://cxqm.zpmc.com";
|
|
|
@Override
|
|
|
public R supervisionRegister(JSONObject jsonObject) {
|
|
|
try {
|
|
|
- String jygs = jsonObject.getString("jygs");
|
|
|
+ String jygsid = jsonObject.getString("jygsid");
|
|
|
String name = jsonObject.getString("name");
|
|
|
String account = jsonObject.getString("account");
|
|
|
String email = jsonObject.getString("email");
|
|
@@ -79,7 +79,7 @@ public class ZhcxRegisterServiceImpl implements ZhcxRegisterService {
|
|
|
ManageDo.setPhone(mobile);
|
|
|
ManageDo.setUserName(name);
|
|
|
ManageDo.setEmail(email);
|
|
|
- ManageDo.setPid(jygs);
|
|
|
+ ManageDo.setPid(jygsid);
|
|
|
ManageDo.setStatus("待审核");
|
|
|
manageService.save(ManageDo);
|
|
|
}
|
|
@@ -87,6 +87,7 @@ public class ZhcxRegisterServiceImpl implements ZhcxRegisterService {
|
|
|
return R.error("验证码错误,请重新输入");
|
|
|
}
|
|
|
try {
|
|
|
+ redisService.getRedisTemplate().delete(CxConstants.REGISTER_PREFIX+mobile);
|
|
|
sendMail();
|
|
|
} catch (Exception e) {
|
|
|
log.info("监理注册审核邮件发送失败");
|
|
@@ -106,14 +107,17 @@ public class ZhcxRegisterServiceImpl implements ZhcxRegisterService {
|
|
|
log.error("收件人邮箱为空:{}", userEmail);
|
|
|
return R.ok();
|
|
|
}
|
|
|
+ Set<String> set = new HashSet<>(userEmail);
|
|
|
+ userEmail.clear();
|
|
|
+ userEmail.addAll(set);
|
|
|
log.debug("开始发送监理账号审核接收人邮件", userEmail);
|
|
|
MailDo mailDo = new MailDo();
|
|
|
mailDo.setReceiveEmail(userEmail.toArray(new String[userEmail.size()]));
|
|
|
mailDo.setSubject("监理账号审核");
|
|
|
mailDo.setCcEmail(new String[]{});
|
|
|
mailDo.setNeedTransReceive(false);
|
|
|
- mailDo.setContent(PY_NEWS_MAIL_CONTENT);
|
|
|
- rwCommonServerFeignService.sendHtmlMail(mailDo);
|
|
|
+ mailDo.setContent(CxConstants.CHECK_MAIL_CONTENT);
|
|
|
+ rwCommonServerFeignService.sendTextMail(mailDo);
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
@@ -124,71 +128,92 @@ public class ZhcxRegisterServiceImpl implements ZhcxRegisterService {
|
|
|
return R.error();
|
|
|
}
|
|
|
String mobile = (String) mobileObj;
|
|
|
- boolean exists = redisService.hasKey("register_"+mobile);
|
|
|
+ boolean exists = redisService.hasKey(CxConstants.REGISTER_PREFIX+mobile);
|
|
|
String sendCodeTimeObj = (String) redisService.getRedisCatchObj("registerCount_"+mobile);
|
|
|
- if (StringUtils.isBlank(sendCodeTimeObj)) {
|
|
|
- sendCodeTimeObj = "0";
|
|
|
- }
|
|
|
- int sendCodeTime = Integer.parseInt(sendCodeTimeObj);
|
|
|
- if( exists && sendCodeTime >= 5 ){
|
|
|
- return R.error("501","验证码发送频繁,请过5分钟后再尝试");
|
|
|
- }
|
|
|
- StringBuilder code = new StringBuilder();
|
|
|
- for (int i = 0; i < 6; i++) {
|
|
|
- if(i == 0){
|
|
|
- code.append(new Random().nextInt(9)+1);
|
|
|
- }else{
|
|
|
- code.append(new Random().nextInt(10));
|
|
|
- }
|
|
|
+ int sendCodeTime = StringUtils.isBlank(sendCodeTimeObj) ? 0 : Integer.parseInt(sendCodeTimeObj);
|
|
|
+ if (exists && sendCodeTime >= CxConstants.MAX_SEND_CODE_TIME) {
|
|
|
+ return R.error("501", "验证码发送频繁,请过5分钟后再尝试");
|
|
|
}
|
|
|
+ String code = SmsCodeGenerateUtils.getInstance().generateVerificationCode();
|
|
|
try {
|
|
|
JSONObject jsonObject = HwSmsUtil.sendSms(null,null, code.toString(), mobile);
|
|
|
String returnCode = jsonObject.getString("code");
|
|
|
- if("000000".equals(returnCode)){
|
|
|
+ if(CxConstants.SUCCESS_CODE.equals(returnCode)){
|
|
|
if(!exists){
|
|
|
- redisService.redisCatchInit("registerCount_"+mobile,0,300);
|
|
|
+ redisService.redisCatchInit(CxConstants.REGISTER_COUNT_PREFIX+mobile,"0",CxConstants.SEND_CODE_INTERVAL);
|
|
|
}
|
|
|
sendCodeTime += 1;
|
|
|
- redisService.redisCatchInit("registerCount_"+mobile,String.valueOf(sendCodeTime),300);
|
|
|
- redisService.redisCatchInit("register_"+mobile,code.toString(),120);
|
|
|
+ redisService.redisCatchInit(CxConstants.REGISTER_COUNT_PREFIX+mobile,String.valueOf(sendCodeTime),CxConstants.SEND_CODE_INTERVAL);
|
|
|
+ redisService.redisCatchInit(CxConstants.REGISTER_PREFIX+mobile,code,CxConstants.VERIFICATION_CODE_EXPIRATION);
|
|
|
return R.ok("发送成功");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.info("发送验证码失败", e);
|
|
|
}
|
|
|
return R.error();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
|
|
public R checkSupervisionUser(List<ZhcxSupervisionCustomUserManageDo> list) {
|
|
|
try {
|
|
|
+ updateStatus(list);
|
|
|
List<String> userIdList = list.stream().map(ZhcxSupervisionCustomUserManageDo::getUserid).collect(Collectors.toList());
|
|
|
- list.forEach((item)->{
|
|
|
- if ("待审核".equals(item.getStatus())) {
|
|
|
- item.setStatus("正常");
|
|
|
- }
|
|
|
- });
|
|
|
- manageService.updateBatchById(list);
|
|
|
- LambdaQueryWrapper<SysUserDo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.and(i -> i.in(SysUserDo::getId, userIdList));
|
|
|
- List<SysUserDo> userList = sysUserService.list(queryWrapper);
|
|
|
- userList.forEach((item)->{
|
|
|
- String pwd = PasswordGenerator.generatePassword(12);
|
|
|
- String saltPwd = SecurityUtil.getSaltMd5AndSha(pwd, item.getId());
|
|
|
- item.setPassword(saltPwd);
|
|
|
- item.setEnabled("0");
|
|
|
- sysUserService.updateById(item);
|
|
|
- try {
|
|
|
- HwSmsUtil.sendSms("7133b7ce87a84896a143b02edf5a4757","8823102504763",item.getAccount()+","+pwd,item.getMobile());
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- });
|
|
|
+ updateUserPasswordAndSendSms(userIdList);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("处理监理注册用户更新发送信息异常", e);
|
|
|
return R.error();
|
|
|
}
|
|
|
return R.ok();
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 更新用户密码并发送短信通知
|
|
|
+ *
|
|
|
+ * @param userIdList 需要更新密码和发送短信的用户ID列表
|
|
|
+ * 该方法首先根据提供的用户ID列表查询用户信息,然后为每个用户生成新密码,更新密码及启用状态,并尝试发送包含新密码的短信通知。
|
|
|
+ */
|
|
|
+ private void updateUserPasswordAndSendSms(List<String> userIdList) {
|
|
|
+ LambdaQueryWrapper<SysUserDo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.and(i -> i.in(SysUserDo::getId, userIdList));
|
|
|
+ List<SysUserDo> userList = sysUserService.list(queryWrapper);
|
|
|
+ userList.forEach((item)->{
|
|
|
+ String pwd = PasswordGenerator.generatePassword(12);
|
|
|
+ String saltPwd = SecurityUtil.getSaltMd5AndSha(pwd, item.getId());
|
|
|
+ item.setPassword(saltPwd);
|
|
|
+ item.setEnabled("0");
|
|
|
+ sysUserService.updateById(item);
|
|
|
+ sendSmsAsync(item);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendSmsAsync(SysUserDo item) {
|
|
|
+ new Thread(() -> {
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = HwSmsUtil.sendSms("7133b7ce87a84896a143b02edf5a4757", "8823102504763", item.getAccount() + "," + "123", item.getMobile());
|
|
|
+ String returnCode = jsonObject.getString("code");
|
|
|
+ if(CxConstants.SUCCESS_CODE.equals(returnCode)){
|
|
|
+ log.info("发送用户注册信息成功");
|
|
|
+ }else {
|
|
|
+ log.info("发送用户注册信息失败: 返回码 {}", returnCode);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("发送短信异常", e);
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新用户状态
|
|
|
+ *
|
|
|
+ * @param list 包含待更新状态的用户信息列表
|
|
|
+ * 此方法遍历列表中的每个用户,将状态为"待审核"的用户状态更新为"正常",然后批量通过manageService更新到数据库中。
|
|
|
+ */
|
|
|
+ private void updateStatus(List<ZhcxSupervisionCustomUserManageDo> list) {
|
|
|
+ list.forEach((item)->{
|
|
|
+ if ("待审核".equals(item.getStatus())) {
|
|
|
+ item.setStatus("正常");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ manageService.updateBatchById(list);
|
|
|
+ }
|
|
|
}
|