package com.empl.mgr.service.impl;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import com.empl.mgr.constant.AddressType;
import com.empl.mgr.constant.EmployeesLogType;
import com.empl.mgr.constant.EmployeesState;
import com.empl.mgr.constant.PageConstant;
import com.empl.mgr.constant.PhoneImageSize;
import com.empl.mgr.constant.TimeFormatConstant;
import com.empl.mgr.constant.TrainLogState;
import com.empl.mgr.constant.TrainingState;
import com.empl.mgr.dao.AddressDao;
import com.empl.mgr.dao.ChooseEducationDao;
import com.empl.mgr.dao.ChooseMarriageDao;
import com.empl.mgr.dao.ChooseNationalDao;
import com.empl.mgr.dao.ChoosePoliticsDao;
import com.empl.mgr.dao.CityDao;
import com.empl.mgr.dao.CountyDao;
import com.empl.mgr.dao.DepartmentDao;
import com.empl.mgr.dao.EmployeesBasicDao;
import com.empl.mgr.dao.EmployeesCompanyDao;
import com.empl.mgr.dao.EmployeesDetailDao;
import com.empl.mgr.dao.EmployeesLogDao;
import com.empl.mgr.dao.EmployeesTrainingLogDao;
import com.empl.mgr.dao.PositionDao;
import com.empl.mgr.dao.ProvinceDao;
import com.empl.mgr.dao.TownshipDao;
import com.empl.mgr.dao.TrainingDao;
import com.empl.mgr.dao.VillageDao;
import com.empl.mgr.dto.EemplByNoneTrainingLogDto;
import com.empl.mgr.dto.EmployeesAddressDto;
import com.empl.mgr.dto.EmployeesBasicInfoDto;
import com.empl.mgr.dto.EmployeesCompnayDto;
import com.empl.mgr.dto.EmployeesInfoDto;
import com.empl.mgr.dto.EmployeesInternshipListDto;
import com.empl.mgr.dto.EmployeesLogDto;
import com.empl.mgr.dto.EmployeesTrainingRecordDto;
import com.empl.mgr.field.TeAddressField;
import com.empl.mgr.field.TeDepartmentField;
import com.empl.mgr.field.TeEmployeesBasicField;
import com.empl.mgr.field.TeEmployeesCompanyField;
import com.empl.mgr.field.TeEmployeesDetailField;
import com.empl.mgr.field.TeEmployeesLogField;
import com.empl.mgr.field.TeEmployeesTrainingLogField;
import com.empl.mgr.field.TePositionField;
import com.empl.mgr.model.TeAddress;
import com.empl.mgr.model.TeDepartment;
import com.empl.mgr.model.TeEmployeesBasic;
import com.empl.mgr.model.TeEmployeesCompany;
import com.empl.mgr.model.TeEmployeesDetail;
import com.empl.mgr.model.TeEmployeesLog;
import com.empl.mgr.model.TeEmployeesTrainingLog;
import com.empl.mgr.model.TePosition;
import com.empl.mgr.model.TeTraining;
import com.empl.mgr.service.EmployeesLogService;
import com.empl.mgr.service.EmployeesService;
import com.empl.mgr.support.JSONReturn;
import com.empl.mgr.utils.CompareUtil;
import com.empl.mgr.utils.DateTimeUtil;
import com.empl.mgr.utils.PageUtils;
@Scope
@Service
@Transactional(readOnly = true)
public class EmployeesServiceImpl implements EmployeesService {
@Autowired
private ChooseEducationDao chooseEducationDao;
@Autowired
private ChooseMarriageDao chooseMarriageDao;
@Autowired
private ChooseNationalDao chooseNationalDao;
@Autowired
private ChoosePoliticsDao choosePoliticsDao;
@Autowired
private PositionDao positionDao;
@Autowired
private DepartmentDao departmentDao;
@Autowired
private EmployeesBasicDao employeesBasicDao;
@Autowired
private EmployeesCompanyDao employeesCompanyDao;
@Autowired
private EmployeesDetailDao employeesDetailDao;
@Autowired
private AddressDao addressDao;
@Autowired
private ProvinceDao provinceDao;
@Autowired
private CityDao cityDao;
@Autowired
private CountyDao countyDao;
@Autowired
private TownshipDao townshipDao;
@Autowired
private VillageDao villageDao;
@Autowired
private EmployeesTrainingLogDao employeesTrainingLogDao;
@Autowired
private TrainingDao trainingDao;
@Autowired
private EmployeesLogService employeesLogService;
@Autowired
private EmployeesLogDao employeesLogDao;
public JSONReturn findChoose() {
// TODO Auto-generated method stub
Map<String, Object> map = new HashMap<String, Object>();
map.put("educationList", chooseEducationDao.findAll());
map.put("marriageList", chooseMarriageDao.findAll());
map.put("nationalList", chooseNationalDao.findAll());
map.put("politicList", choosePoliticsDao.findAll());
return JSONReturn.buildSuccess(map);
}
@Transactional
public JSONReturn saveEmployeesInfo(EmployeesInfoDto dto, String acctName) {
// TODO Auto-generated method stub
if (CompareUtil.isEmpty(dto))
return JSONReturn.buildFailure("员工信息保存失败!");
if (CollectionUtils.isNotEmpty(employeesBasicDao.findByProperty(TeEmployeesBasicField.EM_IDENTITY,
dto.getIdentity())))
return JSONReturn.buildFailure("保存员工信息失败, 身份证重复!");
TeEmployeesBasic basic = conversionEmployeesBasic(null, dto, acctName);
employeesBasicDao.save(basic); // 保存员工基本信息
basic.setEmState(EmployeesState.EMPL_INTERNSHIP); // 默认为实习员工
employeesDetailDao.save(conversionEmployeesDetail(null, dto, basic.getEmId())); // 保存员工详细信息
conversionEmployeesCompany(dto.getCompany(), basic.getEmId()); // 保存员工工作经历信息
basic.setEmCensusRegister(analyzeAddress(dto.getRegister(), basic.getEmId(), AddressType.REGISTER, null, true)); // 解析户籍地址
basic.setEmCurrentAddress(analyzeAddress(dto.getCurrent(), basic.getEmId(), AddressType.CURRENT, null, true)); // 解析现居住地址
employeesLogService.save(basic.getEmId(), acctName, EmployeesLogType.RECORDING_INFORMATION, "");
return JSONReturn.buildSuccess(basic.getEmId());
}
/*
* 解析并转换员工地址信息
* te5l.com [K]
*/
private long analyzeAddress(EmployeesAddressDto dto, long emId, int type, TeAddress ads, boolean isSave) {
// TODO Auto-generated method stub
if (CompareUtil.isEmpty(ads))
ads = new TeAddress();
ads.setAdsType(type);
ads.setAdsProvince(dto.getProvince());
ads.setAdsCity(dto.getCity());
ads.setAdsCounty(dto.getCounty());
ads.setAdsTownship(dto.getTownship());
ads.setAdsVillage(dto.getVillage());
ads.setAdsDetailed(dto.getDetailed());
if (isSave)
addressDao.save(ads);
return ads.getAdsId();
}
/*
* 解析并转换员工工作经历信息
* te5l.com [K]
*/
private boolean conversionEmployeesCompany(EmployeesCompnayDto[] companyArray, long emId) {
// TODO Auto-generated method stub
if (ArrayUtils.isEmpty(companyArray))
return false;
for (EmployeesCompnayDto dto : companyArray) {
TeEmployeesCompany company = new TeEmployeesCompany();
company.setEmplNo(emId);
company.setComName(dto.getName());
company.setComParticipateTime(dto.getState());
company.setComLeaveTime(dto.getEnd());
company.setComPosition(dto.getJobs());
company.setComReason(dto.getReason());
employeesCompanyDao.save(company);
}
return true;
}
/*
* 解析并转换员工详细信息
* te5l.com [K]
*/
private TeEmployeesDetail conversionEmployeesDetail(TeEmployeesDetail detail, EmployeesInfoDto dto, long emId) {
// TODO Auto-generated method stub
if (CompareUtil.isEmpty(detail))
detail = new TeEmployeesDetail();
detail.setEmplNo(emId);
detail.setEmContact(dto.getContact());
detail.setEmEmergencyContact(dto.getEmergencyContact());
detail.setEmEmergencyPhone(dto.getEmergencyPhone());
detail.setEmSchool(dto.getSchool());
detail.setEmProfessional(dto.getProfessional());
detail.setEmGraduationT