package com.fs.his.controller;

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

import com.fs.common.core.redis.RedisCache;
import com.fs.his.vo.OptionsVO;
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.FsArticleCate;
import com.fs.his.service.IFsArticleCateService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 文章分类Controller
 *
 * @author fs
 * @date 2023-07-04
 */
@RestController
@RequestMapping("/his/articleCate")
public class FsArticleCateController extends BaseController
{
    @Autowired
    private IFsArticleCateService fsArticleCateService;
    @Autowired
    RedisCache redisCache;

    /**
     * 查询文章分类列表
     */
    @PreAuthorize("@ss.hasPermi('his:articleCate:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsArticleCate fsArticleCate)
    {
        startPage();
        List<FsArticleCate> list = fsArticleCateService.selectFsArticleCateList(fsArticleCate);
        return getDataTable(list);
    }

    /**
     * 导出文章分类列表
     */
    @PreAuthorize("@ss.hasPermi('his:articleCate:export')")
    @Log(title = "文章分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsArticleCate fsArticleCate)
    {
        List<FsArticleCate> list = fsArticleCateService.selectFsArticleCateList(fsArticleCate);
        ExcelUtil<FsArticleCate> util = new ExcelUtil<FsArticleCate>(FsArticleCate.class);
        return util.exportExcel(list, "文章分类数据");
    }

    /**
     * 获取文章分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:articleCate:query')")
    @GetMapping(value = "/{cateId}")
    public AjaxResult getInfo(@PathVariable("cateId") Long cateId)
    {
        return AjaxResult.success(fsArticleCateService.selectFsArticleCateByCateId(cateId));
    }

    /**
     * 新增文章分类
     */
    @PreAuthorize("@ss.hasPermi('his:articleCate:add')")
    @Log(title = "文章分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsArticleCate fsArticleCate)
    {
        int i = fsArticleCateService.insertFsArticleCate(fsArticleCate);
        Collection<String> keys = redisCache.keys("getArticleCateList*");
        for (String key : keys) {
            redisCache.deleteObject(key);
        }
        return toAjax(i);
    }

    /**
     * 修改文章分类
     */
    @PreAuthorize("@ss.hasPermi('his:articleCate:edit')")
    @Log(title = "文章分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsArticleCate fsArticleCate)
    {
        int i = fsArticleCateService.updateFsArticleCate(fsArticleCate);
        Collection<String> keys = redisCache.keys("getArticleCateList*");
        for (String key : keys) {
            redisCache.deleteObject(key);
        }
        return toAjax(i);
    }

    /**
     * 删除文章分类
     */
    @PreAuthorize("@ss.hasPermi('his:articleCate:remove')")
    @Log(title = "文章分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cateIds}")
    public AjaxResult remove(@PathVariable Long[] cateIds)
    {
        int i = fsArticleCateService.deleteFsArticleCateByCateIds(cateIds);
        Collection<String> keys = redisCache.keys("getArticleCateList*");
        for (String key : keys) {
            redisCache.deleteObject(key);
        }
        return toAjax(i);
    }

    /**
     * 查询文章分类
     */
    @GetMapping("/allList")
    public AjaxResult allList()
    {
        List<OptionsVO> list = fsArticleCateService.selectFsArticleCateAllList();
        return AjaxResult.success(list);
    }


}
