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.*;
import com.jeeplus.modules.sg.budgetSpectaculars.service.ProjectCourseService;
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-22 17:24
 **/
@Controller
@RequestMapping(value = "${adminPath}/projectCourseControl/projectCourseControl")
public class ProjectCourseControlController extends BaseController {
    @Autowired
    private ProjectCourseService service;

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

    /**
     * 过程管控页 列表页面
     * @param projectBasicsInfo
     * @param model
     * @return
     */
    @RequiresPermissions("projectCourseControl:projectCourseControl:list")
    @RequestMapping(value = "list")
    public String list(ProjectCourseControlInfo projectBasicsInfo, Model model) {
        model.addAttribute("projectBasicsInfo", projectBasicsInfo);
        return "modules/sg/project/projectCourse/projectCourseList";
    }

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

}
