package cn.com.countrygarden.bi.main.controller.review;
import cn.com.countrygarden.bi.main.controller.BaseController;
import cn.com.countrygarden.bi.main.core.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import cn.com.countrygarden.bi.main.model.review.ReviewInvestigated;
import cn.com.countrygarden.bi.main.model.review.ReviewQuestionnaire;
import cn.com.countrygarden.bi.main.dao.review.ReviewQuestionnaireMapper;
import cn.com.countrygarden.bi.main.service.review.ReviewInvestigatedService;
import cn.com.countrygarden.bi.main.service.review.ReviewQuestionnaireService;

/**
 * 问卷表-业务逻辑层实现
 *
 * @author 汤婷
 * @email www.justintoforest@gamail.com
 * @date 2018-06-25
 */
@RestController("ReviewQuestionnaireController")
@RequestMapping("/api/reviewQuestionnaire")
public class ReviewQuestionnaireController extends BaseController {
	@Autowired
	private ReviewQuestionnaireService reviewQuestionnaireService;

	@Autowired
	private ReviewInvestigatedService reviewInvestigatedService;
    
	  //答题界面数据
		@GetMapping(value="/getreviewquestionnaireanswer",produces = "application/json;charset=utf-8")
		 public Result investigatedId(@RequestParam int  investigatedId,@RequestParam int reviewJudgeId,@RequestParam int questionnaireId
		    		) {
		    	
		    
		    return reviewInvestigatedService.selectAnswerBeforeVo(investigatedId,reviewJudgeId,questionnaireId);
			}

    
    //问卷及问题逻辑删除
	@GetMapping(value = "/questionnaireParamVoOne", produces = "application/json;charset=utf-8")
	public Result questionnaireParamVoOne(@RequestParam(value = "id", required = true) Integer id,
			HttpServletRequest request) {
		return reviewQuestionnaireService.questionnaireParamVoOne(id);
	}

	// 问卷编辑前返回的数据
	@GetMapping(value = "/questionnaireAndproblem", produces = "application/json;charset=utf-8")
	public Result queryQuestionnaireAndproblemOne(@RequestParam(value = "id", required = true) Integer id,
			HttpServletRequest request) {

		return reviewQuestionnaireService.queryQuestionnaireAndproblem(id);
	}

	@GetMapping(value = "/ReviewQuestionnairelistVo", produces = "application/json;charset=utf-8")
	public Result list(@RequestParam(value = "name", required = false) String name,
			@RequestParam(value = "size", required = false, defaultValue = "10") int size,
			@RequestParam(value = "page", required = false, defaultValue = "1") int page, 
			@RequestParam(value = "investigationmanagementId", required = false) int investigationmanagementId,
			HttpServletRequest request) {
		
		boolean hasRole = hasRole("reviewAdmin");
return reviewQuestionnaireService.ReviewQuestionnairelistVo(name, page, size,hasRole,getAccessToken().getUserCode(),investigationmanagementId);
		
	}

	

	
    @DeleteMapping(value="/del")
    public Result del(@RequestParam(value = "id", required = true)Integer id){
        return  reviewQuestionnaireService.del(id);
    }
    
	@GetMapping(value = "/one", produces = "application/json;charset=utf-8")
	public Result queryById(@RequestParam(value = "id", required = true) Integer id, HttpServletRequest request) {
		return reviewQuestionnaireService.queryById(id);
	}

	@PostMapping(value = "/add")
	public Result add(ReviewQuestionnaire reviewQuestionnaire, HttpServletRequest request) {
		return reviewQuestionnaireService.add(reviewQuestionnaire, getAccessToken(request));
	
	}

	@PutMapping(value = "/edit")
	public Result edit(ReviewQuestionnaire reviewQuestionnaire, HttpServletRequest request) {
		return reviewQuestionnaireService.edit(reviewQuestionnaire, getAccessToken(request));
	}



}
