|
@ -6,20 +6,20 @@ 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;
|
|
|
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;
|
|
|
import com.yihu.wlyy.jkedu.repository.JkeduCategoryDao;
|
|
|
import com.yihu.wlyy.jkedu.repository.JkeduCollectionArticleDao;
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamDao;
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorDao;
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorRoleDao;
|
|
|
import com.yihu.wlyy.repository.education.HealthEduArticleDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.service.common.account.RoleService;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import com.yihu.wlyy.util.ElasticsearchUtil;
|
|
|
import com.yihu.wlyy.util.MapListUtils;
|
|
@ -28,11 +28,8 @@ 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;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
@ -75,12 +72,17 @@ public class EduArticleService {
|
|
|
@Autowired
|
|
|
private JkeduBehaviorArticleDao jkeduBehaviorArticleDao;
|
|
|
@Autowired
|
|
|
private JkeduCategoryDao jkeduCategoryDao;
|
|
|
@Autowired
|
|
|
private ElasticsearchUtil elasticsearchUtil;
|
|
|
@Autowired
|
|
|
private ElasticFactory elasticFactory;
|
|
|
@Autowired
|
|
|
private GcLabelService gcLabelService;
|
|
|
|
|
|
@Autowired
|
|
|
private RoleService roleService;
|
|
|
@Autowired
|
|
|
private DoctorRoleDao doctorRoleDao;
|
|
|
|
|
|
@Value("${es.type.HealthEduArticlePatient}")
|
|
|
private String esType;
|
|
@ -105,6 +107,20 @@ public class EduArticleService {
|
|
|
if (delOldList != null && delOldList.size() > 0) {
|
|
|
jkeduArticleDao.delete(delOldList);
|
|
|
}
|
|
|
|
|
|
//查询所有一级类别
|
|
|
List<NewCategoryModel> firstList = jkeduCategoryDao.findCategory(1);
|
|
|
//查询所有二级类别
|
|
|
List<NewCategoryModel> secondList = jkeduCategoryDao.findCategory(2);
|
|
|
String firstId = "";
|
|
|
String firstName = "健康文章";
|
|
|
if (firstList!=null && firstList.size()>0){
|
|
|
for (NewCategoryModel newCategoryModel : firstList){
|
|
|
if (newCategoryModel.getCategoryName().contains(firstName)){
|
|
|
firstId = newCategoryModel.getCategoryId();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//分页查询,执行插入
|
|
|
String countSql = "select COUNT(1) AS num from wlyy_health_edu_article";
|
|
|
Map<String, Object> countMap = jdbcTemplate.queryForMap(countSql);
|
|
@ -113,8 +129,8 @@ public class EduArticleService {
|
|
|
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 ?,?";
|
|
|
"url AS URL, czrq AS InsertTime, czrq AS UpdateTime,keyword AS KeyWord " +
|
|
|
"FROM wlyy_health_edu_article limit ?,?";
|
|
|
for (int i = 1; i <= pageCount; i++) {
|
|
|
int start = (i - 1) * pageSize;
|
|
|
//分页查询数据
|
|
@ -130,7 +146,6 @@ public class EduArticleService {
|
|
|
newArticleModel.setArticleOrder(99);
|
|
|
newArticleModel.setArticleState(1);
|
|
|
newArticleModel.setOrgName("厦门市卫生与计划生育委员会");
|
|
|
//id
|
|
|
newArticleModel.setArticleSource(wjwCode);
|
|
|
newArticleModel.setArticlelevel(0);
|
|
|
newArticleModel.setOperatorName("厦门市卫生与计划生育委员会");
|
|
@ -141,9 +156,19 @@ public class EduArticleService {
|
|
|
newArticleModel.setArticleType("2");
|
|
|
newArticleModel.setOperatorRoleCode("350200");
|
|
|
newArticleModel.setOperatorRoleLevel("2");
|
|
|
newArticleModel.setFirstLevelCategoryId(firstId);
|
|
|
newArticleModel.setFirstLevelCategoryName(firstName);
|
|
|
newArticleModel.setRoleType(2);
|
|
|
newArticleModel.setUserScope(1);
|
|
|
newArticleModel.setIsOld(1);
|
|
|
if (secondList!=null && secondList.size()>0){
|
|
|
for (NewCategoryModel newCategoryModel : secondList){
|
|
|
if (newCategoryModel.getCategoryName().equals(newArticleModel.getKeyWord())){
|
|
|
newArticleModel.setSecondLevelCategoryId(newCategoryModel.getCategoryId());
|
|
|
newArticleModel.setSecondLevelCategoryName(newCategoryModel.getCategoryName());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
newList.add(newArticleModel);
|
|
|
}
|
|
|
//执行插入新数据库
|
|
@ -306,15 +331,12 @@ public class EduArticleService {
|
|
|
public boolean getArticleSendedListToEs() {
|
|
|
boolean flag = true;
|
|
|
try {
|
|
|
//获取卫计委code
|
|
|
//1.获取卫计委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");
|
|
|
//查询出所有的医生
|
|
|
|
|
|
//2.查询出所有的医生
|
|
|
List<Doctor> doctorList = doctorDao.findAllCertifiedDoctors();
|
|
|
Map<String, Doctor> doctorMap = new HashedMap();
|
|
|
if (doctorList != null && doctorList.size() > 0) {
|
|
@ -322,7 +344,8 @@ public class EduArticleService {
|
|
|
doctorMap.put(doctor.getCode(), doctor);
|
|
|
}
|
|
|
}
|
|
|
//查询出所有的文章列表
|
|
|
|
|
|
//3.查询出所有的文章列表
|
|
|
List<HealthEduArticle> healthEduArticleList = healthEduArticleDao.findAllArticle();
|
|
|
Map<String, HealthEduArticle> articleMap = new HashedMap();
|
|
|
if (healthEduArticleList != null && healthEduArticleList.size() > 0) {
|
|
@ -330,121 +353,187 @@ 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 + "'";
|
|
|
}
|
|
|
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 * 20));
|
|
|
if (pageCount > 0) {
|
|
|
String resultSql = "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 ";
|
|
|
if (StringUtils.isNotBlank(startTimeForSql)) {
|
|
|
resultSql += " AND ap.czrq > '" + startTimeForSql + "' ORDER BY ap.czrq ASC limit ?,? ";
|
|
|
} else {
|
|
|
resultSql += " ORDER BY ap.czrq ASC limit ?,? ";
|
|
|
|
|
|
//4.查询所有一级类别、二级类别
|
|
|
List<NewCategoryModel> firstList = jkeduCategoryDao.findCategory(1);
|
|
|
List<NewCategoryModel> secondList = jkeduCategoryDao.findCategory(2);
|
|
|
String firstId = "";
|
|
|
String firstName = "健康文章";
|
|
|
if (firstList!=null && firstList.size()>0){
|
|
|
for (NewCategoryModel newCategoryModel : firstList){
|
|
|
if (newCategoryModel.getCategoryName().contains(firstName)){
|
|
|
firstId = newCategoryModel.getCategoryId();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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)) {
|
|
|
flag = false;
|
|
|
return flag;
|
|
|
}
|
|
|
List<HealthEduArticleES> esList = new ArrayList<>();
|
|
|
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.setDoctorCode(wjwCode);
|
|
|
//卫计委发送
|
|
|
healthEduArticleES.setSendType(2);
|
|
|
healthEduArticleES.setSendName("厦门市卫生与计划生育委员会");
|
|
|
healthEduArticleES.setDoctorName("厦门市卫生与计划生育委员会");
|
|
|
}
|
|
|
esList.add(healthEduArticleES);
|
|
|
//5.查询出根据batch_no聚合后的每个批次号的数量
|
|
|
String batchNoCountSql = "SELECT batch_no,COUNT(*) batchCount FROM wlyy_health_edu_article_patient_copy where admin_team_code IS NOT NULL AND batch_no IS NOT NULL GROUP BY batch_no ";
|
|
|
List<Map<String,Object>> batchNoCountMapList = jdbcTemplate.queryForList(batchNoCountSql);
|
|
|
|
|
|
//6.清洗数据
|
|
|
flag = CleanDateToEs(doctorMap,articleMap,wjwCode,firstId,firstName,secondList,batchNoCountMapList);
|
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
flag = false;
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 清洗数据到es
|
|
|
* @param doctorMap
|
|
|
* @param articleMap
|
|
|
* @param wjwCode
|
|
|
* @param firstId
|
|
|
* @param firstName
|
|
|
* @param secondList
|
|
|
* @param batchNoCountMapList
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public boolean CleanDateToEs(Map<String,Doctor> doctorMap,Map<String,HealthEduArticle> articleMap,String wjwCode,String firstId,String firstName,List<NewCategoryModel> secondList,List<Map<String,Object>> batchNoCountMapList)throws Exception{
|
|
|
boolean flag = true;
|
|
|
//1.查询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");
|
|
|
|
|
|
//2.获取batchNo不为空的健康教育发送记录数量进行分页,userType=1
|
|
|
String countSql = "SELECT COUNT(id) AS num from wlyy_health_edu_article_patient_copy WHERE admin_team_code IS NOT NULL AND batch_no IS NOT NULL ";
|
|
|
if (StringUtils.isNotBlank(startTimeForSql)) {
|
|
|
countSql += " AND czrq > '" + startTimeForSql + "'";
|
|
|
}
|
|
|
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 * 20));
|
|
|
if (pageCount > 0) {
|
|
|
String resultSql = "SELECT " +
|
|
|
" ap.patient AS patientCode, " +
|
|
|
" ap.article AS articleId, " +
|
|
|
" ap.doctor AS doctorCode, " +
|
|
|
" ap.is_read AS isRead, " +
|
|
|
" ap.czrq AS czrq, " +
|
|
|
" 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_copy 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 AND ap.batch_no IS NOT NULL";
|
|
|
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)) {
|
|
|
flag = false;
|
|
|
return flag;
|
|
|
}
|
|
|
List<HealthEduArticleES> esList = new ArrayList<>();
|
|
|
//循环结果,封装对象
|
|
|
for (Map<String, Object> map : resultList) {
|
|
|
HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
|
|
|
//Map转对象
|
|
|
healthEduArticleES = MapListUtils.convertMap2Bean(map, HealthEduArticleES.class);
|
|
|
healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 1,firstId,firstName,secondList,batchNoCountMapList);
|
|
|
if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
|
|
|
healthEduArticleES.setDoctorCode(wjwCode);
|
|
|
//卫计委发送
|
|
|
healthEduArticleES.setSendType(2);
|
|
|
healthEduArticleES.setSendName("厦门市卫生与计划生育委员会");
|
|
|
healthEduArticleES.setDoctorName("厦门市卫生与计划生育委员会");
|
|
|
}
|
|
|
//保存到Es中
|
|
|
saveDate(esList);
|
|
|
esList.add(healthEduArticleES);
|
|
|
}
|
|
|
//保存到Es中
|
|
|
saveDate(esList);
|
|
|
}
|
|
|
}
|
|
|
//按批次查询文章信息。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);
|
|
|
}
|
|
|
//3.按批次查询文章信息。userType=2
|
|
|
//要先删除原来的数据。
|
|
|
String batSql = "SELECT batch_no from wlyy_health_edu_article_patient_copy WHERE admin_team_code IS NOT NULL AND batch_no IS NOT NULL GROUP BY batch_no ";
|
|
|
List<Map<String, Object>> batchNoMap = jdbcTemplate.queryForList(batSql);
|
|
|
List<String> batchNoList = new ArrayList<>();
|
|
|
if (batchNoMap != null && batchNoMap.size() > 0) {
|
|
|
for (Map<String,Object> map : batchNoMap){
|
|
|
batchNoList.add(String.valueOf(map.get("batch_no")));
|
|
|
}
|
|
|
deleteData(2, batchNoList);
|
|
|
}
|
|
|
|
|
|
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 createTime ASC ";
|
|
|
System.out.println("userType2=========" + BartchNoSql);
|
|
|
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);
|
|
|
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_copy 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 AND ap.batch_no IS NOT NULL GROUP BY ap.batch_no ORDER BY createTime 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,firstId,firstName,secondList,batchNoCountMapList);
|
|
|
if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
|
|
|
healthEduArticleES.setDoctorCode(wjwCode);
|
|
|
//卫计委发送
|
|
|
healthEduArticleES.setSendType(2);
|
|
|
healthEduArticleES.setSendName("厦门市卫生与计划生育委员会");
|
|
|
healthEduArticleES.setDoctorName("厦门市卫生与计划生育委员会");
|
|
|
}
|
|
|
//保存到Es中
|
|
|
saveDate(batchEsList);
|
|
|
batchEsList.add(healthEduArticleES);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
flag = false;
|
|
|
//保存到Es中
|
|
|
saveDate(batchEsList);
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
public HealthEduArticleES setDateToObj(HealthEduArticleES healthEduArticleES, Map<String, Doctor> doctorMap, Map<String, HealthEduArticle> articleMap, String wjwCode, Integer userType) throws Exception {
|
|
|
/**
|
|
|
* 封装Es存储对象
|
|
|
* @param healthEduArticleES
|
|
|
* @param doctorMap
|
|
|
* @param articleMap
|
|
|
* @param wjwCode
|
|
|
* @param userType
|
|
|
* @param firstId
|
|
|
* @param firstName
|
|
|
* @param secondList
|
|
|
* @param batchNoCountMapList
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public HealthEduArticleES setDateToObj(HealthEduArticleES healthEduArticleES, Map<String, Doctor> doctorMap,
|
|
|
Map<String, HealthEduArticle> articleMap, String wjwCode,
|
|
|
Integer userType,String firstId,String firstName,
|
|
|
List<NewCategoryModel> secondList,List<Map<String,Object>> batchNoCountMapList) throws Exception {
|
|
|
//遍历医生
|
|
|
Set<Map.Entry<String, Doctor>> doctorSet = doctorMap.entrySet();
|
|
|
for (Map.Entry<String, Doctor> doctorEntry : doctorSet) {
|
|
@ -452,9 +541,8 @@ public class EduArticleService {
|
|
|
Doctor doctor = doctorEntry.getValue();
|
|
|
healthEduArticleES.setDoctorCode(doctor.getCode());
|
|
|
healthEduArticleES.setDoctorName(doctor.getName());
|
|
|
//healthEduArticleES.setSendCode(doctor.getCode());
|
|
|
//医生发送
|
|
|
healthEduArticleES.setSendName(doctor.getCode());
|
|
|
healthEduArticleES.setSendName(doctor.getName());
|
|
|
healthEduArticleES.setSendPic(doctor.getPhoto());
|
|
|
healthEduArticleES.setSendSex(doctor.getSex() != null ? String.valueOf(doctor.getSex()) : "");
|
|
|
healthEduArticleES.setHospital(doctor.getHospital());
|
|
@ -472,19 +560,66 @@ public class EduArticleService {
|
|
|
HealthEduArticle healthEduArticle = articleEntry.getValue();
|
|
|
healthEduArticleES.setArticleId(healthEduArticle.getCode());
|
|
|
healthEduArticleES.setArticleTitle(healthEduArticle.getTitle());
|
|
|
healthEduArticleES.setArticleContent(healthEduArticle.getSummary());
|
|
|
if (healthEduArticle.getContent().length()>=100){
|
|
|
healthEduArticleES.setArticleContent(healthEduArticle.getContent().substring(0,100));
|
|
|
}else {
|
|
|
healthEduArticleES.setArticleContent(healthEduArticle.getContent());
|
|
|
}
|
|
|
healthEduArticleES.setFirstLevelCategoryId(firstId);
|
|
|
healthEduArticleES.setFirstLevelCategoryName(firstName);
|
|
|
if (secondList!=null && secondList.size()>0){
|
|
|
for (NewCategoryModel newCategoryModel : secondList){
|
|
|
if (newCategoryModel.getCategoryName().equals(healthEduArticle.getKeyword())){
|
|
|
healthEduArticleES.setSecondLevelCategoryId(newCategoryModel.getCategoryId());
|
|
|
healthEduArticleES.setSecondLevelCategoryName(newCategoryModel.getCategoryName());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
/*if (userType==2){
|
|
|
healthEduArticleES.setUserType(userType);
|
|
|
}*/
|
|
|
//替换已读数据code
|
|
|
if (userType==1){
|
|
|
//数据库中的isRead 0已读,1未读--->Es中isRead 0未读 1已读
|
|
|
if (healthEduArticleES.getIsRead()==0){
|
|
|
healthEduArticleES.setIsRead(1);
|
|
|
}else{
|
|
|
healthEduArticleES.setCzrq(null);
|
|
|
healthEduArticleES.setIsRead(0);
|
|
|
}
|
|
|
}
|
|
|
//算出allCount
|
|
|
if (batchNoCountMapList!=null && batchNoCountMapList.size()>0){
|
|
|
for (Map<String,Object> map : batchNoCountMapList){
|
|
|
if (healthEduArticleES.getBatchNo().equals(String.valueOf(map.get("batch_no")))){
|
|
|
healthEduArticleES.setAllCount(Integer.valueOf(String.valueOf(map.get("batchCount"))));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//如果是医生推送
|
|
|
if (!StringUtils.isEmpty(healthEduArticleES.getDoctorName())){
|
|
|
//List<DoctorRole> roleList = doctorRoleDao.findUserRole(healthEduArticleES.getDoctorCode());
|
|
|
int resultLevel = 4;
|
|
|
/*if (roleList != null && roleList.size() > 0) {
|
|
|
for (DoctorRole role : roleList) {
|
|
|
if(resultLevel>=roleService.roleConverse(role.getCode())){
|
|
|
resultLevel=roleService.roleConverse(role.getCode());
|
|
|
}
|
|
|
}
|
|
|
}*/
|
|
|
healthEduArticleES.setCurrentUserRoleCode(healthEduArticleES.getHospital());
|
|
|
healthEduArticleES.setCurrentUserRoleLevel(String.valueOf(resultLevel));
|
|
|
}else{
|
|
|
healthEduArticleES.setCurrentUserRoleCode(wjwCode);
|
|
|
healthEduArticleES.setCurrentUserRoleLevel("2");
|
|
|
}
|
|
|
healthEduArticleES.setCreateTime(new Date());
|
|
|
healthEduArticleES.setUserType(userType);
|
|
|
healthEduArticleES.setOperatorId(wjwCode);
|
|
|
healthEduArticleES.setArticleSource("厦门市卫生与计划生育委员会");
|
|
|
return healthEduArticleES;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 保存数据
|
|
|
*
|
|
@ -497,31 +632,34 @@ public class EduArticleService {
|
|
|
/**
|
|
|
* 删除数据
|
|
|
*/
|
|
|
private void deleteData(int userType, List<Map<String, Object>> batchNoMap) {
|
|
|
private void deleteData(int userType, List<String> batchNoList) {
|
|
|
JestClient jestClient = null;
|
|
|
List<HealthEduArticleES> saveModels = new ArrayList<>();
|
|
|
//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);
|
|
|
}
|
|
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
|
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
|
|
|
boolQueryBuilder.must(QueryBuilders.matchQuery("userType", userType));
|
|
|
/*if (StringUtils.isEmpty(batchNo) || "null".equals(batchNo)){
|
|
|
boolQueryBuilder.must(QueryBuilders.missingQuery("batchNo"));
|
|
|
}else{
|
|
|
boolQueryBuilder.must(QueryBuilders.termsQuery("batchNo", batchNo));
|
|
|
}*/
|
|
|
boolQueryBuilder.must(QueryBuilders.termsQuery("batchNo", batchNoList));
|
|
|
searchSourceBuilder.query(boolQueryBuilder).size(500000);//一次取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) {
|
|
|
for (HealthEduArticleES obj : healthEduArticleESList) {
|
|
|
if (obj != null) {
|
|
|
Delete index = new Delete.Builder(obj.getId()).build();
|
|
|
bulk.addAction(index);
|
|
@ -529,7 +667,7 @@ public class EduArticleService {
|
|
|
}
|
|
|
BulkResult br = jestClient.execute(bulk.build());
|
|
|
|
|
|
logger.info("delete data count:" + saveModels.size());
|
|
|
logger.info("delete data count:" + healthEduArticleESList.size());
|
|
|
logger.info("delete flag:" + br.isSucceeded());
|
|
|
} catch (Exception e) {
|
|
|
System.out.println("======error:" + e.getMessage());
|
|
@ -772,5 +910,120 @@ public class EduArticleService {
|
|
|
return healthEduArticleESSaveList.size();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除Es里所有的旧数据
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public Map<String, Object> deleteEsOldArticlePatient () throws Exception {
|
|
|
|
|
|
Map<String, Object> returnMap = new HashedMap();
|
|
|
int resultSize = 0;
|
|
|
String sql = "SELECT batch_no AS batchNo,COUNT(1) batchCount " +
|
|
|
"FROM wlyy_health_edu_article_patient_copy " +
|
|
|
"WHERE admin_team_code IS NOT NULL AND batch_no IS NOT NULL GROUP BY batch_no";
|
|
|
List<Map<String,Object>> batchMapList = jdbcTemplate.queryForList(sql);
|
|
|
List<String> batchNoList = new ArrayList<>();
|
|
|
if (batchMapList!=null && batchMapList.size()>0){
|
|
|
for (Map<String,Object> map : batchMapList){
|
|
|
batchNoList.add(String.valueOf(map.get("batchNo")));
|
|
|
}
|
|
|
resultSize = deleteEsByBatchNo(batchNoList);
|
|
|
}
|
|
|
returnMap.put("deleteCount",Integer.valueOf(resultSize));
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
|
|
|
private int deleteEsByBatchNo(List<String> list) {
|
|
|
JestClient jestClient = null;
|
|
|
//List<HealthEduArticleES> saveModels = new ArrayList<>();
|
|
|
try {
|
|
|
jestClient = elasticFactory.getJestClient();
|
|
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
|
searchSourceBuilder.query(
|
|
|
new BoolQueryBuilder().must(QueryBuilders.termsQuery("batchNo",list))
|
|
|
).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);
|
|
|
/*if (healthEduArticleESs != null && healthEduArticleESs.size() > 0) {
|
|
|
for (HealthEduArticleES healthEduArticleES : healthEduArticleESs) {
|
|
|
saveModels.add(healthEduArticleES);
|
|
|
}
|
|
|
}*/
|
|
|
//根据id批量删除
|
|
|
Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
|
|
|
for (HealthEduArticleES obj : healthEduArticleESs) {
|
|
|
if (obj != null) {
|
|
|
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());
|
|
|
return healthEduArticleESs.size();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return -1;
|
|
|
} finally {
|
|
|
if (jestClient != null) {
|
|
|
jestClient.shutdownClient();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Map<String ,Object> addBatchNo(String doctorCode){
|
|
|
Map<String,Object> resultMap = new HashedMap();
|
|
|
String sql ="SELECT " +
|
|
|
" id, " +
|
|
|
" patient, " +
|
|
|
" article, " +
|
|
|
" doctor, " +
|
|
|
" doctor_name, " +
|
|
|
" DATE_FORMAT(czrq,'%y-%m-%d')czrq, " +
|
|
|
" admin_team_code, " +
|
|
|
" batch_no " +
|
|
|
" FROM " +
|
|
|
" wlyy_health_edu_article_patient " +
|
|
|
" WHERE " +
|
|
|
" admin_team_code IS NOT NULL " +
|
|
|
" AND batch_no IS NULL " +
|
|
|
" AND doctor = '"+doctorCode+"' ORDER BY czrq ASC";
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
List<Map<String,String>> sqlList = new ArrayList<>();
|
|
|
if (list!=null && list.size()>0){
|
|
|
String oldArticleId = "";
|
|
|
String oldTime = "";
|
|
|
for (Map<String,Object> map : list){
|
|
|
if (!(map.get("article")+"").equals(oldArticleId) || !(map.get("czrq")+"").equals(oldTime)){
|
|
|
oldArticleId = map.get("article")+"";
|
|
|
oldTime = map.get("czrq")+"";
|
|
|
Map<String,String> sqlMap = new HashedMap();
|
|
|
sqlMap.put("id",oldArticleId);
|
|
|
sqlList.add(sqlMap);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
int a = 0;
|
|
|
if (sqlList!=null && sqlList.size()>0){
|
|
|
for (Map<String,String> map : sqlList){
|
|
|
String batchNo = String.valueOf(UUID.randomUUID());
|
|
|
batchNo = batchNo.replace("-","");
|
|
|
String id = map.get("id")+"";
|
|
|
String updateSql ="UPDATE wlyy_health_edu_article_patient " +
|
|
|
" SET batch_no = '"+batchNo+"' " +
|
|
|
" WHERE " +
|
|
|
" admin_team_code IS NOT NULL " +
|
|
|
" AND batch_no IS NULL " +
|
|
|
" AND article = '"+id+"' " +
|
|
|
" AND doctor = '"+doctorCode+"'";
|
|
|
a +=jdbcTemplate.update(updateSql);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
resultMap.put("count",a);
|
|
|
return resultMap;
|
|
|
}
|
|
|
}
|