package com.ruoyi.web.controller.baseinfo;

import java.util.List;

import com.ruoyi.baseinfo.domain.BasePosttypeInfo;
import com.ruoyi.baseinfo.service.IBasePosttypeInfoService;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.util.ShiroUtils;
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.BasePostInfo;
import com.ruoyi.baseinfo.service.IBasePostInfoService;
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-20
 */
@Controller
@RequestMapping("/baseinfo/postinfo")
public class BasePostInfoController extends BaseController
{
    private String prefix = "baseinfo/postinfo";

    @Autowired
    private IBasePostInfoService basePostInfoService;
    @Autowired
    private IBasePosttypeInfoService basePosttypeInfoService;

    @RequiresPermissions("baseinfo:postinfo:view")
    @GetMapping()
    public String postinfo(ModelMap mmap)
    {
        mmap.put("cbPostTypeInfo",basePosttypeInfoService.selectAddBasePosttypeInfoList());
        return prefix + "/postinfo";
    }

    /**
     * 查询职位基础信息列表
     */
    @RequiresPermissions("baseinfo:postinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasePostInfo basePostInfo)
    {
        startPage();
        List<BasePostInfo> list = basePostInfoService.selectBasePostInfoList(basePostInfo);
        return getDataTable(list);
    }

    /**
     * 导出职位基础信息列表
     */
    @RequiresPermissions("baseinfo:postinfo:export")
    @Log(title = "职位基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasePostInfo basePostInfo)
    {
        List<BasePostInfo> list = basePostInfoService.selectBasePostInfoList(basePostInfo);
        ExcelUtil<BasePostInfo> util = new ExcelUtil<BasePostInfo>(BasePostInfo.class);
        return util.exportExcel(list, "postinfo");
    }

    /**
     * 新增职位基础信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("cbPostTypeInfo",basePosttypeInfoService.selectAddBasePosttypeInfoList());
        return prefix + "/add";
    }

    /**
     * 新增保存职位基础信息
     */
    @RequiresPermissions("baseinfo:postinfo:add")
    @Log(title = "职位基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasePostInfo basePostInfo)
    {
        basePostInfo.setCreateTime(DateUtils.getNowDate());
        basePostInfo.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(basePostInfoService.insertBasePostInfo(basePostInfo));
    }

    /**
     * 修改职位基础信息
     */
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap)
    {
        BasePostInfo basePostInfo = basePostInfoService.selectBasePostInfoById(objid);
        mmap.put("cbEditPostTypeInfo",  basePosttypeInfoService.selectEditBasePosttypeInfoList(basePostInfo.getPostTypeId()));
        mmap.put("basePostInfo", basePostInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存职位基础信息
     */
    @RequiresPermissions("baseinfo:postinfo:edit")
    @Log(title = "职位基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasePostInfo basePostInfo)
    {
        basePostInfo.setUpdateTime(DateUtils.getNowDate());
        basePostInfo.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(basePostInfoService.updateBasePostInfo(basePostInfo));
    }

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