package com.ruoyi.web.controller.baseinfo;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.baseinfo.domain.BaseGroupInfo;
import com.ruoyi.baseinfo.service.IBaseGroupInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班组基础信息Controller
 * 
 * @author CasearBao
 * @date 2020-10-21
 */
@Controller
@RequestMapping("/baseinfo/groupinfo")
public class BaseGroupInfoController extends BaseController
{
    private String prefix = "baseinfo/groupinfo";

    @Autowired
    private IBaseGroupInfoService baseGroupInfoService;

    @RequiresPermissions("baseinfo:groupinfo:view")
    @GetMapping()
    public String groupinfo()
    {
        return prefix + "/groupinfo";
    }

    /**
     * 查询班组基础信息列表
     */
    @RequiresPermissions("baseinfo:groupinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseGroupInfo baseGroupInfo)
    {
        startPage();
        List<BaseGroupInfo> list = baseGroupInfoService.selectBaseGroupInfoList(baseGroupInfo);
        return getDataTable(list);
    }

    /**
     * 导出班组基础信息列表
     */
    @RequiresPermissions("baseinfo:groupinfo:export")
    @Log(title = "班组基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseGroupInfo baseGroupInfo)
    {
        List<BaseGroupInfo> list = baseGroupInfoService.selectBaseGroupInfoList(baseGroupInfo);
        ExcelUtil<BaseGroupInfo> util = new ExcelUtil<BaseGroupInfo>(BaseGroupInfo.class);
        return util.exportExcel(list, "groupinfo");
    }

    /**
     * 新增班组基础信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存班组基础信息
     */
    @RequiresPermissions("baseinfo:groupinfo:add")
    @Log(title = "班组基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseGroupInfo baseGroupInfo)
    {
        return toAjax(baseGroupInfoService.insertBaseGroupInfo(baseGroupInfo));
    }

    /**
     * 修改班组基础信息
     */
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap)
    {
        BaseGroupInfo baseGroupInfo = baseGroupInfoService.selectBaseGroupInfoById(objid);
        mmap.put("baseGroupInfo", baseGroupInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存班组基础信息
     */
    @RequiresPermissions("baseinfo:groupinfo:edit")
    @Log(title = "班组基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseGroupInfo baseGroupInfo)
    {
        return toAjax(baseGroupInfoService.updateBaseGroupInfo(baseGroupInfo));
    }

    /**
     * 删除班组基础信息
     */
    @RequiresPermissions("baseinfo:groupinfo:remove")
    @Log(title = "班组基础信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseGroupInfoService.deleteBaseGroupInfoByIds(ids));
    }
}
