浏览代码

保存和获取病历V2版本

gaodm 5 年之前
父节点
当前提交
ab4ecf4cb4

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

@@ -5,6 +5,7 @@ import com.diagbot.dto.RespDTO;
 import com.diagbot.dto.SysSetInfoDTO;
 import com.diagbot.vo.HospitalSetVO;
 import com.diagbot.vo.MrVO;
+import com.diagbot.vo.PushJoinV2VO;
 import com.diagbot.vo.PushJoinVO;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -33,4 +34,10 @@ public interface TranServiceClient {
 
     @PostMapping("/mr/getMr")
     RespDTO<PushJoinVO> getMr(@RequestBody @Valid MrVO mrVO);
+
+    @PostMapping("/mrv2/createMr")
+    RespDTO<String> createMrv2(@RequestBody PushJoinV2VO pushJoinV2VO);
+
+    @PostMapping("/mrv2/getMr")
+    RespDTO<PushJoinV2VO> getMrv2(@RequestBody @Valid MrVO mrVO);
 }

+ 31 - 17
data-service/src/main/java/com/diagbot/client/hystrix/TranServiceHystrix.java

@@ -5,6 +5,7 @@ import com.diagbot.dto.RespDTO;
 import com.diagbot.dto.SysSetInfoDTO;
 import com.diagbot.vo.HospitalSetVO;
 import com.diagbot.vo.MrVO;
+import com.diagbot.vo.PushJoinV2VO;
 import com.diagbot.vo.PushJoinVO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
@@ -22,21 +23,34 @@ import java.util.List;
 @Slf4j
 public class TranServiceHystrix implements TranServiceClient {
 
-	@Override
-	public RespDTO<List<SysSetInfoDTO>> getSysSetInfoDatas(@Valid HospitalSetVO hospitalSetVO) {
-		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;
-	}
+    @Override
+    public RespDTO<List<SysSetInfoDTO>> getSysSetInfoDatas(@Valid HospitalSetVO hospitalSetVO) {
+        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;
+    }
+
+
+    @Override
+    public RespDTO<String> createMrv2(@RequestBody PushJoinV2VO pushJoinV2VO) {
+        log.error("【hystrix】调用{}异常", "createMrv2");
+        return null;
+    }
+
+    @Override
+    public RespDTO<PushJoinV2VO> getMrv2(@RequestBody @Valid MrVO mrVO) {
+        log.error("【hystrix】调用{}异常", "getMrv2");
+        return null;
+    }
 }

+ 32 - 0
data-service/src/main/java/com/diagbot/facade/MrV2Facade.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.PushJoinV2VO;
+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 MrV2Facade {
+    @Autowired
+    private TranServiceClient tranServiceClient;
+
+    public String createMr(PushJoinV2VO pushJoinV2VO) {
+        RespDTO<String> res = tranServiceClient.createMrv2(pushJoinV2VO);
+        RespDTOUtil.respNGDealCover(res, "调用远程服务【createMrv2】失败");
+        return res.data;
+    }
+
+    public PushJoinV2VO getMr(MrVO mrVO) {
+        RespDTO<PushJoinV2VO> res = tranServiceClient.getMrv2(mrVO);
+        RespDTOUtil.respNGDealCover(res, "调用远程服务【getMrv2】失败");
+        return res.data;
+    }
+}

+ 15 - 0
data-service/src/main/java/com/diagbot/vo/PushJoinV2VO.java

@@ -0,0 +1,15 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2019/8/28 17:44
+ */
+@Getter
+@Setter
+public class PushJoinV2VO extends PushJoinVO {
+    private String focus;
+}

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

@@ -0,0 +1,47 @@
+package com.diagbot.web;
+
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.facade.MrV2Facade;
+import com.diagbot.vo.MrVO;
+import com.diagbot.vo.PushJoinV2VO;
+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("/mrv2")
+@Api(value = "电子病历V2API[by:gaodm]", tags = { "电子病历V2API" })
+@SuppressWarnings("unchecked")
+public class MrV2Controller {
+
+    @Autowired
+    private MrV2Facade mrV2Facade;
+
+    @ApiOperation(value = "保存病历信息:[by:gaodm]",
+            notes = "")
+    @PostMapping("/createMr")
+    @SysLogger("createMr")
+    public RespDTO<String> createMr(@RequestBody PushJoinV2VO pushJoinVO) {
+        return RespDTO.onSuc(mrV2Facade.createMr(pushJoinVO));
+    }
+
+    @ApiOperation(value = "获取病历信息 :[by:gaodm]",
+            notes = "mrId: 病历编号,必填<br>")
+    @PostMapping("/getMr")
+    @SysLogger("getMr")
+    public RespDTO<PushJoinV2VO> getMr(@RequestBody @Valid MrVO mrVO) {
+        return RespDTO.onSuc(mrV2Facade.getMr(mrVO));
+    }
+}

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

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

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

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

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

@@ -0,0 +1,120 @@
+package com.diagbot.service.impl;
+
+import com.diagbot.idc.VisibleIdCreater;
+import com.diagbot.service.MrV2Service;
+import com.diagbot.util.DateUtil;
+import com.diagbot.vo.PushJoinV2VO;
+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 MrV2ServiceImpl implements MrV2Service {
+    @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 = "mrv2_%s";
+        return serializeKey(String.format(mrFormat, mrId));
+    }
+
+
+    /**
+     * 创建病历信息
+     */
+    @Override
+    public String createMr(PushJoinV2VO pushJoinV2VO) {
+        Date now = DateUtil.now();
+        final Date expireDate = DateUtil.addMinutes(now, 3);
+        pushJoinV2VO.setCreateTime(now);
+        pushJoinV2VO.setExpireTime(expireDate);
+        pushJoinV2VO.setExpireTimeStr(DateUtil.format(expireDate, "yyyy-MM-dd HH:mm:ss"));
+        String mrId = visibleIdCreater.getNextId(5).toString();
+        pushJoinV2VO.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(pushJoinV2VO)
+                );
+                return true;
+            }
+        });
+        return mrId;
+    }
+
+    /**
+     * 获取病历信息
+     */
+    @Override
+    public PushJoinV2VO getMr(String mrId) {
+        return (PushJoinV2VO) 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;
+    }
+}

+ 15 - 0
tran-service/src/main/java/com/diagbot/vo/PushJoinV2VO.java

@@ -0,0 +1,15 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2019/8/28 17:44
+ */
+@Getter
+@Setter
+public class PushJoinV2VO extends PushJoinVO {
+    private String focus;
+}

+ 47 - 0
tran-service/src/main/java/com/diagbot/web/MrV2Controller.java

@@ -0,0 +1,47 @@
+package com.diagbot.web;
+
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.facade.MrV2Facade;
+import com.diagbot.vo.MrVO;
+import com.diagbot.vo.PushJoinV2VO;
+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("/mrv2")
+@Api(value = "电子病历V2API[by:gaodm]", tags = { "电子病历V2API" })
+@SuppressWarnings("unchecked")
+public class MrV2Controller {
+
+    @Autowired
+    private MrV2Facade mrV2Facade;
+
+    @ApiOperation(value = "保存病历信息:[by:gaodm]",
+            notes = "")
+    @PostMapping("/createMr")
+    @SysLogger("createMr")
+    public RespDTO<String> createMr(@RequestBody PushJoinV2VO pushJoinVO) {
+        return RespDTO.onSuc(mrV2Facade.createMr(pushJoinVO));
+    }
+
+    @ApiOperation(value = "获取病历信息 :[by:gaodm]",
+            notes = "mrId: 病历编号,必填<br>")
+    @PostMapping("/getMr")
+    @SysLogger("getMr")
+    public RespDTO<PushJoinV2VO> getMr(@RequestBody @Valid MrVO mrVO) {
+        return RespDTO.onSuc(mrV2Facade.getMr(mrVO.getMrId()));
+    }
+}