|
@@ -1,12 +1,18 @@
|
|
|
package com.zhongshu.card.server.core.service.org;
|
|
package com.zhongshu.card.server.core.service.org;
|
|
|
|
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
|
|
|
|
+import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
|
import com.github.microservice.auth.client.content.ResultState;
|
|
import com.github.microservice.auth.client.content.ResultState;
|
|
|
import com.github.microservice.auth.client.service.OrganizationUserService;
|
|
import com.github.microservice.auth.client.service.OrganizationUserService;
|
|
|
import com.github.microservice.auth.client.service.RoleService;
|
|
import com.github.microservice.auth.client.service.RoleService;
|
|
|
import com.github.microservice.auth.security.type.AuthType;
|
|
import com.github.microservice.auth.security.type.AuthType;
|
|
|
|
|
+import com.github.microservice.core.util.bean.BeanUtil;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
import com.github.microservice.net.ResultContent;
|
|
|
|
|
+import com.zhongshu.card.client.model.base.ProjectOidParam;
|
|
|
import com.zhongshu.card.client.model.org.*;
|
|
import com.zhongshu.card.client.model.org.*;
|
|
|
import com.zhongshu.card.client.model.orgModel.OrgBindUserAllParam;
|
|
import com.zhongshu.card.client.model.orgModel.OrgBindUserAllParam;
|
|
|
|
|
+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.model.school.RegisterBindSchoolParam;
|
|
|
import com.zhongshu.card.client.type.OrganizationUserType;
|
|
import com.zhongshu.card.client.type.OrganizationUserType;
|
|
|
import com.zhongshu.card.client.type.UserState;
|
|
import com.zhongshu.card.client.type.UserState;
|
|
@@ -20,17 +26,28 @@ import com.zhongshu.card.server.core.service.orgManager.OrganizationManagerServi
|
|
|
import com.zhongshu.card.server.core.service.user.DepartmentServiceImpl;
|
|
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.RoleServiceImpl;
|
|
|
import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
|
|
import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
|
|
|
|
|
+import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
|
|
+import com.zhongshu.card.server.core.util.ExcelUtils;
|
|
|
|
|
+import com.zhongshu.card.server.core.util.excel.CommonExeclParam;
|
|
|
|
|
+import com.zhongshu.card.server.core.util.excel.CommonExeclTd;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.Assert;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -86,8 +103,12 @@ public class OrganizationUserServiceImpl extends SuperService {
|
|
|
*/
|
|
*/
|
|
|
public ResultContent<OrganizationUser> saveOrgUser(UserCountAddParam param) {
|
|
public ResultContent<OrganizationUser> saveOrgUser(UserCountAddParam param) {
|
|
|
String oid = param.getOid();
|
|
String oid = param.getOid();
|
|
|
- Assert.hasText(oid, "oid不能为空");
|
|
|
|
|
- Assert.hasText(param.getName(), "name不能为空");
|
|
|
|
|
|
|
+ if (StringUtils.isEmpty(oid)) {
|
|
|
|
|
+ return ResultContent.buildFail("oid不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isEmpty(param.getName())) {
|
|
|
|
|
+ return ResultContent.buildFail("name不能为空");
|
|
|
|
|
+ }
|
|
|
if (param.getState() == null) {
|
|
if (param.getState() == null) {
|
|
|
param.setState(UserState.Normal);
|
|
param.setState(UserState.Normal);
|
|
|
}
|
|
}
|
|
@@ -251,7 +272,9 @@ public class OrganizationUserServiceImpl extends SuperService {
|
|
|
organizationUser.setAboutOid(oidAboutInfo.getOid());
|
|
organizationUser.setAboutOid(oidAboutInfo.getOid());
|
|
|
organizationUser.setAboutAuthType(oidAboutInfo.getAuthType());
|
|
organizationUser.setAboutAuthType(oidAboutInfo.getAuthType());
|
|
|
organizationUser.setAuthType(organization.getAuthType());
|
|
organizationUser.setAuthType(organization.getAuthType());
|
|
|
-
|
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(param.getProjectOid())) {
|
|
|
|
|
+ organizationUser.setProjectOid(param.getProjectOid());
|
|
|
|
|
+ }
|
|
|
// 用户信息
|
|
// 用户信息
|
|
|
organizationUser.setPhone(userAccount.getPhone());
|
|
organizationUser.setPhone(userAccount.getPhone());
|
|
|
organizationUser.setName(userAccount.getName());
|
|
organizationUser.setName(userAccount.getName());
|
|
@@ -269,7 +292,7 @@ public class OrganizationUserServiceImpl extends SuperService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 绑定结构管理员 (已新的为准,以前的删除掉)
|
|
|
|
|
|
|
+ * 绑定机构管理员 (已新的为准,以前的删除掉)
|
|
|
*
|
|
*
|
|
|
* @param organization
|
|
* @param organization
|
|
|
* @param userAccounts
|
|
* @param userAccounts
|
|
@@ -406,6 +429,131 @@ public class OrganizationUserServiceImpl extends SuperService {
|
|
|
return ResultContent.buildSuccess();
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 导入 学校用户excel
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param request
|
|
|
|
|
+ * @param response
|
|
|
|
|
+ * @param file
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultContent<ImportResultModel> importSchoolUsers(HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response, MultipartFile file, ProjectOidParam proParam) {
|
|
|
|
|
+ String oid = proParam.getProjectOid();
|
|
|
|
|
+ Assert.hasText(oid, "projectOid不能为空");
|
|
|
|
|
+
|
|
|
|
|
+ ImportResultModel model = new ImportResultModel();
|
|
|
|
|
+ try {
|
|
|
|
|
+ int startRow = 2;
|
|
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
|
|
+ List<ExcelUserParam> list = ExcelImportUtil.importExcel(file.getInputStream(),
|
|
|
|
|
+ ExcelUserParam.class, params);
|
|
|
|
|
+ model.setTotal(list.size());
|
|
|
|
|
+
|
|
|
|
|
+ List<String> failDetails = new ArrayList<>();
|
|
|
|
|
+ List<UserCountAddParam> userList = new ArrayList<>();
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(list)) {
|
|
|
|
|
+ for (ExcelUserParam param1 : list) {
|
|
|
|
|
+ // 验证数据合法性
|
|
|
|
|
+ boolean b = true;
|
|
|
|
|
+ if (b && StringUtils.isEmpty(param1.getName())) {
|
|
|
|
|
+ b = false;
|
|
|
|
|
+ failDetails.add(String.format("第%d行名称不能为空", startRow));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (b && StringUtils.isEmpty(param1.getCode())) {
|
|
|
|
|
+ b = false;
|
|
|
|
|
+ failDetails.add(String.format("第%d行编码不能为空", startRow));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (b && StringUtils.isEmpty(param1.getPhone())) {
|
|
|
|
|
+ b = false;
|
|
|
|
|
+ failDetails.add(String.format("第%d行电话不能为空", startRow));
|
|
|
|
|
+ }
|
|
|
|
|
+ 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 (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()));
|
|
|
|
|
+ }
|
|
|
|
|
+ String passWord = param1.getCardNumber().substring(12, 18);
|
|
|
|
|
+ passWord = passWord.toLowerCase().replace("x", "0");
|
|
|
|
|
+ addParam.setPassWord(passWord);
|
|
|
|
|
+ userList.add(addParam);
|
|
|
|
|
+ }
|
|
|
|
|
+ startRow++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 添加到对应的结构中
|
|
|
|
|
+ for (UserCountAddParam param : userList) {
|
|
|
|
|
+ ResultContent resultContent = saveOrgUser(param);
|
|
|
|
|
+ log.info("添加日志: {}", resultContent.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ model.setSuccess(userList.size());
|
|
|
|
|
+ model.setFailDetails(failDetails);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return ResultContent.buildFail(String.format("导入出错:%s", e.getMessage()));
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultContent.buildSuccess(model);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 导出项目用户
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param request
|
|
|
|
|
+ * @param response
|
|
|
|
|
+ * @param param
|
|
|
|
|
+ */
|
|
|
|
|
+ public void exportProjectUser(HttpServletRequest request, HttpServletResponse response,
|
|
|
|
|
+ OrganizationUserSearch param) {
|
|
|
|
|
+ param.setIsSearchProject(Boolean.TRUE);
|
|
|
|
|
+
|
|
|
|
|
+ Organization organization = organizationDao.findTopByOid(param.getOid());
|
|
|
|
|
+ Pageable pageable = PageRequest.of(0, Integer.MAX_VALUE);
|
|
|
|
|
+ Page<OrganizationUser> page = organizationUserDao.page(pageable, param);
|
|
|
|
|
+
|
|
|
|
|
+ List<Map<String, Object>> maps = new ArrayList<>();
|
|
|
|
|
+ if (page.getContent() != null) {
|
|
|
|
|
+ List<OrganizationUser> list = page.getContent();
|
|
|
|
|
+ maps = list.stream().map(it -> {
|
|
|
|
|
+ Map<String, Object> map = BeanUtil.bean2Map(it);
|
|
|
|
|
+ String sex = "";
|
|
|
|
|
+ if (it.getUser() != null && it.getUser().getSex() != null) {
|
|
|
|
|
+ sex = it.getUser().getSex().getRemark();
|
|
|
|
|
+ }
|
|
|
|
|
+ map.put("sexStr", sex);
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ CommonExeclParam execlParam = new CommonExeclParam();
|
|
|
|
|
+ execlParam.setTitle(String.format("%s用户列表", organization.getName()));
|
|
|
|
|
+ execlParam.setStartRow(2);
|
|
|
|
|
+ execlParam.setDatas(maps);
|
|
|
|
|
+
|
|
|
|
|
+ List<CommonExeclTd> tds = new ArrayList<>();
|
|
|
|
|
+ tds.add(CommonExeclTd.build("人员编号", "code"));
|
|
|
|
|
+ tds.add(CommonExeclTd.build("姓名", "name"));
|
|
|
|
|
+ tds.add(CommonExeclTd.build("性别", "sexStr"));
|
|
|
|
|
+ tds.add(CommonExeclTd.build("手机号", "phone"));
|
|
|
|
|
+ tds.add(CommonExeclTd.build("身份证号", "cardNumber"));
|
|
|
|
|
+ tds.add(CommonExeclTd.build("备注", "remark"));
|
|
|
|
|
+
|
|
|
|
|
+ execlParam.setTds(tds);
|
|
|
|
|
+ ExcelUtils.commonExecuteExcel(request, response, execlParam);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 转换机构用户信息(基本信息 角色 部门)
|
|
* 转换机构用户信息(基本信息 角色 部门)
|
|
|
*
|
|
*
|