新增委托方和员工修改;
This commit is contained in:
+113
@@ -1370,6 +1370,119 @@ public class UserApplicationService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 新增用户
|
||||
* @Author Alex
|
||||
* @Date 2022/12/2 13:46
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public UserPo addUserYG(UserDO userDO) {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (ObjectUtil.isNull(loginUser)) {
|
||||
throw new DigitalLogisticsException(UserError.TIMEOUT);
|
||||
}
|
||||
userDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
|
||||
//2023年3月24日 bug修改 增加登录账号/手机号唯一性校验
|
||||
commonApplicationService.checkAccountInfo(userDO);
|
||||
if (ObjectUtil.isNotNull(userDO.getUserId())) {
|
||||
return updateUser(userDO);
|
||||
} else {
|
||||
if (ObjectUtil.isNull(userDO.getOrganizationId())) {
|
||||
userDO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
|
||||
userDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
|
||||
} else {
|
||||
// 如果前端传递了 organizationId,根据 organizationId 查询组织信息,获取正确的组织名称
|
||||
AjaxResult orgInfoResult = productServiceFeign.getInfo(userDO.getOrganizationId());
|
||||
String orgInfoCode = orgInfoResult.get("code").toString();
|
||||
if ("200".equals(orgInfoCode)) {
|
||||
Object orgData = orgInfoResult.get("data");
|
||||
if (ObjectUtil.isNotNull(orgData)) {
|
||||
OrganizationPo organizationPo = BeanUtil.toBean(orgData, OrganizationPo.class);
|
||||
if (ObjectUtil.isNotNull(organizationPo)) {
|
||||
userDO.setOrganizationName(organizationPo.getOrganizationName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
UserPo userPo = new UserPo();
|
||||
//先根据组织ID获取一级组织
|
||||
AjaxResult organizationInfo = productServiceFeign.getTopOrganization(userDO.getOrganizationId());
|
||||
String code = organizationInfo.get("code").toString();
|
||||
if (!"200".equals(code)) {
|
||||
//组织异常提示
|
||||
throw new DigitalLogisticsException(UserError.USER_ACCOUNT_REG_ERROR);
|
||||
}
|
||||
String data = organizationInfo.get("data").toString();
|
||||
if (ObjectUtil.isNotNull(data)) {
|
||||
userDO.setTopOrganizationId(Long.parseLong(data));
|
||||
}
|
||||
if (ObjectUtil.isNotNull(userDO.getUserAreaCountyId())) {
|
||||
SysProvinceCityCountyDTO sysProvinceCityCountyDTO = new SysProvinceCityCountyDTO();
|
||||
sysProvinceCityCountyDTO.setCountyCode(userDO.getUserAreaCountyId());
|
||||
AjaxResult sysAreaPOInfo = systemServiceFeign.findAreaInfo(sysProvinceCityCountyDTO);
|
||||
Object sysAreaPOData = sysAreaPOInfo.get("data");
|
||||
if (ObjectUtil.isNotNull(sysAreaPOData)) {
|
||||
SysAreaPO sysAreaPO = (SysAreaPO) JSONObject.toBean(JSONObject.fromObject(sysAreaPOData), SysAreaPO.class);
|
||||
if (ObjectUtil.isNotNull(sysAreaPO)) {
|
||||
userDO.setUserAreaName(sysAreaPO.getProvinceCityCountyName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//组装新增用户信息
|
||||
addUserInfo(userDO);
|
||||
UserEntity userEntity = userDomainService.addUser(userDO);
|
||||
if ((StringUtils.isEmpty(userEntity.getRoleCode()) || !RoleEnum.PLAT_ADMIN.getCode().equals(userEntity.getRoleCode())) &&
|
||||
(userDO.getUserAccountType() == null || userDO.getUserAccountType() < 4)) {
|
||||
//给用户分配默认普通角色权限
|
||||
RoleDo roleDo = new RoleDo();
|
||||
roleDo.setRoleCode(RoleEnum.OWNER_CARGO.getCode());
|
||||
roleDo.setOrganizationId(userEntity.getOrganizationId());
|
||||
RoleEntity roleEntity = roleDomainService.selectByOrganizationIdAndRoleCode(roleDo);
|
||||
if (roleEntity != null) {
|
||||
UserRoleDo userRoleDo = new UserRoleDo();
|
||||
userRoleDo.setUserId(userEntity.getUserId());
|
||||
userRoleDo.setRoleId(roleEntity.getRoleId());
|
||||
userDO.setRoleId(roleEntity.getRoleId());
|
||||
userRoleDomainService.addUserRole(userRoleDo);
|
||||
}
|
||||
userDO.setRoleCode(RoleEnum.OWNER_CARGO.getCode());
|
||||
userDO.setRoleName(RoleEnum.OWNER_CARGO.getName());
|
||||
userDO.setUserId(userEntity.getUserId());
|
||||
userDomainService.updateUser(userDO);
|
||||
}else{
|
||||
RoleDo roleDo = new RoleDo();
|
||||
roleDo.setRoleCode(userEntity.getRoleCode());
|
||||
roleDo.setOrganizationId(userEntity.getOrganizationId());
|
||||
RoleEntity roleEntity = roleDomainService.selectByOrganizationIdAndRoleCode(roleDo);
|
||||
if (roleEntity != null) {
|
||||
UserRoleDo userRoleDo = new UserRoleDo();
|
||||
userRoleDo.setUserId(userEntity.getUserId());
|
||||
userRoleDo.setRoleId(roleEntity.getRoleId());
|
||||
userRoleDomainService.addUserRole(userRoleDo);
|
||||
|
||||
userDO.setRoleId(roleEntity.getRoleId());
|
||||
userDO.setRoleCode(roleEntity.getRoleCode());
|
||||
userDO.setRoleName(roleEntity.getRoleName());
|
||||
userDO.setUserId(userEntity.getUserId());
|
||||
userDomainService.updateUser(userDO);
|
||||
}
|
||||
}
|
||||
BeanUtils.copyProperties(userEntity, userPo);
|
||||
//同步网货平台员工信息
|
||||
try {
|
||||
wlhyDomainService.addOrEditPlatformUser(userEntity);
|
||||
} catch (Exception e) {
|
||||
// 同步网货失败时,记录日志但不影响用户保存
|
||||
// 避免同步失败导致整个事务回滚,用户数据无法保存
|
||||
log.warn("同步网货平台员工信息失败,但不影响用户保存: {}", e.getMessage());
|
||||
// 如果业务要求必须同步成功,可以取消下面的注释,让异常抛出
|
||||
// throw e;
|
||||
}
|
||||
return userPo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public UserPo addDriverUser(UserDO userDO) {
|
||||
|
||||
Reference in New Issue
Block a user