Commit 1f2dd213c90a2213294a6ef544103e7ec7be53c0

Authored by liquanyu
1 parent b64e1c980c

code update

Showing 2 changed files with 271 additions and 37 deletions

platform-biz-patient-service/src/main/java/com/lyms/platform/biz/JdbcUtil.java View file @ 1f2dd21
... ... @@ -29,6 +29,152 @@
29 29 * Created by Administrator on 2016/9/29.
30 30 */
31 31 public class JdbcUtil {
  32 +
  33 + private static List<Map<String,String>> employees = new ArrayList<>();
  34 + private static List<Map<String,String>> oracleHosps = new ArrayList<>();
  35 + private static List<Map<String,String>> users = new ArrayList<>();
  36 + private static List<Map<String,String>> mysqlHosps = new ArrayList<>();
  37 + private static List<Map<String,String>> datacontents = new ArrayList<>();
  38 + private static List<Map<String,String>> basicConfigs = new ArrayList<>();
  39 +
  40 + static
  41 + {
  42 + initData();
  43 + }
  44 +
  45 + public static void initData()
  46 + {
  47 + List<Map<String,Object>> listEmp = getListDataBySql("select e.e_name,e.e_id from mommy_employee e");
  48 + for(Map<String,Object> map : listEmp)
  49 + {
  50 + Map<String,String> emap = new HashMap<>();
  51 + emap.put("id",getString(map.get("E_ID")));
  52 + emap.put("name",getString(map.get("E_NAME")));
  53 + employees.add(emap);
  54 + }
  55 +
  56 +
  57 + List<Map<String,Object>> datacontentsList = getListDataBySql("select dc_name,dc_id from plat_datacontent ");
  58 + for(Map<String,Object> map : datacontentsList)
  59 + {
  60 + Map<String,String> data = new HashMap<>();
  61 + data.put("id",getString(map.get("DC_ID")));
  62 + data.put("name",getString(map.get("DC_NAME")));
  63 + datacontents.add(data);
  64 + }
  65 + List<Map<String,Object>> orcleHospsList = getListDataBySql("select h_name,h_id from plat_hospital h");
  66 + for(Map<String,Object> map : orcleHospsList)
  67 + {
  68 + Map<String,String> data = new HashMap<>();
  69 + data.put("id",getString(map.get("H_ID")));
  70 + data.put("name",getString(map.get("H_NAME")));
  71 + oracleHosps.add(data);
  72 + }
  73 +
  74 +
  75 + List<Map<String,Object>> usersList = getMysqlListDataBySql("select id,name from users");
  76 + for(Map<String,Object> map : usersList)
  77 + {
  78 + Map<String,String> data = new HashMap<>();
  79 + data.put("id",getString(map.get("ID")));
  80 + data.put("name",getString(map.get("NAME")));
  81 + users.add(data);
  82 + }
  83 +
  84 +
  85 + List<Map<String,Object>> mysqlHospsList = getMysqlListDataBySql("select id,name from organization");
  86 + for(Map<String,Object> map : mysqlHospsList)
  87 + {
  88 + Map<String,String> data = new HashMap<>();
  89 + data.put("id",getString(map.get("ID")));
  90 + data.put("name",getString(map.get("NAME")));
  91 + mysqlHosps.add(data);
  92 + }
  93 + List<Map<String,Object>> oracleBasicList = getListDataBySql("select id,name.parentId from lyms_basicconfig ");
  94 + for(Map<String,Object> map : oracleBasicList)
  95 + {
  96 + Map<String,String> data = new HashMap<>();
  97 + data.put("id",getString(map.get("ID")));
  98 + data.put("name",getString(map.get("NAME")));
  99 + data.put("parentId",getString(map.get("PARENTID")));
  100 + basicConfigs.add(data);
  101 + }
  102 +
  103 + }
  104 +
  105 +
  106 + public static String getDataContentByById(String id)
  107 + {
  108 + for (Map<String,String> map : datacontents)
  109 + {
  110 + if (StringUtils.isNotEmpty(map.get("id")) && map.get("id").equals(map.get(id)))
  111 + {
  112 + return map.get("name");
  113 + }
  114 + }
  115 + return null;
  116 + }
  117 +
  118 +
  119 + public static String getPatHosptalById(String id)
  120 + {
  121 + for (Map<String,String> map : oracleHosps)
  122 + {
  123 + if (StringUtils.isNotEmpty(map.get("id")) && map.get("id").equals(map.get(id)))
  124 + {
  125 + return map.get("name");
  126 + }
  127 + }
  128 + return null;
  129 + }
  130 +
  131 +
  132 + public static String getOrgIdByName(String name)
  133 + {
  134 + for (Map<String,String> map : oracleHosps)
  135 + {
  136 + if (StringUtils.isNotEmpty(map.get("name")) && map.get("name").equals(map.get(name)))
  137 + {
  138 + return map.get("id");
  139 + }
  140 + }
  141 + return null;
  142 + }
  143 + public static String getEmpNameById(String id)
  144 + {
  145 + for (Map<String,String> map : oracleHosps)
  146 + {
  147 + if (StringUtils.isNotEmpty(map.get("id")) && map.get("id").equals(map.get(id)))
  148 + {
  149 + return map.get("name");
  150 + }
  151 + }
  152 + return null;
  153 + }
  154 +
  155 +
  156 + public static String getUserIdByName(String name)
  157 + {
  158 + for (Map<String,String> map : oracleHosps)
  159 + {
  160 + if (StringUtils.isNotEmpty(map.get("name")) && map.get("name").equals(map.get(name)))
  161 + {
  162 + return map.get("id");
  163 + }
  164 + }
  165 + return null;
  166 + } public static String getBasicConfigByNameAndParentId(String name,String parentId)
  167 + {
  168 + for (Map<String,String> map : basicConfigs)
  169 + {
  170 + if (StringUtils.isNotEmpty(map.get("parentId")) && StringUtils.isNotEmpty(map.get("name")) && map.get("name").equals(map.get(name)) && map.get("parentId").equals(parentId))
  171 + {
  172 + return map.get("id");
  173 + }
  174 + }
  175 + return null;
  176 + }
  177 +
32 178 public static Connection getOracleConnection() {
33 179 Connection con = null;
34 180 try {
... ... @@ -113,6 +259,41 @@
113 259 return list;
114 260 }
115 261  
  262 +
  263 + public static List<Map<String,Object>> getMysqlListDataBySql(String sql)
  264 + {
  265 + Connection conn = getMysqlConnection();
  266 + PreparedStatement pst = null;
  267 + ResultSet rs = null;
  268 + List<Map<String,Object>> list = new ArrayList<>();
  269 + try {
  270 + pst = conn.prepareStatement(sql);
  271 + rs = pst.executeQuery();
  272 + int count = rs.getMetaData().getColumnCount();
  273 + while (rs.next()) {
  274 + Map<String,Object> maps = new HashMap<>();
  275 + for (int i = 1; i <= count; i++) {
  276 + String columnName = rs.getMetaData().getColumnName(i);
  277 + Object obj = rs.getObject(columnName);
  278 + if (obj != null) {
  279 + maps.put(columnName, obj);
  280 + }
  281 + else
  282 + {
  283 + maps.put(columnName,null);
  284 + }
  285 + }
  286 + list.add(maps);
  287 + }
  288 + }catch (Exception e)
  289 + {
  290 + e.printStackTrace();
  291 + } finally {
  292 + freeConnection(conn,pst,rs);
  293 + }
  294 + return list;
  295 + }
  296 +
116 297 public static Object getOralceSingleObjBySql(String sql)
117 298 {
118 299 Connection conn = getOracleConnection();
119 300  
120 301  
121 302  
122 303  
123 304  
... ... @@ -176,29 +357,24 @@
176 357 }
177 358  
178 359  
179   - public static void syncPatientData(String hospitalId,MongoTemplate mongoTemplate)
  360 + public static void syncPatientData(String hospitalId,MongoTemplate mongoTemplate,int start,int total)
180 361 {
181 362  
182   - int num = 1;
  363 + int num = start;
183 364  
184 365 while (true) {
185 366 List<Map<String, Object>> list = getListDataBySql(" SELECT * FROM ( SELECT A.*, ROWNUM RN FROM " +
186 367 "(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" +
187   - " on mp.p_platpatientid=pp.p_id where mp.p_hospitalid = '" + hospitalId + "') A WHERE ROWNUM < "+(num+20)+" ) WHERE RN >= "+num+" ");
  368 + " 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+" ");
188 369 if (list == null || list.size() == 0)
189 370 {
190 371 break;
191 372 }
192 373 num=num+20;
193 374 for (Map<String, Object> map : list) {
194   -
195 375 try {
196   -
197   -
198 376 Patients patients = new Patients();
199 377 PersonModel person = new PersonModel();
200   -
201   -
202 378 int type = 1;
203 379 Integer weeks = getInteger(map.get("WEEKS"));
204 380 List<Map<String, Object>> chanList = null;
... ... @@ -243,7 +419,8 @@
243 419  
244 420 if (StringUtils.isNotEmpty(getString(map.get("P_CARDNO")))) {
245 421 String cardType = getString(map.get("P_CARDTYPE")); //证件类型
246   - String cardTypeName = getString(getOralceSingleObjBySql("select dc_name from plat_datacontent where dc_id='" + cardType + "'"));
  422 + String cardTypeName = getDataContentByById(cardType);
  423 + //String cardTypeName = getString(getOralceSingleObjBySql("select dc_name from plat_datacontent where dc_id='" + cardType + "'"));
247 424 if (cardTypeName != null && !"".equals(cardTypeName)) {
248 425 String id = getMongoBasicConfig(cardTypeName, SystemConfig.CERTE_TYPE_ID);
249 426 patients.setPcerteTypeId(id);
... ... @@ -318,8 +495,10 @@
318 495 }
319 496  
320 497 if (buildHospitalId != null && !"".equals(buildHospitalId)) {
321   - String hname = getString(getOralceSingleObjBySql("select h_name from plat_hospital h where h.h_isvalid=1 and h_id = '" + buildHospitalId + "'"));
322   - String id = getString(getMysqlSingleObjBySql("select id from organization where name = '" + hname + "'"));
  498 + //String hname = getString(getOralceSingleObjBySql("select h_name from plat_hospital h where h.h_isvalid=1 and h_id = '" + buildHospitalId + "'"));
  499 + String hname = getPatHosptalById(buildHospitalId);
  500 + // String id = getString(getMysqlSingleObjBySql("select id from organization where name = '" + hname + "'"));
  501 + String id = getOrgIdByName(hname);
323 502 patients.setHospitalId(id);
324 503 }
325 504  
... ... @@ -327,8 +506,10 @@
327 506  
328 507 String doctorId = getString(map.get("P_FILINGOPER"));
329 508 if (doctorId != null && !"".equals(doctorId)) {
330   - String hname = getString(getOralceSingleObjBySql("select e.e_name from mommy_employee e where e.e_id = '" + doctorId + "'"));
331   - String id = getString(getMysqlSingleObjBySql("select id from users where name = '" + hname + "'"));
  509 + //String hname = getString(getOralceSingleObjBySql("select e.e_name from mommy_employee e where e.e_id = '" + doctorId + "'"));
  510 + String userName = getEmpNameById(doctorId);
  511 + //String id = getString(getMysqlSingleObjBySql("select id from users where name = '" + hname + "'"));
  512 + String id = getUserIdByName(userName);
332 513 patients.setBookbuildingDoctor(id); //建档医生(创建者)
333 514 }
334 515  
... ... @@ -449,12 +630,17 @@
449 630 patients.setHprofessionTypeId(id);
450 631 }
451 632  
452   - String P_HUSBANDCARDTYPE = getString(map.get("P_HUSBANDCARDTYPE")); //丈夫证件类型
453   - String hcardTypeName = getString(getOralceSingleObjBySql("select dc_name from plat_datacontent where dc_id='" + P_HUSBANDCARDTYPE + "'"));
454   - if (hcardTypeName != null && !"".equals(hcardTypeName)) {
455   - String id = getMongoBasicConfig(hcardTypeName, SystemConfig.CERTE_TYPE_ID);
456   - patients.setHcertificateTypeId(id);
457   - }
  633 + String P_HUSBANDCARDTYPE = getString(map.get("P_HUSBANDCARDTYPE")); //丈夫证件类
  634 + if (StringUtils.isNotEmpty(P_HUSBANDCARDTYPE))
  635 + {
  636 + String hcardTypeName = getDataContentByById(P_HUSBANDCARDTYPE);
  637 + if (hcardTypeName != null && !"".equals(hcardTypeName)) {
  638 + String id = getMongoBasicConfig(hcardTypeName, SystemConfig.CERTE_TYPE_ID);
  639 + patients.setHcertificateTypeId(id);
  640 + }
  641 + }
  642 + //String hcardTypeName = getString(getOralceSingleObjBySql("select dc_name from plat_datacontent where dc_id='" + P_HUSBANDCARDTYPE + "'"));
  643 +
458 644 patients.setHcertificateNum(getString(map.get("P_HUSBANDCARDNO"))); //证件号码
459 645  
460 646  
... ... @@ -594,8 +780,10 @@
594 780 String doctorId = getString(map.get("FE_DOCTOR"));
595 781 if (doctorId != null && !"".equals(doctorId))
596 782 {
597   - String dname = getString(getOralceSingleObjBySql("select e.e_name from mommy_employee e where e.e_id = '" + doctorId + "'"));
598   - String id = getString(getMysqlSingleObjBySql("select id from users where name = '" + dname + "'"));
  783 + //String dname = getString(getOralceSingleObjBySql("select e.e_name from mommy_employee e where e.e_id = '" + doctorId + "'"));
  784 + String dname = getEmpNameById(doctorId);
  785 + String id = getUserIdByName(dname);
  786 + // String id = getString(getMysqlSingleObjBySql("select id from users where name = '" + dname + "'"));
599 787 chuModel.setProdDoctor(id);//产检医生
600 788 }
601 789  
... ... @@ -627,8 +815,10 @@
627 815 String hid = getString(map.get("FE_HOSPITALID"));
628 816 if (hid != null && !"".equals(hid))
629 817 {
630   - String hname = getString(getOralceSingleObjBySql("select h_name from plat_hospital h where h.h_isvalid=1 and h_id = '" + hid + "'"));
631   - String id = getString(getMysqlSingleObjBySql("select id from organization where name = '" + hname + "'"));
  818 + // String hname = getString(getOralceSingleObjBySql("select h_name from plat_hospital h where h.h_isvalid=1 and h_id = '" + hid + "'"));
  819 + String hname = getPatHosptalById(hid);
  820 +// String id = getString(getMysqlSingleObjBySql("select id from organization where name = '" + hname + "'"));
  821 + String id = getOrgIdByName(hname);
632 822 chuModel.setHospitalId(id);
633 823 }
634 824 if (map.get("FE_LBLOODPRESSURE") != null)
... ... @@ -831,7 +1021,8 @@
831 1021 String checkDoctorName = getString(map.get("CHECKDOCTOR"));
832 1022 if (checkDoctorName != null && !"".equals(checkDoctorName))
833 1023 {
834   - String id = getString(getMysqlSingleObjBySql("select id from users where name = '" + checkDoctorName + "'"));
  1024 + String id = getUserIdByName(checkDoctorName);
  1025 + // String id = getString(getMysqlSingleObjBySql("select id from users where name = '" + checkDoctorName + "'"));
835 1026 antxModel.setCheckDoctor(id);
836 1027 }
837 1028  
... ... @@ -844,8 +1035,10 @@
844 1035 String hid = getString(map.get("HOSPITALID"));
845 1036 if (hid != null && !"".equals(hid))
846 1037 {
847   - String hname = getString(getOralceSingleObjBySql("select h_name from plat_hospital h where h.h_isvalid=1 and h_id = '" + hid + "'"));
848   - String id = getString(getMysqlSingleObjBySql("select id from organization where name = '" + hname + "'"));
  1038 +// String hname = getString(getOralceSingleObjBySql("select h_name from plat_hospital h where h.h_isvalid=1 and h_id = '" + hid + "'"));
  1039 + String hname = getPatHosptalById(hid);
  1040 +// String id = getString(getMysqlSingleObjBySql("select id from organization where name = '" + hname + "'"));
  1041 + String id = getOrgIdByName(hname);
849 1042 antxModel.setHospitalId(id);
850 1043 }
851 1044 antxModel.setcDueWeek(getString(map.get("CDUEWEEK")));
852 1045  
853 1046  
... ... @@ -1352,15 +1545,18 @@
1352 1545  
1353 1546 public static String getMongoBasicConfig(String name,String parentId)
1354 1547 {
1355   - return getString(getOralceSingleObjBySql("select id from lyms_basicconfig where name='" + name + "' and parentId='" + parentId + "'"));
  1548 + //return getString(getOralceSingleObjBySql("select id from lyms_basicconfig where name='" + name + "' and parentId='" + parentId + "'"));
  1549 + return getBasicConfigByNameAndParentId(name,parentId);
1356 1550 }
1357 1551  
1358 1552 public static String getOracleBasicConfig(String id)
1359 1553 {
1360   - return getString(getOralceSingleObjBySql("select dc_name from plat_datacontent where dc_id='" + id + "'"));
  1554 +// return getString(getOralceSingleObjBySql("select dc_name from plat_datacontent where dc_id='" + id + "'"));
  1555 + return getDataContentByById(id);
1361 1556 }
1362 1557  
1363 1558  
  1559 +
1364 1560 public static String getString(Object obj)
1365 1561 {
1366 1562 return obj == null ? null : String.valueOf(obj);
1367 1563  
... ... @@ -1435,10 +1631,32 @@
1435 1631  
1436 1632 }
1437 1633  
1438   - public void syncDataPat(String hid,MongoTemplate mongoTemplate)
  1634 + public void syncDataPat1(String hid,MongoTemplate mongoTemplate)
1439 1635 {
1440 1636 try {
1441   - syncPatientData(hid,mongoTemplate);
  1637 + syncPatientData(hid, mongoTemplate,1,3000);
  1638 + }
  1639 + catch (Exception e)
  1640 + {
  1641 + ExceptionUtils.catchException(e,"孕妇同步出错。。。。。。。。。。。。。。");
  1642 + }
  1643 +
  1644 + }
  1645 + public void syncDataPat2(String hid,MongoTemplate mongoTemplate)
  1646 + {
  1647 + try {
  1648 + syncPatientData(hid,mongoTemplate,30001,8000);
  1649 + }
  1650 + catch (Exception e)
  1651 + {
  1652 + ExceptionUtils.catchException(e,"孕妇同步出错。。。。。。。。。。。。。。");
  1653 + }
  1654 +
  1655 + }
  1656 + public void syncDataPat3(String hid,MongoTemplate mongoTemplate)
  1657 + {
  1658 + try {
  1659 + syncPatientData(hid,mongoTemplate,8001,100000000);
1442 1660 }
1443 1661 catch (Exception e)
1444 1662 {
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java View file @ 1f2dd21
... ... @@ -99,21 +99,37 @@
99 99 @ResponseBody
100 100 public String syncData(@RequestParam(required = true) final String hid) {
101 101 final MongoTemplate template = mongoTemplate;
  102 +// new Thread(new Runnable() {
  103 +// @Override
  104 +// public void run() {
  105 +// System.out.print("同步开始儿童>>>>>>>>>>>>>>>>>>>>>>>>>");
  106 +// new com.lyms.platform.biz.JdbcUtil().syncDataBaby(hid, template);
  107 +// System.out.print("同步结束儿童>>>>>>>>>>>>>>>>>>>>>>>>>");
  108 +// }
  109 +// }).start();
  110 +
102 111 new Thread(new Runnable() {
103 112 @Override
104 113 public void run() {
105   - System.out.print("同步开始儿童>>>>>>>>>>>>>>>>>>>>>>>>>");
106   - new com.lyms.platform.biz.JdbcUtil().syncDataBaby(hid, template);
107   - System.out.print("同步结束儿童>>>>>>>>>>>>>>>>>>>>>>>>>");
  114 + System.out.print("同步开始孕妇1>>>>>>>>>>>>>>>>>>>>>>>>>");
  115 + new com.lyms.platform.biz.JdbcUtil().syncDataPat1(hid, template);
  116 + System.out.print("同步结束孕妇1>>>>>>>>>>>>>>>>>>>>>>>>>");
108 117 }
109 118 }).start();
110   -
111 119 new Thread(new Runnable() {
112 120 @Override
113 121 public void run() {
114   - System.out.print("同步开始孕妇>>>>>>>>>>>>>>>>>>>>>>>>>");
115   - new com.lyms.platform.biz.JdbcUtil().syncDataPat(hid, template);
116   - System.out.print("同步结束孕妇>>>>>>>>>>>>>>>>>>>>>>>>>");
  122 + System.out.print("同步开始孕妇2>>>>>>>>>>>>>>>>>>>>>>>>>");
  123 + new com.lyms.platform.biz.JdbcUtil().syncDataPat2(hid, template);
  124 + System.out.print("同步结束孕妇2>>>>>>>>>>>>>>>>>>>>>>>>>");
  125 + }
  126 + }).start();
  127 + new Thread(new Runnable() {
  128 + @Override
  129 + public void run() {
  130 + System.out.print("同步开始孕妇3>>>>>>>>>>>>>>>>>>>>>>>>>");
  131 + new com.lyms.platform.biz.JdbcUtil().syncDataPat3(hid, template);
  132 + System.out.print("同步结束孕妇3>>>>>>>>>>>>>>>>>>>>>>>>>");
117 133 }
118 134 }).start();
119 135 return "starting...........";