From 745906869d4fc32d64e4086a755df7cc5ae6b662 Mon Sep 17 00:00:00 2001 From: liquanyu Date: Thu, 26 Aug 2021 12:16:15 +0800 Subject: [PATCH] update --- .../lyms/platform/worker/BoneTransferWorker.java | 147 ++++++++++----------- .../com/lyms/platform/worker/TransferWorker.java | 12 +- 2 files changed, 75 insertions(+), 84 deletions(-) diff --git a/platform-transfer/src/main/java/com/lyms/platform/worker/BoneTransferWorker.java b/platform-transfer/src/main/java/com/lyms/platform/worker/BoneTransferWorker.java index 47e52b4..b6de396 100644 --- a/platform-transfer/src/main/java/com/lyms/platform/worker/BoneTransferWorker.java +++ b/platform-transfer/src/main/java/com/lyms/platform/worker/BoneTransferWorker.java @@ -2,12 +2,12 @@ package com.lyms.platform.worker; import com.lyms.platform.comm.ApplicationProperties; import com.lyms.platform.comm.StringUtils; +import com.lyms.platform.conn.BoneConnectionFactory; +import com.lyms.platform.conn.inf.ConnectionFactoryMethod; import com.lyms.platform.conn.inf.IConnection; -import org.apache.commons.httpclient.util.DateUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import java.sql.*; @@ -19,99 +19,96 @@ import java.util.Map; * 骨密度 */ @Component -@Scope("singleton") public class BoneTransferWorker extends TransferAbstract implements ITransfer{ private static final Logger logger = LoggerFactory.getLogger(BoneTransferWorker.class); @Autowired private ApplicationProperties properties; - - - public Connection getConnection() - { - Connection conn = null; - try { - Class.forName("com.hxtt.sql.access.AccessDriver"); - String url = "jdbc:Access:///"+properties.getDataPath(); - conn = DriverManager.getConnection(url, "", ""); - } catch (Exception e) { - logger.error("getConnection error.",e); - } - return conn; - } - - @Override public void doTransfer() { - while (true) - { + logger.info("getBoneRecords start"); Connection conn = null; Statement sta = null; ResultSet rst = null; - IConnection iConnection = null; + ConnectionFactoryMethod factoryMethod = new BoneConnectionFactory(); + IConnection iConnection = factoryMethod.createConnection(properties.getDataPath()); try { - conn = getConnection(); + conn = iConnection.getConnection(); sta = conn.createStatement(); - String sql = "select PatientID,ZScore,TScore,dbSos,dbBqi,dbRrf,dbEoa,YoungAdult,ageMatched,dbAge,PartDisplayName,PatientName from PatientInfo where status is null and DayTimeOfSave > "+ DateUtil.formatDate(new Date(),"yyyy-MM-dd"); + String sql = "select PatientID,ZScore,TScore,dbSos,dbBqi,dbRrf,dbEoa,YoungAdult,ageMatched,dbAge,PartDisplayName,PatientName from PatientInfo where status is null "; rst = sta.executeQuery(sql); - if (!rst.isClosed()) - { - while (rst.next()) { - Map map = new HashMap(); - String PatientID = rst.getString("PatientID"); //身份证后八位 - map.put("cardNo",PatientID); - - String PartDisplayName = rst.getString("PartDisplayName"); - map.put("position",PartDisplayName); - - String PatientName = rst.getString("PatientName"); //孕妇姓名 - map.put("username",PatientName); - - String ZScore = rst.getString("ZScore"); - String TScore = rst.getString("TScore"); - String dbSos = rst.getString("dbSos"); - - String bqi = rst.getString("dbBqi"); - String rrf = rst.getString("dbRrf"); - String eoa = rst.getString("dbEoa"); - - String adultPercent = rst.getString("YoungAdult"); - String agePercent = rst.getString("ageMatched"); - String age = rst.getString("dbAge"); - - map.put("zvalue",ZScore); - map.put("tvalue",TScore); - map.put("sos",dbSos); - - map.put("bqi",bqi); - map.put("rrf",rrf); - map.put("eoa",eoa); - - map.put("adultPercent",adultPercent); - map.put("agePercent",agePercent); - map.put("age",age); - map.put("type",properties.getType()); // - map.put("hospitalId",properties.getHospitalId()); // - - if (map.size() > 0 && StringUtils.isNotEmpty(PatientID)) - { - String response = send(map, properties.getUrl() + "/saveBone"); - if (response.contains("0")) - { - sta.executeUpdate("update PatientInfo set status='1' where PatientID='" + PatientID + "'"); - conn.commit(); - } - } - } - Thread.sleep(30000); + while (rst.next()) { + Map map = new HashMap(); + String PatientID = rst.getString("PatientID"); //身份证后八位 + map.put("cardNo",PatientID); + + String PartDisplayName = rst.getString("PartDisplayName"); + map.put("position",PartDisplayName); + + String PatientName = rst.getString("PatientName"); //孕妇姓名 + map.put("username",PatientName); + + String ZScore = rst.getString("ZScore"); + String TScore = rst.getString("TScore"); + String dbSos = rst.getString("dbSos"); + + String bqi = rst.getString("dbBqi"); + String rrf = rst.getString("dbRrf"); + String eoa = rst.getString("dbEoa"); + + String adultPercent = rst.getString("YoungAdult"); + String agePercent = rst.getString("ageMatched"); + String age = rst.getString("dbAge"); + + map.put("zvalue",ZScore); + map.put("tvalue",TScore); + map.put("sos",dbSos); + + map.put("bqi",bqi); + map.put("rrf",rrf); + map.put("eoa",eoa); + + map.put("adultPercent",adultPercent); + map.put("agePercent",agePercent); + map.put("age",age); + map.put("type",properties.getType()); // + map.put("hospitalId",properties.getHospitalId()); // + exeUpdate( map, PatientID); + } + Thread.sleep(5000); } catch (Exception e) { - logger.error("getBoneRecords Exception. ",e); + logger.error("getBoneRecords Exception. ",e); } finally { iConnection.close(conn, sta,rst); } } + + + public void exeUpdate(Map map,String PatientID) + { + Connection conn = null; + Statement sta = null; + ConnectionFactoryMethod factoryMethod = new BoneConnectionFactory(); + IConnection iConnection = factoryMethod.createConnection(properties.getDataPath()); + try { + conn = iConnection.getConnection(); + sta = conn.createStatement(); + if (map.size() > 0 && StringUtils.isNotEmpty(PatientID)) { + String response = send(map, properties.getUrl() + "/saveBone"); + if (response.contains("0")) { + sta.executeUpdate("update PatientInfo set status='1' where PatientID='" + PatientID + "'"); + } + } + } + catch (Exception e) + { + logger.error("exeUpdate Exception. ",e); + } + finally { + iConnection.close(conn, sta,null); + } } } diff --git a/platform-transfer/src/main/java/com/lyms/platform/worker/TransferWorker.java b/platform-transfer/src/main/java/com/lyms/platform/worker/TransferWorker.java index 3a60111..747a58f 100644 --- a/platform-transfer/src/main/java/com/lyms/platform/worker/TransferWorker.java +++ b/platform-transfer/src/main/java/com/lyms/platform/worker/TransferWorker.java @@ -1,8 +1,6 @@ package com.lyms.platform.worker; -import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -10,19 +8,15 @@ import org.springframework.stereotype.Component; * Created by Administrator on 2020-03-23. */ @Component -public class TransferWorker extends TransferAbstract implements ITransfer,InitializingBean { +public class TransferWorker extends TransferAbstract implements ITransfer { @Autowired private BoneTransferWorker boneTransferWorker; @Override -// @Scheduled(cron = "0 0/1 * * * ?",fixedDelay = 10000) + @Scheduled(cron = "0 0/1 * * * ?") public void doTransfer() { - - } - - @Override - public void afterPropertiesSet() throws Exception { boneTransferWorker.doTransfer(); } + } -- 1.8.3.1