package com.ruoyi.mall.controller;

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

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.mall.domain.Bo.MallSchoolAppraiseExcelBo;
import com.ruoyi.mall.domain.Bo.MallTestSchoolRecordBo;
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.MallTestSchoolRecord;
import com.ruoyi.mall.service.IMallTestSchoolRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 校考院校记录Controller
 *
 * @author ruoyi
 * @date 2023-11-01
 */
@RestController
@RequestMapping("/mall/mallTestSchoolRecord")
public class MallTestSchoolRecordController extends BaseController
{
    @Autowired
    private IMallTestSchoolRecordService mallTestSchoolRecordService;

    /**
     * 查询校考院校记录列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallTestSchoolRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallTestSchoolRecord mallTestSchoolRecord)
    {
        startPage();
        List<MallTestSchoolRecord> list = mallTestSchoolRecordService.selectMallTestSchoolRecordList(mallTestSchoolRecord);
        return getDataTable(list);
    }

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

    /**
     * 获取校考院校记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallTestSchoolRecord:query')")
    @GetMapping(value = "/{testInfoId}")
    public AjaxResult getInfo(@PathVariable("testInfoId") Long testInfoId)
    {
        return AjaxResult.success(mallTestSchoolRecordService.selectMallTestSchoolRecordByTestInfoId(testInfoId));
    }

    /**
     * 新增校考院校记录
     */
    @PreAuthorize("@ss.hasPermi('mall:mallTestSchoolRecord:add')")
    @Log(title = "校考院校记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallTestSchoolRecord mallTestSchoolRecord)
    {
        return toAjax(mallTestSchoolRecordService.insertMallTestSchoolRecord(mallTestSchoolRecord));
    }

    /**
     * 修改校考院校记录
     */
    @PreAuthorize("@ss.hasPermi('mall:mallTestSchoolRecord:edit')")
    @Log(title = "校考院校记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallTestSchoolRecord mallTestSchoolRecord)
    {
        return toAjax(mallTestSchoolRecordService.updateMallTestSchoolRecord(mallTestSchoolRecord));
    }

    /**
     * 删除校考院校记录
     */
    @PreAuthorize("@ss.hasPermi('mall:mallTestSchoolRecord:remove')")
    @Log(title = "校考院校记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{testInfoIds}")
    public AjaxResult remove(@PathVariable Long[] testInfoIds)
    {
        return toAjax(mallTestSchoolRecordService.deleteMallTestSchoolRecordByTestInfoIds(testInfoIds));
    }

    /**
     * 导入校考院校记录列表
     */
    @Log(title = "导入校考院校记录列表", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<MallTestSchoolRecordBo> util = new ExcelUtil<MallTestSchoolRecordBo>(MallTestSchoolRecordBo.class);
        List<MallTestSchoolRecordBo> list = util.importExcel(file.getInputStream());
        LoginUser loginUser = getLoginUser();
        String operName = loginUser.getUsername();
        String message = mallTestSchoolRecordService.importTestSchoolRecord(list, updateSupport, operName);
        return AjaxResult.success(message);
    }
}
