|
|
@@ -5,13 +5,13 @@ 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;
|
|
|
import com.zhongshu.card.client.model.base.UserIdModel;
|
|
|
import com.zhongshu.card.client.model.org.*;
|
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
|
import com.zhongshu.card.client.ret.ResultMessage;
|
|
|
+import com.zhongshu.card.client.service.org.DepartmentService;
|
|
|
import com.zhongshu.card.client.service.org.OrganizationService;
|
|
|
import com.zhongshu.card.client.service.org.UserAccountService;
|
|
|
import com.zhongshu.card.client.utils.type.Sex;
|
|
|
@@ -23,13 +23,9 @@ import com.zhongshu.card.server.core.dataConfig.CardDefault;
|
|
|
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 com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
+import com.zhongshu.card.server.core.util.DateUtils;
|
|
|
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;
|
|
|
@@ -77,6 +73,12 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
@Autowired
|
|
|
RoleService roleService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ RoleServiceImpl roleServiceImpl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DepartmentServiceImpl departmentService;
|
|
|
+
|
|
|
/**
|
|
|
* 添加编辑用户
|
|
|
*
|
|
|
@@ -135,7 +137,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
temp.setOid(null);
|
|
|
temp.setLoginName(loginName);
|
|
|
temp.setIsLogined(Boolean.FALSE);
|
|
|
- temp.setSpellCode(getPinyin(param.getName()));
|
|
|
+ temp.setSpellCode(CommonUtil.getPinyin(param.getName()));
|
|
|
userCountDao.save(temp);
|
|
|
}
|
|
|
} else {
|
|
|
@@ -144,7 +146,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
}
|
|
|
BeanUtils.copyProperties(param, temp);
|
|
|
- temp.setSpellCode(getPinyin(param.getName()));
|
|
|
+ temp.setSpellCode(CommonUtil.getPinyin(param.getName()));
|
|
|
userCountDao.save(temp);
|
|
|
}
|
|
|
|
|
|
@@ -185,6 +187,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 删除机构用户
|
|
|
*
|
|
|
@@ -193,7 +196,30 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
*/
|
|
|
@Override
|
|
|
public ResultContent deleteOrgUser(DelUserCountParam param) {
|
|
|
+ String userId = param.getUserId();
|
|
|
+ String oid = param.getOid();
|
|
|
+ if (StringUtils.isEmpty(oid)) {
|
|
|
+ oid = getCurrentOid();
|
|
|
+ }
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ UserAccount temp = userCountDao.findTopByUserId(userId);
|
|
|
+ if (ObjectUtils.isEmpty(temp)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, userId));
|
|
|
+ }
|
|
|
+ OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, temp);
|
|
|
+ if (ObjectUtils.isEmpty(organizationUser)) {
|
|
|
+ return ResultContent.buildFail(String.format("企业没有改用户:%s", oid));
|
|
|
+ }
|
|
|
+ if (organizationUser.getIsAdmin() != null && organizationUser.getIsAdmin()) {
|
|
|
+ return ResultContent.buildFail(String.format("管理员用户不能删除"));
|
|
|
+ }
|
|
|
+ organizationUserDao.delete(organizationUser);
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
@@ -210,11 +236,22 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
if (StringUtils.isEmpty(oid)) {
|
|
|
oid = getCurrentOid();
|
|
|
}
|
|
|
+ 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));
|
|
|
+ }
|
|
|
UserAccount temp = userCountDao.findTopByUserId(userId);
|
|
|
+ if (ObjectUtils.isEmpty(temp)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, userId));
|
|
|
+ }
|
|
|
OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, temp);
|
|
|
- organizationUser.setState(param.getUserState());
|
|
|
- organizationUserDao.save(organizationUser);
|
|
|
+ if (ObjectUtils.isNotEmpty(organizationUser)) {
|
|
|
+ organizationUser.setState(param.getUserState());
|
|
|
+ organizationUserDao.save(organizationUser);
|
|
|
+ }
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
@@ -263,6 +300,34 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询结构用户列表
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @param pageable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent<Page<OrganizationUserModel>> pageOrgUser(OrganizationUserSearch param, Pageable pageable) {
|
|
|
+ String oid = param.getOid();
|
|
|
+ if (StringUtils.isEmpty(oid)) {
|
|
|
+ oid = getCurrentOid();
|
|
|
+ }
|
|
|
+ param.setOid(oid);
|
|
|
+ Assert.hasText(oid, "oid不能为空");
|
|
|
+ List<Long> times = param.getTimes();
|
|
|
+ if (ObjectUtils.isNotEmpty(times) && times.size() == 2) {
|
|
|
+ Long startTime = times.get(0);
|
|
|
+ startTime = DateUtils.getDayStartTime(startTime);
|
|
|
+ Long endTime = times.get(1);
|
|
|
+ endTime = DateUtils.getDayEndTime(endTime);
|
|
|
+ param.setStartTime(startTime);
|
|
|
+ param.setEndTime(endTime);
|
|
|
+ }
|
|
|
+ Page<OrganizationUser> page = organizationUserDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toOrgUserModel));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 初始化一个 账号信息 (创建机构时用)
|
|
|
*
|
|
|
@@ -350,35 +415,28 @@ 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;
|
|
|
- }
|
|
|
+ public OrganizationUserModel toOrgUserModel(OrganizationUser entity) {
|
|
|
+ OrganizationUserModel model = new OrganizationUserModel();
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+
|
|
|
+ // 用户信息
|
|
|
+ UserCountModel userCountModel = toModel(entity.getUser());
|
|
|
+ model.setUser(userCountModel);
|
|
|
+
|
|
|
+ // 角色信息
|
|
|
+ if (ObjectUtils.isNotEmpty(entity.getRoles())) {
|
|
|
+ List<RoleModel> roleModels = entity.getRoles().stream().map(roleServiceImpl::toModel)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ model.setRoles(roleModels);
|
|
|
+ }
|
|
|
+ // 部门信息
|
|
|
+ if (ObjectUtils.isNotEmpty(entity.getDepartments())) {
|
|
|
+ List<DepartmentModel> roleModels = entity.getDepartments().stream().map(departmentService::toModel)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ model.setDepartments(roleModels);
|
|
|
}
|
|
|
- } catch (BadHanyuPinyinOutputFormatCombination e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- //判断如果包含重庆,则替换拼音中的zhongqing为chongqing
|
|
|
- if (chinaStr.indexOf("重庆") == -1) {
|
|
|
- //do nothing
|
|
|
- } else {
|
|
|
- result = result.replace("zhongqing", "chongqing");
|
|
|
}
|
|
|
- return result;
|
|
|
+ return model;
|
|
|
}
|
|
|
}
|