package com.wechat.service;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wechat.common.Constants;
import com.wechat.common.utils.BaiDuKeyWordFilerUtils;
import com.wechat.common.utils.DateUtils;
import com.wechat.common.utils.JacksonUtils;
import com.wechat.common.utils.LocalFileUtil;
import com.wechat.common.utils.StringsUtils;
import com.wechat.dao.HotelUserRecievedCVRedisDao;
import com.wechat.dao.TrendCommentInfoRedisDao;
import com.wechat.global.CustomException;
import com.wechat.global.base.dao.Pagination;
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.MdeFriendRelation;
import com.wechat.model.dbEntity.MdeInformation;
import com.wechat.model.dbEntity.MdeTrends;
import com.wechat.model.dbEntity.MdeUser;
import com.wechat.model.dto.AdImageDto;
import com.wechat.model.dto.LinkedInTokenDto;
import com.wechat.model.dto.TrendsDto;
import com.wechat.model.dto.UserSimple;
import com.wechat.model.requestDto.JobCollectionReq;
import com.wechat.model.requestDto.TrendCommentInfo;
import com.wechat.model.requestDto.TrendThumbUpInfo;
import com.wechat.model.requestDto.UserCodeWithPage;

@Service
public class MainPageService {
	// private static final Log logger = LogFactory.getLog(MainPageService.class);
	private static final Log log = LogFactory.getLog(MainPageService.class);
	
	@Value("#{configProperties['upload.base.path']}")
	private String basePackagePath;
	
	@Value("#{configProperties['upload.path.image']}")
	private String basePackagePathImage;
	
	@Value("#{configProperties['compress.image.size']}")
	private int compressImageSize;

	@Value("#{configProperties['trends.friendTrends.limitSize']}")
	private int friendsTrendsLimitSize;
	
	@Value("#{configProperties['linkedIn.shareTrendToLinkedIn']}")
	private String linkInShareUrl;

	@Resource
	private MdeTrendsService trendsService;

	@Resource
	private CommonService commonService;

	@Resource
	private TrendCommentInfoRedisDao trendCommentInfoRedisDao;

	@Resource
	private MdeWorkExperienceService workExperienceService;

	@Resource
	private RedisWithExpiryTimeDao redisDao;

	@Resource
	private MdeFriendRelationService friendRelationService;

	@Resource
	private MdeUserService userService;

	@Resource
	private HotelUserRecievedCVRedisDao hotelUserRecievedCVRedisDao;

	@Autowired
	private BaiDuKeyWordFilerUtils baiDuKeyWordFilerUtils;
	@Autowired
	private WeiXinService weiXinService;
	
//	@Autowired
//	private BaiDuKeyWordFilerUtils baiDuKeyWordFilerUtils;
	
//	private int compressImageSize = 200;
	
	@Resource
	private AuthorizedService authorizedService;
	/**
	 * 主页初始化
	 * @param identityFlag 
	 * 
	 * @return
	 */
	public Map<String, Object> init() {
		Map<String, Object> map = new HashMap<String, Object>();

		// 轮播图
		map.put("broadcastPicture", commonService.getAdImages(Constants.PC_MAINPAGE_TOP_AD));
		// PC主页(右侧)
		List<AdImageDto> list1 = commonService.getAdImages(Constants.PC_MAINPAGE_RIGHT_AD1);
		List<AdImageDto> list2 = commonService.getAdImages(Constants.PC_MAINPAGE_RIGHT_AD2);
		list1.addAll(list2);
		map.put("mainPageAd", list1);
		return map;
	}
	
	public Map<String, Object> maybeFriends(String userCode, String lang, String identityFlag) {
		Map<String, Object> map = new HashMap<String, Object>();
		// 可能认识的人
		map.put("maybeFriends", commonService.getMaybeFriends(userCode,identityFlag,lang));
		return map;
	}
	

	
	
	public Map<String, Object> recomments(String userCode, String lang, String identityFlag) {
		Map<String, Object> map = new HashMap<String, Object>();
		// 个人推荐职位
		if(identityFlag != null && identityFlag.equals("0")) {
			// 推荐职位
			map.put("recommentJobs", commonService.getRecommentJobs());
		}
		// 企业推荐
		else if(identityFlag != null && identityFlag.equals("1")){
			// 推荐人才
			map.put("recommentPerson", commonService.getRecommentPeople(userCode));
		}
		return map;
	}
	
	

	/**
	 * 新增动态
	 * 
	 * @param picture
	 * @param description
	 * @param showFlag
	 * @param linkInfo 
	 * @return
	 * @throws IOException
	 */
	@Transactional
	public int insertDynamicMessage(List<MultipartFile> picture, String description, String showFlag, String userCode, String linkInfo) {
		MdeTrends trends = new MdeTrends();
		String path = "";
		String picPath="";
		if (picture.size() > 0) {
			try {
				for(MultipartFile pic:picture) {
					path = LocalFileUtil.transferToImageFile(pic, basePackagePath, basePackagePathImage);
					if(StringsUtils.isEmpty(path))
					{
						throw new CustomException(InfoMsg.ERROR_IMAGE_TYPE);
					}
					// 压缩图片到200k以下
					LocalFileUtil.commpressPicCycle(basePackagePath+path, compressImageSize, 0.8f);
					picPath += path+"|";
				}
				if(picPath.endsWith("|")) picPath = picPath.substring(0,picPath.length()-1);
			}
			catch (CustomException e) {
				throw e;
			} 
			catch (Exception e) {
				throw new CustomException(InfoMsg.ERROR_UPLOAD_FIELD);
			}
			trends.setTrendPicurl(picPath);
		}
		//百度敏感词分析
//		if (StringsUtils.isNotEmpty(description)) {
//			description = baiDuKeyWordFilerUtils.filterKeWord(description);
//		}
		trends.setTrendDesc(StringsUtils.isEmpty(description)?"":description);
		trends.setUserCode(userCode);
		trends.setLinkInfo(linkInfo);
		trends.setShowFlag(StringsUtils.isEmpty(showFlag) ? "0" : showFlag);
		trends.setCommentCount(0);
		trends.setLikeCount(0);
		trends.setVersionNo(1);
		trends.setDelFlag(0);
		trends.setCreateBy(userCode + "");
		trends.setUpdateBy(userCode + "");
		return trendsService.insert(trends);
	}
	/**
	 * 手机端发送动态
	 * @param picture
	 * @param description
	 * @param showFlag
	 * @param userCode
	 * @param linkInfo 
	 * @return
	 * @throws Exception 
	 */
	@Transactional
	public int sendDynamicMessageMB(String[] pictureIds, String description, String showFlag, String userCode, String linkInfo) {
		MdeTrends trends = new MdeTrends();
		String pictures = new String();
		try {
			//图片循环取出
			for(String pId:pictureIds)
			{
				pictures = pictures + weiXinService.saveImageToDisk(pId,"") + "|";
			}
			if (pictures.endsWith("|")) {
				pictures = pictures.substring(0, pictures.length() - 1);
			}
			trends.setTrendPicurl(pictures);
		} catch (Exception e) {
			log.error("手机端发送动态异常",e);
			return 0;
		}
		
		//百度敏感词分析
//		if (StringsUtils.isNotEmpty(description)) {
//			description = baiDuKeyWordFilerUtils.filterKeWord(description);
//		}
		trends.setTrendDesc(StringsUtils.isEmpty(description)?"":description);
		trends.setUserCode(userCode);
		trends.setLinkInfo(linkInfo);
		trends.setShowFlag(StringsUtils.isEmpty(showFlag) ? "0" : showFlag);
		trends.setCommentCount(0);
		trends.setLikeCount(0);
		trends.setVersionNo(1);
		trends.setDelFlag(0);
		trends.setCreateBy(userCode + "");
		trends.setUpdateBy(userCode + "");
		return trendsService.insert(trends);
	}
	
	
	public String formatURL(String description) {
		Map<String,Object> map = new HashMap<String,Object>();
		String regexUrl = "((http|https)://)(([a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\\&%_\\./-~-]*)?";
		Pattern p = Pattern.compile(regexUrl,Pattern.CASE_INSENSITIVE);
        Matcher matcher = p.matcher(description);
        String s="";
        while(matcher.find()){
        	s = matcher.group();
        }
        map.put("title", "");
    	map.put("url", s);
        if(StringsUtils.isNotEmpty(s)) {
            try {
            	// 截取域名
//            	java.net.URL  url = new  java.net.URL(s);
//            	String host = url.getHost();// 获取主机名 
//            	String pro = url.getProtocol();
                Document document = Jsoup.connect(s).get();
                if (document != null) {
                	map.put("title", document.title());
//                	map.put("imgs", pro+"://"+getIcons(document,host));
//                	map.put("content", document.body().text());
                	map.put("url", s);
                	return JSON.toJSONString(map);
                }
            } catch (IOException _e) {
            }
    	}
        return JSON.toJSONString(map);
	}

//	private Object getIcons(Document doc, String host) {
//		Elements els = doc.select("link");
//		for (Element link : els) {
//			String linkHref = link.attr("rel");
//			if(linkHref.indexOf("icon")>=0 || linkHref.indexOf("ICON")>=0) {
//				String iconHref = link.attr("href");
//				return iconHref.indexOf(host)>0?iconHref.substring(iconHref.indexOf(host)):host+iconHref;
//			}
//		}
//		return null;
//	}

	/**
	 * 压缩图片
	 * @param desPath 文件路径
	 * @param desFileSize 目标大小 kb
	 * @param accuracy 图片质量
	 * @throws IOException
	 *//*
	private void commpressPicCycle(String desPath, long desFileSize,  double accuracy) throws IOException {
        File srcFileJPG = new File(desPath);
        long srcFileSizeJPG = srcFileJPG.length();
        // 2、判断大小，如果小于desFileSize，不压缩；如果大于等于desFileSize，压缩
        if (srcFileSizeJPG <= desFileSize * 1024) {
            return;
        }
        // 计算宽高
        BufferedImage bim = ImageIO.read(srcFileJPG);
        int srcWdith = bim.getWidth();
        int srcHeigth = bim.getHeight();
        int desWidth = new BigDecimal(srcWdith).multiply(new BigDecimal(accuracy)).intValue();
        int desHeight = new BigDecimal(srcHeigth).multiply(new BigDecimal(accuracy)).intValue();
        Thumbnails.of(desPath).size(desWidth, desHeight).outputQuality(accuracy).toFile(desPath);
        commpressPicCycle(desPath, desFileSize, accuracy);
    }*/
	/**
	 * 保存动态评论
	 * 		info => userCode 动态发布者的userCode
	 * 		info => commentatorCode 当前评论者的userCode
	 * @param info 
	 * @return
	 */
	@Transactional
	public String commentTrend(TrendCommentInfo info, String lang) {
		info.setDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		info.setUuid(UUID.randomUUID().toString().replace("-", ""));
		// 获取用户的职位信息
		String positionCode = workExperienceService.findWorkPositionByUserCode(info.getCommentatorCode());
		info.setPositionCode(positionCode);
		
		//百度敏感词分析
//		if (StringsUtils.isNotEmpty(info.getComment())) {
//			info.setComment(baiDuKeyWordFilerUtils.filterKeWord(info.getComment()));
//		}
		info.setForeignName(commonService.getUserInfo(info.getCommentatorCode()).getForeignName());
		String trendCommentInfoStr = JacksonUtils.bean2json(info);

		// 将信息存入redis缓存中 (自己评论自己 不记录)
		if(!StringsUtils.isEqual(info.getCommentatorCode(), info.getUserCode())) {
			commonService.insertCommentedTrendsInfo(info);
		}

		// 将信息存入数据库中
		int i = trendsService.updateCommentWho(info.getTrendId(), trendCommentInfoStr);
		if (i != 1) {
			throw new CustomException(InfoMsg.ERROR_SAVE_FIELD);
		}
		return trendsService.getTrendsById(info.getTrendId(),lang).getCommentWho();
	}

	/**
	 * 保存动态点赞 (新增或删除)
	 * 
	 * @param info
	 * @return
	 */
	@Transactional
	public int thumbUpTrend(TrendThumbUpInfo info,String lang) {

		// 获取用户的职位信息
		MdeTrends trendInfo = trendsService.getTrendsById(info.getTrendId(),lang);
		if(trendInfo == null) {
			throw new CustomException(InfoMsg.ERROR_TREND_NOT_EXIST);
		}
		String trendThuumbUpInfoStr = "";
		boolean containFlag = false;
		if (StringsUtils.isNotEmpty(trendInfo.getLikeWho())
				&& trendInfo.getLikeWho().contains("\"userCode\":\"" + info.getCommentatorCode()+"\"") == true) {
			String[] trendsThumbUps = trendInfo.getLikeWho().split(";");
			for (String s : trendsThumbUps) {
				if (s.contains("\"userCode\":\"" + info.getCommentatorCode()+"\"") == false) {
					trendThuumbUpInfoStr += s+";";
				}
			}
			containFlag = true;
		} else {
			String positionCode = workExperienceService.findWorkPositionByUserCode(info.getCommentatorCode());
			info.setPositionCode(positionCode);
			info.setForeignName(commonService.getUserInfo(info.getCommentatorCode()).getForeignName());
			info.setDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
			trendThuumbUpInfoStr = JacksonUtils.bean2json(info) + ";" + trendInfo.getLikeWho();
		}
		// 将信息存入数据库中
		MdeTrends trend = new MdeTrends();
		trend.setTrendId(new Long(info.getTrendId()));
		trend.setLikeWho(trendThuumbUpInfoStr.trim());
		if (containFlag) {
			trend.setLikeCount(-1);
		} else {
			trend.setLikeCount(1);
		}
		trend.setUpdateBy(info.getUserCode() + "");
		int i = trendsService.updateLikeWho(trend);
		// 更新用户字段 点赞过的资讯id
//		MdeUser user = new MdeUser();
		/*MdeUser user_ = commonService.getUserInfo(info.getUserCode());
		if(!StringsUtils.isEmpty(user_.getLikeList()) && 
				user_.getLikeList().indexOf(String.valueOf(info.getTrendId()))>=0) {
			String likeList_ = user_.getLikeList().replaceAll(info.getTrendId()+",", "");
			user.setLikeList(likeList_);
		}else {
			String likeList_ = StringsUtils.isEmpty(user_.getLikeList())?"":user_.getLikeList();
			user.setLikeList(likeList_+info.getTrendId()+",");
		}*/
//		user.setUserCode(info.getCommentatorCode());
//		user.setLikeList(info.getTrendId()+"");
//		int y = userService.updateLikeOrShareList(user);
//		if (y != 1 && i != 1) {
//			throw new CustomException(InfoMsg.ERROR_UPDATE_USER_FAIL);
//		}
		return i;
	}

	/**
	 * 分享动态
	 * 
	 * @param param -> currentUserCode trendId trendDesc showFlag lang
	 * @return
	 */
	@Transactional
	public int shareTrend(Map<String, Object> param) {
		String currentUserCode = param.get("currentUserCode").toString();
		String trendId = param.get("trendId").toString();
		String trendDesc = param.get("trendDesc").toString();
		String showFlag = param.get("showFlag").toString();
		String lang = param.get("lang").toString();
		if(StringsUtils.isEmpty(currentUserCode) ||
				StringsUtils.isEmpty(trendId) ||
//				StringsUtils.isEmpty(trendDesc) ||
				StringsUtils.isEmpty(showFlag) ||
				StringsUtils.isEmpty(lang)) {
			throw new CustomException(InfoMsg.ERROR_PARAMS_ERROR);
		}
		MdeTrends trend = trendsService.getTrendsById(Long.valueOf(trendId), lang);
		// 仅好友可见的动态不可以被分享
		if(trend.getShowFlag().equals("1")) {
			throw new CustomException(InfoMsg.ERROR_CAN_NOT_SHARE);
		}
		// 更新用户字段 点赞过的资讯id
//		MdeUser user = new MdeUser();
//
//		user.setUserCode(Integer.valueOf(currentUserCode));
//		user.setLikeList(trendId);
//		int y = userService.updateLikeOrShareList(user);
//		if (y != 1) {
//			throw new CustomException(InfoMsg.ERROR_UPDATE_USER_FAIL);
//		}
		MdeTrends trends_ = new MdeTrends();
		trends_.setUserCode(currentUserCode);
		trends_.setTrendDesc(trendDesc);
		trends_.setVersionNo(1);
		trends_.setShowFlag(showFlag);
		trends_.setDelFlag(0);
		trends_.setCreateBy(currentUserCode);
		trends_.setUpdateBy(currentUserCode);
		
		// 设置分享源
		// 如果该动态有分享来源则设置来源中动态的属性
		if(trend.getOriginTrendId() > 0 ) {
			trends_.setOriginTrendId(trend.getOriginTrendId());
			trends_.setOriginUserCode(trend.getOriginUserCode());
			trends_.setOriginTrend(trend.getOriginTrend());
		}else {
			trends_.setOriginTrendId(trend.getTrendId());
			trends_.setOriginUserCode(trend.getUserCode());
			trends_.setOriginTrend(getTrendSimpleAsStr(trend));
		}
		return trendsService.insertSharedTrends(trends_);
	}
	
	public String getTrendSimpleAsStr(MdeTrends trend) {
		trend.setCommentWho(null);
		trend.setLikeWho(null);
		return JSONObject.toJSONString(trend);
	}

	/**
	 * 添加好友
	 * 
	 * @param info
	 * @return
	 */
	@Transactional
	public int makeFriends(String userCode1, String userCode2) {
		MdeFriendRelation relation = friendRelationService.getInfoByCode(userCode1, userCode2);
		if (relation == null) {
			// 存入数据库
			return friendRelationService.makeFriends(userCode1, userCode2);
		}
		if (relation.getConfirmTime() == null) {
			throw new CustomException(InfoMsg.ERROR_WAIT_FRIEND_TO_CHECK);
		} else {
			throw new CustomException(InfoMsg.ERROR_IS_FRIEND);
		}
	}

	/**
	 * 获取用户通知数
	 * 
	 * @param userCode
	 * @return
	 */
	public Map<String, Object> getNoticeCount(String userCode) {
		Map<String, Object> map = new HashMap<String, Object>();
		MdeUser user = commonService.getUserInfo(userCode);
		// 已同意好友请求的人员姓名
//		List<String> confirmedFriendship = commonService.getConfirmedFriendship(userCode);
//		map.put("confirmedFriendship", confirmedFriendship);
		// 评论的信息和数量
		int commentedInfoCount = commonService.getCommentedTrendsInfoCounts(userCode);
		map.put("commentedTrendsInfoCount", commentedInfoCount);
		// 好友邀请的信息和数量
		List<MdeFriendRelation> friendInvitation = commonService.getFriendInvitation(userCode);
		map.put("friendInvitationCount", friendInvitation.size());
		// 个人用户
		if (user.getIdentityFlag().equals("0")) {
			// 企业邀请数量
			int invationInfoCount = commonService.getRecievedHotelInvationInfoCounts(userCode);
			map.put("invationInfoCount", invationInfoCount);
			map.put("totalCount", commentedInfoCount + invationInfoCount + friendInvitation.size());
		} else {
			// 酒店收到的投递简历数量
			int recievedCvCount = commonService.getHotelUserRecievedCVCount(userCode);
			map.put("recievedUserCvCount", recievedCvCount);
			map.put("totalCount", commentedInfoCount + friendInvitation.size() + recievedCvCount);
		}
		return map;
	}

	/**
	 * 获取用户通知信息和数量
	 * 
	 * @param userCode
	 * @return
	 */
	public Map<String, Object> getNoticeInfo(String userCode) {
		Map<String, Object> map = new HashMap<String, Object>();
		MdeUser user = commonService.getUserInfo(userCode);
		// 已同意好友请求的人员姓名
		List<UserSimple> confirmedFriendship = commonService.getConfirmedFriendship(userCode);
		map.put("confirmedFriendship", confirmedFriendship);
		// 评论的信息和数量
		List<TrendCommentInfo> commentedInfo = commonService.getCommentedTrendsInfo(userCode);
		map.put("commentedTrendsInfo", commentedInfo);
		map.put("commentedTrendsInfoCount", commentedInfo.size());
		// 好友邀请的信息和数量
		List<MdeFriendRelation> friendInvitation = commonService.getFriendInvitation(userCode);
		map.put("friendInvitation", friendInvitation);
		map.put("friendInvitationCount", friendInvitation.size());
		// 个人用户
		if (user.getIdentityFlag().equals("0")) {
			// 企业邀请数量
			int invationInfoCount = commonService.getRecievedHotelInvationInfoCounts(userCode);
			map.put("invationInfoCount", invationInfoCount);
			map.put("totalCount", commentedInfo.size() + invationInfoCount + friendInvitation.size());
		} else {
			// 酒店收到的投递简历数量
			ArrayList<JobCollectionReq> recievedCvList = commonService.getHotelUserRecievedCV(userCode);
			map.put("recievedUserCv", recievedCvList);
			map.put("recievedUserCvCount", recievedCvList.size());
			map.put("totalCount", commentedInfo.size() + friendInvitation.size() + recievedCvList.size());
		}
		return map;
	}

	/**
	 * 获取更多好友动态
	 * 
	 * @param param { userCode index size }
	 * @return
	 */
	public Map<String, Object> getMoreTrendsOrHotInfo(UserCodeWithPage param,String lang,String userCode) {
		Map<String, Object> map = new HashMap<String, Object>();
		// 好友动态
		Page<TrendsDto> page = new Page<TrendsDto>(param.getIndex(), param.getSize());
		map.put("trendsOfFriends", trendsService.getFriendTrendsForMainpage(page,userCode,lang));
		return map;
	}

	
	/**
	 * 获取动态详细
	 * @param trendId 
	 * @param userCode
	 * @param trendId
	 * @return
	 */
	public List<MdeTrends> getTrendsDetail(Long trendId, String userCode, String lang) {
		List<MdeTrends> list = new ArrayList<>();
		if(trendId == null) {
			List<TrendCommentInfo> infos = commonService.getCommentedTrendsInfo(userCode);
			
			if(infos != null && infos.size() > 0) {
				List<Long> trendIds = new ArrayList<Long>();
				for(int i=0; i<infos.size();i++) {
					trendIds.add(infos.get(i).getTrendId());
				}
				list = trendsService.getTrendsByIds(trendIds, lang);
			}
			commonService.resetCommentedTrendsInfo(userCode);
		}else {
			list.add(trendsService.getTrendsById(trendId, lang));
			commonService.resetCommentedTrendsInfo(userCode,trendId);
		}
		return list;
	}
	
	/**
	 * 获取广告/资讯 详情
	 * @param userCode
	 * @param lang
	 * @param index_ 
	 * @return
	 */
	public MdeInformation getHotInformatinoByID(String userCode, String lang, String infoId) {
		List<MdeInformation> info = commonService.getInformationsById(userCode,infoId);
		return info.size()>0? info.get(0):null;
	}
	
	/**
	 * 分享动态到领英
	 * @param trendId 动态ID
	 * @param userCode 用户code
	 * @param code 领英返回code
	 * @param lang 语言标记
	 * @return
	 */
	public String shareTrendToLinkedIn(String trendId, String userCode, String code, String lang) {
		// 获取令牌 access_token
		LinkedInTokenDto linkedInTokenDto = authorizedService.getLinkedInTokenDto(code);
		if (linkedInTokenDto == null) {
			throw new CustomException(InfoMsg.ERROR_AUZ_FAILED);
		}
		MdeTrends trend = trendsService.getTrendsById(Long.valueOf(trendId), lang);
		if(trend == null) {
			throw new CustomException(InfoMsg.ERROR_TREND_NOT_EXIST);
		}
		authorizedService.shareTrendToLinkedIn(linkedInTokenDto,trend);

		// 构造参数
		Map<String, Object> map = new HashMap<String, Object>();
			
		
		Map<String, Object> map_ = new HashMap<String, Object>();
			map_.put("title", "LinkedIn Developers Resources");
			map_.put("description", "Leverage LinkedIn's APIs to maximize engagement");
			map_.put("submitted-url", "https://www.menduner.com/");
			map_.put("submitted-image-url", "https://www.menduner.com//images/userfiles/1/images/recruitment/mdeAdImages/2018/08/%E8%BD%AE%E6%92%AD.jpg");
		map.put("content", map_);
			map_.clear();
			map_.put("code", "anyone");
		map.put("visibility", map_);
			map_.clear();
		map.put("comment", "Check out developer.linkedin.com!");
		
		String result = authorizedService.sendContentToLinkedIn(linkInShareUrl,map,linkedInTokenDto.getAccessToken());
		
		return result;
	}

}
