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

/**
 * 病人Controller
 * 
 * @author fs
 * @date 2022-03-23
 */
@RestController
@RequestMapping("/store/patient")
public class FsPatientController extends BaseController
{
    @Autowired
    private IFsPatientService fsPatientService;

    /**
     * 查询病人列表
     */
    @PreAuthorize("@ss.hasPermi('store:patient:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsPatient fsPatient)
    {
        startPage();
        List<FsPatient> list = fsPatientService.selectFsPatientList(fsPatient);
        return getDataTable(list);
    }

    /**
     * 导出病人列表
     */
    @PreAuthorize("@ss.hasPermi('store:patient:export')")
    @Log(title = "病人", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsPatient fsPatient)
    {
        List<FsPatient> list = fsPatientService.selectFsPatientList(fsPatient);
        ExcelUtil<FsPatient> util = new ExcelUtil<FsPatient>(FsPatient.class);
        return util.exportExcel(list, "patient");
    }

    /**
     * 获取病人详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:patient:query')")
    @GetMapping(value = "/{patientId}")
    public AjaxResult getInfo(@PathVariable("patientId") Long patientId)
    {
        return AjaxResult.success(fsPatientService.selectFsPatientById(patientId));
    }

    /**
     * 新增病人
     */
    @PreAuthorize("@ss.hasPermi('store:patient:add')")
    @Log(title = "病人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsPatient fsPatient)
    {
        return toAjax(fsPatientService.insertFsPatient(fsPatient));
    }

    /**
     * 修改病人
     */
    @PreAuthorize("@ss.hasPermi('store:patient:edit')")
    @Log(title = "病人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsPatient fsPatient)
    {
        return toAjax(fsPatientService.updateFsPatient(fsPatient));
    }

    /**
     * 删除病人
     */
    @PreAuthorize("@ss.hasPermi('store:patient:remove')")
    @Log(title = "病人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{patientIds}")
    public AjaxResult remove(@PathVariable Long[] patientIds)
    {
        return toAjax(fsPatientService.deleteFsPatientByIds(patientIds));
    }
}
