package com.fs.company.controller.store;

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.his.domain.FsPackage;
import com.fs.his.param.FsPackageParam;
import com.fs.his.service.IFsPackageService;
import com.fs.his.vo.FsPackageExcelVO;
import com.fs.his.vo.FsPackageListVO;
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-08-25
 */
@RestController
@RequestMapping("/store/package")
public class FsPackageController extends BaseController
{
    @Autowired
    private IFsPackageService fsPackageService;

    /**
     * 查询套餐包列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FsPackageParam fsPackage)
    {
        startPage();
        List<FsPackageListVO> list = fsPackageService.selectFsPackageListVO(fsPackage);
        return getDataTable(list);
    }

    /**
     * 导出套餐包列表
     */
    @Log(title = "套餐包", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsPackage fsPackage)
    {
        List<FsPackageExcelVO> list = fsPackageService.selectFsPackageListExcelVO(fsPackage);
        ExcelUtil<FsPackageExcelVO> util = new ExcelUtil<FsPackageExcelVO>(FsPackageExcelVO.class);
        return util.exportExcel(list, "套餐包数据");
    }

    /**
     * 获取套餐包详细信息
     */
    @GetMapping(value = "/{packageId}")
    public AjaxResult getInfo(@PathVariable("packageId") Long packageId)
    {
        return AjaxResult.success(fsPackageService.selectFsPackageByPackageIdVO(packageId));
    }

    /**
     * 新增套餐包
     */
    @PreAuthorize("@ss.hasPermi('store:package:add')")
    @Log(title = "套餐包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsPackage fsPackage)
    {
        return toAjax(fsPackageService.insertFsPackage(fsPackage));
    }

    /**
     * 修改套餐包
     */
    @PreAuthorize("@ss.hasPermi('store:package:edit')")
    @Log(title = "套餐包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsPackage fsPackage)
    {
        return toAjax(fsPackageService.updateFsPackage(fsPackage));
    }

    /**
     * 删除套餐包
     */
    @PreAuthorize("@ss.hasPermi('store:package:remove')")
    @Log(title = "套餐包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{packageIds}")
    public AjaxResult remove(@PathVariable Long[] packageIds)
    {
        return toAjax(fsPackageService.deleteFsPackageByPackageIds(packageIds));
    }

    /**
     * 查询套餐包列表
     */
    @GetMapping("/allList")
    public TableDataInfo getHospital()
    {
        List<OptionsVO> list = fsPackageService.selectAllPackageList();
        return getDataTable(list);
    }

    @GetMapping("/packageList/{packageName}")
    public AjaxResult packageList(@PathVariable("packageName")  String packageName)
    {
        List<FsPackageListVO> list = fsPackageService.selectFsPackageListVByName(packageName);
        return AjaxResult.success(list);
    }
}
