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.MallMemberSearchHistory;
import com.ruoyi.mall.domain.MallMemberSearchHistoryDto;
import com.ruoyi.mall.service.IMallMemberSearchHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * mallController
 *
 * @author ruoyi
 * @date 2021-12-23
 */
@RestController
@RequestMapping("/mall/history")
public class MallMemberSearchHistoryController extends BaseController {
    @Autowired
    private IMallMemberSearchHistoryService mallMemberSearchHistoryService;

    /**
     * 查询mall列表
     */
    @PreAuthorize("@ss.hasPermi('mall:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallMemberSearchHistory mallMemberSearchHistory) {
        startPage();
        List<MallMemberSearchHistoryDto> list = mallMemberSearchHistoryService.selectMallMemberSearchHistoryList(mallMemberSearchHistory);
        return getDataTable(list);
    }

    /**
     * 导出mall列表
     */
    @PreAuthorize("@ss.hasPermi('mall:history:export')")
    @Log(title = "mall", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallMemberSearchHistory mallMemberSearchHistory) {
        List<MallMemberSearchHistoryDto> list = mallMemberSearchHistoryService.selectMallMemberSearchHistoryList(mallMemberSearchHistory);
        ExcelUtil<MallMemberSearchHistoryDto> util = new ExcelUtil<MallMemberSearchHistoryDto>(MallMemberSearchHistoryDto.class);
        return util.exportExcel(list, "mall数据");
    }

    /**
     * 获取mall详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(mallMemberSearchHistoryService.selectMallMemberSearchHistoryById(id));
    }

    /**
     * 新增mall
     */
    @PreAuthorize("@ss.hasPermi('mall:history:add')")
    @Log(title = "mall", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallMemberSearchHistory mallMemberSearchHistory) {
        return toAjax(mallMemberSearchHistoryService.insertMallMemberSearchHistory(mallMemberSearchHistory));
    }

    /**
     * 修改mall
     */
    @PreAuthorize("@ss.hasPermi('mall:history:edit')")
    @Log(title = "mall", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallMemberSearchHistory mallMemberSearchHistory) {
        return toAjax(mallMemberSearchHistoryService.updateMallMemberSearchHistory(mallMemberSearchHistory));
    }

    /**
     * 删除mall
     */
    @PreAuthorize("@ss.hasPermi('mall:history:remove')")
    @Log(title = "mall", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mallMemberSearchHistoryService.deleteMallMemberSearchHistoryByIds(ids));
    }
}
