LAPTOP-KB9HII50\70708 2 lat temu
rodzic
commit
6551d94851

+ 94 - 0
svr/svr-quota/doc/es/hlw_quota_test.txt

@ -0,0 +1,94 @@
查询索引
get http://172.26.0.56:9200/hlw_quota_test
创建索引
PUT http://172.26.0.56:9200/hlw_quota_test
{
    "mappings" :{
        "properties":{
            "deptName":{
                "type":"text"
            },
            "city":{
                "type":"text"
            },
            "slaveKey4Name":{
                "type":"text"
            },
            "doctorName":{
                "type":"text"
            },
            "cityName":{
                "type":"text"
            },
            "areaLevel":{
                "type":"text"
            },
            "id":{
                "type":"text"
            },
            "hospital":{
                "type":"text"
            },
            "slaveKey3Name":{
                "type":"text"
            },
            "quotaDate":{
                "type":"date"
            },
            "quotaCode":{
                "type":"keyword"
            },
          "quotaName" : {
            "type" : "keyword"
          },
            "result2":{
                "type":"double"
            },
            "result1":{
                "type":"double"
            },
            "slaveKey1":{
                "type":"text"
            },
            "slaveKey2":{
                "type":"text"
            },
            "townName":{
                "type":"text"
            },
            "slaveKey3":{
                "type":"text"
            },
            "slaveKey4":{
                "type":"text"
            },
            "town":{
                "type":"text"
            },
            "slaveKey2Name":{
                "type":"text"
            },
            "timeLevel":{
                "type":"text"
            },
            "dept":{
                "type":"text"
            },
            "hospitalName":{
                "type":"text"
            },
            "doctor":{
                "type":"text"
            },
            "createTime":{
                "type":"date"
            },
            "slaveKey1Name":{
                "type":"text"
            }
        }
    }
}

+ 24 - 1
svr/svr-quota/src/main/java/com/yihu/jw/quota/controller/JobController.java

@ -1,7 +1,8 @@
package com.yihu.jw.quota.controller;
import com.yihu.jw.quota.service.job.JobService;
import com.yihu.jw.elasticsearch.ElasticSearch7Util;
import com.yihu.jw.quota.constants.ServiceApi;
import com.yihu.jw.quota.service.job.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -12,6 +13,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
 * 指标任务控制
@ -25,6 +30,24 @@ public class JobController extends BaseController {
    @Autowired
    private JobService jobService;
    @Resource
    private ElasticSearch7Util elasticSearch7Util;
    @ApiOperation(value = "初始执行指标")
    @RequestMapping(value = "getEsBySql", method = RequestMethod.GET)
    public boolean getEsBySql(
            @ApiParam(name = "id", value = "指标ID", required = true)
            @RequestParam(value = "id", required = true) Long id) {
        try {
            String sql = "select * from hlw_quota_test";
            List<Map<String,Object>> list = elasticSearch7Util.executeSQL(sql);
            return true;
        } catch (Exception e) {
            error(e);
            invalidUserException(e, -1, "初始执行指标发生异常:" + e.getMessage());
            return false;
        }
    }
    /**
     * 初始执行指标

+ 5 - 0
svr/svr-quota/src/main/java/com/yihu/jw/quota/etl/Contant.java

@ -55,6 +55,7 @@ public class Contant {
        public static final String area_town = "7";//行政区划 区县
        public static final String area_org = "8";//行政区划 机构
        public static final String area_dept = "9";//科室
        public static final String area_doctor = "10";//医生
    }
    public static class quota {
@ -77,6 +78,7 @@ public class Contant {
        public static final String area_town = "3";//行政区划 区县
        public static final String area_org = "4";//行政区划 机构
        public static final String area_dept = "5";//行政区划 科室
        public static final String area_doctor = "6";//行政区划 医生
        public static String getAreaLevelByMainDimension(String key) {
            switch (key) {
@ -95,6 +97,9 @@ public class Contant {
                case main_dimension.area_dept: {
                    return area_dept;
                }
                case main_dimension.area_doctor: {
                    return area_doctor;
                }
            }
            return "";
        }

+ 15 - 0
svr/svr-quota/src/main/java/com/yihu/jw/quota/etl/extract/ExtractUtil.java

@ -35,6 +35,7 @@ public class ExtractUtil {
    private static String main_town = "twon";
    private static String main_org = "org";
    private static String main_dept = "dept";
    private static String main_doctor = "doctor";
    private static String main_year = "year";
    private static String slave_sex = "sex";
    private static String slave_age = "age";
@ -70,6 +71,7 @@ public class ExtractUtil {
        Map<String,String> orgDictMap = new HashMap<>();
        Map<String,String> deptDictMap = new HashMap<>();
        Map<String,String> yearDictMap = new HashMap<>();
        Map<String,String> doctorDictMap = new HashMap<>();
        Map<String,String> slave1DictMap = new HashMap<>();
        Map<String,String> slave2DictMap = new HashMap<>();
        Map<String,String> slave3DictMap = new HashMap<>();
@ -84,6 +86,9 @@ public class ExtractUtil {
            if(saveModel.getDept() != null){
                deptDictMap.put(saveModel.getDept(), saveModel.getDeptName());
            }
            if(saveModel.getDoctor() != null){
                doctorDictMap.put(saveModel.getDoctor(), saveModel.getDoctorName());
            }
            if(saveModel.getYear() != null){
                yearDictMap.put(saveModel.getYear(), saveModel.getYearName());
            }
@ -133,6 +138,9 @@ public class ExtractUtil {
                            saveModel.setDeptName(deptDictMap.get(value));
                            saveModel.setDept(value);
                        }
                    }else if(main.getMainCode().equals(main_doctor) && !StringUtils.isEmpty(doctorDictMap.get(value))){
                        saveModel.setDoctorName(doctorDictMap.get(value));
                        saveModel.setDoctor(value);
                    }
                }
            }
@ -574,6 +582,13 @@ public class ExtractUtil {
                });
                break;
            }
            case Contant.main_dimension.area_doctor: {
                //设置医生
                dictData.stream().forEach(one -> {
                    setOneData(allData, one.getDoctor(), one, Contant.main_dimension_areaLevel.area_doctor);
                });
                break;
            }
            case Contant.main_dimension.time_year: {
                //设置年份
                dictData.stream().forEach(one -> {

+ 7 - 6
svr/svr-quota/src/main/java/com/yihu/jw/quota/etl/save/es/ElastricSearchSave.java

@ -1,19 +1,18 @@
package com.yihu.jw.quota.etl.save.es;
import com.alibaba.fastjson.JSON;
import com.yihu.jw.quota.etl.Contant;
import com.yihu.jw.quota.etl.model.EsConfig;
import com.yihu.jw.quota.etl.save.LargDataWithRunnable;
import com.yihu.jw.quota.vo.SaveModel;
import io.searchbox.client.JestClient;
import io.searchbox.core.Bulk;
import io.searchbox.core.BulkResult;
import io.searchbox.core.Index;
import net.sf.json.JSONObject;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
@ -100,7 +99,7 @@ public class ElastricSearchSave {
                    for (SaveModel obj : newList) {
                        obj.setCreateTime( new Date());
                        IndexRequest indexRequest = new IndexRequest(esConfig.getIndex());
                        indexRequest.source(obj);
                        indexRequest.source(JSON.toJSONString(obj), XContentType.JSON);
                        bulkRequest.add(indexRequest);
                    }
                    br = restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT) ;
@ -111,10 +110,11 @@ public class ElastricSearchSave {
            }else{
                //得到链接
                BulkRequest request = new BulkRequest();
                request.timeout(TimeValue.timeValueSeconds(10));
                for (SaveModel obj : smss) {
                    obj.setCreateTime( new Date());
                    IndexRequest indexRequest = new IndexRequest(esConfig.getIndex());
                    indexRequest.source(obj);
                    indexRequest.source(JSON.toJSONString(obj), XContentType.JSON);
                    request.add(indexRequest);
                }
                br = restHighLevelClient.bulk(request,RequestOptions.DEFAULT);
@ -124,6 +124,7 @@ public class ElastricSearchSave {
            }
            return isSuccessed;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("ES 保存数据异常"+ e.getMessage());
        }
    }