package com.goafanti.app.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.goafanti.achievement.service.AchievementInterestService;
import com.goafanti.achievement.service.AchievementService;
import com.goafanti.common.bo.Result;
import com.goafanti.common.controller.BaseApiController;
import com.goafanti.common.utils.StringUtils;
import com.goafanti.demand.service.DemandService;
import com.goafanti.news.service.NewsService;
import com.goafanti.user.service.UserIdentityService;

@RestController
@RequestMapping(path = "/open/app/discovery", method = RequestMethod.GET)
public class OpenAppDiscoveryController extends BaseApiController {
	@Resource
	private AchievementService	achievementService;
	@Resource
	private DemandService	demandService;
	@Resource
	private UserIdentityService	userIdentityService;
	@Resource
	private AchievementInterestService	achievementInterestService;
	@Resource
	private NewsService newsService;
	
	/**
	 * 成果列表
	 */
	@RequestMapping(value = "/achievementList", method = RequestMethod.GET)
	private Result achievementList(Integer auditStatus, Integer serialNumber, String name, String keyword,Integer dataCategory,Integer category,
			Integer ownerType,Integer fieldA, Integer status, String releaseDateStartDate, String releaseDateEndDate,
			Integer releaseStatus,String ownerId,String pageNo, String pageSize) {
		Result res = new Result();
		Integer pNo = 1;
		Integer pSize = 10;
		if (StringUtils.isNumeric(pageSize)) {
			pSize = Integer.parseInt(pageSize);
		}

		if (StringUtils.isNumeric(pageNo)) {
			pNo = Integer.parseInt(pageNo);
		}
		res.setData(achievementService.listAppUserAchievement(auditStatus, serialNumber, name, keyword,  dataCategory,category,
				ownerType,  status, releaseDateStartDate, releaseDateEndDate, releaseStatus,ownerId, fieldA, pNo, pSize));
		return res;
	}
	
	
	
	/**
	 * 需求列表
	 */
	@RequestMapping(value = "/demandList", method = RequestMethod.GET)
	public Result demandList(Integer auditStatus, Integer serialNumber, String name, String keyword, Integer demandType,Integer industryCategoryA,
			String validityPeriodStartDate, String validityPeriodEndDate, Integer status, Integer releaseStatus,
			String releaseDateStartDate, String releaseDateEndDate, String employerId,String pageNo, String pageSize) {
		Result res = new Result();
		Integer pNo = 1;
		Integer pSize = 10;
		if (StringUtils.isNumeric(pageSize)) {
			pSize = Integer.parseInt(pageSize);
		}

		if (StringUtils.isNumeric(pageNo)) {
			pNo = Integer.parseInt(pageNo);
		}
		res.setData(demandService.listAppDemand(auditStatus, serialNumber, name, keyword, demandType, industryCategoryA,
				validityPeriodStartDate, validityPeriodEndDate, status, releaseStatus, releaseDateStartDate,
				releaseDateEndDate, employerId, pNo, pSize));
		return res;
	}
	
	/**
	 * 行业分类列表
	 * 
	 */
	@RequestMapping(value = "/industryList", method = RequestMethod.GET)
	public Result industryList() {
		Result res = new Result();
		res.setData(userIdentityService.industryList());
		return res;
	}
	
	/**
	 * 专家领域分类列表
	 * 
	 */
	@RequestMapping(value = "/domainList", method = RequestMethod.GET)
	public Result domainList() {
		Result res = new Result();
		res.setData(userIdentityService.domainList());
		return res;
	}
	/**
	 * 专家列表
	 */
	@RequestMapping(value = "/expertsList", method = RequestMethod.GET)
	public Result expertsList(String name,String industry, Integer pNo, Integer pSize) {
		Result res = new Result();
		res.setData(userIdentityService.expertsList(name,industry,pNo,pSize));
		return res;
	}
	
	/**
	 * 发现页面广告
	 */
	@RequestMapping(value = "/advertising", method = RequestMethod.GET)
	public Result advertising() {
		Result res = new Result();
		res.setData(userIdentityService.advertising());
		return res;
	}
	/**
	 * 政策列表
	 */
	@RequestMapping(value = "/listNews", method = RequestMethod.GET)
	public Result appListNews(String param,Integer pNo,Integer pSize) {
		Result res = new Result();
		res.setData(newsService.appListNews( param ,pNo, pSize));
		return res;
		
	}
	
	/**
	 * 政策详情
	 */
	@RequestMapping(value = "/newsDetail", method = RequestMethod.GET)
	public Result expertsDetail(long id) {
		Result res = new Result();
		res.setData(newsService.findNewsDetail( id));
		return res;
	}
}
