package com.ruoyi.mall.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mall.domain.MallImgShow;
import com.ruoyi.mall.service.IMallImgShowService;
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 ruoyi
 * @date 2022-12-07
 */
@RestController
@RequestMapping("/mall/mallImgShow")
public class MallImgShowController extends BaseController {
    @Autowired
    private IMallImgShowService mallImgShowService;

    /**
     * 查询小程序图片展示列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallImgShow:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallImgShow mallImgShow) {
        startPage();
        mallImgShow.setDelFlag("0");
        List<MallImgShow> list = mallImgShowService.selectMallImgShowList(mallImgShow);
        return getDataTable(list);
    }

    /**
     * 导出小程序图片展示列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallImgShow:export')")
    @Log(title = "小程序图片展示", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallImgShow mallImgShow) {
        List<MallImgShow> list = mallImgShowService.selectMallImgShowList(mallImgShow);
        ExcelUtil<MallImgShow> util = new ExcelUtil<MallImgShow>(MallImgShow.class);
        return util.exportExcel(list, "小程序图片展示数据");
    }

    /**
     * 获取小程序图片展示详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallImgShow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(mallImgShowService.selectMallImgShowById(id));
    }

    /**
     * 新增小程序图片展示
     */
    @PreAuthorize("@ss.hasPermi('mall:mallImgShow:add')")
    @Log(title = "小程序图片展示", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallImgShow mallImgShow) {
        return toAjax(mallImgShowService.insertMallImgShow(mallImgShow));
    }

    /**
     * 修改小程序图片展示
     */
    @PreAuthorize("@ss.hasPermi('mall:mallImgShow:edit')")
    @Log(title = "小程序图片展示", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallImgShow mallImgShow) {
        return toAjax(mallImgShowService.updateMallImgShow(mallImgShow));
    }

    /**
     * 删除小程序图片展示
     */
    @PreAuthorize("@ss.hasPermi('mall:mallImgShow:remove')")
    @Log(title = "小程序图片展示", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mallImgShowService.deleteMallImgShowByIds(ids));
    }


    /**
     * 查询小程序广告弹窗图片展示
     */
    @GetMapping("/popups")
    public AjaxResult adpopups() {
        return AjaxResult.success( mallImgShowService.selectMallImgShowadpopups());
    }
    /**
     * 查询小程序购买须知图片展示
     */
    @GetMapping("/purchasingnotice")
    public AjaxResult purchasingnotice() {
        return AjaxResult.success( mallImgShowService.selectMallpurchasingnotice());
    }
}
