From dc4df9a530016c4fd24f9aebc6ccf1b95310ff1f Mon Sep 17 00:00:00 2001 From: yxh <172933527@qq.com> Date: 星期三, 02 七月 2025 11:13:06 +0800 Subject: [PATCH] Changes --- smartor/src/main/java/com/smartor/service/impl/ExternalInfoServiceImpl.java | 229 ++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 137 insertions(+), 92 deletions(-) diff --git a/smartor/src/main/java/com/smartor/service/impl/ExternalInfoServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ExternalInfoServiceImpl.java index e5007ef..ee6a7a5 100644 --- a/smartor/src/main/java/com/smartor/service/impl/ExternalInfoServiceImpl.java +++ b/smartor/src/main/java/com/smartor/service/impl/ExternalInfoServiceImpl.java @@ -15,6 +15,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.Period; @@ -583,105 +584,149 @@ */ @Override public Boolean getExternalLeaveHospPatientInfo30Day() { - String startTime = null; - String endTime = null; - Date date = patMedInhospMapper.selectEndtimeMax(); - if (ObjectUtils.isNotEmpty(date)) { - Date now = new Date(); - // 浣跨敤Calendar璁$畻30澶╁墠 - Calendar cal = Calendar.getInstance(); - cal.setTime(now); - cal.add(Calendar.DAY_OF_MONTH, -30); - Date before30Days = cal.getTime(); - - + try { + // 鍥哄畾寮�濮嬫椂闂� + String fixedStartTime = "2025-03-25"; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); -// startTime = formatter.format(date); -// startTime = formatter.format(before30Days); - startTime = "2025-03-25"; - endTime = formatter.format(new Date()); - } - List<ExternalLeaveHospPatientInfo> externalLeaveHospPatientInfo = externalInfoMapper.getExternalLeaveHospPatientInfo(startTime, endTime); - for (ExternalLeaveHospPatientInfo externalLeaveHospPatientInfo1 : externalLeaveHospPatientInfo) { - //鍏堝鎮h�呭熀鏈俊鎭繘琛屽鐞� - Long patid = dealPatArchive(externalLeaveHospPatientInfo1.getBrid()); - //鏂板鍑洪櫌鏁版嵁 - //鏍规嵁浣忛櫌鍙锋煡璇㈠叆闄俊鎭� - PatMedInhosp pmi = new PatMedInhosp(); - pmi.setInhospno(externalLeaveHospPatientInfo1.getZybm()); - List<PatMedInhosp> patMedInhospList = patMedInhospMapper.selectPatMedInhospList2(pmi); - log.error("閫氳繃浣忛櫌鍙凤細{}锛屾煡璇㈡偅鑰呭叆闄㈢殑淇℃伅涓�:{}", externalLeaveHospPatientInfo1.getZybm(), patMedInhospList); -// log.error("externalLeaveHospPatientInfo1鐨勭粨鏋滀负锛歿}", externalLeaveHospPatientInfo1); - if (CollectionUtils.isEmpty(patMedInhospList)) { - //濡傛灉涓嶅瓨鍦ㄥ叆闄俊鎭紝鏄笉鏄渶瑕佽幏鍙栦竴涓嬪叆闄俊鎭紝鍒欒繘琛屾柊澧烇紙锛� - List<ExternalInHospPatientInfo> externalInHospPatientInfo1 = externalInfoMapper.getExternalInHospPatientInfo(null, null, externalLeaveHospPatientInfo1.getBrid()); - if (CollectionUtils.isNotEmpty(externalInHospPatientInfo1)) { - //鍏堝鎮h�呭熀鏈俊鎭繘琛屽鐞� - Long pid = dealPatArchive(externalInHospPatientInfo1.get(0).getBrid()); - PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patid); - //鏂板鍏ラ櫌鏁版嵁 - PatMedInhosp inhosp = new PatMedInhosp(); - inhosp.setInhospno(externalInHospPatientInfo1.get(0).getZyhm()); - inhosp.setSerialnum(externalInHospPatientInfo1.get(0).getZyhm()); - inhosp.setNurseId(externalInHospPatientInfo1.get(0).getZrhsbm()); - inhosp.setNurseName(externalInHospPatientInfo1.get(0).getZrhs()); - inhosp.setStarttime(externalInHospPatientInfo1.get(0).getRyrq()); - inhosp.setDiagname(externalInHospPatientInfo1.get(0).getRyqk()); - inhosp.setDeptcode(externalLeaveHospPatientInfo1.getCyks()); - inhosp.setDeptname(externalLeaveHospPatientInfo1.getCyksdm()); - inhosp.setDrname(externalLeaveHospPatientInfo1.getZrys()); - inhosp.setDrcode(externalLeaveHospPatientInfo1.getZrysbm()); - inhosp.setHospitaldistrictid("" + externalInHospPatientInfo1.get(0).getBrbqdm()); - inhosp.setBedNo("" + externalInHospPatientInfo1.get(0).getBrch()); - inhosp.setPatid(pid); - inhosp.setPatname(patArchive.getName()); - inhosp.setTelcode(patArchive.getTelcode()); - inhosp.setPatno(patArchive.getPatientno()); - inhosp.setOutWayName(externalLeaveHospPatientInfo1.getCyfs()); - inhosp.setEndtime(externalLeaveHospPatientInfo1.getCysq()); - inhosp.setLeavediagname(externalLeaveHospPatientInfo1.getCyzd()); - inhosp.setLeavehospitaldistrictcode(externalLeaveHospPatientInfo1.getCybqdm()); - inhosp.setLeavehospitaldistrictname(externalLeaveHospPatientInfo1.getCybq()); - inhosp.setLeaveldeptcode(externalLeaveHospPatientInfo1.getCyksdm()); - inhosp.setLeaveldeptname(externalLeaveHospPatientInfo1.getCyks()); + String today = formatter.format(new Date()); - inhosp.setSchemestatus(2L); - inhosp.setInhospstate("1"); - inhosp.setCreateTime(new Date()); -// log.error("鏂板鐨刾atMedInhosp涓猴細{}", inhosp); - int i = patMedInhospMapper.insertPatMedInhosp(inhosp); - log.error("鏂板鐨刾atMedInhosp缁撴灉涓猴細{}", i); + log.info("寮�濮嬪垎鎵规煡璇㈠嚭闄㈡偅鑰呬俊鎭紝鎬绘椂闂磋寖鍥达細{} 鑷� {}", fixedStartTime, today); - } else { - log.error("璇ョ梾浜轰笉瀛樺湪鍏ラ櫌淇℃伅锛岀梾浜篒D锛歿}", externalLeaveHospPatientInfo1.getBrid()); - } + // 璁$畻闇�瑕佹煡璇㈢殑娆℃暟 + Calendar startCal = Calendar.getInstance(); + Calendar endCal = Calendar.getInstance(); + Calendar currentCal = Calendar.getInstance(); - } else if (CollectionUtils.isNotEmpty(patMedInhospList)) { - //濡傛灉瀛樺湪鍏ラ櫌淇℃伅锛屽垯杩涜淇敼 - pmi = patMedInhospList.get(0); - pmi.setOutWayName(externalLeaveHospPatientInfo1.getCyfs()); - pmi.setEndtime(externalLeaveHospPatientInfo1.getCysq()); - pmi.setLeavediagname(externalLeaveHospPatientInfo1.getCyzd()); - pmi.setLeaveldeptcode(externalLeaveHospPatientInfo1.getCyksdm()); - pmi.setLeaveldeptname(externalLeaveHospPatientInfo1.getCyks()); - pmi.setDeptname(externalLeaveHospPatientInfo1.getCyks()); - pmi.setDeptcode(externalLeaveHospPatientInfo1.getCyksdm()); - pmi.setLeavehospitaldistrictcode(externalLeaveHospPatientInfo1.getCybqdm()); - pmi.setLeavehospitaldistrictname(externalLeaveHospPatientInfo1.getCybq()); -// pmi.setSchemestatus(2L); - pmi.setInhospstate("1"); -// pmi.setUpdateTime(new Date()); - pmi.setNurseId(externalLeaveHospPatientInfo1.getZrhsbm()); - pmi.setNurseName(externalLeaveHospPatientInfo1.getZrhs()); - pmi.setDrcode(externalLeaveHospPatientInfo1.getZrysbm()); - pmi.setDrname(externalLeaveHospPatientInfo1.getZrys()); - - log.error("淇敼鐨刾mi缁撴灉涓猴細{}", pmi); - patMedInhospMapper.updatePatMedInhosp(pmi); + try { + startCal.setTime(formatter.parse(fixedStartTime)); + endCal.setTime(formatter.parse(today)); + } catch (ParseException e) { + log.error("鏃ユ湡瑙f瀽澶辫触锛歿}", e.getMessage(), e); + return false; } + int totalDays = (int) ((endCal.getTimeInMillis() - startCal.getTimeInMillis()) / (1000 * 60 * 60 * 24)); + int batchSize = 10; // 姣忔壒10澶� + int totalBatches = (int) Math.ceil((double) totalDays / batchSize); + + log.info("鎬诲叡闇�瑕佹煡璇� {} 澶╋紝鍒嗕负 {} 鎵规锛屾瘡鎵� {} 澶�", totalDays, totalBatches, batchSize); + + int totalSuccessCount = 0; + int totalFailCount = 0; + + // 鍒嗘壒鏌ヨ + for (int batch = 0; batch < totalBatches; batch++) { + // 璁$畻褰撳墠鎵规鐨勫紑濮嬪拰缁撴潫鏃堕棿 + Calendar batchStartCal = (Calendar) startCal.clone(); + batchStartCal.add(Calendar.DAY_OF_MONTH, batch * batchSize); + + Calendar batchEndCal = (Calendar) batchStartCal.clone(); + batchEndCal.add(Calendar.DAY_OF_MONTH, batchSize - 1); + + // 纭繚涓嶈秴杩囦粖澶� + if (batchEndCal.after(endCal)) { + batchEndCal = (Calendar) endCal.clone(); + } + + String batchStartTime = formatter.format(batchStartCal.getTime()); + String batchEndTime = formatter.format(batchEndCal.getTime()); + + log.info("寮�濮嬫煡璇㈢ {} 鎵规锛屾椂闂磋寖鍥达細{} 鑷� {}", batch + 1, batchStartTime, batchEndTime); + + try { + // 鏌ヨ褰撳墠鎵规鐨勫閮ㄥ嚭闄㈡偅鑰呬俊鎭� + List<ExternalOutHospInfo> externalOutHospInfos = externalInfoMapper.getExternalOutHospInfo(batchStartTime, batchEndTime); + log.info("绗� {} 鎵规鏌ヨ鍒板嚭闄㈡偅鑰呬俊鎭暟閲忥細{}", batch + 1, externalOutHospInfos.size()); + + int batchSuccessCount = 0; + int batchFailCount = 0; + + // 澶勭悊褰撳墠鎵规鐨勬暟鎹� + for (ExternalOutHospInfo externalOutHospInfo : externalOutHospInfos) { + try { + // 澶勭悊鎮h�呮。妗� + Long patid = dealPatArchive(externalOutHospInfo.getBrid()); + PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patid); + + // 鍒涘缓闂ㄨ瘖璁板綍瀵硅薄 + PatMedOuthosp patMedOuthosp = new PatMedOuthosp(); + + // 璁剧疆鍩烘湰淇℃伅 + patMedOuthosp.setOuthospno(externalOutHospInfo.getJzkh()); + patMedOuthosp.setSerialnum(externalOutHospInfo.getJzkh()); + patMedOuthosp.setPatid(patid); + + // 璁剧疆鎮h�呭鍚� + if (ObjectUtils.isNotEmpty(patArchive)) { + patMedOuthosp.setPatname(patArchive.getName()); + } + + // 璁剧疆璇婃柇淇℃伅 + patMedOuthosp.setIcd10code(externalOutHospInfo.getZddm()); + patMedOuthosp.setDiagname(externalOutHospInfo.getZdmc()); + + // 璁剧疆绉戝淇℃伅 + patMedOuthosp.setDeptcode(String.valueOf(externalOutHospInfo.getKsdm())); + patMedOuthosp.setDeptname(externalOutHospInfo.getKsmc()); + + // 璁剧疆鍖荤敓淇℃伅 + patMedOuthosp.setDrcode(String.valueOf(externalOutHospInfo.getYsdm())); + patMedOuthosp.setDrname(externalOutHospInfo.getYsmc()); + + // 璁剧疆鍏朵粬淇℃伅 + patMedOuthosp.setHpi(externalOutHospInfo.getXbs()); + patMedOuthosp.setMainsuit(externalOutHospInfo.getZs()); + patMedOuthosp.setCategory(externalOutHospInfo.getLb()); + patMedOuthosp.setAdmitdate(externalOutHospInfo.getJzrq()); + + // 璁剧疆鏃堕棿瀛楁 + Date now = new Date(); + patMedOuthosp.setUploadTime(now); + patMedOuthosp.setCreateTime(now); + patMedOuthosp.setUpdateTime(now); + + // 璁剧疆榛樿鍊� + patMedOuthosp.setDelFlag("0"); // 鍒犻櫎鏍囧織 + patMedOuthosp.setIsupload(0L); // 涓婁紶鏍囧織 + + // 鎻掑叆鏁版嵁 + int result = patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp); + if (result > 0) { + batchSuccessCount++; + totalSuccessCount++; + } else { + batchFailCount++; + totalFailCount++; + } + + } catch (Exception e) { + batchFailCount++; + totalFailCount++; + log.error("澶勭悊鎮h�呴棬璇婅褰曟椂鍙戠敓寮傚父锛屾偅鑰匢D锛歿}锛岄棬璇婂彿锛歿}锛屽紓甯镐俊鎭細{}", + externalOutHospInfo.getBrid(), externalOutHospInfo.getJzkh(), e.getMessage(), e); + } + } + + log.info("绗� {} 鎵规澶勭悊瀹屾垚锛屾垚鍔燂細{}锛屽け璐ワ細{}", batch + 1, batchSuccessCount, batchFailCount); + + // 姣忔壒娆″鐞嗗畬鍚庣◢浣滃欢杩燂紝閬垮厤瀵规暟鎹簱閫犳垚杩囧ぇ鍘嬪姏 + if (batch < totalBatches - 1) { + Thread.sleep(1000); // 寤惰繜1绉� + } + + } catch (Exception e) { + log.error("绗� {} 鎵规鏌ヨ澶勭悊鏃跺彂鐢熷紓甯革細{}", batch + 1, e.getMessage(), e); + totalFailCount++; + } + } + + log.info("鎵�鏈夋壒娆″鐞嗗畬鎴愶紝鎬昏鎴愬姛锛歿}锛屽け璐ワ細{}", totalSuccessCount, totalFailCount); + return true; + + } catch (Exception e) { + log.error("鑾峰彇鍑洪櫌鎮h�呬俊鎭椂鍙戠敓寮傚父锛歿}", e.getMessage(), e); + return false; } - return null; } -- Gitblit v1.9.3