Browse Source

居民标签工程

LiTaohong 6 years ago
parent
commit
e6beeb4c2c
83 changed files with 6962 additions and 0 deletions
  1. 42 0
      sql/init.sql
  2. 91 0
      svr/figure-label/pom.xml
  3. 63 0
      svr/figure-label/sql/label_es_sql
  4. 54 0
      svr/figure-label/sql/mysql.sql
  5. 32 0
      svr/figure-label/src/main/java/com/yihu/FigureLabelApplication.java
  6. 55 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/DruidConfig.java
  7. 159 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/FigureLabelJpa.java
  8. 27 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/HibernateProperties.java
  9. 36 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/properties/DataSourceLoginProperties.java
  10. 195 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/properties/DataSourceProperties.java
  11. 92 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/swagger/SwaggerConfig.java
  12. 21 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/war/ServletInitializer.java
  13. 17 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/constant/BusinessConstant.java
  14. 46 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/constant/ConstantUtil.java
  15. 440 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/controller/BaseController.java
  16. 77 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/controller/ESDataOperationController.java
  17. 131 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/controller/JobController.java
  18. 50 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/AddressConvert.java
  19. 56 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/AgeConvert.java
  20. 88 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/AgeRangeConvert.java
  21. 91 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/BasicDictItemHelper.java
  22. 67 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/BirthConvert.java
  23. 49 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/ConsultConvert.java
  24. 17 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/Convert.java
  25. 246 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/ConvertHelper.java
  26. 70 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/EhrHealthProblemConvert.java
  27. 216 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/EhrICD10CMConvert.java
  28. 49 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/EvaluateConvert.java
  29. 122 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/FeedbackConvert.java
  30. 21 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/FollowupStatusConvert.java
  31. 57 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/HealthEduArticalConvert.java
  32. 76 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/HealthEduArticleReceiveConvert.java
  33. 55 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/IsConsultConvert.java
  34. 60 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/IsDrinkingConvert.java
  35. 59 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/IsOnlineConvert.java
  36. 60 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/IsSmokingConvert.java
  37. 114 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/MutilThreadConvert.java
  38. 54 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/OnLineConsultConvert.java
  39. 56 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/OnlineAppointmentConvert.java
  40. 77 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/ReplyInTimeConvert.java
  41. 64 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/SexConvert.java
  42. 56 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/WxSubscribeConvert.java
  43. 31 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/dao/FLLabelDictDao.java
  44. 69 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/dao/FlJobConfigDao.java
  45. 30 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/dao/FlLabelDictJobDao.java
  46. 142 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/entity/FlJobConfig.java
  47. 52 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/entity/FlLabelDict.java
  48. 60 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/entity/FlLabelDictJob.java
  49. 38 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/entity/IdEntity.java
  50. 34 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/enums/JobSqlFieldTypeEnum.java
  51. 12 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/enums/SourceTypeEnum.java
  52. 77 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/ESExtracter.java
  53. 22 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/Extracter.java
  54. 150 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/HbaseExtracter.java
  55. 39 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/MutilThreadMysqlExtracter.java
  56. 52 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/MutilThreadSearchSolrIndexExtracter.java
  57. 137 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/MysqlExtracter.java
  58. 155 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Es2EsJob.java
  59. 171 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Hbase2ESJob.java
  60. 239 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Mysql2ESJob.java
  61. 248 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/model/DataModel.java
  62. 170 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/model/SaveModel.java
  63. 100 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/search/controller/SearchController.java
  64. 273 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/search/service/SearchService.java
  65. 5 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/service/ExtractService.java
  66. 170 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/service/JobService.java
  67. 14 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/storage/Storager.java
  68. 58 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/storage/Store2ES.java
  69. 54 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/storage/Store2Hbase.java
  70. 24 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/ApplicationContextHolderUtil.java
  71. 74 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/BeanUtil.java
  72. 124 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/IdCardUtil.java
  73. 55 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/MD5Util.java
  74. 57 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/MakeIDUtil.java
  75. 122 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/QuartzHelpers.java
  76. 110 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/SudokuTool.java
  77. 92 0
      svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/TimeUtil.java
  78. 52 0
      svr/figure-label/src/main/resources/application-dev.yml
  79. 14 0
      svr/figure-label/src/main/resources/application-test.yml
  80. 32 0
      svr/figure-label/src/main/resources/application.yml
  81. 23 0
      svr/figure-label/src/main/resources/banner.txt
  82. 32 0
      svr/figure-label/src/main/resources/logback.xml
  83. 41 0
      svr/figure-label/src/main/resources/quartz.properties

File diff suppressed because it is too large
+ 42 - 0
sql/init.sql


+ 91 - 0
svr/figure-label/pom.xml

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>com.yihu.jw</groupId>
        <artifactId>wlyy-parent-pom</artifactId>
        <version>2.0.0</version>
        <relativePath>../../wlyy-parent-pom/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>patient-co-figure-label</artifactId>
    <dependencies>
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>common-quartz-starter</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>common-logback-starter</artifactId>
            <version>1.0.2</version>
            <exclusions>
                <exclusion>
                    <artifactId>servlet-api</artifactId>
                    <groupId>javax.servlet</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>common-swagger-starter</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-actuator-docs</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.3.10.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.15</version>
        </dependency>
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>common-data-es-starter</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>common-data-hbase-starter</artifactId>
            <version>1.0.1</version>
        </dependency>
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>common-data-solr-starter</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>
    </dependencies>
</project>

+ 63 - 0
svr/figure-label/sql/label_es_sql

@ -0,0 +1,63 @@
-- 新增居民标签索引映射
PUT http://172.19.103.45:9200/figure_label_index
{
        "mappings": {
            "figure_label_type": {
                "properties": {
                    "createTime": {
                        "type": "date",
                        "format": "yyyy-MM-dd HH:mm:ss"
                    },
                    "currentActive": {
                        "type": "boolean"
                    },
                    "id": {
                        "type": "string"
                    },
                    "idcard": {
                        "type": "string"
                    },
                    "labeName": {
                        "type": "string"
                    },
                    "labeValue": {
                        "type": "string"
                    },
                    "labelCode": {
                        "type": "string"
                    },
                    "labelName": {
                        "type": "string"
                    },
                    "labelType": {
                        "type": "string"
                    },
                    "labelValue": {
                        "type": "string"
                    },
                    "modelId": {
                        "type": "string"
                    },
                    "query": {
                        "properties": {
                            "match_all": {
                                "type": "object"
                            }
                        }
                    },
                    "source": {
                        "type": "string"
                    },
                    "sourceTime": {
                        "type": "string"
                    }
                }
            }
        }
}
-- 给索引建立别名
PUT http://172.19.103.45:9200/figure_label_index/figure_label_index_a

+ 54 - 0
svr/figure-label/sql/mysql.sql

@ -0,0 +1,54 @@
# job配置表
DROP TABLE IF EXISTS `fl_job_config`;
CREATE TABLE `fl_job_config` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `job_name` varchar(200) DEFAULT NULL COMMENT '任务名称',
  `job_class` varchar(200) DEFAULT NULL COMMENT '任务执行的class',
  `query_sql` varchar(2000) DEFAULT NULL COMMENT '抽取数据的sql语句',
  `sql_field_type` int(2) DEFAULT NULL COMMENT '增量字段类型 1时间 (yyyy-mm-dd  HH:MM:ss)2数字',
  `sql_field_value` varchar(255) DEFAULT NULL COMMENT '增量字段值',
  `sql_field` varchar(255) DEFAULT NULL COMMENT '增量字段',
  `quartz_cron` varchar(200) DEFAULT NULL COMMENT 'quartz表达式',
  `status` varchar(1) DEFAULT NULL COMMENT '1 启动 0停止',
  `del` varchar(1) DEFAULT NULL COMMENT '1 正常    0 删除',
  `source_type` varchar(20) DEFAULT NULL COMMENT '来源类型(mysql,hbase,file等)',
  `source` varchar(100) DEFAULT NULL COMMENT '数据来源',
  `datasource` varchar(200) NOT NULL DEFAULT '' COMMENT '数据库连接,格式为:url-database',
  `extract_field` varchar(255) DEFAULT '' COMMENT '查询的字段',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
# 标签具体字典表
DROP TABLE IF EXISTS `fl_label_dict`;
CREATE TABLE `fl_label_dict` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `dict_code` varchar(64) DEFAULT NULL COMMENT 'code一致的标签属于同一类',
  `parent_code` varchar(255) DEFAULT '0' COMMENT '字典父类代码,没有父类默认为0',
  `label_code` varchar(200) DEFAULT NULL COMMENT '标签code',
  `label_name` varchar(200) DEFAULT NULL COMMENT '标签名称',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=115 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
# 标签分类表
DROP TABLE IF EXISTS `fl_label_dict_category`;
CREATE TABLE `fl_label_dict_category` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `dict_code` varchar(255) NOT NULL COMMENT '标签字典代码',
  `dict_name` varchar(255) NOT NULL COMMENT '标签字典名称',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8 COMMENT='标签字典分类表';
# 标签转换器表
DROP TABLE IF EXISTS `fl_label_dict_job`;
CREATE TABLE `fl_label_dict_job` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `job_id` int(10) NOT NULL COMMENT '任务id',
  `category_id` int(10) NOT NULL COMMENT '标签分类id',
  `label_type` varchar(10) DEFAULT NULL COMMENT '标签类型 1 个人基本信息 2人群属性 3行政区域 4互联网行为 5签约分析 6咨询分析 7随访记录 8生活环境 9健康档案分析',
  `query_sql` varchar(2000) DEFAULT NULL COMMENT '抽取数据的sql语句',
  `convert_clazz` varchar(255) DEFAULT NULL COMMENT '需要转换的类',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;

+ 32 - 0
svr/figure-label/src/main/java/com/yihu/FigureLabelApplication.java

@ -0,0 +1,32 @@
package com.yihu;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
/**
 * Created by chenweida on 2018/3/5.
 */
@SpringBootApplication
@EnableJpaRepositories(
        entityManagerFactoryRef = "EntityManagerFactory",
        transactionManagerRef = "TransactionManager")
@EnableAutoConfiguration(exclude = {
//        ElasticsearchAutoConfiguration.class,
        ElasticsearchRepositoriesAutoConfiguration.class,
//        ElasticsearchDataAutoConfiguration.class,
        RedisRepositoriesAutoConfiguration.class
})
public class FigureLabelApplication {
    public static ApplicationContext ctx = null;
    public static void main(String[] args) {
        ctx = SpringApplication.run(FigureLabelApplication.class, args);
    }
}

+ 55 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/DruidConfig.java

@ -0,0 +1,55 @@
package com.yihu.wlyy.figure.label.config.db;
import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * Created by chenweida on 2018/3/5.
 */
//@Configuration
public class DruidConfig {
   /* //------------------------------------druid 监控----------------------------------------------
    @Bean
    public ServletRegistrationBean statViewServlet() {
        //创建servlet注册实体
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
        //设置ip白名单
        //servletRegistrationBean.addInitParameter("allow","127.0.0.1");
        //设置ip黑名单,如果allow与deny共同存在时,deny优先于allow
        // servletRegistrationBean.addInitParameter("deny","192.168.0.19");
        //设置控制台管理用户
        servletRegistrationBean.addInitParameter("loginUsername", "jkzl");
        servletRegistrationBean.addInitParameter("loginPassword", "jkzlehr");
        //是否可以重置数据
        servletRegistrationBean.addInitParameter("resetEnable", "false");
        return servletRegistrationBean;
    }
    @Bean
    public FilterRegistrationBean filterRegistrationBean(WebStatFilter webStatFilter) {
        //创建过滤器
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(webStatFilter);
        //设置过滤器过滤路径
        filterRegistrationBean.addUrlPatterns("/*");
        //忽略过滤的形式
        filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
        return filterRegistrationBean;
    }
    @Bean
    public StatFilter statFilter() {
        return new StatFilter();
    }
    @Bean
    public WebStatFilter webStatFilter() {
        return new WebStatFilter();
    }*/
    //------------------------------------druid 监控----------------------------------------------
}

+ 159 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/FigureLabelJpa.java

@ -0,0 +1,159 @@
package com.yihu.wlyy.figure.label.config.db;
import com.alibaba.druid.pool.DruidDataSource;
import com.yihu.base.SolrHelper;
import com.yihu.base.SolrPool;
import com.yihu.wlyy.figure.label.config.db.properties.DataSourceProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
 * Created by chenweida on 2017/4/6.
 */
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
        entityManagerFactoryRef = "EntityManagerFactory",
        transactionManagerRef = "TransactionManager",
        basePackages = {"com.yihu.wlyy.figure.label.dao"})   //设置Repository所在位置
public class FigureLabelJpa {
    @Autowired
    private HibernateProperties hibernateProperties;
    @Autowired
    private DataSourceProperties dataSourceProperties;
//    @Autowired
//    private DruidConfig druidConfig;
    private DataSource buildDataSource(DruidDataSource datasource) throws SQLException{
        //configuration
        datasource.setInitialSize(dataSourceProperties.getInitialSize());
        datasource.setMinIdle(dataSourceProperties.getMinIdle());
        datasource.setMaxActive(dataSourceProperties.getMaxActive());
        datasource.setMaxWait(dataSourceProperties.getMaxWait());
        datasource.setTimeBetweenEvictionRunsMillis(dataSourceProperties.getTimeBetweenEvictionRunsMillis());
        datasource.setMinEvictableIdleTimeMillis(dataSourceProperties.getMinEvictableIdleTimeMillis());
        datasource.setValidationQuery(dataSourceProperties.getValidationQuery());
        datasource.setTestWhileIdle(dataSourceProperties.getTestWhileIdle());
        datasource.setTestOnBorrow(dataSourceProperties.getTestOnBorrow());
        datasource.setTestOnReturn(dataSourceProperties.getTestOnReturn());
        datasource.setPoolPreparedStatements(dataSourceProperties.getPoolPreparedStatements());
        datasource.setMaxPoolPreparedStatementPerConnectionSize(dataSourceProperties.getMaxPoolPreparedStatementPerConnectionSize());
        datasource.setRemoveAbandoned(dataSourceProperties.getRemoveAbandoned());
        datasource.setRemoveAbandonedTimeout(dataSourceProperties.getRemoveAbandonedTimeout());
        datasource.setLogAbandoned(dataSourceProperties.getLogAbandoned());
        datasource.setFilters(dataSourceProperties.getFilters());
        datasource.setConnectProperties(properties());//;# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
        datasource.setUseGlobalDataSourceStat(true);// 合并多个DruidDataSource的监控数据
        List proxyFilters = new ArrayList<>();
//        proxyFilters.add(druidConfig.statFilter());
//        datasource.setProxyFilters(proxyFilters);
        return datasource;
    }
    @Bean(name = "wlyyDataSource")
    @Primary
    public DataSource wlyyDataSource() throws SQLException {
        DruidDataSource datasource = new DruidDataSource();
        datasource.setUrl(dataSourceProperties.getWlyy().getUrl());
        datasource.setUsername(dataSourceProperties.getWlyy().getUsername());
        datasource.setPassword(dataSourceProperties.getWlyy().getPassword());
        datasource.setDriverClassName(dataSourceProperties.getDriverClassName());
        return buildDataSource(datasource);
    }
    @Bean(name = "healtharchiveDataSource")
    public DataSource healtharchiveDataSource() throws SQLException {
        DruidDataSource datasource = new DruidDataSource();
        datasource.setUrl(dataSourceProperties.getHealtharchive().getUrl());
        datasource.setUsername(dataSourceProperties.getHealtharchive().getUsername());
        datasource.setPassword(dataSourceProperties.getHealtharchive().getPassword());
        datasource.setDriverClassName(dataSourceProperties.getDriverClassName());
        return buildDataSource(datasource);
    }
    @Bean(name = "wlyy85DataSource")
    public DataSource wlyy85DataSource() throws SQLException {
        DruidDataSource datasource = new DruidDataSource();
        datasource.setUrl(dataSourceProperties.getWlyy85().getUrl());
        datasource.setUsername(dataSourceProperties.getWlyy85().getUsername());
        datasource.setPassword(dataSourceProperties.getWlyy85().getPassword());
        datasource.setDriverClassName(dataSourceProperties.getDriverClassName());
        return buildDataSource(datasource);
    }
    @Bean(name = "EntityManagerFactory")
    @Primary
    public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary(@Qualifier("wlyyDataSource") DataSource dataSource) {
        LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
        emfb.setDataSource(dataSource);
        emfb.setPackagesToScan("com.yihu.wlyy.figure.label.entity");
        emfb.setPersistenceUnitName("wlyy");
        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        emfb.setJpaVendorAdapter(vendorAdapter);
        emfb.setJpaProperties(hibernateProperties.hibProperties());
        return emfb;
    }
    @Bean(name = "TransactionManager")
    @Primary
    JpaTransactionManager transactionManagerSecondary(@Qualifier("EntityManagerFactory") EntityManagerFactory builder) {
        return new JpaTransactionManager(builder);
    }
    private Properties properties() {
        Properties properties = new Properties();
        properties.put("druid.stat.mergeSql", "true");
        properties.put("slowSqlMillis", "1000");
        return properties;
    }
    @Bean
    public JdbcTemplate jdbcTemplate(@Qualifier("wlyyDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
    @Bean(name = "healtharchiveTemplate")
    public JdbcTemplate secondJdbcTemplate(@Qualifier("healtharchiveDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
    @Bean(name = "wlyy85Template")
    public JdbcTemplate thirdJdbcTemplate(@Qualifier("wlyy85DataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
    @Bean
    public SolrHelper solrHelper() {
        SolrHelper solrHelper = new SolrHelper();
        return solrHelper;
    }
    @Bean
    public SolrPool solrPool() {
        SolrPool solrPool = new SolrPool();
        return solrPool;
    }
}

+ 27 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/HibernateProperties.java

@ -0,0 +1,27 @@
package com.yihu.wlyy.figure.label.config.db;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Properties;
/**
 * Created by chenweida on 2017/4/6.
 */
@Component
public class HibernateProperties {
    @Value("${hibernate.dialect}")
    private String dialect;
    @Value("${hibernate.show_sql}")
    private String show_sql;
    @Value("${hibernate.ejb.naming_strategy}")
    private String naming_strategy;
    public  Properties hibProperties() {
        Properties properties = new Properties();
        properties.put("hibernate.dialect",dialect);
        properties.put("hibernate.show_sql", show_sql);
        properties.put("hibernate.ejb.naming_strategy", naming_strategy);
        return properties;
    }
}

+ 36 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/properties/DataSourceLoginProperties.java

@ -0,0 +1,36 @@
package com.yihu.wlyy.figure.label.config.db.properties;
/**
 * Created by chenweida on 2018/3/5.
 */
public class DataSourceLoginProperties {
    private String username;
    private String password;
    private String url;
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
}

+ 195 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/properties/DataSourceProperties.java

@ -0,0 +1,195 @@
package com.yihu.wlyy.figure.label.config.db.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
 * Created by chenweida on 2018/3/5.
 */
@ConfigurationProperties(prefix = "spring.datasource")
@Component
public class DataSourceProperties {
    private String driverClassName;
    private Integer initialSize;
    private Integer minIdle;
    private Integer maxActive;
    private Integer maxWait;
    private Integer timeBetweenEvictionRunsMillis;
    private Integer minEvictableIdleTimeMillis;
    private String validationQuery;
    private Boolean testWhileIdle;
    private Boolean testOnBorrow;
    private Boolean testOnReturn;
    private Boolean poolPreparedStatements;
    private Integer maxPoolPreparedStatementPerConnectionSize;
    private Boolean removeAbandoned;
    private Integer removeAbandonedTimeout;
    private Boolean logAbandoned;
    private String filters;
    private DataSourceLoginProperties wlyy = new DataSourceLoginProperties();
    private DataSourceLoginProperties healtharchive = new DataSourceLoginProperties();
    private DataSourceLoginProperties wlyy85 = new DataSourceLoginProperties();
    public String getDriverClassName() {
        return driverClassName;
    }
    public void setDriverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
    }
    public Integer getInitialSize() {
        return initialSize;
    }
    public void setInitialSize(Integer initialSize) {
        this.initialSize = initialSize;
    }
    public Integer getMinIdle() {
        return minIdle;
    }
    public void setMinIdle(Integer minIdle) {
        this.minIdle = minIdle;
    }
    public Integer getMaxActive() {
        return maxActive;
    }
    public void setMaxActive(Integer maxActive) {
        this.maxActive = maxActive;
    }
    public Integer getMaxWait() {
        return maxWait;
    }
    public void setMaxWait(Integer maxWait) {
        this.maxWait = maxWait;
    }
    public Integer getTimeBetweenEvictionRunsMillis() {
        return timeBetweenEvictionRunsMillis;
    }
    public void setTimeBetweenEvictionRunsMillis(Integer timeBetweenEvictionRunsMillis) {
        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
    }
    public Integer getMinEvictableIdleTimeMillis() {
        return minEvictableIdleTimeMillis;
    }
    public void setMinEvictableIdleTimeMillis(Integer minEvictableIdleTimeMillis) {
        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
    }
    public String getValidationQuery() {
        return validationQuery;
    }
    public void setValidationQuery(String validationQuery) {
        this.validationQuery = validationQuery;
    }
    public Boolean getTestWhileIdle() {
        return testWhileIdle;
    }
    public void setTestWhileIdle(Boolean testWhileIdle) {
        this.testWhileIdle = testWhileIdle;
    }
    public Boolean getTestOnBorrow() {
        return testOnBorrow;
    }
    public void setTestOnBorrow(Boolean testOnBorrow) {
        this.testOnBorrow = testOnBorrow;
    }
    public Boolean getTestOnReturn() {
        return testOnReturn;
    }
    public void setTestOnReturn(Boolean testOnReturn) {
        this.testOnReturn = testOnReturn;
    }
    public Boolean getPoolPreparedStatements() {
        return poolPreparedStatements;
    }
    public void setPoolPreparedStatements(Boolean poolPreparedStatements) {
        this.poolPreparedStatements = poolPreparedStatements;
    }
    public Integer getMaxPoolPreparedStatementPerConnectionSize() {
        return maxPoolPreparedStatementPerConnectionSize;
    }
    public void setMaxPoolPreparedStatementPerConnectionSize(Integer maxPoolPreparedStatementPerConnectionSize) {
        this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize;
    }
    public Boolean getRemoveAbandoned() {
        return removeAbandoned;
    }
    public void setRemoveAbandoned(Boolean removeAbandoned) {
        this.removeAbandoned = removeAbandoned;
    }
    public Integer getRemoveAbandonedTimeout() {
        return removeAbandonedTimeout;
    }
    public void setRemoveAbandonedTimeout(Integer removeAbandonedTimeout) {
        this.removeAbandonedTimeout = removeAbandonedTimeout;
    }
    public Boolean getLogAbandoned() {
        return logAbandoned;
    }
    public void setLogAbandoned(Boolean logAbandoned) {
        this.logAbandoned = logAbandoned;
    }
    public String getFilters() {
        return filters;
    }
    public void setFilters(String filters) {
        this.filters = filters;
    }
    public DataSourceLoginProperties getWlyy() {
        return wlyy;
    }
    public void setWlyy(DataSourceLoginProperties wlyy) {
        this.wlyy = wlyy;
    }
    public DataSourceLoginProperties getHealtharchive() {
        return healtharchive;
    }
    public void setHealtharchive(DataSourceLoginProperties healtharchive) {
        this.healtharchive = healtharchive;
    }
    public DataSourceLoginProperties getWlyy85() {
        return wlyy85;
    }
    public void setWlyy85(DataSourceLoginProperties wlyy85) {
        this.wlyy85 = wlyy85;
    }
}

+ 92 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/swagger/SwaggerConfig.java

@ -0,0 +1,92 @@
package com.yihu.wlyy.figure.label.config.swagger;
import io.github.swagger2markup.GroupBy;
import io.github.swagger2markup.Language;
import io.github.swagger2markup.Swagger2MarkupConfig;
import io.github.swagger2markup.Swagger2MarkupConverter;
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
import io.github.swagger2markup.markup.builder.MarkupLanguage;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import static com.google.common.base.Predicates.or;
import static springfox.documentation.builders.PathSelectors.regex;
@EnableSwagger2
@Configuration
public class SwaggerConfig {
    private static final String Other_API = "other";
    @Bean
    public Docket otherAPI() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName(Other_API)
                .genericModelSubstitutes(DeferredResult.class)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(true)
                .pathMapping("/")
                .select()
                .paths(or(
                        regex("/.*")
                ))
                .build()
                .apiInfo(otherApiInfo());
    }
    private ApiInfo otherApiInfo() {
        ApiInfo apiInfo = new ApiInfo("居民画像平台API",
                "居民画像平台API",
                "1.0",
                "No terms of service",
                "admin@jkzl.com",
                "The Apache License, Version 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0.html"
        );
        return apiInfo;
    }
    /**
     * 生成html文章专用
     *
     private static final String Doctor_API = "doctor";
     private static final String Patient_API = "patient";
     private static final String Other_API = "other";
     private static final String GateWay_API = "gateway";
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        String groupName="doctor";
        //String groupName="patient";
        //String groupName="other";
        // String groupName="gateway";
        URL remoteSwaggerFile = new URL("http://127.0.0.1:8080//v2/api-docs?group="+groupName);
        Path outputFile = Paths.get("patient-co/patient-co-figure-label/build/"+groupName);
        Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
                .withMarkupLanguage(MarkupLanguage.ASCIIDOC)
                .withOutputLanguage(Language.ZH)
                .withPathsGroupedBy(GroupBy.TAGS)
                .withGeneratedExamples()
                .withoutInlineSchema()
                .withBasePathPrefix()
                .build();
        Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(remoteSwaggerFile)
                .withConfig(config)
                .build();
        converter.toFile(outputFile);
    }
}

+ 21 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/config/war/ServletInitializer.java

@ -0,0 +1,21 @@
package com.yihu.wlyy.figure.label.config.war;//package com.yihu.wlyy.config.war;
import com.yihu.FigureLabelApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
/**
 *
 */
public class ServletInitializer extends SpringBootServletInitializer {
    public ServletInitializer() {
        super();
        setRegisterErrorPageFilter(false); //报错不跳到错误页
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(FigureLabelApplication.class);
    }
}

+ 17 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/constant/BusinessConstant.java

@ -0,0 +1,17 @@
package com.yihu.wlyy.figure.label.constant;
/**
 * @author litaohong on 2018/5/31
 * @project patient-co-management
 * 业务相关的常量
 */
public class BusinessConstant {
    public static final String SQLFIELDCONDITION = "sqlFieldCondition";
    public static final String sqlFieldValue = "sqlFieldValue";
    public static final String sourceType = "sourceType";
    public static final String source = "source";
    public static final String gt = ">";
    public static final String separator = "/";
    public static final String sql_field_str = "@sql_field@";
    public static final String sql_field_value_str = "@sql_field_value@";
}

+ 46 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/constant/ConstantUtil.java

@ -0,0 +1,46 @@
package com.yihu.wlyy.figure.label.constant;
public class ConstantUtil {
    public static final String figure_label_es_index = "figure_label_index";
    public static final String figure_label_es_type = "figure_label_type";
    public static final String date_format = "yyyy-MM-dd HH:mm:ss";
    public static final String figure_label_hbase_table = "figure_label";
    public static final String figure_label_familyA = "label_cloumn";
    // solr字表core
    public static final String subcore = "HealthProfileSub";
    public static final String address_dict = "address_dict";
    public static final String age_dict = "age_dict";
    public static final String birth_dict = "birth_dict";
    public static final String consult_dict = "consult_dict";
    public static final String consult_evaluate_dict = "consult_evaluate_dict";
    public static final String feedback_dict = "feedback_dict";
    public static final String health_edu_artical_dict = "health_edu_artical_dict";
    public static final String health_edu_artical_receive_dict = "health_edu_artical_receive_dict";
    public static final String height_dict = "height_dict";
    public static final String is_consult_dict = "is_consult_dict";
    public static final String is_drinking_dict = "is_drinking_dict";
    public static final String is_pay_online_dict = "is_pay_online_dict";
    public static final String is_sign_online_dict = "is_sign_online_dict";
    public static final String is_smoking_dict = "is_smoking_dict";
    public static final String name_dict = "name_dict";
    public static final String online_appoinment_dict = "online_appoinment_dict";
    public static final String online_consult_dict = "online_consult_dict";
    public static final String people_category_dict = "people_category_dict";
    public static final String renew_dict = "renew_dict";
    public static final String reply_intime_dict = "reply_intime_dict";
    public static final String sex_dict = "sex_dict";
    public static final String sign_doctor_dict = "sign_doctor_dict";
    public static final String sign_server_type_dict = "sign_server_type_dict";
    public static final String sign_team_dict = "sign_team_dict";
    public static final String sign_state_dict = "sign_state_dict";
    public static final String weight_dict = "weight_dict";
    public static final String wx_subscribe_acc_dict = "wx_subscribe_acc_dict";
    public static final String ICD10_dict = "ICD-10-CM_dict";
    public static final String health_problem_dict = "health_problem_dict";
    public static final String followup_dict = "followup_dict";
}

+ 440 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/controller/BaseController.java

@ -0,0 +1,440 @@
package com.yihu.wlyy.figure.label.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.figure.label.entity.IdEntity;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BaseController {
	private static Logger logger = LoggerFactory.getLogger(BaseController.class);
	@Autowired
	protected HttpServletRequest request;
	public String getOpenid() {
		try {
			String userAgent = request.getHeader("userAgent");
			if(StringUtils.isEmpty(userAgent)){
				userAgent = request.getHeader("User-Agent");
			}
			JSONObject json = new JSONObject(userAgent);
			return json.getString("openid");
			
		} catch (Exception e) {
			return null;
		}
	}
	
	/**
	 * 获取用户ID
	 * @return
	 */
	public long getId() {
		try {
			String userAgent = request.getHeader("userAgent");
			if(StringUtils.isEmpty(userAgent)){
				userAgent = request.getHeader("User-Agent");
			}
			JSONObject json = new JSONObject(userAgent);
			return json.getLong("id");
		} catch (Exception e) {
			return 0;
		}
	}
	public String getIMEI() {
		try {
			String userAgent = request.getHeader("userAgent");
			if(StringUtils.isEmpty(userAgent)){
				userAgent = request.getHeader("User-Agent");
			}
			JSONObject json = new JSONObject(userAgent);
			return json.getString("imei");
		} catch (Exception e) {
			return null;
		}
	}
	
	public String getToken() {
		try {
			String userAgent = request.getHeader("userAgent");
			if(StringUtils.isEmpty(userAgent)){
				userAgent = request.getHeader("User-Agent");
			}
			JSONObject json = new JSONObject(userAgent);
			return json.getString("token");
		} catch (Exception e) {
			return null;
		}
	}
	public void error(Exception e) {
		logger.error(getClass().getName() + ":", e.getMessage());
		e.printStackTrace();
	}
	public void warn(Exception e) {
		logger.warn(getClass().getName() + ":", e.getMessage());
		e.printStackTrace();
	}
	/**
	 * 返回接口处理结果
	 * 
	 * @param code 结果码,成功为200
	 * @param msg 结果提示信息
	 * @return
	 */
	public String error(int code, String msg) {
		try {
			Map<Object, Object> map = new HashMap<Object, Object>();
			ObjectMapper mapper = new ObjectMapper();
			map.put("status", code);
			map.put("msg", msg);
			return mapper.writeValueAsString(map);
		} catch (Exception e) {
			error(e);
			return null;
		}
	}
	/**
	 * 接口处理成功
	 * @param msg
	 * @return
	 */
	public String success(String msg) {
		try {
			Map<Object, Object> map = new HashMap<Object, Object>();
			ObjectMapper mapper = new ObjectMapper();
			map.put("status", 200);
			map.put("msg", msg);
			return mapper.writeValueAsString(map);
		} catch (Exception e) {
			error(e);
			return null;
		}
	}
	public String write(int code, String msg) {
		try {
			Map<Object, Object> map = new HashMap<Object, Object>();
			ObjectMapper mapper = new ObjectMapper();
			map.put("status", code);
			map.put("msg", msg);
			return mapper.writeValueAsString(map);
		} catch (Exception e) {
			error(e);
			return null;
		}
	}
	/**
	 * 返回接口处理结果
	 * 
	 * 
	 * @param code 结果码,成功为200
	 * @param msg 结果提示信息
	 * @return
	 */
	public String write(int code, String msg, String key, List<?> list) {
		try {
			Map<Object, Object> map = new HashMap<Object, Object>();
			ObjectMapper mapper = new ObjectMapper();
			map.put("status", code);
			map.put("msg", msg);
			map.put(key, list);
			return mapper.writeValueAsString(map);
		} catch (Exception e) {
			error(e);
			return error(-1, "服务器异常,请稍候再试!");
		}
	}
	/**
	 * 返回接口处理结果
	 * 
	 * 
	 * @param code 结果码,成功为200
	 * @param msg 结果提示信息
	 * @param value 结果数据
	 * @return
	 */
	public String write(int code, String msg, String key, JSONObject value) {
		try {
			JSONObject json = new JSONObject();
			json.put("status", code);
			json.put("msg", msg);
			json.put(key, value);
			return json.toString();
		} catch (Exception e) {
			error(e);
			return error(-1, "服务器异常,请稍候再试!");
		}
	}
	/**
	 * 返回接口处理结果
	 * 
	 * 
	 * @param code 结果码,成功为200
	 * @param msg 结果提示信息
	 * @param value 结果数据
	 * @return
	 */
	public String write(int code, String msg, String key, JSONArray value) {
		try {
			JSONObject json = new JSONObject();
			json.put("status", code);
			json.put("msg", msg);
			json.put(key, value);
			return json.toString();
		} catch (Exception e) {
			error(e);
			return error(-1, "服务器异常,请稍候再试!");
		}
	}
	/**
	 * 返回接口处理结果
	 * 
	 * 
	 * @param code 结果码,成功为200
	 * @param msg 结果提示信息
	 * @param total 总数
	 * @param value 结果数据
	 * @return
	 */
	public String write(int code, String msg, int total, String key, JSONArray value) {
		try {
			JSONObject json = new JSONObject();
			json.put("status", code);
			json.put("msg", msg);
			json.put("total", total);
			json.put(key, value);
			return json.toString();
		} catch (Exception e) {
			error(e);
			return error(-1, "服务器异常,请稍候再试!");
		}
	}
	/**
	 * 返回接口处理结果
	 * 
	 * 
	 * @param code 结果码,成功为200
	 * @param msg 结果提示信息
	 * @param value 结果数据
	 * @return
	 */
	public String write(int code, String msg, String key, Object value) {
		try {
			Map<Object, Object> map = new HashMap<Object, Object>();
			ObjectMapper mapper = new ObjectMapper();
			map.put("status", code);
			map.put("msg", msg);
			map.put(key, value);
			return mapper.writeValueAsString(map);
		} catch (Exception e) {
			error(e);
			return error(-1, "服务器异常,请稍候再试!");
		}
	}
	/**
	 * 返回接口处理结果
	 * 
	 * 
	 * @param code 结果码,成功为200
	 * @param msg 结果提示信息
	 * @return
	 */
	public String write(int code, String msg, String key, Page<?> list) {
		try {
			Map<Object, Object> map = new HashMap<Object, Object>();
			ObjectMapper mapper = new ObjectMapper();
			map.put("status", code);
			map.put("msg", msg);
			// 是否为第一页
			map.put("isFirst", list.isFirst());
			// 是否为最后一页
			map.put("isLast", list.isLast());
			// 总条数
			map.put("total", list.getTotalElements());
			// 总页数
			map.put("totalPages", list.getTotalPages());
			map.put(key, list.getContent());
			return mapper.writeValueAsString(map);
		} catch (Exception e) {
			error(e);
			return error(-1, "服务器异常,请稍候再试!");
		}
	}
	/**
	 * 返回接口处理结果
	 *
	 *
	 * @param code 结果码,成功为200
	 * @param msg 结果提示信息
	 * @return
	 */
	public String write(int code, String msg, String key, Page<?> page, JSONArray array) {
		try {
			JSONObject json = new JSONObject();
			json.put("status", code);
			json.put("msg", msg);
			// 是否为第一页
			json.put("isFirst", page.isFirst());
			// 是否为最后一页
			json.put("isLast", page.isLast());
			// 总条数
			json.put("total", page.getTotalElements());
			// 总页数
			json.put("totalPages", page.getTotalPages());
			json.put(key, array);
			return json.toString();
		} catch (Exception e) {
			error(e);
			return error(-1, "服务器异常,请稍候再试!");
		}
	}
	/**
	 * 返回接口处理结果
	 * 
	 * 
	 * @param code 结果码,成功为200
	 * @param msg 结果提示信息
	 * @param value 结果数据
	 * @return
	 */
	public String write(int code, String msg, String key, Map<?, ?> value) {
		try {
			Map<Object, Object> map = new HashMap<Object, Object>();
			ObjectMapper mapper = new ObjectMapper();
			map.put("status", code);
			map.put("msg", msg);
			map.put(key, value);
			return mapper.writeValueAsString(map);
		} catch (Exception e) {
			error(e);
			return error(-1, "服务器异常,请稍候再试!");
		}
	}
	/**
	* 返回接口处理结果
	*
	* @param code 结果码,成功为200
	* @param msg 结果提示信息
	* @param value 结果数据
	* @return
	*/
	public String write(int code, String msg, String key, String value) {
		try {
			Map<Object, Object> map = new HashMap<Object, Object>();
			ObjectMapper mapper = new ObjectMapper();
			map.put("status", code);
			map.put("msg", msg);
			map.put(key, value);
			return mapper.writeValueAsString(map);
		} catch (Exception e) {
			error(e);
			return error(-1, "服务器异常,请稍候再试!");
		}
	}
	/**
	* 返回接口处理结果
	*
	*
	* @param code 结果码,成功为200
	* @param msg 结果提示信息
	* @return
	*/
	public String write(int code, String msg, String key, IdEntity entity) {
		try {
			Map<Object, Object> map = new HashMap<Object, Object>();
			ObjectMapper mapper = new ObjectMapper();
			map.put("status", code);
			map.put("msg", msg);
			map.put(key, entity);
			return mapper.writeValueAsString(map);
		} catch (Exception e) {
			error(e);
			return error(-1, "服务器异常,请稍候再试!");
		}
	}
	/**
	 * 返回接口处理结果
	 * 
	 * 
	 * @param code 结果码,成功为200
	 * @param msg 结果提示信息
	 * @return
	 */
	public String write(int code, String msg, boolean isFirst, boolean isLast, long total, int totalPages, String key, Object values) {
		try {
			JSONObject json = new JSONObject();
			json.put("status", code);
			json.put("msg", msg);
			// 是否为第一页
			json.put("isFirst", isFirst);
			// 是否为最后一页
			json.put("isLast", isLast);
			// 总条数
			json.put("total", total);
			// 总页数
			json.put("totalPages", totalPages);
			json.put(key, values);
			return json.toString();
		} catch (Exception e) {
			logger.error("BaseController:", e.getMessage());
			return error(-1, "服务器异常,请稍候再试!");
		}
	}
	public String trimEnd(String param, String trimChars) {
		if (param.endsWith(trimChars)) {
			param = param.substring(0, param.length() - trimChars.length());
		}
		return param;
	}
	/**
	 * 无效用户消息返回
	 * @param e
	 * @param defaultCode
	 * @param defaultMsg
	 * @return
	 */
	public String invalidUserException(Exception e, int defaultCode, String defaultMsg) {
		try {
			// if (e instanceof UndeclaredThrowableException) {
			// UndeclaredThrowableException ute = (UndeclaredThrowableException) e;
			// InvalidUserException iue = (InvalidUserException) ute.getUndeclaredThrowable();
			// if (iue != null) {
			// return error(iue.getCode(), iue.getMsg());
			// }
			// }
			return error(defaultCode, defaultMsg);
		} catch (Exception e2) {
			return null;
		}
	}
}

+ 77 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/controller/ESDataOperationController.java

@ -0,0 +1,77 @@
package com.yihu.wlyy.figure.label.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.base.es.config.ElastricSearchHelper;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.TimeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * @author litaohong on 2018/5/3
 * @project patient-co-management
 */
@RestController
@RequestMapping(value = "/data", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "ES数据操作控制器")
public class ESDataOperationController extends BaseController{
    private Logger logger = LoggerFactory.getLogger(ESDataOperationController.class);
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    @Autowired
    ObjectMapper objectMapper;
    @ApiOperation(value = "根据sql删除es数据")
    @RequestMapping(value = "deteleByQuery", method = RequestMethod.POST)
    public String deleteBySql( @ApiParam(name = "sql", value = "sql", required = true)@RequestParam(value = "sql", required = true) String sql) throws JobExecutionException {
       long count = deleteData(sql);
       if(count ==-1){
           return error(-1,"invalid sql");
       }
       return success("删除成功,共计"+ count +"条");
    }
    public long  deleteData(String sql){
        long start = System.currentTimeMillis();
        String logTitle = "delete es data";
        TimeUtil.start(logger,logTitle,start);
        List<Map<String, Object>>  list = new ArrayList<>();
        if((!sql.contains("select") && !sql.contains("SELECT")) || (!sql.contains("from") && !sql.contains("FROM"))){
            return -1;
        }
        if(!sql.contains("limit")){
            sql = sql + " limit 10000";
        }
        list.addAll(elastricSearchHelper.excuceSQL(sql));
        long count = list.size();
        while (list.size() > 0){
            delete(list);
            list = elastricSearchHelper.excuceSQL(sql);
            count+= list.size();
        }
        TimeUtil.finish(logger,logTitle,start,System.currentTimeMillis());
        return count;
    }
    public void delete(List<Map<String, Object>> list){
        elastricSearchHelper.delete(ConstantUtil.figure_label_es_index,ConstantUtil.figure_label_es_type,list);
    }
}

+ 131 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/controller/JobController.java

@ -0,0 +1,131 @@
package com.yihu.wlyy.figure.label.controller;
import com.yihu.wlyy.figure.label.service.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author lith on 2018.03.14
 * 定时任务控制器
 */
@RestController
@RequestMapping(value = "/job", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "定时任务控制器")
public class JobController extends BaseController{
    private Logger logger = LoggerFactory.getLogger(JobController.class);
    @Autowired
    private JobService jobService;
    /**
     * 启动任务
     * @param id
     * @return
     */
    @ApiOperation(value = "根据ID立即单个任务")
    @RequestMapping(value = "startNowById", method = RequestMethod.GET)
    public String startNowById(
            @ApiParam(name = "id", value = "任务ID", required = true)@RequestParam(value = "id", required = true) String id) {
        try {
            jobService.startNowById(id);
            return success("启动成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 启动任务
     *
     * @param id id
     * @return
     */
    @ApiOperation(value = "根据id启动任务,逗号分隔")
    @RequestMapping(value = "startById", method = RequestMethod.GET)
    public String startById(
            @ApiParam(name="id",value="任务id",required=true)@RequestParam(value = "id", required = true) String id) {
        try {
            jobService.startById(id);
            return success("启动成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 停止任务
     *
     * @param id id
     * @return
     */
    @ApiOperation(value = "根据id停止任务,逗号分隔")
    @RequestMapping(value = "stopById", method = RequestMethod.GET)
    public String stopById(@ApiParam(name="id",value="任务id",required=true)@RequestParam(value = "id", required = true)String id) {
        try {
            jobService.stopById(id);
            return success("停止成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 停止所有任务
     *
     * @return
     */
    @ApiOperation(value = "停止所有任务")
    @RequestMapping(value = "stopAll", method = RequestMethod.GET)
    public String stopAll() {
        try {
            jobService.stopAll();
            return success("停止成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 启动所有任务
     *
     * @return
     */
    @ApiOperation(value = "启动所有任务")
    @RequestMapping(value = "startAll", method = RequestMethod.GET)
    public String startAll() {
        try {
            jobService.startAll();
            return success("启动成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    @ApiOperation(value = "清除緩存")
    @RequestMapping(value = "cleanCache", method = RequestMethod.GET)
    public String cleanCache() {
        try {
            return success("启动成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
}

+ 50 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/AddressConvert.java

@ -0,0 +1,50 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author litaohong on 2018/4/12
 * @project patient-co-management
 * 地址标签转换器
 */
@Component
public class AddressConvert implements Convert{
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict dict = flLabelDictList.get(0);
        for(DataModel dataModel : modelList){
            SaveModel saveModel = new SaveModel();
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(dict.getLabelCode());
            saveModel.setLabelName(dict.getLabelName());
            saveModel.setLabelValue(dataModel.getLabelValue());
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            if(StringUtils.isEmpty(saveModel.getSource())){
                return new ArrayList<>();
            }
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 56 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/AgeConvert.java

@ -0,0 +1,56 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.IdCardUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.*;
/**
 * @author lith on 2018.03.14
 * 年龄标签转换器
 */
@Component
public class AgeConvert implements Convert {
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> models, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict one = flLabelDictList.get(0);
        models.forEach(
                model -> {
                    int age = IdCardUtil.getAgeForIdcard(model.getIdcard());
                    SaveModel saveModel = new SaveModel();
                    saveModel.setDictCode(one.getDictCode());
                    saveModel.setIdcard(model.getIdcard());
                    saveModel.setLabelType(one.getParentCode());
                    saveModel.setLabelCode(one.getLabelCode());
                    saveModel.setLabelName(String.valueOf(age) + "岁");
                    //源数据来源时间
                    saveModel.setSourceTime(model.getSourceTime());
                    saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
                    convertHelper.generateDataSource(model,saveModel,sourceType,source);
                    //如果fl_job_config表配置的id和数据来源不一致,则不保存数据
                    if(StringUtils.isEmpty(saveModel.getSource())){
                        return;
                    }
                    saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
                    saveModels.add(saveModel);
                }
        );
        return saveModels;
    }
}

+ 88 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/AgeRangeConvert.java

@ -0,0 +1,88 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.IdCardUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.*;
/**
 * @author lith on 2018.03.14
 * 年龄标签转换器
 */
@Component
public class AgeRangeConvert implements Convert {
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> models, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict one = flLabelDictList.get(0);
        Map<String,String> map = new HashMap<>();
        flLabelDictList.forEach(
                fLlabelDict -> {
                    map.put(fLlabelDict.getLabelCode(),fLlabelDict.getLabelName());
                }
        );
        models.forEach(
                model -> {
                    int age = IdCardUtil.getAgeForIdcard(model.getIdcard());
                    String labelCode = getAgeLabelCode(age);
                    SaveModel saveModel = new SaveModel();
                    saveModel.setDictCode(one.getDictCode());
                    saveModel.setIdcard(model.getIdcard());
                    saveModel.setLabelType(one.getParentCode());
                    saveModel.setLabelCode(one.getLabelCode());
                    saveModel.setLabelName(map.get(labelCode));
                    //源数据来源时间
                    if(null != model.getSourceTime()){
                        saveModel.setSourceTime(model.getSourceTime());
                    }
                    saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
                    convertHelper.generateDataSource(model,saveModel,sourceType,source);
                    //如果fl_job_config表配置的id和数据来源不一致,则不保存数据
                    if(StringUtils.isEmpty(saveModel.getSource())){
                        return;
                    }
                    saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
                    saveModels.add(saveModel);
                }
        );
        return saveModels;
    }
    /**
     * fl_label_dict配置的code
     * @param age
     * @return
     */
    public String getAgeLabelCode(int age) {
        if (age <= 6) {
            return "10";
        }else if(age <=18){
            return "11";
        }else if(age <=30){
            return "12";
        }else if(age <=50){
            return "13";
        }else if(age <=65){
            return "14";
        }else{
            return "15";
        }
    }
}

+ 91 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/BasicDictItemHelper.java

@ -0,0 +1,91 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import io.swagger.annotations.Scope;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author litaohong on 2018/4/27
 * @project patient-co-management
 * 一些基础字典信息载入内存
 */
@Component
public class BasicDictItemHelper {
    public  Map<String,String> dictCategoryMap = new HashMap<>();
    public  Map<String,List<FlLabelDict>> labelDictMap = new HashMap<>();
    @Autowired
    JdbcTemplate jdbcTemplate;
    @PostConstruct
    public void init(){
        loadCategoryMap();
        loadLabelDictMap();
    }
    /**
     * 加载标签分类表
     * @return
     */
    public Map<String,String> loadCategoryMap(){
        if(!CollectionUtils.isEmpty(dictCategoryMap)){
            return dictCategoryMap;
        }
        String sql = "select * from fl_label_dict_category";
        List<Map<String, Object>> dictCategoryList = jdbcTemplate.queryForList(sql);
        dictCategoryList.forEach(
                one -> {
                    dictCategoryMap.put(String.valueOf(one.get("id")),String.valueOf(one.get("dict_code")));
                }
        );
        return dictCategoryMap;
    }
    /**
     * 加载标签字典表
     * @return
     */
    public Map<String,List<FlLabelDict>> loadLabelDictMap(){
        if(!CollectionUtils.isEmpty(labelDictMap)){
            return labelDictMap;
        }
        String sql = "select * from fl_label_dict";
        List<FlLabelDict> labelDictList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(FlLabelDict.class));
        labelDictList.forEach(
                one -> {
                    List list = new ArrayList();
                    if(labelDictMap.containsKey(one.getDictCode())){
                        labelDictMap.get(one.getDictCode()).add(one);
                        return;
                    }
                    list.add(one);
                    labelDictMap.put(one.getDictCode(), list);
                }
        );
        return labelDictMap;
    }
//    public Map<String,FlLabelDict> getOneDictMap(String dictCode){
//        Map<String,FlLabelDict> map = new HashMap<>();
//        if(this.labelDictMap.get(dictCode).size() > 1){
//            List<FlLabelDict> list = this.labelDictMap.get(dictCode);
//            list.forEach(
//                    one -> {
//                        map.put()
//                    }
//            );
//        }
//    }
}

+ 67 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/BirthConvert.java

@ -0,0 +1,67 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.IdCardUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author lith on 2018.03.14
 * 生日标签转换器
 */
@Component
public class BirthConvert implements Convert {
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> models, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict flLabelDict = flLabelDictList.get(0);
        models.forEach(
                model -> {
                    String birth = null;
                    try {
                        birth  = IdCardUtil.getBirthdayForIdcard(model.getIdcard());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    SaveModel saveModel = new SaveModel();
                    saveModel.setIdcard(model.getIdcard());
                    saveModel.setDictCode(flLabelDict.getDictCode());
                    saveModel.setLabelCode(flLabelDict.getLabelCode());
                    saveModel.setLabelType(flLabelDict.getParentCode());
                    saveModel.setLabelName(flLabelDict.getLabelName());
                    saveModel.setLabelValue(birth);
                    //源数据来源时间
                    if(null != model.getSourceTime()){
                        saveModel.setSourceTime(model.getSourceTime());
                    }
                    saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
                    convertHelper.generateDataSource(model,saveModel,sourceType,source);
                    //如果fl_job_config表配置的id和数据来源不一致,则不保存数据
                    if(StringUtils.isEmpty(saveModel.getSource())){
                        return;
                    }
                    saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
                    saveModels.add(saveModel);
                }
        );
        return saveModels;
    }
}

+ 49 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/ConsultConvert.java

@ -0,0 +1,49 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
/**
 * @author litaohong on 2018/4/8
 * @project patient-co-management
 * 咨询问题标签
 */
@Service
public class ConsultConvert implements Convert{
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict dict = flLabelDictList.get(0);
        for(DataModel dataModel:modelList){
            SaveModel saveModel = new SaveModel();
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(dict.getLabelCode());
            saveModel.setLabelName(dict.getLabelName());
            saveModel.setLabelValue(dataModel.getLabelValue());
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            if (StringUtils.isEmpty(saveModel.getSource())) {
                return new ArrayList<>();
            }
            saveModel.setSourceTime(dataModel.getSourceTime());
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 17 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/Convert.java

@ -0,0 +1,17 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import java.util.List;
import java.util.Map;
/**
 * Created by chenweida on 2018/3/7.
 * 数据转换
 */
public interface Convert {
    List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source);
}

+ 246 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/ConvertHelper.java

@ -0,0 +1,246 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.entity.FlLabelDictJob;
import com.yihu.wlyy.figure.label.enums.SourceTypeEnum;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.util.ApplicationContextHolderUtil;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
 * @author lith on 2018.03.14
 * 维度的key值转换器
 */
@Component
@Scope("prototype")
public class ConvertHelper {
    private Logger logger = LoggerFactory.getLogger(ConvertHelper.class);
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private BasicDictItemHelper basicDictItemHelper;
    private ExecutorService executorService = Executors.newCachedThreadPool();
    private int numPerPage = 50000; //分页,一次性最多循环100000万条
    /**
     * 进行具体标签生成转换
     * @param dataModels
     * @param hbaseDatas
     * @param flLabelDictJob
     * @param sourceType
     * @param source
     * @return
     * @throws Exception
     */
    public List<SaveModel> convert(List<DataModel> dataModels, List<Map<String,Object>> hbaseDatas, FlLabelDictJob flLabelDictJob, String sourceType, String source) throws Exception {
        List<SaveModel> saveModels = new ArrayList<>();
        //如果源数据为空
        if(CollectionUtils.isEmpty(dataModels) && CollectionUtils.isEmpty(hbaseDatas)){
            return saveModels;
        }
        //标签job未配置
        if(null == flLabelDictJob){
            return saveModels;
        }
        //转换器为空表示不需要转换
        if (StringUtils.isEmpty(flLabelDictJob.getConvertClazz())) {
            if(dataModels.size() >= numPerPage){
                int number = dataModels.size() / numPerPage + 1;
                for(int i = 0; i < number; i++){
                    MutilThreadConvert mutilThreadConvert = new MutilThreadConvert(dataModels.subList(i*numPerPage,(i+1)*numPerPage),flLabelDictJob.getCategoryId(),sourceType,source);
                    Future<List<SaveModel>> future = executorService.submit(mutilThreadConvert);
                    saveModels.addAll(future.get());
                }
            }else{
                return generateSaveModleWithOutConvert(dataModels,flLabelDictJob.getCategoryId(),sourceType,source);
            }
            return saveModels;
        }
        //转换器不为空,判断配置的字典是否存在,字典不存在则表示此条数据错误
        List<FlLabelDict> flLabelDictList = jdbcTemplate.query(flLabelDictJob.getSql(), new BeanPropertyRowMapper(FlLabelDict.class));
        if(CollectionUtils.isEmpty(flLabelDictList)){
            return saveModels;
        }
        try {
            // 加载转换器类
            Class clazz = Class.forName(flLabelDictJob.getConvertClazz());
            Object obj = ApplicationContextHolderUtil.getContext().getBean(clazz);
            Method method = obj.getClass().getMethod("convert", List.class, List.class,List.class,String.class,String.class);
            // 调用转换方法,数据量大,分批次调用
            if(null != dataModels && dataModels.size() >= numPerPage){
                int number = dataModels.size() / numPerPage + 1;
                for(int i = 0; i < number; i++){
                    List<SaveModel> list = new ArrayList<>();
                    if (i == number - 1) {
                        int size = dataModels.size();
                        list = (List<SaveModel>) method.invoke(obj, dataModels.subList(i * numPerPage, size), hbaseDatas, flLabelDictList, sourceType, source);
                    } else {
                        list = (List<SaveModel>) method.invoke(obj, dataModels.subList(i * numPerPage, (i + 1) * numPerPage), hbaseDatas, flLabelDictList, sourceType, source);
                    }
                    saveModels.addAll(list);
                }
                return saveModels;
            } else if(null != hbaseDatas && hbaseDatas.size() >= numPerPage){
                int number = hbaseDatas.size() / numPerPage + 1;
                for(int i = 0; i < number; i++){
                    List<SaveModel> list = new ArrayList<>();
                    if (i == number - 1) {
                        int size = hbaseDatas.size();
                        list = (List<SaveModel>) method.invoke(obj, dataModels, hbaseDatas.subList(i * numPerPage, size), flLabelDictList, sourceType, source);
                    }else {
                        list = (List<SaveModel>) method.invoke(obj, dataModels, hbaseDatas.subList(i*numPerPage,(i+1)*numPerPage),flLabelDictList,sourceType,source);
                    }
                    saveModels.addAll(list);
                }
                return saveModels;
            }
            else{
                 saveModels = (List<SaveModel>) method.invoke(obj, dataModels, hbaseDatas,flLabelDictList,sourceType,source);
            }
        } catch (Exception e) {
          logger.error("customized class or convert() method not found:" + flLabelDictJob.getConvertClazz());
            e.printStackTrace();
            return saveModels;
        }
        return saveModels;
    }
    /**
     * 无需转换器直接转换,此种情况为源数据已经分类好标签
     * @param dataModels
     * @param categoryId
     * @param sourceType
     * @param source
     *
     * @return
     */
    public List<SaveModel> generateSaveModleWithOutConvert(List<DataModel> dataModels,Long categoryId,String sourceType,String source){
        String dictCode = basicDictItemHelper.dictCategoryMap.get(String.valueOf(categoryId));
        List<SaveModel> saveModels = new ArrayList<>();
        //lambda无法跳出循环
        for(DataModel dataModel:dataModels){
            SaveModel saveModel = new SaveModel();
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setDictCode(dictCode);
            //找不到该类别
            if (null == basicDictItemHelper.labelDictMap.get(dictCode)) {
                logger.error("label dictCode not exist :【" + dictCode + "】");
                return new ArrayList<>();
            }
            //只有一种类别
            if(basicDictItemHelper.labelDictMap.get(dictCode).size() == 1){
                List<FlLabelDict> flLabelDictList = basicDictItemHelper.labelDictMap.get(dictCode);
                saveModel.setLabelType(flLabelDictList.get(0).getParentCode());
                saveModel.setLabelCode(flLabelDictList.get(0).getLabelCode());
                saveModel.setLabelName(flLabelDictList.get(0).getLabelName());
                if(!StringUtils.isEmpty(dataModel.getLabelValue())){
                    if(StringUtils.endsWithIgnoreCase("height_dict",dictCode)){
                        saveModel.setLabelValue(dataModel.getLabelValue()+"cm");
                    }
                    else if(StringUtils.endsWithIgnoreCase("weight_dict",dictCode)){
                        saveModel.setLabelValue(dataModel.getLabelValue()+"kg");
                    }else{
                        saveModel.setLabelValue(dataModel.getLabelValue());
                    }
                }
            }else{
                //当有多种类别,sql里构造好需要格式,例如不同code对应不同的label_name
                saveModel.setLabelType(dataModel.getParentCode());
                saveModel.setLabelCode(dataModel.getLabelCode());
                saveModel.setLabelName(dataModel.getLabelName());
            }
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            this.generateDataSource(dataModel,saveModel,sourceType,source);
            //如果fl_job_config表配置的id和数据来源不一致,则不保存数据,原子性,全部不保存,不然部分存了部分没存不好剔除数据
            if(StringUtils.isEmpty(saveModel.getSource())){
                return new ArrayList<>();
            }
            if(!StringUtils.isEmpty(dataModel.getSourceTime())){
                saveModel.setSourceTime(dataModel.getSourceTime());
            }
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
    /**
     * 生成数据来源
     * @param dataModel
     * @param saveModel
     * @param sourceType
     * @param sources
     * @return
     */
    public void generateDataSource(DataModel dataModel,SaveModel saveModel,String sourceType,String sources) {
        if(!StringUtils.endsWithIgnoreCase(SourceTypeEnum.MYSQL.toString(),sourceType) && !StringUtils.endsWithIgnoreCase(SourceTypeEnum.ELASTICSEARCH.toString(),sourceType) && !StringUtils.endsWithIgnoreCase(SourceTypeEnum.HBASE.toString(),sourceType)){
            return;
        }
        StringBuilder ids = new StringBuilder();
        // 默认值为0
        if(dataModel.getId() != null && dataModel.getId() != 0 ){
            ids.append(dataModel.getId()).append(",");
        }
        if(dataModel.getId1() != null && dataModel.getId1() != 0 ){
            ids.append(dataModel.getId1()).append(",");
        }
        if(dataModel.getId2() != null && dataModel.getId2() != 0 ){
            ids.append(dataModel.getId2()).append(",");
        }
        if(dataModel.getId3() != null && dataModel.getId3() != 0 ){
            ids.append(dataModel.getId3()).append(",");
        }
        if(dataModel.getId4() != null && dataModel.getId4() != 0 ){
            ids.append(dataModel.getId4());
        }
        if(!StringUtils.isEmpty(dataModel.getIdstr())){
            ids.append(dataModel.getIdstr());
        }
        if(!StringUtils.isEmpty(dataModel.getIdstr1())){
            ids.append(dataModel.getIdstr1());
        }
        if(!StringUtils.isEmpty(dataModel.getIdstr2())){
            ids.append(dataModel.getIdstr2());
        }
        String[] idArr = ids.toString().split(",");
        String[]sourceArr = sources.split(",");
        if(idArr.length != sourceArr.length){
            logger.error("number of id is not compatible with table's setted in fl_job_config[sql,source],model do not save!");
            return;
        }
        StringBuilder source = new StringBuilder();
        for(int i = 0; i < idArr.length;i++){
            source.append(sourceType).append(".").append(sourceArr[i]).append(".").append(idArr[i]);
            if(i != idArr.length -1){
                source.append(",");
            }
        }
        saveModel.setSource(source.toString());
        return ;
    }
}

+ 70 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/EhrHealthProblemConvert.java

@ -0,0 +1,70 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import com.yihu.wlyy.figure.label.util.TimeUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author litaohong on 2018/5/7
 * @project patient-co-management
 * 医疗云数据,健康问题标签
 */
@Component
public class EhrHealthProblemConvert implements Convert{
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict one = flLabelDictList.get(0);
        hbaseDatas.forEach(
                hbaseMap -> {
                    SaveModel saveModel = new SaveModel();
                    Object idcard = null;
                    // ehr那边 EHR_000017 demographic_id 为身份证编码,优先选择EHR_000017,demographic_id作为补录
                    if(null != hbaseMap.get("EHR_000017")){
                        idcard = hbaseMap.get("EHR_000017");
                    }else if(null != hbaseMap.get("demographic_id")){
                        idcard = hbaseMap.get("demographic_id");
                    }else{
                        return;
                    }
                    saveModel.setIdcard(String.valueOf(idcard));
                    saveModel.setDictCode(one.getDictCode());
                    Object labelCode = hbaseMap.get("health_problem");
                    if(null == labelCode){
                        return;
                    }
                    Object labelName = hbaseMap.get("health_problem_name");
                    if(null == labelName){
                        return;
                    }
                    saveModel.setLabelType(one.getParentCode());
                    saveModel.setLabelCode(String.valueOf(labelCode));
                    saveModel.setLabelName(String.valueOf(labelName));
                    DataModel dataModel = new DataModel();
                    dataModel.setIdstr(String.valueOf(hbaseMap.get("rowkey")));
                    convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
                    String javaTime = TimeUtil.toJavaTime(String.valueOf(hbaseMap.get("event_date")));
                    saveModel.setSourceTime(javaTime);
                    saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
                    saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
                    saveModels.add(saveModel);
                }
        );
        return saveModels;
    }
}

+ 216 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/EhrICD10CMConvert.java

@ -0,0 +1,216 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.base.SolrHelper;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import com.yihu.wlyy.figure.label.util.TimeUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.solr.common.SolrDocumentList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
 * @author litaohong on 2018/5/7
 * @project patient-co-management
 * 医疗云数据,标准疾病诊断标签
 */
@Component
public class EhrICD10CMConvert implements Convert{
    public static final int solrFqSize = 1000;
    @Autowired
    private ConvertHelper convertHelper;
    @Autowired
    private SolrHelper solrHelper;
    @Autowired
    @Qualifier("healtharchiveTemplate")
    private JdbcTemplate healtharchiveTemplate;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        if(CollectionUtils.isEmpty(hbaseDatas)){
            return saveModels;
        }
        FlLabelDict one = flLabelDictList.get(0);
        StringBuilder code = new StringBuilder();
        List<String> rowkeyList = new ArrayList<>();
        //此次循环,先剔除无用数据
        for (int i = 0; i < hbaseDatas.size(); i++) {
            if (null == hbaseDatas.get(i).get("diagnosis")) {
                continue;
            }
            Object labelName = hbaseDatas.get(i).get("diagnosis_name");
            if (null == labelName) {
                continue;
            }
            String labelCodeStr = String.valueOf(hbaseDatas.get(i).get("diagnosis"));
            if (labelCodeStr.contains(";")) {
                labelCodeStr = labelCodeStr.replace(";", "");
            }
            code.append("'").append(labelCodeStr).append("',");
            rowkeyList.add(String.valueOf(hbaseDatas.get(i).get("rowkey")));
        }
        // 根据rowkey去solr查子表的rowkey,因为rowkey含有字典集,根据字典集即可判断是否新生儿,孕妇等
        String q = "*:*";
        // 返回指定的字段
        String fl = "rowkey,profile_id";
        int num = rowkeyList.size()/solrFqSize + 1;
        List<SolrDocumentList> documentList = new ArrayList<>();
        for(int i = 0; i < num; i++){
            List<String> subList = null;
            if(i == num - 1){
                subList = rowkeyList.subList(i*solrFqSize,rowkeyList.size());
            }else{
                subList = rowkeyList.subList(i*solrFqSize,(i+1)*solrFqSize);
            }
            StringBuilder rowkeyFq = new StringBuilder("profile_id:(");
            for(int j = 0; j < subList.size();j++){
                if(j == subList.size() - 1){
                    rowkeyFq.append(rowkeyList.get(j)).append(")");
                }else{
                    rowkeyFq.append(rowkeyList.get(j)).append(" OR ");
                }
            }
            // 构造过滤查询参数
            String[] fq = {rowkeyFq.toString()};
            long count = 0;
            SolrDocumentList result = null;
            try {
                count = solrHelper.count(ConstantUtil.subcore,q);
                result = solrHelper.queryfl(ConstantUtil.subcore,q,fq,null,fl,0,count);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if(!CollectionUtils.isEmpty(result)){
                documentList.add(result);
            }
        }
        Map<String,String> rowkwy2ProfileIdmap = new HashMap<>();
        if(CollectionUtils.isEmpty(documentList)){
            return saveModels;
        }
        for(SolrDocumentList sdl:documentList){
            sdl.forEach(
                    oneDocument -> {
                        String rowkey = String.valueOf(oneDocument.get("profile_id"));
                        String Subrowkey = String.valueOf(oneDocument.get("rowkey"));
                        if (rowkwy2ProfileIdmap.containsKey(rowkey) && rowkwy2ProfileIdmap.get(rowkey).contains(Subrowkey.split("\\$")[1])) {
                            return;
                        }
                        rowkwy2ProfileIdmap.put(rowkey, Subrowkey);
                    }
            );
        }
        String sql = "select code,chronic_flag,infectious_flag from icd10_dict where code in (" + code.substring(0,code.lastIndexOf(",")) + ")";
        List<Map<String,Object>> icd10Map = healtharchiveTemplate.queryForList(sql);
        Map<String,String> chronicMap = new HashMap<>();
        Map<String,String> infectiousMap = new HashMap<>();
        icd10Map.forEach(
                map -> {
                    if(null != map.get("chronic_flag")){
                        chronicMap.put(String.valueOf(map.get("code")),String.valueOf(map.get("chronic_flag")));
                    }
                    if(null != map.get("infectious_flag")){
                        infectiousMap.put(String.valueOf(map.get("code")),String.valueOf(map.get("infectious_flag")));
                    }
                }
        );
        hbaseDatas.forEach(
                hbaseMap -> {
                    SaveModel saveModel = new SaveModel();
                    Object idcard = null;
                    // ehr那边 EHR_000017 demographic_id 为身份证编码,优先选择EHR_000017,demographic_id作为补录
                    if(null != hbaseMap.get("EHR_000017")){
                        idcard = hbaseMap.get("EHR_000017");
                    }else if(null != hbaseMap.get("demographic_id")){
                        idcard = hbaseMap.get("demographic_id");
                    }else{
                        return;
                    }
                    saveModel.setIdcard(String.valueOf(idcard));
                    saveModel.setDictCode(one.getDictCode());
                    String labelCode = String.valueOf(hbaseMap.get("diagnosis"));
                    if(null == labelCode){
                        return;
                    }
                    Object labelName = hbaseMap.get("diagnosis_name");
                    if(null == labelName){
                        return;
                    }
                    saveModel.setLabelType(one.getParentCode());
                    saveModel.setLabelCode(String.valueOf(labelCode));
                    saveModel.setLabelName(String.valueOf(labelName));
                    String labelValue = "";
                    String[] codearr = labelCode.split(";");
                    for (String codeStr : codearr) {
                        if (null != chronicMap.get(codeStr) && null != infectiousMap.get(codeStr)) {
                            labelValue = "慢病;传染病";
                        } else if (null != chronicMap.get(codeStr)) {
                            labelValue = "慢病";
                        } else if (null != infectiousMap.get(codeStr)) {
                            labelValue = "传染病";
                        }
                    }
                    if(rowkwy2ProfileIdmap.containsKey(hbaseMap.get("rowkey")) && (rowkwy2ProfileIdmap.get(hbaseMap.get("rowkey")).contains("HDSB02_04") || rowkwy2ProfileIdmap.get(hbaseMap.get("rowkey")).contains("HDSB02_07") || rowkwy2ProfileIdmap.get(hbaseMap.get("rowkey")).contains("HDSB02_87"))){
                        labelValue = labelValue + ";孕妇";
                    }else if(rowkwy2ProfileIdmap.containsKey(hbaseMap.get("rowkey")) && (rowkwy2ProfileIdmap.get(hbaseMap.get("rowkey")).contains("HDSB01_01")) || (rowkwy2ProfileIdmap.containsKey(hbaseMap.get("rowkey")) && rowkwy2ProfileIdmap.get(hbaseMap.get("rowkey")).contains("HDSB01_03")) || (rowkwy2ProfileIdmap.containsKey(hbaseMap.get("rowkey")) && rowkwy2ProfileIdmap.get(hbaseMap.get("rowkey")).contains("HDSD00_89"))){
                        labelValue = labelValue + ";新生儿";
                    }
                    saveModel.setLabelValue(labelValue);
                    DataModel dataModel = new DataModel();
                    dataModel.setIdstr(String.valueOf(hbaseMap.get("rowkey")));
                    convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
                    String javaTime = TimeUtil.toJavaTime(String.valueOf(hbaseMap.get("event_date")));
                    saveModel.setSourceTime(javaTime);
                    saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
                    saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
                    saveModels.add(saveModel);
                }
        );
        return saveModels;
    }
    class ThreadSolrSearch implements Callable {
        private String q;
        private String[] fq;
        private String fl;
        public ThreadSolrSearch(String q,String[] fq,String fl){
            this.q = q;
            this.fq = fq;
            this.fl = fl;
        }
        @Override
        public Object call() throws Exception {
            long count = 0;
            SolrDocumentList documentList = null;
            try {
                count = solrHelper.count(ConstantUtil.subcore,q);
                documentList = solrHelper.queryfl(ConstantUtil.subcore,q,fq,null,fl,0,count);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return documentList;
        }
    }
}

+ 49 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/EvaluateConvert.java

@ -0,0 +1,49 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
/**
 * @author litaohong on 2018/4/9
 * @project patient-co-management
 * 评价行为标签
 */
@Component
public class EvaluateConvert implements Convert{
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict dict = flLabelDictList.get(0);
        for(DataModel dataModel:modelList){
            SaveModel saveModel = new SaveModel();
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(dict.getLabelCode());
            saveModel.setLabelName(dataModel.getLabelName());
            // 评价相关的问题的code(业务id)
            saveModel.setLabelValue(dataModel.getLabelValue());
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            if (StringUtils.isEmpty(saveModel.getSource())) {
                return new ArrayList<>();
            }
            saveModel.setSourceTime(dataModel.getSourceTime());
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 122 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/FeedbackConvert.java

@ -0,0 +1,122 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.base.es.config.ElastricSearchHelper;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
/**
 * @author litaohong on 2018/4/9
 * @project patient-co-management
 * 反馈行为标签  记录用户是否有反馈过,反馈了几次
 */
@Component
public class FeedbackConvert implements Convert {
    @Autowired
    private ConvertHelper convertHelper;
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    private Map<String,String> distinctIdcardMap = new HashMap<>();
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict dict = flLabelDictList.get(0);
        Map<String,String> mapES = countESFeedbackByIdcard(modelList);
        Map<String,DataModel> modelMap = distinctIdcard(modelList);
        for(String idcard : modelMap.keySet()){
            SaveModel saveModel = new SaveModel();
            int value = 0;
            saveModel.setIdcard(idcard);
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(dict.getLabelCode());
            saveModel.setLabelName(dict.getLabelName());
            if(mapES.containsKey(idcard)){
                value = Integer.parseInt(mapES.get(idcard));
            }
            if(distinctIdcardMap.containsKey(idcard)){
                value = Integer.parseInt(distinctIdcardMap.get(idcard)) + value;
            }
            saveModel.setLabelValue(String.valueOf(value));
            convertHelper.generateDataSource(modelMap.get(idcard),saveModel,sourceType,source);
            if (StringUtils.isEmpty(saveModel.getSource())) {
                return new ArrayList<>();
            }
            saveModel.setSourceTime(modelMap.get(idcard).getSourceTime());
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
    /**
     * 累加es中每个用户反馈的次数
     * @return
     */
    public Map<String,String> countESFeedbackByIdcard(List<DataModel> modelList){
        Map<String, String> result = new HashMap<>();
        List<Map<String,Object>> list = new ArrayList<>();
        StringBuilder idcardStr = new StringBuilder();
        idcardStr.append("(");
        for (int i = 0; i < modelList.size(); i++) {
            idcardStr.append("'").append(modelList.get(i).getIdcard()).append("'");
            if (i != modelList.size() - 1) {
                idcardStr.append(",");
            }
        }
        idcardStr.append(")");
        //先查找出es中已有的用户的反馈次数
        String querySql = "select labelValue from " + ConstantUtil.figure_label_es_index + "/" + ConstantUtil.figure_label_es_type + " where lableType = 'feedback_dict' and idcard in " + idcardStr.toString();
        list = elastricSearchHelper.excuceSQL(querySql);
        //组装以idcard为key的map
        if(!CollectionUtils.isEmpty(list)){
            list.forEach(
                    data -> {
                        result.put(data.get("idcard").toString(), data.get("lableValue").toString());
                    }
            );
        }
        return result;
    }
    /**
     * 统计从数据库中查询出来的idcard的反馈记录次数,一个人可能会有多条反馈
     * @param modelList
     * @return
     */
    public Map<String,DataModel> distinctIdcard(List<DataModel> modelList){
        Map<String,DataModel> result = new HashMap<>();
        modelList.forEach(
                model ->{
                    if(distinctIdcardMap.containsKey(model.getIdcard())){
                        int count = Integer.parseInt(distinctIdcardMap.get(model.getIdcard())) + 1;
                        distinctIdcardMap.put(model.getIdcard(),String.valueOf(count));
                    }else {
                        distinctIdcardMap.put(model.getIdcard(),"1");
                    }
                    if(result.containsKey(model.getIdcard())){
                        return;
                    }else{
                        result.put(model.getIdcard(),model);
                    }
                }
        );
        return result;
    }
}

+ 21 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/FollowupStatusConvert.java

@ -0,0 +1,21 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import java.util.List;
import java.util.Map;
/**
 * @author litaohong on 2018/6/15
 * @project patient-co-management
 * 居民随访状态转换器
 */
public class FollowupStatusConvert implements Convert {
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        return null;
    }
}

+ 57 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/HealthEduArticalConvert.java

@ -0,0 +1,57 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
/**
 * @author litaohong on 2018/4/4
 * @project patient-co-management
 * 健康教育文章阅读行为标签转换器
 */
@Component
public class HealthEduArticalConvert implements Convert {
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict dict = flLabelDictList.get(0);
        Map<String,String> dictMap = new HashMap<>();
        flLabelDictList.forEach(
                one ->{
                    dictMap.put(one.getLabelCode(),one.getLabelName());
                }
        );
        for(DataModel dataModel:modelList){
            SaveModel saveModel = new SaveModel();
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(dataModel.getLabelCode());
            saveModel.setLabelName(dictMap.get(dataModel.getLabelCode()));
            // 健康文章的code(业务表id)
            saveModel.setLabelValue(dataModel.getLabelValue());
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            if (StringUtils.isEmpty(saveModel.getSource())) {
                return new ArrayList<>();
            }
            saveModel.setSourceTime(dataModel.getSourceTime());
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 76 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/HealthEduArticleReceiveConvert.java

@ -0,0 +1,76 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.constant.BusinessConstant;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.annotation.PostConstruct;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
 * @author litaohong on 2018/5/31
 * @project patient-co-management
 */
public class HealthEduArticleReceiveConvert implements Convert{
    public Map<String,String> code2IdcardMap = new ConcurrentHashMap<>();
    @Autowired
    private ConvertHelper convertHelper;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @PostConstruct
    public void initMap(){
        String sql = "select code,idcard from wlyy.wlyy_patient";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        list.forEach(
                map -> {
                    code2IdcardMap.put(String.valueOf(map.get("code")),String.valueOf(map.get("idcard")));
                }
        );
    }
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict dict = flLabelDictList.get(0);
        Map<String,String> dictMap = new HashMap<>();
        flLabelDictList.forEach(
                one ->{
                    dictMap.put(one.getLabelCode(),one.getLabelName());
                }
        );
        for(DataModel dataModel:modelList){
            SaveModel saveModel = new SaveModel();
            saveModel.setIdcard(code2IdcardMap.get(dataModel.getIdcard()));
            saveModel.setDictCode(dict.getDictCode());
            saveModel.setLabelType(dataModel.getParentCode());
            saveModel.setLabelCode(dataModel.getLabelCode());
            saveModel.setLabelName(dataModel.getLabelName());
            saveModel.setLabelValue(dataModel.getFirstLevelCategoryName() + BusinessConstant.separator + dataModel.getSecondLevelCategoryName());
            // 文章推送人名字
            saveModel.setSendName(dataModel.getSendName());
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            if (StringUtils.isEmpty(saveModel.getSource())) {
                return new ArrayList<>();
            }
            saveModel.setSourceTime(dataModel.getSourceTime());
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 55 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/IsConsultConvert.java

@ -0,0 +1,55 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
/**
 * @author litaohong on 2018/4/9
 * @project patient-co-management
 * 是否有咨询问题标签
 */
@Component
public class IsConsultConvert implements Convert {
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict dict = flLabelDictList.get(0);
        // 有咨询code为0,代表有咨询问题
        String hasConsult = "0";
        Map<String,String> dictMap = new HashMap<>();
        flLabelDictList.forEach(
                one ->{
                    dictMap.put(one.getLabelCode(),one.getLabelName());
                }
        );
        for(DataModel dataModel:modelList){
            SaveModel saveModel = new SaveModel();
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(hasConsult);
            saveModel.setLabelName(dictMap.get(hasConsult));
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            if (StringUtils.isEmpty(saveModel.getSource())) {
                return new ArrayList<>();
            }
            saveModel.setSourceTime(dataModel.getSourceTime());
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 60 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/IsDrinkingConvert.java

@ -0,0 +1,60 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
/**
 * @author humingfen on 2018.04.19
 * 是否饮酒标签转换器
 */
@Component
public class IsDrinkingConvert implements Convert{
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        // 饮酒code为2,代表未知
        String hasDrinking = "2";
        /*Map<String,String> dictMap = new HashMap<>();
        flLabelDictList.forEach(
                one ->{
                    dictMap.put(one.getLabelCode(),one.getLabelName());
                }
        );*/
        for(DataModel dataModel:modelList){
            if(StringUtils.isNotBlank(dataModel.getLabelValue())) {
                float dailyDrinking = Float.parseFloat(dataModel.getLabelValue());
                if(dailyDrinking > 0){
                    hasDrinking = "0";
                }else if(dailyDrinking <= 0) {
                    hasDrinking = "1";
                }
            }
            SaveModel saveModel = new SaveModel();
            FlLabelDict dict = flLabelDictList.get(Integer.parseInt(hasDrinking));
            saveModel.setId(MakeIDUtil.makeEsSaveModelID(dataModel,dict));
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(hasDrinking);
            saveModel.setLabelName(dict.getLabelName());
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            //如果fl_job_config表配置的id和数据来源不一致,则不保存数据
            if (StringUtils.isEmpty(saveModel.getSource())) {
                return new ArrayList<>();
            }
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 59 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/IsOnlineConvert.java

@ -0,0 +1,59 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.*;
/**
 * 适用于线上/线下的签约、缴费
 */
@Component
public class IsOnlineConvert implements Convert {
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> models, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        if(CollectionUtils.isEmpty(flLabelDictList)){
            return saveModels;
        }
        FlLabelDict one = flLabelDictList.get(0);
        Map<String,String> map = new HashMap<>();
        flLabelDictList.forEach(
                fLlabelDict -> {
                    map.put(fLlabelDict.getLabelCode(),fLlabelDict.getLabelName());
                }
        );
        models.forEach(
                model -> {
                    SaveModel saveModel = new SaveModel();
                    saveModel.setIdcard(model.getIdcard());
                    saveModel.setLabelType(one.getParentCode());
                    saveModel.setLabelCode(model.getLabelCode());
                    saveModel.setLabelName(map.get(model.getLabelCode()));
                    saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
                    convertHelper.generateDataSource(model,saveModel,sourceType,source);
                    //如果fl_job_config表配置的id和数据来源不一致,则不保存数据
                    if(StringUtils.isEmpty(saveModel.getSource())){
                        return;
                    }
                    saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
                    saveModels.add(saveModel);
                }
        );
        return saveModels;
    }
}

+ 60 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/IsSmokingConvert.java

@ -0,0 +1,60 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
/**
 * @author humingfen on 2018.03.14
 * 是否抽烟标签转换器
 */
@Component
public class IsSmokingConvert implements Convert{
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        // 抽烟code为2,代表未知
        String hasSmoking = "2";
        Map<String,String> dictMap = new HashMap<>();
        flLabelDictList.forEach(
                one ->{
                    dictMap.put(one.getLabelCode(),one.getLabelName());
                }
        );
        for(DataModel dataModel:modelList){
            if(StringUtils.isNotBlank(dataModel.getLabelValue())) {
                float dailySmoking = Float.parseFloat(dataModel.getLabelValue());
                if(dailySmoking > 0){
                    hasSmoking = "0";
                }else if(dailySmoking <= 0) {
                    hasSmoking = "1";
                }
            }
            SaveModel saveModel = new SaveModel();
            FlLabelDict dict = flLabelDictList.get(Integer.parseInt(hasSmoking));
            saveModel.setId(MakeIDUtil.makeEsSaveModelID(dataModel,dict));
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(hasSmoking);
            saveModel.setLabelName(dictMap.get(hasSmoking));
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            //如果fl_job_config表配置的id和数据来源不一致,则不保存数据
            if (StringUtils.isEmpty(saveModel.getSource())) {
                return new ArrayList<>();
            }
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 114 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/MutilThreadConvert.java

@ -0,0 +1,114 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import com.yihu.wlyy.figure.label.util.TimeUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;
/**
 * @Author lith 2018/03/23
 * 多线程分页查询mysql数据,因为mysql数据量比较大的时候,会比较慢
 */
public class MutilThreadConvert implements Callable {
    private Logger logger = LoggerFactory.getLogger(MutilThreadConvert.class);
    @Autowired
    private ConvertHelper convertHelper;
    @Autowired
    private BasicDictItemHelper basicDictItemHelper;
    private List<DataModel> dataModels;
    private Long categoryId;
    private String sourceType;
    private String source;
    public MutilThreadConvert(List<DataModel> dataModels,Long categoryId, String sourceType, String source){
        this.dataModels = dataModels;
        this.categoryId = categoryId;
        this.sourceType = sourceType;
        this.source = source;
    }
    @Override
    public Object call() throws Exception {
        String title = Thread.currentThread().getName() + " generate savemodel";
        long start = System.currentTimeMillis();
        TimeUtil.start(logger,title,start);
        List<SaveModel> list = generateSaveModleWithOutConvert(dataModels,categoryId,sourceType,source);
        TimeUtil.finish(logger,title,start,System.currentTimeMillis());
        return list;
    }
    /**
     * 无需转换器直接转换,此种情况为源数据已经分类好标签
     * @param dataModels
     * @param categoryId
     * @param sourceType
     * @param source
     *
     * @return
     */
    public List<SaveModel> generateSaveModleWithOutConvert(List<DataModel> dataModels, Long categoryId, String sourceType, String source){
        String dictCode = basicDictItemHelper.dictCategoryMap.get(String.valueOf(categoryId));
        List<SaveModel> saveModels = new ArrayList<>();
        //lambda无法跳出循环
        for(DataModel dataModel:dataModels){
            SaveModel saveModel = new SaveModel();
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setDictCode(dictCode);
            //找不到该类别
            if (null == basicDictItemHelper.labelDictMap.get(dictCode)) {
                logger.error("label dictCode not exist :【" + dictCode + "】");
                return new ArrayList<>();
            }
            //只有一种类别
            if(basicDictItemHelper.labelDictMap.get(dictCode).size() == 1){
                List<FlLabelDict> flLabelDictList = basicDictItemHelper.labelDictMap.get(dictCode);
                saveModel.setLabelType(flLabelDictList.get(0).getParentCode());
                saveModel.setLabelCode(flLabelDictList.get(0).getLabelCode());
                saveModel.setLabelName(flLabelDictList.get(0).getLabelName());
                if(!StringUtils.isEmpty(dataModel.getLabelValue())){
                    if(StringUtils.endsWithIgnoreCase("height_dict",dictCode)){
                        saveModel.setLabelValue(dataModel.getLabelValue()+"cm");
                    }
                    else if(StringUtils.endsWithIgnoreCase("weight_dict",dictCode)){
                        saveModel.setLabelValue(dataModel.getLabelValue()+"kg");
                    }else{
                        saveModel.setLabelValue(dataModel.getLabelValue());
                    }
                }
            }else{
                //当有多种类别,sql里构造好需要格式,例如不同code对应不同的label_name
                saveModel.setLabelType(dataModel.getParentCode());
                saveModel.setLabelCode(dataModel.getLabelCode());
                saveModel.setLabelName(dataModel.getLabelName());
            }
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            //如果fl_job_config表配置的id和数据来源不一致,则不保存数据,原子性,全部不保存,不然部分存了部分没存不好剔除数据
            if(StringUtils.isEmpty(saveModel.getSource())){
                return new ArrayList<>();
            }
            if(!StringUtils.isEmpty(dataModel.getSourceTime())){
                saveModel.setSourceTime(dataModel.getSourceTime());
            }
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 54 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/OnLineConsultConvert.java

@ -0,0 +1,54 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
/**
 * @author litaohong on 2018/03/27
 * @project patient-co-management
 * 线上咨询问题标签(包括续方咨询,续方咨询只是线上咨询的一种类型)
 */
@Component
public class OnLineConsultConvert implements Convert {
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict dict = flLabelDictList.get(0);
        Map<String,String> dictMap = new HashMap<>();
        flLabelDictList.forEach(
                one ->{
                    dictMap.put(one.getLabelCode(),one.getLabelName());
                }
        );
        for(DataModel dataModel:modelList){
            SaveModel saveModel = new SaveModel();
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(dataModel.getLabelCode());
            saveModel.setLabelName(dictMap.get(dataModel.getLabelCode()));
            saveModel.setLabelValue(dataModel.getLabelValue());
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            if (StringUtils.isEmpty(saveModel.getSource())) {
                return new ArrayList<>();
            }
            saveModel.setSourceTime(dataModel.getSourceTime());
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 56 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/OnlineAppointmentConvert.java

@ -0,0 +1,56 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author litaohong on 2018/4/12
 * @project patient-co-management
 * 网上预约行为标签
 */
@Component
public class OnlineAppointmentConvert implements Convert{
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict dict = flLabelDictList.get(0);
        for(DataModel dataModel : modelList){
            SaveModel saveModel = new SaveModel();
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setDictCode(dict.getDictCode());
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(dataModel.getLabelCode());
            saveModel.setLabelName(dataModel.getParentName() + "-" + dataModel.getLabelName());
            saveModel.setLabelValue(dataModel.getLabelValue());
            //如果有医生代预约
            if(!StringUtils.isEmpty(dataModel.getDoctor())){
                saveModel.setDoctor(dataModel.getDoctor());
            }
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            if(StringUtils.isEmpty(saveModel.getSource())){
                return new ArrayList<>();
            }
            saveModel.setSourceTime(dataModel.getSourceTime());
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 77 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/ReplyInTimeConvert.java

@ -0,0 +1,77 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.base.es.config.ElastricSearchHelper;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * @author litaohong on 2018/4/8
 * @project patient-co-management
 * 医生咨询分析--及时回复标签
 */
@Component
public class ReplyInTimeConvert implements Convert{
    @Autowired
    private ConvertHelper convertHelper;
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict dict = flLabelDictList.get(0);
        for(DataModel model:modelList){
            SaveModel saveModel = new SaveModel();
            saveModel.setIdcard(model.getIdcard());
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(dict.getLabelCode());
            saveModel.setLabelName(dict.getLabelName());
            saveModel.setLabelValue(model.getLabelValue());
            //记录回复时间,方便以后统计一定时间内的回复率
            saveModel.setSourceTime(model.getSourceTime());
            convertHelper.generateDataSource(model,saveModel,sourceType,source);
            if(StringUtils.isEmpty(saveModel.getSource())){
                return new ArrayList<>();
            }
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
    //lambda无法跳出循环
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5};
        List list = new ArrayList();
        list.addAll(CollectionUtils.arrayToList(arr));
        list.forEach(
                one ->{
                    if(StringUtils.endsWithIgnoreCase(one.toString(),"3")){
                        return;
                    }
                    System.out.println(one);
                }
        );
        System.out.println("*********************************************************");
        for(Object one:list){
            if(StringUtils.endsWithIgnoreCase(one.toString(),"3")){
                return;
            }
            System.out.println(one);
        }
    }
}

+ 64 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/SexConvert.java

@ -0,0 +1,64 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.IdCardUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.*;
/**
 * @author lith on 2018.03.14
 * 性别标签转换器
 */
@Component
public class SexConvert implements Convert{
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> models, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict one = flLabelDictList.get(0);
        Map<String,String> map = new HashMap<>();
        flLabelDictList.forEach(
                fLlabelDict -> {
                    map.put(fLlabelDict.getLabelCode(),fLlabelDict.getLabelName());
                }
        );
        models.forEach(
                model -> {
                    SaveModel saveModel = new SaveModel();
                    saveModel.setIdcard(model.getIdcard());
                    saveModel.setLabelType(one.getParentCode());
                    String sex = IdCardUtil.getSexForIdcard(model.getIdcard());
                    saveModel.setDictCode(one.getDictCode());
                    saveModel.setLabelCode(sex);
                    saveModel.setLabelName(map.get(sex));
                    //源数据来源时间
                    if(null != model.getSourceTime()){
                        saveModel.setSourceTime(model.getSourceTime());
                    }
                    saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
                    convertHelper.generateDataSource(model,saveModel,sourceType,source);
                    //如果fl_job_config表配置的id和数据来源不一致,则不保存数据
                    if(StringUtils.isEmpty(saveModel.getSource())){
                        return;
                    }
                    saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
                    saveModels.add(saveModel);
                }
        );
        return saveModels;
    }
}

+ 56 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/WxSubscribeConvert.java

@ -0,0 +1,56 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
/**
 * @author litaohong on 2018/03/27
 * @project patient-co-management
 * 是否有关注i健康微信公众号
 */
@Component
public class WxSubscribeConvert implements Convert {
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, List<Map<String, Object>> hbaseDatas, List<FlLabelDict> flLabelDictList, String sourceType, String source) {
        List<SaveModel> saveModels = new ArrayList<>();
        FlLabelDict dict = flLabelDictList.get(0);
        // 有咨询code为0,代表有咨询问题
        String yes = "0";
        Map<String,String> dictMap = new HashMap<>();
        flLabelDictList.forEach(
                one ->{
                    dictMap.put(one.getLabelCode(),one.getLabelName());
                }
        );
        for(DataModel dataModel:modelList){
            SaveModel saveModel = new SaveModel();
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(yes);
            saveModel.setLabelName(dictMap.get(yes));
            saveModel.setLabelValue(dataModel.getLabelValue());
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            if (StringUtils.isEmpty(saveModel.getSource())) {
                return new ArrayList<>();
            }
            saveModel.setSourceTime(dataModel.getSourceTime());
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModel.setId(MakeIDUtil.makeSaveModelID(saveModel));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 31 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/dao/FLLabelDictDao.java

@ -0,0 +1,31 @@
package com.yihu.wlyy.figure.label.dao;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author lith on 2018.03.14
 * 标签字典
 */
public interface FLLabelDictDao extends PagingAndSortingRepository<FlLabelDict, String>, JpaSpecificationExecutor<FlLabelDict> {
    /**
     * 根据父类标签查询字典信息
     * @param parentCode
     * @return
     */
    @Query(" FROM FlLabelDict a WHERE a.parentCode=?1")
    FlLabelDict findByParentCode(String parentCode);
    /**
     * 根据父类code和标签code查询标签字典信息
     * @param parentCode
     * @param labelCode
     * @return
     */
    @Query(" FROM FlLabelDict a WHERE a.parentCode=?1 and labelCode = ?2")
    FlLabelDict findByParentCodeAndLabelCode(String parentCode, String labelCode);
}

+ 69 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/dao/FlJobConfigDao.java

@ -0,0 +1,69 @@
package com.yihu.wlyy.figure.label.dao;
import com.yihu.wlyy.figure.label.entity.FlJobConfig;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author lith on 2018.03.14
 * 定时任务配置
 */
public interface FlJobConfigDao extends PagingAndSortingRepository<FlJobConfig, Long>, JpaSpecificationExecutor<FlJobConfig> {
    /**
     * 根据id和状态查询job配置
     * @param id
     * @param status
     * @return
     */
    @Query(" FROM FlJobConfig a WHERE a.id=?1 and a.status=?2 and a.del='1'")
    FlJobConfig findByIdAndStatus(Long id, String status);
    /**
     * 查询所有的job配置
     * @param status
     * @return
     */
    @Query(" FROM FlJobConfig a WHERE a.status=?1 and a.del='1'")
    List<FlJobConfig> findByAll(String status);
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Query(" FROM FlJobConfig a WHERE a.id=?1 and a.del='1'")
    FlJobConfig findById(Long id);
    /**
     * 更新job的状态(状态为启动或停止)
     * @param id
     * @param status
     * @return
     */
    @Modifying
    @Query(" update FlJobConfig a set a.status=?2 where a.id=?1 ")
    int updateStatus(Long id, String status);
    /**
     * 删除job(0 正常 1 删除)
     * @param id
     * @return
     */
    @Modifying
    @Query(" update FlJobConfig a set a.del = 1 where a.id=?1 ")
    int deleteJob(Long id);
    /**
     * 更新增量时间
     * @param id
     * @param value
     * @return
     */
    @Modifying
    @Query(" update FlJobConfig a set a.sqlFieldValue=?2 where a.id=?1 ")
    int updateSqlFildeValue(Long id, String value);
}

+ 30 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/dao/FlLabelDictJobDao.java

@ -0,0 +1,30 @@
package com.yihu.wlyy.figure.label.dao;
import com.yihu.wlyy.figure.label.entity.FlLabelDictJob;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author lith on 2018.03.14
 * 定时任务具体字典维度
 */
public interface FlLabelDictJobDao extends PagingAndSortingRepository<FlLabelDictJob, String>, JpaSpecificationExecutor<FlLabelDictJob> {
    /**
     * 根据jobId查询
     * @param jobId
     * @return
     */
    @Query(" FROM FlLabelDictJob a WHERE a.jobId=?1")
    FlLabelDictJob findByJobId(Long jobId);
    /**
     * 根据标签类型查询
     * @param type
     * @return
     */
    @Query(" FROM FlLabelDictJob a WHERE a.labelType=?1")
    FlLabelDictJob findByLabelType(String type);
}

+ 142 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/entity/FlJobConfig.java

@ -0,0 +1,142 @@
package com.yihu.wlyy.figure.label.entity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * @author lith on 2018.03.07
 *
 */
@Entity
@Table(name = "fl_job_config")
public class FlJobConfig extends IdEntity {
    private String jobName;
    private String jobClass;
    private String query_sql;
    private String countSql;
    private Integer sqlFieldType;
    private String sqlFieldValue;
    private String sqlField;
    private String quartzCron;
    private String status;
    private String del;
    private String sourceType;
    private String source;
    private String datasource;
    private String extractField;
    public String getJobName() {
        return jobName;
    }
    public void setJobName(String jobName) {
        this.jobName = jobName;
    }
    public String getJobClass() {
        return jobClass;
    }
    public void setJobClass(String jobClass) {
        this.jobClass = jobClass;
    }
    public String getQuery_sql() {
        return query_sql;
    }
    public void setQuery_sql(String query_sql) {
        this.query_sql = query_sql;
    }
    public Integer getSqlFieldType() {
        return sqlFieldType;
    }
    public void setSqlFieldType(Integer sqlFieldType) {
        this.sqlFieldType = sqlFieldType;
    }
    public String getSqlFieldValue() {
        return sqlFieldValue;
    }
    public void setSqlFieldValue(String sqlFieldValue) {
        this.sqlFieldValue = sqlFieldValue;
    }
    public String getSqlField() {
        return sqlField;
    }
    public void setSqlField(String sqlField) {
        this.sqlField = sqlField;
    }
    public String getQuartzCron() {
        return quartzCron;
    }
    public void setQuartzCron(String quartzCron) {
        this.quartzCron = quartzCron;
    }
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    public String getDel() {
        return del;
    }
    public void setDel(String del) {
        this.del = del;
    }
    public String getSourceType() {
        return sourceType;
    }
    public void setSourceType(String sourceType) {
        this.sourceType = sourceType;
    }
    public String getSource() {
        return source;
    }
    public void setSource(String source) {
        this.source = source;
    }
    public String getDatasource() {
        return datasource;
    }
    public void setDatasource(String datasource) {
        this.datasource = datasource;
    }
    public String getExtractField() {
        return extractField;
    }
    public void setExtractField(String extractField) {
        this.extractField = extractField;
    }
    public String getCountSql() {
        return countSql;
    }
    public void setCountSql(String countSql) {
        this.countSql = countSql;
    }
}

+ 52 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/entity/FlLabelDict.java

@ -0,0 +1,52 @@
package com.yihu.wlyy.figure.label.entity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * @author lith on 2018.03.07
 *
 */
@Entity
@Table(name = "fl_label_dict")
public class FlLabelDict extends IdEntity {
    private String parentCode;
    private String labelName;
    private String labelCode;
    private String dictCode;
    public String getDictCode() {
        return dictCode;
    }
    public void setDictCode(String dictCode) {
        this.dictCode = dictCode;
    }
    public String getParentCode() {
        return parentCode;
    }
    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }
    public String getLabelName() {
        return labelName;
    }
    public void setLabelName(String labelName) {
        this.labelName = labelName;
    }
    public String getLabelCode() {
        return labelCode;
    }
    public void setLabelCode(String labelCode) {
        this.labelCode = labelCode;
    }
}

+ 60 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/entity/FlLabelDictJob.java

@ -0,0 +1,60 @@
package com.yihu.wlyy.figure.label.entity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * @author lith on 2018.03.07
 *
 */
@Entity
@Table(name = "fl_label_dict_job")
public class FlLabelDictJob extends IdEntity {
    private Long jobId;
    private String labelType;
    private String sql;
    private String convertClazz;
    private Long categoryId;
    public Long getCategoryId() {
        return categoryId;
    }
    public void setCategoryId(Long categoryId) {
        this.categoryId = categoryId;
    }
    public Long getJobId() {
        return jobId;
    }
    public void setJobId(Long jobId) {
        this.jobId = jobId;
    }
    public String getLabelType() {
        return labelType;
    }
    public void setLabelType(String labelType) {
        this.labelType = labelType;
    }
    public String getSql() {
        return sql;
    }
    public void setSql(String sql) {
        this.sql = sql;
    }
    public String getConvertClazz() {
        return convertClazz;
    }
    public void setConvertClazz(String convertClazz) {
        this.convertClazz = convertClazz;
    }
}

+ 38 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/entity/IdEntity.java

@ -0,0 +1,38 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.wlyy.figure.label.entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
/**
 * 统一定义id的entity基类.
 * 
 * 基类统一定义id的属性名称、数据类型、列名映射及生成策略.
 * Oracle需要每个Entity独立定义id的SEQUCENCE时,不继承于本类而改为实现一个Idable的接口。
 * 
 * @author calvin
 */
// JPA 基类的标识
@MappedSuperclass
public abstract class IdEntity implements Serializable {
	private static final long serialVersionUID = 3673803562328635206L;
	protected Long id;  // 非业务主键
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
}

+ 34 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/enums/JobSqlFieldTypeEnum.java

@ -0,0 +1,34 @@
package com.yihu.wlyy.figure.label.enums;
/**
 * @author litaohong on 2018/4/11
 * @project patient-co-management
 *
 * 增量字段类型枚举 1时间 (yyyy-mm-dd  HH:MM:ss)2数字
 */
public enum JobSqlFieldTypeEnum {
    TIME(1,"时间"),
    NUM(2,"数字");
    private int value;
    private String desc;
    private JobSqlFieldTypeEnum(int value,String desc){
        this.value = value;
        this.desc = desc;
    }
    public int getValue() {
        return value;
    }
    public String getDesc() {
        return desc;
    }
    @Override
    public String toString() {
        return String.valueOf(this.getValue());
    }
}

+ 12 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/enums/SourceTypeEnum.java

@ -0,0 +1,12 @@
package com.yihu.wlyy.figure.label.enums;
/**
 * @author litaohong on 2018/3/29
 * @project patient-co-management
 */
public enum SourceTypeEnum {
    MYSQL,
    HBASE,
    FILE,
    ELASTICSEARCH;
}

+ 77 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/ESExtracter.java

@ -0,0 +1,77 @@
package com.yihu.wlyy.figure.label.extract;
import com.yihu.base.es.config.ElasticsearchUtil;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.util.BeanUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * @author humingfen on 2018.04.19
 * ES数据抽取器
 */
@Component
public class ESExtracter implements Extracter{
    private Logger logger = LoggerFactory.getLogger(ESExtracter.class);
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    @Override
    public  List<DataModel> extractData(String sql, String datasource){
        List<DataModel> saveModels = new ArrayList<>();
        List<Map<String,Object>> list = elasticsearchUtil.excuteDataModel(sql);
        for(Map<String,Object> tempMap:list){
            try {
                DataModel dataModel = (DataModel)BeanUtil.mapToBean(tempMap,DataModel.class);
               /* for (String s : tempMap.keySet()) {
                    String key = null;
                    Object value = tempMap.get(s);
                    if (s.startsWith("_")) {
                        continue;
                    }else if((s.equals("id") || s.equals("id1") || s.equals("id2")) && value != null) {
                        value = Integer.parseInt(String.valueOf(value));
                    }
                    key = "set" + UpFirstStr(s);
                    try {
                        if (value instanceof String) {
                            DataModel.class.getMethod(key, String.class).invoke(dataModel, value);
                        } else if (value instanceof Integer) {
                            DataModel.class.getMethod(key, Integer.class).invoke(dataModel, value);
                        } else if (value instanceof Double) {
                            DataModel.class.getMethod(key, Double.class).invoke(dataModel, value);
                        } else if (value instanceof java.util.Date) {
                            DataModel.class.getMethod(key, java.util.Date.class).invoke(dataModel, value);
                        }
                    } catch (Exception e) {
                        logger.error(e.getMessage());
                    }
                }*/
                saveModels.add(dataModel);
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
        return saveModels;
    }
    /**
     * 首字母大写
     *
     * @param str
     * @return
     */
    private String UpFirstStr(String str) {
        return str.replaceFirst(str.substring(0, 1), str.substring(0, 1).toUpperCase());
    }
}

+ 22 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/Extracter.java

@ -0,0 +1,22 @@
package com.yihu.wlyy.figure.label.extract;
import com.yihu.wlyy.figure.label.model.DataModel;
import java.util.List;
/**
 * @author lith on 2018.03.14 -- Created by chenweida on 2018/3/7.
 * 数据抽取器
 */
public interface Extracter {
    /**
     * 数据抽取
     *
     * @return
     */
//    List<ExtractModel> extract();
    List<DataModel> extractData(String sql,String datasource);
}

+ 150 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/HbaseExtracter.java

@ -0,0 +1,150 @@
package com.yihu.wlyy.figure.label.extract;
import com.yihu.base.SolrHelper;
import com.yihu.base.hbase.HBaseHelper;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.util.TimeUtil;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.filter.BinaryComparator;
import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.QualifierFilter;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CollectionUtils;
import org.apache.solr.common.SolrDocumentList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.hadoop.hbase.HbaseTemplate;
import org.springframework.data.hadoop.hbase.TableCallback;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
 * @author litaohong on 2018/5/5
 * @project patient-co-management
 * hbase数据抽取器
 */
@Component
public class HbaseExtracter implements Extracter{
    private Logger logger = LoggerFactory.getLogger(HbaseExtracter.class);
    @Autowired
    private HBaseHelper hBaseHelper;
    @Autowired
    private SolrHelper solrHelper;
    @Autowired
    private HbaseTemplate hbaseTemplate;
    private int numPerPage = 1000; //从solr中一次性取得1000条
    @Override
    public List<DataModel> extractData(String sql, String datasource) {
        return null;
    }
    public  List<Map<String,Object>>  extractData(String core, String q, String fq,String extractColumn) {
        List<Map<String,Object>> resultList = new ArrayList<>();
        String[] arr = core.split(";");
        String solrCore = arr[0];
        String table = arr[1];
        //组装提取的列
        String basicFl = "";
        String dFl = "";
        String[] columnArr = extractColumn.split(";");
        if(null != columnArr){
            for(int i = 0;i < columnArr.length; i++){
                if (columnArr[i].contains("basic=")) {
                    basicFl = columnArr[i].split("=")[1];
                } else if (columnArr[i].contains("d=")) {
                    dFl = columnArr[i].split("=")[1];
                }
            }
        }
        List<String> rowkeys = new ArrayList<>();
        rowkeys = getRowkeys(solrCore,q,fq);
        if(CollectionUtils.isEmpty(rowkeys)){
            return resultList;
        }
        long start = System.currentTimeMillis();
        String logTitle = "get data from hbase";
        TimeUtil.start(logger, logTitle, start);
        Result[] resultArr = hBaseHelper.getResultList(table,rowkeys,basicFl,dFl);
        for(int i = 0; i < resultArr.length; i++){
            List<Cell> ceList = resultArr[i].listCells();
            if(CollectionUtils.isEmpty(ceList)){
                continue;
            }
            Map<String, Object> map = new HashMap();
            map.put("rowkey",rowkeys.get(i));
            Iterator var5 = ceList.iterator();
            while(var5.hasNext()) {
                Cell cell = (Cell)var5.next();
                map.put(Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()), Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
            }
            resultList.add(map);
        }
        TimeUtil.finish(logger, logTitle, start, System.currentTimeMillis());
        logger.info("hbase data counts:" + resultList.size());
        return resultList;
    }
    public List<String> getRowkeys(String core, String q, String fq) {
        List<String> rowkeyList = new ArrayList<>();
        long count = 0;
        try {
            count = solrHelper.count(core, q);
            String[] fqs = {fq};
            rowkeyList = getRowkeysFromSolr(core, q, fqs, "rowkey",0, count);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("get solr query error");
        }
        return rowkeyList;
    }
    /**
     * 从solr中获取rowkey
     * @param core
     * @param q
     * @param fq
     * @param start
     * @param rows
     * @return
     */
    public List<String> getRowkeysFromSolr(String core, String q, String[] fq, String fl,long start, long rows){
        List<String> rowkeyList = new ArrayList<>();
        SolrDocumentList solrDocumentList = null;
        String logTitle = "get rowkeys from solr";
        long startTime = System.currentTimeMillis();
        TimeUtil.start(logger, logTitle, startTime);
        try {
            solrDocumentList = solrHelper.queryfl(core,q,fq,null,fl,start,rows);
        } catch (Exception e) {
            e.printStackTrace();
        }
        long finish = System.currentTimeMillis();
        TimeUtil.finish(logger, logTitle, startTime, finish);
        logger.info("rowkeys counts:" + solrDocumentList.size());
        solrDocumentList.forEach(
                document -> {
                    rowkeyList.add(document.get("rowkey").toString());
                }
        );
        return rowkeyList;
    }
}

+ 39 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/MutilThreadMysqlExtracter.java

@ -0,0 +1,39 @@
package com.yihu.wlyy.figure.label.extract;
import com.yihu.wlyy.figure.label.model.DataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
/**
 * @Author lith 2018/03/23
 * 多线程分页查询mysql数据,因为mysql数据量比较大的时候,会比较慢
 */
public class MutilThreadMysqlExtracter implements Callable {
    private Logger logger = LoggerFactory.getLogger(MysqlExtracter.class);
    @Autowired
    private JdbcTemplate jdbcTemplate;
    private String sql;
    public MutilThreadMysqlExtracter(JdbcTemplate jdbcTemplate,String sql){
        this.jdbcTemplate = jdbcTemplate;
        this.sql = sql;
    }
    @Override
    public Object call() throws Exception {
        List<DataModel> datas = jdbcTemplate.query(sql,new BeanPropertyRowMapper(DataModel.class));
        logger.info("job get data counts:" + datas.size());
        return datas;
    }
}

+ 52 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/MutilThreadSearchSolrIndexExtracter.java

@ -0,0 +1,52 @@
package com.yihu.wlyy.figure.label.extract;
import com.yihu.base.SolrHelper;
import com.yihu.wlyy.figure.label.model.DataModel;
import org.apache.solr.common.SolrDocumentList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
/**
 * @Author lith 2018/03/23
 * 多线程分页查询mysql数据,因为mysql数据量比较大的时候,会比较慢
 */
public class MutilThreadSearchSolrIndexExtracter implements Callable {
    private Logger logger = LoggerFactory.getLogger(MysqlExtracter.class);
    private SolrHelper solrHelper;
    private String core;
    private String q;
    private String[] fq;
    private long start;
    private long rows;
    public MutilThreadSearchSolrIndexExtracter(SolrHelper solrHelper,String core,String q,String fq,long start,long rows){
        this.solrHelper = solrHelper;
        this.core = core;
        this.q = q;
        this.start = start;
        this.rows = rows;
    }
    @Override
    public Object call() throws Exception {
        List<String> rowkeyList = new ArrayList<>();
        SolrDocumentList solrDocumentList = solrHelper.queryfl(core,q,fq,null,"rowkey",start,rows);
        logger.info("job get data counts:" + solrDocumentList.size());
        solrDocumentList.forEach(
                document -> {
                    rowkeyList.add(document.get("rowkey").toString());
                }
        );
        return rowkeyList;
    }
}

+ 137 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/MysqlExtracter.java

@ -0,0 +1,137 @@
package com.yihu.wlyy.figure.label.extract;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.util.TimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
/**
 * @author lith on 2018.03.14 -- Created by chenweida on 2018/3/7.
 * mysql数据抽取器
 */
@Component
public class MysqlExtracter implements Extracter {
    private Logger logger = LoggerFactory.getLogger(MysqlExtracter.class);
    private ExecutorService threadPoolService = Executors.newCachedThreadPool();
    private int numPerPage = 100000; //一次性最多查询10万条
    private Map<String,JdbcTemplate> templateMap = new HashMap<>();
    @Autowired
    @Qualifier("jdbcTemplate")
    private JdbcTemplate wlyydefaultJdbcTemplate;
    @Autowired
    @Qualifier("healtharchiveTemplate")
    private JdbcTemplate healtharchiveTemplate;
    @Autowired
    @Qualifier("wlyy85Template")
    private JdbcTemplate wlyy85Template;
    @PostConstruct
    public void initTemplateMap(){
        templateMap.put("wlyy",wlyydefaultJdbcTemplate);
        templateMap.put("healtharchive",healtharchiveTemplate);
        templateMap.put("wlyy85",wlyy85Template);
    }
    @Override
    public List<DataModel> extractData(String sql, String datasource) {
        return null;
    }
    public List<DataModel> extractData(String sql,String countSql,String datasource) {
        if(StringUtils.isEmpty(countSql)){
            return null;
        }
        JdbcTemplate jdbcTemplate = null;
        // 默认的
        if(StringUtils.isEmpty(datasource)){
            jdbcTemplate = templateMap.get("wlyy");
            return  getDataByThread(sql,countSql,jdbcTemplate);
        }
        String [] arr = datasource.split("-");
        if(null == arr || arr.length <= 1){
            logger.error("invalid datasource format,check in fl_job_config: "+ datasource);
            return null;
        }
        jdbcTemplate = templateMap.get(arr[1]);
        if(null == jdbcTemplate){
            logger.error("datasource not exist,check in fl_job_config: "+ datasource);
            return null;
        }
        return  getDataByThread(sql,countSql,jdbcTemplate);
    }
    /**
     * 根据数据量采用多线程分页查询数据
     * @param sql
     * @return
     */
    public List<DataModel> getDataByThread(String sql,String countSql,JdbcTemplate jdbcTemplate){
        List<DataModel> datas = new ArrayList<>();
        int size = 0;
        // 统计出有多少条数据
        size = jdbcTemplate.queryForObject(countSql, Integer.class);
        logger.info("data count:" + size);
        int number = size / numPerPage + 1;
        List<Callable<List<DataModel>>> threadList = new ArrayList<>();
        // 计时
        long start = System.currentTimeMillis();
        String logTitle = "therad get data";
        TimeUtil.start(logger,logTitle,start);
        // 循环,拼凑分页sql
        try {
            for (int i = 0; i < number; i++) {
                StringBuilder limitSql = new StringBuilder();
                if(sql.contains("limitNumber") && i == 0){
                    String replacedSql = sql.replace("limitNumber",String.valueOf(1));
                    limitSql.append(replacedSql);
                }else if(sql.contains("limitNumber") && number > 1 && i > 0){
                    String replacedSql = sql.replace("limitNumber",String.valueOf(i * numPerPage));
                    limitSql.append(replacedSql);
                }else{
                    limitSql.append(sql);
                }
                limitSql.append(" limit ")
                        .append(numPerPage);
                MutilThreadMysqlExtracter mutilThreadMysqlExtracter = new MutilThreadMysqlExtracter(jdbcTemplate, limitSql.toString());
                threadList.add(mutilThreadMysqlExtracter);
//                Future<List<DataModel>> future = threadPoolService.submit(mutilThreadMysqlExtracter);
//                datas.addAll(future.get());
            }
            List<Future<List<DataModel>>> futureList = threadPoolService.invokeAll(threadList);
            for(Future<List<DataModel>> future : futureList){
                datas.addAll(future.get());
            }
            TimeUtil.finish(logger,logTitle,start,System.currentTimeMillis());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("MutilThreadConvert call failed!");
        }
        return datas;
    }
}

+ 155 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Es2EsJob.java

@ -0,0 +1,155 @@
package com.yihu.wlyy.figure.label.job;
import com.yihu.wlyy.figure.label.constant.BusinessConstant;
import com.yihu.wlyy.figure.label.controller.JobController;
import com.yihu.wlyy.figure.label.convert.ConvertHelper;
import com.yihu.wlyy.figure.label.dao.FlJobConfigDao;
import com.yihu.wlyy.figure.label.dao.FlLabelDictJobDao;
import com.yihu.wlyy.figure.label.entity.FlJobConfig;
import com.yihu.wlyy.figure.label.entity.FlLabelDictJob;
import com.yihu.wlyy.figure.label.enums.JobSqlFieldTypeEnum;
import com.yihu.wlyy.figure.label.extract.ESExtracter;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.service.JobService;
import com.yihu.wlyy.figure.label.storage.Store2ES;
import com.yihu.wlyy.figure.label.util.TimeUtil;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
@Service
@Scope("prototype")
@DisallowConcurrentExecution//防止到了执行时间点前一任务还在执行中,但是这时有空闲的线程,那么马上又会执行,这样一来就会存在同一job被并行执行
public class Es2EsJob implements Job {
    private Logger logger = LoggerFactory.getLogger(JobController.class);
    @Autowired
    private FlJobConfigDao flJobConfigDao;
    @Autowired
    private FlLabelDictJobDao flLabelDictJobDao;
    @Autowired
    private ESExtracter esExtracter;
    @Autowired
    private ConvertHelper convertHelper;
    @Autowired
    Store2ES store2ES;
    @Autowired
    private JobService jobService;
    private FlJobConfig flJobConfig;
    private Long flJobConfigId;
    private String sqlFiledValue;
    private String sqlFiledCondition;
    private String finalSql;
    private List<DataModel> dataModelList;
    private String sourceType;
    private String source;
    /**
     * 数据表的id,有些数据是按时间增量查询,有些数据是按表的主键id增量查询
     */
    private long lastDataId;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap paramsMap = context.getJobDetail().getJobDataMap();
        initParams(paramsMap);
        //提取数据
        extract();
        //数据转换
        //数据转换
        List<SaveModel> list = convert();
        //转换后的结果
        if (!CollectionUtils.isEmpty(list)) {
            //数据保存
            boolean bool = save(list);
            //增量存储成功后,修改增量的czrq时间为当前时间或主键id为上次获取到的数据的最后的一条的id
            if (StringUtils.endsWithIgnoreCase(this.flJobConfig.getSqlFieldType().toString(), JobSqlFieldTypeEnum.TIME.toString())) {
                jobService.updateFieldValuetoCurrentTimeOrId(this.flJobConfigId, null, bool);
            } else if (StringUtils.endsWithIgnoreCase(this.flJobConfig.getSqlFieldType().toString(), JobSqlFieldTypeEnum.NUM.toString())) {
                int index = dataModelList.size();
                lastDataId = dataModelList.get(index - 1).getId();
                jobService.updateFieldValuetoCurrentTimeOrId(this.flJobConfigId, this.lastDataId, bool);
            }
        }
    }
    public void initParams(JobDataMap paramsMap){
        this.flJobConfigId = (Long)paramsMap.get("jobConfig");
        this.sourceType = String.valueOf(paramsMap.get("sourceType"));
        this.source = String.valueOf(paramsMap.get("source"));
        this.flJobConfig = flJobConfigDao.findById(this.flJobConfigId);
        this.sqlFiledValue = flJobConfig.getSqlFieldValue();
        this.sqlFiledCondition = paramsMap.getString(BusinessConstant.SQLFIELDCONDITION);
        //没有传增量值,以数据库配置的默认值为查询条件
        if(org.springframework.util.StringUtils.isEmpty(this.sqlFiledValue)){
            this.sqlFiledValue = this.flJobConfig.getSqlFieldValue();
            this.sqlFiledCondition= BusinessConstant.gt;
        }
        //1抽取数据
        String sql = this.flJobConfig.getQuery_sql();
        String sqlFiled = this.flJobConfig.getSqlField();
        this.finalSql = sql + " where " + sqlFiled + BusinessConstant.gt + "'" + TimeUtil.toEsTime(flJobConfig.getSqlFieldValue()) + "'";
    }
    /**
     * 提取数据,按数据库中配置的增量条件提取
     */
    public void extract(){
        this.dataModelList = esExtracter.extractData(this.finalSql,"");
    }
    /**
     * 转换
     */
    public List<SaveModel> convert(){
        List<SaveModel> list = new ArrayList<>();
        FlLabelDictJob flLabelDictJob = flLabelDictJobDao.findByJobId(this.flJobConfigId);
        try {
            list = convertHelper.convert(this.dataModelList, null,flLabelDictJob,this.sourceType,this.source);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return list;
    }
    /**
     * 保存
     * @param list
     */
    public boolean save(List<SaveModel> list){
        boolean bool = true;
        try {
            store2ES.save(list);
        }catch (Exception e){
            logger.error("save to elasticsearch failed,convet data count:" + list.size());
            bool = false;
        }
        return bool;
    }
}

+ 171 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Hbase2ESJob.java

@ -0,0 +1,171 @@
package com.yihu.wlyy.figure.label.job;
import com.yihu.wlyy.figure.label.controller.JobController;
import com.yihu.wlyy.figure.label.convert.ConvertHelper;
import com.yihu.wlyy.figure.label.dao.FlJobConfigDao;
import com.yihu.wlyy.figure.label.dao.FlLabelDictJobDao;
import com.yihu.wlyy.figure.label.entity.FlJobConfig;
import com.yihu.wlyy.figure.label.entity.FlLabelDictJob;
import com.yihu.wlyy.figure.label.enums.JobSqlFieldTypeEnum;
import com.yihu.wlyy.figure.label.extract.HbaseExtracter;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.service.JobService;
import com.yihu.wlyy.figure.label.storage.Store2ES;
import com.yihu.wlyy.figure.label.util.TimeUtil;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * Created by chenweida on 2018/3/7.
 */
//@Component
@Service
@Scope("prototype")
@DisallowConcurrentExecution//防止到了执行时间点前一任务还在执行中,但是这时有空闲的线程,那么马上又会执行,这样一来就会存在同一job被并行执行
public class Hbase2ESJob implements Job {
    private Logger logger = LoggerFactory.getLogger(JobController.class);
    @Autowired
    private FlJobConfigDao flJobConfigDao;
    @Autowired
    private FlLabelDictJobDao flLabelDictJobDao;
    @Autowired
    private ConvertHelper convertHelper;
    @Autowired HbaseExtracter hbaseExtracter;
    @Autowired
    Store2ES store2ES;
    @Autowired
    private JobService jobService;
    private FlJobConfig flJobConfig;
    private Long flJobConfigId;
    private String sqlFiledValue;
    private String sqlFiledCondition;
    private List<Map<String,Object>> datas;
    private String sourceType;
    private String source;
    private String datasource;
    private String q;
    private String fq;
    private String extractColumn;
    /**
     * 数据表的id,有些数据是按时间增量查询,有些数据是按表的主键id增量查询
     */
    private long lastDataId;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap paramsMap = context.getJobDetail().getJobDataMap();
        initParams(paramsMap);
        //根据obconfig里配置的sql提取数据
        extract();
        //数据转换
        List<SaveModel> list = convert();
        //转换后的结果
        if (!CollectionUtils.isEmpty(list)) {
            //数据保存
            boolean bool = save(list);
            //增量存储成功后,修改增量的czrq时间为当前时间或主键id为上次获取到的数据的最后的一条的id
            if(StringUtils.endsWithIgnoreCase(this.flJobConfig.getSqlFieldType().toString(), JobSqlFieldTypeEnum.TIME.toString())){
                jobService.updateFieldValuetoCurrentTimeOrId(this.flJobConfigId,null,bool);
            }else if(StringUtils.endsWithIgnoreCase(this.flJobConfig.getSqlFieldType().toString(), JobSqlFieldTypeEnum.NUM.toString())){
                int size = datas.size();
                DataModel dataModel = (DataModel)datas.get(size -1);
                lastDataId = dataModel.getId();
                jobService.updateFieldValuetoCurrentTimeOrId(this.flJobConfigId,this.lastDataId,bool);
            }
        }
    }
    public void initParams(JobDataMap paramsMap){
        this.flJobConfigId = (Long)paramsMap.get("jobConfig");
        this.sourceType = String.valueOf(paramsMap.get("sourceType"));
        this.source = String.valueOf(paramsMap.get("source"));
        this.flJobConfig = flJobConfigDao.findById(this.flJobConfigId);
        this.datasource = flJobConfig.getDatasource();
        this.sqlFiledCondition = paramsMap.getString("sqlFiledCondition");
        this.sqlFiledValue = flJobConfig.getSqlFieldValue();
        //没有传增量值,以数据库配置的默认值为查询条件
        if(StringUtils.isEmpty(this.sqlFiledValue)){
            this.sqlFiledValue = this.flJobConfig.getSqlFieldValue();
            this.sqlFiledCondition=">";
        }
        //1抽取数据
        this.q = this.flJobConfig.getQuery_sql();
        fq = this.flJobConfig.getSqlField() + ":" + "[" + TimeUtil.toSolrTime(this.sqlFiledValue) +" TO *]";
        //要从hbase中查询的列
        this.extractColumn = this.flJobConfig.getExtractField();
    }
    /**
     * 提取数据,按数据库中配置的增量条件提取
     */
    public void extract(){
        this.datas = hbaseExtracter.extractData(this.datasource,this.q,this.fq,this.extractColumn);
    }
    /**
     * 转换
     */
    public List<SaveModel> convert(){
        List<SaveModel> list = new ArrayList<>();
        FlLabelDictJob flLabelDictJob = flLabelDictJobDao.findByJobId(this.flJobConfigId);
        try {
            list = convertHelper.convert(null,this.datas, flLabelDictJob,this.sourceType,this.source);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return list;
    }
    /**
     * 保存
     * @param list
     */
    public boolean save(List<SaveModel> list){
        boolean bool = true;
        try {
            store2ES.save(list);
        }catch (Exception e){
            logger.error("save to elasticsearch failed,convet data count:" + list.size());
            bool = false;
        }
        return bool;
    }
}

+ 239 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Mysql2ESJob.java

@ -0,0 +1,239 @@
package com.yihu.wlyy.figure.label.job;
import com.yihu.wlyy.figure.label.constant.BusinessConstant;
import com.yihu.wlyy.figure.label.controller.JobController;
import com.yihu.wlyy.figure.label.convert.ConvertHelper;
import com.yihu.wlyy.figure.label.dao.FlJobConfigDao;
import com.yihu.wlyy.figure.label.dao.FlLabelDictJobDao;
import com.yihu.wlyy.figure.label.entity.FlJobConfig;
import com.yihu.wlyy.figure.label.entity.FlLabelDictJob;
import com.yihu.wlyy.figure.label.enums.JobSqlFieldTypeEnum;
import com.yihu.wlyy.figure.label.extract.MysqlExtracter;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.service.JobService;
import com.yihu.wlyy.figure.label.storage.Store2ES;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by chenweida on 2018/3/7.
 */
//@Component
@Service
@Scope("prototype")
@DisallowConcurrentExecution//防止到了执行时间点前一任务还在执行中,但是这时有空闲的线程,那么马上又会执行,这样一来就会存在同一job被并行执行
public class Mysql2ESJob implements Job {
    private Logger logger = LoggerFactory.getLogger(JobController.class);
    @Autowired
    private FlJobConfigDao flJobConfigDao;
    @Autowired
    private FlLabelDictJobDao flLabelDictJobDao;
    @Autowired
    private MysqlExtracter mysqlExtracter;
    @Autowired
    private ConvertHelper convertHelper;
    @Autowired
    Store2ES store2ES;
    @Autowired
    private JobService jobService;
    private FlJobConfig flJobConfig;
    private Long flJobConfigId;
    private String sqlFieldValue;
    private String sqlFieldCondition;
    private String finalSql;
    private String countSql;
    private List<DataModel> dataModelList;
    private String sourceType;
    private String source;
    private String datasource;
    /**
     * 数据表的id,有些数据是按时间增量查询,有些数据是按表的主键id增量查询
     */
    private long lastDataId;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap paramsMap = context.getJobDetail().getJobDataMap();
        initParams(paramsMap);
        //根据obconfig里配置的sql提取数据
        extract();
        //数据转换
        List<SaveModel> list = convert();
        //转换后的结果
        if (!CollectionUtils.isEmpty(list)) {
            //数据保存
            boolean bool = save(list);
            //增量存储成功后,修改增量的czrq时间为当前时间或主键id为上次获取到的数据的最后的一条的id
            if(StringUtils.endsWithIgnoreCase(this.flJobConfig.getSqlFieldType().toString(), JobSqlFieldTypeEnum.TIME.toString())){
                jobService.updateFieldValuetoCurrentTimeOrId(this.flJobConfigId,null,bool);
            }else if(StringUtils.endsWithIgnoreCase(this.flJobConfig.getSqlFieldType().toString(), JobSqlFieldTypeEnum.NUM.toString())){
                int index = dataModelList.size();
                lastDataId = dataModelList.get(index -1).getId();
                jobService.updateFieldValuetoCurrentTimeOrId(this.flJobConfigId,this.lastDataId,bool);
            }
        }
    }
    public void initParams(JobDataMap paramsMap){
        this.flJobConfigId = (Long)paramsMap.get("jobConfig");
        this.flJobConfig = flJobConfigDao.findById(this.flJobConfigId);
        this.sourceType = flJobConfig.getSourceType();
        this.source = flJobConfig.getSource();
        this.datasource = flJobConfig.getDatasource();
        this.sqlFieldCondition = paramsMap.getString(BusinessConstant.SQLFIELDCONDITION);
        this.sqlFieldValue = flJobConfig.getSqlFieldValue();
        //没有传增量值,以数据库配置的默认值为查询条件
        if(StringUtils.isEmpty(this.sqlFieldValue)){
            this.sqlFieldValue = this.flJobConfig.getSqlFieldValue();
            this.sqlFieldCondition =">";
        }
        //1抽取数据
        String sql = this.flJobConfig.getQuery_sql();
        String sqlFiled = this.flJobConfig.getSqlField();
        this.finalSql = getFinalSql(sql,sqlFiled,sqlFieldValue);
        this.countSql = getTotalCountSql(flJobConfig.getCountSql(),sqlFiled, sqlFieldValue);
    }
    /**
     * 提取数据,按数据库中配置的增量条件提取
     */
    public void extract(){
        this.dataModelList = mysqlExtracter.extractData(this.finalSql,this.countSql,this.datasource);
    }
    /**
     * 转换
     */
    public List<SaveModel> convert(){
        List<SaveModel> list = new ArrayList<>();
        FlLabelDictJob flLabelDictJob = flLabelDictJobDao.findByJobId(this.flJobConfigId);
        try {
            list = convertHelper.convert(this.dataModelList, null,flLabelDictJob,this.sourceType,this.source);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return list;
    }
    /**
     * 保存
     * @param list
     */
    public boolean save(List<SaveModel> list){
        boolean bool = true;
        try {
            store2ES.save(list);
        }catch (Exception e){
            logger.error("save to elasticsearch failed,convet data count:" + list.size());
            bool = false;
        }
        return bool;
    }
    /**
     * 拼凑获取增量数据的sql
     * @param sql
     * @param sqlFiledValue
     * @return
     */
    public String getJobConfigSql(String sql,String sqlFiled,String sqlFiledCondition,String sqlFiledValue){
        StringBuilder result = new StringBuilder();
        result.append(sql).append(" ");
        if(StringUtils.isEmpty(sqlFiledCondition)){
            return result.toString();
        }
        String[] sqlFiledConditionStr = {};
        if (sqlFiledCondition.contains(",")){
            sqlFiledConditionStr = sqlFiledCondition.split(",");
        }
        StringBuffer sqlFiledString = new StringBuffer();
        if (sqlFiledConditionStr.length>0 && sqlFiledValue.contains(",")){
            String[] sqlFiledValues = sqlFiledValue.split(",");
            sqlFiledString.append(sqlFiled).append(sqlFiledConditionStr[0]).append("\'"+sqlFiledValues[0]+"\'").append(" and ").append(sqlFiled).append(sqlFiledConditionStr[1]).append("\'"+sqlFiledValues[1]+"\'");
        }else{
            sqlFiledString.append(sqlFiled).append(sqlFiledCondition).append("\'"+sqlFiledValue+"\'");
        }
        if (sql.contains("where") &&  !sql.contains("$")) {
            result.append(" and ").append(sqlFiledString.toString());
        }else if (sql.contains("$")){
            StringBuffer otherCondition = new StringBuffer();
            if (sql.contains("where")){
                otherCondition.append(" and ").append(sqlFiledString.toString());
            }else{
                otherCondition.append(" where ").append(sqlFiledString.toString());
            }
            result.replace(result.indexOf("$"),result.indexOf("$")+1,otherCondition.toString());
        }else {
            result.append(" where ").append(sqlFiledString.toString());
        }
        return result.toString();
    }
    /**
     * 最终执行获取数据的sql,替换增量字段为具体值
     * @param sql
     * @param sqlfield
     * @param sqlfieldValue
     * @return
     */
    public String getFinalSql(String sql, String sqlfield, String sqlfieldValue) {
        String firstReplaceSql = sql.replace(BusinessConstant.sql_field_str,sqlfield);
        String result = firstReplaceSql.replace(BusinessConstant.sql_field_value_str,sqlfieldValue);
        return result.toString();
    }
    /**
     * 统计增量数据的条数
     * @param countSql
     * @param sqlfield
     * @param sqlfieldValue
     * @return
     */
    public String getTotalCountSql(String countSql, String sqlfield, String sqlfieldValue) {
        if(StringUtils.isEmpty(countSql)){
            logger.error("countSql is null,job_config id = :" + this.flJobConfigId);
            return "";
        }
       String firstReplaceSql = countSql.replace(BusinessConstant.sql_field_str,sqlfield);
       String result = firstReplaceSql.replace(BusinessConstant.sql_field_value_str,sqlfieldValue);
        return result.toString();
    }
}

+ 248 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/model/DataModel.java

@ -0,0 +1,248 @@
package com.yihu.wlyy.figure.label.model;
/**
 * jboConfig配置里sql查询出的数据
 */
public class DataModel {
    /**
     * 这些id用作记录数据来源,当有多个表时,记录多个表的id,并依据fl_job_config里的sourceTyep,source来区别
     */
    private Integer id;
    private Integer id1;
    private Integer id2;
    private Integer id3;
    private Integer id4;
    /**
     * 有些表的id为uuid,是string类型,所以为了兼容所有的,此种类型id命名为idstr,进行数据抽取时需多注意
     */
    private String idstr;
    private String idstr1;
    private String idstr2;
    /**
     * 居民身份证号
     */
    private String idcard;
    /**
     * 父类标签码
     */
    private String parentCode;
    /**
     * 父类标签名
     */
    private String parentName;
    /**
     * 标签码
     */
    private String labelCode;
    /**
     * 标签名
     */
    private String labelName;
    /**
     * 标签值,某个单独的值,如及时回复中的问题id
     */
    private String labelValue;
    /**
     * 转换类
     */
    private String convertClazz;
    /**
     * 定时任务的表id
     */
    private String jobId;
    /**
     * 原数据来源时间
     */
    private String sourceTime;
    /**
     * 代预约的医生姓名
     */
    private String doctor;
    /**
     * 健康教育文章一级类别名称
     */
    private String firstLevelCategoryName;
    /**
     * 健康教育文章二级类别名称
     */
    private String secondLevelCategoryName;
    /**
     * 健康教育文章推送人名称
     */
    private String sendName;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public Integer getId1() {
        return id1;
    }
    public void setId1(Integer id1) {
        this.id1 = id1;
    }
    public Integer getId2() {
        return id2;
    }
    public void setId2(Integer id2) {
        this.id2 = id2;
    }
    public Integer getId3() {
        return id3;
    }
    public void setId3(Integer id3) {
        this.id3 = id3;
    }
    public Integer getId4() {
        return id4;
    }
    public void setId4(Integer id4) {
        this.id4 = id4;
    }
    public String getIdstr() {
        return idstr;
    }
    public void setIdstr(String idstr) {
        this.idstr = idstr;
    }
    public String getIdstr1() {
        return idstr1;
    }
    public void setIdstr1(String idstr1) {
        this.idstr1 = idstr1;
    }
    public String getIdstr2() {
        return idstr2;
    }
    public void setIdstr2(String idstr2) {
        this.idstr2 = idstr2;
    }
    public String getIdcard() {
        return idcard;
    }
    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }
    public String getParentCode() {
        return parentCode;
    }
    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }
    public String getParentName() {
        return parentName;
    }
    public void setParentName(String parentName) {
        this.parentName = parentName;
    }
    public String getLabelName() {
        return labelName;
    }
    public void setLabelName(String labelName) {
        this.labelName = labelName;
    }
    public String getLabelCode() {
        return labelCode;
    }
    public void setLabelCode(String labelCode) {
        this.labelCode = labelCode;
    }
    public String getConvertClazz() {
        return convertClazz;
    }
    public void setConvertClazz(String convertClazz) {
        this.convertClazz = convertClazz;
    }
    public String getJobId() {
        return jobId;
    }
    public void setJobId(String jobId) {
        this.jobId = jobId;
    }
    public String getSourceTime() {
        return sourceTime;
    }
    public void setSourceTime(String sourceTime) {
        this.sourceTime = sourceTime;
    }
    public String getLabelValue() {
        return labelValue;
    }
    public void setLabelValue(String labelValue) {
        this.labelValue = labelValue;
    }
    public String getDoctor() {
        return doctor;
    }
    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }
    public String getFirstLevelCategoryName() {
        return firstLevelCategoryName;
    }
    public void setFirstLevelCategoryName(String firstLevelCategoryName) {
        this.firstLevelCategoryName = firstLevelCategoryName;
    }
    public String getSecondLevelCategoryName() {
        return secondLevelCategoryName;
    }
    public void setSecondLevelCategoryName(String secondLevelCategoryName) {
        this.secondLevelCategoryName = secondLevelCategoryName;
    }
    public String getSendName() {
        return sendName;
    }
    public void setSendName(String sendName) {
        this.sendName = sendName;
    }
}

+ 170 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/model/SaveModel.java

@ -0,0 +1,170 @@
package com.yihu.wlyy.figure.label.model;
import io.searchbox.annotations.JestId;
import java.io.Serializable;
/**
 * Created by chenweida on 2018/3/7.
 */
public class SaveModel implements Serializable{
    @JestId
    /**
     * 存入elasticsearch的id由 idcard,parentCode,labelName,labelCode MD5加密而成。不用es自动生成的_id,实现数据插入排重
     */
    private String id;
    /**
     * 身份证
     */
    private String idcard;
    /**
     * 标签字典码
     */
    private String dictCode;
    /**
     * 标签类型
     */
    private String labelType;
    /**
     * 标签code
     */
    private String labelCode;
    /**
     * 标签名称
     */
    private String labelName;
    /**
     * 标签值,仅当标签只有一个分类的时候才有此值,比如生日,体重等
     */
    private String labelValue;
    /**
     * 创建时间
     */
    private String createTime;
    /**
     * 当前标签是否激活
     */
    /**
     * 标签生成来源
     */
    private String source;
    /**
     * 标签源数据来源时间
     */
    private String sourceTime;
    /**
     * 代预约的医生姓名
     */
    private String doctor;
    /**
     * 健康教育文章推送人名称
     */
    private String sendName;
    public String getIdcard() {
        return idcard;
    }
    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }
    public String getLabelType() {
        return labelType;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getDictCode() {
        return dictCode;
    }
    public void setDictCode(String dictCode) {
        this.dictCode = dictCode;
    }
    public void setLabelType(String labelType) {
        this.labelType = labelType;
    }
    public String getLabelCode() {
        return labelCode;
    }
    public void setLabelCode(String labelCode) {
        this.labelCode = labelCode;
    }
    public String getLabelName() {
        return labelName;
    }
    public void setLabelName(String labelName) {
        this.labelName = labelName;
    }
    public String getLabelValue() {
        return labelValue;
    }
    public void setLabelValue(String labelValue) {
        this.labelValue = labelValue;
    }
    public String getCreateTime() {
        return createTime;
    }
    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }
    public String getSource() {
        return source;
    }
    public void setSource(String source) {
        this.source = source;
    }
    public String getSourceTime() {
        return sourceTime;
    }
    public void setSourceTime(String sourceTime) {
        this.sourceTime = sourceTime;
    }
    public String getDoctor() {
        return doctor;
    }
    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }
    public String getSendName() {
        return sendName;
    }
    public void setSendName(String sendName) {
        this.sendName = sendName;
    }
}

+ 100 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/search/controller/SearchController.java

@ -0,0 +1,100 @@
package com.yihu.wlyy.figure.label.search.controller;
import com.yihu.wlyy.figure.label.controller.JobController;
import com.yihu.wlyy.figure.label.search.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static sun.management.Agent.error;
/**
 * @author litaohong on 2018/5/17
 * @project patient-co-management
 */
@RestController
@RequestMapping(value = "/label", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "标签查询控制器")
public class SearchController {
    private Logger logger = LoggerFactory.getLogger(JobController.class);
    @Autowired
    private SearchService searchService;
    /**
     * @param idcard
     * @return
     */
    @ApiOperation(value = "根据idcard查询基本信息标签")
    @RequestMapping(value = "searchBaseInfo", method = RequestMethod.GET)
    public String searchBaseInfo(
            @ApiParam(name = "idcard", value = "身份证号", required = true)@RequestParam(value = "idcard", required = true) String idcard) {
        try {
            return searchService.getBaseInfo(idcard).toJSONString();
        } catch (Exception e) {
            error(e);
            return "error";
        }
    }
    /**
     * @param idcard
     * @return
     */
    @ApiOperation(value = "根据idcard查询病种信息标签")
    @RequestMapping(value = "searchDieaseInfo", method = RequestMethod.GET)
    public String searchDieaseInfo(
            @ApiParam(name = "idcard", value = "身份证号", required = true)@RequestParam(value = "idcard", required = true) String idcard) {
        try {
            return searchService.getDiseaseInfo(idcard).toJSONString();
        } catch (Exception e) {
            error(e);
            return "error";
        }
    }
    /**
     * @param idcard
     * @return
     */
    @ApiOperation(value = "根据idcard查询代预约情况")
    @RequestMapping(value = "searchAppointmentInfo", method = RequestMethod.GET)
    public String searchAppointmentInfo(
            @ApiParam(name = "idcard", value = "身份证号", required = true)@RequestParam(value = "idcard", required = true) String idcard) {
        try {
            return searchService.getAppointmentInfo(idcard).toJSONString();
        } catch (Exception e) {
            error(e);
            return "error";
        }
    }
    /**
     * @param idcard
     * @return
     */
    @ApiOperation(value = "根据idcard查询ehr基本档案信息")
    @RequestMapping(value = "searchehrbaseinfo", method = RequestMethod.GET)
    public String searchEHRRecordInfo(
            @ApiParam(name = "idcard", value = "身份证号", required = true)@RequestParam(value = "idcard", required = true) String idcard) {
        try {
            return searchService.getEHRRecordInfo(idcard);
        } catch (Exception e) {
            error(e);
            return "error";
        }
    }
}

+ 273 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/search/service/SearchService.java

@ -0,0 +1,273 @@
package com.yihu.wlyy.figure.label.search.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.base.es.config.ElastricSearchHelper;
import com.yihu.base.hbase.HBaseHelper;
import com.yihu.wlyy.figure.label.constant.BusinessConstant;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.hadoop.hbase.HbaseTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.*;
/**
 * @author litaohong on 2018/5/17
 * @project patient-co-management
 * 标签搜索服务
 */
@Service
public class SearchService {
    private Logger logger = LoggerFactory.getLogger(Service.class);
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    @Autowired
    private HBaseHelper hBaseHelper;
    @Autowired
    private HbaseTemplate hbaseTemplate;
    /**
     * 用户基本信息
     * @param idcard
     * @return
     */
    public JSONObject getBaseInfo(String idcard){
        List<Map<String, Object>> result = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        String sql = "select * from " + ConstantUtil.figure_label_es_index + "/" + ConstantUtil.figure_label_es_type + " where idcard = '" + idcard + "'" ;
        result = elastricSearchHelper.excuceSQL(sql);
        result.forEach(
                map -> {
                    if(StringUtils.endsWithIgnoreCase(String.valueOf(map.get("dictCode")),ConstantUtil.name_dict)){
                        jsonObject.put("name",String.valueOf(map.get("labelValue")));
                    }
                    if(StringUtils.endsWithIgnoreCase(String.valueOf(map.get("dictCode")),ConstantUtil.sex_dict)){
                        jsonObject.put("sex",String.valueOf(map.get("labelName")));
                    }
                    if(StringUtils.endsWithIgnoreCase(String.valueOf(map.get("dictCode")),ConstantUtil.age_dict)){
                        jsonObject.put("age",String.valueOf(map.get("labelName")));
                    }
                    if(StringUtils.endsWithIgnoreCase(String.valueOf(map.get("dictCode")),ConstantUtil.birth_dict)){
                        jsonObject.put("birth",String.valueOf(map.get("labelValue")));
                    }
                    if(StringUtils.endsWithIgnoreCase(String.valueOf(map.get("dictCode")),ConstantUtil.height_dict)){
                        String height = String.valueOf(map.get("labelName")) + String.valueOf(map.get("labelValue"));
                        jsonObject.put("height",height);
                    }
                    if(StringUtils.endsWithIgnoreCase(String.valueOf(map.get("dictCode")),ConstantUtil.weight_dict)){
                        String weight = String.valueOf(map.get("labelName")) + String.valueOf(map.get("labelValue"));
                        jsonObject.put("weight",weight);
                    }
                }
        );
        if(null == jsonObject.get("name")){
            jsonObject.put("name","");
        }
        if(null == jsonObject.get("sex")){
            jsonObject.put("sex","");
        }
        if(null == jsonObject.get("age")){
            jsonObject.put("age","");
        }
        if(null == jsonObject.get("birth")){
            jsonObject.put("birth","");
        }
        if(null == jsonObject.get("height")){
            jsonObject.put("height","");
        }
        if(null == jsonObject.get("weight")){
            jsonObject.put("weight","");
        }
        return jsonObject;
    }
    /**
     * 用户病种信息
     * @param idcard
     * @return
     */
    public JSONObject getDiseaseInfo(String idcard) {
        JSONObject jsonObject = new JSONObject();
        String sql = "select * from " + ConstantUtil.figure_label_es_index + "/" + ConstantUtil.figure_label_es_type + " where idcard = '" + idcard + "' and dictCode in ('" + ConstantUtil.ICD10_dict + "','" + ConstantUtil.health_problem_dict + "')";
        List<Map<String, Object>> result = elastricSearchHelper.excuceSQL(sql);
        Set<String> set = new HashSet<>();
        result.forEach(
                map -> {
                    if (!StringUtils.isEmpty(map.get("labelValue"))) {
                        set.add(map.get("labelValue").toString());
                    }
                });
        jsonObject.put("label",set);
        return jsonObject;
    }
    /**
     * 用户就诊记录
     * @param idcard
     * @return
     */
    public JSONObject getAppointmentInfo(String idcard) {
        JSONObject result = new JSONObject();
        result.put("idcard",idcard);
        StringBuilder sqlBuilder = new StringBuilder();
        String sql = "select * from " + ConstantUtil.figure_label_es_index + "/" + ConstantUtil.figure_label_es_type + " where idcard = '" + idcard + "' and dictCode = '" + ConstantUtil.online_appoinment_dict + "',";
        List<Map<String, Object>> list = elastricSearchHelper.excuceSQL(sql);
        JSONArray jsonArray = new JSONArray();
        list.forEach(
                map -> {
                    //如果有医生姓名,表示是医生代预约
                    if(null == map.get("doctor")){
                            return;
                    }
                    JSONObject jsonObject = new JSONObject();
                    String labelName = String.valueOf(map.get("labelName"));
                    jsonObject.put("hospitalName", labelName.split("-")[0]);
                    jsonObject.put("deptName", labelName.split("-")[1]);
                    jsonObject.put("apponinementTime", map.get("sourceTime"));
                    jsonObject.put("doctor",map.get("doctor"));
                    jsonArray.add(jsonObject);
                }
        );
        JSONObject appoint = new JSONObject();
        appoint.put("appointdata",jsonArray);
        result.putAll(appoint);
        return result;
    }
    /**
     * 获取历史健康问题,默认获取所有
     * @param idcard
     * @param date
     * @return
     */
    public String getHistoryHealthProblem(String idcard,String date){
        JSONObject result = new JSONObject();
        StringBuilder sqlBuilder = new StringBuilder();
        String sql = "select * from " + ConstantUtil.figure_label_es_index + "/" + ConstantUtil.figure_label_es_type + " where idcard = '" + idcard + "' and dictCode = '" + ConstantUtil.health_problem_dict;
        sqlBuilder.append(sql);
        if(!StringUtils.isEmpty(date)){
            sqlBuilder.append(" and sourceTime <= '").append(date).append("'");
        }
        List<Map<String, Object>> list = elastricSearchHelper.excuceSQL(sqlBuilder.toString());
        Set<String> set = new HashSet<>();
        list.forEach(
                map -> {
                    String name = String.valueOf(map.get("labelName"));
                    if(name.contains(";")){
                        for(String str : name.split(";")){
                            set.add(str);
                        }
                    }else{
                        set.add(name);
                    }
                }
        );
        result.put("historyHealthProblem",set);
        return result.toJSONString();
    }
    /**
     * 医疗云档案查询接口(包括基本信息,疾病标签如慢病新生儿等,就诊记录信息)
     * @param idcard
     * @return
     */
    public String getEHRRecordInfo(String idcard) {
        JSONObject result = new JSONObject();
        // 基础信息标签
        JSONObject baseinfo = getBaseInfo(idcard);
        baseinfo.put("idcard",idcard);
        result.putAll(baseinfo);
        //疾病标签
        JSONObject diesase = getDiseaseInfo(idcard);
        result.putAll(diesase);
        //就诊记录标签
        JSONObject appointmentinfo = getAppointmentInfo(idcard);
        if(appointmentinfo.getJSONArray("appointdata").size() > 0){
            result.putAll(appointmentinfo);
        }
        return result.toJSONString();
    }
    /**
     * 获取健康教育文章记录
     * @return
     */
    public String getHealthArticle(String idcard){
        JSONArray jsonArray = new JSONArray();
        String sql = "select * from " + ConstantUtil.figure_label_es_index + "/" + ConstantUtil.figure_label_es_type + "where dictCode = '" + ConstantUtil.health_edu_artical_receive_dict + "' and idcard ='" + idcard + "'";
        List<Map<String, Object>> list = elastricSearchHelper.excuceSQL(sql.toString());
        list.forEach(
                map -> {
                    JSONObject result = new JSONObject();
                    // 文章标题
                    String title = String.valueOf(map.get("labelName"));
                    result.put("title",title);
                    // 文章分类标题
                    String name = String.valueOf(map.get("labelValue"));
                    if (!StringUtils.isEmpty(name) && name.contains(BusinessConstant.separator)) {
                        String[] nameArr = name.split(BusinessConstant.separator);
                        result.put("firstCategoryName", nameArr[0]);
                        result.put("secondCategoryName", nameArr[1]);
                    }
                    // 文章推送时间
                    Object sendTime = map.get("sourceTime");
                    result.put("sendTime",sendTime);
                    // 文章推送人
                    Object sender = map.get("sendName");
                    result.put("sender",sender);
                    jsonArray.add(result);
                }
        );
        return jsonArray.toJSONString();
    }
    /**
     *
     * 获取随访记录
     * @return
     */
    public String getFollowupRecord(String idcard){
        JSONArray jsonArray = new JSONArray();
        String sql = "select * from " + ConstantUtil.figure_label_es_index + "/" + ConstantUtil.figure_label_es_type + "where dictCode = '" + ConstantUtil.followup_dict + "' and idcard ='" + idcard + "'";
        List<Map<String, Object>> list = elastricSearchHelper.excuceSQL(sql.toString());
        list.forEach(
                map -> {
                    JSONObject result = new JSONObject();
                    // 随访疾病名称
                    String followupName = String.valueOf(map.get("labelName"));
                    result.put("followupName", followupName);
                    // 随访方式
                    String followupStyle = String.valueOf(map.get("labelValue"));
                    result.put("followupStyle", followupStyle);
                    // 随访时间
                    Object followupTime = map.get("sourceTime");
                    result.put("followupTime", followupTime);
                    // 随访医生
                    Object followupDoctor = map.get("sendName");
                    result.put("followupDoctor", followupDoctor);
                    // 随访评价
                    Object followupEvaluate = map.get("followupEvaluate");
                    result.put("followupDoctor", followupEvaluate);
                    jsonArray.add(result);
                }
        );
        return jsonArray.toJSONString();
    }
}

+ 5 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/service/ExtractService.java

@ -0,0 +1,5 @@
package com.yihu.wlyy.figure.label.service;
public class ExtractService {
}

+ 170 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/service/JobService.java

@ -0,0 +1,170 @@
package com.yihu.wlyy.figure.label.service;
import com.yihu.wlyy.figure.label.constant.BusinessConstant;
import com.yihu.wlyy.figure.label.dao.FlJobConfigDao;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.entity.FlJobConfig;
import com.yihu.wlyy.figure.label.util.QuartzHelpers;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.*;
import static com.yihu.wlyy.figure.label.constant.BusinessConstant.gt;
/**
 *@author lith on 2018.03.23
 */
@Service
public class JobService {
    @Value("${JobService.sleepTime}")
    private Integer sleepTime;
    @Autowired
    private FlJobConfigDao flJobConfigDao;
    @Autowired
    private QuartzHelpers quartzHelpers;
    @Transactional(rollbackFor = Exception.class)
    public void stopById(String id) throws Exception {
        String[] idarr = id.split(",");
        for(String oneId : idarr){
        FlJobConfig flJobConfig = flJobConfigDao.findByIdAndStatus(Long.valueOf(oneId), "1");
        if (flJobConfig != null) {
            quartzHelpers.removeJob(flJobConfig.getId().toString());
            flJobConfigDao.updateStatus(flJobConfig.getId(), "0");
            ;
        } else {
            throw new Exception("任务已经停止");
        }
        }
    }
    @Transactional(rollbackFor = Exception.class)
    public void startById(String id) throws Exception {
        String[] idarr = id.split(",");
        for(String oneId : idarr){
            FlJobConfig flJobConfig = flJobConfigDao.findByIdAndStatus(Long.valueOf(oneId), "0");
            if (flJobConfig != null) {
                startOneJob(flJobConfig);
            } else {
                throw new Exception("任务已经启动");
            }
        }
    }
    @Transactional(rollbackFor = Exception.class)
    public void stopAll() throws Exception {
        List<FlJobConfig> FlJobConfigs = flJobConfigDao.findByAll("1");
        if (FlJobConfigs != null && FlJobConfigs.size() > 0) {
            for (FlJobConfig FlJobConfig : FlJobConfigs) {
                quartzHelpers.removeJob(FlJobConfig.getId().toString());
                flJobConfigDao.updateStatus(FlJobConfig.getId(), "0");
            }
        } else {
            throw new Exception("任务已经全部停止");
        }
    }
    @Transactional(rollbackFor = Exception.class)
    public void startAll() throws Exception {
        List<FlJobConfig> FlJobConfigs = flJobConfigDao.findByAll("0");
        if (FlJobConfigs != null && FlJobConfigs.size() > 0) {
            for (FlJobConfig FlJobConfig : FlJobConfigs) {
                startOneJob(FlJobConfig);
            }
        } else {
            throw new Exception("任务已经全部启动");
        }
    }
    /**
     * 启动单个任务
     *
     * @param FlJobConfig
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public void startOneJob(FlJobConfig FlJobConfig) throws Exception {
        FlJobConfig flJobConfigVO = new FlJobConfig();
        BeanUtils.copyProperties(FlJobConfig, flJobConfigVO);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("jobConfig", flJobConfigVO.getId());
        params.put(BusinessConstant.sourceType, flJobConfigVO.getSourceType());
        params.put(BusinessConstant.sourceType, flJobConfigVO.getSource());
        //表里设置的增量查询类型和增量查询初始值,如果值没有配置,以当前时间为准
        if(!StringUtils.isEmpty(flJobConfigVO.getSqlFieldValue())){
            params.put(BusinessConstant.sqlFieldValue,flJobConfigVO.getSqlFieldValue());
        }else{
            params.put(BusinessConstant.sqlFieldValue, DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
        }
        params.put(BusinessConstant.SQLFIELDCONDITION, BusinessConstant.gt);
        if (!StringUtils.isEmpty(FlJobConfig.getJobClass())) {
            //往quartz框架添加任务
            quartzHelpers.addJob(getRightClass(FlJobConfig), FlJobConfig.getQuartzCron(), FlJobConfig.getId().toString(), params);
            flJobConfigDao.updateStatus(FlJobConfig.getId(), "1");//设置任务状态是启动 }
        }
    }
    public void startNowById(String id) throws Exception {
        FlJobConfig FlJobConfig = flJobConfigDao.findOne(Long.parseLong(id));
        FlJobConfig flJobConfigVO = new FlJobConfig();
        BeanUtils.copyProperties(FlJobConfig, flJobConfigVO);
        Map<String, Object> params = new HashMap<>();
        params.put("jobConfig", flJobConfigVO.getId());
        params.put(BusinessConstant.sourceType, flJobConfigVO.getSourceType());
        params.put(BusinessConstant.source, flJobConfigVO.getSource());
        if(!StringUtils.isEmpty(flJobConfigVO.getSqlFieldValue())){
            params.put(flJobConfigVO.getSqlField(),flJobConfigVO.getSqlFieldValue());
        }else{
            params.put(flJobConfigVO.getSqlField(), DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
        }
        params.put(BusinessConstant.SQLFIELDCONDITION, BusinessConstant.gt);
        //往quartz框架添加任务
        if (!StringUtils.isEmpty(FlJobConfig.getJobClass())) {
            quartzHelpers.startNow(getRightClass(FlJobConfig), FlJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
            Thread.sleep(sleepTime);
        }
    }
    /**
     * @param FlJobConfig
     * @return
     * @throws ClassNotFoundException
     */
    private Class getRightClass(FlJobConfig FlJobConfig) throws ClassNotFoundException {
        return Class.forName(FlJobConfig.getJobClass());
    }
        /**
         * 增量查询数据成功后,将增量时间改为当前时间
         * @param id
         * @param lastDataId
         * @param bool
         */
    @Transactional(rollbackFor = Exception.class)
    public void updateFieldValuetoCurrentTimeOrId(Long id,Long lastDataId,boolean bool) {
        if (!bool) {
            return;
        }
        if(null != lastDataId && lastDataId != 0){
            this.flJobConfigDao.updateSqlFildeValue(id,String.valueOf(lastDataId));
            return;
        }
        this.flJobConfigDao.updateSqlFildeValue(id, DateFormatUtils.format(new Date(), ConstantUtil.date_format));
    }
}

+ 14 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/storage/Storager.java

@ -0,0 +1,14 @@
package com.yihu.wlyy.figure.label.storage;
import com.yihu.wlyy.figure.label.model.SaveModel;
import java.util.List;
/**
 * @author lith on 2018.03.14 -- Created by chenweida on 2018/3/7.
 * 存储器
 */
public interface Storager {
    void save(List<SaveModel> modelList);
}

+ 58 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/storage/Store2ES.java

@ -0,0 +1,58 @@
package com.yihu.wlyy.figure.label.storage;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.base.es.config.ElastricSearchHelper;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import com.yihu.wlyy.figure.label.util.TimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
 *@author lith on 2018.03.23
 */
@Component
public class Store2ES implements Storager {
    private Logger logger = LoggerFactory.getLogger(Store2ES.class);
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    @Autowired
    ObjectMapper objectMapper;
    @Override
    public void save(List<SaveModel> modelList) {
        List<String> list = new ArrayList<>();
        int saveCount = 0;
        long start = System.currentTimeMillis();
        String logtitle = "loop(save) data,total size:" + modelList.size();
        TimeUtil.start(logger,logtitle,start);
        for(SaveModel saveModel:modelList){
            try {
                String str =  objectMapper.writeValueAsString(saveModel);
                list.add(str);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
            //防止内存溢出,一次性存储10W条
            if(list.size() >= 100000){
                elastricSearchHelper.saveBulkWithCustomId(ConstantUtil.figure_label_es_index, ConstantUtil.figure_label_es_type, list,"id");
                list.clear();
                saveCount ++;
            }else if(modelList.size() - saveCount * 100000 == list.size()){
                //剩余的零头
                elastricSearchHelper.saveBulkWithCustomId(ConstantUtil.figure_label_es_index, ConstantUtil.figure_label_es_type, list,"id");
            }
        }
        long finish = System.currentTimeMillis();
        TimeUtil.finish(logger,"loop(save) data",start,finish);
    }
}

+ 54 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/storage/Store2Hbase.java

@ -0,0 +1,54 @@
package com.yihu.wlyy.figure.label.storage;
import com.yihu.base.hbase.HBaseAdmin;
import com.yihu.base.hbase.HBaseHelper;
import com.yihu.base.hbase.TableBundle;
import com.yihu.wlyy.figure.label.model.SaveModel;
import com.yihu.wlyy.figure.label.util.BeanUtil;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Map;
/**
 * @author lith 2018.03.23
 */
public class Store2Hbase implements Storager {
    private Logger logger = LoggerFactory.getLogger(Store2Hbase.class);
    @Autowired
    private HBaseHelper hBaseHelper;
    @Autowired
    private HBaseAdmin hBaseAdmin;
    @Override
    public void save(List<SaveModel> modelList) {
        if(CollectionUtils.isEmpty(modelList)){
            return;
        }
        String[] fieldName = BeanUtil.getFiledName(modelList.get(0));
        try {
            if(!hBaseAdmin.isTableExists(ConstantUtil.figure_label_hbase_table)){
                hBaseAdmin.createTable(ConstantUtil.figure_label_hbase_table,fieldName);
            }
        }catch (Exception e){
            logger.error("invalid hbase table:" + ConstantUtil.figure_label_hbase_table);
        }
        TableBundle tableBundle = new TableBundle();
        for (SaveModel saveModel : modelList) {
            tableBundle.addFamily(saveModel.getId(), ConstantUtil.figure_label_familyA);
            tableBundle.addColumns(saveModel.getId(), ConstantUtil.figure_label_familyA,fieldName);
            Map<String,String> map = BeanUtil.beanToMap(saveModel);
            tableBundle.addValues(saveModel.getId(), ConstantUtil.figure_label_familyA,map);
        }
        hBaseHelper.save(ConstantUtil.figure_label_hbase_table,tableBundle);
        logger.info("save to hbase count:" + modelList.size());
    }
}

+ 24 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/ApplicationContextHolderUtil.java

@ -0,0 +1,24 @@
package com.yihu.wlyy.figure.label.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
 * @author litaohong on 2018/4/11
 * @project patient-co-management
 */
@Component
public class ApplicationContextHolderUtil implements ApplicationContextAware {
    private static ApplicationContext context;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }
    public static ApplicationContext getContext() {
        return context;
    }
}

+ 74 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/BeanUtil.java

@ -0,0 +1,74 @@
package com.yihu.wlyy.figure.label.util;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
/**
 * @project figure-label
 * @author litaohong on 2018/3/27
 */
public class BeanUtil {
    /**
     * 获取类字段名
     * @param obj
     * @return
     */
    public static String[] getFiledName(Object obj) {
        try {
            Field[] fields = obj.getClass().getDeclaredFields();
            String[] fieldNames = new String[fields.length];
            for (int i = 0; i < fields.length; i++) {
                //id字段去掉
                if(StringUtils.equals("id",fields[i].getName())){
                    continue;
                }
                fieldNames[i] = fields[i].getName();
            }
            return fieldNames;
        } catch (SecurityException e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 将对象转换成map
     * @param obj
     * @return
     * @throws IllegalAccessException
     */
    public static Map<String, String> beanToMap(Object obj) {
        Map<String, String> map = new HashMap<>();
        try {
            Class<?> clazz = obj.getClass();
            for (Field field : clazz.getDeclaredFields()) {
                //id字段去掉
                if (StringUtils.equals("id", field.getName())) {
                    continue;
                }
                field.setAccessible(true);
                String fieldName = field.getName();
                Object value = field.get(obj);
                map.put(fieldName, value.toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }
    public static Object mapToBean(Map<String, Object> map, Class<?> beanClass) throws Exception {
        if (map == null){
            return null;
        }
        Object bean = beanClass.newInstance();
        org.apache.commons.beanutils.BeanUtils.populate(bean, map);
        return bean;
    }
}

+ 124 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/IdCardUtil.java

@ -0,0 +1,124 @@
package com.yihu.wlyy.figure.label.util;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import java.util.Calendar;
/***
 * 根据居民身份证提取相对应的信息
 */
@Component
public class IdCardUtil {
    /**
     * 根据身份证的号码算出当前身份证持有者的性别
     * 1 女 2 男 3未知
     *
     * @return
     * @throws Exception
     */
    public static String getSexForIdcard(String idCard){
        if(StringUtils.isEmpty(idCard)){
            return "未知";
        }
        try {
            String sex = "2";
            if (idCard.length() == 18) {
                if (Integer.parseInt(idCard.substring(16).substring(0, 1)) % 2 == 0) {// 判断性别
                    sex = "1";
                } else {
                    sex = "2";
                }
            } else if (idCard.length() == 15) {
                String usex = idCard.substring(14, 15);// 用户的性别
                if (Integer.parseInt(usex) % 2 == 0) {
                    sex = "1";
                } else {
                    sex = "2";
                }
            }
            return sex;
        } catch (Exception e) {
            return "1";
        }
    }
    /**
     * 根据身份证的号码算出当前身份证持有者的年龄
     *
     * @param
     * @throws Exception
     */
    public static int getAgeForIdcard(String idCard) {
        int age = 0;
        if(StringUtils.isEmpty(idCard)){
            return age;
        }
        try {
            if (org.springframework.util.StringUtils.isEmpty(idCard)) {
                return age;
            }
            String birth = "";
            if (idCard.length() == 18) {
                birth = idCard.substring(6, 14);
            } else if (idCard.length() == 15) {
                birth = "19" + idCard.substring(6, 12);
            } else {
                return age;
            }
            int year = Integer.valueOf(birth.substring(0, 4));
            int month = Integer.valueOf(birth.substring(4, 6));
            int day = Integer.valueOf(birth.substring(6));
            Calendar cal = Calendar.getInstance();
            age = cal.get(Calendar.YEAR) - year;
            //周岁计算
            if (cal.get(Calendar.MONTH) < (month - 1) || (cal.get(Calendar.MONTH) == (month - 1) && cal.get(Calendar.DATE) < day)) {
                age--;
            }
            return age;
        } catch (Exception e) {
            return 0;
        }
    }
    /**
     * 身份证提取出身日期
     * @param idCard
     * @return
     * @throws Exception
     */
    public static String getBirthdayForIdcard(String idCard) throws Exception {
        if(StringUtils.isEmpty(idCard)){
            return "";
        }
        String year = "";
        String month = "";
        String day = "";
        if (idCard.length() == 18) {
            year = idCard.substring(6,10);
            month = idCard.substring(10,12);
            day = idCard.substring(12,14);
        } else if (idCard.length() == 15) {
            year = "19" + idCard.substring(6,8);
            month = idCard.substring(8,10);
            day = idCard.substring(10,12);
        }
        StringBuilder birthday = new StringBuilder();
        birthday.append(year).append("-");
        birthday.append(month).append("-");
        birthday.append(day);
        return birthday.toString();
    }
    public static void main(String args[]) throws Exception {
        System.out.println(getBirthdayForIdcard("411321198004273615"));
        System.out.println(getBirthdayForIdcard("440253850213582"));
//        System.out.println(getSexForIdcard("411321198004273615"));
//        System.out.println(getAgeForIdcard("411321198004273615"));
    }
}

+ 55 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/MD5Util.java

@ -0,0 +1,55 @@
package com.yihu.wlyy.figure.label.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Util {
    // 全局数组
    private final static String[] strDigits = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
    private static  MessageDigest md = null;
    static {
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
    public MD5Util() {
    }
    // 返回形式为数字跟字符串
    private static String byteToArrayString(byte bByte) {
        int iRet = bByte;
        if (iRet < 0) {
            iRet += 256;
        }
        int iD1 = iRet / 16;
        int iD2 = iRet % 16;
        return strDigits[iD1] + strDigits[iD2];
    }
    // 转换字节数组为16进制字串
    private static String byteToString(byte[] bByte) {
        StringBuffer sBuffer = new StringBuffer();
        for (int i = 0; i < bByte.length; i++) {
            sBuffer.append(byteToArrayString(bByte[i]));
        }
        return sBuffer.toString();
    }
    public static String GetMD5Code(String strObj) {
        String resultString = null;
        if(null == md){
            try {
                md = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
        }
        resultString = byteToString(md.digest(strObj.getBytes()));
        return resultString;
    }
}

+ 57 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/MakeIDUtil.java

@ -0,0 +1,57 @@
package com.yihu.wlyy.figure.label.util;
import com.yihu.wlyy.figure.label.entity.FlLabelDict;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.model.SaveModel;
import org.springframework.util.StringUtils;
public class MakeIDUtil {
    /**
     * 生成从mysql获取,后存入es的id,确保数据不会重复
     * id由 idcard,dictCode,parentCode,labelName,labelCode MD5加密而成。
     * @param saveModel
     * @return
     */
    public static String makeSaveModelID(SaveModel saveModel) {
        StringBuilder idStr = new StringBuilder();
        idStr.append(saveModel.getDictCode())
                .append(saveModel.getIdcard()).append("-")
                .append(saveModel.getLabelType()).append("-")
                .append(saveModel.getLabelCode()).append("-")
                .append(saveModel.getLabelName());
       if(!StringUtils.isEmpty(saveModel.getLabelValue())){
           idStr.append("-").append(saveModel.getLabelValue());
       }
        return MD5Util.GetMD5Code(idStr.toString());
    }
    /**
     * 生成从es获取,后存入es的id,确保数据不会重复
     * id由 id,id1,parentCode,labelName,labelCode MD5加密而成。
     * @param dataModel
     * @param flLabelDict
     * @return
     */
    public static String makeEsSaveModelID(DataModel dataModel, FlLabelDict flLabelDict) {
        StringBuilder idStr = new StringBuilder();
        idStr.append(dataModel.getId() + "").append("-")
                .append(dataModel.getId1() + "").append("-")
                .append(flLabelDict.getParentCode()).append("-")
                .append(flLabelDict.getLabelCode()).append("-")
                .append(flLabelDict.getLabelName());
        return MD5Util.GetMD5Code(idStr.toString());
    }
    public static void main(String[] args) {
        DataModel dataModel = new DataModel();
        dataModel.setIdcard("350881199004241228");
        dataModel.setParentCode("2");
        dataModel.setLabelCode("1");
        dataModel.setLabelName("健康人群");
//        String MD5ID = makeSaveModelID(dataModel,"");
    }
}

+ 122 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/QuartzHelpers.java

@ -0,0 +1,122 @@
package com.yihu.wlyy.figure.label.util;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.Map;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
@Component
public class QuartzHelpers {
    @Autowired
    private SchedulerFactoryBean schedulerFactoryBean;
    private Scheduler scheduler = null;
    @PostConstruct
    public void init() {
        try {
//            SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
            scheduler = schedulerFactoryBean.getScheduler();
            scheduler.clear();
            scheduler.start();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
    public void addJob(Class jobClass, String cronString, String jobKey,
                       Map<String, Object> params) throws Exception {
        if (!CronExpression.isValidExpression(cronString)) {
            throw new Exception("cronExpression is not a valid Expression");
        }
        try {
            JobDetail job = JobBuilder.newJob(jobClass)
                    .withIdentity("job-id:" + jobKey, "job-group:" + jobKey)
                    .build();
            JobDataMap jobDataMap = job.getJobDataMap();
            jobDataMap.putAll(params);
            CronTrigger trigger = TriggerBuilder
                    .newTrigger()
                    .withIdentity("trigger-name:" + jobKey, "trigger-group:" + jobKey)
                    .withSchedule(
                            CronScheduleBuilder
                                    .cronSchedule(cronString)
                                    //——以错过的第一个频率时间立刻开始执行
                                    //——重做错过的所有频率周期后
                                    //——当下一次触发频率发生时间大于当前时间后,再按照正常的Cron频率依次执行
                                    .withMisfireHandlingInstructionIgnoreMisfires()
                    )
                    .build();
            scheduler.scheduleJob(job, trigger);
            scheduler.start();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
    public void removeJob(String jobKeyString) throws Exception {
        TriggerKey triggerKey = new TriggerKey("trigger-name:" + jobKeyString, "trigger-group:" + jobKeyString);
        JobKey jobName = new JobKey("job-id:" + jobKeyString, "job-group:" + jobKeyString);
        scheduler.pauseTrigger(triggerKey);// 停止触发器
        scheduler.unscheduleJob(triggerKey);// 移除触发器
        scheduler.deleteJob(jobName);// 删除任务
    }
    public boolean isExistJob(String jobKey) throws SchedulerException {
        JobKey jk = new JobKey("job-id:" + jobKey, "job-group:" + jobKey);
        if (scheduler.checkExists(jk)) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * 立即执行任务。
     *
     * @param jobClass
     * @param id
     * @param params
     * @throws Exception
     */
    public void startNow(Class jobClass, String id, Map<String, Object> params) throws Exception {
        startAt(new Date(), jobClass, id, params);
    }
    /**
     * 在指定时间点执行。
     *
     * @param time
     * @param jobClass
     * @param id
     * @param params
     * @throws Exception
     */
    public void startAt(Date time, Class jobClass, String id, Map<String, Object> params) throws Exception {
        JobDetail job = JobBuilder.newJob(jobClass).withIdentity("job-id:" + id, "job-group:" + id).build();
        JobDataMap jobDataMap = job.getJobDataMap();
        if (null != params) {
            jobDataMap.putAll(params);
        }
        SimpleTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger-id:" + id, "trigger-group:" + id)
                .startAt(time)
                .withSchedule(
                        simpleSchedule()
                                .withIntervalInSeconds(10)
                                .withRepeatCount(0)
                                .withMisfireHandlingInstructionIgnoreMisfires()
                )
                .build();
        scheduler.scheduleJob(job, trigger);
        scheduler.start();
    }
}

+ 110 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/SudokuTool.java

@ -0,0 +1,110 @@
package com.yihu.wlyy.figure.label.util;
/**
 * @author litaohong on 2018/7/26
 * @project patient-co-management
 */
public class SudokuTool {
    private int[][] matrix;
    public SudokuTool(int[][] matrix) {
        this.matrix = matrix;
    }
    public static void main(String[] args) {
        // 号称世界上最难数独
        int[][] sudoku = {
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 3, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0}};
        SudokuTool s = new SudokuTool(sudoku);
        s.backTrace(0, 0);
    }
    /**
     * 数独算法
     *
     * @param i 行号
     * @param j 列号
     */
    private void backTrace(int i, int j) {
        if (i == 8 && j == 9) {
            //已经成功了,打印数组即可
            System.out.println("获取正确解");
            printArray();
            return;
        }
        //已经到了列末尾了,还没到行尾,就换行
        if (j == 9) {
            i++;
            j = 0;
        }
        //如果i行j列是空格,那么才进入给空格填值的逻辑
        if (matrix[i][j] == 0) {
            for (int k = 1; k <= 9; k++) {
                //判断给i行j列放1-9中的任意一个数是否能满足规则
                if (check(i, j, k)) {
                    //将该值赋给该空格,然后进入下一个空格
                    matrix[i][j] = k;
                    backTrace(i, j + 1);
                    //初始化该空格
                    matrix[i][j] = 0;
                }
            }
        } else {
            //如果该位置已经有值了,就进入下一个空格进行计算
            backTrace(i, j + 1);
        }
    }
    /**
     * 判断给某行某列赋值是否符合规则
     *
     * @param row    被赋值的行号
     * @param line   被赋值的列号
     * @param number 赋的值
     * @return
     */
    private boolean check(int row, int line, int number) {
        //判断该行该列是否有重复数字
        for (int i = 0; i < 9; i++) {
            if (matrix[row][i] == number || matrix[i][line] == number) {
                return false;
            }
        }
        //判断小九宫格是否有重复
        int tempRow = row / 3;
        int tempLine = line / 3;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (matrix[tempRow * 3 + i][tempLine * 3 + j] == number) {
                    return false;
                }
            }
        }
        return true;
    }
    /**
     * 打印矩阵
     */
    public void printArray() {
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                System.out.print(matrix[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println();
    }
}

+ 92 - 0
svr/figure-label/src/main/java/com/yihu/wlyy/figure/label/util/TimeUtil.java

@ -0,0 +1,92 @@
package com.yihu.wlyy.figure.label.util;
import com.yihu.wlyy.figure.label.constant.ConstantUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import java.util.Date;
import java.util.concurrent.TimeUnit;
/**
 * @author litaohong on 2018/5/3
 * @project patient-co-management
 * 计时器工具类
 */
public class TimeUtil{
    public static void start(Logger logger,String title,long start){
        StringBuilder sb = new StringBuilder();
        sb.append(title).append(" start at ")
                .append(DateFormatUtils.format(start, ConstantUtil.date_format));
        logger.info(sb.toString());
    }
    public static void finish(Logger logger,String title,long start,long finishTime){
        StringBuilder sb = new StringBuilder();
        long delta = finishTime - start;
        sb.append(title).append(" finish at ")
                .append(DateFormatUtils.format(finishTime, ConstantUtil.date_format)).append(",coast: ");
        long day = 1000 * 60 * 60 * 24;
        long hour = 1000 * 60 * 60;
        long min = 1000 * 60;
        if(delta > day){
            sb.append(TimeUnit.MILLISECONDS.toSeconds(delta) % 60).append("天");
        }
        if(delta > hour){
            sb.append(TimeUnit.MILLISECONDS.toHours(delta) % 24).append("时");
        }
        if(delta > min){
            sb.append(TimeUnit.MILLISECONDS.toMinutes(delta) % 60).append("分");
        }
        sb.append(TimeUnit.MILLISECONDS.toSeconds(delta) % 60).append("秒");
        logger.info(sb.toString());
    }
    /**
     * 转换为Solr时间格式
     * @param datetime
     * @return
     */
    public static String toSolrTime(String datetime){
        if(StringUtils.isEmpty(datetime)){
            return "";
        }
        String solrTime = "";
        String[] timeArr = datetime.split(" ");
        solrTime = timeArr[0] + "T" + timeArr[1]+"Z";
        return solrTime;
    }
    /**
     * 转换为elasticsearch时间格式
     * @param datetime
     * @return
     */
    public static String toEsTime(String datetime){
        if(StringUtils.isEmpty(datetime)){
            return "";
        }
        String EsTime = "";
        String[] timeArr = datetime.split(" ");
        EsTime = timeArr[0] + "T" + timeArr[1]+"+0800";
        return EsTime;
    }
    /**
     * 将Solr时间格式转为java时间格式
     * @param solrTime 2017-12-18T08:53:36Z
     * @return
     */
    public static String toJavaTime(String solrTime){
        if(StringUtils.isEmpty(solrTime)){
            return "";
        }
        String date = solrTime.substring(0,10);
        String time = solrTime.substring(11,solrTime.length()-1);
        return date+" "+time;
    }
}

+ 52 - 0
svr/figure-label/src/main/resources/application-dev.yml

@ -0,0 +1,52 @@
##开发的配置
spring:
  profiles: dev
  datasource:
#    wlyy:
#      url: jdbc:mysql://172.19.103.85/figure_lable?useUnicode:true&amp;characterEncoding=utf-8&amp;autoReconnect=true
#      username: linzhou
#      password: linzhou
    wlyy:
      url: jdbc:mysql://172.19.103.77/figure_lable?useUnicode:true&amp;characterEncoding=utf-8&amp;autoReconnect=true
      username: root
      password: 123456
    healtharchive:
      url: jdbc:mysql://172.19.103.50:3306/healtharchive?useUnicode=true&characterEncoding=UTF-8&useSSL=false
      username: chenweishan
      password: chenweishan
    wlyy85:
      url: jdbc:mysql://172.19.103.85/wlyy?useUnicode:true&amp;characterEncoding=utf-8&amp;autoReconnect=true
      username: linzhou
      password: linzhou
  data:
    elasticsearch:
      cluster-name: jkzl #es集群的名字
      cluster-nodes: 172.19.103.45:9300,172.19.103.68:9300 # 11.1.2.28:9300,11.1.2.29:9300
      cluster-nodes-jest: http://172.19.103.68:9200,http://172.19.103.45:9200  #http://11.1.2.28:9200,http://11.1.2.29:9200   #多个逗号分割
      repositories:
        enabled: true
      properties:
        client:
          transport:
            sniff: false #开启嗅探集群  用nginx代理一层过后会出现ip解析失败问题
    solr:
      zk-host: node2.hde.h3c.com:2181,node1.hde.h3c.com:2181,node3.hde.h3c.com:2181/solr
quartz:
  namespace: patient-co-figure-label ##quartz的命名空间,名称一样实现消费负载
  overwriteExistingJobs: false ##是否覆盖job
JobService:
  sleepTime: 40000
hadoop:
  hbase-properties:
    hbase.zookeeper.property.clientPort: 2181
    zookeeper.znode.parent: /hbase-unsecure
    hbase.zookeeper.quorum:  node1.hde.h3c.com,node2.hde.h3c.com,node3.hde.h3c.com
  user:
    name: root

+ 14 - 0
svr/figure-label/src/main/resources/application-test.yml

@ -0,0 +1,14 @@
##开发的配置
spring:
  profiles: dev
  datasource:
    wlyy:
      url: jdbc:mysql://172.19.103.77/figure_lable?useUnicode:true&amp;characterEncoding=utf-8&amp;autoReconnect=true
      username: root
      password: 123456
quartz:
  namespace: patient-co-figure-label ##quartz的命名空间,名称一样实现消费负载
  overwriteExistingJobs: false ##是否覆盖job

+ 32 - 0
svr/figure-label/src/main/resources/application.yml

@ -0,0 +1,32 @@
server:
  port: 8080
spring:
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    initialSize: 50
    maxActive: 50
    minIdle: 50 #最大空闲连接
    maxWait: 50
    validationQuery: SELECT 1 #SQL 查询, 用来验证从连接池取出的连接, 在将连接返回给调用者之前。 如果指定, 则查询必须是一个SQL SELECT 并且必须返回至少一行记录
    testOnBorrow: true #指明是否在从池中取出连接前进行检验, 如果检验失败, 则从池中去除连接并尝试取出另一个。注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串
    testOnReturn: true #指明是否在归还到池中前进行检验 注意: 设置为true 后如果要生效validationQuery 参数必须设置为非空字符串
    testWhileIdle: true #指明连接是否被空闲连接回收器(如果有)进行检验,如果检测失败,则连接将被从池中去除
    minEvictableIdleTimeMillis: 3600000 #连接池中连接,在时间段内一直空闲,被逐出连接池的时间(1000*60*60),以毫秒为单位
    timeBetweenEvictionRunsMillis: 300000 #在空闲连接回收器线程运行期间休眠的时间值,以毫秒为单位,一般比minEvictableIdleTimeMillis小
    poolPreparedStatements: true # 打开PSCache,并且指定每个连接上PSCache的大小
    maxPoolPreparedStatementPerConnectionSize: 50
    removeAbandoned: false #超过时间限制是否回收
    removeAbandonedTimeout: 7200 #超时时间;单位为秒。180秒=3分钟
    logAbandoned: false #关闭abanded连接时输出错误日志
    # filters: stat,wall,logback #配置监控统计拦截的filters,去掉后监控界面sql将无法统计,'wall'用于防火墙
    filters: stat,logback #配置监控统计拦截的filters,去掉后监控界面sql将无法统计,'wall'用于防火墙
hibernate:
  dialect: org.hibernate.dialect.MySQL5Dialect
  show_sql: false
  ejb:
    naming_strategy: org.hibernate.cfg.ImprovedNamingStrategy

+ 23 - 0
svr/figure-label/src/main/resources/banner.txt

@ -0,0 +1,23 @@
${AnsiColor.BRIGHT_GREEN}
                                    ////////////////////////////////////////////////////////////////////
                                    //                          _ooOoo_                               //
                                    //                         o8888888o                              //
                                    //                         88" . "88                              //
                                    //                         (| ^_^ |)                              //
                                    //                         O\  =  /O                              //
                                    //                      ____/`---'\____                           //
                                    //                    .'  \\|     |//  `.                         //
                                    //                   /  \\|||  :  |||//  \                        //
                                    //                  /  _||||| -:- |||||-  \                       //
                                    //                  |   | \\\  -  /// |   |                       //
                                    //                  | \_|  ''\---/''  |   |                       //
                                    //                  \  .-\__  `-`  ___/-. /                       //
                                    //                ___`. .'  /--.--\  `. . ___                     //
                                    //              ."" '<  `.___\_<|>_/___.'  >'"".                  //
                                    //            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
                                    //            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
                                    //      ========`-.____`-.___\_____/___.-`____.-'========         //
                                    //                           `=---='                              //
                                    //      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
                                    //            佛祖保佑       永不宕机     永无BUG                 //
                                    ////////////////////////////////////////////////////////////////////

+ 32 - 0
svr/figure-label/src/main/resources/logback.xml

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="io.searchbox" level="WARN"/>
    <jmxConfigurator/>
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy/MM/dd-HH:mm:ss} %level [%thread] %caller{1} - %msg%n</pattern>
            <charset class="java.nio.charset.Charset">UTF-8</charset>
        </encoder>
    </appender>
    <appender name="rollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/tmp/logs/figure-label</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>/tmp/logs/figure-label.%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>15</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
            <charset class="java.nio.charset.Charset">UTF-8</charset>
        </encoder>
    </appender>
    <!--<root level="debug">-->
    <root level="info">
        <!--<appender-ref ref="console" />-->
        <appender-ref ref="rollingFile"/>
    </root>
</configuration>

+ 41 - 0
svr/figure-label/src/main/resources/quartz.properties

@ -0,0 +1,41 @@
# Default Properties file for use by StdSchedulerFactory
# to create a Quartz Scheduler Instance, if a different
# properties file is not explicitly specified.
#
 
org.quartz.scheduler.instanceName: DefaultQuartzScheduler
org.quartz.scheduler.rmi.export: false
org.quartz.scheduler.rmi.proxy: false
org.quartz.scheduler.wrapJobExecutionInUserTransaction: false
 
org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 20
org.quartz.threadPool.threadPriority: 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: true
 
org.quartz.jobStore.misfireThreshold: 60000
 
#============================================================================
# Configure JobStore
#============================================================================
 
# RAM
# org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore
# Configure JobStore Cluster
org.quartz.jobStore.class:org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass:org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#datasource׺
org.quartz.jobStore.tablePrefix:qrtz_
#org.quartz.jobStore.dataSource:qzDS
#
##============================================================================
## Configure Datasources
##============================================================================
##datasource
#org.quartz.dataSource.qzDS.driver: com.mysql.jdbc.Driver
#org.quartz.dataSource.qzDS.URL: jdbc:mysql://172.19.103.85/wlyy?useUnicode=true&characterEncoding=utf-8&autoReconnect=true
#org.quartz.dataSource.qzDS.user: root
#org.quartz.dataSource.qzDS.password: 123456
org.quartz.jobGroupName = RS_JOBGROUP_NAME
org.quartz.triggerGroupName = RS_TRIGGERGROUP_NAME