/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.wechat.dao;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.wechat.global.base.dao.impl.BaseDao;
import com.wechat.global.base.interceptor.Page;
import com.wechat.model.dbEntity.MdePositionCvRel;
import com.wechat.model.dto.JobRepFormDtlDto;
import com.wechat.model.dto.PositionCvHisDto;
import com.wechat.model.dto.UserInfoResp;
import com.wechat.model.responseDto.LVResp;

/**
 * 职位简历投递履历表
 * 
 * @author tangwc
 * @version 2018-05-23
 */
@Repository
public class MdePositionCvRelDao extends BaseDao {

	public MdePositionCvRel getInfoById(int id) {
		return super.selectOne("MdePositionCvRelMapper.get", id);
	}

	public int insertUserCvRel(MdePositionCvRel cv) {
		return sqlSession.insert("MdePositionCvRelMapper.insertUserCvRel", cv);
	}

	/**
	 * 职位投递进展 - 详情
	 * 
	 * @param userCode
	 * @return
	 */
	public List<PositionCvHisDto> getPostCVDetailInfo(Map<String, Object> maps) {
		return super.select("MdePositionCvRelMapper.getPostCVDetailInfo", maps);
	}

	public int update(MdePositionCvRel mdePositionCvRel) {
		return super.update("MdePositionCvRelMapper.update", mdePositionCvRel);
	}
	
	public int updatePositionCvRel(MdePositionCvRel mdePositionCvRel) {
		return super.update("MdePositionCvRelMapper.updatePositionCvRel", mdePositionCvRel);
	}


	/**
	 * 根据投递状态获取简历列表
	 * @param page
	 * @return
	 */
	/*
	 * public PagingResult<UserInfoResp> getUserCvStateListInfo(Pagination page) {
	 * return
	 * super.selectPagination("MdePositionCvRelMapper.getUserCvStateListInfo",
	 * "MdePositionCvRelMapper.getUserCvStateListInfoCount", page); }
	 */
	
	public Page<UserInfoResp> getUserCvStateListInfo(Page<UserInfoResp> page,UserInfoResp paramsDto) {
		return super.findPage(page, "MdePositionCvRelMapper.getUserCvStateListInfo", paramsDto);
	}


	/**
	 * 更新简历状态
	 * 
	 * @param userCode
	 *            用户code
	 * @param state
	 *            状态
	 * @return
	 */
	public int updateUserCvStatus(Map<String, String> maps) {
		return sqlSession.update("MdePositionCvRelMapper.updateUserCvStatus", maps);
	}

	/**
	 * 获取投递该职位的简历地址
	 * 
	 * @param maps
	 * @return
	 */
	public List<MdePositionCvRel> findPositionCvRelByJobIdAndUserCode(Map<String, Object> maps) {
		return select("MdePositionCvRelMapper.findPositionCvRelByJobIdAndUserCode", maps);
	}
	/**
	 * 获取职位投递履历表
	 * @param cv 
	 * posId 职位id
	 * candidate 投递人
	 * @return
	 */
	public MdePositionCvRel getInfoByIdAndUserCode(MdePositionCvRel cv) {
		return selectOne("MdePositionCvRelMapper.getInfoByIdAndUserCode", cv);
	}
	
	/**
	 * 是否投递过该职位
	 * @param userCode
	 * @param jobId
	 * @param deliverDate
	 * @return
	 */
	public MdePositionCvRel hasPosted(String userCode, int jobId,Date deliverDate) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userCode", userCode);
		map.put("jobId", jobId);
		map.put("deliverDate", deliverDate);
		return selectOne("MdePositionCvRelMapper.hasPosted", map);
	}
	/**
	 * 删除简历
	 * @param cv
	 */
	public void deleteCv(MdePositionCvRel cv) {
		delete("MdePositionCvRelMapper.deleteCv", cv);
	}
	
	/**
	 * 更新简历状态为已读：1
	 * 
	 * @param userCode
	 *            简历投递者code
	 * @param state
	 *            状态
	 * @return
	 */
	public int updateCvAlready(String userCode, int jobId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userCode", userCode);
		map.put("jobId", jobId);
		return sqlSession.update("MdePositionCvRelMapper.updateCvAlready", map);
	}
	
	/**
	 * 更新全部简历状态为已读：1
	 * 
	 * @param userCode
	 *            发布职位者code
	 * @param state
	 *            状态
	 * @return
	 */
	public int updateCvsAlready(String userCode) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userCode", userCode);
		return sqlSession.update("MdePositionCvRelMapper.updateCvsAlready", map);
	}
	
	
	/**
	 *  投递量
	 * @param userCode
	 * @param from 开始时间
	 * @param to 结束时间
	 * @param jobId 职位id
	 * @return
	 */
	public Integer countCvsByDateStaus(Map<String, Object> map){
		return super.selectOne("MdePositionCvRelMapper.countCvsByDateStaus",map);
	}
	
	/**
	 * 求职者学历
	 * @param userCode
	 * @param from 开始时间
	 * @param to 结束时间
	 * @param jobId 职位id
	 * @return
	 */
	public List<LVResp> countEducationByDate(Map<String, Object> map){
		return super.select("MdePositionCvRelMapper.countEducationByDate",map);
	}
	
	
	/**
	 * 查询时间段内 各职位投递和阅读量
	 * @param userCode
	 * @param from 开始时间
	 * @param to 结束时间
	 * @return
	 */
	public List<JobRepFormDtlDto> getReportsFormByDate(Map<String, Object> map){
		return super.select("MdePositionCvRelMapper.getReportsFormByDate",map);
	}
	
}