|  | @ -10,6 +10,8 @@ import com.yihu.wlyy.config.es.ElastricSearchSave;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.doctor.profile.Doctor;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.education.HealthEduArticle;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.education.HealthEduArticleDoctor;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.education.HealthEduArticlePatient;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.Patient;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.jkedu.repository.JkeduArticleDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.jkedu.repository.JkeduBehaviorArticleDao;
 | 
	
	
		
			
				|  | @ -22,10 +24,12 @@ import com.yihu.wlyy.util.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.ElasticsearchUtil;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.MapListUtils;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.SpringUtil;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.web.third.gateway.service.GcLabelService;
 | 
	
		
			
				|  |  | 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.list.AbstractLinkedList;
 | 
	
		
			
				|  |  | import org.apache.commons.collections.map.HashedMap;
 | 
	
		
			
				|  |  | import org.apache.commons.lang.StringUtils;
 | 
	
		
			
				|  |  | import org.elasticsearch.action.update.UpdateRequest;
 | 
	
	
		
			
				|  | @ -38,6 +42,7 @@ import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.hateoas.alps.Doc;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
	
		
			
				|  | @ -73,6 +78,9 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |     private ElasticsearchUtil elasticsearchUtil;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ElasticFactory elasticFactory;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private GcLabelService gcLabelService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Value("${es.type.HealthEduArticlePatient}")
 | 
	
		
			
				|  |  |     private String esType;
 | 
	
	
		
			
				|  | @ -83,9 +91,10 @@ public class EduArticleService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 健康教育文章列表转移
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public boolean getArticleListToNewDataBase(){
 | 
	
		
			
				|  |  |     public boolean getArticleListToNewDataBase() {
 | 
	
		
			
				|  |  |         boolean flag = true;
 | 
	
		
			
				|  |  |         //获取卫计委code
 | 
	
		
			
				|  |  |         String wjwSql = "select code AS wjwCode from wlyy_role WHERE  name LIKE '%厦门市卫生与计划生育委员会%' and LENGTH(code)=6";
 | 
	
	
		
			
				|  | @ -93,31 +102,31 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |         String wjwCode = result.get("wjwCode") + "";
 | 
	
		
			
				|  |  |         //先将原来数据库的数据删除
 | 
	
		
			
				|  |  |         List<NewArticleModel> delOldList = jkeduArticleDao.findOldArticle();
 | 
	
		
			
				|  |  |         if (delOldList!=null && delOldList.size()>0){
 | 
	
		
			
				|  |  |         if (delOldList != null && delOldList.size() > 0) {
 | 
	
		
			
				|  |  |             jkeduArticleDao.delete(delOldList);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //分页查询,执行插入
 | 
	
		
			
				|  |  |         String countSql = "select COUNT(1) AS num from wlyy_health_edu_article";
 | 
	
		
			
				|  |  |         Map<String,Object> countMap = jdbcTemplate.queryForMap(countSql);
 | 
	
		
			
				|  |  |         if (countMap!=null){
 | 
	
		
			
				|  |  |         Map<String, Object> countMap = jdbcTemplate.queryForMap(countSql);
 | 
	
		
			
				|  |  |         if (countMap != null) {
 | 
	
		
			
				|  |  |             int count = Integer.valueOf(String.valueOf(countMap.get("num")));
 | 
	
		
			
				|  |  |             double pageCount = Math.ceil(Double.valueOf(count)/Double.valueOf(pageSize));
 | 
	
		
			
				|  |  |             if (pageCount>0){
 | 
	
		
			
				|  |  |                 String  sql ="SELECT code AS ArticleId,title AS ArticleTitle,summary AS Summary,content AS ArticleContent, " +
 | 
	
		
			
				|  |  |             double pageCount = Math.ceil(Double.valueOf(count) / Double.valueOf(pageSize));
 | 
	
		
			
				|  |  |             if (pageCount > 0) {
 | 
	
		
			
				|  |  |                 String sql = "SELECT code AS ArticleId,title AS ArticleTitle,summary AS Summary,content AS ArticleContent, " +
 | 
	
		
			
				|  |  |                         "url AS URL, czrq AS InsertTime, czrq AS UpdateTime,whea_type AS FirstLevelCategoryId," +
 | 
	
		
			
				|  |  |                         " keyword AS KeyWord FROM wlyy_health_edu_article limit ?,?";
 | 
	
		
			
				|  |  |                 for (int i = 1;i<=pageCount;i++){
 | 
	
		
			
				|  |  |                     int start = (i-1)*pageSize;
 | 
	
		
			
				|  |  |                 for (int i = 1; i <= pageCount; i++) {
 | 
	
		
			
				|  |  |                     int start = (i - 1) * pageSize;
 | 
	
		
			
				|  |  |                     //分页查询数据
 | 
	
		
			
				|  |  |                     List<Map<String,Object>>  list = jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
 | 
	
		
			
				|  |  |                     List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, new Object[]{start, pageSize});
 | 
	
		
			
				|  |  |                     List<NewArticleModel> newList = new ArrayList<>();
 | 
	
		
			
				|  |  |                     try {
 | 
	
		
			
				|  |  |                         for (Map<String, Object> map : list) {
 | 
	
		
			
				|  |  |                             OldArticleModel oldArticleModel = new OldArticleModel();
 | 
	
		
			
				|  |  |                             NewArticleModel newArticleModel = new NewArticleModel();
 | 
	
		
			
				|  |  |                             //转换数据
 | 
	
		
			
				|  |  |                             oldArticleModel = MapListUtils.convertMap2Bean(map,OldArticleModel.class);
 | 
	
		
			
				|  |  |                             BeanUtils.copyProperties(oldArticleModel,newArticleModel);
 | 
	
		
			
				|  |  |                             oldArticleModel = MapListUtils.convertMap2Bean(map, OldArticleModel.class);
 | 
	
		
			
				|  |  |                             BeanUtils.copyProperties(oldArticleModel, newArticleModel);
 | 
	
		
			
				|  |  |                             newArticleModel.setArticleOrder(99);
 | 
	
		
			
				|  |  |                             newArticleModel.setArticleState(1);
 | 
	
		
			
				|  |  |                             newArticleModel.setOrgName("厦门市卫生与计划生育委员会");
 | 
	
	
		
			
				|  | @ -139,7 +148,7 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         //执行插入新数据库
 | 
	
		
			
				|  |  |                         jkeduArticleDao.save(newList);
 | 
	
		
			
				|  |  |                     }catch (Exception e){
 | 
	
		
			
				|  |  |                     } catch (Exception e) {
 | 
	
		
			
				|  |  |                         e.printStackTrace();
 | 
	
		
			
				|  |  |                         flag = false;
 | 
	
		
			
				|  |  |                     }
 | 
	
	
		
			
				|  | @ -153,9 +162,10 @@ public class EduArticleService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 健康教育收藏列表转移
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public boolean getArticleCollectToNewDataBase(){
 | 
	
		
			
				|  |  |     public boolean getArticleCollectToNewDataBase() {
 | 
	
		
			
				|  |  |         boolean flag = true;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             //获取卫计委code
 | 
	
	
		
			
				|  | @ -164,14 +174,14 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |             String wjwCode = result.get("wjwCode") + "";
 | 
	
		
			
				|  |  |             //先将原来数据库的数据删除
 | 
	
		
			
				|  |  |             List<Integer> delOldList = jkeduCollectionArticleDao.findOldArticleCollection();
 | 
	
		
			
				|  |  |             if (delOldList!=null && delOldList.size()>0){
 | 
	
		
			
				|  |  |             if (delOldList != null && delOldList.size() > 0) {
 | 
	
		
			
				|  |  |                 int count = 1;
 | 
	
		
			
				|  |  |                 double num = Math.ceil(Double.valueOf(delOldList.size())/1000.0);
 | 
	
		
			
				|  |  |                 for (int i=0;i<num;i++){
 | 
	
		
			
				|  |  |                 double num = Math.ceil(Double.valueOf(delOldList.size()) / 1000.0);
 | 
	
		
			
				|  |  |                 for (int i = 0; i < num; i++) {
 | 
	
		
			
				|  |  |                     List idsList = new ArrayList<>();
 | 
	
		
			
				|  |  |                     for (int j =0;j<1000;j++){
 | 
	
		
			
				|  |  |                         if (count<=delOldList.size()){
 | 
	
		
			
				|  |  |                             idsList.add(delOldList.get(j+i*1000));
 | 
	
		
			
				|  |  |                     for (int j = 0; j < 1000; j++) {
 | 
	
		
			
				|  |  |                         if (count <= delOldList.size()) {
 | 
	
		
			
				|  |  |                             idsList.add(delOldList.get(j + i * 1000));
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         count++;
 | 
	
		
			
				|  |  |                     }
 | 
	
	
		
			
				|  | @ -179,13 +189,13 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             //先分页查询
 | 
	
		
			
				|  |  |             String countSql ="select COUNT(1) AS num from wlyy_health_edu_article_doctor";
 | 
	
		
			
				|  |  |             Map<String,Object> countMap = jdbcTemplate.queryForMap(countSql);
 | 
	
		
			
				|  |  |             if (countMap!=null){
 | 
	
		
			
				|  |  |             String countSql = "select COUNT(1) AS num from wlyy_health_edu_article_doctor";
 | 
	
		
			
				|  |  |             Map<String, Object> countMap = jdbcTemplate.queryForMap(countSql);
 | 
	
		
			
				|  |  |             if (countMap != null) {
 | 
	
		
			
				|  |  |                 int count = Integer.valueOf(String.valueOf(countMap.get("num")));
 | 
	
		
			
				|  |  |                 double pageCount = Math.ceil(Double.valueOf(count)/Double.valueOf(pageSize));
 | 
	
		
			
				|  |  |                 if (pageCount>0) {
 | 
	
		
			
				|  |  |                     String  sql ="SELECT" +
 | 
	
		
			
				|  |  |                 double pageCount = Math.ceil(Double.valueOf(count) / Double.valueOf(pageSize));
 | 
	
		
			
				|  |  |                 if (pageCount > 0) {
 | 
	
		
			
				|  |  |                     String sql = "SELECT" +
 | 
	
		
			
				|  |  |                             " ad.doctor AS UserId," +
 | 
	
		
			
				|  |  |                             " ad.article AS ArticleId, " +
 | 
	
		
			
				|  |  |                             " ad.url, " +
 | 
	
	
		
			
				|  | @ -200,13 +210,13 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |                     for (int i = 1; i <= pageCount; i++) {
 | 
	
		
			
				|  |  |                         int start = (i - 1) * pageSize;
 | 
	
		
			
				|  |  |                         //分页查询数据
 | 
	
		
			
				|  |  |                         List<Map<String,Object>>  list = jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
 | 
	
		
			
				|  |  |                         List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, new Object[]{start, pageSize});
 | 
	
		
			
				|  |  |                         for (Map<String, Object> map : list) {
 | 
	
		
			
				|  |  |                             OldArticleCollectModel oldArticleCollectModel = new OldArticleCollectModel();
 | 
	
		
			
				|  |  |                             NewArticleCollectModel newArticleCollectModel = new NewArticleCollectModel();
 | 
	
		
			
				|  |  |                             oldArticleCollectModel = MapListUtils.convertMap2Bean(map,OldArticleCollectModel.class);
 | 
	
		
			
				|  |  |                             oldArticleCollectModel = MapListUtils.convertMap2Bean(map, OldArticleCollectModel.class);
 | 
	
		
			
				|  |  |                             //@// TODO: 2017/12/25 完善数据
 | 
	
		
			
				|  |  |                             BeanUtils.copyProperties(oldArticleCollectModel,newArticleCollectModel);
 | 
	
		
			
				|  |  |                             BeanUtils.copyProperties(oldArticleCollectModel, newArticleCollectModel);
 | 
	
		
			
				|  |  |                             newArticleCollectModel.setUserType(1);
 | 
	
		
			
				|  |  |                             newArticleCollectModel.setOrgName("厦门市卫生与计划生育委员会");
 | 
	
		
			
				|  |  |                             newArticleCollectModel.setOrgId(wjwCode);
 | 
	
	
		
			
				|  | @ -218,7 +228,7 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             flag = false;
 | 
	
		
			
				|  |  |         }
 | 
	
	
		
			
				|  | @ -227,22 +237,23 @@ public class EduArticleService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 转移健康教育行为
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public boolean getArticleBehaviorToNewDataBase(){
 | 
	
		
			
				|  |  |     public boolean getArticleBehaviorToNewDataBase() {
 | 
	
		
			
				|  |  |         boolean flag = true;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             //数量也许过大,分批次删除
 | 
	
		
			
				|  |  |             //先将原来数据库的数据删除
 | 
	
		
			
				|  |  |             List<NewArticleBehaviorModel> delOldList = jkeduBehaviorArticleDao.findOldArticleBehavior();
 | 
	
		
			
				|  |  |             if (delOldList!=null && delOldList.size()>0){
 | 
	
		
			
				|  |  |             if (delOldList != null && delOldList.size() > 0) {
 | 
	
		
			
				|  |  |                 int count = 1;
 | 
	
		
			
				|  |  |                 double num = Math.ceil(Double.valueOf(delOldList.size())/1000.0);
 | 
	
		
			
				|  |  |                 for (int i=0;i<num;i++){
 | 
	
		
			
				|  |  |                 double num = Math.ceil(Double.valueOf(delOldList.size()) / 1000.0);
 | 
	
		
			
				|  |  |                 for (int i = 0; i < num; i++) {
 | 
	
		
			
				|  |  |                     List idsList = new ArrayList<>();
 | 
	
		
			
				|  |  |                     for (int j =0;j<1000;j++){
 | 
	
		
			
				|  |  |                         if (count<=delOldList.size()){
 | 
	
		
			
				|  |  |                             idsList.add(delOldList.get(j+i*1000).getID());
 | 
	
		
			
				|  |  |                     for (int j = 0; j < 1000; j++) {
 | 
	
		
			
				|  |  |                         if (count <= delOldList.size()) {
 | 
	
		
			
				|  |  |                             idsList.add(delOldList.get(j + i * 1000).getID());
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         count++;
 | 
	
		
			
				|  |  |                     }
 | 
	
	
		
			
				|  | @ -251,25 +262,25 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             //分批次查询
 | 
	
		
			
				|  |  |             String countSql = "select COUNT(1) AS num from wlyy_health_edu_article_op_history";
 | 
	
		
			
				|  |  |             Map<String,Object> countMap = jdbcTemplate.queryForMap(countSql);
 | 
	
		
			
				|  |  |             if (countMap!=null) {
 | 
	
		
			
				|  |  |             Map<String, Object> countMap = jdbcTemplate.queryForMap(countSql);
 | 
	
		
			
				|  |  |             if (countMap != null) {
 | 
	
		
			
				|  |  |                 int count = Integer.valueOf(String.valueOf(countMap.get("num")));
 | 
	
		
			
				|  |  |                 double pageCount = Math.ceil(Double.valueOf(count) / Double.valueOf(pageSize));
 | 
	
		
			
				|  |  |                 if (pageCount > 0) {
 | 
	
		
			
				|  |  |                     String  sql ="SELECT code AS ArticleId, status AS BehaviorAction,creater AS UserId," +
 | 
	
		
			
				|  |  |                     String sql = "SELECT code AS ArticleId, status AS BehaviorAction,creater AS UserId," +
 | 
	
		
			
				|  |  |                             " created_time AS InsertTime FROM wlyy_health_edu_article_op_history limit ?,?";
 | 
	
		
			
				|  |  |                     List<NewArticleBehaviorModel> newList = new ArrayList<>();
 | 
	
		
			
				|  |  |                     //分页查询
 | 
	
		
			
				|  |  |                     for (int i = 1; i <= pageCount; i++) {
 | 
	
		
			
				|  |  |                         int start = (i - 1) * pageSize;
 | 
	
		
			
				|  |  |                         List<Map<String,Object>>  list = jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
 | 
	
		
			
				|  |  |                         List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, new Object[]{start, pageSize});
 | 
	
		
			
				|  |  |                         for (Map<String, Object> map : list) {
 | 
	
		
			
				|  |  |                             OldArticleBehaviorModel oldArticleBehaviorModel = new OldArticleBehaviorModel();
 | 
	
		
			
				|  |  |                             NewArticleBehaviorModel newArticleBehaviorModel = new NewArticleBehaviorModel();
 | 
	
		
			
				|  |  |                             oldArticleBehaviorModel = MapListUtils.convertMap2Bean(map,OldArticleBehaviorModel.class);
 | 
	
		
			
				|  |  |                             oldArticleBehaviorModel = MapListUtils.convertMap2Bean(map, OldArticleBehaviorModel.class);
 | 
	
		
			
				|  |  |                             //@// TODO: 2017/12/25 完善数据
 | 
	
		
			
				|  |  |                             BeanUtils.copyProperties(oldArticleBehaviorModel,newArticleBehaviorModel);
 | 
	
		
			
				|  |  |                             if (newArticleBehaviorModel.getBehaviorAction()==1){
 | 
	
		
			
				|  |  |                             BeanUtils.copyProperties(oldArticleBehaviorModel, newArticleBehaviorModel);
 | 
	
		
			
				|  |  |                             if (newArticleBehaviorModel.getBehaviorAction() == 1) {
 | 
	
		
			
				|  |  |                                 newArticleBehaviorModel.setBehaviorAction(5);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                             newArticleBehaviorModel.setIsOld(1);
 | 
	
	
		
			
				|  | @ -280,7 +291,7 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             flag = false;
 | 
	
		
			
				|  |  |         }
 | 
	
	
		
			
				|  | @ -289,44 +300,45 @@ public class EduArticleService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 数据转移至Es.
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public boolean getArticleSendedListToEs(){
 | 
	
		
			
				|  |  |     public boolean getArticleSendedListToEs() {
 | 
	
		
			
				|  |  |         boolean flag = true;
 | 
	
		
			
				|  |  |         try{
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             //获取卫计委code
 | 
	
		
			
				|  |  |             String sql = "select code AS wjwCode from wlyy_role WHERE  name LIKE '%厦门市卫生与计划生育委员会%' and LENGTH(code)=6";
 | 
	
		
			
				|  |  |             Map<String, Object> result = jdbcTemplate.queryForMap(sql);
 | 
	
		
			
				|  |  |             String wjwCode = result.get("wjwCode") + "";
 | 
	
		
			
				|  |  |             //查询es最大的时间记录
 | 
	
		
			
				|  |  |             String timeSql ="select createTime from "+esType+" order by createTime desc limit 0,1";
 | 
	
		
			
				|  |  |             HealthEduArticleESResult healthEduArticleESResult = (HealthEduArticleESResult)elasticsearchUtil.excuteOneObject(timeSql,HealthEduArticleESResult.class,esType,esIndex);
 | 
	
		
			
				|  |  |             String startTimeForSql = DateUtil.dateToStr(healthEduArticleESResult.getCreateTime(),"yyyy-MM-dd HH:mm:ss");
 | 
	
		
			
				|  |  |             String timeSql = "select createTime from " + esType + " order by createTime desc limit 0,1";
 | 
	
		
			
				|  |  |             HealthEduArticleESResult healthEduArticleESResult = (HealthEduArticleESResult) elasticsearchUtil.excuteOneObject(timeSql, HealthEduArticleESResult.class, esType, esIndex);
 | 
	
		
			
				|  |  |             String startTimeForSql = DateUtil.dateToStr(healthEduArticleESResult.getCreateTime(), "yyyy-MM-dd HH:mm:ss");
 | 
	
		
			
				|  |  |             //查询出所有的医生
 | 
	
		
			
				|  |  |             List<Doctor> doctorList = doctorDao.findAllCertifiedDoctors();
 | 
	
		
			
				|  |  |             Map<String,Doctor> doctorMap = new HashedMap();
 | 
	
		
			
				|  |  |             if (doctorList!=null && doctorList.size()>0){
 | 
	
		
			
				|  |  |                 for (Doctor doctor: doctorList){
 | 
	
		
			
				|  |  |                     doctorMap.put(doctor.getCode(),doctor);
 | 
	
		
			
				|  |  |             Map<String, Doctor> doctorMap = new HashedMap();
 | 
	
		
			
				|  |  |             if (doctorList != null && doctorList.size() > 0) {
 | 
	
		
			
				|  |  |                 for (Doctor doctor : doctorList) {
 | 
	
		
			
				|  |  |                     doctorMap.put(doctor.getCode(), doctor);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             //查询出所有的文章列表
 | 
	
		
			
				|  |  |             List<HealthEduArticle> healthEduArticleList = healthEduArticleDao.findAllArticle();
 | 
	
		
			
				|  |  |             Map<String,HealthEduArticle> articleMap = new HashedMap();
 | 
	
		
			
				|  |  |             if (healthEduArticleList!=null && healthEduArticleList.size()>0){
 | 
	
		
			
				|  |  |                 for (HealthEduArticle healthEduArticle: healthEduArticleList){
 | 
	
		
			
				|  |  |                     articleMap.put(healthEduArticle.getCode(),healthEduArticle);
 | 
	
		
			
				|  |  |             Map<String, HealthEduArticle> articleMap = new HashedMap();
 | 
	
		
			
				|  |  |             if (healthEduArticleList != null && healthEduArticleList.size() > 0) {
 | 
	
		
			
				|  |  |                 for (HealthEduArticle healthEduArticle : healthEduArticleList) {
 | 
	
		
			
				|  |  |                     articleMap.put(healthEduArticle.getCode(), healthEduArticle);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             //获取所有的健康教育发送记录数量,分页,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)){
 | 
	
		
			
				|  |  |                 countSql += " AND czrq > '"+startTimeForSql+"'";
 | 
	
		
			
				|  |  |             if (StringUtils.isNotBlank(startTimeForSql)) {
 | 
	
		
			
				|  |  |                 countSql += " AND czrq > '" + startTimeForSql + "'";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             Map<String, Object> countMap = jdbcTemplate.queryForMap(countSql);
 | 
	
		
			
				|  |  |             if (countMap!=null) {
 | 
	
		
			
				|  |  |             if (countMap != null) {
 | 
	
		
			
				|  |  |                 int count = Integer.valueOf(String.valueOf(countMap.get("num")));
 | 
	
		
			
				|  |  |                 double pageCount = Math.ceil(Double.valueOf(count) / Double.valueOf(pageSize*20));
 | 
	
		
			
				|  |  |                 double pageCount = Math.ceil(Double.valueOf(count) / Double.valueOf(pageSize * 20));
 | 
	
		
			
				|  |  |                 if (pageCount > 0) {
 | 
	
		
			
				|  |  |                     String resultSql = "SELECT " +
 | 
	
		
			
				|  |  |                             " ap.patient AS patientCode, " +
 | 
	
	
		
			
				|  | @ -336,25 +348,25 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |                             " 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"+
 | 
	
		
			
				|  |  |                             " 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 ";
 | 
	
		
			
				|  |  |                     if (StringUtils.isNotBlank(startTimeForSql)){
 | 
	
		
			
				|  |  |                         resultSql += " AND ap.czrq > '"+startTimeForSql+"' ORDER BY ap.czrq ASC limit ?,? ";
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                     if (StringUtils.isNotBlank(startTimeForSql)) {
 | 
	
		
			
				|  |  |                         resultSql += " AND ap.czrq > '" + startTimeForSql + "' ORDER BY ap.czrq ASC limit ?,? ";
 | 
	
		
			
				|  |  |                     } else {
 | 
	
		
			
				|  |  |                         resultSql += "  ORDER BY ap.czrq ASC limit ?,? ";
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     for (int i = 1; i <= pageCount; i++) {
 | 
	
		
			
				|  |  |                         int start = (i - 1) * (pageSize*20);
 | 
	
		
			
				|  |  |                         List<Map<String,Object>> resultList = jdbcTemplate.queryForList(resultSql,new Object[]{start,pageSize*20});
 | 
	
		
			
				|  |  |                         if (CollectionUtils.isEmpty(resultList)){
 | 
	
		
			
				|  |  |                         int start = (i - 1) * (pageSize * 20);
 | 
	
		
			
				|  |  |                         List<Map<String, Object>> resultList = jdbcTemplate.queryForList(resultSql, new Object[]{start, pageSize * 20});
 | 
	
		
			
				|  |  |                         if (CollectionUtils.isEmpty(resultList)) {
 | 
	
		
			
				|  |  |                             flag = false;
 | 
	
		
			
				|  |  |                             return flag;
 | 
	
		
			
				|  |  |                         }
 | 
	
	
		
			
				|  | @ -362,9 +374,9 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |                         for (Map<String, Object> map : resultList) {
 | 
	
		
			
				|  |  |                             HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
 | 
	
		
			
				|  |  |                             //Map转对象
 | 
	
		
			
				|  |  |                             healthEduArticleES = MapListUtils.convertMap2Bean(map,HealthEduArticleES.class);
 | 
	
		
			
				|  |  |                             healthEduArticleES = setDateToObj(healthEduArticleES,doctorMap,articleMap,wjwCode,1);
 | 
	
		
			
				|  |  |                             if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())){
 | 
	
		
			
				|  |  |                             healthEduArticleES = MapListUtils.convertMap2Bean(map, HealthEduArticleES.class);
 | 
	
		
			
				|  |  |                             healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 1);
 | 
	
		
			
				|  |  |                             if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
 | 
	
		
			
				|  |  |                                 healthEduArticleES.setDoctorCode(wjwCode);
 | 
	
		
			
				|  |  |                                 //卫计委发送
 | 
	
		
			
				|  |  |                                 healthEduArticleES.setSendType(2);
 | 
	
	
		
			
				|  | @ -380,10 +392,10 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             //按批次查询文章信息。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){
 | 
	
		
			
				|  |  |                 deleteData(2,batchNoMap);
 | 
	
		
			
				|  |  |             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) {
 | 
	
		
			
				|  |  |                 deleteData(2, batchNoMap);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String BartchNoSql = "SELECT " +
 | 
	
	
		
			
				|  | @ -394,26 +406,26 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |                     " 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"+
 | 
	
		
			
				|  |  |                     " 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 createTime ASC ";
 | 
	
		
			
				|  |  |             System.out.println("userType2========="+BartchNoSql);
 | 
	
		
			
				|  |  |             List<Map<String,Object>> batchList = jdbcTemplate.queryForList(BartchNoSql);
 | 
	
		
			
				|  |  |             System.out.println("userType2=========" + BartchNoSql);
 | 
	
		
			
				|  |  |             List<Map<String, Object>> batchList = jdbcTemplate.queryForList(BartchNoSql);
 | 
	
		
			
				|  |  |             List<HealthEduArticleES> batchEsList = new ArrayList<>();
 | 
	
		
			
				|  |  |             if (batchList!=null && batchList.size()>0){
 | 
	
		
			
				|  |  |             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 = MapListUtils.convertMap2Bean(map, HealthEduArticleES.class);
 | 
	
		
			
				|  |  |                     healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 2);
 | 
	
		
			
				|  |  |                     if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
 | 
	
		
			
				|  |  |                         healthEduArticleES.setDoctorCode(wjwCode);
 | 
	
		
			
				|  |  |                         //卫计委发送
 | 
	
		
			
				|  |  |                         healthEduArticleES.setSendType(2);
 | 
	
	
		
			
				|  | @ -425,18 +437,18 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |                 //保存到Es中
 | 
	
		
			
				|  |  |                 saveDate(batchEsList);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             flag= false;
 | 
	
		
			
				|  |  |             flag = false;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return flag;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public HealthEduArticleES setDateToObj(HealthEduArticleES healthEduArticleES,Map<String,Doctor> doctorMap,Map<String,HealthEduArticle> articleMap,String wjwCode,Integer userType)throws Exception{
 | 
	
		
			
				|  |  |     public HealthEduArticleES setDateToObj(HealthEduArticleES healthEduArticleES, Map<String, Doctor> doctorMap, Map<String, HealthEduArticle> articleMap, String wjwCode, Integer userType) throws Exception {
 | 
	
		
			
				|  |  |         //遍历医生
 | 
	
		
			
				|  |  |         Set<Map.Entry<String,Doctor>> doctorSet=doctorMap.entrySet();
 | 
	
		
			
				|  |  |         for(Map.Entry<String, Doctor> doctorEntry:doctorSet){
 | 
	
		
			
				|  |  |             if (doctorEntry.getKey().equals(healthEduArticleES.getDoctorCode())){
 | 
	
		
			
				|  |  |         Set<Map.Entry<String, Doctor>> doctorSet = doctorMap.entrySet();
 | 
	
		
			
				|  |  |         for (Map.Entry<String, Doctor> doctorEntry : doctorSet) {
 | 
	
		
			
				|  |  |             if (doctorEntry.getKey().equals(healthEduArticleES.getDoctorCode())) {
 | 
	
		
			
				|  |  |                 Doctor doctor = doctorEntry.getValue();
 | 
	
		
			
				|  |  |                 healthEduArticleES.setDoctorCode(doctor.getCode());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setDoctorName(doctor.getName());
 | 
	
	
		
			
				|  | @ -454,8 +466,8 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //遍历文章
 | 
	
		
			
				|  |  |         Set<Map.Entry<String,HealthEduArticle>> articleSet=articleMap.entrySet();
 | 
	
		
			
				|  |  |         for(Map.Entry<String, HealthEduArticle> articleEntry:articleSet){
 | 
	
		
			
				|  |  |         Set<Map.Entry<String, HealthEduArticle>> articleSet = articleMap.entrySet();
 | 
	
		
			
				|  |  |         for (Map.Entry<String, HealthEduArticle> articleEntry : articleSet) {
 | 
	
		
			
				|  |  |             if (articleEntry.getKey().equals(healthEduArticleES.getArticleId())) {
 | 
	
		
			
				|  |  |                 HealthEduArticle healthEduArticle = articleEntry.getValue();
 | 
	
		
			
				|  |  |                 healthEduArticleES.setArticleId(healthEduArticle.getCode());
 | 
	
	
		
			
				|  | @ -469,7 +481,7 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |         healthEduArticleES.setUserType(userType);
 | 
	
		
			
				|  |  |         healthEduArticleES.setOperatorId(wjwCode);
 | 
	
		
			
				|  |  |         healthEduArticleES.setArticleSource("厦门市卫生与计划生育委员会");
 | 
	
		
			
				|  |  |         return  healthEduArticleES;
 | 
	
		
			
				|  |  |         return healthEduArticleES;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -478,39 +490,39 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     private Boolean saveDate(List<HealthEduArticleES> sms)throws Exception {
 | 
	
		
			
				|  |  |     private Boolean saveDate(List<HealthEduArticleES> sms) throws Exception {
 | 
	
		
			
				|  |  |         return SpringUtil.getBean(SaveEduArticleHelper.class).save(sms);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 删除数据
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     private void deleteData(int userType,List<Map<String,Object>> batchNoMap) {
 | 
	
		
			
				|  |  |     private void deleteData(int userType, List<Map<String, Object>> batchNoMap) {
 | 
	
		
			
				|  |  |         JestClient jestClient = null;
 | 
	
		
			
				|  |  |         List<HealthEduArticleES> saveModels = new ArrayList<>();
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             jestClient = elasticFactory.getJestClient();
 | 
	
		
			
				|  |  |             //先根据条件查找出来
 | 
	
		
			
				|  |  |            for (Map<String,Object> map: batchNoMap){
 | 
	
		
			
				|  |  |                SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
 | 
	
		
			
				|  |  |                BoolQueryBuilder boolQueryBuilder =  new BoolQueryBuilder();
 | 
	
		
			
				|  |  |                boolQueryBuilder.must(QueryBuilders.matchQuery("userType",userType));
 | 
	
		
			
				|  |  |                boolQueryBuilder.must(QueryBuilders.matchQuery("batchNo",map.get("batch_no")+""));
 | 
	
		
			
				|  |  |                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> healthEduArticleESList =  result.getSourceAsObjectList(HealthEduArticleES.class);
 | 
	
		
			
				|  |  |                if (healthEduArticleESList!=null && healthEduArticleESList.size()>0){
 | 
	
		
			
				|  |  |                    for (HealthEduArticleES healthEduArticleES : healthEduArticleESList){
 | 
	
		
			
				|  |  |                        saveModels.add(healthEduArticleES);
 | 
	
		
			
				|  |  |                    }
 | 
	
		
			
				|  |  |                }
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |             for (Map<String, Object> map : batchNoMap) {
 | 
	
		
			
				|  |  |                 SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
 | 
	
		
			
				|  |  |                 BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
 | 
	
		
			
				|  |  |                 boolQueryBuilder.must(QueryBuilders.matchQuery("userType", userType));
 | 
	
		
			
				|  |  |                 boolQueryBuilder.must(QueryBuilders.matchQuery("batchNo", map.get("batch_no") + ""));
 | 
	
		
			
				|  |  |                 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> healthEduArticleESList = result.getSourceAsObjectList(HealthEduArticleES.class);
 | 
	
		
			
				|  |  |                 if (healthEduArticleESList != null && healthEduArticleESList.size() > 0) {
 | 
	
		
			
				|  |  |                     for (HealthEduArticleES healthEduArticleES : healthEduArticleESList) {
 | 
	
		
			
				|  |  |                         saveModels.add(healthEduArticleES);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             //根据id批量删除
 | 
	
		
			
				|  |  |             Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
 | 
	
		
			
				|  |  |             for (HealthEduArticleES obj : saveModels) {
 | 
	
		
			
				|  |  |                 if (obj!=null){
 | 
	
		
			
				|  |  |                 if (obj != null) {
 | 
	
		
			
				|  |  |                     Delete index = new Delete.Builder(obj.getId()).build();
 | 
	
		
			
				|  |  |                     bulk.addAction(index);
 | 
	
		
			
				|  |  |                 }
 | 
	
	
		
			
				|  | @ -520,7 +532,7 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |             logger.info("delete data count:" + saveModels.size());
 | 
	
		
			
				|  |  |             logger.info("delete flag:" + br.isSucceeded());
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             System.out.println("======error:"+e.getMessage());
 | 
	
		
			
				|  |  |             System.out.println("======error:" + e.getMessage());
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         } finally {
 | 
	
		
			
				|  |  |             if (jestClient != null) {
 | 
	
	
		
			
				|  | @ -532,19 +544,19 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 更新es数据库数据
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public boolean updateData(){
 | 
	
		
			
				|  |  |     public boolean updateData() {
 | 
	
		
			
				|  |  |         boolean flag = true;
 | 
	
		
			
				|  |  |         JestClient jestClient = null;
 | 
	
		
			
				|  |  |         try{
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             jestClient = elasticFactory.getJestClient();
 | 
	
		
			
				|  |  |             //先查询出相关数据
 | 
	
		
			
				|  |  |             /*String timeSql ="select * from "+esType+" where userType<>1 and userType<>2 ";
 | 
	
		
			
				|  |  |             List<HealthEduArticleES> saveModels = elasticsearchUtil.excute(timeSql,HealthEduArticleES.class,esType,esIndex);*/
 | 
	
		
			
				|  |  |             //先根据条件查找出来
 | 
	
		
			
				|  |  |             SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
 | 
	
		
			
				|  |  |             BoolQueryBuilder boolQueryBuilder =  new BoolQueryBuilder();
 | 
	
		
			
				|  |  |             boolQueryBuilder.mustNot(QueryBuilders.matchQuery("userType",1));
 | 
	
		
			
				|  |  |             boolQueryBuilder.mustNot(QueryBuilders.matchQuery("userType",2));
 | 
	
		
			
				|  |  |             BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
 | 
	
		
			
				|  |  |             boolQueryBuilder.mustNot(QueryBuilders.matchQuery("userType", 1));
 | 
	
		
			
				|  |  |             boolQueryBuilder.mustNot(QueryBuilders.matchQuery("userType", 2));
 | 
	
		
			
				|  |  |             searchSourceBuilder.query(boolQueryBuilder).size(100000);//一次取100000条
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
 | 
	
	
		
			
				|  | @ -563,14 +575,202 @@ public class EduArticleService {
 | 
	
		
			
				|  |  |             BulkResult br = jestClient.execute(bulk.build());
 | 
	
		
			
				|  |  |             logger.info("update data count:" + saveModels.size());
 | 
	
		
			
				|  |  |             logger.info("update flag:" + br.isSucceeded());
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             flag = false;
 | 
	
		
			
				|  |  |         }finally {
 | 
	
		
			
				|  |  |         } finally {
 | 
	
		
			
				|  |  |             if (jestClient != null) {
 | 
	
		
			
				|  |  |                 jestClient.shutdownClient();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return flag;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Map<String, net.sf.json.JSONObject> getArticleSendToEsByDoctor(String doctorCodes) throws Exception {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Map<String, net.sf.json.JSONObject> returnMap = new HashedMap();
 | 
	
		
			
				|  |  |         String[] doctorCodeArr = doctorCodes.split(",");
 | 
	
		
			
				|  |  |         //初始化文章
 | 
	
		
			
				|  |  |         for (String doctorCode : doctorCodeArr) {
 | 
	
		
			
				|  |  |             net.sf.json.JSONObject o = new net.sf.json.JSONObject();
 | 
	
		
			
				|  |  |             //删除医生的推送记录
 | 
	
		
			
				|  |  |             deleteEsDataByDoctor(doctorCode);
 | 
	
		
			
				|  |  |             //新增医生的推送记录
 | 
	
		
			
				|  |  |             Integer size = saveByDoctor(doctorCode);
 | 
	
		
			
				|  |  |             o.put("saveEsSize", size);
 | 
	
		
			
				|  |  |             returnMap.put(doctorCode, o);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return returnMap;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 根据code删除ES中的推送表的记录
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param doctorCode
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     private void deleteEsDataByDoctor(String doctorCode) {
 | 
	
		
			
				|  |  |         JestClient jestClient = null;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             jestClient = elasticFactory.getJestClient();
 | 
	
		
			
				|  |  |             //先根据条件查找出来
 | 
	
		
			
				|  |  |             SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
 | 
	
		
			
				|  |  |             searchSourceBuilder.query(
 | 
	
		
			
				|  |  |                     new BoolQueryBuilder()
 | 
	
		
			
				|  |  |                             .must(QueryBuilders.matchQuery("quotaCode", doctorCode))
 | 
	
		
			
				|  |  |             ).size(500000);//一次取10000条
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
 | 
	
		
			
				|  |  |                     .build();
 | 
	
		
			
				|  |  |             SearchResult result = jestClient.execute(search);
 | 
	
		
			
				|  |  |             List<HealthEduArticleES> healthEduArticleESs = result.getSourceAsObjectList(HealthEduArticleES.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //根据id批量删除
 | 
	
		
			
				|  |  |             Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
 | 
	
		
			
				|  |  |             for (HealthEduArticleES obj : healthEduArticleESs) {
 | 
	
		
			
				|  |  |                 Delete index = new Delete.Builder(obj.getId()).build();
 | 
	
		
			
				|  |  |                 bulk.addAction(index);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             BulkResult br = jestClient.execute(bulk.build());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             logger.info("delete data count:" + healthEduArticleESs.size());
 | 
	
		
			
				|  |  |             logger.info("delete flag:" + br.isSucceeded());
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         } finally {
 | 
	
		
			
				|  |  |             if (jestClient != null) {
 | 
	
		
			
				|  |  |                 jestClient.shutdownClient();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 保存推送记录到ES中
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param doctorCode
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     private Integer saveByDoctor(String doctorCode) throws Exception {
 | 
	
		
			
				|  |  |         Doctor doctor = doctorDao.findByCode(doctorCode);
 | 
	
		
			
				|  |  |         //1.查询出所有的文章列表
 | 
	
		
			
				|  |  |         List<HealthEduArticle> healthEduArticleList = healthEduArticleDao.findAllArticle();
 | 
	
		
			
				|  |  |         Map<String, HealthEduArticle> articleMap = new HashedMap();//key是文章code
 | 
	
		
			
				|  |  |         if (healthEduArticleList != null && healthEduArticleList.size() > 0) {
 | 
	
		
			
				|  |  |             for (HealthEduArticle healthEduArticle : healthEduArticleList) {
 | 
	
		
			
				|  |  |                 articleMap.put(healthEduArticle.getCode(), healthEduArticle);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //2.获取医生的推送记录
 | 
	
		
			
				|  |  |         String sql = "select * from wlyy_health_edu_article_patient where doctor='" + doctorCode + "'";
 | 
	
		
			
				|  |  |         List<HealthEduArticlePatient> healthEduArticlePatients = jdbcTemplate.query(sql, new BeanPropertyRowMapper(HealthEduArticlePatient.class));
 | 
	
		
			
				|  |  |         //推送记录按照批次号分组
 | 
	
		
			
				|  |  |         Map<String, List<HealthEduArticlePatient>> healthEduArticlePatientMap = new HashMap<>();
 | 
	
		
			
				|  |  |         healthEduArticlePatients.stream().forEach(one -> {
 | 
	
		
			
				|  |  |             List<HealthEduArticlePatient> healthEduArticlePatientTemp = healthEduArticlePatientMap.get(one.getBatchNo());
 | 
	
		
			
				|  |  |             if (healthEduArticlePatientTemp == null) {
 | 
	
		
			
				|  |  |                 healthEduArticlePatientTemp = new ArrayList<HealthEduArticlePatient>();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             healthEduArticlePatientTemp.add(one);
 | 
	
		
			
				|  |  |             healthEduArticlePatientMap.put(one.getBatchNo(), healthEduArticlePatientTemp);
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |         //3.转换成新的健康教育需要的数据
 | 
	
		
			
				|  |  |         List<HealthEduArticleES> healthEduArticleESSaveList = new ArrayList<>();
 | 
	
		
			
				|  |  |         //获取医生的角色
 | 
	
		
			
				|  |  |         Map<String,Object> roleMaps=  gcLabelService.fetchUserHighestAuthority(doctorCode);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         healthEduArticlePatientMap.keySet().stream().forEach(one -> {
 | 
	
		
			
				|  |  |             //获取患者数据
 | 
	
		
			
				|  |  |             List<HealthEduArticlePatient> healthEduArticlePatientTemps = healthEduArticlePatientMap.get(one);
 | 
	
		
			
				|  |  |             AdminTeam adminTeam = doctorAdminTeamDao.findOne(healthEduArticlePatientTemps.get(0).getId());
 | 
	
		
			
				|  |  |             //遍历数据
 | 
	
		
			
				|  |  |             healthEduArticlePatientTemps.stream().forEach(healthEduArticlePatient -> {
 | 
	
		
			
				|  |  |                 //3,1 保存userType=1的
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 healthEduArticleES.setDoctorCode(doctorCode);
 | 
	
		
			
				|  |  |                 healthEduArticleES.setDoctorName(doctor.getName());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setSendName(doctor.getName());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setSendSex(doctor.getSex().toString());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setSendPic(doctor.getPhoto());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setSendLevel(doctor.getLevel().toString());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setSendSource(1);//旧数据都是1 i健康发送
 | 
	
		
			
				|  |  |                 healthEduArticleES.setSendType(1);//默认是医生发送
 | 
	
		
			
				|  |  |                 if(roleMaps!=null){
 | 
	
		
			
				|  |  |                    // healthEduArticleES.setCurrentUserRoleLevel("2");
 | 
	
		
			
				|  |  |                    // healthEduArticleES.setCurrentUserRoleCode();
 | 
	
		
			
				|  |  |                 }else{
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 healthEduArticleES.setBatchNo(healthEduArticlePatient.getBatchNo());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setPatientCode(healthEduArticlePatient.getPatient());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setPatientName(patientDao.findByCode(healthEduArticlePatient.getPatient()).getName());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 HealthEduArticle healthEduArticle = articleMap.get(healthEduArticlePatient.getArticle());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setArticleId(healthEduArticle.getCode());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setArticleContent(healthEduArticle.getContent());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setArticleTitle(healthEduArticle.getTitle());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setIsRead(healthEduArticlePatient.getRead());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setOperatorId(doctorCode); //之前旧数据没有文章作者 默认是发送人
 | 
	
		
			
				|  |  |                 healthEduArticleES.setArticleCover(healthEduArticle.getUrl());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setArticleSource(adminTeam.getOrgName());//文章来源 旧数据默认是医生的所在团队的所属机构
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 healthEduArticleES.setAdminTeamCode(adminTeam.getId());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setAdminTeamName(adminTeam.getName());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setHospital(adminTeam.getOrgCode());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setHospitalName(adminTeam.getOrgName());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setTown(adminTeam.getTownCode());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setTownName(adminTeam.getTownName());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 healthEduArticleES.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                 healthEduArticleES.setUserType(1);//患者
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 healthEduArticleESSaveList.add(healthEduArticleES);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             });
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //3,2 保存userType=2的
 | 
	
		
			
				|  |  |             HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             healthEduArticleES.setDoctorCode(doctorCode);
 | 
	
		
			
				|  |  |             healthEduArticleES.setDoctorName(doctor.getName());
 | 
	
		
			
				|  |  |             healthEduArticleES.setSendName(doctor.getName());
 | 
	
		
			
				|  |  |             healthEduArticleES.setSendSex(doctor.getSex().toString());
 | 
	
		
			
				|  |  |             healthEduArticleES.setSendPic(doctor.getPhoto());
 | 
	
		
			
				|  |  |             healthEduArticleES.setSendLevel(doctor.getLevel().toString());
 | 
	
		
			
				|  |  |             healthEduArticleES.setSendSource(1);//旧数据都是1 i健康发送
 | 
	
		
			
				|  |  |             healthEduArticleES.setSendType(1);//默认是医生发送
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             healthEduArticleES.setBatchNo(healthEduArticlePatientTemps.get(0).getBatchNo());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             HealthEduArticle healthEduArticle = articleMap.get(healthEduArticlePatientTemps.get(0).getArticle());
 | 
	
		
			
				|  |  |             healthEduArticleES.setArticleId(healthEduArticle.getCode());
 | 
	
		
			
				|  |  |             healthEduArticleES.setArticleContent(healthEduArticle.getContent());
 | 
	
		
			
				|  |  |             healthEduArticleES.setArticleTitle(healthEduArticle.getTitle());
 | 
	
		
			
				|  |  |             healthEduArticleES.setOperatorId(doctorCode); //之前旧数据没有文章作者 默认是发送人
 | 
	
		
			
				|  |  |             healthEduArticleES.setArticleCover(healthEduArticle.getUrl());
 | 
	
		
			
				|  |  |             healthEduArticleES.setArticleSource(adminTeam.getOrgName());//文章来源 旧数据默认是医生的所在团队的所属机构
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             healthEduArticleES.setAdminTeamCode(adminTeam.getId());
 | 
	
		
			
				|  |  |             healthEduArticleES.setAdminTeamName(adminTeam.getName());
 | 
	
		
			
				|  |  |             healthEduArticleES.setHospital(adminTeam.getOrgCode());
 | 
	
		
			
				|  |  |             healthEduArticleES.setHospitalName(adminTeam.getOrgName());
 | 
	
		
			
				|  |  |             healthEduArticleES.setTown(adminTeam.getTownCode());
 | 
	
		
			
				|  |  |             healthEduArticleES.setTownName(adminTeam.getTownName());
 | 
	
		
			
				|  |  |             healthEduArticleES.setUserType(2); //医生
 | 
	
		
			
				|  |  |             healthEduArticleES.setAllCount(healthEduArticlePatientTemps.size());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             healthEduArticleES.setCreateTime(new Date());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             healthEduArticleESSaveList.add(healthEduArticleES);
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //数据存到ES
 | 
	
		
			
				|  |  |         saveDate(healthEduArticleESSaveList);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return healthEduArticleESSaveList.size();
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |