package com.goafanti.common.controller;


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

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.goafanti.achievement.service.AchievementInterestService;
import com.goafanti.achievement.service.AchievementService;
import com.goafanti.admin.service.AdminVideoService;
import com.goafanti.app.bo.ExpertsListBo;
import com.goafanti.banners.service.BannersService;
import com.goafanti.business.bo.JtBusinessCategoryBo;
import com.goafanti.business.bo.JtBusinessCategoryTree;
import com.goafanti.business.bo.JtBusinessProjectResult;
import com.goafanti.business.service.JtBusinessService;
import com.goafanti.business.service.JtTagService;
import com.goafanti.common.bo.PolicyEntity;
import com.goafanti.common.bo.Result;
import com.goafanti.common.bo.fieldGlossoryBo;
import com.goafanti.common.constant.AFTConstants;
import com.goafanti.common.dao.JtBusinessCategoryMapper;
import com.goafanti.common.dao.ProjectInterestMapper;
import com.goafanti.common.enums.ConsultantType;
import com.goafanti.common.model.AchievementInterest;
import com.goafanti.common.model.Banners;
import com.goafanti.common.model.DemandInterest;
import com.goafanti.common.model.JtBusinessCategory;
import com.goafanti.common.model.JtBusinessProject;
import com.goafanti.common.model.News;
import com.goafanti.common.model.Policy;
import com.goafanti.common.model.User;
import com.goafanti.common.model.UserIdentity;
import com.goafanti.common.service.GlobalSearchService;
import com.goafanti.common.utils.LimitLengthUtil;
import com.goafanti.common.utils.StringUtils;
import com.goafanti.core.mybatis.page.Pagination;
import com.goafanti.core.shiro.token.TokenManager;
import com.goafanti.demand.bo.DemandListBo;
import com.goafanti.demand.service.DemandInterestService;
import com.goafanti.demand.service.DemandService;
import com.goafanti.news.bo.NewsPortalList;
import com.goafanti.news.bo.PolicyResult;
import com.goafanti.news.enums.NewsType;
import com.goafanti.news.service.NewsService;
import com.goafanti.news.service.PolicyService;
import com.goafanti.portal.bo.AchievementObject;
import com.goafanti.user.bo.OrgIdentityBo;
import com.goafanti.user.service.OrganizationIdentityService;
import com.goafanti.user.service.UserIdentityService;
import com.goafanti.user.service.UserService;

@Controller
public class WebpageController extends BaseController {

	@Resource
	private DemandService demandService;

	@Resource
	private AchievementService achievementService;

	@Resource
	private BannersService bannersService;

	@Resource
	private UserIdentityService userIdentityService;

	@Resource
	private OrganizationIdentityService organizationIdentityService;

	@Resource
	private NewsService newsService;

	@Resource
	private PolicyService policyService;

	@Resource
	private JtBusinessService jtBusinessService;

	@Resource
	private UserService userService;

	@Resource
	private AchievementInterestService achievementInterestService;

	@Resource
	private DemandInterestService demandInterestService;
	@Resource
	private GlobalSearchService globalSearchService;

	@Resource
	private ProjectInterestMapper projectInterestMapper;
	
	@Resource
	private JtBusinessCategoryMapper jtBusinessCategoryMapper; 
	@Resource
	private JtTagService jtTagService; 
	
	@Resource
	private AdminVideoService adminVideoService;

	@RequestMapping(value = "/user/account/index", method = RequestMethod.GET)
	public ModelAndView index(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/user/account/index");
		return modelview;
	}

	@RequestMapping(value = "/user/account/evaluateInfo", method = RequestMethod.GET)
	public ModelAndView evaluateInfo(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/user/account/evaluateInfo");
		return modelview;
	}

	@RequestMapping(value = "/user/account/set", method = RequestMethod.GET)
	public ModelAndView userSet(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/user/account/set");
		return modelview;
	}
	@RequestMapping(value = "/portal/news/agreement", method = RequestMethod.GET)
	public ModelAndView portalNewsAgreement(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/news/agreement");
		return modelview;
	}

	@RequestMapping(value = "/user/account/achievement", method = RequestMethod.GET)
	public ModelAndView userAchievement(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/user/account/achievement");
		return modelview;
	}

	@RequestMapping(value = "/user/account/demand", method = RequestMethod.GET)
	public ModelAndView userDemand(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/user/account/demand");
		return modelview;
	}

	@RequestMapping(value = "/user/login", method = RequestMethod.GET)
	public String userLogin(HttpServletRequest request, ModelAndView modelview) {
		return "/user/login";
	}

	@RequestMapping(value = "/user/logout", method = RequestMethod.GET)
	public String userLogout(HttpServletRequest request, ModelAndView modelview) {
		TokenManager.logout();
		// return userLogin(request, modelview);
		return "redirect:/portal/index";
	}

	@RequestMapping(value = "/user/signIn", method = RequestMethod.GET)
	public String userSignin(HttpServletRequest request, ModelAndView modelview) {
		return "/user/signIn";
	}

	@RequestMapping(value = "/user/msignIn", method = RequestMethod.GET)
	public String mSignin(HttpServletRequest request, ModelAndView modelview) {
		return "/user/msignIn";
	}

	@RequestMapping(value = "/user/certify", method = RequestMethod.GET)
	public ModelAndView userCertify(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/user/certify");
		return modelview;
	}

	@RequestMapping(value = "/user/groupCertify", method = RequestMethod.GET)
	public ModelAndView userGroupCertify(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/user/groupCertify");
		return modelview;
	}

	@RequestMapping(value = "/user/account/services", method = RequestMethod.GET)
	public ModelAndView userServices(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/user/account/services");
		return modelview;
	}

	@RequestMapping(value = "/admin/login", method = RequestMethod.GET)
	public String adminLogin(HttpServletRequest request, ModelAndView modelview) {
		return "/admin/login";
	}

	@RequestMapping(value = "/admin/demand", method = RequestMethod.GET)
	public String adminDemand(HttpServletRequest request, ModelAndView modelview) {
		return "/admin/demand";
	}

	@RequestMapping(value = "/admin/achievement", method = RequestMethod.GET)
	public String adminAchievement(HttpServletRequest request, ModelAndView modelview) {
		return "/admin/achievement";
	}

	@RequestMapping(value = "/admin/set", method = RequestMethod.GET)
	public String adminSet(HttpServletRequest request, ModelAndView modelview) {
		return "/admin/set";
	}

	@RequestMapping(value = "/admin/userManage", method = RequestMethod.GET)
	public ModelAndView adminUserManage(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/userManage");
		return modelview;
	}

	@RequestMapping(value = "/admin/customer", method = RequestMethod.GET)
	public ModelAndView adminCustomer(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/customer");
		return modelview;
	}

	@RequestMapping(value = "/admin/servicesManage/technology", method = RequestMethod.GET)
	public ModelAndView adminServicesManageTechnology(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/servicesManage/technology");
		return modelview;
	}

	@RequestMapping(value = "/admin/servicesManage/patent", method = RequestMethod.GET)
	public ModelAndView adminServicesManagePatent(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/servicesManage/patent");
		return modelview;
	}

	@RequestMapping(value = "/admin/servicesManage/contract", method = RequestMethod.GET)
	public ModelAndView adminServicesManageContract(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/servicesManage/contract");
		return modelview;
	}

	@RequestMapping(value = "/admin/servicesManage/highTech", method = RequestMethod.GET)
	public ModelAndView adminServicesManageHighTech(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/servicesManage/highTech");
		return modelview;
	}

	@RequestMapping(value = "/admin/servicesManage/copyright", method = RequestMethod.GET)
	public ModelAndView adminServicesManageCopyright(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/servicesManage/copyright");
		return modelview;
	}

	@RequestMapping(value = "/admin/servicesManage/projectOrder", method = RequestMethod.GET)
	public ModelAndView adminServiceManageProjectOrder(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/servicesManage/projectOrder");
		return modelview;
	}

	@RequestMapping(value = "/admin/index", method = RequestMethod.GET)
	public ModelAndView adminHome(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/index");
		return modelview;
	}

	@RequestMapping(value = "/admin/idea", method = RequestMethod.GET)
	public ModelAndView adminIdea(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/idea");
		return modelview;
	}

	@RequestMapping(value = "/admin/userOrder", method = RequestMethod.GET)
	public ModelAndView adminUserOrder(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/userOrder");
		return modelview;
	}

	@RequestMapping(value = "/portal/continueHigh", method = RequestMethod.GET)
	public ModelAndView portalContinueHigh(HttpServletRequest request, ModelAndView modelview) {
		JtBusinessCategory bc1=jtBusinessService.getBusinessCategoryByLayerAndName(2, "高企诊断");
		JtBusinessCategory bc2=jtBusinessService.getBusinessCategoryByLayerAndName(2, "高企认定");
		JtBusinessCategory bc3=jtBusinessService.getBusinessCategoryByLayerAndName(2, "高企培育");
		modelview.addObject("gqc1", bc1);
		modelview.addObject("gqc2", bc2);
		modelview.addObject("gqc3", bc3);
		modelview.setViewName("/portal/continueHigh");
		return modelview;
	}

	@RequestMapping(value = "/portal/militaryProject", method = RequestMethod.GET)
	public ModelAndView portalMilitaryProject(HttpServletRequest request, ModelAndView modelview) {
		JtBusinessCategory bc1=jtBusinessService.getBusinessCategoryByLayerAndName(2, "武器装备科研生产保密资格认证");
		JtBusinessCategory bc2=jtBusinessService.getBusinessCategoryByLayerAndName(2, "武器装备科研生产许可证认证");
		JtBusinessCategory bc3=jtBusinessService.getBusinessCategoryByLayerAndName(2, "装备承制单位资格认证");
		modelview.addObject("gqc1", bc1);
		modelview.addObject("gqc2", bc2);
		modelview.addObject("gqc3", bc3);
		modelview.setViewName("/portal/militaryProject");
		return modelview;
	}

	@RequestMapping(value = "/portal/practicalPatent", method = RequestMethod.GET)
	public ModelAndView portalPracticalPatent(HttpServletRequest request, ModelAndView modelview) {
		JtBusinessCategory bc1=jtBusinessService.getBusinessCategoryByLayerAndName(2, "发明专利");
		JtBusinessCategory bc2=jtBusinessService.getBusinessCategoryByLayerAndName(2, "商标注册");
		JtBusinessCategory bc3=jtBusinessService.getBusinessCategoryByLayerAndName(2, "软著申请");
		modelview.addObject("gqc1", bc1);
		modelview.addObject("gqc2", bc2);
		modelview.addObject("gqc3", bc3);
		modelview.setViewName("/portal/practicalPatent");
		return modelview;
	}

	@RequestMapping(value = "/admin/order", method = RequestMethod.GET)
	public ModelAndView adminOrder(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/order");
		return modelview;
	}

	@RequestMapping(value = "/admin/operate", method = RequestMethod.GET)
	public ModelAndView adminOperate(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/admin/operate");
		return modelview;
	}

	@RequestMapping(value = "/portal/membership", method = RequestMethod.GET)
	public ModelAndView membership(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/membership");
		return modelview;
	}

	@RequestMapping(value = "/portal/search/subscriberUser", method = RequestMethod.GET)
	public ModelAndView portalSearchSubscriberUser(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/search/subscriberUser");
		return modelview;
	}

	@RequestMapping(value = "/portal/search/subscriberOrg", method = RequestMethod.GET)
	public ModelAndView portalSearchSubscriberOrg(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/search/subscriberOrg");
		return modelview;
	}

	/**
	 * 评估页
	 */
	@RequestMapping(value = "/portal/evaluation/index", method = RequestMethod.GET)
	public ModelAndView evaluation(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/evaluation/index");
		//handleBanners(modelview, BannersType.JI_SHU_PING_GU);
		return modelview;
	}

	/**
	 * 服务汇
	 */
	@RequestMapping(value = "/portal/service/serviceIndex", method = RequestMethod.GET)
	public ModelAndView portalServiceServiceIndex(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/service/services");
		Map<String, Object> map=new HashMap<>();
		map.put("military", jtBusinessService.getProjectByTag("军工市场采购",2));
		map.put("government", jtBusinessService.getProjectByTag("政府市场采购", 1));
		map.put("international", jtBusinessService.getProjectByTag("国际市场开发", 3));
		//减税免税
		List<JtBusinessProject> l1 = jtBusinessService.getProjectByTag("减税免税", 3);
		//融资
		List<JtBusinessProject> l2 = jtBusinessService.getProjectByTag("融资租售", 3);
		map.put("taxReduction", handleAdvertisement(l1));
		map.put("financingLease",handleAdvertisement(l2));
		map.put("defenseWeapon", jtBusinessService.getProjectByTag("攻防利器", 1));
		map.put("ownUse", jtBusinessService.getProjectByTag("他山己用", 4));
		modelview.addObject("prolist", map);//标签项目
		modelview.addObject("technologyProject", jtBusinessService.getCategoryByModule(5,2,12));//科技项目3级
		
		//科技项目下面的一级
		//modelview.addObject("tProject", jtBusinessService.getCategoryByModule(5,1,4));//科技项目2级
		
		
		// 政策
		// List<PolicyEntity>policyEntities=achievementService.getIntellectualProperty(8);
		/*List<PolicyResult> policies = (List<PolicyResult>) policyService
				.searchPolicy("", 2, null, null, "web_tech_service_index", 1, 8, null).getList();
		modelview.addObject("policyList", policies);
		// 新闻
		List<News> news = (List<News>) newsService.portalNewsList(5, 1, null, null, null, null, 2).getList();
		modelview.addObject("newsList", news);*/
		//军工认证
		/*JtBusinessCategory military = jtBusinessService.getBusinessCategoryByLayerAndName(1, "军工认证");
		List<JtBusinessProject> l = jtBusinessService.getModuleByName("军工认证", null, 3);
		for (JtBusinessProject project : l) {
			//去除数据中的标签
			if(StringUtils.isNotBlank(project.getIntroduce())){
				project.setIntroduce(project.getIntroduce().replaceAll("\\<.*?>", "")); 
			}
		}
		modelview.addObject("military", military);
		modelview.addObject("militaryList", l);*/
		// 高企服务
		/*JtBusinessCategory gaoqi = jtBusinessService.getBusinessCategoryByLayerAndName(1, "高新技术企业服务");
		JtBusinessCategory gaoqi2 = jtBusinessService.getBusinessCategoryByLayerAndName(2, "高新技术企业服务");
		if (gaoqi2 != null) {
			List<JtBusinessProject> gaoqiList = jtBusinessService.getBusinessProjectByCategoryId(gaoqi2.getId(), 6,
					null);
			for (JtBusinessProject project : gaoqiList) {
				if (project.getMinImgUrl() != null && project.getMinImgUrl().length() <= 0)
					project.setMinImgUrl(null);
				//去除数据中的标签
				if(StringUtils.isNotBlank(project.getIntroduce())){
					project.setIntroduce(project.getIntroduce().replaceAll("\\<.*?>", "")); 
				}
			}
			modelview.addObject("gaoqiList", gaoqiList);
			modelview.addObject("gqc1", gaoqi);
		}
		// 知识产权贯标
		JtBusinessCategory zscqgb = jtBusinessService.getBusinessCategoryByLayerAndName(1, "知识产权");
		if (zscqgb != null) {
			List<JtBusinessCategory> zscqgbCategories = jtBusinessService.getBusinessCategoryBySuperId(zscqgb.getId(),
					4);
			int[] zscqsizes = { 1, 2, 4, 10 };
			businessHelper(modelview, "zscqgb", zscqgbCategories, zscqsizes);
			modelview.addObject("zscqc1", zscqgb);
		}
		// 企业认证
		JtBusinessCategory qiyerenzheng = jtBusinessService.getBusinessCategoryByLayerAndName(1, "企业资质认定");
		if (qiyerenzheng != null) {
			List<JtBusinessCategory> qyrzCategories = jtBusinessService
					.getBusinessCategoryBySuperId(qiyerenzheng.getId(), 2);
			int[] qyrzsizes = { 8, 8 };
			businessHelper(modelview, "qyrz", qyrzCategories, qyrzsizes);
			modelview.addObject("qyrzc1", qiyerenzheng);
		}
		// 管理体系
		JtBusinessCategory manageSys = jtBusinessService.getBusinessCategoryByLayerAndName(1, "管理体系认证");
		JtBusinessCategory manageSys2 = jtBusinessService.getBusinessCategoryByLayerAndName(2, "管理体系认证");
		if (manageSys2 != null) {
			List<JtBusinessProject> manageSysPro = jtBusinessService.getBusinessProjectByCategoryId(manageSys2.getId(),
					18, null);
			modelview.addObject("manageSystemList", manageSysPro);
			modelview.addObject("managerSysc1", manageSys);
		}
		// 科技项目
		JtBusinessCategory scienceProject = jtBusinessService.getBusinessCategoryByLayerAndName(1, "科技项目");
		JtBusinessCategory scienceProject2 = jtBusinessService.getBusinessCategoryByLayerAndName(2, "科技项目");
		if (scienceProject2 != null) {
			List<JtBusinessProject> scienceProjects = jtBusinessService
					.getBusinessProjectByCategoryId(scienceProject2.getId(), 12, AFTConstants.YES);
			modelview.addObject("scienceProjectList", scienceProjects);
			modelview.addObject("spc1", scienceProject);
		}
		*/
		/*************以下是重新查询的数据********************************/
		/*JtBusinessCategory category = new JtBusinessCategory();
		category.setPcIndex(1);
		category.setLayer(6);
		category.setName("高新技术企业服务");
		//高企服务
		JtBusinessCategory gaoqi = jtBusinessService.getBusinessCategoryByLayerAndName(1, "高新技术企业服务");
		if (gaoqi != null) {
			List<JtBusinessCategory> gaoqiList = jtBusinessCategoryMapper.getCategoryByName(category);
			modelview.addObject("gaoqiList", gaoqiList);
			modelview.addObject("gqc1", gaoqi);
		}
		//企业资质认证
		JtBusinessCategory qiyerenzheng = jtBusinessService.getBusinessCategoryByLayerAndName(1, "企业资质认定");
		category.setLayer(10);
		category.setName("企业资质认定");
		if (qiyerenzheng != null) {
			//List<JtBusinessProject> qyrzCategories = jtBusinessService.getModuleByName("企业资质认定", null, 12);
			List<JtBusinessCategory> qyrzCategories = jtBusinessCategoryMapper.getCategoryByName(category);
			modelview.addObject("qyrzCategories", qyrzCategories);
			modelview.addObject("qyrzc1", qiyerenzheng);
		}
		//管理体系认证
		JtBusinessCategory manageSys2 = jtBusinessService.getBusinessCategoryByLayerAndName(1, "管理体系认证");
		category.setLayer(14);
		category.setName("管理体系认证");
		if (manageSys2 != null) {
			List<JtBusinessCategory> qyrzCategories = jtBusinessCategoryMapper.getCategoryByName(category);
			//List<JtBusinessProject> qyrzCategories = jtBusinessService.getModuleByName("管理体系认证", null, 18);
			modelview.addObject("manageSystemList", qyrzCategories);
			modelview.addObject("managerSysc1", manageSys2);
		}
		
		//军工认证
		JtBusinessCategory jungong1 = jtBusinessService.getBusinessCategoryByLayerAndName(1, "军工认证");
		category.setLayer(3);
		category.setName("军工认证");
		if (manageSys2 != null) {
			List<JtBusinessCategory> jungongList = jtBusinessCategoryMapper.getCategoryByName(category);
			modelview.addObject("jungongList", jungongList);
			modelview.addObject("jungong1", jungong1);
		}
		
		
		//科技项目
		//获得所有模块为5的科技项目id
		JtBusinessCategory scienceProject1 = jtBusinessService.getBusinessCategoryByLayerAndName(1, "科技项目");
		category.setLayer(2);//第3级分类
		category.setModule(5);
		category.setPcIndex(1);//pc首页显示
		category.setSort(12);//个数
		List<JtBusinessCategory> manageSysPro = jtBusinessCategoryMapper.getCategoryByModel(category);
		modelview.addObject("scienceProjectList", manageSysPro);
		modelview.addObject("spc1", scienceProject1);
		*/
		//军民融合
		/*JtBusinessCategory jmrh = jtBusinessService.getBusinessCategoryByLayerAndName(1, "军民融合");
		List<JtBusinessProject> jlist = jtBusinessService.getKJListByIds(3,null,3);
		modelview.addObject("jmrh", jmrh);
		modelview.addObject("jlist", jlist);*/
		/****************************以上是新修改的部分********************************************/
		// 咨询师
		/*List<UserIdentityBo> userIdentityBos = userIdentityService.getExperts(8);
		// List<consultantListBo>userIdentityBos=userIdentityService.getConsultantList(8);
		modelview.addObject("consultants", userIdentityBos);*/
		//获得轮播图数据
		List<Banners> blist = bannersService.findBannersList("serviceIndex", 0, 3, 1);
		if(null != blist){
			modelview.addObject("sbannerlist", blist);
		}
		return modelview;
	}

	/*
	 * 服务详情
	 * 
	 * @param id String
	 */
	@RequestMapping(value = "/portal/service/serviceDetail", method = RequestMethod.GET)
	public ModelAndView portalServiceServiceDetail(HttpServletRequest request, ModelAndView modelview, String id) {
		modelview.setViewName("/portal/service/serviceDetails");
		JtBusinessProject jtBusinessProject = jtBusinessService.getBusinessProjectDetail(id);
		if (null != jtBusinessProject) {
			if (jtBusinessProject.getMaxImgUrl() != null && jtBusinessProject.getMaxImgUrl().length() <= 0)
				jtBusinessProject.setMaxImgUrl(null);
		}
		if (jtBusinessProject.getCreateTime() != null
				&& 7 >= differentDaysByMillisecond(jtBusinessProject.getCreateTime(), new Date())) {
			modelview.addObject("newly", true);
		} else
			modelview.addObject("newly", false);
		String owner = "平台管理员";
		/*if (jtBusinessProject.getOwnerId() != null) {
			User user = userService.selectByPrimaryKey(jtBusinessProject.getOwnerId());
			if (user != null && user.getIdentifyName() != null) {
				owner = user.getIdentifyName();
			}
		}*/
		if (jtBusinessProject.getOwnerId() != null) {
			User user = userService.selectByPrimaryKey(jtBusinessProject.getOwnerId());
			if (user != null && user.getNickname() != null) {
				owner = user.getNickname();
			}
		}
		modelview.addObject("owner", owner);
		modelview.addObject("pj", jtBusinessProject);
		
		//判断是否是个人还是组织
		if(null != jtBusinessProject.getType() && 0 == jtBusinessProject.getType()){//个人
			UserIdentity uide =  userIdentityService.selectUserIdentityByUserId(jtBusinessProject.getOwnerId());
			modelview.addObject("uide", uide);
		}else if(null != jtBusinessProject.getType() && 1 == jtBusinessProject.getType()){//企业
			String oide = organizationIdentityService.selectOrgIdentityBoByUserId(jtBusinessProject.getOwnerId()).getUid();
			modelview.addObject("oide", oide);
		}
		//System.out.println(jtBusinessProject.toString());
		if (jtBusinessProject != null) {
			JtBusinessCategoryTree tree = jtBusinessService.getCategoryTree(jtBusinessProject.getCategoryId());
			modelview.addObject("tree", tree);
		}
		JtBusinessCategory jtBusinessCategory = jtBusinessService.getCategoryById(jtBusinessProject.getCategoryId());
		if (jtBusinessCategory != null && jtBusinessCategory.getModule() != null)
			modelview.addObject("module", jtBusinessCategory.getModule());
		else
			modelview.addObject("module", 0);

		// 是否关注
		if (StringUtils.isNotBlank(TokenManager.getUserId())) {
			int projectInterest = projectInterestMapper.checkUidAndDid(id, TokenManager.getUserId());
			if (projectInterest > 0)
				modelview.addObject("interested", true);
		}
		return modelview;
	}

	/*
	 * 服务详情2
	 * 
	 * @param id String
	 */
	@RequestMapping(value = "/portal/service/patentDetail", method = RequestMethod.GET)
	public ModelAndView portalServicePatentDetail(HttpServletRequest request, ModelAndView modelview, String id) {
		modelview.setViewName("/portal/service/patenteDetails");
		JtBusinessProject jtBusinessProject = jtBusinessService.getBusinessProjectDetail(id);
		if (jtBusinessProject != null) {
			if (jtBusinessProject.getMaxImgUrl() != null && jtBusinessProject.getMaxImgUrl().length() <= 0)
				jtBusinessProject.setMaxImgUrl(null);
		}
		if (jtBusinessProject.getCreateTime() != null
				&& 7 >= differentDaysByMillisecond(jtBusinessProject.getCreateTime(), new Date())) {
			modelview.addObject("newly", true);
		} else
			modelview.addObject("newly", false);
		String owner = "平台管理员";
		/*if (jtBusinessProject.getOwnerId() != null) {
			User user = userService.selectByPrimaryKey(jtBusinessProject.getOwnerId());
			if (user != null && user.getIdentifyName() != null) {
				owner = user.getIdentifyName();
			}
		}*/
		if (jtBusinessProject.getOwnerId() != null) {
			User user = userService.selectByPrimaryKey(jtBusinessProject.getOwnerId());
			if (user != null && user.getNickname() != null) {
				owner = user.getNickname();
			}
		}
		modelview.addObject("owner", owner);
		modelview.addObject("pj", jtBusinessProject);
		//判断是否是个人还是组织
		if(0 == jtBusinessProject.getType()){//个人
			UserIdentity uide =  userIdentityService.selectUserIdentityByUserId(jtBusinessProject.getOwnerId());
			modelview.addObject("uide", uide);
		}else if(1 == jtBusinessProject.getType()){//企业
			String oide =  organizationIdentityService.selectOrgIdentityBoByUserId(jtBusinessProject.getOwnerId()).getUid();
			modelview.addObject("oide", oide);
		}
		//System.out.println(jtBusinessProject.toString());
		if (jtBusinessProject != null) {
			JtBusinessCategoryTree tree = jtBusinessService.getCategoryTree(jtBusinessProject.getCategoryId());
			modelview.addObject("tree", tree);
		}
		JtBusinessCategory jtBusinessCategory = jtBusinessService.getCategoryById(jtBusinessProject.getCategoryId());
		if (jtBusinessCategory != null && jtBusinessCategory.getModule() != null)
			modelview.addObject("module", jtBusinessCategory.getModule());
		else
			modelview.addObject("module", 0);

		// 是否关注
		if (StringUtils.isNotBlank(TokenManager.getUserId())) {
			int projectInterest = projectInterestMapper.checkUidAndDid(id, TokenManager.getUserId());
			if (projectInterest > 0)
				modelview.addObject("interested", true);
		}
		return modelview;
	}

	@RequestMapping(value = "/portal/service/serviceList", method = RequestMethod.GET)
	public ModelAndView serviceList(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/service/serviceList");
		return modelview;
	}

	@RequestMapping(value = "/portal/technologyTrading/demandList", method = RequestMethod.GET)
	public ModelAndView demandList(HttpServletRequest request, ModelAndView modelview) {
		String url = com.goafanti.common.utils.StringUtils.getDomainByHttpRequest(request);
		modelview.setViewName("/portal/technologyTrading/demandList");
		List<DemandListBo> boutiques = demandService.getHotDemand(3, url, "web_demand_list", 0);
		modelview.addObject("boutiques", boutiques);
		return modelview;
	}

	@RequestMapping(value = "/portal/technologyTrading/achievementList", method = RequestMethod.GET)
	public ModelAndView achievementList(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/technologyTrading/achievementList");
		List<AchievementObject> boutiques = achievementService.getBoutiquePatent(3,0);
		modelview.addObject("boutiques", boutiques);
		return modelview;
	}

	/**
	 * 知识产权
	 * 
	 * @param request
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/service/propertyRight", method = RequestMethod.GET)
	public ModelAndView propertyRight(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/service/propertyRight");
		return modelview;
	}

	/**
	 * 高企认定
	 * 
	 * @param request
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/service/highTechCognizance", method = RequestMethod.GET)
	public ModelAndView highTechCognizance(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/service/highTechCognizance");
		return modelview;
	}

	/**
	 * 技术交易
	 */
	@RequestMapping(value = "/portal/technologyTrading/index", method = RequestMethod.GET)
	public ModelAndView portalTechnologyTradingIndex(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/technologyTrading/index");
		//handleBanners(modelview, BannersType.JI_SHU_JIAO_YI);
		List<NewsPortalList> newsPortalList = newsService.portalNewsPolicy();
		modelview.addObject("newsPortalList", newsPortalList);
		List<NewsPortalList> portalNewsQuestion = newsService.portalNewsQuestion();
		modelview.addObject("portalNewsQuestion", portalNewsQuestion);
		return modelview;
	}

	/**
	 * 
	 * 智库咨询
	 * 
	 * @param request
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/thinkTank/index", method = RequestMethod.GET)
	public ModelAndView thinkTank(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/thinkTank/index");
		return modelview;
	}

	/**
	 * 政策列表
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/portal/thinkTank/policyList", method = RequestMethod.GET)
	public ModelAndView policyList(ModelAndView modelview) {
		modelview.setViewName("/portal/thinkTank/policyList");
		List<NewsPortalList> newsList = (List<NewsPortalList>) newsService
				.portalNewsList(5, 1, null, null, null, null, 2).getList();
		modelview.addObject("newsList", newsList);
		return modelview;
	}

	/**
	 * 会员介绍
	 * 
	 * @param request
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/member")
	public ModelAndView member(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/member");
		return modelview;
	}

	/**
	 * 技术评估
	 * 
	 * @param request
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/technologyTrading/assessMent")
	public ModelAndView assessMent(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/technologyTrading/assessMent");
		modelview.addObject("zcfg", newsService.findIndexNewsList(0, NewsType.KJZX.getCode(), 4));
		return modelview;
	}

	/**
	 * 关于我们
	 * 
	 * @param request
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/aboutUs", method = RequestMethod.GET)
	public ModelAndView aboutUs(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/aboutUs");
		return modelview;
	}

	/**
	 * 联系我们
	 * 
	 * @param request
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/contactUs", method = RequestMethod.GET)
	public ModelAndView contactUs(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/contactUs");
		return modelview;
	}

	/*private void handleBanners(ModelAndView modelview, BannersType bannersType) {
		List<Banners> banners = bannersService.findPortalBanners(bannersType.getKey());
		if (!banners.isEmpty()) {
			modelview.addObject("banners", banners);
		}
	}*/

	/**
	 * 服务-推荐
	 * 
	 * @param request
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/service/recommended")
	public ModelAndView recommended(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/service/recommended");
		return modelview;
	}

	/*
	 * 首页
	 * 
	 */

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/portal/index")
	public ModelAndView mainIndex(HttpServletRequest request, ModelAndView modelview) {
//		String url = com.goafanti.common.utils.StringUtils.getDomainByHttpRequest(request);
		modelview.setViewName("/portal/index");
		List<JtBusinessCategoryBo> patentCategory = jtBusinessService.getHomeIndex(1,1);
		patentCategory = patentCategory.subList(0, Math.min(7, patentCategory.size()));
		modelview.addObject("patentCategory", patentCategory);
		List<JtBusinessProject> jtBusinessProjects = (List<JtBusinessProject>) jtBusinessService
				.getProjects(null,null, null, null, 8, 1, 1, 2, null, 1, 0, 0, null).getList();
		for (JtBusinessProject project : jtBusinessProjects) {
			if (project.getMaxImgUrl() != null && project.getMaxImgUrl().length() <= 0)
				project.setMaxImgUrl(null);
			if (project.getMinImgUrl() != null && project.getMinImgUrl().length() <= 0)
				project.setMinImgUrl(null);
			//去除数据中的标签
			if(StringUtils.isNotBlank(project.getIntroduce())){
				project.setIntroduce(project.getIntroduce().replaceAll("\\<.*?>", "")); 
			}
		}
		modelview.addObject("projects", jtBusinessProjects);
		List<PolicyResult> policies = (List<PolicyResult>) policyService
				.searchPolicy("", 2, null, null, "web_index", 1, 99, null).getList();
		for (PolicyResult p : policies) {
			if (null != p.getTitleImg() && p.getTitleImg().contains(",")) {
				p.setTitleImg(p.getTitleImg().substring(0, p.getTitleImg().indexOf(",")));
			}
		}
		modelview.addObject("policys", policies);//政策
		List<News> newsList = (List<News>) newsService
				.listNews(0, null, null, null, null, null, null, 1, 8, "2", null, null,null).getList();
		modelview.addObject("news", newsList);//资讯
		//
		List<News> subscriptions = (List<News>) newsService
				.listNews(99, null, null, null, null, null, null, 1, 8, "2", null, null,null).getList();
		modelview.addObject("subscription", subscriptions);//技淘观点精选

		if (subscriptions != null && subscriptions.size() > 0 && subscriptions.get(0).getSourceUrl() != null
				&& subscriptions.get(0).getSourceUrl().contains(".")) {
			modelview.addObject("videoUrl", subscriptions.get(0).getSourceUrl());
		}
		
		//获得轮播图数据
		List<Banners> blist = bannersService.findBannersList("index", 0, 4, 1);
		if(null != blist){
			modelview.addObject("bannerlist", blist);
		}
		//视频
		String url = adminVideoService.getIndexVideo(1).getUrl();//首页
		modelview.addObject("vurl", url);
		// List<AchievementObject>
		// achievementObjects=achievementService.getHotAchievements(9, url,
		// "web_index");
		// modelview.addObject("achievements",achievementObjects);
		//
		//
		//
		//
		// List<DemandListBo> demandListBos=demandService.getHotDemand(9, url,
		// "web_index");
		// for(DemandListBo demandListBo:demandListBos) {
		// if(demandListBo.getPictureUrl()==null ||
		// !demandListBo.getPictureUrl().contains("."))demandListBo.setPictureUrl(null);
		// else
		// demandListBo.setPictureUrl(demandListBo.getPictureUrl().split(",")[0]);
		// }
		// //专家
		// List<UserIdentityBo>aExperts=userIdentityService.getExperts(8);
		// for(UserIdentityBo u:aExperts) {
		// if(u.getHeadPortraitUrl()!=null &&
		// u.getHeadPortraitUrl().length()<=0) {
		// u.setHeadPortraitUrl(null);
		// }
		// }
		// modelview.addObject("experts",aExperts);
		// modelview.addObject("demands",demandListBos);

		return modelview;
	}

	/*
	 * 
	 * 
	 * 技淘3.0-科技需求页
	 * 
	 * @param request
	 * 
	 * @param modelview
	 * 
	 * @return
	 * 
	 */
	// 需求首页
	@RequestMapping(value = "/portal/technologyTrading/demand")
	public ModelAndView demand(HttpServletRequest request, ModelAndView modelview) {
		String showLocation = "web_demand_main";
		String url = com.goafanti.common.utils.StringUtils.getDomainByHttpRequest(request);
		modelview.setViewName("/portal/technologyTrading/demand");
		// 行业
		List<fieldGlossoryBo> industryList = userIdentityService.domainList();
		modelview.addObject("industryList", industryList);

		// 最新需求
		List<DemandListBo> recentDemandList = demandService.recentDemand(5, url, showLocation);
		LimitLengthUtil.limiteDemandCompanyAndName(recentDemandList, 18, 18);
		modelview.addObject("recentDemandList", recentDemandList);
		//
		// //加急需求
		List<DemandListBo> urgentDemand = demandService.getUrgentDemand(5, url, showLocation);
		List<DemandListBo> urgentDemand2 = urgentDemand.subList(0, Math.min(2, urgentDemand.size()));
		List<DemandListBo> urgentDemand3 = urgentDemand.subList(Math.min(2, urgentDemand.size()),
				Math.min(5, urgentDemand.size()));
		System.out.print("u2:" + urgentDemand2.size() + " u3:" + urgentDemand3.size());
		LimitLengthUtil.limiteDemandLength(urgentDemand2, 13, 30);
		LimitLengthUtil.limiteDemandLength(urgentDemand3, 13, 33);
		modelview.addObject("urgentDemand2", urgentDemand2);
		modelview.addObject("urgentDemand3", urgentDemand3);

		// 热点需求
		List<DemandListBo> hotDemand = demandService.getHotDemand(5, url, showLocation,0);
		List<DemandListBo> hotDemand2 = hotDemand.subList(0, Math.min(2, hotDemand.size()));
		List<DemandListBo> hotDemand3 = hotDemand.subList(Math.min(2, hotDemand.size()), Math.min(5, hotDemand.size()));
		System.out.print("u2:" + hotDemand2.size() + " u3:" + hotDemand3.size());
		LimitLengthUtil.limiteDemandLength(hotDemand2, 13, 30);
		LimitLengthUtil.limiteDemandLength(hotDemand3, 13, 33);
		modelview.addObject("hotDemand2", hotDemand2);
		modelview.addObject("hotDemand3", hotDemand3);

		// 企业技术需求
		List<DemandListBo> eightMaxCompanyDemand = demandService.companyDemand(8, url, showLocation);
		for (DemandListBo demandListBo : eightMaxCompanyDemand) {
			if (demandListBo.getPictureUrl() == null || !demandListBo.getPictureUrl().contains("."))
				demandListBo.setPictureUrl(null);
			else
				demandListBo.setPictureUrl(demandListBo.getPictureUrl().split(",")[0]);
		}
		modelview.addObject("companyDemandList", eightMaxCompanyDemand);

		// 地区产业需求 最多4个
		List<DemandListBo> fourMaxareaDemand = demandService.areaDemand(4, url, showLocation);
		for (DemandListBo demandListBo : fourMaxareaDemand) {
			if (demandListBo.getPictureUrl() == null || !demandListBo.getPictureUrl().contains("."))
				demandListBo.setPictureUrl(null);
			else
				demandListBo.setPictureUrl(demandListBo.getPictureUrl().split(",")[0]);
		}
		LimitLengthUtil.limiteDemandLength(fourMaxareaDemand, 10, 208);
		modelview.addObject("areaDemandList", fourMaxareaDemand);

		// 产学研需求 最多9个
		List<DemandListBo> nightMaxProLearnStudyDemand = demandService.proLearnStudyDemand(9, url, showLocation);
		for (DemandListBo demandListBo : nightMaxProLearnStudyDemand) {
			if (demandListBo.getPictureUrl() == null || !demandListBo.getPictureUrl().contains("."))
				demandListBo.setPictureUrl(null);
			else
				demandListBo.setPictureUrl(demandListBo.getPictureUrl().split(",")[0]);
		}
		LimitLengthUtil.limiteDemandLength(nightMaxProLearnStudyDemand, 10, 18);
		LimitLengthUtil.limiteDemandCompanyAndName(nightMaxProLearnStudyDemand, 10, 18);
		modelview.addObject("proLearnStudyDemandList", nightMaxProLearnStudyDemand);

		// 研产资金需求 最多4个
		List<DemandListBo> fourMaxFundDemand = demandService.getFundCrowdDemand(4, url, showLocation);
		for (DemandListBo demandListBo : fourMaxFundDemand) {
			if (demandListBo.getPictureUrl() == null || !demandListBo.getPictureUrl().contains("."))
				demandListBo.setPictureUrl(null);
			else
				demandListBo.setPictureUrl(demandListBo.getPictureUrl().split(",")[0]);
		}
		LimitLengthUtil.limiteDemandLength(fourMaxFundDemand, 9, 30);
		modelview.addObject("fundDemandList", fourMaxFundDemand);

		// 技术人才需求
		List<DemandListBo> sixMaxPersonnelDemand = demandService.getPersonnelDemand(6, url, showLocation);
		// List
		// <DemandListBo>fourMaxPersonnelDemand=personnelDemand.subList(0,Math.min(6,
		// personnelDemand.size()));
		for (DemandListBo demandListBo : sixMaxPersonnelDemand) {
			if (demandListBo.getPictureUrl() == null || !demandListBo.getPictureUrl().contains("."))
				demandListBo.setPictureUrl(null);
			else
				demandListBo.setPictureUrl(demandListBo.getPictureUrl().split(",")[0]);
		}
		LimitLengthUtil.limiteDemandLength(sixMaxPersonnelDemand, 7, 30);
		modelview.addObject("personnelDemandList", sixMaxPersonnelDemand);
		
		//获得轮播图数据
		List<Banners> blist = bannersService.findBannersList("demand", 0, 3, 1);
		if(null != blist){
			modelview.addObject("dbannerlist", blist);
		}
		return modelview;
	}

	// 需求详情
	@RequestMapping(value = "/portal/technologyTrading/demandDetail")
	public ModelAndView DemandDetail(HttpServletRequest request, ModelAndView modelAndView, String id, Integer type) {
		String url = StringUtils.getDomainByHttpRequest(request);
		// 详情
		DemandListBo demand = demandService.getDemandDetail(id, type);
		int countInterest = demandService.getInterestCount(id);
		demand.setCountInterest(countInterest);
		modelAndView.addObject("demand", demand);

		// 精品需求
		List<DemandListBo> boutiqueDemandList = LimitLengthUtil
				.LimitListLengthRandomly(demandService.getHotDemand(10, url, "web_demand_list",0), 3, 10);
		modelAndView.addObject("reboutiquedemand", boutiqueDemandList);

		// 猜你喜欢
		List<DemandListBo> guessYouLikeList = LimitLengthUtil
				.LimitListLengthRandomly(demandService.recentDemand(10, url, "web_demand_list"), 4, 10);
		modelAndView.addObject("redemandlist", guessYouLikeList);

		// view
		modelAndView.setViewName("/portal/technologyTrading/demandDetail");

		// 是否关注
		if (StringUtils.isNotBlank(TokenManager.getUserId())) {
			DemandInterest demandInterest = demandInterestService
					.selectDemandInterestByUidAndDemandId(TokenManager.getUserId(), id);
			if (demandInterest != null)
				modelAndView.addObject("interested", true);
		}
		return modelAndView;
	}

	// 成果首页
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/portal/technologyTrading/achievement", method = RequestMethod.GET)
	public ModelAndView portalSearchAchievement(HttpServletRequest request, ModelAndView modelview) {
		String showLocation = "web_achievement_main";
		String url = com.goafanti.common.utils.StringUtils.getDomainByHttpRequest(request);
		modelview.setViewName("/portal/technologyTrading/achievement");
		// 行业
		List<fieldGlossoryBo> industryList = userIdentityService.domainList();// 行业类型
																				// 1级
		modelview.addObject("industryList", industryList);

		// 最新成果
		List<AchievementObject> recentAchievements = achievementService.recentAchievements(5, url, showLocation);
		modelview.addObject("recentAchievements", recentAchievements);
		// 热门关注
		List<AchievementObject> hotAchievements = achievementService.getHotAchievements(6, url, showLocation);
		modelview.addObject("hotAchievements", hotAchievements);

		// 专利
		List<AchievementObject> patentAchievements = achievementService.getPatentList(6, url, showLocation);
		modelview.addObject("patents", patentAchievements);
		// 实用技术
		List<AchievementObject> practicalTechnology = achievementService.getPracticalTechnologys(8, url, showLocation);
		modelview.addObject("practicalTechnology", practicalTechnology);

		// List<PolicyEntity>intellectualPropertyPolicyList=achievementService.getIntellectualProperty(5);
		List<PolicyResult> policies = (List<PolicyResult>) policyService
				.searchPolicy("", 2, null, null, "web_index", 1, 5, null).getList();
		modelview.addObject("policyList", policies);
		
		//获得轮播图数据
		List<Banners> blist = bannersService.findBannersList("achievement", 0, 3, 1);
		if(null != blist){
			modelview.addObject("abannerlist", blist);
		}
		
		return modelview;
	}

	@RequestMapping(value = "/portal/technologyTrading/achievementDetail")
	public ModelAndView achievementDetail(HttpServletRequest request, ModelAndView modelAndView, String id,
			Integer type) {
		if (type == null) {
			type = 1;
		}
		// 详情
		AchievementObject achievementObject = achievementService.getAchievementDetail(id, type);
		modelAndView.addObject("achievementdetail", achievementObject);
		// 精品
		List<AchievementObject> boutiques = LimitLengthUtil
				.LimitListLengthRandomly(achievementService.getBoutiquePatent(10,0), 3, 10);
		modelAndView.addObject("reboutiqueachievement", boutiques);

		// 猜你喜欢
		List<AchievementObject> guess = LimitLengthUtil.LimitListLengthRandomly(achievementService.guessYouLike(10), 4,
				10);
		modelAndView.addObject("guess", guess);
		// view
		modelAndView.setViewName("/portal/technologyTrading/achievementDetail");

		// 是否关注
		if (StringUtils.isNotBlank(TokenManager.getUserId())) {
			AchievementInterest achievementInterest = achievementInterestService
					.selectAchievementInterestByUidAndAchievementId(TokenManager.getUserId(), id);
			if (achievementInterest != null)
				modelAndView.addObject("isInterested", true);
		}
		return modelAndView;
	}

	@RequestMapping(value = "/portal/service/patentList")
	public ModelAndView patentList(HttpServletRequest request, ModelAndView modelAndView, String id, Integer type) {

		modelAndView.setViewName("/portal/service/patentList");

		return modelAndView;
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/portal/service/patent")
	public ModelAndView patentIndex(HttpServletRequest request, ModelAndView modelAndView, String id, Integer type) {
		List<JtBusinessCategoryBo> categoryBos = jtBusinessService.getCategoryBoList(1);
		modelAndView.addObject("categories", categoryBos);
		modelAndView.setViewName("/portal/service/patent");

		// 最新发布
		List<JtBusinessProjectResult> recents = (List<JtBusinessProjectResult>) jtBusinessService
				.getProjects(null,null, null, null, 4, 1, 1, 2, 1, null, 0, 0, null).getList();
		modelAndView.addObject("recent", recents);

		// 专利服务-商标服务-版权服务
		/*for (JtBusinessCategoryBo c : categoryBos) {
			if ("专利服务".equals(c.getTopLevel())) {
				List<JtBusinessProjectResult> res = (List<JtBusinessProjectResult>) jtBusinessService
						.getProjects(null,c.getTopLevelId(), null, null, 3, 1, 1, 2, 1, null, 0, 0, null).getList();
				modelAndView.addObject("patentService", res);
				modelAndView.addObject("patentTopId", c.getTopLevelId());
			} else if ("商标服务".equals(c.getTopLevel())) {
				List<JtBusinessProjectResult> res = (List<JtBusinessProjectResult>) jtBusinessService
						.getProjects(null,c.getTopLevelId(), null, null, 4, 1, 1, 2, 1, null, 0, 0, null).getList();
				modelAndView.addObject("branchService", res);
				modelAndView.addObject("branchTopId", c.getTopLevelId());
			} else if ("版权服务".equals(c.getTopLevel())) {
				List<JtBusinessProjectResult> res = (List<JtBusinessProjectResult>) jtBusinessService
						.getProjects(null,c.getTopLevelId(), null, null, 3, 1, 1, 2, 1, null, 0, 0, null).getList();
				modelAndView.addObject("copyrightService", res);
				modelAndView.addObject("copyrightTopId", c.getTopLevelId());
			}

		}*/
		/*******************************************修改首页专利商标版权************************************************/
		JtBusinessCategory category = new JtBusinessCategory();
		category.setPcIndex(1);
		category.setLayer(3);
		category.setName("专利服务");
		//专利 3
		List<JtBusinessCategory> zl = jtBusinessCategoryMapper.getCategoryByName(category);
		if(null != zl && zl.size() > 0){
			modelAndView.addObject("patentService", zl);
			modelAndView.addObject("patentTopId", zl.get(0).getSuperId());
		}
		//商标4
		category.setLayer(4);
		category.setName("商标服务");
		List<JtBusinessCategory> sb = jtBusinessCategoryMapper.getCategoryByName(category);
		if(null != sb && sb.size() > 0){
			modelAndView.addObject("branchService", sb);
			modelAndView.addObject("branchTopId", sb.get(0).getSuperId());
		}
		//版权3
		category.setLayer(3);
		category.setName("版权服务");
		List<JtBusinessCategory> bq = jtBusinessCategoryMapper.getCategoryByName(category);
		if(null != bq && bq.size() > 0){
			modelAndView.addObject("copyrightService", bq);
			modelAndView.addObject("copyrightTopId", bq.get(0).getSuperId());
		}
		/*********************************结束**************************************/
		
		// 知产百科
		List<News> news = (List<News>) newsService
				.listNews(98, null, null, null, null, null, null, 1, 4, 2 + "", null, null,null)
				.getList();
		for (News n : news) {
			if (null != n.getTitleImg() && n.getTitleImg().contains(",")) {
				n.setTitleImg(n.getTitleImg().substring(0, n.getTitleImg().indexOf(",")));
			}
		}
		modelAndView.addObject("jtNews", news);
		//获得轮播图数据
		List<Banners> blist = bannersService.findBannersList("patent", 0, 3, 1);
		if(null != blist){
			modelAndView.addObject("pbannerlist", blist);
		}
		return modelAndView;
	}

	/*
	 * 交易
	 */
	@RequestMapping(value = "/portal/technologyTrading/tradingIndex")
	public ModelAndView patentTrading(HttpServletRequest request, ModelAndView modelAndView) {
		String url = com.goafanti.common.utils.StringUtils.getDomainByHttpRequest(request);
		modelAndView.setViewName("/portal/technologyTrading/tradingIndex");
		// 成果
		List<AchievementObject> achievementObjects = achievementService.getHotAchievements(4, url,
				"web_achievement_trading_index");
		for (AchievementObject a : achievementObjects) {
			if (null != a.getTechnicalPictureUrl() && a.getTechnicalPictureUrl().contains(",")) {
				a.setTechnicalPictureUrl(
						a.getTechnicalPictureUrl().substring(0, a.getTechnicalPictureUrl().indexOf(",")));
			}
		}
		modelAndView.addObject("achievement", achievementObjects);

		// 需求
		List<DemandListBo> demandListBos = demandService.getHotDemand(2, url, "web_demand_trading_index",0);
		for (DemandListBo d : demandListBos) {
			if (null != d.getFirstPic() && d.getFirstPic().contains(",")) {
				d.setFirstPic(d.getFirstPic().substring(0, d.getFirstPic().indexOf(",")));
			}
		}
		modelAndView.addObject("demand", demandListBos);
		return modelAndView;
	}

	

	@RequestMapping(value = "/portal/facilitatorDetails")
	public ModelAndView companyProfile(HttpServletRequest request, ModelAndView modelAndView, String uid) {
		modelAndView.setViewName("/portal/facilitator");
		
		OrgIdentityBo org = organizationIdentityService.selectOrgIdentityBoByUserId(uid);
		modelAndView.addObject("org", org);
		/*List<JtBusinessProjectResult> projectResults = (List<JtBusinessProjectResult>) jtBusinessService
				.getProjects(null,null, null, null, 12, 1, 0, 2, null, null, 0, 0, uid).getList();
		modelAndView.addObject("jtProjects", projectResults);*/
		String honor = org.getHonorPicture();
		if (honor != null && honor.contains(".")) {
			List<String> honorPictures = Arrays.asList(honor.split(","));
			if (honorPictures.size() > 0)
				modelAndView.addObject("honors", honorPictures);
		}
		return modelAndView;
	}

/*	private void businessHelper(ModelAndView modelAndView, String categoryName,
			List<JtBusinessCategory> jtBusinessCategories, int[] sizes) {
		for (int i = 0; i < jtBusinessCategories.size(); i++) {
			List<JtBusinessProject> projects = jtBusinessService
					.getBusinessProjectByCategoryId(jtBusinessCategories.get(i).getId(), sizes[i], null);
			modelAndView.addObject(categoryName + i, jtBusinessCategories.get(i));
			modelAndView.addObject(categoryName + "List" + i, projects);
		}

	}*/

	public static int differentDaysByMillisecond(Date date1, Date date2) {
		int days = (int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24));
		return days;
	}

	@RequestMapping(value = "/portal/technologyTrading/shopList")
	public ModelAndView shopList(HttpServletRequest request, ModelAndView modelAndView, String id, Integer type) {
		modelAndView.setViewName("/portal/technologyTrading/shopList");
		return modelAndView;
	}

	/*
	 * - * - * type 0-政策 1-新闻 - *
	 */
	@RequestMapping(value = "/portal/news/newsDetail", method = RequestMethod.GET)
	public ModelAndView portalHighTechEvaluateIprInfo(HttpServletRequest request, ModelAndView modelview, Long id,
			Integer type) {
		modelview.setViewName("/portal/news/newsDetail");
		modelview.addObject("type", type);
		if (type == null)
			type = 1;
		if (type == 1) {
			Pagination<NewsPortalList> newsList = newsService.portalNewsList(6, 1, null, 1, null, null, 2);
			News newsDetail = newsService.findNewsDetail(id);
			Object news = null;
			if (newsList != null && newsList.getList().size() > 0)
				news = newsList.getList().get(0);
			if (null != newsDetail) {
				newsDetail.setCreateTimeS(newsDetail.getCreateTime() != null
						? DateFormatUtils.format(newsDetail.getCreateTime(), AFTConstants.MMDDYYYY) : "");
				String summary = newsDetail.getSummary();
				modelview.addObject("hasHighTech",
						summary != null && (summary.indexOf("高新") > -1 || summary.indexOf("高企") > -1));
				modelview.addObject("hasPatent",
						summary != null && (summary.indexOf("专利") > -1 || summary.indexOf("知识产权") > -1));
				modelview.addObject("hasCopyright",
						summary != null && (summary.indexOf("软著") > -1 || summary.indexOf("知识产权") > -1));
				modelview.addObject("hasTechProj",
						summary != null && (summary.indexOf("科技") > -1 || summary.indexOf("项目") > -1));
			}
			@SuppressWarnings("unchecked")
			List<NewsPortalList> la = (List<NewsPortalList>) newsList.getList();
			for (NewsPortalList n : la) {
				String createTimeFormattedDate = n.getCreateTimeFormattedDate();
				n.setDataS(createTimeFormattedDate);
			}
			if (newsDetail.getTitleImg() != null) {
				String[] imgs = newsDetail.getTitleImg().split(",");
				if (imgs[0] == null || imgs[0].length() < 1)
					modelview.addObject("imgs", null);
				else
					modelview.addObject("imgs", imgs[0]);
			}
			modelview.addObject("newsDetail", newsDetail);
			modelview.addObject("newsList", newsList.getList());
			if (news != null)
				modelview.addObject("news", news);

		} else {
			List<PolicyEntity> newsList = achievementService.getIntellectualProperty(6);
			PolicyEntity newsDetail = newsService.getPolicyDetail(id + "");
			if (null != newsDetail) {
				String summary = newsDetail.getSummary();
				modelview.addObject("hasHighTech",
						summary != null && (summary.indexOf("高新") > -1 || summary.indexOf("高企") > -1));
				modelview.addObject("hasPatent",
						summary != null && (summary.indexOf("专利") > -1 || summary.indexOf("知识产权") > -1));
				modelview.addObject("hasCopyright",
						summary != null && (summary.indexOf("软著") > -1 || summary.indexOf("知识产权") > -1));
				modelview.addObject("hasTechProj",
						summary != null && (summary.indexOf("科技") > -1 || summary.indexOf("项目") > -1));
			}
			if (newsDetail.getTitleImg() != null) {
				String[] imgs = newsDetail.getTitleImg().split(",");
				if (imgs[0] == null || imgs[0].length() < 1)
					modelview.addObject("imgs", null);
				else
					modelview.addObject("imgs", imgs[0]);
			}
			modelview.addObject("newsDetail", newsDetail);
			modelview.addObject("newsList", newsList);
			if (newsList != null && newsList.size() > 0)
				modelview.addObject("news", newsList.get(0));
		}
		return modelview;
	}

	/**
	 * 新闻详情列表
	 */
	@RequestMapping(value = "/portal/news/list", method = RequestMethod.GET)
	@ResponseBody
	public Result portalNewsList(Integer type, String pageSize, String pageNo, Integer hot, Integer provinceId,
			String keyword) {
		Result res = new Result();
		Integer pNo = 1, pSize = 4;
		if (StringUtils.isNumeric(pageNo)) {
			pNo = Integer.parseInt(pageNo);
		}
		if (StringUtils.isNumeric(pageSize)) {
			pSize = Integer.parseInt(pageSize);
		}
		res.setData(newsService.portalNewsList(pSize, pNo, type, hot, provinceId, keyword, 2));
		return res;
	}

	/**
	 * 政策列表
	 */
	@RequestMapping(value = "/portal/policy/list", method = RequestMethod.GET)
	@ResponseBody
	public Result policyList(Integer type, String pageSize, String pageNo, Integer hot, Integer provinceId,
			String keyword) {
		Result res = new Result();
		Integer pNo = 1, pSize = 4;
		if (StringUtils.isNumeric(pageNo)) {
			pNo = Integer.parseInt(pageNo);
		}
		if (StringUtils.isNumeric(pageSize)) {
			pSize = Integer.parseInt(pageSize);
		}
		res.setData(policyService.searchPolicy(keyword, 2, null, null, null, pNo, pSize, provinceId));
		return res;
	}

	/**
	 * 全局搜索
	 */
	@RequestMapping(value = "/portal/globalSearch", method = RequestMethod.GET)
	@ResponseBody
	public Result globalSearch(String  name,String keyword,Integer pageSize,Integer pageNo) {
		Result res = new Result();
		res.setData(globalSearchService.globalSearchList(name,pageNo,pageSize));
		return res;
	}
	/**
	 * 手机网站全局搜索
	 */
	@RequestMapping(value = "/api/portal/globalSearch", method = RequestMethod.GET)
	@ResponseBody
	public Result appWebGlobalSearch(String  name,String keyword,Integer pageSize,Integer pageNo) {
		Result res = new Result();
		res.setData(globalSearchService.globalSearchList(name,pageNo,pageSize));
		return res;
	}
	
	/**
	 * 知识产权维权
	 * @param request
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/service/safeguarding", method = RequestMethod.GET)
	public ModelAndView portalServiceSafeguarding(HttpServletRequest request, ModelAndView modelview){
		//获得法律顾问列表数据
		User u = userService.selectByPrimaryKey(TokenManager.getUserId());
		if(null != u&&u.getType()!=null){
			modelview.addObject("userType",u.getType() );
		}
		
		modelview.addObject("slist", userIdentityService.consultantList( null, 1,  4,  null, null, null,  0,  12).getList());
		modelview.setViewName("/portal/service/safeguarding");
		return modelview;
	}
	
	/**
	 * 高企自评
	 * @param request
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/evaluation/evaluate", method = RequestMethod.GET)
	public ModelAndView evaluate(HttpServletRequest request, ModelAndView modelview) {
		modelview.setViewName("/portal/evaluation/evaluate");
		return modelview;
	}
	
	/**
	 * 顾问详情
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/adviser/adviserDetail", method = RequestMethod.GET)
	public ModelAndView adviserDetail(ModelAndView modelview,String id){
		modelview.setViewName("/portal/adviser/adviserDetail");
		ExpertsListBo adviserDetail = userIdentityService.selectExpertsDetail(id);
		adviserDetail.setConsultantTypeName(ConsultantType.getDesc(adviserDetail.getConsultantType()));
		modelview.addObject("adviserDetail", adviserDetail);
		return modelview;
	}
	/**
	 * 顾问列表
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/adviser/adviserList", method = RequestMethod.GET)
	public ModelAndView adviserList(ModelAndView modelview){
		modelview.setViewName("/portal/adviser/adviserList");
		return modelview;
	}
	/**
	 * 顾问首页
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/adviser", method = RequestMethod.GET)
	public ModelAndView portalAdviser(ModelAndView modelview){
		modelview.setViewName("/portal/adviser");
		User u = userService.selectByPrimaryKey(TokenManager.getUserId());
		if(null != u&&u.getType()!=null){
			modelview.addObject("userType",u.getType() );
		}
		return modelview;
	}
	/**
	 * 搜索列表页
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/search", method = RequestMethod.GET)
	public ModelAndView portalSearch(ModelAndView modelview){
		modelview.setViewName("/portal/search");
		return modelview;
	}
	
	/**
	 * 邀请好友
	 * @param modelview
	 * @return
	 */
	@RequestMapping(value = "/portal/invitation", method = RequestMethod.GET)
	public ModelAndView portalInvitation(ModelAndView modelview){
		modelview.setViewName("/portal/invitation");
		return modelview;
	}
	
	/**
	 * 政策 资讯 百科
	 * @param policy
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value="/portal/policyAndNewsList", method = RequestMethod.GET)
	@ResponseBody
	public Result policyAndNewsList(Policy policy, Integer pageNo, Integer pageSize){
		Result res = new Result();
		//如果type是null 查看政策和新闻等的数据
		if(null == policy.getType() || "".equals(policy.getType())){
			res.setData(policyService.searchPolicyAndNewsList(policy, pageNo, pageSize));
		}else if(policy.getType() == 0 || policy.getType() == 99 || policy.getType() == 98 ){//资讯\观点\知产 news表
			Pagination<News> listNews = newsService.listNews(policy.getType(), policy.getTitle(), null, null, null, null, null, pageNo, pageSize, "2", null, null,policy.getProvince());
			@SuppressWarnings("unchecked")
			Iterator<News> iterator = (Iterator<News>) listNews.getList().iterator();
			while (iterator.hasNext()) {
				News news = (News) iterator.next();
				news.setType(1);
				news.setHot(news.getHotspot());//是否热门处理
			}
			res.setData(listNews);
		}else{//政策
			Pagination<PolicyResult> policyList = policyService.searchPolicy(policy.getTitle(), 2, null, null, null, pageNo, pageSize, policy.getProvince());
			@SuppressWarnings("unchecked")
			Iterator<PolicyResult> iterator = (Iterator<PolicyResult>) policyList.getList().iterator();
			while (iterator.hasNext()) {
				PolicyResult policyResult = (PolicyResult) iterator.next();
				policyResult.setType(0);
			}
			res.setData(policyList);
		}
		return res;
	} 
	
	/**
	 * 法律顾问列表
	 * @param modelview
	 * @return
	 */
	@RequestMapping("/portal/service/safeguardingList")
	public ModelAndView safeguardingList(ModelAndView modelview){
		modelview.setViewName("/portal/service/safeguardingList");
		return modelview;
	}
	
	/**
	 * 获得除了指定数据的其他随机法律顾问
	 * @param id
	 * @return
	 */
	@RequestMapping("/portal/service/safeguardingDetail")
	public ModelAndView safeguardingDetail(ModelAndView modelview, String id, Integer size, Integer type){
		List<ExpertsListBo> list = userIdentityService.getRandAdviserByType(id, 4, 4);//其他法律顾问
		ExpertsListBo safeguardingDetail = userIdentityService.selectExpertsDetail(id);//法律顾问
		safeguardingDetail.setConsultantTypeName(ConsultantType.getDesc(safeguardingDetail.getConsultantType()));
		modelview.addObject("sd", safeguardingDetail);
		modelview.addObject("list", list);
		modelview.setViewName("/portal/service/safeguardingDetail");
		return modelview;
	}
	
	/**
	 * 品牌建设
	 * @param modelview
	 * @return
	 */
	@RequestMapping("/portal/service/brandBuild")
	public ModelAndView brandBuild(ModelAndView modelview){
		modelview.addObject("list", jtBusinessService.getProjectByTag("品牌建设", 10));
		modelview.setViewName("/portal/service/brandBuild");
		return modelview;
	}
	/**
	 * 政府扶持
	 * @param modelview
	 * @return
	 */
	@RequestMapping("/portal/service/governmentSupport")
	public ModelAndView governmentSupport(ModelAndView modelview){
		modelview.addObject("list", jtBusinessService.getProjectByTag("政府扶持", 4));
		modelview.setViewName("/portal/service/governmentSupport");
		return modelview;
	}
	/**
	 * 市场开拓
	 * @param modelview
	 * @return
	 */
	@RequestMapping("/portal/service/marketOpen")
	public ModelAndView marketOpen(ModelAndView modelview){
		modelview.addObject("list1", jtBusinessService.getProjectByTag("国际市场开发", 4));
		modelview.addObject("list2", jtBusinessService.getProjectByTag("政府市场采购", 2));
		modelview.addObject("list3", jtBusinessService.getProjectByTag("军工市场采购", 3));
		modelview.setViewName("/portal/service/marketOpen");
		return modelview;
	}
	/**
	 * 财税金融
	 * @param modelview
	 * @return
	 */
	@RequestMapping("/portal/service/taxFinance")
	public ModelAndView taxFinance(ModelAndView modelview){
		modelview.addObject("list", jtBusinessService.getProjectByTag("财税金融", 3));
		modelview.setViewName("/portal/service/taxFinance");
		return modelview;
	}
	
	private List<JtBusinessProject> handleAdvertisement(List<JtBusinessProject> list){
		for (JtBusinessProject jtBusinessProject : list) {
			if(StringUtils.isNotBlank(jtBusinessProject.getAdvertisement())){
				String[] sary = jtBusinessProject.getAdvertisement().split("[#]");
				String str = "";
				int c = sary.length > 4 ? 4: sary.length;
 				for (int i = 0; i < c; i++) {
					str += "<p>" + sary[i] + "</p>";
				}
 				jtBusinessProject.setAdvertisement(str);
			}
		}
		return list;
	}
	@RequestMapping("/portal/assessment")
	public ModelAndView assessment(ModelAndView modelAndView){
		modelAndView.setViewName("/portal/assessment");
		return modelAndView;
	}
	
}
