package com.ruoyi.web.controller.warehouse.basicData;

import com.ruoyi.basicData.domain.TCompany;
import com.ruoyi.basicData.service.ITCompanyService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公司名称Controller
 *
 * @author ruoyi
 * @date 2020-12-11
 */
@RestController
@RequestMapping("/basicdata/company")
public class TCompanyController extends BaseController {
    @Autowired
    private ITCompanyService tCompanyService;

    /**
     * 查询公司名称列表
     */
    @PreAuthorize("@ss.hasPermi('basicdata:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCompany tCompany) {
        startPage();
        List<TCompany> list = tCompanyService.selectTCompanyList(tCompany);
        return getDataTable(list);
    }

    /**
     * 导出公司名称列表
     */
    @PreAuthorize("@ss.hasPermi('basicdata:company:export')")
    @Log(title = "公司名称", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TCompany tCompany) {
        List<TCompany> list = tCompanyService.selectTCompanyList(tCompany);
        ExcelUtil<TCompany> util = new ExcelUtil<TCompany>(TCompany.class);
        return util.exportExcel(list, "company");
    }

    /**
     * 获取公司名称详细信息
     */
    @PreAuthorize("@ss.hasPermi('basicdata:company:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
        return AjaxResult.success(tCompanyService.selectTCompanyById(fId));
    }

    /**
     * 新增公司名称
     */
    @PreAuthorize("@ss.hasPermi('basicdata:company:add')")
    @Log(title = "公司名称", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCompany tCompany) {
        return toAjax(tCompanyService.insertTCompany(tCompany));
    }

    /**
     * 修改公司名称
     */
    @PreAuthorize("@ss.hasPermi('basicdata:company:edit')")
    @Log(title = "公司名称", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCompany tCompany) {
        return toAjax(tCompanyService.updateTCompany(tCompany));
    }

    /**
     * 删除公司名称
     */
    @PreAuthorize("@ss.hasPermi('basicdata:company:remove')")
    @Log(title = "公司名称", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds) {
        return toAjax(tCompanyService.deleteTCompanyByIds(fIds));
    }
}
