|
@@ -338,6 +338,57 @@ public class UserLogic {
|
|
|
user.updateById();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据初始化的师傅待入驻信息,通过手机号生成用户类型
|
|
|
+ *
|
|
|
+ * @param user
|
|
|
+ */
|
|
|
+ public void userTypeInit2(User user) {
|
|
|
+ String mobile = user.getMobile();
|
|
|
+ CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
|
|
|
+ List<UserWait> list = userWaitService.lambdaQuery()
|
|
|
+ .eq(UserWait::getMobile, mobile)
|
|
|
+ .eq(UserWait::getCompanyWechatId, currentCompanyWechat.getCurrentCompanyWechatId())
|
|
|
+ .list();
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ UserTypeEnum userTypeEnum = UserTypeEnum.valueOf(user.getType());
|
|
|
+ for (UserWait userWait : list) {
|
|
|
+ user.setWorkerNumber(userWait.getWorkerNumber());
|
|
|
+ user.setNickName(userWait.getName());
|
|
|
+ if (StringUtils.isBlank(user.getIdCard())) {
|
|
|
+ user.setIdCard(userWait.getIdcard());
|
|
|
+ }
|
|
|
+ //非师傅状态,只有有1个入驻师傅的就是师傅
|
|
|
+ if (userWait.getUserType().equals(UserTypeEnum.WORKER.getKey())) {
|
|
|
+
|
|
|
+ userTypeEnum = UserTypeEnum.WORKER;
|
|
|
+
|
|
|
+ if (!user.getType().equals(UserTypeEnum.WORKER.getKey())) {
|
|
|
+ //新增网点师傅,先删后增
|
|
|
+ websitUserService.lambdaUpdate()
|
|
|
+ .eq(WebsitUser::getWebsitId, userWait.getWebsitId())
|
|
|
+ .eq(WebsitUser::getUserId, user.getUserId())
|
|
|
+ .remove();
|
|
|
+
|
|
|
+ WebsitUser websitUser = new WebsitUser();
|
|
|
+ websitUser.setUserId(user.getUserId());
|
|
|
+ websitUser.setWebsitId(userWait.getWebsitId());
|
|
|
+ websitUser.setExamineStatus(ExamineStatusEnum.OK.getKey());
|
|
|
+ websitUser.setExamineTime(new Date());
|
|
|
+ websitUser.setExamineRemark("初始化");
|
|
|
+ websitUser.setBankAccount(userWait.getBankAccount());
|
|
|
+ websitUser.setWorkerNumber(userWait.getWorkerNumber());
|
|
|
+ websitUser.insert();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ user.setApplyType(userTypeEnum.getKey());
|
|
|
+ user.setType(userTypeEnum.getKey());
|
|
|
+ user.updateById();
|
|
|
+ }
|
|
|
|
|
|
// public User userToService(User user,CurrentCompanyWechat currentCompanyWechat){
|
|
|
// //判断该手机号是否为业务员
|
|
@@ -1233,7 +1284,7 @@ public class UserLogic {
|
|
|
smsLogic.sendSms2(mobile, key, vrifyCode);
|
|
|
}
|
|
|
|
|
|
- public UserWxBean workerMobileLogin(String mobile, String messageCode) {
|
|
|
+ public UserWxBean workerMobileLogin(String mobile, String messageCode) throws Exception {
|
|
|
Object validMessageCode = redisUtil.get(Constant.RedisPrefix.SMS + ":" + mobile);
|
|
|
if (Objects.isNull(validMessageCode)) {
|
|
|
throw new RemoteServiceException("短信验证码过期");
|
|
@@ -1252,25 +1303,62 @@ public class UserLogic {
|
|
|
return this.appUser(user);
|
|
|
}
|
|
|
|
|
|
- private User initAppUser(AdminCompanyWechat wechat, String mobile) {
|
|
|
+ private User initAppUser(AdminCompanyWechat wechat, String mobile) throws Exception {
|
|
|
UserWait userWait = userWaitService.lambdaQuery()
|
|
|
.eq(UserWait::getMobile, mobile)
|
|
|
.eq(UserWait::getUserType, UserTypeEnum.WORKER.getKey())
|
|
|
.last("limit 1")
|
|
|
.one();
|
|
|
|
|
|
+ User user = null;
|
|
|
if (Objects.isNull(userWait)) {
|
|
|
- throw new RemoteServiceException("无师傅信息");
|
|
|
+ user = userService.lambdaQuery()
|
|
|
+ .eq(User::getMobile, mobile)
|
|
|
+ .eq(User::getType, UserTypeEnum.WORKER.getKey())
|
|
|
+ .last("limit 1")
|
|
|
+ .one();
|
|
|
+
|
|
|
+ if (Objects.isNull(user)) {
|
|
|
+ throw new RemoteServiceException("无师傅信息");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- User user = new User();
|
|
|
- user.setCompanyWechatId(wechat.getCompanyWechatId())
|
|
|
- .setCompanyName(wechat.getCompanyName())
|
|
|
- .setNickName(userWait.getName())
|
|
|
- .setMobile(userWait.getMobile())
|
|
|
- .setType(UserTypeEnum.WORKER.getKey())
|
|
|
- .setWorkerNumber(userWait.getWorkerNumber());
|
|
|
- return user;
|
|
|
+ String key = Constant.RedisPrefix.LOCK_AUTH + ":" + mobile;
|
|
|
+ Lock obtain = redisLockRegistry.obtain(key);
|
|
|
+ if (!obtain.tryLock(2, TimeUnit.SECONDS)) {
|
|
|
+ log.error("请勿重复登录");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ //如果用户不存在则新注册
|
|
|
+ if (Objects.isNull(user) ) {
|
|
|
+ user = new User();
|
|
|
+ user.setUserId(IdWorker.getIdStr());
|
|
|
+ user.setLastLoginTime(new Date());
|
|
|
+ user.setCreateTime(new Date());
|
|
|
+ user.setMobile(mobile);
|
|
|
+ user.setCompanyWechatId(wechat.getCompanyWechatId());
|
|
|
+ user.setCompanyName(wechat.getCompanyName());
|
|
|
+ userService.save(user);
|
|
|
+ } else {
|
|
|
+ //如果用户存在,并更新相关信息
|
|
|
+ if (!user.getStatus()) {
|
|
|
+ throw new RemoteServiceException("用户已被冻结");
|
|
|
+ }
|
|
|
+ user.setLastLoginTime(new Date());
|
|
|
+ //授权手机号
|
|
|
+ user.updateById();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.nonNull(userWait)) {
|
|
|
+ this.userTypeInit2(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ return user;
|
|
|
+ } finally {
|
|
|
+ obtain.unlock();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void addVisit(UserWxBean userWxBean) {
|
|
@@ -1281,4 +1369,5 @@ public class UserLogic {
|
|
|
userVisit.setCompanyName(userWxBean.getCompanyName());
|
|
|
userVisit.insert();
|
|
|
}
|
|
|
+
|
|
|
}
|