package cn.cslg.report.controller.InvalidReReport;

import cn.cslg.report.common.core.base.Constants;
import cn.cslg.report.common.model.dto.ShareReportDTO;
import cn.cslg.report.common.utils.Response;
import cn.cslg.report.service.business.InvalidReReport.InvalidProcessService;
import cn.cslg.report.service.business.asso.AssoReportPersonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * 报告分享管理的Controller层
 *
 * @Author lrj
 * @Data 2023/4/1
 */
@Tag(name = "无效事务管理")
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping(Constants.REPORT_API + "/invalidProcess")
public class InvalidProcessController {
    private final InvalidProcessService invalidProcessService;

    @Operation(summary = "添加无效事务")
    @PostMapping("/add")
    public String add(@RequestBody String invalidProcessStr, MultipartFile file) {
        if (invalidProcessStr != null && invalidProcessStr != "") {
            invalidProcessService.addInvalidProcess(invalidProcessStr, file);
            return Response.success("添加成功");
        } else {
            return Response.error("添加失败");
        }
    }

    @Operation(summary = "删除无效事务")
    @PostMapping("/delete")
    public String delete(Integer id) {
        if(id != null && id > 0) {
            invalidProcessService.removeInvalidProcess(id);
            return Response.success("删除成功");
        } else {
            return Response.error("删除失败");
        }
    }

    @Operation(summary = "修改无效事务")
    @PostMapping("/update")
    public String update(String invalidProcessStr,MultipartFile file) throws IOException {
        if(invalidProcessStr != null && invalidProcessStr != "") {
            invalidProcessService.updateInvalidProcess(invalidProcessStr, file);
            return Response.success("修改无效事务成功");
        } else {
            return Response.error("传入数据不能为空");
        }
    }

    @Operation(summary = "查询无效事务")
    @GetMapping("/query")
    public String query(Integer reportId, Integer orderBy) throws IOException {
        if(reportId != null && reportId != 0){
            return Response.success(invalidProcessService.queryInvalidProcess(reportId, orderBy));
        } else {
            return Response.error("传入报告id不可为空");
        }
    }
}
