1.app角色升级功能
2.sys_user表新增字段
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
package com.njcn.user.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/6/25 20:50
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum AppRoleEnum {
|
||||||
|
|
||||||
|
TOURIST("tourist","游客"),
|
||||||
|
APP_VIP_USER("app_vip_user","移动端正式用户"),
|
||||||
|
MARKET_USER("market_user","营销角色"),
|
||||||
|
ENGINEERING_USER("engineering_user","工程角色"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
AppRoleEnum(String code, String message) {
|
||||||
|
this.code=code;
|
||||||
|
this.message=message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -95,6 +95,9 @@ public enum UserResponseEnum {
|
|||||||
|
|
||||||
ROLE_NAME_REPEAT("A0117","角色名称重复"),
|
ROLE_NAME_REPEAT("A0117","角色名称重复"),
|
||||||
DEPT_PID_EXCEPTION("A0118","新增部门父节点信息异常"),
|
DEPT_PID_EXCEPTION("A0118","新增部门父节点信息异常"),
|
||||||
|
|
||||||
|
REFERRAL_CODE_LAPSE("A0119","角色推荐码失效,请联系管理员"),
|
||||||
|
REFERRAL_CODE_ERROR("A0119","角色推荐码错误,请联系管理员"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final String code;
|
private final String code;
|
||||||
|
|||||||
@@ -79,6 +79,12 @@ public class UserParam {
|
|||||||
@NotEmpty(message = UserValidMessage.ROLE_NOT_BLANK)
|
@NotEmpty(message = UserValidMessage.ROLE_NOT_BLANK)
|
||||||
private List<String> role;
|
private List<String> role;
|
||||||
|
|
||||||
|
@ApiModelProperty("手机识别码")
|
||||||
|
private String devCode;
|
||||||
|
|
||||||
|
@ApiModelProperty("移动端用户头像")
|
||||||
|
private String headSculpture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户新增操作实体
|
* 用户新增操作实体
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -143,4 +143,7 @@ public class User extends BaseEntity {
|
|||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
private LocalDateTime lockTime;
|
private LocalDateTime lockTime;
|
||||||
|
|
||||||
|
private String devCode;
|
||||||
|
|
||||||
|
private String headSculpture;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,4 +46,7 @@ public class UserVO extends UserParam implements Serializable {
|
|||||||
@ApiModelProperty("角色id")
|
@ApiModelProperty("角色id")
|
||||||
private List<String> roleList;
|
private List<String> roleList;
|
||||||
|
|
||||||
|
@ApiModelProperty("头像")
|
||||||
|
private String headSculpture;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.njcn.user.pojo.vo.app;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/6/25 18:40
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class RoleReferralCodeVO {
|
||||||
|
|
||||||
|
@ApiModelProperty("角色名称")
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
@ApiModelProperty("角色推荐码")
|
||||||
|
private String roleReferralCode;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.njcn.user.controller.app;
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.common.utils.HttpResultUtil;
|
||||||
|
import com.njcn.user.service.IAppRoleService;
|
||||||
|
import com.njcn.web.controller.BaseController;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/6/25 18:30
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/appRole")
|
||||||
|
@Api(tags = "App角色管理")
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class AppRoleController extends BaseController {
|
||||||
|
|
||||||
|
private final IAppRoleService appRoleService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* app用户角色升级
|
||||||
|
*/
|
||||||
|
@PostMapping("/roleUpdate")
|
||||||
|
@OperateInfo
|
||||||
|
@ApiOperation(value = "角色升级", notes = "角色升级")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query"),
|
||||||
|
@ApiImplicitParam(name = "referralCode", value = "推荐码", required = true, paramType = "query"),
|
||||||
|
@ApiImplicitParam(name = "devCode", value = "设备码", required = true, paramType = "query"),
|
||||||
|
})
|
||||||
|
public HttpResult<String> roleUpdate(@Param("userId")String userId,@Param("referralCode")String referralCode,@Param("devCode")String devCode) {
|
||||||
|
String methodDescribe = getMethodDescribe("roleUpdate");
|
||||||
|
appRoleService.roleUpdate(userId,referralCode,devCode);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "success", methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.njcn.user.controller.app;
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.common.utils.HttpResultUtil;
|
||||||
|
import com.njcn.user.pojo.vo.app.RoleReferralCodeVO;
|
||||||
|
import com.njcn.user.service.IReferralCodeService;
|
||||||
|
import com.njcn.web.controller.BaseController;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/6/25 16:13
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/referralCode")
|
||||||
|
@Api(tags = "推荐码管理")
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ReferralCodeController extends BaseController {
|
||||||
|
|
||||||
|
private final IReferralCodeService referralCodeService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看角色推荐码
|
||||||
|
* 1.用完就生成新的推荐码
|
||||||
|
* 2.规定时间内失效,重新生成推荐码
|
||||||
|
*/
|
||||||
|
@PostMapping("findReferralCode")
|
||||||
|
@OperateInfo
|
||||||
|
@ApiOperation(value = "查看角色推荐码", notes = "生成角色推荐码")
|
||||||
|
public HttpResult<List<RoleReferralCodeVO>> findReferralCode() {
|
||||||
|
String methodDescribe = getMethodDescribe("findReferralCode");
|
||||||
|
List<RoleReferralCodeVO> list = referralCodeService.findReferralCode();
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新角色推荐码
|
||||||
|
* 1.重新生成推荐码
|
||||||
|
*/
|
||||||
|
@PostMapping("refreshReferralCode")
|
||||||
|
@OperateInfo
|
||||||
|
@ApiOperation(value = "刷新角色推荐码", notes = "刷新角色推荐码")
|
||||||
|
public HttpResult<List<RoleReferralCodeVO>> refreshReferralCode() {
|
||||||
|
String methodDescribe = getMethodDescribe("refreshReferralCode");
|
||||||
|
List<RoleReferralCodeVO> list = referralCodeService.refreshReferralCode();
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.njcn.user.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/6/25 18:32
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface IAppRoleService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色升级
|
||||||
|
* @param userId
|
||||||
|
* @param referralCode
|
||||||
|
* @param devCode
|
||||||
|
*/
|
||||||
|
void roleUpdate(String userId, String referralCode, String devCode);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.njcn.user.service;
|
||||||
|
|
||||||
|
import com.njcn.user.pojo.vo.app.RoleReferralCodeVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/6/25 16:17
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface IReferralCodeService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询角色推荐码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<RoleReferralCodeVO> findReferralCode();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新角色推荐码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<RoleReferralCodeVO> refreshReferralCode();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -79,5 +79,11 @@ public interface IRoleService extends IService<Role> {
|
|||||||
|
|
||||||
Boolean selectRelevance(List<String> ids);
|
Boolean selectRelevance(List<String> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据角色code获取角色
|
||||||
|
* @param code
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Role getRoleByCode(String code);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package com.njcn.user.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.TypeReference;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
|
import com.njcn.user.enums.UserResponseEnum;
|
||||||
|
import com.njcn.user.pojo.po.UserRole;
|
||||||
|
import com.njcn.user.pojo.vo.app.RoleReferralCodeVO;
|
||||||
|
import com.njcn.user.service.IAppRoleService;
|
||||||
|
import com.njcn.user.service.IReferralCodeService;
|
||||||
|
import com.njcn.user.service.IRoleService;
|
||||||
|
import com.njcn.user.service.IUserRoleService;
|
||||||
|
import com.njcn.web.utils.RequestUtil;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/6/25 18:32
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class AppRoleServiceImpl implements IAppRoleService {
|
||||||
|
|
||||||
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
|
private final IRoleService roleService;
|
||||||
|
|
||||||
|
private final IUserRoleService userRoleService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void roleUpdate(String userId, String referralCode, String devCode) {
|
||||||
|
Object object = redisUtil.getObjectByKey("roleReferralCode");
|
||||||
|
if (Objects.isNull(object)){
|
||||||
|
throw new BusinessException(UserResponseEnum.REFERRAL_CODE_LAPSE);
|
||||||
|
}
|
||||||
|
LinkedHashMap<String,String> map = (LinkedHashMap<String,String>) object;
|
||||||
|
if (Objects.isNull(map.get(referralCode))){
|
||||||
|
throw new BusinessException(UserResponseEnum.REFERRAL_CODE_ERROR);
|
||||||
|
}
|
||||||
|
//修改用户和角色的关系
|
||||||
|
LambdaUpdateWrapper<UserRole> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
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(ReferralCodeServiceImpl.getCode(),entry.getValue());
|
||||||
|
} else {
|
||||||
|
roleMap.put(entry.getKey(),entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
redisUtil.saveByKeyWithExpire("roleReferralCode",roleMap,120L);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package com.njcn.user.service.impl;
|
||||||
|
|
||||||
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
|
import com.njcn.user.pojo.vo.app.RoleReferralCodeVO;
|
||||||
|
import com.njcn.user.service.IReferralCodeService;
|
||||||
|
import com.njcn.user.service.IRoleService;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类的介绍:
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @version 1.0.0
|
||||||
|
* @createTime 2023/6/25 16:17
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ReferralCodeServiceImpl implements IReferralCodeService {
|
||||||
|
|
||||||
|
private static final String BASIC = "123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZZ";
|
||||||
|
|
||||||
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
|
private final IRoleService roleService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RoleReferralCodeVO> findReferralCode() {
|
||||||
|
List<RoleReferralCodeVO> list = new ArrayList<>();
|
||||||
|
Object object = redisUtil.getObjectByKey("roleReferralCode");
|
||||||
|
if (Objects.isNull(object)){
|
||||||
|
LinkedHashMap<String,String> roleMap = new LinkedHashMap<>();
|
||||||
|
String code1 = getCode();
|
||||||
|
String code2 = getCode();
|
||||||
|
String code3 = getCode();
|
||||||
|
roleMap.put(code1,"market_user");
|
||||||
|
roleMap.put(code2,"engineering_user");
|
||||||
|
roleMap.put(code3,"app_user");
|
||||||
|
redisUtil.saveByKeyWithExpire("roleReferralCode",roleMap,120L);
|
||||||
|
RoleReferralCodeVO vo1 = new RoleReferralCodeVO();
|
||||||
|
vo1.setRoleName(roleService.getRoleByCode("market_user").getName());
|
||||||
|
vo1.setRoleReferralCode(code1);
|
||||||
|
RoleReferralCodeVO vo2 = new RoleReferralCodeVO();
|
||||||
|
vo2.setRoleName(roleService.getRoleByCode("engineering_user").getName());
|
||||||
|
vo2.setRoleReferralCode(code2);
|
||||||
|
RoleReferralCodeVO vo3 = new RoleReferralCodeVO();
|
||||||
|
vo3.setRoleName(roleService.getRoleByCode("app_user").getName());
|
||||||
|
vo3.setRoleReferralCode(code3);
|
||||||
|
list = Arrays.asList(vo1,vo2,vo3);
|
||||||
|
} else {
|
||||||
|
LinkedHashMap<String,String> map = (LinkedHashMap<String,String>) redisUtil.getObjectByKey("roleReferralCode");
|
||||||
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
|
RoleReferralCodeVO vo = new RoleReferralCodeVO();
|
||||||
|
vo.setRoleReferralCode(entry.getKey());
|
||||||
|
vo.setRoleName(roleService.getRoleByCode(entry.getValue()).getName());
|
||||||
|
list.add(vo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RoleReferralCodeVO> refreshReferralCode() {
|
||||||
|
LinkedHashMap<String,String> roleMap = new LinkedHashMap<>();
|
||||||
|
String code1 = getCode();
|
||||||
|
String code2 = getCode();
|
||||||
|
String code3 = getCode();
|
||||||
|
roleMap.put(code1,"market_user");
|
||||||
|
roleMap.put(code2,"engineering_user");
|
||||||
|
roleMap.put(code3,"app_user");
|
||||||
|
redisUtil.saveByKeyWithExpire("roleReferralCode",roleMap,120L);
|
||||||
|
RoleReferralCodeVO vo1 = new RoleReferralCodeVO();
|
||||||
|
vo1.setRoleName(roleService.getRoleByCode("market_user").getName());
|
||||||
|
vo1.setRoleReferralCode(code1);
|
||||||
|
RoleReferralCodeVO vo2 = new RoleReferralCodeVO();
|
||||||
|
vo2.setRoleName(roleService.getRoleByCode("engineering_user").getName());
|
||||||
|
vo2.setRoleReferralCode(code2);
|
||||||
|
RoleReferralCodeVO vo3 = new RoleReferralCodeVO();
|
||||||
|
vo3.setRoleName(roleService.getRoleByCode("app_user").getName());
|
||||||
|
vo3.setRoleReferralCode(code3);
|
||||||
|
return Arrays.asList(vo1,vo2,vo3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成随机推荐码
|
||||||
|
*/
|
||||||
|
public static String getCode(){
|
||||||
|
char[] basicArray = BASIC.toCharArray();
|
||||||
|
Random random = new Random();
|
||||||
|
char[] result = new char[6];
|
||||||
|
for (int i = 0; i < result.length; i++) {
|
||||||
|
int index = random.nextInt(100) % (basicArray.length);
|
||||||
|
result[i] = basicArray[index];
|
||||||
|
}
|
||||||
|
return new String(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -193,6 +193,11 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Role getRoleByCode(String code) {
|
||||||
|
return this.lambdaQuery().eq(Role::getCode,code).eq(Role::getState,1).one();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验参数,检查是否存在相同编码的角色代码
|
* 校验参数,检查是否存在相同编码的角色代码
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user