From 1f2dd213c90a2213294a6ef544103e7ec7be53c0 Mon Sep 17 00:00:00 2001 From: liquanyu Date: Wed, 12 Oct 2016 17:29:47 +0800 Subject: [PATCH] code update --- .../main/java/com/lyms/platform/biz/JdbcUtil.java | 278 ++++++++++++++++++--- .../operate/web/controller/TestController.java | 30 ++- 2 files changed, 271 insertions(+), 37 deletions(-) diff --git a/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/JdbcUtil.java b/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/JdbcUtil.java index 77a692a..ac72f3e 100644 --- a/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/JdbcUtil.java +++ b/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/JdbcUtil.java @@ -29,6 +29,152 @@ import java.util.Date; * Created by Administrator on 2016/9/29. */ public class JdbcUtil { + + private static List> employees = new ArrayList<>(); + private static List> oracleHosps = new ArrayList<>(); + private static List> users = new ArrayList<>(); + private static List> mysqlHosps = new ArrayList<>(); + private static List> datacontents = new ArrayList<>(); + private static List> basicConfigs = new ArrayList<>(); + + static + { + initData(); + } + + public static void initData() + { + List> listEmp = getListDataBySql("select e.e_name,e.e_id from mommy_employee e"); + for(Map map : listEmp) + { + Map emap = new HashMap<>(); + emap.put("id",getString(map.get("E_ID"))); + emap.put("name",getString(map.get("E_NAME"))); + employees.add(emap); + } + + + List> datacontentsList = getListDataBySql("select dc_name,dc_id from plat_datacontent "); + for(Map map : datacontentsList) + { + Map data = new HashMap<>(); + data.put("id",getString(map.get("DC_ID"))); + data.put("name",getString(map.get("DC_NAME"))); + datacontents.add(data); + } + List> orcleHospsList = getListDataBySql("select h_name,h_id from plat_hospital h"); + for(Map map : orcleHospsList) + { + Map data = new HashMap<>(); + data.put("id",getString(map.get("H_ID"))); + data.put("name",getString(map.get("H_NAME"))); + oracleHosps.add(data); + } + + + List> usersList = getMysqlListDataBySql("select id,name from users"); + for(Map map : usersList) + { + Map data = new HashMap<>(); + data.put("id",getString(map.get("ID"))); + data.put("name",getString(map.get("NAME"))); + users.add(data); + } + + + List> mysqlHospsList = getMysqlListDataBySql("select id,name from organization"); + for(Map map : mysqlHospsList) + { + Map data = new HashMap<>(); + data.put("id",getString(map.get("ID"))); + data.put("name",getString(map.get("NAME"))); + mysqlHosps.add(data); + } + List> oracleBasicList = getListDataBySql("select id,name.parentId from lyms_basicconfig "); + for(Map map : oracleBasicList) + { + Map data = new HashMap<>(); + data.put("id",getString(map.get("ID"))); + data.put("name",getString(map.get("NAME"))); + data.put("parentId",getString(map.get("PARENTID"))); + basicConfigs.add(data); + } + + } + + + public static String getDataContentByById(String id) + { + for (Map map : datacontents) + { + if (StringUtils.isNotEmpty(map.get("id")) && map.get("id").equals(map.get(id))) + { + return map.get("name"); + } + } + return null; + } + + + public static String getPatHosptalById(String id) + { + for (Map map : oracleHosps) + { + if (StringUtils.isNotEmpty(map.get("id")) && map.get("id").equals(map.get(id))) + { + return map.get("name"); + } + } + return null; + } + + + public static String getOrgIdByName(String name) + { + for (Map map : oracleHosps) + { + if (StringUtils.isNotEmpty(map.get("name")) && map.get("name").equals(map.get(name))) + { + return map.get("id"); + } + } + return null; + } + public static String getEmpNameById(String id) + { + for (Map map : oracleHosps) + { + if (StringUtils.isNotEmpty(map.get("id")) && map.get("id").equals(map.get(id))) + { + return map.get("name"); + } + } + return null; + } + + + public static String getUserIdByName(String name) + { + for (Map map : oracleHosps) + { + if (StringUtils.isNotEmpty(map.get("name")) && map.get("name").equals(map.get(name))) + { + return map.get("id"); + } + } + return null; + } public static String getBasicConfigByNameAndParentId(String name,String parentId) + { + for (Map map : basicConfigs) + { + if (StringUtils.isNotEmpty(map.get("parentId")) && StringUtils.isNotEmpty(map.get("name")) && map.get("name").equals(map.get(name)) && map.get("parentId").equals(parentId)) + { + return map.get("id"); + } + } + return null; + } + public static Connection getOracleConnection() { Connection con = null; try { @@ -113,6 +259,41 @@ public class JdbcUtil { return list; } + + public static List> getMysqlListDataBySql(String sql) + { + Connection conn = getMysqlConnection(); + PreparedStatement pst = null; + ResultSet rs = null; + List> list = new ArrayList<>(); + try { + pst = conn.prepareStatement(sql); + rs = pst.executeQuery(); + int count = rs.getMetaData().getColumnCount(); + while (rs.next()) { + Map maps = new HashMap<>(); + for (int i = 1; i <= count; i++) { + String columnName = rs.getMetaData().getColumnName(i); + Object obj = rs.getObject(columnName); + if (obj != null) { + maps.put(columnName, obj); + } + else + { + maps.put(columnName,null); + } + } + list.add(maps); + } + }catch (Exception e) + { + e.printStackTrace(); + } finally { + freeConnection(conn,pst,rs); + } + return list; + } + public static Object getOralceSingleObjBySql(String sql) { Connection conn = getOracleConnection(); @@ -176,29 +357,24 @@ public class JdbcUtil { } - public static void syncPatientData(String hospitalId,MongoTemplate mongoTemplate) + public static void syncPatientData(String hospitalId,MongoTemplate mongoTemplate,int start,int total) { - int num = 1; + int num = start; while (true) { List> list = getListDataBySql(" SELECT * FROM ( SELECT A.*, ROWNUM RN FROM " + "(select replace(mp.P_NO,'-','') as PID,mp.*,p_birthday,p_name,floor((trunc(sysdate) - trunc(mp.P_LASTMENSTRUALPERIOD)+1) /7) as weeks from MOMMY_PATIENT mp left join Plat_Patient pp" + - " on mp.p_platpatientid=pp.p_id where mp.p_hospitalid = '" + hospitalId + "') A WHERE ROWNUM < "+(num+20)+" ) WHERE RN >= "+num+" "); + " on mp.p_platpatientid=pp.p_id where mp.p_hospitalid = '" + hospitalId + "' and rownum < "+total+" order by mp.p_lastmenstrualperiod desc ) A WHERE ROWNUM < "+(num+100)+" ) WHERE RN >= "+num+" "); if (list == null || list.size() == 0) { break; } num=num+20; for (Map map : list) { - try { - - Patients patients = new Patients(); PersonModel person = new PersonModel(); - - int type = 1; Integer weeks = getInteger(map.get("WEEKS")); List> chanList = null; @@ -243,7 +419,8 @@ public class JdbcUtil { if (StringUtils.isNotEmpty(getString(map.get("P_CARDNO")))) { String cardType = getString(map.get("P_CARDTYPE")); //证件类型 - String cardTypeName = getString(getOralceSingleObjBySql("select dc_name from plat_datacontent where dc_id='" + cardType + "'")); + String cardTypeName = getDataContentByById(cardType); + //String cardTypeName = getString(getOralceSingleObjBySql("select dc_name from plat_datacontent where dc_id='" + cardType + "'")); if (cardTypeName != null && !"".equals(cardTypeName)) { String id = getMongoBasicConfig(cardTypeName, SystemConfig.CERTE_TYPE_ID); patients.setPcerteTypeId(id); @@ -318,8 +495,10 @@ public class JdbcUtil { } if (buildHospitalId != null && !"".equals(buildHospitalId)) { - String hname = getString(getOralceSingleObjBySql("select h_name from plat_hospital h where h.h_isvalid=1 and h_id = '" + buildHospitalId + "'")); - String id = getString(getMysqlSingleObjBySql("select id from organization where name = '" + hname + "'")); + //String hname = getString(getOralceSingleObjBySql("select h_name from plat_hospital h where h.h_isvalid=1 and h_id = '" + buildHospitalId + "'")); + String hname = getPatHosptalById(buildHospitalId); + // String id = getString(getMysqlSingleObjBySql("select id from organization where name = '" + hname + "'")); + String id = getOrgIdByName(hname); patients.setHospitalId(id); } @@ -327,8 +506,10 @@ public class JdbcUtil { String doctorId = getString(map.get("P_FILINGOPER")); if (doctorId != null && !"".equals(doctorId)) { - String hname = getString(getOralceSingleObjBySql("select e.e_name from mommy_employee e where e.e_id = '" + doctorId + "'")); - String id = getString(getMysqlSingleObjBySql("select id from users where name = '" + hname + "'")); + //String hname = getString(getOralceSingleObjBySql("select e.e_name from mommy_employee e where e.e_id = '" + doctorId + "'")); + String userName = getEmpNameById(doctorId); + //String id = getString(getMysqlSingleObjBySql("select id from users where name = '" + hname + "'")); + String id = getUserIdByName(userName); patients.setBookbuildingDoctor(id); //建档医生(创建者) } @@ -449,12 +630,17 @@ public class JdbcUtil { patients.setHprofessionTypeId(id); } - String P_HUSBANDCARDTYPE = getString(map.get("P_HUSBANDCARDTYPE")); //丈夫证件类型 - String hcardTypeName = getString(getOralceSingleObjBySql("select dc_name from plat_datacontent where dc_id='" + P_HUSBANDCARDTYPE + "'")); - if (hcardTypeName != null && !"".equals(hcardTypeName)) { - String id = getMongoBasicConfig(hcardTypeName, SystemConfig.CERTE_TYPE_ID); - patients.setHcertificateTypeId(id); - } + String P_HUSBANDCARDTYPE = getString(map.get("P_HUSBANDCARDTYPE")); //丈夫证件类 + if (StringUtils.isNotEmpty(P_HUSBANDCARDTYPE)) + { + String hcardTypeName = getDataContentByById(P_HUSBANDCARDTYPE); + if (hcardTypeName != null && !"".equals(hcardTypeName)) { + String id = getMongoBasicConfig(hcardTypeName, SystemConfig.CERTE_TYPE_ID); + patients.setHcertificateTypeId(id); + } + } + //String hcardTypeName = getString(getOralceSingleObjBySql("select dc_name from plat_datacontent where dc_id='" + P_HUSBANDCARDTYPE + "'")); + patients.setHcertificateNum(getString(map.get("P_HUSBANDCARDNO"))); //证件号码 @@ -594,8 +780,10 @@ public class JdbcUtil { String doctorId = getString(map.get("FE_DOCTOR")); if (doctorId != null && !"".equals(doctorId)) { - String dname = getString(getOralceSingleObjBySql("select e.e_name from mommy_employee e where e.e_id = '" + doctorId + "'")); - String id = getString(getMysqlSingleObjBySql("select id from users where name = '" + dname + "'")); + //String dname = getString(getOralceSingleObjBySql("select e.e_name from mommy_employee e where e.e_id = '" + doctorId + "'")); + String dname = getEmpNameById(doctorId); + String id = getUserIdByName(dname); + // String id = getString(getMysqlSingleObjBySql("select id from users where name = '" + dname + "'")); chuModel.setProdDoctor(id);//产检医生 } @@ -627,8 +815,10 @@ public class JdbcUtil { String hid = getString(map.get("FE_HOSPITALID")); if (hid != null && !"".equals(hid)) { - String hname = getString(getOralceSingleObjBySql("select h_name from plat_hospital h where h.h_isvalid=1 and h_id = '" + hid + "'")); - String id = getString(getMysqlSingleObjBySql("select id from organization where name = '" + hname + "'")); + // String hname = getString(getOralceSingleObjBySql("select h_name from plat_hospital h where h.h_isvalid=1 and h_id = '" + hid + "'")); + String hname = getPatHosptalById(hid); +// String id = getString(getMysqlSingleObjBySql("select id from organization where name = '" + hname + "'")); + String id = getOrgIdByName(hname); chuModel.setHospitalId(id); } if (map.get("FE_LBLOODPRESSURE") != null) @@ -831,7 +1021,8 @@ public class JdbcUtil { String checkDoctorName = getString(map.get("CHECKDOCTOR")); if (checkDoctorName != null && !"".equals(checkDoctorName)) { - String id = getString(getMysqlSingleObjBySql("select id from users where name = '" + checkDoctorName + "'")); + String id = getUserIdByName(checkDoctorName); + // String id = getString(getMysqlSingleObjBySql("select id from users where name = '" + checkDoctorName + "'")); antxModel.setCheckDoctor(id); } @@ -844,8 +1035,10 @@ public class JdbcUtil { String hid = getString(map.get("HOSPITALID")); if (hid != null && !"".equals(hid)) { - String hname = getString(getOralceSingleObjBySql("select h_name from plat_hospital h where h.h_isvalid=1 and h_id = '" + hid + "'")); - String id = getString(getMysqlSingleObjBySql("select id from organization where name = '" + hname + "'")); +// String hname = getString(getOralceSingleObjBySql("select h_name from plat_hospital h where h.h_isvalid=1 and h_id = '" + hid + "'")); + String hname = getPatHosptalById(hid); +// String id = getString(getMysqlSingleObjBySql("select id from organization where name = '" + hname + "'")); + String id = getOrgIdByName(hname); antxModel.setHospitalId(id); } antxModel.setcDueWeek(getString(map.get("CDUEWEEK"))); @@ -1352,15 +1545,18 @@ public class JdbcUtil { public static String getMongoBasicConfig(String name,String parentId) { - return getString(getOralceSingleObjBySql("select id from lyms_basicconfig where name='" + name + "' and parentId='" + parentId + "'")); + //return getString(getOralceSingleObjBySql("select id from lyms_basicconfig where name='" + name + "' and parentId='" + parentId + "'")); + return getBasicConfigByNameAndParentId(name,parentId); } public static String getOracleBasicConfig(String id) { - return getString(getOralceSingleObjBySql("select dc_name from plat_datacontent where dc_id='" + id + "'")); +// return getString(getOralceSingleObjBySql("select dc_name from plat_datacontent where dc_id='" + id + "'")); + return getDataContentByById(id); } + public static String getString(Object obj) { return obj == null ? null : String.valueOf(obj); @@ -1435,10 +1631,32 @@ public class JdbcUtil { } - public void syncDataPat(String hid,MongoTemplate mongoTemplate) + public void syncDataPat1(String hid,MongoTemplate mongoTemplate) + { + try { + syncPatientData(hid, mongoTemplate,1,3000); + } + catch (Exception e) + { + ExceptionUtils.catchException(e,"孕妇同步出错。。。。。。。。。。。。。。"); + } + + } + public void syncDataPat2(String hid,MongoTemplate mongoTemplate) + { + try { + syncPatientData(hid,mongoTemplate,30001,8000); + } + catch (Exception e) + { + ExceptionUtils.catchException(e,"孕妇同步出错。。。。。。。。。。。。。。"); + } + + } + public void syncDataPat3(String hid,MongoTemplate mongoTemplate) { try { - syncPatientData(hid,mongoTemplate); + syncPatientData(hid,mongoTemplate,8001,100000000); } catch (Exception e) { diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java index 889effa..08ba50a 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java @@ -99,21 +99,37 @@ public class TestController { @ResponseBody public String syncData(@RequestParam(required = true) final String hid) { final MongoTemplate template = mongoTemplate; +// new Thread(new Runnable() { +// @Override +// public void run() { +// System.out.print("同步开始儿童>>>>>>>>>>>>>>>>>>>>>>>>>"); +// new com.lyms.platform.biz.JdbcUtil().syncDataBaby(hid, template); +// System.out.print("同步结束儿童>>>>>>>>>>>>>>>>>>>>>>>>>"); +// } +// }).start(); + new Thread(new Runnable() { @Override public void run() { - System.out.print("同步开始儿童>>>>>>>>>>>>>>>>>>>>>>>>>"); - new com.lyms.platform.biz.JdbcUtil().syncDataBaby(hid, template); - System.out.print("同步结束儿童>>>>>>>>>>>>>>>>>>>>>>>>>"); + System.out.print("同步开始孕妇1>>>>>>>>>>>>>>>>>>>>>>>>>"); + new com.lyms.platform.biz.JdbcUtil().syncDataPat1(hid, template); + System.out.print("同步结束孕妇1>>>>>>>>>>>>>>>>>>>>>>>>>"); + } + }).start(); + new Thread(new Runnable() { + @Override + public void run() { + System.out.print("同步开始孕妇2>>>>>>>>>>>>>>>>>>>>>>>>>"); + new com.lyms.platform.biz.JdbcUtil().syncDataPat2(hid, template); + System.out.print("同步结束孕妇2>>>>>>>>>>>>>>>>>>>>>>>>>"); } }).start(); - new Thread(new Runnable() { @Override public void run() { - System.out.print("同步开始孕妇>>>>>>>>>>>>>>>>>>>>>>>>>"); - new com.lyms.platform.biz.JdbcUtil().syncDataPat(hid, template); - System.out.print("同步结束孕妇>>>>>>>>>>>>>>>>>>>>>>>>>"); + System.out.print("同步开始孕妇3>>>>>>>>>>>>>>>>>>>>>>>>>"); + new com.lyms.platform.biz.JdbcUtil().syncDataPat3(hid, template); + System.out.print("同步结束孕妇3>>>>>>>>>>>>>>>>>>>>>>>>>"); } }).start(); return "starting..........."; -- 1.8.3.1