|
@ -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,7 @@ public class EduArticleService {
|
|
|
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+"'";
|
|
@ -323,6 +334,7 @@ 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"+
|
|
|
" FROM " +
|
|
@ -337,7 +349,6 @@ public class EduArticleService {
|
|
|
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});
|
|
@ -350,10 +361,11 @@ public class EduArticleService {
|
|
|
HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
|
|
|
//Map转对象
|
|
|
healthEduArticleES = MapListUtils.convertMap2Bean(map,HealthEduArticleES.class);
|
|
|
healthEduArticleES = setDateToObj(healthEduArticleES,doctorMap,articleMap,wjwCode);
|
|
|
healthEduArticleES = setDateToObj(healthEduArticleES,doctorMap,articleMap,wjwCode,1);
|
|
|
if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())){
|
|
|
healthEduArticleES.setDoctorCode(wjwCode);
|
|
|
//healthEduArticleES.setSendCode(wjwCode);
|
|
|
//卫计委发送
|
|
|
healthEduArticleES.setSendType(2);
|
|
|
healthEduArticleES.setSendName("厦门市卫生与计划生育委员会");
|
|
|
healthEduArticleES.setDoctorName("厦门市卫生与计划生育委员会");
|
|
|
}
|
|
@ -364,6 +376,54 @@ 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){
|
|
|
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("厦门市卫生与计划生育委员会");
|
|
|
}
|
|
|
batchEsList.add(healthEduArticleES);
|
|
|
}
|
|
|
//保存到Es中
|
|
|
saveDate(batchEsList);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
flag= false;
|
|
@ -371,7 +431,7 @@ public class EduArticleService {
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
public HealthEduArticleES setDateToObj(HealthEduArticleES healthEduArticleES,Map<String,Doctor> doctorMap,Map<String,HealthEduArticle> articleMap,String wjwCode)throws Exception{
|
|
|
public HealthEduArticleES setDateToObj(HealthEduArticleES healthEduArticleES,Map<String,Doctor> doctorMap,Map<String,HealthEduArticle> articleMap,String wjwCode,int userType)throws Exception{
|
|
|
//遍历医生
|
|
|
Set<Map.Entry<String,Doctor>> doctorSet=doctorMap.entrySet();
|
|
|
for(Map.Entry<String, Doctor> doctorEntry:doctorSet){
|
|
@ -380,6 +440,8 @@ public class EduArticleService {
|
|
|
healthEduArticleES.setDoctorCode(doctor.getCode());
|
|
|
healthEduArticleES.setDoctorName(doctor.getName());
|
|
|
//healthEduArticleES.setSendCode(doctor.getCode());
|
|
|
//医生发送
|
|
|
healthEduArticleES.setSendType(1);
|
|
|
healthEduArticleES.setSendName(doctor.getCode());
|
|
|
healthEduArticleES.setSendPic(doctor.getPhoto());
|
|
|
healthEduArticleES.setSendSex(doctor.getSex() != null ? String.valueOf(doctor.getSex()) : "");
|
|
@ -401,8 +463,7 @@ public class EduArticleService {
|
|
|
healthEduArticleES.setArticleContent(healthEduArticle.getSummary());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
healthEduArticleES.setSendType(2);
|
|
|
healthEduArticleES.setUserType(userType);
|
|
|
healthEduArticleES.setOperatorId(wjwCode);
|
|
|
healthEduArticleES.setArticleSource("厦门市卫生与计划生育委员会");
|
|
|
return healthEduArticleES;
|
|
@ -474,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();
|