|
@ -46,6 +46,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by zhangdan on 2017/12/25.
|
|
@ -114,9 +115,9 @@ public class EduArticleService {
|
|
|
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)){
|
|
|
if (firstList != null && firstList.size() > 0) {
|
|
|
for (NewCategoryModel newCategoryModel : firstList) {
|
|
|
if (newCategoryModel.getCategoryName().contains(firstName)) {
|
|
|
firstId = newCategoryModel.getCategoryId();
|
|
|
}
|
|
|
}
|
|
@ -146,7 +147,7 @@ public class EduArticleService {
|
|
|
newArticleModel.setArticleOrder(99);
|
|
|
newArticleModel.setArticleState(1);
|
|
|
newArticleModel.setOrgName("厦门市卫生与计划生育委员会");
|
|
|
newArticleModel.setArticleSource(wjwCode);
|
|
|
newArticleModel.setArticleSource("厦门市卫生与计划生育委员会");
|
|
|
newArticleModel.setArticlelevel(0);
|
|
|
newArticleModel.setOperatorName("厦门市卫生与计划生育委员会");
|
|
|
newArticleModel.setOperatorId(wjwCode);
|
|
@ -161,9 +162,9 @@ public class EduArticleService {
|
|
|
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())){
|
|
|
if (secondList != null && secondList.size() > 0) {
|
|
|
for (NewCategoryModel newCategoryModel : secondList) {
|
|
|
if (newCategoryModel.getCategoryName().equals(newArticleModel.getKeyWord())) {
|
|
|
newArticleModel.setSecondLevelCategoryId(newCategoryModel.getCategoryId());
|
|
|
newArticleModel.setSecondLevelCategoryName(newCategoryModel.getCategoryName());
|
|
|
}
|
|
@ -359,9 +360,9 @@ public class EduArticleService {
|
|
|
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)){
|
|
|
if (firstList != null && firstList.size() > 0) {
|
|
|
for (NewCategoryModel newCategoryModel : firstList) {
|
|
|
if (newCategoryModel.getCategoryName().contains(firstName)) {
|
|
|
firstId = newCategoryModel.getCategoryId();
|
|
|
}
|
|
|
}
|
|
@ -369,13 +370,13 @@ public class EduArticleService {
|
|
|
|
|
|
//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);
|
|
|
List<Map<String, Object>> batchNoCountMapList = jdbcTemplate.queryForList(batchNoCountSql);
|
|
|
|
|
|
//6.清洗数据
|
|
|
flag = CleanDateToEs(doctorMap,articleMap,wjwCode,firstId,firstName,secondList,batchNoCountMapList);
|
|
|
flag = CleanDateToEs(doctorMap, articleMap, wjwCode, firstId, firstName, secondList, batchNoCountMapList);
|
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
flag = false;
|
|
|
}
|
|
@ -384,6 +385,7 @@ public class EduArticleService {
|
|
|
|
|
|
/**
|
|
|
* 清洗数据到es
|
|
|
*
|
|
|
* @param doctorMap
|
|
|
* @param articleMap
|
|
|
* @param wjwCode
|
|
@ -394,7 +396,7 @@ public class EduArticleService {
|
|
|
* @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{
|
|
|
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";
|
|
@ -447,7 +449,7 @@ public class EduArticleService {
|
|
|
HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
|
|
|
//Map转对象
|
|
|
healthEduArticleES = MapListUtils.convertMap2Bean(map, HealthEduArticleES.class);
|
|
|
healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 1,firstId,firstName,secondList,batchNoCountMapList);
|
|
|
healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 1, firstId, firstName, secondList, batchNoCountMapList);
|
|
|
if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
|
|
|
healthEduArticleES.setDoctorCode(wjwCode);
|
|
|
//卫计委发送
|
|
@ -468,7 +470,7 @@ public class EduArticleService {
|
|
|
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){
|
|
|
for (Map<String, Object> map : batchNoMap) {
|
|
|
batchNoList.add(String.valueOf(map.get("batch_no")));
|
|
|
}
|
|
|
deleteData(2, batchNoList);
|
|
@ -500,7 +502,7 @@ public class EduArticleService {
|
|
|
healthEduArticleES.setNewArricleFlag(false);
|
|
|
//Map转对象
|
|
|
healthEduArticleES = MapListUtils.convertMap2Bean(map, HealthEduArticleES.class);
|
|
|
healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 2,firstId,firstName,secondList,batchNoCountMapList);
|
|
|
healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 2, firstId, firstName, secondList, batchNoCountMapList);
|
|
|
if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
|
|
|
healthEduArticleES.setDoctorCode(wjwCode);
|
|
|
//卫计委发送
|
|
@ -518,6 +520,7 @@ public class EduArticleService {
|
|
|
|
|
|
/**
|
|
|
* 封装Es存储对象
|
|
|
*
|
|
|
* @param healthEduArticleES
|
|
|
* @param doctorMap
|
|
|
* @param articleMap
|
|
@ -532,8 +535,8 @@ public class EduArticleService {
|
|
|
*/
|
|
|
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 {
|
|
|
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) {
|
|
@ -560,16 +563,16 @@ public class EduArticleService {
|
|
|
HealthEduArticle healthEduArticle = articleEntry.getValue();
|
|
|
healthEduArticleES.setArticleId(healthEduArticle.getCode());
|
|
|
healthEduArticleES.setArticleTitle(healthEduArticle.getTitle());
|
|
|
if (healthEduArticle.getContent().length()>=100){
|
|
|
healthEduArticleES.setArticleContent(healthEduArticle.getContent().substring(0,100));
|
|
|
}else {
|
|
|
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())){
|
|
|
if (secondList != null && secondList.size() > 0) {
|
|
|
for (NewCategoryModel newCategoryModel : secondList) {
|
|
|
if (newCategoryModel.getCategoryName().equals(healthEduArticle.getKeyword())) {
|
|
|
healthEduArticleES.setSecondLevelCategoryId(newCategoryModel.getCategoryId());
|
|
|
healthEduArticleES.setSecondLevelCategoryName(newCategoryModel.getCategoryName());
|
|
|
}
|
|
@ -579,25 +582,25 @@ public class EduArticleService {
|
|
|
}
|
|
|
}
|
|
|
//替换已读数据code
|
|
|
if (userType==1){
|
|
|
if (userType == 1) {
|
|
|
//数据库中的isRead 0已读,1未读--->Es中isRead 0未读 1已读
|
|
|
if (healthEduArticleES.getIsRead()==0){
|
|
|
if (healthEduArticleES.getIsRead() == 0) {
|
|
|
healthEduArticleES.setIsRead(1);
|
|
|
}else{
|
|
|
} 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")))){
|
|
|
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())){
|
|
|
if (!StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
|
|
|
//List<DoctorRole> roleList = doctorRoleDao.findUserRole(healthEduArticleES.getDoctorCode());
|
|
|
int resultLevel = 4;
|
|
|
/*if (roleList != null && roleList.size() > 0) {
|
|
@ -609,7 +612,7 @@ public class EduArticleService {
|
|
|
}*/
|
|
|
healthEduArticleES.setCurrentUserRoleCode(healthEduArticleES.getHospital());
|
|
|
healthEduArticleES.setCurrentUserRoleLevel(String.valueOf(resultLevel));
|
|
|
}else{
|
|
|
} else {
|
|
|
healthEduArticleES.setCurrentUserRoleCode(wjwCode);
|
|
|
healthEduArticleES.setCurrentUserRoleLevel("2");
|
|
|
}
|
|
@ -724,6 +727,171 @@ public class EduArticleService {
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
public Map<String, net.sf.json.JSONObject> getArticleSendToEsByBatchNo(String batchNos) throws Exception {
|
|
|
|
|
|
Map<String, net.sf.json.JSONObject> returnMap = new HashedMap();
|
|
|
String[] batchNosArr = batchNos.split(",");
|
|
|
//初始化文章
|
|
|
for (String batchNo : batchNosArr) {
|
|
|
net.sf.json.JSONObject o = new net.sf.json.JSONObject();
|
|
|
//删除同一哥批次号下的所有推送记录
|
|
|
deleteEsDataByBatch(batchNo);
|
|
|
//新增医生的推送记录
|
|
|
Integer size = saveByBatch(batchNo);
|
|
|
o.put("saveEsSize", size);
|
|
|
returnMap.put(batchNo, o);
|
|
|
}
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据批次号batchNo删除es数据
|
|
|
*
|
|
|
* @param batchNo
|
|
|
*/
|
|
|
private void deleteEsDataByBatch(String batchNo) {
|
|
|
JestClient jestClient = null;
|
|
|
try {
|
|
|
int i = 0;
|
|
|
jestClient = elasticFactory.getJestClient();
|
|
|
Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
|
|
|
String sql = "select id from " + esIndex + " where batchNo='" + batchNo + "'";
|
|
|
List<Map<String, Object>> returnList = elasticsearchUtil.excuteDataModel(sql);
|
|
|
//根据id批量删除
|
|
|
for (Map<String, Object> obj : returnList) {
|
|
|
if (obj.containsKey("_id")) {
|
|
|
i++;
|
|
|
Delete index = new Delete.Builder(obj.get("id").toString()).build();
|
|
|
bulk.addAction(index);
|
|
|
}
|
|
|
}
|
|
|
BulkResult br = jestClient.execute(bulk.build());
|
|
|
|
|
|
logger.info("delete data count:" + i);
|
|
|
logger.info("delete flag:" + br.isSucceeded());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
if (jestClient != null) {
|
|
|
jestClient.shutdownClient();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private int saveByBatch(String batchNo) throws Exception {
|
|
|
//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.获取卫计委code
|
|
|
String sqlwjw = "select code AS wjwCode from wlyy_role WHERE name LIKE '%厦门市卫生与计划生育委员会%' and LENGTH(code)=6";
|
|
|
Map<String, Object> result = jdbcTemplate.queryForMap(sqlwjw);
|
|
|
String wjwCode = result.get("wjwCode") + "";
|
|
|
|
|
|
//3.查询所有一级类别、二级类别
|
|
|
List<NewCategoryModel> firstList = jkeduCategoryDao.findCategory(1);
|
|
|
List<NewCategoryModel> secondList = jkeduCategoryDao.findCategory(2);
|
|
|
String firstIdStr = "";
|
|
|
String firstName = "健康文章";
|
|
|
if (firstList != null && firstList.size() > 0) {
|
|
|
for (NewCategoryModel newCategoryModel : firstList) {
|
|
|
if (newCategoryModel.getCategoryName().contains(firstName)) {
|
|
|
firstIdStr = newCategoryModel.getCategoryId();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
final String firstId = firstIdStr;
|
|
|
|
|
|
//4.获取同一个批次号的推送记录,基本同一个批次号是同一个医生发送的,也是同一篇文章
|
|
|
String sql = "select * from wlyy_health_edu_article_patient_copy where admin_team_code IS NOT NULL AND batch_no IS NOT NULL AND batch_no='" + batchNo + "'";
|
|
|
List<HealthEduArticlePatient> healthEduArticlePatients = jdbcTemplate.query(sql, new BeanPropertyRowMapper(HealthEduArticlePatient.class));
|
|
|
|
|
|
//5.转换成新的健康教育需要的数据
|
|
|
List<HealthEduArticleES> healthEduArticleESSaveList = new ArrayList<>();
|
|
|
if (healthEduArticlePatients != null && healthEduArticlePatients.size() > 0) {
|
|
|
String doctorCode = healthEduArticlePatients.get(0).getDoctor();
|
|
|
Doctor doctor = doctorDao.findByCode(doctorCode);
|
|
|
AdminTeam adminTeam = doctorAdminTeamDao.findOne(healthEduArticlePatients.get(0).getAdminTeamCode());
|
|
|
HealthEduArticle healthEduArticle = healthEduArticleDao.findByCode(healthEduArticlePatients.get(0).getArticle());
|
|
|
for (HealthEduArticlePatient healthEduArticlePatient : healthEduArticlePatients) {
|
|
|
HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
|
|
|
|
|
|
healthEduArticleES.setBatchNo(batchNo);
|
|
|
healthEduArticleES.setPatientCode(healthEduArticlePatient.getPatient());
|
|
|
healthEduArticleES.setPatientName(patientDao.findByCode(healthEduArticlePatient.getPatient()).getName());
|
|
|
|
|
|
//医生
|
|
|
healthEduArticleES.setDoctorCode(doctor.getCode());
|
|
|
healthEduArticleES.setDoctorName(doctor.getName());
|
|
|
healthEduArticleES.setSendName(doctor.getName());
|
|
|
healthEduArticleES.setSendPic(doctor.getPhoto());
|
|
|
healthEduArticleES.setSendSex(doctor.getSex() != null ? String.valueOf(doctor.getSex()) : "");
|
|
|
healthEduArticleES.setHospital(doctor.getHospital());
|
|
|
healthEduArticleES.setHospitalName(doctor.getHospitalName());
|
|
|
healthEduArticleES.setTown(doctor.getTown());
|
|
|
healthEduArticleES.setTownName(doctor.getTownName());
|
|
|
healthEduArticleES.setSendType(1);
|
|
|
healthEduArticleES.setSendLevel(doctor.getLevel() != null ? String.valueOf(doctor.getLevel()) : "");
|
|
|
healthEduArticleES.setCurrentUserRoleCode(healthEduArticleES.getHospital());
|
|
|
//文章
|
|
|
healthEduArticleES.setArticleId(healthEduArticle.getCode());
|
|
|
healthEduArticleES.setArticleTitle(healthEduArticle.getTitle());
|
|
|
healthEduArticleES.setArticleCover(healthEduArticle.getUrl());
|
|
|
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());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//数据库中的isRead 0已读,1未读--->Es中isRead 0未读 1已读
|
|
|
if (healthEduArticlePatient.getRead() == null) {
|
|
|
healthEduArticleES.setIsRead(1);
|
|
|
healthEduArticleES.setCzrq(healthEduArticlePatient.getCzrq());
|
|
|
} else {
|
|
|
healthEduArticleES.setCzrq(null);
|
|
|
healthEduArticleES.setIsRead(0);
|
|
|
}
|
|
|
if (adminTeam != null) {
|
|
|
healthEduArticleES.setAdminTeamName(adminTeam.getName());
|
|
|
healthEduArticleES.setAdminTeamCode(adminTeam.getId());
|
|
|
}
|
|
|
healthEduArticleES.setAllCount(healthEduArticlePatients.size());
|
|
|
healthEduArticleES.setCreateTime(new Date());
|
|
|
healthEduArticleES.setUserType(1);
|
|
|
healthEduArticleES.setOperatorId(wjwCode);
|
|
|
healthEduArticleES.setArticleSource("厦门市卫生与计划生育委员会");
|
|
|
|
|
|
healthEduArticleESSaveList.add(healthEduArticleES);
|
|
|
}
|
|
|
if (healthEduArticleESSaveList != null && healthEduArticleESSaveList.size() > 0) {
|
|
|
HealthEduArticleES healthEduArticleESUserType2 = healthEduArticleESSaveList.get(0);
|
|
|
healthEduArticleESUserType2.setUserType(2);
|
|
|
healthEduArticleESUserType2.setCzrq(null);
|
|
|
healthEduArticleESUserType2.setPatientCode(null);
|
|
|
healthEduArticleESUserType2.setPatientName(null);
|
|
|
healthEduArticleESSaveList.add(healthEduArticleESUserType2);
|
|
|
}
|
|
|
|
|
|
//数据存到ES
|
|
|
saveDate(healthEduArticleESSaveList);
|
|
|
}
|
|
|
return healthEduArticleESSaveList.size();
|
|
|
}
|
|
|
|
|
|
public Map<String, net.sf.json.JSONObject> getArticleSendToEsByDoctor(String doctorCodes) throws Exception {
|
|
|
|
|
|
Map<String, net.sf.json.JSONObject> returnMap = new HashedMap();
|
|
@ -750,27 +918,23 @@ public class EduArticleService {
|
|
|
JestClient jestClient = null;
|
|
|
try {
|
|
|
jestClient = elasticFactory.getJestClient();
|
|
|
Integer i = 0;
|
|
|
//先根据条件查找出来
|
|
|
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);
|
|
|
String sql = "select id from " + esIndex + " where doctorCode='" + doctorCode + "'";
|
|
|
List<Map<String, Object>> returnList = elasticsearchUtil.excuteDataModel(sql);
|
|
|
//根据id批量删除
|
|
|
for (Map<String, Object> obj : returnList) {
|
|
|
if (obj.containsKey("_id")) {
|
|
|
i++;
|
|
|
Delete index = new Delete.Builder(obj.get("id").toString()).build();
|
|
|
bulk.addAction(index);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
BulkResult br = jestClient.execute(bulk.build());
|
|
|
|
|
|
logger.info("delete data count:" + healthEduArticleESs.size());
|
|
|
logger.info("delete data count:" + i);
|
|
|
logger.info("delete flag:" + br.isSucceeded());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@ -796,8 +960,28 @@ public class EduArticleService {
|
|
|
articleMap.put(healthEduArticle.getCode(), healthEduArticle);
|
|
|
}
|
|
|
}
|
|
|
//2.获取医生的推送记录
|
|
|
String sql = "select * from wlyy_health_edu_article_patient where doctor='" + doctorCode + "'";
|
|
|
|
|
|
//2.获取卫计委code
|
|
|
String sqlwjw = "select code AS wjwCode from wlyy_role WHERE name LIKE '%厦门市卫生与计划生育委员会%' and LENGTH(code)=6";
|
|
|
Map<String, Object> result = jdbcTemplate.queryForMap(sqlwjw);
|
|
|
String wjwCode = result.get("wjwCode") + "";
|
|
|
|
|
|
//3.查询所有一级类别、二级类别
|
|
|
List<NewCategoryModel> firstList = jkeduCategoryDao.findCategory(1);
|
|
|
List<NewCategoryModel> secondList = jkeduCategoryDao.findCategory(2);
|
|
|
String firstIdStr = "";
|
|
|
String firstName = "健康文章";
|
|
|
if (firstList != null && firstList.size() > 0) {
|
|
|
for (NewCategoryModel newCategoryModel : firstList) {
|
|
|
if (newCategoryModel.getCategoryName().contains(firstName)) {
|
|
|
firstIdStr = newCategoryModel.getCategoryId();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
final String firstId = firstIdStr;
|
|
|
|
|
|
//4.获取医生的推送记录
|
|
|
String sql = "select * from wlyy_health_edu_article_patient_copy where admin_team_code IS NOT NULL AND batch_no IS NOT NULL AND doctor='" + doctorCode + "'";
|
|
|
List<HealthEduArticlePatient> healthEduArticlePatients = jdbcTemplate.query(sql, new BeanPropertyRowMapper(HealthEduArticlePatient.class));
|
|
|
//推送记录按照批次号分组
|
|
|
Map<String, List<HealthEduArticlePatient>> healthEduArticlePatientMap = new HashMap<>();
|
|
@ -812,7 +996,7 @@ public class EduArticleService {
|
|
|
//3.转换成新的健康教育需要的数据
|
|
|
List<HealthEduArticleES> healthEduArticleESSaveList = new ArrayList<>();
|
|
|
//获取医生的角色
|
|
|
Map<String,Object> roleMaps= gcLabelService.fetchUserHighestAuthority(doctorCode);
|
|
|
Map<String, Object> roleMaps = gcLabelService.fetchUserHighestAuthority(doctorCode);
|
|
|
|
|
|
healthEduArticlePatientMap.keySet().stream().forEach(one -> {
|
|
|
//获取患者数据
|
|
@ -827,16 +1011,20 @@ public class EduArticleService {
|
|
|
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.setSendSex(doctor.getSex() != null ? String.valueOf(doctor.getSex()) : "");
|
|
|
healthEduArticleES.setHospital(doctor.getHospital());
|
|
|
healthEduArticleES.setHospitalName(doctor.getHospitalName());
|
|
|
healthEduArticleES.setTown(doctor.getTown());
|
|
|
healthEduArticleES.setTownName(doctor.getTownName());
|
|
|
healthEduArticleES.setSendType(1);
|
|
|
healthEduArticleES.setSendLevel(doctor.getLevel() != null ? String.valueOf(doctor.getLevel()) : "");
|
|
|
healthEduArticleES.setSendSource(1);//旧数据都是1 i健康发送
|
|
|
healthEduArticleES.setSendType(1);//默认是医生发送
|
|
|
if(roleMaps!=null){
|
|
|
// healthEduArticleES.setCurrentUserRoleLevel("2");
|
|
|
// healthEduArticleES.setCurrentUserRoleCode();
|
|
|
}else{
|
|
|
|
|
|
healthEduArticleES.setCurrentUserRoleCode(doctor.getHospital());
|
|
|
if (roleMaps != null) {
|
|
|
healthEduArticleES.setCurrentUserRoleLevel(roleMaps.get("level") + "");
|
|
|
} else {
|
|
|
healthEduArticleES.setCurrentUserRoleLevel("4");
|
|
|
}
|
|
|
|
|
|
healthEduArticleES.setBatchNo(healthEduArticlePatient.getBatchNo());
|
|
@ -845,23 +1033,42 @@ public class EduArticleService {
|
|
|
|
|
|
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.setOperatorId(wjwCode); //之前旧数据没有文章作者 默认是发送人
|
|
|
healthEduArticleES.setArticleSource("厦门市卫生与计划生育委员会");//文章来源 旧数据默认是医生的所在团队的所属机构
|
|
|
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());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//数据库中的isRead 0已读,1未读--->Es中isRead 0未读 1已读
|
|
|
if (healthEduArticlePatient.getRead() == null) {
|
|
|
healthEduArticleES.setIsRead(1);
|
|
|
healthEduArticleES.setCzrq(healthEduArticlePatient.getCzrq());
|
|
|
} else {
|
|
|
healthEduArticleES.setCzrq(null);
|
|
|
healthEduArticleES.setIsRead(0);
|
|
|
}
|
|
|
|
|
|
healthEduArticleES.setAdminTeamCode(adminTeam.getId());
|
|
|
healthEduArticleES.setAdminTeamName(adminTeam.getName());
|
|
|
healthEduArticleES.setHospital(adminTeam.getOrgCode());
|
|
|
healthEduArticleES.setHospitalName(adminTeam.getOrgName());
|
|
|
healthEduArticleES.setTown(adminTeam.getTownCode());
|
|
|
healthEduArticleES.setTownName(adminTeam.getTownName());
|
|
|
if (adminTeam!=null){
|
|
|
healthEduArticleES.setAdminTeamCode(adminTeam.getId());
|
|
|
healthEduArticleES.setAdminTeamName(adminTeam.getName());
|
|
|
}
|
|
|
|
|
|
healthEduArticleES.setCreateTime(new Date());
|
|
|
healthEduArticleES.setUserType(1);//患者
|
|
|
|
|
|
healthEduArticleES.setAllCount(healthEduArticlePatientTemps.size());
|
|
|
healthEduArticleESSaveList.add(healthEduArticleES);
|
|
|
|
|
|
|
|
@ -879,26 +1086,47 @@ public class EduArticleService {
|
|
|
healthEduArticleES.setSendLevel(doctor.getLevel().toString());
|
|
|
healthEduArticleES.setSendSource(1);//旧数据都是1 i健康发送
|
|
|
healthEduArticleES.setSendType(1);//默认是医生发送
|
|
|
healthEduArticleES.setHospital(doctor.getHospital());
|
|
|
healthEduArticleES.setHospitalName(doctor.getHospitalName());
|
|
|
healthEduArticleES.setTown(doctor.getTown());
|
|
|
healthEduArticleES.setTownName(doctor.getTownName());
|
|
|
|
|
|
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.setOperatorId(wjwCode); //之前旧数据没有文章作者 默认是卫计委
|
|
|
healthEduArticleES.setArticleSource("厦门市卫生与计划生育委员会");//文章来源 旧数据默认是卫计委
|
|
|
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 (adminTeam != null) {
|
|
|
healthEduArticleES.setAdminTeamCode(adminTeam.getId());
|
|
|
healthEduArticleES.setAdminTeamName(adminTeam.getName());
|
|
|
}
|
|
|
healthEduArticleES.setUserType(2); //医生
|
|
|
healthEduArticleES.setAllCount(healthEduArticlePatientTemps.size());
|
|
|
|
|
|
healthEduArticleES.setCurrentUserRoleCode(doctor.getHospital());
|
|
|
if (roleMaps != null) {
|
|
|
healthEduArticleES.setCurrentUserRoleLevel(roleMaps.get("level") + "");
|
|
|
} else {
|
|
|
healthEduArticleES.setCurrentUserRoleLevel("4");
|
|
|
}
|
|
|
healthEduArticleES.setCreateTime(new Date());
|
|
|
|
|
|
healthEduArticleESSaveList.add(healthEduArticleES);
|
|
@ -912,25 +1140,19 @@ public class EduArticleService {
|
|
|
|
|
|
/**
|
|
|
* 删除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));
|
|
|
public Map<String, Object> deleteEsOldArticlePatient() throws Exception {
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|
|
|
|
|
|
String sql = "select batch_no code 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>> queryids = jdbcTemplate.queryForList(sql);
|
|
|
List<String> ids = queryids.stream().map(one -> one.containsKey("code") ? one.get("code").toString() : "").collect(Collectors.toList());
|
|
|
int count = deleteEsByBatchNo(ids);
|
|
|
returnMap.put("deleteBatch", ids.size());
|
|
|
returnMap.put("deleteCount", Integer.valueOf(count));
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
@ -939,31 +1161,27 @@ public class EduArticleService {
|
|
|
JestClient jestClient = null;
|
|
|
//List<HealthEduArticleES> saveModels = new ArrayList<>();
|
|
|
try {
|
|
|
int i = 0;
|
|
|
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);
|
|
|
for (String batchNo : list) {
|
|
|
String sql = "select id from " + esIndex + " where batchNo='" + batchNo + "' limit 0,50000";
|
|
|
List<Map<String, Object>> returnList = elasticsearchUtil.excuteDataModel(sql);
|
|
|
//根据id批量删除
|
|
|
for (Map<String, Object> obj : returnList) {
|
|
|
if (obj.containsKey("_id")) {
|
|
|
Delete index = new Delete.Builder(obj.get("_id").toString()).build();
|
|
|
bulk.addAction(index);
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
BulkResult br = jestClient.execute(bulk.build());
|
|
|
logger.info("delete data count:" + healthEduArticleESs.size());
|
|
|
logger.info("delete data count:" + i);
|
|
|
logger.info("delete flag:" + br.isSucceeded());
|
|
|
return healthEduArticleESs.size();
|
|
|
return i;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return -1;
|
|
@ -974,9 +1192,9 @@ public class EduArticleService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Map<String ,Object> addBatchNo(String doctorCode){
|
|
|
Map<String,Object> resultMap = new HashedMap();
|
|
|
String sql ="SELECT " +
|
|
|
public Map<String, Object> addBatchNo(String doctorCode) {
|
|
|
Map<String, Object> resultMap = new HashedMap();
|
|
|
String sql = "SELECT " +
|
|
|
" id, " +
|
|
|
" patient, " +
|
|
|
" article, " +
|
|
@ -990,40 +1208,41 @@ public class EduArticleService {
|
|
|
" 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){
|
|
|
" 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);
|
|
|
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){
|
|
|
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+"' " +
|
|
|
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);
|
|
|
" AND article = '" + id + "' " +
|
|
|
" AND doctor = '" + doctorCode + "'";
|
|
|
a += jdbcTemplate.update(updateSql);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
resultMap.put("count",a);
|
|
|
resultMap.put("count", a);
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
}
|