package com.ruoyi.web.controller.care;

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.care.domain.CareHospital;
import com.ruoyi.care.service.ICareHospitalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医院Controller
 * 
 * @author ruoyi
 * @date 2024-11-29
 */
@RestController
@RequestMapping("/care/hospital")
public class CareHospitalController extends BaseController
{
    @Autowired
    private ICareHospitalService careHospitalService;

    /**
     * 查询医院列表
     */
    @PreAuthorize("@ss.hasPermi('care:hospital:list')")
    @GetMapping("/list")
    public TableDataInfo list(CareHospital careHospital)
    {
        startPage();
        List<CareHospital> list = careHospitalService.selectCareHospitalList(careHospital);
        return getDataTable(list);
    }

    /**
     * 导出医院列表
     */
    @PreAuthorize("@ss.hasPermi('care:hospital:export')")
    @Log(title = "医院", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CareHospital careHospital)
    {
        List<CareHospital> list = careHospitalService.selectCareHospitalList(careHospital);
        ExcelUtil<CareHospital> util = new ExcelUtil<CareHospital>(CareHospital.class);
        util.exportExcel(response, list, "医院数据");
    }

    /**
     * 获取医院详细信息
     */
    @PreAuthorize("@ss.hasPermi('care:hospital:query')")
    @GetMapping(value = "/{hospitalId}")
    public AjaxResult getInfo(@PathVariable("hospitalId") Long hospitalId)
    {
        return success(careHospitalService.selectCareHospitalByHospitalId(hospitalId));
    }

    /**
     * 新增医院
     */
    @PreAuthorize("@ss.hasPermi('care:hospital:add')")
    @Log(title = "医院", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CareHospital careHospital)
    {
        return toAjax(careHospitalService.insertCareHospital(careHospital));
    }

    /**
     * 修改医院
     */
    @PreAuthorize("@ss.hasPermi('care:hospital:edit')")
    @Log(title = "医院", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CareHospital careHospital)
    {
        return toAjax(careHospitalService.updateCareHospital(careHospital));
    }

    /**
     * 删除医院
     */
    @PreAuthorize("@ss.hasPermi('care:hospital:remove')")
    @Log(title = "医院", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hospitalIds}")
    public AjaxResult remove(@PathVariable Long[] hospitalIds)
    {
        return toAjax(careHospitalService.deleteCareHospitalByHospitalIds(hospitalIds));
    }

    /**
     * 查询所有医院列表
     */
    @GetMapping("/listAll")
    public List<CareHospital> listAll(CareHospital careHospital)
    {
        List<CareHospital> list = careHospitalService.selectCareHospitalList(careHospital);
        return list;
    }
}
