Commit 4e8c60bed387649d2a6ee9ed091519c71fe85eb5

Authored by jiangjiazhi

Merge remote-tracking branch 'origin/master'

Showing 7 changed files

platform-biz-patient-service/src/main/java/com/lyms/platform/biz/BasicConfigServiceTest.java View file @ 4e8c60b
1 1 package com.lyms.platform.biz;
2 2  
  3 +import java.io.File;
  4 +import java.io.IOException;
3 5 import java.text.SimpleDateFormat;
4 6 import java.util.*;
5 7  
6   -import com.lyms.platform.pojo.DataPermissionsModel;
  8 +import com.lyms.platform.biz.service.GuidelinesService;
  9 +import com.lyms.platform.common.enums.YnEnums;
  10 +import com.lyms.platform.common.utils.JsonUtil;
  11 +import com.lyms.platform.common.utils.SystemConfig;
  12 +import com.lyms.platform.pojo.*;
  13 +import org.apache.commons.io.FileUtils;
7 14 import org.springframework.context.ApplicationContext;
8 15 import org.springframework.context.support.ClassPathXmlApplicationContext;
9 16  
10 17 import com.lyms.platform.biz.service.BabyService;
11 18 import com.lyms.platform.biz.service.PuerperaService;
12 19 import com.lyms.platform.biz.service.VisitService;
13   -import com.lyms.platform.pojo.BabyModel;
14   -import com.lyms.platform.pojo.PuerperaModel;
15   -import com.lyms.platform.pojo.VisitModel;
16 20 import com.lyms.platform.query.PuerperaModelQuery;
17 21 import org.springframework.data.mongodb.core.MongoTemplate;
18 22  
... ... @@ -71,7 +75,111 @@
71 75 System.out.println(users2.toString());
72 76 }*/
73 77 // addDataPermission(applicationContext);
74   - addVisit(applicationContext);
  78 +// addVisit(applicationContext);
  79 + addKidsGuidelines(applicationContext);
  80 + }
  81 +
  82 + public static void addKidsGuidelines(ApplicationContext applicationContext) {
  83 + MongoTemplate mongoTemplate
  84 + =(MongoTemplate)applicationContext.getBean("mongoTemplate");
  85 + mongoTemplate.getDb().authenticate("platform", "platform123".toCharArray());
  86 + Set<String> set = mongoTemplate.getCollectionNames();
  87 + for (String s:set) {
  88 + System.out.println(s);
  89 + }
  90 + try {
  91 + List<String> list = FileUtils.readLines(new File("E:\\temp\\儿童指导意见.csv"));
  92 + int i=0;
  93 + for (String line:list) {
  94 + i++;
  95 + String[] array = line.split(",");
  96 + if (array.length == 3) {
  97 + Guidelines guidelines = new Guidelines();
  98 + guidelines.setYn(YnEnums.YES.getId());
  99 + guidelines.setCategory(array[1]);
  100 + guidelines.setContent(array[2]);
  101 + guidelines.setType(3);
  102 + guidelines.setStart(Integer.valueOf(array[0]));
  103 + guidelines.setEnd(guidelines.getStart());
  104 + System.out.println(i+" == "+JsonUtil.obj2JsonString(guidelines));
  105 + mongoTemplate.save(guidelines);
  106 + }
  107 + }
  108 + } catch (IOException e) {
  109 + e.printStackTrace();
  110 + }
  111 + }
  112 +
  113 + public static void addGuidelines(ApplicationContext applicationContext) {
  114 + MongoTemplate mongoTemplate
  115 + =(MongoTemplate)applicationContext.getBean("mongoTemplate");
  116 + mongoTemplate.getDb().authenticate("platform", "platform123".toCharArray());
  117 + Set<String> set = mongoTemplate.getCollectionNames();
  118 + for (String s:set) {
  119 + System.out.println(s);
  120 + }
  121 + try {
  122 + List<String> list = FileUtils.readLines(new File("E:\\temp\\孕产报告指导意见.csv"));
  123 + int i=0;
  124 + for (String line:list) {
  125 + i++;
  126 + String[] array = line.split(",");
  127 + if (line.startsWith("孕")) {
  128 + if (array.length == 3) {
  129 + Guidelines guidelines = new Guidelines();
  130 + guidelines.setYn(YnEnums.YES.getId());
  131 + guidelines.setCategory(array[1]);
  132 + guidelines.setContent(array[2]);
  133 + guidelines.setType(1);
  134 + String[] subArray = array[0].split("-|—");
  135 + if (subArray.length == 2) {
  136 + guidelines.setStart(Integer.valueOf(subArray[0].replace("孕","").replace("周","")));
  137 + guidelines.setEnd(Integer.valueOf(subArray[1].replace("孕","").replace("周","")));
  138 + } else {
  139 + guidelines.setStart(Integer.valueOf(array[0].replace("孕","").replace("周","")));
  140 + guidelines.setEnd(guidelines.getStart());
  141 + }
  142 +//TODO mongoTemplate.save(guidelines);
  143 + }
  144 + } else if (line.startsWith("产后")) {
  145 + if (array.length == 3) {
  146 + Guidelines guidelines = new Guidelines();
  147 + guidelines.setYn(YnEnums.YES.getId());
  148 + guidelines.setCategory(array[1]);
  149 + guidelines.setContent(array[2]);
  150 + guidelines.setType(2);
  151 + if (array[0].endsWith("剖宫产")) {
  152 + array[0] = array[0].replace("——剖宫产", "");
  153 + guidelines.setDeliveryType("2");
  154 + } else if (array[0].endsWith("顺产")) {
  155 + array[0] = array[0].replace("——顺产", "");
  156 + guidelines.setDeliveryType("1");
  157 + }
  158 + String[] subArray = array[0].split("-|—");
  159 + if (subArray.length == 2) {
  160 + guidelines.setStart(Integer.valueOf(subArray[0].replace("产后","").replace("天","")));
  161 + guidelines.setEnd(Integer.valueOf(subArray[1].replace("产后","").replace("天","")));
  162 + } else {
  163 + guidelines.setStart(Integer.valueOf(array[0].replace("产后","").replace("天","")));
  164 + guidelines.setEnd(guidelines.getStart());
  165 + }
  166 + if (guidelines.getDeliveryType() == null) {
  167 + // 存两个
  168 + guidelines.setDeliveryType("1");
  169 + mongoTemplate.save(guidelines);
  170 + guidelines.setDeliveryType("2");
  171 + guidelines.setId(null);
  172 + mongoTemplate.save(guidelines);
  173 + } else {
  174 + mongoTemplate.save(guidelines);
  175 + }
  176 + System.out.println(i + " == " + JsonUtil.obj2JsonString(guidelines));
  177 + }
  178 + }
  179 + }
  180 + } catch (IOException e) {
  181 + e.printStackTrace();
  182 + }
75 183 }
76 184  
77 185 public static void addDataPermission(ApplicationContext applicationContext){
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/IGuidelinesDao.java View file @ 4e8c60b
  1 +package com.lyms.platform.biz.dal;
  2 +
  3 +import com.lyms.platform.common.dao.operator.MongoQuery;
  4 +import com.lyms.platform.common.dao.operator.Page;
  5 +import com.lyms.platform.pojo.BasicConfig;
  6 +import com.lyms.platform.pojo.Guidelines;
  7 +
  8 +import java.util.Collection;
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * Created by Administrator on 2016/8/2 0002.
  13 + */
  14 +public interface IGuidelinesDao {
  15 +
  16 + public Guidelines addGuidelines(Guidelines obj);
  17 +
  18 + public void updateGuidelines(Guidelines obj, String id);
  19 +
  20 + public void deleteGuidelines(String id);
  21 +
  22 + public Guidelines getGuidelines(String id);
  23 +
  24 + public int queryGuidelinesCount(MongoQuery query);
  25 +
  26 + public List<Guidelines> queryGuidelines(MongoQuery query);
  27 +
  28 + public Page<Guidelines> findPage(MongoQuery query);
  29 +
  30 + public Guidelines getOneGuidelinesById(String id);
  31 +
  32 +}
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/impl/GuidelinesDaoImpl.java View file @ 4e8c60b
  1 +package com.lyms.platform.biz.dal.impl;
  2 +
  3 +import com.lyms.platform.biz.dal.IBasicConfigDao;
  4 +import com.lyms.platform.biz.dal.IGuidelinesDao;
  5 +import com.lyms.platform.common.dao.BaseMongoDAOImpl;
  6 +import com.lyms.platform.common.dao.operator.MongoCondition;
  7 +import com.lyms.platform.common.dao.operator.MongoOper;
  8 +import com.lyms.platform.common.dao.operator.MongoQuery;
  9 +import com.lyms.platform.common.dao.operator.Page;
  10 +import com.lyms.platform.pojo.BasicConfig;
  11 +import com.lyms.platform.pojo.Guidelines;
  12 +import org.springframework.stereotype.Repository;
  13 +
  14 +import java.util.List;
  15 +
  16 +/**
  17 + * Created by Administrator on 2016/8/2 0002.
  18 + */
  19 +@Repository("guidelinesDao")
  20 +public class GuidelinesDaoImpl extends BaseMongoDAOImpl<Guidelines> implements IGuidelinesDao {
  21 + @Override
  22 + public Guidelines addGuidelines(Guidelines obj) {
  23 + return save(obj);
  24 + }
  25 +
  26 + @Override
  27 + public void updateGuidelines(Guidelines obj, String id) {
  28 + update(new MongoQuery(new MongoCondition("id", id, MongoOper.IS)).convertToMongoQuery(), obj);
  29 + }
  30 +
  31 + @Override
  32 + public void deleteGuidelines(String id) {
  33 + delete(new MongoQuery(new MongoCondition("id", id, MongoOper.IS)).convertToMongoQuery());
  34 + }
  35 +
  36 + @Override
  37 + public Guidelines getGuidelines(String id) {
  38 + return findById(id);
  39 + }
  40 +
  41 + @Override
  42 + public int queryGuidelinesCount(MongoQuery query) {
  43 + return (int) count(query.convertToMongoQuery());
  44 + }
  45 +
  46 + @Override
  47 + public List<Guidelines> queryGuidelines(MongoQuery query) {
  48 + return find(query.convertToMongoQuery());
  49 + }
  50 +
  51 + @Override
  52 + public Page<Guidelines> findPage(MongoQuery query) {
  53 + return findPage(query.convertToMongoQuery());
  54 + }
  55 +
  56 + @Override
  57 + public Guidelines getOneGuidelinesById(String id) {
  58 + return findById(id);
  59 + }
  60 +}
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/GuidelinesService.java View file @ 4e8c60b
  1 +package com.lyms.platform.biz.service;
  2 +
  3 +import com.google.common.cache.CacheLoader;
  4 +import com.google.common.cache.LoadingCache;
  5 +import com.lyms.platform.biz.dal.IGuidelinesDao;
  6 +import com.lyms.platform.common.dao.operator.MongoCondition;
  7 +import com.lyms.platform.common.dao.operator.MongoOper;
  8 +import com.lyms.platform.common.dao.operator.MongoQuery;
  9 +import com.lyms.platform.common.dao.operator.Page;
  10 +import com.lyms.platform.common.enums.YnEnums;
  11 +import com.lyms.platform.common.utils.CacheHelper;
  12 +import com.lyms.platform.pojo.BasicConfig;
  13 +import com.lyms.platform.pojo.Guidelines;
  14 +import com.lyms.platform.query.BasicConfigQuery;
  15 +import com.lyms.platform.query.GuidelinesQuery;
  16 +import org.apache.commons.lang.StringUtils;
  17 +import org.springframework.beans.factory.InitializingBean;
  18 +import org.springframework.beans.factory.annotation.Autowired;
  19 +import org.springframework.data.domain.Sort;
  20 +import org.springframework.stereotype.Service;
  21 +
  22 +import java.util.Collection;
  23 +import java.util.List;
  24 +
  25 +/**
  26 + * Created by Administrator on 2016/8/2 0002.
  27 + */
  28 +@Service("guidelinesService")
  29 +public class GuidelinesService implements InitializingBean {
  30 +
  31 + private LoadingCache<String, Guidelines> cached=null;
  32 +
  33 + @Autowired
  34 + private IGuidelinesDao guidelinesDao;
  35 +
  36 + public void addGuidelines(Guidelines obj) {
  37 + guidelinesDao.addGuidelines(obj);
  38 + }
  39 +
  40 + public void updateGuidelines(Guidelines obj) {
  41 + guidelinesDao.updateGuidelines(obj, obj.getId());
  42 + }
  43 +
  44 + public List<Guidelines> queryGuidelines(GuidelinesQuery guidelinesQuery) {
  45 + MongoQuery query = guidelinesQuery.convertToQuery();
  46 + if (StringUtils.isNotEmpty(guidelinesQuery.getNeed())) {
  47 + guidelinesQuery.mysqlBuild(guidelinesDao.queryGuidelinesCount(guidelinesQuery.convertToQuery()));
  48 + query.start(guidelinesQuery.getOffset()).end(guidelinesQuery.getLimit());
  49 + }
  50 +
  51 + return guidelinesDao.queryGuidelines(query.addOrder(Sort.Direction.ASC, "id"));
  52 + }
  53 +
  54 + public Guidelines getOneGuidelinesById(String id) {
  55 + try{
  56 + return cached.get(id);
  57 + }catch (Exception e){
  58 + }
  59 + return null;
  60 + }
  61 +
  62 + @Override
  63 + public void afterPropertiesSet() throws Exception {
  64 + //cache size 为400 缓存3分钟
  65 + cached = CacheHelper.cached(new CacheLoader<String, Guidelines>() {
  66 + @Override
  67 + public Guidelines load(String key) throws Exception {
  68 + return guidelinesDao.getOneGuidelinesById(key);
  69 + }
  70 + }, 400, 3);
  71 + }
  72 +}
platform-biz-patient-service/src/main/resources/database.properties View file @ 4e8c60b
1   -mongo.db.host=localhost
2   -mongo.db.port=27017
  1 +mongo.db.host=119.90.57.26
  2 +mongo.db.port=10001
3 3 mongo.db.dbname=platform
  4 +mongo.db.username=platform
  5 +mongo.db.password=platform123
platform-dal/src/main/java/com/lyms/platform/pojo/Guidelines.java View file @ 4e8c60b
  1 +package com.lyms.platform.pojo;
  2 +
  3 +import com.lyms.platform.common.result.BaseModel;
  4 +import org.springframework.data.annotation.Id;
  5 +import org.springframework.data.mongodb.core.mapping.Document;
  6 +
  7 +/**
  8 + * Created by Administrator on 2016/8/2 0002.
  9 + * 指导意见
  10 + */
  11 +@Document(collection="lyms_guidelines")
  12 +public class Guidelines extends BaseModel {
  13 +
  14 + private static final long serialVersionUID = 1L;
  15 + @Id
  16 + private String id;
  17 + /* 1:孕期,2:产后,3:儿童 */
  18 + private Integer type;
  19 +
  20 + /*分娩方式 FmTypeEnums*/
  21 + private String deliveryType;
  22 +
  23 + /* 孕期:周;产后:天;儿童:月 */
  24 + private Integer start;
  25 + private Integer end;
  26 +
  27 + private String category;
  28 + private String content;
  29 + private Integer yn;
  30 +
  31 + public String getDeliveryType() {
  32 + return deliveryType;
  33 + }
  34 +
  35 + public void setDeliveryType(String deliveryType) {
  36 + this.deliveryType = deliveryType;
  37 + }
  38 +
  39 + public String getId() {
  40 + return id;
  41 + }
  42 +
  43 + public void setId(String id) {
  44 + this.id = id;
  45 + }
  46 +
  47 + public Integer getType() {
  48 + return type;
  49 + }
  50 +
  51 + public void setType(Integer type) {
  52 + this.type = type;
  53 + }
  54 +
  55 + public Integer getStart() {
  56 + return start;
  57 + }
  58 +
  59 + public void setStart(Integer start) {
  60 + this.start = start;
  61 + }
  62 +
  63 + public Integer getEnd() {
  64 + return end;
  65 + }
  66 +
  67 + public void setEnd(Integer end) {
  68 + this.end = end;
  69 + }
  70 +
  71 + public String getCategory() {
  72 + return category;
  73 + }
  74 +
  75 + public void setCategory(String category) {
  76 + this.category = category;
  77 + }
  78 +
  79 + public String getContent() {
  80 + return content;
  81 + }
  82 +
  83 + public void setContent(String content) {
  84 + this.content = content;
  85 + }
  86 +
  87 + public Integer getYn() {
  88 + return yn;
  89 + }
  90 +
  91 + public void setYn(Integer yn) {
  92 + this.yn = yn;
  93 + }
  94 +}
platform-dal/src/main/java/com/lyms/platform/query/GuidelinesQuery.java View file @ 4e8c60b
  1 +package com.lyms.platform.query;
  2 +
  3 +import com.lyms.platform.common.base.IConvertToNativeQuery;
  4 +import com.lyms.platform.common.dao.BaseQuery;
  5 +import com.lyms.platform.common.dao.operator.MongoCondition;
  6 +import com.lyms.platform.common.dao.operator.MongoOper;
  7 +import com.lyms.platform.common.dao.operator.MongoQuery;
  8 +import com.lyms.platform.common.enums.YnEnums;
  9 +
  10 +/**
  11 + * Created by Administrator on 2016/8/2 0002.
  12 + */
  13 +public class GuidelinesQuery extends BaseQuery implements IConvertToNativeQuery {
  14 +
  15 + @Override
  16 + public MongoQuery convertToQuery() {
  17 + MongoCondition condition = MongoCondition.newInstance("yn", YnEnums.YES.getId(), MongoOper.IS);
  18 + if (null != id) {
  19 + condition = condition.and("id", id, MongoOper.IS);
  20 + }
  21 + if (null != type) {
  22 + condition = condition.and("type", type, MongoOper.IS);
  23 + }
  24 + if (null != deliveryType) {
  25 + condition = condition.and("deliveryType", deliveryType, MongoOper.IS);
  26 + }
  27 + if (null != maxStart) {
  28 + condition = condition.and("start", maxStart, MongoOper.LTE);
  29 + }
  30 + if (null != minStart) {
  31 + condition = condition.and("start", minStart, MongoOper.GTE);
  32 + }
  33 + if (null != maxEnd) {
  34 + condition = condition.and("end", maxEnd, MongoOper.LTE);
  35 + }
  36 + if (null != minEnd) {
  37 + condition = condition.and("end", minEnd, MongoOper.GTE);
  38 + }
  39 + return condition.toMongoQuery();
  40 + }
  41 +
  42 + private String id;
  43 + /* 1:孕期,2:产后,3:儿童 */
  44 + private Integer type;
  45 +
  46 + /* 孕期:周;产后:天;儿童:?TODO */
  47 + private Integer maxStart;
  48 + private Integer minStart;
  49 + private Integer maxEnd;
  50 + private Integer minEnd;
  51 + /*分娩方式 FmTypeEnums*/
  52 + private String deliveryType;
  53 +
  54 + public String getDeliveryType() {
  55 + return deliveryType;
  56 + }
  57 +
  58 + public void setDeliveryType(String deliveryType) {
  59 + this.deliveryType = deliveryType;
  60 + }
  61 +
  62 + public String getId() {
  63 + return id;
  64 + }
  65 +
  66 + public void setId(String id) {
  67 + this.id = id;
  68 + }
  69 +
  70 + public Integer getType() {
  71 + return type;
  72 + }
  73 +
  74 + public void setType(Integer type) {
  75 + this.type = type;
  76 + }
  77 +
  78 + public Integer getMaxStart() {
  79 + return maxStart;
  80 + }
  81 +
  82 + public void setMaxStart(Integer maxStart) {
  83 + this.maxStart = maxStart;
  84 + }
  85 +
  86 + public Integer getMinStart() {
  87 + return minStart;
  88 + }
  89 +
  90 + public void setMinStart(Integer minStart) {
  91 + this.minStart = minStart;
  92 + }
  93 +
  94 + public Integer getMaxEnd() {
  95 + return maxEnd;
  96 + }
  97 +
  98 + public void setMaxEnd(Integer maxEnd) {
  99 + this.maxEnd = maxEnd;
  100 + }
  101 +
  102 + public Integer getMinEnd() {
  103 + return minEnd;
  104 + }
  105 +
  106 + public void setMinEnd(Integer minEnd) {
  107 + this.minEnd = minEnd;
  108 + }
  109 +}