package com.fs.his.controller;

import java.util.List;

import com.fs.his.domain.FsInquiryOrder;
import com.fs.his.utils.RedisCacheUtil;
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.FsAdv;
import com.fs.his.service.IFsAdvService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 广告Controller
 *
 * @author fs
 * @date 2023-06-08
 */
@RestController
@RequestMapping("/his/adv")
public class FsAdvController extends BaseController
{
    @Autowired
    private IFsAdvService fsAdvService;
    @Autowired
    private RedisCacheUtil redisCacheUtil;
    /**
     * 查询广告列表
     */
    @PreAuthorize("@ss.hasPermi('store:adv:list') or @ss.hasPermi('his:adv:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsAdv fsAdv)
    {
        startPage();
        List<FsAdv> list = fsAdvService.selectFsAdvList(fsAdv);
        return getDataTable(list);
    }

    /**
     * 导出广告列表
     */
    @PreAuthorize("@ss.hasPermi('store:adv:export') or @ss.hasPermi('his:adv:export')")
    @Log(title = "广告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsAdv fsAdv)
    {
        List<FsAdv> list = fsAdvService.selectFsAdvList(fsAdv);
        ExcelUtil<FsAdv> util = new ExcelUtil<FsAdv>(FsAdv.class);
        return util.exportExcel(list, "广告数据");
    }

    /**
     * 获取广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:adv:query') or @ss.hasPermi('his:adv:query')")
    @GetMapping(value = "/{advId}")
    public AjaxResult getInfo(@PathVariable("advId") String advId)
    {
        //生成一段代码
        return AjaxResult.success(fsAdvService.selectFsAdvByAdvId(advId));
    }

    /**
     * 新增广告
     */
    @PreAuthorize("@ss.hasPermi('store:adv:add') or @ss.hasPermi('his:adv:add')")
    @Log(title = "广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsAdv fsAdv)
    {
        fsAdvService.insertFsAdv(fsAdv);
        redisCacheUtil.delRedisKey("getAdvList");
        redisCacheUtil.delRedisKey("getAppAdvList");

        return toAjax(1);
    }

    /**
     * 修改广告
     */
    @PreAuthorize("@ss.hasPermi('store:adv:edit') or @ss.hasPermi('his:adv:edit')")
    @Log(title = "广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsAdv fsAdv)
    {
        fsAdvService.updateFsAdv(fsAdv);
        redisCacheUtil.delRedisKey("getAdvList");
        redisCacheUtil.delRedisKey("getAppAdvList");
        return toAjax(1);
    }

    /**
     * 删除广告
     */
    @PreAuthorize("@ss.hasPermi('store:adv:remove') or @ss.hasPermi('his:adv:remove')")
    @Log(title = "广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{advIds}")
    public AjaxResult remove(@PathVariable String[] advIds)
    {
        fsAdvService.deleteFsAdvByAdvIds(advIds);
        redisCacheUtil.delRedisKey("getAdvList");
        redisCacheUtil.delRedisKey("getAppAdvList");
        return toAjax(1);
    }
}
