package com.wechat.service;

import com.google.common.collect.Maps;
import com.wechat.common.utils.MessageUtils;
import com.wechat.common.utils.StringsUtils;
import com.wechat.dao.MdeJobAdvertisedDao;
import com.wechat.dao.MdePositionCvRelDao;
import com.wechat.dao.MdeUserDao;
import com.wechat.global.CustomException;
import com.wechat.global.base.BaseService;
import com.wechat.global.base.dao.Pagination;
import com.wechat.global.base.dao.PagingResult;
import com.wechat.global.base.dao.RedisWithExpiryTimeDao;
import com.wechat.global.base.interceptor.Page;
import com.wechat.global.message.InfoMsg;
import com.wechat.model.dbEntity.MdePositionCvRel;
import com.wechat.model.dbEntity.MdeUser;
import com.wechat.model.dto.UserInfoResp;
import com.wechat.model.dto.WorkDateDto;
import com.wechat.model.requestDto.*;
import com.wechat.model.responseDto.ContactUserInfoResp;
import com.wechat.model.responseDto.JobAdvertisedResp;
import com.wechat.model.responseDto.ResultEntity;
import org.apache.commons.collections.CollectionUtils;
import org.nutz.lang.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;

@Service
public class EnterpriseService extends BaseService {

    public static Logger log = LoggerFactory.getLogger(EnterpriseService.class);
    @Autowired
    private CommonService commonService;
    @Autowired
    private MdePositionCvRelDao mdePositionCvRelDao;
    @Autowired
    private RecruitmentInformationReleaseService recruitmentReleaseService;
    @Resource
    private RedisWithExpiryTimeDao redisDao;
    @Autowired
    private MdeJobAdvertisedDao mdeJobAdvertisedDao;
    @Autowired
    private PositionService postitionService;
    @Autowired
    private TalentRetrievalService talentRetrievalService;
    @Autowired
    private MdeUserDao mdeUserDao;
    @Value("#{configProperties['upload.path.template']}")
    private String fileTemplate;
    @Value("#{configProperties['upload.base.path']}")
    private String basePackagePath; // 简历路径

    @Value("#{configProperties['upload.path.file']}")
    private String filePath; // 简历路径

    @Value("#{configProperties['url.base']}")
    private String domainUrl; // 域名

    @Value("#{configProperties['interview_invitation_template_id']}")
    private String interviewInvitationTemplateId; // 邀请面试 推送模板Id

    @Value("#{configProperties['interview_invitation_url']}")
    private String interviewInvitationUrl; //  邀请面试 跳转地址

    // 视频小程序-用户唯一凭证
    @Value("#{configProperties['wx.miniprog.video.appid']}")
    private String videoAppId;

    // 视频小程序-跳转小程序类型：developer为开发版；trial为体验版；formal为正式版；默认为正式版
    @Value("#{configProperties['wx.miniprog.video.state']}")
    private String videoMpState;

    // 视频小程序-主页链接
    @Value("#{configProperties['wx.miniprog.video.tmsg.invite.url']}")
    private String videoTmsgInviteUrl;

    //非付费企业月可发职位次数
    @Value("#{configProperties['unvip_release_no']}")
    private String unvipReleaseNo;


    /**
     * 企业查看简历 首页
     *
     * @param req
     * @param resp
     * @return
     */
/*	public Map<String, Object> receiveUserCv(HttpServletRequest req, Page page) {
		Map<String, Object> maps = Maps.newHashMap();
		Pagination pagination = new Pagination(page.getIndex(), page.getSize());
		// 当前登录账号的企业code
		String userCode = commonService.getUserCode(req);
		String lang = commonService.getLanguage(req);

		// 获取投递该企业的用户信息
		Map<Object, Object> params = Maps.newHashMap();
		params.put("status", "0"); // 新投递
		params.put("userCode", userCode);
		pagination.setParams(params);
		PagingResult<UserInfoResp> pagingResult = mdePositionCvRelDao.getUserCvStateListInfo(pagination);
		// 获取所有userCode
		List<String> userCodeList = Lists.transform(pagingResult.getResultList(), new Function<UserInfoResp, String>() {
			@Override
			public String apply(UserInfoResp arg0) {
				return arg0.getUserCode();
			}
		});

		if (CollectionUtils.isNotEmpty(userCodeList)) {
			// 教育经历
			List<MdeEducationExperience> educationList = mdeEducationExperienceDao
					.getEducationExperienceByUserCodeList(userCodeList,lang);
			// 根据userCode分组
			ListMultimap<String, MdeEducationExperience> index = Multimaps.index(educationList,
					new Function<MdeEducationExperience, String>() {
						@Override
						public String apply(MdeEducationExperience arg0) {
							return arg0.getUserCode();
						}
					});
			Set<String> keySet = index.keySet();
			// 组织UserInfoResp实体 赋值教育经历
			for (UserInfoResp userInfoResp : pagingResult.getResultList()) {
				if (keySet.contains(userInfoResp.getUserCode())) {
					userInfoResp.setEducationExperience(index.get(userInfoResp.getUserCode()).get(0));
				}
			}
			// 获取工作经历
			List<MdeWorkExperience> workList = mdeWorkExperienceDao.getWorkExperienceByUserCodeList(userCodeList);
			// 根据userCode分组
			ListMultimap<String, MdeWorkExperience> workIndex = Multimaps.index(workList,
					new Function<MdeWorkExperience, String>() {
						@Override
						public String apply(MdeWorkExperience arg0) {
							return arg0.getUserCode();
						}
					});
			Set<String> workKeySet = workIndex.keySet();
			for (UserInfoResp userInfoResp : pagingResult.getResultList()) {
				if (workKeySet.contains(userInfoResp.getUserCode())) {
					userInfoResp.setWorkExperience(workIndex.get(userInfoResp.getUserCode()));
				}
			}
		}
		List<UserInfoResp> list = commonService.addDomainUrlEnterUserCv(pagingResult.getResultList()); // 拼接头像域名
		pagingResult.setResultList(list);
		maps.put("page", pagingResult);
		// }
		// 清空缓存中投递简历信息
		// commonService.deleteUserCvMessage(userCode);
		// 删除缓存中投递该企业的简历数量
		redisDao.delete("hotelUserRecievedCVCount_" + userCode);

		maps.put("allUserCvCount", getAllUserCvCount(userCode)); // 所有简历数量
		maps.put("inviteAuditionCount", inviteAuditionCount(userCode)); // 邀请简历数量
		maps.put("matriculateUserCv", matriculateUserCvCount(userCode)); // 录用简历数量
		maps.put("eliminateUserCvCount", eliminateUserCvCount(userCode)); // 淘汰简历数量
		return maps;
	}*/

    /**
     * 更新职位发布状态
     *
     * @param maps
     * @return
     * @throws Exception
     */
    @Transactional
    public ResultEntity<String> updateJobAdvertisedStatus(HttpServletRequest req, Map<String, String> maps) throws Exception {
        // 当前登录账号的企业code
        String userCode = commonService.getUserCode(req);
        //需要修改为的状态，不是修改前的状态
        String jobStatus = maps.get("jobStatus");
        String jobId = maps.get("jobId");
        if (StringsUtils.isEmpty(jobId)) {
            return new ResultEntity<>(InfoMsg.EERROE_POSITION_ERROR);
        }
        if (!"0".equals(jobStatus) && !"1".equals(jobStatus)) {
            return new ResultEntity<>(InfoMsg.ERROR_JOBSTATUS_ERROR);
        } else if ("0".equals(jobStatus)) {
            //验证企业发布次数
            if (!recruitmentReleaseService.checkReleaseLimit(userCode)) {
                //超限
                InfoMsg msg = InfoMsg.ERROR_RELEASE_BEYOND;
                msg.setMsg(MessageUtils.getText(msg.getMsg(), unvipReleaseNo));
                return new ResultEntity<>(msg);
            }
        }


        maps.put("userCode", userCode);
        int upd = mdeJobAdvertisedDao.updateJobAdvertisedStatus(maps);
        if (upd < 1) {
            log.error("职位发布状态更新失败" + "jobId:【" + jobId + "】 " + "userCode:【" + userCode + "】 ");
            return new ResultEntity<>(InfoMsg.ERROR_INSERT_ERROR);
        }

        return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST);
    }

    /**
     * 更新职位首推状态
     *
     * @param maps
     * @return
     */
    @Transactional
    public ResultEntity<String> updateJobRecommend(HttpServletRequest req, Map<String, String> maps) {
        String recommendFlag = maps.get("recommendFlag");
        String jobId = maps.get("jobId");
        if (StringsUtils.isEmpty(jobId)) {
            return new ResultEntity<>(InfoMsg.EERROE_POSITION_ERROR);
        }
        if (!"0".equals(recommendFlag) && !"1".equals(recommendFlag)) {
            return new ResultEntity<>(InfoMsg.ERROR_PARAMS_ERROR);
        }

        // 当前登录账号的企业code
        String userCode = commonService.getUserCode(req);
        maps.put("userCode", userCode);
        int upd = mdeJobAdvertisedDao.updateJobRecommend(maps);

        if (upd < 1) {
            log.error("职位首推状态更新失败" + "jobId:【" + jobId + "】 " + "userCode:【" + userCode + "】 ");
            return new ResultEntity<>(InfoMsg.ERROR_INSERT_ERROR);
        }
        return new ResultEntity<>(InfoMsg.SUCCESS_REQUEST);
    }

    /**
     * 查看简历
     *
     * @param userCode  用户code
     * @param hotelCode 酒店code
     * @return
     */
    @Transactional
    public ContactUserInfoResp lookUserCv(String hotelCode, Map<String, String> param, String lang) {
        int jobId = Integer.parseInt(param.get("jobId"));
        String userCode = param.get("userCode");
        String status = param.get("status");

        if (StringsUtils.isEmpty(param.get("jobId")) || StringsUtils.isEmpty(param.get("userCode")) || StringsUtils.isEmpty(param.get("status"))) {
            throw new CustomException(InfoMsg.ERROR_PARAMS_ERROR);
        }
        // 根据用户code 查询用户信息
        ContactUserInfoResp contactUserInfoResp = talentRetrievalService.getContactNumber(userCode, lang);
        if ("0".equals(status)) {
            //新简历投递的情况下，更新为已读
            mdePositionCvRelDao.updateCvAlready(userCode, jobId);
            //获取当前企业的新简历数 更新缓存
            int count = mdeJobAdvertisedDao.getNewCvCountByPublisher(hotelCode);
            redisDao.insert("hotelUserRecievedCVCount_" + hotelCode, String.valueOf(count));
        }

        return contactUserInfoResp;
    }

    /**
     * 下载简历的用户code
     *
     * @param userCode
     * @return
     */
    @Transactional
    public String downloadUserCv(HttpServletRequest req, HttpServletResponse resp, Map<String, Object> param) {
        String lang = commonService.getLanguage(req);
        String userCode = param.get("userCode").toString();
        String jobId = param.get("jobId").toString();
        Map<String, Object> maps = Maps.newHashMap();
        maps.put("userCode", userCode);
        maps.put("jobId", jobId);
        MdeUser mdeUser = mdeUserDao.getUserInfoByCode(userCode);
        List<MdePositionCvRel> mdePositionCvRelsList = mdePositionCvRelDao.findPositionCvRelByJobIdAndUserCode(maps);
        String cvUrl = "";
        BufferedInputStream bufferInputStream = null;
        BufferedOutputStream bufferOutStream = null;
        try {
            if (CollectionUtils.isNotEmpty(mdePositionCvRelsList)) {
                MdePositionCvRel mdePositionCvRel = mdePositionCvRelsList.get(0);
                cvUrl = mdePositionCvRel.getCvUrl();
                if (Strings.isEmpty(cvUrl)) {
                    // word模板生成简历
                    String relativePath = postitionService.exportUserCvDoc(resp, userCode, lang);
                    cvUrl = domainUrl + relativePath;
//					String pdfPath = relativePath.substring(0, relativePath.indexOf("."))+".pdf";
//					Word2Pdf.convertWordToPdf(basePackagePath+relativePath, basePackagePath+pdfPath);
                } else {
                    cvUrl = basePackagePath + mdePositionCvRel.getCvUrl();
                    String suffx = cvUrl.substring(cvUrl.lastIndexOf("."), cvUrl.length());
                    StringBuffer buffer = new StringBuffer();
                    buffer.append(mdeUser.getName() + "(");
                    buffer.append(mdeUser.getUserName() + ")_门墩儿" + suffx);
                    File file = new File(cvUrl);
                    if (!file.exists()) {
                        throw new CustomException(InfoMsg.EERROE_FILENOTEXIST_ERROR);
                    }
                    bufferInputStream = new BufferedInputStream(new FileInputStream(file));
                    File saveFile = new File(basePackagePath + fileTemplate);
                    if (!saveFile.exists()) {
                        saveFile.mkdirs();
                    }
                    int len = 0;
                    bufferOutStream = new BufferedOutputStream(
                            new FileOutputStream(new File(basePackagePath + fileTemplate + buffer.toString())), 1024);
                    while ((len = bufferInputStream.read()) != -1) {
                        bufferOutStream.write(len);
                    }
                    String relativePath = fileTemplate + buffer.toString();
                    cvUrl = domainUrl + relativePath;
//					if(suffx.substring(1).equalsIgnoreCase("doc") || suffx.substring(1).equalsIgnoreCase("docx")) {
//						String pdfPath = relativePath.substring(0, relativePath.indexOf("."))+".pdf";
////						Word2Pdf.convertWordToPdf(basePackagePath+relativePath, basePackagePath+pdfPath);
//					}else if(suffx.substring(1).equalsIgnoreCase("xls") || suffx.substring(1).equalsIgnoreCase("xlsx")) {
//						
//					}

                }
                try {
                    if (Integer.valueOf(mdePositionCvRel.getCvStatus()) < 2) {
                        // 更新简历状态
                        mdePositionCvRel.setCvStatus("2"); // 已下载
                        mdePositionCvRelDao.update(mdePositionCvRel);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new CustomException(InfoMsg.ERROR_UPDATE_USERCVSTATUS_FILE);
                } finally {
                    if (bufferOutStream != null) {
                        bufferOutStream.flush();
                        bufferOutStream.close();
                    }
                    if (bufferInputStream != null) {
                        bufferInputStream.close();
                    }
                }
            }

            return cvUrl;
        } catch (Exception e) {
            log.info(e.getMessage());
            throw new CustomException(InfoMsg.ERROR_READ_FILE);
        }
    }


    /**
     * 根据职位查询投递者简历信息
     *
     * @param req
     * @param statusReq
     * @param model     终端类型（1-PC端 只显示1个面试时间）
     * @return
     * @author jadyn.wu
     */
    public Map<String, Object> getUserCvStateListInfoByJob(HttpServletRequest req, UserCvByJobReq cvJobReq, String model) {
        Page<UserInfoResp> page2 = new Page<UserInfoResp>(cvJobReq.getIndex(), cvJobReq.getSize());

        Map<String, Object> maps = Maps.newHashMap();

        String userCode = commonService.getUserCode(req);
        String lang = commonService.getLanguage(req);

        // 根据jobId获取简历信息
        UserInfoResp paramsDto = new UserInfoResp();
        paramsDto.setPublisher(userCode);
        paramsDto.setLang(lang);
        paramsDto.setJobId(cvJobReq.getJobId());
        paramsDto.setModel(model);
        page2 = mdePositionCvRelDao.getUserCvStateListInfo(page2, paramsDto);

        maps.put("allUserCvCount", getAllUserCvCount(userCode)); // 所有简历数量
        maps.put("inviteAuditionCount", inviteAuditionCount(userCode)); // 邀请简历数量
        maps.put("matriculateUserCv", matriculateUserCvCount(userCode)); // 录用简历数量
        maps.put("eliminateUserCvCount", eliminateUserCvCount(userCode)); // 淘汰简历数量
        List<UserInfoResp> list = commonService.addDomainUrlEnterUserCv(page2.getResultList()); // 拼接头像域名

        page2.setResultList(list);
        maps.put("page", page2);
        return maps;
    }

    /**
     * 根据简历状态查询投递者简历信息
     *
     * @param req
     * @param statusReq
     * @param model     终端类型（1-PC端 只显示1个面试时间）
     * @return
     * @author jadyn.wu
     */
    public Map<String, Object> getUserCvStateListInfo2(HttpServletRequest req, UserCvStatusReq statusReq, String model) {
        Page<UserInfoResp> page2 = new Page<UserInfoResp>(statusReq.getIndex(), statusReq.getSize());

        Map<String, Object> maps = Maps.newHashMap();

        String userCode = commonService.getUserCode(req);
        String lang = commonService.getLanguage(req);
        String type = statusReq.getType();

        // 根据type 获取简历信息 0-新投递；1-已查看；2-已下载；3-邀请面试；4-录取；5-淘汰；6-储备
        UserInfoResp paramsDto = new UserInfoResp();
        paramsDto.setPublisher(userCode);
        paramsDto.setLang(lang);
        paramsDto.setStatus(type);
        paramsDto.setModel(model);
        page2 = mdePositionCvRelDao.getUserCvStateListInfo(page2, paramsDto);

        maps.put("allUserCvCount", getAllUserCvCount(userCode)); // 所有简历数量
        maps.put("inviteAuditionCount", inviteAuditionCount(userCode)); // 邀请简历数量
        maps.put("matriculateUserCv", matriculateUserCvCount(userCode)); // 录用简历数量
        maps.put("eliminateUserCvCount", eliminateUserCvCount(userCode)); // 淘汰简历数量
        List<UserInfoResp> list = commonService.addDomainUrlEnterUserCv(page2.getResultList()); // 拼接头像域名

        // 查询新投递简历的情况下
        /* 去除自动更新为已读状态
         * if("0".equals(type)) { //删除缓存中投递该企业的简历数量
         * redisDao.delete("hotelUserRecievedCVCount_" + userCode); //新简历投递的情况下，更新为已读
         * mdePositionCvRelDao.updateCvsAlready(userCode); }
         */
        page2.setResultList(list);
        maps.put("page", page2);
        return maps;
    }


    /**
     * 更新简历状态 type （0.邀请面试1.录用2.淘汰）
     *
     * @param req
     * @param resp
     * @param jo
     * @return
     */
    @Transactional
    public InfoMsg updateUserCvStatus(HttpServletRequest req, UpdUserCvReq param, InterviewCreateReq intvReq) {
        String lang = commonService.getLanguage(req);
        String userCode = param.getUserCode();
        String jobId = param.getJobId();
        String type = param.getType();

        Map<String, String> maps = Maps.newHashMap();
        maps.put("userCode", userCode);
        maps.put("jobId", jobId);
        maps.put("remark", param.getRemark());
        // 根据type 更新简历状态 （0-新投递；1-已查看；2-已下载；3-邀请面试；4-录取；5-淘汰；6-储备）
        try {
            if ("3".equals(type) || "4".equals(type) || "5".equals(type) || "6".equals(type)) {
                maps.put("status", type);
                mdePositionCvRelDao.updateUserCvStatus(maps);
            }
        } catch (Exception e) {
            log.error("简历状态更新失败" + e.getMessage());
            throw new CustomException(InfoMsg.ERROR_UPDATE_USERCVSTATUS_FILE);
        }
        // 邀请面试发送微信消息给用户
//		if("3".equals(type)) {
//			String currentUserCode = commonService.getUserCode(req);
//			MdeUser personUser = mdeUserDao.getFullInfo(userCode);
//			if(StringsUtils.isNotEmpty(personUser.getOpenId())) {
//				MdeUser enterpriseUser = mdeUserDao.getFullInfo(currentUserCode);
//				MdeJobAdvertised job = mdeJobAdvertisedDao.getInfoById(Integer.valueOf(jobId),lang);
//				TMsgSendBaseReq re = organizationParam(personUser,enterpriseUser,job.getJobName(),"",intvReq);
//				String errorCode = templateMsgService.sendTMsg(re); // 微信消息推送
//				if (!"0".equals(errorCode)) {
//					//发送失败再次尝试
//					templateMsgService.sendTMsg(re); // 微信消息推送
//				}
//			}else{
//			    //发送短信
//			    String phoneNo = personUser.getUserName();
//			    String phoneCode = personUser.getPhoneCode();
//                // 判断是否是大陆手机号 (手机号 如+8612345)
//                if ("86".equals(phoneCode)) {
//                    // 邀请面试 发送短信 （大陆）
//                    verificationCodeService.sendInterviewCn(phoneNo, personUser.getName());
//                } else {
//                    // 国际
//                    phoneNo = phoneNo.substring(phoneCode.length() + 1, phoneNo.length()); // 截取手机号
//                    // 手机号 开头为0 去掉
//                    if (phoneNo.startsWith("0")) {
//                        phoneNo = phoneNo.substring(1, phoneNo.length());
//                    }
//                    verificationCodeService.sendInterviewEn(phoneCode, phoneNo, personUser.getName());
//                }
//			}
//		}
        return InfoMsg.SUCCESS_REQUEST;
    }

//	private TMsgSendBaseReq organizationParam(MdeUser user,MdeUser publisher,String jobName,String remarks,InterviewCreateReq intvReq) {
//		TMsgSendBaseReq invited = new TMsgSendBaseReq();
//		invited.setTemplate_id(interviewInvitationTemplateId);
//		invited.setUrl(interviewInvitationUrl);
//		invited.setTouser(user.getOpenId());
//		//小程序信息
//		WxMiniTMsgProgramDto miniprogram = new WxMiniTMsgProgramDto(videoAppId);
//		miniprogram.setPagepath(videoTmsgInviteUrl);
//		invited.setMiniprogram(miniprogram);
//		//信息参数设置
//		TMsg5ParamsDto dto = new TMsg5ParamsDto();
//		dto.setFirst(user.getName()+"，你好。有企业HR向您发出了面试邀请。","#173177");
//		dto.setKeyword1(publisher.getName());
//		dto.setKeyword2(jobName);
//		dto.setKeyword3("点击查看并确认面试时间" );
//		//面试方式[0-现场面试 1-视频面试]
//		if("0".equals(intvReq.getType()))
//		{
//			dto.setKeyword4(intvReq.getAddrProvince()+intvReq.getAddrCity()+intvReq.getAddrArea()+intvReq.getAddDetail());
//		} else {
//			dto.setKeyword4("线上视频面试");
//		}
//		//负责HR
//		dto.setKeyword5(intvReq.getEntContacts()+""+intvReq.getEntContactInfo());
//		dto.setRemark(remarks,"#173177");
//		invited.setData(dto);
//		return invited;
//	}

    /**
     * 已发布信息
     *
     * @param req
     * @param resp
     * @return
     */
    public PagingResult<JobAdvertisedResp> alreadyPublish(HttpServletRequest req, HttpServletResponse resp, String userCode,
                                                          JobAdvertisedReqDto jobReq) {
        String language = commonService.getLanguage(req);
        // 刷新招聘中职位  （发布日期为当前日期）
        if (jobReq.isRefresh()) {
            batchUpdatePublishDate(userCode);
        }
        Pagination page = new Pagination(jobReq.getIndex(), jobReq.getSize());
        Map<Object, Object> pageParam = new HashMap<Object, Object>();
        pageParam.put("userCode", userCode);
        pageParam.put("lang", language);
        pageParam.put("jobStatus", jobReq.getJobStatus());
        List<String> positionIdList = null;
        if (StringsUtils.isNotEmpty(jobReq.getPositionIdList())) {
            positionIdList = Arrays.asList(jobReq.getPositionIdList().split(","));
        }
        pageParam.put("positionIdList", positionIdList);
        pageParam.put("newDelivery", jobReq.getNewDelivery());
        pageParam.put("dayStart", jobReq.getDayStart());
        pageParam.put("dayEnd", jobReq.getDayEnd());
        pageParam.put("workExperience", jobReq.getWorkExperience());

        page.setParams(pageParam);
        PagingResult<JobAdvertisedResp> list = mdeJobAdvertisedDao.alreadyPublish(page);
        return list;
    }


    /**
     * @param keyWordReq 关键词
     * @param req
     * @param userCode   用户code
     * @return PagingResult<JobAdvertisedResp>
     * @description 已发职位关键词检索
     * @author rayson
     * @date 2023-09-12 14:42
     **/
    public PagingResult<JobAdvertisedResp> searchKeyWord(KeyWordReq keyWordReq, String userCode, HttpServletRequest req) {
        if (keyWordReq != null && StringsUtils.isEmpty(keyWordReq.getKeyWord())) {
            PagingResult<JobAdvertisedResp> pagingResult = new PagingResult<>();
            pagingResult.setCurrentPage(keyWordReq.getIndex());
            pagingResult.setTotalSize(0);
            pagingResult.setPageSize(keyWordReq.getSize());
            pagingResult.setResultList(new ArrayList<JobAdvertisedResp>());
            pagingResult.setPageNoSize(10);
            return pagingResult;
        }
        String language = commonService.getLanguage(req);

        Pagination page = new Pagination(keyWordReq.getIndex(), keyWordReq.getSize());

        Map<Object, Object> pageParam = Maps.newHashMap();
        pageParam.put("userCode", userCode);
        pageParam.put("lang", language);
        pageParam.put("keyWord", keyWordReq.getKeyWord());
        page.setParams(pageParam);
        PagingResult<JobAdvertisedResp> list = mdeJobAdvertisedDao.searchKeyWord(page);
        return list;
    }

    /**
     * 获取投递该公司总简历数
     *
     * @param userCode 企业code
     * @return
     */
    public int getAllUserCvCount(String userCode) {
        return mdeJobAdvertisedDao.getAllUserCvCount(userCode);
    }

    /**
     * 获取邀请面试简历数量
     *
     * @param userCode 企业code
     * @return
     */
    public int inviteAuditionCount(String userCode) {
        return mdeJobAdvertisedDao.inviteAuditionCount(userCode);
    }

    /**
     * 获取录用简历数量
     *
     * @param userCode 企业code
     * @return
     */
    public int matriculateUserCvCount(String userCode) {
        return mdeJobAdvertisedDao.matriculateUserCvCount(userCode);
    }

    /**
     * 淘汰简历数量
     *
     * @param userCode 企业code
     * @return
     */
    public int eliminateUserCvCount(String userCode) {
        return mdeJobAdvertisedDao.eliminateUserCvCount(userCode);
    }

    /**
     * 获取指定企业的新简历数量
     *
     * @param userCode 企业code
     * @return
     */
    public int getNewCvCountByPublisher(String userCode) {
        return mdeJobAdvertisedDao.getNewCvCountByPublisher(userCode);
    }

    /**
     * 批量更新发布日期（招聘中职位）
     *
     * @return
     */
    @Transactional
    public void batchUpdatePublishDate(String userCode) {
        try {
            mdeJobAdvertisedDao.batchUpdatePublishDate(userCode);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException(InfoMsg.ERROR_UPDATE_USERCVSTATUS_FILE);
        }
    }
}
