dev-tmp1
luotaiqian 2026-08-11 13:53:37 +08:00
parent dd5014c00f
commit 88172e0868
1 changed files with 161 additions and 5 deletions

View File

@ -1,9 +1,12 @@
package org.qinan.safetyeval.app.support;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.validation.ValidationUtil;
import com.alibaba.excel.EasyExcel;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.jjb.saas.framework.core.utils.ValidatorUtils;
import com.jjb.saas.system.client.user.request.RoleDeptAddCmd;
import com.jjb.saas.system.client.user.request.UserAddCmd;
import com.zcloud.gbscommon.utils.MD5;
@ -31,6 +34,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.validation.ValidationUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@ -57,6 +61,9 @@ public class OrgPersonnelExcelImporter {
private static final DateTimeFormatter SLASH_DATE_FORMATTER =
new DateTimeFormatterBuilder().appendPattern("yyyy/M/d").toFormatter();
/** 手机号格式11位纯数字、1开头 */
private static final String MOBILE_PHONE_REGEX = "^1\\d{10}$";
@Resource
private OrgDepartmentGateway orgDepartmentGateway;
@ -220,11 +227,12 @@ public class OrgPersonnelExcelImporter {
}
row.setRowIndex(i + 2);
// 文件内手机号重复:剔除该行并记录提示(空账号不参与去重)
String account = trim(row.getAccount());
if (StringUtils.hasText(account) && !seenAccounts.add(account)) {
errors.add(new OrgPersonnelImportErrorCO(row.getRowIndex(), account, trim(row.getUserName()),
"账号在文件内重复,已剔除该行"));
// 账号(手机号)校验:必填、格式、文件内去重
if (!validateAccount(row, seenAccounts, errors)) {
continue;
}
// 字段级校验:必填、长度、格式
if (!validateRowFields(row, errors)) {
continue;
}
rows.add(row);
@ -232,6 +240,154 @@ public class OrgPersonnelExcelImporter {
return rows;
}
/**
*
*
* @param row
* @param seenAccounts
* @param errors
* @return true false
*/
private boolean validateAccount(OrgPersonnelImportRow row, Set<String> seenAccounts,
List<OrgPersonnelImportErrorCO> errors) {
Integer rowIndex = row.getRowIndex();
String account = trim(row.getAccount());
String userName = trim(row.getUserName());
// 账号必填DB: account NOT NULL
if (!StringUtils.hasText(account)) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName, "账号不能为空"));
return false;
}
// 手机号格式校验11位纯数字、1开头
if (!account.matches(MOBILE_PHONE_REGEX)) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName,
"手机号格式不正确应为11位数字且以1开头"));
return false;
}
// 文件内去重
if (!seenAccounts.add(account)) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName,
"账号在文件内重复,已剔除该行"));
return false;
}
return true;
}
/**
* /
* <p>
* {@code org_personnel}
* <ul>
* <li>NOT NULL user_nameaccount</li>
* <li>varchar </li>
* <li>/</li>
* </ul>
*
* @param row
* @param errors
* @return true false
*/
private boolean validateRowFields(OrgPersonnelImportRow row, List<OrgPersonnelImportErrorCO> errors) {
Integer rowIndex = row.getRowIndex();
String account = trim(row.getAccount());
String userName = trim(row.getUserName());
// 姓名必填DB: user_name varchar(50) NOT NULL
if (!StringUtils.hasText(userName)) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName, "姓名不能为空"));
return false;
}
if (userName.length() > 50) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName, "姓名长度不能超过50个字符"));
return false;
}
// 身份证号可选格式校验DB: id_card_no varchar(18)
String idCardNo = trim(row.getIdCardNo());
if (StringUtils.hasText(idCardNo) && !IdcardUtil.isValidCard(idCardNo)) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName,
"身份证号格式不正确应为15或18位有效身份证号"));
return false;
}
// 性别名称最大10DB: gender_name varchar(10)
String gender = trim(row.getGender());
if (StringUtils.hasText(gender) && gender.length() > 10) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName, "性别长度不能超过10个字符"));
return false;
}
// 出生日期日期格式校验DB: birth_date date
String birthDate = trim(row.getBirthDate());
if (StringUtils.hasText(birthDate) && parseDate(birthDate) == null) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName,
"出生日期格式不正确应为yyyy-MM-dd或yyyy/M/d"));
return false;
}
// 参加工作时间日期格式校验DB: join_work_date date
String joinWorkDate = trim(row.getJoinWorkDate());
if (StringUtils.hasText(joinWorkDate) && parseDate(joinWorkDate) == null) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName,
"参加工作时间格式不正确应为yyyy-MM-dd或yyyy/M/d"));
return false;
}
// 学历名称最大50DB: education_name varchar(50)
String education = trim(row.getEducation());
if (StringUtils.hasText(education) && education.length() > 50) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName, "学历长度不能超过50个字符"));
return false;
}
// 毕业院校最大200DB: graduate_school varchar(200)
String graduateSchool = trim(row.getGraduateSchool());
if (StringUtils.hasText(graduateSchool) && graduateSchool.length() > 200) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName, "毕业院校长度不能超过200个字符"));
return false;
}
// 所学专业最大100DB: major varchar(100)
String major = trim(row.getMajor());
if (StringUtils.hasText(major) && major.length() > 100) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName, "所学专业长度不能超过100个字符"));
return false;
}
// 现住地址最大500DB: current_address varchar(500)
String currentAddress = trim(row.getCurrentAddress());
if (StringUtils.hasText(currentAddress) && currentAddress.length() > 500) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName, "现住地址长度不能超过500个字符"));
return false;
}
// 办公地址最大500DB: office_address varchar(500)
String officeAddress = trim(row.getOfficeAddress());
if (StringUtils.hasText(officeAddress) && officeAddress.length() > 500) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName, "办公地址长度不能超过500个字符"));
return false;
}
// 出版学术专著等最大1000DB: publications varchar(1000)
String publications = trim(row.getPublications());
if (StringUtils.hasText(publications) && publications.length() > 1000) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName,
"出版学术专著等信息长度不能超过1000个字符"));
return false;
}
// 自我申报专业能力最大1000DB: ability_declaration varchar(1000)
String abilityDeclaration = trim(row.getAbilityDeclaration());
if (StringUtils.hasText(abilityDeclaration) && abilityDeclaration.length() > 1000) {
errors.add(new OrgPersonnelImportErrorCO(rowIndex, account, userName,
"自我申报的专业能力信息长度不能超过1000个字符"));
return false;
}
return true;
}
/**
*
* <p>