代理商在增加员工时,同步增加员工的角色
This commit is contained in:
parent
9e733f71ff
commit
543f972c5c
@ -30,6 +30,7 @@ public enum ResultCodeEnum {
|
|||||||
USER_MOBILE_EXIST(1002, "该账号号已经被注册"),
|
USER_MOBILE_EXIST(1002, "该账号号已经被注册"),
|
||||||
PHONE_IS_REPEAT(1009, "账号已被注册,请重新输入"),
|
PHONE_IS_REPEAT(1009, "账号已被注册,请重新输入"),
|
||||||
USER_NOT_FOUND(1003, "用户不存在"),
|
USER_NOT_FOUND(1003, "用户不存在"),
|
||||||
|
USER_SAVE_ERROR(10031, "用户保存失败"),
|
||||||
USER_PERMISSION_DENIED_ERROR(1004, "用户权限不足"),
|
USER_PERMISSION_DENIED_ERROR(1004, "用户权限不足"),
|
||||||
PLEASE_LOGIN(1005, "请先登录"),
|
PLEASE_LOGIN(1005, "请先登录"),
|
||||||
USERNAME_IS_REPEAT(1006, "用户名重复"),
|
USERNAME_IS_REPEAT(1006, "用户名重复"),
|
||||||
@ -337,7 +338,9 @@ public enum ResultCodeEnum {
|
|||||||
PARENT_NOT_FOUND(13011, "家长不存在"),
|
PARENT_NOT_FOUND(13011, "家长不存在"),
|
||||||
INVALID_ACTIVITY_STATUS(13012, "无效的活动状态"),
|
INVALID_ACTIVITY_STATUS(13012, "无效的活动状态"),
|
||||||
PARENT_ALREADY_SIGN_UP(130121, "已经报名参加该活动"),
|
PARENT_ALREADY_SIGN_UP(130121, "已经报名参加该活动"),
|
||||||
UNAUTHORIZED_UPDATE_EMPLOYEE(13013, "无权限更新员工信息");
|
UNAUTHORIZED_UPDATE_EMPLOYEE(13013, "无权限更新员工信息"),
|
||||||
|
DATA_REPEAT_ERROR(130014, "数据重复"),
|
||||||
|
DATA_NOT_EXIST(130015, "数据不存在");
|
||||||
|
|
||||||
private int code;
|
private int code;
|
||||||
private String msg;
|
private String msg;
|
||||||
|
|||||||
@ -45,7 +45,12 @@ public enum RoleEnum implements ArrayValuable<String> {
|
|||||||
/**
|
/**
|
||||||
* 访客
|
* 访客
|
||||||
*/
|
*/
|
||||||
GUEST("GUEST", "GUEST", "访客"),;
|
GUEST("GUEST", "GUEST", "访客"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代理商
|
||||||
|
*/
|
||||||
|
AGENT("AGENT", "代理商", "代理商角色");
|
||||||
|
|
||||||
public static final String[] ARRAYS = Arrays.stream(values()).map(RoleEnum::getCode).toArray(String[]::new);
|
public static final String[] ARRAYS = Arrays.stream(values()).map(RoleEnum::getCode).toArray(String[]::new);
|
||||||
|
|
||||||
|
|||||||
@ -40,6 +40,9 @@ public class MpAgentEmployeeRelationEntity extends BaseEntity {
|
|||||||
@TableField("employee_name")
|
@TableField("employee_name")
|
||||||
private String employeeName;
|
private String employeeName;
|
||||||
|
|
||||||
|
@TableField("contact_phone")
|
||||||
|
private String contactPhone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 员工职位
|
* 员工职位
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.seer.teach.mp.entity;
|
package com.seer.teach.mp.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.seer.teach.common.entity.BaseEntity;
|
import com.seer.teach.common.entity.BaseEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -31,6 +32,9 @@ public class MpAgentEntity extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
private String contactName;
|
private String contactName;
|
||||||
|
|
||||||
|
@TableField("contact_user_id")
|
||||||
|
private Integer contactUserId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 联系电话
|
* 联系电话
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -5,14 +5,21 @@ import com.seer.teach.common.PageListBean;
|
|||||||
import com.seer.teach.common.ResultBean;
|
import com.seer.teach.common.ResultBean;
|
||||||
import com.seer.teach.common.annotation.LogPrint;
|
import com.seer.teach.common.annotation.LogPrint;
|
||||||
import com.seer.teach.mp.admin.controller.req.AgentQueryReq;
|
import com.seer.teach.mp.admin.controller.req.AgentQueryReq;
|
||||||
|
import com.seer.teach.mp.admin.controller.req.MpAgentReq;
|
||||||
import com.seer.teach.mp.admin.controller.resp.AgentResp;
|
import com.seer.teach.mp.admin.controller.resp.AgentResp;
|
||||||
import com.seer.teach.mp.admin.service.AdminAgentService;
|
import com.seer.teach.mp.admin.service.AdminAgentService;
|
||||||
import com.seer.teach.mp.entity.MpAgentEntity;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -42,15 +49,15 @@ public class AdminAgentController {
|
|||||||
@Operation(summary = "新增")
|
@Operation(summary = "新增")
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@SaCheckPermission("mp:admin:agent:save")
|
@SaCheckPermission("mp:admin:agent:save")
|
||||||
public ResultBean<Boolean> save(@RequestBody MpAgentEntity agentEntity) {
|
public ResultBean<Boolean> save(@RequestBody MpAgentReq req) {
|
||||||
return ResultBean.success(adminAgentService.saveAgent(agentEntity));
|
return ResultBean.success(adminAgentService.saveAgent(req));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "更新")
|
@Operation(summary = "更新")
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@SaCheckPermission("mp:admin:agent:update")
|
@SaCheckPermission("mp:admin:agent:update")
|
||||||
public ResultBean<Boolean> update(@RequestBody MpAgentEntity agentEntity) {
|
public ResultBean<Boolean> update(@RequestBody MpAgentReq req) {
|
||||||
return ResultBean.success(adminAgentService.updateAgent(agentEntity));
|
return ResultBean.success(adminAgentService.updateAgent(req));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "删除")
|
@Operation(summary = "删除")
|
||||||
|
|||||||
@ -0,0 +1,54 @@
|
|||||||
|
package com.seer.teach.mp.admin.controller.req;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(name = "MpAgentReq", description = "代理商请求参数")
|
||||||
|
@Data
|
||||||
|
public class MpAgentReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代理商名称
|
||||||
|
*/
|
||||||
|
private String agentName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代理商编码
|
||||||
|
*/
|
||||||
|
private String agentCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代理商等级
|
||||||
|
*/
|
||||||
|
private String agentLevel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 联系人姓名
|
||||||
|
*/
|
||||||
|
private String contactName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 联系人用户Id
|
||||||
|
*/
|
||||||
|
private Integer contactUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 联系电话
|
||||||
|
*/
|
||||||
|
private String contactPhone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代理商地址
|
||||||
|
*/
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代理商状态:0-禁用,1-启用
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.seer.teach.mp.admin.convert;
|
package com.seer.teach.mp.admin.convert;
|
||||||
|
|
||||||
import com.seer.teach.mp.admin.controller.req.AgentQueryReq;
|
import com.seer.teach.mp.admin.controller.req.AgentQueryReq;
|
||||||
|
import com.seer.teach.mp.admin.controller.req.MpAgentReq;
|
||||||
import com.seer.teach.mp.admin.controller.resp.AgentResp;
|
import com.seer.teach.mp.admin.controller.resp.AgentResp;
|
||||||
import com.seer.teach.mp.entity.MpAgentEntity;
|
import com.seer.teach.mp.entity.MpAgentEntity;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
@ -19,5 +20,7 @@ public interface AgentConvert {
|
|||||||
|
|
||||||
MpAgentEntity convertOne(AgentQueryReq req);
|
MpAgentEntity convertOne(AgentQueryReq req);
|
||||||
|
|
||||||
|
MpAgentEntity convertOne2Entity(MpAgentReq req);
|
||||||
|
|
||||||
AgentQueryReq convertToReq(MpAgentEntity entity);
|
AgentQueryReq convertToReq(MpAgentEntity entity);
|
||||||
}
|
}
|
||||||
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.seer.teach.common.PageListBean;
|
import com.seer.teach.common.PageListBean;
|
||||||
import com.seer.teach.common.utils.PageConverterUtils;
|
import com.seer.teach.common.utils.PageConverterUtils;
|
||||||
import com.seer.teach.mp.admin.controller.req.AgentQueryReq;
|
import com.seer.teach.mp.admin.controller.req.AgentQueryReq;
|
||||||
|
import com.seer.teach.mp.admin.controller.req.MpAgentReq;
|
||||||
import com.seer.teach.mp.admin.controller.resp.AgentResp;
|
import com.seer.teach.mp.admin.controller.resp.AgentResp;
|
||||||
import com.seer.teach.mp.admin.convert.AgentConvert;
|
import com.seer.teach.mp.admin.convert.AgentConvert;
|
||||||
import com.seer.teach.mp.entity.MpAgentEntity;
|
import com.seer.teach.mp.entity.MpAgentEntity;
|
||||||
@ -59,11 +60,12 @@ public class AdminAgentService {
|
|||||||
/**
|
/**
|
||||||
* 保存代理商
|
* 保存代理商
|
||||||
*
|
*
|
||||||
* @param agentEntity 代理商实体
|
* @param req 代理商
|
||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
public Boolean saveAgent(MpAgentEntity agentEntity) {
|
public Boolean saveAgent(MpAgentReq req) {
|
||||||
boolean result = mpAgentService.saveAgent(agentEntity);
|
MpAgentEntity agentEntity = AgentConvert.INSTANCE.convertOne2Entity(req);
|
||||||
|
boolean result = mpAgentService.saveAgent(agentEntity,req.getPassword());
|
||||||
log.info("保存代理商结果: {}", result);
|
log.info("保存代理商结果: {}", result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -71,10 +73,11 @@ public class AdminAgentService {
|
|||||||
/**
|
/**
|
||||||
* 更新代理商
|
* 更新代理商
|
||||||
*
|
*
|
||||||
* @param agentEntity 代理商实体
|
* @param req 代理商
|
||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
public Boolean updateAgent(MpAgentEntity agentEntity) {
|
public Boolean updateAgent(MpAgentReq req) {
|
||||||
|
MpAgentEntity agentEntity = AgentConvert.INSTANCE.convertOne2Entity(req);
|
||||||
boolean result = mpAgentService.updateAgent(agentEntity);
|
boolean result = mpAgentService.updateAgent(agentEntity);
|
||||||
log.info("更新代理商结果: {}", result);
|
log.info("更新代理商结果: {}", result);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -76,7 +76,7 @@ public class AdminDealerApplicationsService {
|
|||||||
userInfoDTO.setRealName(application.getApplicantName());
|
userInfoDTO.setRealName(application.getApplicantName());
|
||||||
userInfoDTO.setMobile(application.getPhone());
|
userInfoDTO.setMobile(application.getPhone());
|
||||||
userInfoDTO.setIdCardNumber(application.getIdCardNumber());
|
userInfoDTO.setIdCardNumber(application.getIdCardNumber());
|
||||||
userInfoDTO.setRoleCode(RoleEnum.DISTRIBUTOR.getCode());
|
userInfoDTO.setRoleCode(RoleEnum.DISTRIBUTOR);
|
||||||
boolean updated = userInfoServiceApi.updateUserInfoAndAssignRole(userInfoDTO);
|
boolean updated = userInfoServiceApi.updateUserInfoAndAssignRole(userInfoDTO);
|
||||||
log.info("更新用户[{}]信息结果: {}",application.getApplicantUserId(), updated);
|
log.info("更新用户[{}]信息结果: {}",application.getApplicantUserId(), updated);
|
||||||
if(updated){
|
if(updated){
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.seer.teach.common.PageListBean;
|
import com.seer.teach.common.PageListBean;
|
||||||
import com.seer.teach.common.enums.ResultCodeEnum;
|
import com.seer.teach.common.enums.ResultCodeEnum;
|
||||||
|
import com.seer.teach.common.enums.RoleEnum;
|
||||||
import com.seer.teach.common.utils.AssertUtils;
|
import com.seer.teach.common.utils.AssertUtils;
|
||||||
import com.seer.teach.common.utils.PageConverterUtils;
|
import com.seer.teach.common.utils.PageConverterUtils;
|
||||||
import com.seer.teach.mp.admin.controller.req.AgentEmployeeRelationQueryReq;
|
import com.seer.teach.mp.admin.controller.req.AgentEmployeeRelationQueryReq;
|
||||||
@ -86,12 +87,12 @@ public class AdminAgentEmployeeRelationServiceImpl implements IAdminAgentEmploye
|
|||||||
UserInfoDTO userInfoDTO = new UserInfoDTO();
|
UserInfoDTO userInfoDTO = new UserInfoDTO();
|
||||||
userInfoDTO.setUserName(request.getEmployeeName());
|
userInfoDTO.setUserName(request.getEmployeeName());
|
||||||
userInfoDTO.setPassword(request.getPassword());
|
userInfoDTO.setPassword(request.getPassword());
|
||||||
userInfoServiceApi.saveAgentInfo(userInfoDTO);
|
userInfoDTO.setRoleCode(RoleEnum.AGENT);
|
||||||
Integer employeeUserId = userInfoServiceApi.getUserIdByUserName(request.getEmployeeName());
|
Integer userId = userInfoServiceApi.addUserInfoAndAssignRole(userInfoDTO);
|
||||||
Integer agentId = mpAgentService.lambdaQuery().eq(MpAgentEntity::getAgentName, request.getAgentName()).one().getId();
|
Integer agentId = mpAgentService.lambdaQuery().eq(MpAgentEntity::getAgentName, request.getAgentName()).one().getId();
|
||||||
MpAgentEmployeeRelationEntity entity = new MpAgentEmployeeRelationEntity();
|
MpAgentEmployeeRelationEntity entity = new MpAgentEmployeeRelationEntity();
|
||||||
entity.setAgentId(agentId);
|
entity.setAgentId(agentId);
|
||||||
entity.setEmployeeUserId(employeeUserId);
|
entity.setEmployeeUserId(userId);
|
||||||
entity.setEmployeeName(request.getEmployeeName());
|
entity.setEmployeeName(request.getEmployeeName());
|
||||||
entity.setAgentName(request.getAgentName());
|
entity.setAgentName(request.getAgentName());
|
||||||
entity.setPosition(request.getPosition());
|
entity.setPosition(request.getPosition());
|
||||||
|
|||||||
@ -25,6 +25,12 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>seer-user-api</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springdoc</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
|||||||
@ -50,7 +50,6 @@ public class AppAgentEmployeeRelationController {
|
|||||||
@SaCheckLogin
|
@SaCheckLogin
|
||||||
public ResultBean<Boolean> updateEmployee(@RequestBody @Validated AppAgentEmployeeRelationReq request) {
|
public ResultBean<Boolean> updateEmployee(@RequestBody @Validated AppAgentEmployeeRelationReq request) {
|
||||||
Integer agentId = StpUtil.getLoginIdAsInt();
|
Integer agentId = StpUtil.getLoginIdAsInt();
|
||||||
// 验证员工是否属于当前代理商
|
|
||||||
boolean belongsToAgent = agentEmployeeRelationService.isEmployeeBelongsToAgent(request.getId(), agentId);
|
boolean belongsToAgent = agentEmployeeRelationService.isEmployeeBelongsToAgent(request.getId(), agentId);
|
||||||
if (!belongsToAgent) {
|
if (!belongsToAgent) {
|
||||||
return ResultBean.error(ResultCodeEnum.UNAUTHORIZED_UPDATE_EMPLOYEE);
|
return ResultBean.error(ResultCodeEnum.UNAUTHORIZED_UPDATE_EMPLOYEE);
|
||||||
@ -74,8 +73,7 @@ public class AppAgentEmployeeRelationController {
|
|||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
@SaCheckLogin
|
@SaCheckLogin
|
||||||
public ResultBean<AppAgentEmployeeRelationResp> getEmployee(@PathVariable Integer id) {
|
public ResultBean<AppAgentEmployeeRelationResp> getEmployee(@PathVariable Integer id) {
|
||||||
Integer agentId = StpUtil.getLoginIdAsInt(); // 假设代理商ID就是登录ID
|
Integer agentId = StpUtil.getLoginIdAsInt();
|
||||||
// 验证员工是否属于当前代理商
|
|
||||||
boolean belongsToAgent = agentEmployeeRelationService.isEmployeeBelongsToAgent(id, agentId);
|
boolean belongsToAgent = agentEmployeeRelationService.isEmployeeBelongsToAgent(id, agentId);
|
||||||
if (!belongsToAgent) {
|
if (!belongsToAgent) {
|
||||||
return ResultBean.error(ResultCodeEnum.UNAUTHORIZED_UPDATE_EMPLOYEE);
|
return ResultBean.error(ResultCodeEnum.UNAUTHORIZED_UPDATE_EMPLOYEE);
|
||||||
@ -88,7 +86,7 @@ public class AppAgentEmployeeRelationController {
|
|||||||
@GetMapping("/all")
|
@GetMapping("/all")
|
||||||
@SaCheckLogin
|
@SaCheckLogin
|
||||||
public ResultBean<List<AppAgentEmployeeRelationResp>> getAllEmployees() {
|
public ResultBean<List<AppAgentEmployeeRelationResp>> getAllEmployees() {
|
||||||
Integer agentId = StpUtil.getLoginIdAsInt(); // 假设代理商ID就是登录ID
|
Integer agentId = StpUtil.getLoginIdAsInt();
|
||||||
return ResultBean.success(agentEmployeeRelationService.getAllEmployeesByAgentId(agentId));
|
return ResultBean.success(agentEmployeeRelationService.getAllEmployeesByAgentId(agentId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -13,11 +13,16 @@ public class AppAgentEmployeeRelationReq {
|
|||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@Schema(description = "代理商ID")
|
@Schema(description = "代理商ID")
|
||||||
private Integer agentId; // 用于内部验证,不强制要求前端传入
|
private Integer agentId;
|
||||||
|
|
||||||
@NotNull(message = "员工用户ID不能为空")
|
@Schema(description = "员工名称")
|
||||||
@Schema(description = "员工用户ID")
|
private String employeeName;
|
||||||
private Integer employeeUserId;
|
|
||||||
|
@Schema(description = "员工密码")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Schema(description = "联系电话")
|
||||||
|
private String contactPhone;
|
||||||
|
|
||||||
@Schema(description = "员工职位")
|
@Schema(description = "员工职位")
|
||||||
private String position;
|
private String position;
|
||||||
|
|||||||
@ -27,4 +27,7 @@ public class AppMpAgentResp {
|
|||||||
|
|
||||||
@Schema(description = "代理商地址")
|
@Schema(description = "代理商地址")
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
|
@Schema(description = "是否是代理商联系人")
|
||||||
|
private Boolean isContactPerson;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.seer.teach.common.PageListBean;
|
import com.seer.teach.common.PageListBean;
|
||||||
import com.seer.teach.common.enums.ResultCodeEnum;
|
import com.seer.teach.common.enums.ResultCodeEnum;
|
||||||
|
import com.seer.teach.common.enums.RoleEnum;
|
||||||
import com.seer.teach.common.exception.CommonException;
|
import com.seer.teach.common.exception.CommonException;
|
||||||
import com.seer.teach.common.utils.AssertUtils;
|
import com.seer.teach.common.utils.AssertUtils;
|
||||||
import com.seer.teach.common.utils.PageConverterUtils;
|
import com.seer.teach.common.utils.PageConverterUtils;
|
||||||
@ -15,8 +16,10 @@ import com.seer.teach.mp.app.controller.resp.AppAgentEmployeeRelationResp;
|
|||||||
import com.seer.teach.mp.app.service.IAppAgentEmployeeRelationService;
|
import com.seer.teach.mp.app.service.IAppAgentEmployeeRelationService;
|
||||||
import com.seer.teach.mp.entity.MpAgentEmployeeRelationEntity;
|
import com.seer.teach.mp.entity.MpAgentEmployeeRelationEntity;
|
||||||
import com.seer.teach.mp.service.IMpAgentEmployeeRelationService;
|
import com.seer.teach.mp.service.IMpAgentEmployeeRelationService;
|
||||||
import com.seer.teach.user.api.UserService;
|
import com.seer.teach.user.api.UserInfoServiceApi;
|
||||||
|
import com.seer.teach.user.api.UserRelationServiceApi;
|
||||||
import com.seer.teach.user.api.dto.UserInfoDTO;
|
import com.seer.teach.user.api.dto.UserInfoDTO;
|
||||||
|
import com.seer.teach.user.api.dto.UserRelationDTO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -39,18 +42,18 @@ import java.util.stream.Collectors;
|
|||||||
public class AppAgentEmployeeRelationServiceImpl implements IAppAgentEmployeeRelationService {
|
public class AppAgentEmployeeRelationServiceImpl implements IAppAgentEmployeeRelationService {
|
||||||
|
|
||||||
private final IMpAgentEmployeeRelationService mpAgentEmployeeRelationService;
|
private final IMpAgentEmployeeRelationService mpAgentEmployeeRelationService;
|
||||||
private final UserService userService;
|
private final UserInfoServiceApi userInfoServiceApi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageListBean<AppAgentEmployeeRelationResp> pageList(AppAgentEmployeeRelationQueryReq query) {
|
public PageListBean<AppAgentEmployeeRelationResp> pageList(AppAgentEmployeeRelationQueryReq query) {
|
||||||
log.info("查询参数:{}", query);
|
log.info("查询参数:{}", query);
|
||||||
IPage<MpAgentEmployeeRelationEntity> page = new Page<>(query.getPageNo(), query.getPageSize());
|
IPage<MpAgentEmployeeRelationEntity> page = new Page<>(query.getPageNo(), query.getPageSize());
|
||||||
var pageResult = mpAgentEmployeeRelationService.page(page, new LambdaQueryWrapper<>(MpAgentEmployeeRelationEntity.class)
|
var pageResult = mpAgentEmployeeRelationService.page(page, new LambdaQueryWrapper<>(MpAgentEmployeeRelationEntity.class)
|
||||||
.eq(query.getAgentId() != null, MpAgentEmployeeRelationEntity::getAgentId, query.getAgentId()) // 只查询当前代理商的员工
|
.eq(MpAgentEmployeeRelationEntity::getAgentId, query.getAgentId())
|
||||||
.like(StringUtils.isNotBlank(query.getPosition()), MpAgentEmployeeRelationEntity::getPosition, query.getPosition())
|
.like(StringUtils.isNotBlank(query.getPosition()), MpAgentEmployeeRelationEntity::getPosition, query.getPosition())
|
||||||
.eq(query.getStatus() != null, MpAgentEmployeeRelationEntity::getStatus, query.getStatus()));
|
.eq(query.getStatus() != null, MpAgentEmployeeRelationEntity::getStatus, query.getStatus()));
|
||||||
|
|
||||||
if (pageResult.getRecords() == null || pageResult.getRecords().isEmpty()) {
|
if (CollectionUtil.isEmpty(pageResult.getRecords())) {
|
||||||
log.info("查询结果为空");
|
log.info("查询结果为空");
|
||||||
}
|
}
|
||||||
log.info("查询代理商员工数量:{}", pageResult.getTotal());
|
log.info("查询代理商员工数量:{}", pageResult.getTotal());
|
||||||
@ -60,19 +63,24 @@ public class AppAgentEmployeeRelationServiceImpl implements IAppAgentEmployeeRel
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addEmployee(AppAgentEmployeeRelationReq request) {
|
public boolean addEmployee(AppAgentEmployeeRelationReq request) {
|
||||||
// 检查员工是否已经存在于当前代理商下
|
|
||||||
LambdaQueryWrapper<MpAgentEmployeeRelationEntity> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<MpAgentEmployeeRelationEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(MpAgentEmployeeRelationEntity::getAgentId, request.getAgentId())
|
wrapper.eq(MpAgentEmployeeRelationEntity::getAgentId, request.getAgentId())
|
||||||
.eq(MpAgentEmployeeRelationEntity::getEmployeeUserId, request.getEmployeeUserId());
|
.eq(MpAgentEmployeeRelationEntity::getContactPhone, request.getContactPhone());
|
||||||
|
|
||||||
MpAgentEmployeeRelationEntity existing = mpAgentEmployeeRelationService.getOne(wrapper);
|
MpAgentEmployeeRelationEntity existing = mpAgentEmployeeRelationService.getOne(wrapper);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
throw new CommonException(ResultCodeEnum.DATA_REPEAT_ERROR, "该员工已属于当前代理商");
|
throw new CommonException(ResultCodeEnum.DATA_REPEAT_ERROR, "该员工已属于当前代理商");
|
||||||
}
|
}
|
||||||
|
UserInfoDTO userInfoDTO = new UserInfoDTO();
|
||||||
|
userInfoDTO.setUserName(request.getEmployeeName());
|
||||||
|
userInfoDTO.setMobile(request.getContactPhone());
|
||||||
|
userInfoDTO.setPassword(request.getPassword());
|
||||||
|
userInfoDTO.setRoleCode(RoleEnum.AGENT);
|
||||||
|
Integer userId = userInfoServiceApi.addUserInfoAndAssignRole(userInfoDTO);
|
||||||
|
|
||||||
MpAgentEmployeeRelationEntity entity = new MpAgentEmployeeRelationEntity();
|
MpAgentEmployeeRelationEntity entity = new MpAgentEmployeeRelationEntity();
|
||||||
entity.setAgentId(request.getAgentId());
|
entity.setAgentId(request.getAgentId());
|
||||||
entity.setEmployeeUserId(request.getEmployeeUserId());
|
entity.setEmployeeUserId(userId);
|
||||||
entity.setPosition(request.getPosition());
|
entity.setPosition(request.getPosition());
|
||||||
entity.setStatus(request.getStatus());
|
entity.setStatus(request.getStatus());
|
||||||
|
|
||||||
@ -91,10 +99,19 @@ public class AppAgentEmployeeRelationServiceImpl implements IAppAgentEmployeeRel
|
|||||||
throw new CommonException(ResultCodeEnum.PERMISSION_DENIED, "无权限操作此员工");
|
throw new CommonException(ResultCodeEnum.PERMISSION_DENIED, "无权限操作此员工");
|
||||||
}
|
}
|
||||||
|
|
||||||
existing.setEmployeeUserId(request.getEmployeeUserId());
|
UserInfoDTO userInfoDTO = new UserInfoDTO();
|
||||||
existing.setPosition(request.getPosition());
|
userInfoDTO.setUserName(request.getEmployeeName());
|
||||||
existing.setStatus(request.getStatus());
|
userInfoDTO.setMobile(request.getContactPhone());
|
||||||
|
userInfoDTO.setPassword(request.getPassword());
|
||||||
|
boolean updateUserResult = userInfoServiceApi.updateUserInfo(userInfoDTO);
|
||||||
|
log.info("更新员工结果:{}", updateUserResult);
|
||||||
|
|
||||||
|
MpAgentEmployeeRelationEntity updateEntity = new MpAgentEmployeeRelationEntity();
|
||||||
|
updateEntity.setId(request.getId());
|
||||||
|
updateEntity.setPosition(request.getPosition());
|
||||||
|
updateEntity.setStatus(request.getStatus());
|
||||||
|
updateEntity.setEmployeeName(request.getEmployeeName());
|
||||||
|
existing.setContactPhone(request.getContactPhone());
|
||||||
boolean result = mpAgentEmployeeRelationService.updateById(existing);
|
boolean result = mpAgentEmployeeRelationService.updateById(existing);
|
||||||
log.info("更新员工结果:{}", result);
|
log.info("更新员工结果:{}", result);
|
||||||
return result;
|
return result;
|
||||||
@ -102,10 +119,8 @@ public class AppAgentEmployeeRelationServiceImpl implements IAppAgentEmployeeRel
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteEmployee(Integer id) {
|
public boolean deleteEmployee(Integer id) {
|
||||||
// 验证员工是否属于当前代理商
|
|
||||||
MpAgentEmployeeRelationEntity existing = mpAgentEmployeeRelationService.getById(id);
|
MpAgentEmployeeRelationEntity existing = mpAgentEmployeeRelationService.getById(id);
|
||||||
AssertUtils.notNull(existing, ResultCodeEnum.DATA_NOT_EXIST);
|
AssertUtils.notNull(existing, ResultCodeEnum.DATA_NOT_EXIST);
|
||||||
|
|
||||||
boolean result = mpAgentEmployeeRelationService.removeById(id);
|
boolean result = mpAgentEmployeeRelationService.removeById(id);
|
||||||
log.info("删除员工结果:{}", result);
|
log.info("删除员工结果:{}", result);
|
||||||
return result;
|
return result;
|
||||||
@ -130,7 +145,6 @@ public class AppAgentEmployeeRelationServiceImpl implements IAppAgentEmployeeRel
|
|||||||
if (CollectionUtil.isEmpty(entities)) {
|
if (CollectionUtil.isEmpty(entities)) {
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
return entities.stream()
|
return entities.stream()
|
||||||
.map(this::convertToResp)
|
.map(this::convertToResp)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -159,7 +173,7 @@ public class AppAgentEmployeeRelationServiceImpl implements IAppAgentEmployeeRel
|
|||||||
|
|
||||||
// 通过用户服务获取员工的详细信息
|
// 通过用户服务获取员工的详细信息
|
||||||
if (entity.getEmployeeUserId() != null) {
|
if (entity.getEmployeeUserId() != null) {
|
||||||
UserInfoDTO userInfo = userService.getUserInfoById(entity.getEmployeeUserId());
|
UserInfoDTO userInfo = userInfoServiceApi.getByUserId(entity.getEmployeeUserId());
|
||||||
resp.setEmployeeUserInfo(userInfo);
|
resp.setEmployeeUserInfo(userInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,9 @@ public class AppAgentServiceImpl implements IAppAgentService {
|
|||||||
if (agentEntity == null) {
|
if (agentEntity == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return AppAgentConvert.INSTANCE.entityToResp(agentEntity);
|
AppMpAgentResp appMpAgentResp = AppAgentConvert.INSTANCE.entityToResp(agentEntity);
|
||||||
|
appMpAgentResp.setIsContactPerson(agentEntity.getContactUserId().equals(userId));
|
||||||
|
return appMpAgentResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -22,9 +22,10 @@ public interface IMpAgentService extends IService<MpAgentEntity> {
|
|||||||
* 保存代理商
|
* 保存代理商
|
||||||
*
|
*
|
||||||
* @param agentEntity 代理商实体
|
* @param agentEntity 代理商实体
|
||||||
|
* @param password m密码
|
||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
Boolean saveAgent(MpAgentEntity agentEntity);
|
Boolean saveAgent(MpAgentEntity agentEntity,String password);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新代理商
|
* 更新代理商
|
||||||
|
|||||||
@ -1,9 +1,15 @@
|
|||||||
package com.seer.teach.mp.service.impl;
|
package com.seer.teach.mp.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.seer.teach.common.enums.RoleEnum;
|
||||||
|
import com.seer.teach.common.utils.CommonUtils;
|
||||||
import com.seer.teach.mp.entity.MpAgentEntity;
|
import com.seer.teach.mp.entity.MpAgentEntity;
|
||||||
import com.seer.teach.mp.mapper.MpAgentMapper;
|
import com.seer.teach.mp.mapper.MpAgentMapper;
|
||||||
import com.seer.teach.mp.service.IMpAgentService;
|
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.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -11,16 +17,28 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 代理商服务实现类
|
* 代理商服务实现类
|
||||||
*/
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class MpAgentServiceImpl extends ServiceImpl<MpAgentMapper, MpAgentEntity> implements IMpAgentService {
|
public class MpAgentServiceImpl extends ServiceImpl<MpAgentMapper, MpAgentEntity> implements IMpAgentService {
|
||||||
|
|
||||||
|
private final UserInfoServiceApi userInfoServiceApi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MpAgentEntity getAgentById(Integer id) {
|
public MpAgentEntity getAgentById(Integer id) {
|
||||||
return this.getById(id);
|
return this.getById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean saveAgent(MpAgentEntity agentEntity) {
|
public Boolean saveAgent(MpAgentEntity agentEntity,String password) {
|
||||||
|
UserInfoDTO userInfoDTO = new UserInfoDTO();
|
||||||
|
userInfoDTO.setUserName(agentEntity.getAgentName());
|
||||||
|
userInfoDTO.setPassword(password);
|
||||||
|
userInfoDTO.setMobile(agentEntity.getContactPhone());
|
||||||
|
userInfoDTO.setRoleCode(RoleEnum.AGENT);
|
||||||
|
Integer userId = userInfoServiceApi.addUserInfoAndAssignRole(userInfoDTO);
|
||||||
|
log.info("用户id:{}", userId);
|
||||||
|
agentEntity.setContactUserId(userId);
|
||||||
return this.save(agentEntity);
|
return this.save(agentEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import com.seer.teach.user.api.dto.*;
|
|||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
@ -124,6 +125,24 @@ public interface UserInfoServiceApi {
|
|||||||
@PostMapping("/update-user-assign-role")
|
@PostMapping("/update-user-assign-role")
|
||||||
boolean updateUserInfoAndAssignRole(@RequestBody UserInfoDTO userInfoDTO);
|
boolean updateUserInfoAndAssignRole(@RequestBody UserInfoDTO userInfoDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跟新用户信息
|
||||||
|
*
|
||||||
|
* @param userInfoDTO 用户信息
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
@PutMapping("/update")
|
||||||
|
boolean updateUserInfo(@RequestBody UserInfoDTO userInfoDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增用户信息并分配角色
|
||||||
|
*
|
||||||
|
* @param userInfoDTO 用户信息
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
@PostMapping("/update-user-assign-role")
|
||||||
|
Integer addUserInfoAndAssignRole(@RequestBody UserInfoDTO userInfoDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据孩子Id获取家长信息
|
* 根据孩子Id获取家长信息
|
||||||
*
|
*
|
||||||
@ -174,6 +193,4 @@ public interface UserInfoServiceApi {
|
|||||||
@GetMapping("/getUserIdByUserName")
|
@GetMapping("/getUserIdByUserName")
|
||||||
Integer getUserIdByUserName(@RequestParam("userName") String userName);
|
Integer getUserIdByUserName(@RequestParam("userName") String userName);
|
||||||
|
|
||||||
@PostMapping("/save-agentInfo")
|
|
||||||
boolean saveAgentInfo(@RequestBody UserInfoDTO userInfoDTO);
|
|
||||||
}
|
}
|
||||||
@ -2,12 +2,28 @@ package com.seer.teach.user.api;
|
|||||||
|
|
||||||
import com.seer.teach.user.api.dto.UserRelationDTO;
|
import com.seer.teach.user.api.dto.UserRelationDTO;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
@FeignClient(name = ApiConstants.SERVER_NAME, contextId = "userRelationServiceApi", path = "/seer/user/internal")
|
@FeignClient(name = ApiConstants.SERVER_NAME, contextId = "userRelationServiceApi", path = "/seer/user/internal")
|
||||||
public interface UserRelationServiceApi {
|
public interface UserRelationServiceApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存用户关系
|
||||||
|
*
|
||||||
|
* @param userRelationDTO 用户关系信息
|
||||||
|
* @return 保存结果
|
||||||
|
*/
|
||||||
@PostMapping("/save-relation")
|
@PostMapping("/save-relation")
|
||||||
boolean saveUserRelation(@RequestBody UserRelationDTO userRelationDTO);
|
boolean saveUserRelation(@RequestBody UserRelationDTO userRelationDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户关系
|
||||||
|
*
|
||||||
|
* @param userRelationDTO 用户关系信息
|
||||||
|
* @return 删除结果
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
boolean deleteUserRelation(@RequestBody UserRelationDTO userRelationDTO);
|
||||||
}
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.seer.teach.user.api.dto;
|
package com.seer.teach.user.api.dto;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.seer.teach.common.enums.RoleEnum;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@ -62,5 +63,5 @@ public class UserInfoDTO {
|
|||||||
private Integer experience;
|
private Integer experience;
|
||||||
|
|
||||||
@Schema(description = "角色编码")
|
@Schema(description = "角色编码")
|
||||||
private String roleCode;
|
private RoleEnum roleCode;
|
||||||
}
|
}
|
||||||
@ -1,18 +1,23 @@
|
|||||||
package com.seer.teach.user.api.dto;
|
package com.seer.teach.user.api.dto;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "用户关系DTO")
|
||||||
@Data
|
@Data
|
||||||
public class UserRelationDTO {
|
public class UserRelationDTO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户ID
|
* 用户ID
|
||||||
*/
|
*/
|
||||||
|
@NotNull(message = "用户ID不能为空")
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关联的用户ID
|
* 关联的用户ID
|
||||||
*/
|
*/
|
||||||
|
@NotNull(message = "关联的用户ID不能为空")
|
||||||
private Integer relationId;
|
private Integer relationId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import com.seer.teach.common.enums.ResultCodeEnum;
|
|||||||
import com.seer.teach.common.enums.RoleEnum;
|
import com.seer.teach.common.enums.RoleEnum;
|
||||||
import com.seer.teach.common.enums.im.UserInfoTopiTagEnum;
|
import com.seer.teach.common.enums.im.UserInfoTopiTagEnum;
|
||||||
import com.seer.teach.common.enums.iot.IsInfoEnum;
|
import com.seer.teach.common.enums.iot.IsInfoEnum;
|
||||||
|
import com.seer.teach.common.exception.CommonException;
|
||||||
import com.seer.teach.common.utils.AssertUtils;
|
import com.seer.teach.common.utils.AssertUtils;
|
||||||
import com.seer.teach.common.utils.CommonUtils;
|
import com.seer.teach.common.utils.CommonUtils;
|
||||||
import com.seer.teach.iot.api.UserDeviceServiceApi;
|
import com.seer.teach.iot.api.UserDeviceServiceApi;
|
||||||
@ -215,10 +216,29 @@ public class UserInfoServiceApiImpl implements UserInfoServiceApi {
|
|||||||
@Override
|
@Override
|
||||||
public boolean updateUserInfoAndAssignRole(UserInfoDTO userInfoDTO) {
|
public boolean updateUserInfoAndAssignRole(UserInfoDTO userInfoDTO) {
|
||||||
UserEntity UserEntity = UserInfoConvert.INSTANCE.convertOne(userInfoDTO);
|
UserEntity UserEntity = UserInfoConvert.INSTANCE.convertOne(userInfoDTO);
|
||||||
userRoleService.assignUserRoleByRoleCode(UserEntity.getId(), userInfoDTO.getRoleCode());
|
userRoleService.assignUserRoleByRoleCode(UserEntity.getId(), userInfoDTO.getRoleCode().getCode());
|
||||||
return userService.updateById(UserEntity);
|
return userService.updateById(UserEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateUserInfo(UserInfoDTO userInfoDTO) {
|
||||||
|
UserEntity UserEntity = UserInfoConvert.INSTANCE.convertOne(userInfoDTO);
|
||||||
|
return userService.updateById(UserEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer addUserInfoAndAssignRole(UserInfoDTO userInfoDTO) {
|
||||||
|
UserEntity userEntity = UserInfoConvert.INSTANCE.convertOne(userInfoDTO);
|
||||||
|
userEntity.setPassword(CommonUtils.encryptPassword(userInfoDTO.getPassword()));
|
||||||
|
boolean saved = userService.save(userEntity);
|
||||||
|
log.info("保存用户信息:{}", saved);
|
||||||
|
if(saved){
|
||||||
|
userRoleService.assignUserRoleByRoleCode(userEntity.getId(), userInfoDTO.getRoleCode().getCode());
|
||||||
|
return userEntity.getId();
|
||||||
|
}
|
||||||
|
throw new CommonException(ResultCodeEnum.USER_SAVE_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getParentIdByChildrenId(Integer childrenId) {
|
public Integer getParentIdByChildrenId(Integer childrenId) {
|
||||||
return userRelationService.getParentIdByChildrenId(childrenId);
|
return userRelationService.getParentIdByChildrenId(childrenId);
|
||||||
@ -290,18 +310,6 @@ public class UserInfoServiceApiImpl implements UserInfoServiceApi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean saveAgentInfo(UserInfoDTO userInfoDTO) {
|
|
||||||
UserEntity one = userService.getOne(new LambdaQueryWrapper<UserEntity>()
|
|
||||||
.eq(UserEntity::getUserName, userInfoDTO.getUserName()));
|
|
||||||
AssertUtils.isNull(one, ResultCodeEnum.USERNAME_IS_EXIST);
|
|
||||||
UserEntity user = new UserEntity();
|
|
||||||
user.setUserName(userInfoDTO.getUserName());
|
|
||||||
String password = CommonUtils.encryptPassword(userInfoDTO.getPassword());
|
|
||||||
user.setPassword(password);
|
|
||||||
return userService.save(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 推送更新孩子信息的MQ消息
|
* 推送更新孩子信息的MQ消息
|
||||||
*
|
*
|
||||||
|
|||||||
@ -22,4 +22,11 @@ public class UserRelationServiceApiImpl implements UserRelationServiceApi {
|
|||||||
UserRelationEntity userRelation = UserRelationConvert.INSTANCE.convertOne(userRelationDTO);
|
UserRelationEntity userRelation = UserRelationConvert.INSTANCE.convertOne(userRelationDTO);
|
||||||
return userRelationService.save(userRelation);
|
return userRelationService.save(userRelation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteUserRelation(UserRelationDTO userRelationDTO) {
|
||||||
|
log.info("删除用户关系:{}", userRelationDTO);
|
||||||
|
UserRelationEntity userRelation = UserRelationConvert.INSTANCE.convertOne(userRelationDTO);
|
||||||
|
return userRelationService.deleteUserRelation(userRelation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,4 +117,12 @@ public interface IUserRelationService extends IService<UserRelationEntity> {
|
|||||||
* @return 用户关系列表
|
* @return 用户关系列表
|
||||||
*/
|
*/
|
||||||
List<UserRelationEntity> getUserRelationByUserIdAndFamilyId(Integer userId, Integer familyId);
|
List<UserRelationEntity> getUserRelationByUserIdAndFamilyId(Integer userId, Integer familyId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户关系
|
||||||
|
*
|
||||||
|
* @param userRelation 用户关系
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean deleteUserRelation(UserRelationEntity userRelation);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public interface IUserRoleService extends IService<UserRoleEntity> {
|
|||||||
* @param userId 角色编号
|
* @param userId 角色编号
|
||||||
* @param roleIds 角色编号集合
|
* @param roleIds 角色编号集合
|
||||||
*/
|
*/
|
||||||
void assignUserRole(Integer userId, Set<Integer> roleIds);
|
boolean assignUserRole(Integer userId, Set<Integer> roleIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为用户分配角色
|
* 为用户分配角色
|
||||||
@ -48,7 +48,7 @@ public interface IUserRoleService extends IService<UserRoleEntity> {
|
|||||||
* @param userId 角色编号
|
* @param userId 角色编号
|
||||||
* @param roleId 角色编号集合
|
* @param roleId 角色编号集合
|
||||||
*/
|
*/
|
||||||
void assignUserRole(Integer userId, Integer roleId);
|
boolean assignUserRole(Integer userId, Integer roleId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为用户分配角色
|
* 为用户分配角色
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -105,4 +106,12 @@ public class UserRelationServiceImpl extends ServiceImpl<UserRelationMapper, Use
|
|||||||
.eq(UserRelationEntity::getFamilyId, familyId)
|
.eq(UserRelationEntity::getFamilyId, familyId)
|
||||||
.eq(UserRelationEntity::getUserId, userId));
|
.eq(UserRelationEntity::getUserId, userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteUserRelation(UserRelationEntity userRelation) {
|
||||||
|
return super.remove(new LambdaQueryWrapper<>(UserRelationEntity.class)
|
||||||
|
.eq(UserRelationEntity::getUserId, userRelation.getUserId())
|
||||||
|
.eq(UserRelationEntity::getRelationId, userRelation.getRelationId())
|
||||||
|
.eq(Objects.nonNull(userRelation.getType()),UserRelationEntity::getType, userRelation.getType()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,42 +58,38 @@ public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRoleEnt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void assignUserRole(Integer userId, Set<Integer> roleIds) {
|
public boolean assignUserRole(Integer userId, Set<Integer> roleIds) {
|
||||||
List<UserRoleEntity> userRoleList = this.getListByUserId(userId);
|
List<UserRoleEntity> userRoleList = this.getListByUserId(userId);
|
||||||
if(CollectionUtils.isEmpty(userRoleList)){
|
if(CollectionUtils.isEmpty(userRoleList)){
|
||||||
List<UserRoleEntity> userRoles = roleIds.stream().map(roleId -> UserRoleEntity.builder().userId(userId).roleId(roleId.intValue()).build()).collect(Collectors.toList());
|
List<UserRoleEntity> userRoles = roleIds.stream().map(roleId -> UserRoleEntity.builder().userId(userId).roleId(roleId.intValue()).build()).collect(Collectors.toList());
|
||||||
boolean savedBatch = super.saveBatch(userRoles);
|
boolean savedBatch = super.saveBatch(userRoles);
|
||||||
log.info("分配角色[{}] result:{}", userRoles, savedBatch);
|
log.info("分配角色[{}] result:{}", userRoles, savedBatch);
|
||||||
return;
|
return savedBatch;
|
||||||
}
|
}
|
||||||
Set<Integer> roleIdSet = userRoleList.stream().map(UserRoleEntity::getRoleId).collect(Collectors.toSet());
|
Set<Integer> roleIdSet = userRoleList.stream().map(UserRoleEntity::getRoleId).collect(Collectors.toSet());
|
||||||
Collection<Integer> createRoleIds = CollUtil.subtract(roleIds, roleIdSet);
|
Collection<Integer> createRoleIds = CollUtil.subtract(roleIds, roleIdSet);
|
||||||
Collection<Integer> deleteRoleIds = CollUtil.subtract(roleIdSet, roleIds);
|
|
||||||
if (CollUtil.isNotEmpty(createRoleIds)) {
|
if (CollUtil.isNotEmpty(createRoleIds)) {
|
||||||
List<UserRoleEntity> userRoles = createRoleIds.stream().map(roleId -> UserRoleEntity.builder().userId(userId).roleId(roleId.intValue()).build()).collect(Collectors.toList());
|
List<UserRoleEntity> userRoles = createRoleIds.stream().map(roleId -> UserRoleEntity.builder().userId(userId).roleId(roleId.intValue()).build()).collect(Collectors.toList());
|
||||||
boolean savedBatch = super.saveBatch(userRoles);
|
boolean savedBatch = super.saveBatch(userRoles);
|
||||||
log.info("新增角色[{}] result:{}", userRoles, savedBatch);
|
log.info("新增角色[{}] result:{}", userRoles, savedBatch);
|
||||||
|
return savedBatch;
|
||||||
}
|
}
|
||||||
if (CollUtil.isNotEmpty(deleteRoleIds)) {
|
return true;
|
||||||
super.remove(new LambdaQueryWrapper<>(UserRoleEntity.class).eq(UserRoleEntity::getUserId, userId).in(UserRoleEntity::getRoleId, deleteRoleIds));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void assignUserRole(Integer userId, Integer roleId) {
|
public boolean assignUserRole(Integer userId, Integer roleId) {
|
||||||
Set<Integer> roleIds = new HashSet<>();
|
Set<Integer> roleIds = new HashSet<>();
|
||||||
roleIds.add(roleId);
|
roleIds.add(roleId);
|
||||||
assignUserRole(userId, roleIds);
|
return assignUserRole(userId, roleIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean assignUserRoleByRoleCode(Integer userId, String roleCode) {
|
public boolean assignUserRoleByRoleCode(Integer userId, String roleCode) {
|
||||||
Optional<RoleEntity> role = roleService.getRoleByCode(roleCode);
|
Optional<RoleEntity> role = roleService.getRoleByCode(roleCode);
|
||||||
if(!role.isPresent()){
|
if(role.isPresent()){
|
||||||
return false;
|
return assignUserRole(userId, role.get().getId());
|
||||||
}
|
}
|
||||||
assignUserRole(userId, role.get().getId());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user