Commit 06cffe29986c2f603f3b09557302e7cbdc5d87cb
1 parent
3cb43f20a7
Exists in
master
and in
6 other branches
update
Showing 7 changed files with 208 additions and 0 deletions
- platform-common/src/main/java/com/lyms/platform/common/utils/IpUtils.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/LisController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/LisFacade.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/MybatisSqlInterceptor.java
- platform-operate-api/src/main/resources/config.properties
- platform-operate-api/src/main/resources/mybatis.xml
- platform-operate-api/src/main/resources/spring/applicationContext-dal.xml
platform-common/src/main/java/com/lyms/platform/common/utils/IpUtils.java
View file @
06cffe2
| 1 | +package com.lyms.platform.common.utils; | |
| 2 | + | |
| 3 | +import org.apache.commons.collections.CollectionUtils; | |
| 4 | + | |
| 5 | +import java.util.HashSet; | |
| 6 | +import java.util.Set; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * ip 白名单验证 | |
| 10 | + * Created by Administrator on 2017-04-21. | |
| 11 | + */ | |
| 12 | +public class IpUtils { | |
| 13 | + | |
| 14 | + private static Set<String> ipSet = new HashSet<>(); | |
| 15 | + | |
| 16 | + static | |
| 17 | + { | |
| 18 | + String ips = PropertiesUtils.getPropertyValue("app_server_ip_white"); | |
| 19 | + if (StringUtils.isNotEmpty(ips)) | |
| 20 | + { | |
| 21 | + CollectionUtils.addAll(ipSet, ips.split(",")); | |
| 22 | + } | |
| 23 | + } | |
| 24 | + | |
| 25 | + public static boolean isWhite(String ip) { | |
| 26 | + return ipSet.contains(ip); | |
| 27 | + } | |
| 28 | + | |
| 29 | + | |
| 30 | +} |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/LisController.java
View file @
06cffe2
| ... | ... | @@ -129,6 +129,7 @@ |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * 获取lis和ris报告的接口 |
| 132 | + * 包含这个孕妇在整个区域的lis、ris数据 | |
| 132 | 133 | * @param vcCardNo 就诊卡号 |
| 133 | 134 | * @param sortType 排序类型(1,根据日期分类;2,根据检查项目分类) |
| 134 | 135 | * @return |
| ... | ... | @@ -141,6 +142,20 @@ |
| 141 | 142 | HttpServletRequest request) { |
| 142 | 143 | LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); |
| 143 | 144 | return lisFacade.getLisAndRisData(vcCardNo,sortType,loginState.getId()); |
| 145 | + } | |
| 146 | + | |
| 147 | + | |
| 148 | + /** | |
| 149 | + * 返回小程序查询个人的lis报告 | |
| 150 | + * 该接口由app服务器端调用 | |
| 151 | + * @param patientId 院内系统的孕妇的建档id | |
| 152 | + * @return | |
| 153 | + */ | |
| 154 | + @RequestMapping(method = RequestMethod.GET, value = "/getAppLis") | |
| 155 | + @ResponseBody | |
| 156 | + public BaseResponse getLisAndRisData(@RequestParam("patientId") String patientId, | |
| 157 | + HttpServletRequest request) { | |
| 158 | + return lisFacade.getAppLis(patientId,request); | |
| 144 | 159 | } |
| 145 | 160 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/LisFacade.java
View file @
06cffe2
| ... | ... | @@ -28,6 +28,7 @@ |
| 28 | 28 | import org.springframework.data.domain.Sort; |
| 29 | 29 | import org.springframework.stereotype.Component; |
| 30 | 30 | |
| 31 | +import javax.servlet.http.HttpServletRequest; | |
| 31 | 32 | import java.util.*; |
| 32 | 33 | |
| 33 | 34 | /** |
| ... | ... | @@ -384,6 +385,23 @@ |
| 384 | 385 | } |
| 385 | 386 | } |
| 386 | 387 | return result; |
| 388 | + } | |
| 389 | + | |
| 390 | + /** | |
| 391 | + * 返回小程序查询个人的lis报告 | |
| 392 | + * 该接口由app服务器端调用 | |
| 393 | + * @param patientId | |
| 394 | + * @param request | |
| 395 | + * @return | |
| 396 | + */ | |
| 397 | + public BaseResponse getAppLis(String patientId, HttpServletRequest request) { | |
| 398 | + | |
| 399 | + System.out.println(request.getRemoteAddr()); | |
| 400 | + System.out.println(request.getRemoteHost()); | |
| 401 | + System.out.println(request.getRemotePort()); | |
| 402 | + System.out.println(request.getRequestURI()); | |
| 403 | + System.out.println(request.getRequestURL()); | |
| 404 | + return null; | |
| 387 | 405 | } |
| 388 | 406 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/MybatisSqlInterceptor.java
View file @
06cffe2
| 1 | +package com.lyms.platform.operate.web.inteceptor; | |
| 2 | + | |
| 3 | + | |
| 4 | +import java.text.DateFormat; | |
| 5 | +import java.util.Date; | |
| 6 | +import java.util.List; | |
| 7 | +import java.util.Locale; | |
| 8 | +import java.util.Properties; | |
| 9 | + | |
| 10 | +import org.apache.ibatis.executor.Executor; | |
| 11 | +import org.apache.ibatis.mapping.BoundSql; | |
| 12 | +import org.apache.ibatis.mapping.MappedStatement; | |
| 13 | +import org.apache.ibatis.mapping.ParameterMapping; | |
| 14 | +import org.apache.ibatis.plugin.Interceptor; | |
| 15 | +import org.apache.ibatis.plugin.Intercepts; | |
| 16 | +import org.apache.ibatis.plugin.Invocation; | |
| 17 | +import org.apache.ibatis.plugin.Plugin; | |
| 18 | +import org.apache.ibatis.plugin.Signature; | |
| 19 | +import org.apache.ibatis.reflection.MetaObject; | |
| 20 | +import org.apache.ibatis.session.Configuration; | |
| 21 | +import org.apache.ibatis.session.ResultHandler; | |
| 22 | +import org.apache.ibatis.session.RowBounds; | |
| 23 | +import org.apache.ibatis.type.TypeHandlerRegistry; | |
| 24 | + | |
| 25 | +/** | |
| 26 | + * Created by Administrator on 2017-04-24. | |
| 27 | + */ | |
| 28 | +@Intercepts({ | |
| 29 | + @Signature(type = Executor.class, method = "update", args = { MappedStatement.class, Object.class }) }) | |
| 30 | +public class MybatisSqlInterceptor implements Interceptor { | |
| 31 | + | |
| 32 | + private Properties properties; | |
| 33 | + | |
| 34 | + public Object intercept(Invocation invocation) throws Throwable { | |
| 35 | + MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0]; | |
| 36 | + Object parameter = null; | |
| 37 | + if (invocation.getArgs().length > 1) { | |
| 38 | + parameter = invocation.getArgs()[1]; | |
| 39 | + } | |
| 40 | + String sqlId = mappedStatement.getId(); | |
| 41 | + BoundSql boundSql = mappedStatement.getBoundSql(parameter); | |
| 42 | + Configuration configuration = mappedStatement.getConfiguration(); | |
| 43 | + Object returnValue = null; | |
| 44 | + long start = System.currentTimeMillis(); | |
| 45 | + returnValue = invocation.proceed(); | |
| 46 | + long end = System.currentTimeMillis(); | |
| 47 | + long time = (end - start); | |
| 48 | + if (time > 1) { | |
| 49 | + String sql = getSql(configuration, boundSql, sqlId, time); | |
| 50 | + System.err.println(sql); | |
| 51 | + } | |
| 52 | + return returnValue; | |
| 53 | + } | |
| 54 | + | |
| 55 | + public static String getSql(Configuration configuration, BoundSql boundSql, String sqlId, long time) { | |
| 56 | + String sql = showSql(configuration, boundSql); | |
| 57 | + StringBuilder str = new StringBuilder(100); | |
| 58 | + str.append(sqlId); | |
| 59 | + str.append(":"); | |
| 60 | + str.append(sql); | |
| 61 | + str.append(":"); | |
| 62 | + str.append(time); | |
| 63 | + str.append("ms"); | |
| 64 | + return str.toString(); | |
| 65 | + } | |
| 66 | + | |
| 67 | + private static String getParameterValue(Object obj) { | |
| 68 | + String value = null; | |
| 69 | + if (obj instanceof String) { | |
| 70 | + value = "'" + obj.toString() + "'"; | |
| 71 | + } else if (obj instanceof Date) { | |
| 72 | + DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.CHINA); | |
| 73 | + value = "'" + formatter.format(new Date()) + "'"; | |
| 74 | + } else { | |
| 75 | + if (obj != null) { | |
| 76 | + value = obj.toString(); | |
| 77 | + } else { | |
| 78 | + value = ""; | |
| 79 | + } | |
| 80 | + | |
| 81 | + } | |
| 82 | + return value; | |
| 83 | + } | |
| 84 | + | |
| 85 | + public static String showSql(Configuration configuration, BoundSql boundSql) { | |
| 86 | + Object parameterObject = boundSql.getParameterObject(); | |
| 87 | + List<ParameterMapping> parameterMappings = boundSql.getParameterMappings(); | |
| 88 | + String sql = boundSql.getSql().replaceAll("[\\s]+", " "); | |
| 89 | + if (parameterMappings.size() > 0 && parameterObject != null) { | |
| 90 | + TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry(); | |
| 91 | + if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) { | |
| 92 | + sql = sql.replaceFirst("\\?", getParameterValue(parameterObject)); | |
| 93 | + | |
| 94 | + } else { | |
| 95 | + MetaObject metaObject = configuration.newMetaObject(parameterObject); | |
| 96 | + for (ParameterMapping parameterMapping : parameterMappings) { | |
| 97 | + String propertyName = parameterMapping.getProperty(); | |
| 98 | + if (metaObject.hasGetter(propertyName)) { | |
| 99 | + Object obj = metaObject.getValue(propertyName); | |
| 100 | + sql = sql.replaceFirst("\\?", getParameterValue(obj)); | |
| 101 | + } else if (boundSql.hasAdditionalParameter(propertyName)) { | |
| 102 | + Object obj = boundSql.getAdditionalParameter(propertyName); | |
| 103 | + sql = sql.replaceFirst("\\?", getParameterValue(obj)); | |
| 104 | + } | |
| 105 | + } | |
| 106 | + } | |
| 107 | + } | |
| 108 | + System.out.println("========"+sql); | |
| 109 | + return sql; | |
| 110 | + } | |
| 111 | + | |
| 112 | + public Object plugin(Object target) { | |
| 113 | + return Plugin.wrap(target, this); | |
| 114 | + } | |
| 115 | + | |
| 116 | + public void setProperties(Properties properties0) { | |
| 117 | + this.properties = properties0; | |
| 118 | + } | |
| 119 | +} |
platform-operate-api/src/main/resources/config.properties
View file @
06cffe2
platform-operate-api/src/main/resources/mybatis.xml
View file @
06cffe2
| 1 | +<?xml version="1.0" encoding="UTF-8" ?> | |
| 2 | +<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" | |
| 3 | + "http://mybatis.org/dtd/mybatis-3-config.dtd"> | |
| 4 | +<configuration> | |
| 5 | +<settings> | |
| 6 | + <setting name="cacheEnabled" value="true" /> | |
| 7 | + <setting name="lazyLoadingEnabled" value="true" /> | |
| 8 | + <setting name="aggressiveLazyLoading" value="false" /> | |
| 9 | + <setting name="multipleResultSetsEnabled" value="true" /> | |
| 10 | + <setting name="useColumnLabel" value="true" /> | |
| 11 | + <setting name="autoMappingBehavior" value="FULL" /> | |
| 12 | + <setting name="defaultExecutorType" value="SIMPLE" /> | |
| 13 | + <setting name="defaultStatementTimeout" value="25000" /> | |
| 14 | +</settings> | |
| 15 | + <plugins> | |
| 16 | + <!-- mybatis写出sql记录控件(拦截器) --> | |
| 17 | + <plugin interceptor="com.lyms.platform.operate.web.inteceptor.MybatisSqlInterceptor"> <!-- 自己写的那个拦截器 --> | |
| 18 | + <property name="dialect" value="mysql"/> <!-- mysql的方言 --> | |
| 19 | + </plugin> | |
| 20 | + </plugins> | |
| 21 | +</configuration> |
platform-operate-api/src/main/resources/spring/applicationContext-dal.xml
View file @
06cffe2
| ... | ... | @@ -32,6 +32,7 @@ |
| 32 | 32 | |
| 33 | 33 | <bean id="masterSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> |
| 34 | 34 | <property name="dataSource" ref="masterdataSourceB"/> |
| 35 | + <property name="configLocation" value="classpath:mybatis.xml"/> | |
| 35 | 36 | <property name="mapperLocations"> |
| 36 | 37 | <list> |
| 37 | 38 | <value>classpath*:mainOrm/master/*.xml</value> |