package com.ruoyi.mall.controller;

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

import com.ruoyi.mall.service.IMallCountMethodService;
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.MallSchoolAcceptRecord;
import com.ruoyi.mall.service.IMallSchoolAcceptRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 院校录取数据Controller
 *
 * @author lsm
 * @date 2023-10-19
 */
@RestController
@RequestMapping("/mall/mallSchoolAcceptRecord")
public class MallSchoolAcceptRecordController extends BaseController
{
    @Autowired
    private IMallSchoolAcceptRecordService mallSchoolAcceptRecordService;
    @Resource
    private IMallCountMethodService mallCountMethodService;

    /**
     * 查询院校录取数据列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolAcceptRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallSchoolAcceptRecord mallSchoolAcceptRecord)
    {
        startPage();
        List<MallSchoolAcceptRecord> list = mallSchoolAcceptRecordService.selectMallSchoolAcceptRecordList(mallSchoolAcceptRecord);
        if (!list.isEmpty()){
            for (MallSchoolAcceptRecord schoolAcceptRecord : list) {
                String countMethodStr = mallCountMethodService.getCountMethodStr(schoolAcceptRecord.getAcceptRuleId());
                schoolAcceptRecord.setRuleStr(countMethodStr);
            }

        }
        return getDataTable(list);
    }

    /**
     * 导出院校录取数据列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolAcceptRecord:export')")
    @Log(title = "院校录取数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallSchoolAcceptRecord mallSchoolAcceptRecord)
    {
        List<MallSchoolAcceptRecord> list = mallSchoolAcceptRecordService.selectMallSchoolAcceptRecordList(mallSchoolAcceptRecord);
        ExcelUtil<MallSchoolAcceptRecord> util = new ExcelUtil<MallSchoolAcceptRecord>(MallSchoolAcceptRecord.class);
        util.exportExcel(response, list, "院校录取数据数据");
    }

    /**
     * 获取院校录取数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolAcceptRecord:query')")
    @GetMapping(value = "/{schoolAcceptRecordId}")
    public AjaxResult getInfo(@PathVariable("schoolAcceptRecordId") Long schoolAcceptRecordId)
    {
        return AjaxResult.success(mallSchoolAcceptRecordService.selectMallSchoolAcceptRecordBySchoolAcceptRecordId(schoolAcceptRecordId));
    }

    /**
     * 新增院校录取数据
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolAcceptRecord:add')")
    @Log(title = "院校录取数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallSchoolAcceptRecord mallSchoolAcceptRecord)
    {
        if (mallSchoolAcceptRecord.getAcceptLowest() == null) {
            mallSchoolAcceptRecord.setAcceptLowest(mallSchoolAcceptRecord.getLowestScore());
        }
        return toAjax(mallSchoolAcceptRecordService.insertMallSchoolAcceptRecord(mallSchoolAcceptRecord));
    }

    /**
     * 修改院校录取数据
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolAcceptRecord:edit')")
    @Log(title = "院校录取数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallSchoolAcceptRecord mallSchoolAcceptRecord)
    {
        if (mallSchoolAcceptRecord.getAcceptLowest() == null) {
            mallSchoolAcceptRecord.setAcceptLowest(mallSchoolAcceptRecord.getLowestScore());
        }
        return toAjax(mallSchoolAcceptRecordService.updateMallSchoolAcceptRecord(mallSchoolAcceptRecord));
    }

    /**
     * 删除院校录取数据
     */
    @PreAuthorize("@ss.hasPermi('mall:mallSchoolAcceptRecord:remove')")
    @Log(title = "院校录取数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{schoolAcceptRecordIds}")
    public AjaxResult remove(@PathVariable Long[] schoolAcceptRecordIds)
    {
        return toAjax(mallSchoolAcceptRecordService.deleteMallSchoolAcceptRecordBySchoolAcceptRecordIds(schoolAcceptRecordIds));
    }
}
