|
@@ -0,0 +1,583 @@
|
|
|
+package com.xjrsoft.module.veb.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.annotation.ExcelProperty;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
+import com.xjrsoft.common.annotation.Required;
|
|
|
+import com.xjrsoft.common.enums.DeleteMark;
|
|
|
+import com.xjrsoft.common.enums.YesOrNoEnum;
|
|
|
+import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
+import com.xjrsoft.module.base.entity.*;
|
|
|
+import com.xjrsoft.module.base.mapper.*;
|
|
|
+import com.xjrsoft.module.organization.entity.User;
|
|
|
+import com.xjrsoft.module.organization.mapper.UserMapper;
|
|
|
+import com.xjrsoft.module.student.entity.BaseMajor;
|
|
|
+import com.xjrsoft.module.system.entity.DictionaryDetail;
|
|
|
+import com.xjrsoft.module.system.entity.DictionaryItem;
|
|
|
+import com.xjrsoft.module.system.mapper.DictionarydetailMapper;
|
|
|
+import com.xjrsoft.module.system.mapper.DictionaryitemMapper;
|
|
|
+import com.xjrsoft.module.veb.entity.InternshipPlanManage;
|
|
|
+import com.xjrsoft.module.veb.entity.InternshipPlanManageParticipant;
|
|
|
+import com.xjrsoft.module.veb.entity.TrainingOutside;
|
|
|
+import com.xjrsoft.module.veb.entity.TrainingSchool;
|
|
|
+import com.xjrsoft.module.veb.mapper.InternshipPlanManageMapper;
|
|
|
+import com.xjrsoft.module.veb.mapper.InternshipPlanManageParticipantMapper;
|
|
|
+import com.xjrsoft.module.veb.mapper.TrainingOutsideMapper;
|
|
|
+import com.xjrsoft.module.veb.mapper.TrainingSchoolMapper;
|
|
|
+import com.xjrsoft.module.veb.service.ImportRubAndHandService;
|
|
|
+import com.xjrsoft.module.veb.vo.BaseCourseSubjectImportVo;
|
|
|
+import com.xjrsoft.module.veb.vo.InternshipPlanImportVo;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.Consumer;
|
|
|
+import java.util.function.Supplier;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 手搓导入
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class ImportRubAndHandServiceImpl implements ImportRubAndHandService {
|
|
|
+
|
|
|
+ private final DictionarydetailMapper dictionarydetailMapper;
|
|
|
+
|
|
|
+ private final DictionaryitemMapper dictionaryitemMapper;
|
|
|
+
|
|
|
+ private final BaseSemesterMapper baseSemesterMapper;
|
|
|
+
|
|
|
+ private final BaseCourseSubjectMapper baseCourseSubjectMapper;
|
|
|
+
|
|
|
+ private final CourseSubjectDetailMapper courseSubjectDetailMapper;
|
|
|
+
|
|
|
+ private final TrainingSchoolMapper trainingSchoolMapper;
|
|
|
+
|
|
|
+ private final TrainingOutsideMapper trainingOutsideMapper;
|
|
|
+
|
|
|
+ private final InternshipPlanManageMapper internshipPlanManageMapper;
|
|
|
+
|
|
|
+ private final InternshipPlanManageParticipantMapper internshipPlanManageParticipantMapper;
|
|
|
+
|
|
|
+ private final UserMapper userMapper;
|
|
|
+
|
|
|
+ private final BaseMajorSetMapper baseMajorSetMapper;
|
|
|
+
|
|
|
+ private final BaseClassMapper baseClassMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String courseSubject(MultipartFile file) throws IOException, IllegalAccessException {
|
|
|
+ List<BaseCourseSubjectImportVo> excelDataList = EasyExcel.read(file.getInputStream()).headRowNumber(1).head(BaseCourseSubjectImportVo.class).sheet().doReadSync();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+
|
|
|
+ List<String> codeList = new ArrayList<>();
|
|
|
+ codeList.add("course_category");
|
|
|
+ codeList.add("course_nature");
|
|
|
+ codeList.add("course_attribute");
|
|
|
+ codeList.add("course_type");
|
|
|
+ codeList.add("subject_quality");
|
|
|
+ codeList.add("course_resource");
|
|
|
+
|
|
|
+ Map<String, String> dictionary = initDictionary(codeList);
|
|
|
+
|
|
|
+ List<BaseCourseSubject> baseCourseSubjects = new ArrayList<>();
|
|
|
+ List<CourseSubjectDetail> courseSubjectDetails = new ArrayList<>();
|
|
|
+ for (int i = 0; i < excelDataList.size(); i++) {
|
|
|
+ BaseCourseSubjectImportVo dto = excelDataList.get(i);
|
|
|
+ if (isRequiredFieldsFilled(dto,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ BaseCourseSubject courseSubject = new BaseCourseSubject();
|
|
|
+ Long id = IdUtil.getSnowflakeNextId();
|
|
|
+ courseSubject.setId(id);
|
|
|
+ courseSubject.setName(dto.getName());
|
|
|
+ courseSubject.setCode(dto.getCode());
|
|
|
+ baseCourseSubjects.add(courseSubject);
|
|
|
+
|
|
|
+ CourseSubjectDetail courseSubjectDetail = BeanUtil.toBean(dto, CourseSubjectDetail.class);
|
|
|
+ courseSubjectDetail.setBaseCourseSubjectId(courseSubject.getId());
|
|
|
+
|
|
|
+ // 验证字段的合理性
|
|
|
+ // 字典类型
|
|
|
+ if (validateAndSetDictionaryField(dto::getCourseCategory,
|
|
|
+ "course_category",
|
|
|
+ "课程类别",
|
|
|
+ dictionary,
|
|
|
+ courseSubjectDetail::setCourseCategory,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(dto::getCourseNature,
|
|
|
+ "course_nature",
|
|
|
+ "课程性质",
|
|
|
+ dictionary,
|
|
|
+ courseSubjectDetail::setCourseNature,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(dto::getCourseAttribute,
|
|
|
+ "course_attribute",
|
|
|
+ "课程属性",
|
|
|
+ dictionary,
|
|
|
+ courseSubjectDetail::setCourseAttribute,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(dto::getCourseType,
|
|
|
+ "course_type",
|
|
|
+ "课程分类",
|
|
|
+ dictionary,
|
|
|
+ courseSubjectDetail::setCourseType,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(dto::getSubjectQuality,
|
|
|
+ "subject_quality",
|
|
|
+ "学科类别",
|
|
|
+ dictionary,
|
|
|
+ courseSubjectDetail::setSubjectQuality,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(dto::getCourseResource,
|
|
|
+ "course_resource",
|
|
|
+ "课堂教学设计主要选用课程资源",
|
|
|
+ dictionary,
|
|
|
+ courseSubjectDetail::setCourseResource,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 布尔类型
|
|
|
+
|
|
|
+ courseSubjectDetails.add(courseSubjectDetail);
|
|
|
+ }
|
|
|
+
|
|
|
+ //批量新增
|
|
|
+ if (!baseCourseSubjects.isEmpty()) {
|
|
|
+ for (BaseCourseSubject baseCourseSubject : baseCourseSubjects) {
|
|
|
+ baseCourseSubjectMapper.insert(baseCourseSubject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!courseSubjectDetails.isEmpty()) {
|
|
|
+ for (CourseSubjectDetail courseSubjectDetail : courseSubjectDetails) {
|
|
|
+ courseSubjectDetailMapper.insert(courseSubjectDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String internshipPlan(MultipartFile file) throws IOException, IllegalAccessException {
|
|
|
+ List<InternshipPlanImportVo> excelDataList = EasyExcel.read(file.getInputStream()).headRowNumber(1).head(InternshipPlanImportVo.class).sheet().doReadSync();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+
|
|
|
+ // 字典
|
|
|
+ List<String> codeList = new ArrayList<>();
|
|
|
+ codeList.add("ins_p_type");
|
|
|
+ codeList.add("insurance_type");
|
|
|
+ codeList.add("participant_type");
|
|
|
+ codeList.add("pr_ent_type");
|
|
|
+ codeList.add("int_where_type");
|
|
|
+ codeList.add("SECTOR");
|
|
|
+ codeList.add("lodging_plan");
|
|
|
+ codeList.add("internship_site_type");
|
|
|
+ codeList.add("unit_source");
|
|
|
+
|
|
|
+ Map<String, String> dictionary = initDictionary(codeList);
|
|
|
+
|
|
|
+ // 学期
|
|
|
+ List<BaseSemester> baseSemesters = baseSemesterMapper.selectList(
|
|
|
+ Wrappers
|
|
|
+ .lambdaQuery(BaseSemester.class)
|
|
|
+ .eq(BaseSemester::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<String, Long> baseSemesterMap = baseSemesters.stream()
|
|
|
+ .collect(Collectors.toMap(BaseSemester::getName, BaseSemester::getId, (o1, o2) -> o1));
|
|
|
+
|
|
|
+ List<TrainingSchool> trainingSchools = trainingSchoolMapper.selectList(
|
|
|
+ Wrappers
|
|
|
+ .lambdaQuery(TrainingSchool.class)
|
|
|
+ .eq(TrainingSchool::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<String, Long> trainingSchoolMap = trainingSchools.stream()
|
|
|
+ .collect(Collectors.toMap(TrainingSchool::getTrainingName, TrainingSchool::getId, (o1, o2) -> o1));
|
|
|
+
|
|
|
+ List<TrainingOutside> trainingOutsides = trainingOutsideMapper.selectList(
|
|
|
+ Wrappers
|
|
|
+ .lambdaQuery(TrainingOutside.class)
|
|
|
+ .eq(TrainingOutside::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<String, Long> trainingOutsideMap = trainingOutsides.stream()
|
|
|
+ .collect(Collectors.toMap(TrainingOutside::getTrainingName, TrainingOutside::getId, (o1, o2) -> o1));
|
|
|
+
|
|
|
+ List<User> users = userMapper.selectList(
|
|
|
+ Wrappers
|
|
|
+ .lambdaQuery(User.class)
|
|
|
+ .eq(User::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<String, Long> userMap = users.stream()
|
|
|
+ .collect(Collectors.toMap(User::getName, User::getId, (o1, o2) -> o1));
|
|
|
+
|
|
|
+ List<BaseMajorSet> baseMajors = baseMajorSetMapper.selectList(
|
|
|
+ Wrappers
|
|
|
+ .lambdaQuery(BaseMajorSet.class)
|
|
|
+ .eq(BaseMajorSet::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<String, Long> baseMajorMap = baseMajors.stream()
|
|
|
+ .collect(Collectors.toMap(BaseMajorSet::getName, BaseMajorSet::getId, (o1, o2) -> o1));
|
|
|
+
|
|
|
+ List<BaseClass> baseClasses = baseClassMapper.selectList(
|
|
|
+ Wrappers
|
|
|
+ .lambdaQuery(BaseClass.class)
|
|
|
+ .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<String, Long> baseClassMap = baseClasses.stream()
|
|
|
+ .collect(Collectors.toMap(BaseClass::getName, BaseClass::getId, (o1, o2) -> o1));
|
|
|
+
|
|
|
+ Map<String, InternshipPlanManage> internshipPlanManageMap = new HashMap<>();
|
|
|
+ List<InternshipPlanManageParticipant> internshipPlanManageParticipants = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < excelDataList.size(); i++) {
|
|
|
+ InternshipPlanImportVo vo = excelDataList.get(i);
|
|
|
+
|
|
|
+ if (isRequiredFieldsFilled(vo,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理主表
|
|
|
+ String key = vo.getBaseSemester() +
|
|
|
+ vo.getInternshipPlanName() +
|
|
|
+ vo.getTrainingBaseName() +
|
|
|
+ vo.getStartTime() +
|
|
|
+ vo.getInternshipUnitName();
|
|
|
+
|
|
|
+ Long id = IdUtil.getSnowflakeNextId();
|
|
|
+ if (!internshipPlanManageMap.containsKey(key)) {
|
|
|
+ InternshipPlanManage internshipPlanManage = BeanUtil.toBean(vo, InternshipPlanManage.class);
|
|
|
+ internshipPlanManage.setId(id);
|
|
|
+ if (validateAndSetString2LongField(vo::getBaseSemester,
|
|
|
+ "学期",
|
|
|
+ baseSemesterMap,
|
|
|
+ internshipPlanManage::setBaseSemesterId,
|
|
|
+ sb,
|
|
|
+ i
|
|
|
+ )) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(vo::getInternshipPlanType,
|
|
|
+ "participant_type",
|
|
|
+ "实习类别",
|
|
|
+ dictionary,
|
|
|
+ internshipPlanManage::setInternshipPlanType,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetString2LongField(vo::getTrainingBaseName,
|
|
|
+ "实训基地名称",
|
|
|
+ trainingSchoolMap,
|
|
|
+ internshipPlanManage::setTrainingBaseId,
|
|
|
+ sb,
|
|
|
+ i
|
|
|
+ ) && (validateAndSetString2LongField(vo::getTrainingBaseName,
|
|
|
+ "实训基地名称",
|
|
|
+ trainingOutsideMap,
|
|
|
+ internshipPlanManage::setTrainingBaseId,
|
|
|
+ sb,
|
|
|
+ i
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(vo::getInsurancePurchaser,
|
|
|
+ "ins_p_type",
|
|
|
+ "保险购买方",
|
|
|
+ dictionary,
|
|
|
+ internshipPlanManage::setInsurancePurchaser,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(vo::getInternshipWhereabouts,
|
|
|
+ "int_where_type",
|
|
|
+ "实习去向",
|
|
|
+ dictionary,
|
|
|
+ internshipPlanManage::setInternshipWhereabouts,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(vo::getInsuranceType,
|
|
|
+ "insurance_type",
|
|
|
+ "购买保险种类",
|
|
|
+ dictionary,
|
|
|
+ internshipPlanManage::setInsuranceType,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(vo::getEnterpriseIndustry,
|
|
|
+ "SECTOR",
|
|
|
+ "企业所属行业",
|
|
|
+ dictionary,
|
|
|
+ internshipPlanManage::setInsuranceType,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(vo::getInternshipSiteType,
|
|
|
+ "internship_site_type",
|
|
|
+ "实习场所类型",
|
|
|
+ dictionary,
|
|
|
+ internshipPlanManage::setInternshipSiteType,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(vo::getInternshipUnitSource,
|
|
|
+ "unit_source",
|
|
|
+ "实习单位来源",
|
|
|
+ dictionary,
|
|
|
+ internshipPlanManage::setInternshipUnitSource,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(vo::getLodgingPlan,
|
|
|
+ "lodging_plan",
|
|
|
+ "住宿安排",
|
|
|
+ dictionary,
|
|
|
+ internshipPlanManage::setLodgingPlan,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (validateAndSetDictionaryField(vo::getProfessionalRelevanceEnterprise,
|
|
|
+ "pr_ent_type",
|
|
|
+ "专业对口程度",
|
|
|
+ dictionary,
|
|
|
+ internshipPlanManage::setProfessionalRelevanceEnterprise,
|
|
|
+ sb,
|
|
|
+ i)) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+ internshipPlanManageMap.put(key, internshipPlanManage);
|
|
|
+ } else {
|
|
|
+ InternshipPlanManage internshipPlanManage = internshipPlanManageMap.get(key);
|
|
|
+ id = internshipPlanManage.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理子表
|
|
|
+ InternshipPlanManageParticipant internshipPlanManageParticipant = BeanUtil.toBean(vo, InternshipPlanManageParticipant.class);
|
|
|
+ internshipPlanManageParticipant.setInternshipPlanManageId(id);
|
|
|
+ if (validateAndSetString2LongField(vo::getParticipantUserName,
|
|
|
+ "实习参与人姓名",
|
|
|
+ userMap,
|
|
|
+ internshipPlanManageParticipant::setParticipantUserId,
|
|
|
+ sb,
|
|
|
+ i
|
|
|
+ )) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+ if (validateAndSetString2LongField(vo::getBaseMajorName,
|
|
|
+ "所属专业名称",
|
|
|
+ baseMajorMap,
|
|
|
+ internshipPlanManageParticipant::setBaseMajorId,
|
|
|
+ sb,
|
|
|
+ i
|
|
|
+ )) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+ if (validateAndSetString2LongField(vo::getClassName,
|
|
|
+ "班级名称",
|
|
|
+ baseClassMap,
|
|
|
+ internshipPlanManageParticipant::setClassId,
|
|
|
+ sb,
|
|
|
+ i
|
|
|
+ )) {
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+ internshipPlanManageParticipants.add(internshipPlanManageParticipant);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<InternshipPlanManage> internshipPlanManages = new ArrayList<>(internshipPlanManageMap.values());
|
|
|
+ //批量新增
|
|
|
+ if (!internshipPlanManages.isEmpty()) {
|
|
|
+ for (InternshipPlanManage internshipPlanManage : internshipPlanManages) {
|
|
|
+ internshipPlanManageMapper.insert(internshipPlanManage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!internshipPlanManageParticipants.isEmpty()) {
|
|
|
+ for (InternshipPlanManageParticipant internshipPlanManageParticipant : internshipPlanManageParticipants) {
|
|
|
+ internshipPlanManageParticipantMapper.insert(internshipPlanManageParticipant);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateAndSetString2LongField(Supplier<String> getter,
|
|
|
+ String fieldName,
|
|
|
+ Map<String, Long> string2Long,
|
|
|
+ Consumer<Long> setter,
|
|
|
+ StringBuilder sb, int i) {
|
|
|
+ String value = getter.get();
|
|
|
+ if (value != null && !value.trim().isEmpty()) {
|
|
|
+ Long sublistValue = string2Long.get(value);
|
|
|
+ if (sublistValue != null) {
|
|
|
+ setter.accept(sublistValue);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ sb.append("第");
|
|
|
+ sb.append(i + 2);
|
|
|
+ sb.append("行的");
|
|
|
+ sb.append(fieldName);
|
|
|
+ sb.append("列的值不存在于系统对应基础数据中,请到基础数据维护");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false; // 字段为空,不进行验证
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateAndSetBooleanField(Supplier<String> getter,
|
|
|
+ String fieldName,
|
|
|
+ Consumer<Integer> setter,
|
|
|
+ StringBuilder sb, int i) {
|
|
|
+ String value = getter.get();
|
|
|
+ if (value != null && !value.trim().isEmpty()) {
|
|
|
+ Integer booleanValue = YesOrNoEnum.getCode(value);
|
|
|
+ if (booleanValue != null) {
|
|
|
+ setter.accept(booleanValue);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ sb.append("第");
|
|
|
+ sb.append(i + 2);
|
|
|
+ sb.append("行的");
|
|
|
+ sb.append(fieldName);
|
|
|
+ sb.append("列的值不符合,该列的值只能为是或否");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false; // 字段为空,不进行验证
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateAndSetDictionaryField(Supplier<String> getter,
|
|
|
+ String prefix,
|
|
|
+ String fieldName,
|
|
|
+ Map<String, String> dictionary,
|
|
|
+ Consumer<String> setter,
|
|
|
+ StringBuilder sb, int i) {
|
|
|
+ String value = getter.get();
|
|
|
+ if (value != null && !value.trim().isEmpty()) {
|
|
|
+ String dictValue = dictionary.get(prefix + value.trim());
|
|
|
+ if (dictValue != null && !dictValue.trim().isEmpty()) {
|
|
|
+ setter.accept(dictValue.trim());
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ sb.append("第");
|
|
|
+ sb.append(i + 2);
|
|
|
+ sb.append("行的");
|
|
|
+ sb.append(fieldName);
|
|
|
+ sb.append("列的值不存在于字典中,请到字典中维护");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false; // 字段为空,不进行验证
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> initDictionary(List<String> codeList) {
|
|
|
+ List<DictionaryDetail> detailList = dictionarydetailMapper.selectJoinList(DictionaryDetail.class,
|
|
|
+ new MPJLambdaWrapper<DictionaryDetail>()
|
|
|
+ .select(DictionaryDetail::getId)
|
|
|
+ .select(DictionaryDetail.class, x -> VoToColumnUtil.fieldsToColumns(DictionaryDetail.class).contains(x.getProperty()))
|
|
|
+ .leftJoin(DictionaryItem.class, DictionaryItem::getId, DictionaryDetail::getItemId)
|
|
|
+ .in(DictionaryItem::getCode, codeList)
|
|
|
+ );
|
|
|
+
|
|
|
+ List<DictionaryItem> dictionaryItemList = dictionaryitemMapper.selectList(
|
|
|
+ new QueryWrapper<DictionaryItem>().lambda()
|
|
|
+ .eq(DictionaryItem::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<Long, String> itemMap = new HashMap<>();
|
|
|
+ for (DictionaryItem dictionaryItem : dictionaryItemList) {
|
|
|
+ itemMap.put(dictionaryItem.getId(), dictionaryItem.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> resultMap = new HashMap<>();
|
|
|
+ for (DictionaryDetail dictionaryDetail : detailList) {
|
|
|
+ resultMap.put(itemMap.get(dictionaryDetail.getItemId()) + dictionaryDetail.getName(), dictionaryDetail.getCode());
|
|
|
+ }
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isRequiredFieldsFilled(Object instance,
|
|
|
+ StringBuilder sb,
|
|
|
+ int i)
|
|
|
+ throws IllegalAccessException {
|
|
|
+ if (instance == null) {
|
|
|
+ return true; // 如果对象本身为 null,则认为没有通过验证
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Field field : instance.getClass().getDeclaredFields()) {
|
|
|
+ Required required = field.getAnnotation(Required.class);
|
|
|
+ if (required != null) { // 如果字段被 @Required 标记
|
|
|
+ field.setAccessible(true); // 允许访问私有字段
|
|
|
+ Object value = field.get(instance); // 获取字段的值
|
|
|
+ if (value == null || (value instanceof String && ((String) value).trim().isEmpty())) {
|
|
|
+ sb.append("第");
|
|
|
+ sb.append(i + 2);
|
|
|
+ sb.append("行的");
|
|
|
+ if (field.isAnnotationPresent(ExcelProperty.class)) {
|
|
|
+ ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
|
|
|
+ String[] annotationValues = excelProperty.value();
|
|
|
+ sb.append(annotationValues.length > 0 ? annotationValues[0] : "");
|
|
|
+ }
|
|
|
+ sb.append("列的值为必填");
|
|
|
+ return true; // 如果任何必需字段为空,则返回 true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false; // 所有必需字段都不为空
|
|
|
+ }
|
|
|
+}
|