package cn.cslg.report.controller;

import cn.cslg.report.common.core.base.Constants;

import cn.cslg.report.common.utils.Response;
import cn.cslg.report.entity.CompareRecords;
import cn.cslg.report.entity.InvalidRecord;
import cn.cslg.report.service.business.CompareRecordsService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@Tag(name = "对比记录")
@RestController
@RequestMapping(Constants.REPORT_API + "/CompareRecords")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
@SuppressWarnings({"all"})
public class CompareRecordsController {
    private final CompareRecordsService compareRecordsService;

    @PostMapping(value = "/addCompareRecords")
    @Operation(summary = "增加对比记录数据")
    public String addCompareRecords(String jsons, List<MultipartFile> files)throws IOException{
        CompareRecords compareRecords = JSONObject.parseObject(jsons,CompareRecords.class);
        return compareRecordsService.addCompareRecord(compareRecords,files);
    }
    @RequestMapping(value = "/deleCompareRecords", method = RequestMethod.GET)
    @Operation(summary = "删除对比记录数据")
    public String deleCompareRecords(Integer id) throws IOException{
        return compareRecordsService. deleCompareRecords(Arrays.asList(id));
    }

    @PostMapping(value = "/updateCompareRecords")
    @Operation(summary = "修改对比记录数据")
    @Transactional(rollbackFor = Exception.class)
    public String updateCompareRecords(String jsons, List<MultipartFile> files) throws IOException{
        CompareRecords compareRecords = JSONObject.parseObject(jsons,CompareRecords.class);
        return compareRecordsService.updateCompareRecords(compareRecords,files);

    }
    @PostMapping(value = "/selectCompareRecord")
    @Operation(summary ="查询对比记录")
    public String getCompareRecords(@RequestBody CompareRecords compareRecord)throws IOException{

      return compareRecordsService.getCompareRecords(compareRecord);
    }

    }




