package com.docus.server.rpc.impl;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.docus.infrastructure.web.api.CommonResult;
import com.docus.server.rpc.SdRyHospitalRpc;
import com.docus.server.rpc.util.HttpUrlUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class SdRyHospitalRpcImpl  implements SdRyHospitalRpc {
    @Value("${docus.basic.confirmAndUpdIcuRecordStateUrl:}")
    private String confirmAndUpdIcuRecordStateUrl;

    @Override
    public CommonResult<String> confirmAndUpdIcuRecordState(String inpatientNo, Integer admissTimes) {
        Map<String, String> param = new HashMap<>(2);
        param.put("inpatientNo",inpatientNo);
        param.put("admissTimes",admissTimes.toString());
        try {
            String url = HttpUrlUtil.addUrlParam(confirmAndUpdIcuRecordStateUrl, param);
            log.info("确认重症患者并修改标识，接口{}",url);
            String resp = HttpUtil.get(url);
            log.info("确认重症患者并修改标识，接口返回：{}",resp);
           return JSON.parseObject(resp,new TypeReference<CommonResult<String>>(){});
        }catch (Exception ex){
            log.error(ex.getMessage(),ex);
            return null;
        }
    }
}
