2021-05-24 09:25:57 +08:00
|
|
|
|
package cn.com.tenlion.util;
|
|
|
|
|
|
|
|
|
|
import cn.com.tenlion.dao.excel.IExcelDao;
|
2021-06-03 19:05:55 +08:00
|
|
|
|
import cn.com.tenlion.pojo.dtos.classplan.ClassPlanDTO;
|
2021-06-01 19:17:13 +08:00
|
|
|
|
import cn.com.tenlion.pojo.model.ApplyStudentsModel;
|
2021-06-03 19:05:55 +08:00
|
|
|
|
import cn.com.tenlion.pojo.model.ApplyStudentsNewModel;
|
|
|
|
|
import cn.com.tenlion.service.classplan.IClassPlanService;
|
2021-05-24 09:25:57 +08:00
|
|
|
|
import cn.com.tenlion.service.handleimportexcel.IHandleImportExcelService;
|
2021-06-08 11:09:52 +08:00
|
|
|
|
import cn.com.tenlion.staff.dao.basicstaffinfo.IBasicStaffInfoDao;
|
|
|
|
|
import cn.com.tenlion.staff.pojo.dtos.basicstaffinfo.BasicStaffInfoDTO;
|
2021-06-03 19:05:55 +08:00
|
|
|
|
import com.alibaba.excel.context.AnalysisContext;
|
|
|
|
|
import ink.wgink.exceptions.SaveException;
|
2021-05-24 09:25:57 +08:00
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
2021-06-08 11:09:52 +08:00
|
|
|
|
import java.util.List;
|
2021-05-24 09:25:57 +08:00
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导入excel数据的校验类
|
|
|
|
|
* @author renpc
|
|
|
|
|
*/
|
|
|
|
|
@Component
|
|
|
|
|
public class ImportExcelHelper {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IHandleImportExcelService handleImportExcelService;
|
2021-06-03 19:05:55 +08:00
|
|
|
|
private static IClassPlanService classPlanService;
|
2021-06-08 11:09:52 +08:00
|
|
|
|
private static IBasicStaffInfoDao basicStaffInfoDao;
|
2021-06-03 19:05:55 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
public void init(IClassPlanService classPlanService) {
|
|
|
|
|
ImportExcelHelper.classPlanService = classPlanService;
|
|
|
|
|
}
|
2021-06-08 11:09:52 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
public void init(IBasicStaffInfoDao basicStaffInfoDao) {
|
|
|
|
|
ImportExcelHelper.basicStaffInfoDao = basicStaffInfoDao;
|
|
|
|
|
}
|
2021-05-24 09:25:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* excelDao
|
|
|
|
|
*/
|
|
|
|
|
private static IExcelDao excelDao;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
public void init(IExcelDao excelDao) {
|
|
|
|
|
ImportExcelHelper.excelDao = excelDao;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 19:05:55 +08:00
|
|
|
|
public static <T> String checkDataValid(T obj, AnalysisContext analysisContext) {
|
2021-05-24 09:25:57 +08:00
|
|
|
|
if(null == obj) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-06-03 19:05:55 +08:00
|
|
|
|
String returnStr = isMustInput(obj, analysisContext);
|
2021-05-24 09:25:57 +08:00
|
|
|
|
return returnStr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查数据是否必填项缺失
|
|
|
|
|
* @param obj
|
|
|
|
|
* @param <T>
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2021-06-03 19:05:55 +08:00
|
|
|
|
private static <T> String isMustInput(T obj, AnalysisContext analysisContext) {
|
|
|
|
|
// 考试成绩旧
|
2021-05-24 09:25:57 +08:00
|
|
|
|
if(obj instanceof ApplyStudentsModel) {
|
|
|
|
|
Object temp = obj;
|
2021-06-03 19:05:55 +08:00
|
|
|
|
ApplyStudentsModel applyStudentsModel = (ApplyStudentsModel) temp;
|
|
|
|
|
return checkApplyStudentsData(applyStudentsModel);
|
|
|
|
|
}
|
|
|
|
|
// 考试成绩新
|
|
|
|
|
if(obj instanceof ApplyStudentsNewModel) {
|
|
|
|
|
Object temp = obj;
|
|
|
|
|
ApplyStudentsNewModel applyStudentsNewModel = (ApplyStudentsNewModel) temp;
|
|
|
|
|
return checkApplyStudentsNewData(applyStudentsNewModel, analysisContext);
|
2021-05-24 09:25:57 +08:00
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从数据库比对数据,并转换为数据库数据
|
|
|
|
|
* @param obj
|
|
|
|
|
* @param <T>
|
|
|
|
|
*/
|
2021-06-19 17:32:49 +08:00
|
|
|
|
public static <T> void checkDataFromDatabase(T obj, String workType, String examType) {
|
2021-06-03 19:05:55 +08:00
|
|
|
|
// 考试成绩旧
|
2021-05-24 09:25:57 +08:00
|
|
|
|
if(obj instanceof ApplyStudentsModel) {
|
|
|
|
|
Object temp = obj;
|
|
|
|
|
ApplyStudentsModel applyStudentsModel = (ApplyStudentsModel) temp;
|
|
|
|
|
applyStudentsCheck(applyStudentsModel);
|
|
|
|
|
temp = applyStudentsModel;
|
|
|
|
|
obj = (T) temp;
|
|
|
|
|
}
|
2021-06-03 19:05:55 +08:00
|
|
|
|
// 考试成绩新
|
|
|
|
|
if(obj instanceof ApplyStudentsNewModel) {
|
|
|
|
|
Object temp = obj;
|
|
|
|
|
ApplyStudentsNewModel applyStudentsNewModel = (ApplyStudentsNewModel) temp;
|
2021-06-19 17:32:49 +08:00
|
|
|
|
applyStudentsNewCheck(applyStudentsNewModel, workType, examType);
|
2021-06-03 19:05:55 +08:00
|
|
|
|
temp = applyStudentsNewModel;
|
|
|
|
|
obj = (T) temp;
|
|
|
|
|
}
|
2021-05-24 09:25:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-03 19:05:55 +08:00
|
|
|
|
* 检查数据是否必填项缺失(考生成绩)旧
|
2021-05-24 09:25:57 +08:00
|
|
|
|
* @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 "";
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 19:05:55 +08:00
|
|
|
|
/**
|
|
|
|
|
* 检查数据是否必填项缺失(考生成绩)新
|
|
|
|
|
* @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 "";
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-24 09:25:57 +08:00
|
|
|
|
/**
|
|
|
|
|
* 从数据库比对数据,并转换为数据库数据(考生成绩)
|
|
|
|
|
* @param applyStudentsModel
|
|
|
|
|
*/
|
|
|
|
|
private static void applyStudentsCheck(ApplyStudentsModel applyStudentsModel) {
|
|
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 19:05:55 +08:00
|
|
|
|
/**
|
|
|
|
|
* 从数据库比对数据,并转换为数据库数据(考生成绩)
|
|
|
|
|
* @param applyStudentsNewModel
|
|
|
|
|
*/
|
2021-06-19 17:32:49 +08:00
|
|
|
|
private static void applyStudentsNewCheck(ApplyStudentsNewModel applyStudentsNewModel, String workType, String examType) {
|
2021-06-03 19:05:55 +08:00
|
|
|
|
Map<String, Object> param = new HashMap<>();
|
2021-06-19 17:32:49 +08:00
|
|
|
|
if(StringUtils.isEmpty(workType)) {
|
|
|
|
|
throw new SaveException("工种信息不能为空");
|
2021-06-03 19:05:55 +08:00
|
|
|
|
}
|
2021-06-19 17:32:49 +08:00
|
|
|
|
if(StringUtils.isEmpty(examType)) {
|
|
|
|
|
throw new SaveException("考试类型不能为空");
|
|
|
|
|
}
|
|
|
|
|
applyStudentsNewModel.setWorkType(workType);
|
|
|
|
|
applyStudentsNewModel.setExamType(examType);
|
|
|
|
|
/*String cardNumber = applyStudentsNewModel.getCardNumber();
|
2021-06-03 19:05:55 +08:00
|
|
|
|
applyStudentsNewModel.setClassPlanId(classPlanId);
|
|
|
|
|
ClassPlanDTO classPlanDTO = classPlanService.get(classPlanId);
|
|
|
|
|
if(null != classPlanDTO) {
|
|
|
|
|
applyStudentsNewModel.setOrgId(classPlanDTO.getOrgId());
|
|
|
|
|
applyStudentsNewModel.setOrgName(classPlanDTO.getOrgName());
|
|
|
|
|
}
|
2021-06-08 11:09:52 +08:00
|
|
|
|
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());
|
2021-06-19 17:32:49 +08:00
|
|
|
|
}*/
|
2021-06-03 19:05:55 +08:00
|
|
|
|
}
|
2021-05-24 09:25:57 +08:00
|
|
|
|
|
|
|
|
|
}
|