You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
206 lines
8.9 KiB
206 lines
8.9 KiB
|
3 months ago
|
package com.ynxbd.common.service;
|
||
|
|
|
||
|
|
import com.ynxbd.common.bean.Patient;
|
||
|
|
import com.ynxbd.common.helper.common.CodeHelper;
|
||
|
|
import com.ynxbd.common.helper.common.JsonHelper;
|
||
|
|
import com.ynxbd.common.helper.http.OkHttpHelper;
|
||
|
|
import com.ynxbd.common.result.JsonResult;
|
||
|
|
import com.ynxbd.common.result.JsonResultEnum;
|
||
|
|
import com.ynxbd.common.result.ServiceException;
|
||
|
|
import com.ynxbd.wx.config.WeChatConfig;
|
||
|
|
import com.ynxbd.wx.wxfactory.AesWxHelper;
|
||
|
|
import com.ynxbd.wx.wxfactory.WxAuthHelper;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.apache.commons.lang3.ObjectUtils;
|
||
|
|
|
||
|
|
import javax.servlet.http.HttpServletRequest;
|
||
|
|
import java.util.ArrayList;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
@Slf4j
|
||
|
|
public class GMCService {
|
||
|
|
|
||
|
|
public List<Patient> queryGmcPatientList(HttpServletRequest request, String openId, String unionId) {
|
||
|
|
try {
|
||
|
|
if (WeChatConfig.IS_ENABLE_GMC && !WeChatConfig.IS_GMC_SERVER) { // 开启医共体服务 & 不为医共体主体
|
||
|
|
return new ArrayList<>();
|
||
|
|
}
|
||
|
|
if (ObjectUtils.isEmpty(openId)) {
|
||
|
|
return new ArrayList<>();
|
||
|
|
}
|
||
|
|
JsonResult jsonResult = postFormGMC(request, "/patient/queryPatientList", params -> {
|
||
|
|
params.put("openId", openId);
|
||
|
|
params.put("hospAppId", AesWxHelper.encode(WeChatConfig.GMC_APP_ID));
|
||
|
|
}, null);
|
||
|
|
if (!jsonResult.success()) {
|
||
|
|
return new ArrayList<>();
|
||
|
|
}
|
||
|
|
List<Patient> data = jsonResult.getDataMapList(Patient.class, "data");
|
||
|
|
System.out.println(JsonHelper.toJsonString(data));
|
||
|
|
return data;
|
||
|
|
} catch (Exception e) {
|
||
|
|
log.error(e.getMessage());
|
||
|
|
}
|
||
|
|
return new ArrayList<>();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 医共体绑定
|
||
|
|
*
|
||
|
|
* @param request request
|
||
|
|
* @param bindInfo 绑定信息
|
||
|
|
*/
|
||
|
|
public Patient bindGmcServer(HttpServletRequest request, Patient bindInfo) throws ServiceException {
|
||
|
|
if (!WeChatConfig.IS_ENABLE_GMC) { // 未开启医共体开关
|
||
|
|
return bindInfo;
|
||
|
|
}
|
||
|
|
// String openid = bindInfo.getOpenid();
|
||
|
|
// String hospAppId = AesWxHelper.decode(bindInfo.getEnHospAppId());
|
||
|
|
// if (ObjectUtils.isEmpty(hospAppId)) {
|
||
|
|
// throw new ServiceException("医共体子公众号id参数错误");
|
||
|
|
// }
|
||
|
|
|
||
|
|
String gmcUniqueId;
|
||
|
|
if (WeChatConfig.IS_GMC_SERVER) { // 是医共体主服务器
|
||
|
|
// if (!WeChatConfig.APP_ID.equals(hospAppId)) { // 不为自身AppId
|
||
|
|
// bindInfo.setHospAppId(hospAppId); // 需存的数据
|
||
|
|
// }
|
||
|
|
bindInfo.setGmcUniqueId(CodeHelper.get32UUID());
|
||
|
|
return bindInfo;
|
||
|
|
}
|
||
|
|
|
||
|
|
String enGmcOpenId = bindInfo.getEnGmcOpenId(); // 只有子服务器有主服务器的openId
|
||
|
|
String gmcOpenId = AesWxHelper.decode(enGmcOpenId);
|
||
|
|
|
||
|
|
log.info("[转发]enGmcOpenId={}, gmcOpenId={}", enGmcOpenId, gmcOpenId);
|
||
|
|
if (ObjectUtils.isEmpty(gmcOpenId)) {
|
||
|
|
throw new ServiceException("医共体非主体公众号ID参数异常");
|
||
|
|
}
|
||
|
|
|
||
|
|
JsonResult jsonResult = postFormGMC(request, "/healthCode/bind", params -> {
|
||
|
|
params.put("isAreaCode", false);
|
||
|
|
params.put("isFace", false);
|
||
|
|
params.put("isHealthCard", false);
|
||
|
|
|
||
|
|
params.put("openid", gmcOpenId); // 主服务器的openId
|
||
|
|
params.put("address", bindInfo.getAddress());
|
||
|
|
params.put("areaCode", bindInfo.getAreaCode());
|
||
|
|
params.put("areaAddress", bindInfo.getAreaAddress());
|
||
|
|
params.put("tel", bindInfo.getTel());
|
||
|
|
params.put("sex", bindInfo.getSex());
|
||
|
|
params.put("name", bindInfo.getName());
|
||
|
|
params.put("nation", bindInfo.getNation());
|
||
|
|
params.put("birthday", bindInfo.getBirthday());
|
||
|
|
params.put("idCardNo", bindInfo.getIdCardNo());
|
||
|
|
params.put("enOpenId", enGmcOpenId);
|
||
|
|
params.put("enUnionId", bindInfo.getEnUnionId());
|
||
|
|
params.put("hospAppId", WeChatConfig.APP_ID);
|
||
|
|
}, null);
|
||
|
|
if (!jsonResult.success()) {
|
||
|
|
throw new ServiceException(jsonResult.getMessage());
|
||
|
|
}
|
||
|
|
log.info("[医供体]绑定转发 resp={}", JsonHelper.toJsonString(jsonResult));
|
||
|
|
// JSONObject dataJson = jsonResult.dataMapGetNodeToJsonObj();
|
||
|
|
// gmcUniqueId = dataJson.getString("gmcUniqueId");
|
||
|
|
// if (ObjectUtils.isEmpty(gmcUniqueId)) {
|
||
|
|
// throw new ServiceException("医共体返回唯一id为空");
|
||
|
|
// }
|
||
|
|
// bindInfo.setGmcUniqueId(gmcUniqueId);
|
||
|
|
// if (!enGmcOpenId.equals(dataJson.getString("enOpenId"))) {
|
||
|
|
// throw new ServiceException("医共体主体openId不匹配");
|
||
|
|
// }
|
||
|
|
return bindInfo;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public static JsonResult postForm(String url, OkHttpHelper.MapParams params, OkHttpHelper.Header header) {
|
||
|
|
return OkHttpHelper.postForm(url, params, header, JsonResultEnum.SYS_COMMON);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static JsonResult postFormGMC(HttpServletRequest request, String api, OkHttpHelper.MapParams params, OkHttpHelper.Header header) {
|
||
|
|
String url = WeChatConfig.getGMCAuthDomain(WxAuthHelper.isHttpsWithProxy(request), true); // 医共体请求服务地址
|
||
|
|
return OkHttpHelper.postForm((url + api), params, header, JsonResultEnum.SYS_COMMON);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public List<Patient> updatePatientList(String openId){
|
||
|
|
|
||
|
|
return new ArrayList<>();
|
||
|
|
}
|
||
|
|
|
||
|
|
// public Patient queryGmcPatientList(HttpServletRequest request, Patient bindInfo) throws ServiceException {
|
||
|
|
// if (!WeChatConfig.IS_ENABLE_GMC) { // 不为医共体主体
|
||
|
|
// return bindInfo;
|
||
|
|
// }
|
||
|
|
// String openid = bindInfo.getOpenid();
|
||
|
|
// String hospAppId = AesWxHelper.decode(bindInfo.getEnHospAppId());
|
||
|
|
// if (ObjectUtils.isEmpty(hospAppId)) {
|
||
|
|
// throw new ServiceException("医共体子公众号id参数错误");
|
||
|
|
// }
|
||
|
|
//
|
||
|
|
// String gmcUniqueId;
|
||
|
|
// if (WeChatConfig.IS_GMC_SERVER) { // 是医共体主服务器
|
||
|
|
// if (!WeChatConfig.APP_ID.equals(hospAppId)) { // 不为自身AppId
|
||
|
|
// bindInfo.setHospAppId(hospAppId); // 需存的数据
|
||
|
|
// }
|
||
|
|
// bindInfo.setGmcUniqueId(CodeHelper.get32UUID());
|
||
|
|
//
|
||
|
|
// } else {
|
||
|
|
// String enGmcOpenId = bindInfo.getEnGmcOpenId(); // 只有子公众号有
|
||
|
|
// String gmcOpenId = AesWxHelper.decode(enGmcOpenId);
|
||
|
|
//
|
||
|
|
// log.info("[转发]enGmcOpenId={}, gmcOpenId={}", enGmcOpenId, gmcOpenId);
|
||
|
|
// if (ObjectUtils.isEmpty(gmcOpenId)) {
|
||
|
|
// throw new ServiceException("医共体非主体公众号ID参数异常");
|
||
|
|
// }
|
||
|
|
//
|
||
|
|
// JsonResult jsonResult = WxAuthHelper.postFormGMC(request, "/patient/bind", params -> {
|
||
|
|
// params.put("isAreaCode", false);
|
||
|
|
// params.put("isFace", false);
|
||
|
|
// params.put("isHealthCard", false);
|
||
|
|
//
|
||
|
|
// params.put("openid", gmcOpenId); // 主体的openid
|
||
|
|
// params.put("address", bindInfo.getAddress());
|
||
|
|
// params.put("areaCode", bindInfo.getAreaCode());
|
||
|
|
// params.put("areaAddress", bindInfo.getAreaAddress());
|
||
|
|
// params.put("tel", bindInfo.getTel());
|
||
|
|
// params.put("sex", bindInfo.getSex());
|
||
|
|
// params.put("name", bindInfo.getName());
|
||
|
|
// params.put("nation", bindInfo.getNation());
|
||
|
|
// params.put("birthday", bindInfo.getBirthday());
|
||
|
|
// params.put("idCardNo", bindInfo.getIdCardNo());
|
||
|
|
// //
|
||
|
|
// params.put("enOpenId", enGmcOpenId);
|
||
|
|
// params.put("enUnionId", bindInfo.getEnUnionId());
|
||
|
|
// params.put("enGmcOpenId", enGmcOpenId);
|
||
|
|
// params.put("enHospAppId", AesWxHelper.encode(WeChatConfig.APP_ID));
|
||
|
|
// }, null);
|
||
|
|
// if (!jsonResult.success()) {
|
||
|
|
// throw new ServiceException(jsonResult.getMessage());
|
||
|
|
// }
|
||
|
|
// log.info("[绑定转发]resp={}", JsonHelper.toJsonString(jsonResult));
|
||
|
|
//
|
||
|
|
// JSONObject dataJson = jsonResult.dataMapGetNodeToJsonObj();
|
||
|
|
// gmcUniqueId = dataJson.getString("gmcUniqueId");
|
||
|
|
// if (ObjectUtils.isEmpty(gmcUniqueId)) {
|
||
|
|
// throw new ServiceException("医共体返回唯一id为空");
|
||
|
|
// }
|
||
|
|
// bindInfo.setGmcUniqueId(gmcUniqueId);
|
||
|
|
// if (!enGmcOpenId.equals(dataJson.getString("enOpenId"))) {
|
||
|
|
// throw new ServiceException("医共体主体openId不匹配");
|
||
|
|
// }
|
||
|
|
//
|
||
|
|
// GMCUser findGMCUser = new GMCUserService().queryInfoByOpenId(openid);
|
||
|
|
// if (findGMCUser == null) {
|
||
|
|
// boolean isOK = new GMCUserService().addInfo(openid, gmcOpenId, bindInfo.getUnionId(), gmcUniqueId);
|
||
|
|
// if (!isOK) {
|
||
|
|
// log.error("[医共体关系]添加失败 openid={}, gmcOpenId={}, uuid={}", openid, gmcOpenId, gmcUniqueId);
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// return bindInfo;
|
||
|
|
// }
|
||
|
|
|
||
|
|
}
|