yms租户同步
This commit is contained in:
@@ -16,7 +16,8 @@ public enum RoleEnum {
|
|||||||
STORE_ADMIN("店铺管理员", "store_admin"),
|
STORE_ADMIN("店铺管理员", "store_admin"),
|
||||||
OWNER_CARGO("货主", "ownerCargo"),
|
OWNER_CARGO("货主", "ownerCargo"),
|
||||||
SUPPLIER("供应商", "supplier"),
|
SUPPLIER("供应商", "supplier"),
|
||||||
CUSTOMER("客户", "customer");
|
CUSTOMER("客户", "customer"),
|
||||||
|
TENANT("租户", "tenant");
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String code;
|
private String code;
|
||||||
|
|||||||
+8
-2
@@ -129,8 +129,14 @@ public class CommonApplicationService {
|
|||||||
* @param userDO
|
* @param userDO
|
||||||
*/
|
*/
|
||||||
public void checkAccountInfo(UserDO userDO) {
|
public void checkAccountInfo(UserDO userDO) {
|
||||||
//获取当前登录用户的最高组织
|
//获取当前登录用户的最高组织,远程Feign调用无loginUser时从userDO取
|
||||||
Long topOrganizationId = SecurityUtils.getLoginUser().getUserPo().getTopOrganizationId();
|
Long topOrganizationId;
|
||||||
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
|
if (ObjectUtil.isNotNull(loginUser)) {
|
||||||
|
topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
|
||||||
|
} else {
|
||||||
|
topOrganizationId = userDO.getTopOrganizationId();
|
||||||
|
}
|
||||||
|
|
||||||
checkUserInfo(topOrganizationId, userDO);
|
checkUserInfo(topOrganizationId, userDO);
|
||||||
}
|
}
|
||||||
|
|||||||
+130
-18
@@ -735,14 +735,20 @@ public class UserApplicationService {
|
|||||||
*/
|
*/
|
||||||
public void addUserInfo(UserDO userDO) {
|
public void addUserInfo(UserDO userDO) {
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
if (ObjectUtil.isNull(loginUser)) {
|
UserPo loginUserPo = null;
|
||||||
throw new DigitalLogisticsException(UserError.USER_NULL);
|
if (ObjectUtil.isNotNull(loginUser)) {
|
||||||
|
loginUserPo = loginUser.getUserPo();
|
||||||
}
|
}
|
||||||
UserPo loginUserPo = loginUser.getUserPo();
|
|
||||||
CheckDO checkDO = userFactory.getCheckDo(userDO);
|
CheckDO checkDO = userFactory.getCheckDo(userDO);
|
||||||
//用户密码传值
|
//用户密码传值
|
||||||
if (StringUtils.isNotEmpty(userDO.getUserPassword())) {
|
if (StringUtils.isNotEmpty(userDO.getUserPassword())) {
|
||||||
String userPassword = AESUtil.decrypt(userDO.getUserPassword());
|
String userPassword;
|
||||||
|
if (ObjectUtil.isNotNull(loginUser)) {
|
||||||
|
userPassword = AESUtil.decrypt(userDO.getUserPassword());
|
||||||
|
} else {
|
||||||
|
// Feign调用传入的是明文密码,无需AES解密
|
||||||
|
userPassword = userDO.getUserPassword();
|
||||||
|
}
|
||||||
checkDO.setUserPassword(userPassword);
|
checkDO.setUserPassword(userPassword);
|
||||||
}
|
}
|
||||||
//用户信息格式校验
|
//用户信息格式校验
|
||||||
@@ -750,9 +756,15 @@ public class UserApplicationService {
|
|||||||
String salt = OConvertUtils.randomGen(8);
|
String salt = OConvertUtils.randomGen(8);
|
||||||
userDO.setUserSalt(salt);
|
userDO.setUserSalt(salt);
|
||||||
regCheck(checkDO);
|
regCheck(checkDO);
|
||||||
//用户密码传值
|
//用户密码加密入库
|
||||||
if (StringUtils.isNotEmpty(userDO.getUserPassword())) {
|
if (StringUtils.isNotEmpty(userDO.getUserPassword())) {
|
||||||
String userPassword = AESUtil.decrypt(userDO.getUserPassword());
|
String userPassword;
|
||||||
|
if (ObjectUtil.isNotNull(loginUser)) {
|
||||||
|
userPassword = AESUtil.decrypt(userDO.getUserPassword());
|
||||||
|
} else {
|
||||||
|
// Feign调用传入的是明文密码,无需AES解密
|
||||||
|
userPassword = userDO.getUserPassword();
|
||||||
|
}
|
||||||
//加密算法,PBEWithMD5AndDES,
|
//加密算法,PBEWithMD5AndDES,
|
||||||
String passwordEncode = PasswordUtil.encrypt(userDO.getUserAccount(), userPassword, salt);
|
String passwordEncode = PasswordUtil.encrypt(userDO.getUserAccount(), userPassword, salt);
|
||||||
userDO.setUserPassword(passwordEncode);
|
userDO.setUserPassword(passwordEncode);
|
||||||
@@ -783,11 +795,13 @@ public class UserApplicationService {
|
|||||||
String idCardDes = DesensitizedUtil.desensitizedIdNumber(idCard);
|
String idCardDes = DesensitizedUtil.desensitizedIdNumber(idCard);
|
||||||
userDO.setUserIdcardNumberDes(idCardDes);
|
userDO.setUserIdcardNumberDes(idCardDes);
|
||||||
}
|
}
|
||||||
userDO.setCreateBy(loginUserPo.getUserId());
|
if (ObjectUtil.isNotNull(loginUserPo)) {
|
||||||
userDO.setCreateByName(loginUserPo.getUserName());
|
userDO.setCreateBy(loginUserPo.getUserId());
|
||||||
if (loginUserPo.getUserAccountType() != null && loginUserPo.getUserAccountType() == 5) {
|
userDO.setCreateByName(loginUserPo.getUserName());
|
||||||
userDO.setCreateBy(loginUserPo.getCreateBy());
|
if (loginUserPo.getUserAccountType() != null && loginUserPo.getUserAccountType() == 5) {
|
||||||
userDO.setCreateByName(loginUserPo.getCreateByName());
|
userDO.setCreateBy(loginUserPo.getCreateBy());
|
||||||
|
userDO.setCreateByName(loginUserPo.getCreateByName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
userDO.setCreateTime(new Date());
|
userDO.setCreateTime(new Date());
|
||||||
//用户状态:0-无状态,1-正常,2-锁定
|
//用户状态:0-无状态,1-正常,2-锁定
|
||||||
@@ -1379,6 +1393,66 @@ public class UserApplicationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 远程Feign调用新增用户(无token),仅操作USER表基本字段
|
||||||
|
* 调用方需传入:organizationId、userAccount、userPassword(明文)、userName
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public UserPo addUserByFeign(UserDO userDO) {
|
||||||
|
// 1. 获取一级组织
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
// 2. 获取组织名称
|
||||||
|
AjaxResult orgInfoResult = productServiceFeign.getInfo(userDO.getOrganizationId());
|
||||||
|
if ("200".equals(orgInfoResult.get("code").toString())) {
|
||||||
|
Object orgData = orgInfoResult.get("data");
|
||||||
|
if (ObjectUtil.isNotNull(orgData)) {
|
||||||
|
OrganizationPo organizationPo = BeanUtil.toBean(orgData, OrganizationPo.class);
|
||||||
|
if (ObjectUtil.isNotNull(organizationPo)) {
|
||||||
|
userDO.setOrganizationName(organizationPo.getOrganizationName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 3. 密码加密(调用方传入明文,无需AES解密)
|
||||||
|
if (StringUtils.isNotEmpty(userDO.getUserPassword())) {
|
||||||
|
String salt = OConvertUtils.randomGen(8);
|
||||||
|
userDO.setUserSalt(salt);
|
||||||
|
String passwordEncode = PasswordUtil.encrypt(userDO.getUserAccount(), userDO.getUserPassword(), salt);
|
||||||
|
userDO.setUserPassword(passwordEncode);
|
||||||
|
}
|
||||||
|
// 4. 根据userId判断新增还是更新
|
||||||
|
if (ObjectUtil.isNotNull(userDO.getUserId())) {
|
||||||
|
// 有userId,更新已有用户
|
||||||
|
UserEntity updateEntity = new UserEntity();
|
||||||
|
BeanUtils.copyProperties(userDO, updateEntity);
|
||||||
|
userMapper.updateById(updateEntity);
|
||||||
|
UserPo userPo = userMapper.selectByUserId(userDO.getUserId());
|
||||||
|
return userPo;
|
||||||
|
} else {
|
||||||
|
// 无userId,新增用户
|
||||||
|
userDO.setCreateTime(new Date());
|
||||||
|
userDO.setUserStatus(1);
|
||||||
|
userDO.setUserAuthStatus(1);
|
||||||
|
userDO.setDelFlag(1);
|
||||||
|
userDO.setRoleCode(RoleEnum.MUST.getCode());
|
||||||
|
userDO.setRoleName(RoleEnum.MUST.getName());
|
||||||
|
if (ObjectUtil.isNull(userDO.getUserAccount()) && ObjectUtil.isNotNull(userDO.getUserPhone())) {
|
||||||
|
userDO.setUserAccount(userDO.getUserPhone());
|
||||||
|
}
|
||||||
|
UserEntity userEntity = userDomainService.addUser(userDO);
|
||||||
|
UserPo userPo = new UserPo();
|
||||||
|
BeanUtils.copyProperties(userEntity, userPo);
|
||||||
|
return userPo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description 新增用户
|
* @Description 新增用户
|
||||||
* @Author Alex
|
* @Author Alex
|
||||||
@@ -1388,18 +1462,31 @@ public class UserApplicationService {
|
|||||||
public UserPo addUserYG(UserDO userDO) {
|
public UserPo addUserYG(UserDO userDO) {
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
String password = userDO.getPlainPassword();
|
String password = userDO.getPlainPassword();
|
||||||
if (ObjectUtil.isNull(loginUser)) {
|
// 远程Feign调用时可能无loginUser,优先从loginUser取组织信息,否则使用userDO自身携带的数据
|
||||||
throw new DigitalLogisticsException(UserError.TIMEOUT);
|
if (ObjectUtil.isNotNull(loginUser)) {
|
||||||
|
userDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
|
||||||
|
} else if (ObjectUtil.isNotNull(userDO.getOrganizationId()) && ObjectUtil.isNull(userDO.getTopOrganizationId())) {
|
||||||
|
// 无loginUser时,提前获取一级组织ID,供后续checkAccountInfo使用
|
||||||
|
AjaxResult topOrgResult = productServiceFeign.getTopOrganization(userDO.getOrganizationId());
|
||||||
|
if ("200".equals(topOrgResult.get("code").toString())) {
|
||||||
|
String topOrgData = topOrgResult.get("data").toString();
|
||||||
|
if (ObjectUtil.isNotNull(topOrgData)) {
|
||||||
|
userDO.setTopOrganizationId(Long.parseLong(topOrgData));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
userDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
|
|
||||||
//2023年3月24日 bug修改 增加登录账号/手机号唯一性校验
|
//2023年3月24日 bug修改 增加登录账号/手机号唯一性校验
|
||||||
commonApplicationService.checkAccountInfo(userDO);
|
commonApplicationService.checkAccountInfo(userDO);
|
||||||
if (ObjectUtil.isNotNull(userDO.getUserId())) {
|
if (ObjectUtil.isNotNull(userDO.getUserId())) {
|
||||||
return updateUser(userDO);
|
return updateUser(userDO);
|
||||||
} else {
|
} else {
|
||||||
if (ObjectUtil.isNull(userDO.getOrganizationId())) {
|
if (ObjectUtil.isNull(userDO.getOrganizationId())) {
|
||||||
userDO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
|
if (ObjectUtil.isNotNull(loginUser)) {
|
||||||
userDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
|
userDO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
|
||||||
|
userDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
|
||||||
|
} else {
|
||||||
|
throw new DigitalLogisticsException(UserError.TIMEOUT);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 如果前端传递了 organizationId,根据 organizationId 查询组织信息,获取正确的组织名称
|
// 如果前端传递了 organizationId,根据 organizationId 查询组织信息,获取正确的组织名称
|
||||||
AjaxResult orgInfoResult = productServiceFeign.getInfo(userDO.getOrganizationId());
|
AjaxResult orgInfoResult = productServiceFeign.getInfo(userDO.getOrganizationId());
|
||||||
@@ -1441,7 +1528,14 @@ public class UserApplicationService {
|
|||||||
|
|
||||||
//组装新增用户信息
|
//组装新增用户信息
|
||||||
addUserInfo(userDO);
|
addUserInfo(userDO);
|
||||||
|
// 远程Feign调用无loginUser时,强制分配默认普通角色,不走管理员
|
||||||
|
if (ObjectUtil.isNull(loginUser)) {
|
||||||
|
userDO.setRoleCode(RoleEnum.TENANT.getCode());
|
||||||
|
userDO.setRoleName(RoleEnum.TENANT.getName());
|
||||||
|
userDO.setUserAccountType(null);
|
||||||
|
}
|
||||||
UserEntity userEntity = userDomainService.addUser(userDO);
|
UserEntity userEntity = userDomainService.addUser(userDO);
|
||||||
|
if (ObjectUtil.isNotNull(loginUser)) {
|
||||||
if (isCustomerManagementPresetRole(userEntity.getRoleCode())) {
|
if (isCustomerManagementPresetRole(userEntity.getRoleCode())) {
|
||||||
// 保持插入结果,不再改 role_code / user_role
|
// 保持插入结果,不再改 role_code / user_role
|
||||||
} else if ((StringUtils.isEmpty(userEntity.getRoleCode()) || !RoleEnum.PLAT_ADMIN.getCode().equals(userEntity.getRoleCode())) &&
|
} else if ((StringUtils.isEmpty(userEntity.getRoleCode()) || !RoleEnum.PLAT_ADMIN.getCode().equals(userEntity.getRoleCode())) &&
|
||||||
@@ -1480,6 +1574,22 @@ public class UserApplicationService {
|
|||||||
userDomainService.updateUser(userDO);
|
userDomainService.updateUser(userDO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} // end of loginUser != null check
|
||||||
|
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.setUserId(userEntity.getUserId());
|
||||||
|
userDomainService.updateUser(userDO);
|
||||||
|
}
|
||||||
|
}
|
||||||
BeanUtils.copyProperties(userEntity, userPo);
|
BeanUtils.copyProperties(userEntity, userPo);
|
||||||
//同步网货平台员工信息
|
//同步网货平台员工信息
|
||||||
try {
|
try {
|
||||||
@@ -1492,13 +1602,15 @@ public class UserApplicationService {
|
|||||||
// throw e;
|
// throw e;
|
||||||
}
|
}
|
||||||
//获取组织信息
|
//获取组织信息
|
||||||
Long organizationId = loginUser.getUserPo().getOrganizationId();
|
Long organizationId = ObjectUtil.isNotNull(loginUser) ? loginUser.getUserPo().getOrganizationId() : userDO.getOrganizationId();
|
||||||
Integer isQueue = userMapper.getOrdIsQueue(organizationId);
|
Integer isQueue = userMapper.getOrdIsQueue(organizationId);
|
||||||
|
|
||||||
if (isQueue==1) {
|
if (isQueue==1) {
|
||||||
//同步YMS员工信息
|
//同步YMS员工信息
|
||||||
try {
|
try {
|
||||||
userEntity.setUserPassword(password);
|
if (StringUtils.isNotEmpty(password)) {
|
||||||
|
userEntity.setUserPassword(password);
|
||||||
|
}
|
||||||
ymsDomainService.addOrEditYmsUser(userEntity);
|
ymsDomainService.addOrEditYmsUser(userEntity);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 同步YMS失败时,记录日志但不影响用户保存
|
// 同步YMS失败时,记录日志但不影响用户保存
|
||||||
|
|||||||
+5
-5
@@ -22,12 +22,12 @@ public class UserRoleFactory {
|
|||||||
UserRoleEntity userRoleEntity = new UserRoleEntity();
|
UserRoleEntity userRoleEntity = new UserRoleEntity();
|
||||||
BeanUtils.copyProperties(userRoleDo,userRoleEntity, IgnoreNullUtil.getNullPropertyNames(userRoleDo));
|
BeanUtils.copyProperties(userRoleDo,userRoleEntity, IgnoreNullUtil.getNullPropertyNames(userRoleDo));
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
if (ObjectUtil.isNull(loginUser)) {
|
String userName = null;
|
||||||
throw new DigitalLogisticsException(UserError.TIMEOUT);
|
Long userId = null;
|
||||||
|
if (ObjectUtil.isNotNull(loginUser)) {
|
||||||
|
userName = loginUser.getUsername();
|
||||||
|
userId = loginUser.getUserid();
|
||||||
}
|
}
|
||||||
String userName = loginUser.getUsername();
|
|
||||||
// 获取登录人id
|
|
||||||
Long userId = loginUser.getUserid();
|
|
||||||
if(userRoleDo.getUserRoleId() != null){
|
if(userRoleDo.getUserRoleId() != null){
|
||||||
if(userId != null){
|
if(userId != null){
|
||||||
userRoleEntity.setUpdateBy(userId);
|
userRoleEntity.setUpdateBy(userId);
|
||||||
|
|||||||
+6
-2
@@ -12,6 +12,7 @@ import com.mhd.user.domain.userAggregate.repository.todo.UserDO;
|
|||||||
import com.mhd.common.core.domain.po.app.UserAppPo;
|
import com.mhd.common.core.domain.po.app.UserAppPo;
|
||||||
import com.mhd.common.core.annotation.fieldsetvalue.NeedSetValueMethod;
|
import com.mhd.common.core.annotation.fieldsetvalue.NeedSetValueMethod;
|
||||||
import com.mhd.common.security.utils.SecurityUtils;
|
import com.mhd.common.security.utils.SecurityUtils;
|
||||||
|
import com.mhd.system.api.model.LoginUser;
|
||||||
import com.mhd.user.infrastructure.util.annotation.DataPermissions;
|
import com.mhd.user.infrastructure.util.annotation.DataPermissions;
|
||||||
import com.mhd.user.interfaces.dto.queryDTO.UserDocumentWarningQueryDTO;
|
import com.mhd.user.interfaces.dto.queryDTO.UserDocumentWarningQueryDTO;
|
||||||
import com.mhd.user.interfaces.dto.updateDTO.UpdateHasDefaultAddressDTO;
|
import com.mhd.user.interfaces.dto.updateDTO.UpdateHasDefaultAddressDTO;
|
||||||
@@ -50,9 +51,12 @@ public class UserDomainService {
|
|||||||
*/
|
*/
|
||||||
public UserEntity updateUser(UserDO userDO) {
|
public UserEntity updateUser(UserDO userDO) {
|
||||||
UserEntity userEntity = userFactory.getUserEntity(userDO);
|
UserEntity userEntity = userFactory.getUserEntity(userDO);
|
||||||
userEntity.setUpdateBy(SecurityUtils.getLoginUser().getUserid());
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
|
if (ObjectUtil.isNotNull(loginUser)) {
|
||||||
|
userEntity.setUpdateBy(loginUser.getUserid());
|
||||||
|
userEntity.setUpdateByName(loginUser.getUsername());
|
||||||
|
}
|
||||||
userEntity.setUpdateTime(new Date());
|
userEntity.setUpdateTime(new Date());
|
||||||
userEntity.setUpdateByName(SecurityUtils.getLoginUser().getUsername());
|
|
||||||
userRepositoryInterface.updateUser(userEntity);
|
userRepositoryInterface.updateUser(userEntity);
|
||||||
return userEntity;
|
return userEntity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -283,6 +283,22 @@ public class UserAPI extends BaseController {
|
|||||||
return R.ok(sysUserVo, "操作成功");
|
return R.ok(sysUserVo, "操作成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 远程Feign调用新增用户(无token),仅操作USER表基本字段
|
||||||
|
*/
|
||||||
|
@ApiOperation("远程Feign修改用户(无token)")
|
||||||
|
@PostMapping("/addUserByFeign")
|
||||||
|
public R<LoginUser> addUserByFeign(@RequestBody UserDTO userDTO) {
|
||||||
|
LoginUser sysUserVo = new LoginUser();
|
||||||
|
UserDO userDO = userAssember.toUserDO(userDTO);
|
||||||
|
UserPo userPo = userApplicationService.addUserByFeign(userDO);
|
||||||
|
if (ObjectUtil.isNotNull(userPo)) {
|
||||||
|
sysUserVo.setUserid(userPo.getUserId());
|
||||||
|
}
|
||||||
|
sysUserVo.setUserPo(userPo);
|
||||||
|
return R.ok(sysUserVo, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description 新增合作商
|
* @Description 新增合作商
|
||||||
* @Author Alex
|
* @Author Alex
|
||||||
|
|||||||
Reference in New Issue
Block a user