Sfoglia il codice sorgente

数据清洗至Es、总体分析咨询量bug

zd_123 7 anni fa
parent
commit
c4521f6b86

+ 8 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statisticsES/StatisticsESService.java

@ -378,8 +378,14 @@ public class StatisticsESService {
        }
        Collections.sort(resultList, new Comparator<Map<String, Object>>() {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                long map1value = (long) o1.get("amount");
                long map2value = (long) o2.get("amount");
                long map1value = 0L;
                long map2value = 0L;
                if(o1.get("amount")!=null && o1.get("amount")+""!=""){
                     map1value = Long.valueOf(String.valueOf(o1.get("amount")));
                }
                if(o2.get("amount")!=null && o2.get("amount")+""!=""){
                    map2value = Long.valueOf(String.valueOf(o2.get("amount")));
                }
                if (map1value - map2value > 0) {
                    return sort == 1 ? -1 : 1;

+ 3 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/EsStatisticsController.java

@ -273,12 +273,13 @@ public class EsStatisticsController extends BaseController {
            /**旧版统计代码start**/
            //未回复-22 到达量
            JSONArray jsonArray2 = null;
            if (DateUtil.getYear(endDate, "yyyy-MM-dd").equals(year)) {
            /*if (DateUtil.getYear(endDate, "yyyy-MM-dd").equals(year)) {
                jsonArray2 = statisticsESService.getLowLevelIncrementDetail(endDate, endDate, area, level, indexes[1], sort, lowLevel);
            } else {
                String date = Integer.valueOf(year) + 1 + "-06-30";
                jsonArray2 = statisticsESService.getLowLevelIncrementDetail(date, date, area, level, indexes[1], sort, lowLevel);
            }
            }*/
            jsonArray2 = statisticsESService.getLowLevelIncrementDetail(endDate, endDate, area, level, indexes[1], sort, lowLevel);
            jsonArrays.add(jsonArray2);
            /**旧版统计代码end**/

+ 98 - 26
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/service/EduArticleService.java

@ -4,6 +4,7 @@ package com.yihu.wlyy.web.third.jkedu.service;
import com.yihu.edu.entity.dataClean.*;
import com.yihu.es.entity.HealthEduArticleES;
import com.yihu.es.entity.HealthEduArticleESResult;
import com.yihu.wlyy.config.es.ElasticFactory;
import com.yihu.wlyy.config.es.ElastricSearchSave;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
@ -21,9 +22,16 @@ import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.util.MapListUtils;
import com.yihu.wlyy.util.SpringUtil;
import com.yihu.wlyy.web.third.jkedu.vo.save.SaveEduArticleHelper;
import io.searchbox.client.JestClient;
import io.searchbox.core.*;
import org.apache.axis.utils.Admin;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -41,6 +49,8 @@ import java.util.*;
@Service
@Transactional(rollbackFor = Exception.class)
public class EduArticleService {
    private Logger logger = LoggerFactory.getLogger(EduArticleService.class);
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
@ -59,6 +69,8 @@ public class EduArticleService {
    private JkeduBehaviorArticleDao jkeduBehaviorArticleDao;
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    @Autowired
    private ElasticFactory elasticFactory;
    @Value("${es.type.HealthEduArticlePatient}")
    private String esType;
@ -103,7 +115,6 @@ public class EduArticleService {
                            NewArticleModel newArticleModel = new NewArticleModel();
                            //转换数据
                            oldArticleModel = MapListUtils.convertMap2Bean(map,OldArticleModel.class);
                            //@// TODO: 2017/12/25 完善数据
                            BeanUtils.copyProperties(oldArticleModel,newArticleModel);
                            newArticleModel.setArticleOrder(99);
                            newArticleModel.setArticleState(1);
@ -117,8 +128,8 @@ public class EduArticleService {
                            newArticleModel.setAuthenticationId(wjwCode);
                            newArticleModel.setIsAuthentication(1);
                            newArticleModel.setArticleType("2");
                            newArticleModel.setOperatorRoleCode("管理员code");
                            newArticleModel.setOperatorRoleLevel("管理员");
                            newArticleModel.setOperatorRoleCode("350200");
                            newArticleModel.setOperatorRoleLevel("2");
                            newArticleModel.setRoleType(2);
                            newArticleModel.setUserScope(1);
                            newArticleModel.setIsOld(1);
@ -305,7 +316,6 @@ public class EduArticleService {
                    articleMap.put(healthEduArticle.getCode(),healthEduArticle);
                }
            }
            String BartchNoSql ="";
            //获取所有的健康教育发送记录数量,分页,userType=1
            String countSql = "SELECT COUNT(id) AS num from wlyy_health_edu_article_patient WHERE admin_team_code IS NOT NULL";
            if (StringUtils.isNotBlank(startTimeForSql)){
@ -333,7 +343,6 @@ public class EduArticleService {
                            " LEFT JOIN wlyy_admin_team t ON ap.admin_team_code = t.id" +
                            " WHERE " +
                            " ap.admin_team_code IS NOT NULL ";
                    BartchNoSql = resultSql;
                    if (StringUtils.isNotBlank(startTimeForSql)){
                        resultSql += " AND ap.czrq > '"+startTimeForSql+"'ORDER BY ap.czrq ASC limit ?,?";
                    }else {
@ -366,29 +375,54 @@ public class EduArticleService {
                        saveDate(esList);
                    }
                }
                //按批次查询文章信息。userType=2
                //每次执行前把之前的
                 BartchNoSql +=" GROUP BY ap.batch_no ORDER BY ap.czrq ASC";
                List<Map<String,Object>> batchList = jdbcTemplate.queryForList(BartchNoSql);
                List<HealthEduArticleES> batchEsList = new ArrayList<>();
                if (batchList!=null && batchList.size()>0){
                    for (Map<String, Object> map : batchList) {
                        HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
                        //Map转对象
                        healthEduArticleES = MapListUtils.convertMap2Bean(map,HealthEduArticleES.class);
                        healthEduArticleES = setDateToObj(healthEduArticleES,doctorMap,articleMap,wjwCode,2);
                        if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())){
                            healthEduArticleES.setDoctorCode(wjwCode);
                            //卫计委发送
                            healthEduArticleES.setSendType(2);
                            healthEduArticleES.setSendName("厦门市卫生与计划生育委员会");
                            healthEduArticleES.setDoctorName("厦门市卫生与计划生育委员会");
                        }
                        batchEsList.add(healthEduArticleES);
            }
            //按批次查询文章信息。userType=2
            //要先删除原来的数据。
            String batSql ="SELECT batch_no from wlyy_health_edu_article_patient WHERE admin_team_code IS NOT NULL GROUP BY batch_no ";
            List<Map<String,Object>> batchNoMap = jdbcTemplate.queryForList(batSql);
            if (batchNoMap!=null && batchNoMap.size()>0){
                for (Map<String,Object> map : batchNoMap){
                    deleteData(2,map.get("batch_no")+"");
                }
            }
            String BartchNoSql = "SELECT " +
                    " ap.patient AS patientCode, " +
                    " ap.article AS articleId, " +
                    " ap.doctor AS doctorCode, " +
                    " ap.is_read AS isRead, " +
                    " ap.czrq AS createTime, " +
                    " ap.admin_team_code AS adminTeamCode, " +
                    " ap.batch_no AS batchNo, " +
                    " ap.send_type AS sendSource,"+
                    " p.name AS patientName,"+
                    " t.name AS adminTeamName"+
                    " FROM " +
                    " wlyy_health_edu_article_patient ap " +
                    " LEFT JOIN wlyy_patient p ON ap.patient = p.code " +
                    " LEFT JOIN wlyy_admin_team t ON ap.admin_team_code = t.id" +
                    " WHERE " +
                    " ap.admin_team_code IS NOT NULL GROUP BY ap.batch_no ORDER BY ap.czrq ASC";
            List<Map<String,Object>> batchList = jdbcTemplate.queryForList(BartchNoSql);
            List<HealthEduArticleES> batchEsList = new ArrayList<>();
            if (batchList!=null && batchList.size()>0){
                for (Map<String, Object> map : batchList) {
                    HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
                    healthEduArticleES.setNewArricleFlag(false);
                    //Map转对象
                    healthEduArticleES = MapListUtils.convertMap2Bean(map,HealthEduArticleES.class);
                    healthEduArticleES = setDateToObj(healthEduArticleES,doctorMap,articleMap,wjwCode,2);
                    if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())){
                        healthEduArticleES.setDoctorCode(wjwCode);
                        //卫计委发送
                        healthEduArticleES.setSendType(2);
                        healthEduArticleES.setSendName("厦门市卫生与计划生育委员会");
                        healthEduArticleES.setDoctorName("厦门市卫生与计划生育委员会");
                    }
                    //保存到Es中
                    saveDate(batchEsList);
                    batchEsList.add(healthEduArticleES);
                }
                //保存到Es中
                saveDate(batchEsList);
            }
        }catch (Exception e){
            e.printStackTrace();
@ -501,6 +535,44 @@ public class EduArticleService {
    private Boolean saveDate(List<HealthEduArticleES> sms)throws Exception {
        return SpringUtil.getBean(SaveEduArticleHelper.class).save(sms);
    }
    /**
     * 删除数据
     */
    private void deleteData(int userType,String batchNo) {
        JestClient jestClient = null;
        try {
            jestClient = elasticFactory.getJestClient();
            //先根据条件查找出来
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolQueryBuilder =  new BoolQueryBuilder();
            boolQueryBuilder.must(QueryBuilders.matchQuery("userType",userType));
            boolQueryBuilder.must(QueryBuilders.matchQuery("batchNo",batchNo));
            searchSourceBuilder.query(boolQueryBuilder).size(100);//一次取10000条
            Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
                    .build();
            SearchResult result = jestClient.execute(search);
            List<HealthEduArticleES> saveModels = result.getSourceAsObjectList(HealthEduArticleES.class);
            //根据id批量删除
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            for (HealthEduArticleES obj : saveModels) {
                Delete index = new Delete.Builder(obj.getId()).build();
                bulk.addAction(index);
            }
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("delete data count:" + saveModels.size());
            logger.info("delete flag:" + br.isSucceeded());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
    }
    @Transactional
    public void save(){
        NewArticleModel newArticleModel = new NewArticleModel();