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

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学校风景Controller
 *
 * @author Lsm
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/mall/mallSchoolScenery")
public class MallSchoolSceneryController extends BaseController
{
    @Autowired
    private IMallSchoolSceneryService mallSchoolSceneryService;

    /**
     * 查询学校风景列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolScenery:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallSchoolScenery mallSchoolScenery)
    {
        startPage();
        List<MallSchoolScenery> list = mallSchoolSceneryService.selectMallSchoolSceneryList(mallSchoolScenery);
        return getDataTable(list);
    }

    /**
     * 导出学校风景列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolScenery:export')")
    @Log(title = "学校风景", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallSchoolScenery mallSchoolScenery)
    {
        List<MallSchoolScenery> list = mallSchoolSceneryService.selectMallSchoolSceneryList(mallSchoolScenery);
        ExcelUtil<MallSchoolScenery> util = new ExcelUtil<MallSchoolScenery>(MallSchoolScenery.class);
        util.exportExcel(response, list, "学校风景数据");
    }

    /**
     * 获取学校风景详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolScenery:query')")
    @GetMapping(value = "/{sceneryId}")
    public AjaxResult getInfo(@PathVariable("sceneryId") Long sceneryId)
    {
        return AjaxResult.success(mallSchoolSceneryService.selectMallSchoolSceneryBySceneryId(sceneryId));
    }

    /**
     * 新增学校风景
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolScenery:add')")
    @Log(title = "学校风景", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallSchoolScenery mallSchoolScenery)
    {
        return toAjax(mallSchoolSceneryService.insertMallSchoolScenery(mallSchoolScenery));
    }

    /**
     * 修改学校风景
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolScenery:edit')")
    @Log(title = "学校风景", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallSchoolScenery mallSchoolScenery)
    {
        return toAjax(mallSchoolSceneryService.updateMallSchoolScenery(mallSchoolScenery));
    }

    /**
     * 删除学校风景
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolScenery:remove')")
    @Log(title = "学校风景", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sceneryIds}")
    public AjaxResult remove(@PathVariable Long[] sceneryIds)
    {
        return toAjax(mallSchoolSceneryService.deleteMallSchoolSceneryBySceneryIds(sceneryIds));
    }
}
