package com.fs.his.controller;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.fs.common.core.redis.RedisCache;
import com.fs.his.param.FsPackageCateUParam;
import com.fs.his.vo.OptionsVO;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
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.FsPackageCate;
import com.fs.his.service.IFsPackageCateService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 套餐包分类Controller
 *
 * @author fs
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/his/packageCate")
public class FsPackageCateController extends BaseController
{
    @Autowired
    private IFsPackageCateService fsPackageCateService;
    @Autowired
    RedisCache redisCache;
    /**
     * 查询套餐包分类列表
     */
    @PreAuthorize("@ss.hasPermi('his:packageCate:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsPackageCateUParam fsPackageCate)
    {
        startPage();
        List<FsPackageCate> list = fsPackageCateService.selectFsPackageCateList(fsPackageCate);
        return getDataTable(list);
    }

    /**
     * 导出套餐包分类列表
     */
    @PreAuthorize("@ss.hasPermi('his:packageCate:export')")
    @Log(title = "套餐包分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsPackageCateUParam fsPackageCate)
    {
        List<FsPackageCate> list = fsPackageCateService.selectFsPackageCateList(fsPackageCate);
        ExcelUtil<FsPackageCate> util = new ExcelUtil<FsPackageCate>(FsPackageCate.class);
        return util.exportExcel(list, "套餐包分类数据");
    }

    /**
     * 获取套餐包分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:packageCate:query')")
    @GetMapping(value = "/{cateId}")
    public AjaxResult getInfo(@PathVariable("cateId") Long cateId)
    {
        return AjaxResult.success(fsPackageCateService.selectFsPackageCateByCateId(cateId));
    }

    /**
     * 新增套餐包分类
     */
    @PreAuthorize("@ss.hasPermi('his:packageCate:add')")
    @Log(title = "套餐包分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsPackageCate fsPackageCate)
    {
        fsPackageCateService.insertFsPackageCate(fsPackageCate);
//        Collection<String> keys = redisCache.keys("getPackagCateList*");
//        for (String key : keys) {
//            redisCache.deleteObject(key);
//        }
        return toAjax(1);
    }

    /**
     * 修改套餐包分类
     */
    @PreAuthorize("@ss.hasPermi('his:packageCate:edit')")
    @Log(title = "套餐包分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsPackageCate fsPackageCate)
    {
        fsPackageCateService.updateFsPackageCate(fsPackageCate);
//        Collection<String> keys = redisCache.keys("getPackagCateList*");
//        for (String key : keys) {
//            redisCache.deleteObject(key);
//        }
        return toAjax(1);
    }

    /**
     * 删除套餐包分类
     */
    @PreAuthorize("@ss.hasPermi('his:packageCate:remove')")
    @Log(title = "套餐包分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cateIds}")
    public AjaxResult remove(@PathVariable Long[] cateIds)
    {
        return toAjax(fsPackageCateService.deleteFsPackageCateByCateIds(cateIds));
    }


    @GetMapping("/allList")
    public AjaxResult allList()
    {
        Map map = fsPackageCateService.selectFsArticleCateAllList();
        return AjaxResult.success(map);
    }
    @GetMapping("/cateList")
    public TableDataInfo cateList()
    {
        List<OptionsVO> list = fsPackageCateService.selectCateList();
        return getDataTable(list);
    }
}
