package com.ruoyi.mall.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.MallSchoolBatchLink;
import com.ruoyi.mall.service.IMallSchoolBatchLinkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学校批次关联Controller
 * 
 * @author Lsm
 * @date 2023-10-19
 */
@RestController
@RequestMapping("/mall/link")
public class MallSchoolBatchLinkController extends BaseController
{
    @Autowired
    private IMallSchoolBatchLinkService mallSchoolBatchLinkService;

    /**
     * 查询学校批次关联列表
     */
    @PreAuthorize("@ss.hasPermi('mall:link:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallSchoolBatchLink mallSchoolBatchLink)
    {
        startPage();
        List<MallSchoolBatchLink> list = mallSchoolBatchLinkService.selectMallSchoolBatchLinkList(mallSchoolBatchLink);
        return getDataTable(list);
    }

    /**
     * 导出学校批次关联列表
     */
    @PreAuthorize("@ss.hasPermi('mall:link:export')")
    @Log(title = "学校批次关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallSchoolBatchLink mallSchoolBatchLink)
    {
        List<MallSchoolBatchLink> list = mallSchoolBatchLinkService.selectMallSchoolBatchLinkList(mallSchoolBatchLink);
        ExcelUtil<MallSchoolBatchLink> util = new ExcelUtil<MallSchoolBatchLink>(MallSchoolBatchLink.class);
        util.exportExcel(response, list, "学校批次关联数据");
    }

    /**
     * 获取学校批次关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:link:query')")
    @GetMapping(value = "/{schoolBatchId}")
    public AjaxResult getInfo(@PathVariable("schoolBatchId") Long schoolBatchId)
    {
        return AjaxResult.success(mallSchoolBatchLinkService.selectMallSchoolBatchLinkBySchoolBatchId(schoolBatchId));
    }

    /**
     * 新增学校批次关联
     */
    @PreAuthorize("@ss.hasPermi('mall:link:add')")
    @Log(title = "学校批次关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallSchoolBatchLink mallSchoolBatchLink)
    {
        return toAjax(mallSchoolBatchLinkService.insertMallSchoolBatchLink(mallSchoolBatchLink));
    }

    /**
     * 修改学校批次关联
     */
    @PreAuthorize("@ss.hasPermi('mall:link:edit')")
    @Log(title = "学校批次关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallSchoolBatchLink mallSchoolBatchLink)
    {
        return toAjax(mallSchoolBatchLinkService.updateMallSchoolBatchLink(mallSchoolBatchLink));
    }

    /**
     * 删除学校批次关联
     */
    @PreAuthorize("@ss.hasPermi('mall:link:remove')")
    @Log(title = "学校批次关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{schoolBatchIds}")
    public AjaxResult remove(@PathVariable Long[] schoolBatchIds)
    {
        return toAjax(mallSchoolBatchLinkService.deleteMallSchoolBatchLinkBySchoolBatchIds(schoolBatchIds));
    }
}
