|
|
@@ -15,6 +15,7 @@ import com.zhongshu.card.client.model.base.AuthTypeParam;
|
|
|
import com.zhongshu.card.client.model.base.UserIdModel;
|
|
|
import com.zhongshu.card.client.model.org.*;
|
|
|
import com.zhongshu.card.client.model.org.role.RoleModel;
|
|
|
+import com.zhongshu.card.client.model.orgModel.OrgBindUserAllParam;
|
|
|
import com.zhongshu.card.client.model.school.DictInfoSimpleModel;
|
|
|
import com.zhongshu.card.client.service.org.OrganizationService;
|
|
|
import com.zhongshu.card.client.service.org.UserAccountService;
|
|
|
@@ -26,6 +27,7 @@ import com.zhongshu.card.server.core.dataConfig.CardSystemDefault;
|
|
|
import com.zhongshu.card.server.core.domain.org.*;
|
|
|
import com.zhongshu.card.server.core.domain.school.DictInfo;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.card.server.core.service.org.OrganizationUserServiceImpl;
|
|
|
import com.zhongshu.card.server.core.service.school.DictInfoServiceImpl;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
@@ -94,8 +96,11 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
@Autowired
|
|
|
DictInfoServiceImpl dictInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ OrganizationUserServiceImpl organizationUserServiceImpl;
|
|
|
+
|
|
|
/**
|
|
|
- * 添加编辑用户 添加机构用户
|
|
|
+ * 添加编辑用户 添加机构用户 (包括角色 部门 职位等信息)
|
|
|
*
|
|
|
* @param param
|
|
|
* @return
|
|
|
@@ -103,9 +108,6 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
@Override
|
|
|
public ResultContent<OrganizationUser> update(UserCountAddParam param) {
|
|
|
String oid = param.getOid();
|
|
|
- if (StringUtils.isEmpty(oid)) {
|
|
|
- oid = getCurrentOid();
|
|
|
- }
|
|
|
Assert.hasText(oid, "oid不能为空");
|
|
|
Assert.hasText(param.getName(), "name不能为空");
|
|
|
if (param.getState() == null) {
|
|
|
@@ -117,153 +119,66 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
if (ObjectUtils.isEmpty(organization)) {
|
|
|
return ResultContent.buildFail(String.format("oid不存在:%s", oid));
|
|
|
}
|
|
|
- List<Role> roles = new ArrayList<>();
|
|
|
- Department department = null;
|
|
|
- if (ObjectUtils.isNotEmpty(param.getRoleIds())) {
|
|
|
- roles = roleDao.findByOidAndIdIn(oid, param.getRoleIds());
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotEmpty(param.getDepartmentId())) {
|
|
|
- department = departmentDao.findTopById(param.getDepartmentId());
|
|
|
- }
|
|
|
-
|
|
|
- UserAccount temp = null;
|
|
|
- String userId = "";
|
|
|
- // 这的ID是 用户和机构关系数据ID
|
|
|
- if (StringUtils.isEmpty(param.getId())) {
|
|
|
- Assert.hasText(param.getPhone(), "phone不能为空");
|
|
|
-
|
|
|
- String loginName = param.getPhone();
|
|
|
- // 添加
|
|
|
- // 判断用户是否存在
|
|
|
- temp = userCountDao.findTopByLoginName(loginName);
|
|
|
- if (ObjectUtils.isEmpty(temp)) {
|
|
|
- String password = param.getPassWord();
|
|
|
- // 验证密码
|
|
|
- ValidateResult validateResult = ValidateUtils.validatePassWord(password);
|
|
|
- if (!validateResult.isSuccess()) {
|
|
|
- return ResultContent.buildFail(validateResult.getMsg());
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(password)) {
|
|
|
- password = CardSystemDefault.DEFAULT_PASSWORD;
|
|
|
- }
|
|
|
-
|
|
|
- //权限中心:添加用户
|
|
|
- com.github.microservice.auth.client.content.ResultContent<String> addModelResult = userService.add(UserAuthModel.builder().loginType(LoginType.Phone).loginValue(loginName).passWord(password).build());
|
|
|
- if (addModelResult.getState() != ResultState.Success) {
|
|
|
- return ResultContent.buildFail(String.format("权限中心添加用户出错:%s", addModelResult.getMsg()));
|
|
|
- }
|
|
|
- temp = new UserAccount();
|
|
|
- BeanUtils.copyProperties(param, temp);
|
|
|
-
|
|
|
- userId = addModelResult.getContent();
|
|
|
- temp.setUserId(userId);
|
|
|
- temp.setUserType(UserType.Consumer);
|
|
|
- temp.setLoginType(UserLoginType.All);
|
|
|
- temp.setOid(null);
|
|
|
- temp.setLoginName(loginName);
|
|
|
- temp.setIsLogined(Boolean.FALSE);
|
|
|
- temp.setSpellCode(CommonUtil.getPinyin(param.getName()));
|
|
|
- temp.setIsUpdatedPsw(Boolean.FALSE);
|
|
|
- userCountDao.save(temp);
|
|
|
- } else {
|
|
|
- // 编辑用户
|
|
|
- BeanUtils.copyProperties(param, temp, "id", "loginName", "userId", "userType", "loginType");
|
|
|
- temp.setSpellCode(CommonUtil.getPinyin(param.getName()));
|
|
|
- userCountDao.save(temp);
|
|
|
- }
|
|
|
- } else {
|
|
|
- OrganizationUser organizationUser = organizationUserDao.findTopById(param.getId());
|
|
|
- if (ObjectUtils.isEmpty(organizationUser)) {
|
|
|
- return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
- }
|
|
|
- temp = organizationUser.getUser();
|
|
|
- if (StringUtils.isEmpty(param.getPhone())) {
|
|
|
- param.setPhone(temp.getPhone());
|
|
|
- }
|
|
|
- // 用户信息
|
|
|
- BeanUtils.copyProperties(param, temp, "id", "userId", "userType", "loginType");
|
|
|
- temp.setSpellCode(CommonUtil.getPinyin(param.getName()));
|
|
|
- userCountDao.save(temp);
|
|
|
- }
|
|
|
-
|
|
|
- userId = temp.getUserId();
|
|
|
- //权限中心: 在角色组添加用户
|
|
|
- String[] roleGroupIds = roles.stream().map(it -> it.getRoleGroupId()).collect(Collectors.toList()).toArray(String[]::new);
|
|
|
- roleService.addUsersToRoleGroup(userId, roleGroupIds);
|
|
|
-
|
|
|
- OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, temp);
|
|
|
- if (ObjectUtils.isEmpty(organizationUser)) {
|
|
|
- // 不在机构中
|
|
|
- organizationUser = new OrganizationUser();
|
|
|
- initEntity(organizationUser);
|
|
|
- organizationUser.setOid(organization.getOid());
|
|
|
- organizationUser.setOrganization(organization);
|
|
|
- organizationUser.setUser(temp);
|
|
|
- organizationUser.setUserId(temp.getUserId());
|
|
|
- organizationUser.setIsAdmin(Boolean.FALSE);
|
|
|
- organizationUser.setAuthType(organization.getAuthType());
|
|
|
- organizationUser.setCreateUserId(getCurrentUserId());
|
|
|
- // 在机构中的用户类型
|
|
|
- organizationUser.setUserType(OrganizationUserType.Consumer);
|
|
|
- } else {
|
|
|
- //权限中心: 删除以前的,这不存在的角色组
|
|
|
- List<Role> oldRoles = organizationUser.getRoles();
|
|
|
- if (ObjectUtils.isNotEmpty(oldRoles)) {
|
|
|
- List<String> ids = roles.stream().map(it -> it.getRoleGroupId()).collect(Collectors.toList());
|
|
|
- String[] userIds = new String[]{userId};
|
|
|
- for (Role oldRole : oldRoles) {
|
|
|
- if (!ids.contains(oldRole.getRoleGroupId())) {
|
|
|
- roleService.removeUserFromRoleGroup(oldRole.getRoleGroupId(), userIds);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- BeanUtils.copyProperties(param, organizationUser, "id", "oid");
|
|
|
- // 职位信息
|
|
|
- DictInfo position = null;
|
|
|
- if (StringUtils.isNotEmpty(param.getPositionId())) {
|
|
|
- position = dictInfoDao.findTopById(param.getPositionId());
|
|
|
+ // 用户基本信息维护
|
|
|
+ RegisterUserAccountParam userAccountParam = new RegisterUserAccountParam();
|
|
|
+ userAccountParam.setLoginName(param.getPhone());
|
|
|
+ userAccountParam.setPassword(param.getPassWord());
|
|
|
+ userAccountParam.setPhone(param.getPhone());
|
|
|
+ userAccountParam.setName(param.getName());
|
|
|
+ userAccountParam.setCardNumber(param.getCardNumber());
|
|
|
+ userAccountParam.setSex(param.getSex());
|
|
|
+ ResultContent<String> userAccountContent = registerUserAccount(userAccountParam);
|
|
|
+ if (userAccountContent.isFailed()) {
|
|
|
+ return ResultContent.buildFail(userAccountContent.getMsg());
|
|
|
}
|
|
|
- organizationUser.setPosition(position);
|
|
|
+ String userId = userAccountContent.getContent();
|
|
|
+ UserAccount userAccount = userCountDao.findTopByUserId(userId);
|
|
|
|
|
|
- organizationUser.setAuthType(organization.getAuthType());
|
|
|
- // 设置角色
|
|
|
- organizationUser.setRoles(roles);
|
|
|
- // 设置部门
|
|
|
- organizationUser.setDepartment(department);
|
|
|
- organizationUserDao.save(organizationUser);
|
|
|
+ OrgBindUserAllParam orgBindUserAllParam = new OrgBindUserAllParam();
|
|
|
+ orgBindUserAllParam.setUserId(userAccount.getUserId());
|
|
|
+ orgBindUserAllParam.setOrgOid(organization.getOid());
|
|
|
+ orgBindUserAllParam.setCode(param.getCode());
|
|
|
+ orgBindUserAllParam.setPositionId(param.getPositionId());
|
|
|
+ orgBindUserAllParam.setDepartmentId(param.getDepartmentId());
|
|
|
+ orgBindUserAllParam.setRoleIds(param.getRoleIds());
|
|
|
+ orgBindUserAllParam.setState(param.getState());
|
|
|
+ orgBindUserAllParam.setIsAdmin(param.getIsAdmin());
|
|
|
|
|
|
- // 权限中心 绑定用户
|
|
|
- com.github.microservice.auth.client.content.ResultContent<Void> resultContent = organizationUserService.update(organization.getOid(), new String[]{userId});
|
|
|
- if (resultContent.getState() == ResultState.Success) {
|
|
|
- log.info("权限中心:绑定机构和用户关系成功");
|
|
|
- } else {
|
|
|
- log.error("权限中心:绑定机构和用户关系出错:{}", resultContent.getMsg());
|
|
|
+ ResultContent<OrganizationUser> bindUserContent = organizationUserServiceImpl.orgBindUser(orgBindUserAllParam);
|
|
|
+ if (bindUserContent.isFailed()) {
|
|
|
+ return ResultContent.buildFail(bindUserContent.getMsg());
|
|
|
}
|
|
|
+ OrganizationUser organizationUser = bindUserContent.getContent();
|
|
|
|
|
|
return ResultContent.buildSuccess(organizationUser);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * 注册基本用户
|
|
|
+ * 注册基本用户 (没有就注册,有就修改)
|
|
|
*
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public ResultContent<String> registerUserAccount(RegisterUserAccountParam param) {
|
|
|
+ if (StringUtils.isEmpty(param.getLoginName())) {
|
|
|
+ return ResultContent.buildFail(String.format("loginName不能为空"));
|
|
|
+ }
|
|
|
// 电话号码为登录名
|
|
|
- String loginName = param.getPhone();
|
|
|
+ String loginName = param.getLoginName();
|
|
|
UserAccount userAccount = userCountDao.findTopByLoginName(loginName);
|
|
|
if (ObjectUtils.isEmpty(userAccount)) {
|
|
|
String cardNumber = param.getCardNumber();
|
|
|
- String passWord = CardSystemDefault.DEFAULT_PASSWORD;
|
|
|
+ String passWord = param.getPassword();
|
|
|
+ if (StringUtils.isEmpty(passWord)) {
|
|
|
+ passWord = CardSystemDefault.DEFAULT_PASSWORD;
|
|
|
+ }
|
|
|
if (ValidateUtils.isIDCard(cardNumber)) {
|
|
|
passWord = cardNumber.substring(12, 18);
|
|
|
passWord = passWord.toLowerCase().replace("x", "0");
|
|
|
}
|
|
|
+
|
|
|
String userId = "";
|
|
|
// 检查权限中心有这用户不
|
|
|
com.github.microservice.auth.client.content.ResultContent<UserModel> queryContent = userService.queryFromLoginType(LoginType.Phone, loginName);
|
|
|
@@ -275,17 +190,18 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(userId)) {
|
|
|
- //权限中心:添加用户
|
|
|
- com.github.microservice.auth.client.content.ResultContent<String> addModelResult = userService.add(
|
|
|
- UserAuthModel.builder().loginType(LoginType.Phone).loginValue(loginName).passWord(passWord).build());
|
|
|
+ // 权限中心:添加用户
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<String> addModelResult = userService.add(UserAuthModel.builder().loginType(LoginType.Phone).loginValue(loginName).passWord(passWord).build());
|
|
|
if (addModelResult.getState() != ResultState.Success) {
|
|
|
return ResultContent.buildFail(String.format("权限中心添加用户出错:%s", addModelResult.getMsg()));
|
|
|
}
|
|
|
userId = addModelResult.getContent();
|
|
|
}
|
|
|
|
|
|
+ // 本地用户
|
|
|
userAccount = new UserAccount();
|
|
|
BeanUtils.copyProperties(param, userAccount);
|
|
|
+
|
|
|
String realName = param.getRealName();
|
|
|
if (StringUtils.isEmpty(realName)) {
|
|
|
realName = param.getName();
|
|
|
@@ -293,11 +209,13 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
userAccount.setRealName(realName);
|
|
|
userAccount.setUserId(userId);
|
|
|
userAccount.setLoginType(UserLoginType.All);
|
|
|
+
|
|
|
userAccount.setOid(null);
|
|
|
userAccount.setLoginName(loginName);
|
|
|
userAccount.setIsLogined(Boolean.FALSE);
|
|
|
userAccount.setSpellCode(CommonUtil.getPinyin(param.getName()));
|
|
|
userAccount.setIsUpdatedPsw(Boolean.FALSE);
|
|
|
+ userAccount.setUserType(UserType.Consumer);
|
|
|
userCountDao.save(userAccount);
|
|
|
} else {
|
|
|
// 编辑
|
|
|
@@ -412,7 +330,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
}
|
|
|
Assert.hasText(oid, "oid不能为空");
|
|
|
Assert.hasText(userId, "userId不能为空");
|
|
|
-
|
|
|
+ // 价差用户数据
|
|
|
Organization organization = organizationDao.findTopByOid(oid);
|
|
|
if (ObjectUtils.isEmpty(organization)) {
|
|
|
return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, oid));
|
|
|
@@ -421,6 +339,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
if (ObjectUtils.isEmpty(temp)) {
|
|
|
return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, userId));
|
|
|
}
|
|
|
+
|
|
|
OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, temp);
|
|
|
if (ObjectUtils.isNotEmpty(organizationUser)) {
|
|
|
organizationUser.setState(param.getUserState());
|
|
|
@@ -514,8 +433,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
if (ObjectUtils.isEmpty(userCount)) {
|
|
|
return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getUserId()));
|
|
|
}
|
|
|
- com.github.microservice.auth.client.content.ResultContent<Void> resultContent =
|
|
|
- userService.updateLoginPassword(param.getUserId(), CardSystemDefault.DEFAULT_PASSWORD);
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<Void> resultContent = userService.updateLoginPassword(param.getUserId(), CardSystemDefault.DEFAULT_PASSWORD);
|
|
|
if (resultContent.getState() != ResultState.Success) {
|
|
|
return ResultContent.buildFail(resultContent.getMsg());
|
|
|
}
|
|
|
@@ -523,7 +441,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 查询结构用户列表
|
|
|
+ * 查询机构用户列表
|
|
|
*
|
|
|
* @param param
|
|
|
* @param pageable
|
|
|
@@ -676,6 +594,12 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 转换数据模型
|
|
|
+ *
|
|
|
+ * @param list
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public List<UserCountSimpleModel> toListSimpleModel(List<UserAccount> list) {
|
|
|
if (ObjectUtils.isNotEmpty(list)) {
|
|
|
return list.stream().map(this::toSimpleModel).collect(Collectors.toList());
|
|
|
@@ -683,6 +607,12 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 所有数据字段
|
|
|
+ *
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public UserCountModel toModel(UserAccount entity) {
|
|
|
UserCountModel model = null;
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
@@ -692,6 +622,12 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
return model;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 用户的基本信息 (简介模型)
|
|
|
+ *
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public UserCountSimpleModel toSimpleModel(UserAccount entity) {
|
|
|
UserCountSimpleModel model = null;
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
@@ -701,6 +637,12 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
return model;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 用户在机构的数据模型(用户信息、职位、部门、角色等)
|
|
|
+ *
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public OrganizationUserModel toOrgUserModel(OrganizationUser entity) {
|
|
|
OrganizationUserModel model = new OrganizationUserModel();
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|