|
|
@@ -15,6 +15,7 @@ import com.zhongshu.card.client.model.school.ExcelUserParam;
|
|
|
import com.zhongshu.card.client.model.school.ImportResultModel;
|
|
|
import com.zhongshu.card.client.model.school.RegisterBindSchoolParam;
|
|
|
import com.zhongshu.card.client.type.DataOperationType;
|
|
|
+import com.zhongshu.card.client.type.DictInfoType;
|
|
|
import com.zhongshu.card.client.type.OrganizationUserType;
|
|
|
import com.zhongshu.card.client.type.UserState;
|
|
|
import com.zhongshu.card.server.core.dao.org.*;
|
|
|
@@ -26,6 +27,7 @@ import com.zhongshu.card.server.core.event.OrgUserBindUpdateSyncEvent;
|
|
|
import com.zhongshu.card.server.core.model.org.OrgBindUserParam;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.service.orgManager.OrganizationManagerServiceImpl;
|
|
|
+import com.zhongshu.card.server.core.service.school.DictInfoServiceImpl;
|
|
|
import com.zhongshu.card.server.core.service.user.DepartmentServiceImpl;
|
|
|
import com.zhongshu.card.server.core.service.user.RoleServiceImpl;
|
|
|
import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
|
|
|
@@ -50,6 +52,7 @@ import org.springframework.util.Assert;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -101,6 +104,9 @@ public class OrganizationUserServiceImpl extends SuperService {
|
|
|
@Autowired
|
|
|
ApplicationContext applicationContext;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DictInfoServiceImpl dictInfoService;
|
|
|
+
|
|
|
/**
|
|
|
* 添加编辑用户 添加机构用户 (包括角色 部门 职位等信息)
|
|
|
* 用户可能不存在
|
|
|
@@ -303,8 +309,7 @@ public class OrganizationUserServiceImpl extends SuperService {
|
|
|
organizationUserDao.save(organizationUser);
|
|
|
|
|
|
if (isUpdate) {
|
|
|
- OrgUserBindUpdateSyncEvent event = new OrgUserBindUpdateSyncEvent(
|
|
|
- this, List.of(organizationUser.getId()), DataOperationType.Update);
|
|
|
+ OrgUserBindUpdateSyncEvent event = new OrgUserBindUpdateSyncEvent(this, List.of(organizationUser.getId()), DataOperationType.Update);
|
|
|
applicationContext.publishEvent(event);
|
|
|
}
|
|
|
// 权限中心 绑定用户
|
|
|
@@ -465,8 +470,7 @@ public class OrganizationUserServiceImpl extends SuperService {
|
|
|
OrganizationUser organizationUser = organizationUserDao.findTopById(id);
|
|
|
if (ObjectUtils.isNotEmpty(organizationUser)) {
|
|
|
organizationUserDao.delete(organizationUser);
|
|
|
- OrgUserBindUpdateSyncEvent event = new OrgUserBindUpdateSyncEvent(
|
|
|
- this, List.of(id), DataOperationType.Delete);
|
|
|
+ OrgUserBindUpdateSyncEvent event = new OrgUserBindUpdateSyncEvent(this, List.of(id), DataOperationType.Delete);
|
|
|
applicationContext.publishEvent(event);
|
|
|
}
|
|
|
return ResultContent.buildSuccess();
|
|
|
@@ -480,8 +484,7 @@ public class OrganizationUserServiceImpl extends SuperService {
|
|
|
* @return
|
|
|
*/
|
|
|
public List<OrganizationUser> getUserOrgList(String userId, String projectOid) {
|
|
|
- return organizationUserDao.findByUserIdAndProjectOidAndIsOrg(
|
|
|
- userId, projectOid, Boolean.TRUE);
|
|
|
+ return organizationUserDao.findByUserIdAndProjectOidAndIsOrg(userId, projectOid, Boolean.TRUE);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -492,10 +495,9 @@ public class OrganizationUserServiceImpl extends SuperService {
|
|
|
* @param file
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultContent<ImportResultModel> importSchoolUsers(HttpServletRequest request,
|
|
|
- HttpServletResponse response, MultipartFile file, ProjectOidParam proParam) {
|
|
|
- String oid = proParam.getProjectOid();
|
|
|
- Assert.hasText(oid, "projectOid不能为空");
|
|
|
+ public ResultContent<ImportResultModel> importSchoolUsers(HttpServletRequest request, HttpServletResponse response, MultipartFile file, ProjectOidParam proParam) {
|
|
|
+ String projectOid = proParam.getProjectOid();
|
|
|
+ Assert.hasText(projectOid, "projectOid不能为空");
|
|
|
|
|
|
ImportResultModel model = new ImportResultModel();
|
|
|
try {
|
|
|
@@ -503,50 +505,112 @@ public class OrganizationUserServiceImpl extends SuperService {
|
|
|
ImportParams params = new ImportParams();
|
|
|
params.setHeadRows(1);
|
|
|
params.setTitleRows(1);
|
|
|
- List<ExcelUserParam> list = ExcelImportUtil.importExcel(file.getInputStream(),
|
|
|
- ExcelUserParam.class, params);
|
|
|
+ List<ExcelUserParam> list = ExcelImportUtil.importExcel(file.getInputStream(), ExcelUserParam.class, params);
|
|
|
model.setTotal(list.size());
|
|
|
|
|
|
List<String> failDetails = new ArrayList<>();
|
|
|
List<UserCountAddParam> userList = new ArrayList<>();
|
|
|
+
|
|
|
+ HashMap<String, String> name2Id = new HashMap<>();
|
|
|
+ HashMap<String, List<String>> role2Id = new HashMap<>();
|
|
|
+ HashMap<String, String> pos2Id = new HashMap<>();
|
|
|
+
|
|
|
if (ObjectUtils.isNotEmpty(list)) {
|
|
|
- for (ExcelUserParam param1 : list) {
|
|
|
+ for (ExcelUserParam excelUserParam : list) {
|
|
|
// 验证数据合法性
|
|
|
boolean b = true;
|
|
|
- if (b && StringUtils.isEmpty(param1.getName())) {
|
|
|
- b = false;
|
|
|
+ if (StringUtils.isEmpty(excelUserParam.getName())) {
|
|
|
failDetails.add(String.format("第%d行名称不能为空", startRow));
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (b && StringUtils.isEmpty(param1.getCode())) {
|
|
|
- b = false;
|
|
|
+ if (StringUtils.isEmpty(excelUserParam.getCode())) {
|
|
|
failDetails.add(String.format("第%d行编码不能为空", startRow));
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (b && StringUtils.isEmpty(param1.getPhone())) {
|
|
|
- b = false;
|
|
|
+ if (StringUtils.isEmpty(excelUserParam.getPhone())) {
|
|
|
failDetails.add(String.format("第%d行电话不能为空", startRow));
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (b) {
|
|
|
- if (StringUtils.isEmpty(param1.getCardNumber())) {
|
|
|
- b = false;
|
|
|
- failDetails.add(String.format("第%d行身份证号不能为空", startRow));
|
|
|
- } else if (param1.getCardNumber().length() != 18) {
|
|
|
- b = false;
|
|
|
- failDetails.add(String.format("第%d行身份证号格式不正确", startRow));
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(excelUserParam.getCardNumber())) {
|
|
|
+ failDetails.add(String.format("第%d行身份证号不能为空", startRow));
|
|
|
+ continue;
|
|
|
+ } else if (excelUserParam.getCardNumber().length() != 18) {
|
|
|
+ failDetails.add(String.format("第%d行身份证号格式不正确", startRow));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证通过
|
|
|
+ UserCountAddParam addParam = new UserCountAddParam();
|
|
|
+ String beLongOid = "";
|
|
|
+
|
|
|
+ // 验证机构信息
|
|
|
+ String orgName = excelUserParam.getOrgName();
|
|
|
+ if (StringUtils.isEmpty(orgName)) {
|
|
|
+ failDetails.add(String.format("第%d行机构信息不能为空", startRow));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (name2Id.containsKey(orgName)) {
|
|
|
+ beLongOid = name2Id.get(orgName);
|
|
|
+ } else {
|
|
|
+ Organization organization = organizationDao.findTopByProjectOidAndName(projectOid, orgName);
|
|
|
+ if (ObjectUtils.isEmpty(organization)) {
|
|
|
+ failDetails.add(String.format("%s 机构信息不存在", orgName));
|
|
|
+ continue;
|
|
|
}
|
|
|
+ name2Id.put(orgName, organization.getOid());
|
|
|
}
|
|
|
+
|
|
|
+ // 部门
|
|
|
+ if (StringUtils.isNotEmpty(excelUserParam.getDepartmentName())) {
|
|
|
+ if (name2Id.containsKey(excelUserParam.getDepartmentName())) {
|
|
|
+ addParam.setDepartmentId(name2Id.get(excelUserParam.getDepartmentName()));
|
|
|
+ } else {
|
|
|
+ Department department = departmentService.getProjectDepartmentByName(projectOid, excelUserParam.getDepartmentName());
|
|
|
+ if (ObjectUtils.isNotEmpty(department)) {
|
|
|
+ addParam.setDepartmentId(department.getId());
|
|
|
+ name2Id.put(excelUserParam.getDepartmentName(), department.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 角色
|
|
|
+ if (StringUtils.isNotEmpty(excelUserParam.getRoleName())) {
|
|
|
+ if (role2Id.containsKey(excelUserParam.getRoleName())) {
|
|
|
+ addParam.setRoleIds(role2Id.get(excelUserParam.getRoleName()));
|
|
|
+ } else {
|
|
|
+ List<Role> roles = roleServiceImpl.getProjectRoleByName(projectOid, excelUserParam.getRoleName());
|
|
|
+ if (ObjectUtils.isNotEmpty(roles)) {
|
|
|
+ addParam.setRoleIds(roles.stream().map(it -> it.getId()).collect(Collectors.toList()));
|
|
|
+ role2Id.put(excelUserParam.getRoleName(), addParam.getRoleIds());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 职位
|
|
|
+ if (StringUtils.isNotEmpty(excelUserParam.getPositionName())) {
|
|
|
+ if (pos2Id.containsKey(excelUserParam.getPositionName())) {
|
|
|
+ addParam.setPositionId(pos2Id.get(excelUserParam.getPositionName()));
|
|
|
+ } else {
|
|
|
+ DictInfo dictInfo = dictInfoService.getProjectDictByName(projectOid, DictInfoType.Position, excelUserParam.getPositionName());
|
|
|
+ if (ObjectUtils.isNotEmpty(dictInfo)) {
|
|
|
+ addParam.setPositionId(dictInfo.getId());
|
|
|
+ pos2Id.put(excelUserParam.getPositionName(), dictInfo.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (b) {
|
|
|
- // 验证通过
|
|
|
- UserCountAddParam addParam = new UserCountAddParam();
|
|
|
- initDefaultUserParam(addParam);
|
|
|
- addParam.setOid(oid);
|
|
|
-
|
|
|
- com.zhongshu.card.server.core.util.BeanUtils.copyProperties(param1, addParam);
|
|
|
- if (StringUtils.isNotBlank(param1.getSexStr())) {
|
|
|
- addParam.setSex(CommonUtil.getSexByStr(param1.getSexStr()));
|
|
|
+ addParam.setProjectOid(projectOid);
|
|
|
+ addParam.setOid(beLongOid);
|
|
|
+
|
|
|
+ com.zhongshu.card.server.core.util.BeanUtils.copyProperties(excelUserParam, addParam);
|
|
|
+ if (StringUtils.isNotBlank(excelUserParam.getSexStr())) {
|
|
|
+ addParam.setSex(CommonUtil.getSexByStr(excelUserParam.getSexStr()));
|
|
|
}
|
|
|
String passWord = CardSystemDefault.DEFAULT_PASSWORD;
|
|
|
- if (StringUtils.isNotEmpty(param1.getCardNumber())) {
|
|
|
- param1.getCardNumber().substring(12, 18);
|
|
|
+ if (StringUtils.isNotEmpty(excelUserParam.getCardNumber())) {
|
|
|
+ excelUserParam.getCardNumber().substring(12, 18);
|
|
|
passWord = passWord.toLowerCase().replace("x", "0");
|
|
|
}
|
|
|
addParam.setPassWord(passWord);
|
|
|
@@ -577,8 +641,7 @@ public class OrganizationUserServiceImpl extends SuperService {
|
|
|
* @param response
|
|
|
* @param param
|
|
|
*/
|
|
|
- public void exportProjectUser(HttpServletRequest request, HttpServletResponse response,
|
|
|
- OrganizationUserSearch param) {
|
|
|
+ public void exportProjectUser(HttpServletRequest request, HttpServletResponse response, OrganizationUserSearch param) {
|
|
|
param.setIsSearchProject(Boolean.TRUE);
|
|
|
Assert.hasText(param.getProjectOid(), "projectOid不能为空");
|
|
|
|