|
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ynxbd.common.bean.GMCUser; |
|
|
|
import com.ynxbd.common.bean.GMCUser; |
|
|
|
import com.ynxbd.common.bean.Patient; |
|
|
|
import com.ynxbd.common.bean.Patient; |
|
|
|
import com.ynxbd.common.bean.enums.HCardTypeEnum; |
|
|
|
import com.ynxbd.common.bean.enums.HCardTypeEnum; |
|
|
|
|
|
|
|
import com.ynxbd.common.cache.GmcCacheManager; |
|
|
|
import com.ynxbd.common.dao.GMCUserDao; |
|
|
|
import com.ynxbd.common.dao.GMCUserDao; |
|
|
|
import com.ynxbd.common.dao.PatientDao; |
|
|
|
import com.ynxbd.common.dao.PatientDao; |
|
|
|
import com.ynxbd.common.dao.his.HisPatientDao; |
|
|
|
import com.ynxbd.common.dao.his.HisPatientDao; |
|
|
|
@ -45,8 +46,8 @@ public class GMCService { |
|
|
|
} |
|
|
|
} |
|
|
|
String enGmcOpenId = AesWxHelper.encode(gmcOpenId); |
|
|
|
String enGmcOpenId = AesWxHelper.encode(gmcOpenId); |
|
|
|
long begTime = System.currentTimeMillis(); |
|
|
|
long begTime = System.currentTimeMillis(); |
|
|
|
JsonResult jsonResult = postFormGMC(request, "/patient/queryPatientList", params -> { |
|
|
|
JsonResult jsonResult = postFormGMC(request, "/patient/getGmcPatientList", params -> { |
|
|
|
params.put("openId", enGmcOpenId); |
|
|
|
params.put("gmcOpenId", enGmcOpenId); |
|
|
|
params.put("hospAppId", AesWxHelper.encode(WeChatConfig.GMC_APP_ID)); |
|
|
|
params.put("hospAppId", AesWxHelper.encode(WeChatConfig.GMC_APP_ID)); |
|
|
|
}, null); |
|
|
|
}, null); |
|
|
|
if (!jsonResult.success()) { |
|
|
|
if (!jsonResult.success()) { |
|
|
|
@ -55,11 +56,19 @@ public class GMCService { |
|
|
|
throw new ServiceException("[医共体-数据同步]请求主服务失败:" + (ObjectUtils.isEmpty(message) ? "" : message)); |
|
|
|
throw new ServiceException("[医共体-数据同步]请求主服务失败:" + (ObjectUtils.isEmpty(message) ? "" : message)); |
|
|
|
} |
|
|
|
} |
|
|
|
List<Patient> gmcPatients = jsonResult.getDataMapList(Patient.class, "data"); |
|
|
|
List<Patient> gmcPatients = jsonResult.getDataMapList(Patient.class, "data"); |
|
|
|
|
|
|
|
for (Patient item : gmcPatients) { |
|
|
|
|
|
|
|
item.setTel(AesWxHelper.decode(item.getEnTel())); |
|
|
|
|
|
|
|
item.setIdCardNo(AesWxHelper.decode(item.getEnCardNo())); |
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
item.setAddress(AesWxHelper.decode(item.getAddress())); |
|
|
|
|
|
|
|
item.setBirthday(AesWxHelper.decode(item.getBirthday())); |
|
|
|
|
|
|
|
item.setHealthCardId(AesWxHelper.decode(item.getHealthCardId())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<Patient> addList = new ArrayList<>(); // 需添加用户
|
|
|
|
List<Patient> addList = new ArrayList<>(); // 需添加用户
|
|
|
|
List<Integer> removeIds = new ArrayList<>(); // 需删除用户ids
|
|
|
|
List<Integer> removeIds = new ArrayList<>(); // 需删除用户ids
|
|
|
|
|
|
|
|
|
|
|
|
List<Patient> dbPatients = new PatientDao().selectListByToken(wxOpenId, unionId); |
|
|
|
List<Patient> dbPatients = new PatientService().queryGmcCachePatientsByOpenId(wxOpenId, unionId); |
|
|
|
for (Patient item : gmcPatients) { |
|
|
|
for (Patient item : gmcPatients) { |
|
|
|
item.setId(null); |
|
|
|
item.setId(null); |
|
|
|
item.setOpenid(wxOpenId); |
|
|
|
item.setOpenid(wxOpenId); |
|
|
|
@ -73,20 +82,12 @@ public class GMCService { |
|
|
|
)).findFirst().orElse(null); |
|
|
|
)).findFirst().orElse(null); |
|
|
|
|
|
|
|
|
|
|
|
if (findDBItem == null) { // 需新增
|
|
|
|
if (findDBItem == null) { // 需新增
|
|
|
|
item.setPatientId(null); // 清空主体医院的-本院患者id
|
|
|
|
|
|
|
|
item.setHisPatientId(null); |
|
|
|
|
|
|
|
addList.add(item); |
|
|
|
addList.add(item); |
|
|
|
} else { // 比对数据
|
|
|
|
} else { // 比对数据
|
|
|
|
item.setId(findDBItem.getId()); |
|
|
|
item.setId(findDBItem.getId()); |
|
|
|
item.setPatientId(findDBItem.getPatientId()); // 本院患者id->用于新增数据
|
|
|
|
|
|
|
|
item.setHisPatientId(findDBItem.getPatientId()); // 本院患者id->用于检查数据
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!findDBItem.equalsPatient(item)) { // 数据不同->需修改本地数据
|
|
|
|
if (!findDBItem.equalsPatient(item)) { // 数据不同->需修改本地数据
|
|
|
|
removeIds.add(findDBItem.getId()); |
|
|
|
removeIds.add(findDBItem.getId()); |
|
|
|
addList.add(item); |
|
|
|
addList.add(item); |
|
|
|
} else { |
|
|
|
|
|
|
|
item.setGmcCheckTime(findDBItem.getGmcCheckTime()); // 本院的检查时间
|
|
|
|
|
|
|
|
checkGmcPatient(item); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -118,6 +119,7 @@ public class GMCService { |
|
|
|
} |
|
|
|
} |
|
|
|
if (new PatientDao().updateGmcBindState(gmcUniqueId, item.getId(), item.getEmpiId())) { |
|
|
|
if (new PatientDao().updateGmcBindState(gmcUniqueId, item.getId(), item.getEmpiId())) { |
|
|
|
log.error("[医共体]同步用户数据,修改医共体绑定状态失败 id:{}", item.getId()); |
|
|
|
log.error("[医共体]同步用户数据,修改医共体绑定状态失败 id:{}", item.getId()); |
|
|
|
|
|
|
|
item.setEmpiId(empiId); |
|
|
|
item.setGmcUniqueId(gmcUniqueId); |
|
|
|
item.setGmcUniqueId(gmcUniqueId); |
|
|
|
gmcPatients.add(item); |
|
|
|
gmcPatients.add(item); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -135,6 +137,9 @@ public class GMCService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int addRows = addDBPatients(addList); // 添加后会补充数据
|
|
|
|
int addRows = addDBPatients(addList); // 添加后会补充数据
|
|
|
|
|
|
|
|
if (addRows > 0 || delRows > 0) { |
|
|
|
|
|
|
|
GmcCacheManager.removeCacheGmcUser(wxOpenId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
long endTime = System.currentTimeMillis(); |
|
|
|
long endTime = System.currentTimeMillis(); |
|
|
|
String takeTime = (endTime - begTime) + "ms"; // 耗时
|
|
|
|
String takeTime = (endTime - begTime) + "ms"; // 耗时
|
|
|
|
@ -158,18 +163,22 @@ public class GMCService { |
|
|
|
|
|
|
|
|
|
|
|
for (Patient item : patients) { |
|
|
|
for (Patient item : patients) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (ObjectUtils.isEmpty(item.getEmpiId())) { |
|
|
|
// 清空多余id和本院id
|
|
|
|
log.info("[医共体-数据同步]本院绑定失败"); |
|
|
|
item.setPatientId(null); |
|
|
|
continue; |
|
|
|
item.setEnPatientId(null); |
|
|
|
} |
|
|
|
item.setHisPatientId(null); |
|
|
|
|
|
|
|
item.setEnHisPatientId(null); |
|
|
|
|
|
|
|
|
|
|
|
Patient hisBindInfo = hisPatientDao.bind(false, item); |
|
|
|
Patient hisBindInfo = hisPatientDao.bind(false, item); |
|
|
|
if (hisBindInfo == null) { |
|
|
|
if (hisBindInfo == null) { |
|
|
|
log.info("[医共体-数据同步]本院绑定失败"); |
|
|
|
log.info("[医共体-数据同步]本院绑定失败"); |
|
|
|
|
|
|
|
item.setIsSyncFail(false); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
String hisPatientId = hisBindInfo.getHisPatientId(); // 本院患者id
|
|
|
|
String hisPatientId = hisBindInfo.getHisPatientId(); // 本院患者id
|
|
|
|
String empiId = hisBindInfo.getEmpiId(); // 医共体id
|
|
|
|
String empiId = hisBindInfo.getEmpiId(); // 医共体id
|
|
|
|
if (ObjectUtils.isEmpty(hisPatientId) || ObjectUtils.isEmpty(empiId)) { |
|
|
|
if (ObjectUtils.isEmpty(hisPatientId) || ObjectUtils.isEmpty(empiId)) { |
|
|
|
|
|
|
|
item.setIsSyncFail(false); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
item.setGmcCheckTime(LocalDateTime.now()); |
|
|
|
item.setGmcCheckTime(LocalDateTime.now()); |
|
|
|
@ -178,6 +187,7 @@ public class GMCService { |
|
|
|
item.setEmpiId(empiId); |
|
|
|
item.setEmpiId(empiId); |
|
|
|
addList.add(item); |
|
|
|
addList.add(item); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
item.setIsSyncFail(false); |
|
|
|
log.error(e.getMessage()); |
|
|
|
log.error(e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -231,7 +241,8 @@ public class GMCService { |
|
|
|
String enGmcOpenId = bindInfo.getEnGmcOpenId(); // 认证主体的openid[县医院openid]
|
|
|
|
String enGmcOpenId = bindInfo.getEnGmcOpenId(); // 认证主体的openid[县医院openid]
|
|
|
|
String gmcOpenId = AesWxHelper.decode(enGmcOpenId); |
|
|
|
String gmcOpenId = AesWxHelper.decode(enGmcOpenId); |
|
|
|
|
|
|
|
|
|
|
|
String enOpenId = bindInfo.getEnOpenId(); // 本院openid
|
|
|
|
String openid = bindInfo.getOpenid(); // 本院openid
|
|
|
|
|
|
|
|
String enOpenId = AesWxHelper.encode(openid); |
|
|
|
|
|
|
|
|
|
|
|
log.info("[医共体绑定-转发]enGmcOpenId={}, gmcOpenId={}", enGmcOpenId, gmcOpenId); |
|
|
|
log.info("[医共体绑定-转发]enGmcOpenId={}, gmcOpenId={}", enGmcOpenId, gmcOpenId); |
|
|
|
if (ObjectUtils.isEmpty(gmcOpenId)) { |
|
|
|
if (ObjectUtils.isEmpty(gmcOpenId)) { |
|
|
|
@ -294,6 +305,8 @@ public class GMCService { |
|
|
|
log.error("[医共体]主体绑定-数据enEmpiId解密失败"); |
|
|
|
log.error("[医共体]主体绑定-数据enEmpiId解密失败"); |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 主体绑定成功后,清除本院缓存
|
|
|
|
|
|
|
|
GmcCacheManager.removeCacheGmcUser(openid); |
|
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient(); |
|
|
|
Patient patient = new Patient(); |
|
|
|
patient.setEnGmcOpenId(enGmcOpenId); // 主体医院openid
|
|
|
|
patient.setEnGmcOpenId(enGmcOpenId); // 主体医院openid
|
|
|
|
@ -324,13 +337,15 @@ public class GMCService { |
|
|
|
String gmcOpenId = gmcUser.getGmcOpenId(); |
|
|
|
String gmcOpenId = gmcUser.getGmcOpenId(); |
|
|
|
|
|
|
|
|
|
|
|
JsonResult jsonResult = postFormGMC(request, "/patient/unBind", params -> { |
|
|
|
JsonResult jsonResult = postFormGMC(request, "/patient/unBind", params -> { |
|
|
|
params.put("openid", gmcOpenId); |
|
|
|
params.put("openid", AesWxHelper.encode(gmcOpenId)); |
|
|
|
params.put("epId", epId); |
|
|
|
params.put("epId", AesWxHelper.encode(epId)); |
|
|
|
params.put("hospAppId", WeChatConfig.APP_ID); |
|
|
|
params.put("hospAppId", WeChatConfig.APP_ID); |
|
|
|
}, null); |
|
|
|
}, null); |
|
|
|
if (!jsonResult.success()) { |
|
|
|
if (!jsonResult.success()) { |
|
|
|
throw new ServiceException(jsonResult.getMessage()); |
|
|
|
throw new ServiceException(jsonResult.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 主体解绑成功后,清除本院缓存
|
|
|
|
|
|
|
|
GmcCacheManager.removeCacheGmcUser(openId); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|