|
@@ -0,0 +1,194 @@
|
|
|
+package com.rongwei.bscommon.sys.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+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.HwSmsUtil;
|
|
|
+import com.rongwei.bscommon.sys.utils.PasswordGenerator;
|
|
|
+import com.rongwei.bsentity.domain.ZhcxSupervisionCustomUserManageDo;
|
|
|
+import com.rongwei.commonservice.service.RedisService;
|
|
|
+import com.rongwei.rwadmincommon.system.domain.SysUserDo;
|
|
|
+import com.rongwei.rwadmincommon.system.service.SysUserService;
|
|
|
+import com.rongwei.rwcommon.base.R;
|
|
|
+import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
+import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
+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.Transactional;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Random;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class ZhcxRegisterServiceImpl implements ZhcxRegisterService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisService redisService;
|
|
|
+ @Autowired
|
|
|
+ private SysUserService sysUserService;
|
|
|
+ @Autowired
|
|
|
+ private ZhcxSupervisionCustomUserManageService manageService;
|
|
|
+ @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 name = jsonObject.getString("name");
|
|
|
+ String account = jsonObject.getString("account");
|
|
|
+ String email = jsonObject.getString("email");
|
|
|
+ String mobile = jsonObject.getString("mobile");
|
|
|
+ String code = jsonObject.getString("code");
|
|
|
+ Object yzmObj = redisService.getRedisCatchObj("register_"+mobile);
|
|
|
+ if(ObjectUtil.isEmpty(yzmObj)){
|
|
|
+ return R.error("未获取到验证码或验证码已过期,请获取验证码");
|
|
|
+ }
|
|
|
+ String yzm = (String) yzmObj;
|
|
|
+ if(code.equals(yzm)){
|
|
|
+ LambdaQueryWrapper<SysUserDo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.and(i -> i.eq(SysUserDo::getAccount, account).
|
|
|
+ or().eq(SysUserDo::getMobile, mobile).
|
|
|
+ or().eq(SysUserDo::getEmail, email));
|
|
|
+ List<SysUserDo> list = sysUserService.list(queryWrapper);
|
|
|
+ if(list.size() > 0){
|
|
|
+ return R.error("账号,手机号,邮箱已存在,请联系管理员");
|
|
|
+ }else{
|
|
|
+ SysUserDo sysUserDo = new SysUserDo();
|
|
|
+ ZhcxSupervisionCustomUserManageDo ManageDo = new ZhcxSupervisionCustomUserManageDo();
|
|
|
+ String uuid = SecurityUtil.getUUID();
|
|
|
+ sysUserDo.setId(uuid);
|
|
|
+ sysUserDo.setAccount(account);
|
|
|
+ sysUserDo.setMobile(mobile);
|
|
|
+ sysUserDo.setName(name);
|
|
|
+ sysUserDo.setEmail(email);
|
|
|
+ sysUserDo.setEnabled("1");
|
|
|
+ sysUserService.save(sysUserDo);
|
|
|
+ ManageDo.setId(SecurityUtil.getUUID());
|
|
|
+ ManageDo.setUserid(uuid);
|
|
|
+ ManageDo.setAccount(account);
|
|
|
+ ManageDo.setPhone(mobile);
|
|
|
+ ManageDo.setUserName(name);
|
|
|
+ ManageDo.setEmail(email);
|
|
|
+ ManageDo.setPid(jygs);
|
|
|
+ ManageDo.setStatus("待审核");
|
|
|
+ manageService.save(ManageDo);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return R.error("验证码错误,请重新输入");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ sendMail();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("监理注册审核邮件发送失败");
|
|
|
+ }
|
|
|
+ return R.ok("请等待后台管理员审核");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+
|
|
|
+ private R sendMail() {
|
|
|
+ List<SysUserDo> receiveUserList = manageService.getUserByRoleCode("role088");
|
|
|
+ List<String> userEmail = receiveUserList.stream().map(SysUserDo::getEmail).filter(StringUtils::isNotBlank).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (userEmail.isEmpty()) {
|
|
|
+ log.error("收件人邮箱为空:{}", userEmail);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R sendCode(Map<String, Object> map) {
|
|
|
+ Object mobileObj = map.get("mobile");
|
|
|
+ if(ObjectUtil.isEmpty(mobileObj)){
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+ String mobile = (String) mobileObj;
|
|
|
+ boolean exists = redisService.hasKey("register_"+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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = HwSmsUtil.sendSms(null,null, code.toString(), mobile);
|
|
|
+ String returnCode = jsonObject.getString("code");
|
|
|
+ if("000000".equals(returnCode)){
|
|
|
+ if(!exists){
|
|
|
+ redisService.redisCatchInit("registerCount_"+mobile,0,300);
|
|
|
+ }
|
|
|
+ sendCodeTime += 1;
|
|
|
+ redisService.redisCatchInit("registerCount_"+mobile,String.valueOf(sendCodeTime),300);
|
|
|
+ redisService.redisCatchInit("register_"+mobile,code.toString(),120);
|
|
|
+ return R.ok("发送成功");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R checkSupervisionUser(List<ZhcxSupervisionCustomUserManageDo> list) {
|
|
|
+ try {
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+}
|