Explorar el Código

数据服务模式病历保存到redis

gaodm hace 5 años
padre
commit
99e20e619a
Se han modificado 23 ficheros con 824 adiciones y 0 borrados
  1. 15 0
      config-server/src/main/resources/shared/tran-service-dev.yml
  2. 15 0
      config-server/src/main/resources/shared/tran-service-local.yml
  3. 15 0
      config-server/src/main/resources/shared/tran-service-pro.yml
  4. 15 0
      config-server/src/main/resources/shared/tran-service-test.yml
  5. 8 0
      data-service/src/main/java/com/diagbot/client/TranServiceClient.java
  6. 16 0
      data-service/src/main/java/com/diagbot/client/hystrix/TranServiceHystrix.java
  7. 32 0
      data-service/src/main/java/com/diagbot/facade/MrFacade.java
  8. 18 0
      data-service/src/main/java/com/diagbot/vo/MrVO.java
  9. 55 0
      data-service/src/main/java/com/diagbot/vo/PushJoinVO.java
  10. 47 0
      data-service/src/main/java/com/diagbot/web/MrController.java
  11. 11 0
      tran-service/pom.xml
  12. 19 0
      tran-service/src/main/java/com/diagbot/config/IdcConfigurer.java
  13. 112 0
      tran-service/src/main/java/com/diagbot/config/RedisConfigurer.java
  14. 26 0
      tran-service/src/main/java/com/diagbot/dto/LisResult.java
  15. 13 0
      tran-service/src/main/java/com/diagbot/facade/MrFacade.java
  16. 36 0
      tran-service/src/main/java/com/diagbot/idc/AbstractIdCreater.java
  17. 26 0
      tran-service/src/main/java/com/diagbot/idc/IdCreater.java
  18. 71 0
      tran-service/src/main/java/com/diagbot/idc/VisibleIdCreater.java
  19. 28 0
      tran-service/src/main/java/com/diagbot/service/MrService.java
  20. 120 0
      tran-service/src/main/java/com/diagbot/service/impl/MrServiceImpl.java
  21. 18 0
      tran-service/src/main/java/com/diagbot/vo/MrVO.java
  22. 55 0
      tran-service/src/main/java/com/diagbot/vo/PushJoinVO.java
  23. 53 0
      tran-service/src/main/java/com/diagbot/web/MrController.java

+ 15 - 0
config-server/src/main/resources/shared/tran-service-dev.yml

@@ -66,6 +66,21 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  #redis
+  redis:
+    database:
+      mr: 7 # Redis病历索引
+    host: 192.168.2.236  #Redis服务器地址
+    port: 6379 # Redis服务器连接端口
+    password: lantone # Redis服务器连接密码(默认为空)
+    lettuce:
+      pool:
+        max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
+        max-idle: 5 # 连接池中的最大空闲连接
+        max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
+        min-idle: 0 # 连接池中的最小空闲连接
+    timeout: 20000 # 连接超时时间(毫秒)
+
 #mybatis
 mybatis-plus:
   mapper-locations: classpath:/mapper/*Mapper.xml

+ 15 - 0
config-server/src/main/resources/shared/tran-service-local.yml

@@ -66,6 +66,21 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  #redis
+  redis:
+    database:
+      mr: 8 # Redis病历索引
+    host: 192.168.2.236  #Redis服务器地址
+    port: 6379 # Redis服务器连接端口
+    password: lantone # Redis服务器连接密码(默认为空)
+    lettuce:
+      pool:
+        max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
+        max-idle: 5 # 连接池中的最大空闲连接
+        max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
+        min-idle: 0 # 连接池中的最小空闲连接
+    timeout: 20000 # 连接超时时间(毫秒)
+
 #mybatis
 mybatis-plus:
   mapper-locations: classpath:/mapper/*Mapper.xml

+ 15 - 0
config-server/src/main/resources/shared/tran-service-pro.yml

@@ -66,6 +66,21 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  #redis
+  redis:
+    database:
+      mr: 7 # Redis病历索引
+    host: 192.168.2.236  #Redis服务器地址
+    port: 6379 # Redis服务器连接端口
+    password: lantone # Redis服务器连接密码(默认为空)
+    lettuce:
+      pool:
+        max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
+        max-idle: 5 # 连接池中的最大空闲连接
+        max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
+        min-idle: 0 # 连接池中的最小空闲连接
+    timeout: 20000 # 连接超时时间(毫秒)
+
 #mybatis
 mybatis-plus:
   mapper-locations: classpath:/mapper/*Mapper.xml

+ 15 - 0
config-server/src/main/resources/shared/tran-service-test.yml

@@ -66,6 +66,21 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  #redis
+  redis:
+    database:
+      mr: 7 # Redis病历索引
+    host: 192.168.2.241  #Redis服务器地址
+    port: 6379 # Redis服务器连接端口
+    password: lantone # Redis服务器连接密码(默认为空)
+    lettuce:
+      pool:
+        max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
+        max-idle: 5 # 连接池中的最大空闲连接
+        max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
+        min-idle: 0 # 连接池中的最小空闲连接
+    timeout: 20000 # 连接超时时间(毫秒)
+
 #mybatis
 mybatis-plus:
   mapper-locations: classpath:/mapper/*Mapper.xml

+ 8 - 0
data-service/src/main/java/com/diagbot/client/TranServiceClient.java

@@ -4,6 +4,8 @@ import java.util.List;
 
 import javax.validation.Valid;
 
+import com.diagbot.vo.MrVO;
+import com.diagbot.vo.PushJoinVO;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -28,4 +30,10 @@ public interface TranServiceClient {
 	 */
     @PostMapping("/sysSet/getSysSetInfoDatas")
     RespDTO<List<SysSetInfoDTO>> getSysSetInfoDatas(@Valid @RequestBody HospitalSetVO hospitalSetVO);
+
+	@PostMapping("/mr/createMr")
+	RespDTO<String> createMr(@RequestBody PushJoinVO pushJoinVO);
+
+	@PostMapping("/mr/getMr")
+	RespDTO<PushJoinVO> getMr(@RequestBody @Valid MrVO mrVO);
 }

+ 16 - 0
data-service/src/main/java/com/diagbot/client/hystrix/TranServiceHystrix.java

@@ -4,6 +4,8 @@ import java.util.List;
 
 import javax.validation.Valid;
 
+import com.diagbot.vo.MrVO;
+import com.diagbot.vo.PushJoinVO;
 import org.springframework.stereotype.Component;
 
 import com.diagbot.client.TranServiceClient;
@@ -12,6 +14,8 @@ import com.diagbot.dto.SysSetInfoDTO;
 import com.diagbot.vo.HospitalSetVO;
 
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 
 /**
  * @Description: 调用信息对接层服务
@@ -27,4 +31,16 @@ public class TranServiceHystrix implements TranServiceClient {
 		log.error("【hystrix】调用{}异常", "getSysSetInfoDatas");
 		return null;
 	}
+
+	@Override
+	public RespDTO<String> createMr(@RequestBody PushJoinVO pushJoinVO){
+		log.error("【hystrix】调用{}异常", "createMr");
+		return null;
+	}
+
+	@Override
+	public RespDTO<PushJoinVO> getMr(@RequestBody @Valid MrVO mrVO){
+		log.error("【hystrix】调用{}异常", "getMr");
+		return null;
+	}
 }

+ 32 - 0
data-service/src/main/java/com/diagbot/facade/MrFacade.java

@@ -0,0 +1,32 @@
+package com.diagbot.facade;
+
+import com.diagbot.client.TranServiceClient;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.util.RespDTOUtil;
+import com.diagbot.vo.MrVO;
+import com.diagbot.vo.PushJoinVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description: 病历保存到redis装饰层
+ * @author: gaodm
+ * @time: 2019/8/28 16:25
+ */
+@Component
+public class MrFacade {
+    @Autowired
+    private TranServiceClient tranServiceClient;
+
+    public String createMr(PushJoinVO pushJoinVO) {
+        RespDTO<String> res = tranServiceClient.createMr(pushJoinVO);
+        RespDTOUtil.respNGDealCover(res, "调用远程服务【createMr】失败");
+        return res.data;
+    }
+
+    public PushJoinVO getMr(MrVO mrVO) {
+        RespDTO<PushJoinVO> res = tranServiceClient.getMr(mrVO);
+        RespDTOUtil.respNGDealCover(res, "调用远程服务【getMr】失败");
+        return res.data;
+    }
+}

+ 18 - 0
data-service/src/main/java/com/diagbot/vo/MrVO.java

@@ -0,0 +1,18 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2019/8/28 18:45
+ */
+@Getter
+@Setter
+public class MrVO {
+    @NotBlank(message = "请输入病历编号")
+    private String mrId; //病历编号
+}

+ 55 - 0
data-service/src/main/java/com/diagbot/vo/PushJoinVO.java

@@ -0,0 +1,55 @@
+package com.diagbot.vo;
+
+import com.diagbot.client.bean.LisResult;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotNull;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2019/8/28 17:44
+ */
+@Getter
+@Setter
+public class PushJoinVO {
+    @NotNull(message = "请输入年龄")
+    private Integer age;
+    @NotNull(message = "请输入性别")
+    private Integer sex;
+    private String symptom;
+    private String diag;
+    private String vital;
+    private List<LisResult> lis;
+    private String pacs;
+    @ApiModelProperty(hidden = true)
+    private String past;
+    private String other;
+    //不能分类文本
+    private String unknown;
+
+    private String diseaseName;
+    private String scaleName; //量表名称
+    @ApiModelProperty(hidden = true)
+    private Integer disType;  //0-普通病(默认不填),1-慢病,2-急诊
+    private String adverseReactions; //不良反应
+    private String indications;   //推理指标
+    private String hosCode;   //医院编码
+
+    //创建时间
+    @ApiModelProperty(hidden = true)
+    private String mrId; //病历编号
+    //创建时间
+    @ApiModelProperty(hidden = true)
+    private Date createTime;
+    //过期时间
+    @ApiModelProperty(hidden = true)
+    private Date expireTime;
+    //过期时间字符串
+    @ApiModelProperty(hidden = true)
+    private String expireTimeStr;
+}

+ 47 - 0
data-service/src/main/java/com/diagbot/web/MrController.java

@@ -0,0 +1,47 @@
+package com.diagbot.web;
+
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.facade.MrFacade;
+import com.diagbot.vo.MrVO;
+import com.diagbot.vo.PushJoinVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+
+/**
+ * @Description: 病历保存到redis控制层
+ * @author: gaodm
+ * @time: 2019/8/28 16:25
+ */
+@RestController
+@RequestMapping("/mr")
+@Api(value = "电子病历API[by:wangfeng]", tags = { "电子病历API" })
+@SuppressWarnings("unchecked")
+public class MrController {
+
+	@Autowired
+	private MrFacade mrFacade;
+
+	@ApiOperation(value = "保存病历信息:[by:gaodm]",
+			notes = "")
+	@PostMapping("/createMr")
+	@SysLogger("createMr")
+	public RespDTO<String> createMr(@RequestBody PushJoinVO pushJoinVO) {
+		return RespDTO.onSuc(mrFacade.createMr(pushJoinVO));
+	}
+
+	@ApiOperation(value = "获取病历信息 :[by:gaodm]",
+			notes = "mrId: 病历编号,必填<br>")
+	@PostMapping("/getMr")
+	@SysLogger("getMr")
+	public RespDTO<PushJoinVO> getMr(@RequestBody @Valid MrVO mrVO) {
+		return RespDTO.onSuc(mrFacade.getMr(mrVO));
+	}
+}

+ 11 - 0
tran-service/pom.xml

@@ -162,6 +162,17 @@
         <!--</dependency>-->
         <!--&lt;!&ndash; CXF webservice &ndash;&gt;-->
 
+        <!--redis设置-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+        <!-- 必须加上,jedis依赖此  -->
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-pool2</artifactId>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 19 - 0
tran-service/src/main/java/com/diagbot/config/IdcConfigurer.java

@@ -0,0 +1,19 @@
+package com.diagbot.config;
+
+import com.diagbot.idc.VisibleIdCreater;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @Description: ID生成器配置
+ * @author: gaodm
+ * @time: 2018/9/20 10:43
+ */
+@Configuration
+public class IdcConfigurer {
+
+    @Bean
+    public VisibleIdCreater visibleIdCreater() {
+        return new VisibleIdCreater(0, 0);
+    }
+}

+ 112 - 0
tran-service/src/main/java/com/diagbot/config/RedisConfigurer.java

@@ -0,0 +1,112 @@
+package com.diagbot.config;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cache.annotation.CachingConfigurerSupport;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
+import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
+import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+import java.time.Duration;
+
+@Configuration
+@Slf4j
+public class RedisConfigurer extends CachingConfigurerSupport {
+
+    @Value("${spring.redis.database.mr}")
+    private String databaseMr;
+    @Value("${spring.redis.host}")
+    private String host;
+    @Value("${spring.redis.password}")
+    private String password;
+    @Value("${spring.redis.port}")
+    private int port;
+    @Value("${spring.redis.timeout}")
+    private int timeout;
+    @Value("${spring.redis.lettuce.pool.max-active}")
+    private int maxActive;
+    @Value("${spring.redis.lettuce.pool.max-idle}")
+    private int maxIdle;
+    @Value("${spring.redis.lettuce.pool.max-wait}")
+    private long maxWaitMillis;
+    @Value("${spring.redis.lettuce.pool.min-idle}")
+    private int minIdle;
+
+    @Bean
+    public GenericObjectPoolConfig getRedisConfig() {
+        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
+        poolConfig.setMaxTotal(maxActive);
+        poolConfig.setMaxIdle(maxIdle);
+        poolConfig.setMaxWaitMillis(maxWaitMillis);
+        poolConfig.setMinIdle(minIdle);
+        return poolConfig;
+    }
+
+
+    private Jackson2JsonRedisSerializer getSerializer() {
+        Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
+        ObjectMapper om = new ObjectMapper();
+        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
+        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
+        jackson2JsonRedisSerializer.setObjectMapper(om);
+        return jackson2JsonRedisSerializer;
+    }
+
+    /**
+     * 电子病历使用的redis
+     *
+     * @return
+     */
+    @Bean("factoryForMr")
+    public LettuceConnectionFactory redisConnectionFactoryForIdc() {
+        return getRedisConnectionFactory(Integer.valueOf(databaseMr));
+    }
+
+    @Bean(name = "redisTemplateForMr")
+    public RedisTemplate<String, Object> redisTemplateForIdc(@Qualifier("factoryForMr") LettuceConnectionFactory factory) {
+        return getRedisTemplate(factory);
+    }
+
+
+    private LettuceConnectionFactory getRedisConnectionFactory(Integer database) {
+        RedisStandaloneConfiguration connection = new RedisStandaloneConfiguration();
+        connection.setHostName(host);
+        connection.setPort(port);
+        connection.setPassword(password);
+        connection.setDatabase(database);
+        GenericObjectPoolConfig poolConfig = getRedisConfig();
+        LettuceClientConfiguration builder = LettucePoolingClientConfiguration.builder()
+                .commandTimeout(Duration.ofMillis(timeout))
+                .poolConfig(poolConfig)
+                .shutdownTimeout(Duration.ZERO)
+                .build();
+        LettuceConnectionFactory factory = new LettuceConnectionFactory(connection, builder);
+        return factory;
+    }
+
+    private RedisTemplate<String, Object> getRedisTemplate(LettuceConnectionFactory factory) {
+        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
+        redisTemplate.setConnectionFactory(factory);
+
+        // value值的序列化
+        redisTemplate.setValueSerializer(getSerializer());
+        redisTemplate.setHashValueSerializer(getSerializer());
+        // key的序列化采用StringRedisSerializer
+        redisTemplate.setKeySerializer(new StringRedisSerializer());
+        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
+        redisTemplate.afterPropertiesSet();
+        return redisTemplate;
+    }
+}
+ 

+ 26 - 0
tran-service/src/main/java/com/diagbot/dto/LisResult.java

@@ -0,0 +1,26 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @Description:化验信息
+ * @Author:zhaops
+ * @time: 2018/12/19 14:03
+ */
+@Getter
+@Setter
+public class LisResult {
+    private String name;//套餐名称
+    private String detailName;//化验项名称
+    private String uniqueName;//公表名称
+    private Double value;//值
+    private Double maxValue;//最大值
+    private Double minValue;//最小值
+    private String units;//单位
+    private String otherValue;//其他结果,包括阴性阳性,文字描述等
+    @NotNull(message = "请输入数据来源")
+    private Integer source;
+}

+ 13 - 0
tran-service/src/main/java/com/diagbot/facade/MrFacade.java

@@ -0,0 +1,13 @@
+package com.diagbot.facade;
+
+import com.diagbot.service.impl.MrServiceImpl;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description: 病历保存到redis装饰层
+ * @author: gaodm
+ * @time: 2019/8/28 16:25
+ */
+@Component
+public class MrFacade extends MrServiceImpl {
+}

+ 36 - 0
tran-service/src/main/java/com/diagbot/idc/AbstractIdCreater.java

@@ -0,0 +1,36 @@
+package com.diagbot.idc;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Description: ID生成抽象类接口
+ * @author: gaodm
+ * @time: 2018/9/5 9:20
+ */
+public abstract class AbstractIdCreater<T> implements IdCreater<T> {
+
+    protected int machineId;
+    protected int dataCenterId;
+
+    public AbstractIdCreater(int machineId, int dataCenterId) {
+        this.machineId = machineId;
+        this.dataCenterId = dataCenterId;
+    }
+
+    @Override
+    public abstract Long getNextId(T param);
+
+    @Override
+    public List<Long> getNextIds(T param, int size) {
+        List<Long> longs = new ArrayList<>(size);
+        for (int i = 0; i < size; i++) {
+            longs.add(getNextId(param));
+        }
+        return longs;
+    }
+
+    protected long timeGen() {
+        return System.currentTimeMillis();
+    }
+}

+ 26 - 0
tran-service/src/main/java/com/diagbot/idc/IdCreater.java

@@ -0,0 +1,26 @@
+package com.diagbot.idc;
+
+import java.util.List;
+
+/**
+ * @Description: ID生成接口
+ * @author: gaodm
+ * @time: 2018/9/5 9:21
+ */
+public interface IdCreater<T> {
+
+    /**
+     * 生成一个id
+     *
+     * @return 生成的id
+     */
+    Long getNextId(T param);
+
+    /**
+     * 批量生成id
+     *
+     * @param size 生成数量
+     * @return 生成的id列表
+     */
+    List<Long> getNextIds(T param, int size);
+}

+ 71 - 0
tran-service/src/main/java/com/diagbot/idc/VisibleIdCreater.java

@@ -0,0 +1,71 @@
+package com.diagbot.idc;
+
+
+import com.diagbot.util.DateUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.RandomUtils;
+import org.apache.commons.lang3.time.DateUtils;
+
+import java.util.Calendar;
+
+/**
+ * @Description: 可见id每秒递增
+ * @author: gaodm
+ * @time: 2018/9/5 10:45
+ */
+@Slf4j
+public class VisibleIdCreater extends AbstractIdCreater<Integer> {
+
+    private long lastTimestamp = -1L;
+
+    private long sequence = 0L;
+    private long sequenceMask = 9999;
+
+    public VisibleIdCreater(int machineId, int dataCenterId) {
+        super(machineId, dataCenterId);
+    }
+
+    @Override
+    /**
+     *  对外id生成规则
+     *  180905123451110001
+     *  180905 - 12345 -  1   -  1   -     1     - 0001
+     *   日期 -  秒数  - 业务 - 机器 - 数据中心 - 秒内自增
+     *  @param type 业务id 1.订单 2.交易 3.退款
+     *  @return 生成的id
+     */
+    public synchronized Long getNextId(Integer type) {
+
+        Calendar calendar = Calendar.getInstance();
+
+        long timestamp = timeGen() / 1000;
+
+        if (timestamp < lastTimestamp) {
+            log.error(String.format("clock is moving backwards. Rejecting requests until %d.", lastTimestamp));
+            throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
+        }
+
+        if (lastTimestamp == timestamp) {
+            sequence = (sequence + 1);
+            if (sequence > sequenceMask) {
+                //timestamp = tilNextMillis(lastTimestamp);
+                log.error(String.format("id creater sequence is full. wait to next time"));
+                return null;
+            }
+        } else {
+            sequence = getNewSequence();
+        }
+
+        lastTimestamp = timestamp;
+
+        String date = DateUtil.format(calendar.getTime(), "yyMMdd");
+        long seconds = DateUtils.getFragmentInSeconds(calendar, Calendar.DAY_OF_YEAR);
+
+        return Long.valueOf(date + String.format("%05d", seconds) + String.valueOf(type) + machineId + dataCenterId + sequence);
+    }
+
+    private long getNewSequence() {
+        return RandomUtils.nextInt(1000, 2000);
+    }
+
+}

+ 28 - 0
tran-service/src/main/java/com/diagbot/service/MrService.java

@@ -0,0 +1,28 @@
+package com.diagbot.service;
+
+import com.diagbot.vo.PushJoinVO;
+
+/**
+ * @Description: 病历保存到redis接口
+ * @author: gaodm
+ * @time: 2019/8/28 16:25
+ */
+public interface MrService {
+
+    /**
+     * 创建病历信息
+     *
+     */
+    String createMr(PushJoinVO imgVerInfo);
+
+    /**
+     * 获取病历信息
+     *
+     */
+    PushJoinVO getMr(String mrId);
+
+    /**
+     * 删除病历信息
+     */
+    Boolean deleteMr(String mrId);
+}

+ 120 - 0
tran-service/src/main/java/com/diagbot/service/impl/MrServiceImpl.java

@@ -0,0 +1,120 @@
+package com.diagbot.service.impl;
+
+import com.diagbot.idc.VisibleIdCreater;
+import com.diagbot.service.MrService;
+import com.diagbot.util.DateUtil;
+import com.diagbot.vo.PushJoinVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.dao.DataAccessException;
+import org.springframework.data.redis.connection.RedisConnection;
+import org.springframework.data.redis.core.RedisCallback;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+
+/**
+ * @Description: 病历保存到redis接口实现
+ * @author: gaodm
+ * @time: 2019/8/28 16:25
+ */
+@Service
+@Slf4j
+public class MrServiceImpl implements MrService {
+    @Autowired
+    @Qualifier("redisTemplateForMr")
+    private RedisTemplate redisForMr;
+
+    @Autowired
+    private VisibleIdCreater visibleIdCreater;
+
+    private byte[] serializeKey(Object o) {
+        return redisForMr.getKeySerializer().serialize(o);
+    }
+
+    private byte[] serializeValue(Object o) {
+        return redisForMr.getValueSerializer().serialize(o);
+    }
+
+    private Object deserializeValue(byte[] b) {
+        return redisForMr.getValueSerializer().deserialize(b);
+    }
+
+    private byte[] getMrKey(String mrId) {
+        String mrFormat = "mr_%s";
+        return serializeKey(String.format(mrFormat, mrId));
+    }
+
+
+    /**
+     * 创建病历信息
+     */
+    @Override
+    public String createMr(PushJoinVO pushJoinVO) {
+        Date now = DateUtil.now();
+        final Date expireDate = DateUtil.addMonth(now, 5);
+        pushJoinVO.setCreateTime(now);
+        pushJoinVO.setExpireTime(expireDate);
+        pushJoinVO.setExpireTimeStr(DateUtil.format(expireDate, "yyyy-MM-dd HH:mm:ss"));
+        String mrId = visibleIdCreater.getNextId(5).toString();
+        pushJoinVO.setMrId(mrId);
+        final byte[] redis_key = getMrKey(mrId);
+        redisForMr.execute(new RedisCallback<Object>() {
+            @Override
+            public Object doInRedis(RedisConnection connection) throws DataAccessException {
+                //获取旧的
+                byte[] bytes = connection.get(redis_key);
+                //删除旧的
+                if (bytes != null) {
+                    connection.del(bytes);
+                }
+                //设置新的
+                connection.setEx(
+                        redis_key,
+                        (expireDate.getTime() - DateUtil.now().getTime()) / 1000,
+                        serializeValue(pushJoinVO)
+                );
+                return true;
+            }
+        });
+        return mrId;
+    }
+
+    /**
+     * 获取病历信息
+     */
+    @Override
+    public PushJoinVO getMr(String mrId) {
+        return (PushJoinVO) redisForMr.execute(new RedisCallback<Object>() {
+            @Override
+            public Object doInRedis(RedisConnection connection) throws DataAccessException {
+                byte[] redis_key = getMrKey(mrId);
+                byte[] bytes = connection.get(redis_key);
+                if (bytes == null) {
+                    return null;
+                }
+                return deserializeValue(bytes);
+            }
+        });
+    }
+
+    /**
+     * 删除用户短信验证码信息
+     */
+    /**
+     * 删除病历信息
+     */
+    @Override
+    public Boolean deleteMr(String mrId) {
+        final byte[] redis_key = getMrKey(mrId);
+        Long l = (Long) redisForMr.execute(new RedisCallback<Long>() {
+            @Override
+            public Long doInRedis(RedisConnection connection) throws DataAccessException {
+                return connection.del(redis_key);
+            }
+        });
+        return l > 0;
+    }
+}

+ 18 - 0
tran-service/src/main/java/com/diagbot/vo/MrVO.java

@@ -0,0 +1,18 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2019/8/28 18:45
+ */
+@Getter
+@Setter
+public class MrVO {
+    @NotBlank(message = "请输入病历编号")
+    private String mrId; //病历编号
+}

+ 55 - 0
tran-service/src/main/java/com/diagbot/vo/PushJoinVO.java

@@ -0,0 +1,55 @@
+package com.diagbot.vo;
+
+import com.diagbot.dto.LisResult;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotNull;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2019/8/28 17:44
+ */
+@Getter
+@Setter
+public class PushJoinVO {
+    @NotNull(message = "请输入年龄")
+    private Integer age;
+    @NotNull(message = "请输入性别")
+    private Integer sex;
+    private String symptom;
+    private String diag;
+    private String vital;
+    private List<LisResult> lis;
+    private String pacs;
+    @ApiModelProperty(hidden = true)
+    private String past;
+    private String other;
+    //不能分类文本
+    private String unknown;
+
+    private String diseaseName;
+    private String scaleName; //量表名称
+    @ApiModelProperty(hidden = true)
+    private Integer disType;  //0-普通病(默认不填),1-慢病,2-急诊
+    private String adverseReactions; //不良反应
+    private String indications;   //推理指标
+    private String hosCode;   //医院编码
+
+    //创建时间
+    @ApiModelProperty(hidden = true)
+    private String mrId; //病历编号
+    //创建时间
+    @ApiModelProperty(hidden = true)
+    private Date createTime;
+    //过期时间
+    @ApiModelProperty(hidden = true)
+    private Date expireTime;
+    //过期时间字符串
+    @ApiModelProperty(hidden = true)
+    private String expireTimeStr;
+}

+ 53 - 0
tran-service/src/main/java/com/diagbot/web/MrController.java

@@ -0,0 +1,53 @@
+package com.diagbot.web;
+
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.LisConfigDTO;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.facade.MrFacade;
+import com.diagbot.facade.TranLisConfigFacade;
+import com.diagbot.vo.LisConfigVO;
+import com.diagbot.vo.LisHospitalCodeVO;
+import com.diagbot.vo.MrVO;
+import com.diagbot.vo.PushJoinVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 病历保存到redis控制层
+ * @author: gaodm
+ * @time: 2019/8/28 16:25
+ */
+@RestController
+@RequestMapping("/mr")
+@Api(value = "电子病历API[by:wangfeng]", tags = { "电子病历API" })
+@SuppressWarnings("unchecked")
+public class MrController {
+
+	@Autowired
+	private MrFacade mrFacade;
+
+	@ApiOperation(value = "保存病历信息:[by:gaodm]",
+			notes = "")
+	@PostMapping("/createMr")
+	@SysLogger("createMr")
+	public RespDTO<String> createMr(@RequestBody PushJoinVO pushJoinVO) {
+		return RespDTO.onSuc(mrFacade.createMr(pushJoinVO));
+	}
+
+	@ApiOperation(value = "获取病历信息 :[by:gaodm]",
+			notes = "mrId: 病历编号,必填<br>")
+	@PostMapping("/getMr")
+	@SysLogger("getMr")
+	public RespDTO<PushJoinVO> getMr(@RequestBody @Valid MrVO mrVO) {
+		return RespDTO.onSuc(mrFacade.getMr(mrVO.getMrId()));
+	}
+}