package com.fs.company.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.company.domain.CompanyPurchase;
import com.fs.company.service.ICompanyPurchaseService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 采购Controller
 * 
 * @author fs
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/company/companyPurchase")
public class CompanyPurchaseController extends BaseController
{
    @Autowired
    private ICompanyPurchaseService companyPurchaseService;

    /**
     * 查询采购列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyPurchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyPurchase companyPurchase)
    {
        startPage();
        List<CompanyPurchase> list = companyPurchaseService.selectCompanyPurchaseList(companyPurchase);
        return getDataTable(list);
    }

    /**
     * 导出采购列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyPurchase:export')")
    @Log(title = "采购", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyPurchase companyPurchase)
    {
        List<CompanyPurchase> list = companyPurchaseService.selectCompanyPurchaseList(companyPurchase);
        ExcelUtil<CompanyPurchase> util = new ExcelUtil<CompanyPurchase>(CompanyPurchase.class);
        return util.exportExcel(list, "采购数据");
    }

    /**
     * 获取采购详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyPurchase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(companyPurchaseService.selectCompanyPurchaseById(id));
    }

    /**
     * 新增采购
     */
    @PreAuthorize("@ss.hasPermi('company:companyPurchase:add')")
    @Log(title = "采购", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyPurchase companyPurchase)
    {
        return toAjax(companyPurchaseService.insertCompanyPurchase(companyPurchase));
    }

    /**
     * 修改采购
     */
    @PreAuthorize("@ss.hasPermi('company:companyPurchase:edit')")
    @Log(title = "采购", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyPurchase companyPurchase)
    {
        return toAjax(companyPurchaseService.updateCompanyPurchase(companyPurchase));
    }

    /**
     * 删除采购
     */
    @PreAuthorize("@ss.hasPermi('company:companyPurchase:remove')")
    @Log(title = "采购", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(companyPurchaseService.deleteCompanyPurchaseByIds(ids));
    }
}
