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.FsDepartment;
import com.fs.store.service.IFsDepartmentService;
import com.fs.his.vo.OptionsVO;
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/department")
public class FsDepartmentController extends BaseController
{
    @Autowired
    private IFsDepartmentService fsDepartmentService;

    /**
     * 查询科室列表
     */
    @PreAuthorize("@ss.hasPermi('his:department:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsDepartment fsDepartment)
    {
        startPage();
        List<FsDepartment> list = fsDepartmentService.selectFsDepartmentList(fsDepartment);
        return getDataTable(list);
    }

    /**
     * 导出科室列表
     */
    @PreAuthorize("@ss.hasPermi('his:department:export')")
    @Log(title = "科室", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsDepartment fsDepartment)
    {
        List<FsDepartment> list = fsDepartmentService.selectFsDepartmentList(fsDepartment);
        ExcelUtil<FsDepartment> util = new ExcelUtil<FsDepartment>(FsDepartment.class);
        return util.exportExcel(list, "科室数据");
    }

    /**
     * 获取科室详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:department:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(fsDepartmentService.selectFsDepartmentByDeptId(deptId));
    }

    /**
     * 新增科室
     */
    @PreAuthorize("@ss.hasPermi('his:department:add')")
    @Log(title = "科室", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsDepartment fsDepartment)
    {
        return toAjax(fsDepartmentService.insertFsDepartment(fsDepartment));
    }

    /**
     * 修改科室
     */
    @PreAuthorize("@ss.hasPermi('his:department:edit')")
    @Log(title = "科室", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsDepartment fsDepartment)
    {
        return toAjax(fsDepartmentService.updateFsDepartment(fsDepartment));
    }

    /**
     * 删除科室
     */
    @PreAuthorize("@ss.hasPermi('his:department:remove')")
    @Log(title = "科室", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(fsDepartmentService.deleteFsDepartmentByDeptIds(deptIds));
    }




    @GetMapping("/listOptions")
    public TableDataInfo listOptions()
    {
        List<OptionsVO> list = fsDepartmentService.selectFsDiseaseOptionsVO();
        return getDataTable(list);
    }
}
