Commit f3df88180f8e729500a8fcf146003424847c6953
1 parent
b33b2ce23f
Exists in
master
and in
6 other branches
追访统计
Showing 5 changed files with 121 additions and 35 deletions
- platform-common/src/main/java/com/lyms/platform/common/utils/StringUtils.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AntenatalExaminationFacade.java
- platform-transfer/src/main/java/com/lyms/platform/microelement/MicroelementWorker.java
- platform-transfer/src/main/resources/spring/applicationContext-quartz.xml
- platform-transfer/src/main/resources/spring/applicationContext.xml
platform-common/src/main/java/com/lyms/platform/common/utils/StringUtils.java
View file @
f3df881
| 1 | 1 | package com.lyms.platform.common.utils; |
| 2 | 2 | |
| 3 | -import java.util.ArrayList; | |
| 4 | -import java.util.Date; | |
| 5 | -import java.util.List; | |
| 6 | -import java.util.UUID; | |
| 3 | +import java.util.*; | |
| 4 | +import java.util.regex.Matcher; | |
| 5 | +import java.util.regex.Pattern; | |
| 7 | 6 | |
| 8 | 7 | /** |
| 9 | 8 | * 添加类的一句话简单描述。 |
| ... | ... | @@ -324,8 +323,56 @@ |
| 324 | 323 | return list; |
| 325 | 324 | } |
| 326 | 325 | |
| 327 | -// public static void main(String[] arg) { | |
| 328 | -// System.out.print(encryPhone("18382670036")); | |
| 329 | -// } | |
| 326 | + public static void main(String[] arg) { | |
| 327 | + System.out.print(checkNum("75.82umol/l") ); | |
| 328 | + } | |
| 329 | + | |
| 330 | + | |
| 331 | + public static String checkNum(String str) { | |
| 332 | + //先判断有没有整数,如果没有整数那就肯定就没有小数 | |
| 333 | + Pattern p = Pattern.compile("(\\d+)"); | |
| 334 | + Matcher m = p.matcher(str); | |
| 335 | + String result = ""; | |
| 336 | + if (m.find()) { | |
| 337 | + Map<Integer, String> map = new TreeMap(); | |
| 338 | + Pattern p2 = Pattern.compile("(\\d+\\.\\d+)"); | |
| 339 | + m = p2.matcher(str); | |
| 340 | + //遍历小数部分 | |
| 341 | + while (m.find()) { | |
| 342 | + result = m.group(1) == null ? "" : m.group(1); | |
| 343 | + int i = str.indexOf(result); | |
| 344 | + String s = str.substring(i, i + result.length()); | |
| 345 | + map.put(i, s); | |
| 346 | + //排除小数的整数部分和另一个整数相同的情况下,寻找整数位置出现错误的可能,还有就是寻找重复的小数 | |
| 347 | + // 例子中是排除第二个345.56时第一个345.56产生干扰和寻找整数345的位置时,前面的小数345.56会干扰 | |
| 348 | + str = str.substring(0, i) + str.substring(i + result.length()); | |
| 349 | + } | |
| 350 | + //遍历整数 | |
| 351 | + Pattern p3 = Pattern.compile("(\\d+)"); | |
| 352 | + m = p3.matcher(str); | |
| 353 | + while (m.find()) { | |
| 354 | + result = m.group(1) == null ? "" : m.group(1); | |
| 355 | + int i = str.indexOf(result); | |
| 356 | + //排除jia567.23.23在第一轮过滤之后留下来的jia.23对整数23产生干扰 | |
| 357 | + if (String.valueOf(str.charAt(i - 1)).equals(".")) { | |
| 358 | + //将这个字符串删除 | |
| 359 | + str = str.substring(0, i - 1) + str.substring(i + result.length()); | |
| 360 | + continue; | |
| 361 | + } | |
| 362 | + String s = str.substring(i, i + result.length()); | |
| 363 | + map.put(i, s); | |
| 364 | + str = str.substring(0, i) + str.substring(i + result.length()); | |
| 365 | + } | |
| 366 | + result = ""; | |
| 367 | + for (Map.Entry<Integer, String> e : map.entrySet()) { | |
| 368 | + result += e.getValue() + ","; | |
| 369 | + } | |
| 370 | + result = result.substring(0, result.length()-1); | |
| 371 | + } else { | |
| 372 | + result = ""; | |
| 373 | + } | |
| 374 | + return result; | |
| 375 | + } | |
| 376 | + | |
| 330 | 377 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AntenatalExaminationFacade.java
View file @
f3df881
platform-transfer/src/main/java/com/lyms/platform/microelement/MicroelementWorker.java
View file @
f3df881
| ... | ... | @@ -3,8 +3,8 @@ |
| 3 | 3 | import com.lyms.platform.common.utils.HttpClientUtil; |
| 4 | 4 | import com.lyms.platform.common.utils.JsonUtil; |
| 5 | 5 | import com.lyms.platform.common.utils.PropertiesUtils; |
| 6 | +import com.lyms.platform.common.utils.StringUtils; | |
| 6 | 7 | import com.lyms.platform.conn.MicroelementConnection; |
| 7 | -import com.lyms.platform.pojo.MicroelementModel; | |
| 8 | 8 | |
| 9 | 9 | import java.sql.Connection; |
| 10 | 10 | import java.sql.ResultSet; |
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | |
| ... | ... | @@ -16,57 +16,97 @@ |
| 16 | 16 | import java.util.Map; |
| 17 | 17 | |
| 18 | 18 | public class MicroelementWorker { |
| 19 | + | |
| 19 | 20 | public static final String url = PropertiesUtils.getPropertyValue("url"); |
| 20 | - public static Map<String,Object> getMicroelementRecords() | |
| 21 | + | |
| 22 | + public static void getMicroelementRecords() | |
| 21 | 23 | { |
| 22 | - Map<String,Object> data = new HashMap<>(); | |
| 23 | 24 | Connection conn = null; |
| 24 | 25 | Statement sta = null; |
| 25 | 26 | ResultSet rst = null; |
| 26 | 27 | try { |
| 27 | 28 | conn = MicroelementConnection.getConnection(); |
| 28 | 29 | sta = conn.createStatement(); |
| 29 | - rst = sta.executeQuery("select * from BaseInfo where AUTOID=23928"); | |
| 30 | - if(rst.next()){ | |
| 30 | + rst = sta.executeQuery("select * from BaseInfo where status is null "); | |
| 31 | + while (rst.next()){ | |
| 32 | + Map<String,Object> data = new HashMap<>(); | |
| 31 | 33 | String numberCode = rst.getString("编号"); |
| 32 | 34 | String autoId = rst.getString("AUTOID"); |
| 33 | - data.put("numberCode","123456"); | |
| 34 | - rst = sta.executeQuery("select * from ItemsInfo where BaseAutoId = "+autoId); | |
| 35 | + data.put("numberCode",numberCode); | |
| 36 | + data.put("autoId",autoId); | |
| 37 | + getMicroelementRecords(data); | |
| 38 | + } | |
| 39 | + } | |
| 40 | + catch (SQLException e) { | |
| 41 | + } | |
| 42 | + finally { | |
| 43 | + MicroelementConnection.close(conn, sta,rst); | |
| 44 | + } | |
| 45 | + } | |
| 35 | 46 | |
| 36 | - List<Map> microelements = new ArrayList<>(); | |
| 37 | - while (rst.next()) { | |
| 38 | - Map map = new HashMap(); | |
| 39 | - String eleName = rst.getString("元素名称"); | |
| 40 | - String result = rst.getString("测量值"); | |
| 41 | - map.put("result",result); | |
| 42 | - map.put("eleName",eleName); | |
| 43 | - microelements.add(map); | |
| 47 | + | |
| 48 | + public static void getMicroelementRecords(Map<String,Object> data) | |
| 49 | + { | |
| 50 | + Connection conn = null; | |
| 51 | + Statement sta = null; | |
| 52 | + ResultSet rst = null; | |
| 53 | + try { | |
| 54 | + String autoId = data.get("autoId").toString(); | |
| 55 | + sta = conn.createStatement(); | |
| 56 | + rst = sta.executeQuery("select * from ItemsInfo where BaseAutoId = "+autoId); | |
| 57 | + | |
| 58 | + List<Map> microelements = new ArrayList<>(); | |
| 59 | + while (rst.next()) { | |
| 60 | + Map map = new HashMap(); | |
| 61 | + String eleName = rst.getString("元素名称"); | |
| 62 | + String value = rst.getString("测量值"); | |
| 63 | + String result = StringUtils.checkNum(value); | |
| 64 | + map.put("result",result); | |
| 65 | + map.put("unit",value.contains("mmol") ? "mmol/l" : (value.contains("umol") ? "umol/l" : "ug/l")); | |
| 66 | + map.put("eleName",eleName); | |
| 67 | + map.put("refValue","");//TODO | |
| 68 | + microelements.add(map); | |
| 69 | + } | |
| 70 | + data.put("microelements", microelements); | |
| 71 | + data.remove("autoId"); | |
| 72 | + if (microelements.size() > 0) | |
| 73 | + { | |
| 74 | + String response = autoTransfer(data); | |
| 75 | + if (response.contains("0")) | |
| 76 | + { | |
| 77 | + sta.executeUpdate("update BaseInfo set status='1' where AUTOID="+autoId); | |
| 78 | + conn.commit(); | |
| 44 | 79 | } |
| 45 | - data.put("microelements",microelements); | |
| 46 | 80 | } |
| 81 | + | |
| 47 | 82 | } |
| 48 | - catch (SQLException e) { | |
| 83 | + catch (Exception e) { | |
| 84 | + try { | |
| 85 | + conn.rollback(); | |
| 86 | + } catch (SQLException e1) { | |
| 87 | + e1.printStackTrace(); | |
| 88 | + } | |
| 49 | 89 | } |
| 50 | 90 | finally { |
| 51 | - MicroelementConnection.close(conn,sta,rst); | |
| 91 | + MicroelementConnection.close(conn, sta,rst); | |
| 52 | 92 | } |
| 53 | - return data; | |
| 54 | 93 | } |
| 55 | 94 | |
| 56 | - public static void autoTransfer() | |
| 95 | + public static String autoTransfer( Map<String,Object> data) | |
| 57 | 96 | { |
| 58 | - Map<String,Object> data = getMicroelementRecords(); | |
| 59 | 97 | if (data != null && data.size() > 0) |
| 60 | 98 | { |
| 61 | 99 | String json = JsonUtil.obj2Str(data); |
| 62 | 100 | System.out.println(json); |
| 63 | 101 | String result = HttpClientUtil.doPostSSL(url,json); |
| 64 | 102 | System.out.println("http result= "+result); |
| 103 | + return result; | |
| 65 | 104 | } |
| 105 | + return ""; | |
| 66 | 106 | } |
| 67 | 107 | |
| 68 | - public static void main(String[] args) { | |
| 69 | - autoTransfer(); | |
| 70 | - } | |
| 108 | +// public static void main(String[] args) { | |
| 109 | +// getMicroelementRecords(); | |
| 110 | +// } | |
| 71 | 111 | } |
platform-transfer/src/main/resources/spring/applicationContext-quartz.xml
View file @
f3df881
| ... | ... | @@ -15,14 +15,14 @@ |
| 15 | 15 | <!-- 要调用的bean --> |
| 16 | 16 | <property name="targetObject" ref="microelementWorker"></property> |
| 17 | 17 | <!-- 要调用的Method --> |
| 18 | - <property name="targetMethod" value="microelementAutoTransfer"></property> | |
| 18 | + <property name="targetMethod" value="getMicroelementRecords"></property> | |
| 19 | 19 | <!-- 是否并发,false表示 如果发生错误也不影响下一次的调用 --> |
| 20 | 20 | <property name="concurrent" value="false"></property> |
| 21 | 21 | </bean> |
| 22 | 22 | <!-- 配置一个触发器 --> |
| 23 | 23 | <bean id="microelementWorkerTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> |
| 24 | 24 | <property name="jobDetail" ref="startWorkTask"></property> |
| 25 | - <property name="cronExpression" value="0 0 1 * * ?"></property> | |
| 25 | + <property name="cronExpression" value="0 0/1 * * * ?"></property> | |
| 26 | 26 | </bean> |
| 27 | 27 | |
| 28 | 28 | <!-- 总调度,用于启动定时器 --> |
platform-transfer/src/main/resources/spring/applicationContext.xml
View file @
f3df881