package com.docus.server.report.api.impl;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.docus.core.util.Func;
import com.docus.infrastructure.core.exception.BaseException;
import com.docus.infrastructure.web.api.CommonResult;
import com.docus.server.report.api.MedicalRecordService;
import com.docus.server.report.api.request.CqcAuditRequest;
import com.docus.server.report.config.ApplicationBusinessConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class MedicalRecordServiceImpl implements MedicalRecordService {
    @Autowired
    private ApplicationBusinessConfig businessConfig;

    @Override
    public CommonResult<String> cqcAudit(List<CqcAuditRequest> request) {
        String nisApproveUrl = businessConfig.getNisApproveUrl();
        if(Func.isBlank(nisApproveUrl)){
            throw new BaseException("未配置质控地址！");
        }
        // 地址是否已经自带参数了
        String result = HttpUtil.post(nisApproveUrl, JSON.toJSONString(request));
        return JSON.parseObject(result,new TypeReference<CommonResult<String>>(){});
    }
}
