Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

liuwenbin 7 years ago
parent
commit
28dda2d26a
17 changed files with 562 additions and 199 deletions
  1. 5 2
      common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticleES.java
  2. 51 5
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/controller/manager/user/UserController.java
  3. 12 0
      patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/user/user_modify.jsp
  4. 4 0
      patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/user/user_modify_js.jsp
  5. 1 1
      patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java
  6. 19 7
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelInfoService.java
  7. 18 18
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/scheme/DoctorSchemeService.java
  8. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/jimeiJkEdu/JMJkEduArticleService.java
  9. 57 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ElasticsearchUtil.java
  10. 11 9
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandlingController.java
  11. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java
  12. 12 7
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelInfoController.java
  13. 8 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/scheme/DoctroSchemeController.java
  14. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcLableController.java
  15. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/controller/doctor/EduLableController.java
  16. 359 140
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/service/EduArticleService.java
  17. 1 1
      patient-co/patient-co-wlyy/src/main/resources/system.properties

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

@ -1,5 +1,6 @@
package com.yihu.es.entity;
package com.yihu.es.entity;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.Patient;
import io.searchbox.annotations.JestId;
import io.searchbox.annotations.JestId;
@ -34,8 +35,8 @@ public class HealthEduArticleES {
    private String town; // 所属区划(ES)
    private String town; // 所属区划(ES)
    private String townName; // 所属区划(ES)
    private String townName; // 所属区划(ES)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyyMMdd'T'HHmmss.SSS'Z'")
    @CreatedDate
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssXX")
    @JSONField(format = "yyyy-MM-dd'T'HH:mm:ssXX")
    private Date createTime;  // 创建时间(ES:必填)
    private Date createTime;  // 创建时间(ES:必填)
    private Integer sendType;//发送类型 1医生发送 2(管理员)卫纪委发送(ES:必填)
    private Integer sendType;//发送类型 1医生发送 2(管理员)卫纪委发送(ES:必填)
    private String sendLevel;   // 发送人级别  1专科医生,2全科医生,3健康管理师 4 管理员(ES)
    private String sendLevel;   // 发送人级别  1专科医生,2全科医生,3健康管理师 4 管理员(ES)
@ -69,6 +70,8 @@ public class HealthEduArticleES {
    //说明:如医生推送文章给5个居民,则保存5条userType=1的记录和1条userType=2的记录(共6条)
    //说明:如医生推送文章给5个居民,则保存5条userType=1的记录和1条userType=2的记录(共6条)
    //业务需求:userType=1为居民被推送文章列表;userType=2医生推送的文章列表;
    //业务需求:userType=1为居民被推送文章列表;userType=2医生推送的文章列表;
    private Integer userType; // 1、患者,2医生(ES:必填)
    private Integer userType; // 1、患者,2医生(ES:必填)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssXX")
    @JSONField(format = "yyyy-MM-dd'T'HH:mm:ssXX")
    private Date czrq;//阅读时间(默认为空,isRead=0;如isRead=1已读,则该字段有值)(ES:非必填)
    private Date czrq;//阅读时间(默认为空,isRead=0;如isRead=1已读,则该字段有值)(ES:非必填)
    public String getId() {
    public String getId() {

+ 51 - 5
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/controller/manager/user/UserController.java

@ -1,10 +1,10 @@
package com.yihu.wlyy.controller.manager.user;
package com.yihu.wlyy.controller.manager.user;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.controller.BaseController;
import com.yihu.wlyy.controller.BaseController;
import com.yihu.wlyy.entity.User;
import com.yihu.wlyy.entity.User;
import com.yihu.wlyy.service.manager.user.UserService;
import com.yihu.wlyy.service.manager.user.UserService;
import com.yihu.wlyy.util.Envelop;
import com.yihu.wlyy.util.MD5;
import com.yihu.wlyy.util.MD5;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringUtils;
@ -16,8 +16,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
/**
 * Created by yww on 2016/12/6.
 * Created by yww on 2016/12/6.
@ -142,6 +143,11 @@ public class UserController extends BaseController {
    @ResponseBody
    @ResponseBody
    public String updateUser(String jsonData){
    public String updateUser(String jsonData){
        try{
        try{
    
            JSONObject data = JSONObject.parseObject(jsonData);
            
            String oldpsw = data.getString("oldpsw");
            
            User user = objectMapper.readValue(jsonData, User.class);
            User user = objectMapper.readValue(jsonData, User.class);
            String mobile = user.getMobile();
            String mobile = user.getMobile();
            if(mobile == null){
            if(mobile == null){
@ -154,14 +160,54 @@ public class UserController extends BaseController {
            userNew.setMobile(user.getMobile());
            userNew.setMobile(user.getMobile());
            userNew.setOrganizationId(user.getOrganizationId());
            userNew.setOrganizationId(user.getOrganizationId());
            userNew.setRoles(user.getRoles());
            userNew.setRoles(user.getRoles());
            //修改手机号对应初始化密码(因暂未提供修改密码操作)-手机号后六位
            if(userNew.getMobile() != user.getMobile()){
                String password=mobile.substring(5);
    
            String password=user.getPassword();
            
            //如果新密码不为空,则进入修改密码的分支
            if(StringUtils.isNotBlank(password)){
                
                if(StringUtils.isBlank(oldpsw)){
                    return error(-1,"旧密码不能为空");
                }
    
                oldpsw =  MD5.GetMD5Code(oldpsw+userNew.getSalt());
    
                if(!oldpsw.equals(userNew.getPassword())){
                    return error(-1,"旧密码错误,无法修改");
                }
    
                //
//            复杂(同时包含数字,字母,特殊符号)
//            "^^(?![a-zA-z]+$)(?!\\d+$)(?![!@#$%^&*_-]+$)(?![a-zA-z\\d]+$)(?![a-zA-z!@#$%^&*_-]+$)(?![\\d!@#$%^&*_-]+$)[a-zA-Z\\d!@#$%^&*_-]+$"
//            中级(包含字母和数字)
                String regStr = "^(?![a-zA-z]+$)(?!\\d+$)(?![!@#$%^&*]+$)[a-zA-Z\\d!@#$%^&*]+$";
                Pattern pattern = Pattern.compile(regStr);
                Matcher matcher = pattern.matcher(password);
                boolean rs = matcher.find();
                if(!rs){
                    return error(-1,"新密码必须包含字母和数字!");
                }
    
                String salt= UUID.randomUUID().toString().replace("-", "");
                String salt= UUID.randomUUID().toString().replace("-", "");
                password = MD5.GetMD5Code(password+salt);
                password = MD5.GetMD5Code(password+salt);
                userNew.setPassword(password);
                userNew.setPassword(password);
                userNew.setSalt(salt);
                userNew.setSalt(salt);
            }
            }
    
            
    
            
//            //修改手机号对应初始化密码(因暂未提供修改密码操作)-手机号后六位
//            if(userNew.getMobile() != user.getMobile()){
//                String password=mobile.substring(5);
//                String salt= UUID.randomUUID().toString().replace("-", "");
//                password = MD5.GetMD5Code(password+salt);
//                userNew.setPassword(password);
//                userNew.setSalt(salt);
//            }
            userNew = userService.save(userNew);
            userNew = userService.save(userNew);
            return write(200,"操作成功!");
            return write(200,"操作成功!");
        }catch (Exception ex){
        }catch (Exception ex){

+ 12 - 0
patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/user/user_modify.jsp

@ -40,6 +40,18 @@
			<input type="text"  id="inp_type" class="required useTitle f-w240 validate-special-char" required-title="用户类型不能为空"  data-attr-scan="type"/>
			<input type="text"  id="inp_type" class="required useTitle f-w240 validate-special-char" required-title="用户类型不能为空"  data-attr-scan="type"/>
		</div>
		</div>
	</div>
	</div>
	<div class="m-form-group" id="new_psw_div" style="display: none">
		<label class="label_title" style="width:120px">登陆密码</label>
		<div class="l-text-wrapper m-form-control essential">
			<input type="password"  id="inp_psw" class="required useTitle f-w240 validate-special-char" required-title="登陆密码不能为空"  data-attr-scan="password"/>
		</div>
	</div>
	<div class="m-form-group" id="old_psw_div" style="display: none">
		<label class="label_title" style="width:120px">旧密码</label>
		<div class="l-text-wrapper m-form-control essential">
			<input type="password"  id="inp_old_psw" class="required useTitle f-w240 validate-special-char" required-title="旧密码不能为空"  data-attr-scan="oldpsw"/>
		</div>
	</div>
	<div id="customer" style="display: none">
	<div id="customer" style="display: none">
		<div class="m-form-group">
		<div class="m-form-group">
			<label class="label_title" style="width:120px">工号</label>
			<label class="label_title" style="width:120px">工号</label>

+ 4 - 0
patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/user/user_modify_js.jsp

@ -99,6 +99,10 @@
						this.$form.removeClass("m-form-readonly");
						this.$form.removeClass("m-form-readonly");
						$(".XXXtest").addClass("essential");
						$(".XXXtest").addClass("essential");
						$("#btn_save_close").css("display", "block");
						$("#btn_save_close").css("display", "block");
                        if(type == "edit"){
                            $("#new_psw_div").css("display", "block");
                            $("#old_psw_div").css("display", "block");
                        }
					}
					}
					this.$form.show();
					this.$form.show();
				},
				},

+ 1 - 1
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java

@ -424,7 +424,7 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
    //查询wlyy_sign_family有续签却未同步到wlyy_sign_family_renew_log数据
    //查询wlyy_sign_family有续签却未同步到wlyy_sign_family_renew_log数据
    @Query(value = "SELECT f.* FROM wlyy_sign_family f LEFT JOIN wlyy_sign_family_renew_log r ON f.`code` = r.sign_code WHERE r.sign_code IS NULL  " +
    @Query(value = "SELECT f.* FROM wlyy_sign_family f LEFT JOIN wlyy_sign_family_renew_log r ON f.`code` = r.sign_code WHERE r.sign_code IS NULL  " +
            " AND f.renew_flag IN (1, 2) and f.`status`!=-4  ",nativeQuery = true)
            " AND f.renew_flag IN (1, 2) AND f.`status` IN (1, 2)  ",nativeQuery = true)
    List<SignFamily> findRenew();
    List<SignFamily> findRenew();
    //根据身份证号查询最近的已到期签约数据
    //根据身份证号查询最近的已到期签约数据

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

@ -314,7 +314,7 @@ public class SignPatientLabelInfoService extends BaseService {
     */
     */
    public JSONArray getPatientByLabel(String doctor, String labelCode, String labelType,
    public JSONArray getPatientByLabel(String doctor, String labelCode, String labelType,
                                       Long teamCode, int page, int pagesize, boolean isSlowDisease,
                                       Long teamCode, int page, int pagesize, boolean isSlowDisease,
                                       String diseaseCondition,boolean isFollowWeChat,String trackFlag) throws Exception {
                                       String diseaseCondition,boolean isFollowWeChat,String trackFlag,String sDate,String eDate) throws Exception {
        Doctor doc = doctorDao.findByCode(doctor);
        Doctor doc = doctorDao.findByCode(doctor);
        if (doc == null) {
        if (doc == null) {
@ -416,6 +416,9 @@ public class SignPatientLabelInfoService extends BaseService {
            }
            }
            if(StringUtils.isNotBlank(trackFlag)&&"1".equals(trackFlag)){
            if(StringUtils.isNotBlank(trackFlag)&&"1".equals(trackFlag)){
                sql = sql + " AND tp.del='1'  AND tp.doctor_code ='"+doctor+"' AND tp.team_code ="+teamCode;
                sql = sql + " AND tp.del='1'  AND tp.doctor_code ='"+doctor+"' AND tp.team_code ="+teamCode;
                if(StringUtils.isNotBlank(sDate)&&StringUtils.isNotBlank(eDate)){
                    sql += " AND tp.create_time >='"+sDate+" 00:00:00' AND tp.create_time <='"+eDate+" 23:59:59' ";
                }
            }
            }
    
    
            sql = sql + " order by p.standard_status DESC ,p.disease_condition DESC,t2.label DESC,t1.openid DESC ,convert(t1.name using gbk) ";
            sql = sql + " order by p.standard_status DESC ,p.disease_condition DESC,t2.label DESC,t1.openid DESC ,convert(t1.name using gbk) ";
@ -1116,7 +1119,7 @@ public class SignPatientLabelInfoService extends BaseService {
     * @param teamCode  标签类型为4时,不能为空
     * @param teamCode  标签类型为4时,不能为空
     * @return
     * @return
     */
     */
    public JSONArray getPatientAmountByLabelType(String doctor, String labelType, Long teamCode, boolean isSlowDisease, String diseaseCondition,String trackFlag) throws Exception {
    public JSONArray getPatientAmountByLabelType(String doctor, String labelType, Long teamCode, boolean isSlowDisease, String diseaseCondition,String trackFlag,String sDate,String eDate) throws Exception {
        Doctor doc = doctorDao.findByCode(doctor);
        Doctor doc = doctorDao.findByCode(doctor);
        if (doc == null) {
        if (doc == null) {
@ -1212,6 +1215,9 @@ public class SignPatientLabelInfoService extends BaseService {
                                //1.4.2新增重点居民跟踪过滤
                                //1.4.2新增重点居民跟踪过滤
                                if(StringUtils.isNotBlank(trackFlag)&&"1".equals(trackFlag)){
                                if(StringUtils.isNotBlank(trackFlag)&&"1".equals(trackFlag)){
                                    sql = sql + " AND tp.del='1' AND tp.doctor_code='"+doctor+"' AND tp.team_code ="+teamCode;
                                    sql = sql + " AND tp.del='1' AND tp.doctor_code='"+doctor+"' AND tp.team_code ="+teamCode;
                                    if(StringUtils.isNotBlank(sDate)&&StringUtils.isNotBlank(eDate)){
                                        sql +=" AND tp.create_time <='"+eDate+" 23:59:59' AND tp.create_time >='"+sDate+" 00:00:00'";
                                    }
                                }
                                }
                        if (teamCode > 0) {
                        if (teamCode > 0) {
@ -4408,7 +4414,7 @@ public class SignPatientLabelInfoService extends BaseService {
                                                           String labelCode, String labelType, long teamCode,
                                                           String labelCode, String labelType, long teamCode,
                                                           String exLabelCode,
                                                           String exLabelCode,
                                                           String exLabelType,
                                                           String exLabelType,
                                                           int page, int pagesize) throws Exception {
                                                           int page, int pagesize,String trackFlag) throws Exception {
        Doctor doc = doctorDao.findByCode(doctor);
        Doctor doc = doctorDao.findByCode(doctor);
        if (doc == null) {
        if (doc == null) {
@ -4430,13 +4436,19 @@ public class SignPatientLabelInfoService extends BaseService {
        sql = "select " +
        sql = "select " +
                "    DISTINCT t1.* " +
                "    DISTINCT t1.* " +
                " FROM " +
                " FROM " +
                "    wlyy_sign_family t1 " +
                " JOIN wlyy_sign_patient_label_info t2 ON t1.patient = t2.patient and t2.status=1 " +
                "    wlyy_sign_family t1 ";
        if(StringUtils.isNotBlank(trackFlag)&&"1".equals(trackFlag)){
            sql +=" JOIN wlyy_track_patient tp ON tp.patient_code = t1.patient ";
        }
        sql +=" JOIN wlyy_sign_patient_label_info t2 ON t1.patient = t2.patient and t2.status=1 " +
                " JOIN wlyy_patient t3 ON t1.patient = t3.code " +
                " JOIN wlyy_patient t3 ON t1.patient = t3.code " +
                (teamCode > 0 ? " join (select * from wlyy_sign_patient_label where label_type != '4' or team_code = " + teamCode + " or (label_type = '4' and (label_code in (1,2)))) lb on t2.label = lb.label_code and t2.label_type = lb.label_type " : "") +
                (teamCode > 0 ? " join (select * from wlyy_sign_patient_label where label_type != '4' or team_code = " + teamCode + " or (label_type = '4' and (label_code in (1,2)))) lb on t2.label = lb.label_code and t2.label_type = lb.label_type " : "") +
                " WHERE " +
                " WHERE " +
                "    (t1.doctor = ? or t1.doctor_health = ?) " +
                "    AND t1.status > 0 " +
                "    (t1.doctor = ? or t1.doctor_health = ?) " ;
        if(StringUtils.isNotBlank(trackFlag)&&"1".equals(trackFlag)){
            sql = sql + " AND tp.del='1' AND tp.doctor_code='"+doctor+"' AND tp.team_code ="+teamCode;
        }
        sql +=  "    AND t1.status > 0 " +
                "    AND t2.status = 1 " +
                "    AND t2.status = 1 " +
//                (StringUtils.isNotEmpty(labelCode) ? " AND t2.label = ? " : "") +
//                (StringUtils.isNotEmpty(labelCode) ? " AND t2.label = ? " : "") +
//                (StringUtils.isNotEmpty(labelType) ? " AND t2.label_type = ? " : "") +
//                (StringUtils.isNotEmpty(labelType) ? " AND t2.label_type = ? " : "") +

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

@ -1589,8 +1589,8 @@ public class DoctorSchemeService extends BaseService{
                "   AND i.type = 1 " +
                "   AND i.type = 1 " +
                "   AND i.value2 IN (2, 4, 6) " +
                "   AND i.value2 IN (2, 4, 6) " +
                "   AND i.value1 > 7.8 " +
                "   AND i.value1 > 7.8 " +
                "   AND i.i.record_date >='"+startDate+"'" +
                "   AND i.i.record_date <='"+endDate+"'" +
                "   AND i.record_date >='"+startDate+"'" +
                "   AND i.record_date <='"+endDate+"'" +
                "   GROUP BY " +
                "   GROUP BY " +
                "    i. USER " +
                "    i. USER " +
                "  ) pid ON pid. USER = t.patient_code " +
                "  ) pid ON pid. USER = t.patient_code " +
@ -1624,8 +1624,8 @@ public class DoctorSchemeService extends BaseService{
                "  AND i.type = 1 " +
                "  AND i.type = 1 " +
                "  AND i.value2 IN (1, 3, 5, 7) " +
                "  AND i.value2 IN (1, 3, 5, 7) " +
                "  AND i.value1 > 6.1 " +
                "  AND i.value1 > 6.1 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "  AND i.record_date >='"+startDate+"'" +
                "  AND i.record_date <='"+endDate+"'" +
                "  GROUP BY " +
                "  GROUP BY " +
                "   i. USER " +
                "   i. USER " +
                " ) pid ON pid. USER = t.patient_code " +
                " ) pid ON pid. USER = t.patient_code " +
@ -1666,8 +1666,8 @@ public class DoctorSchemeService extends BaseService{
                "   AND i.type = 1 " +
                "   AND i.type = 1 " +
                "   AND i.value2 IN (2, 4, 6) " +
                "   AND i.value2 IN (2, 4, 6) " +
                "   AND i.value1 < 4.4 " +
                "   AND i.value1 < 4.4 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "  AND i.record_date >='"+startDate+"'" +
                "  AND i.record_date <='"+endDate+"'" +
                "   GROUP BY " +
                "   GROUP BY " +
                "    i. USER " +
                "    i. USER " +
                "  ) pid ON pid. USER = t.patient_code " +
                "  ) pid ON pid. USER = t.patient_code " +
@ -1701,8 +1701,8 @@ public class DoctorSchemeService extends BaseService{
                "  AND i.type = 1 " +
                "  AND i.type = 1 " +
                "  AND i.value2 IN (1, 3, 5, 7) " +
                "  AND i.value2 IN (1, 3, 5, 7) " +
                "  AND i.value1 < 3.9 " +
                "  AND i.value1 < 3.9 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "  AND i.record_date >='"+startDate+"'" +
                "  AND i.record_date <='"+endDate+"'" +
                "  GROUP BY " +
                "  GROUP BY " +
                "   i. USER " +
                "   i. USER " +
                " ) pid ON pid. USER = t.patient_code " +
                " ) pid ON pid. USER = t.patient_code " +
@ -1745,8 +1745,8 @@ public class DoctorSchemeService extends BaseService{
                "   AND i.value2 IN (2, 4, 6) " +
                "   AND i.value2 IN (2, 4, 6) " +
                "   AND i.value1 >= 4.4 " +
                "   AND i.value1 >= 4.4 " +
                "   AND i.value1 <= 7.8 " +
                "   AND i.value1 <= 7.8 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "  AND i.record_date >='"+startDate+"'" +
                "  AND i.record_date <='"+endDate+"'" +
                "   GROUP BY " +
                "   GROUP BY " +
                "    i. USER " +
                "    i. USER " +
                "  ) pid ON pid. USER = t.patient_code " +
                "  ) pid ON pid. USER = t.patient_code " +
@ -1781,8 +1781,8 @@ public class DoctorSchemeService extends BaseService{
                "  AND i.value2 IN (1, 3, 5, 7) " +
                "  AND i.value2 IN (1, 3, 5, 7) " +
                "  AND i.value1 >= 3.9 " +
                "  AND i.value1 >= 3.9 " +
                "  AND i.value1 <= 6.1 " +
                "  AND i.value1 <= 6.1 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "  AND i.record_date >='"+startDate+"'" +
                "  AND i.record_date <='"+endDate+"'" +
                "  GROUP BY " +
                "  GROUP BY " +
                "   i. USER " +
                "   i. USER " +
                " ) pid ON pid. USER = t.patient_code " +
                " ) pid ON pid. USER = t.patient_code " +
@ -1839,8 +1839,8 @@ public class DoctorSchemeService extends BaseService{
                "    i.del = '1' " +
                "    i.del = '1' " +
                "   AND i.type = 2 " +
                "   AND i.type = 2 " +
                "   AND i.value1 < 90 " +
                "   AND i.value1 < 90 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "  AND i.record_date >='"+startDate+"'" +
                "  AND i.record_date <='"+endDate+"'" +
                "   GROUP BY " +
                "   GROUP BY " +
                "    i. USER " +
                "    i. USER " +
                "  ) pid ON pid. USER = t.patient_code " +
                "  ) pid ON pid. USER = t.patient_code " +
@ -1872,8 +1872,8 @@ public class DoctorSchemeService extends BaseService{
                "   AND i.type = 2 " +
                "   AND i.type = 2 " +
                "   AND i.value1 >= 90 " +
                "   AND i.value1 >= 90 " +
                "   AND i.value1 <=139 " +
                "   AND i.value1 <=139 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "  AND i.record_date >='"+startDate+"'" +
                "  AND i.record_date <='"+endDate+"'" +
                "   GROUP BY " +
                "   GROUP BY " +
                "    i. USER " +
                "    i. USER " +
                "  ) pid ON pid. USER = t.patient_code " +
                "  ) pid ON pid. USER = t.patient_code " +
@ -1905,8 +1905,8 @@ public class DoctorSchemeService extends BaseService{
                "    i.del = '1' " +
                "    i.del = '1' " +
                "   AND i.type = 2 " +
                "   AND i.type = 2 " +
                "   AND i.value1 >139 " +
                "   AND i.value1 >139 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "  AND i.record_date >='"+startDate+"'" +
                "  AND i.record_date <='"+endDate+"'" +
                "   GROUP BY " +
                "   GROUP BY " +
                "    i. USER " +
                "    i. USER " +
                "  ) pid ON pid. USER = t.patient_code " +
                "  ) pid ON pid. USER = t.patient_code " +

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

@ -938,7 +938,7 @@ public class JMJkEduArticleService extends BaseService {
    }
    }
    private void getPatientByGroup(String userCode,String labelCode, String labelType, Long teamCode, Set<String> patientSet, int page, int pagesize) throws Exception {
    private void getPatientByGroup(String userCode,String labelCode, String labelType, Long teamCode, Set<String> patientSet, int page, int pagesize) throws Exception {
        org.json.JSONArray result = signPatientLabelInfoService.getPatientByLabel(userCode, labelCode, labelType, teamCode, page, pagesize, false, "",true,null);
        org.json.JSONArray result = signPatientLabelInfoService.getPatientByLabel(userCode, labelCode, labelType, teamCode, page, pagesize, false, "",true,null,null,null);
        for (Object o : result) {
        for (Object o : result) {
            org.json.JSONObject json = (org.json.JSONObject) o;
            org.json.JSONObject json = (org.json.JSONObject) o;
            String patient = (String) json.get("code");
            String patient = (String) json.get("code");

+ 57 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ElasticsearchUtil.java

@ -8,6 +8,7 @@ import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.web.quota.vo.SaveModel;
import com.yihu.wlyy.web.quota.vo.SaveModel;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.nlpcn.es4sql.domain.Select;
import org.nlpcn.es4sql.domain.Select;
import org.nlpcn.es4sql.jdbc.ObjectResult;
import org.nlpcn.es4sql.jdbc.ObjectResult;
import org.nlpcn.es4sql.jdbc.ObjectResultsExtractor;
import org.nlpcn.es4sql.jdbc.ObjectResultsExtractor;
@ -27,9 +28,7 @@ import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
/**
/**
 * Created by chenweida on 2017/7/17.
 * Created by chenweida on 2017/7/17.
@ -1313,4 +1312,59 @@ public class ElasticsearchUtil {
        }
        }
        return resultLevel;
        return resultLevel;
    }
    }
    public List<Map<String, Object>> excuteDataModel(String sql) {
        List<Map<String, Object>> returnModels = new ArrayList<>();
        try {
            SQLExprParser parser = new ElasticSqlExprParser(sql);
            SQLExpr expr = parser.expr();
            SQLQueryExpr queryExpr = (SQLQueryExpr) expr;
//            if (parser.getLexer().token() != Token.EOF) {
//                throw new ParserException("illegal sql expr : " + sql);
//            }
            Select select = null;
            select = new SqlParser().parseSelect(queryExpr);
            //通过抽象语法树,封装成自定义的Select,包含了select、from、where group、limit等
            AggregationQueryAction action = null;
            DefaultQueryAction queryAction = null;
            SqlElasticSearchRequestBuilder requestBuilder = null;
            if (select.isAgg) {
                //包含计算的的排序分组的
                action = new AggregationQueryAction(elasticFactory.getTransportClient(), select);
                requestBuilder = action.explain();
            } else {
                //封装成自己的Select对象
                Client client = elasticFactory.getTransportClient();
                queryAction = new DefaultQueryAction(client, select);
                requestBuilder = queryAction.explain();
            }
            SearchResponse response = (SearchResponse) requestBuilder.get();
            Object queryResult = null;
            if (sql.toUpperCase().indexOf("GROUP") != -1 || sql.toUpperCase().indexOf("SUM") != -1) {
                queryResult = response.getAggregations();
            } else {
                queryResult = response.getHits();
            }
            ObjectResult temp = new ObjectResultsExtractor(true, true, true).extractResults(queryResult, true);
            List<String> heads = temp.getHeaders();
            temp.getLines().stream().forEach(one -> {
                try {
                    Map<String, Object> oneMap = new HashMap<String, Object>();
                    for (int i = 0; i < one.size(); i++) {
                        String key = null;
                        Object value = one.get(i);
                        key = heads.get(i);
                        oneMap.put(key, value);
                    }
                    returnModels.add(oneMap);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnModels;
    }
}
}

+ 11 - 9
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandlingController.java

@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;
import java.util.Map;
/**
/**
 * Created by Administrator on 2016.10.08.
 * Created by Administrator on 2016.10.08
 * 修改历史数据处理控制器
 * 修改历史数据处理控制器
 */
 */
@Controller
@Controller
@ -139,16 +139,18 @@ public class DataHandlingController extends BaseController {
        }
        }
    }
    }
    @RequestMapping(value = "/getArticleSendToEs", method = RequestMethod.GET)
    @RequestMapping(value = "/getArticleSendToEsByBatchNo", method = RequestMethod.GET)
    @ResponseBody
    @ResponseBody
    @ApiOperation("已发送文章列表转移Es")
    public String getArticleSendToEs() {
        boolean flag = eduArticleService.getArticleSendedListToEs();
        if (flag) {
            return write(200, "数据转移成功!");
        } else {
            return write(0, "数据转移失败!");
    @ApiOperation("根据批次号把Mysql数据转移到ES")
    public String getArticleSendToEsByBatchNo(
            @ApiParam(name = "batchNos", value = "文章批次号,多个逗号分割", required = true) @RequestParam(value = "batchNos", required = true) String batchNos) {
        Map<String, JSONObject> flag = null;
        try {
            flag = eduArticleService.getArticleSendToEsByBatchNo(batchNos);
        } catch (Exception e) {
            e.printStackTrace();
        }
        }
        return write(200, "数据转移成功!","data",flag);
    }
    }
    @RequestMapping(value = "/updateEsArticlePatent", method = RequestMethod.GET)
    @RequestMapping(value = "/updateEsArticlePatent", method = RequestMethod.GET)

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthEduArticleController.java

@ -512,7 +512,7 @@ public class DoctorHealthEduArticleController extends WeixinBaseController {
    }
    }
    private void getPatientByGroup(String labelCode, String labelType, Long teamCode, Set<String> patientSet, int page, int pagesize) throws Exception {
    private void getPatientByGroup(String labelCode, String labelType, Long teamCode, Set<String> patientSet, int page, int pagesize) throws Exception {
        JSONArray result = signPatientLabelInfoService.getPatientByLabel(getUID(), labelCode, labelType, teamCode, page, pagesize, false, "",false,null);
        JSONArray result = signPatientLabelInfoService.getPatientByLabel(getUID(), labelCode, labelType, teamCode, page, pagesize, false, "",false,null,null,null);
        for (Object o : result) {
        for (Object o : result) {
            JSONObject json = (JSONObject) o;
            JSONObject json = (JSONObject) o;
            String patient = (String) json.get("code");
            String patient = (String) json.get("code");

+ 12 - 7
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelInfoController.java

@ -187,7 +187,9 @@ public class SignPatientLabelInfoController extends BaseController {
                                        @RequestParam(required = false) String diseaseCondition,
                                        @RequestParam(required = false) String diseaseCondition,
                                        @RequestParam(required = false) boolean isSlowDisease,
                                        @RequestParam(required = false) boolean isSlowDisease,
                                        @RequestParam(required = false) boolean isFollowWeChat,
                                        @RequestParam(required = false) boolean isFollowWeChat,
                                        @RequestParam(required = false) String trackFlag) {
                                        @RequestParam(required = false) String trackFlag,
                                        @RequestParam(required = false) String startDate,
                                        @RequestParam(required = false) String enddate) {
        try {
        try {
            if (StringUtils.isEmpty(labelCode)) {
            if (StringUtils.isEmpty(labelCode)) {
                return error(-1, "标签cdoe不能为空");
                return error(-1, "标签cdoe不能为空");
@ -208,7 +210,7 @@ public class SignPatientLabelInfoController extends BaseController {
                return write(200, "查询成功", "data", jsonObject);
                return write(200, "查询成功", "data", jsonObject);
            }
            }
            JSONArray result = labelInfoService.getPatientByLabel(getUID(), labelCode, labelType, teamCode, page, pagesize,isSlowDisease,diseaseCondition,isFollowWeChat,trackFlag);
            JSONArray result = labelInfoService.getPatientByLabel(getUID(), labelCode, labelType, teamCode, page, pagesize,isSlowDisease,diseaseCondition,isFollowWeChat,trackFlag,startDate,enddate);
//            JSONArray result = labelInfoService.getPatientByLabel("xy201703150222", labelCode, labelType, teamCode, page, pagesize,isSlowDisease,diseaseCondition,isFollowWeChat);
//            JSONArray result = labelInfoService.getPatientByLabel("xy201703150222", labelCode, labelType, teamCode, page, pagesize,isSlowDisease,diseaseCondition,isFollowWeChat);
            return write(200, "查询成功", "data", result);
            return write(200, "查询成功", "data", result);
@ -326,7 +328,9 @@ public class SignPatientLabelInfoController extends BaseController {
            @RequestParam(required = false) Long teamCode,
            @RequestParam(required = false) Long teamCode,
            @RequestParam(required = false) boolean isSlowDisease,
            @RequestParam(required = false) boolean isSlowDisease,
            @RequestParam(required = false) String diseaseCondition,
            @RequestParam(required = false) String diseaseCondition,
            @RequestParam(required = false)String trackFlag) {
            @RequestParam(required = false)String trackFlag,
            @RequestParam(required = false)String startDate,
            @RequestParam(required = false)String endDate) {
        try {
        try {
            if (StringUtils.isEmpty(labelType)) {
            if (StringUtils.isEmpty(labelType)) {
                return error(-1, "标签类型不能为空");
                return error(-1, "标签类型不能为空");
@ -348,7 +352,7 @@ public class SignPatientLabelInfoController extends BaseController {
                return write(200, "查询成功", "data", r);
                return write(200, "查询成功", "data", r);
            }
            }
            JSONArray result = labelInfoService.getPatientAmountByLabelType(getUID(), labelType, teamCode,isSlowDisease,diseaseCondition,trackFlag);
            JSONArray result = labelInfoService.getPatientAmountByLabelType(getUID(), labelType, teamCode,isSlowDisease,diseaseCondition,trackFlag,startDate,endDate);
            return write(200, "查询成功", "data", result);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
        } catch (Exception e) {
@ -817,8 +821,9 @@ public class SignPatientLabelInfoController extends BaseController {
                                             @RequestParam(required = false) Long teamCode,
                                             @RequestParam(required = false) Long teamCode,
                                             @RequestParam(required = false) String exLabelCode,
                                             @RequestParam(required = false) String exLabelCode,
                                             @RequestParam(required = false) String exLabelType,
                                             @RequestParam(required = false) String exLabelType,
                                             @RequestParam(required = true) int page,
                                             @RequestParam(required = true) int pagesize) {
                                             @RequestParam(required = true) Integer page,
                                             @RequestParam(required = true) Integer pagesize,
                                             @RequestParam(required = false) String trackFlag) {
        try {
        try {
            if (StringUtils.isEmpty(filter)) {
            if (StringUtils.isEmpty(filter)) {
                return error(-1, "搜索字段不能为空");
                return error(-1, "搜索字段不能为空");
@ -838,7 +843,7 @@ public class SignPatientLabelInfoController extends BaseController {
            page = page - 1;
            page = page - 1;
            JSONArray result = labelInfoService.searchSlowDiseasePatientByNameOrLabel(getUID(), filter, labelCode, labelType, teamCode, exLabelCode, exLabelType, page, pagesize);
            JSONArray result = labelInfoService.searchSlowDiseasePatientByNameOrLabel(getUID(), filter, labelCode, labelType, teamCode, exLabelCode, exLabelType, page, pagesize,trackFlag);
//            JSONArray result = labelInfoService.searchSlowDiseasePatientByNameOrLabel("xy201703150222", filter, labelCode, labelType, teamCode, exLabelCode, exLabelType, page, pagesize);
//            JSONArray result = labelInfoService.searchSlowDiseasePatientByNameOrLabel("xy201703150222", filter, labelCode, labelType, teamCode, exLabelCode, exLabelType, page, pagesize);
            return write(200, "查询成功", "data", result);
            return write(200, "查询成功", "data", result);

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

@ -337,9 +337,15 @@ public class DoctroSchemeController extends BaseController {
    @RequestMapping(value="getTrackPatientIndexCountList",method = RequestMethod.GET)
    @RequestMapping(value="getTrackPatientIndexCountList",method = RequestMethod.GET)
    @ApiOperation("获取关注居民测量数据列表")
    @ApiOperation("获取关注居民测量数据列表")
    public String getTrackPatientIndexCountList(Integer teamCode,String type,String startDate,String endDate,String keyword,Integer page,Integer size){
    public String getTrackPatientIndexCountList(@ApiParam(name="teamCode", value="团队ID") @RequestParam(value = "teamCode",required = true)Integer teamCode,
                                                @ApiParam(name="type", value="1.糖尿病,其他为高血压") @RequestParam(value = "type",required = true)String type,
                                                @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="keyword", value="姓名模糊匹配,身份证号") @RequestParam(value = "keyword",required = false)String keyword,
                                                @ApiParam(name="page", value="起始页,1开始") @RequestParam(value = "page",required = true)Integer page,
                                                @ApiParam(name="size", value="每页大小") @RequestParam(value = "size",required = true)Integer size){
        try {
        try {
            return write(200, "查询成功", "data",doctorSchemeService.getTrackPatientIndexCountList(getUID(), teamCode, type, startDate, endDate, keyword, page, size));
            return write(200, "查询成功", "data",doctorSchemeService.getTrackPatientIndexCountList("xh1D2017031503333", teamCode, type, startDate, endDate, keyword, page, size));
        }catch (Exception e){
        }catch (Exception e){
            error(e);
            error(e);
            //返回接口异常信息处理结果
            //返回接口异常信息处理结果

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcLableController.java

@ -101,7 +101,7 @@ public class GcLableController extends BaseController {
            @ApiParam(name = "isFollowWeChat", value = "是否过滤微信关注居民", required = false) @RequestParam(value="isFollowWeChat",required = false,defaultValue = "false") boolean isFollowWeChat
            @ApiParam(name = "isFollowWeChat", value = "是否过滤微信关注居民", required = false) @RequestParam(value="isFollowWeChat",required = false,defaultValue = "false") boolean isFollowWeChat
    ) {
    ) {
        try {
        try {
            JSONArray result = signPatientLabelInfoService.getPatientByLabel(getUID(), labelCode, labelType, teamCode, page-1, pageSize, isSlowDisease, "",isFollowWeChat,null);
            JSONArray result = signPatientLabelInfoService.getPatientByLabel(getUID(), labelCode, labelType, teamCode, page-1, pageSize, isSlowDisease, "",isFollowWeChat,null,null,null);
            List<PatientModel> patientLabelModels = new ArrayList<>();
            List<PatientModel> patientLabelModels = new ArrayList<>();
            for (int i = 0; i < result.length(); i++) {
            for (int i = 0; i < result.length(); i++) {
                JSONObject jo = result.getJSONObject(i);
                JSONObject jo = result.getJSONObject(i);

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/controller/doctor/EduLableController.java

@ -100,7 +100,7 @@ public class EduLableController extends BaseController {
            @ApiParam(name = "isFollowWeChat", value = "是否过滤微信关注居民", required = true) @RequestParam(value="isFollowWeChat",required = false,defaultValue = "false") boolean isFollowWeChat
            @ApiParam(name = "isFollowWeChat", value = "是否过滤微信关注居民", required = true) @RequestParam(value="isFollowWeChat",required = false,defaultValue = "false") boolean isFollowWeChat
    ) {
    ) {
        try {
        try {
            JSONArray result = signPatientLabelInfoService.getPatientByLabel(getUID(), labelCode, labelType, teamCode, page-1, pageSize, isSlowDisease, "",isFollowWeChat,null);
            JSONArray result = signPatientLabelInfoService.getPatientByLabel(getUID(), labelCode, labelType, teamCode, page-1, pageSize, isSlowDisease, "",isFollowWeChat,null,null,null);
            List<PatientModel> patientLabelModels = new ArrayList<>();
            List<PatientModel> patientLabelModels = new ArrayList<>();
            for (int i = 0; i < result.length(); i++) {
            for (int i = 0; i < result.length(); i++) {
                JSONObject jo = result.getJSONObject(i);
                JSONObject jo = result.getJSONObject(i);

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

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

+ 1 - 1
patient-co/patient-co-wlyy/src/main/resources/system.properties

@ -31,7 +31,7 @@ patient_QRCode_url=https://open.weixin.qq.com/connect/oauth2/authorize?appid={ap
#居民wifi图片地址
#居民wifi图片地址
patient_wifi_pic_url = {server}/images/wifi.png
patient_wifi_pic_url = {server}/images/wifi.png
#居民wifi链接
#居民wifi链接
patient_wifi_url = https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&amp;redirect_uri=http://www.baidu.com
patient_wifi_url =http://freewifi.mobcb.com/Portal/Wx/login
#就诊记录
#就诊记录
patient_visit_pic ={server}/images/visit.png
patient_visit_pic ={server}/images/visit.png
#检查检验
#检查检验