package com.fendou.archive.service.impl;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.BeanUtils;
import com.fendou.archive.dao.ArchiveDao;
import com.fendou.archive.po.Archive;
import com.fendou.archive.po.CArchive;
import com.fendou.archive.service.ArchiveService;
import com.fendou.archive.web.form.ArchiveForm;
import com.fendou.common.dao.CommonDao;
import com.fendou.common.po.Common;
import com.fendou.department.dao.DepartmentDao;
import com.fendou.engage.dao.MajorDao;
import com.fendou.engage.dao.ResumeDao;
import com.fendou.engage.po.Resume;
import com.fendou.engage.po.ResumeVo;
import com.fendou.salary.dao.SalaryStandardDao;
import com.fendou.system.po.Page;
import com.fendou.system.test.ServiceUtil;
import com.fendou.system.util.DateConvert;
import com.fendou.system.util.DateUtil;
import com.fendou.system.util.PageUtil;
public class ArchiveServiceImpl implements ArchiveService {
private ArchiveDao archiveDao;
private CommonDao commonDao;
private DepartmentDao departmentDao;
private MajorDao majorDao;
private SalaryStandardDao salaryStandardDao;
private ResumeDao resumeDao;
public void setResumeDao(ResumeDao resumeDao) {
this.resumeDao = resumeDao;
}
private Page page;
public Page getPage() {
return page;
}
public void setPage(Page page) {
this.page = page;
}
public void setSalaryStandardDao(SalaryStandardDao salaryStandardDao) {
this.salaryStandardDao = salaryStandardDao;
}
public void setMajorDao(MajorDao majorDao) {
this.majorDao = majorDao;
}
public void setDepartmentDao(DepartmentDao departmentDao) {
this.departmentDao = departmentDao;
}
public void setCommonDao(CommonDao commonDao) {
this.commonDao = commonDao;
}
public void setArchiveDao(ArchiveDao archiveDao) {
this.archiveDao = archiveDao;
}
public void deleteArchive(int id) {
Archive archive = archiveDao.selectArchive(id);
archive.setState('2');
archive.setFileChangAmount((short) (archive.getFileChangAmount() + 1));
archiveDao.updateArchive(archive);
}
public Page getPage(String where, Object[] values, String currPage) {
Page page = archiveDao.getPage(where, values);
this.setPage(PageUtil.getPageUtil().setCurrpage(currPage, page));
return page;
}
public Page getCPage(String where, Object[] values, String currPage) {
Page page = archiveDao.getPage(" where state=2", values);
this.setPage(PageUtil.getPageUtil().setCurrpage(currPage, page));
return page;
}
public void insertArchive(ArchiveForm form) {
Archive archive = new Archive();
BeanUtils.copyProperties(form, archive);
archive.setHumanCode(System.currentTimeMillis() + "");
archive.setBirthday(DateConvert.convert(form.getBirth()));
if (form.getNationalityId() != 0) {
Common country = commonDao.selectCommon(form.getNationalityId());
archive.setNationality(country);
// 国籍为中国必须给一个民族
if ("中国".equals(country.getVal()))
archive.setRace(commonDao.selectCommon(form.getRaceId()));
}
if (form.getReligionId() != 0)
archive.setReligion(commonDao.selectCommon(form.getReligionId()));
if (form.getPartyId() != 0)
archive.setParty(commonDao.selectCommon(form.getPartyId()));
archive.setPosition(commonDao.selectCommon(form.getPositionId()));
archive.setEducatedDegree(commonDao.selectCommon(form
.getEducatedDegreeId()));
archive.setDepartment(departmentDao.selectDepartment(form
.getDepartmentId()));
archive.setMajor(majorDao.selectMajor(form.getMajorId()));
archive.setSalaryStandard(salaryStandardDao.selectObject(form
.getSalaryStandardId()));
archive
.setRegister(ServiceUtil.getServiceUtil()
.getUser(form.getUid()));
archive.setRegistTime(new Date());
archiveDao.insertArchive(archive);
}
public List<Archive> selectArchiveByHQL(String where, Object[] values,
String currPage, String[] prama) {
return archiveDao.selectByHQL("from Archive " + where, values, this
.getPage(), prama);
}
public List<Archive> selectArchiveByHQL(String where, Object[] values,
String currPage) {
return archiveDao.selectByHQL("from Archive " + where, values, this
.getPage());
}
public Archive selectArchiveById(int id) {
return archiveDao.selectArchive(id);
}
public void updateArchive(ArchiveForm form) {
Archive archive = archiveDao.selectArchive(form.getArId());
if(archive.getCheckStatus()=='2') {
CArchive carchive = new CArchive();
BeanUtils.copyProperties(archive, carchive);
archiveDao.insertCArchive(carchive);
}
BeanUtils.copyProperties(form, archive);
archive.setBirthday(DateConvert.convert(form.getBirth()));
if (form.getNationalityId() != 0) {
Common country = commonDao.selectCommon(form.getNationalityId());
archive.setNationality(country);
// 国籍为中国必须给一个民族
if ("中国".equals(country.getVal()))
archive.setRace(commonDao.selectCommon(form.getRaceId()));
}
if (form.getReligionId() != 0)
archive.setReligion(commonDao.selectCommon(form.getReligionId()));
if (form.getPartyId() != 0)
archive.setParty(commonDao.selectCommon(form.getPartyId()));
archive.setPosition(commonDao.selectCommon(form.getPositionId()));
archive.setEducatedDegree(commonDao.selectCommon(form
.getEducatedDegreeId()));
archive.setDepartment(departmentDao.selectDepartment(form
.getDepartmentId()));
archive.setMajor(majorDao.selectMajor(form.getMajorId()));
archive.setSalaryStandard(salaryStandardDao.selectObject(form
.getSalaryStandardId()));
archive
.setChanger((ServiceUtil.getServiceUtil()
.getUser(form.getUid())));
archive.setChangeTime(new Date());
archive.setFileChangAmount((short) (archive.getFileChangAmount() + 1));
archive.setLastlyChangeTime(new Date());
archiveDao.updateArchive(archive);
}
public List<Archive> selectArchiveByQBC(String[] param, Object[] obj,
Page page, String[] paramName) {
Criterion[] criterion = null;
if (param != null && param.length > 0) {
criterion = new Criterion[param.length];
for (int i = 0; i < param.length; i++) {
criterion[i] = Restrictions.eq(param[i], obj[i]);
}
}
return archiveDao.selectByQBC(criterion, page, paramName);
}
public Archive selectArchiveById(String id, String[] paramName) {
return archiveDao.selectArchive(Integer.parseInt(id), paramName);
}
public List<CArchive> selectCArchiveByHQL(String hql, Object[] obj,
String currPage, String[] paramName) {
if (!"".equals(hql) && hql != null) {
hql = "where " + hql;
}
return archiveDao.selectCByHQL("from CArchive " + hql, obj, this
.getCPage(hql, obj, currPage), paramName);
}
public CArchive selectCArchiveById(String id, String[] paramName) {
return archiveDao.selectCArchive(Integer.parseInt(id), paramName);
}
public Page getPage(Criterion[] criterion, String currPage) {
Page page = archiveDao.getPage(criterion);
this.setPage(PageUtil.getPageUtil().setCurrpage(currPage, page));
return page;
}
public List<Archive> selectArchiveByQBC(Map<String, Object> map,
String currPage, String[] paramName) {
Criterion[] criterion = new Criterion[map.size()];
int i = 0;
String name=(String)map.get("name");
String humanCode = (String)map.get("humanCode");
String majorName = (String)map.get("majorName");
String position = (String)map.get("position");
String race = (String)map.get("race");
String sex = (String)map.get("sex");
String registTime = (String)map.get("registTime");
String changeTime = (String)map.get("changeTime");
String checkStatus = (String)map.get("checkStatus");
String state = (String)map.get("state");
int from = (Integer)map.g