bt-yjj-system-examination-s.../src/main/java/cn/com/tenlion/util/ImportExcelHelper.java
2021-06-19 17:32:49 +08:00

202 lines
7.3 KiB
Java

package cn.com.tenlion.util;
import cn.com.tenlion.dao.excel.IExcelDao;
import cn.com.tenlion.pojo.dtos.classplan.ClassPlanDTO;
import cn.com.tenlion.pojo.model.ApplyStudentsModel;
import cn.com.tenlion.pojo.model.ApplyStudentsNewModel;
import cn.com.tenlion.service.classplan.IClassPlanService;
import cn.com.tenlion.service.handleimportexcel.IHandleImportExcelService;
import cn.com.tenlion.staff.dao.basicstaffinfo.IBasicStaffInfoDao;
import cn.com.tenlion.staff.pojo.dtos.basicstaffinfo.BasicStaffInfoDTO;
import com.alibaba.excel.context.AnalysisContext;
import ink.wgink.exceptions.SaveException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 导入excel数据的校验类
* @author renpc
*/
@Component
public class ImportExcelHelper {
@Autowired
private IHandleImportExcelService handleImportExcelService;
private static IClassPlanService classPlanService;
private static IBasicStaffInfoDao basicStaffInfoDao;
@Autowired
public void init(IClassPlanService classPlanService) {
ImportExcelHelper.classPlanService = classPlanService;
}
@Autowired
public void init(IBasicStaffInfoDao basicStaffInfoDao) {
ImportExcelHelper.basicStaffInfoDao = basicStaffInfoDao;
}
/**
* excelDao
*/
private static IExcelDao excelDao;
@Autowired
public void init(IExcelDao excelDao) {
ImportExcelHelper.excelDao = excelDao;
}
public static <T> String checkDataValid(T obj, AnalysisContext analysisContext) {
if(null == obj) {
return null;
}
String returnStr = isMustInput(obj, analysisContext);
return returnStr;
}
/**
* 检查数据是否必填项缺失
* @param obj
* @param <T>
* @return
*/
private static <T> String isMustInput(T obj, AnalysisContext analysisContext) {
// 考试成绩旧
if(obj instanceof ApplyStudentsModel) {
Object temp = obj;
ApplyStudentsModel applyStudentsModel = (ApplyStudentsModel) temp;
return checkApplyStudentsData(applyStudentsModel);
}
// 考试成绩新
if(obj instanceof ApplyStudentsNewModel) {
Object temp = obj;
ApplyStudentsNewModel applyStudentsNewModel = (ApplyStudentsNewModel) temp;
return checkApplyStudentsNewData(applyStudentsNewModel, analysisContext);
}
return "";
}
/**
* 从数据库比对数据,并转换为数据库数据
* @param obj
* @param <T>
*/
public static <T> void checkDataFromDatabase(T obj, String workType, String examType) {
// 考试成绩旧
if(obj instanceof ApplyStudentsModel) {
Object temp = obj;
ApplyStudentsModel applyStudentsModel = (ApplyStudentsModel) temp;
applyStudentsCheck(applyStudentsModel);
temp = applyStudentsModel;
obj = (T) temp;
}
// 考试成绩新
if(obj instanceof ApplyStudentsNewModel) {
Object temp = obj;
ApplyStudentsNewModel applyStudentsNewModel = (ApplyStudentsNewModel) temp;
applyStudentsNewCheck(applyStudentsNewModel, workType, examType);
temp = applyStudentsNewModel;
obj = (T) temp;
}
}
/**
* 检查数据是否必填项缺失(考生成绩)旧
* @param applyStudentsModel
* @return
*/
private static String checkApplyStudentsData(ApplyStudentsModel applyStudentsModel) {
if(StringUtils.isEmpty(applyStudentsModel.getPlanNumber())) {
return "班号必填";
}
if(StringUtils.isEmpty(applyStudentsModel.getUserName())) {
return "考生姓名必填";
}
if(StringUtils.isEmpty(applyStudentsModel.getCardNumber())) {
return "考生身份证号码必填";
}
if(StringUtils.isEmpty(applyStudentsModel.getScore())) {
return "考生成绩必填";
}
return "";
}
/**
* 检查数据是否必填项缺失(考生成绩)新
* @param applyStudentsNewModel
* @return
*/
private static String checkApplyStudentsNewData(ApplyStudentsNewModel applyStudentsNewModel, AnalysisContext analysisContext) {
if(StringUtils.isEmpty(applyStudentsNewModel.getName())) {
return "姓名必填";
}
if(StringUtils.isEmpty(applyStudentsNewModel.getSex())) {
return "性别必填";
}
if(StringUtils.isEmpty(applyStudentsNewModel.getCardNumber())) {
return "身份证号码必填";
}
if(StringUtils.isEmpty(applyStudentsNewModel.getPhone())) {
return "移动电话必填";
}
if(StringUtils.isEmpty(applyStudentsNewModel.getExamOrgName())) {
return "考试机构必填";
}
if(analysisContext.readRowHolder().getCellMap().size() == 14) {
// 申请发证状态
applyStudentsNewModel.setApplyPaperStatus(applyStudentsNewModel.getHandsGrade());
applyStudentsNewModel.setHandsGrade("");
// 补考知识成绩
applyStudentsNewModel.setResitExamGrade(applyStudentsNewModel.getExamGrade());
applyStudentsNewModel.setExamGrade("");
// 知识成绩
applyStudentsNewModel.setExamGrade(applyStudentsNewModel.getHandsPointName());
applyStudentsNewModel.setHandsPointName("");
}
return "";
}
/**
* 从数据库比对数据,并转换为数据库数据(考生成绩)
* @param applyStudentsModel
*/
private static void applyStudentsCheck(ApplyStudentsModel applyStudentsModel) {
Map<String, Object> param = new HashMap<>();
}
/**
* 从数据库比对数据,并转换为数据库数据(考生成绩)
* @param applyStudentsNewModel
*/
private static void applyStudentsNewCheck(ApplyStudentsNewModel applyStudentsNewModel, String workType, String examType) {
Map<String, Object> param = new HashMap<>();
if(StringUtils.isEmpty(workType)) {
throw new SaveException("工种信息不能为空");
}
if(StringUtils.isEmpty(examType)) {
throw new SaveException("考试类型不能为空");
}
applyStudentsNewModel.setWorkType(workType);
applyStudentsNewModel.setExamType(examType);
/*String cardNumber = applyStudentsNewModel.getCardNumber();
applyStudentsNewModel.setClassPlanId(classPlanId);
ClassPlanDTO classPlanDTO = classPlanService.get(classPlanId);
if(null != classPlanDTO) {
applyStudentsNewModel.setOrgId(classPlanDTO.getOrgId());
applyStudentsNewModel.setOrgName(classPlanDTO.getOrgName());
}
param.put("keywords", applyStudentsNewModel.getCardNumber());
List<BasicStaffInfoDTO> basicStaffInfoDTOList = basicStaffInfoDao.list(param);
if(null != basicStaffInfoDTOList && basicStaffInfoDTOList.size() > 0) {
applyStudentsNewModel.setUserId(basicStaffInfoDTOList.get(0).getBindUserAccount());
applyStudentsNewModel.setCardType(basicStaffInfoDTOList.get(0).getCardType());
}*/
}
}