路泰机电科技体检——数据平台后端
zhaowenxuan
2025-06-12 493d39e60bae93a724448af7dd53e2ff10b927c8
增加新医院
2个文件已添加
1220 ■■■■■ 已修改文件
src/main/java/com/example/service/shanjianyi/shanxiqin/baoji/bjsqyy/BjsqyyHisService.java 610 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/example/service/shanjianyi/shanxiqin/baoji/ssyjyy/SsyjyyHisService.java 610 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/example/service/shanjianyi/shanxiqin/baoji/bjsqyy/BjsqyyHisService.java
New file
@@ -0,0 +1,610 @@
package com.example.service.shanjianyi.shanxiqin.baoji.bjsqyy;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.example.config.ConfigValue;
import com.example.constant.ApiParamsConstants;
import com.example.domain.DictCommonHisConfig;
import com.example.domain.HisSyncDict;
import com.example.domain.TjFlowingWaterHis;
import com.example.service.DictCommonHisConfigService;
import com.example.service.HisService;
import com.example.utils.AjaxResult;
import com.example.utils.FieldNameConverter;
import com.example.utils.HttpClientUtils;
import com.example.utils.synczd.shanjianyi.DictionaryUtilShanXiWeiNanBjxjyy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
 * @Company: 西安路泰科技有限公司
 * @Author: zhaowenxuan
 * @Date: 2025/3/18 10:17
 */
@Slf4j
@Service("ShanXiQinBaoJiBjsqyy")
public class BjsqyyHisService implements HisService {
    @Autowired
    private DictionaryUtilShanXiWeiNanBjxjyy syncZd;
    @Autowired
    private ConfigValue configValue;
//    http://oapi.xamjyy.com/OAPI/oauth/token
//    grant_type:client_credentials
//    client_id:XFZZQEfXTZ7exhhi
//    client_secret:05a192176c21edfcc9cf5fa26fc5a9e0c5b131ad
//    http://oapi.xamjyy.com/OAPI
    @Autowired
    private RedisTemplate<Object ,Object> redisTemplate;
    @Autowired
    private DictCommonHisConfigService dictCommonHisConfigService;
    //获取token
    private JSONObject getToken () {
        String GRANT_TYPE = "client_credentials";
        String CLIENT_ID = "XFZZQEfXTZ7exhhi";
        String CLIENT_SECRET = "05a192176c21edfcc9cf5fa26fc5a9e0c5b131ad";
        Map<String, Object> map = new HashMap<>();
        map.put("grant_type", GRANT_TYPE);
        map.put("client_id", CLIENT_ID);
        map.put("client_secret", CLIENT_SECRET);
//        map.put("scope",SCOP);
//        String post = sendPostTokenFormUrlencoded (HIS_URL+"/oauth/token", map);
        String his_url = dictCommonHisConfigService.getConfigValByHospitalAndKey("bjsqyy", "HIS_URL");
        String post = HttpClientUtils.sendPostTokenFormUrlencoded(his_url + "/oauth/token", map, null);
        if (StrUtil.isBlank(post)) return null;
        return JSONUtil.parseObj(post);
    }
    @Override
    public String jianDang(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("jiuZhenKh", params.get(ApiParamsConstants.CARD_ID));
        map.put ("kaiLeiXing","4");
        map.put ("xingMing", params.get(ApiParamsConstants.CUS_NAME));
        long cusSex = Long.parseLong(params.get(ApiParamsConstants.CUS_SEX).toString());
        if(cusSex==0L){
            map.put ("xingBie","男");
        }else if(cusSex==1L){
            map.put ("xingBie","女");
        }else {
            map.put ("xingBie","未知");
        }
        map.put ("shenFenZh", params.get(ApiParamsConstants.CUS_ID_CARD));
        map.put ("danWeiBh",params.get(ApiParamsConstants.COMP_ID));
        map.put ("chuShengRq", params.get(ApiParamsConstants.CUS_BRITHDAY));
        map.put ("lianXiDz", params.get(ApiParamsConstants.CUS_ADDR));
        map.put ("lianXiDh", params.get(ApiParamsConstants.CUS_PHONE));
        map.put ("feiYongLb","");
        map.put ("feiYongXz","");
        map.put ("jiLuLy","3");
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        map.put ("caoZuoYuan",config.getCzyId());
        map.put ("chongZhiJe","");
        map.put ("yiBaoKh","");
        map.put ("geRenBh","");
        map.put ("yiBaoBrXx","");
        map.put ("gongZuoDw",params.get(ApiParamsConstants.COMP_NAME));
        map.put ("canBaoXzMc","");
        map.put ("muLuBlLb","");
        map.put ("kunNanJzDj","");
        map.put ("yiLiaoLb","");
        map.put ("minZuDm","");
        map.put ("minZuMc","");
//        职业编码
        String post = sendPost(config.getHisUrl() + "/menZhenJz/jianDang", map);
        JSONObject jsonObject = JSONUtil.parseObj(post);
        if (jsonObject.getStr("returnCode").equals("1")) {
            JSONObject obj = JSONUtil.createObj();
            obj.putOpt("code","200");
            obj.putOpt("data",jsonObject.getJSONObject("returnData"));
            return JSONUtil.toJsonStr(obj);
        }else {
            JSONObject obj = JSONUtil.createObj();
            obj.putOpt("code","500");
            return JSONUtil.toJsonStr(obj);
        }
    }
    @Override
    public String getBingRenXxByShengFenZheng(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        map.put ("caoZuoYuan",config.getCzyId());
        map.put ("shenFenZh", params.get(ApiParamsConstants.CUS_ID_CARD));
        map.put ("danWeiBh",params.get(ApiParamsConstants.COMP_ID));
        //职业编码
        String string = sendPostTokenFormUrlencoded(config.getHisUrl() + "/menZhenJz/getBingRenXxByShengFenZheng", map);
        JSONObject object = JSONUtil.createObj();
        if (StrUtil.isBlank(string)){
            object.putOpt("code",500);
            return JSONUtil.toJsonStr(object);
        }
        JSONObject entries = JSONUtil.parseObj(string);
        log.info("获取病人信息返回数据 ->{}", entries);
        Object returnData = entries.get("returnData");
        if (null != returnData && !returnData.toString().equals("null")) {
            HashMap<String, String> hashMap = new HashMap<>();
            JSONArray returnData1 = entries.getJSONArray("returnData");
            JSONObject jsonObject = (JSONObject) returnData1.get(0);
            hashMap.put(ApiParamsConstants.CARD_ID,jsonObject.getStr("jiuZhenKh"));
            hashMap.put(ApiParamsConstants.PATIONID,jsonObject.getStr("bingRenId"));
            object.putOpt("code",200);
            object.putOpt("data",hashMap);
            return JSONUtil.toJsonStr(object);
        }else {
            object.putOpt("code",404);
        }
        return JSONUtil.toJsonStr(object);
    }
    @Override
    public String saveBingRenXx(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("bingRenId", params.get(ApiParamsConstants.PATIONID));
        map.put ("kaiLeiXing","4");
        map.put("jiuZhenKh",params.get(ApiParamsConstants.CARD_ID));
        map.put ("xingMing", params.get(ApiParamsConstants.CUS_NAME));
        Long cusSex = Long.parseLong(params.get(ApiParamsConstants.CUS_SEX).toString());
        if (cusSex == 0L) {
            map.put("xingBie", "男");
        } else if (cusSex == 1L) {
            map.put("xingBie", "女");
        } else {
            map.put("xingBie", "未知");
        }
        map.put ("shenFenZh", params.get(ApiParamsConstants.CUS_ID_CARD));
        map.put ("danWeiBh","");
        map.put ("chuShengRq", params.get(ApiParamsConstants.CUS_BRITHDAY));
        map.put ("lianXiDz", params.get(ApiParamsConstants.CUS_ADDR));
        map.put ("lianXiDh", params.get(ApiParamsConstants.CUS_PHONE));
        map.put ("feiYongLb","");
        map.put ("feiYongXz","");
        map.put ("jiLuLy","3");
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        map.put ("caoZuoYuan",config.getCzyId());
        //职业编码
        String post = sendPost(config.getHisUrl() + "/menZhenJz/saveBingRenXx", map);
        JSONObject jsonObject = JSONUtil.parseObj(post);
        if (jsonObject.getStr("returnCode").equals("1")) {
            JSONObject obj = JSONUtil.createObj();
            obj.putOpt("code","200");
            obj.putOpt("data",jsonObject.getJSONObject("returnData"));
            return JSONUtil.toJsonStr(obj);
        }else {
            JSONObject obj = JSONUtil.createObj();
            obj.putOpt("code","500");
            return JSONUtil.toJsonStr(obj);
        }
    }
    @Override
    public String getListDaiShouFei(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("bingRenId",params.get(ApiParamsConstants.PATIONID));
        map.put ("jiuZhenKh",params.get(ApiParamsConstants.CARD_ID));
        map.put ("yuanQuId","1");
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        String post = sendPost(config.getHisUrl() + "/shouFei/getListDaiShouFei", map);
        JSONObject jsonObject = JSONUtil.parseObj(post);
        if (jsonObject.getStr("returnCode").equals("1")) {
            JSONObject data = jsonObject.getJSONObject("returnData");
            JSONArray list = data.getJSONArray("dtoMzFeiyong1List");
            JSONArray list1 = data.getJSONArray("dtoMzFeiYong2List");
            JSONObject result = JSONUtil.createObj();
            result.putOpt("list1",list);
            result.putOpt("list2",list1);
            return AjaxResult.success(result);
        }else {
            return AjaxResult.error(post);
        }
    }
    @Override
    public String createMenZhenFy(Map<String, Object> params) {
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        Map<String, Object> map = new HashMap<> ();
        map.put ("bingRenId",params.get(ApiParamsConstants.PATIONID));
        map.put ("jiuZhenKh",params.get(ApiParamsConstants.CARD_ID));
        map.put ("caoZuoYuan",config.getCzyId());
        map.put ("yuanQuId","1");
        map.put ("yingYongId","870101");
        map.put ("kaiDanKs",config.getKdks());
        map.put ("dengJiLsh",params.get(ApiParamsConstants.Tj_NUM));
        map.put ("shouTuiBz",params.get(ApiParamsConstants.SHOU_TUI_STATUS));
        map.put ("feiYongMxList",params.get(ApiParamsConstants.FEI_YONG_INFO_LIST));
        //职业编码
        String post = sendPost(config.getHisUrl() + "/shouFei/createMenZhenFy", map);
        JSONObject jsonObject = JSONUtil.parseObj(post);
        if (jsonObject.getInt("returnCode") != 1) return AjaxResult.error(post);
        JSONObject data = jsonObject.getJSONObject("returnData");
        JSONObject result = JSONUtil.createObj();
        result.putOpt(ApiParamsConstants.PATIONID,data.getStr(ApiParamsConstants.PATIONID));
        result.putOpt(ApiParamsConstants.FEI_YONG_ID,data.getStr(ApiParamsConstants.FEI_YONG_ID));
        JSONArray feiYongMxList = data.getJSONArray("feiYongMxList");
        ArrayList<TjFlowingWaterHis> tjFlowingWaterHis = new ArrayList<>();
        for (Object o : feiYongMxList) {
            JSONObject entries = (JSONObject) o;
            TjFlowingWaterHis waterHis = new TjFlowingWaterHis();
            waterHis.setId(IdUtil.getSnowflakeNextId());
            waterHis.setParentId(data.getStr(ApiParamsConstants.FEI_YONG_ID));
            waterHis.setCurrentId(entries.getStr("feiYongMxId"));
            waterHis.setXmId(entries.getStr("xiangMuId"));
            tjFlowingWaterHis.add(waterHis);
        }
        result.putOpt("mxList",tjFlowingWaterHis);
        return AjaxResult.success(result);
    }
    @Override
    public String cheXiaoMzFy(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("bingRenId",params.get(ApiParamsConstants.PATIONID));
        map.put ("jiuZhenKh",params.get(ApiParamsConstants.CARD_ID));
        ArrayList<JSONObject> ids = new ArrayList<>();
        String string = params.get(ApiParamsConstants.FEI_YONG_ID_LIST).toString();
        String[] split = string.split(",");
        Arrays.stream(split).forEach(i -> {
            JSONObject object = JSONUtil.createObj();
            object.putOpt("feiYongId",i);
            ids.add(object);
        });
        map.put ("feiYongIdList",ids);
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        //职业编码
        String post = sendPost(config.getHisUrl() + "/shouFei/cheXiaoMzFy", map);
        JSONObject entries = JSONUtil.parseObj(post);
        if (entries.getStr("returnCode").equals("1"))
            return AjaxResult.success();
        else return AjaxResult.error(post);
    }
    @Override
    public String getKeShi(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("yuanQuId","1");
        map.put ("keShiMc",params.get(ApiParamsConstants.DEPT_NAME));
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getKeShi", map);
    }
    @Override
    public String getListYiShengZd(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("yuanQuId","1");
        map.put ("keShiMc",params.get(ApiParamsConstants.DEPT_NAME));
        map.put ("bianGengSj","");
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getListYiShengZd", map);
    }
    @Override
    public String getShouFeiXm(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("queryString",params.get(ApiParamsConstants.COMMON_QUERY_KEY));
        map.put ("bianGengSj","");
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getShouFeiXm", map);
    }
    @Override
    public String getKeShiByConditions(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("xingZhiSx","");
        map.put ("queryString",params.get(ApiParamsConstants.COMMON_QUERY_KEY));
        map.put ("zuoFeiBz",params.get(ApiParamsConstants.DEPT_ZUOFEI_STATUS));
        map.put ("yuanQuId","1");
        map.put ("keShiIds",params.get(ApiParamsConstants.DEPT_IDS));
        map.put ("ifPlus","");
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getKeShiByConditions", map);
    }
    @Override
    public String getYangBen(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("queryString",params.get(ApiParamsConstants.COMMON_QUERY_KEY));
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getYangBen", map);
    }
    @Override
    public String getListBingQuZd(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("yuanQuId",params.get(ApiParamsConstants.YUANQU_ID));
        map.put ("keShiId",params.get(ApiParamsConstants.DEPT_ID));
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getListBingQuZd", map);
    }
    @Override
    public String getZhiGongPage(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("bianGengSj","");
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getZhiGongPage", map);
    }
    @Override
    public String getJianChaXm(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("queryString",params.get(ApiParamsConstants.COMMON_QUERY_KEY));
        map.put ("bianGengSj","");
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getJianChaXm", map);
    }
    @Override
    public String getJianYanXm(Map<String, Object> map) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("queryCode",map.get(ApiParamsConstants.COMMON_QUERY_KEY));
        hashMap.put("page",map.get(ApiParamsConstants.PAGE_INDEX));
        hashMap.put("size",map.get(ApiParamsConstants.PAGE_SIZE));
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getJianYanXm", hashMap);
    }
    @Override
    public String getShouFeiXmJg(Map<String, Object> map) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("shouFeiXmId",map.get(ApiParamsConstants.COMMON_QUERY_KEY));
        hashMap.put("jiaGeTx",map.get(ApiParamsConstants.COMMON_QUERY_KEY2));
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getShouFeiXmJg", hashMap);
    }
    @Override
    public String getRongQi(Map<String, Object> map) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("queryString",map.get(ApiParamsConstants.COMMON_QUERY_KEY));
        hashMap.put("pageIndex",map.get(ApiParamsConstants.PAGE_INDEX));
        hashMap.put("pageSize",map.get(ApiParamsConstants.PAGE_SIZE));
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getRongQi", hashMap);
    }
    @Override
    public String getJyYangBen(Map<String, Object> map) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("queryString",map.get(ApiParamsConstants.COMMON_QUERY_KEY));
        hashMap.put("pageIndex",map.get(ApiParamsConstants.PAGE_INDEX));
        hashMap.put("pageSize",map.get(ApiParamsConstants.PAGE_SIZE));
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getYangBen", hashMap);
    }
    @Override
    public String pushZhiFuMsg(String hospName,Map<String, Object> params) {
        log.info("回调触发 ->{}",params);
        configValue.refresh();
        Map<String, Object> map = new HashMap<> ();
        map.put ("feiYongId",params.get("feiyongid"));
        String string = params.get("status").toString();
        if (!string.equals("1"))
            string = "2";
        map.put ("yeWuLx",string);
        // 参数类型区分
        map.put("type","1");
        HashMap<String, Object> headers = new HashMap<>();
        headers.put("hospId","bjsqyy");
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        String post = HttpClientUtils.sendPost(config.getTjUrl() + "/callBack/pushZhiFuMsg", map,headers);
        JSONObject jsonObject = JSONUtil.parseObj(post);
        JSONObject obj = JSONUtil.createObj();
        if (jsonObject.getStr("code").equals("200")) {
            obj.putOpt("returnCode",1);
            obj.putOpt("exceptionContent","");
            obj.putOpt("returnData",null);
        }else {
            obj.putOpt("returnCode",0);
            obj.putOpt("exceptionContent",jsonObject.getStr("msg"));
            obj.putOpt("returnData",null);
        }
        return JSONUtil.toJsonStr(obj);
    }
    private String sendPost(String url, Map<String, Object> hashMap){
        Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:shanxiqinbjsqyy");
        if (entries != null && !entries.isEmpty()) {
            String timeStr = entries.get("time").toString();
            String expiresInStr = entries.get("expires_in").toString();
            long time = Long.parseLong(timeStr);
            long expiresIn = Long.parseLong(expiresInStr);
            Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn);
            Instant now = Instant.now();
            if (now.isAfter(tokenExpirationTime)){
                return refreshToken(url,hashMap,"json");
            }else {
                String accessToken = entries.get("access_token").toString();
                String tokenType = entries.get("token_type").toString();
                String string = HttpClientUtils.sendPostToken(url, hashMap, tokenType + " " + accessToken);
                if(StrUtil.isNotBlank(string)){
                    JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string));
                    return JSONUtil.toJsonStr(json);
                } else return JSONUtil.createObj().toString();
            }
        }else {
            return refreshToken(url, hashMap,"json");
        }
    }
    private String sendPostTokenFormUrlencoded(String url, Map<String, Object> hashMap){
        Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:shanxiqinbjsqyy");
        if (!entries.isEmpty()) {
            String timeStr = entries.get("time").toString();
            String expiresInStr = entries.get("expires_in").toString();
            long time = Long.parseLong(timeStr);
            long expiresIn = Long.parseLong(expiresInStr);
            Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn);
            Instant now = Instant.now();
            if (now.isAfter(tokenExpirationTime)){
                return refreshToken(url,hashMap,"url");
            }else {
                String accessToken = entries.get("access_token").toString();
                String tokenType = entries.get("token_type").toString();
                String string = HttpClientUtils.sendPostTokenFormUrlencoded(url, hashMap, tokenType + " " + accessToken);
                return StrUtil.isNotBlank(string) ? string : JSONUtil.createObj().toString();
            }
        }else {
            return refreshToken(url, hashMap,"url");
        }
    }
    private String sendPostTokenFormData(String url, Map<String, Object> hashMap){
        Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:shanxiqinbjsqyy");
        if (entries != null && !entries.isEmpty()) {
            String timeStr = entries.get("time").toString();
            String expiresInStr = entries.get("expires_in").toString();
            long time = Long.parseLong(timeStr);
            long expiresIn = Long.parseLong(expiresInStr);
            Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn);
            Instant now = Instant.now();
            if (now.isAfter(tokenExpirationTime)){
                return refreshToken(url,hashMap,"form");
            }else {
                String accessToken = entries.get("access_token").toString();
                String tokenType = entries.get("token_type").toString();
                String string = HttpClientUtils.sendPostTokenFormData(url, hashMap, tokenType + " " + accessToken);
                if(StrUtil.isNotBlank(string)){
                    JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string));
                    return JSONUtil.toJsonStr(json);
                }else return JSONUtil.createObj().toString();
            }
        }else {
            return refreshToken(url, hashMap,"form");
        }
    }
    private String refreshToken(String url, Map<String, Object> hashMap,String type) {
        JSONObject parseObj = getToken();
        if (parseObj != null) {
            Integer expiresIn = parseObj.getInt("expires_in");
            if (expiresIn != null) {
                parseObj.putOpt("time", Instant.now().getEpochSecond());
                redisTemplate.opsForHash().putAll("token:his:shanxiqinbjsqyy", parseObj);
                redisTemplate.expire("token:his:shanxiqinbjsqyy", expiresIn - 10, TimeUnit.SECONDS);
                String accessToken = parseObj.getStr("access_token");
                String tokenType = parseObj.getStr("token_type");
                switch (type){
                    case "json":
                        String string = HttpClientUtils.sendPostToken(url, hashMap, tokenType + " " + accessToken);
                        if(StrUtil.isNotBlank(string)){
                            JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string));
                            return JSONUtil.toJsonStr(json);
                        } else return JSONUtil.createObj().toString();
                    case "form":
                        String string1 = HttpClientUtils.sendPostTokenFormData(url, hashMap, tokenType + " " + accessToken);
                        if(StrUtil.isNotBlank(string1)){
                            JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string1));
                            return JSONUtil.toJsonStr(json);
                        } else return JSONUtil.createObj().toString();
                    case "url":
                        String string2 = HttpClientUtils.sendPostTokenFormUrlencoded(url, hashMap, tokenType + " " + accessToken);
                        if(StrUtil.isNotBlank(string2)){
                            JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string2));
                            return JSONUtil.toJsonStr(json);
                        } else return JSONUtil.createObj().toString();
                }
            }
        }
        return JSONUtil.createObj().toString();
    }
    @Override
    public void syncDict(String hospName) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("hosp","shanxiqinbjsqyy");
        HashMap<String, Object> headers = new HashMap<>();
        headers.put("hospId","bjsqyy");
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjsqyy");
        String post = HttpClientUtils.sendPost(config.getTjUrl() + "/callBack/getZdList", map,headers);
        JSONArray jsonArray = JSONUtil.parseObj(post).getJSONArray("data");
        if (jsonArray != null && !jsonArray.isEmpty()) {
            List<HisSyncDict> list = jsonArray.toList(HisSyncDict.class);
            String token = "";
            Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:shanxiqinbjsqyy");
            if (!entries.isEmpty()) {
                String timeStr = entries.get("time").toString();
                String expiresInStr = entries.get("expires_in").toString();
                long time = Long.parseLong(timeStr);
                Long expiresIn = Long.parseLong(expiresInStr);
                Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn);
                Instant now = Instant.now();
                if (now.isAfter(tokenExpirationTime)){
                    JSONObject parseObj = getToken();
                    if (parseObj != null) {
                        expiresIn = parseObj.getLong("expires_in");
                        if (expiresIn != null) {
                            parseObj.putOpt("time", Instant.now().getEpochSecond());
                            redisTemplate.opsForHash().putAll("token:his:shanxiqinbjsqyy", parseObj);
                            redisTemplate.expire("token:his:shanxiqinbjsqyy", expiresIn - 10, TimeUnit.SECONDS);
                            String accessToken = parseObj.getStr("access_token");
                            String tokenType = parseObj.getStr("token_type");
                            token = tokenType + " " + accessToken;
                        }
                    }
                }else {
                    String accessToken = entries.get("access_token").toString();
                    String tokenType = entries.get("token_type").toString();
                    token = tokenType + " " + accessToken;
                }
            }else {
                JSONObject parseObj = getToken();
                if (parseObj != null) {
                    Integer expiresIn = parseObj.getInt("expires_in");
                    if (expiresIn != null) {
                        parseObj.putOpt("time", Instant.now().getEpochSecond());
                        redisTemplate.opsForHash().putAll("token:his:shanxiqinbjsqyy", parseObj);
                        redisTemplate.expire("token:his:shanxiqinbjsqyy", expiresIn - 10, TimeUnit.SECONDS);
                        String accessToken = parseObj.getStr("access_token");
                        String tokenType = parseObj.getStr("token_type");
                        token = tokenType + " " + accessToken;
                    }
                }
            }
            if (StrUtil.isNotBlank(token))
                syncZd.exec(list, token);
        }
    }
}
src/main/java/com/example/service/shanjianyi/shanxiqin/baoji/ssyjyy/SsyjyyHisService.java
New file
@@ -0,0 +1,610 @@
package com.example.service.shanjianyi.shanxiqin.baoji.ssyjyy;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.example.config.ConfigValue;
import com.example.constant.ApiParamsConstants;
import com.example.domain.DictCommonHisConfig;
import com.example.domain.HisSyncDict;
import com.example.domain.TjFlowingWaterHis;
import com.example.service.DictCommonHisConfigService;
import com.example.service.HisService;
import com.example.utils.AjaxResult;
import com.example.utils.FieldNameConverter;
import com.example.utils.HttpClientUtils;
import com.example.utils.synczd.shanjianyi.DictionaryUtilShanXiWeiNanBjxjyy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
 * @Company: 西安路泰科技有限公司
 * @Author: zhaowenxuan
 * @Date: 2025/3/18 10:17
 */
@Slf4j
@Service("ShanXiQinBaoJiSsyjyy")
public class SsyjyyHisService implements HisService {
    @Autowired
    private DictionaryUtilShanXiWeiNanBjxjyy syncZd;
    @Autowired
    private ConfigValue configValue;
//    http://oapi.xamjyy.com/OAPI/oauth/token
//    grant_type:client_credentials
//    client_id:XFZZQEfXTZ7exhhi
//    client_secret:05a192176c21edfcc9cf5fa26fc5a9e0c5b131ad
//    http://oapi.xamjyy.com/OAPI
    @Autowired
    private RedisTemplate<Object ,Object> redisTemplate;
    @Autowired
    private DictCommonHisConfigService dictCommonHisConfigService;
    //获取token
    private JSONObject getToken () {
        String GRANT_TYPE = "client_credentials";
        String CLIENT_ID = "XFZZQEfXTZ7exhhi";
        String CLIENT_SECRET = "05a192176c21edfcc9cf5fa26fc5a9e0c5b131ad";
        Map<String, Object> map = new HashMap<>();
        map.put("grant_type", GRANT_TYPE);
        map.put("client_id", CLIENT_ID);
        map.put("client_secret", CLIENT_SECRET);
//        map.put("scope",SCOP);
//        String post = sendPostTokenFormUrlencoded (HIS_URL+"/oauth/token", map);
        String his_url = dictCommonHisConfigService.getConfigValByHospitalAndKey("ssyjyy", "HIS_URL");
        String post = HttpClientUtils.sendPostTokenFormUrlencoded(his_url + "/oauth/token", map, null);
        if (StrUtil.isBlank(post)) return null;
        return JSONUtil.parseObj(post);
    }
    @Override
    public String jianDang(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("jiuZhenKh", params.get(ApiParamsConstants.CARD_ID));
        map.put ("kaiLeiXing","4");
        map.put ("xingMing", params.get(ApiParamsConstants.CUS_NAME));
        long cusSex = Long.parseLong(params.get(ApiParamsConstants.CUS_SEX).toString());
        if(cusSex==0L){
            map.put ("xingBie","男");
        }else if(cusSex==1L){
            map.put ("xingBie","女");
        }else {
            map.put ("xingBie","未知");
        }
        map.put ("shenFenZh", params.get(ApiParamsConstants.CUS_ID_CARD));
        map.put ("danWeiBh",params.get(ApiParamsConstants.COMP_ID));
        map.put ("chuShengRq", params.get(ApiParamsConstants.CUS_BRITHDAY));
        map.put ("lianXiDz", params.get(ApiParamsConstants.CUS_ADDR));
        map.put ("lianXiDh", params.get(ApiParamsConstants.CUS_PHONE));
        map.put ("feiYongLb","");
        map.put ("feiYongXz","");
        map.put ("jiLuLy","3");
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        map.put ("caoZuoYuan",config.getCzyId());
        map.put ("chongZhiJe","");
        map.put ("yiBaoKh","");
        map.put ("geRenBh","");
        map.put ("yiBaoBrXx","");
        map.put ("gongZuoDw",params.get(ApiParamsConstants.COMP_NAME));
        map.put ("canBaoXzMc","");
        map.put ("muLuBlLb","");
        map.put ("kunNanJzDj","");
        map.put ("yiLiaoLb","");
        map.put ("minZuDm","");
        map.put ("minZuMc","");
//        职业编码
        String post = sendPost(config.getHisUrl() + "/menZhenJz/jianDang", map);
        JSONObject jsonObject = JSONUtil.parseObj(post);
        if (jsonObject.getStr("returnCode").equals("1")) {
            JSONObject obj = JSONUtil.createObj();
            obj.putOpt("code","200");
            obj.putOpt("data",jsonObject.getJSONObject("returnData"));
            return JSONUtil.toJsonStr(obj);
        }else {
            JSONObject obj = JSONUtil.createObj();
            obj.putOpt("code","500");
            return JSONUtil.toJsonStr(obj);
        }
    }
    @Override
    public String getBingRenXxByShengFenZheng(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        map.put ("caoZuoYuan",config.getCzyId());
        map.put ("shenFenZh", params.get(ApiParamsConstants.CUS_ID_CARD));
        map.put ("danWeiBh",params.get(ApiParamsConstants.COMP_ID));
        //职业编码
        String string = sendPostTokenFormUrlencoded(config.getHisUrl() + "/menZhenJz/getBingRenXxByShengFenZheng", map);
        JSONObject object = JSONUtil.createObj();
        if (StrUtil.isBlank(string)){
            object.putOpt("code",500);
            return JSONUtil.toJsonStr(object);
        }
        JSONObject entries = JSONUtil.parseObj(string);
        log.info("获取病人信息返回数据 ->{}", entries);
        Object returnData = entries.get("returnData");
        if (null != returnData && !returnData.toString().equals("null")) {
            HashMap<String, String> hashMap = new HashMap<>();
            JSONArray returnData1 = entries.getJSONArray("returnData");
            JSONObject jsonObject = (JSONObject) returnData1.get(0);
            hashMap.put(ApiParamsConstants.CARD_ID,jsonObject.getStr("jiuZhenKh"));
            hashMap.put(ApiParamsConstants.PATIONID,jsonObject.getStr("bingRenId"));
            object.putOpt("code",200);
            object.putOpt("data",hashMap);
            return JSONUtil.toJsonStr(object);
        }else {
            object.putOpt("code",404);
        }
        return JSONUtil.toJsonStr(object);
    }
    @Override
    public String saveBingRenXx(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("bingRenId", params.get(ApiParamsConstants.PATIONID));
        map.put ("kaiLeiXing","4");
        map.put("jiuZhenKh",params.get(ApiParamsConstants.CARD_ID));
        map.put ("xingMing", params.get(ApiParamsConstants.CUS_NAME));
        Long cusSex = Long.parseLong(params.get(ApiParamsConstants.CUS_SEX).toString());
        if (cusSex == 0L) {
            map.put("xingBie", "男");
        } else if (cusSex == 1L) {
            map.put("xingBie", "女");
        } else {
            map.put("xingBie", "未知");
        }
        map.put ("shenFenZh", params.get(ApiParamsConstants.CUS_ID_CARD));
        map.put ("danWeiBh","");
        map.put ("chuShengRq", params.get(ApiParamsConstants.CUS_BRITHDAY));
        map.put ("lianXiDz", params.get(ApiParamsConstants.CUS_ADDR));
        map.put ("lianXiDh", params.get(ApiParamsConstants.CUS_PHONE));
        map.put ("feiYongLb","");
        map.put ("feiYongXz","");
        map.put ("jiLuLy","3");
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        map.put ("caoZuoYuan",config.getCzyId());
        //职业编码
        String post = sendPost(config.getHisUrl() + "/menZhenJz/saveBingRenXx", map);
        JSONObject jsonObject = JSONUtil.parseObj(post);
        if (jsonObject.getStr("returnCode").equals("1")) {
            JSONObject obj = JSONUtil.createObj();
            obj.putOpt("code","200");
            obj.putOpt("data",jsonObject.getJSONObject("returnData"));
            return JSONUtil.toJsonStr(obj);
        }else {
            JSONObject obj = JSONUtil.createObj();
            obj.putOpt("code","500");
            return JSONUtil.toJsonStr(obj);
        }
    }
    @Override
    public String getListDaiShouFei(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("bingRenId",params.get(ApiParamsConstants.PATIONID));
        map.put ("jiuZhenKh",params.get(ApiParamsConstants.CARD_ID));
        map.put ("yuanQuId","1");
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        String post = sendPost(config.getHisUrl() + "/shouFei/getListDaiShouFei", map);
        JSONObject jsonObject = JSONUtil.parseObj(post);
        if (jsonObject.getStr("returnCode").equals("1")) {
            JSONObject data = jsonObject.getJSONObject("returnData");
            JSONArray list = data.getJSONArray("dtoMzFeiyong1List");
            JSONArray list1 = data.getJSONArray("dtoMzFeiYong2List");
            JSONObject result = JSONUtil.createObj();
            result.putOpt("list1",list);
            result.putOpt("list2",list1);
            return AjaxResult.success(result);
        }else {
            return AjaxResult.error(post);
        }
    }
    @Override
    public String createMenZhenFy(Map<String, Object> params) {
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        Map<String, Object> map = new HashMap<> ();
        map.put ("bingRenId",params.get(ApiParamsConstants.PATIONID));
        map.put ("jiuZhenKh",params.get(ApiParamsConstants.CARD_ID));
        map.put ("caoZuoYuan",config.getCzyId());
        map.put ("yuanQuId","1");
        map.put ("yingYongId","870101");
        map.put ("kaiDanKs",config.getKdks());
        map.put ("dengJiLsh",params.get(ApiParamsConstants.Tj_NUM));
        map.put ("shouTuiBz",params.get(ApiParamsConstants.SHOU_TUI_STATUS));
        map.put ("feiYongMxList",params.get(ApiParamsConstants.FEI_YONG_INFO_LIST));
        //职业编码
        String post = sendPost(config.getHisUrl() + "/shouFei/createMenZhenFy", map);
        JSONObject jsonObject = JSONUtil.parseObj(post);
        if (jsonObject.getInt("returnCode") != 1) return AjaxResult.error(post);
        JSONObject data = jsonObject.getJSONObject("returnData");
        JSONObject result = JSONUtil.createObj();
        result.putOpt(ApiParamsConstants.PATIONID,data.getStr(ApiParamsConstants.PATIONID));
        result.putOpt(ApiParamsConstants.FEI_YONG_ID,data.getStr(ApiParamsConstants.FEI_YONG_ID));
        JSONArray feiYongMxList = data.getJSONArray("feiYongMxList");
        ArrayList<TjFlowingWaterHis> tjFlowingWaterHis = new ArrayList<>();
        for (Object o : feiYongMxList) {
            JSONObject entries = (JSONObject) o;
            TjFlowingWaterHis waterHis = new TjFlowingWaterHis();
            waterHis.setId(IdUtil.getSnowflakeNextId());
            waterHis.setParentId(data.getStr(ApiParamsConstants.FEI_YONG_ID));
            waterHis.setCurrentId(entries.getStr("feiYongMxId"));
            waterHis.setXmId(entries.getStr("xiangMuId"));
            tjFlowingWaterHis.add(waterHis);
        }
        result.putOpt("mxList",tjFlowingWaterHis);
        return AjaxResult.success(result);
    }
    @Override
    public String cheXiaoMzFy(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("bingRenId",params.get(ApiParamsConstants.PATIONID));
        map.put ("jiuZhenKh",params.get(ApiParamsConstants.CARD_ID));
        ArrayList<JSONObject> ids = new ArrayList<>();
        String string = params.get(ApiParamsConstants.FEI_YONG_ID_LIST).toString();
        String[] split = string.split(",");
        Arrays.stream(split).forEach(i -> {
            JSONObject object = JSONUtil.createObj();
            object.putOpt("feiYongId",i);
            ids.add(object);
        });
        map.put ("feiYongIdList",ids);
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        //职业编码
        String post = sendPost(config.getHisUrl() + "/shouFei/cheXiaoMzFy", map);
        JSONObject entries = JSONUtil.parseObj(post);
        if (entries.getStr("returnCode").equals("1"))
            return AjaxResult.success();
        else return AjaxResult.error(post);
    }
    @Override
    public String getKeShi(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("yuanQuId","1");
        map.put ("keShiMc",params.get(ApiParamsConstants.DEPT_NAME));
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getKeShi", map);
    }
    @Override
    public String getListYiShengZd(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("yuanQuId","1");
        map.put ("keShiMc",params.get(ApiParamsConstants.DEPT_NAME));
        map.put ("bianGengSj","");
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getListYiShengZd", map);
    }
    @Override
    public String getShouFeiXm(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("queryString",params.get(ApiParamsConstants.COMMON_QUERY_KEY));
        map.put ("bianGengSj","");
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getShouFeiXm", map);
    }
    @Override
    public String getKeShiByConditions(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("xingZhiSx","");
        map.put ("queryString",params.get(ApiParamsConstants.COMMON_QUERY_KEY));
        map.put ("zuoFeiBz",params.get(ApiParamsConstants.DEPT_ZUOFEI_STATUS));
        map.put ("yuanQuId","1");
        map.put ("keShiIds",params.get(ApiParamsConstants.DEPT_IDS));
        map.put ("ifPlus","");
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getKeShiByConditions", map);
    }
    @Override
    public String getYangBen(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("queryString",params.get(ApiParamsConstants.COMMON_QUERY_KEY));
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getYangBen", map);
    }
    @Override
    public String getListBingQuZd(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("yuanQuId",params.get(ApiParamsConstants.YUANQU_ID));
        map.put ("keShiId",params.get(ApiParamsConstants.DEPT_ID));
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getListBingQuZd", map);
    }
    @Override
    public String getZhiGongPage(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("bianGengSj","");
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getZhiGongPage", map);
    }
    @Override
    public String getJianChaXm(Map<String, Object> params) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("queryString",params.get(ApiParamsConstants.COMMON_QUERY_KEY));
        map.put ("bianGengSj","");
        map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX));
        map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE));
        //职业编码
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getJianChaXm", map);
    }
    @Override
    public String getJianYanXm(Map<String, Object> map) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("queryCode",map.get(ApiParamsConstants.COMMON_QUERY_KEY));
        hashMap.put("page",map.get(ApiParamsConstants.PAGE_INDEX));
        hashMap.put("size",map.get(ApiParamsConstants.PAGE_SIZE));
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getJianYanXm", hashMap);
    }
    @Override
    public String getShouFeiXmJg(Map<String, Object> map) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("shouFeiXmId",map.get(ApiParamsConstants.COMMON_QUERY_KEY));
        hashMap.put("jiaGeTx",map.get(ApiParamsConstants.COMMON_QUERY_KEY2));
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getShouFeiXmJg", hashMap);
    }
    @Override
    public String getRongQi(Map<String, Object> map) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("queryString",map.get(ApiParamsConstants.COMMON_QUERY_KEY));
        hashMap.put("pageIndex",map.get(ApiParamsConstants.PAGE_INDEX));
        hashMap.put("pageSize",map.get(ApiParamsConstants.PAGE_SIZE));
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getRongQi", hashMap);
    }
    @Override
    public String getJyYangBen(Map<String, Object> map) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("queryString",map.get(ApiParamsConstants.COMMON_QUERY_KEY));
        hashMap.put("pageIndex",map.get(ApiParamsConstants.PAGE_INDEX));
        hashMap.put("pageSize",map.get(ApiParamsConstants.PAGE_SIZE));
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        return sendPost(config.getHisUrl()+"/zhuShuJu/getYangBen", hashMap);
    }
    @Override
    public String pushZhiFuMsg(String hospName,Map<String, Object> params) {
        log.info("回调触发 ->{}",params);
        configValue.refresh();
        Map<String, Object> map = new HashMap<> ();
        map.put ("feiYongId",params.get("feiyongid"));
        String string = params.get("status").toString();
        if (!string.equals("1"))
            string = "2";
        map.put ("yeWuLx",string);
        // 参数类型区分
        map.put("type","1");
        HashMap<String, Object> headers = new HashMap<>();
        headers.put("hospId","ssyjyy");
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        String post = HttpClientUtils.sendPost(config.getTjUrl() + "/callBack/pushZhiFuMsg", map,headers);
        JSONObject jsonObject = JSONUtil.parseObj(post);
        JSONObject obj = JSONUtil.createObj();
        if (jsonObject.getStr("code").equals("200")) {
            obj.putOpt("returnCode",1);
            obj.putOpt("exceptionContent","");
            obj.putOpt("returnData",null);
        }else {
            obj.putOpt("returnCode",0);
            obj.putOpt("exceptionContent",jsonObject.getStr("msg"));
            obj.putOpt("returnData",null);
        }
        return JSONUtil.toJsonStr(obj);
    }
    private String sendPost(String url, Map<String, Object> hashMap){
        Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:shanxiqinssyjyy");
        if (entries != null && !entries.isEmpty()) {
            String timeStr = entries.get("time").toString();
            String expiresInStr = entries.get("expires_in").toString();
            long time = Long.parseLong(timeStr);
            long expiresIn = Long.parseLong(expiresInStr);
            Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn);
            Instant now = Instant.now();
            if (now.isAfter(tokenExpirationTime)){
                return refreshToken(url,hashMap,"json");
            }else {
                String accessToken = entries.get("access_token").toString();
                String tokenType = entries.get("token_type").toString();
                String string = HttpClientUtils.sendPostToken(url, hashMap, tokenType + " " + accessToken);
                if(StrUtil.isNotBlank(string)){
                    JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string));
                    return JSONUtil.toJsonStr(json);
                } else return JSONUtil.createObj().toString();
            }
        }else {
            return refreshToken(url, hashMap,"json");
        }
    }
    private String sendPostTokenFormUrlencoded(String url, Map<String, Object> hashMap){
        Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:shanxiqinssyjyy");
        if (!entries.isEmpty()) {
            String timeStr = entries.get("time").toString();
            String expiresInStr = entries.get("expires_in").toString();
            long time = Long.parseLong(timeStr);
            long expiresIn = Long.parseLong(expiresInStr);
            Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn);
            Instant now = Instant.now();
            if (now.isAfter(tokenExpirationTime)){
                return refreshToken(url,hashMap,"url");
            }else {
                String accessToken = entries.get("access_token").toString();
                String tokenType = entries.get("token_type").toString();
                String string = HttpClientUtils.sendPostTokenFormUrlencoded(url, hashMap, tokenType + " " + accessToken);
                return StrUtil.isNotBlank(string) ? string : JSONUtil.createObj().toString();
            }
        }else {
            return refreshToken(url, hashMap,"url");
        }
    }
    private String sendPostTokenFormData(String url, Map<String, Object> hashMap){
        Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:shanxiqinssyjyy");
        if (entries != null && !entries.isEmpty()) {
            String timeStr = entries.get("time").toString();
            String expiresInStr = entries.get("expires_in").toString();
            long time = Long.parseLong(timeStr);
            long expiresIn = Long.parseLong(expiresInStr);
            Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn);
            Instant now = Instant.now();
            if (now.isAfter(tokenExpirationTime)){
                return refreshToken(url,hashMap,"form");
            }else {
                String accessToken = entries.get("access_token").toString();
                String tokenType = entries.get("token_type").toString();
                String string = HttpClientUtils.sendPostTokenFormData(url, hashMap, tokenType + " " + accessToken);
                if(StrUtil.isNotBlank(string)){
                    JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string));
                    return JSONUtil.toJsonStr(json);
                }else return JSONUtil.createObj().toString();
            }
        }else {
            return refreshToken(url, hashMap,"form");
        }
    }
    private String refreshToken(String url, Map<String, Object> hashMap,String type) {
        JSONObject parseObj = getToken();
        if (parseObj != null) {
            Integer expiresIn = parseObj.getInt("expires_in");
            if (expiresIn != null) {
                parseObj.putOpt("time", Instant.now().getEpochSecond());
                redisTemplate.opsForHash().putAll("token:his:shanxiqinssyjyy", parseObj);
                redisTemplate.expire("token:his:shanxiqinssyjyy", expiresIn - 10, TimeUnit.SECONDS);
                String accessToken = parseObj.getStr("access_token");
                String tokenType = parseObj.getStr("token_type");
                switch (type){
                    case "json":
                        String string = HttpClientUtils.sendPostToken(url, hashMap, tokenType + " " + accessToken);
                        if(StrUtil.isNotBlank(string)){
                            JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string));
                            return JSONUtil.toJsonStr(json);
                        } else return JSONUtil.createObj().toString();
                    case "form":
                        String string1 = HttpClientUtils.sendPostTokenFormData(url, hashMap, tokenType + " " + accessToken);
                        if(StrUtil.isNotBlank(string1)){
                            JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string1));
                            return JSONUtil.toJsonStr(json);
                        } else return JSONUtil.createObj().toString();
                    case "url":
                        String string2 = HttpClientUtils.sendPostTokenFormUrlencoded(url, hashMap, tokenType + " " + accessToken);
                        if(StrUtil.isNotBlank(string2)){
                            JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string2));
                            return JSONUtil.toJsonStr(json);
                        } else return JSONUtil.createObj().toString();
                }
            }
        }
        return JSONUtil.createObj().toString();
    }
    @Override
    public void syncDict(String hospName) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("hosp","shanxiqinssyjyy");
        HashMap<String, Object> headers = new HashMap<>();
        headers.put("hospId","ssyjyy");
        DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("ssyjyy");
        String post = HttpClientUtils.sendPost(config.getTjUrl() + "/callBack/getZdList", map,headers);
        JSONArray jsonArray = JSONUtil.parseObj(post).getJSONArray("data");
        if (jsonArray != null && !jsonArray.isEmpty()) {
            List<HisSyncDict> list = jsonArray.toList(HisSyncDict.class);
            String token = "";
            Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:shanxiqinssyjyy");
            if (!entries.isEmpty()) {
                String timeStr = entries.get("time").toString();
                String expiresInStr = entries.get("expires_in").toString();
                long time = Long.parseLong(timeStr);
                Long expiresIn = Long.parseLong(expiresInStr);
                Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn);
                Instant now = Instant.now();
                if (now.isAfter(tokenExpirationTime)){
                    JSONObject parseObj = getToken();
                    if (parseObj != null) {
                        expiresIn = parseObj.getLong("expires_in");
                        if (expiresIn != null) {
                            parseObj.putOpt("time", Instant.now().getEpochSecond());
                            redisTemplate.opsForHash().putAll("token:his:shanxiqinssyjyy", parseObj);
                            redisTemplate.expire("token:his:shanxiqinssyjyy", expiresIn - 10, TimeUnit.SECONDS);
                            String accessToken = parseObj.getStr("access_token");
                            String tokenType = parseObj.getStr("token_type");
                            token = tokenType + " " + accessToken;
                        }
                    }
                }else {
                    String accessToken = entries.get("access_token").toString();
                    String tokenType = entries.get("token_type").toString();
                    token = tokenType + " " + accessToken;
                }
            }else {
                JSONObject parseObj = getToken();
                if (parseObj != null) {
                    Integer expiresIn = parseObj.getInt("expires_in");
                    if (expiresIn != null) {
                        parseObj.putOpt("time", Instant.now().getEpochSecond());
                        redisTemplate.opsForHash().putAll("token:his:shanxiqinssyjyy", parseObj);
                        redisTemplate.expire("token:his:shanxiqinssyjyy", expiresIn - 10, TimeUnit.SECONDS);
                        String accessToken = parseObj.getStr("access_token");
                        String tokenType = parseObj.getStr("token_type");
                        token = tokenType + " " + accessToken;
                    }
                }
            }
            if (StrUtil.isNotBlank(token))
                syncZd.exec(list, token);
        }
    }
}