package com.ruoyi.controller;

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 com.ruoyi.cs.domain.CsCompany;
import com.ruoyi.cs.service.ICsCompanyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 单位信息Controller
 *
 * @author ruoyi
 * @date 2024-05-31
 */
@RestController
@RequestMapping("/cs/csCompany")
public class CsCompanyController extends BaseController
{
    @Resource
    private ICsCompanyService csCompanyService;

    /**
     * 查询单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csCompany:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsCompany csCompany)
    {
        startPage();
        csCompany.setDelFlag("0");
        List<CsCompany> list = csCompanyService.selectCsCompanyList(csCompany);
        return getDataTable(list);
    }

    /**
     * 导出单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csCompany:export')")
    @Log(title = "单位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsCompany csCompany)
    {
        csCompany.setDelFlag("0");
        List<CsCompany> list = csCompanyService.selectCompanyInfoList(csCompany);
        ExcelUtil<CsCompany> util = new ExcelUtil<CsCompany>(CsCompany.class);
        util.exportExcel(response, list, "单位信息数据");
    }

    /**
     * 获取单位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csCompany:query')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") String companyId)
    {
        return AjaxResult.success(csCompanyService.selectCsCompanyByCompanyId(companyId));
    }

    /**
     * 新增单位信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csCompany:add')")
    @Log(title = "单位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsCompany csCompany)
    {
        return toAjax(csCompanyService.insertCsCompany(csCompany));
    }

    /**
     * 修改单位信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csCompany:edit')")
    @Log(title = "单位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsCompany csCompany)
    {
        return toAjax(csCompanyService.updateCsCompany(csCompany));
    }

    /**
     * 删除单位信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csCompany:remove')")
    @Log(title = "单位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable String[] companyIds)
    {
        return toAjax(csCompanyService.deleteCsCompanyByCompanyIds(companyIds));
    }

    /**
     * 查询单位信息列表
     */
    @GetMapping("/selectCompanyInfoList")
    public TableDataInfo selectCompanyInfoList(CsCompany csCompany)
    {
        startPage();
        csCompany.setDelFlag("0");
        List<CsCompany> list = csCompanyService.selectCompanyInfoList(csCompany);
        return getDataTable(list);
    }
}
