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

import com.alibaba.fastjson.JSONArray;
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.entity.SysConfig;
import com.qmth.teachcloud.common.service.CommonCacheService;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import com.qmth.teachcloud.mark.bean.scanpackage.ScanPackageQuery;
import com.qmth.teachcloud.mark.service.ScanPackageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;

/**
 * <p>
 * 签到表 前端控制器
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@Api(tags = "扫描-签到表")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_SCAN + "/package")
public class ScanPackageController {
    @Autowired
    private CommonCacheService commonCacheService;
    @Autowired
    private ScanPackageService scanPackageService;

    @ApiOperation(value = "签到表条码识别坐标获取")
    @RequestMapping(value = "position/get", method = RequestMethod.POST)
    public Result positionGet() {
        SysConfig sysConfig = commonCacheService.addSysConfigCache(SystemConstant.PACKAGE_BARCODE_POSITION);
        String value = sysConfig.getConfigValue();
        JSONArray ja = JSONArray.parseArray(value);
        return ResultUtil.ok(ja);
    }

    @ApiOperation(value = "签到表扫描图片上传")
    @RequestMapping(value = "image/upload", method = RequestMethod.POST)
    public Result imageUpload(@RequestParam Long examId, @RequestParam String packageCode,
                              @RequestParam Integer packageNo, @RequestParam MultipartFile file, @RequestParam String md5) {
        return ResultUtil.ok(scanPackageService.imageUpload(examId, packageCode, packageNo, file, md5));
    }

    @ApiOperation(value = "签到表扫描结果列表")
    @RequestMapping(value = "image/list", method = RequestMethod.POST)
    public Result imagePage(@Validated ScanPackageQuery query) {
        return ResultUtil.ok(scanPackageService.imagePage(query));
    }

    @ApiOperation(value = "签到表编号查询")
    @RequestMapping(value = "find", method = RequestMethod.POST)
    public Result find(@RequestParam Long examId, @RequestParam String packageCode) {
        return ResultUtil.ok(scanPackageService.find(examId, packageCode));
    }

    @ApiOperation(value = "签到表详情")
    @RequestMapping(value = "image/get", method = RequestMethod.POST)
    public Result imageGet(@RequestParam Long examId, @RequestParam String coursePaperId,
                           @RequestParam String packageCode) {
        return ResultUtil.ok(scanPackageService.imageGet(examId, coursePaperId, packageCode));
    }
}
