|
|
@@ -1,7 +1,10 @@
|
|
|
package com.zhongshu.card.server.core.service.org;
|
|
|
|
|
|
import com.github.microservice.auth.client.content.ResultState;
|
|
|
+import com.github.microservice.auth.client.model.UserAuthModel;
|
|
|
+import com.github.microservice.auth.client.service.RoleService;
|
|
|
import com.github.microservice.auth.client.service.UserService;
|
|
|
+import com.github.microservice.auth.client.type.LoginType;
|
|
|
import com.github.microservice.auth.security.type.AuthType;
|
|
|
import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
import com.zhongshu.card.client.model.base.AuthTypeParam;
|
|
|
@@ -12,14 +15,21 @@ import com.zhongshu.card.client.ret.ResultMessage;
|
|
|
import com.zhongshu.card.client.service.org.OrganizationService;
|
|
|
import com.zhongshu.card.client.service.org.UserAccountService;
|
|
|
import com.zhongshu.card.client.utils.type.Sex;
|
|
|
+import com.zhongshu.card.client.utils.type.UserLoginType;
|
|
|
import com.zhongshu.card.client.utils.type.UserState;
|
|
|
-import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
+import com.zhongshu.card.client.utils.type.UserType;
|
|
|
+import com.zhongshu.card.server.core.dao.org.*;
|
|
|
import com.zhongshu.card.server.core.dataConfig.CardDefault;
|
|
|
-import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
-import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
+import com.zhongshu.card.server.core.domain.org.*;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import net.sourceforge.pinyin4j.PinyinHelper;
|
|
|
+import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
|
|
|
+import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
|
|
|
+import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
|
|
|
+import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
|
|
|
+import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -30,7 +40,9 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author TRX
|
|
|
@@ -50,16 +62,159 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
@Autowired
|
|
|
UserService userService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ RoleDao roleDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DepartmentDao departmentDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrganizationDao organizationDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrganizationUserDao organizationUserDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RoleService roleService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加编辑用户
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public ResultContent update(UserCountAddParam param) {
|
|
|
- UserAccount userCount = new UserAccount();
|
|
|
- if (StringUtils.isNotEmpty(param.getUserId())) {
|
|
|
- UserAccount userCount1 = userCountDao.findTopByUserId(param.getUserId());
|
|
|
- if (ObjectUtils.isEmpty(userCount1)) {
|
|
|
- return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getUserId()));
|
|
|
+ String oid = param.getOid();
|
|
|
+ if (StringUtils.isEmpty(oid)) {
|
|
|
+ oid = getCurrentOid();
|
|
|
+ }
|
|
|
+ Assert.hasText(oid, "oid不能为空");
|
|
|
+ Assert.hasText(param.getPhone(), "phone不能为空");
|
|
|
+ Assert.hasText(param.getName(), "name不能为空");
|
|
|
+ if (param.getState() == null) {
|
|
|
+ param.setState(UserState.Normal);
|
|
|
+ }
|
|
|
+ // 机构信息
|
|
|
+ Organization organization = organizationDao.findTopByOid(oid);
|
|
|
+ if (ObjectUtils.isEmpty(organization)) {
|
|
|
+ return ResultContent.buildFail(String.format("oid不存在:%s", oid));
|
|
|
+ }
|
|
|
+ List<Role> roles = new ArrayList<>();
|
|
|
+ List<Department> departments = new ArrayList<>();
|
|
|
+ if (ObjectUtils.isNotEmpty(param.getRoleIds())) {
|
|
|
+ roles = roleDao.findByOidAndIdIn(oid, param.getRoleIds());
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(param.getDepartmentIds())) {
|
|
|
+ departments = departmentDao.findByOidAndIdIn(oid, param.getDepartmentIds());
|
|
|
+ }
|
|
|
+ UserAccount temp = null;
|
|
|
+ String loginName = param.getPhone();
|
|
|
+ String userId = "";
|
|
|
+ if (StringUtils.isEmpty(param.getId())) {
|
|
|
+ // 添加
|
|
|
+ // 判断用户是否存在
|
|
|
+ temp = userCountDao.findTopByLoginName(loginName);
|
|
|
+ if (ObjectUtils.isEmpty(temp)) {
|
|
|
+ String password = param.getPassWord();
|
|
|
+ if (StringUtils.isEmpty(password)) {
|
|
|
+ password = CardDefault.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(getPinyin(param.getName()));
|
|
|
+ userCountDao.save(temp);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ temp = userCountDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(temp)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
}
|
|
|
+ BeanUtils.copyProperties(param, temp);
|
|
|
+ temp.setSpellCode(getPinyin(param.getName()));
|
|
|
+ userCountDao.save(temp);
|
|
|
}
|
|
|
- // 在授权中心添加用户
|
|
|
+
|
|
|
+ //权限中心: 在角色组添加用户
|
|
|
+ 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();
|
|
|
+ organizationUser.setOrganization(organization);
|
|
|
+ organizationUser.setUser(temp);
|
|
|
+ organizationUser.setUserId(temp.getUserId());
|
|
|
+ organizationUser.setIsAdmin(Boolean.FALSE);
|
|
|
+ organizationUser.setAuthType(organizationUser.getAuthType());
|
|
|
+ organizationUser.setCreateUserId(getCurrentUserId());
|
|
|
+ } 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ organizationUser.setPhone(temp.getPhone());
|
|
|
+ organizationUser.setName(temp.getName());
|
|
|
+ organizationUser.setState(temp.getState());
|
|
|
+ organizationUser.setRoles(roles);
|
|
|
+ organizationUser.setDepartments(departments);
|
|
|
+ organizationUserDao.save(organizationUser);
|
|
|
+
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除机构用户
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent deleteOrgUser(DelUserCountParam param) {
|
|
|
+
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改用户状态
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent updateOrgUserState(UpdateUserStateParam param) {
|
|
|
+ String userId = param.getUserId();
|
|
|
+ String oid = param.getOid();
|
|
|
+ if (StringUtils.isEmpty(oid)) {
|
|
|
+ oid = getCurrentOid();
|
|
|
+ }
|
|
|
+ Organization organization = organizationDao.findTopByOid(oid);
|
|
|
+ UserAccount temp = userCountDao.findTopByUserId(userId);
|
|
|
+ OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, temp);
|
|
|
+ organizationUser.setState(param.getUserState());
|
|
|
+ organizationUserDao.save(organizationUser);
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
@@ -91,6 +246,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
|
|
|
/**
|
|
|
* 重置密码
|
|
|
+ *
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -193,4 +349,36 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
}
|
|
|
return model;
|
|
|
}
|
|
|
+
|
|
|
+ private String getPinyin(String chinaStr) {
|
|
|
+ if (StringUtils.isEmpty(chinaStr)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ HanyuPinyinOutputFormat forMat = new HanyuPinyinOutputFormat();
|
|
|
+ forMat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
|
|
|
+ forMat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
|
|
+ forMat.setVCharType(HanyuPinyinVCharType.WITH_V);
|
|
|
+ char[] arrays = chinaStr.trim().toCharArray();
|
|
|
+ String result = "";
|
|
|
+ try {
|
|
|
+ for (int i = 0; i < arrays.length; i++) {
|
|
|
+ char ti = arrays[i];
|
|
|
+ if (Character.toString(ti).matches("[\\u4e00-\\u9fa5]")) { //匹配是否是中文
|
|
|
+ String[] temp = PinyinHelper.toHanyuPinyinStringArray(ti, forMat);
|
|
|
+ result += temp[0];
|
|
|
+ } else {
|
|
|
+ result += ti;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (BadHanyuPinyinOutputFormatCombination e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ //判断如果包含重庆,则替换拼音中的zhongqing为chongqing
|
|
|
+ if (chinaStr.indexOf("重庆") == -1) {
|
|
|
+ //do nothing
|
|
|
+ } else {
|
|
|
+ result = result.replace("zhongqing", "chongqing");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|