package com.zhyc.module.biosafety.controller;

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

import com.zhyc.module.biosafety.service.ISwPrescriptionService;
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.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.common.enums.BusinessType;
import com.zhyc.module.biosafety.domain.SwPrescription;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * 处方Controller
 * 
 * @author ruoyi
 * @date 2025-07-11
 */
@RestController
@RequestMapping("/biosafety/prescription")
public class SwPrescriptionController extends BaseController
{
    @Autowired
    private ISwPrescriptionService swPrescriptionService;

    /**
     * 查询处方列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:prescription:list')")
    @GetMapping("/list")
    public TableDataInfo list(SwPrescription swPrescription)
    {
        startPage();
        List<SwPrescription> list = swPrescriptionService.selectSwPrescriptionList(swPrescription);
        return getDataTable(list);
    }

    /**
     * 导出处方列表
     */
    @PreAuthorize("@ss.hasPermi('biosafety:prescription:export')")
    @Log(title = "处方", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SwPrescription swPrescription)
    {
        List<SwPrescription> list = swPrescriptionService.selectSwPrescriptionList(swPrescription);
        ExcelUtil<SwPrescription> util = new ExcelUtil<SwPrescription>(SwPrescription.class);
        util.exportExcel(response, list, "处方数据");
    }

    /**
     * 获取处方详细信息
     */
    @PreAuthorize("@ss.hasPermi('biosafety:prescription:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(swPrescriptionService.selectSwPrescriptionById(id));
    }

    /**
     * 新增处方
     */
    @PreAuthorize("@ss.hasPermi('biosafety:prescription:add')")
    @Log(title = "处方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SwPrescription swPrescription)
    {
        return toAjax(swPrescriptionService.insertSwPrescription(swPrescription));
    }

    /**
     * 修改处方
     */
    @PreAuthorize("@ss.hasPermi('biosafety:prescription:edit')")
    @Log(title = "处方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SwPrescription swPrescription)
    {
        return toAjax(swPrescriptionService.updateSwPrescription(swPrescription));
    }

    /**
     * 删除处方
     */
    @PreAuthorize("@ss.hasPermi('biosafety:prescription:remove')")
    @Log(title = "处方", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(swPrescriptionService.deleteSwPrescriptionByIds(ids));
    }
}
