package com.ruoyi.mall.controller;

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

import org.checkerframework.checker.units.qual.A;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.MallBatch;
import com.ruoyi.mall.service.IMallBatchService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 录取批次Controller
 *
 * @author Lsm
 * @date 2023-10-19
 */
@RestController
@RequestMapping("/mall/mallBatch")
public class MallBatchController extends BaseController
{
    @Autowired
    private IMallBatchService mallBatchService;

    /**
     * 查询录取批次列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallBatch:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallBatch mallBatch)
    {
        startPage();
        List<MallBatch> list = mallBatchService.selectMallBatchList(mallBatch);
        return getDataTable(list);
    }

    /**
     * 导出录取批次列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallBatch:export')")
    @Log(title = "录取批次", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallBatch mallBatch)
    {
        List<MallBatch> list = mallBatchService.selectMallBatchList(mallBatch);
        ExcelUtil<MallBatch> util = new ExcelUtil<MallBatch>(MallBatch.class);
        util.exportExcel(response, list, "录取批次数据");
    }

    /**
     * 获取录取批次详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallBatch:query')")
    @GetMapping(value = "/{batchId}")
    public AjaxResult getInfo(@PathVariable("batchId") Long batchId)
    {
        return AjaxResult.success(mallBatchService.selectMallBatchByMallBatchId(batchId));
    }

    /**
     * 新增录取批次
     */
    @PreAuthorize("@ss.hasPermi('mall:mallBatch:add')")
    @Log(title = "录取批次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallBatch mallBatch)
    {
        return toAjax(mallBatchService.insertMallBatch(mallBatch));
    }

    /**
     * 修改录取批次
     */
    @PreAuthorize("@ss.hasPermi('mall:mallBatch:edit')")
    @Log(title = "录取批次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallBatch mallBatch)
    {
        return toAjax(mallBatchService.updateMallBatch(mallBatch));
    }

    /**
     * 删除录取批次
     */
    @PreAuthorize("@ss.hasPermi('mall:mallBatch:remove')")
    @Log(title = "录取批次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mallBatchIds}")
    public AjaxResult remove(@PathVariable Long[] mallBatchIds)
    {
        return toAjax(mallBatchService.deleteMallBatchByMallBatchIds(mallBatchIds));
    }

    /**
     * 所有批次列表
     * @return 结果
     */
    @GetMapping("/selectAllBatchList")
    public AjaxResult selectAllBatchList(){
        return AjaxResult.success(mallBatchService.selectAllBatchList());
    }
}
