Commit e2abd2c5a9db257569635a395dbbb7bad2177088

Authored by litao@lymsh.com
1 parent 38611d53c5

改bug

Showing 12 changed files with 364 additions and 5 deletions

platform-common/src/main/java/com/lyms/platform/common/dao/BaseSyncDataDao.java View file @ e2abd2c
  1 +package com.lyms.platform.common.dao;
  2 +
  3 +/**
  4 + * 区域和线上数据相互同步
  5 + */
  6 +public interface BaseSyncDataDao<T> {
  7 +
  8 + void save(T entity);
  9 +
  10 + void update(T entity);
  11 +
  12 + void delete(T entity);
  13 +
  14 +}
platform-common/src/main/java/com/lyms/platform/common/dao/BaseSyncDataDaoImpl.java View file @ e2abd2c
  1 +package com.lyms.platform.common.dao;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.lyms.platform.common.enums.CrudEnums;
  6 +import com.lyms.platform.common.enums.SyncStatusEnmus;
  7 +import com.lyms.platform.common.enums.YnEnums;
  8 +import com.lyms.platform.common.pojo.SyncRegionDataModel;
  9 +import com.lyms.platform.common.utils.MongoConvertHelper;
  10 +import com.lyms.platform.common.utils.ReflectionUtils;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.data.mongodb.core.MongoTemplate;
  13 +import org.springframework.data.mongodb.core.query.Criteria;
  14 +import org.springframework.data.mongodb.core.query.Query;
  15 +import org.springframework.data.mongodb.core.query.Update;
  16 +import org.springframework.util.Assert;
  17 +
  18 +import java.util.Date;
  19 +
  20 +/**
  21 + * Created by lt on 2017/11/6 0006
  22 + */
  23 +public class BaseSyncDataDaoImpl<T> implements BaseSyncDataDao<T> {
  24 +
  25 + @Autowired
  26 + protected MongoTemplate mongoTemplate;
  27 +
  28 + @Override
  29 + public void save(T entity) {
  30 + mongoTemplate.save(entity);
  31 + syncData(entity, CrudEnums.CREATE);
  32 + }
  33 +
  34 + @Override
  35 + public void update(T entity) {
  36 + Update update = MongoConvertHelper
  37 + .convertToNativeUpdate(ReflectionUtils.getUpdateField(entity));
  38 + JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(entity));
  39 + mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(jsonObject.getString("id"))), update, entity.getClass());
  40 + syncData(entity, CrudEnums.UPDATE);
  41 + }
  42 +
  43 + @Override
  44 + public void delete(T entity) {
  45 + JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(entity));
  46 + jsonObject.put("yn", YnEnums.NO.getId());
  47 + entity = (T) JSON.parseObject(JSON.toJSONString(entity), entity.getClass());
  48 + update(entity);
  49 + }
  50 +
  51 + private void syncData(T entity, CrudEnums crudEnums) {
  52 + Assert.notNull(entity, "entity must not be null!");
  53 + Assert.notNull(crudEnums, "crudEnums must not be null!");
  54 +
  55 + SyncRegionDataModel syncModel = new SyncRegionDataModel();
  56 + syncModel.setAction(crudEnums.getAction());
  57 + syncModel.setClassName(entity.getClass().getName());
  58 + syncModel.setCreated(new Date());
  59 + syncModel.setJsonData(JSON.toJSONString(entity));
  60 + syncModel.setStatus(SyncStatusEnmus.WAITING_FOR_SYNC.getType());
  61 + mongoTemplate.save(syncModel);
  62 + }
  63 +
  64 +}
platform-common/src/main/java/com/lyms/platform/common/dao/SyncTestModel.java View file @ e2abd2c
  1 +package com.lyms.platform.common.dao;
  2 +
  3 +import org.springframework.data.mongodb.core.mapping.Document;
  4 +
  5 +import java.util.Date;
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +
  9 +@Document(collection="lyms_sync_test_model")
  10 +public class SyncTestModel {
  11 +
  12 + private String id;
  13 +
  14 + private Integer yn;
  15 +
  16 + private String name;
  17 +
  18 + private Date created;
  19 +
  20 + private List<String> list;
  21 +
  22 + private List<Map<String, Object>> mapList;
  23 +
  24 + private Map<String, Object> map;
  25 +
  26 + public String getId() {
  27 + return id;
  28 + }
  29 +
  30 + public void setId(String id) {
  31 + this.id = id;
  32 + }
  33 +
  34 + public Integer getYn() {
  35 + return yn;
  36 + }
  37 +
  38 + public void setYn(Integer yn) {
  39 + this.yn = yn;
  40 + }
  41 +
  42 + public String getName() {
  43 + return name;
  44 + }
  45 +
  46 + public void setName(String name) {
  47 + this.name = name;
  48 + }
  49 +
  50 + public Date getCreated() {
  51 + return created;
  52 + }
  53 +
  54 + public void setCreated(Date created) {
  55 + this.created = created;
  56 + }
  57 +
  58 + public List<String> getList() {
  59 + return list;
  60 + }
  61 +
  62 + public void setList(List<String> list) {
  63 + this.list = list;
  64 + }
  65 +
  66 + public List<Map<String, Object>> getMapList() {
  67 + return mapList;
  68 + }
  69 +
  70 + public void setMapList(List<Map<String, Object>> mapList) {
  71 + this.mapList = mapList;
  72 + }
  73 +
  74 + public Map<String, Object> getMap() {
  75 + return map;
  76 + }
  77 +
  78 + public void setMap(Map<String, Object> map) {
  79 + this.map = map;
  80 + }
  81 +
  82 + @Override
  83 + public String toString() {
  84 + return "SyncTestModel{" +
  85 + "id='" + id + '\'' +
  86 + ", yn=" + yn +
  87 + ", name='" + name + '\'' +
  88 + ", created=" + created +
  89 + ", list=" + list +
  90 + ", mapList=" + mapList +
  91 + ", map=" + map +
  92 + '}';
  93 + }
  94 +}
platform-common/src/main/java/com/lyms/platform/common/dao/SyncTestModelDao.java View file @ e2abd2c
  1 +package com.lyms.platform.common.dao;
  2 +
  3 +/**
  4 + * Created by lt on 2017/11/6 0006
  5 + */
  6 +public interface SyncTestModelDao extends BaseSyncDataDao<SyncTestModel> {
  7 +}
platform-common/src/main/java/com/lyms/platform/common/dao/SyncTestModelDaoImpl.java View file @ e2abd2c
  1 +package com.lyms.platform.common.dao;
  2 +
  3 +import org.springframework.stereotype.Repository;
  4 +
  5 +@Repository
  6 +public class SyncTestModelDaoImpl extends BaseSyncDataDaoImpl<SyncTestModel> implements SyncTestModelDao {
  7 +}
platform-common/src/main/java/com/lyms/platform/common/enums/CrudEnums.java View file @ e2abd2c
  1 +package com.lyms.platform.common.enums;
  2 +
  3 +public enum CrudEnums {
  4 + CREATE("CREATE"),
  5 + READ("READ"),
  6 + UPDATE("UPDATE"),
  7 + DELETE("DELETE");
  8 +
  9 + private String action;
  10 +
  11 + CrudEnums(String action) {
  12 + this.action = action;
  13 + }
  14 +
  15 + public String getAction() {
  16 + return action;
  17 + }
  18 +}
platform-common/src/main/java/com/lyms/platform/common/enums/SyncStatusEnmus.java View file @ e2abd2c
  1 +package com.lyms.platform.common.enums;
  2 +
  3 +/**
  4 + * Created by lt on 2017/11/6 0006
  5 + */
  6 +public enum SyncStatusEnmus {
  7 +
  8 + WAITING_FOR_SYNC(1, "等待同步"),
  9 + SYNCHRONIZATION(2, "已同步");
  10 +
  11 + private Integer type;
  12 + private String desc;
  13 +
  14 + SyncStatusEnmus(Integer type, String desc) {
  15 + this.type = type;
  16 + this.desc = desc;
  17 + }
  18 +
  19 + public Integer getType() {
  20 + return type;
  21 + }
  22 +
  23 + public void setType(Integer type) {
  24 + this.type = type;
  25 + }
  26 +
  27 + public String getDesc() {
  28 + return desc;
  29 + }
  30 +
  31 + public void setDesc(String desc) {
  32 + this.desc = desc;
  33 + }
  34 +}
platform-common/src/main/java/com/lyms/platform/common/pojo/SyncRegionDataModel.java View file @ e2abd2c
  1 +package com.lyms.platform.common.pojo;
  2 +
  3 +import org.springframework.data.mongodb.core.mapping.Document;
  4 +
  5 +import java.util.Date;
  6 +
  7 +@Document(collection = "lyms_sync_region_data")
  8 +public class SyncRegionDataModel {
  9 +
  10 + private String id;
  11 +
  12 + private Date created;
  13 +
  14 + private Date modified;
  15 +
  16 + private String action;
  17 +
  18 + private String className;
  19 +
  20 + private String jsonData;
  21 +
  22 + private Integer status; // 1:未同步 , 2:已同步
  23 +
  24 + public String getId() {
  25 + return id;
  26 + }
  27 +
  28 + public void setId(String id) {
  29 + this.id = id;
  30 + }
  31 +
  32 + public Date getCreated() {
  33 + return created;
  34 + }
  35 +
  36 + public void setCreated(Date created) {
  37 + this.created = created;
  38 + }
  39 +
  40 + public Date getModified() {
  41 + return modified;
  42 + }
  43 +
  44 + public void setModified(Date modified) {
  45 + this.modified = modified;
  46 + }
  47 +
  48 + public String getAction() {
  49 + return action;
  50 + }
  51 +
  52 + public void setAction(String action) {
  53 + this.action = action;
  54 + }
  55 +
  56 + public String getClassName() {
  57 + return className;
  58 + }
  59 +
  60 + public void setClassName(String className) {
  61 + this.className = className;
  62 + }
  63 +
  64 + public String getJsonData() {
  65 + return jsonData;
  66 + }
  67 +
  68 + public void setJsonData(String jsonData) {
  69 + this.jsonData = jsonData;
  70 + }
  71 +
  72 + public Integer getStatus() {
  73 + return status;
  74 + }
  75 +
  76 + public void setStatus(Integer status) {
  77 + this.status = status;
  78 + }
  79 +}
platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java View file @ e2abd2c
... ... @@ -970,6 +970,9 @@
970 970 Integer betweenDay = DateUtil.getDays(start, end);
971 971 Integer week = betweenDay / 7;
972 972 Integer day = betweenDay % 7;
  973 + if(week > 42) {
  974 + return "已分娩";
  975 + }
973 976 return "孕" + week + "周" + (day > 0 ? "+" + day + "天" : "");
974 977 }
975 978  
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/SyncRegionDataController.java View file @ e2abd2c
  1 +package com.lyms.platform.operate.web.controller;
  2 +
  3 +import com.lyms.platform.common.dao.SyncTestModel;
  4 +import com.lyms.platform.common.dao.SyncTestModelDao;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.stereotype.Controller;
  7 +import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.ResponseBody;
  9 +
  10 +@Controller
  11 +@RequestMapping("/sync/region")
  12 +public class SyncRegionDataController {
  13 + @Autowired
  14 + private SyncTestModelDao syncTestModelDao;
  15 +
  16 + @RequestMapping("/test/save")
  17 + @ResponseBody
  18 + public String test(SyncTestModel syncTestModel) {
  19 + syncTestModelDao.save(syncTestModel);
  20 + return "ok";
  21 + }
  22 +
  23 +}
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java View file @ e2abd2c
1 1 package com.lyms.platform.operate.web.controller;
2 2  
  3 +import com.alibaba.fastjson.JSON;
3 4 import com.lyms.hospitalapi.dzfy.DzfyFmService;
4 5 import com.lyms.hospitalapi.qhdfy.QhdfyFmService;
5 6 import com.lyms.hospitalapi.qhdfy.QhdfyHisService;
6 7  
... ... @@ -21,11 +22,13 @@
21 22 import com.lyms.platform.permission.service.OrganizationService;
22 23 import com.lyms.platform.pojo.*;
23 24 import com.lyms.platform.query.*;
  25 +import com.mongodb.Mongo;
24 26 import org.apache.commons.collections.CollectionUtils;
25 27 import org.apache.commons.io.FileUtils;
26 28 import org.apache.commons.lang.StringUtils;
27 29 import org.springframework.beans.factory.annotation.Autowired;
28 30 import org.springframework.beans.factory.annotation.Qualifier;
  31 +import org.springframework.data.authentication.UserCredentials;
29 32 import org.springframework.data.domain.Sort;
30 33 import org.springframework.data.mongodb.core.MongoTemplate;
31 34 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
... ... @@ -1203,8 +1206,21 @@
1203 1206 return "syncDzFmByPhone finish";
1204 1207 }
1205 1208  
1206   - public static void main(String[] a) {
1207   - try {
  1209 + public static void main(String[] a) throws Exception {
  1210 + Mongo mongo = new Mongo("119.90.57.26", 10001);
  1211 + UserCredentials credentials = new UserCredentials("platform", "platform123");
  1212 + MongoTemplate mongoTemplate = new MongoTemplate(mongo, "platform", credentials);
  1213 + PatientWeight pw = mongoTemplate.findById("123", PatientWeight.class);
  1214 + Map<String, String> s = new HashMap<>();
  1215 + s.put("name", "1");
  1216 + s.put("name2", "12");
  1217 + pw.setDayWeights(s);
  1218 + String json = JSON.toJSONString(pw);
  1219 + String clazz = "com.lyms.platform.pojo.PatientWeight";
  1220 + JSON.parseObject(json, Class.forName(clazz));
  1221 + mongoTemplate.save(pw);
  1222 +
  1223 + /* try {
1208 1224 List<String> list = FileUtils.readLines(new File("D:\\QHD.csv"), "gbk");
1209 1225 List<String> linenums = new ArrayList<>();
1210 1226 for (String line : list) {
... ... @@ -1225,7 +1241,7 @@
1225 1241 // FileUtils.writeStringToFile(new File("d:\\temp\\qhdfy_lost_data.csv"), sb.toString());
1226 1242 } catch (Exception e) {
1227 1243 e.printStackTrace();
1228   - }
  1244 + }*/
1229 1245 }
1230 1246  
1231 1247 @RequestMapping("/poll")
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java View file @ e2abd2c
... ... @@ -777,8 +777,8 @@
777 777 String householdAddress = findName(patient.getProvinceId()) + findName(patient.getCityId()) + findName(patient.getAreaId()) + findName(patient.getStreetId()) + patient.getAddress();
778 778 temp.put("householdAddress", householdAddress.replace("null", "")); /** 户籍地 */
779 779 temp.put("lastMenses", DateUtil.getyyyy_MM_dd(patient.getLastMenses()));
780   - temp.put("week", DateUtil.getWeek(patient.getLastMenses(), new Date()) > 42 ? "已分娩" : DateUtil.getWeekDesc(patient.getLastMenses(), new Date())); /** 当前孕周 */
781   - temp.put("buildWeek", DateUtil.getWeek(patient.getLastMenses(), patient.getBookbuildingDate()) > 42 ? "已分娩" : DateUtil.getWeekDesc(patient.getLastMenses(), patient.getBookbuildingDate())); /** 建档孕周 */
  780 + temp.put("week", DateUtil.getWeekDesc(patient.getLastMenses(), new Date())); /** 当前孕周 */
  781 + temp.put("buildWeek", DateUtil.getWeekDesc(patient.getLastMenses(), patient.getBookbuildingDate())); /** 建档孕周 */
782 782 temp.put("buildDate", DateUtil.getyyyy_MM_dd(patient.getBookbuildingDate())); /** 建档日期 */
783 783 temp.put("doctorName", couponMapper.getUserName(patient.getBookbuildingDoctor()));
784 784 temp.put("hospitalName", couponMapper.findHospitalNameById(patient.getHospitalId()));