package com.xinyilu.web.controller.testScoreBatchinfo;

import com.xinyilu.common.annotation.Log;
import com.xinyilu.common.core.controller.BaseController;
import com.xinyilu.common.core.domain.AjaxResult;
import com.xinyilu.common.core.page.TableDataInfo;
import com.xinyilu.common.custominterface.Insert;
import com.xinyilu.common.custominterface.Update;
import com.xinyilu.common.enums.BusinessType;
import com.xinyilu.common.utils.poi.ExcelUtil;
import com.xinyilu.system.domain.dto.TestScoreBatchDTO;
import com.xinyilu.system.domain.testItem.TestItems;
import com.xinyilu.system.domain.testScoreBatchinfo.TestScoreBatch;
import com.xinyilu.system.service.testScoreBatchinfo.ITestScoreBatchService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 测试成绩批次Controller
 *
 * @author xinyilu
 * @date 2022-08-02
 */
@RestController
@RequestMapping("/system/testScoreBatch")
public class TestScoreBatchController extends BaseController {
    @Resource
    private ITestScoreBatchService testScoreBatchService;

    /**
     * 查询测试成绩批次列表
     */
//    @PreAuthorize("@ss.hasPermi('system:testScoreBatch:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestScoreBatch testScoreBatch) {
        startPage();
        List<TestScoreBatch> list = testScoreBatchService.selectTestScoreBatchList(testScoreBatch);
        return getDataTable(list);
    }

    /**
     * 导出测试成绩批次列表
     */
    @PreAuthorize("@ss.hasPermi('system:testScoreBatch:export')")
    @Log(title = "测试成绩批次", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestScoreBatch testScoreBatch) {
        List<TestScoreBatch> list = testScoreBatchService.selectTestScoreBatchList(testScoreBatch);
        ExcelUtil<TestScoreBatch> util = new ExcelUtil<TestScoreBatch>(TestScoreBatch.class);
        util.exportExcel(response, list, "测试成绩批次数据");
    }

    /**
     * 获取测试成绩批次详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:testScoreBatch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(testScoreBatchService.selectTestScoreBatchById(id));
    }

    /**
     * 新增测试成绩批次
     */
    @PreAuthorize("@ss.hasPermi('system:testScoreBatch:add')")
    @Log(title = "测试成绩批次", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated(Insert.class) @RequestBody TestScoreBatchDTO testScoreBatch) {
        testScoreBatch.setCreateBy(getUsername());
        return testScoreBatchService.insertTestScoreBatch(testScoreBatch);
    }

    /**
     * 修改测试成绩批次
     */
    @PreAuthorize("@ss.hasPermi('system:testScoreBatch:edit')")
    @Log(title = "测试成绩批次", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@Validated(Update.class) @RequestBody TestScoreBatchDTO testScoreBatch) {
        testScoreBatch.setUpdateBy(getUsername());
        return testScoreBatchService.updateTestScoreBatch(testScoreBatch);
    }

    /**
     * 删除测试成绩批次
     */
    @PreAuthorize("@ss.hasPermi('system:testScoreBatch:remove')")
    @Log(title = "测试成绩批次", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return testScoreBatchService.updateTestScoreBatchByIds(ids);
    }

    /**
     * 查询测试成绩批次列表
     */
    @PreAuthorize("@ss.hasPermi('system:testScoreBatch:list')")
    @GetMapping("/temBatchInfoList")
    public TableDataInfo temBatchInfoList(Long batchId) {
        startPage();
        List<TestItems> itemBatchInfoList = testScoreBatchService.getItemBatchInfoList(batchId);
        return getDataTable(itemBatchInfoList);
    }
}
