package com.fs.his.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.his.domain.FsDoctorPrescribeDrug;
import com.fs.his.service.IFsDoctorPrescribeDrugService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 医生处方药品Controller
 *
 * @author fs
 * @date 2023-08-08
 */
@RestController
@RequestMapping("/his/doctorPrescribeDrug")
public class FsDoctorPrescribeDrugController extends BaseController
{
    @Autowired
    private IFsDoctorPrescribeDrugService fsDoctorPrescribeDrugService;

    /**
     * 查询医生处方药品列表
     */

    @GetMapping("/list")
    public TableDataInfo list(FsDoctorPrescribeDrug fsDoctorPrescribeDrug)
    {
        startPage();
        List<FsDoctorPrescribeDrug> list = fsDoctorPrescribeDrugService.selectFsDoctorPrescribeDrugList(fsDoctorPrescribeDrug);
        return getDataTable(list);
    }

    /**
     * 导出医生处方药品列表
     */
    @PreAuthorize("@ss.hasPermi('his:doctorPrescribeDrug:export')")
    @Log(title = "医生处方药品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsDoctorPrescribeDrug fsDoctorPrescribeDrug)
    {
        List<FsDoctorPrescribeDrug> list = fsDoctorPrescribeDrugService.selectFsDoctorPrescribeDrugList(fsDoctorPrescribeDrug);
        ExcelUtil<FsDoctorPrescribeDrug> util = new ExcelUtil<FsDoctorPrescribeDrug>(FsDoctorPrescribeDrug.class);
        return util.exportExcel(list, "医生处方药品数据");
    }

    /**
     * 获取医生处方药品详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:doctorPrescribeDrug:query')")
    @GetMapping(value = "/{drugId}")
    public AjaxResult getInfo(@PathVariable("drugId") Long drugId)
    {
        return AjaxResult.success(fsDoctorPrescribeDrugService.selectFsDoctorPrescribeDrugByDrugId(drugId));
    }

    /**
     * 新增医生处方药品
     */
    @PreAuthorize("@ss.hasPermi('his:doctorPrescribeDrug:add')")
    @Log(title = "医生处方药品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsDoctorPrescribeDrug fsDoctorPrescribeDrug)
    {
        return toAjax(fsDoctorPrescribeDrugService.insertFsDoctorPrescribeDrug(fsDoctorPrescribeDrug));
    }

    /**
     * 修改医生处方药品
     */
    @PreAuthorize("@ss.hasPermi('his:doctorPrescribeDrug:edit')")
    @Log(title = "医生处方药品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsDoctorPrescribeDrug fsDoctorPrescribeDrug)
    {
        return toAjax(fsDoctorPrescribeDrugService.updateFsDoctorPrescribeDrug(fsDoctorPrescribeDrug));
    }

    /**
     * 删除医生处方药品
     */
    @PreAuthorize("@ss.hasPermi('his:doctorPrescribeDrug:remove')")
    @Log(title = "医生处方药品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{drugIds}")
    public AjaxResult remove(@PathVariable Long[] drugIds)
    {
        return toAjax(fsDoctorPrescribeDrugService.deleteFsDoctorPrescribeDrugByDrugIds(drugIds));
    }
}
