package com.fs.store.controller;

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.store.domain.FsPrescribeDrug;
import com.fs.store.service.IFsPrescribeDrugService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 处方药品Controller
 * 
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/prescribeDrug")
public class FsPrescribeDrugController extends BaseController
{
    @Autowired
    private IFsPrescribeDrugService fsPrescribeDrugService;

    /**
     * 查询处方药品列表
     */
    @PreAuthorize("@ss.hasPermi('store:prescribeDrug:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsPrescribeDrug fsPrescribeDrug)
    {
        startPage();
        List<FsPrescribeDrug> list = fsPrescribeDrugService.selectFsPrescribeDrugList(fsPrescribeDrug);
        return getDataTable(list);
    }

    /**
     * 导出处方药品列表
     */
    @PreAuthorize("@ss.hasPermi('store:prescribeDrug:export')")
    @Log(title = "处方药品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsPrescribeDrug fsPrescribeDrug)
    {
        List<FsPrescribeDrug> list = fsPrescribeDrugService.selectFsPrescribeDrugList(fsPrescribeDrug);
        ExcelUtil<FsPrescribeDrug> util = new ExcelUtil<FsPrescribeDrug>(FsPrescribeDrug.class);
        return util.exportExcel(list, "prescribeDrug");
    }

    /**
     * 获取处方药品详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:prescribeDrug:query')")
    @GetMapping(value = "/{drugId}")
    public AjaxResult getInfo(@PathVariable("drugId") Long drugId)
    {
        return AjaxResult.success(fsPrescribeDrugService.selectFsPrescribeDrugById(drugId));
    }

    /**
     * 新增处方药品
     */
    @PreAuthorize("@ss.hasPermi('store:prescribeDrug:add')")
    @Log(title = "处方药品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsPrescribeDrug fsPrescribeDrug)
    {
        return toAjax(fsPrescribeDrugService.insertFsPrescribeDrug(fsPrescribeDrug));
    }

    /**
     * 修改处方药品
     */
    @PreAuthorize("@ss.hasPermi('store:prescribeDrug:edit')")
    @Log(title = "处方药品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsPrescribeDrug fsPrescribeDrug)
    {
        return toAjax(fsPrescribeDrugService.updateFsPrescribeDrug(fsPrescribeDrug));
    }

    /**
     * 删除处方药品
     */
    @PreAuthorize("@ss.hasPermi('store:prescribeDrug:remove')")
    @Log(title = "处方药品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{drugIds}")
    public AjaxResult remove(@PathVariable Long[] drugIds)
    {
        return toAjax(fsPrescribeDrugService.deleteFsPrescribeDrugByIds(drugIds));
    }
}
