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.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import cn.com.countrygarden.bi.main.model.review.ReviewQuestionnaire;
import cn.com.countrygarden.bi.main.model.review.ReviewQuestionnaireProblem;
import cn.com.countrygarden.bi.main.dto.ReviewQuestionnaireEditVo;
import cn.com.countrygarden.bi.main.dto.ReviewQuestionnaireProblemEditVo;
import cn.com.countrygarden.bi.main.dto.ReviewQuestionnaireProblemVo;
import cn.com.countrygarden.bi.main.service.AccessTokenService;
import javax.servlet.http.HttpServletRequest;
import cn.com.countrygarden.bi.main.dao.review.ReviewQuestionnaireProblemMapper;
import cn.com.countrygarden.bi.main.service.review.ReviewQuestionnaireProblemService;
import cn.com.countrygarden.bi.main.service.review.ReviewQuestionnaireService;

/**
 * 问题表-业务逻辑层实现
 * 
 * @author 汤婷
 * @email www.justintoforest@gamail.com
 * @url
 * @date 2018-06-25
 */
@RestController("ReviewQuestionnaireProblemController")
@RequestMapping("/api/reviewQuestionnaireProblem")
public class ReviewQuestionnaireProblemController extends BaseController {
	@Autowired
	private ReviewQuestionnaireProblemService reviewQuestionnaireProblemService;

	@Autowired
	private AccessTokenService accessTokenService;

	@Autowired
	private ReviewQuestionnaireService reviewQuestionnaireService;
	

	
    //添加问卷前返回的数据
	@GetMapping(value = "/problemTypeAndProblemClassList", produces = "application/json;charset=utf-8")
	public Result queryProblemTypeAndProblemClassList(
			@RequestParam(value = "investigationmanagementId") int investigationmanagementId) {
		return reviewQuestionnaireProblemService.queryProblemTypeAndProblemClass(investigationmanagementId);
	}

	// 编辑问题
	@PutMapping(value = "/edit")
	public Result edit(ReviewQuestionnaireEditVo reviewQuestionnaireEditVo,
			@RequestParam(value = "str", required = false) String str,
			@RequestParam(value = "qclassAryNew") String qclassAryNew, HttpServletRequest request)
			throws ParseException {

		return reviewQuestionnaireProblemService.edit(reviewQuestionnaireEditVo, str, qclassAryNew,
				getAccessToken(request));
	}

	@PostMapping(value = "/add")
	public Result add(ReviewQuestionnaire reviewQuestionnaire,
			@RequestParam(value = "str", required = false) String str,
			@RequestParam(value = "qclassAryNew") String qclassAryNew, HttpServletRequest request) {

		return reviewQuestionnaireProblemService.add(reviewQuestionnaire, str, qclassAryNew, getAccessToken(request));

	}

	@GetMapping(value = "/list", produces = "application/json;charset=utf-8")
	public Result list(ReviewQuestionnaireProblem reviewQuestionnaireProblem,
			@RequestParam(value = "size", required = false, defaultValue = "10") int size,
			@RequestParam(value = "page", required = false, defaultValue = "1") int page, HttpServletRequest request) {
		return reviewQuestionnaireProblemService.queryPageList(reviewQuestionnaireProblem, page, size);
	}

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

	@DeleteMapping(value = "/del")
	public Result del(@RequestParam(value = "id", required = true) Integer id) {
		return reviewQuestionnaireProblemService.del(id);
	}

}