package com.docus.server.rpc.impl;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.docus.core.util.Func;
import com.docus.infrastructure.web.api.CommonResult;
import com.docus.server.rpc.V3ViewTaskCollectService;
import com.docus.server.rpc.dto.CompensateTaskDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author YongBin Wen
 * @date 2024/8/13 17:41
 */
@Service
@Slf4j
public class V3ViewTaskCollectServiceImpl implements V3ViewTaskCollectService {
    @Value("${docus.url.viewtask-v3:}")
    private String v3ViewTaskServerUrl;

    @Override
    public CommonResult<String> compensateTask(CompensateTaskDTO dto) {
        String uri = "api/NoViewCollect/compensateTask";
        String url = v3ViewTaskServerUrl + uri;
        String body = Func.toJson(dto);
        log.info("3.0任务生成，地址：{}，参数：{}", url, body);
        String result = HttpUtil.post(url, body);
        return JSONObject.parseObject(result, new TypeReference<CommonResult<String>>() {
        });
    }
}
