package com.fs.his.controller;

import java.util.List;

import com.fs.his.domain.FsChineseMedicine;
import com.fs.his.vo.FsInquiryDiseaseVO;
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.FsInquiryDisease;
import com.fs.his.service.IFsInquiryDiseaseService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 问诊疾病Controller
 *
 * @author fs
 * @date 2024-08-02
 */
@RestController
@RequestMapping("/his/inquiryDisease")
public class FsInquiryDiseaseController extends BaseController
{
    @Autowired
    private IFsInquiryDiseaseService fsInquiryDiseaseService;

    /**
     * 查询问诊疾病列表
     */
    @PreAuthorize("@ss.hasPermi('his:inquiryDisease:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsInquiryDisease fsInquiryDisease)
    {
        startPage();
        List<FsInquiryDisease> list = fsInquiryDiseaseService.selectFsInquiryDiseaseList(fsInquiryDisease);
        return getDataTable(list);
    }

    /**
     * 导出问诊疾病列表
     */
    @PreAuthorize("@ss.hasPermi('his:inquiryDisease:export')")
    @Log(title = "问诊疾病", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsInquiryDisease fsInquiryDisease)
    {
        List<FsInquiryDisease> list = fsInquiryDiseaseService.selectFsInquiryDiseaseList(fsInquiryDisease);
        ExcelUtil<FsInquiryDisease> util = new ExcelUtil<FsInquiryDisease>(FsInquiryDisease.class);
        return util.exportExcel(list, "问诊疾病数据");
    }

    /**
     * 获取问诊疾病详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:inquiryDisease:query')")
    @GetMapping(value = "/{diseaseId}")
    public AjaxResult getInfo(@PathVariable("diseaseId") Long diseaseId)
    {
        return AjaxResult.success(fsInquiryDiseaseService.selectFsInquiryDiseaseByDiseaseId(diseaseId));
    }

    /**
     * 新增问诊疾病
     */
    @PreAuthorize("@ss.hasPermi('his:inquiryDisease:add')")
    @Log(title = "问诊疾病", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsInquiryDisease fsInquiryDisease)
    {
        return toAjax(fsInquiryDiseaseService.insertFsInquiryDisease(fsInquiryDisease));
    }

    /**
     * 修改问诊疾病
     */
    @PreAuthorize("@ss.hasPermi('his:inquiryDisease:edit')")
    @Log(title = "问诊疾病", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsInquiryDisease fsInquiryDisease)
    {
        return toAjax(fsInquiryDiseaseService.updateFsInquiryDisease(fsInquiryDisease));
    }

    /**
     * 删除问诊疾病
     */
    @PreAuthorize("@ss.hasPermi('his:inquiryDisease:remove')")
    @Log(title = "问诊疾病", businessType = BusinessType.DELETE)
	@DeleteMapping("/{diseaseIds}")
    public AjaxResult remove(@PathVariable Long[] diseaseIds)
    {
        return toAjax(fsInquiryDiseaseService.deleteFsInquiryDiseaseByDiseaseIds(diseaseIds));
    }

    @GetMapping("/listBySearch")
    public TableDataInfo listBySearch(FsInquiryDisease fsInquiryDisease)
    {
        startPage();
        List<FsInquiryDiseaseVO> list = fsInquiryDiseaseService.selectFsInquiryDiseaseListVO(fsInquiryDisease);
        return getDataTable(list);
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<FsInquiryDisease> util = new ExcelUtil<>(FsInquiryDisease.class);
        return util.importTemplateExcel("导入模板");
    }

    @Log(title = "导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<FsInquiryDisease> util = new ExcelUtil<>(FsInquiryDisease.class);
        List<FsInquiryDisease> list = util.importExcel(file.getInputStream());
        String message = fsInquiryDiseaseService.importData(list);
        return AjaxResult.success(message);
    }
}
