ソースを参照

Merge branch 'dev' of LiTaohong/patient-co-management into dev

yeshijie 7 年 前
コミット
a16ee34ce3
25 ファイル変更383 行追加161 行削除
  1. 9 0
      common/common-entity/src/main/java/com/yihu/figure_label/entity/FlLabelDict.java
  2. 9 0
      common/common-entity/src/main/java/com/yihu/figure_label/entity/FlLabelDictJob.java
  3. 0 0
      patient-co/patient-co-figure-label/patient-co-figure-label.iml___jb_tmp___
  4. 1 1
      patient-co/patient-co-figure-label/pom.xml
  5. 14 0
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/FigureLabelJpa.java
  6. 10 0
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/properties/DataSourceProperties.java
  7. 68 0
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/controller/DataOperationController.java
  8. 7 0
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/AgeConvert.java
  9. 91 0
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/BasicDictItemHelper.java
  10. 6 0
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/BirthConvert.java
  11. 43 7
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/ConvertHelper.java
  12. 0 48
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/HeightConvert.java
  13. 6 1
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/SexConvert.java
  14. 1 1
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/SignDoctorConvert.java
  15. 1 1
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/SignTeamConvert.java
  16. 0 52
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/WeightConvert.java
  17. 2 1
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/ESExtracter.java
  18. 21 3
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/MysqlExtracter.java
  19. 1 1
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Es2EsJob.java
  20. 2 0
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Mysql2ESJob.java
  21. 15 28
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/model/DataModel.java
  22. 13 9
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/model/SaveModel.java
  23. 14 3
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/storage/Store2ES.java
  24. 43 0
      patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/util/TimeUtil.java
  25. 6 5
      patient-co/patient-co-figure-label/src/main/resources/application-dev.yml

+ 9 - 0
common/common-entity/src/main/java/com/yihu/figure_label/entity/FlLabelDict.java

@ -17,6 +17,15 @@ 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;

+ 9 - 0
common/common-entity/src/main/java/com/yihu/figure_label/entity/FlLabelDictJob.java

@ -18,6 +18,15 @@ public class FlLabelDictJob extends IdEntity {
    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;

+ 0 - 0
patient-co/patient-co-figure-label/patient-co-figure-label.iml___jb_tmp___


+ 1 - 1
patient-co/patient-co-figure-label/pom.xml

@ -81,7 +81,7 @@
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>common-data-es-starter</artifactId>
            <version>1.1.0</version>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>com.yihu</groupId>

+ 14 - 0
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/FigureLabelJpa.java

@ -90,6 +90,15 @@ public class FigureLabelJpa {
        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 = "wlyyEntityManagerFactory")
    @Primary
@ -128,4 +137,9 @@ public class FigureLabelJpa {
    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);
    }
}

+ 10 - 0
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/config/db/properties/DataSourceProperties.java

@ -31,6 +31,8 @@ public class DataSourceProperties {
    private DataSourceLoginProperties healtharchive = new DataSourceLoginProperties();
    private DataSourceLoginProperties wlyy85 = new DataSourceLoginProperties();
    public String getDriverClassName() {
        return driverClassName;
    }
@ -182,4 +184,12 @@ public class DataSourceProperties {
    public void setHealtharchive(DataSourceLoginProperties healtharchive) {
        this.healtharchive = healtharchive;
    }
    public DataSourceLoginProperties getWlyy85() {
        return wlyy85;
    }
    public void setWlyy85(DataSourceLoginProperties wlyy85) {
        this.wlyy85 = wlyy85;
    }
}

+ 68 - 0
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/controller/DataOperationController.java

@ -0,0 +1,68 @@
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.util.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 DataOperationController extends BaseController{
    private Logger logger = LoggerFactory.getLogger(DataOperationController.class);
    @Autowired
    private ElastricSearchHelper elastricSearchHelper;
    @Autowired
    ObjectMapper objectMapper;
    @ApiOperation(value = "根据dictCode删除es数据")
    @RequestMapping(value = "deteleByDictCode", method = RequestMethod.POST)
    public String deleteBydictCode( @ApiParam(name = "dictCode", value = "dictCode", required = true)@RequestParam(value = "dictCode", required = true) String dictCode) throws JobExecutionException {
       long count = deleteData(dictCode);
       return success("删除成功,共计"+ count +"条");
    }
    public long  deleteData(String dictCode){
        long start = System.currentTimeMillis();
        TimeUtil.start(logger,"start delete",start);
        List<Map<String, Object>>  list = new ArrayList<>();
        String sql = "select * from " + ConstantUtil.figure_label_es_index + "/" +  ConstantUtil.figure_label_es_type + " where dictCode ='" + dictCode + "' 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,"finish delete",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);
    }
}

+ 7 - 0
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/AgeConvert.java

@ -44,12 +44,19 @@ public class AgeConvert implements Convert {
                    saveModel.setLabelType(one.getParentCode());
                    saveModel.setLabelCode(labelCode);
                    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;
                    }
                    saveModels.add(saveModel);
                }

+ 91 - 0
patient-co/patient-co-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.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()
//                    }
//            );
//        }
//    }
}

+ 6 - 0
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/BirthConvert.java

@ -44,6 +44,12 @@ public class BirthConvert implements Convert {
                    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);

+ 43 - 7
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/ConvertHelper.java

@ -35,6 +35,9 @@ public class ConvertHelper {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private BasicDictItemHelper basicDictItemHelper;
    /**
     * 进行具体标签生成转换
     * @return
@ -46,9 +49,13 @@ public class ConvertHelper {
        if(CollectionUtils.isEmpty(dataModels)){
            return saveModels;
        }
        //标签job未配置
        if(null == flLabelDictJob){
            return saveModels;
        }
        //转换器为空表示不需要转换
        if (flLabelDictJob == null || StringUtils.isEmpty(flLabelDictJob.getConvertClazz())) {
            return generateSaveModleWithOutConvert(dataModels,sourceType,source);
        if (StringUtils.isEmpty(flLabelDictJob.getConvertClazz())) {
            return generateSaveModleWithOutConvert(dataModels,flLabelDictJob.getCategoryId(),sourceType,source);
        }
        List<FlLabelDict> flLabelDictList = jdbcTemplate.query(flLabelDictJob.getSql(), new BeanPropertyRowMapper(FlLabelDict.class));
        //如果配置的字典为空
@ -61,7 +68,7 @@ public class ConvertHelper {
            Method method = obj.getClass().getMethod("convert", List.class, List.class,String.class,String.class);
            saveModels = (List<SaveModel>) method.invoke(obj, dataModels, flLabelDictList,sourceType,source);
        } catch (Exception e) {
//          logger.error("customized class or convert(List<DataModel> modelList,List<FlLabelDict> flLabelDictList,String sourceType,String source) method not found:" + flLabelDictJob.getConvertClazz());
          logger.error("customized class or convert() method not found:" + flLabelDictJob.getConvertClazz());
            e.printStackTrace();
            return saveModels;
        }
@ -71,26 +78,55 @@ public class ConvertHelper {
    /**
     * 无需转换器直接转换,此种情况为源数据已经分类好标签
     * @param dataModels
     * @param categoryId
     * @param sourceType
     * @param source
     * @return
     */
    public List<SaveModel> generateSaveModleWithOutConvert(List<DataModel> dataModels,String sourceType,String source){
    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.setId(MakeIDUtil.makeSaveModelID(dataModel,""));
            saveModel.setLabelType(dataModel.getParentCode());
            saveModel.setLabelCode(dataModel.getLabelCode());
            saveModel.setLabelName(dataModel.getLabelName());
            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());
            }
            saveModels.add(saveModel);
        }
        return saveModels;

+ 0 - 48
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/HeightConvert.java

@ -1,48 +0,0 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.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.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.04.11
 * 身高标签转换器
 */
@Component
public class HeightConvert implements Convert {
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList,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.setId(MakeIDUtil.makeSaveModelID(dataModel,dataModel.getLabelValue()));
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(dict.getLabelCode());
            saveModel.setLabelName(dict.getLabelName());
            saveModel.setLabelValue(dataModel.getLabelValue() + "cm");
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            if(org.apache.commons.lang3.StringUtils.isEmpty(saveModel.getSource())){
                return new ArrayList<>();
            }
            saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
            saveModels.add(saveModel);
        }
        return saveModels;
    }
}

+ 6 - 1
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/SexConvert.java

@ -40,9 +40,14 @@ public class SexConvert implements Convert{
                    saveModel.setLabelType(one.getParentCode());
                    String sex = IdCardUtil.getSexForIdcard(model.getIdcard());
                    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);

+ 1 - 1
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/SignDoctorConvert.java

@ -32,7 +32,7 @@ public class SignDoctorConvert implements Convert {
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(dataModel.getLabelCode());
            saveModel.setLabelName(dataModel.getLabelName());
            saveModel.setLabelName(dict.getLabelName());
            saveModel.setLabelValue(dataModel.getLabelValue());
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            if (StringUtils.isEmpty(saveModel.getSource())) {

+ 1 - 1
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/SignTeamConvert.java

@ -34,7 +34,7 @@ public class SignTeamConvert implements Convert {
            saveModel.setIdcard(dataModel.getIdcard());
            saveModel.setLabelType(dict.getParentCode());
            saveModel.setLabelCode(dataModel.getLabelCode());
            saveModel.setLabelName(dataModel.getLabelName());
            saveModel.setLabelName(dict.getLabelName());
            saveModel.setLabelValue(dataModel.getLabelValue());
            convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
            if (StringUtils.isEmpty(saveModel.getSource())) {

+ 0 - 52
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/convert/WeightConvert.java

@ -1,52 +0,0 @@
package com.yihu.wlyy.figure.label.convert;
import com.yihu.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.ConstantUtil;
import com.yihu.wlyy.figure.label.util.MakeIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * @author litaohong on 2018/4/12
 * @project patient-co-management
 * 体重标签转换器
 */
@Component
public class WeightConvert implements Convert{
    @Autowired
    private ConvertHelper convertHelper;
    @Override
    public List<SaveModel> convert(List<DataModel> modelList, 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.setId(MakeIDUtil.makeSaveModelID(dataModel,dataModel.getLabelValue()));
                    saveModel.setIdcard(dataModel.getIdcard());
                    saveModel.setLabelType(dict.getParentCode());
                    saveModel.setLabelCode(dict.getLabelCode());
                    saveModel.setLabelName(dict.getLabelName());
                    saveModel.setLabelValue(dataModel.getLabelValue() + "kg");
                    convertHelper.generateDataSource(dataModel,saveModel,sourceType,source);
                    if(StringUtils.isEmpty(saveModel.getSource())){
                         return new ArrayList<>();
                    }
                    saveModel.setCreateTime(DateFormatUtils.format(new Date(), ConstantUtil.date_format));
                    saveModels.add(saveModel);
                }
        return saveModels;
    }
}

+ 2 - 1
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/ESExtracter.java

@ -24,7 +24,8 @@ public class ESExtracter implements Extracter{
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    public List<DataModel> extractDataByJobConfigsql(String sql){
    @Override
    public List<DataModel> extractDataByJobConfigsql(String sql,String datasource){
        List<DataModel> saveModels = new ArrayList<>();
        List<Map<String,Object>> list = elasticsearchUtil.excuteDataModel(sql);
        for(Map<String,Object> tempMap:list){

+ 21 - 3
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/extract/MysqlExtracter.java

@ -1,6 +1,10 @@
package com.yihu.wlyy.figure.label.extract;
import com.yihu.wlyy.figure.label.model.DataModel;
import com.yihu.wlyy.figure.label.util.ConstantUtil;
import com.yihu.wlyy.figure.label.util.TimeUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -37,10 +41,16 @@ public class MysqlExtracter implements Extracter {
    @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
@ -51,7 +61,13 @@ public class MysqlExtracter implements Extracter {
            jdbcTemplate = templateMap.get("wlyy");
            return  getDataByThread(sql,jdbcTemplate);
        }
        jdbcTemplate = templateMap.get(datasource);
        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;
@ -82,13 +98,15 @@ public class MysqlExtracter implements Extracter {
                threadList.add(mutilThreadMysqlExtracter);
            }
            long start = System.currentTimeMillis();
            logger.info("start time:" + String.valueOf(start));
            String logTitle = "therad get data";
            TimeUtil.start(logger,logTitle,start);
            List<Future<List<DataModel>>> futureList = fixedThreadPool.invokeAll(threadList);
            //取回线程执行的结果
            for (Future future : futureList) {
                datas.addAll((List<DataModel>) future.get());
            }
            logger.info("coast time:" + String.valueOf(System.currentTimeMillis() - start));
            long finish = System.currentTimeMillis();
            TimeUtil.finish(logger,logTitle,start,finish);
        } catch (Exception e) {
            logger.error("MutilThreadMysqlExtracter call failed!");
        }finally {

+ 1 - 1
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Es2EsJob.java

@ -132,7 +132,7 @@ public class Es2EsJob implements Job {
     * 提取数据,按数据库中配置的增量条件提取
     */
    public void extract(){
        this.dataModelList = esExtracter.extractDataByJobConfigsql(this.finalSql);
        this.dataModelList = esExtracter.extractDataByJobConfigsql(this.finalSql,"");
    }
    /**

+ 2 - 0
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/job/Mysql2ESJob.java

@ -124,6 +124,7 @@ public class Mysql2ESJob implements Job {
        //1抽取数据
        String sql = this.flJobConfig.getSql();
        String sqlFiled = this.flJobConfig.getSqlField();
//        this.finalSql = getJobConfigSql(sql,sqlFiled,sqlFiledCondition,sqlFiledValue);
        this.finalSql = getFinalSql(sql,sqlFiled,sqlFiledCondition,sqlFiledValue);
    }
@ -131,6 +132,7 @@ public class Mysql2ESJob implements Job {
    /**
     * 提取数据,按数据库中配置的增量条件提取
     */
    public void extract(){
        this.dataModelList = mysqlExtracter.extractDataByJobConfigsql(this.finalSql,this.datasource);
    }

+ 15 - 28
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/model/DataModel.java

@ -8,11 +8,11 @@ public class DataModel {
    /**
     * 这些id用作记录数据来源,当有多个表时,记录多个表的id,并依据fl_job_config里的sourceTyep,source来区别
     */
    private int id;
    private int id1;
    private int id2;
    private int id3;
    private int id4;
    private Integer id;
    private Integer id1;
    private Integer id2;
    private Integer id3;
    private Integer id4;
    /**
     * 有些表的id为uuid,是string类型,所以为了兼容所有的,此种类型id命名为idstr,进行数据抽取时需多注意
@ -58,48 +58,43 @@ public class DataModel {
     */
    private String sourceTime;
    /**
     * 标签状态,eg:预约挂号-预约成功,预约失败
     */
    private String status;
    public int getId() {
    public Integer getId() {
        return id;
    }
    public void setId(int id) {
    public void setId(Integer id) {
        this.id = id;
    }
    public int getId1() {
    public Integer getId1() {
        return id1;
    }
    public void setId1(int id1) {
    public void setId1(Integer id1) {
        this.id1 = id1;
    }
    public int getId2() {
    public Integer getId2() {
        return id2;
    }
    public void setId2(int id2) {
    public void setId2(Integer id2) {
        this.id2 = id2;
    }
    public int getId3() {
    public Integer getId3() {
        return id3;
    }
    public void setId3(int id3) {
    public void setId3(Integer id3) {
        this.id3 = id3;
    }
    public int getId4() {
    public Integer getId4() {
        return id4;
    }
    public void setId4(int id4) {
    public void setId4(Integer id4) {
        this.id4 = id4;
    }
@ -191,14 +186,6 @@ public class DataModel {
        this.sourceTime = sourceTime;
    }
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    public String getLabelValue() {
        return labelValue;
    }

+ 13 - 9
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/model/SaveModel.java

@ -19,6 +19,11 @@ public class SaveModel implements Serializable{
     * 身份证
     */
    private String idcard;
    /**
     * 标签字典码
     */
    private String dictCode;
    /**
     * 标签类型
     */
@ -46,7 +51,6 @@ public class SaveModel implements Serializable{
    /**
     * 当前标签是否激活
     */
//    private boolean isCurrentActive;
    /**
     * 标签生成来源
@ -71,7 +75,6 @@ public class SaveModel implements Serializable{
        return labelType;
    }
    public String getId() {
        return id;
    }
@ -80,6 +83,14 @@ public class SaveModel implements Serializable{
        this.id = id;
    }
    public String getDictCode() {
        return dictCode;
    }
    public void setDictCode(String dictCode) {
        this.dictCode = dictCode;
    }
    public void setLabelType(String labelType) {
        this.labelType = labelType;
    }
@ -116,13 +127,6 @@ public class SaveModel implements Serializable{
        this.createTime = createTime;
    }
//    public boolean isCurrentActive() {
//        return isCurrentActive;
//    }
//    public void setCurrentActive(boolean currentActive) {
//        isCurrentActive = currentActive;
//    }
    public String getSource() {
        return source;
    }

+ 14 - 3
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/storage/Store2ES.java

@ -5,6 +5,10 @@ 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.util.ConstantUtil;
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.stereotype.Component;
@ -17,15 +21,22 @@ import java.util.List;
@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 = "start to loop(save) data,total size:" + modelList.size();
        TimeUtil.start(logger,logtitle,start);
        for(SaveModel saveModel:modelList){
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                String str =  objectMapper.writeValueAsString(saveModel);
                list.add(str);
@ -42,7 +53,7 @@ public class Store2ES implements Storager {
                elastricSearchHelper.saveBulkWithCustomId(ConstantUtil.figure_label_es_index, ConstantUtil.figure_label_es_type, list,"id");
            }
        }
        long finish = System.currentTimeMillis();
        TimeUtil.finish(logger,logtitle,start,finish);
    }
}

+ 43 - 0
patient-co/patient-co-figure-label/src/main/java/com/yihu/wlyy/figure/label/util/TimeUtil.java

@ -0,0 +1,43 @@
package com.yihu.wlyy.figure.label.util;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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(start, 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());
    }
}

+ 6 - 5
patient-co/patient-co-figure-label/src/main/resources/application-dev.yml

@ -15,14 +15,15 @@ spring:
      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.68:9300
#      ,172.19.103.45:9300, #多个逗号分割
      cluster-nodes-jest: http://172.19.103.68:9200
#      ,http://172.19.103.45:9200  #多个逗号分割
      cluster-nodes: http://11.1.2.28:9300,http://11.1.2.29:9300 # 172.19.103.45:9300,172.19.103.68:9300
      cluster-nodes-jest: http://11.1.2.28:9200,http://11.1.2.29:9200  # http://172.19.103.68:9200,http://172.19.103.45:9200  #多个逗号分割
      repositories:
        enabled: true
      properties: