package com.ruoyi.web.controller.business;

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.business.domain.SCompany;
import com.ruoyi.business.service.ISCompanyService;
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 xiatao
 * @date 2022-01-18
 */
@Controller
@RequestMapping("/business/company")
public class SCompanyController extends BaseController
{
    private String prefix = "business/company";

    @Autowired
    private ISCompanyService sCompanyService;

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

    /**
     * 查询公司列表
     */
    @RequiresPermissions("business:company:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SCompany sCompany)
    {
        startPage();
        List<SCompany> list = sCompanyService.selectSCompanyList(sCompany);
        return getDataTable(list);
    }

    /**
     * 导出公司列表
     */
    @RequiresPermissions("business:company:export")
    @Log(title = "公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SCompany sCompany)
    {
        List<SCompany> list = sCompanyService.selectSCompanyList(sCompany);
        ExcelUtil<SCompany> util = new ExcelUtil<SCompany>(SCompany.class);
        return util.exportExcel(list, "公司数据");
    }

    /**
     * 新增公司
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公司
     */
    @RequiresPermissions("business:company:add")
    @Log(title = "公司", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SCompany sCompany)
    {
        return toAjax(sCompanyService.insertSCompany(sCompany));
    }

    /**
     * 修改公司
     */
    @RequiresPermissions("business:company:edit")
    @GetMapping("/edit/{companyId}")
    public String edit(@PathVariable("companyId") Long companyId, ModelMap mmap)
    {
        SCompany sCompany = sCompanyService.selectSCompanyByCompanyId(companyId);
        mmap.put("sCompany", sCompany);
        return prefix + "/edit";
    }

    /**
     * 修改保存公司
     */
    @RequiresPermissions("business:company:edit")
    @Log(title = "公司", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SCompany sCompany)
    {
        return toAjax(sCompanyService.updateSCompany(sCompany));
    }

    /**
     * 删除公司
     */
    @RequiresPermissions("business:company:remove")
    @Log(title = "公司", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sCompanyService.deleteSCompanyByCompanyIds(ids));
    }
}
