package com.wechat.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wechat.dao.MdeWorkExperienceDao;
import com.wechat.model.dbEntity.MdeWorkExperience;
import com.wechat.model.dto.WorkExperienceBaseDto;

@Service
@Transactional
public class MdeWorkExperienceService {

	@Autowired
	private MdeWorkExperienceDao mdeWorkExperienceDao;

	public MdeWorkExperience getInfoById(Integer workId) {
		return mdeWorkExperienceDao.getInfoById(workId);
	}
	/**
	 * 工作履历记录
	 * 
	 * @param userCode
	 * @return
	 */
	public int findByUserCodeCount(String userCode) {
		return mdeWorkExperienceDao.findByUserCodeCount(userCode);
	}

	/**
	 * 工作经历持久化
	 * 
	 * @param userCode
	 * @return
	 */
	public int insert(MdeWorkExperience mdeWorkExperience) {

		return mdeWorkExperienceDao.insert(mdeWorkExperience);
	}

	/**
	 * 根据userCode获取职位头衔
	 * 
	 * @param userCode
	 * @return
	 */
	public String findWorkPositionByUserCode(String userCode) {
		MdeWorkExperience work = mdeWorkExperienceDao.findWorkPTByUserCode(userCode);
		if (work == null) {
			return null;
		}
		return work.getPositionTitle();
	}

	/**
	 * 根据userCode获取职位头衔
	 * 
	 * @param userCode
	 * @return
	 */
	public MdeWorkExperience findShowExperienceByUserCode(String userCode) {
		return mdeWorkExperienceDao.findWorkPTByUserCode(userCode);
	}

	/**
	 * 获取工作简历列表（基本信息）
	 * 
	 * @param userCode
	 * @return
	 */
	public List<WorkExperienceBaseDto> getBaseWorkExperienceByUserCode(String userCode) {
		return mdeWorkExperienceDao.getBaseWorkExperienceByUserCode(userCode);
	}
	
	/**
	 * 获取工作简历列表（全部信息）
	 * 
	 * @param userCode
	 * @return
	 */
	public List<MdeWorkExperience> getAllWorkExperienceByUserCode(String userCode) {
		return mdeWorkExperienceDao.getAllWorkExperienceByUserCode(userCode);
	}

	public int update(MdeWorkExperience workExperience) {
		return mdeWorkExperienceDao.update(workExperience);
	}

	/**
	 * 获取职位头衔
	 * 
	 * @param userCode
	 * @return
	 */
	public MdeWorkExperience getWorkPositionTitleByUserCode(String userCode) {
		return mdeWorkExperienceDao.findWorkPTByUserCode(userCode);
	}

	public int delete(Integer workId) {
		return mdeWorkExperienceDao.delete(workId);
	}

	public int updatePositionTitle(MdeWorkExperience workExperience) {
		return mdeWorkExperienceDao.updatePositionTitle(workExperience);
	}

	/**
	 * 获取最近一次工作经历
	 * 
	 * @param userCode
	 * @return
	 */
//	public List<MdeWorkExperience> getWorkExperienceAndQuitDateDesc(String userCode) {
//		return mdeWorkExperienceDao.getWorkExperienceAndQuitDateDesc(userCode);
//	}

	/**
	 * 获取离职时间为空并按入职时间降序
	 * 
	 * @param userCode
	 * @return
	 */
//	public List<MdeWorkExperience> getQuitDateIsNull(String userCode) {
//		return mdeWorkExperienceDao.getQuitDateIsNull(userCode);
//	}

	/**
	 * 修改当前头衔 为不显示
	 * 
	 * @param userCode
	 */
	public void updateCurrentPositionTitle(String userCode) {
		mdeWorkExperienceDao.updateCurrentPositionTitle(userCode);
	}
	/**
	 * 重置用户职位头衔显示
	 * @param userCode
	 */
	@Transactional(readOnly = false)
	public void resetPositionTitle(String userCode) {
		mdeWorkExperienceDao.resetPositionTitle(userCode);
	}
	/**
	 * 设置最近的工作履历为显示的职位头衔
	 * @param userCode
	 */
	@Transactional(readOnly = false)
	public void setLatestWEShow(String userCode) {
		mdeWorkExperienceDao.setLatestWEShow(userCode);
	}
}
