package cn.com.countrygarden.bi.main.controller.canteen;
import cn.com.countrygarden.bi.main.controller.BaseController;
import cn.com.countrygarden.bi.main.core.Response;
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.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import cn.com.countrygarden.bi.main.model.canteen.CanteenInvestigate;
import cn.com.countrygarden.bi.main.model.review.ReviewQuestionnaire;
import cn.com.countrygarden.bi.main.dao.canteen.CanteenInvestigateMapper;
import cn.com.countrygarden.bi.main.dto.*;
import cn.com.countrygarden.bi.main.service.canteen.CanteenInvestigateService;
import cn.com.countrygarden.bi.main.service.dup.ContractStatisticalService;

/**
 * 调查表-控制层实现
 *
 * @author 吕伟峰
 * @email www.justintoforest@gamail.com
 * @url 
 * @date 2018-08-13
 */
@RestController("CanteenInvestigateController")
@RequestMapping("/api/canteenInvestigate")
public class CanteenInvestigateController extends BaseController{
    @Autowired
    private CanteenInvestigateService canteenInvestigateService;
    
    @Autowired
	 private ContractStatisticalService contractStatisticalService;
    
	@Value("${qcode.appUrl}")
	private String qCodeUrl;

    //问卷管理列表
    @GetMapping(value = "/getList", produces = "application/json;charset=utf-8")
    public Result getList(@RequestParam(value = "name", required = false) String name,
    		           @RequestParam(value = "investigationmanagementId", required = false) int investigationmanagementId,
                       @RequestParam(value = "size", required = false, defaultValue = "10") int size,
                       @RequestParam(value = "page", required = false, defaultValue = "1") int page,
                       HttpServletRequest request){
    	
    	
    	boolean hasRole = hasRole("canteenAdmin");
        return  canteenInvestigateService.canteenrqdtolist(name, page, size, hasRole, getAccessToken().getUserCode(), investigationmanagementId);
    }
    
    //发起调查
    @PostMapping(value = "/addcanteenApp")
    public Result addcanteenApp(CanteenInvestigate canteenInvestigate,
                      HttpServletRequest request){
    	
        return  canteenInvestigateService.addcantapp(canteenInvestigate,qCodeUrl,getAccessToken(request));
    }
    
    //查询区域经理
    @GetMapping(value = "/cannquOrderCoder", produces = "application/json;charset=utf-8")
    public Result cannquOrderCoder(@RequestParam(value="areaId",required=true)String areaId,HttpServletRequest request) {
    	    
    	List<ContractStatisticalarpojnameDTO> areaquname=contractStatisticalService.areaquname(areaId);
    	    	
    	 return Response.response(areaquname);
    }
    
  //查询项目经理
    @GetMapping(value = "/cannxiangOrderCoder", produces = "application/json;charset=utf-8")
    public Result cannxiangOrderCoder(@RequestParam(value="projectId",required=true)Integer projectId,HttpServletRequest request) {
    	    
    	List<ContractStatisticalarpojnameDTO> projectname=contractStatisticalService.projectname(projectId);
    	    	
    	 return Response.response(projectname);
    }
    
    // 调查列表canteenInvestigationlist
 	@GetMapping(value = "/canteenInvestigationlist", produces = "application/json;charset=utf-8")
 	public Result canteenInvestigationlist(canteenInvestigationliebiaoDTO canteentionliebiaoDTO,@RequestParam(value = "size", required = false, defaultValue = "10") int size,
 			@RequestParam(value = "page", required = false, defaultValue = "1") int page, HttpServletRequest request) {

 		boolean hasRole=hasRole("canteenAdmin");
 				
 		
 		return canteenInvestigateService.canteenInvestigationlist(canteentionliebiaoDTO,page, size,hasRole,getAccessToken().getUserCode());
 	}
 	
 	//查看二维码
    @GetMapping(value = "/getdeid", produces = "application/json;charset=utf-8")
    public Result getdeid(canteenInvestigationliebiaoDTO canteentionliebiaoDTO,
                       HttpServletRequest request){
    	
    	
        return  canteenInvestigateService.getdeid(canteentionliebiaoDTO,qCodeUrl);
    }
 	
 	//查询身份
 	@GetMapping(value = "/bdpsndoc", produces = "application/json;charset=utf-8")
 	public Result bdpsndoc( @RequestParam(value="bdid",required=true)String bdid,
 			HttpServletRequest request) {
 		 			
 		return  canteenInvestigateService.bdpsndoc(bdid);
 	}
 	
 
 	
 	//答题界面数据
 	@GetMapping(value="/getcantequestionnaireaca",produces = "application/json;charset=utf-8")
 	public Result cantequestionnaireaca(@RequestParam int questionnaireId,
 			@RequestParam int projectid,@RequestParam int canteeninsdid,
 			@RequestParam int investigatagementid) {
 			    	
 			    
 	return canteenInvestigateService.cantequestionnaireaca(questionnaireId,projectid,canteeninsdid,investigatagementid);
 	}
 	
 	
    
    @GetMapping(value = "/list", produces = "application/json;charset=utf-8")
    public Result list(CanteenInvestigate canteenInvestigate,
                       @RequestParam(value = "size", required = false, defaultValue = "10") int size,
                       @RequestParam(value = "page", required = false, defaultValue = "1") int page,
                       HttpServletRequest request){
        return  canteenInvestigateService.queryPageList(canteenInvestigate,page,size);
    }

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

    @PostMapping(value = "/add")
    public Result add(CanteenInvestigate canteenInvestigate,
                      HttpServletRequest request){
        return  canteenInvestigateService.add(canteenInvestigate,getAccessToken(request));
    }

    @PutMapping(value = "/edit")
    public Result edit(CanteenInvestigate canteenInvestigate, HttpServletRequest request){
        return  canteenInvestigateService.edit(canteenInvestigate,getAccessToken(request));
    }
    
    //结束调查
    @PutMapping(value = "/canteenInvestigationedit")
    public Result canteenInvestigationedit(CanteenInvestigate canteenInvestigate, HttpServletRequest request){
        return  canteenInvestigateService.canteenInvestigationedit(canteenInvestigate,getAccessToken(request));
    }
    
    //开始调查
    @PutMapping(value = "/canteenInvestigationgokai")
    public Result canteenInvestigationgokai(CanteenInvestigate canteenInvestigate, HttpServletRequest request){
        return  canteenInvestigateService.canteenInvestigationgokai(canteenInvestigate,getAccessToken(request));
    }

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


}