zhoutg пре 5 година
родитељ
комит
936dc1b623

+ 3 - 1
common/src/main/java/com/diagbot/exception/CommonErrorCode.java

@@ -32,7 +32,9 @@ public enum CommonErrorCode implements ErrorCode {
     NOPERMISSION_ERROR("20020005", "无权限访问"),
     SERVICE_STOP_ERROR("20020006", "当前服务已停用"),
     NOTVALID_ERROR("20020007", "该产品未在有效服务期内,无法使用"),
-    EXPIRE_ERROR("20020008", "该产品已超出有效服务期,无法使用");
+    EXPIRE_ERROR("20020008", "该产品已超出有效服务期,无法使用"),
+    LICENCE_ERROR("20020009", "licence异常"),
+    LICENCE_EXPIRE("20020010", "licence已到期");
 
     private String code;
     private String msg;

Разлика између датотеке није приказан због своје велике величине
+ 117 - 0
common/src/main/java/com/diagbot/util/RSAEncrypt.java


+ 27 - 0
gateway-service/src/main/java/com/diagbot/client/TranServiceClient.java

@@ -0,0 +1,27 @@
+package com.diagbot.client;
+
+import com.diagbot.client.hystrix.TranServiceHystrix;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.dto.SysSetInfoDTO;
+import com.diagbot.vo.HospitalSetVO;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import javax.validation.Valid;
+import java.util.List;
+
+/**
+ * @Description: 调用信息对接层服务
+ * @author: gaodm
+ * @time: 2019/2/1 17:00
+ */
+@FeignClient(value = "tran-service", fallback = TranServiceHystrix.class)
+public interface TranServiceClient {
+    /**
+     * @param hospitalSetVO
+     * @return
+     */
+    @PostMapping("/sysSet/getSysSetInfoDatas")
+    RespDTO<List<SysSetInfoDTO>> getSysSetInfoDatas(@Valid @RequestBody HospitalSetVO hospitalSetVO);
+}

+ 29 - 0
gateway-service/src/main/java/com/diagbot/client/hystrix/TranServiceHystrix.java

@@ -0,0 +1,29 @@
+package com.diagbot.client.hystrix;
+
+import com.diagbot.client.TranServiceClient;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.dto.SysSetInfoDTO;
+import com.diagbot.vo.HospitalSetVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import javax.validation.Valid;
+import java.util.List;
+
+/**
+ * @Description: 调用信息对接层服务
+ * @author: gaodm
+ * @time: 2019/2/1 17:00
+ */
+@Component
+@Slf4j
+public class TranServiceHystrix implements TranServiceClient {
+
+    @Override
+    public RespDTO<List<SysSetInfoDTO>> getSysSetInfoDatas(@Valid HospitalSetVO hospitalSetVO) {
+        log.error("【hystrix】调用{}异常", "getSysSetInfoDatas");
+        return null;
+    }
+    
+    
+}

+ 28 - 0
gateway-service/src/main/java/com/diagbot/config/ScheduleTask.java

@@ -0,0 +1,28 @@
+package com.diagbot.config;
+
+import com.diagbot.client.TranServiceClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+
+/**
+ * @description:
+ * @author: zhoutg
+ * @time: 2019/11/19 13:52
+ */
+@Component
+@Configuration      //1.主要用于标记配置类,兼备Component的效果。
+@EnableScheduling   // 2.开启定时任务
+public class ScheduleTask {
+
+
+    // 添加定时任务,每天12点执行
+    @Scheduled(cron = "0 0 12 * * ?")
+    private void configureTasks() {
+        System.err.println("执行静态定时任务时间: " + LocalDateTime.now());
+    }
+}

+ 39 - 0
gateway-service/src/main/java/com/diagbot/dto/SysSetInfoDTO.java

@@ -0,0 +1,39 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 
+ * @author wangfeng
+ * @Description: TODO
+ * @date 2019年6月18日 上午10:24:42
+ */
+@Setter
+@Getter
+public class SysSetInfoDTO {
+
+    /**
+     * 医院编码
+     */
+    private String hospitalCode;
+
+    /**
+     * 访问的系统类型 1:user-service,2:diagbotman-service,3:uaa-service,4:log-service,5:bi-service,6:knowledge-service,7:feedback-service,8:icss-web
+     */
+    private Integer sysType;
+
+    /**
+     * 配置名称
+     */
+    private String name;
+    
+    /**
+     * 配置编码
+     */
+    private String code;
+    /**
+     * 配置值
+     */
+    private String value;
+}

+ 62 - 0
gateway-service/src/main/java/com/diagbot/filter/GlobalGatewayFilter.java

@@ -1,16 +1,23 @@
 package com.diagbot.filter;
 
 import com.diagbot.client.DiagbotmanServiceClient;
+import com.diagbot.client.TranServiceClient;
 import com.diagbot.dto.RespDTO;
+import com.diagbot.dto.SysSetInfoDTO;
 import com.diagbot.entity.HasPermissionDTO;
 import com.diagbot.entity.ServiceFilter;
 import com.diagbot.entity.ServiceToken;
 import com.diagbot.entity.SysLog;
 import com.diagbot.enums.SysTypeEnum;
 import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
 import com.diagbot.rabbit.MySender;
+import com.diagbot.util.DateUtil;
 import com.diagbot.util.EnDecodeUtil;
 import com.diagbot.util.GsonUtil;
+import com.diagbot.util.RSAEncrypt;
+import com.diagbot.util.StringUtil;
+import com.diagbot.vo.HospitalSetVO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -32,6 +39,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -45,8 +53,12 @@ import java.util.Map;
 public class GlobalGatewayFilter implements GlobalFilter {
 
     private static final String GATE_WAY_PREFIX = "/api";
+    private static final String LICENCE = "licence_day";
     private static Boolean IS_GENERATE = false;
     private static Map<String, Long> SERVICE_FILTER = new HashMap<>();
+    private static Map<String, String> licenceMap = new HashMap<>(); // licence对象
+    private static boolean initLicence = false; // 是否初始化licence
+
 
     @Value("${lantone.product}")
     private String lantonePrduct;
@@ -55,6 +67,8 @@ public class GlobalGatewayFilter implements GlobalFilter {
     DiagbotmanServiceClient diagbotmanServiceClient;
     @Autowired
     private MySender mySender;
+    @Autowired
+    TranServiceClient tranServiceClient;
 
 
     @Override
@@ -142,6 +156,10 @@ public class GlobalGatewayFilter implements GlobalFilter {
 
         }
 
+        // 进行licence校验
+        String hospitalCode = request.getHeaders().getFirst("hospitalCode");
+        verifyLicence(hospitalCode, serviceName);
+
         ServerHttpRequest.Builder builder = serverWebExchange.getRequest().mutate();
         builder.header("Authorization", "Authorization Bearer token");
         gatewayFilterChain.filter(serverWebExchange.mutate().request(builder.build()).build());
@@ -176,4 +194,48 @@ public class GlobalGatewayFilter implements GlobalFilter {
         }
         return serviceFilters;
     }
+
+
+    /**
+     * 校验licence
+     *
+     * @param hospitalCode 医院编码
+     * @param serviceName 服务
+     */
+    public void verifyLicence(String hospitalCode, String serviceName) {
+        // 初始化licence
+        if (!initLicence) {
+            HospitalSetVO hospitalSetVO = new HospitalSetVO();
+            hospitalSetVO.setCode(LICENCE);
+            RespDTO<List<SysSetInfoDTO>> respDTO = tranServiceClient.getSysSetInfoDatas(hospitalSetVO);
+            if (respDTO != null) {
+                for (SysSetInfoDTO setInfoDTO : respDTO.data) {
+                    String serName = SysTypeEnum.getName(setInfoDTO.getSysType());
+                    licenceMap.put(setInfoDTO.getHospitalCode() + serName.substring(0, serName.indexOf("-")), setInfoDTO.getValue());
+                }
+            }
+        }
+
+        // 校验
+        String value = licenceMap.get(hospitalCode + serviceName);
+        if (StringUtil.isNotEmpty(value)) {
+            String licence = "";
+            try {
+                licence = RSAEncrypt.decrypt(value);
+            } catch (Exception e) { // licence 被篡改
+                throw new CommonException(CommonErrorCode.LICENCE_ERROR);
+            }
+            String nowStr = DateUtil.format(new Date(), "YYYY-MM-dd HH:mm:ss");
+            System.out.println(nowStr);
+            System.out.println(licence);
+            if (licence.compareTo(nowStr) < 0) { // licence 已到期
+                throw new CommonException(CommonErrorCode.LICENCE_EXPIRE);
+            }
+        }
+    }
+
+
+    public void refreshLicence() {
+
+    }
 }

+ 19 - 0
gateway-service/src/main/java/com/diagbot/vo/HospitalSetVO.java

@@ -0,0 +1,19 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @author: ztg
+ * @Description:
+ * @date 2019年6月12日 下午3:30:26
+ */
+@Setter
+@Getter
+public class HospitalSetVO {
+
+    /**
+     * 配置编码
+     */
+    private String code;
+}

+ 1 - 1
tran-service/src/main/java/com/diagbot/dto/SysSetInfoDTO.java

@@ -64,7 +64,7 @@ public class SysSetInfoDTO {
     /**
      * 配置值
      */
-    private Integer value;
+    private String value;
 
     /**
      * 备注

+ 5 - 112
tran-service/src/main/java/com/diagbot/entity/SysSet.java

@@ -3,6 +3,8 @@ package com.diagbot.entity;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Getter;
+import lombok.Setter;
 
 import java.io.Serializable;
 import java.util.Date;
@@ -16,6 +18,8 @@ import java.util.Date;
  * @since 2019-08-14
  */
 @TableName("tran_sys_set")
+@Getter
+@Setter
 public class SysSet implements Serializable {
 
     private static final long serialVersionUID = 1L;
@@ -79,121 +83,10 @@ public class SysSet implements Serializable {
     /**
      * 配置值
      */
-    private Integer value;
+    private String value;
 
     /**
      * 备注
      */
     private String remark;
-
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-    public String getIsDeleted() {
-        return isDeleted;
-    }
-
-    public void setIsDeleted(String isDeleted) {
-        this.isDeleted = isDeleted;
-    }
-    public Date getGmtCreate() {
-        return gmtCreate;
-    }
-
-    public void setGmtCreate(Date gmtCreate) {
-        this.gmtCreate = gmtCreate;
-    }
-    public Date getGmtModified() {
-        return gmtModified;
-    }
-
-    public void setGmtModified(Date gmtModified) {
-        this.gmtModified = gmtModified;
-    }
-    public String getCreator() {
-        return creator;
-    }
-
-    public void setCreator(String creator) {
-        this.creator = creator;
-    }
-    public String getModifier() {
-        return modifier;
-    }
-
-    public void setModifier(String modifier) {
-        this.modifier = modifier;
-    }
-    public String getHospitalCode() {
-        return hospitalCode;
-    }
-
-    public void setHospitalCode(String hospitalCode) {
-        this.hospitalCode = hospitalCode;
-    }
-    public Integer getPlan() {
-        return plan;
-    }
-
-    public void setPlan(Integer plan) {
-        this.plan = plan;
-    }
-    public Integer getSysType() {
-        return sysType;
-    }
-
-    public void setSysType(Integer sysType) {
-        this.sysType = sysType;
-    }
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-    public String getCode() {
-        return code;
-    }
-
-    public void setCode(String code) {
-        this.code = code;
-    }
-    public Integer getValue() {
-        return value;
-    }
-
-    public void setValue(Integer value) {
-        this.value = value;
-    }
-    public String getRemark() {
-        return remark;
-    }
-
-    public void setRemark(String remark) {
-        this.remark = remark;
-    }
-
-    @Override
-    public String toString() {
-        return "SysSet{" +
-        "id=" + id +
-        ", isDeleted=" + isDeleted +
-        ", gmtCreate=" + gmtCreate +
-        ", gmtModified=" + gmtModified +
-        ", creator=" + creator +
-        ", modifier=" + modifier +
-        ", hospitalCode=" + hospitalCode +
-        ", plan=" + plan +
-        ", sysType=" + sysType +
-        ", name=" + name +
-        ", code=" + code +
-        ", value=" + value +
-        ", remark=" + remark +
-        "}";
-    }
 }

+ 18 - 0
tran-service/src/main/java/com/diagbot/facade/SysSetFacade.java

@@ -1,10 +1,13 @@
 package com.diagbot.facade;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.diagbot.dto.SysSetInfoDTO;
 import com.diagbot.entity.SysSet;
 import com.diagbot.service.impl.SysSetServiceImpl;
 import com.diagbot.util.BeanUtil;
 import com.diagbot.util.IntegerUtil;
+import com.diagbot.util.ListUtil;
+import com.diagbot.vo.HospitalListVO;
 import com.diagbot.vo.HospitalSetVO;
 import org.springframework.stereotype.Component;
 
@@ -33,4 +36,19 @@ public class SysSetFacade extends SysSetServiceImpl {
         return data;
     }
 
+
+    /**
+     * @param hospitalListVO
+     * @return
+     */
+    public List<SysSetInfoDTO> getSysSetInfoDataByList(HospitalListVO hospitalListVO) {
+        List<SysSet> sysSetData = this.list(new QueryWrapper<SysSet>()
+                .in(ListUtil.isNotEmpty( hospitalListVO.getHospitalCode()), "hospital_code", hospitalListVO.getHospitalCode())
+                .in(ListUtil.isNotEmpty( hospitalListVO.getSysType()), "sys_type", hospitalListVO.getSysType())
+                .in(ListUtil.isNotEmpty( hospitalListVO.getPlan()), "plan", hospitalListVO.getPlan())
+                .in(ListUtil.isNotEmpty( hospitalListVO.getCode()), "code", hospitalListVO.getCode())
+        );
+        List<SysSetInfoDTO> data = BeanUtil.listCopyTo(sysSetData, SysSetInfoDTO.class);
+        return data;
+    }
 }

+ 34 - 0
tran-service/src/main/java/com/diagbot/vo/HospitalListVO.java

@@ -0,0 +1,34 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * 
+ * @author ztg
+ * @Description: TODO
+ * @date 2019年6月12日 下午3:30:26
+ */
+@Setter
+@Getter
+public class HospitalListVO {
+
+	private List<String> hospitalCode;
+	
+	/**
+     * 访问的系统类型 1:user-service,2:diagbotman-service,3:uaa-service,4:log-service,5:bi-service,6:knowledge-service,7:feedback-service,8:icss-web
+     */
+    private List<Integer> sysType;
+
+    /**
+     * 方案编号
+     */
+    private List<Integer> plan;
+
+    /**
+     * 配置编码
+     */
+    private List<String> code;
+}

+ 9 - 0
tran-service/src/main/java/com/diagbot/web/SysSetController.java

@@ -40,4 +40,13 @@ public class SysSetController {
         List<SysSetInfoDTO> data = sysSetFacade.getSysSetInfoData(hospitalSetVO);
         return RespDTO.onSuc(data);
     }
+
+
+    @ApiOperation(value = "根据医院编码获取配置信息[by:wangfeng]", notes = "hospitalCode :医院code  必填<br> ")
+    @PostMapping("/getSysSetInfoDatasByList")
+    @SysLogger("getSysSetInfoDatasByList")
+    public RespDTO<List<SysSetInfoDTO>> getSysSetInfoDataByList(@Valid @RequestBody HospitalSetVO hospitalSetVO) {
+        List<SysSetInfoDTO> data = sysSetFacade.getSysSetInfoData(hospitalSetVO);
+        return RespDTO.onSuc(data);
+    }
 }