package com.zehong.web.controller.transaction;

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.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.enums.BusinessType;
import com.zehong.system.domain.TPurchase;
import com.zehong.system.service.ITPurchaseService;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.common.core.page.TableDataInfo;

/**
 * 外部采购（报销）申请Controller
 * 
 * @author zehong
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/system/purchase")
public class TPurchaseController extends BaseController
{
    @Autowired
    private ITPurchaseService tPurchaseService;

    /**
     * 查询外部采购（报销）申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:purchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPurchase tPurchase)
    {
        startPage();
        List<TPurchase> list = tPurchaseService.selectTPurchaseList(tPurchase);
        return getDataTable(list);
    }

    /**
     * 导出外部采购（报销）申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:purchase:export')")
    @Log(title = "外部采购（报销）申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TPurchase tPurchase)
    {
        List<TPurchase> list = tPurchaseService.selectTPurchaseList(tPurchase);
        ExcelUtil<TPurchase> util = new ExcelUtil<TPurchase>(TPurchase.class);
        return util.exportExcel(list, "外部采购（报销）申请数据");
    }

    /**
     * 获取外部采购（报销）申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:purchase:query')")
    @GetMapping(value = "/{purchaseId}")
    public AjaxResult getInfo(@PathVariable("purchaseId") Long purchaseId)
    {
        return AjaxResult.success(tPurchaseService.selectTPurchaseById(purchaseId));
    }

    /**
     * 新增外部采购（报销）申请
     */
    @PreAuthorize("@ss.hasPermi('system:purchase:add')")
    @Log(title = "外部采购（报销）申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPurchase tPurchase)
    {
        return toAjax(tPurchaseService.insertTPurchase(tPurchase));
    }

    /**
     * 修改外部采购（报销）申请
     */
    @PreAuthorize("@ss.hasPermi('system:purchase:edit')")
    @Log(title = "外部采购（报销）申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPurchase tPurchase)
    {
        return toAjax(tPurchaseService.updateTPurchase(tPurchase));
    }

    /**
     * 删除外部采购（报销）申请
     */
    @PreAuthorize("@ss.hasPermi('system:purchase:remove')")
    @Log(title = "外部采购（报销）申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purchaseIds}")
    public AjaxResult remove(@PathVariable Long[] purchaseIds)
    {
        return toAjax(tPurchaseService.deleteTPurchaseByIds(purchaseIds));
    }
}
