角色推荐码逻辑调整

1.用完不刷新
2.24小时刷新一次
This commit is contained in:
2023-08-15 16:35:04 +08:00
parent 63b8228cb6
commit c7050e9747
5 changed files with 31 additions and 21 deletions

View File

@@ -117,5 +117,4 @@ public enum UserResponseEnum {
}
return "";
}
}

View File

@@ -15,6 +15,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
@@ -57,6 +58,7 @@ public class ReferralCodeController extends BaseController {
@PostMapping("refreshReferralCode")
@OperateInfo
@ApiOperation(value = "刷新角色推荐码", notes = "刷新角色推荐码")
@ApiIgnore
public HttpResult<List<RoleReferralCodeVO>> refreshReferralCode() {
String methodDescribe = getMethodDescribe("refreshReferralCode");
List<RoleReferralCodeVO> list = referralCodeService.refreshReferralCode();

View File

@@ -17,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
/**
* 类的介绍:
@@ -42,7 +43,7 @@ public class AppRoleServiceImpl implements IAppRoleService {
if (Objects.isNull(object)){
throw new BusinessException(UserResponseEnum.REFERRAL_CODE_LAPSE);
}
LinkedHashMap<String,String> map = (LinkedHashMap<String,String>) object;
Map<String, String> map = ( Map<String, String>) object;
if (Objects.isNull(map.get(referralCode))){
throw new BusinessException(UserResponseEnum.REFERRAL_CODE_ERROR);
}
@@ -51,15 +52,15 @@ public class AppRoleServiceImpl implements IAppRoleService {
lambdaUpdateWrapper.eq(UserRole::getUserId,userId).set(UserRole::getRoleId,roleService.getRoleByCode(map.get(referralCode)).getId());
userRoleService.update(lambdaUpdateWrapper);
//重新生成新的推荐码
LinkedHashMap<String,String> roleMap = new LinkedHashMap<>();
for (Map.Entry<String, String> entry : map.entrySet()) {
if (Objects.equals(entry.getKey(),referralCode)){
roleMap.put(PubUtils.getCode(6),entry.getValue());
} else {
roleMap.put(entry.getKey(),entry.getValue());
}
}
redisUtil.saveByKeyWithExpire("ROLE_REFERRAL_CODE",roleMap,120L);
// LinkedHashMap<String,String> roleMap = new LinkedHashMap<>();
// for (Map.Entry<String, String> entry : map.entrySet()) {
// if (Objects.equals(entry.getKey(),referralCode)){
// roleMap.put(PubUtils.getCode(6),entry.getValue());
// } else {
// roleMap.put(entry.getKey(),entry.getValue());
// }
// }
// redisUtil.saveByKeyWithExpire("ROLE_REFERRAL_CODE",roleMap,120L);
}
}

View File

@@ -1,5 +1,6 @@
package com.njcn.user.service.impl;
import cn.hutool.core.util.IdUtil;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
@@ -110,7 +111,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, User> impleme
}
} else {
if (null == user) {
throw new BusinessException(UserResponseEnum.LOGIN_USERNAME_NOT_FOUND);
throw new BusinessException(UserResponseEnum.LOGIN_PHONE_NOT_REGISTER);
} else {
user.setDevCode(devCode);
logger.info("更新手机id" + devCode);
@@ -165,7 +166,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, User> impleme
} catch (Exception e) {
logger.error("发送短信异常,异常为:"+e.getMessage());
if (e.getMessage().length() < 10) {
throw new BusinessException(UserResponseEnum.getCodeByMsg(e.getMessage()));
throw new BusinessException(e.getMessage());
} else {
throw new BusinessException(UserResponseEnum.SEND_CODE_FAIL);
}
@@ -378,7 +379,12 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, User> impleme
appSendMsg.setSendStatus(sendSmsResponse.getCode() == null ? "无状态" : sendSmsResponse.getCode());
appSendMsgService.save(appSendMsg);
} catch (ClientException e) {
e.printStackTrace();
logger.error("发送短信异常,异常为:"+e.getMessage());
if (e.getMessage().length() < 10) {
throw new BusinessException(e.getMessage());
} else {
throw new BusinessException(UserResponseEnum.SEND_CODE_FAIL);
}
}
}
@@ -394,7 +400,8 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, User> impleme
//填写一些默认值
user.setPhone(phone);
user.setDevCode(devCode);
user.setName(phone);
//用户名随机
user.setName(IdUtil.fastSimpleUUID());
user.setLoginName(phone);
user.setType(3);
user.setState(UserState.ENABLE);

View File

@@ -9,6 +9,7 @@ import com.njcn.user.service.IReferralCodeService;
import com.njcn.user.service.IRoleService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.map.CaseInsensitiveMap;
import org.springframework.stereotype.Service;
import java.util.*;
@@ -36,7 +37,7 @@ public class ReferralCodeServiceImpl implements IReferralCodeService {
if (Objects.isNull(object)){
list = refreshReferralCode();
} else {
LinkedHashMap<String,String> map = (LinkedHashMap<String,String>) redisUtil.getObjectByKey(RedisKeyEnum.ROLE_REFERRAL_CODE_KEY.getKey());
Map<String, String> map = ( Map<String, String>) redisUtil.getObjectByKey(RedisKeyEnum.ROLE_REFERRAL_CODE_KEY.getKey());
for (Map.Entry<String, String> entry : map.entrySet()) {
RoleReferralCodeVO vo = new RoleReferralCodeVO();
vo.setRoleReferralCode(entry.getKey());
@@ -49,14 +50,14 @@ public class ReferralCodeServiceImpl implements IReferralCodeService {
@Override
public List<RoleReferralCodeVO> refreshReferralCode() {
LinkedHashMap<String,String> roleMap = new LinkedHashMap<>();
Map<String, String> result = new CaseInsensitiveMap();
String code1 = PubUtils.getCode(6);
String code2 = PubUtils.getCode(6);
String code3 = PubUtils.getCode(6);
roleMap.put(code1,AppRoleEnum.MARKET_USER.getCode());
roleMap.put(code2,AppRoleEnum.ENGINEERING_USER.getCode());
roleMap.put(code3,AppRoleEnum.APP_VIP_USER.getCode());
redisUtil.saveByKeyWithExpire("ROLE_REFERRAL_CODE",roleMap,120L);
result.put(code1,AppRoleEnum.MARKET_USER.getCode());
result.put(code2,AppRoleEnum.ENGINEERING_USER.getCode());
result.put(code3,AppRoleEnum.APP_VIP_USER.getCode());
redisUtil.saveByKeyWithExpire("ROLE_REFERRAL_CODE",result,86400L);
RoleReferralCodeVO vo1 = new RoleReferralCodeVO();
vo1.setRoleName(roleService.getRoleByCode(AppRoleEnum.MARKET_USER.getCode()).getName());
vo1.setRoleReferralCode(code1);