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.V2ViewTaskCollectService;
import com.docus.server.rpc.dto.TaskMakeupDto;
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 V2ViewTaskCollectServiceImpl implements V2ViewTaskCollectService {
    @Value("${docus.url.viewtask-v2:}")
    private String v2ViewTaskServerUrl;


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