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

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

import org.springframework.stereotype.Repository;

import com.wechat.common.IdGenarator;
import com.wechat.common.utils.StringsUtils;
import com.wechat.global.base.dao.Pagination;
import com.wechat.global.base.dao.PagingResult;
import com.wechat.global.base.dao.impl.BaseDao;
import com.wechat.model.dbEntity.MdeUser;
import com.wechat.model.dto.BeInvitedDtlDto;
import com.wechat.model.dto.InvitationNumDto;
import com.wechat.model.dto.TalentRetrievalDto;
import com.wechat.model.dto.UserAndIsFriendDto;
import com.wechat.model.requestDto.JobCollectionReq;
import com.wechat.model.responseDto.ContactUserInfoResp;

/**
 * 单表生成DAO接口
 * 
 * @author tangwc
 * @version 2018-05-23
 */
@Repository
public class MdeUserDao extends BaseDao {
	
	/**
	 * 推荐人才
	 * @param userCode
	 * @param recommentTalenRetrievalLimit 
	 * @return
	 */
	public List<MdeUser> getRecommentPeople(String userCode, int limitSize) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userCode", userCode);
		map.put("limitSize", limitSize);
		return super.select("MdeUserMapper.getRecommentPeople",map);
	}
	
	public PagingResult<MdeUser> findByKeyWord(Pagination page) {
		return super.selectPagination("MdeUserMapper.findByKeyWord", "MdeUserMapper.findByKeyWordCount", page);
	}

	public int updateUser(MdeUser mdeUser) {
		return super.update("MdeUserMapper.updateUser", mdeUser);	
	}
	
	public int insert(MdeUser mdeUser) {
		mdeUser.setUserCode(String.valueOf(IdGenarator.nextId()));
		return super.insert("MdeUserMapper.insert", mdeUser);
	}
	public int insertNew(MdeUser mdeUser) {
		mdeUser.setUserCode(String.valueOf(IdGenarator.nextId()));
		return sqlSession.insert("MdeUserMapper.insert", mdeUser);
	}
	
	//预先采番好用户code
	public int insertWithUserCode(MdeUser mdeUser) {
		return sqlSession.insert("MdeUserMapper.insert", mdeUser);
	}

	public MdeUser getInfoById(String userCode) {
		return super.selectOne("MdeUserMapper.get", userCode);
	}
	public MdeUser getInfoByIdWithLang(String userCode,String lang) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userCode", userCode);
		map.put("lang", lang);
		return super.selectOne("MdeUserMapper.getWithLang", map);
	}
	/**
	 * 通过userCode或userName获取用户信息
	 *
	 * @param info
	 * @return
	 */
	public MdeUser getUserInfoByIdOrUserName(String info) {
		return super.selectOne("MdeUserMapper.getUser", info);
	}
	public MdeUser getUserSensitiveInfo(String userCode) {
		return super.selectOne("MdeUserMapper.getUserSensitiveInfo", userCode);
	}

	public MdeUser getFullInfo(String userCode) {
		return super.selectOne("MdeUserMapper.getFullInfo", userCode);
	}

	public MdeUser findByUserName(String userName) {
		return sqlSession.selectOne("MdeUserMapper.findByUserName", userName);
	}

	public MdeUser findByUnionId (String unionId) {
		return sqlSession.selectOne("MdeUserMapper.findByUnionId", unionId);
	}

	public int changePassword(MdeUser mdeUser) {
		return super.update("MdeUserMapper.update", mdeUser);
	}

	public List<MdeUser> getMaybeFriendsOfPerson(String userCode, String lang, int limitSize) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userCode", userCode);
		map.put("lang", lang);
		map.put("limitSize", limitSize);
		return super.select("MdeUserMapper.getMaybeFriendsOfPerson", map);
	}
	public List<MdeUser> getMaybeFriendsOfEnterprise(String userCode, String name, String foreignName, String lang, int limitSize) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userCode", userCode);
		map.put("name", name);
		map.put("foreignName", foreignName);
		map.put("lang", lang);
		map.put("limitSize", limitSize);
		return super.select("MdeUserMapper.getMaybeFriendsOfEnterprise", map);
	}

	public int update(MdeUser mdeUser) {
		return super.update("MdeUserMapper.update", mdeUser);
	}
	
    public int unbind(MdeUser mdeUser) {
    	int count = 0;
    	if(!StringsUtils.isEmpty(mdeUser.getUnionId()) || !StringsUtils.isEmpty(mdeUser.getLinkedinId())) {
    		count = super.update("MdeUserMapper.unbind", mdeUser);
    	}
        return count;
    }
	
	public int updateBind(MdeUser mdeUser) {
		return super.update("MdeUserMapper.updateBind", mdeUser);
	}
    

	public MdeUser findByLinkedId(String linkedId) {
		return sqlSession.selectOne("MdeUserMapper.findByLinkedId", linkedId);
	}

	public MdeUser getUserInfoByCode(String userCode) {
		return super.selectOne("MdeUserMapper.getUserInfoByCode", userCode);
	}

	public List<MdeUser> getFriends(String userCode) {
		return super.select("MdeUserMapper.getFriendsByCode", userCode);
	}

	public PagingResult<MdeUser> getFriends(Pagination page) {
		return super.selectPagination("MdeUserMapper.getFriendsByCode", "MdeUserMapper.getFriendsCounts", page);
	}

	public int insertWetchRegister(MdeUser mdeUser) {
		mdeUser.setUserCode(String.valueOf(IdGenarator.nextId()));
		return super.insert("MdeUserMapper.insertWetchRegister", mdeUser);
	}

	public int linkedInRegister(MdeUser mdeUser) {
		mdeUser.setUserCode(String.valueOf(IdGenarator.nextId()));
		return super.insert("MdeUserMapper.linkedInRegister", mdeUser);
	}

	public MdeUser getHotelUserInfoByJobId(int jobId) {
		return super.selectOne("MdeUserMapper.getInfoByJobId", jobId);
	}

	public int updateUserPositionList(JobCollectionReq collection) {
		return sqlSession.update("MdeUserMapper.updateUserPositionList", collection);
	}

	public MdeUser fingByUserName(String userName) {

		return sqlSession.selectOne("MdeUserMapper.findByUserName", userName);

	}

	/**
	 * 获取联系方式及工作履历
	 * 
	 * @param userCode
	 * @return
	 */
	public ContactUserInfoResp getContactNumber(String userCode) {
		return super.selectOne("MdeUserMapper.getContactNumber", userCode);
	}

	public String getEducationId(Map<Object,Object> keyWord) {
		return super.selectOne("MdeUserMapper.getEducationId", keyWord);
	}

	/**
	 * 关键词搜索
	 * 
	 * @param page
	 * @return
	 */
	public PagingResult<TalentRetrievalDto> searchKeyWord(Pagination page) {
		return super.selectPagination("MdeUserMapper.searchKeyWord", "MdeUserMapper.searchKeyWordCount", page);
	}

	/**
	 * 人才筛选
	 * 
	 * @return
	 */
	public PagingResult<TalentRetrievalDto> filterPersonAbility(Pagination page) {
		return super.selectPagination("MdeUserMapper.filterPersonAbility", "MdeUserMapper.filterPersonAbilityCount", page);
	}

	/**
	 * 下载用户简历 sql中的字段与 下载模版中的字段一一对应
	 * 
	 * @param userCode
	 * @return
	 */
	public MdeUser exportUserCvDoc(String userCode) {
		return super.selectOne("MdeUserMapper.exportUserCvDoc", userCode);
	}

	/**
	 * 酒店推荐 (大于50) 
	 * @return
	 */
	public List<MdeUser> getRecommentHotelsJoinRand(Integer limitSize) {
		return super.select("MdeUserMapper.getRecommentHotelsJoinRand",limitSize);
	}
	
	/**
	 * 酒店推荐 (小于50) 
	 * @return
	 */
	public List<MdeUser> getRecommentHotelsRand(Integer limitSize) {
		return super.select("MdeUserMapper.getRecommentHotelsRand",limitSize);
	}
	
	/**
	 * 酒店推荐的数量
	 * @return
	 */
	public int getRecommentHotelsCount() {
		return sqlSession.selectOne("MdeUserMapper.getRecommentHotelsCount");
	}
	
	public List<MdeUser> getSimilarHotel(String userCode,int similarHotelsLimitSize) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("userCode", userCode);
		map.put("limitSize", similarHotelsLimitSize);
		return super.select("MdeHotelCompanyMapper.getSimilarHotel", userCode);
	}

	public List<MdeUser> getRecommentHotels(String userCode, String lang, int recommentHotelsLimitSize) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("userCode", userCode);
		map.put("lang", lang);
		map.put("limitSize", recommentHotelsLimitSize);
		return super.select("MdeHotelCompanyMapper.getRecommentHotels", map);
	}

	public int updateLikeOrShareList(MdeUser user) {
		return sqlSession.update("MdeUserMapper.updateLikeOrShareList", user);
	}

	public int updateUserPicture(MdeUser user) {
		return sqlSession.update("MdeUserMapper.updateUserPicture", user);
	}

	/**
	 * 获取邀请的结果数据
	 * @return
	 */
	public InvitationNumDto getInvitationNum(String inviter,String userCode,String actId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("inviter", inviter);
		map.put("userCode", userCode);
		map.put("actId", actId);
        return super.selectOne("MdeUserMapper.getInvitationNum", map);
    }
	
	/**
	 * 获取受邀人详情列表
	 * @return
	 */
	public List<BeInvitedDtlDto> getBeInvitedDtl(String inviter) {
        return super.select("MdeUserMapper.getBeInvitedDtl", inviter);
    }
	
	/** 
	 * 根据用户userCode查询用户,并获取查询人和被查询人是否好友
	 * @param beViewed 被查询人
	 * @param theSearch 查询人
	 */
	public UserAndIsFriendDto getUserAndIsFriend(String beViewed,String theSearch,String lang) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("beViewed", beViewed);
		map.put("theSearch", theSearch);
		map.put("lang", lang);
		return super.selectOne("MdeUserMapper.getUserAndIsFriend", map);
	}
	
	
	/**
	 * 优选人才 -分页查询
	 * 
	 * @return
	 */
	public PagingResult<TalentRetrievalDto> getPagingRecommentTalent(Pagination page) {
		return super.selectPagination("MdeUserMapper.getPagingRecommentTalent", "MdeUserMapper.getPagingRecommentTalentCount", page);
	}
	
	
	public int updatePrivateFlag(MdeUser user) {
		return super.update("MdeUserMapper.updatePrivateFlag", user);	
	}
	
	public int modifySubscribedFlag(String userCode,String subdFlag) {
		MdeUser dto = new MdeUser();
		dto.preUpdate(userCode);
		dto.setSubscribedFlag(subdFlag);
		dto.setUserCode(userCode);
		return super.update("MdeUserMapper.modifySubscribedFlag", dto);	
	}
	
	public int uploadBgImages(MdeUser mdeUser) {
		return super.update("MdeUserMapper.uploadBgImages", mdeUser);
	}
	
}