package com.goafanti.portal.controller;



import java.text.ParseException;

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.business.service.BusinessProjectService;
import com.goafanti.business.service.BusinessVarietiesService;
import com.goafanti.common.bo.Result;
import com.goafanti.common.constant.ErrorConstants;
import com.goafanti.common.controller.BaseController;
import com.goafanti.common.utils.StringUtils;
import com.goafanti.core.shiro.token.TokenManager;
import com.goafanti.order.service.OrderService;
import com.goafanti.user.service.UserIdentityService;

@RestController
@RequestMapping(value = "/portal/app/services")
public class PortalServicesController extends BaseController {
	@Resource
	BusinessProjectService	businessProjectService;
	@Resource
	UserIdentityService	userIdentityService;
	@Resource
	BusinessVarietiesService	businessVarietiesService;
	@Resource
	OrderService	orderService;





	/**
	 * 推荐列表
	 */
	@RequestMapping(value = "/recommend", method = RequestMethod.GET)
	public Result recommendProjectList(Integer pNo,Integer pSize) {
		Result res = new Result();
		res.setData(businessProjectService.portalRecommendList( pNo, pSize));
		return res;
	}

	/**
	 * 一对一
	 */
	@RequestMapping(value = "/consultant", method = RequestMethod.GET)
	public Result consultantList(Integer pNo,Integer pSize) {
		Result res = new Result();
		res.setData(userIdentityService.portalConsultantList( pNo, pSize));
		return res;
	}

	/**
	 * 获取初级品类
	 */
	@RequestMapping(value = "/portal/services/varieties", method = RequestMethod.GET)
	public Result getVarieties() {
		Result res = new Result();
		res.setData(businessVarietiesService.portalVarieties());
		return res;
	}

	/**
	 * 获取品类下的项目
	 */
	@RequestMapping(value = "/businessProject", method = RequestMethod.GET)
	public Result getBusinessProject(String id,Integer pNo,Integer pSize) {
		Result res = new Result();
		if (StringUtils.isBlank(id)) {
			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"品类必须指定","品类"));
			return res;
		}
		res.setData(businessProjectService.portalBusinessProject(id,pNo, pSize));
		return res;
	}
	/**
	 * 项目关注功能
	 */
	@RequestMapping(value = "/interest", method = RequestMethod.GET)
	public Result interest(String objectId,String interest) {
		Result res = new Result();
		if (null==objectId) {
			res.getError().add(buildError( "项目必须指定", "项目必须指定"));
			return res;
		}
		if (null==interest) {
			res.getError().add(buildError( "关注参数错误", "关注参数错误"));
			return res;
		}
		String uid=null;
		if (StringUtils.isNotBlank(TokenManager.getUserId())) {
			uid=TokenManager.getUserId();
		}
		//uid="904d1d5a-30f6-4813-b632-1ff07a1ad317";
		if (StringUtils.isBlank(uid)) {
			res.getError().add(buildError( "用户未登录", "用户未登录"));
			return res;
		}
		res.setData(businessVarietiesService.saveInterest( uid, objectId,interest));
		return res;
	}







}
