package com.business.controller;

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.validation.annotation.Validated;
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.sooka.common.annotation.Log;
import com.sooka.common.enums.BusinessType;
import com.business.domain.BusGridPersonInfo;
import com.business.service.IBusGridPersonInfoService;
import com.sooka.common.core.controller.BaseController;
import com.sooka.common.core.domain.AjaxResult;
import com.sooka.common.utils.poi.ExcelUtil;
import com.sooka.common.core.page.TableDataInfo;

/**
 * 网格人员管理Controller
 * 
 * @author lei_wang
 * @date 2020-07-29
 */
@Controller
@RequestMapping("/grid/gridPerson")
public class BusGridPersonInfoController extends BaseController
{
    private String prefix = "grid/gridPerson";

    @Autowired
    private IBusGridPersonInfoService busGridPersonInfoService;

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

    /**
     * 查询网格人员管理列表
     */
    @RequiresPermissions("grid:gridPerson:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusGridPersonInfo busGridPersonInfo)
    {
        startPage();
        List<BusGridPersonInfo> list = busGridPersonInfoService.selectBusGridPersonInfoList(busGridPersonInfo);
        return getDataTable(list);
    }

    /**
     * 导出网格人员管理列表
     */
    @RequiresPermissions("grid:gridPerson:export")
    @Log(title = "网格人员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusGridPersonInfo busGridPersonInfo)
    {
        List<BusGridPersonInfo> list = busGridPersonInfoService.selectBusGridPersonInfoList(busGridPersonInfo);
        ExcelUtil<BusGridPersonInfo> util = new ExcelUtil<BusGridPersonInfo>(BusGridPersonInfo.class);
        return util.exportExcel(list, "gridPerson");
    }

    /**
     * 新增网格人员管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存网格人员管理
     */
    @RequiresPermissions("grid:gridPerson:add")
    @Log(title = "网格人员管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated BusGridPersonInfo busGridPersonInfo)
    {
        return toAjax(busGridPersonInfoService.insertBusGridPersonInfo(busGridPersonInfo));
    }

    /**
     * 修改网格人员管理
     */
    @GetMapping("/edit/{gridPersonId}")
    public String edit(@PathVariable("gridPersonId") Long gridPersonId, ModelMap mmap)
    {
        BusGridPersonInfo busGridPersonInfo = busGridPersonInfoService.selectBusGridPersonInfoById(gridPersonId);
        mmap.put("busGridPersonInfo", busGridPersonInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存网格人员管理
     */
    @RequiresPermissions("grid:gridPerson:edit")
    @Log(title = "网格人员管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated BusGridPersonInfo busGridPersonInfo)
    {
        return toAjax(busGridPersonInfoService.updateBusGridPersonInfo(busGridPersonInfo));
    }

    /**
     * 删除网格人员管理
     */
    @RequiresPermissions("grid:gridPerson:remove")
    @Log(title = "网格人员管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(busGridPersonInfoService.deleteBusGridPersonInfoByIds(ids));
    }
}
