Compare commits
8 Commits
master
...
dev-chenji
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b386ef9106 | ||
|
|
cace0eb2f5 | ||
|
|
7068df5eda | ||
|
|
941351d432 | ||
|
|
3053430c83 | ||
|
|
a5c87016e2 | ||
|
|
3bfed2ce99 | ||
|
|
0b7008a8b4 |
@ -61,7 +61,7 @@ public class AdminAgentEmployeeRelationController {
|
||||
}
|
||||
|
||||
@Operation(summary = "根据代理商ID获取员工列表")
|
||||
@GetMapping("/by-agent/{agentId}")
|
||||
@PostMapping("/by-agent/{agentId}")
|
||||
@SaCheckPermission("mp:admin:agent:employee:by-agent")
|
||||
public ResultBean<PageListBean<AgentEmployeeRelationResp>> getByAgent(@PathVariable Integer agentId,
|
||||
@RequestBody @Validated AgentEmployeeRelationQueryReq query) {
|
||||
|
||||
@ -15,6 +15,9 @@ public class AgentEmployeeSaveReq {
|
||||
@NotNull(message = "代理商Id不能为空")
|
||||
private Integer agentId;
|
||||
|
||||
@Schema(description = "用户Id")
|
||||
private Integer userId;
|
||||
|
||||
@Schema(description = "员工名称")
|
||||
@NotBlank(message = "员工名称不能为空")
|
||||
private String employeeName;
|
||||
|
||||
@ -17,7 +17,6 @@ import com.seer.teach.mp.entity.MpAgentEntity;
|
||||
import com.seer.teach.mp.service.IMpAgentEmployeeRelationService;
|
||||
import com.seer.teach.mp.service.IMpAgentService;
|
||||
import com.seer.teach.user.api.UserInfoServiceApi;
|
||||
import com.seer.teach.user.api.dto.UserInfoDTO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@ -85,7 +85,14 @@ public class AdminAgentEmployeeRelationServiceImpl implements IAdminAgentEmploye
|
||||
|
||||
@Override
|
||||
public boolean deleteRelation(Integer id) {
|
||||
return agentEmployeeRelationService.deleteRelation(id);
|
||||
Integer employeeUserId = agentEmployeeRelationService.lambdaQuery()
|
||||
.eq(MpAgentEmployeeRelationEntity::getId, id).one().getEmployeeUserId();
|
||||
boolean result = agentEmployeeRelationService.deleteRelation(id);
|
||||
if (result) {
|
||||
boolean deleteAgentRole = userInfoServiceApi.deleteAgentRole(employeeUserId);
|
||||
log.info("删除代理商角色关联结果: {}", deleteAgentRole);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -108,22 +115,33 @@ public class AdminAgentEmployeeRelationServiceImpl implements IAdminAgentEmploye
|
||||
@Override
|
||||
public boolean save(AgentEmployeeSaveReq request) {
|
||||
MpAgentEmployeeRelationEntity one = agentEmployeeRelationService.lambdaQuery()
|
||||
.eq(MpAgentEmployeeRelationEntity::getEmployeeName, request.getEmployeeName()).one();
|
||||
.eq(MpAgentEmployeeRelationEntity::getContactPhone, request.getMobile()).one();
|
||||
AssertUtils.isNull(one, ResultCodeEnum.AGENT_EMPLOYEE_ALREADY_EXISTS);
|
||||
|
||||
UserInfoDTO userInfoDTO = new UserInfoDTO();
|
||||
userInfoDTO.setUserName(request.getEmployeeName());
|
||||
userInfoDTO.setPassword(request.getPassword());
|
||||
userInfoDTO.setMobile(request.getMobile());
|
||||
userInfoDTO.setRoleCode(RoleEnum.AGENT);
|
||||
Integer userId = userInfoServiceApi.addUserInfoAndAssignRole(userInfoDTO);
|
||||
|
||||
MpAgentEmployeeRelationEntity entity = new MpAgentEmployeeRelationEntity();
|
||||
entity.setAgentId(request.getAgentId());
|
||||
entity.setAgentName(mpAgentService.getById(request.getAgentId()).getAgentName());
|
||||
entity.setEmployeeUserId(userId);
|
||||
entity.setEmployeeName(request.getEmployeeName());
|
||||
entity.setPosition(request.getPosition());
|
||||
entity.setStatus(request.getStatus());
|
||||
entity.setContactPhone(request.getMobile());
|
||||
if (request.getUserId() == null) {
|
||||
Integer userId = userInfoServiceApi.addUserInfoAndAssignRole(userInfoDTO);
|
||||
entity.setEmployeeUserId(userId);
|
||||
} else {
|
||||
entity.setEmployeeUserId(request.getUserId());
|
||||
userInfoDTO.setId(request.getUserId());
|
||||
boolean updated = userInfoServiceApi.updateUserInfo(userInfoDTO);
|
||||
if (updated) {
|
||||
userInfoServiceApi.saveUserRole("AGENT", request.getUserId());
|
||||
}
|
||||
}
|
||||
agentEmployeeRelationService.save(entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -7,10 +7,10 @@ CREATE TABLE `mp_test_child_character`(
|
||||
`constellation` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '星座',
|
||||
`child_birth_date` date NULL DEFAULT NULL COMMENT '出生年月',
|
||||
`child_gender` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '孩子性别(男,女)',
|
||||
`character_analysis` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '性格分析结果',
|
||||
`character_traits` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '性格特征',
|
||||
`suggestions` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '建议',
|
||||
`character_type` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '性格类型',
|
||||
`character_analysis` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '性格分析结果',
|
||||
`character_traits` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '性格特征',
|
||||
`suggestions` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '建议',
|
||||
`character_type` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '性格类型',
|
||||
`deleted` int NOT NULL COMMENT '逻辑删除(0-正常,1-已删除)',
|
||||
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||
`create_by` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NULL DEFAULT NULL COMMENT '创建人',
|
||||
|
||||
@ -201,4 +201,9 @@ public interface UserInfoServiceApi {
|
||||
@DeleteMapping("/deleteUserRoleByUserId")
|
||||
boolean deleteUserRoleByUserId(@RequestParam("userId") Integer userId);
|
||||
|
||||
@PostMapping("/saveUserRole")
|
||||
boolean saveUserRole(@RequestParam("roleCode") String roleCode, @RequestParam("userId") Integer userId);
|
||||
|
||||
@DeleteMapping("/deleteAgentRole")
|
||||
boolean deleteAgentRole(@RequestParam("userId") Integer userId);
|
||||
}
|
||||
@ -6,19 +6,24 @@ import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.seer.teach.common.PageListBean;
|
||||
import com.seer.teach.common.ResultBean;
|
||||
import com.seer.teach.common.annotation.LogPrint;
|
||||
import com.seer.teach.user.admin.request.*;
|
||||
import com.seer.teach.user.admin.request.AdminUpdateReq;
|
||||
import com.seer.teach.user.admin.request.AdminUserLoginReq;
|
||||
import com.seer.teach.user.admin.request.AdminUserSearchReq;
|
||||
import com.seer.teach.user.admin.request.RegisterAdminReq;
|
||||
import com.seer.teach.user.admin.response.AdminUserInfoResp;
|
||||
import com.seer.teach.user.admin.response.AdminUserPageResp;
|
||||
import com.seer.teach.user.admin.service.AdminUserService;
|
||||
import com.seer.teach.user.admin.service.AdminAuthorityService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.seer.teach.user.admin.service.AdminUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -169,4 +174,13 @@ public class AdminUserController {
|
||||
@Parameter(description = "角色编码") @RequestParam(value = "roleCode") String roleCode) {
|
||||
return ResultBean.success(adminUserService.listByRole(pageNo, pageSize, roleCode));
|
||||
}
|
||||
|
||||
@Operation(summary = "根据角色编码查询非代理商人员列表")
|
||||
@GetMapping("/getUserListByRole/{pageNo}/{pageSize}")
|
||||
public ResultBean<PageListBean<AdminUserPageResp>> getUserListByRole(
|
||||
@Parameter(description = "页码") @PathVariable("pageNo") Integer pageNo,
|
||||
@Parameter(description = "每页数量") @PathVariable("pageSize") Integer pageSize) {
|
||||
List<String> roleCodes = Arrays.asList("ADMIN", "AGENT");
|
||||
return ResultBean.success(adminUserService.getUserListByRole(pageNo, pageSize, roleCodes));
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,6 @@ package com.seer.teach.user.admin.response;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -61,6 +60,9 @@ public class AdminUserPageResp {
|
||||
@Schema(description = "微信open_id")
|
||||
private String openId;
|
||||
|
||||
@Schema(description = "是否为代理商(0-不是,1-是)")
|
||||
private Integer isAgent;
|
||||
|
||||
@Schema(description = "添加时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import com.seer.teach.user.admin.request.RegisterAdminReq;
|
||||
import com.seer.teach.user.admin.response.AdminUserPageResp;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -109,4 +110,13 @@ public interface AdminUserService {
|
||||
* @return 角色Id查询人员列表的响应数据
|
||||
*/
|
||||
PageListBean<AdminUserPageResp> getUserListByRoleId(AdminUserSearchReq searchReq);
|
||||
|
||||
/**
|
||||
* 根据角色查询人员列表
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param roleCodes
|
||||
* @return
|
||||
*/
|
||||
PageListBean<AdminUserPageResp> getUserListByRole(Integer pageNo, Integer pageSize, List<String> roleCodes);
|
||||
}
|
||||
|
||||
@ -13,7 +13,10 @@ import com.seer.teach.common.utils.AssertUtils;
|
||||
import com.seer.teach.common.utils.CommonUtils;
|
||||
import com.seer.teach.common.utils.PageConverterUtils;
|
||||
import com.seer.teach.user.admin.convert.AdminUserConvert;
|
||||
import com.seer.teach.user.admin.request.*;
|
||||
import com.seer.teach.user.admin.request.AdminUpdateReq;
|
||||
import com.seer.teach.user.admin.request.AdminUserLoginReq;
|
||||
import com.seer.teach.user.admin.request.AdminUserSearchReq;
|
||||
import com.seer.teach.user.admin.request.RegisterAdminReq;
|
||||
import com.seer.teach.user.admin.response.AdminUserPageResp;
|
||||
import com.seer.teach.user.admin.service.AdminUserService;
|
||||
import com.seer.teach.user.entity.RoleEntity;
|
||||
@ -137,6 +140,13 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
AssertUtils.notNull(adminUserEntity,ResultCodeEnum.USER_NOT_FOUND);
|
||||
|
||||
UserEntity userEntity = AdminUserConvert.INSTANCE.convertOne(params);
|
||||
// 如果密码不为空,则修改密码
|
||||
if (params.getPassword() != null && !params.getPassword().isEmpty()) {
|
||||
String password = CommonUtils.encryptPassword(params.getPassword());
|
||||
userEntity.setPassword(password);
|
||||
} else {
|
||||
userEntity.setPassword(adminUserEntity.getPassword());
|
||||
}
|
||||
userEntity.setId(id);
|
||||
userService.updateById(userEntity);
|
||||
}
|
||||
@ -255,4 +265,43 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
Page<UserEntity> resultPage = userService.page(page, new LambdaQueryWrapper<>(UserEntity.class).in(UserEntity::getId, userIds));
|
||||
return PageConverterUtils.convertPageListBean(resultPage, AdminUserConvert.INSTANCE::toPageRespList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageListBean<AdminUserPageResp> getUserListByRole(Integer pageNo, Integer pageSize, List<String> roleCodes) {
|
||||
Optional<List<RoleEntity>> role = roleService.getNotRoleByCode(roleCodes);
|
||||
if(role.isEmpty()){
|
||||
return new PageListBean<>();
|
||||
}
|
||||
List<UserRoleEntity> userRoles = userRoleService.list(new LambdaQueryWrapper<>(UserRoleEntity.class)
|
||||
.in(UserRoleEntity::getRoleId, role.get().stream().map(RoleEntity::getId).toList()));
|
||||
if (CollectionUtil.isEmpty(userRoles)) {
|
||||
return new PageListBean<>();
|
||||
}
|
||||
List<Integer> userIds = userRoles.stream().map(UserRoleEntity::getUserId).toList();
|
||||
if (CollectionUtil.isEmpty(userIds)) {
|
||||
return new PageListBean<>();
|
||||
}
|
||||
// 查询所有用户角色
|
||||
List<UserRoleEntity> allUserRoles = userRoleService.list(new LambdaQueryWrapper<>(UserRoleEntity.class)
|
||||
.in(UserRoleEntity::getUserId, userIds));
|
||||
Integer agentRoleId = roleService.getOne(new LambdaQueryWrapper<>(RoleEntity.class).eq(RoleEntity::getRoleCode, "AGENT")).getId();
|
||||
Set<Integer> agentUserIds = allUserRoles.stream().filter(ur -> ur.getRoleId().equals(agentRoleId)).map(UserRoleEntity::getUserId)
|
||||
.collect(Collectors.toSet());
|
||||
Page<UserEntity> page = new Page<>(pageNo, pageSize);
|
||||
LambdaQueryWrapper<UserEntity> wrapper = new LambdaQueryWrapper<>(UserEntity.class);
|
||||
wrapper.in(UserEntity::getId, userIds)
|
||||
.and(wrapperInner -> wrapperInner
|
||||
.isNotNull(UserEntity::getUserName)
|
||||
.and(i -> i.ne(UserEntity::getUserName, ""))
|
||||
.or()
|
||||
.isNotNull(UserEntity::getMobile)
|
||||
.and(i -> i.ne(UserEntity::getMobile, "")));
|
||||
Page<UserEntity> resultPage = userService.page(page, wrapper);
|
||||
PageListBean<AdminUserPageResp> pageList = PageConverterUtils.convertPageListBean(resultPage, AdminUserConvert.INSTANCE::toPageRespList);
|
||||
pageList.getList().forEach(resp -> {
|
||||
resp.setIsAgent(agentUserIds.contains(resp.getId()) ? 1 : 0);
|
||||
});
|
||||
return pageList;
|
||||
}
|
||||
|
||||
}
|
||||
@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@ -59,6 +60,8 @@ public class UserInfoServiceApiImpl implements UserInfoServiceApi {
|
||||
|
||||
private final IUserAuthService userAuthService;
|
||||
|
||||
private final IRoleService roleService;
|
||||
|
||||
|
||||
/**
|
||||
* 根据用户ID获取用户信息
|
||||
@ -343,8 +346,6 @@ public class UserInfoServiceApiImpl implements UserInfoServiceApi {
|
||||
public boolean deleteUserRoleByUserId(Integer userId) {
|
||||
UserRoleEntity one = userRoleService.lambdaQuery().eq(UserRoleEntity::getUserId, userId).one();
|
||||
if (one != null) {
|
||||
// 删除用户信息
|
||||
userService.removeById(userId);
|
||||
// 删除用户角色
|
||||
return userRoleService.removeById(one);
|
||||
}
|
||||
@ -352,6 +353,33 @@ public class UserInfoServiceApiImpl implements UserInfoServiceApi {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveUserRole(String roleCode, Integer userId) {
|
||||
Optional<RoleEntity> roleByCode = roleService.getRoleByCode(roleCode);
|
||||
if (roleByCode.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
UserRoleEntity userRoleEntity = new UserRoleEntity();
|
||||
userRoleEntity.setRoleId(roleByCode.get().getId());
|
||||
userRoleEntity.setUserId(userId);
|
||||
return userRoleService.save(userRoleEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAgentRole(Integer userId) {
|
||||
Optional<RoleEntity> role = roleService.getRoleByCode(RoleEnum.AGENT.getCode());
|
||||
if (role.isEmpty()) {
|
||||
log.warn("代理商角色不存在,无法删除代理商角色关联");
|
||||
return false;
|
||||
}
|
||||
Integer agentRoleId = role.get().getId();
|
||||
boolean result = userRoleService.remove(new LambdaQueryWrapper<UserRoleEntity>()
|
||||
.eq(UserRoleEntity::getUserId, userId)
|
||||
.eq(UserRoleEntity::getRoleId, agentRoleId));
|
||||
log.info("删除用户ID={}的代理商角色关联,结果={}", userId, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送更新孩子信息的MQ消息
|
||||
*
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package com.seer.teach.user.service;
|
||||
|
||||
import com.seer.teach.user.entity.RoleEntity;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.seer.teach.user.entity.RoleEntity;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -41,4 +41,5 @@ public interface IRoleService extends IService<RoleEntity> {
|
||||
*/
|
||||
Collection<RoleEntity> getRoleListByRoleIds(Collection<Integer> roleIds);
|
||||
|
||||
Optional<List<RoleEntity>> getNotRoleByCode(List<String> roleCodes);
|
||||
}
|
||||
|
||||
@ -2,14 +2,15 @@ package com.seer.teach.user.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.seer.teach.user.entity.RoleEntity;
|
||||
import com.seer.teach.user.mapper.RoleMapper;
|
||||
import com.seer.teach.user.service.IRoleService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@ -40,4 +41,13 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, RoleEntity> impleme
|
||||
}
|
||||
return super.list(new LambdaQueryWrapper<>(RoleEntity.class).in(RoleEntity::getId, roleIds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<RoleEntity>> getNotRoleByCode(List<String> roleCodes) {
|
||||
if (roleCodes == null || roleCodes.isEmpty()) {
|
||||
return Optional.ofNullable(super.list());
|
||||
}
|
||||
return Optional.ofNullable(super.list(new LambdaQueryWrapper<>(RoleEntity.class)
|
||||
.notIn(RoleEntity::getRoleCode, roleCodes)));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user