package com.zcloud.controller.questionnaire;

import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.PageData;
import com.zcloud.service.questionnaire.SurveyService;
import com.zcloud.util.DateUtil;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 说明：习题管理
 * 作者：luoxiaobao
 * 时间：2021-07-03
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/app/survey")
public class AppSurveyController extends BaseController {



	@Autowired
	private SurveyService surveyService;
//	@Autowired
//	private SurveycorpinfoService surveycorpinfoService;


//	/**通过试卷ID获取阶段试卷相关数据（试卷、试卷试题）
//	 * @param
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/getSurvey")
//	@ResponseBody
////	@LogAnno(menuType= "手机",menuServer= "阶段考试试卷表",instructionsOperate = "阶段考试试卷表",instructionsType = "通过试卷ID获取阶段试卷相关数据")
//	public Object getExam() throws Exception{
//		Map<String,Object> map = new HashMap<String,Object>();
//		String errInfo = "success";
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		pd = surveyService.getSurvey(pd);	//通过试卷ID获取数据
//		map.put("pd", pd);
//		map.put("result", errInfo);
//		return map;
//	}

	/**去修改页面获取数据
	 * @param
	 * @throws Exceptionexists
	 */
	@RequestMapping(value="/getQuestions")
//	// @RequiresPermissions("survey:edit")
	@ResponseBody
	public Object getQuestions() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd = surveyService.findById(pd);
		map.put("pd",pd);
		map.put("questions", surveyService.getQuestions(pd));
		map.put("result", errInfo);
		return map;
	}
	/**去修改页面获取数据
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/goEdit")
//	// @RequiresPermissions("survey:edit")
	@ResponseBody
	public Object goEdit() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		Date d = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
		String dateNowStr = sdf.format(d);
		System.out.println("格式化后的日期：" + dateNowStr);
		pd.put("dateNowStr",dateNowStr);
		pd = surveyService.findBycorpinfoId(pd);	//根据ID读取
		map.put("pd", pd);
		map.put("result", errInfo);
		return map;
	}

	/**修改
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/getstate")
	// @RequiresPermissions( value = {"question:edit" , "courseware:edit"}, logical = Logical.OR)
	@ResponseBody
	public Object getstate() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
//		pd.put("OPERATOR", Jurisdiction.getUsername());	//修改人
		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//修改时间
		surveyService.getstate(pd);
		map.put("pd", pd);
		map.put("result", errInfo);
		return map;
	}

}
