/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the yifu4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */
package com.yifu.cloud.plus.v1.yifu.archives.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ArrayUtil;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.read.metadata.holder.ReadRowHolder;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.archives.entity.*;
import com.yifu.cloud.plus.v1.yifu.archives.mapper.TPreEmpMainMapper;
import com.yifu.cloud.plus.v1.yifu.archives.service.*;
import com.yifu.cloud.plus.v1.yifu.archives.vo.*;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.SecurityConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.*;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.compress.utils.Lists;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.stereotype.Service;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.*;

/**
 * 预入职-主表
 *
 * @author hgw
 * @date 2024-06-17 11:31:08
 */
@Log4j2
@AllArgsConstructor
@Service
public class TPreEmpMainServiceImpl extends ServiceImpl<TPreEmpMainMapper, TPreEmpMain> implements TPreEmpMainService {
	// 预入职-员工不良记录表
	private final TPreEmpBadRecordService tPreEmpBadRecordService;
	// 预入职-员工工作履历信息表
	private final TPreEmpWorkRecordingService tPreEmpWorkRecordingService;
	// 预入职-紧急联络人
	private final TPreEmpContactInfoService tPreEmpContactInfoService;
	// 预入职-员工申明
	private final TPreEmpDeclarationService tPreEmpDeclarationService;
	// 预入职-员工伤残信息表
	private final TPreEmpDisabilityInfoService tPreEmpDisabilityInfoService;
	// 预入职-员工学历信息表
	private final TPreEmpEducationService tPreEmpEducationService;
	// 预入职-员工家庭信息表
	private final TPreEmpFamilyService tPreEmpFamilyService;
	// 预入职-人员档案表
	private final TPreEmployeeInfoService tPreEmployeeInfoService;
	// 预入职-项目档案表
	private final TPreEmployeeProjectService tPreEmployeeProjectService;
	// 预入职-员工职业资格信息表
	private final TPreEmpProfessionalQualificationService tPreEmpProfessionalService;
	// 附件21（预入职申明签名）；22（预入职确认签名）；23（预入职pdf文件)
	private final TAttaInfoService tAttaInfoService;

	// 档案相关服务：
	// 预入职-员工不良记录表
	private final TEmpBadRecordService tEmpBadRecordService;
	// 预入职-员工工作履历信息表
	private final TEmpWorkRecordingService tEmpWorkRecordingService;
	// 预入职-紧急联络人
	private final TEmpContactInfoService tEmpContactInfoService;
	// 预入职-员工伤残信息表
	private final TEmpDisabilityInfoService tEmpDisabilityInfoService;
	// 预入职-员工学历信息表
	private final TEmpEducationService tEmpEducationService;
	// 预入职-员工家庭信息表
	private final TEmpFamilyService tEmpFamilyService;
	// 预入职-人员档案表
	private final TEmployeeInfoService tEmployeeInfoService;
	// 预入职-项目档案表
	private final TEmployeeProjectService tEmployeeProjectService;
	// 预入职-员工职业资格信息表
	private final TEmpProfessionalQualificationService tEmpProfessionalService;
	// 项目
	private final TSettleDomainService tSettleDomainService;
	// 审核日志
	private final TPreEmpMainLogService tPreEmpMainLogService;

	private final OSSUtil ossUtil;

	private final static String ID = "id";
	/**
	 * 预入职-主表简单分页查询
	 *
	 * @param tPreEmpMain 预入职-主表
	 * @return
	 */
	@Override
	public IPage<TPreEmpMain> getTPreEmpMainPage(Page<TPreEmpMain> page, TPreEmpMainSearchVo tPreEmpMain) {
		return baseMapper.getTPreEmpMainPage(page, tPreEmpMain);
	}

	/**
	 * @Description: 详情
	 * @Author: hgw
	 * @Date: 2024/6/17 17:19
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<com.yifu.cloud.plus.v1.yifu.archives.vo.PreEmpMainDetailVo>
	 **/
	@Override
	public R<PreEmpMainDetailVo> getByCardAndDeptId(String empIdCard, String deptId) {
		TSettleDomain dept = tSettleDomainService.getById(deptId);
		if (dept == null) {
			return R.failed("未找到项目信息！");
		}
		TPreEmpMain main = baseMapper.getTPreEmpMainByCardAndDept(empIdCard, deptId);
		TEmployeeInfo employee = null;
		String empId = null;
		TEmployeeProject project;
		PreEmpMainDetailVo vo = new PreEmpMainDetailVo();
		Set<String> dbAuthsSet = new HashSet<>();
		Collection<? extends GrantedAuthority> authorities = AuthorityUtils
				.createAuthorityList(dbAuthsSet.toArray(new String[0]));
		YifuUser user = new YifuUser("2", 1L, "", "预入职扫码",
				"预入职扫码", "0", SecurityConstants.BCRYPT + "123456",
				"12345678911", true, true, true,
				true,
				"1", authorities, "1",
				null, null,
				null);
		if (main != null && CommonConstants.FIVE_STRING.equals(main.getStatus())) {
			// 清空信息
			if (Common.isNotNull(main.getId())) {
				tPreEmpWorkRecordingService.deleteByMainId(main.getId());
				tPreEmpProfessionalService.deleteProfessionalByMainId(main.getId());
				tAttaInfoService.deleteByDomainId(main.getId());
			}
			baseMapper.deleteById(main);
			main = null;
		}
		if (main != null) {
			if (CommonConstants.ONE_STRING.equals(main.getStatus())
					|| CommonConstants.TWO_STRING.equals(main.getStatus())
					|| CommonConstants.FOUR_STRING.equals(main.getStatus())) {
				return R.failed("信息已填写，请勿重复操作！");
			}
			TPreEmployeeInfo tPreEmployeeInfo = tPreEmployeeInfoService.getTPreEmployeeInfoList(main.getId());
			if (tPreEmployeeInfo != null && Common.isNotNull(tPreEmployeeInfo.getId())) {
				empId = tPreEmployeeInfo.getId();
				vo.setTpreEmployeeInfo(tPreEmployeeInfo);
			} else {
				tPreEmployeeInfo = new TPreEmployeeInfo();
				tPreEmployeeInfo.setEmpIdcard(main.getEmpIdcard());
				tPreEmployeeInfo.setEmpName(main.getEmpName());
				tPreEmployeeInfo.setPreMainId(main.getId());
				tPreEmployeeInfo.setCreateBy(user.getId());
				tPreEmployeeInfo.setCreateName(user.getNickname());
				tPreEmployeeInfo.setCreateTime(LocalDateTime.now());
				tPreEmployeeInfoService.save(tPreEmployeeInfo);
				vo.setTpreEmployeeInfo(tPreEmployeeInfo);
			}
			TPreEmployeeProject tPreEmployeeProject = tPreEmployeeProjectService.getTPreEmployeeProjectList(main.getId());
			// 预入职-项目档案表
			if (tPreEmployeeProject != null) {
				vo.setTpreEmployeeProject(tPreEmployeeProject);
			} else {
				tPreEmployeeProject = new TPreEmployeeProject();
				tPreEmployeeProject.setEmpIdcard(main.getEmpIdcard());
				tPreEmployeeProject.setEmpName(main.getEmpName());
				tPreEmployeeProject.setDeptId(main.getDeptId());
				tPreEmployeeProject.setDeptName(main.getDeptName());
				tPreEmployeeProject.setDeptNo(main.getDeptNo());
				tPreEmployeeProject.setPreMainId(main.getId());
				tPreEmployeeProject.setCreateBy(user.getId());
				tPreEmployeeProject.setCreateName(user.getNickname());
				tPreEmployeeProject.setCreateTime(LocalDateTime.now());
				tPreEmployeeProjectService.save(tPreEmployeeProject);
				vo.setTpreEmployeeProject(tPreEmployeeProject);
			}
		} else {
			main = new TPreEmpMain();
			main.setEmpIdcard(empIdCard);
			main.setDeptId(dept.getId());
			main.setDeptName(dept.getDepartName());
			main.setDeptNo(dept.getDepartNo());
			main.setUnitId(dept.getCustomerId());
			main.setUnitName(dept.getCustomerName());
			main.setUnitNo(dept.getCustomerNo());
			main.setBusinessPrimaryType(dept.getBusinessPrimaryType());
			main.setBusinessSecondType(dept.getBusinessSecondType());
			main.setBusinessThirdType(dept.getBusinessThirdType());
			main.setStatus(CommonConstants.FIVE_STRING);
			// 预入职-员工申明
			TPreEmpDeclaration tPreEmpDeclaration;
			if (Common.isNotNull(main.getDeclarationId())) {
				tPreEmpDeclaration = tPreEmpDeclarationService.getById(main.getDeclarationId());
			} else {
				tPreEmpDeclaration = tPreEmpDeclarationService.getTPreEmpDeclarationList();
			}
			vo.setTpreEmpDeclaration(tPreEmpDeclaration);
			main.setDeclarationId(tPreEmpDeclaration.getId());
			this.save(main);
			// 查询档案信息
			employee = tEmployeeInfoService.getInfoByIdcard(empIdCard);
			TPreEmployeeInfo tPreEmployeeInfo;
			TPreEmployeeProject tPreEmployeeProject;
			if (employee != null) {
				empId = employee.getId();
				tPreEmployeeInfo = new TPreEmployeeInfo();
				BeanUtil.copyProperties(employee, tPreEmployeeInfo, ID);
				tPreEmployeeInfo.setOldId(employee.getId());
				tPreEmployeeInfo.setPreMainId(main.getId());
				tPreEmployeeInfo.setCreateBy(user.getId());
				tPreEmployeeInfo.setCreateName(user.getNickname());
				tPreEmployeeInfo.setCreateTime(LocalDateTime.now());
				tPreEmployeeInfoService.saveOrUpdate(tPreEmployeeInfo);
				vo.setTpreEmployeeInfo(tPreEmployeeInfo);
				project = tEmployeeProjectService.getByEmpIdAndDeptId(empId, deptId);
				if (project != null) {
					tPreEmployeeProject = new TPreEmployeeProject();
					BeanUtil.copyProperties(project, tPreEmployeeProject, ID);
					tPreEmployeeProject.setOldId(project.getId());
					tPreEmployeeProject.setPreMainId(main.getId());
					tPreEmployeeProject.setCreateBy(user.getId());
					tPreEmployeeProject.setCreateName(user.getNickname());
					tPreEmployeeProject.setCreateTime(LocalDateTime.now());
					tPreEmployeeProjectService.saveOrUpdate(tPreEmployeeProject);
					vo.setTpreEmployeeProject(tPreEmployeeProject);
				}
			} else {
				tPreEmployeeInfo = new TPreEmployeeInfo();
				tPreEmployeeInfo.setEmpIdcard(main.getEmpIdcard());
				tPreEmployeeInfo.setPreMainId(main.getId());
				tPreEmployeeInfo.setCreateBy(user.getId());
				tPreEmployeeInfo.setCreateName(user.getNickname());
				tPreEmployeeInfo.setCreateTime(LocalDateTime.now());
				tPreEmployeeInfoService.save(tPreEmployeeInfo);
				vo.setTpreEmployeeInfo(tPreEmployeeInfo);
				tPreEmployeeProject = new TPreEmployeeProject();
				tPreEmployeeProject.setEmpIdcard(main.getEmpIdcard());
				tPreEmployeeProject.setDeptId(main.getDeptId());
				tPreEmployeeProject.setDeptName(main.getDeptName());
				tPreEmployeeProject.setDeptNo(main.getDeptNo());
				tPreEmployeeProject.setPreMainId(main.getId());
				tPreEmployeeProject.setCreateBy(user.getId());
				tPreEmployeeProject.setCreateName(user.getNickname());
				tPreEmployeeProject.setCreateTime(LocalDateTime.now());
				tPreEmployeeProjectService.save(tPreEmployeeProject);
				vo.setTpreEmployeeProject(tPreEmployeeProject);
			}
		}
		String id = main.getId();
		vo.setMain(main);
		// 预入职-员工不良记录表
		TPreEmpBadRecord tPreEmpBadRecord = tPreEmpBadRecordService.getTPreEmpBadRecordList(id);
		if (tPreEmpBadRecord == null) {
			tPreEmpBadRecord = new TPreEmpBadRecord();
			if (Common.isNotNull(empId)) {
				TEmpBadRecord info = tEmpBadRecordService.getByEmpId(empId);
				if (info != null) {
					BeanUtil.copyProperties(info, tPreEmpBadRecord, ID);
					tPreEmpBadRecord.setEmpId(empId);
					tPreEmpBadRecord.setOldId(info.getId());
				}
			}
			tPreEmpBadRecord.setPreMainId(id);
			tPreEmpBadRecord.setSettleDomain(deptId);
			tPreEmpBadRecord.setProject(dept.getDepartName());
			tPreEmpBadRecord.setProjectCode(dept.getDepartNo());
			tPreEmpBadRecord.setEmpIdcard(empIdCard);
			tPreEmpBadRecord.setCreateBy(user.getId());
			tPreEmpBadRecord.setCreateName(user.getNickname());
			tPreEmpBadRecord.setCreateTime(LocalDateTime.now());
			tPreEmpBadRecordService.save(tPreEmpBadRecord);
		}
		vo.setTpreEmpBadRecord(tPreEmpBadRecord);
		// 预入职-紧急联络人
		TPreEmpContactInfo tPreEmpContactInfo = tPreEmpContactInfoService.getTPreEmpContactInfoList(id);
		if (tPreEmpContactInfo == null) {
			tPreEmpContactInfo = new TPreEmpContactInfo();
			if (Common.isNotNull(empId)) {
				TEmpContactInfo info = tEmpContactInfoService.getByEmpId(empId);
				if (info != null) {
					BeanUtil.copyProperties(info, tPreEmpContactInfo, ID);
					tPreEmpContactInfo.setEmpId(empId);
					tPreEmpContactInfo.setOldId(info.getId());
				}
			}
			tPreEmpContactInfo.setPreMainId(id);
			tPreEmpContactInfo.setCreateBy(user.getId());
			tPreEmpContactInfo.setCreateName(user.getNickname());
			tPreEmpContactInfo.setCreateTime(LocalDateTime.now());
			tPreEmpContactInfoService.save(tPreEmpContactInfo);
		}
		vo.setTpreEmpContactInfo(tPreEmpContactInfo);
		// 预入职-员工伤残信息表
		TPreEmpDisabilityInfo tPreEmpDisabilityInfo = tPreEmpDisabilityInfoService.getTPreEmpDisabilityInfoList(id);
		if (tPreEmpDisabilityInfo == null) {
			tPreEmpDisabilityInfo = new TPreEmpDisabilityInfo();
			if (Common.isNotNull(empId)) {
				TEmpDisabilityInfo info = tEmpDisabilityInfoService.getByEmpId(empId);
				if (info != null) {
					BeanUtil.copyProperties(info, tPreEmpDisabilityInfo, ID);
					tPreEmpDisabilityInfo.setEmpId(empId);
					tPreEmpDisabilityInfo.setOldId(info.getId());
				}
			}
			tPreEmpDisabilityInfo.setPreMainId(id);
			tPreEmpDisabilityInfo.setSettleDomain(deptId);
			if (employee != null) {
				tPreEmpDisabilityInfo.setEmpId(employee.getId());
				tPreEmpDisabilityInfo.setEmpName(employee.getEmpName());
				tPreEmpDisabilityInfo.setEmpCode(employee.getEmpCode());
			}
			tPreEmpDisabilityInfo.setEmpIdcard(empIdCard);
			tPreEmpDisabilityInfo.setCreateBy(user.getId());
			tPreEmpDisabilityInfo.setCreateName(user.getNickname());
			tPreEmpDisabilityInfo.setCreateTime(LocalDateTime.now());
			tPreEmpDisabilityInfoService.save(tPreEmpDisabilityInfo);
		}
		vo.setTpreEmpDisabilityInfo(tPreEmpDisabilityInfo);
		// 预入职-员工学历信息表
		TPreEmpEducation tPreEmpEducation = tPreEmpEducationService.getTPreEmpEducationList(id);
		if (tPreEmpEducation == null) {
			tPreEmpEducation = new TPreEmpEducation();
			if (Common.isNotNull(empId)) {
				TEmpEducation info = tEmpEducationService.getByEmpId(empId);
				if (info != null) {
					BeanUtil.copyProperties(info, tPreEmpEducation, ID);
					tPreEmpEducation.setEmpId(empId);
					tPreEmpEducation.setOldId(info.getId());

					// 附件
					List<TAttaInfo> attaInfoList = tAttaInfoService.getTAttaInfoListByDoMainId(info.getId());
					if (attaInfoList != null) {
						URL url;
						for (TAttaInfo atta : attaInfoList) {
							url = ossUtil.getObjectUrl(null, atta.getAttaSrc());
							atta.setAttaUrl(String.valueOf(url));
						}
					}
					tPreEmpEducation.setAttaList(attaInfoList);
				}
			}
			tPreEmpEducation.setPreMainId(id);
			tPreEmpEducation.setSettleDomain(deptId);
			if (employee != null) {
				tPreEmpEducation.setEmpId(employee.getId());
				tPreEmpEducation.setEmpName(employee.getEmpName());
				tPreEmpEducation.setEmpCode(employee.getEmpCode());
			}
			tPreEmpEducation.setEmpIdcard(empIdCard);
			tPreEmpEducation.setCreateBy(user.getId());
			tPreEmpEducation.setCreateName(user.getNickname());
			tPreEmpEducation.setCreateTime(LocalDateTime.now());
			tPreEmpEducationService.save(tPreEmpEducation);
		} else {
			// 附件
			List<TAttaInfo> attaInfoList = tAttaInfoService.getTAttaInfoListByDoMainId(tPreEmpEducation.getId());
			if (attaInfoList != null) {
				URL url;
				for (TAttaInfo atta : attaInfoList) {
					url = ossUtil.getObjectUrl(null, atta.getAttaSrc());
					atta.setAttaUrl(String.valueOf(url));
				}
			}
			tPreEmpEducation.setAttaList(attaInfoList);
		}
		vo.setTpreEmpEducation(tPreEmpEducation);
		// 预入职-员工家庭信息表
		List<TPreEmpFamily> tPreEmpFamilyList = tPreEmpFamilyService.getTPreEmpFamilyList(id);
		if (tPreEmpFamilyList == null || tPreEmpFamilyList.isEmpty()) {
			tPreEmpFamilyList = new ArrayList<>();
			if (Common.isNotNull(empId)) {
				List<TEmpFamily> infoList = tEmpFamilyService.getListByEmpId(empId);
				if (infoList != null && !infoList.isEmpty()) {
					TPreEmpFamily record;
					for (TEmpFamily info : infoList) {
						record = new TPreEmpFamily();
						BeanUtil.copyProperties(info, record, ID);
						record.setEmpId(empId);
						record.setOldId(info.getId());
						record.setSettleDomain(deptId);
						if (employee != null) {
							record.setEmpId(employee.getId());
							record.setEmpName(employee.getEmpName());
							record.setEmpCode(employee.getEmpCode());
						}
						record.setEmpIdcard(empIdCard);
						record.setPreMainId(id);
						record.setCreateBy(user.getId());
						record.setCreateName(user.getNickname());
						record.setCreateTime(LocalDateTime.now());
						tPreEmpFamilyList.add(record);
					}
					tPreEmpFamilyService.saveBatch(tPreEmpFamilyList);
				}
			}
			if (tPreEmpFamilyList.isEmpty()) {
				TPreEmpFamily record = new TPreEmpFamily();
				record.setSettleDomain(deptId);
				if (employee != null) {
					record.setEmpId(employee.getId());
					record.setEmpName(employee.getEmpName());
					record.setEmpCode(employee.getEmpCode());
				}
				record.setEmpIdcard(empIdCard);
				record.setPreMainId(id);
				record.setCreateBy(user.getId());
				record.setCreateName(user.getNickname());
				record.setCreateTime(LocalDateTime.now());
				tPreEmpFamilyService.save(record);
				tPreEmpFamilyList.add(record);
			}
		}
		vo.setTpreEmpFamilyList(tPreEmpFamilyList);
		// 预入职-人员档案表
		if (vo.getTpreEmployeeInfo() == null) {
			TPreEmployeeInfo tPreEmployeeInfo = tPreEmployeeInfoService.getTPreEmployeeInfoList(id);
			vo.setTpreEmployeeInfo(tPreEmployeeInfo);
		}
		// 预入职-项目档案表
		if (vo.getTpreEmployeeProject() == null) {
			TPreEmployeeProject tPreEmployeeProject = tPreEmployeeProjectService.getTPreEmployeeProjectList(id);
			vo.setTpreEmployeeProject(tPreEmployeeProject);
		}
		// 预入职-员工职业资格信息表
		List<TPreEmpProfessionalQualification> tPreEmpProfessionalQualificationList = tPreEmpProfessionalService.getTPreEmpProfessionalQualificationList(id);
		if (tPreEmpProfessionalQualificationList == null || tPreEmpProfessionalQualificationList.isEmpty()) {
			tPreEmpProfessionalQualificationList = new ArrayList<>();
			if (Common.isNotNull(empId)) {
				List<TEmpProfessionalQualification> infoList = tEmpProfessionalService.getListByEmpId(empId);
				TPreEmpProfessionalQualification record;
				if (infoList != null && !infoList.isEmpty()) {
					for (TEmpProfessionalQualification info : infoList) {
						record = new TPreEmpProfessionalQualification();
						BeanUtil.copyProperties(info, record, ID);
						record.setEmpId(empId);
						record.setOldId(info.getId());
						record.setSettleDomain(deptId);
						if (employee != null) {
							record.setEmpId(employee.getId());
							record.setEmpName(employee.getEmpName());
							record.setEmpCode(employee.getEmpCode());
						}

						// 附件
						List<TAttaInfo> attaInfoList = tAttaInfoService.getTAttaInfoListByDoMainId(info.getId());
						if (attaInfoList != null) {
							URL url;
							for (TAttaInfo atta : attaInfoList) {
								url = ossUtil.getObjectUrl(null, atta.getAttaSrc());
								atta.setAttaUrl(String.valueOf(url));
							}
						}
						record.setAttaList(attaInfoList);
						record.setPreMainId(id);
						record.setEmpIdcard(empIdCard);
						record.setCreateBy(user.getId());
						record.setCreateName(user.getNickname());
						record.setCreateTime(LocalDateTime.now());
						tPreEmpProfessionalQualificationList.add(record);
					}
					tPreEmpProfessionalService.saveBatch(tPreEmpProfessionalQualificationList);
				}
			}
			if (tPreEmpProfessionalQualificationList.isEmpty()) {
				TPreEmpProfessionalQualification record = new TPreEmpProfessionalQualification();
				record.setSettleDomain(deptId);
				if (employee != null) {
					record.setEmpId(employee.getId());
					record.setEmpName(employee.getEmpName());
					record.setEmpCode(employee.getEmpCode());
				}
				record.setEmpIdcard(empIdCard);
				record.setPreMainId(id);
				record.setAttaList(new ArrayList<>());
				record.setCreateBy(user.getId());
				record.setCreateName(user.getNickname());
				record.setCreateTime(LocalDateTime.now());
				tPreEmpProfessionalService.save(record);
				tPreEmpProfessionalQualificationList.add(record);
			}
		} else {
			for (TPreEmpProfessionalQualification info : tPreEmpProfessionalQualificationList) {
				// 附件
				List<TAttaInfo> attaInfoList = tAttaInfoService.getTAttaInfoListByDoMainId(info.getId());
				if (attaInfoList != null) {
					URL url;
					for (TAttaInfo atta : attaInfoList) {
						url = ossUtil.getObjectUrl(null, atta.getAttaSrc());
						atta.setAttaUrl(String.valueOf(url));
					}
				}
				info.setAttaList(attaInfoList);
			}
		}
		vo.setTpreEmpProfessionalQualificationList(tPreEmpProfessionalQualificationList);
		// 预入职-员工工作履历信息表
		List<TPreEmpWorkRecording> tPreEmpWorkRecordingList = tPreEmpWorkRecordingService.getTPreEmpWorkRecordingList(id);
		if (tPreEmpWorkRecordingList == null || tPreEmpWorkRecordingList.isEmpty()) {
			tPreEmpWorkRecordingList = new ArrayList<>();
			if (Common.isNotNull(empId)) {
				List<TEmpWorkRecording> infoList = tEmpWorkRecordingService.getListByEmpId(empId);
				TPreEmpWorkRecording record;
				if (infoList != null && !infoList.isEmpty()) {
					for (TEmpWorkRecording info : infoList) {
						record = new TPreEmpWorkRecording();
						BeanUtil.copyProperties(info, record, ID);
						record.setEmpId(empId);
						record.setOldId(info.getId());
						record.setSettleDomain(deptId);
						if (employee != null) {
							record.setEmpId(employee.getId());
							record.setEmpName(employee.getEmpName());
							record.setEmpCode(employee.getEmpCode());
						}
						record.setEmpIdcard(empIdCard);
						record.setPreMainId(id);
						record.setCreateBy(user.getId());
						record.setCreateName(user.getNickname());
						record.setCreateTime(LocalDateTime.now());
						tPreEmpWorkRecordingList.add(record);
					}
					tPreEmpWorkRecordingService.saveBatch(tPreEmpWorkRecordingList);
				}
			}
			if (tPreEmpWorkRecordingList.isEmpty()) {
				TPreEmpWorkRecording record = new TPreEmpWorkRecording();
				record.setSettleDomain(deptId);
				if (employee != null) {
					record.setEmpId(employee.getId());
					record.setEmpName(employee.getEmpName());
					record.setEmpCode(employee.getEmpCode());
				}
				record.setEmpIdcard(empIdCard);
				record.setPreMainId(id);
				record.setCreateBy(user.getId());
				record.setCreateName(user.getNickname());
				record.setCreateTime(LocalDateTime.now());
				tPreEmpWorkRecordingService.save(record);
				tPreEmpWorkRecordingList.add(record);
			}
		}
		vo.setTpreEmpWorkRecordingList(tPreEmpWorkRecordingList);

		// 预入职-附件 9身份证 10 户口本；21（预入职申明签名）；22（预入职确认签名）；23（预入职pdf文件)
		List<TAttaInfo> attaInfoList = tAttaInfoService.getTAttaInfoListByDoMainId(id);
		if ((attaInfoList == null || attaInfoList.isEmpty()) && Common.isNotNull(empId)) {
			attaInfoList = tAttaInfoService.getTAttaInfoListByDoMainId(empId);
		}
		if (attaInfoList != null && !attaInfoList.isEmpty()) {
			URL url;
			for (TAttaInfo atta : attaInfoList) {
				url = ossUtil.getObjectUrl(null, atta.getAttaSrc());
				atta.setAttaUrl(String.valueOf(url));
			}
		}
		vo.setAttaInfoList(attaInfoList);
		return R.ok(vo);

	}

	/**
	 * @Description: 详情
	 * @Author: hgw
	 * @Date: 2024/6/17 17:19
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<com.yifu.cloud.plus.v1.yifu.archives.vo.PreEmpMainDetailVo>
	 **/
	@Override
	public R<PreEmpMainDetailVo> getInfoById(String id) {
		TPreEmpMain main = this.getById(id);
		PreEmpMainDetailVo vo = new PreEmpMainDetailVo();
		if (main != null && main.getId() != null) {
			vo.setMain(main);
			// 预入职-员工不良记录表
			TPreEmpBadRecord tPreEmpBadRecord = tPreEmpBadRecordService.getTPreEmpBadRecordList(id);
			vo.setTpreEmpBadRecord(tPreEmpBadRecord);
			// 预入职-紧急联络人
			TPreEmpContactInfo tPreEmpContactInfo = tPreEmpContactInfoService.getTPreEmpContactInfoList(id);
			vo.setTpreEmpContactInfo(tPreEmpContactInfo);
			// 预入职-员工申明
			TPreEmpDeclaration tPreEmpDeclaration;
			if (Common.isNotNull(main.getDeclarationId())) {
				tPreEmpDeclaration = tPreEmpDeclarationService.getById(main.getDeclarationId());
			} else {
				tPreEmpDeclaration = tPreEmpDeclarationService.getTPreEmpDeclarationList();
			}
			vo.setTpreEmpDeclaration(tPreEmpDeclaration);
			// 预入职-员工伤残信息表
			TPreEmpDisabilityInfo tPreEmpDisabilityInfo = tPreEmpDisabilityInfoService.getTPreEmpDisabilityInfoList(id);
			vo.setTpreEmpDisabilityInfo(tPreEmpDisabilityInfo);
			// 预入职-员工学历信息表
			TPreEmpEducation tPreEmpEducation = tPreEmpEducationService.getTPreEmpEducationList(id);
			if (tPreEmpEducation != null) {
				List<TAttaInfo> attaInfoList = tAttaInfoService.getTAttaInfoListByDoMainId(tPreEmpEducation.getId());
				if (attaInfoList != null) {
					URL url;
					for (TAttaInfo atta : attaInfoList) {
						url = ossUtil.getObjectUrl(null, atta.getAttaSrc());
						atta.setAttaUrl(String.valueOf(url));
					}
				}
				tPreEmpEducation.setAttaList(attaInfoList);
			}
			vo.setTpreEmpEducation(tPreEmpEducation);
			// 预入职-员工家庭信息表
			List<TPreEmpFamily> tPreEmpFamily = tPreEmpFamilyService.getTPreEmpFamilyList(id);
			vo.setTpreEmpFamilyList(tPreEmpFamily);
			// 预入职-人员档案表
			TPreEmployeeInfo tPreEmployeeInfo = tPreEmployeeInfoService.getTPreEmployeeInfoList(id);
			vo.setTpreEmployeeInfo(tPreEmployeeInfo);
			// 预入职-项目档案表
			TPreEmployeeProject tPreEmployeeProject = tPreEmployeeProjectService.getTPreEmployeeProjectList(id);
			vo.setTpreEmployeeProject(tPreEmployeeProject);
			// 预入职-员工职业资格信息表
			List<TPreEmpProfessionalQualification> tPreEmpProfessionalQualificationList = tPreEmpProfessionalService.getTPreEmpProfessionalQualificationList(id);

			if (tPreEmpProfessionalQualificationList != null) {
				List<TAttaInfo> attaInfoList;
				for (TPreEmpProfessionalQualification info : tPreEmpProfessionalQualificationList) {
					attaInfoList = tAttaInfoService.getTAttaInfoListByDoMainId(info.getId());
					if (attaInfoList != null) {
						URL url;
						for (TAttaInfo atta : attaInfoList) {
							url = ossUtil.getObjectUrl(null, atta.getAttaSrc());
							atta.setAttaUrl(String.valueOf(url));
						}
						info.setAttaList(attaInfoList);
					}
				}
			}

			vo.setTpreEmpProfessionalQualificationList(tPreEmpProfessionalQualificationList);
			// 预入职-员工工作履历信息表
			List<TPreEmpWorkRecording> tPreEmpWorkRecording = tPreEmpWorkRecordingService.getTPreEmpWorkRecordingList(id);
			vo.setTpreEmpWorkRecordingList(tPreEmpWorkRecording);

			// 预入职-附件 9身份证 10 户口本；21（预入职申明签名）；22（预入职确认签名）；23（预入职pdf文件)
			List<TAttaInfo> attaInfoList = tAttaInfoService.getTAttaInfoListByDoMainId(id);
			if (attaInfoList != null) {
				URL url;
				for (TAttaInfo atta : attaInfoList) {
					url = ossUtil.getObjectUrl(null, atta.getAttaSrc());
					atta.setAttaUrl(String.valueOf(url));
				}
			}
			vo.setAttaInfoList(attaInfoList);
			return R.ok(vo);
		} else {
			return R.failed("根据ID，未找到预入职主表！");
		}
	}

	/**
	 * @Description: 单个完善信息
	 * @Author: hgw
	 * @Date: 2024/6/17 17:42
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.lang.Boolean>
	 **/
	@Override
	public R<String> doImproveInformation(PreEmpMainDetailVo vo) {
		TPreEmpMain preMain = vo.getMain();
		TPreEmployeeInfo tPreEmployee = vo.getTpreEmployeeInfo();
		TPreEmployeeProject project = vo.getTpreEmployeeProject();
		if (preMain == null || tPreEmployee == null || project == null ||
				Common.isEmpty(preMain.getId()) || Common.isEmpty(tPreEmployee.getId()) || Common.isEmpty(project.getId())) {
			return R.failed("请传主表ID与人员ID与项目ID");
		}
		TPreEmpMain main = this.getById(preMain.getId());
		if (!CommonConstants.ONE_STRING.equals(main.getStatus())) {
			return R.failed("状态不为待完善，不可编辑！");
		}
		String errorInfo = null;
		if (Common.isEmpty(tPreEmployee.getEmpNatrue())) {
			errorInfo = "【员工类型】";
		}
		if (Common.isEmpty(tPreEmployee.getFileProvince())) {
			errorInfo += "【档案地省】";
		}
		if (Common.isNotNull(errorInfo)) {
			return R.failed(errorInfo + "不可为空！");
		}
		tPreEmployeeInfoService.updateById(tPreEmployee);
		project.setEmpNatrue(tPreEmployee.getEmpNatrue());
		tPreEmployeeProjectService.updateById(project);

		main.setEmpNatrue(tPreEmployee.getEmpNatrue());
		main.setStatus(CommonConstants.TWO_STRING);
		this.updateById(main);
		return R.ok("已完善！");
	}

	/**
	 * @param vo
	 * @Description: 草稿
	 * @Author: hgw
	 * @Date: 2024/6/17 17:42
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.lang.Boolean>
	 **/
	@Override
	public R<String> saveDraftPreEmpMain(PreEmpMainDetailVo vo) {
		return saveBase(vo, CommonConstants.ZERO_STRING);
	}

	/**
	 * @param vo
	 * @Description: 保存
	 * @Author: hgw
	 * @Date: 2024/6/17 17:42
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.lang.Boolean>
	 **/
	@Override
	public R<String> savePreEmpMain(PreEmpMainDetailVo vo) {
		return saveBase(vo, CommonConstants.ONE_STRING);
	}

	/**
	 * @Description: 核心保存
	 * @Author: hgw
	 * @Date: 2024/6/17 17:44
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.lang.String>
	 **/
	private R<String> saveBase(PreEmpMainDetailVo vo, String status) {
		Set<String> dbAuthsSet = new HashSet<>();
		Collection<? extends GrantedAuthority> authorities = AuthorityUtils
				.createAuthorityList(dbAuthsSet.toArray(new String[0]));
		YifuUser user = new YifuUser("2", 1L, "", "预入职扫码",
				"预入职扫码", "0", SecurityConstants.BCRYPT + "123456",
				"12345678911", true, true, true,
				true,
				"1", authorities, "1",
				null, null,
				null);
		TPreEmpMain main = vo.getMain();
		if (main != null && Common.isNotNull(main.getEmpIdcard())) {
			TPreEmployeeProject tPreEmployeeProject = vo.getTpreEmployeeProject();
			if (tPreEmployeeProject != null && Common.isNotNull(tPreEmployeeProject.getOldId())) {
				// 预入职-人员档案表
				TPreEmployeeInfo tPreEmployeeInfo = vo.getTpreEmployeeInfo();
				if (tPreEmployeeInfo != null && Common.isNotNull(tPreEmployeeInfo.getOldId())) {
					// 转到更新档案去
					return updateToEmployeeByPre(vo);
				} else {
					return R.failed("档案原ID不可为空！");
				}
			} else {
				main.setStatus(status);
				main.setCreateBy(user.getId());
				main.setCreateName(user.getNickname());
				main.setCreateTime(LocalDateTime.now());
				this.saveOrUpdate(main);
				String mainId = main.getId();

				// 预入职-员工不良记录表
				TPreEmpBadRecord tPreEmpBadRecord = vo.getTpreEmpBadRecord();
				if (tPreEmpBadRecord != null) {
					tPreEmpBadRecord.setPreMainId(mainId);
					tPreEmpBadRecord.setCreateBy(user.getId());
					tPreEmpBadRecord.setCreateName(user.getNickname());
					tPreEmpBadRecord.setCreateTime(LocalDateTime.now());
					tPreEmpBadRecordService.saveOrUpdate(tPreEmpBadRecord);
				}
				// 预入职-紧急联络人
				TPreEmpContactInfo tPreEmpContactInfo = vo.getTpreEmpContactInfo();
				if (tPreEmpContactInfo != null) {
					tPreEmpContactInfo.setPreMainId(mainId);
					tPreEmpContactInfo.setCreateBy(user.getId());
					tPreEmpContactInfo.setCreateName(user.getNickname());
					tPreEmpContactInfo.setCreateTime(LocalDateTime.now());
					tPreEmpContactInfoService.saveOrUpdate(tPreEmpContactInfo);
				}
				// 预入职-员工伤残信息表
				TPreEmpDisabilityInfo tPreEmpDisabilityInfo = vo.getTpreEmpDisabilityInfo();
				if (tPreEmpDisabilityInfo != null) {
					tPreEmpDisabilityInfo.setPreMainId(mainId);
					tPreEmpDisabilityInfo.setCreateBy(user.getId());
					tPreEmpDisabilityInfo.setCreateName(user.getNickname());
					tPreEmpDisabilityInfo.setCreateTime(LocalDateTime.now());
					tPreEmpDisabilityInfoService.saveOrUpdate(tPreEmpDisabilityInfo);
				}
				// 预入职-员工学历信息表
				TPreEmpEducation tPreEmpEducation = vo.getTpreEmpEducation();
				if (tPreEmpEducation != null) {
					tPreEmpEducation.setPreMainId(mainId);
					tPreEmpEducation.setCreateBy(user.getId());
					tPreEmpEducation.setCreateName(user.getNickname());
					tPreEmpEducation.setCreateTime(LocalDateTime.now());
					tPreEmpEducationService.saveOrUpdate(tPreEmpEducation);
					// 附件
					if (tPreEmpEducation.getAttaList() != null && !tPreEmpEducation.getAttaList().isEmpty()) {
						List<TAttaInfo> attaList = tPreEmpEducation.getAttaList();
						if (attaList != null) {
							tAttaInfoService.deleteByDomainId(tPreEmpEducation.getId());
							for (TAttaInfo atta : attaList) {
								atta.setDomainId(tPreEmpEducation.getId());
								atta.setCreateBy(user.getId());
								atta.setCreateName(user.getNickname());
								atta.setCreateTime(LocalDateTime.now());
							}
							tAttaInfoService.saveOrUpdateBatch(attaList);
						}
					}
				}
				// 预入职-员工家庭信息表
				List<TPreEmpFamily> tPreEmpFamily = vo.getTpreEmpFamilyList();
				if (tPreEmpFamily != null) {
					for (TPreEmpFamily info : tPreEmpFamily) {
						info.setPreMainId(mainId);
						info.setCreateBy(user.getId());
						info.setCreateName(user.getNickname());
						info.setCreateTime(LocalDateTime.now());
					}
					tPreEmpFamilyService.saveOrUpdateBatch(tPreEmpFamily);
				}
				// 预入职-人员档案表
				TPreEmployeeInfo tPreEmployeeInfo = vo.getTpreEmployeeInfo();
				if (tPreEmployeeInfo != null) {
					if (tPreEmpEducation != null) {
						if (Common.isNotNull(tPreEmpEducation.getEducationName())) {
							// 5大专 6本科 7硕士 8博士
							if ("5".equals(tPreEmpEducation.getEducationName())
									|| "6".equals(tPreEmpEducation.getEducationName())
									|| "7".equals(tPreEmpEducation.getEducationName())
									|| "8".equals(tPreEmpEducation.getEducationName())) {
								tPreEmployeeInfo.setIsCollege(CommonConstants.ONE_INT);
							} else {
								tPreEmployeeInfo.setIsCollege(CommonConstants.ZERO_INT);
							}
						}
					}
					// 生成性别年龄等：
					this.setBaseSexInfo(tPreEmployeeInfo);
					tPreEmployeeInfo.setPreMainId(mainId);
					tPreEmployeeInfo.setCreateBy(user.getId());
					tPreEmployeeInfo.setCreateName(user.getNickname());
					tPreEmployeeInfo.setCreateTime(LocalDateTime.now());
					tPreEmployeeInfoService.saveOrUpdate(tPreEmployeeInfo);
				}
				// 预入职-项目档案表
				if (tPreEmployeeProject != null) {
					tPreEmployeeProject.setPreMainId(mainId);
					tPreEmployeeProject.setCreateBy(user.getId());
					tPreEmployeeProject.setCreateName(user.getNickname());
					tPreEmployeeProject.setCreateTime(LocalDateTime.now());
					tPreEmployeeProjectService.saveOrUpdate(tPreEmployeeProject);
				}
				// 预入职-员工职业资格信息表
				List<TPreEmpProfessionalQualification> tPreEmpProfessionalQualification = vo.getTpreEmpProfessionalQualificationList();
				if (tPreEmpProfessionalQualification != null) {
					// 先删除后增加
					tPreEmpProfessionalService.deleteProfessionalByMainId(mainId);
					for (TPreEmpProfessionalQualification info : tPreEmpProfessionalQualification) {
						info.setPreMainId(mainId);
						info.setCreateBy(user.getId());
						info.setCreateName(user.getNickname());
						info.setCreateTime(LocalDateTime.now());
						tPreEmpProfessionalService.saveOrUpdate(info);
						// 附件
						if (info.getAttaList() != null && !info.getAttaList().isEmpty()) {
							List<TAttaInfo> attaList = info.getAttaList();
							if (attaList != null) {
								tAttaInfoService.deleteByDomainId(info.getId());
								for (TAttaInfo atta : attaList) {
									atta.setDomainId(info.getId());
									atta.setCreateBy(user.getId());
									atta.setCreateName(user.getNickname());
									atta.setCreateTime(LocalDateTime.now());
								}
								tAttaInfoService.saveOrUpdateBatch(attaList);
							}
						}
					}
				}
				// 预入职-员工工作履历信息表
				List<TPreEmpWorkRecording> tPreEmpWorkRecording = vo.getTpreEmpWorkRecordingList();
				if (tPreEmpWorkRecording != null) {
					// 先删除后增加
					tPreEmpWorkRecordingService.deleteByMainId(mainId);
					for (TPreEmpWorkRecording info : tPreEmpWorkRecording) {
						info.setPreMainId(mainId);
						info.setCreateBy(user.getId());
						info.setCreateName(user.getNickname());
						info.setCreateTime(LocalDateTime.now());
					}
					tPreEmpWorkRecordingService.saveOrUpdateBatch(tPreEmpWorkRecording);
				}
				// 预入职-附件
				List<TAttaInfo> attaInfoList = vo.getAttaInfoList();
				if (attaInfoList != null) {
					// 先删除后增加
					tAttaInfoService.deleteByDomainId(mainId);
					for (TAttaInfo info : attaInfoList) {
						info.setDomainId(mainId);
						info.setCreateBy(user.getId());
						info.setCreateName(user.getNickname());
						info.setCreateTime(LocalDateTime.now());
					}
					tAttaInfoService.updateBatchById(attaInfoList);
				}
			}
			return R.ok("成功");
		} else {
			return R.failed("身份证不可为空！");
		}
	}

	/**
	 * @Description: 执行复制到档案的操作
	 * @Author: hgw
	 * @Date: 2024/6/18 19:35
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.lang.String>
	 **/
	private R<String> updateToEmployeeByPre(PreEmpMainDetailVo vo) {
		YifuUser user = SecurityUtils.getUser();
		// 预入职-人员档案表
		TPreEmployeeInfo tPreEmployeeInfo = vo.getTpreEmployeeInfo();
		// 预入职-项目档案表
		TPreEmployeeProject tPreEmployeeProject = vo.getTpreEmployeeProject();
		// 预入职-员工学历信息表
		TPreEmpEducation tPreEmpEducation = vo.getTpreEmpEducation();
		// 如果档案项目id都没有，则新增。newFlag是true：
		boolean newFlag = true;
		String empId = null;
		String empProjectId = null;
		String empIdCard = null;
		// 1人员档案
		TEmployeeInfo emp = null;
		// 2项目档案
		TEmployeeProject project = null;
		TSettleDomain dept = null;
		if (tPreEmployeeProject != null && Common.isNotNull(tPreEmployeeProject.getDeptId())) {
			dept = tSettleDomainService.getById(tPreEmployeeProject.getDeptId());
		}
		if (dept == null) {
			return R.failed("根据项目id，未找到项目！");
		}
		if (tPreEmployeeInfo != null && Common.isNotNull(tPreEmployeeInfo.getOldId())
				&& Common.isNotNull(tPreEmployeeProject.getOldId())) {
			newFlag = false;
			empId = tPreEmployeeInfo.getOldId();
			emp = tEmployeeInfoService.getById(empId);
			if (emp != null) {
				BeanUtil.copyProperties(tPreEmployeeInfo, emp, ID);
				if (CommonConstants.ONE_INT == emp.getFileStatus()) {
					emp.setCreateTime(LocalDateTime.now());
					emp.setFileStatus(CommonConstants.ZERO_INT);
				}
				tEmployeeInfoService.updateById(emp);
			} else {
				emp = this.saveTEmployeeInfo(user, tPreEmployeeInfo);
				empId = emp.getId();
			}
			empIdCard = emp.getEmpIdcard();
			project = tEmployeeProjectService.getById(tPreEmployeeProject.getOldId());
			if (project != null) {
				BeanUtil.copyProperties(tPreEmployeeInfo, project, ID);
				if (CommonConstants.ONE_INT == project.getProjectStatus()) {
					project.setCreateTime(LocalDateTime.now());
					project.setDeleteFlag(CommonConstants.STATUS_NORMAL);
					project.setProjectStatus(CommonConstants.ZERO_INT);
				}
				tEmployeeProjectService.updateById(project);
			} else {
				project = this.saveTEmployeeProject(project, user, tPreEmployeeProject, emp, dept);
			}
			if (Common.isNotNull(project)) {
				empProjectId = project.getId();
			}
		} else {
			// 新建档案、项目档案，将档案id赋值，给其他附属信息
			if (tPreEmployeeInfo != null) {
				if (tPreEmpEducation != null) {
					if (Common.isNotNull(tPreEmpEducation.getEducationName())) {
						if ("5".equals(tPreEmpEducation.getEducationName())
								|| "6".equals(tPreEmpEducation.getEducationName())
								|| "7".equals(tPreEmpEducation.getEducationName())
								|| "8".equals(tPreEmpEducation.getEducationName())) {
							tPreEmployeeInfo.setIsCollege(CommonConstants.ONE_INT);
						} else {
							tPreEmployeeInfo.setIsCollege(CommonConstants.ZERO_INT);
						}
					}
				}
				// 生成性别年龄等：
				this.setBaseSexInfo(tPreEmployeeInfo);

				// 1人员档案
				emp = this.saveTEmployeeInfo(user, tPreEmployeeInfo);
				empId = emp.getId();
				empIdCard = emp.getEmpIdcard();
				// 2项目档案
				project = this.saveTEmployeeProject(project, user, tPreEmployeeProject, emp, dept);
				if (Common.isNotNull(project)) {
					empProjectId = project.getId();
				}
			}
		}
		if (emp == null) {
			return R.failed("新建员工失败！");
		}

		// 3:其他附属信息

		// 预入职-员工不良记录表
		// 预入职-员工工作履历信息表
		// 预入职-紧急联络人
		// 预入职-员工伤残信息表
		// 预入职-员工学历信息表
		// 预入职-员工家庭信息表
		// 预入职-人员档案表
		// 预入职-项目档案表
		// 预入职-员工职业资格信息表

		// 最高学历
		if (tPreEmpEducation != null) {
			TEmpEducation tEmpEducation = null;
			if (Common.isNotNull(tPreEmpEducation.getOldId())) {
				tEmpEducation = tEmpEducationService.getById(tPreEmpEducation.getOldId());
			}
			if (tEmpEducation == null) {
				tEmpEducation = new TEmpEducation();
			} else {
				// 已存在的学历信息（如果不一致，要更新档案的最高学历）
				if (Common.isEmpty(tEmpEducation.getEducationName())
						|| !tEmpEducation.getEducationName().equals(tPreEmpEducation.getEducationName())) {
					emp.setHignEducation(tPreEmpEducation.getEducationName());
					tEmployeeInfoService.updateById(emp);
				}
			}
			BeanUtil.copyProperties(tPreEmpEducation, tEmpEducation, ID);
			tEmpEducation.setDeleteFlag(CommonConstants.STATUS_NORMAL);
			tEmpEducation.setEmpId(empId);
			if (Common.isNotNull(empIdCard)) {
				tEmpEducationService.updateEducationToNoByIdCard(empIdCard);
			}
			tEmpEducationService.saveOrUpdate(tEmpEducation);

			if (tPreEmpEducation.getAttaList() != null && !tPreEmpEducation.getAttaList().isEmpty()) {
				List<TAttaInfo> attaList = tPreEmpEducation.getAttaList();
				if (attaList != null) {
					String attaId = tPreEmpEducation.getOldId();
					if (!newFlag) {
						tAttaInfoService.deleteByDomainId(attaId);
					}
					TAttaInfo newEmpAtta;
					for (TAttaInfo atta : attaList) {
						newEmpAtta = new TAttaInfo();
						BeanUtil.copyProperties(atta, newEmpAtta, ID);
						newEmpAtta.setDomainId(tEmpEducation.getId());
						tAttaInfoService.saveOrUpdate(newEmpAtta);
					}
				}
			}
		}
		// 预入职-员工不良记录表
		TPreEmpBadRecord tPreEmpBadRecord = vo.getTpreEmpBadRecord();
		if (tPreEmpBadRecord != null) {
			TEmpBadRecord tEmpBadRecord = null;
			if (Common.isNotNull(tPreEmpBadRecord.getOldId())) {
				tEmpBadRecord = tEmpBadRecordService.getById(tPreEmpBadRecord.getOldId());
			}
			if (tEmpBadRecord == null) {
				tEmpBadRecord = new TEmpBadRecord();
			}
			BeanUtil.copyProperties(tPreEmpBadRecord, tEmpBadRecord, ID);
			tEmpBadRecord.setEmpId(empId);
			tEmpBadRecordService.saveOrUpdate(tEmpBadRecord);
		}
		// 预入职-紧急联络人
		TPreEmpContactInfo tPreEmpContactInfo = vo.getTpreEmpContactInfo();
		if (tPreEmpContactInfo != null) {
			TEmpContactInfo tEmpContactInfo = null;
			if (Common.isNotNull(tPreEmpContactInfo.getOldId())) {
				tEmpContactInfo = tEmpContactInfoService.getById(tPreEmpContactInfo.getOldId());
			}
			if (tEmpContactInfo == null) {
				tEmpContactInfo = new TEmpContactInfo();
			}
			BeanUtil.copyProperties(tPreEmpContactInfo, tEmpContactInfo, ID);
			tEmpContactInfo.setEmpId(empId);
			tEmpContactInfoService.saveOrUpdate(tEmpContactInfo);
		}
		// 预入职-员工伤残信息表
		TPreEmpDisabilityInfo tPreEmpDisabilityInfo = vo.getTpreEmpDisabilityInfo();
		if (tPreEmpDisabilityInfo != null) {
			TEmpDisabilityInfo tEmpDisabilityInfo = null;
			if (Common.isNotNull(tPreEmpDisabilityInfo.getOldId())) {
				tEmpDisabilityInfo = tEmpDisabilityInfoService.getById(tPreEmpDisabilityInfo.getOldId());
			}
			if (tEmpDisabilityInfo == null) {
				tEmpDisabilityInfo = new TEmpDisabilityInfo();
			}
			BeanUtil.copyProperties(tPreEmpDisabilityInfo, tEmpDisabilityInfo, ID);
			tEmpDisabilityInfo.setDeleteFlag(CommonConstants.STATUS_NORMAL);
			tEmpDisabilityInfo.setEmpId(empId);
			tEmpDisabilityInfoService.saveOrUpdate(tEmpDisabilityInfo);
		}

		// 预入职-员工家庭信息表
		List<TPreEmpFamily> tPreEmpFamilyList = vo.getTpreEmpFamilyList();
		if (tPreEmpFamilyList != null) {
			// 先删除其他信息
			tEmpFamilyService.deleteByEmpId(empId);
			TEmpFamily tEmpFamily;
			for (TPreEmpFamily tPreEmpFamily : tPreEmpFamilyList) {
				tEmpFamily = new TEmpFamily();
				BeanUtil.copyProperties(tPreEmpFamily, tEmpFamily, ID);
				tEmpFamily.setEmpId(empId);
				tEmpFamily.setDeleteFlag(CommonConstants.STATUS_NORMAL);
				tEmpFamily.setEmpCode(emp.getEmpCode());
				tEmpFamily.setEmpName(emp.getEmpName());
				tEmpFamily.setEmpIdcard(emp.getEmpIdcard());
				if (Common.isNotNull(tPreEmpFamily.getOldId())) {
					tEmpFamily.setId(tPreEmpFamily.getOldId());
				}
				tEmpFamilyService.save(tEmpFamily);
			}
		}
		// 预入职-员工职业资格信息表
		List<TPreEmpProfessionalQualification> tPreEmpProfessionalQualificationList = vo.getTpreEmpProfessionalQualificationList();
		if (tPreEmpProfessionalQualificationList != null) {
			// 先删除其他信息
			tEmpProfessionalService.deleteProfessionalByEmpId(empId);
			TEmpProfessionalQualification info;
			for (TPreEmpProfessionalQualification preInfo : tPreEmpProfessionalQualificationList) {
				info = new TEmpProfessionalQualification();
				BeanUtil.copyProperties(preInfo, info, ID);
				info.setDeleteFlag(CommonConstants.STATUS_NORMAL);
				info.setEmpId(empId);
				info.setEmpCode(emp.getEmpCode());
				info.setEmpName(emp.getEmpName());
				info.setEmpIdcard(emp.getEmpIdcard());
				if (Common.isNotNull(preInfo.getOldId())) {
					info.setId(preInfo.getOldId());
				}
				tEmpProfessionalService.save(info);
				if (preInfo.getAttaList() != null && !preInfo.getAttaList().isEmpty()) {
					List<TAttaInfo> attaList = preInfo.getAttaList();
					if (attaList != null) {
						String attaId = preInfo.getOldId();
						if (!newFlag) {
							tAttaInfoService.deleteByDomainId(attaId);
						}
						TAttaInfo newEmpAtta;
						for (TAttaInfo atta : attaList) {
							newEmpAtta = new TAttaInfo();
							BeanUtil.copyProperties(atta, newEmpAtta, ID);
							newEmpAtta.setDomainId(info.getId());
							tAttaInfoService.saveOrUpdate(newEmpAtta);
						}
					}
				}
			}
		}
		// 预入职-员工工作履历信息表
		List<TPreEmpWorkRecording> tPreEmpWorkRecordingList = vo.getTpreEmpWorkRecordingList();
		if (tPreEmpWorkRecordingList != null) {
			// 先删除其他信息
			tEmpWorkRecordingService.deleteWorkRecordByEmpId(empId);
			TEmpWorkRecording info;
			for (TPreEmpWorkRecording preInfo : tPreEmpWorkRecordingList) {
				info = new TEmpWorkRecording();
				BeanUtil.copyProperties(preInfo, info, ID);
				info.setDeleteFlag(CommonConstants.STATUS_NORMAL);
				info.setEmpId(empId);
				info.setEmpCode(emp.getEmpCode());
				info.setEmpName(emp.getEmpName());
				info.setEmpIdcard(emp.getEmpIdcard());
				if (Common.isNotNull(preInfo.getOldId())) {
					info.setId(preInfo.getOldId());
					tEmpWorkRecordingService.updateById(info);
				} else {
					tEmpWorkRecordingService.save(info);
				}
			}
		}
		// 预入职-附件
		List<TAttaInfo> attaList = vo.getAttaInfoList();
		if (attaList != null) {
			// 先删除其他信息
			tAttaInfoService.deleteByDomainId(empId);
			for (TAttaInfo atta : attaList) {
				if (Common.isEmpty(atta.getDomainId())) {
					atta.setDomainId(empId);
				}
			}
			tAttaInfoService.saveOrUpdateBatch(attaList);
		}
		return R.ok("保存档案成功！");
	}

	// 2新增或更新项目
	private TEmployeeProject saveTEmployeeProject(TEmployeeProject project, YifuUser user, TPreEmployeeProject tPreEmployeeProject, TEmployeeInfo emp, TSettleDomain dept) {
		boolean isNew;
		if (Common.isNotNull(tPreEmployeeProject.getEmpIdcard()) && Common.isNotNull(tPreEmployeeProject.getDeptId())) {
			project = tEmployeeProjectService.getByEmpIdAndDeptId(tPreEmployeeProject.getEmpIdcard(), tPreEmployeeProject.getDeptId());
			if (project == null) {
				project = tEmployeeProjectService.getByEmpIdAndDeptIdAndDelete(tPreEmployeeProject.getEmpIdcard(), tPreEmployeeProject.getDeptId());
				if (project != null) {
					project.setCreateTime(LocalDateTime.now());
					project.setProjectStatus(CommonConstants.ZERO_INT);
					project.setDeleteFlag(CommonConstants.STATUS_NORMAL);
				}
			} else if (CommonConstants.ONE_INT == project.getProjectStatus()) {
				project.setCreateTime(LocalDateTime.now());
				project.setProjectStatus(CommonConstants.ZERO_INT);
			}
			isNew = false;
			if (project == null) {
				isNew = true;
				project = new TEmployeeProject();
			}
			BeanUtil.copyProperties(tPreEmployeeProject, project, ID);
			if (isNew) {
				// 新项目档案塞基本属性
				this.setNewEmpProjectBaseData(project, emp, dept, user);
			}
			tEmployeeProjectService.saveOrUpdate(project);
		}
		return project;
	}

	// 1新增档案
	private TEmployeeInfo saveTEmployeeInfo(YifuUser user, TPreEmployeeInfo tPreEmployeeInfo) {
		TEmployeeInfo emp = tEmployeeInfoService.getInfoByIdcard(tPreEmployeeInfo.getEmpIdcard());
		if (emp == null) {
			emp = tEmployeeInfoService.getInfoByDelete(tPreEmployeeInfo.getEmpIdcard());
			if (emp != null) {
				emp.setCreateTime(LocalDateTime.now());
				emp.setFileStatus(CommonConstants.ZERO_INT);
				emp.setDeleteFlag(CommonConstants.STATUS_NORMAL);
			}
		} else if (CommonConstants.ONE_INT == emp.getFileStatus()) {
			emp.setCreateTime(LocalDateTime.now());
			emp.setFileStatus(CommonConstants.ZERO_INT);
		}
		boolean isNew = false;
		if (emp == null) {
			isNew = true;
			emp = new TEmployeeInfo();
		}
		BeanUtil.copyProperties(tPreEmployeeInfo, emp, ID);
		if (isNew) {
			// 新员工塞基本属性
			this.setNewEmpBaseData(emp, user);
		}
		tEmployeeInfoService.saveOrUpdate(emp);
		return emp;
	}

	/**
	 * @Description: 新员工塞基本信息
	 * @Author: hgw
	 * @Date: 2024/6/19 14:26
	 * @return: void
	 **/
	private void setNewEmpBaseData(TEmployeeInfo employeeInfo, YifuUser user) {
		// 新增档案
		employeeInfo.setEmpCode(tEmployeeInfoService.getCode());
		employeeInfo.setCreateBy(user.getId());
		employeeInfo.setCreateName(user.getNickname());
		employeeInfo.setCreateTime(LocalDateTime.now());

		employeeInfo.setFileSource(CommonConstants.SEVEN_STRING);
		employeeInfo.setStatus(CommonConstants.ZERO_INT);
		employeeInfo.setFileStatus(CommonConstants.ZERO_INT);
		employeeInfo.setProjectNum(CommonConstants.ONE_INT);
		employeeInfo.setDeleteFlag(CommonConstants.STATUS_NORMAL);

		employeeInfo.setContractStatus(CommonConstants.ZERO_INT);
		employeeInfo.setInsuranceStatus(CommonConstants.ZERO_INT);
		employeeInfo.setSocialStatus(CommonConstants.ZERO_INT);
		employeeInfo.setFundStatus(CommonConstants.ZERO_INT);
		employeeInfo.setSalaryStatus(CommonConstants.ZERO_INT);
	}

	/**
	 * @Description: 新员工塞基本项目档案信息
	 * @Author: hgw
	 * @Date: 2024/6/19 14:26
	 * @return: void
	 **/
	private void setNewEmpProjectBaseData(TEmployeeProject insTEmployeePro, TEmployeeInfo tEmployeeInfo, TSettleDomain tSettleDomain, YifuUser user) {
		// 新增档案
		insTEmployeePro.setId(String.valueOf(UUID.randomUUID()).replaceAll("-", ""));
		insTEmployeePro.setDeleteFlag(CommonConstants.STATUS_NORMAL);
		insTEmployeePro.setStatus(CommonConstants.ZERO_INT);

		//获取项目和单位信息
		if (Common.isNotNull(tSettleDomain)) {
			insTEmployeePro.setDeptId(tSettleDomain.getId());
			insTEmployeePro.setDeptName(tSettleDomain.getDepartName());
			insTEmployeePro.setBusinessPrimaryType(tSettleDomain.getBusinessPrimaryType());
			insTEmployeePro.setBusinessSecondType(tSettleDomain.getBusinessSecondType());
			insTEmployeePro.setBusinessThirdType(tSettleDomain.getBusinessThirdType());
			insTEmployeePro.setUnitId(tSettleDomain.getCustomerId());
			insTEmployeePro.setUnitNo(tSettleDomain.getCustomerNo());
			insTEmployeePro.setUnitName(tSettleDomain.getCustomerName());
			String empNO = tEmployeeProjectService.getEmpNo(insTEmployeePro.getDeptNo());
			insTEmployeePro.setEmpNo(empNO);
		}
		//员工编码生成规则
		insTEmployeePro.setEmpCode(tEmployeeInfo.getEmpCode());
		insTEmployeePro.setCreateBy(user.getId());
		insTEmployeePro.setEmpName(tEmployeeInfo.getEmpName());
		insTEmployeePro.setCreateTime(LocalDateTime.now());
		insTEmployeePro.setCreateName(user.getNickname());
		insTEmployeePro.setProjectSource(CommonConstants.SIX_STRING);
		insTEmployeePro.setEmpId(tEmployeeInfo.getId());
	}


	/**
	 * @param employeeInfo
	 * @Description: 生成基础性别等信息
	 * @Author: hgw
	 * @Date: 2022/6/24 16:51
	 * @return: void
	 **/
	private void setBaseSexInfo(TPreEmployeeInfo employeeInfo) {
		String idCard = employeeInfo.getEmpIdcard();
		if (Common.isNotNull(idCard) && Common.isEmpty(employeeInfo.getEmpSex()) && idCard.length() > 14) {

			// 出生日期
			String idCardDate = idCard.substring(6, 14);
			Date empBirthday = DateUtil.stringToDateByPatten(idCardDate, "yyyyMMdd");
			employeeInfo.setEmpBirthday(empBirthday);

			// 性别
			if (idCard.length() > 17) {
				if (Integer.parseInt(idCard.substring(16, 17)) % 2 == 1) {
					employeeInfo.setEmpSex(CommonConstants.SEX_MAN);
				} else {
					employeeInfo.setEmpSex(CommonConstants.SEX_WONMAN);
				}
			}

			// 年龄
			int idCardYear = Integer.parseInt(idCard.substring(6, 10));
			employeeInfo.setEmpAge(DateUtil.getAge(idCardYear));
		}
	}

	/**
	 * 预入职-主表批量导出
	 *
	 * @return
	 */
	@Override
	public void listExport(HttpServletResponse response, TPreEmpMainSearchVo searchVo) {
		String fileName = "预入职导出主表" + DateUtil.getThisTime() + ".xlsx";
		//获取要导出的列表
		List<TPreEmpMain> list = new ArrayList<>();
		long count = baseMapper.getTPreEmpMainCount(searchVo);
		ServletOutputStream out = null;
		try {
			out = response.getOutputStream();
			response.setContentType(CommonConstants.MULTIPART_FORM_DATA);
			response.setCharacterEncoding("utf-8");
			response.setHeader(CommonConstants.CONTENT_DISPOSITION, CommonConstants.ATTACHMENT_FILENAME + URLEncoder.encode(fileName, CommonConstants.UTF8));
			// 这里 需要指定写用哪个class去写，然后写到第一个sheet，然后文件流会自动关闭
			ExcelWriter excelWriter = EasyExcelFactory.write(out, TPreEmpMain.class).build();
			int index = 0;
			if (count > CommonConstants.ZERO_INT) {
				for (int i = 0; i <= count; i += CommonConstants.EXCEL_EXPORT_LIMIT) {
					// 获取实际记录
					searchVo.setLimitStart(i);
					searchVo.setLimitEnd(CommonConstants.EXCEL_EXPORT_LIMIT);
					list = baseMapper.getTPreEmpMainList(searchVo);
					if (Common.isNotNull(list)) {
						ExcelUtil<TPreEmpMain> util = new ExcelUtil<>(TPreEmpMain.class);
						for (TPreEmpMain vo : list) {
							util.convertEntity(vo, null, null, null);
						}
					}
					if (Common.isNotNull(list)) {
						WriteSheet writeSheet = EasyExcelFactory.writerSheet("预入职-主表" + index).build();
						excelWriter.write(list, writeSheet);
						index++;
					}
					if (Common.isNotNull(list)) {
						list.clear();
					}
				}
			} else {
				WriteSheet writeSheet = EasyExcelFactory.writerSheet("预入职-主表" + index).build();
				excelWriter.write(list, writeSheet);
			}
			if (Common.isNotNull(list)) {
				list.clear();
			}
			out.flush();
			excelWriter.finish();
		} catch (Exception e) {
			log.error("执行异常", e);
		} finally {
			try {
				if (null != out) {
					out.close();
				}
			} catch (IOException e) {
				log.error("执行异常", e);
			}
		}
	}

	@Override
	public List<TPreEmpMain> noPageDiy(TPreEmpMainSearchVo searchVo) {
		LambdaQueryWrapper<TPreEmpMain> wrapper = buildQueryWrapper(searchVo);
		List<String> idList = Common.getList(searchVo.getIds());
		if (Common.isNotNull(idList)) {
			wrapper.in(TPreEmpMain::getId, idList);
		}
		if (searchVo.getLimitStart() >= 0 && searchVo.getLimitEnd() > 0) {
			wrapper.last(" limit " + searchVo.getLimitStart() + "," + searchVo.getLimitEnd());
		}
		wrapper.orderByDesc(BaseEntity::getCreateTime);
		return baseMapper.selectList(wrapper);
	}

	private LambdaQueryWrapper buildQueryWrapper(TPreEmpMainSearchVo entity) {
		LambdaQueryWrapper<TPreEmpMain> wrapper = Wrappers.lambdaQuery();
		if (ArrayUtil.isNotEmpty(entity.getCreateTimeStart())) {
			wrapper.ge(TPreEmpMain::getCreateTime, entity.getCreateTimeStart());
		}
		if (ArrayUtil.isNotEmpty(entity.getCreateTimeEnd())) {
			wrapper.le(TPreEmpMain::getCreateTime, entity.getCreateTimeEnd());
		}
		if (Common.isNotNull(entity.getStatusArray())) {
			wrapper.in(TPreEmpMain::getStatus, entity.getStatusArray());
		}
		if (Common.isNotNull(entity.getEmpNatureArray())) {
			wrapper.in(TPreEmpMain::getEmpNatrue, entity.getEmpNatureArray());
		}
		if (Common.isNotNull(entity.getCreateName())) {
			wrapper.eq(TPreEmpMain::getCreateName, entity.getCreateName());
		}
		return wrapper;
	}

	/**
	 * @Description: 批量完善信息
	 * @Author: hgw
	 * @Date: 2024/6/21 15:26
	 * @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage>>
	 **/
	@Override
	public R<List<ErrorMessage>> importDiy(InputStream inputStream) {
		List<ErrorMessage> errorMessageList = new ArrayList<>();
		ExcelUtil<TPreEmpMainVo> util1 = new ExcelUtil<>(TPreEmpMainVo.class);
		// 写法2：
		// 匿名内部类 不用额外写一个DemoDataListener
		// 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
		try {
			EasyExcelFactory.read(inputStream, TPreEmpMainVo.class, new ReadListener<TPreEmpMainVo>() {
				/**
				 * 单次缓存的数据量
				 */
				public static final int BATCH_COUNT = CommonConstants.BATCH_COUNT;
				/**
				 *临时存储
				 */
				private List<TPreEmpMainVo> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);

				@Override
				public void invoke(TPreEmpMainVo data, AnalysisContext context) {
					ReadRowHolder readRowHolder = context.readRowHolder();
					Integer rowIndex = readRowHolder.getRowIndex();
					data.setRowIndex(rowIndex + 1);
					ErrorMessage errorMessage = util1.checkEntity(data, data.getRowIndex());
					if (Common.isNotNull(errorMessage)) {
						errorMessageList.add(errorMessage);
					} else {
						cachedDataList.add(data);
					}
					if (cachedDataList.size() >= BATCH_COUNT) {
						saveData();
						// 存储完成清理 list
						cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
					}
				}

				@Override
				public void doAfterAllAnalysed(AnalysisContext context) {
					saveData();
				}

				/**
				 * 加上存储数据库
				 */
				private void saveData() {
					log.info("{}条数据，开始存储数据库！", cachedDataList.size());
					importTPreEmpMain(cachedDataList, errorMessageList);
					log.info("存储数据库成功！");
				}
			}).sheet().doRead();
		} catch (Exception e) {
			log.error(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR, e);
			return R.failed(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR);
		}
		if (errorMessageList.isEmpty()) {
			return R.ok();
		} else {
			return R.failed(errorMessageList);
		}
	}

	private void importTPreEmpMain(List<TPreEmpMainVo> excelVOList, List<ErrorMessage> errorMessageList) {
		TPreEmpMain main;
		TPreEmployeeInfo employee;
		TPreEmployeeProject project;
		// 执行数据插入操作 组装
		for (int i = 0; i < excelVOList.size(); i++) {
			TPreEmpMainVo excel = excelVOList.get(i);
			if (Common.isEmpty(excel.getDeptNo()) || Common.isEmpty(excel.getEmpIdcard()) || Common.isEmpty(excel.getEmpNatrue()) || Common.isEmpty(excel.getFileProvince())) {
				errorMessageList.add(new ErrorMessage(excel.getRowIndex(), "完善信息不可为空！"));
			} else {
				// 插入
				main = baseMapper.getTPreEmpMainByCardAndDeptNo(excel.getEmpIdcard(), excel.getDeptNo());
				if (main == null || Common.isEmpty(main.getId()) || Common.isEmpty(main.getStatus())) {
					errorMessageList.add(new ErrorMessage(excel.getRowIndex(), "未找到预入职主表！"));
				} else {
					if (!CommonConstants.ONE_STRING.equals(main.getStatus())) {
						errorMessageList.add(new ErrorMessage(excel.getRowIndex(), "状态不为待完善，不可编辑！"));
					} else {
						employee = tPreEmployeeInfoService.getTPreEmployeeInfoList(main.getId());
						if (employee == null || Common.isEmpty(employee.getId())) {
							errorMessageList.add(new ErrorMessage(excel.getRowIndex(), "未找到预入职人员表！"));
						} else {
							project = tPreEmployeeProjectService.getTPreEmployeeProjectList(main.getId());
							if (project == null || Common.isEmpty(project.getId())) {
								errorMessageList.add(new ErrorMessage(excel.getRowIndex(), "未找到预入职项目档案表！"));
							} else {
								employee.setEmpNatrue(excel.getEmpNatrue());
								project.setEmpNatrue(excel.getEmpNatrue());
								employee.setFileProvince(Integer.parseInt(excel.getFileProvince()));
								if (Common.isEmpty(excel.getFileCity())) {
									employee.setFileCity(CommonConstants.ZERO_INT);
								} else {
									try {
										employee.setFileCity(Integer.parseInt(excel.getFileCity()));
									} catch (Exception e) {
										errorMessageList.add(new ErrorMessage(excel.getRowIndex(), "未找到市！"));
									}
								}
								if (Common.isEmpty(excel.getFileTown())) {
									employee.setFileTown(CommonConstants.ZERO_INT);
								} else {
									try {
										employee.setFileTown(Integer.parseInt(excel.getFileTown()));
									} catch (Exception e) {
										errorMessageList.add(new ErrorMessage(excel.getRowIndex(), "未找到县！"));
									}
								}
								tPreEmployeeInfoService.updateById(employee);
								tPreEmployeeProjectService.updateById(project);
								main.setEmpNatrue(excel.getEmpNatrue());
								main.setStatus(CommonConstants.TWO_STRING);
								this.updateById(main);
							}
						}
					}
				}
			}
		}
	}

	@Override
	public R<String> doAudit(String id, String status, String auditRemark) {
		if (Common.isEmpty(id) && Common.isEmpty(status)) {
			return R.failed("id、status不可为空！");
		}
		TPreEmpMain preEmpMain = this.getById(id);
		if (preEmpMain == null || Common.isEmpty(preEmpMain.getStatus()) || !CommonConstants.TWO_STRING.equals(preEmpMain.getStatus())) {
			return R.failed("请确认ID与状态！");
		}
		if (!CommonConstants.THREE_STRING.equals(status) && !CommonConstants.FOUR_STRING.equals(status)) {
			return R.failed("审核状态不对！");
		}
		if (CommonConstants.THREE_STRING.equals(status) && Common.isEmpty(auditRemark)) {
			return R.failed("审核不通过，原因必填！");
		}
		YifuUser user = SecurityUtils.getUser();
		if (user == null || Common.isEmpty(user.getId())) {
			return R.failed("未找到登录信息！");
		}
		preEmpMain.setStatus(status);
		preEmpMain.setAuditId(user.getId());
		preEmpMain.setAuditRemark(auditRemark);
		preEmpMain.setAuditName(user.getNickname());
		preEmpMain.setAuditTime(new Date());

		// 审核日志
		TPreEmpMainLog auditLog = new TPreEmpMainLog();
		auditLog.setAuditId(user.getId());
		auditLog.setAuditName(user.getNickname());
		auditLog.setAuditTime(new Date());
		auditLog.setAuditRemark(auditRemark);
		auditLog.setMainId(preEmpMain.getId());
		auditLog.setAuditResult(status);

		R<PreEmpMainDetailVo> voR = this.getInfoById(id);
		PreEmpMainDetailVo vo = null;
		if (voR != null && voR.getCode() == CommonConstants.SUCCESS) {
			// 转到更新档案去
			vo = voR.getData();
			this.updateById(preEmpMain);
			tPreEmpMainLogService.save(auditLog);
			return updateToEmployeeByPre(vo);
		} else {
			return R.failed("未找到信息，未更新！");
		}
	}

	@Override
	public R<List<ErrorVO>> doBatchAudit(List<String> ids, String status, String auditRemark) {
		if (Common.isEmpty(ids) && Common.isEmpty(status)) {
			return R.failed("id、status不可为空！");
		}
		if (!CommonConstants.THREE_STRING.equals(status) && !CommonConstants.FOUR_STRING.equals(status)) {
			return R.failed("审核状态不对！");
		}
		if (CommonConstants.THREE_STRING.equals(status) && Common.isEmpty(auditRemark)) {
			return R.failed("审核不通过，原因必填！");
		}
		YifuUser user = SecurityUtils.getUser();
		if (user == null || Common.isEmpty(user.getId())) {
			return R.failed("未找到登录信息！");
		}
		List<ErrorVO> returnList = new ArrayList<>();
		TPreEmpMain preEmpMain;
		ErrorVO errorVo;
		int i = 1;
		boolean isTrue = true;
		for (String id : ids) {
			errorVo = new ErrorVO();
			errorVo.setResult(CommonConstants.ZERO_INT);
			errorVo.setLineNum(i++);
			preEmpMain = this.getById(id);
			if (preEmpMain == null || Common.isEmpty(preEmpMain.getStatus()) || !CommonConstants.TWO_STRING.equals(preEmpMain.getStatus())) {
				errorVo.setErrorInfo("请确认ID与状态！");
				returnList.add(errorVo);
				isTrue = false;
			} else {
				errorVo.setResult(CommonConstants.ONE_INT);
				errorVo.setMainName(preEmpMain.getEmpIdcard() + CommonConstants.DOWN_LINE_STRING + preEmpMain.getDeptNo());
				returnList.add(errorVo);
				preEmpMain.setStatus(status);
				preEmpMain.setAuditId(user.getId());
				preEmpMain.setAuditRemark(auditRemark);
				preEmpMain.setAuditName(user.getNickname());
				preEmpMain.setAuditTime(new Date());

				// 审核日志
				TPreEmpMainLog auditLog = new TPreEmpMainLog();
				auditLog.setAuditId(user.getId());
				auditLog.setAuditName(user.getNickname());
				auditLog.setAuditTime(new Date());
				auditLog.setAuditRemark(auditRemark);
				auditLog.setMainId(preEmpMain.getId());
				auditLog.setAuditResult(status);

				R<PreEmpMainDetailVo> voR = this.getInfoById(id);
				PreEmpMainDetailVo vo = null;
				if (voR != null && voR.getCode() == CommonConstants.SUCCESS) {
					// 转到更新档案去
					vo = voR.getData();
					updateToEmployeeByPre(vo);
					this.updateById(preEmpMain);
					tPreEmpMainLogService.save(auditLog);
				}
			}
		}
		if (isTrue) {
			return R.ok(returnList);
		} else {
			return R.failed(returnList);
		}
	}

	private List<String> getNewArrayList(String[] strArr) {
		return Arrays.asList(strArr);
	}

	/**
	 * 预入职导出全量
	 *
	 * @return
	 */
	@Override
	public void exportAll(HttpServletResponse response, TPreEmpMainSearchVo searchVo) {
		String name = "预入职导出全量";
		String fileName = name + DateUtil.getThisTime() + ".xlsx";
		//获取要导出的列表
		List<TPreMainExportAllVO> list = Lists.newArrayList();
		long count = baseMapper.getTPreEmpMainAllCount(searchVo);
		ServletOutputStream out = null;
		try {
			out = response.getOutputStream();
			response.setContentType(CommonConstants.MULTIPART_FORM_DATA);
			response.setCharacterEncoding("utf-8");
			response.setHeader(CommonConstants.CONTENT_DISPOSITION, CommonConstants.ATTACHMENT_FILENAME + URLEncoder.encode(fileName, CommonConstants.UTF8));
			// 这里 需要指定写用哪个class去写，然后写到第一个sheet，然后文件流会自动关闭
			List<List<String>> headList = Lists.newArrayList();
			headList.add(this.getNewArrayList(new String[]{"状态", "状态"}));
			headList.add(this.getNewArrayList(new String[]{"提交时间", "提交时间"}));
			String oneTitle = "员工基本信息";
			headList.add(this.getNewArrayList(new String[]{oneTitle, "员工主码"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "员工类型"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "员工姓名"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "身份证号"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "性别"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "身份证期限"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "身份证开始日期"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "身份证截止日期"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "出生日期"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "年龄"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "婚姻状况"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "民族"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "政治面貌"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "手机号码"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "邮箱"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "户籍所在地"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "户口性质"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "档案所在地"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "档案状态"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "通信地址"}));
			oneTitle = "在项信息";
			headList.add(this.getNewArrayList(new String[]{oneTitle, "客户名称"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "项目名称"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "业务类型"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "合同类型"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "工时制"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "就职岗位"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "入职日期"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "试用期"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "标签"}));
			oneTitle = "紧急联络人";
			headList.add(this.getNewArrayList(new String[]{oneTitle, "姓名"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "与本人关系"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "联系地址"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "联系电话"}));
			oneTitle = "最高教育经历";
			headList.add(this.getNewArrayList(new String[]{oneTitle, "学校"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "专业"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "学历"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "是否大专及以上"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "最高学历"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "入学时间"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "毕业时间"}));
			oneTitle = "主要工作经历";
			headList.add(this.getNewArrayList(new String[]{oneTitle, "是否为首份工作"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "工作单位"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "工作岗位"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "开始工作日期"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "结束工作日期"}));
			oneTitle = "主要家庭成员信息";
			headList.add(this.getNewArrayList(new String[]{oneTitle, "成员姓名"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "与本人关系"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "手机号码"}));
			oneTitle = "职业资格信息";
			headList.add(this.getNewArrayList(new String[]{oneTitle, "是否有职业资格证书"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "申报年度"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "职业资格名称"}));
			oneTitle = "伤残信息";
			headList.add(this.getNewArrayList(new String[]{oneTitle, "是否曾被认定为工伤"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "是否有职业病"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "职业病名称"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "是否有传染性疾病"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "传染病名称"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "是否持有残疾人证明"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "伤残病名称"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "伤残等级"}));
			headList.add(this.getNewArrayList(new String[]{oneTitle, "是否从事过井下、高空、高温、特别繁重体力劳动以及有毒有害工种"}));
			oneTitle = "不良记录";
			headList.add(this.getNewArrayList(new String[]{oneTitle, "不良记录描述"}));
			ExcelWriter excelWriter = EasyExcelFactory.write(out).head(headList).build();
			int index = 0;
			if (count > CommonConstants.ZERO_INT) {
				for (int i = 0; i <= count; i += CommonConstants.EXCEL_EXPORT_LIMIT) {
					// 获取实际记录
					searchVo.setLimitStart(i);
					searchVo.setLimitEnd(CommonConstants.EXCEL_EXPORT_LIMIT);
					list = baseMapper.getTPreEmpMainAllList(searchVo);
					if (Common.isNotNull(list)) {
						ExcelWriterSheetBuilder writeSheet = EasyExcelFactory.writerSheet(name + index);
						excelWriter.write(list, writeSheet.build());
						index++;
					}
					if (Common.isNotNull(list)) {
						list.clear();
					}
				}
			} else {
				WriteSheet writeSheet = EasyExcelFactory.writerSheet(name + index).build();
				excelWriter.write(list, writeSheet);
			}
			if (Common.isNotNull(list)) {
				list.clear();
			}
			out.flush();
			excelWriter.finish();
		} catch (Exception e) {
			log.error("执行异常", e);
		} finally {
			try {
				if (null != out) {
					out.close();
				}
			} catch (IOException e) {
				log.error("执行异常", e);
			}
		}
	}

	/**
	 * @Description: 合并单元格
	 * @Author: hgw
	 * @Date: 2024/6/27 10:35
	 * @return: void
	 **/
	private void getHeBingHang(List<TPreMainExportAllVO> list, ExcelWriterSheetBuilder writeSheet) {
		OnceAbsoluteMergeStrategy strategy;
		int startRow = 0;
		int endRow = 0;
		boolean preBoo;
		boolean afterBoo;

		int startRow0 = 0;
		int endRow0 = 0;
		int startRow1 = 0;
		int endRow1 = 0;
		int startRow2 = 0;
		int endRow2 = 0;
		int startRow3 = 0;
		int endRow3 = 0;
		int startRow4 = 0;
		int endRow4 = 0;
		int startRow5 = 0;
		int endRow5 = 0;
		int startRow6 = 0;
		int endRow6 = 0;
		int startRow7 = 0;
		int endRow7 = 0;
		int startRow8 = 0;
		int endRow8 = 0;
		int startRow9 = 0;
		int endRow9 = 0;
		for (int j = 1; j < list.size() - 1; j++) {
			// 0状态
			preBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j - 1).getField6())) && (Common.isNotNull(list.get(j).getField1()) &&list.get(j).getField1().equals(list.get(j - 1).getField1()));
			afterBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j + 1).getField6())) && (Common.isNotNull(list.get(j).getField1()) &&list.get(j).getField1().equals(list.get(j + 1).getField1()));
			if (preBoo && startRow0 == 0) {
				startRow0 = 1 + j;
			}
			if (!afterBoo && startRow0 > 0) {
				endRow0 = 2 + j;
			}
			if ( j == list.size() - 2 && startRow0 > 0) {
				endRow0 = 3 + j;
			}
			if (startRow0 > 0 && endRow0 > 0) {
				strategy = new OnceAbsoluteMergeStrategy(startRow0, endRow0, 0, 0);
				writeSheet.registerWriteHandler(strategy);
				startRow0 = 0;
				endRow0 = 0;
			}
			// 1提交时间
			preBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j - 1).getField6())) && (Common.isNotNull(list.get(j).getField2()) &&list.get(j).getField2().equals(list.get(j - 1).getField2()));
			afterBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j + 1).getField6())) && (Common.isNotNull(list.get(j).getField2()) &&list.get(j).getField2().equals(list.get(j + 1).getField2()));
			if (preBoo && startRow1 == 0) {
				startRow1 = 1 + j;
			}
			if (!afterBoo && startRow1 > 0) {
				endRow1 = 2 + j;
			}
			if ( j == list.size() - 2 && startRow1 > 0) {
				endRow1 = 3 + j;
			}
			if (startRow1 > 0 && endRow1 > 0) {
				strategy = new OnceAbsoluteMergeStrategy(startRow1, endRow1, 0, 0);
				writeSheet.registerWriteHandler(strategy);
				startRow1 = 0;
				endRow1 = 0;
			}
			// 1员工基本信息-身份证
			preBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j - 1).getField6()));
			afterBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j + 1).getField6()));
			if (startRow == 0) {
				if (preBoo) {
					startRow = 1 + j;
				} else if (afterBoo) {
					startRow = 2 + j;
				}
			}
			if (!afterBoo && startRow > 0) {
				endRow = 2 + j;
			}
			if ( j == list.size() - 2 && startRow > 0) {
				endRow = 3 + j;
			}
			if (startRow > 0 && endRow > 0) {
				for (int k = 2; k < 22; k++) {
					strategy = new OnceAbsoluteMergeStrategy(startRow, endRow, k, k);
					writeSheet.registerWriteHandler(strategy);
				}
				startRow = 0;
				endRow = 0;
			}
			// 2在项信息-项目名称
			preBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j - 1).getField6())) && (Common.isNotNull(list.get(j).getField24()) &&list.get(j).getField24().equals(list.get(j - 1).getField24()));
			afterBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j + 1).getField6())) && (Common.isNotNull(list.get(j).getField24()) &&list.get(j).getField24().equals(list.get(j + 1).getField24()));
			if (startRow2 == 0) {
				if (preBoo) {
					startRow2 = 1 + j;
				} else if (afterBoo) {
					startRow2 = 2 + j;
				}
			}
			if (!afterBoo && startRow2 > 0) {
				endRow2 = 2 + j;
			}
			if ( j == list.size() - 2 && startRow2 > 0) {
				endRow2 = 3 + j;
			}
			if (startRow2 > 0 && endRow2 > 0) {
				for (int k = 22; k < 31; k++) {
					strategy = new OnceAbsoluteMergeStrategy(startRow2, endRow2, k, k);
					writeSheet.registerWriteHandler(strategy);
				}
				startRow2 = 0;
				endRow2 = 0;
			}
			// 3紧急联络人-姓名
			preBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j - 1).getField6())) && (Common.isNotNull(list.get(j).getField32()) &&list.get(j).getField32().equals(list.get(j - 1).getField32()));
			afterBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j + 1).getField6())) && (Common.isNotNull(list.get(j).getField32()) &&list.get(j).getField32().equals(list.get(j + 1).getField32()));
			if (startRow3 == 0) {
				if (preBoo) {
					startRow3 = 1 + j;
				} else if (afterBoo) {
					startRow3 = 2 + j;
				}
			}
			if (!afterBoo && startRow3 > 0) {
				endRow3 = 2 + j;
			}
			if ( j == list.size() - 2 && startRow3 > 0) {
				endRow3 = 3 + j;
			}
			if (startRow3 > 0 && endRow3 > 0) {
				for (int k = 31; k < 35; k++) {
					strategy = new OnceAbsoluteMergeStrategy(startRow3, endRow3, k, k);
					writeSheet.registerWriteHandler(strategy);
				}
				startRow3 = 0;
				endRow3 = 0;
			}
			// 4最高教育经历-专业
			preBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j - 1).getField6())) && (Common.isNotNull(list.get(j).getField37()) &&list.get(j).getField37().equals(list.get(j - 1).getField37()));
			afterBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j + 1).getField6())) && (Common.isNotNull(list.get(j).getField37()) &&list.get(j).getField37().equals(list.get(j + 1).getField37()));
			if (preBoo && startRow4 == 0) {
				startRow4 = 1 + j;
			}
			 if (!afterBoo && startRow4 > 0) {
				endRow4 = 2 + j;
			}
			if ( j == list.size() - 2 && startRow4 > 0) {
				endRow4 = 3 + j;
			}
			if (startRow4 > 0 && endRow4 > 0) {
				for (int k = 35; k < 42; k++) {
					strategy = new OnceAbsoluteMergeStrategy(startRow4, endRow4, k, k);
					writeSheet.registerWriteHandler(strategy);
				}
				startRow4 = 0;
				endRow4 = 0;
			}
			// 5主要工作经历-专业
			preBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j - 1).getField6())) && (Common.isNotNull(list.get(j).getField44()) &&list.get(j).getField44().equals(list.get(j - 1).getField44()));
			afterBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j + 1).getField6())) && (Common.isNotNull(list.get(j).getField44()) &&list.get(j).getField44().equals(list.get(j + 1).getField44()));
			if (preBoo && startRow5 == 0) {
				startRow5 = 1 + j;
			}
			 if (!afterBoo && startRow5 > 0) {
				endRow5 = 2 + j;
			}
			if ( j == list.size() - 2 && startRow5 > 0) {
				endRow5 = 3 + j;
			}
			if (startRow5 > 0 && endRow5 > 0) {
				for (int k = 42; k < 47; k++) {
					strategy = new OnceAbsoluteMergeStrategy(startRow5, endRow5, k, k);
					writeSheet.registerWriteHandler(strategy);
				}
				startRow5 = 0;
				endRow5 = 0;
			}
			// 6主要家庭成员信息-成员姓名
			preBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j - 1).getField6())) && (Common.isNotNull(list.get(j).getField47()) &&list.get(j).getField47().equals(list.get(j - 1).getField47()));
			afterBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j + 1).getField6())) && (Common.isNotNull(list.get(j).getField47()) &&list.get(j).getField47().equals(list.get(j + 1).getField47()));
			if (preBoo && startRow6 == 0) {
				startRow6 = 1 + j;
			}
			 if (!afterBoo && startRow6 > 0) {
				endRow6 = 2 + j;
			}
			if ( j == list.size() - 2 && startRow6 > 0) {
				endRow6 = 3 + j;
			}
			if (startRow6 > 0 && endRow6 > 0) {
				for (int k = 47; k < 50; k++) {
					strategy = new OnceAbsoluteMergeStrategy(startRow6, endRow6, k, k);
					writeSheet.registerWriteHandler(strategy);
				}
				startRow6 = 0;
				endRow6 = 0;
			}
			// 7职业资格信息-职业资格名称
			preBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j - 1).getField6())) && (Common.isNotNull(list.get(j).getField53()) &&list.get(j).getField53().equals(list.get(j - 1).getField53()));
			afterBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j + 1).getField6())) && (Common.isNotNull(list.get(j).getField53()) &&list.get(j).getField53().equals(list.get(j + 1).getField53()));
			if (preBoo && startRow7 == 0) {
				startRow7 = 1 + j;
			}
			 if (!afterBoo && startRow7 > 0) {
				endRow7 = 2 + j;
			}
			if ( j == list.size() - 2 && startRow7 > 0) {
				endRow7 = 3 + j;
			}
			if (startRow7 > 0 && endRow7 > 0) {
				for (int k = 50; k < 53; k++) {
					strategy = new OnceAbsoluteMergeStrategy(startRow7, endRow7, k, k);
					writeSheet.registerWriteHandler(strategy);
				}
				startRow7 = 0;
				endRow7 = 0;
			}
			// 8伤残信息-职业资格名称+传染病名称+伤残病名称
			preBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j - 1).getField6())) && (Common.isNotNull(list.get(j).getField56()) &&list.get(j).getField56().equals(list.get(j - 1).getField56()))
					&& (Common.isNotNull(list.get(j).getField58()) &&list.get(j).getField58().equals(list.get(j - 1).getField58()))
					&& (Common.isNotNull(list.get(j).getField60()) &&list.get(j).getField60().equals(list.get(j - 1).getField60()));
			afterBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j + 1).getField6())) && (Common.isNotNull(list.get(j).getField56()) &&list.get(j).getField56().equals(list.get(j + 1).getField56()))
					&& (Common.isNotNull(list.get(j).getField58()) &&list.get(j).getField58().equals(list.get(j + 1).getField58()))
					&& (Common.isNotNull(list.get(j).getField60()) &&list.get(j).getField60().equals(list.get(j + 1).getField60()));
			if (preBoo && startRow8 == 0) {
				startRow8 = 1 + j;
			}
			 if (!afterBoo && startRow8 > 0) {
				endRow8 = 2 + j;
			}
			if ( j == list.size() - 2 && startRow8 > 0) {
				endRow8 = 3 + j;
			}
			if (startRow8 > 0 && endRow8 > 0) {
				for (int k = 53; k < 62; k++) {
					strategy = new OnceAbsoluteMergeStrategy(startRow8, endRow8, k, k);
					writeSheet.registerWriteHandler(strategy);
				}
				startRow8 = 0;
				endRow8 = 0;
			}
			// 9不良记录
			preBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j - 1).getField6())) && (Common.isNotNull(list.get(j).getField63()) &&list.get(j).getField63().equals(list.get(j - 1).getField63()));
			afterBoo = (Common.isNotNull(list.get(j).getField6()) &&list.get(j).getField6().equals(list.get(j + 1).getField6())) && (Common.isNotNull(list.get(j).getField63()) &&list.get(j).getField63().equals(list.get(j + 1).getField63()));
			if (preBoo && startRow9 == 0) {
				startRow9 = 1 + j;
			}
			 if (!afterBoo && startRow9 > 0) {
				endRow9 = 2 + j;
			}
			if ( j == list.size() - 2 && startRow9 > 0) {
				endRow9 = 3 + j;
			}
			if (startRow9 > 0 && endRow9 > 0) {
				strategy = new OnceAbsoluteMergeStrategy(startRow9, endRow9, 62, 62);
				writeSheet.registerWriteHandler(strategy);
				startRow9 = 0;
				endRow9 = 0;
			}
		}
	}

}
