Kaynağa Gözat

代码修改

yeshijie 7 yıl önce
ebeveyn
işleme
205238d9d0
22 değiştirilmiş dosya ile 1470 ekleme ve 187 silme
  1. 2 2
      common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticleES.java
  2. 51 0
      common/common-entity/src/main/java/com/yihu/wlyy/entity/doctor/DoctorSwitch.java
  3. 97 0
      common/common-entity/src/main/java/com/yihu/wlyy/entity/patient/TrackPatient.java
  4. 1 1
      edu-article/JkEdu/WebRoot/WEB-INF/classes/articlePc.sql.xml
  5. BIN
      edu-article/JkEdu/WebRoot/WEB-INF/classes/com/yihu/jk/dao/ArticleDao.class
  6. 1 1
      edu-article/JkEdu/src/articlePc.sql.xml
  7. 1 0
      edu-article/JkEdu/src/com/yihu/jk/dao/ArticleDao.java
  8. 5 1
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/activemq/HealthArtListener.java
  9. 12 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/DoctorSwitchDao.java
  10. 12 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/PatientAimBloodPressureDao.java
  11. 14 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/PatientAimBloodSuggerDao.java
  12. 17 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/TrackPatientDao.java
  13. 42 5
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelInfoService.java
  14. 664 5
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/scheme/DoctorSchemeService.java
  15. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java
  16. 5 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/jimeiJkEdu/JMJkEduArticleService.java
  17. 61 36
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandlingController.java
  18. 15 7
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/jimeiJkEduPC/DoctorJMJkEduArticlePCController.java
  19. 16 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelInfoController.java
  20. 127 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/scheme/DoctroSchemeController.java
  21. 3 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/jimeiJkEdu/PatientJMJkEduArticleController.java
  22. 323 123
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/service/EduArticleService.java

+ 2 - 2
common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticleES.java

@ -54,8 +54,8 @@ public class HealthEduArticleES {
    private List<RoleVo> roleList;//发送者角色
    private String leaveWords;//医生留言
    private String currentUserRoleCode;//发送者当前登录的角色code
    private String currentUserRoleLevel;//发送者当前登录的角色级别
    private String currentUserRoleCode;//发送者当前登录的角色code  currentUserRoleCode与currentUserRoleLevel要一一对应取
    private String currentUserRoleLevel;//发送者当前登录的角色级别  省,市,区,机构,对应1.2.3.4   旧数据默认是2
    private Integer sendSource; //1或者为空 i健康后台推送  2PC端推送
    private Integer allCount;//所有的推送数目
    private Long readNumber;//阅读数(备注和浏览数不一样)

+ 51 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/doctor/DoctorSwitch.java

@ -0,0 +1,51 @@
package com.yihu.wlyy.entity.doctor;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Trick on 2018/1/4.
 */
@Entity
@Table(name = "wlyy_doctor_switch")
public class DoctorSwitch extends IdEntity{
    private String doctor;//关联医生
    private String alertPatientSwitch;//0不自动跟踪居民,1自动跟踪预警居民
    private Date createTime;//创建时间
    private Date updateTime;//更新时间
    public String getDoctor() {
        return doctor;
    }
    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }
    public String getAlertPatientSwitch() {
        return alertPatientSwitch;
    }
    public void setAlertPatientSwitch(String alertPatientSwitch) {
        this.alertPatientSwitch = alertPatientSwitch;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}

+ 97 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/patient/TrackPatient.java

@ -0,0 +1,97 @@
package com.yihu.wlyy.entity.patient;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Trick on 2018/1/4.
 */
@Entity
@Table(name = "wlyy_track_patient")
public class TrackPatient extends IdEntity {
    private String patientCode;//关联居民code,医生的重点关注对象
    private String patientName;//患者姓名
    private String doctorCode;//所属医生
    private String doctorName;//所属医生名
    private Integer teamCode;//居民签约团队
    private String idcard;//身份证号
    private String ssc;//社保卡号
    private Date createTime;//创建时间
    private Date updateTime;//更新时间
    public String getPatientCode() {
        return patientCode;
    }
    public void setPatientCode(String patientCode) {
        this.patientCode = patientCode;
    }
    public String getPatientName() {
        return patientName;
    }
    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }
    public String getDoctorCode() {
        return doctorCode;
    }
    public void setDoctorCode(String doctorCode) {
        this.doctorCode = doctorCode;
    }
    public String getDoctorName() {
        return doctorName;
    }
    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }
    public Integer getTeamCode() {
        return teamCode;
    }
    public void setTeamCode(Integer teamCode) {
        this.teamCode = teamCode;
    }
    public String getIdcard() {
        return idcard;
    }
    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }
    public String getSsc() {
        return ssc;
    }
    public void setSsc(String ssc) {
        this.ssc = ssc;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}

+ 1 - 1
edu-article/JkEdu/WebRoot/WEB-INF/classes/articlePc.sql.xml

@ -3,7 +3,7 @@
	<Sqls> 
		 <Sql name='getArticlePcList'>
		 <![CDATA[
				select m.*,IFNULL(n.BrowseNumber,0) as BrowseNumber,IFNULL(n.PointNumber,0) as PointNumber,IFNULL(n.CollectionNumber,0) as CollectionNumber,IFNULL(n.CommentNumber,0) as CommentNumber ,
				select m.*,IFNULL(n.BrowseNumber,0) as BrowseNumber,IFNULL(n.PointNumber,0) as PointNumber,IFNULL(n.CollectionNumber,0) as CollectionNumber,IFNULL(n.CommentNumber,0) as CommentNumber ,IFNULL(n.PushNumber,0) as PushNumber ,
				(select count(1) from user_articlecollection a where a.ArticleId=m.ArticleId  @Condition2 )as collectionType, IFNULL(n.PushNumber,0) as PushNumber from Org_Article m
				LEFT JOIN User_ArticleStatistics n on m.ArticleId=n.ArticleId where 1=1   and  ArticleState =1  @Condition    order by ArticleOrder desc  ,UpdateTime desc   @PageParam
			]]>

BIN
edu-article/JkEdu/WebRoot/WEB-INF/classes/com/yihu/jk/dao/ArticleDao.class


+ 1 - 1
edu-article/JkEdu/src/articlePc.sql.xml

@ -3,7 +3,7 @@
	<Sqls> 
		 <Sql name='getArticlePcList'>
		 <![CDATA[
				select m.*,IFNULL(n.BrowseNumber,0) as BrowseNumber,IFNULL(n.PointNumber,0) as PointNumber,IFNULL(n.CollectionNumber,0) as CollectionNumber,IFNULL(n.CommentNumber,0) as CommentNumber ,
				select m.*,IFNULL(n.BrowseNumber,0) as BrowseNumber,IFNULL(n.PointNumber,0) as PointNumber,IFNULL(n.CollectionNumber,0) as CollectionNumber,IFNULL(n.CommentNumber,0) as CommentNumber ,IFNULL(n.PushNumber,0) as PushNumber ,
				(select count(1) from user_articlecollection a where a.ArticleId=m.ArticleId  @Condition2 )as collectionType, IFNULL(n.PushNumber,0) as PushNumber from Org_Article m
				LEFT JOIN User_ArticleStatistics n on m.ArticleId=n.ArticleId where 1=1   and  ArticleState =1  @Condition    order by ArticleOrder desc  ,UpdateTime desc   @PageParam
			]]>

+ 1 - 0
edu-article/JkEdu/src/com/yihu/jk/dao/ArticleDao.java

@ -114,6 +114,7 @@ public class ArticleDao {
			userParam.append(" and UserType  =").append(vo.getUserType());
		}
		param.append(" order by insertTime desc ");
		param.append(" limit ").append(start * pageSize + "," + pageSize);
		sql.addVar("@Condition", param.toString());

+ 5 - 1
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/activemq/HealthArtListener.java

@ -49,6 +49,10 @@ public class HealthArtListener implements MessageListener {
            TextMessage textMessage = (TextMessage) message;
            HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
            JSONObject obj = JSONObject.fromObject(textMessage.getText());
            if(obj.get("doctorCode")==null||obj.get("doctorName")==null){
                message.acknowledge();
                return ;
            }
            healthEduArticleES.setBatchNo(obj.get("batchNo")!=null?obj.get("batchNo").toString():null);
            healthEduArticleES.setPatientCode(obj.get("patientCode")!=null?obj.get("patientCode").toString():null);
            healthEduArticleES.setPatientName(obj.get("patientName")!=null?obj.get("patientName").toString():null);
@ -83,7 +87,7 @@ public class HealthArtListener implements MessageListener {
            healthEduArticleES.setCurrentUserRoleLevel(obj.get("currentUserRoleLevel")!=null?obj.get("currentUserRoleLevel").toString():null);
            healthEduArticleES.setSendSource(obj.get("sendSource")!=null?(Integer)obj.get("sendSource"):null);
            healthEduArticleES.setAllCount(obj.get("allCount")!=null?(Integer)obj.get("allCount"):null);
            healthEduArticleES.setReadNumber(obj.get("readNumber")!=null?(Long)obj.get("readNumber"):null);
//            healthEduArticleES.setReadNumber(obj.get("readNumber")!=null?(Long)obj.get("readNumber"):null);
            healthEduArticleES.setNewArricleFlag(obj.get("newArricleFlag")!=null?(Boolean)obj.get("newArricleFlag"):null);
            healthEduArticleES.setUserType(obj.get("userType")!=null?(Integer) obj.get("userType"):null);
//            HealthEduArticleES one = (HealthEduArticleES)JSONObject.toBean(JSONObject.fromObject(textMessage.getText()),HealthEduArticleES.class);

+ 12 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/DoctorSwitchDao.java

@ -0,0 +1,12 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.DoctorSwitch;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2018/1/5.
 */
public interface DoctorSwitchDao extends PagingAndSortingRepository<DoctorSwitch, Long>, JpaSpecificationExecutor<DoctorSwitch> {
    public DoctorSwitch findByDoctor(String doctor);
}

+ 12 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/PatientAimBloodPressureDao.java

@ -0,0 +1,12 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.patient.PatientAimBloodPressure;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2018/1/5.
 */
public interface PatientAimBloodPressureDao extends PagingAndSortingRepository<PatientAimBloodPressure, Integer>, JpaSpecificationExecutor<PatientAimBloodPressure> {
    public  PatientAimBloodPressure findByPatientcode(String patientcode);
}

+ 14 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/PatientAimBloodSuggerDao.java

@ -0,0 +1,14 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.OperatorLog;
import com.yihu.wlyy.entity.patient.PatientAimBloodSugger;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2018/1/5.
 */
public interface PatientAimBloodSuggerDao extends PagingAndSortingRepository<PatientAimBloodSugger, Integer>, JpaSpecificationExecutor<PatientAimBloodSugger> {
    public PatientAimBloodSugger findByPatientcode(String patientcode);
}

+ 17 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/TrackPatientDao.java

@ -0,0 +1,17 @@
package com.yihu.wlyy.repository.patient;
import com.yihu.wlyy.entity.patient.TrackPatient;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Trick on 2018/1/4.
 */
public interface TrackPatientDao extends PagingAndSortingRepository<TrackPatient, String>, JpaSpecificationExecutor<TrackPatient> {
    public TrackPatient findByDoctorCodeAndPatientCode(String doctorCode,String patientCode);
    public List<TrackPatient> findByDoctorCodeAndTeamCode(String doctorCode,Integer teamCode);
}

+ 42 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelInfoService.java

@ -5,10 +5,7 @@ import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelInfo;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientDisease;
import com.yihu.wlyy.entity.patient.PatientRemindRecords;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.*;
import com.yihu.wlyy.entity.patient.vo.PatientVO;
import com.yihu.wlyy.entity.statistics.WlyyQuotaResult;
import com.yihu.wlyy.logs.BusinessLogs;
@ -22,6 +19,7 @@ import com.yihu.wlyy.service.app.account.PatientInfoService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.IdCardUtil;
import io.swagger.models.auth.In;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
@ -77,6 +75,8 @@ public class SignPatientLabelInfoService extends BaseService {
    SignPatientLabelInfoDao signPatientLabelInfoDao;
    @Autowired
    PatientInfoService patientInfoService;
    @Autowired
    TrackPatientDao trackPatientDao;
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
@ -87,7 +87,7 @@ public class SignPatientLabelInfoService extends BaseService {
     * @return
     * @throws Exception
     */
    public JSONObject getPatient(String patient) throws Exception {
    public JSONObject getPatient(String patient,String doctor) throws Exception {
        JSONObject json = new JSONObject();
//        Patient p = patientDao.findByCode(patient);
        PatientVO p = patientInfoService.getPatientVOByCode(patient);
@ -249,9 +249,46 @@ public class SignPatientLabelInfoService extends BaseService {
        json.put("countryCode",p.getSickVillage()==null?"":p.getSickVillage());
        json.put("countryName",p.getSickVillageName()==null?"":p.getSickVillageName());
        //1.4.2 是否追踪居民健康体征
        if(StringUtils.isNotBlank(doctor)){
            String trackSql = "SELECT t.id FROM wlyy_track_patient t WHERE t,patient_code = '"+patient+"' AND t.doctor_code ='"+doctor+"'";
            List<Map<String,Object>> list = jdbcTemplate.queryForList(trackSql);
            if(list!=null&&list.size()>0){
                json.put("isTrack","1");
            }else{
                json.put("isTrack","0");
            }
        }
        return json;
    }
    public String setTrackPatient(String patient,String doctor){
        TrackPatient tp  = trackPatientDao.findByDoctorCodeAndPatientCode(doctor,patient);
        if(tp!=null){
            trackPatientDao.delete(tp);
        }else{
            Doctor d = doctorDao.findByCode(doctor);
            Patient p = patientDao.findByCode(patient);
            TrackPatient tkp = new TrackPatient();
            tkp.setCreateTime(new Date());
            tkp.setDoctorCode(doctor);
            tkp.setDoctorName(d.getName());
            tkp.setPatientCode(patient);
            tkp.setPatientName(p.getName());
            tkp.setSsc(p.getSsc());
            tkp.setIdcard(p.getIdcard());
            String signSql = "SELECT f.admin_team_code FROM wlyy_sign_family f WHERE (f.doctor = '"+doctor+"' OR f.doctor_health ='"+doctor+"') AND f.patient = '"+patient+"' AND f.status >0 ";
            List<Map<String,Object>> list = jdbcTemplate.queryForList(signSql);
            if(list!=null&&list.size()>0){
                Map<String,Object> map = list.get(0);
                Integer adminTeamId = (Integer) map.get("admin_team_code");
                tkp.setTeamCode(adminTeamId);
            }else{
                return "-1";
            }
        }
        return "1";
    }
    /**
     * 根据标签查询患者信息
     *

+ 664 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/scheme/DoctorSchemeService.java

@ -3,24 +3,27 @@ package com.yihu.wlyy.service.app.scheme;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sun.media.jfxmedia.track.Track;
import com.yihu.device.entity.DevicePatientHealthIndex;
import com.yihu.wlyy.entity.doctor.DoctorSwitch;
import com.yihu.wlyy.entity.doctor.scheme.DoctorSchemeBloodPressure;
import com.yihu.wlyy.entity.doctor.scheme.DoctorSchemeBloodSugger;
import com.yihu.wlyy.entity.doctor.scheme.vo.DoctorSchemeBloodPressureVO;
import com.yihu.wlyy.entity.doctor.scheme.vo.DoctorSchemeBloodSuggerVO;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientSchemeList;
import com.yihu.wlyy.entity.patient.*;
import com.yihu.wlyy.entity.patient.vo.PatientVO;
import com.yihu.wlyy.health.repository.DevicePatientHealthIndexDao;
import com.yihu.wlyy.repository.doctor.DoctoreSchemeBloodPressureDao;
import com.yihu.wlyy.repository.doctor.DoctrorSchemeBloodSuggerDao;
import com.yihu.wlyy.repository.doctor.*;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.TrackPatientDao;
import com.yihu.wlyy.repository.patient.scheme.PatientSchemeListDao;
import com.yihu.wlyy.util.DateUtil;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.jpa.JpaTransactionManager;
@ -62,6 +65,21 @@ public class DoctorSchemeService {
    @Autowired
    private DevicePatientHealthIndexDao devicePatientHealthIndexDao;
    @Autowired
    private PatientAimBloodSuggerDao patientAimBloodSuggerDao;
    @Autowired
    private PatientAimBloodPressureDao patientAimBloodPressureDao;
    @Autowired
    private DoctorSwitchDao doctorSwitchDao;
    @Autowired
    private TrackPatientDao trackPatientDao;
    @Value("${im.data_base_name}")
    private String im_dataBase_name;
    /**
     * 根据团队CODE/居民标签/病情/设备绑定状态查询团队具名CODE列表
@ -532,7 +550,13 @@ public class DoctorSchemeService {
//            result.add(sugar_unusual_count);
        }
        //1.4.2 重点关注居民
        List<TrackPatient> list = trackPatientDao.findByDoctorCodeAndTeamCode(doctorcode,Integer.parseInt(teamCode));
        if(list!=null&&list.size()>0){
            result.put("trackPatientCount",list.size());
        }else{
            result.put("trackPatientCount",0);
        }
        return result;
    }
@ -554,4 +578,639 @@ public class DoctorSchemeService {
            doctoreSchemeBloodPressureDao.updateDelStatus(1,doctorcode,schemecode);
        }
    }
    public Map<String,Object> getPatientHealthIndex(String patient,String startDate,String endDate,String type){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String highSql ="SELECT  " +
                " (bf.befHighCount + aft.aftHighCount) AS highCount " +
                " FROM " +
                " ( " +
                " SELECT " +
                " COUNT(1) AS befHighCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.type = '1' " +
                " AND i.del = '1' " +
                " AND i.value2 in(1,3,5,7) " +
                " AND i.value1 > 6.1 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user ='"+patient+"'" +
                " ) bf, " +
                " (  " +
                " SELECT " +
                " COUNT(1) AS aftHighCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.type = '1' " +
                " AND i.del = '1' " +
                " AND i.value2 in(2,4,6) " +
                " AND i.value1 > 7.8 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user ='"+patient+"'" +
                " ) aft";
        String stdSql ="SELECT  " +
                " (bf.befHighCount + aft.aftHighCount) AS stdCount " +
                " FROM " +
                " ( " +
                " SELECT " +
                " COUNT(1) AS befHighCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.type = '1' " +
                " AND i.del = '1' " +
                " AND i.value2 in(1,3,5,7) " +
                " AND i.value1 <= 6.1 " +
                " AND i.value1 >= 3.9 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user ='"+patient+"'" +
                " ) bf, " +
                " (  " +
                " SELECT " +
                " COUNT(1) AS aftHighCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.type = '1' " +
                " AND i.del = '1' " +
                " AND i.value2 in(2,4,6) " +
                " AND i.value1 <= 7.8 " +
                " AND i.value1 >= 4.4 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user ='"+patient+"'" +
                " ) aft";
        String lowSql ="SELECT  " +
                " (bf.befHighCount + aft.aftHighCount) AS lowCount " +
                " FROM " +
                " ( " +
                " SELECT " +
                " COUNT(1) AS befHighCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.type = '1' " +
                " AND i.del = '1' " +
                " AND i.value2 in(1,3,5,7) " +
                " AND i.value1 <= 3.9 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user ='"+patient+"'" +
                " ) bf, " +
                " (  " +
                " SELECT " +
                " COUNT(1) AS aftHighCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.type = '1' " +
                " AND i.del = '1' " +
                " AND i.value2 in(2,4,6) " +
                " AND i.value1 <= 4.4 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user ='"+patient+"'" +
                " ) aft";
        String pHighSql ="SELECT " +
                " count(1) AS highCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.del = '1' " +
                " AND i.type = '2' " +
                " AND i.value1 >= 139 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user ='"+patient+"'";
        String  pStdSql ="SELECT " +
                " count(1) AS stdCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.del = '1' " +
                " AND i.type = '2' " +
                " AND i.value1 <= 139 " +
                " AND i.value1 >= 90 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user ='"+patient+"'";
        String pLowSql ="SELECT " +
                " count(1) AS lowCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.del = '1' " +
                " AND i.type = '2' " +
                " AND i.value1 <= 90 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user ='"+patient+"'";
        Map<String,Object> rs = new HashedMap();
        //0血檀
        if ("0".equals(type)){
            //1.高
            List<Map<String,Object>> high = jdbcTemplate.queryForList(highSql);
            if(high!=null&&high.size()>0){
                Map<String,Object> h = high.get(0);
                rs.put("highCount",h.get("highCount"));
            }
            //2.正常
            List<Map<String,Object>> std = jdbcTemplate.queryForList(pStdSql);
            if(std!=null&&std.size()>0){
                Map<String,Object> st = std.get(0);
                rs.put("stdCount",st.get("stdCount"));
            }
            //3.偏低
            List<Map<String,Object>> low = jdbcTemplate.queryForList(pLowSql);
            if(low!=null&&low.size()>0){
                Map<String,Object> lw = low.get(0);
                rs.put("lowCount",lw.get("lowCount"));
            }
            //其他血压
        }else{
            //1.高
            List<Map<String,Object>> high = jdbcTemplate.queryForList(pHighSql);
            if(high!=null&&high.size()>0){
                Map<String,Object> h = high.get(0);
                rs.put("highCount",h.get("highCount"));
            }
            //2.正常
            List<Map<String,Object>> std = jdbcTemplate.queryForList(stdSql);
            if(std!=null&&std.size()>0){
                Map<String,Object> st = std.get(0);
                rs.put("stdCount",st.get("stdCount"));
            }
            //3.偏低
            List<Map<String,Object>> low = jdbcTemplate.queryForList(lowSql);
            if(low!=null&&low.size()>0){
                Map<String,Object> lw = low.get(0);
                rs.put("lowCount",lw.get("lowCount"));
            }
        }
        return rs;
    }
    public Map<String,Object> getPatientHealthIndex(String startDate,String endDate,String type,Long teamCode,String doctor){
        startDate = startDate+" 00:00:00";
        endDate = endDate+" 23:59:59";
        String highSql ="SELECT  " +
                " (bf.befHighCount + aft.aftHighCount) AS highCount " +
                " FROM " +
                " ( " +
                " SELECT " +
                " COUNT(1) AS befHighCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.type = '1' " +
                " AND i.del = '1' " +
                " AND i.value2 in(1,3,5,7) " +
                " AND i.value1 > 6.1 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user IN (SELECT t.patient_code FROM wlyy.wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +teamCode+")" +
                " ) bf, " +
                " (  " +
                " SELECT " +
                " COUNT(1) AS aftHighCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.type = '1' " +
                " AND i.del = '1' " +
                " AND i.value2 in(2,4,6) " +
                " AND i.value1 > 7.8 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user IN (SELECT t.patient_code FROM wlyy.wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +teamCode+")" +
                " ) aft";
        String stdSql ="SELECT  " +
                " (bf.befHighCount + aft.aftHighCount) AS stdCount " +
                " FROM " +
                " ( " +
                " SELECT " +
                " COUNT(1) AS befHighCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.type = '1' " +
                " AND i.del = '1' " +
                " AND i.value2 in(1,3,5,7) " +
                " AND i.value1 <= 6.1 " +
                " AND i.value1 >= 3.9 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user IN (SELECT t.patient_code FROM wlyy.wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +teamCode+")" +
                " ) bf, " +
                " (  " +
                " SELECT " +
                " COUNT(1) AS aftHighCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.type = '1' " +
                " AND i.del = '1' " +
                " AND i.value2 in(2,4,6) " +
                " AND i.value1 <= 7.8 " +
                " AND i.value1 >= 4.4 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user IN (SELECT t.patient_code FROM wlyy.wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +teamCode+")" +
                " ) aft";
        String lowSql ="SELECT  " +
                " (bf.befHighCount + aft.aftHighCount) AS lowCount " +
                " FROM " +
                " ( " +
                " SELECT " +
                " COUNT(1) AS befHighCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.type = '1' " +
                " AND i.del = '1' " +
                " AND i.value2 in(1,3,5,7) " +
                " AND i.value1 <= 3.9 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user IN (SELECT t.patient_code FROM wlyy.wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +teamCode+")" +
                " ) bf, " +
                " (  " +
                " SELECT " +
                " COUNT(1) AS aftHighCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.type = '1' " +
                " AND i.del = '1' " +
                " AND i.value2 in(2,4,6) " +
                " AND i.value1 <= 4.4 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user IN (SELECT t.patient_code FROM wlyy.wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +teamCode+")" +
                " ) aft";
        String pHighSql ="SELECT " +
                " count(1) AS highCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.del = '1' " +
                " AND i.type = '2' " +
                " AND i.value1 >= 139 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user IN (SELECT t.patient_code FROM wlyy.wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +teamCode+")";
        String  pStdSql ="SELECT " +
                " count(1) AS stdCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.del = '1' " +
                " AND i.type = '2' " +
                " AND i.value1 <= 139 " +
                " AND i.value1 >= 90 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user IN (SELECT t.patient_code FROM wlyy.wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +teamCode+")";
        String pLowSql ="SELECT " +
                " count(1) AS lowCount " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.del = '1' " +
                " AND i.type = '2' " +
                " AND i.value1 <= 90 " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'" +
                " AND i.user IN (SELECT t.patient_code FROM wlyy.wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +teamCode+")";
        Map<String,Object> rs = new HashedMap();
        //0血檀
        if ("0".equals(type)){
            //1.高
            List<Map<String,Object>> high = jdbcTemplate.queryForList(highSql);
            if(high!=null&&high.size()>0){
                Map<String,Object> h = high.get(0);
                rs.put("highCount",h.get("highCount"));
            }
            //2.正常
            List<Map<String,Object>> std = jdbcTemplate.queryForList(pStdSql);
            if(std!=null&&std.size()>0){
                Map<String,Object> st = std.get(0);
                rs.put("stdCount",st.get("stdCount"));
            }
            //3.偏低
            List<Map<String,Object>> low = jdbcTemplate.queryForList(pLowSql);
            if(low!=null&&low.size()>0){
                Map<String,Object> lw = low.get(0);
                rs.put("lowCount",lw.get("lowCount"));
            }
        //其他血压
        }else{
            //1.高
            List<Map<String,Object>> high = jdbcTemplate.queryForList(pHighSql);
            if(high!=null&&high.size()>0){
                Map<String,Object> h = high.get(0);
                rs.put("highCount",h.get("highCount"));
            }
            //2.正常
            List<Map<String,Object>> std = jdbcTemplate.queryForList(stdSql);
            if(std!=null&&std.size()>0){
                Map<String,Object> st = std.get(0);
                rs.put("stdCount",st.get("stdCount"));
            }
            //3.偏低
            List<Map<String,Object>> low = jdbcTemplate.queryForList(lowSql);
            if(low!=null&&low.size()>0){
                Map<String,Object> lw = low.get(0);
                rs.put("lowCount",lw.get("lowCount"));
            }
        }
        return rs;
    }
    public Map<String,Object> getTrackPatientInfo(String patient){
        Map<String,Object> rs = new HashedMap();
        rs.put("wxSport",0);
        String hsql = "SELECT " +
                " i.value1 AS weight, " +
                " i.value2 AS height, " +
                " i.value3 AS BMI " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.del = '1' " +
                " AND i.type = '3'  " +
                " AND i.user ='"+patient+"'" +
                " ORDER BY " +
                " i.record_date DESC LIMIT 1,1";
        String xtSchSql="SELECT " +
                " l.id " +
                " FROM " +
                " wlyy_patient_scheme_list l " +
                " WHERE " +
                " l.type = 1 " +
                " AND l.patientcode = '"+patient+"'";
        String xySchSql="SELECT " +
                " l.id " +
                " FROM " +
                " wlyy_patient_scheme_list l " +
                " WHERE " +
                " l.type = 2 " +
                " AND l.patientcode = '"+patient+"'";
        List<Map<String,Object>> hList = jdbcTemplate.queryForList(hsql);
        if(hList!=null&&hList.size()>0){
            Map<String,Object> body = hList.get(0);
            rs.put("body",body);
        }else{
            rs.put("body",null);
        }
        List<Map<String,Object>> xtList = jdbcTemplate.queryForList(xtSchSql);
        if(xtList!=null&&xtList.size()>0){
            rs.put("sugger","1");
        }else{
            rs.put("sugger","0");
        }
        List<Map<String,Object>> xyList = jdbcTemplate.queryForList(xySchSql);
        if(xyList!=null&&xyList.size()>0){
            rs.put("pressure","1");
        }else{
            rs.put("pressure","0");
        }
        return  rs;
    }
    public Map<String,Object> getControlObjectives(String patient){
        Map<String,Object> rs = new HashedMap();
        PatientAimBloodSugger patientAimBloodSugger =  patientAimBloodSuggerDao.findByPatientcode(patient);
        PatientAimBloodPressure patientAimBloodPressure = patientAimBloodPressureDao.findByPatientcode(patient);
        rs.put("patientAimBloodSugger",patientAimBloodSugger);
        rs.put("patientAimBloodPressure",patientAimBloodPressure);
        return rs;
    }
    public List<Map<String,Object>> getBodyInfo(String patient,String startDate,String endDate,Integer page,Integer size){
        startDate = startDate+" 00:00:00";
        endDate = endDate + " 23:59:59";
        String sql = "SELECT " +
                " i.record_date, " +
                " i.value1 AS weight, " +
                " i.value2 AS height, " +
                " i.value3 AS BMI " +
                " FROM " +
                " device.wlyy_patient_health_index i " +
                " WHERE " +
                " i.del = '1' " +
                " AND i.type = 3 " +
                " AND i.`user` = '"+patient+"' " +
                " AND i.record_date >='"+startDate+"'" +
                " AND i.record_date <='"+endDate+"'"+
                " ORDER BY " +
                " i.record_date DESC LIMIT "+(page-1)*size+","+size;
        List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql);
        return rs;
    }
    public String setDoctorSwitchTrackPatient(String doctor,String state){
        DoctorSwitch doctorSwitch =doctorSwitchDao.findByDoctor(doctor);
        if(doctorSwitch!=null){
            doctorSwitch.setAlertPatientSwitch(state);
        }else{
            DoctorSwitch dw = new DoctorSwitch();
            dw.setDoctor(doctor);
            dw.setAlertPatientSwitch(state);
            dw.setCreateTime(new Date());
            doctorSwitchDao.save(dw);
        }
        return "0";
    }
    public Map<String,Object> getDoctorSwitchTrackPatient(String doctor){
        DoctorSwitch doctorSwitch = doctorSwitchDao.findByDoctor(doctor);
        Map<String,Object> rs = new HashedMap();
        rs.put("alertPatientSwitch",doctorSwitch.getAlertPatientSwitch());
        return rs;
    }
    public Map<String,Object> getTrackPatientCountTitle(Integer teamCode,String doctor,String startDate,String endDate){
        List<TrackPatient> trackPatients = trackPatientDao.findByDoctorCodeAndTeamCode(doctor,teamCode);
        Map<String,Object> rs = new HashedMap();
        rs.put("trackPatientCount",trackPatients.size());
        String sql = "SELECT " +
                " COUNT(1) AS total " +
                " FROM " +
                " wlyy_track_patient t " +
                " WHERE " +
                " t.doctor_code = '"+doctor+"' " +
                " AND t.team_code = '"+teamCode+"' " +
                " AND t.create_time >= '"+startDate+"' " +
                " AND t.create_time <= '"+endDate+"'";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        if(list!=null&&list.size()>0){
            Long total = (Long)list.get(0).get("total");
            rs.put("trackPatientAddCount",total);
        }else{
            rs.put("trackPatientAddCount",0);
        }
        return rs;
    }
    public  Map<String,Object> getTrackPatientServerCount(Long teamCode,String patient,String doctor,String startDate,String endDate){
        startDate = startDate + " 00:00:00";
        endDate = endDate + " 23:59:59";
        Map<String,Object> rs = new  HashedMap();
        //咨询
        rs.put("consultCount",getConsultByteam(teamCode,doctor,startDate,endDate));
        //随访
        rs.put("followupCount",getFollowByTeam(teamCode,doctor,startDate,endDate));
        //获取健康指导
        rs.put("guidanceCount",getGuidanceByTeam(teamCode,doctor,startDate,endDate));
        //获取待预约
        rs.put("reservationCount",getReservationByteam(teamCode,doctor,startDate,endDate));
        //续方审核
        rs.put("reviewedCount",getPresCount(teamCode,doctor,startDate,endDate));
        return rs;
    }
    /**
     * 获取咨询数
     *
     * @param id
     * @param startDate
     * @param endDate
     * @return
     */
    public Long getConsultByteam(Long id, String doctor,String startDate, String endDate) {
        String imDataBaseName = im_dataBase_name;
        //咨询量
        String consult_sql = "SELECT " +
                "  COUNT(1) consultCount " +
                "  FROM " +
                " wlyy_admin_team_member m JOIN(" +
                " SELECT d.id,t.create_time FROM " +
                "  " + imDataBaseName + ".Topics t, " +
                "  " + imDataBaseName + ".Participants p, " +
                "  " + imDataBaseName + ".Doctors d, " +
                "  Wlyy_Consult_Team c, " +
                "  " + imDataBaseName + ".Patients s " +
                "  WHERE " +
                "  d.id = p.participant_id " +
                " AND c.type <> 8  " +
                " AND c.consult = t.id " +
                " AND c.patient = s.id " +
                " AND p.session_id = t.session_id " +
                " AND c.admin_team_code =" + id +
                " AND t.create_time >= '" + startDate + "' " +
                " AND t.create_time <= '" + endDate + "'" +
                " AND c.patient IN(" +
                "  SELECT t.patient_code FROM wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +id+
                " )" +
                " )c ON c.id = m.doctor_code " +
                " WHERE " +
                " m.team_id = "  + id+
                " m.doctor_code ='"+doctor+"'" ;
        //获取咨詢數
        Map<String, Object> consultCout = jdbcTemplate.queryForMap(consult_sql);
        if (consultCout.get("consultCount") == null) {
            consultCout.put("consultCount", 0);
        }
        return (Long)consultCout.get("consultCount");
    }
    public Long getReservationByteam(Long id,String doctor, String startDate, String endDate) {
        //获取待预约
        String reservation_sql = "SELECT COUNT(1) AS reservationCount FROM wlyy_patient_reservation  w WHERE w.admin_team_code =" + id + " AND w.czrq <='" + endDate + "' AND w.czrq >='" + startDate + "' " +
                " AND w.doctor ='"+doctor+"' AND w.patient IN (SELECT t.patient_code FROM wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +id+") ";
        //获取待预约
        Map<String, Object> reservationCout = jdbcTemplate.queryForMap(reservation_sql);
        if (reservationCout.get("reservationCount") == null) {
            reservationCout.put("reservationCount", 0);
        }
        return (Long)reservationCout.get("reservationCount");
    }
    public Long getEduArticleByTeam(Long id,String doctor, String startDate, String endDate) {
        //获取健康教育
        String article_sql = "SELECT COUNT(1) AS articleCount FROM wlyy_health_edu_article_patient w WHERE  w.admin_team_code =" + id + " AND w.czrq <='" + endDate + "' AND w.czrq >='" + startDate + "'" +
                " AND w.doctor ='"+doctor+"' AND w.patient IN (SELECT t.patient_code FROM wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +id+") ";
        //获取健康教育
        Map<String, Object> articleCout = jdbcTemplate.queryForMap(article_sql);
        if (articleCout.get("articleCount") == null) {
            articleCout.put("articleCount", 0);
        }
        return (Long)articleCout.get("articleCount");
    }
    public Long getGuidanceByTeam(Long id,String doctor, String startDate, String endDate) {
        //获取健康指导
        String guidance_sql = "SELECT COUNT(1) AS guidanceCount  FROM wlyy_patient_health_guidance w WHERE w.admin_team_code =" + id + " AND w.czrq <='" + endDate + "' AND w.czrq >='" + startDate + "' " +
                " AND w.doctor ='"+doctor+"' AND w.patient IN (SELECT t.patient_code FROM wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +id+") ";
        //获取健康指导
        Map<String, Object> guidanceCout = jdbcTemplate.queryForMap(guidance_sql);
        if (guidanceCout.get("guidanceCount") == null) {
            guidanceCout.put("guidanceCount", 0);
        }
        return (Long)guidanceCout.get("guidanceCount");
    }
    public Long getFollowByTeam(Long id,String doctor, String startDate, String endDate) {
        //随访数目
        String followup_sql = "SELECT COUNT(1) AS followupCount from wlyy_followup w WHERE w.admin_team_code=" + id + " AND  w.create_time >='" + startDate + "' AND w.create_time<='" + endDate + "' " +
                " AND w.doctor_code ='"+doctor+"' AND w.patient_code IN (SELECT t.patient_code FROM wlyy_track_patient t WHERE t.doctor_code ='"+doctor+"' AND t.team_code = " +id+") ";
        //随访数目
        Map<String, Object> followupCout = jdbcTemplate.queryForMap(followup_sql);
        if (followupCout.get("followupCount") == null) {
            followupCout.put("followupCount", 0);
        }
        return (Long)followupCout.get("followupCount");
    }
    public Long getPresCount(Long id,String doctor, String startDate, String endDate){
        String sql ="SELECT " +
                " count(1) AS reviewedCount " +
                " FROM " +
                " wlyy_prescription p " +
                " JOIN wlyy_prescription_reviewed r ON r.prescription_code = p.`code` " +
                " WHERE " +
                " r.doctor = '"+doctor+"' " +
                " AND p.admin_team_id = " + id +
                " AND r.reviewed_time >= '"+startDate+"' " +
                " AND r.reviewed_time <= '"+endDate+"' " +
                " AND p.patient IN ( " +
                " SELECT t.patient_code " +
                " FROM wlyy_track_patient t " +
                " WHERE t.doctor_code ='"+doctor+"' " +
                " AND t.team_code = " +id+")";
        //审核数目
        Map<String, Object> reviewedCount = jdbcTemplate.queryForMap(sql);
        if (reviewedCount.get("reviewedCount") == null) {
            reviewedCount.put("reviewedCount", 0);
        }
        return (Long)reviewedCount.get("reviewedCount");
    }
}

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -833,7 +833,7 @@ public class FamilyContractService extends BaseService {
     */
    public int unsignRenew(String patient, String doctor) throws Exception {
        if (DateUtil.getNowMonth() < 7) {
        if (4 < DateUtil.getNowMonth() && DateUtil.getNowMonth() < 7) {
            SignFamilyRenew sf = signFamilyRenewDao.findByDoctorPatient(doctor, patient);
            if (sf != null && sf.getStatus() != 0 && sf.getStatus() != 2) {
                return -2;

+ 5 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/jimeiJkEdu/JMJkEduArticleService.java

@ -31,6 +31,7 @@ import io.searchbox.core.*;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.annotation.Transient;
@ -171,7 +172,7 @@ public class JMJkEduArticleService extends BaseService {
            heapm.setLevel(article.getString("articlelevel"));
//            heapm.setAllCount(heapm.getAllCount() + one.getPatients().size());
            sql3 = new StringBuffer();
            sql3.append("SELECT COUNT(*) as num FROM health_edu_article_patient_test3 WHERE isRead='1' AND batchNo = '"+one.getBatchNo()+"' AND patientCode is not null AND articleId='"+article.getString("articleId")+"'");
            sql3.append("SELECT COUNT(*) as num FROM "+esType+" WHERE isRead='1' AND batchNo = '"+one.getBatchNo()+"' AND patientCode is not null AND articleId='"+article.getString("articleId")+"'");
            Long num = elasticsearchUtil.excuteForLong(sql3.toString(), esType, esIndex);
            if(num!=null){
                heapm.setReadNumber(num.longValue());
@ -645,7 +646,9 @@ public class JMJkEduArticleService extends BaseService {
        //保存到ES中
        elastricSearchSave.save(healthEduArticleESList, esIndex, esType);
        HealthEduArticleES e = healthEduArticleESList.get(0);
        HealthEduArticleES e = new HealthEduArticleES();
        BeanUtils.copyProperties(healthEduArticleESList.get(0),e);
        e.setUserType(2);
        e.setPatientCode(null);
        e.setPatientName(null);

+ 61 - 36
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandlingController.java

@ -8,8 +8,8 @@ import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.web.third.jkedu.service.EduArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.json.JSONArray;
import org.json.JSONObject;
import io.swagger.annotations.ApiParam;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;
/**
 * Created by Administrator on 2016.10.08.
 * 修改历史数据处理控制器
@ -39,10 +41,11 @@ public class DataHandlingController extends BaseController {
    private com.yihu.wlyy.util.HttpUtil HttpUtil;
    @Autowired
    private EduArticleService eduArticleService;
    /**
     * 生成签约表中的行政团队的code
     */
    @RequestMapping(value = "produceSignAdminTeamCode",method =RequestMethod.GET)
    @RequestMapping(value = "produceSignAdminTeamCode", method = RequestMethod.GET)
    @ResponseBody
    public String produceSignAdminTeamCode() {
        try {
@ -55,9 +58,10 @@ public class DataHandlingController extends BaseController {
    /**
     * 生成咨询表中中的行政团队的code
     *
     * @return
     */
    @RequestMapping(value = "produceConsultAdminTeamCode",method =RequestMethod.GET)
    @RequestMapping(value = "produceConsultAdminTeamCode", method = RequestMethod.GET)
    @ResponseBody
    public String produceConsultAdminTeamCode() {
        try {
@ -70,10 +74,11 @@ public class DataHandlingController extends BaseController {
    /**
     * 生成医生和患者表中有身份的用户的密码
     *
     * @return
     */
    @ApiOperation("生成医生和患者表中有身份的用户的密码")
    @RequestMapping(value = "producePatientAndDoctorPassword",method =RequestMethod.GET)
    @RequestMapping(value = "producePatientAndDoctorPassword", method = RequestMethod.GET)
    @ResponseBody
    public String producePatientAndDoctorPasswor() {
        try {
@ -83,12 +88,14 @@ public class DataHandlingController extends BaseController {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 初始化wlyy_doctor的数据到wlyy_user
     *
     * @return
     */
    @ApiOperation("初始化wlyy_doctor的数据到wlyy_user")
    @RequestMapping(value = "initWLyyDoctorTable2WLyyUserTable",method = RequestMethod.GET)
    @RequestMapping(value = "initWLyyDoctorTable2WLyyUserTable", method = RequestMethod.GET)
    @ResponseBody
    public String initWLyyDoctorTable2WLyyUserTable() {
        try {
@ -99,63 +106,81 @@ public class DataHandlingController extends BaseController {
        }
    }
    @RequestMapping(value = "/getArticleListToNewDataBase",method = RequestMethod.GET)
    @RequestMapping(value = "/getArticleListToNewDataBase", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("文章列表转移")
    public String getArticleListToNewDataBase(){
    public String getArticleListToNewDataBase() {
        boolean flag = eduArticleService.getArticleListToNewDataBase();
        if (flag){
            return write(200,"数据转移成功!");
        }else{
            return write(0,"数据转移失败!");
        if (flag) {
            return write(200, "数据转移成功!");
        } else {
            return write(0, "数据转移失败!");
        }
    }
    @RequestMapping(value = "/getArticleCollectToNewDataBase",method = RequestMethod.GET)
    @RequestMapping(value = "/getArticleCollectToNewDataBase", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("文章收藏转移")
    public String getArticleCollectToNewDataBase(){
    public String getArticleCollectToNewDataBase() {
        boolean flag = eduArticleService.getArticleCollectToNewDataBase();
        if (flag){
            return write(200,"数据转移成功!");
        }else{
            return write(0,"数据转移失败!");
        if (flag) {
            return write(200, "数据转移成功!");
        } else {
            return write(0, "数据转移失败!");
        }
    }
    @RequestMapping(value = "/getArticleBehaviorToNewDataBase",method = RequestMethod.GET)
    @RequestMapping(value = "/getArticleBehaviorToNewDataBase", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("文章行为转移")
    public String getArticleBehaviorToNewDataBase(){
    public String getArticleBehaviorToNewDataBase() {
        boolean flag = eduArticleService.getArticleBehaviorToNewDataBase();
        if (flag){
            return write(200,"数据转移成功!");
        }else{
            return write(0,"数据转移失败!");
        if (flag) {
            return write(200, "数据转移成功!");
        } else {
            return write(0, "数据转移失败!");
        }
    }
    @RequestMapping(value = "/getArticleSendToEs",method = RequestMethod.GET)
    @RequestMapping(value = "/getArticleSendToEs", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("已发送文章列表转移Es")
    public String getArticleSendToEs(){
    public String getArticleSendToEs() {
        boolean flag = eduArticleService.getArticleSendedListToEs();
        if (flag){
            return write(200,"数据转移成功!");
        }else{
            return write(0,"数据转移失败!");
        if (flag) {
            return write(200, "数据转移成功!");
        } else {
            return write(0, "数据转移失败!");
        }
    }
    @RequestMapping(value = "/updateEsArticlePatent",method = RequestMethod.GET)
    @RequestMapping(value = "/updateEsArticlePatent", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("更新es里的数据没有userType")
    public String updateEsArticlePatent(){
    public String updateEsArticlePatent() {
        boolean flag = eduArticleService.updateData();
        if (flag){
            return write(200,"数据更新成功!");
        }else{
            return write(0,"数据更新失败!");
        if (flag) {
            return write(200, "数据更新成功!");
        } else {
            return write(0, "数据更新失败!");
        }
    }
    @RequestMapping(value = "/getArticleSendToEsByDoctor", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("根据医生去把Mysql数据抽到区ES数据")
    public String getArticleSendToEsByDoctor(
            @ApiParam(name = "doctorCodes", value = "医生code,多个逗号分割", required = true) @RequestParam(value = "doctorCodes", required = true) String doctorCodes
    ) {
        Map<String, JSONObject> flag = null;
        try {
            flag = eduArticleService.getArticleSendToEsByDoctor(doctorCodes);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return write(200, "数据更新成功!","data",flag);
    }
}

+ 15 - 7
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/jimeiJkEduPC/DoctorJMJkEduArticlePCController.java

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yihu.es.entity.HealthEduArticleES;
import com.yihu.wlyy.service.app.health.HealthEduArticleLabelService;
import com.yihu.wlyy.service.jimeiJkEdu.JMJkEduArticleService;
import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.web.third.gateway.vo.HealthEduArticlePatientModel;
import io.swagger.annotations.Api;
@ -14,11 +15,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -37,6 +34,12 @@ public class DoctorJMJkEduArticlePCController extends BaseController {
    String fastdfs_file_url;
    @Value("${neiwang.enable}")
    private Boolean isneiwang = false;  //如果不是内网项目要转到到内网wlyy在上传
    @Value("${es.type.HealthEduArticlePatient}")
    private String esType;
    @Value("${es.index.HealthEduArticlePatient}")
    private String esIndex;
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    @Autowired
    private HealthEduArticleLabelService healthEduArticleLabelService;
@ -147,12 +150,13 @@ public class DoctorJMJkEduArticlePCController extends BaseController {
            if(StringUtils.isNotBlank(patient)){
                com.alibaba.fastjson.JSONArray pushresponse = jmJkEduArticleService.pushArticleLogs(0,0,patient,"");
                Set<String> articleids = new HashSet<>();
                if(pushresponse.size() > 0){
                if(pushresponse.size() > 0)
                {
                    for (int i = 0; i < pushresponse.size(); i++) {
                        articleids.add(pushresponse.getJSONObject(i).getString("articleId"));
                    }
                }
                
                StringBuffer sql3 = null;
                JSONArray datas = response.getJSONArray("aaData");
                if(datas.size() > 0 && !articleids.isEmpty()){
                    for (int i = 0; i < datas.size(); i++) {
@ -162,6 +166,10 @@ public class DoctorJMJkEduArticlePCController extends BaseController {
                        }else{
                            datas.getJSONObject(i).put("ispush","0");
                        }
//                        sql3 = new StringBuffer();
//                        sql3.append("SELECT COUNT(*) as num FROM "+esType+" WHERE  userType=2 AND articleId='"+dataarticleid+"'");
//                        Long num = elasticsearchUtil.excuteForLong(sql3.toString(), esType, esIndex);
//                        datas.getJSONObject(i).put("ispush","0");
                    }
                    response.put("aaData",datas);
                }

+ 16 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelInfoController.java

@ -130,13 +130,28 @@ public class SignPatientLabelInfoController extends BaseController {
            if (StringUtils.isEmpty(patient)) {
                return error(-1, "居民不能为空");
            }
            JSONObject p = labelInfoService.getPatient(patient);
            JSONObject p = labelInfoService.getPatient(patient,getUID());
            return write(200, "查询成功", "data", p);
        } catch (Exception e) {
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "/setTrackPatient", method = RequestMethod.POST)
    @ApiOperation("设置居民重点关注")
    public String setTrackPatient(@ApiParam(name="patient",value="患者Code")@RequestParam(required = false)String patient){
        try {
            String rs =  labelInfoService.setTrackPatient(patient,getUID());
            if("-1".equals(rs)){
                return error(-1, "查询失败,未找到签约关系");
            }
            return write(200, "查询成功", "data", rs);
        } catch (Exception e) {
            return error(-1, "查询失败");
        }
    }
    /**
     * 查询某个团队的某个标签下的患者信息
     *

+ 127 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/scheme/DoctroSchemeController.java

@ -153,4 +153,131 @@ public class DoctroSchemeController extends BaseController {
            return error(-1, "操作失败,"+e.getMessage());
        }
    }
    @RequestMapping(value="getPatientHealthIndex",method = RequestMethod.GET)
    @ApiOperation("获取最近一周血糖情况/血压情况")
    public String getPatientHealthIndex(@ApiParam(name="patient", value="居民code") @RequestParam(value = "patient",required = true) String patient,
                                        @ApiParam(name="startDate", value="开始时间,YYYY-MM-dd") @RequestParam(value = "startDate",required = true)String startDate,
                                        @ApiParam(name="endDate", value="结束时间,YYYY-MM-dd") @RequestParam(value = "endDate",required = true)String endDate,
                                        @ApiParam(name="type", value="0血糖,1.血压") @RequestParam(value = "type",required = true)String type){
        try {
            return write(200, "查询成功", "data",doctorSchemeService.getPatientHealthIndex(patient,startDate, endDate, type));
        }catch (Exception e){
            error(e);
            //返回接口异常信息处理结果
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value="getTrackPatientInfo",method = RequestMethod.GET)
    @ApiOperation("获取:微信运动,身高体重,血糖监测方案,血压监测方案")
    public String getTrackPatientInfo(@ApiParam(name="patient", value="居民code") @RequestParam(value = "patient",required = true)String patient){
        try {
            return write(200, "查询成功", "data",doctorSchemeService.getTrackPatientInfo(patient));
        }catch (Exception e){
            error(e);
            //返回接口异常信息处理结果
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value="getControlObjectives",method = RequestMethod.GET)
    @ApiOperation("获取控制目标,血压,血糖")
    public String getControlObjectives(@ApiParam(name="patient", value="居民code") @RequestParam(value = "patient",required = true)String patient){
        try {
            return write(200, "查询成功", "data",doctorSchemeService.getControlObjectives(patient));
        }catch (Exception e){
            error(e);
            //返回接口异常信息处理结果
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value="getBodyInfo",method = RequestMethod.GET)
    @ApiOperation("获取身高体重详情列表")
    public String getBodyInfo(@ApiParam(name="patient", value="居民code") @RequestParam(value = "patient",required = true)String patient,
                              @ApiParam(name="startDate", value="开始时间,YYYY-MM-dd") @RequestParam(value = "startDate",required = true)String startDate,
                              @ApiParam(name="endDate", value="结束时间,YYYY—MM-dd") @RequestParam(value = "endDate",required = true)String endDate,
                              @ApiParam(name="page", value="起始页") @RequestParam(value = "page",required = true)Integer page,
                              @ApiParam(name="size", value="每页大小") @RequestParam(value = "size",required = true)Integer size){
        try {
            return write(200, "查询成功", "data",doctorSchemeService.getBodyInfo(patient,startDate,endDate,page,size));
        }catch (Exception e){
            error(e);
            //返回接口异常信息处理结果
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value="setDoctorSwitchTrackPatient",method = RequestMethod.GET)
    @ApiOperation("医生跟踪预警居民开关接口")
    public String setDoctorSwitchTrackPatient(@ApiParam(name="state", value="0不自动跟踪居民,1自动跟踪预警居民") @RequestParam(value = "state",required = true)String state){
        try {
            return write(200, "操作成功", "data",doctorSchemeService.setDoctorSwitchTrackPatient(getUID(),state));
        }catch (Exception e){
            error(e);
            //返回接口异常信息处理结果
            return error(-1, "操作失败");
        }
    }
    @RequestMapping(value="getDoctorSwitchTrackPatient",method = RequestMethod.GET)
    @ApiOperation("医生跟踪预警居民开关接口")
    public String getDoctorSwitchTrackPatient(){
        try {
            return write(200, "查询成功", "data",doctorSchemeService.getDoctorSwitchTrackPatient(getUID()));
        }catch (Exception e){
            error(e);
            //返回接口异常信息处理结果
            return error(-1, "操作失败");
        }
    }
    @RequestMapping(value="getTrackPatientCountTitle",method = RequestMethod.GET)
    @ApiOperation("获取重点跟踪居民数,近一周增加数")
    public String getTrackPatientCountTitle(@ApiParam(name="teamCode", value="团队ID") @RequestParam(value = "teamCode",required = true)Integer teamCode,
                                            @ApiParam(name="startDate", value="开始时间") @RequestParam(value = "startDate",required = true)String startDate,
                                            @ApiParam(name="endDate", value="结束时间") @RequestParam(value = "endDate",required = true)String endDate){
        try {
            return write(200, "查询成功", "data",doctorSchemeService.getTrackPatientCountTitle(teamCode,getUID(),startDate,endDate));
        }catch (Exception e){
            error(e);
            //返回接口异常信息处理结果
            return error(-1, "操作失败");
        }
    }
    @RequestMapping(value="getTrackPatientServerCount",method = RequestMethod.GET)
    @ApiOperation("团队医生下,居民近一周服务情况接口")
    public String getTrackPatientServerCount(@ApiParam(name="teamCode", value="团队ID") @RequestParam(value = "teamCode",required = true)Long teamCode,
                                             @ApiParam(name="patient", value="居民Code") @RequestParam(value = "patient",required = true)String patient,
                                             @ApiParam(name="startDate", value="开始时间") @RequestParam(value = "startDate",required = true)String startDate,
                                             @ApiParam(name="endDate", value="结束时间") @RequestParam(value = "endDate",required = true)String endDate){
        try {
            return write(200, "查询成功", "data",doctorSchemeService.getTrackPatientServerCount(teamCode,patient,getUID(),startDate,endDate));
        }catch (Exception e){
            error(e);
            //返回接口异常信息处理结果
            return error(-1, "操作失败");
        }
    }
    @RequestMapping(value="getPatientHealthIndexByTeam",method = RequestMethod.GET)
    @ApiOperation("获取医生团队最近一周血糖情况/血压情况")
    public String getPatientHealthIndexByTeam(@ApiParam(name="patient", value="居民code") @RequestParam(value = "patient",required = true) String patient,
                                        @ApiParam(name="startDate", value="开始时间,YYYY-MM-dd") @RequestParam(value = "startDate",required = true)String startDate,
                                        @ApiParam(name="endDate", value="结束时间,YYYY-MM-dd") @RequestParam(value = "endDate",required = true)String endDate,
                                        @ApiParam(name="type", value="0血糖,1.血压") @RequestParam(value = "type",required = true)String type,
                                        @ApiParam(name="teamCode", value="团队code") @RequestParam(value = "teamCode",required = true)Long teamCode){
        try {
            return write(200, "查询成功", "data",doctorSchemeService.getPatientHealthIndex(startDate, endDate, type,teamCode,getUID()));
        }catch (Exception e){
            error(e);
            //返回接口异常信息处理结果
            return error(-1, "查询失败");
        }
    }
}

+ 3 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/jimeiJkEdu/PatientJMJkEduArticleController.java

@ -143,7 +143,8 @@ public class PatientJMJkEduArticleController extends BaseController {
                                      @ApiParam(name = "roleType", value = "1、普通医生,2、管理员")
                                      @RequestParam(value = "archive", required = false) Integer roleType,
                                      @ApiParam(name = "patient", value = "居民CODE")
                                      @RequestParam(value = "patient", required = false) String patient){
                                      @RequestParam(value = "patient", required = false) String patient,
                                      @RequestParam(value = "doctor", required = false) String doctor){
        try {
            if(StringUtils.isEmpty(currentUserRole)){
                currentUserRole=getCurrentRoleCode();
@ -153,7 +154,7 @@ public class PatientJMJkEduArticleController extends BaseController {
            }
            JSONObject response = jmJkEduArticleService.queryArticlePcList(firstLevelCategoryId,secondLevelCategoryId,insertTimeStart,insertTimeEnd,articlelevel,articleTitle,
                    getUID(),currentUserRole,currentUserRoleLevel,isAuthentication,isMyArticle,page,pageSize,sEcho,roleType);
                    doctor,currentUserRole,currentUserRoleLevel,isAuthentication,isMyArticle,page,pageSize,sEcho,roleType);
            //判断文章列表是否有推送过该居民

+ 323 - 123
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/service/EduArticleService.java

@ -10,6 +10,8 @@ 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;
@ -22,10 +24,12 @@ import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.util.MapListUtils;
import com.yihu.wlyy.util.SpringUtil;
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;
@ -38,6 +42,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.hateoas.alps.Doc;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -73,6 +78,9 @@ public class EduArticleService {
    private ElasticsearchUtil elasticsearchUtil;
    @Autowired
    private ElasticFactory elasticFactory;
    @Autowired
    private GcLabelService gcLabelService;
    @Value("${es.type.HealthEduArticlePatient}")
    private String esType;
@ -83,9 +91,10 @@ public class EduArticleService {
    /**
     * 健康教育文章列表转移
     *
     * @return
     */
    public boolean getArticleListToNewDataBase(){
    public boolean getArticleListToNewDataBase() {
        boolean flag = true;
        //获取卫计委code
        String wjwSql = "select code AS wjwCode from wlyy_role WHERE  name LIKE '%厦门市卫生与计划生育委员会%' and LENGTH(code)=6";
@ -93,31 +102,31 @@ public class EduArticleService {
        String wjwCode = result.get("wjwCode") + "";
        //先将原来数据库的数据删除
        List<NewArticleModel> delOldList = jkeduArticleDao.findOldArticle();
        if (delOldList!=null && delOldList.size()>0){
        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){
        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, " +
            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;
                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<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);
                            BeanUtils.copyProperties(oldArticleModel,newArticleModel);
                            oldArticleModel = MapListUtils.convertMap2Bean(map, OldArticleModel.class);
                            BeanUtils.copyProperties(oldArticleModel, newArticleModel);
                            newArticleModel.setArticleOrder(99);
                            newArticleModel.setArticleState(1);
                            newArticleModel.setOrgName("厦门市卫生与计划生育委员会");
@ -139,7 +148,7 @@ public class EduArticleService {
                        }
                        //执行插入新数据库
                        jkeduArticleDao.save(newList);
                    }catch (Exception e){
                    } catch (Exception e) {
                        e.printStackTrace();
                        flag = false;
                    }
@ -153,9 +162,10 @@ public class EduArticleService {
    /**
     * 健康教育收藏列表转移
     *
     * @return
     */
    public boolean getArticleCollectToNewDataBase(){
    public boolean getArticleCollectToNewDataBase() {
        boolean flag = true;
        try {
            //获取卫计委code
@ -164,14 +174,14 @@ public class EduArticleService {
            String wjwCode = result.get("wjwCode") + "";
            //先将原来数据库的数据删除
            List<Integer> delOldList = jkeduCollectionArticleDao.findOldArticleCollection();
            if (delOldList!=null && delOldList.size()>0){
            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++){
                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));
                    for (int j = 0; j < 1000; j++) {
                        if (count <= delOldList.size()) {
                            idsList.add(delOldList.get(j + i * 1000));
                        }
                        count++;
                    }
@ -179,13 +189,13 @@ public class EduArticleService {
                }
            }
            //先分页查询
            String countSql ="select COUNT(1) AS num from wlyy_health_edu_article_doctor";
            Map<String,Object> countMap = jdbcTemplate.queryForMap(countSql);
            if (countMap!=null){
            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" +
                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, " +
@ -200,13 +210,13 @@ public class EduArticleService {
                    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<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);
                            oldArticleCollectModel = MapListUtils.convertMap2Bean(map, OldArticleCollectModel.class);
                            //@// TODO: 2017/12/25 完善数据
                            BeanUtils.copyProperties(oldArticleCollectModel,newArticleCollectModel);
                            BeanUtils.copyProperties(oldArticleCollectModel, newArticleCollectModel);
                            newArticleCollectModel.setUserType(1);
                            newArticleCollectModel.setOrgName("厦门市卫生与计划生育委员会");
                            newArticleCollectModel.setOrgId(wjwCode);
@ -218,7 +228,7 @@ public class EduArticleService {
                    }
                }
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
        }
@ -227,22 +237,23 @@ public class EduArticleService {
    /**
     * 转移健康教育行为
     *
     * @return
     */
    public boolean getArticleBehaviorToNewDataBase(){
    public boolean getArticleBehaviorToNewDataBase() {
        boolean flag = true;
        try {
            //数量也许过大,分批次删除
            //先将原来数据库的数据删除
            List<NewArticleBehaviorModel> delOldList = jkeduBehaviorArticleDao.findOldArticleBehavior();
            if (delOldList!=null && delOldList.size()>0){
            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++){
                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());
                    for (int j = 0; j < 1000; j++) {
                        if (count <= delOldList.size()) {
                            idsList.add(delOldList.get(j + i * 1000).getID());
                        }
                        count++;
                    }
@ -251,25 +262,25 @@ public class EduArticleService {
            }
            //分批次查询
            String countSql = "select COUNT(1) AS num from wlyy_health_edu_article_op_history";
            Map<String,Object> countMap = jdbcTemplate.queryForMap(countSql);
            if (countMap!=null) {
            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," +
                    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});
                        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);
                            oldArticleBehaviorModel = MapListUtils.convertMap2Bean(map, OldArticleBehaviorModel.class);
                            //@// TODO: 2017/12/25 完善数据
                            BeanUtils.copyProperties(oldArticleBehaviorModel,newArticleBehaviorModel);
                            if (newArticleBehaviorModel.getBehaviorAction()==1){
                            BeanUtils.copyProperties(oldArticleBehaviorModel, newArticleBehaviorModel);
                            if (newArticleBehaviorModel.getBehaviorAction() == 1) {
                                newArticleBehaviorModel.setBehaviorAction(5);
                            }
                            newArticleBehaviorModel.setIsOld(1);
@ -280,7 +291,7 @@ public class EduArticleService {
                    }
                }
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
        }
@ -289,44 +300,45 @@ public class EduArticleService {
    /**
     * 数据转移至Es.
     *
     * @return
     */
    public boolean getArticleSendedListToEs(){
    public boolean getArticleSendedListToEs() {
        boolean flag = true;
        try{
        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") + "";
            //查询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");
            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");
            //查询出所有的医生
            List<Doctor> doctorList = doctorDao.findAllCertifiedDoctors();
            Map<String,Doctor> doctorMap = new HashedMap();
            if (doctorList!=null && doctorList.size()>0){
                for (Doctor doctor: doctorList){
                    doctorMap.put(doctor.getCode(),doctor);
            Map<String, Doctor> doctorMap = new HashedMap();
            if (doctorList != null && doctorList.size() > 0) {
                for (Doctor doctor : doctorList) {
                    doctorMap.put(doctor.getCode(), doctor);
                }
            }
            //查询出所有的文章列表
            List<HealthEduArticle> healthEduArticleList = healthEduArticleDao.findAllArticle();
            Map<String,HealthEduArticle> articleMap = new HashedMap();
            if (healthEduArticleList!=null && healthEduArticleList.size()>0){
                for (HealthEduArticle healthEduArticle: healthEduArticleList){
                    articleMap.put(healthEduArticle.getCode(),healthEduArticle);
            Map<String, HealthEduArticle> articleMap = new HashedMap();
            if (healthEduArticleList != null && healthEduArticleList.size() > 0) {
                for (HealthEduArticle healthEduArticle : healthEduArticleList) {
                    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+"'";
            if (StringUtils.isNotBlank(startTimeForSql)) {
                countSql += " AND czrq > '" + startTimeForSql + "'";
            }
            Map<String, Object> countMap = jdbcTemplate.queryForMap(countSql);
            if (countMap!=null) {
            if (countMap != null) {
                int count = Integer.valueOf(String.valueOf(countMap.get("num")));
                double pageCount = Math.ceil(Double.valueOf(count) / Double.valueOf(pageSize*20));
                double pageCount = Math.ceil(Double.valueOf(count) / Double.valueOf(pageSize * 20));
                if (pageCount > 0) {
                    String resultSql = "SELECT " +
                            " ap.patient AS patientCode, " +
@ -336,25 +348,25 @@ public class EduArticleService {
                            " ap.czrq AS createTime, " +
                            " ap.admin_team_code AS adminTeamCode, " +
                            " ap.batch_no AS batchNo, " +
                            " ap.send_type AS sendSource,"+
                            " p.name AS patientName,"+
                            " t.name AS adminTeamName"+
                            " 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 {
                    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)){
                        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;
                        }
@ -362,9 +374,9 @@ public class EduArticleService {
                        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 = MapListUtils.convertMap2Bean(map, HealthEduArticleES.class);
                            healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 1);
                            if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
                                healthEduArticleES.setDoctorCode(wjwCode);
                                //卫计委发送
                                healthEduArticleES.setSendType(2);
@ -380,10 +392,10 @@ public class EduArticleService {
            }
            //按批次查询文章信息。userType=2
            //要先删除原来的数据。
            String batSql ="SELECT batch_no from wlyy_health_edu_article_patient WHERE admin_team_code IS NOT NULL GROUP BY batch_no ";
            List<Map<String,Object>> batchNoMap = jdbcTemplate.queryForList(batSql);
            if (batchNoMap!=null && batchNoMap.size()>0){
                deleteData(2,batchNoMap);
            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);
            }
            String BartchNoSql = "SELECT " +
@ -394,26 +406,26 @@ public class EduArticleService {
                    " ap.czrq AS createTime, " +
                    " ap.admin_team_code AS adminTeamCode, " +
                    " ap.batch_no AS batchNo, " +
                    " ap.send_type AS sendSource,"+
                    " p.name AS patientName,"+
                    " t.name AS adminTeamName"+
                    " 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);
            System.out.println("userType2=========" + BartchNoSql);
            List<Map<String, Object>> batchList = jdbcTemplate.queryForList(BartchNoSql);
            List<HealthEduArticleES> batchEsList = new ArrayList<>();
            if (batchList!=null && batchList.size()>0){
            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 = MapListUtils.convertMap2Bean(map, HealthEduArticleES.class);
                    healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 2);
                    if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
                        healthEduArticleES.setDoctorCode(wjwCode);
                        //卫计委发送
                        healthEduArticleES.setSendType(2);
@ -425,18 +437,18 @@ public class EduArticleService {
                //保存到Es中
                saveDate(batchEsList);
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            flag= false;
            flag = false;
        }
        return flag;
    }
    public HealthEduArticleES setDateToObj(HealthEduArticleES healthEduArticleES,Map<String,Doctor> doctorMap,Map<String,HealthEduArticle> articleMap,String wjwCode,Integer userType)throws Exception{
    public HealthEduArticleES setDateToObj(HealthEduArticleES healthEduArticleES, Map<String, Doctor> doctorMap, Map<String, HealthEduArticle> articleMap, String wjwCode, Integer userType) throws Exception {
        //遍历医生
        Set<Map.Entry<String,Doctor>> doctorSet=doctorMap.entrySet();
        for(Map.Entry<String, Doctor> doctorEntry:doctorSet){
            if (doctorEntry.getKey().equals(healthEduArticleES.getDoctorCode())){
        Set<Map.Entry<String, Doctor>> doctorSet = doctorMap.entrySet();
        for (Map.Entry<String, Doctor> doctorEntry : doctorSet) {
            if (doctorEntry.getKey().equals(healthEduArticleES.getDoctorCode())) {
                Doctor doctor = doctorEntry.getValue();
                healthEduArticleES.setDoctorCode(doctor.getCode());
                healthEduArticleES.setDoctorName(doctor.getName());
@ -454,8 +466,8 @@ public class EduArticleService {
            }
        }
        //遍历文章
        Set<Map.Entry<String,HealthEduArticle>> articleSet=articleMap.entrySet();
        for(Map.Entry<String, HealthEduArticle> articleEntry:articleSet){
        Set<Map.Entry<String, HealthEduArticle>> articleSet = articleMap.entrySet();
        for (Map.Entry<String, HealthEduArticle> articleEntry : articleSet) {
            if (articleEntry.getKey().equals(healthEduArticleES.getArticleId())) {
                HealthEduArticle healthEduArticle = articleEntry.getValue();
                healthEduArticleES.setArticleId(healthEduArticle.getCode());
@ -469,7 +481,7 @@ public class EduArticleService {
        healthEduArticleES.setUserType(userType);
        healthEduArticleES.setOperatorId(wjwCode);
        healthEduArticleES.setArticleSource("厦门市卫生与计划生育委员会");
        return  healthEduArticleES;
        return healthEduArticleES;
    }
@ -478,39 +490,39 @@ public class EduArticleService {
     *
     * @param
     */
    private Boolean saveDate(List<HealthEduArticleES> sms)throws Exception {
    private Boolean saveDate(List<HealthEduArticleES> sms) throws Exception {
        return SpringUtil.getBean(SaveEduArticleHelper.class).save(sms);
    }
    /**
     * 删除数据
     */
    private void deleteData(int userType,List<Map<String,Object>> batchNoMap) {
    private void deleteData(int userType, List<Map<String, Object>> batchNoMap) {
        JestClient jestClient = null;
        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);
                   }
               }
           }
            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);
                    }
                }
            }
            //根据id批量删除
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            for (HealthEduArticleES obj : saveModels) {
                if (obj!=null){
                if (obj != null) {
                    Delete index = new Delete.Builder(obj.getId()).build();
                    bulk.addAction(index);
                }
@ -520,7 +532,7 @@ public class EduArticleService {
            logger.info("delete data count:" + saveModels.size());
            logger.info("delete flag:" + br.isSucceeded());
        } catch (Exception e) {
            System.out.println("======error:"+e.getMessage());
            System.out.println("======error:" + e.getMessage());
            e.printStackTrace();
        } finally {
            if (jestClient != null) {
@ -532,19 +544,19 @@ public class EduArticleService {
    /**
     * 更新es数据库数据
     */
    public boolean updateData(){
    public boolean updateData() {
        boolean flag = true;
        JestClient jestClient = null;
        try{
        try {
            jestClient = elasticFactory.getJestClient();
            //先查询出相关数据
            /*String timeSql ="select * from "+esType+" where userType<>1 and userType<>2 ";
            List<HealthEduArticleES> saveModels = elasticsearchUtil.excute(timeSql,HealthEduArticleES.class,esType,esIndex);*/
            //先根据条件查找出来
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolQueryBuilder =  new BoolQueryBuilder();
            boolQueryBuilder.mustNot(QueryBuilders.matchQuery("userType",1));
            boolQueryBuilder.mustNot(QueryBuilders.matchQuery("userType",2));
            BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
            boolQueryBuilder.mustNot(QueryBuilders.matchQuery("userType", 1));
            boolQueryBuilder.mustNot(QueryBuilders.matchQuery("userType", 2));
            searchSourceBuilder.query(boolQueryBuilder).size(100000);//一次取100000条
            Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
@ -563,14 +575,202 @@ public class EduArticleService {
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("update data count:" + saveModels.size());
            logger.info("update flag:" + br.isSucceeded());
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
        }finally {
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
        return flag;
    }
    public Map<String, net.sf.json.JSONObject> getArticleSendToEsByDoctor(String doctorCodes) throws Exception {
        Map<String, net.sf.json.JSONObject> returnMap = new HashedMap();
        String[] doctorCodeArr = doctorCodes.split(",");
        //初始化文章
        for (String doctorCode : doctorCodeArr) {
            net.sf.json.JSONObject o = new net.sf.json.JSONObject();
            //删除医生的推送记录
            deleteEsDataByDoctor(doctorCode);
            //新增医生的推送记录
            Integer size = saveByDoctor(doctorCode);
            o.put("saveEsSize", size);
            returnMap.put(doctorCode, o);
        }
        return returnMap;
    }
    /**
     * 根据code删除ES中的推送表的记录
     *
     * @param doctorCode
     */
    private void deleteEsDataByDoctor(String doctorCode) {
        JestClient jestClient = null;
        try {
            jestClient = elasticFactory.getJestClient();
            //先根据条件查找出来
            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);
            }
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("delete data count:" + healthEduArticleESs.size());
            logger.info("delete flag:" + br.isSucceeded());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (jestClient != null) {
                jestClient.shutdownClient();
            }
        }
    }
    /**
     * 保存推送记录到ES中
     *
     * @param doctorCode
     */
    private Integer saveByDoctor(String doctorCode) throws Exception {
        Doctor doctor = doctorDao.findByCode(doctorCode);
        //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.获取医生的推送记录
        String sql = "select * from wlyy_health_edu_article_patient where doctor='" + doctorCode + "'";
        List<HealthEduArticlePatient> healthEduArticlePatients = jdbcTemplate.query(sql, new BeanPropertyRowMapper(HealthEduArticlePatient.class));
        //推送记录按照批次号分组
        Map<String, List<HealthEduArticlePatient>> healthEduArticlePatientMap = new HashMap<>();
        healthEduArticlePatients.stream().forEach(one -> {
            List<HealthEduArticlePatient> healthEduArticlePatientTemp = healthEduArticlePatientMap.get(one.getBatchNo());
            if (healthEduArticlePatientTemp == null) {
                healthEduArticlePatientTemp = new ArrayList<HealthEduArticlePatient>();
            }
            healthEduArticlePatientTemp.add(one);
            healthEduArticlePatientMap.put(one.getBatchNo(), healthEduArticlePatientTemp);
        });
        //3.转换成新的健康教育需要的数据
        List<HealthEduArticleES> healthEduArticleESSaveList = new ArrayList<>();
        //获取医生的角色
        Map<String,Object> roleMaps=  gcLabelService.fetchUserHighestAuthority(doctorCode);
        healthEduArticlePatientMap.keySet().stream().forEach(one -> {
            //获取患者数据
            List<HealthEduArticlePatient> healthEduArticlePatientTemps = healthEduArticlePatientMap.get(one);
            AdminTeam adminTeam = doctorAdminTeamDao.findOne(healthEduArticlePatientTemps.get(0).getId());
            //遍历数据
            healthEduArticlePatientTemps.stream().forEach(healthEduArticlePatient -> {
                //3,1 保存userType=1的
                HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
                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.setSendSource(1);//旧数据都是1 i健康发送
                healthEduArticleES.setSendType(1);//默认是医生发送
                if(roleMaps!=null){
                   // healthEduArticleES.setCurrentUserRoleLevel("2");
                   // healthEduArticleES.setCurrentUserRoleCode();
                }else{
                }
                healthEduArticleES.setBatchNo(healthEduArticlePatient.getBatchNo());
                healthEduArticleES.setPatientCode(healthEduArticlePatient.getPatient());
                healthEduArticleES.setPatientName(patientDao.findByCode(healthEduArticlePatient.getPatient()).getName());
                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.setAdminTeamCode(adminTeam.getId());
                healthEduArticleES.setAdminTeamName(adminTeam.getName());
                healthEduArticleES.setHospital(adminTeam.getOrgCode());
                healthEduArticleES.setHospitalName(adminTeam.getOrgName());
                healthEduArticleES.setTown(adminTeam.getTownCode());
                healthEduArticleES.setTownName(adminTeam.getTownName());
                healthEduArticleES.setCreateTime(new Date());
                healthEduArticleES.setUserType(1);//患者
                healthEduArticleESSaveList.add(healthEduArticleES);
            });
            //3,2 保存userType=2的
            HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
            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.setSendSource(1);//旧数据都是1 i健康发送
            healthEduArticleES.setSendType(1);//默认是医生发送
            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.setUserType(2); //医生
            healthEduArticleES.setAllCount(healthEduArticlePatientTemps.size());
            healthEduArticleES.setCreateTime(new Date());
            healthEduArticleESSaveList.add(healthEduArticleES);
        });
        //数据存到ES
        saveDate(healthEduArticleESSaveList);
        return healthEduArticleESSaveList.size();
    }
}