Browse Source

正则规则

wangfeng 4 years ago
parent
commit
41b110eac0

+ 17 - 0
src/main/java/com/diagbot/dto/RegularValueDTO.java

@@ -0,0 +1,17 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @author wangfeng
+ * @Description:
+ * @date 2020-12-01 9:46
+ */
+@Setter
+@Getter
+public class RegularValueDTO {
+    private String  key;
+    private String  value;
+    private Integer  type;
+}

+ 168 - 0
src/main/java/com/diagbot/entity/SysRegularConfig.java

@@ -0,0 +1,168 @@
+package com.diagbot.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author zhoutg
+ * @since 2020-11-30
+ */
+public class SysRegularConfig implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 资源ID
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 是否删除,N:未删除,Y:删除
+     */
+    private String isDeleted;
+
+    /**
+     * 记录创建时间
+     */
+    private Date gmtCreate;
+
+    /**
+     * 记录修改时间,如果时间是1970年则表示纪录未修改
+     */
+    private Date gmtModified;
+
+    /**
+     * 创建人,0表示无创建人值
+     */
+    private String creator;
+
+    /**
+     * 修改人,如果为0则表示纪录未修改
+     */
+    private String modifier;
+
+    /**
+     * 正则编码
+     */
+    private String rulesCode;
+
+    /**
+     * 正则名称
+     */
+    private String rulesName;
+
+    /**
+     * 正则类型
+     */
+    private Integer rulesTepy;
+
+    /**
+     * 正则式
+     */
+    private String rulesValue;
+
+    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 getRulesCode() {
+        return rulesCode;
+    }
+
+    public void setRulesCode(String rulesCode) {
+        this.rulesCode = rulesCode;
+    }
+    public String getRulesName() {
+        return rulesName;
+    }
+
+    public void setRulesName(String rulesName) {
+        this.rulesName = rulesName;
+    }
+    public Integer getRulesTepy() {
+        return rulesTepy;
+    }
+
+    public void setRulesTepy(Integer rulesTepy) {
+        this.rulesTepy = rulesTepy;
+    }
+    public String getRulesValue() {
+        return rulesValue;
+    }
+
+    public void setRulesValue(String rulesValue) {
+        this.rulesValue = rulesValue;
+    }
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    @Override
+    public String toString() {
+        return "SysRegularConfig{" +
+            "id=" + id +
+            ", isDeleted=" + isDeleted +
+            ", gmtCreate=" + gmtCreate +
+            ", gmtModified=" + gmtModified +
+            ", creator=" + creator +
+            ", modifier=" + modifier +
+            ", rulesCode=" + rulesCode +
+            ", rulesName=" + rulesName +
+            ", rulesTepy=" + rulesTepy +
+            ", rulesValue=" + rulesValue +
+            ", remark=" + remark +
+        "}";
+    }
+}

+ 60 - 0
src/main/java/com/diagbot/enums/RegularConfigEnum.java

@@ -0,0 +1,60 @@
+package com.diagbot.enums;
+
+import com.diagbot.core.KeyedNamed;
+import lombok.Setter;
+
+/**
+ * @author wangfeng
+ * @Description:
+ * @date 2020-12-01 11:10
+ */
+public enum RegularConfigEnum implements KeyedNamed {
+    lis(1, "化验"),
+    allergy(2, "过敏源");
+
+    @Setter
+    private int key;
+
+    @Setter
+    private String name;
+
+    RegularConfigEnum(int key, String name) {
+        this.key = key;
+        this.name = name;
+    }
+
+    public static RegularConfigEnum getEnum(int key) {
+        for (RegularConfigEnum item : RegularConfigEnum.values()) {
+            if (item.key == key) {
+                return item;
+            }
+        }
+        return null;
+    }
+
+    public static TypeEnum getEnum(String value) {
+        for (TypeEnum item : TypeEnum.values()) {
+            if (item.getName().equals(value)) {
+                return item;
+            }
+        }
+        return null;
+    }
+
+    public static String getName(int key) {
+        RegularConfigEnum item = getEnum(key);
+        return item != null ? item.name : null;
+    }
+
+    @Override
+    public int getKey() {
+        return key;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+
+}

+ 25 - 1
src/main/java/com/diagbot/facade/IndicationFacade.java

@@ -1,14 +1,19 @@
 package com.diagbot.facade;
 
+import com.baomidou.mybatisplus.extension.api.R;
+import com.diagbot.biz.push.entity.Lis;
 import com.diagbot.client.StandConvertServiceClient;
 import com.diagbot.dto.IndicationDTO;
+import com.diagbot.dto.RegularValueDTO;
 import com.diagbot.dto.WordCrfDTO;
+import com.diagbot.enums.RegularConfigEnum;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
 import com.diagbot.rule.CommonRule;
 import com.diagbot.util.CoreUtil;
 import com.diagbot.util.ListUtil;
 import com.diagbot.vo.IndicationPushVO;
+import com.diagbot.vo.RegularConfigDataVO;
 import com.diagbot.vo.StandConvert;
 import io.github.lvyahui8.spring.facade.DataFacade;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,6 +44,8 @@ public class IndicationFacade {
     StandConvertServiceClient standConvertServiceClient;
     @Autowired
     CommonRule commonRule;
+    @Autowired
+    SysRegularConfigFacade sysRegularConfigFacade;
 
     private static final Map<String, List<String>> methodMap;
 
@@ -85,7 +92,24 @@ public class IndicationFacade {
             wordCrfDTO = commonFacade.crf_process(indicationPushVO);
         }
         CoreUtil.getDebugStr(crfStart, "模型处理耗时", debug);
-
+        //正则匹配
+        String symptom = wordCrfDTO.getSymptom();
+        RegularConfigDataVO  regularConfigData= new RegularConfigDataVO();
+        regularConfigData.setText(symptom);
+        List<RegularValueDTO> regularConfigDatas = sysRegularConfigFacade.getRegularConfigDatas(regularConfigData);
+        List<Lis> lisData = wordCrfDTO.getLis();
+        if(ListUtil.isNotEmpty(regularConfigDatas)){
+            for(RegularValueDTO data:regularConfigDatas){
+                if(data.getType().equals(RegularConfigEnum.lis.getKey())){
+                    Lis lis = new Lis();
+                    lis.setUniqueName(data.getKey());
+                    lis.setName(data.getKey());
+                    lis.setValue(Double.valueOf(data.getValue()));
+                    lisData.add(lis);
+                }
+            }
+        }
+        wordCrfDTO.setLis(lisData);
         // 标准词转换
         long standStart = System.currentTimeMillis();
         if (methodList.contains("stand")) {

+ 62 - 0
src/main/java/com/diagbot/facade/SysRegularConfigFacade.java

@@ -0,0 +1,62 @@
+package com.diagbot.facade;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.diagbot.dto.RegularValueDTO;
+import com.diagbot.entity.SysRegularConfig;
+import com.diagbot.enums.IsDeleteEnum;
+import com.diagbot.enums.RegularConfigEnum;
+import com.diagbot.service.impl.SysRegularConfigServiceImpl;
+import com.diagbot.util.ListUtil;
+import com.diagbot.vo.RegularConfigDataVO;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author wangfeng
+ * @Description:
+ * @date 2020-11-30 16:10
+ */
+@Component
+public class SysRegularConfigFacade extends SysRegularConfigServiceImpl {
+
+    public List<RegularValueDTO> getRegularConfigDatas(RegularConfigDataVO regularConfigDataVO) {
+        List<RegularValueDTO> listData = new ArrayList<>();
+        QueryWrapper<SysRegularConfig> regularQuery = new QueryWrapper<>();
+        regularQuery.eq("is_deleted", IsDeleteEnum.N.getKey())
+                .eq(regularConfigDataVO.getRulesCode() != null, "rules_code", regularConfigDataVO.getRulesCode())
+                .eq(regularConfigDataVO.getRulesTepy() != null, "rules_tepy", regularConfigDataVO.getRulesTepy());
+        List<SysRegularConfig> regularConfigs = list(regularQuery);
+        if (ListUtil.isNotEmpty(regularConfigs)) {
+            for (SysRegularConfig data : regularConfigs) {
+                String pattern = data.getRulesValue();
+                // 创建 Pattern 对象
+                Pattern r = Pattern.compile(pattern);
+                // 现在创建 matcher 对象
+                Matcher m = r.matcher(regularConfigDataVO.getText());
+                while (m.find()) {
+                    //System.out.println(m.group());
+                    String steing = m.group();
+                    String key ="";
+                    String value = "";
+                    Integer type = data.getRulesTepy();
+                    if(data.getRulesTepy().equals(RegularConfigEnum.lis.getKey())){
+                        value = steing.replaceAll("([^\\d\\.]|\\.(?=[^\\.]*\\.))", "");
+                    }
+                    RegularValueDTO regularValueDTO = new RegularValueDTO();
+                    regularValueDTO.setKey(data.getRulesName());
+                    regularValueDTO.setType(type);
+                    regularValueDTO.setValue(value);
+                    listData.add(regularValueDTO);
+                    System.out.println(listData.toString());
+                }
+            }
+        }
+        return listData;
+    }
+
+}

+ 16 - 0
src/main/java/com/diagbot/mapper/SysRegularConfigMapper.java

@@ -0,0 +1,16 @@
+package com.diagbot.mapper;
+
+import com.diagbot.entity.SysRegularConfig;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author zhoutg
+ * @since 2020-11-30
+ */
+public interface SysRegularConfigMapper extends BaseMapper<SysRegularConfig> {
+
+}

+ 16 - 0
src/main/java/com/diagbot/service/SysRegularConfigService.java

@@ -0,0 +1,16 @@
+package com.diagbot.service;
+
+import com.diagbot.entity.SysRegularConfig;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author zhoutg
+ * @since 2020-11-30
+ */
+public interface SysRegularConfigService extends IService<SysRegularConfig> {
+
+}

+ 20 - 0
src/main/java/com/diagbot/service/impl/SysRegularConfigServiceImpl.java

@@ -0,0 +1,20 @@
+package com.diagbot.service.impl;
+
+import com.diagbot.entity.SysRegularConfig;
+import com.diagbot.mapper.SysRegularConfigMapper;
+import com.diagbot.service.SysRegularConfigService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author zhoutg
+ * @since 2020-11-30
+ */
+@Service
+public class SysRegularConfigServiceImpl extends ServiceImpl<SysRegularConfigMapper, SysRegularConfig> implements SysRegularConfigService {
+
+}

+ 17 - 0
src/main/java/com/diagbot/vo/RegularConfigDataVO.java

@@ -0,0 +1,17 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @author wangfeng
+ * @Description:
+ * @date 2020-11-30 16:19
+ */
+@Setter
+@Getter
+public class RegularConfigDataVO {
+    private String text;
+    private String rulesCode;
+    private Integer rulesTepy;
+}

+ 45 - 0
src/main/java/com/diagbot/web/SysRegularConfigController.java

@@ -0,0 +1,45 @@
+package com.diagbot.web;
+
+
+import com.diagbot.dto.RegularValueDTO;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.facade.SysRegularConfigFacade;
+import com.diagbot.vo.RegularConfigDataVO;
+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;
+
+/**
+ * <p>
+ * 前端控制器
+ * </p>
+ *
+ * @author zhoutg
+ * @since 2020-11-30
+ */
+@RestController
+@RequestMapping("/sysRegularConfig")
+@Api(value = "正则匹配相关API", tags = { "正则匹配相关API" })
+@SuppressWarnings("unchecked")
+public class SysRegularConfigController {
+
+    @Autowired
+    SysRegularConfigFacade sysRegularConfigFacade;
+
+    @ApiOperation(value = "从文本中取出化验相应正则数据",
+            notes = "从文本中取出化验相应正则数据")
+    @PostMapping("/getRegularConfigData")
+    public RespDTO<List<RegularValueDTO>> getRegularConfigData(@Valid @RequestBody RegularConfigDataVO regularConfigDataVO) {
+        List<RegularValueDTO> data = sysRegularConfigFacade.getRegularConfigDatas(regularConfigDataVO);
+        return RespDTO.onSuc(data);
+    }
+
+}

+ 20 - 0
src/main/resources/mapper/SysRegularConfigMapper.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.diagbot.mapper.SysRegularConfigMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.diagbot.entity.SysRegularConfig">
+        <id column="id" property="id" />
+        <result column="is_deleted" property="isDeleted" />
+        <result column="gmt_create" property="gmtCreate" />
+        <result column="gmt_modified" property="gmtModified" />
+        <result column="creator" property="creator" />
+        <result column="modifier" property="modifier" />
+        <result column="rules_code" property="rulesCode" />
+        <result column="rules_name" property="rulesName" />
+        <result column="rules_tepy" property="rulesTepy" />
+        <result column="rules_value" property="rulesValue" />
+        <result column="remark" property="remark" />
+    </resultMap>
+
+</mapper>