|  | @ -1,14 +1,20 @@
 | 
	
		
			
				|  |  | package com.yihu.wlyy.web.third.gateway.service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //import com.yihu.es.entity.ArticleTest;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.es.entity.HealthEduArticlePatient;
 | 
	
		
			
				|  |  | import com.yihu.es.entity.HealthEduArticlePatientESModel;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.config.es.ElastricSearchSave;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.doctor.profile.Doctor;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.Patient;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.SignFamily;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.doctor.DoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.education.HealthEduArticlePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.patient.PatientDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.patient.SignFamilyDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.app.health.HealthEduArticleOpHistoryService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.common.account.PatientService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.third.fzzb.HealthEducationArticleService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.ElasticsearchUtil;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.web.third.gateway.vo.HealthEduArticlePatientModel;
 | 
	
		
			
				|  |  | import org.springframework.beans.BeanUtils;
 | 
	
	
		
			
				|  | @ -20,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | import org.springframework.util.StringUtils;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
	
		
			
				|  | @ -37,6 +44,12 @@ public class GcEduArticleService {
 | 
	
		
			
				|  |  |     private HealthEduArticlePatientDao healthEduArticlePatientDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DoctorDao doctorDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private HealthEducationArticleService healthEducationArticleService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientService patientService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientDao patientDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ElastricSearchSave elastricSearchSave;
 | 
	
	
		
			
				|  | @ -65,14 +78,16 @@ public class GcEduArticleService {
 | 
	
		
			
				|  |  |         if (!org.springframework.util.StringUtils.isEmpty(labelType)) {
 | 
	
		
			
				|  |  |             switch (labelType) {
 | 
	
		
			
				|  |  |                 case "1":{
 | 
	
		
			
				|  |  |                     sb.append(" select w.patient FROM wlyy_sign_family w  left join wlyy_sign_family_server s on w.code=s.sign_code " +
 | 
	
		
			
				|  |  |                     sb.append(" select w.code FROM wlyy_sign_family w  left join wlyy_sign_family_server s on w.code=s.sign_code " +
 | 
	
		
			
				|  |  |                             " left join wlyy_patient p on p.code=w.patient "+
 | 
	
		
			
				|  |  |                             "where w.`status` > 0 and s.server_type=? ");
 | 
	
		
			
				|  |  |                     params.add(labelCode);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 case "2":
 | 
	
		
			
				|  |  |                 case "3":
 | 
	
		
			
				|  |  |                 case "4":{
 | 
	
		
			
				|  |  |                     sb.append(" SELECT w.patient FROM wlyy_sign_family w left join wlyy_sign_patient_label_info l on w.patient = l.patient " +
 | 
	
		
			
				|  |  |                     sb.append(" SELECT w.code FROM wlyy_sign_family w left join wlyy_sign_patient_label_info l on w.patient = l.patient " +
 | 
	
		
			
				|  |  |                             " left join wlyy_patient p on p.code=w.patient "+
 | 
	
		
			
				|  |  |                             "where w.`status` > 0 and l.label_type = ? AND l.label = ? and l.status=1 ");
 | 
	
		
			
				|  |  |                     params.add(labelType);
 | 
	
		
			
				|  |  |                     params.add(labelCode);
 | 
	
	
		
			
				|  | @ -88,7 +103,9 @@ public class GcEduArticleService {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (patients != null && patients.length > 0) {
 | 
	
		
			
				|  |  |             List<String> arrPatient = java.util.Arrays.asList(patients);
 | 
	
		
			
				|  |  |             patientSet.addAll(arrPatient);
 | 
	
		
			
				|  |  |             for(String str:arrPatient){
 | 
	
		
			
				|  |  |                 patientSet.add(str);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (unPatients != null && unPatients.length > 0) {
 | 
	
		
			
				|  |  |             for (String unPatient : unPatients) {
 | 
	
	
		
			
				|  | @ -99,6 +116,82 @@ public class GcEduArticleService {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //    /**
 | 
	
		
			
				|  |  | //     * 保存发送信息
 | 
	
		
			
				|  |  | //     *
 | 
	
		
			
				|  |  | //     * @param patientSet   患者set集和
 | 
	
		
			
				|  |  | //     * @param sendCode     发送人code、
 | 
	
		
			
				|  |  | //     * @param sendName     发送人名称
 | 
	
		
			
				|  |  | //     * @param sendMessage  发送人携带的信息
 | 
	
		
			
				|  |  | //     * @param teamId       发送人所属团队
 | 
	
		
			
				|  |  | //     * @param articleId    文章列表
 | 
	
		
			
				|  |  | //     * @param articlePic   文件封面
 | 
	
		
			
				|  |  | //     * @param articleTitle 文章主题
 | 
	
		
			
				|  |  | //     */
 | 
	
		
			
				|  |  | //    @Transactional
 | 
	
		
			
				|  |  | //    public List<com.yihu.es.entity.HealthEduArticlePatient> getSaveArticle(Set<String> patientSet,
 | 
	
		
			
				|  |  | //                                                                        String sendCode,
 | 
	
		
			
				|  |  | //                                                                        String sendName,
 | 
	
		
			
				|  |  | //                                                                        Integer sendType,
 | 
	
		
			
				|  |  | //                                                                        String sendMessage,
 | 
	
		
			
				|  |  | //                                                                        Long teamId,
 | 
	
		
			
				|  |  | //                                                                        String articleId,
 | 
	
		
			
				|  |  | //                                                                        String articlePic,
 | 
	
		
			
				|  |  | //                                                                        String articleTitle,
 | 
	
		
			
				|  |  | //                                                                        String articleContent,
 | 
	
		
			
				|  |  | //                                                                        String articleType,
 | 
	
		
			
				|  |  | //                                                                        String level1Type,
 | 
	
		
			
				|  |  | //                                                                        String level2Type,
 | 
	
		
			
				|  |  | //                                                                        String level,
 | 
	
		
			
				|  |  | //                                                                        String articleUrl) {
 | 
	
		
			
				|  |  | //        List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = new ArrayList<>();
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //        Doctor doctor = doctorDao.findByCode(sendCode);
 | 
	
		
			
				|  |  | //        String batchNo = UUID.randomUUID().toString();
 | 
	
		
			
				|  |  | //        Date createTime = new Date();
 | 
	
		
			
				|  |  | //        for (String patient : patientSet) {
 | 
	
		
			
				|  |  | //            SignFamily signFamily = signFamilyDao.findByjiatingPatient(patient);
 | 
	
		
			
				|  |  | //            if (signFamily == null) {
 | 
	
		
			
				|  |  | //                continue;
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //            com.yihu.es.entity.HealthEduArticlePatient healthEduArticlePatient = new com.yihu.es.entity.HealthEduArticlePatient();
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setSendCode(sendCode);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setSendName(sendName);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setSendType(sendType);
 | 
	
		
			
				|  |  | ////            healthEduArticlePatient.setPatient(patient);
 | 
	
		
			
				|  |  | ////            healthEduArticlePatient.setPatientName(signFamily.getName());
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setAdminTeamCode(teamId);
 | 
	
		
			
				|  |  | //            if (doctor != null) {
 | 
	
		
			
				|  |  | //                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()):"");
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setBatchNo(batchNo);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setCreateTime(createTime);
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setArticleId(articleId);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setAttachedTitle(articleTitle);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setAttachedPic(articlePic);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setAttachedContent(articleContent);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setAttachedMessage(sendMessage);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setArticleType(articleType);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setLevel(level);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setLevel1Type(level1Type);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setLevel2Type(level2Type);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setType("1");//文章
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setArticleUrl(articleUrl);
 | 
	
		
			
				|  |  | //            healthEduArticlePatients.add(healthEduArticlePatient);
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //        //保存到ES中
 | 
	
		
			
				|  |  | //        elastricSearchSave.save(healthEduArticlePatients, esIndex, esType);
 | 
	
		
			
				|  |  | //        return healthEduArticlePatients;
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 保存发送信息
 | 
	
		
			
				|  |  |      *
 | 
	
	
		
			
				|  | @ -108,78 +201,78 @@ public class GcEduArticleService {
 | 
	
		
			
				|  |  |      * @param sendMessage  发送人携带的信息
 | 
	
		
			
				|  |  |      * @param teamId       发送人所属团队
 | 
	
		
			
				|  |  |      * @param articleId    文章列表
 | 
	
		
			
				|  |  |      * @param articlePic   文件封面
 | 
	
		
			
				|  |  |      * @param articleTitle 文章主题
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Transactional
 | 
	
		
			
				|  |  |     public List<com.yihu.es.entity.HealthEduArticlePatient> getSaveArticle(Set<String> patientSet,
 | 
	
		
			
				|  |  |                                                                         String sendCode,
 | 
	
		
			
				|  |  |                                                                         String sendName,
 | 
	
		
			
				|  |  |                                                                         Integer sendType,
 | 
	
		
			
				|  |  |                                                                         String sendMessage,
 | 
	
		
			
				|  |  |                                                                         Long teamId,
 | 
	
		
			
				|  |  |                                                                         String articleId,
 | 
	
		
			
				|  |  |                                                                         String articlePic,
 | 
	
		
			
				|  |  |                                                                         String articleTitle,
 | 
	
		
			
				|  |  |                                                                         String articleContent,
 | 
	
		
			
				|  |  |                                                                         String articleType,
 | 
	
		
			
				|  |  |                                                                         String level1Type,
 | 
	
		
			
				|  |  |                                                                         String level2Type,
 | 
	
		
			
				|  |  |                                                                         String level,
 | 
	
		
			
				|  |  |                                                                         String articleUrl) {
 | 
	
		
			
				|  |  |         List<com.yihu.es.entity.HealthEduArticlePatient> healthEduArticlePatients = new ArrayList<>();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Doctor doctor = doctorDao.findByCode(sendCode);
 | 
	
		
			
				|  |  |     public HealthEduArticlePatient getSaveArticle(Set<String> patientSet,
 | 
	
		
			
				|  |  |                                                         String sendCode,
 | 
	
		
			
				|  |  |                                                         String sendName,
 | 
	
		
			
				|  |  |                                                         Integer sendType,
 | 
	
		
			
				|  |  |                                                         String sendMessage,
 | 
	
		
			
				|  |  |                                                         Long teamId,
 | 
	
		
			
				|  |  |                                                         String articleId) throws Exception{
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String batchNo = UUID.randomUUID().toString();
 | 
	
		
			
				|  |  |         Date createTime = new Date();
 | 
	
		
			
				|  |  |         List<Patient> patientList = new ArrayList<>();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         for (String patient : patientSet) {
 | 
	
		
			
				|  |  |             SignFamily signFamily = signFamilyDao.findByjiatingPatient(patient);
 | 
	
		
			
				|  |  |             if (signFamily == null) {
 | 
	
		
			
				|  |  |                 continue;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             com.yihu.es.entity.HealthEduArticlePatient healthEduArticlePatient = new com.yihu.es.entity.HealthEduArticlePatient();
 | 
	
		
			
				|  |  |             patientList.add(new Patient(patient));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         HealthEduArticlePatient healthEduArticlePatient = new HealthEduArticlePatient();
 | 
	
		
			
				|  |  |         //1、医生,2、卫计委
 | 
	
		
			
				|  |  |         //如果是卫计委得区别角色
 | 
	
		
			
				|  |  |         Doctor doctor = null;
 | 
	
		
			
				|  |  |         if(sendType==2){
 | 
	
		
			
				|  |  |             String sql = "select r.code as roleCode from wlyy_user_role u " +
 | 
	
		
			
				|  |  |                     "left join wlyy_role r on r.`code`=u.role where u.user='"+sendCode+"'";
 | 
	
		
			
				|  |  |             Map<String,Object> result = jdbcTemplate.queryForMap(sql);
 | 
	
		
			
				|  |  |             //角色的code值
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setSendCode(result.get("roleCode")+"");
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             doctor = doctorDao.findByCode(sendCode);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setSendCode(sendCode);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setSendName(sendName);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setSendType(sendType);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setPatient(patient);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setPatientName(signFamily.getName());
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setAdminTeamCode(teamId);
 | 
	
		
			
				|  |  |             if (doctor != null) {
 | 
	
		
			
				|  |  |                 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()):"");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setBatchNo(batchNo);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setCreateTime(createTime);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setArticleId(articleId);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setAttachedTitle(articleTitle);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setAttachedPic(articlePic);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setAttachedContent(articleContent);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setAttachedMessage(sendMessage);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setArticleType(articleType);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setLevel(level);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setLevel1Type(level1Type);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setLevel2Type(level2Type);
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setType("1");//文章
 | 
	
		
			
				|  |  |             healthEduArticlePatient.setArticleUrl(articleUrl);
 | 
	
		
			
				|  |  |             healthEduArticlePatients.add(healthEduArticlePatient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setSendName(sendName);
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setSendType(sendType);
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setAdminTeamCode(teamId);
 | 
	
		
			
				|  |  |         if (doctor != null) {
 | 
	
		
			
				|  |  |             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()):"");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setBatchNo(batchNo);
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setCreateTime(new Date());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //通过文章id 获取文章详情
 | 
	
		
			
				|  |  |         JSONObject article = healthEducationArticleService.getArticalById(articleId);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setArticleId(article.get("articleId")+"");
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setAttachedTitle(article.get("articleTitle")+"");
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setAttachedPic(article.get("articleCover")+"");
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setAttachedContent(article.get("articleContent")+"");
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setAttachedMessage(sendMessage);
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setArticleType(article.get("articleType")+"");
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setLevel(article.get("articlelevel")+"");
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setLevel1Type(article.get("firstLevelCategoryId")+"");
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setLevel2Type(article.get("secondLevelCategoryId")+"");
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setType("1");//文章
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setArticleUrl("");
 | 
	
		
			
				|  |  |         healthEduArticlePatient.setPatients(patientList);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //保存到ES中
 | 
	
		
			
				|  |  |         elastricSearchSave.save(healthEduArticlePatients, esIndex, esType);
 | 
	
		
			
				|  |  |         return healthEduArticlePatients;
 | 
	
		
			
				|  |  |         elastricSearchSave.save(healthEduArticlePatient, esIndex, esType);
 | 
	
		
			
				|  |  |         return healthEduArticlePatient;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<HealthEduArticlePatientModel> getPatientHealthLogs(String sendCode, String articleType, String level1Type, String level2Type, String level, String attachedTitle, String startTime, String endTime, int page, int pagesize) {
 | 
	
		
			
				|  |  |         pagesize = page * pagesize;
 | 
	
		
			
				|  |  |         page = (page - 1) * pagesize;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         StringBuffer sql = new StringBuffer("select *,count(articleId) allCount from health_edu_article_patient_test  " +
 | 
	
		
			
				|  |  |         StringBuffer sql = new StringBuffer("select *,count(articleId) allCount from   " +esType+
 | 
	
		
			
				|  |  |                 " where  sendCode='" + sendCode + "' ");
 | 
	
		
			
				|  |  |         if (!StringUtils.isEmpty(articleType)) {
 | 
	
		
			
				|  |  |             sql.append(" and  articleType='" + articleType + "'  ");
 | 
	
	
		
			
				|  | @ -219,7 +312,7 @@ public class GcEduArticleService {
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private com.yihu.es.entity.HealthEduArticlePatient findOne(String articleId) {
 | 
	
		
			
				|  |  |         String sql = "select level,level2Type,level1Type,attachedContent,attachedTitle,articleId,createTime,articleType,sendCode,sendName from health_edu_article_patient_test where articleId='" + articleId + "' order by createTime desc limit 0,1";
 | 
	
		
			
				|  |  |         String sql = "select level,level2Type,level1Type,attachedContent,attachedTitle,articleId,createTime,articleType,sendCode,sendName from "+esType+" where articleId='" + articleId + "' order by createTime desc limit 0,1";
 | 
	
		
			
				|  |  |         com.yihu.es.entity.HealthEduArticlePatient esList = (com.yihu.es.entity.HealthEduArticlePatient) elasticsearchUtil.excuteOneObject(sql, com.yihu.es.entity.HealthEduArticlePatient.class, esIndex, esType);
 | 
	
		
			
				|  |  |         return esList;
 | 
	
		
			
				|  |  |     }
 | 
	
	
		
			
				|  | @ -257,10 +350,45 @@ public class GcEduArticleService {
 | 
	
		
			
				|  |  |         return quotaDate + "T00:00:00+0800";
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //    public void initPatient(Set<String> patientSet,String labelUnit,String labelSex,String labelServe,String labelDisease,String labelHealth){
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //        String tableSql = " select w.patient from wlyy_sign_family w ";
 | 
	
		
			
				|  |  | //        String whereSql = " where w.status>0  ";
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //        if(!StringUtils.isEmpty(labelServe)){
 | 
	
		
			
				|  |  | //            tableSql += " left join wlyy_sign_family_server s on w.code= s.sign_code ";
 | 
	
		
			
				|  |  | //            whereSql += " and s.server_type in ("+labelServe+" ) ";
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //        if(!StringUtils.isEmpty(labelHealth)||!StringUtils.isEmpty(labelDisease)){
 | 
	
		
			
				|  |  | //            tableSql += " left join wlyy_sign_patient_label_info l on w.patient=l.patient ";
 | 
	
		
			
				|  |  | //            whereSql += " and l.status=1 ";
 | 
	
		
			
				|  |  | //            whereSql += " and ( ";
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //        if(!StringUtils.isEmpty(labelHealth)){
 | 
	
		
			
				|  |  | //            whereSql += " (l.label_type = 2 AND l.label in ("+labelHealth+")) ";
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //        if(!StringUtils.isEmpty(labelDisease)){
 | 
	
		
			
				|  |  | //            if(!whereSql.endsWith(" and ( ")) {
 | 
	
		
			
				|  |  | //                whereSql += " or (l.label_type = 3 AND l.label in ("+labelDisease+"))) ";
 | 
	
		
			
				|  |  | //            }else{
 | 
	
		
			
				|  |  | //                whereSql += " (l.label_type = 1 AND l.label in ("+labelDisease+"))) ";
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //        if(!StringUtils.isEmpty(labelSex)){
 | 
	
		
			
				|  |  | //            tableSql += " left join wlyy_patient p on p.code=w.patient ";
 | 
	
		
			
				|  |  | //            whereSql += " and p.sex in ("+labelSex+") ";
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //        if(!StringUtils.isEmpty(labelUnit)){
 | 
	
		
			
				|  |  | //            whereSql += " and w.hospital in ("+labelUnit+") ";
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //        List<String> groupPatient = jdbcTemplate.queryForList(tableSql+whereSql, String.class);
 | 
	
		
			
				|  |  | //        patientSet.addAll(groupPatient);
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void initPatient(Set<String> patientSet,String labelUnit,String labelSex,String labelServe,String labelDisease,String labelHealth){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String tableSql = " select w.patient from wlyy_sign_family w ";
 | 
	
		
			
				|  |  |         String whereSql = " where w.status>0  ";
 | 
	
		
			
				|  |  |         String tableSql = " select p.code from wlyy_sign_family w ";
 | 
	
		
			
				|  |  |         String whereSql = " where w.status>0 and p.town='350211' ";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(!StringUtils.isEmpty(labelServe)){
 | 
	
		
			
				|  |  |             tableSql += " left join wlyy_sign_family_server s on w.code= s.sign_code ";
 | 
	
	
		
			
				|  | @ -281,8 +409,8 @@ public class GcEduArticleService {
 | 
	
		
			
				|  |  |                 whereSql += " (l.label_type = 1 AND l.label in ("+labelDisease+"))) ";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         tableSql += " left join wlyy_patient p on p.code=w.patient ";
 | 
	
		
			
				|  |  |         if(!StringUtils.isEmpty(labelSex)){
 | 
	
		
			
				|  |  |             tableSql += " left join wlyy_patient p on p.code=w.patient ";
 | 
	
		
			
				|  |  |             whereSql += " and p.sex in ("+labelSex+") ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(!StringUtils.isEmpty(labelUnit)){
 | 
	
	
		
			
				|  | @ -292,17 +420,117 @@ public class GcEduArticleService {
 | 
	
		
			
				|  |  |         patientSet.addAll(groupPatient);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Transactional
 | 
	
		
			
				|  |  |     public void getSaveArticle(){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //        ArticleTest aa = new ArticleTest();
 | 
	
		
			
				|  |  | //        Patient pa = new Patient();
 | 
	
		
			
				|  |  | //    /**
 | 
	
		
			
				|  |  | //     * 保存发送信息
 | 
	
		
			
				|  |  | //     *
 | 
	
		
			
				|  |  | //     */
 | 
	
		
			
				|  |  | //    @Transactional
 | 
	
		
			
				|  |  | //    public List<com.yihu.es.entity.ArticleTest> getSaveArticle2() {
 | 
	
		
			
				|  |  | //        List<com.yihu.es.entity.ArticleTest> healthEduArticlePatients = new ArrayList<>();
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //        String batchNo = UUID.randomUUID().toString();
 | 
	
		
			
				|  |  | //        pa.setCode(batchNo);
 | 
	
		
			
				|  |  | //        pa.setCity("1212");
 | 
	
		
			
				|  |  | //        pa.setName("hukun");
 | 
	
		
			
				|  |  | //        batchNo = UUID.randomUUID().toString();
 | 
	
		
			
				|  |  | //        aa.setBatchNo(batchNo);
 | 
	
		
			
				|  |  | //        aa.setPatients(pa);
 | 
	
		
			
				|  |  | //        Date createTime = new Date();
 | 
	
		
			
				|  |  | ////            com.yihu.es.entity.HealthEduArticlePatient healthEduArticlePatient = new com.yihu.es.entity.HealthEduArticlePatient();
 | 
	
		
			
				|  |  | //            com.yihu.es.entity.ArticleTest healthEduArticlePatient = new ArticleTest();
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setSendCode("123");
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setSendName("123");
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setBatchNo(batchNo);
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setCreateTime(createTime);
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setAttachedMessage("5656");
 | 
	
		
			
				|  |  | //            healthEduArticlePatient.setType("1");//文章
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | ////            People patient1 = new People();
 | 
	
		
			
				|  |  | ////            patient1.setName("胡坤3");
 | 
	
		
			
				|  |  | ////            People patient2 = new People();
 | 
	
		
			
				|  |  | ////            patient2.setName("胡坤4");
 | 
	
		
			
				|  |  | ////            List<People> a = new ArrayList<>();
 | 
	
		
			
				|  |  | ////            a.add(patient1);
 | 
	
		
			
				|  |  | ////            a.add(patient2);
 | 
	
		
			
				|  |  | //            List<String> a = new ArrayList<>();
 | 
	
		
			
				|  |  | //            a.add("胡坤3");
 | 
	
		
			
				|  |  | //        a.add("胡坤4");
 | 
	
		
			
				|  |  | ////            healthEduArticlePatient.setP
 | 
	
		
			
				|  |  | //            healthEduArticlePatients.add(healthEduArticlePatient);
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //        //保存到ES中
 | 
	
		
			
				|  |  | //        elastricSearchSave.save(healthEduArticlePatients, esIndex, esType);
 | 
	
		
			
				|  |  | //        return healthEduArticlePatients;
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<HealthEduArticlePatientModel> pushArticleLogs(int page, int pagesize,String sendCode) throws Exception{
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         pagesize = page * pagesize;
 | 
	
		
			
				|  |  |         page = (page - 1) * pagesize;
 | 
	
		
			
				|  |  |         String sql = "select r.code as roleCode from wlyy_user_role u " +
 | 
	
		
			
				|  |  |                 "left join wlyy_role r on r.`code`=u.role where u.user='"+sendCode+"'";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Map<String,Object> resultMap = jdbcTemplate.queryForMap(sql);
 | 
	
		
			
				|  |  |         sendCode = resultMap.get("roleCode").toString();
 | 
	
		
			
				|  |  |         StringBuffer sql2 = new StringBuffer("select *  from   " +esType+
 | 
	
		
			
				|  |  |                 " where  sendCode='" + sendCode + "' ");
 | 
	
		
			
				|  |  |         sql2.append("  order by createTime limit " + page + "," + pagesize);
 | 
	
		
			
				|  |  |         List<com.yihu.es.entity.HealthEduArticlePatient> esList = elasticsearchUtil.excute(sql2.toString(), com.yihu.es.entity.HealthEduArticlePatient.class, esIndex, esType);
 | 
	
		
			
				|  |  |         List<HealthEduArticlePatientModel> returnList = new ArrayList<>();
 | 
	
		
			
				|  |  |         Map<String,HealthEduArticlePatientModel> result = new HashMap<>();
 | 
	
		
			
				|  |  |         HealthEduArticlePatientModel heapm = null;
 | 
	
		
			
				|  |  |         com.alibaba.fastjson.JSONObject article = null;
 | 
	
		
			
				|  |  |         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXX");
 | 
	
		
			
				|  |  |         for(HealthEduArticlePatient one :esList){
 | 
	
		
			
				|  |  |             article = healthEducationArticleService.getArticalById(one.getArticleId());
 | 
	
		
			
				|  |  | //            com.yihu.es.entity.HealthEduArticlePatient p = findOne(one.getArticleId());
 | 
	
		
			
				|  |  | //            if (p != null) {
 | 
	
		
			
				|  |  | //                p.setAllCount(one.getAllCount());
 | 
	
		
			
				|  |  | //                HealthEduArticlePatientModel heapm = new HealthEduArticlePatientModel();
 | 
	
		
			
				|  |  | //                BeanUtils.copyProperties(p, heapm);
 | 
	
		
			
				|  |  | //                returnList.add(heapm);
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  |             if(result.get(one.getArticleId())!=null){
 | 
	
		
			
				|  |  |                 heapm = result.get(one.getArticleId());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 heapm = new HealthEduArticlePatientModel();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             heapm.setSendName(one.getSendName());
 | 
	
		
			
				|  |  |             heapm.setSendCode(one.getSendCode());
 | 
	
		
			
				|  |  |             heapm.setCreateTime(one.getCreateTime());
 | 
	
		
			
				|  |  |             heapm.setArticleId(article.getString("articleId"));
 | 
	
		
			
				|  |  |             heapm.setAttachedTitle(article.getString("articleTitle"));
 | 
	
		
			
				|  |  |             heapm.setAttachedContent(article.getString("articleContent"));
 | 
	
		
			
				|  |  |             heapm.setArticleType(article.getString("articleType"));
 | 
	
		
			
				|  |  |             heapm.setLevel1Type(article.getString("firstLevelCategoryId"));
 | 
	
		
			
				|  |  |             heapm.setLevel2Type(article.getString("secondLevelCategoryId"));
 | 
	
		
			
				|  |  |             heapm.setLevel(article.getString("articlelevel"));
 | 
	
		
			
				|  |  |             heapm.setAllCount(heapm.getAllCount()+one.getPatients().size());
 | 
	
		
			
				|  |  |             heapm.setBrowseNumbere(article.getInteger("browseNumber"));
 | 
	
		
			
				|  |  |             heapm.setCommentNumber(article.getInteger("commentNumber"));
 | 
	
		
			
				|  |  |             result.put(one.getArticleId(),heapm);
 | 
	
		
			
				|  |  |         };
 | 
	
		
			
				|  |  |         List< HealthEduArticlePatientModel > resultList = new ArrayList<>();
 | 
	
		
			
				|  |  |         for (Map.Entry< String, HealthEduArticlePatientModel > entry : result.entrySet()) {
 | 
	
		
			
				|  |  |             resultList.add(entry.getValue());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return resultList;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Long pushArticleLogsCount(String sendCode) {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         StringBuffer sql = new StringBuffer("select count(distinct articleId) count  from   " +esType+
 | 
	
		
			
				|  |  |                 " where  sendCode='" + sendCode + "' ");
 | 
	
		
			
				|  |  |         return elasticsearchUtil.excuteForLong(sql.toString(), esIndex, esType);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject pushArticleConfirm(String articleId, String labelUnit,String labelSex,String labelServe,String labelDisease,String labelHealth) throws Exception{
 | 
	
		
			
				|  |  |         JSONObject article = healthEducationArticleService.getArticalById(articleId);
 | 
	
		
			
				|  |  |         Set<String> patientSet = new HashSet<>();
 | 
	
		
			
				|  |  |         initPatient(patientSet,labelUnit,labelSex,labelServe,labelDisease,labelHealth);
 | 
	
		
			
				|  |  |         long num = patientSet.size();
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         result.put("num",num);
 | 
	
		
			
				|  |  |         result.put("articleTitle",article.getString("articleTitle"));
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |