package com.ruoyi.inventory.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.ruoyi.inventory.domain.HealthcareDrugArchive;
import com.ruoyi.inventory.domain.HealthcareInventoryDrugentry;
import com.ruoyi.inventory.service.IHealthcareDrugArchiveService;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.inventory.domain.HealthcareDrugFiling;
import com.ruoyi.inventory.service.IHealthcareDrugFilingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 药品库存Controller
 *
 * @author 蒋松霖
 * @date 2024-09-24
 */
@RestController
@RequestMapping("/healthcare/filing")
public class HealthcareDrugFilingController extends BaseController
{
    @Autowired
    private IHealthcareDrugFilingService healthcareDrugFilingService;
    @Autowired
    private IHealthcareDrugArchiveService healthcareDrugArchiveService;

    /**
     * 查询药品库存列表
     */
    @PreAuthorize("@ss.hasPermi('healthcare:filing:list')")
    @GetMapping("/list")
    public TableDataInfo list(HealthcareDrugFiling healthcareDrugFiling)
    {
        startPage();
        List<HealthcareDrugFiling> list = healthcareDrugFilingService.selectHealthcareDrugFilingList(healthcareDrugFiling);
        return getDataTable(list);
    }


    /**
     * 导出药品库存列表
     */
    @PreAuthorize("@ss.hasPermi('healthcare:filing:export')")
    @Log(title = "药品库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")


    public void export(HttpServletResponse response, HealthcareDrugFiling healthcareDrugFiling)
    {
        List<HealthcareDrugFiling> list = healthcareDrugFilingService.selectHealthcareDrugFilingList(healthcareDrugFiling);
        ExcelUtil<HealthcareDrugFiling> util = new ExcelUtil<HealthcareDrugFiling>(HealthcareDrugFiling.class);
        util.exportExcel(response, list, "药品库存数据");
    }

    /**
     * 获取药品库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('healthcare:filing:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(healthcareDrugFilingService.selectHealthcareDrugFilingById(id));
    }

    /**
     * 新增药品库存
     */
    @PreAuthorize("@ss.hasPermi('healthcare:filing:add')")
    @Log(title = "药品库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthcareDrugFiling healthcareDrugFiling)
    {
        return toAjax(healthcareDrugFilingService.insertHealthcareDrugFiling(healthcareDrugFiling));
    }

    /**
     * 修改药品库存
     */
    @PreAuthorize("@ss.hasPermi('healthcare:filing:edit')")
    @Log(title = "药品库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthcareDrugFiling healthcareDrugFiling)
    {
        return toAjax(healthcareDrugFilingService.updateHealthcareDrugFiling(healthcareDrugFiling));
    }

    /**
     * 删除药品库存
     */
    @PreAuthorize("@ss.hasPermi('healthcare:filing:remove')")
    @Log(title = "药品库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(healthcareDrugFilingService.deleteHealthcareDrugFilingByIds(ids));
    }

}
