package com.jeesite.modules.admin.wenjuan.web;


import com.jeesite.modules.admin.wenjuan.entity.AdminQuestionItem;
import com.jeesite.modules.admin.wenjuan.entity.AdminQuestionOption;
import com.jeesite.modules.admin.wenjuan.entity.AdminQuestionnaireRecord;
import com.jeesite.modules.admin.wenjuan.entity.AdminQuestionnaireSurvey;
import com.jeesite.modules.admin.wenjuan.service.AdminQuestionItemService;
import com.jeesite.modules.admin.wenjuan.service.AdminQuestionOptionService;
import com.jeesite.modules.admin.wenjuan.service.AdminQuestionnaireSurveyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;


/**
 * 问卷调查提交接口
 */
@Controller
@RequestMapping(value = "${adminPath}/admin/adminQuestionSubmit")
public class AdminQuestionSubmitController {

    @Autowired
    private AdminQuestionnaireSurveyService adminQuestionnaireSurveyService;

    @Autowired
    private AdminQuestionItemService adminQuestionItemService;

    @Autowired
    private AdminQuestionOptionService adminQuestionOptionService;

    /**
     * 查询列表   跳转的页面
     */
    /*@RequiresPermissions("admin:adminQuestionnaireRecord:view")*/
    @RequestMapping(value = {"list", ""})
    public String list(AdminQuestionnaireRecord adminQuestionnaireRecord, Model model) {
        model.addAttribute("adminQuestionnaireRecord", adminQuestionnaireRecord);
        return "modules/admin/wenjuan/......";
    }


    /**
     * 查询列表   跳转的页面
     */
    /*@RequiresPermissions("admin:adminQuestionnaireRecord:view")*/
    @RequestMapping(value = {"list1", ""})
//    @ResponseBody
    public String list1(String questionnaireSurveyId, Model model) {

        //根据问卷调查ID--->查询问卷调查项表
        List<AdminQuestionItem> adminQuestionItems = adminQuestionItemService.selectQItemList(questionnaireSurveyId);


        for (AdminQuestionItem adminQuestionItem : adminQuestionItems) {
            //根据问卷调查项ID --> 查询 问卷调查选项表
            List<AdminQuestionOption> adminQuestionOption = adminQuestionOptionService.selectQOptionList(adminQuestionItem.getQuestionitemId());
            adminQuestionItem.setAdminQuestionOptionList(adminQuestionOption);
        }

        AdminQuestionnaireSurvey adminQuestionnaireSurvey = new AdminQuestionnaireSurvey();
        adminQuestionnaireSurvey.setId(questionnaireSurveyId);
        //根据根据问卷调查ID  查询问卷调查信息
        AdminQuestionnaireSurvey adminQuestionnaireSurvey1 = adminQuestionnaireSurveyService.get(adminQuestionnaireSurvey);

        adminQuestionnaireSurvey1.setAdminQuestionItemList(adminQuestionItems);

        model.addAttribute("adminQuestionnaireSurvey1", adminQuestionnaireSurvey1);

//        return adminQuestionnaireSurvey1;

        return "modules/admin/wenjuan/demo";
    }
}
