From 18a3086255dc6e73a88b1b38ba0ad4f95c50613f Mon Sep 17 00:00:00 2001 From: liquanyu Date: Wed, 10 Jan 2018 00:07:57 +0800 Subject: [PATCH] update code --- .../com/lyms/platform/pojo/MeasureInfoModel.java | 163 +++++++++++++++++++++ .../com/lyms/platform/query/MeasureInfoQuery.java | 131 +++++++++++++++++ .../operate/web/service/SyncDataTaskService.java | 44 ++---- .../platform/operate/web/utils/HttpClientUtil.java | 12 +- 4 files changed, 319 insertions(+), 31 deletions(-) create mode 100644 platform-dal/src/main/java/com/lyms/platform/pojo/MeasureInfoModel.java create mode 100644 platform-dal/src/main/java/com/lyms/platform/query/MeasureInfoQuery.java diff --git a/platform-dal/src/main/java/com/lyms/platform/pojo/MeasureInfoModel.java b/platform-dal/src/main/java/com/lyms/platform/pojo/MeasureInfoModel.java new file mode 100644 index 0000000..8d26fc3 --- /dev/null +++ b/platform-dal/src/main/java/com/lyms/platform/pojo/MeasureInfoModel.java @@ -0,0 +1,163 @@ +package com.lyms.platform.pojo; + +import org.springframework.data.mongodb.core.mapping.Document; + +import java.util.Date; + +/** + * Created by Administrator on 2018-01-09. + * 测量血糖和脉搏、身高和体重的值 + */ +@Document(collection = "lyms_measureInfo") +public class MeasureInfoModel { + + private Integer id; + //用户姓名 + private String userName; + //证件类型 + private String certType; + //证件号 + private String certNo; + //性别 + private Integer sex; + //就诊卡号 + private String vcCardNo; + //血压/体重 + private String valueOne; + //脉搏/身高 + private String valueTwo; + //值类型: 1 身高、体重 2 血压和脉搏 + private Integer valueType; + //记录时间 + private Date recordTime; + //微信号 + private String wxXode; + //记录总次数 + private Integer recordCount; + //openId + private String openId; + //创建时间 + private Date created; + //修改时间 + private Date modified; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getCertType() { + return certType; + } + + public void setCertType(String certType) { + this.certType = certType; + } + + public String getCertNo() { + return certNo; + } + + public void setCertNo(String certNo) { + this.certNo = certNo; + } + + public Integer getSex() { + return sex; + } + + public void setSex(Integer sex) { + this.sex = sex; + } + + public String getVcCardNo() { + return vcCardNo; + } + + public void setVcCardNo(String vcCardNo) { + this.vcCardNo = vcCardNo; + } + + public String getValueOne() { + return valueOne; + } + + public void setValueOne(String valueOne) { + this.valueOne = valueOne; + } + + public String getValueTwo() { + return valueTwo; + } + + public void setValueTwo(String valueTwo) { + this.valueTwo = valueTwo; + } + + public Integer getValueType() { + return valueType; + } + + public void setValueType(Integer valueType) { + this.valueType = valueType; + } + + public Date getRecordTime() { + return recordTime; + } + + public void setRecordTime(Date recordTime) { + this.recordTime = recordTime; + } + + public String getWxXode() { + return wxXode; + } + + public void setWxXode(String wxXode) { + this.wxXode = wxXode; + } + + public Integer getRecordCount() { + return recordCount; + } + + public void setRecordCount(Integer recordCount) { + this.recordCount = recordCount; + } + + public String getOpenId() { + return openId; + } + + public void setOpenId(String openId) { + this.openId = openId; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } + + public Date getModified() { + return modified; + } + + public void setModified(Date modified) { + this.modified = modified; + } +} diff --git a/platform-dal/src/main/java/com/lyms/platform/query/MeasureInfoQuery.java b/platform-dal/src/main/java/com/lyms/platform/query/MeasureInfoQuery.java new file mode 100644 index 0000000..8422eb6 --- /dev/null +++ b/platform-dal/src/main/java/com/lyms/platform/query/MeasureInfoQuery.java @@ -0,0 +1,131 @@ +package com.lyms.platform.query; + + +import com.lyms.platform.common.base.IConvertToNativeQuery; +import com.lyms.platform.common.dao.BaseQuery; +import com.lyms.platform.common.dao.operator.MongoCondition; +import com.lyms.platform.common.dao.operator.MongoOper; +import com.lyms.platform.common.dao.operator.MongoQuery; +import org.springframework.data.mongodb.core.query.Criteria; + +import java.util.Date; + +/** + * Created by Administrator on 2018-01-09. + * 测量血糖和脉搏、身高和体重的值 + */ +public class MeasureInfoQuery extends BaseQuery implements IConvertToNativeQuery { + + private Integer id; + //用户姓名 + private String userName; + //证件类型 + private String certType; + //证件号 + private String certNo; + //性别 + private Integer sex; + //就诊卡号 + private String vcCardNo; + //血压/体重 + private String valueOne; + + //手机号码 + private String phone; + + //脉搏/身高 + private String valueTwo; + //值类型: 1 身高、体重 2 血压和脉搏 + private Integer valueType; + //记录时间 + private Date recordTimeStart; + private Date recordTimeEnd; + //微信号 + private String wxCode; + //记录总次数 + private Integer recordCount; + //openId + private String openId; + //创建时间 + private Date created; + //修改时间 + private Date modified; + + @Override + public MongoQuery convertToQuery() { + MongoCondition condition = MongoCondition.newInstance(); + if (null != id) { + condition = condition.and("id", id, MongoOper.IS); + } + + if (null != userName) { + condition = condition.and("userName", userName, MongoOper.IS); + } + + if (null != certType) { + condition = condition.and("certType", certType, MongoOper.IS); + } + + if (null != certNo) { + condition = condition.and("certNo", certNo, MongoOper.IS); + } + + + if (null != sex) { + condition = condition.and("sex", sex, MongoOper.IS); + } + + + if (null != vcCardNo) { + condition = condition.and("vcCardNo", vcCardNo, MongoOper.IS); + } + + if (null != valueType) { + condition = condition.and("valueType", valueType, MongoOper.IS); + } + + + if (null != wxCode) { + condition = condition.and("wxCode", wxCode, MongoOper.IS); + } + + if (null != phone) { + condition = condition.and("phone", phone, MongoOper.IS); + } + + + + Criteria c1 = null; + if (null != recordTimeStart) { + if (null != c1) { + c1 = c1.and("recordTime").gte(recordTimeStart); + } else { + c1 = Criteria.where("recordTime").gte(recordTimeStart); + } + } + if (null != recordTimeEnd) { + if (c1 != null) { + c1 = c1.lte(recordTimeEnd); + } else { + c1 = Criteria.where("recordTime").lte(recordTimeEnd); + } + } + + if (null != c1) { + condition = condition.andCondition(new MongoCondition(c1)); + } + return condition.toMongoQuery(); + } + + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + +} diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/SyncDataTaskService.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/SyncDataTaskService.java index adf637c..37732a2 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/SyncDataTaskService.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/SyncDataTaskService.java @@ -138,35 +138,21 @@ public class SyncDataTaskService { { List list = JsonUtil.toList(json, SyncDataModel.class); System.out.println(DateUtil.getyyyy_MM_dd_hms(new Date())+url+" ; syncdata size = "+ list.size()); - int batchSize = 200; - int end = 0; - for (int i = 0; i < list.size(); i += batchSize) { - end = (end + batchSize); - if (end > list.size()) { - end = list.size(); - } - final List tempList = list.subList(i, end); - commonThreadPool.execute(new Runnable() { - @Override - public void run() { - if (CollectionUtils.isNotEmpty(tempList)) - { - StringBuffer ids = new StringBuffer(); - for (SyncDataModel model : tempList) { - boolean boo = mongoSyncService.syncData(model.getAction(), model.getDataId(), model.getClassName(), model.getJsonData()); - if (boo) { - ids.append(model.getId()); - ids.append(","); - } - } - if (ids.length() > 0) { - Map params = new HashMap(); - params.put("ids", ids.toString()); - excePost("https://" + url + "/updateSyncData", params); - } - } + if (CollectionUtils.isNotEmpty(list)) + { + StringBuffer ids = new StringBuffer(); + for (SyncDataModel model : list) { + boolean boo = mongoSyncService.syncData(model.getAction(), model.getDataId(), model.getClassName(), model.getJsonData()); + if (boo) { + ids.append(model.getId()); + ids.append(","); } - }); + } + if (ids.length() > 0) { + Map params = new HashMap(); + params.put("ids", ids.toString()); + excePost("https://" + url + "/updateSyncData", params); + } } } }catch(Exception ex){ @@ -176,7 +162,7 @@ public class SyncDataTaskService { } - private synchronized String excePost(String url,Map param) + private String excePost(String url,Map param) { String json = HttpClientUtil.doPost(url, param, "utf-8"); return json; diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/HttpClientUtil.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/HttpClientUtil.java index 52e45cf..781997a 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/HttpClientUtil.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/HttpClientUtil.java @@ -59,6 +59,7 @@ public class HttpClientUtil { HttpClient httpClient = null; HttpPost httpPost = null; String result = null; + HttpResponse response = null; try{ httpClient = new SSLClient(); @@ -75,7 +76,7 @@ public class HttpClientUtil { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list,charset); httpPost.setEntity(entity); } - HttpResponse response = httpClient.execute(httpPost); + response = httpClient.execute(httpPost); if(response != null){ HttpEntity resEntity = response.getEntity(); if(resEntity != null){ @@ -87,9 +88,16 @@ public class HttpClientUtil { return null; } finally { + if (response != null) { + try { + EntityUtils.consume(response.getEntity()); + } catch (IOException e) { + e.printStackTrace(); + } + } if (httpPost != null) { - httpPost.reset(); + httpPost.releaseConnection(); } } -- 1.8.3.1