package com.codvision.base.controller.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.codvision.base.entity.ExcelErrorRecord;
import com.codvision.base.service.IExcelErrorRecordService;
import com.codvision.commoncore.common.ResponseEntity;
import com.codvision.webcore.annotation.ApiSecret;
import com.codvision.webcore.bean.QueryPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * Excel导入异常信息记录管理
 *
 * @author lingee
 * @date 2023-11-20
 */
@Slf4j
@RestController
@RequestMapping("/v1/manager/excelErrorRecord")
@Api(tags = "平台管理端-Excel导入异常信息记录")
public class ManagerExcelErrorRecordController {

    @Resource
    private IExcelErrorRecordService service;

    @PostMapping("/findAll")
    @ApiOperation("通用查询")
    public ResponseEntity<IPage<ExcelErrorRecord>> findAll(@RequestParam(value = "reqNo") String reqNo,
                                                           @RequestParam(value = "page", required = false, defaultValue = "1") int page,
                                                           @RequestParam(value = "size", required = false, defaultValue = "10") int size) {
        ResponseEntity<IPage<ExcelErrorRecord>> responseEntity = new ResponseEntity<>();

        LambdaQueryWrapper<ExcelErrorRecord> wrapper = Wrappers.<ExcelErrorRecord>lambdaQuery().eq(ExcelErrorRecord::getReqNo, reqNo);
        IPage<ExcelErrorRecord> pageResult = service.page(new QueryPage<ExcelErrorRecord>(page, size).getPage(), wrapper);

        return responseEntity.ok().data(pageResult);
    }

    @ApiSecret(ignore = true)
    @ApiOperation("异常数据导出")
    @GetMapping("/export")
    public ResponseEntity<String> excelExport(@RequestParam(value = "reqNo") String reqNo) {
        ResponseEntity<String> responseEntity = new ResponseEntity<>();

        service.excelExport(reqNo);
        return responseEntity.ok();
    }
}

