package com.ruoyi.web.controller.baseinfo;

import java.util.List;

import com.ruoyi.baseinfo.service.IBasePostInfoService;
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.BaseEmployeeInfo;
import com.ruoyi.baseinfo.service.IBaseEmployeeInfoService;
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 CaesarBao
 * @date 2020-10-21
 */
@Controller
@RequestMapping("/baseinfo/employeeinfo")
public class BaseEmployeeInfoController extends BaseController
{
    private String prefix = "baseinfo/employeeinfo";

    @Autowired
    private IBaseEmployeeInfoService baseEmployeeInfoService;
    @Autowired
    private IBasePostInfoService basePostInfoService;

    @RequiresPermissions("baseinfo:employeeinfo:view")
    @GetMapping()
    public String employeeinfo(ModelMap mmap)
    {
        mmap.put("cbPostInfo",basePostInfoService.selectAddBasePostInfoList());
        return prefix + "/employeeinfo";
    }

    /**
     * 查询职员基础信息列表
     */
    @RequiresPermissions("baseinfo:employeeinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseEmployeeInfo baseEmployeeInfo)
    {
        startPage();
        List<BaseEmployeeInfo> list = baseEmployeeInfoService.selectBaseEmployeeInfoList(baseEmployeeInfo);
        return getDataTable(list);
    }

    /**
     * 导出职员基础信息列表
     */
    @RequiresPermissions("baseinfo:employeeinfo:export")
    @Log(title = "职员基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseEmployeeInfo baseEmployeeInfo)
    {
        List<BaseEmployeeInfo> list = baseEmployeeInfoService.selectBaseEmployeeInfoList(baseEmployeeInfo);
        ExcelUtil<BaseEmployeeInfo> util = new ExcelUtil<BaseEmployeeInfo>(BaseEmployeeInfo.class);
        return util.exportExcel(list, "employeeinfo");
    }

    /**
     * 新增职员基础信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("cbPostInfo",basePostInfoService.selectAddBasePostInfoList());
        return prefix + "/add";
    }

    /**
     * 新增保存职员基础信息
     */
    @RequiresPermissions("baseinfo:employeeinfo:add")
    @Log(title = "职员基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseEmployeeInfo baseEmployeeInfo)
    {
        return toAjax(baseEmployeeInfoService.insertBaseEmployeeInfo(baseEmployeeInfo));
    }

    /**
     * 修改职员基础信息
     */
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap)
    {
        BaseEmployeeInfo baseEmployeeInfo = baseEmployeeInfoService.selectBaseEmployeeInfoById(objid);
        mmap.put("cbEditPostInfo",basePostInfoService.selectEditBasePostInfoList(baseEmployeeInfo.getPostId()));
        mmap.put("baseEmployeeInfo", baseEmployeeInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存职员基础信息
     */
    @RequiresPermissions("baseinfo:employeeinfo:edit")
    @Log(title = "职员基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseEmployeeInfo baseEmployeeInfo)
    {
        return toAjax(baseEmployeeInfoService.updateBaseEmployeeInfo(baseEmployeeInfo));
    }

    /**
     * 删除职员基础信息
     */
    @RequiresPermissions("baseinfo:employeeinfo:remove")
    @Log(title = "职员基础信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseEmployeeInfoService.deleteBaseEmployeeInfoByIds(ids));
    }
}
