package com.ruoyi.framework.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.framework.system.domain.Patients;
import com.ruoyi.framework.system.service.IPatientsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病患信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/system/Patients")
public class PatientsController extends BaseController
{
    @Autowired
    private IPatientsService patientsService;

    /**
     * 查询病患信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:Patients:list')")
    @GetMapping("/list")
    public TableDataInfo list(Patients patients)
    {
        startPage();
        List<Patients> list = patientsService.selectPatientsList(patients);
        return getDataTable(list);
    }

    /**
     * 导出病患信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:Patients:export')")
    @Log(title = "病患信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Patients patients)
    {
        List<Patients> list = patientsService.selectPatientsList(patients);
        ExcelUtil<Patients> util = new ExcelUtil<Patients>(Patients.class);
        util.exportExcel(response, list, "病患信息数据");
    }

    /**
     * 获取病患信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:Patients:query')")
    @GetMapping(value = "/{PatientID}")
    public AjaxResult getInfo(@PathVariable("PatientID") Long PatientID)
    {
        return success(patientsService.selectPatientsByPatientID(PatientID));
    }

    /**
     * 新增病患信息
     */
    @PreAuthorize("@ss.hasPermi('system:Patients:add')")
    @Log(title = "病患信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Patients patients)
    {
        return toAjax(patientsService.insertPatients(patients));
    }

    /**
     * 修改病患信息
     */
    @PreAuthorize("@ss.hasPermi('system:Patients:edit')")
    @Log(title = "病患信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Patients patients)
    {
        return toAjax(patientsService.updatePatients(patients));
    }

    /**
     * 删除病患信息
     */
    @PreAuthorize("@ss.hasPermi('system:Patients:remove')")
    @Log(title = "病患信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{PatientIDs}")
    public AjaxResult remove(@PathVariable Long[] PatientIDs)
    {
        return toAjax(patientsService.deletePatientsByPatientIDs(PatientIDs));
    }
}
