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.FsDoctorArticleListVO;
import com.fs.his.vo.FsDoctorArticleVO;
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.FsDoctorArticle;
import com.fs.his.service.IFsDoctorArticleService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 医生文章Controller
 *
 * @author fs
 * @date 2023-06-05
 */
@RestController
@RequestMapping("/his/doctorArticle")
public class FsDoctorArticleController extends BaseController
{
    @Autowired
    private IFsDoctorArticleService fsDoctorArticleService;
    @Autowired
    RedisCache redisCache;
    /**
     * 查询医生文章列表
     */
    @PreAuthorize("@ss.hasPermi('his:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsDoctorArticle fsDoctorArticle)
    {
        startPage();
        List<FsDoctorArticleListVO> list = fsDoctorArticleService.selectFsDoctorArticleListVO(fsDoctorArticle);
        return getDataTable(list);
    }

    /**
     * 导出医生文章列表
     */
    @PreAuthorize("@ss.hasPermi('his:article:export')")
    @Log(title = "医生文章", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsDoctorArticle fsDoctorArticle)
    {
        List<FsDoctorArticle> list = fsDoctorArticleService.selectFsDoctorArticleList(fsDoctorArticle);
        ExcelUtil<FsDoctorArticle> util = new ExcelUtil<FsDoctorArticle>(FsDoctorArticle.class);
        return util.exportExcel(list, "医生文章数据");
    }

    /**
     * 获取医生文章详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:article:query')")
    @GetMapping(value = "/{articleId}")
    public AjaxResult getInfo(@PathVariable("articleId") Long articleId)
    {
        return AjaxResult.success(fsDoctorArticleService.selectFsDoctorArticleByArticleId(articleId));
    }

    /**
     * 新增医生文章
     */
    @PreAuthorize("@ss.hasPermi('his:article:add')")
    @Log(title = "医生文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsDoctorArticle fsDoctorArticle)
    {
        fsDoctorArticleService.insertFsDoctorArticle(fsDoctorArticle);
        Collection<String> keys = redisCache.keys("getDoctorArticleList*");
        for (String key : keys) {
            redisCache.deleteObject(key);
        }
        return toAjax(1);
    }

    /**
     * 修改医生文章
     */
    @PreAuthorize("@ss.hasPermi('his:article:edit')")
    @Log(title = "医生文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsDoctorArticle fsDoctorArticle)
    {
        fsDoctorArticleService.updateFsDoctorArticle(fsDoctorArticle);
        Collection<String> keys = redisCache.keys("getDoctorArticleList*");
        for (String key : keys) {
            redisCache.deleteObject(key);
        }
        return toAjax(1);
    }

    /**
     * 删除医生文章
     */
    @PreAuthorize("@ss.hasPermi('his:article:remove')")
    @Log(title = "医生文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{articleIds}")
    public AjaxResult remove(@PathVariable Long[] articleIds)
    {
        return toAjax(fsDoctorArticleService.deleteFsDoctorArticleByArticleIds(articleIds));
    }
}
