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.FsVessel;
import com.fs.store.service.IFsVesselService;
import com.fs.store.vo.FsVesselListVO;
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 org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 经络管理Controller
 *
 * @author fs
 * @date 2023-10-23
 */
@RestController
@RequestMapping("/his/vessel")
public class FsVesselController extends BaseController
{
    @Autowired
    private IFsVesselService fsVesselService;

    /**
     * 查询经络管理列表
     */
    @PreAuthorize("@ss.hasPermi('his:vessel:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsVessel fsVessel)
    {
        startPage();
        List<FsVesselListVO> list = fsVesselService.selectFsVesselListVO(fsVessel);
        return getDataTable(list);
    }

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


    @Log(title = "导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<FsVessel> util = new ExcelUtil<>(FsVessel.class);
        List<FsVessel> list = util.importExcel(file.getInputStream());
        String message = fsVesselService.importData(list);
        return AjaxResult.success(message);
    }
    /**
     * 导出经络管理列表
     */
    @PreAuthorize("@ss.hasPermi('his:vessel:export')")
    @Log(title = "经络管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsVessel fsVessel)
    {
        List<FsVessel> list = fsVesselService.selectFsVesselList(fsVessel);
        ExcelUtil<FsVessel> util = new ExcelUtil<FsVessel>(FsVessel.class);
        return util.exportExcel(list, "经络管理数据");
    }

    /**
     * 获取经络管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:vessel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsVesselService.selectFsVesselById(id));
    }

    /**
     * 新增经络管理
     */
    @PreAuthorize("@ss.hasPermi('his:vessel:add')")
    @Log(title = "经络管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsVessel fsVessel)
    {
        return toAjax(fsVesselService.insertFsVessel(fsVessel));
    }

    /**
     * 修改经络管理
     */
    @PreAuthorize("@ss.hasPermi('his:vessel:edit')")
    @Log(title = "经络管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsVessel fsVessel)
    {
        return toAjax(fsVesselService.updateFsVessel(fsVessel));
    }

    /**
     * 删除经络管理
     */
    @PreAuthorize("@ss.hasPermi('his:vessel:remove')")
    @Log(title = "经络管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsVesselService.deleteFsVesselByIds(ids));
    }

    @GetMapping("/allList")
    public AjaxResult getAllList()
    {
        List<OptionsVO> list = fsVesselService.selectFsVesselListOptions();
        return  AjaxResult.success(list);
    }
}
