package com.xinelu.manage.controller.basedruginfo;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.basedruginfo.BaseDrugInfo;
import com.xinelu.manage.service.basedruginfo.IBaseDrugInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 药品库Controller
 *
 * @author xinelu
 * @date 2024-05-17
 */
@RestController
@RequestMapping("/system/baseDrug")
public class BaseDrugInfoController extends BaseController {
    @Resource
    private IBaseDrugInfoService baseDrugInfoService;

    /**
     * 查询药品库列表
     */
    @PreAuthorize("@ss.hasPermi('system:baseDrug:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseDrugInfo baseDrugInfo) {
        startPage();
        List<BaseDrugInfo> list = baseDrugInfoService.selectBaseDrugInfoList(baseDrugInfo);
        return getDataTable(list);
    }

    /**
     * 导出药品库列表
     */
    @PreAuthorize("@ss.hasPermi('system:baseDrug:export')")
    @Log(title = "药品库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseDrugInfo baseDrugInfo) {
        List<BaseDrugInfo> list = baseDrugInfoService.selectBaseDrugInfoList(baseDrugInfo);
        ExcelUtil<BaseDrugInfo> util = new ExcelUtil<>(BaseDrugInfo.class);
        util.exportExcel(response, list, "药品库数据");
    }

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

    /**
     * 新增药品库
     */
    @PreAuthorize("@ss.hasPermi('system:baseDrug:add')")
    @Log(title = "药品库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BaseDrugInfo baseDrugInfo) {
        return toAjax(baseDrugInfoService.insertBaseDrugInfo(baseDrugInfo));
    }

    /**
     * 修改药品库
     */
    @PreAuthorize("@ss.hasPermi('system:baseDrug:edit')")
    @Log(title = "药品库", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody BaseDrugInfo baseDrugInfo) {
        return toAjax(baseDrugInfoService.updateBaseDrugInfo(baseDrugInfo));
    }

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