package com.goafanti.sc.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.common.bo.Result;
import com.goafanti.common.constant.ErrorConstants;
import com.goafanti.common.controller.CertifyApiController;

import com.goafanti.common.utils.StringUtils;
import com.goafanti.sc.bo.inputAchievement;
import com.goafanti.sc.service.ScAchievementService;

@RestController
@RequestMapping(value = "/open/api")
public class ScAchievementApiController extends CertifyApiController {
	@Resource
    private ScAchievementService		scachievementService;
    
    /**
     * 添加成果列表
     */
    @RequestMapping(value = "/achievements", method = RequestMethod.POST)
    private Result achievements (inputAchievement a ) {
        Result res = new Result();
        if (StringUtils.isBlank(a.getName())) {
        	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果"));
             return res;
		}
        if (StringUtils.isBlank(a.getIntroduce())) {
       	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到介绍", "介绍"));
            return res;
		}
        if (null==a.getIndustry()) {
       	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到行业", "行业"));
            return res;
		}
        if (StringUtils.isBlank(a.getOwnerName())) {
       	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果所有人", "成果所有人"));
            return res;
		}
        if (StringUtils.isBlank(a.getPublisherName())) {
          	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到负责人", "负责人"));
               return res;
   		}
        if (StringUtils.isBlank(a.getTelephone())) {
          	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到负责人联系电话", "负责人联系电话"));
               return res;
   		}
       res.setData(scachievementService.addAchievements(a));
       return res;
    }
    
    /**
     * 成果列表
     */
    @RequestMapping(value = "/achievementList", method = RequestMethod.GET)
    private Result achievementList(String ownerName,String patentNumber,String name,Integer pageSize,Integer pageNo) {
        Result res = new Result();
       res.setData(scachievementService.listAchievement(ownerName,patentNumber,name,pageSize,pageNo));
       return res;
    }
   /**
    * 删除成果
    */
    @RequestMapping(value = "/delectAchievement", method = RequestMethod.GET)
    private Result delectAchievement(String id){
    	Result res = new Result();
    	if (StringUtils.isBlank(id)) {
         	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果", "成果ID"));
              return res;
  		}
    	 res.setData(scachievementService.delectachievement(id));
    	 return res;
    }
    /**
     * 修改成果
     */
     @RequestMapping(value = "/updateAchievement", method = RequestMethod.POST)
     private Result updateAchievement(inputAchievement a){
     	Result res = new Result();
     	 if (StringUtils.isBlank(a.getName())) {
        	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "名称"));
             return res;
		}
        if (StringUtils.isBlank(a.getIntroduce())) {
       	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到介绍", "介绍"));
            return res;
		}
        if (null==a.getIndustry()) {
       	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到行业", "行业"));
            return res;
		}
        if (StringUtils.isBlank(a.getOwnerName())) {
       	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果所有人", "成果所有人"));
            return res;
		}
        if (StringUtils.isBlank(a.getPublisherName())) {
          	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到负责人", "负责人"));
               return res;
   		}
        if (StringUtils.isBlank(a.getTelephone())) {
          	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到负责人联系电话", "负责人联系电话"));
               return res;
   		}
     	 res.setData(scachievementService.updateAchievement(a));
     	 return res;
     }
     /**
      * 成果详情
      */
      @RequestMapping(value = "/AchievementDetails", method = RequestMethod.GET)
      private Result AchievementDetails(String id){
      	Result res = new Result();
      	if (StringUtils.isBlank(id)) {
           	 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果", "成果ID"));
                return res;
    		}
      	 res.setData(scachievementService.AchievementDetails(id));
      	 return res;
      }
}