package com.fs.his.controller;

import java.util.List;

import com.fs.his.vo.FsStoreProductExcelVO;
import com.fs.his.vo.OptionsVO;
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.his.domain.FsHospital;
import com.fs.his.service.IFsHospitalService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 医院Controller
 *
 * @author fs
 * @date 2023-06-01
 */
@RestController
@RequestMapping("/his/hospital")
public class FsHospitalController extends BaseController
{
    @Autowired
    private IFsHospitalService fsHospitalService;

    /**
     * 查询医院列表
     */
    @PreAuthorize("@ss.hasPermi('his:hospital:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsHospital fsHospital)
    {
        startPage();
        List<FsHospital> list = fsHospitalService.selectFsHospitalList(fsHospital);
        return getDataTable(list);
    }

    /**
     * 导出医院列表
     */
    @PreAuthorize("@ss.hasPermi('his:hospital:export')")
    @Log(title = "医院", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsHospital fsHospital)
    {
        List<FsHospital> list = fsHospitalService.selectFsHospitalList(fsHospital);
        ExcelUtil<FsHospital> util = new ExcelUtil<FsHospital>(FsHospital.class);
        return util.exportExcel(list, "医院数据");
    }
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<FsHospital> util = new ExcelUtil<>(FsHospital.class);
        return util.importTemplateExcel("导入模板");
    }

    @Log(title = "导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<FsHospital> util = new ExcelUtil<>(FsHospital.class);
        List<FsHospital> list = util.importExcel(file.getInputStream());
        String message = fsHospitalService.importData(list);
        return AjaxResult.success(message);
    }
    /**
     * 获取医院详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:hospital:query')")
    @GetMapping(value = "/{hospitalId}")
    public AjaxResult getInfo(@PathVariable("hospitalId") Long hospitalId)
    {
        return AjaxResult.success(fsHospitalService.selectFsHospitalByHospitalId(hospitalId));
    }

    /**
     * 新增医院
     */
    @PreAuthorize("@ss.hasPermi('his:hospital:add')")
    @Log(title = "医院", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsHospital fsHospital)
    {
        return toAjax(fsHospitalService.insertFsHospital(fsHospital));
    }

    /**
     * 修改医院
     */
    @PreAuthorize("@ss.hasPermi('his:hospital:edit')")
    @Log(title = "医院", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsHospital fsHospital)
    {
        return toAjax(fsHospitalService.updateFsHospital(fsHospital));
    }

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


    /**
     * 查询医院列表
     */
    @GetMapping("/allList")
    public TableDataInfo getHospital()
    {
        List<OptionsVO> list = fsHospitalService.selectAllFsHospitalList();
        return getDataTable(list);
    }


}
