package com.ruoyi.system.controller;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.system.domain.BusPatient;
import com.ruoyi.system.service.IBusPatientService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 患者Controller
 * 
 * @author zsl
 * @date 2022-06-02
 */
@Api("患者管理")
@RestController
@RequestMapping("/system/patient")
public class BusPatientController extends BaseController
{
    @Autowired
    private IBusPatientService busPatientService;

    /**
     * 查询患者列表
     */
    @ApiOperation("查询患者列表")
    @PreAuthorize("@ss.hasPermi('system:patient:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusPatient busPatient)
    {
        startPage();
        List<BusPatient> list = busPatientService.selectBusPatientList(busPatient);
        return getDataTable(list);
    }

    /**
     * 导出患者列表
     */
    @ApiOperation("导出患者列表")
    @PreAuthorize("@ss.hasPermi('system:patient:export')")
    @Log(title = "患者", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusPatient busPatient)
    {
        List<BusPatient> list = busPatientService.selectBusPatientList(busPatient);
        ExcelUtil<BusPatient> util = new ExcelUtil<BusPatient>(BusPatient.class);
        util.exportExcel(response, list, "患者数据");
    }

    /**
     * 获取患者详细信息
     */
    @ApiOperation("获取患者详细信息")
    @PreAuthorize("@ss.hasPermi('system:patient:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(busPatientService.selectBusPatientById(id));
    }

    /**
     * 新增患者
     */
    @ApiOperation("新增患者")
    @PreAuthorize("@ss.hasPermi('system:patient:add')")
    @Log(title = "患者", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusPatient busPatient)
    {
        return toAjax(busPatientService.insertBusPatient(busPatient));
    }

    /**
     * 修改患者
     */
    @ApiOperation("修改患者")
    @PreAuthorize("@ss.hasPermi('system:patient:edit')")
    @Log(title = "患者", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusPatient busPatient)
    {
        return toAjax(busPatientService.updateBusPatient(busPatient));
    }

    /**
     * 删除患者
     */
    @ApiOperation("删除患者")
    @PreAuthorize("@ss.hasPermi('system:patient:remove')")
    @Log(title = "患者", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busPatientService.deleteBusPatientByIds(ids));
    }
}
