package com.fs.store.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.store.domain.FsDisease;
import com.fs.store.service.IFsDiseaseService;
import com.fs.store.vo.FsDiseaseListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 疾病Controller
 *
 * @author fs
 * @date 2023-06-01
 */
@RestController
@RequestMapping("/his/disease")
public class FsDiseaseController extends BaseController
{
    @Autowired
    private IFsDiseaseService fsDiseaseService;

    /**
     * 查询疾病列表
     */
    @PreAuthorize("@ss.hasPermi('his:disease:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsDisease fsDisease)
    {
        startPage();
        List<FsDiseaseListVO> list = fsDiseaseService.selectFsDiseaseListVO(fsDisease);
        return getDataTable(list);
    }

    /**
     * 导出疾病列表
     */
    @PreAuthorize("@ss.hasPermi('his:disease:export')")
    @Log(title = "疾病", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsDisease fsDisease)
    {
        List<FsDisease> list = fsDiseaseService.selectFsDiseaseList(fsDisease);
        ExcelUtil<FsDisease> util = new ExcelUtil<FsDisease>(FsDisease.class);
        return util.exportExcel(list, "疾病数据");
    }

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

    /**
     * 新增疾病
     */
    @PreAuthorize("@ss.hasPermi('his:disease:add')")
    @Log(title = "疾病", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsDisease fsDisease)
    {
        return toAjax(fsDiseaseService.insertFsDisease(fsDisease));
    }

    /**
     * 修改疾病
     */
    @PreAuthorize("@ss.hasPermi('his:disease:edit')")
    @Log(title = "疾病", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsDisease fsDisease)
    {
        return toAjax(fsDiseaseService.updateFsDisease(fsDisease));
    }

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