|
@ -0,0 +1,377 @@
|
|
|
|
package com.yihu.wlyy.web.third.jkedu.service;
|
|
|
|
|
|
|
|
|
|
|
|
import com.yihu.edu.entity.dataClean.*;
|
|
|
|
import com.yihu.es.entity.HealthEduArticlePatient;
|
|
|
|
import com.yihu.wlyy.config.es.ElastricSearchSave;
|
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
|
import com.yihu.wlyy.entity.education.HealthEduArticle;
|
|
|
|
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.JkeduCollectionArticleDao;
|
|
|
|
import com.yihu.wlyy.repository.doctor.DoctorDao;
|
|
|
|
import com.yihu.wlyy.repository.education.HealthEduArticleDao;
|
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
|
import com.yihu.wlyy.util.MapListUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by zhangdan on 2017/12/25.
|
|
|
|
*/
|
|
|
|
@Service
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public class EduArticleService {
|
|
|
|
@Autowired
|
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
@Autowired
|
|
|
|
private DoctorDao doctorDao;
|
|
|
|
@Autowired
|
|
|
|
private ElastricSearchSave elastricSearchSave;
|
|
|
|
@Autowired
|
|
|
|
private HealthEduArticleDao healthEduArticleDao;
|
|
|
|
@Autowired
|
|
|
|
private JkeduArticleDao jkeduArticleDao;
|
|
|
|
@Autowired
|
|
|
|
private JkeduCollectionArticleDao jkeduCollectionArticleDao;
|
|
|
|
@Autowired
|
|
|
|
private JkeduBehaviorArticleDao jkeduBehaviorArticleDao;
|
|
|
|
|
|
|
|
@Value("${es.type.HealthEduArticlePatient}")
|
|
|
|
private String esType;
|
|
|
|
@Value("${es.index.HealthEduArticlePatient}")
|
|
|
|
private String esIndex;
|
|
|
|
|
|
|
|
private static int pageSize = 1000;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 健康教育文章列表转移
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean getArticleListToNewDataBase(){
|
|
|
|
boolean flag = true;
|
|
|
|
//获取卫计委code
|
|
|
|
String wjwSql = "select code AS wjwCode from wlyy_role WHERE name LIKE '%厦门市卫生与计划生育委员会%' and LENGTH(code)=6";
|
|
|
|
Map<String, Object> result = jdbcTemplate.queryForMap(wjwSql);
|
|
|
|
String wjwCode = result.get("wjwCode") + "";
|
|
|
|
//先将原来数据库的数据删除
|
|
|
|
List<NewArticleModel> delOldList = jkeduArticleDao.findOldArticle();
|
|
|
|
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){
|
|
|
|
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, " +
|
|
|
|
"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;
|
|
|
|
//分页查询数据
|
|
|
|
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);
|
|
|
|
//@// TODO: 2017/12/25 完善数据
|
|
|
|
BeanUtils.copyProperties(oldArticleModel,newArticleModel);
|
|
|
|
newArticleModel.setArticleOrder(99);
|
|
|
|
newArticleModel.setArticleState(1);
|
|
|
|
newArticleModel.setOrgName("厦门市卫生与计划生育委员会");
|
|
|
|
//id
|
|
|
|
newArticleModel.setArticleSource(wjwCode);
|
|
|
|
newArticleModel.setArticlelevel(0);
|
|
|
|
newArticleModel.setOperatorName("厦门市卫生与计划生育委员会");
|
|
|
|
newArticleModel.setOperatorId(wjwCode);
|
|
|
|
newArticleModel.setAuthentication("厦门市卫生与计划生育委员会");
|
|
|
|
newArticleModel.setAuthenticationId(wjwCode);
|
|
|
|
newArticleModel.setIsAuthentication(1);
|
|
|
|
newArticleModel.setArticleType("2");
|
|
|
|
newArticleModel.setOperatorRoleCode("管理员code");
|
|
|
|
newArticleModel.setOperatorRoleLevel("管理员");
|
|
|
|
newArticleModel.setRoleType(2);
|
|
|
|
newArticleModel.setUserScope(1);
|
|
|
|
newArticleModel.setIsOld(1);
|
|
|
|
newList.add(newArticleModel);
|
|
|
|
}
|
|
|
|
//执行插入新数据库
|
|
|
|
jkeduArticleDao.save(newList);
|
|
|
|
}catch (Exception e){
|
|
|
|
e.printStackTrace();
|
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 健康教育收藏列表转移
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean getArticleCollectToNewDataBase(){
|
|
|
|
boolean flag = true;
|
|
|
|
try {
|
|
|
|
//获取卫计委code
|
|
|
|
String wjwSql = "select code AS wjwCode from wlyy_role WHERE name LIKE '%厦门市卫生与计划生育委员会%' and LENGTH(code)=6";
|
|
|
|
Map<String, Object> result = jdbcTemplate.queryForMap(wjwSql);
|
|
|
|
String wjwCode = result.get("wjwCode") + "";
|
|
|
|
//先将原来数据库的数据删除
|
|
|
|
List<Integer> delOldList = jkeduCollectionArticleDao.findOldArticleCollection();
|
|
|
|
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++){
|
|
|
|
List idsList = new ArrayList<>();
|
|
|
|
for (int j =0;j<1000;j++){
|
|
|
|
if (count<=delOldList.size()){
|
|
|
|
idsList.add(delOldList.get(j+i*1000));
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
jkeduCollectionArticleDao.deleteByIds(idsList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//先分页查询
|
|
|
|
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" +
|
|
|
|
" ad.doctor AS UserId," +
|
|
|
|
" ad.article AS ArticleId, " +
|
|
|
|
" ad.url, " +
|
|
|
|
" ad.title, " +
|
|
|
|
" ad.content, " +
|
|
|
|
" ad.czrq AS InsertTime, " +
|
|
|
|
" d.`name` AS CName " +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_health_edu_article_doctor ad " +
|
|
|
|
" LEFT JOIN wlyy_doctor d ON ad.doctor = d. CODE LIMIT ?,?";
|
|
|
|
List<NewArticleCollectModel> 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});
|
|
|
|
for (Map<String, Object> map : list) {
|
|
|
|
OldArticleCollectModel oldArticleCollectModel = new OldArticleCollectModel();
|
|
|
|
NewArticleCollectModel newArticleCollectModel = new NewArticleCollectModel();
|
|
|
|
oldArticleCollectModel = MapListUtils.convertMap2Bean(map,OldArticleCollectModel.class);
|
|
|
|
//@// TODO: 2017/12/25 完善数据
|
|
|
|
BeanUtils.copyProperties(oldArticleCollectModel,newArticleCollectModel);
|
|
|
|
newArticleCollectModel.setUserType(1);
|
|
|
|
newArticleCollectModel.setOrgName("厦门市卫生与计划生育委员会");
|
|
|
|
newArticleCollectModel.setOrgId(wjwCode);
|
|
|
|
newArticleCollectModel.setIsOld(1);
|
|
|
|
newList.add(newArticleCollectModel);
|
|
|
|
}
|
|
|
|
//跨数据库插入数据
|
|
|
|
jkeduCollectionArticleDao.save(newList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch (Exception e){
|
|
|
|
e.printStackTrace();
|
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 转移健康教育行为
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean getArticleBehaviorToNewDataBase(){
|
|
|
|
boolean flag = true;
|
|
|
|
try {
|
|
|
|
//数量也许过大,分批次删除
|
|
|
|
//先将原来数据库的数据删除
|
|
|
|
List<NewArticleBehaviorModel> delOldList = jkeduBehaviorArticleDao.findOldArticleBehavior();
|
|
|
|
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++){
|
|
|
|
List idsList = new ArrayList<>();
|
|
|
|
for (int j =0;j<1000;j++){
|
|
|
|
if (count<=delOldList.size()){
|
|
|
|
idsList.add(delOldList.get(j+i*1000).getID());
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
jkeduBehaviorArticleDao.deleteByIds(idsList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//分批次查询
|
|
|
|
String countSql = "select COUNT(1) AS num from wlyy_health_edu_article_op_history";
|
|
|
|
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," +
|
|
|
|
" 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});
|
|
|
|
for (Map<String, Object> map : list) {
|
|
|
|
OldArticleBehaviorModel oldArticleBehaviorModel = new OldArticleBehaviorModel();
|
|
|
|
NewArticleBehaviorModel newArticleBehaviorModel = new NewArticleBehaviorModel();
|
|
|
|
oldArticleBehaviorModel = MapListUtils.convertMap2Bean(map,OldArticleBehaviorModel.class);
|
|
|
|
//@// TODO: 2017/12/25 完善数据
|
|
|
|
BeanUtils.copyProperties(oldArticleBehaviorModel,newArticleBehaviorModel);
|
|
|
|
if (newArticleBehaviorModel.getBehaviorAction()==1){
|
|
|
|
newArticleBehaviorModel.setBehaviorAction(5);
|
|
|
|
}
|
|
|
|
newArticleBehaviorModel.setIsOld(1);
|
|
|
|
newList.add(newArticleBehaviorModel);
|
|
|
|
}
|
|
|
|
//跨数据库插入数据
|
|
|
|
jkeduBehaviorArticleDao.save(newList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch (Exception e){
|
|
|
|
e.printStackTrace();
|
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 数据转移至Es
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean getArticleSendedListToEs(){
|
|
|
|
boolean flag = true;
|
|
|
|
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") + "";
|
|
|
|
//转移到数据库的时候按照批次来聚合
|
|
|
|
sql = "SELECT batch_no ,article,doctor,doctor_name,admin_team_code,czrq " +
|
|
|
|
" FROM wlyy_health_edu_article_patient " +
|
|
|
|
" WHERE batch_no IS NOT NULL GROUP BY batch_no";
|
|
|
|
List<Map<String,Object>> resultList = jdbcTemplate.queryForList(sql);
|
|
|
|
if (CollectionUtils.isEmpty(resultList)){
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Map<String, Object> map: resultList){
|
|
|
|
List<Map<String,Object>> articleList = null;
|
|
|
|
String batchNo = map.get("batch_no")+"";
|
|
|
|
String article = map.get("article")+"";
|
|
|
|
String doctorCode = map.get("doctor")+"";
|
|
|
|
String adminTeamId = map.get("admin_team_code")+"";
|
|
|
|
String czrq = map.get("czrq")+"";
|
|
|
|
//同一个批次号只会有一篇文章
|
|
|
|
String batchSql = "select * from wlyy_health_edu_article_patient where batch_no = '"+batchNo+"'";
|
|
|
|
HealthEduArticlePatient healthEduArticlePatient = setDateToObj(batchSql,doctorCode,adminTeamId,wjwCode,batchNo,article,czrq);
|
|
|
|
//保存到Es中
|
|
|
|
elastricSearchSave.save(healthEduArticlePatient, esIndex, esType);
|
|
|
|
}
|
|
|
|
}catch (Exception e){
|
|
|
|
e.printStackTrace();
|
|
|
|
flag= false;
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
public HealthEduArticlePatient setDateToObj(String batchSql,String doctorCode,String adminTeamId,String wjwCode,String batchNo,String article,String czrq)throws Exception{
|
|
|
|
HealthEduArticlePatient healthEduArticlePatient = new HealthEduArticlePatient();
|
|
|
|
//创建对象
|
|
|
|
List<Map<String,Object>> articleList= jdbcTemplate.queryForList(batchSql);
|
|
|
|
//放置患者集合
|
|
|
|
if (!CollectionUtils.isEmpty(articleList)){
|
|
|
|
List<Patient> patientList = new ArrayList<>();
|
|
|
|
for (Map<String,Object> sendMap: articleList){
|
|
|
|
patientList.add(new Patient(sendMap.get("patient")+""));
|
|
|
|
}
|
|
|
|
healthEduArticlePatient.setPatients(patientList);
|
|
|
|
}
|
|
|
|
Doctor doctor = doctorDao.findByCode(doctorCode);
|
|
|
|
healthEduArticlePatient.setAdminTeamCode(Long.valueOf(adminTeamId));
|
|
|
|
if (doctor!=null){
|
|
|
|
healthEduArticlePatient.setDoctorCode(doctor.getCode());
|
|
|
|
healthEduArticlePatient.setSendName(doctor.getCode());
|
|
|
|
healthEduArticlePatient.setDoctorName(doctor.getName());
|
|
|
|
healthEduArticlePatient.setSendType(1);
|
|
|
|
healthEduArticlePatient.setHospital(doctor.getHospital());
|
|
|
|
healthEduArticlePatient.setHospitalName(doctor.getHospitalName());
|
|
|
|
healthEduArticlePatient.setTown(doctor.getTown());
|
|
|
|
healthEduArticlePatient.setTownName(doctor.getTownName());
|
|
|
|
healthEduArticlePatient.setSendLevel(doctor.getLevel() != null ? String.valueOf(doctor.getLevel()) : "");
|
|
|
|
healthEduArticlePatient.setSendPic(doctor.getPhoto());
|
|
|
|
healthEduArticlePatient.setSendSex(doctor.getSex() != null ? String.valueOf(doctor.getSex()) : "");
|
|
|
|
}else{
|
|
|
|
healthEduArticlePatient.setDoctorCode(wjwCode);
|
|
|
|
healthEduArticlePatient.setSendName("厦门市卫生与计划生育委员会");
|
|
|
|
healthEduArticlePatient.setDoctorName("厦门市卫生与计划生育委员会");
|
|
|
|
healthEduArticlePatient.setSendType(2);
|
|
|
|
}
|
|
|
|
healthEduArticlePatient.setBatchNo(batchNo);
|
|
|
|
Date czrqDate = DateUtil.strToDate(czrq);
|
|
|
|
healthEduArticlePatient.setCreateTime(czrqDate);
|
|
|
|
//获取文章详情
|
|
|
|
HealthEduArticle healthEduArticle = healthEduArticleDao.findByCode(article);
|
|
|
|
healthEduArticlePatient.setArticleId(healthEduArticle.getCode());
|
|
|
|
healthEduArticlePatient.setAttachedTitle(healthEduArticle.getTitle());
|
|
|
|
healthEduArticlePatient.setAttachedContent(healthEduArticle.getContent());
|
|
|
|
healthEduArticlePatient.setArticleType("2");
|
|
|
|
healthEduArticlePatient.setLevel("1");
|
|
|
|
healthEduArticlePatient.setType("1");//文章
|
|
|
|
//healthEduArticlePatient.setAttachedPic("");
|
|
|
|
//healthEduArticlePatient.setAttachedMessage(sendMessage);
|
|
|
|
//healthEduArticlePatient.setLevel1Type(article.get("firstLevelCategoryId") + "");
|
|
|
|
//healthEduArticlePatient.setLevel2Type(article.get("secondLevelCategoryId") + "");
|
|
|
|
return healthEduArticlePatient;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
public void save(){
|
|
|
|
NewArticleModel newArticleModel = new NewArticleModel();
|
|
|
|
newArticleModel.setArticleId("123");
|
|
|
|
newArticleModel.setArticleTitle("测试123");
|
|
|
|
newArticleModel.setArticleContent("测试123内容");
|
|
|
|
newArticleModel.setArticleState(1);
|
|
|
|
newArticleModel.setIsAuthentication(1);
|
|
|
|
newArticleModel.setArticleOrder(99);
|
|
|
|
newArticleModel.setArticleState(1);
|
|
|
|
newArticleModel.setOrgName("厦门市卫生与计划生育委员会");
|
|
|
|
newArticleModel.setArticleSource("厦门市卫生与计划生育委员会");//id
|
|
|
|
newArticleModel.setArticlelevel(0);
|
|
|
|
newArticleModel.setOperatorName("厦门市卫生与计划生育委员会");
|
|
|
|
newArticleModel.setOperatorId("");
|
|
|
|
newArticleModel.setAuthentication("厦门市卫生与计划生育委员会");
|
|
|
|
newArticleModel.setAuthenticationId("");
|
|
|
|
newArticleModel.setIsAuthentication(1);
|
|
|
|
newArticleModel.setArticleType("2");
|
|
|
|
newArticleModel.setOperatorRoleCode("管理员code");
|
|
|
|
newArticleModel.setOperatorRoleLevel("管理员");
|
|
|
|
newArticleModel.setRoleType(2);
|
|
|
|
newArticleModel.setUserScope(1);
|
|
|
|
jkeduArticleDao.save(newArticleModel);
|
|
|
|
}
|
|
|
|
}
|