package com.fs.hospital.controller.hospital;

import java.util.List;

import com.fs.common.utils.ServletUtils;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.hospital.vo.HospitalProductOutOrderItemListHVO;
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.HospitalProductOutOrderItem;
import com.fs.hospital.service.IHospitalProductOutOrderItemService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 领用单明细Controller
 *
 * @author fs
 * @date 2024-03-14
 */
@RestController
@RequestMapping("/hospital/hospitalProductOutOrderItem")
public class HospitalProductOutOrderItemController extends BaseController
{
    @Autowired
    private IHospitalProductOutOrderItemService hospitalProductOutOrderItemService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询领用单明细列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalProductOutOrderItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalProductOutOrderItem hospitalProductOutOrderItem)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalProductOutOrderItem.setHospitalId( loginUser.getHospital().getHospitalId());
        List<HospitalProductOutOrderItemListHVO> list = hospitalProductOutOrderItemService.selectHospitalProductOutOrderItemListPVO(hospitalProductOutOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出领用单明细列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalProductOutOrderItem:export')")
    @Log(title = "领用单明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalProductOutOrderItem hospitalProductOutOrderItem)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalProductOutOrderItem.setHospitalId( loginUser.getHospital().getHospitalId());
        List<HospitalProductOutOrderItem> list = hospitalProductOutOrderItemService.selectHospitalProductOutOrderItemList(hospitalProductOutOrderItem);
        ExcelUtil<HospitalProductOutOrderItem> util = new ExcelUtil<HospitalProductOutOrderItem>(HospitalProductOutOrderItem.class);
        return util.exportExcel(list, "领用单明细数据");
    }

    /**
     * 获取领用单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalProductOutOrderItem:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return AjaxResult.success(hospitalProductOutOrderItemService.selectHospitalProductOutOrderItemByItemId(itemId));
    }

    /**
     * 新增领用单明细
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalProductOutOrderItem:add')")
    @Log(title = "领用单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalProductOutOrderItem hospitalProductOutOrderItem)
    {
        return toAjax(hospitalProductOutOrderItemService.insertHospitalProductOutOrderItem(hospitalProductOutOrderItem));
    }

    /**
     * 修改领用单明细
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalProductOutOrderItem:edit')")
    @Log(title = "领用单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalProductOutOrderItem hospitalProductOutOrderItem)
    {
        return toAjax(hospitalProductOutOrderItemService.updateHospitalProductOutOrderItem(hospitalProductOutOrderItem));
    }

    /**
     * 删除领用单明细
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalProductOutOrderItem:remove')")
    @Log(title = "领用单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(hospitalProductOutOrderItemService.deleteHospitalProductOutOrderItemByItemIds(itemIds));
    }
}
