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.dto.ReviewInvestigationVo;
import cn.com.countrygarden.bi.main.service.review.ReviewInvestigatedService;
import cn.com.countrygarden.bi.main.service.review.ReviewJudgeService;

/**
 * 被调查人-业务逻辑层实现
 *
 * @author 汤婷
 * @email www.justintoforest@gamail.com
 * @url 
 * @date 2018-06-25
 */
@RestController("ReviewInvestigatedController")
@RequestMapping("/api/reviewInvestigated")
public class ReviewInvestigatedController extends BaseController {
	@Autowired
	private ReviewInvestigatedService reviewInvestigatedService;

	
	@Autowired
	private ReviewJudgeService reviewjudgeService;
	
	@PostMapping(value = "/resendSms")
	public Result resendSms(@RequestParam(value = "investigatedId", required = true) int investigatedId,
			@RequestParam(value = "investigatedName", required = true) String investigatedName,
			@RequestParam(value="questionnaireId", required = true)int questionnaireId,
			@RequestParam(value="questionnaireName", required = true)String questionnaireName
			) {
		
		return reviewInvestigatedService.resendSms(investigatedId, investigatedName,questionnaireId,questionnaireName);
	}
	
	// 调查列表
	@GetMapping(value = "/investigationVoList", produces = "application/json;charset=utf-8")
	public Result InvestigationVoList(ReviewInvestigationVo reviewinvesti,@RequestParam(value = "size", required = false, defaultValue = "10") int size,
			@RequestParam(value = "page", required = false, defaultValue = "1") int page, HttpServletRequest request) {

		boolean haseole=hasRole("reviewAdmin");
		return reviewInvestigatedService.selectInvestigationVoList(reviewinvesti,page, size,haseole,getAccessToken().getUserCode());
	}

	@GetMapping(value = "/one", produces = "application/json;charset=utf-8")
	public Result queryById(@RequestParam(value = "id", required = true) Integer id, HttpServletRequest request) {
		return reviewInvestigatedService.queryById(id);
	}
	
  @PostMapping(value = "/add")
  public Result add(ReviewInvestigated reviewInvestigated,String upJsonStr,String sameJsonStr,String downJsonStr 
                    ,HttpServletRequest request){
  	
      return  reviewInvestigatedService.add(reviewInvestigated,upJsonStr,sameJsonStr,downJsonStr,getAccessToken(request));
  }

	@PutMapping(value = "/edit")
	public Result edit(ReviewInvestigated reviewInvestigated, HttpServletRequest request) {
		return reviewInvestigatedService.edit(reviewInvestigated, getAccessToken(request));
	}

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

}