package cn.hnthyy.thmz.service.impl.thmz;

import cn.hnthyy.thmz.service.thmz.ZyjsService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ZyjsServiceImpl implements ZyjsService {
    @Value("${wxPayOrderServiceUrl}")
    private String wxPayOrderServiceUrl;
    @Override
    public List<Map<String, Object>> getActOrders(String inpatientNo, Integer admissTimes) {
        RestTemplate restTemplate = new RestTemplate();
        Map<String, Object> httpRes = restTemplate.getForObject(wxPayOrderServiceUrl+"/dismiss/getActOrders?inpatientNo="+inpatientNo+"&admissTimes="+admissTimes, Map.class);
        if(httpRes!=null && (Integer)httpRes.get("code")==200){
            return (List<Map<String, Object>>)httpRes.get("data");
        }
        return null;
    }

    @Override
    public Map<String, Object> verification(String staffId, String inpatientNo, Integer admissTimes, Integer dismissFlag, String zjdzDatetime) {
        RestTemplate restTemplate = new RestTemplate();
        Map<String,Object> params = new HashMap<>();
        params.put("staffId",staffId);
        params.put("inpatientNo",inpatientNo);
        params.put("admissTimes",admissTimes);
        params.put("dismissFlag",dismissFlag);
        if(zjdzDatetime!=null){
            params.put("zjdzDatetime",zjdzDatetime);
        }
        return restTemplate.postForObject(wxPayOrderServiceUrl+"/dismiss/verification", params, Map.class);
    }

    @Override
    public Map<String, Object> execute(String staffId, String inpatientNo, Integer admissTimes, Integer dismissFlag, String zjdzDatetime) {
        RestTemplate restTemplate = new RestTemplate();
        Map<String,Object> params = new HashMap<>();
        params.put("staffId",staffId);
        params.put("inpatientNo",inpatientNo);
        params.put("admissTimes",admissTimes);
        params.put("dismissFlag",dismissFlag);
        if(zjdzDatetime!=null){
            params.put("zjdzDatetime",zjdzDatetime);
        }
        return restTemplate.postForObject(wxPayOrderServiceUrl+"/dismiss/execute", params, Map.class);
    }
}
