package com.fs.hospital.controller;

import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.common.utils.SecurityUtils;
import com.fs.hospital.param.HospitalParam;
import com.fs.hospital.vo.HospitalHVO;
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.hospital.domain.Hospital;
import com.fs.hospital.service.IHospitalService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 诊所Controller
 *
 * @author fs
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/hospital/hospital")
public class HospitalController extends BaseController
{
    @Autowired
    private IHospitalService hospitalService;

    /**
     * 查询诊所列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalParam hospital)
    {
        startPage();
        List<HospitalHVO> list = hospitalService.selectHospitalListVO(hospital);
        return getDataTable(list);
    }

    /**
     * 导出诊所列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:export')")
    @Log(title = "诊所", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalParam hospital)
    {
        List<HospitalHVO> list = hospitalService.selectHospitalListVO(hospital);
        ExcelUtil<HospitalHVO> util = new ExcelUtil<HospitalHVO>(HospitalHVO.class);
        return util.exportExcel(list, "诊所数据");
    }

    /**
     * 获取诊所详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:query')")
    @GetMapping(value = "/{hospitalId}")
    public AjaxResult getInfo(@PathVariable("hospitalId") Long hospitalId)
    {
        return AjaxResult.success(hospitalService.selectHospitalByHospitalId(hospitalId));
    }

    /**
     * 新增诊所
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:add')")
    @Log(title = "诊所", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody Hospital hospital)
    {
        hospital.setPassword(SecurityUtils.encryptPassword(hospital.getPassword()));
        return hospitalService.insertHospital(hospital);
    }

    /**
     * 修改诊所
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:edit')")
    @Log(title = "诊所", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Hospital hospital)
    {
        return toAjax(hospitalService.updateHospital(hospital));
    }

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