package com.fs.hospital.controller.hospital;

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.hospital.domain.HospitalProductPurchaseOrderItem;
import com.fs.hospital.service.IHospitalProductPurchaseOrderItemService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 采购单明细Controller
 *
 * @author fs
 * @date 2024-03-12
 */
@RestController
@RequestMapping("/hospital/hospitalPurchaseOrderItem")
public class HospitalProductPurchaseOrderItemController extends BaseController
{
    @Autowired
    private IHospitalProductPurchaseOrderItemService hospitalPurchaseOrderItemService;

    /**
     * 查询采购单明细列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalPurchaseOrderItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalProductPurchaseOrderItem hospitalProductPurchaseOrderItem)
    {
        startPage();
        List<HospitalProductPurchaseOrderItem> list = hospitalPurchaseOrderItemService.selectHospitalPurchaseOrderItemList(hospitalProductPurchaseOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出采购单明细列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalPurchaseOrderItem:export')")
    @Log(title = "采购单明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalProductPurchaseOrderItem hospitalProductPurchaseOrderItem)
    {
        List<HospitalProductPurchaseOrderItem> list = hospitalPurchaseOrderItemService.selectHospitalPurchaseOrderItemList(hospitalProductPurchaseOrderItem);
        ExcelUtil<HospitalProductPurchaseOrderItem> util = new ExcelUtil<HospitalProductPurchaseOrderItem>(HospitalProductPurchaseOrderItem.class);
        return util.exportExcel(list, "采购单明细数据");
    }

    /**
     * 获取采购单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalPurchaseOrderItem:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return AjaxResult.success(hospitalPurchaseOrderItemService.selectHospitalPurchaseOrderItemByItemId(itemId));
    }

    /**
     * 新增采购单明细
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalPurchaseOrderItem:add')")
    @Log(title = "采购单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalProductPurchaseOrderItem hospitalProductPurchaseOrderItem)
    {
        return toAjax(hospitalPurchaseOrderItemService.insertHospitalPurchaseOrderItem(hospitalProductPurchaseOrderItem));
    }

    /**
     * 修改采购单明细
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalPurchaseOrderItem:edit')")
    @Log(title = "采购单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalProductPurchaseOrderItem hospitalProductPurchaseOrderItem)
    {
        return toAjax(hospitalPurchaseOrderItemService.updateHospitalPurchaseOrderItem(hospitalProductPurchaseOrderItem));
    }

    /**
     * 删除采购单明细
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalPurchaseOrderItem:remove')")
    @Log(title = "采购单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(hospitalPurchaseOrderItemService.deleteHospitalPurchaseOrderItemByItemIds(itemIds));
    }
}
