package com.qmth.distributed.print.api.mark;


import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import com.qmth.teachcloud.mark.service.ScanLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * <p>
 * 扫描日志 前端控制器
 * </p>
 *
 * @author xf
 * @since 2023-12-08
 */
@Api(tags = "扫描日志上传知学知考接口")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_SCAN + "/log")
@Aac(auth = false)
public class ScanLogController {

    @Resource
    private ScanLogService scanLogService;

    /**
     * 班级阅卷进度列表查询
     */
    @ApiOperation(value = "日志文件上传")
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public Result upload(@ApiParam(value = "学校代码", required = true) @RequestParam String schoolCode,
                         @ApiParam(value = "设备编号", required = true) @RequestParam String deviceCode,
                         @ApiParam(value = "文件", required = true) @RequestParam MultipartFile file,
                         @ApiParam(value = "md5", required = true) @RequestParam String md5,
                         @ApiParam(value = "扫描账号") @RequestParam(required = false) String loginName,
                         @ApiParam(value = "错误文件类型，崩溃异常文件：COLLAPSE，正常文件：NORMAL", required = true) @RequestParam String type) {
        return ResultUtil.ok(scanLogService.uploadLogFile(schoolCode, deviceCode, file, md5, loginName, type));
    }

    /**
     * 评阅题目列表
     */
    @ApiOperation(value = "日志文件查询")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result listGroupQuestions(@ApiParam(value = "学校代码") @RequestParam(required = false) String schoolCode,
                                     @ApiParam(value = "扫描账号") @RequestParam(required = false) String loginName,
                                     @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                                     @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        return ResultUtil.ok(scanLogService.listScanLog(schoolCode, loginName, pageNumber, pageSize));
    }
}
