Commit 35d3bb2362c2886427cfccfa2f0709a26bf28b42

Authored by fangcheng
1 parent df2a9041e7
Exists in master

数据同步模块工程

Showing 16 changed files with 484 additions and 4 deletions

center.manager/src/main/java/com/lyms/cm/entity/sys/SysPermissions.java View file @ 35d3bb2
1 1 package com.lyms.cm.entity.sys;
2 2  
3   -import com.baomidou.mybatisplus.annotations.TableId;
  3 +import java.io.Serializable;
  4 +
4 5 import com.baomidou.mybatisplus.annotations.TableField;
5 6 import com.baomidou.mybatisplus.annotations.TableName;
6   -import java.io.Serializable;
7 7  
8 8 /**
9 9 * <p>
center.manager/src/main/java/com/lyms/cm/entity/sys/SysRolePermissionMaps.java View file @ 35d3bb2
1 1 package com.lyms.cm.entity.sys;
2 2  
3   -import com.baomidou.mybatisplus.annotations.TableId;
  3 +import java.io.Serializable;
  4 +
4 5 import com.baomidou.mybatisplus.annotations.TableField;
5 6 import com.baomidou.mybatisplus.annotations.TableName;
6   -import java.io.Serializable;
7 7  
8 8 /**
9 9 * <p>
core.sdk/src/main/java/com/lyms/web/controller/BaseController.java View file @ 35d3bb2
... ... @@ -2,6 +2,8 @@
2 2  
3 3 import java.io.IOException;
4 4 import java.io.PrintWriter;
  5 +import java.net.InetAddress;
  6 +import java.net.UnknownHostException;
5 7 import java.text.SimpleDateFormat;
6 8 import java.util.Date;
7 9 import java.util.HashMap;
... ... @@ -314,6 +316,48 @@
314 316 }
315 317 return new MobileInfo(appVersion, systemVersion, deviceId, width, height, night != 0);
316 318 }
  319 +
  320 + /**
  321 + * <li>@Description:获取客户端IP
  322 + * <li>@param request
  323 + * <li>@return
  324 + * <li>创建人:方承
  325 + * <li>创建时间:2016年11月26日
  326 + * <li>修改人:
  327 + * <li>修改时间:
  328 + */
  329 + public static final String getHost(HttpServletRequest request) {
  330 + String ip = request.getHeader("X-Forwarded-For");
  331 + if (StrUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
  332 + ip = request.getHeader("Proxy-Client-IP");
  333 + }
  334 + if (StrUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
  335 + ip = request.getHeader("WL-Proxy-Client-IP");
  336 + }
  337 + if (StrUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
  338 + ip = request.getHeader("X-Real-IP");
  339 + }
  340 + if (StrUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
  341 + ip = request.getRemoteAddr();
  342 + }
  343 + if ("127.0.0.1".equals(ip)) {
  344 + InetAddress inet = null;
  345 + try { // 根据网卡取本机配置的IP
  346 + inet = InetAddress.getLocalHost();
  347 + } catch (UnknownHostException e) {
  348 + e.printStackTrace();
  349 + }
  350 + ip = inet.getHostAddress();
  351 + }
  352 + // 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
  353 + if (ip != null && ip.length() > 15) {
  354 + if (ip.indexOf(",") > 0) {
  355 + ip = ip.substring(0, ip.indexOf(","));
  356 + }
  357 + }
  358 + return ip;
  359 + }
  360 +
317 361  
318 362 }
hospital.web/pom.xml View file @ 35d3bb2
... ... @@ -23,6 +23,11 @@
23 23 <artifactId>hospital.mac</artifactId>
24 24 <version>${project.parent.version}</version>
25 25 </dependency>
  26 + <dependency>
  27 + <groupId>com.lyms</groupId>
  28 + <artifactId>sync.data</artifactId>
  29 + <version>${project.parent.version}</version>
  30 + </dependency>
26 31  
27 32 <!-- swagger2 need begin -->
28 33 <dependency>
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/generator/.gitignore View file @ 35d3bb2
1 1 /MysqlGenerator.java
  2 +/MysqlGeneratorHospital.java
sync.data/pom.xml View file @ 35d3bb2
  1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3 + <modelVersion>4.0.0</modelVersion>
  4 + <parent>
  5 + <groupId>com.lyms</groupId>
  6 + <artifactId>hospital.parent</artifactId>
  7 + <version>0.0.1-SNAPSHOT</version>
  8 + </parent>
  9 + <artifactId>sync.data</artifactId>
  10 + <dependencies>
  11 + <dependency>
  12 + <groupId>com.lyms</groupId>
  13 + <artifactId>core.sdk</artifactId>
  14 + <version>${project.parent.version}</version>
  15 + </dependency>
  16 + </dependencies>
  17 +</project>
sync.data/src/main/java/com/lyms/hospital/controller/CenterCallHospitalController.java View file @ 35d3bb2
  1 +package com.lyms.hospital.controller;
  2 +
  3 +import javax.servlet.http.HttpServletRequest;
  4 +
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.web.bind.annotation.RequestMapping;
  9 +import org.springframework.web.bind.annotation.RequestMethod;
  10 +import org.springframework.web.bind.annotation.ResponseBody;
  11 +import org.springframework.web.bind.annotation.RestController;
  12 +import com.alibaba.fastjson.JSONObject;
  13 +import com.lyms.spring.PropertiesUtil;
  14 +import com.lyms.sync.data.constants.SyncStatus;
  15 +import com.lyms.sync.data.service.SyncDataBasicService;
  16 +import com.lyms.web.controller.BaseController;
  17 +
  18 +@RestController
  19 +@RequestMapping(value = "/sync", method = RequestMethod.POST)
  20 +public class CenterCallHospitalController extends BaseController {
  21 +
  22 + private static Logger log = LoggerFactory.getLogger(CenterCallHospitalController.class);
  23 +
  24 + private static final String ALLOW_IP = PropertiesUtil.getString("sync_allow_ip");
  25 +
  26 + @Autowired
  27 + private SyncDataBasicService syncDataBasicService;
  28 +
  29 + @ResponseBody
  30 + @RequestMapping(value = "/getNeedSyncData", method = RequestMethod.POST)
  31 + public String getNeedSyncData(HttpServletRequest request) {
  32 + if (isAllow(request)) {
  33 + return getMsg(SyncStatus.SUCCESS,syncDataBasicService.getNeedSyncData());
  34 + }else{
  35 + return getMsg(SyncStatus.NOTALLOW);
  36 + }
  37 + }
  38 +
  39 + private boolean isAllow(HttpServletRequest request){
  40 + String ip = getHost(request);
  41 + if (ip.equalsIgnoreCase(ALLOW_IP)) {
  42 + return true;
  43 + }
  44 + log.info("不是受理允许的ip【{}】地址请求基础数据同步!", ip);
  45 + return false;
  46 + }
  47 +
  48 + /**
  49 + * <li>@Description:组装json字符串
  50 + * <li>@param status
  51 + * <li>@param dataObj
  52 + * <li>@return
  53 + * <li>创建人:方承
  54 + * <li>创建时间:2017年3月13日
  55 + * <li>修改人:
  56 + * <li>修改时间:
  57 + */
  58 + private String getMsg(SyncStatus status,Object ...dataObj){
  59 + JSONObject json = new JSONObject();
  60 + json.put("state", status);
  61 + if(status.equals(SyncStatus.NOTALLOW)){
  62 + json.put("data", "没有被授权的请求,您的所有信息已经保存,如果您再视图访问,本公司将保留追究法律责任的权利!");
  63 + }else{
  64 + json.put("data", JSONObject.toJSONString(dataObj));
  65 + }
  66 + return json.toJSONString();
  67 + }
  68 +
  69 +}
sync.data/src/main/java/com/lyms/sync/data/constants/EventType.java View file @ 35d3bb2
  1 +package com.lyms.sync.data.constants;
  2 +
  3 +public enum EventType {
  4 +
  5 + ADD(1),
  6 + DELETE(2),
  7 + UPDATE(3);
  8 +
  9 + private int type;
  10 +
  11 + private EventType(int type) {
  12 + this.setType(type);
  13 + }
  14 +
  15 + public int getType() {
  16 + return type;
  17 + }
  18 +
  19 + public void setType(int type) {
  20 + this.type = type;
  21 + }
  22 +
  23 +}
sync.data/src/main/java/com/lyms/sync/data/constants/ModuleType.java View file @ 35d3bb2
  1 +package com.lyms.sync.data.constants;
  2 +
  3 +public enum ModuleType {
  4 +
  5 + USER("user"),
  6 + ROLE("role"),
  7 + ORGANIZATION("org"),
  8 + DEPARTMENT("dep");
  9 +
  10 + private String type ;
  11 +
  12 + private ModuleType(String type) {
  13 + this.setType(type);
  14 + }
  15 +
  16 + public String getType() {
  17 + return type;
  18 + }
  19 +
  20 + public void setType(String type) {
  21 + this.type = type;
  22 + }
  23 +
  24 +}
sync.data/src/main/java/com/lyms/sync/data/constants/SyncStatus.java View file @ 35d3bb2
  1 +package com.lyms.sync.data.constants;
  2 +
  3 +public enum SyncStatus {
  4 +
  5 + SUCCESS("success"),
  6 + ERROR("error"),
  7 + NOTALLOW("notallow");
  8 +
  9 + private String code;
  10 +
  11 + private SyncStatus(String code) {
  12 + this.setCode(code);
  13 + }
  14 +
  15 + public String getCode() {
  16 + return code;
  17 + }
  18 +
  19 + public void setCode(String code) {
  20 + this.code = code;
  21 + }
  22 +
  23 +
  24 +}
sync.data/src/main/java/com/lyms/sync/data/dao/SyncDataBasicMapper.java View file @ 35d3bb2
  1 +package com.lyms.sync.data.dao;
  2 +
  3 +import com.lyms.sync.data.entity.SyncDataBasic;
  4 +import com.baomidou.mybatisplus.mapper.BaseMapper;
  5 +import org.springframework.stereotype.Repository;
  6 +import java.io.Serializable;
  7 +/**
  8 + * <p>
  9 + * Mapper接口
  10 + * </p>
  11 + *
  12 + * @author fangcheng
  13 + * @since 2017-03-13
  14 + */
  15 +@Repository
  16 +public interface SyncDataBasicMapper extends BaseMapper<SyncDataBasic> {
  17 +
  18 + public Integer deleteLogicById(Serializable id);
  19 +
  20 +}
sync.data/src/main/java/com/lyms/sync/data/dao/SyncDataBasicMapper.xml View file @ 35d3bb2
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.lyms.sync.data.dao.SyncDataBasicMapper">
  4 +
  5 + <!-- 通用查询映射结果 -->
  6 + <resultMap id="BaseResultMap" type="com.lyms.sync.data.entity.SyncDataBasic">
  7 + <id column="ID" property="id" />
  8 + <result column="BID" property="bid" />
  9 + <result column="MODULE" property="module" />
  10 + <result column="EVENT" property="event" />
  11 + <result column="DATA" property="data" />
  12 + <result column="CREATE_TIME" property="createTime" />
  13 + <result column="IFSUC" property="ifsuc" />
  14 + </resultMap>
  15 +
  16 + <!-- 通用查询结果列 -->
  17 + <sql id="Base_Column_List">
  18 + ID AS id, BID AS bid, MODULE AS module, EVENT AS event, DATA AS data, CREATE_TIME AS createTime, IFSUC AS ifsuc
  19 + </sql>
  20 +</mapper>
sync.data/src/main/java/com/lyms/sync/data/entity/SyncDataBasic.java View file @ 35d3bb2
  1 +package com.lyms.sync.data.entity;
  2 +
  3 +import com.baomidou.mybatisplus.annotations.TableId;
  4 +import com.baomidou.mybatisplus.annotations.TableField;
  5 +import com.baomidou.mybatisplus.annotations.TableName;
  6 +import java.io.Serializable;
  7 +import java.util.Date;
  8 +
  9 +/**
  10 + * <p>
  11 + * 用户、角色、权限、医院、部门等基础数据同步
  12 + * </p>
  13 + *
  14 + * @author fangcheng
  15 + * @since 2017-03-13
  16 + */
  17 +@TableName("SYNC_DATA_BASIC")
  18 +public class SyncDataBasic implements Serializable {
  19 +
  20 + private static final long serialVersionUID = 1L;
  21 +
  22 + /**
  23 + *
  24 + */
  25 + @TableId(value="ID")
  26 + private String id;
  27 + /**
  28 + * 数据对象业务主键
  29 + */
  30 + @TableField(value="BID")
  31 + private String bid;
  32 + /**
  33 + * 模块
  34 + */
  35 + @TableField(value="MODULE")
  36 + private String module;
  37 + /**
  38 + * 事件,1a,2d,3u
  39 + */
  40 + @TableField(value="EVENT")
  41 + private Integer event;
  42 + /**
  43 + * 数据对象
  44 + */
  45 + @TableField(value="DATA")
  46 + private String data;
  47 + /**
  48 + * 创建时间
  49 + */
  50 + @TableField(value="CREATE_TIME")
  51 + private Date createTime;
  52 + /**
  53 + * 数据上传是否成功
  54 + */
  55 + @TableField(value="IFSUC")
  56 + private Integer ifsuc;
  57 +
  58 +
  59 + public String getId() {
  60 + return id;
  61 + }
  62 +
  63 + public void setId(String id) {
  64 + this.id = id;
  65 + }
  66 +
  67 + public String getBid() {
  68 + return bid;
  69 + }
  70 +
  71 + public void setBid(String bid) {
  72 + this.bid = bid;
  73 + }
  74 +
  75 + public String getModule() {
  76 + return module;
  77 + }
  78 +
  79 + public void setModule(String module) {
  80 + this.module = module;
  81 + }
  82 +
  83 + public Integer getEvent() {
  84 + return event;
  85 + }
  86 +
  87 + public void setEvent(Integer event) {
  88 + this.event = event;
  89 + }
  90 +
  91 + public String getData() {
  92 + return data;
  93 + }
  94 +
  95 + public void setData(String data) {
  96 + this.data = data;
  97 + }
  98 +
  99 + public Date getCreateTime() {
  100 + return createTime;
  101 + }
  102 +
  103 + public void setCreateTime(Date createTime) {
  104 + this.createTime = createTime;
  105 + }
  106 +
  107 + public Integer getIfsuc() {
  108 + return ifsuc;
  109 + }
  110 +
  111 + public void setIfsuc(Integer ifsuc) {
  112 + this.ifsuc = ifsuc;
  113 + }
  114 +
  115 +}
sync.data/src/main/java/com/lyms/sync/data/parse/ParseDataBasicTools.java View file @ 35d3bb2
  1 +package com.lyms.sync.data.parse;
  2 +
  3 +/**
  4 + * <li>@ClassName: 解析基础数据的工具类
  5 + * <li>@Description: TODO(类描述)
  6 + * <li>@author 方承
  7 + * <li>@date 2017年3月13日
  8 + * <li>
  9 + */
  10 +public class ParseDataBasicTools {
  11 +
  12 +
  13 +
  14 +}
sync.data/src/main/java/com/lyms/sync/data/service/SyncDataBasicService.java View file @ 35d3bb2
  1 +package com.lyms.sync.data.service;
  2 +
  3 +import com.lyms.sync.data.constants.EventType;
  4 +import com.lyms.sync.data.constants.ModuleType;
  5 +import com.lyms.sync.data.entity.SyncDataBasic;
  6 +import com.lyms.web.service.BaseService;
  7 +import java.io.Serializable;
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * <p>
  12 + * 服务类
  13 + * </p>
  14 + *
  15 + * @author fangcheng
  16 + * @since 2017-03-13
  17 + */
  18 +public interface SyncDataBasicService extends BaseService<SyncDataBasic> {
  19 +
  20 + /**
  21 + * <li>@Description:逻辑删除,ifDel = 1 为删除,否则为没有删除
  22 + * <li>@param id 删除主键id
  23 + * <li>@return 大于0修改成功,否则为失败
  24 + */
  25 + public Integer deleteLogicById(Serializable id);
  26 +
  27 + /**
  28 + * <li>@Description:添加需要同步的数据
  29 + * <li>@param bid 业务主键id
  30 + * <li>@param moduleType 模块类型
  31 + * <li>@param eventType 时间类型
  32 + * <li>@param objData 数据对象
  33 + * <li>@return
  34 + * <li>创建人:方承
  35 + * <li>创建时间:2017年3月13日
  36 + * <li>修改人:
  37 + * <li>修改时间:
  38 + */
  39 + public boolean addSyncData(String bid, ModuleType moduleType, EventType eventType, Object objData);
  40 +
  41 +
  42 + /**
  43 + * <li>@Description:获取所有需要同步的数据列表
  44 + * <li>@return
  45 + * <li>创建人:方承
  46 + * <li>创建时间:2017年3月13日
  47 + * <li>修改人:
  48 + * <li>修改时间:
  49 + */
  50 + public List<SyncDataBasic> getNeedSyncData();
  51 +
  52 +}
sync.data/src/main/java/com/lyms/sync/data/service/impl/SyncDataBasicServiceImpl.java View file @ 35d3bb2
  1 +package com.lyms.sync.data.service.impl;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.List;
  5 +
  6 +import org.springframework.stereotype.Service;
  7 +
  8 +import com.alibaba.fastjson.JSONObject;
  9 +import com.baomidou.mybatisplus.mapper.EntityWrapper;
  10 +import com.baomidou.mybatisplus.service.impl.ServiceImpl;
  11 +import com.lyms.sync.data.constants.EventType;
  12 +import com.lyms.sync.data.constants.ModuleType;
  13 +import com.lyms.sync.data.dao.SyncDataBasicMapper;
  14 +import com.lyms.sync.data.entity.SyncDataBasic;
  15 +import com.lyms.sync.data.service.SyncDataBasicService;
  16 +import com.lyms.util.DateTimeUtils;
  17 +import com.lyms.util.StrUtils;
  18 +
  19 +/**
  20 + * <p>
  21 + * 用户、角色、权限、医院、部门等基础数据同步 服务实现类
  22 + * </p>
  23 + *
  24 + * @author fangcheng
  25 + * @since 2017-03-13
  26 + */
  27 +@Service
  28 +public class SyncDataBasicServiceImpl extends ServiceImpl<SyncDataBasicMapper, SyncDataBasic> implements SyncDataBasicService {
  29 +
  30 + public Integer deleteLogicById(Serializable id){
  31 + return baseMapper.deleteLogicById(id);
  32 + }
  33 +
  34 + @Override
  35 + public boolean addSyncData(String bid,ModuleType moduleType, EventType eventType, Object dataObj) {
  36 + SyncDataBasic entity = new SyncDataBasic();
  37 + entity.setId(StrUtils.uuid());
  38 + entity.setIfsuc(0);
  39 + entity.setCreateTime(DateTimeUtils.getNow());
  40 +
  41 + entity.setBid(bid);
  42 + entity.setModule(moduleType.getType());
  43 + entity.setEvent(eventType.getType());
  44 + entity.setData(JSONObject.toJSONString(dataObj));
  45 + return insert(entity);
  46 + }
  47 +
  48 + @Override
  49 + public List<SyncDataBasic> getNeedSyncData() {
  50 + return selectList(new EntityWrapper<SyncDataBasic>().where("IFSUC", "0"));
  51 + }
  52 +}