package com.jeeplus.modules.sg.budgetSpectaculars.web;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.sg.budgetSpectaculars.entity.PostEvaluationInfo;
import com.jeeplus.modules.sg.budgetSpectaculars.service.ProjectPostEvaluationService;
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.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 后评价显示表Controller
 * @author: 徐滕
 * @create: 2021-09-24 09:26
 **/
@Controller
@RequestMapping(value = "${adminPath}/projectPostEvaluation/projectPostEvaluation")
public class ProjectPostEvaluationController extends BaseController {
    @Autowired
    private ProjectPostEvaluationService service;

    @ModelAttribute
    public PostEvaluationInfo get(@RequestParam(required=false) String id) {
        PostEvaluationInfo entity = null;
        if (StringUtils.isNotBlank(id)){
            entity = service.get(id);
        }
        if (entity == null){
            entity = new PostEvaluationInfo();
        }
        return entity;
    }

    /**
     * 后评价显示表 列表页面
     * @param projectBasicsInfo
     * @param model
     * @return
     */
    @RequiresPermissions("projectPostEvaluation:projectPostEvaluation:list")
    @RequestMapping(value = "list")
    public String list(PostEvaluationInfo projectBasicsInfo, Model model) {
        model.addAttribute("projectBasicsInfo", projectBasicsInfo);
        return "modules/sg/project/postEvaluation/projectPostEvaluationList";
    }

    /**
     * 基础底表展示信息 列表数据
     * @param projectBasicsInfo
     * @param request
     * @param response
     * @param model
     * @return
     */
    @ResponseBody
    @RequiresPermissions("projectPostEvaluation:projectPostEvaluation:list")
    @RequestMapping(value = "data")
    public Map<String, Object> data(PostEvaluationInfo projectBasicsInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<PostEvaluationInfo> page = service.findPage(new Page<PostEvaluationInfo>(request, response), projectBasicsInfo);
        return getBootstrapData(page);
    }

}
