Quellcode durchsuchen

完善数据清洗es

zd_123 vor 7 Jahren
Ursprung
Commit
83c5815e2c
25 geänderte Dateien mit 1014 neuen und 231 gelöschten Zeilen
  1. 202 0
      common/common-entity/src/main/java/com/yihu/device/entity/DeviceDetail.java
  2. 5 2
      common/common-entity/src/main/java/com/yihu/es/entity/HealthEduArticleES.java
  3. 9 18
      patient-co-manage/redis-cache/src/main/java/com/yihu/wlyy/task/RedisScheduledTask.java
  4. 6 5
      patient-co-manage/redis-cache/src/main/resources/application.yml
  5. 2 1
      patient-co-manage/redis-cache/src/main/webapp/WEB-INF/views/redis/cache/category/listJs.jsp
  6. 2 2
      patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/common/thread/LoadThread.java
  7. 1 1
      patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/service/SignZYService.java
  8. 15 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/health/repository/DeviceDetailDao.java
  9. 2 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/template/DoctorTeamGuidanceTemplateDao.java
  10. 51 14
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceService.java
  11. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java
  12. 2 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelInfoService.java
  13. 393 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/scheme/DoctorSchemeService.java
  14. 10 10
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/jimeiJkEdu/JMJkEduArticleService.java
  15. 4 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorGuidanceTempService.java
  16. 95 10
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/iot/IotDeviceService.java
  17. 57 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ElasticsearchUtil.java
  18. 11 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/scheme/DoctroSchemeController.java
  19. 1 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/template/DoctorGuidanceTempController.java
  20. 19 15
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/device/PatientDeviceController.java
  21. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/PatientHealthController.java
  22. 1 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/scheme/PatientSchemeController.java
  23. 29 6
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/iot/IotDeviceController.java
  24. 94 131
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkedu/service/EduArticleService.java
  25. 1 1
      patient-co/patient-co-wlyy/src/main/resources/system.properties

+ 202 - 0
common/common-entity/src/main/java/com/yihu/device/entity/DeviceDetail.java

@ -0,0 +1,202 @@
package com.yihu.device.entity;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by ysj on 2018/01/10.
 */
@Entity
@Table(name = "wlyy_devices")
public class DeviceDetail extends IdEntity{
    private String deviceName;
    private String deviceModel;
    private String deviceCode;
    private String manufacturer;
    private String applyDate;;
    private String orgName;
    private String linkman;
    private String tel;
    private String serverIp;
    private String manufacturerCode;
    private String address;
    private String representative;
    private String applicantName;
    private String applicantIdentity;
    private String applicantTel;
    private String applicantMail;
    /** default constructor */
    public DeviceDetail() {
    }
    /** full constructor */
    public DeviceDetail(String deviceName, String deviceModel, String deviceCode, String manufacturer, String applyDate
            , String orgName, String linkman, String tel, String serverIp, String manufacturerCode, String address
            , String representative, String applicantName, String applicantIdentity, String applicantTel, String applicantMail) {
        this.deviceName = deviceName;
        this.deviceModel = deviceModel;
        this.deviceCode = deviceCode;
        this.manufacturer = manufacturer;
        this.applyDate = applyDate;
        this.orgName = orgName;
        this.linkman = linkman;
        this.tel = tel;
        this.serverIp = serverIp;
        this.manufacturerCode = manufacturerCode;
        this.address = address;
        this.representative = representative;
        this.applicantName = applicantName;
        this.applicantIdentity = applicantIdentity;
        this.applicantTel = applicantTel;
        this.applicantMail = applicantMail;
    }
    @Column(name = "device_name")
    public String getDeviceName() {
        return deviceName;
    }
    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }
    @Column(name = "device_model")
    public String getDeviceModel() {
        return deviceModel;
    }
    public void setDeviceModel(String deviceModel) {
        this.deviceModel = deviceModel;
    }
    @Column(name = "device_code")
    public String getDeviceCode() {
        return deviceCode;
    }
    public void setDeviceCode(String deviceCode) {
        this.deviceCode = deviceCode;
    }
    @Column(name = "manufacturer")
    public String getManufacturer() {
        return manufacturer;
    }
    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }
    @Column(name = "apply_date")
    public String getApplyDate() {
        return applyDate;
    }
    public void setApplyDate(String applyDate) {
        this.applyDate = applyDate;
    }
    @Column(name = "org_name")
    public String getOrgName() {
        return orgName;
    }
    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }
    @Column(name = "linkman")
    public String getLinkman() {
        return linkman;
    }
    public void setLinkman(String linkman) {
        this.linkman = linkman;
    }
    @Column(name = "tel")
    public String getTel() {
        return tel;
    }
    public void setTel(String tel) {
        this.tel = tel;
    }
    @Column(name = "server_ip")
    public String getServerIp() {
        return serverIp;
    }
    public void setServerIp(String serverIp) {
        this.serverIp = serverIp;
    }
    @Column(name = "manufacturerCode")
    public String getManufacturerCode() {
        return manufacturerCode;
    }
    public void setManufacturerCode(String manufacturerCode) {
        this.manufacturerCode = manufacturerCode;
    }
    @Column(name = "address")
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    @Column(name = "representative")
    public String getRepresentative() {
        return representative;
    }
    public void setRepresentative(String representative) {
        this.representative = representative;
    }
    @Column(name = "applicant_name")
    public String getApplicantName() {
        return applicantName;
    }
    public void setApplicantName(String applicantName) {
        this.applicantName = applicantName;
    }
    @Column(name = "applicant_identity")
    public String getApplicantIdentity() {
        return applicantIdentity;
    }
    public void setApplicantIdentity(String applicantIdentity) {
        this.applicantIdentity = applicantIdentity;
    }
    @Column(name = "applicant_tel")
    public String getApplicantTel() {
        return applicantTel;
    }
    public void setApplicantTel(String applicantTel) {
        this.applicantTel = applicantTel;
    }
    @Column(name = "applicant_mail")
    public String getApplicantMail() {
        return applicantMail;
    }
    public void setApplicantMail(String applicantMail) {
        this.applicantMail = applicantMail;
    }
}

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

@ -1,5 +1,6 @@
package com.yihu.es.entity;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.wlyy.entity.patient.Patient;
import io.searchbox.annotations.JestId;
@ -34,8 +35,8 @@ public class HealthEduArticleES {
    private String town; // 所属区划(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 Integer sendType;//发送类型 1医生发送 2(管理员)卫纪委发送(ES:必填)
    private String sendLevel;   // 发送人级别  1专科医生,2全科医生,3健康管理师 4 管理员(ES)
@ -69,6 +70,8 @@ public class HealthEduArticleES {
    //说明:如医生推送文章给5个居民,则保存5条userType=1的记录和1条userType=2的记录(共6条)
    //业务需求:userType=1为居民被推送文章列表;userType=2医生推送的文章列表;
    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:非必填)
    public String getId() {

+ 9 - 18
patient-co-manage/redis-cache/src/main/java/com/yihu/wlyy/task/RedisScheduledTask.java

@ -36,9 +36,6 @@ import java.util.List;
 * @date 2017/12/6 09:22
 */
@Component
//@RestController
//@RequestMapping(value = ApiVersion.Version1_0)
//@Api(description = "定时任务", tags = {"缓存服务管理--定时任务"})
public class RedisScheduledTask {
    Logger logger = LoggerFactory.getLogger(RedisScheduledTask.class);
@ -48,18 +45,14 @@ public class RedisScheduledTask {
    @Value("${ehr-redis.cache.memory.outFilePath}")
    private String outFilePath;
    // 生产环境服务器不允许代码直接通过SSH访问服务器,故暂时注释,另寻方法。
//    @Value("${ehr-redis.server.host}")
//    private String redisServerHost;
//    @Value("${ehr-redis.server.username}")
//    private String redisServerUsername;
//    @Value("${ehr-redis.server.password}")
//    private String redisServerPwd;
//    @Value("${ehr-redis.server.ssh-port}")
//    private int redisServerSshPort;
    private String redisServerHost = "";
    private String redisServerUsername = "";
    private String redisServerPwd = "";
    private int redisServerSshPort = 22;
    @Value("${ehr-redis.server.host}")
    private String redisServerHost;
    @Value("${ehr-redis.server.username}")
    private String redisServerUsername;
    @Value("${ehr-redis.server.password}")
    private String redisServerPwd;
    @Value("${ehr-redis.server.ssh-port}")
    private int redisServerSshPort;
    @Autowired
    private RedisCacheKeyMemoryService redisCacheKeyMemoryService;
@ -69,7 +62,6 @@ public class RedisScheduledTask {
    /**
     * 生成 Redis 快照
     */
//    @RequestMapping(value = "/redis/cache/statistics/backupRedis", method = RequestMethod.GET)
    @Scheduled(cron = "0 0 0 15 * ?")
    public void backupRedis() {
        redisTemplate.execute(new RedisCallback() {
@ -85,14 +77,13 @@ public class RedisScheduledTask {
    /**
     * 导出 redis 内存分析报告,并导入到数据库
     */
//    @RequestMapping(value = "/redis/cache/statistics/exportAndImportRedisMemoryData", method = RequestMethod.GET)
    @Scheduled(cron = "0 30 0 15 * ?")
    public void exportAndImportRedisMemoryData() {
        long start = System.currentTimeMillis();
        try {
            // 导出内存分析报告CSV文件(得到的内存值是近似值,比实际略小)
            // 生产环境服务器不允许代码直接通过SSH访问服务器,故暂时注释,另寻方法。
//            exportRedisMemoryReport();
            exportRedisMemoryReport();
            long export = System.currentTimeMillis();
            logger.info("成功导出Redis内存分析报告,耗时:" + (export - start) + " 毫秒");

+ 6 - 5
patient-co-manage/redis-cache/src/main/resources/application.yml

@ -43,9 +43,9 @@ spring:
      password: 123456
  redis:
    host: 172.19.103.47 # Redis server host.
    host: 172.19.103.88 # Redis server host.
    port: 6379
    password: redis!@456
    password:
fast-dfs:
  tracker-server: 172.19.103.13:22122
@ -57,13 +57,14 @@ ehr-redis:
      responseTimeChannel: redis.cache.reponse-time
  cache:
    memory:
      rdbFilePath: /usr/local/bin/dump.rdb
#      rdbFilePath: /usr/local/bin/dump.rdb
      rdbFilePath: /usr/local/redis/bin/dump.rdb
      outFilePath: /usr/local/ehr/redisReport/
      filename: memory.csv
  server:
    host: 172.19.103.47
    host: 172.19.103.88
    username: root
    password: jkzl
    password: ceshi
    ssh-port: 22
---
spring:

+ 2 - 1
patient-co-manage/redis-cache/src/main/webapp/WEB-INF/views/redis/cache/category/listJs.jsp

@ -112,10 +112,11 @@
        /*-- 与明细 Dialog 页面间回调的函数 --*/
        window.reloadMasterGrid = function() {
            reloadGrid();
        };
        window.closeDetailDialog = function (type, msg) {
            detailDialog.close();
            reloadGrid();
            msg && $.Notice.success(msg);
        };
    });

+ 2 - 2
patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/common/thread/LoadThread.java

@ -20,7 +20,7 @@ public class LoadThread implements Runnable {
    Integer morningHours = 6;
    //默认线程间隔
    Integer sleepTime = 600;
    Integer sleepTime = 180;
    @Override
    public void run() {
@ -51,7 +51,7 @@ public class LoadThread implements Runnable {
                            System.out.print(DateUtil.dateToStrLong(new Date()) + " 采集签约结束。\r\n");
                        }
                        Thread.sleep(sleepTime*1000);
                        Thread.sleep(sleepTime*1000);//间隔三分钟
                        continue;
                    }
                    else{

+ 1 - 1
patient-co-service/wlyy_sign/src/main/java/com/yihu/wlyy/sign/service/SignZYService.java

@ -580,7 +580,7 @@ public class SignZYService {
                else{
                    boolean needSave = false;
                    //社保卡号(为空填值)
                    if(!StringUtil.isEmpty(patientCardNo) && StringUtil.isEmpty(patient.getSsc()))
                    if(!StringUtil.isEmpty(patientCardNo) && ( StringUtil.isEmpty(patient.getSsc()) || !patientCardNo.equals(patient.getSsc())))
                    {
                        patient.setSsc(patientCardNo);
                        needSave = true;

+ 15 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/health/repository/DeviceDetailDao.java

@ -0,0 +1,15 @@
package com.yihu.wlyy.health.repository;
import com.yihu.device.entity.DeviceDetail;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author yeshijie on 2018/1/10.
 */
public interface DeviceDetailDao extends PagingAndSortingRepository<DeviceDetail, Long>, JpaSpecificationExecutor<DeviceDetail> {
    @Query(value = "select a.* from device.wlyy_devices a where a.device_code=?1 limit 0,1",nativeQuery = true)
    DeviceDetail findBySn(String sn);
}

+ 2 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/template/DoctorTeamGuidanceTemplateDao.java

@ -49,7 +49,7 @@ public interface DoctorTeamGuidanceTemplateDao extends PagingAndSortingRepositor
    // 根据模板文章标题模糊搜索团队指导模板
    @Query("SELECT b FROM DoctorTeamGuidanceDetail a, DoctorTeamGuidanceTemplate b WHERE a.code = b.teamTemplateCode  " +
            " AND b.del = 1 AND b.teamId = ?1 AND b.title LIKE ?2 order by b.useTimes desc  ")
    Page<DoctorTeamGuidanceTemplate> listByTile(int teamId, String owner, Pageable pageRequest);
            " AND b.del = 1 AND b.title LIKE ?1 order by b.useTimes desc  ")
    Page<DoctorTeamGuidanceTemplate> listByTile(String title, Pageable pageRequest);
}

+ 51 - 14
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceService.java

@ -1,5 +1,6 @@
package com.yihu.wlyy.service.app.device;
import com.yihu.device.entity.DeviceDetail;
import com.yihu.wlyy.entity.device.Device;
import com.yihu.wlyy.entity.device.PatientBloodSugger;
import com.yihu.wlyy.entity.device.PatientDevice;
@ -7,6 +8,7 @@ import com.yihu.wlyy.entity.device.PatientHealthTime;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.health.repository.DeviceDetailDao;
import com.yihu.wlyy.repository.deviece.DeviceDao;
import com.yihu.wlyy.repository.deviece.PatientBloodSuggerDao;
import com.yihu.wlyy.repository.deviece.PatientHealthTimeDao;
@ -57,7 +59,8 @@ public class PatientDeviceService extends BaseService {
    @Autowired
    private DoctorAdminTeamMemberDao doctorAdminTeamMemberDao;
    @Autowired
    private DeviceDetailDao deviceDetailDao;
    @Autowired
    private AdminTeamService adminTeamService;
    @Autowired
@ -76,6 +79,34 @@ public class PatientDeviceService extends BaseService {
    private String registerDevice = "DeviceGateway/DeviceApi/registerDevice";//注册设备
    /**
     * 验证sn码 先调总部接口 未注册才查询本地数据库,如果也没有才不能绑定
     * @param deviceSn
     * @return
     * @throws Exception
     */
    public Boolean checkDeviceSn(String deviceSn) throws Exception{
        Boolean flag = false;
        Map<String, String> params = new HashMap<>();
        params.put("deviceSn", deviceSn);
        //调用服务
        String response = HttpClientUtil.httpPost(url + registerDevice, HttpClientUtil.getSecretParams(params, appid, secret));
        System.out.println("注册设备=" + response);
        JSONObject json = new JSONObject(response);
        String code = json.get("Code").toString();
        //10000注册成功 10001已注册 -10000参数不通过(没传参数) -10001设备不存在 -10002设备未出库
        if ("10000".equals(code) || "10001".equals(code)) {
            flag = true;
        } else {
            DeviceDetail deviceDetail = deviceDetailDao.findBySn(deviceSn);
            if(deviceDetail != null){
                flag = true;
            }
        }
        return flag;
    }
    /**
     * 保存患者设备
     */
@ -117,20 +148,26 @@ public class PatientDeviceService extends BaseService {
            Patient patient = patientDao.findByCode(patientDevice.getUser());
            patientDevice.setUserIdcard(patient.getIdcard());
            //注册设备
            Map<String, String> params = new HashMap<>();
            params.put("deviceSn", sn);
            //调用服务
            String response = HttpClientUtil.httpPost(url + registerDevice, HttpClientUtil.getSecretParams(params, appid, secret));
            System.out.println("注册设备=" + response);
            JSONObject json = new JSONObject(response);
            String code = json.get("Code").toString();
            //10000注册成功 10001已注册 -10000参数不通过(没传参数) -10001设备不存在 -10002设备未出库
            if ("10000".equals(code) || "10001".equals(code)) {
//            //注册设备
//            Map<String, String> params = new HashMap<>();
//            params.put("deviceSn", sn);
//
//            //调用服务
//            String response = HttpClientUtil.httpPost(url + registerDevice, HttpClientUtil.getSecretParams(params, appid, secret));
//            System.out.println("注册设备=" + response);
//            JSONObject json = new JSONObject(response);
//            String code = json.get("Code").toString();
//            //10000注册成功 10001已注册 -10000参数不通过(没传参数) -10001设备不存在 -10002设备未出库
//            if ("10000".equals(code) || "10001".equals(code)) {
//                patientDeviceDao.save(patientDevice);
//            } else {
//                String message = json.get("Message").toString();
//                throw new Exception(message);
//            }
            if(checkDeviceSn(sn)){
                patientDeviceDao.save(patientDevice);
            } else {
                String message = json.get("Message").toString();
            }else {
                String message = "设备不存在";
                throw new Exception(message);
            }

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java

@ -908,7 +908,7 @@ public class PatientHealthIndexService extends BaseService {
            }
    
            obj = patientHealthIndexDao.save(obj);
    
            //判断是否有未结束的续方咨询,发送消息给对应的医生
            sendPrescriptionHealthIndexMsgresult(obj,patient);
    

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

@ -396,7 +396,7 @@ public class SignPatientLabelInfoService extends BaseService {
                    "  LEFT JOIN wlyy_patient p on p.code = t1.patient  "+
                    "  RIGHT JOIN wlyy_sign_patient_label_info t2 on t2.patient = t1.patient ";
            if(StringUtils.isNotBlank(trackFlag)&&"1".equals(trackFlag)){
                sql = sql +" JOIN wlyy_track_patient tp WHERE tp.patient_code = p.code";
                sql = sql +" JOIN wlyy_track_patient tp ON tp.patient_code = p.code";
            }
            sql = sql + " WHERE t2.label = ?";
@ -415,7 +415,7 @@ public class SignPatientLabelInfoService extends BaseService {
                sql += "  AND p.openid IS NOT NULL AND p.openid <>'' ";
            }
            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;
            }
    
            sql = sql + " order by p.standard_status DESC ,p.disease_condition DESC,t2.label DESC,t1.openid DESC ,convert(t1.name using gbk) ";

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

@ -1530,4 +1530,397 @@ public class DoctorSchemeService extends BaseService{
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    public List<Map<String,Object>> getTrackPatientIndexCountList(String doctor,Integer teamCode,String type,String startDate,String endDate,String keyword,Integer page,Integer size){
        startDate = startDate+" 00:00:00";
        endDate = endDate + " 23:59:59";
        // /血糖查询
        if("1".equals(type)){
            List<Map<String,Object>> list = jdbcTemplate.queryForList(getXTTrackPatientIndexCountListSql(doctor,teamCode,startDate,endDate,keyword, page, size));
            return list;
        }else{
            List<Map<String,Object>> list = jdbcTemplate.queryForList(getXYTrackPatientIndexCountListSql(doctor,teamCode,startDate,endDate,keyword, page, size));
            return list;
        }
    }
    public String getXTTrackPatientIndexCountListSql(String doctor,Integer teamCode,String startDate,String endDate,String keyword,Integer page,Integer size){
        String sql = "SELECT  " +
                " tt1.patient_code, " +
                " tt1.highCount, " +
                " tt2.lowCount, " +
                " tt3.stdCount, " +
                " p.`name`, " +
                " IFNULL(year( from_days( datediff( now(), p.birthday))),'未知') age, " +
                " p.photo, " +
                " p.idcard " +
                " FROM " +
                " " +
                "( " +
                " " +
                " SELECT " +
                " t1.patient_code, " +
                " t2.total + t1.total AS highCount " +
                " FROM " +
                " ( " +
                "  SELECT " +
                "   t.patient_code, " +
                "   IFNULL(pid.total, 0) AS total " +
                "  FROM " +
                "   ( " +
                "    SELECT " +
                "     tp.patient_code " +
                "    FROM " +
                "     wlyy_track_patient tp " +
                "    WHERE " +
                "     tp.del = '1' " +
                "    AND tp.doctor_code = '"+doctor+"' " +
                "    AND tp.team_code = " +teamCode+
                "   ) t " +
                "  LEFT JOIN ( " +
                "   SELECT " +
                "    i. USER, " +
                "    COUNT(1) AS total " +
                "   FROM " +
                "    device.wlyy_patient_health_index i " +
                "   WHERE " +
                "    i.del = '1' " +
                "   AND i.type = 1 " +
                "   AND i.value2 IN (2, 4, 6) " +
                "   AND i.value1 > 7.8 " +
                "   AND i.i.record_date >='"+startDate+"'" +
                "   AND i.i.record_date <='"+endDate+"'" +
                "   GROUP BY " +
                "    i. USER " +
                "  ) pid ON pid. USER = t.patient_code " +
                " ) t1  " +
                " " +
                " JOIN  " +
                " " +
                " ( " +
                " SELECT " +
                "  t.patient_code, " +
                "  IFNULL(pid.total, 0) AS total " +
                " FROM " +
                "  ( " +
                "   SELECT " +
                "    tp.patient_code " +
                "   FROM " +
                "    wlyy_track_patient tp " +
                "   WHERE " +
                "    tp.del = '1' " +
                "   AND tp.doctor_code = '"+doctor+"' " +
                "   AND tp.team_code =" +teamCode+
                "  ) t " +
                " LEFT JOIN ( " +
                "  SELECT " +
                "   i. USER, " +
                "   COUNT(1) AS total " +
                "  FROM " +
                "   device.wlyy_patient_health_index i " +
                "  WHERE " +
                "   i.del = '1' " +
                "  AND i.type = 1 " +
                "  AND i.value2 IN (1, 3, 5, 7) " +
                "  AND i.value1 > 6.1 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "  GROUP BY " +
                "   i. USER " +
                " ) pid ON pid. USER = t.patient_code " +
                ") t2 ON t1.patient_code = t2.patient_code " +
                " " +
                ") tt1  " +
                " " +
                " JOIN  " +
                " " +
                "( " +
                "  SELECT " +
                " t1.patient_code, " +
                " t1.total + t2.total AS lowCount " +
                " FROM " +
                " ( " +
                "  SELECT " +
                "   t.patient_code, " +
                "   IFNULL(pid.total, 0) AS total " +
                "  FROM " +
                "   ( " +
                "    SELECT " +
                "     tp.patient_code " +
                "    FROM " +
                "     wlyy_track_patient tp " +
                "    WHERE " +
                "     tp.del = '1' " +
                "    AND tp.doctor_code = '"+doctor+"' " +
                "    AND tp.team_code =  " +teamCode+
                "   ) t " +
                "  LEFT JOIN ( " +
                "   SELECT " +
                "    i. USER, " +
                "    COUNT(1) AS total " +
                "   FROM " +
                "    device.wlyy_patient_health_index i " +
                "   WHERE " +
                "    i.del = '1' " +
                "   AND i.type = 1 " +
                "   AND i.value2 IN (2, 4, 6) " +
                "   AND i.value1 < 4.4 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "   GROUP BY " +
                "    i. USER " +
                "  ) pid ON pid. USER = t.patient_code " +
                " ) t1  " +
                " " +
                " JOIN  " +
                " " +
                "( " +
                " SELECT " +
                "  t.patient_code, " +
                "  IFNULL(pid.total, 0) AS total " +
                " FROM " +
                "  ( " +
                "   SELECT " +
                "    tp.patient_code " +
                "   FROM " +
                "    wlyy_track_patient tp " +
                "   WHERE " +
                "    tp.del = '1' " +
                "   AND tp.doctor_code = '"+doctor+"' " +
                "   AND tp.team_code =  " +teamCode+
                "  ) t " +
                " LEFT JOIN ( " +
                "  SELECT " +
                "   i. USER, " +
                "   COUNT(1) AS total " +
                "  FROM " +
                "   device.wlyy_patient_health_index i " +
                "  WHERE " +
                "   i.del = '1' " +
                "  AND i.type = 1 " +
                "  AND i.value2 IN (1, 3, 5, 7) " +
                "  AND i.value1 < 3.9 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "  GROUP BY " +
                "   i. USER " +
                " ) pid ON pid. USER = t.patient_code " +
                ") t2 ON t1.patient_code = t2.patient_code " +
                " " +
                ") tt2 ON tt1.patient_code = tt2.patient_code  " +
                " " +
                "JOIN  " +
                " " +
                "( " +
                "   " +
                " SELECT " +
                " t1.patient_code, " +
                " t1.total + t2.total AS stdCount " +
                " FROM " +
                " ( " +
                "  SELECT " +
                "   t.patient_code, " +
                "   IFNULL(pid.total, 0) AS total " +
                "  FROM " +
                "   ( " +
                "    SELECT " +
                "     tp.patient_code " +
                "    FROM " +
                "     wlyy_track_patient tp " +
                "    WHERE " +
                "     tp.del = '1' " +
                "    AND tp.doctor_code = '"+doctor+"' " +
                "    AND tp.team_code = " +teamCode +
                "   ) t " +
                "  LEFT JOIN ( " +
                "   SELECT " +
                "    i. USER, " +
                "    COUNT(1) AS total " +
                "   FROM " +
                "    device.wlyy_patient_health_index i " +
                "   WHERE " +
                "    i.del = '1' " +
                "   AND i.type = 1 " +
                "   AND i.value2 IN (2, 4, 6) " +
                "   AND i.value1 >= 4.4 " +
                "   AND i.value1 <= 7.8 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "   GROUP BY " +
                "    i. USER " +
                "  ) pid ON pid. USER = t.patient_code " +
                " ) t1  " +
                " " +
                " JOIN  " +
                " " +
                " ( " +
                " SELECT " +
                "  t.patient_code, " +
                "  IFNULL(pid.total, 0) AS total " +
                " FROM " +
                "  ( " +
                "   SELECT " +
                "    tp.patient_code " +
                "   FROM " +
                "    wlyy_track_patient tp " +
                "   WHERE " +
                "    tp.del = '1' " +
                "   AND tp.doctor_code = '"+doctor+"' " +
                "   AND tp.team_code = " +teamCode+
                "  ) t " +
                " LEFT JOIN ( " +
                "  SELECT " +
                "   i. USER, " +
                "   COUNT(1) AS total " +
                "  FROM " +
                "   device.wlyy_patient_health_index i " +
                "  WHERE " +
                "   i.del = '1' " +
                "  AND i.type = 1 " +
                "  AND i.value2 IN (1, 3, 5, 7) " +
                "  AND i.value1 >= 3.9 " +
                "  AND i.value1 <= 6.1 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "  GROUP BY " +
                "   i. USER " +
                " ) pid ON pid. USER = t.patient_code " +
                " ) t2 ON t1.patient_code = t2.patient_code " +
                " " +
                " )tt3 ON tt1.patient_code = tt3.patient_code " +
                " " +
                " JOIN wlyy_patient p On tt1.patient_code =p.code";
        if(StringUtils.isNotBlank(keyword)){
            Patient p = patientDao.findByIdcard(keyword);
            if(p!=null){
                sql =sql + " WHERE p.idcard ='"+keyword+"'";
            }else{
                sql =sql + " WHERE p.name like '%"+keyword+"%' ";
            }
        }
        sql += " ORDER BY highCount DESC LIMIT "+(page-1)*size+","+size;
        return sql ;
    }
    public String getXYTrackPatientIndexCountListSql(String doctor,Integer teamCode,String startDate,String endDate,String keyword,Integer page,Integer size){
        String sql ="SELECT  " +
                " t1.patient_code, " +
                " t1.total AS lowCount, " +
                " t2.total AS stdCount, " +
                " t3.total AS highCount, " +
                " p.`name`, " +
                " IFNULL(year( from_days( datediff( now(), p.birthday))),'未知') age, " +
                " p.photo " +
                " FROM " +
                " " +
                " ( " +
                "  SELECT " +
                "   t.patient_code, " +
                "   IFNULL(pid.total, 0) AS total " +
                "  FROM " +
                "   ( " +
                "    SELECT " +
                "     tp.patient_code " +
                "    FROM " +
                "     wlyy_track_patient tp " +
                "    WHERE " +
                "     tp.del = '1' " +
                "   AND tp.doctor_code = '"+doctor+"' " +
                "   AND tp.team_code = " +teamCode+
                "   ) t " +
                "  LEFT JOIN ( " +
                "   SELECT " +
                "    i. USER, " +
                "    COUNT(1) AS total " +
                "   FROM " +
                "    device.wlyy_patient_health_index i " +
                "   WHERE " +
                "    i.del = '1' " +
                "   AND i.type = 2 " +
                "   AND i.value1 < 90 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "   GROUP BY " +
                "    i. USER " +
                "  ) pid ON pid. USER = t.patient_code " +
                " ) t1  " +
                " JOIN " +
                " ( " +
                "  SELECT " +
                "   t.patient_code, " +
                "   IFNULL(pid.total, 0) AS total " +
                "  FROM " +
                "   ( " +
                "    SELECT " +
                "     tp.patient_code " +
                "    FROM " +
                "     wlyy_track_patient tp " +
                "    WHERE " +
                "     tp.del = '1' " +
                "   AND tp.doctor_code = '"+doctor+"' " +
                "   AND tp.team_code = " +teamCode+
                "   ) t " +
                "  LEFT JOIN ( " +
                "   SELECT " +
                "    i. USER, " +
                "    COUNT(1) AS total " +
                "   FROM " +
                "    device.wlyy_patient_health_index i " +
                "   WHERE " +
                "    i.del = '1' " +
                "   AND i.type = 2 " +
                "   AND i.value1 >= 90 " +
                "   AND i.value1 <=139 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "   GROUP BY " +
                "    i. USER " +
                "  ) pid ON pid. USER = t.patient_code " +
                "  " +
                " ) t2 ON t1.patient_code = t2.patient_code " +
                " JOIN  " +
                " ( " +
                "  SELECT " +
                "   t.patient_code, " +
                "   IFNULL(pid.total, 0) AS total " +
                "  FROM " +
                "   ( " +
                "    SELECT " +
                "     tp.patient_code " +
                "    FROM " +
                "     wlyy_track_patient tp " +
                "    WHERE " +
                "     tp.del = '1' " +
                "   AND tp.doctor_code = '"+doctor+"' " +
                "   AND tp.team_code = " +teamCode+
                "   ) t " +
                "  LEFT JOIN ( " +
                "   SELECT " +
                "    i. USER, " +
                "    COUNT(1) AS total " +
                "   FROM " +
                "    device.wlyy_patient_health_index i " +
                "   WHERE " +
                "    i.del = '1' " +
                "   AND i.type = 2 " +
                "   AND i.value1 >139 " +
                "  AND i.i.record_date >='"+startDate+"'" +
                "  AND i.i.record_date <='"+endDate+"'" +
                "   GROUP BY " +
                "    i. USER " +
                "  ) pid ON pid. USER = t.patient_code " +
                " ) t3 ON t1.patient_code = t3.patient_code " +
                " JOIN wlyy_patient p ON t1.patient_code = p.`code`";
        if(StringUtils.isNotBlank(keyword)){
            Patient p = patientDao.findByIdcard(keyword);
            if(p!=null){
                sql =sql + " WHERE p.idcard ='"+keyword+"'";
            }else{
                sql =sql + " WHERE p.name like '%"+keyword+"%' ";
            }
        }
        sql += " ORDER BY highCount DESC LIMIT "+(page-1)*size+","+size;
        return sql;
    }
}

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

@ -1221,20 +1221,20 @@ public class JMJkEduArticleService extends BaseService {
            heapm.setSendName(one.getSendName());
            heapm.setSendCode(one.getDoctorCode());
            heapm.setCreateTime(DateUtil.dateToStrLong(one.getCreateTime()));
            heapm.setArticleId(article.getString("articleId"));
            heapm.setAttachedTitle(article.getString("articleTitle"));
            heapm.setAttachedContent(article.getString("articleContent"));
            heapm.setArticleType(article.getString("articleType"));
            heapm.setLevel1Type(article.getString("firstLevelCategoryId"));
            heapm.setLevel2Type(article.getString("secondLevelCategoryId"));
            heapm.setLevel(article.getString("articlelevel"));
            heapm.setArticleId(article.containsKey("articleId")?article.getString("articleId"):"");
            heapm.setAttachedTitle(article.containsKey("articleTitle")?article.getString("articleTitle"):"");
            heapm.setAttachedContent(article.containsKey("articleContent")?article.getString("articleContent"):"");
            heapm.setArticleType(article.containsKey("articleType")?article.getString("articleType"):"");
            heapm.setLevel1Type(article.containsKey("firstLevelCategoryId")?article.getString("firstLevelCategoryId"):"");
            heapm.setLevel2Type(article.containsKey("secondLevelCategoryId")?article.getString("secondLevelCategoryId"):"");
            heapm.setLevel(article.containsKey("articlelevel")?article.getString("articlelevel"):"");
//            heapm.setAllCount(heapm.getAllCount() + one.getPatients().size());
            heapm.setBrowseNumbere(Integer.valueOf(article.containsKey("browseNumber")?article.getString("browseNumber"):"0"));//文章浏览数
            heapm.setCommentNumber(Integer.valueOf(article.containsKey("commentNumber")?article.getString("commentNumber"):"0"));//文章评论数
            heapm.setPointNumber(Integer.valueOf(article.containsKey("pointNumber")?article.getString("pointNumber"):"0"));//文章点赞数
            heapm.setArticleCover(article.getString("articleCover"));//封面
            heapm.setComputeTime(computeTime(article.getString("insertTime")));
            heapm.setOperatorName(article.getString("operatorName"));
            heapm.setArticleCover(article.containsKey("articleCover")?article.getString("articleCover"):"");//封面
            heapm.setComputeTime(article.containsKey("insertTime")?computeTime(article.getString("insertTime")):"");
            heapm.setOperatorName(article.containsKey("operatorName")?article.getString("operatorName"):"");
            heapm.setSendType(one.getSendType());//发送类型
            heapm.setIsread(String.valueOf(one.getIsRead()));//已读未读标识,1已读,2未读
            heapm.setLeaveWords(one.getLeaveWords());//医生留言

+ 4 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorGuidanceTempService.java

@ -261,7 +261,7 @@ public class DoctorGuidanceTempService extends BaseService {
     * @return
     * @throws Exception
     */
    public List<Map<String, Object>> listByTitle(String filter,String type, Integer teamId, int pageSize, int pageNo) throws Exception {
    public List<Map<String, Object>> listByTitle(String filter,String type, int pageSize, int pageNo) throws Exception {
        PageRequest pageRequest = new PageRequest(pageNo, pageSize);
        List<Map<String, Object>> listMap = new ArrayList<>();
@ -293,14 +293,15 @@ public class DoctorGuidanceTempService extends BaseService {
                tem.put("modelName", dgt.getModelName());
                listMap.add(tem);
            }
        } else if("3".equals(type) && teamId!=null){
            Page<DoctorTeamGuidanceTemplate> temps = doctorTeamGuidanceTemplateDao.listByTile(teamId,"%"+filter+"%", pageRequest);
        } else if("3".equals(type)){
            Page<DoctorTeamGuidanceTemplate> temps = doctorTeamGuidanceTemplateDao.listByTile("%"+filter+"%", pageRequest);
            List<DoctorTeamGuidanceTemplate> list = temps.getContent();
            for (int i = 0; i < list.size(); i++) {
                DoctorTeamGuidanceTemplate dgt = list.get(i);
                Map<String, Object> tem = new HashMap<>();
                tem.put("teamId", dgt.getTeamId());
                tem.put("teamName", dgt.getTeamName());
                tem.put("code", dgt.getTeamTemplateCode());
                tem.put("owner", dgt.getCreater());
                tem.put("sendTimes", dgt.getUseTimes());

+ 95 - 10
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/iot/IotDeviceService.java

@ -1,7 +1,11 @@
package com.yihu.wlyy.service.third.iot;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.device.entity.DevicePatientHealthIndex;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.util.HttpClientUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
@ -18,13 +22,92 @@ import java.util.List;
public class IotDeviceService {
//    @Value("${}")
    private String baseUrl = "https://iot.xmtyw.cn/";
    private String grantType = "client_credentials&";
    private String clientId = "Va5yQRHlA4Fq4eR3LT0vuXV4&";
    private String baseUrl = "http://192.168.131.24:8080/svr-iot/";
    private String grantType = "client_credentials";
    private String clientId = "Va5yQRHlA4Fq4eR3LT0vuXV4";
    private String clientSecret = "0rDSjzQ20XUj5itV7WRtznPQSzr5pVw2";
    private String dataSource = "iHealth";
    private String accessToken = "test";
    private String bloodSugarUnit = "mmol/L";
    private String bloodPressureUnit = "mmHg";
    private String pulseUnit = "bpm";
    private String heightUnit = "cm";
    private String weightUnit = "kg";
    private String bmiUnit = "kg/m^2";
    private String waistUnit = "cm";
    @Autowired
    private HttpClientUtil httpClientUtil;
    private String accessToken = "";
    /**
     * 将上传数据转换成标准的json传
     * @param obj
     * @param userType
     * @return
     */
    public DevicePatientHealthIndex upload(DevicePatientHealthIndex obj,String userType,String deviceName,String deviceModel,Patient patient){
        JSONObject json = new JSONObject();
        json.put("sn",obj.getDeviceSn());
        json.put("ext_code",userType);
        json.put("device_name",deviceName);
        json.put("device_model",deviceModel);
        json.put("idcard",patient.getIdcard());
        json.put("username",patient.getName());
        json.put("usercode",patient.getCode());
        JSONArray jsonArray = new JSONArray();
        JSONObject js = new JSONObject();
        js.put("measure_time",obj.getRecordDate());
        switch (obj.getType()){
            case 1:
                //血糖
                js.put("blood_sugar",obj.getValue1());
                js.put("blood_sugar_unit",bloodSugarUnit);
                js.put("blood_sugar_result",obj.getValue2());
                break;
            case 2:
                //血压
                js.put("systolic",obj.getValue1());
                js.put("systolic_unit",bloodPressureUnit);
                js.put("diastolic",obj.getValue2());
                js.put("diastolic_unit",bloodPressureUnit);
                if(StringUtils.isNotBlank(obj.getValue3())){
                    js.put("pulse",obj.getValue3());
                    js.put("pulse_unit",pulseUnit);
                }
                break;
            case 3:
                //体重/身高/BMI
                js.put("height",obj.getValue1());
                js.put("height_unit",heightUnit);
                js.put("weight",obj.getValue2());
                js.put("weight_unit",weightUnit);
                if(StringUtils.isNotBlank(obj.getValue3())){
                    js.put("bmi",obj.getValue3());
                    js.put("bmi_unit",bmiUnit);
                }
                break;
            case 4:
                //腰围
                js.put("waist",obj.getValue1());
                js.put("waist_unit",waistUnit);
                break;
            default:
                break;
        }
        jsonArray.add(js);
        json.put("data",jsonArray);
        //上传
        String response = upload(json);
        JSONObject re = JSONObject.parseObject(response);
        String errorMsg = re.getString("errorMsg");//错误信息(请求失败才有错误消息)
        String successMsg = re.getString("successMsg");//成功信息(请求成功才有成功消息)
        if(StringUtils.isBlank(errorMsg)){
            re.getJSONObject("obj").getString("id");
        }
        return obj;
    }
    public String getAccessToken(){
@ -44,7 +127,8 @@ public class IotDeviceService {
     */
    public String registedevice(JSONObject json){
        json.put("access_token",accessToken);
        String url = baseUrl+"/registedevice";
        json.put("data_source",dataSource);
        String url = baseUrl+"/dataInput/userBind";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("json",json.toString()));
        String response = httpClientUtil.post(url, params, "UTF-8");
@ -58,11 +142,12 @@ public class IotDeviceService {
     */
    public String upload(JSONObject json){
        json.put("access_token",accessToken);
        String url = baseUrl+"/upload";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("json",json.toString()));
        String response = httpClientUtil.post(url, params, "UTF-8");
        return null;
        json.put("data_source",dataSource);
        String url = baseUrl+"/dataInput/input";
        org.json.JSONObject params = new org.json.JSONObject();
        params.put("json_data",json.toString());
        String response = httpClientUtil.postBody(url, params);
        return response;
    }
    /**

+ 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 org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.nlpcn.es4sql.domain.Select;
import org.nlpcn.es4sql.jdbc.ObjectResult;
import org.nlpcn.es4sql.jdbc.ObjectResultsExtractor;
@ -27,9 +28,7 @@ import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
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.
@ -1313,4 +1312,59 @@ public class ElasticsearchUtil {
        }
        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 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/scheme/DoctroSchemeController.java

@ -335,4 +335,15 @@ public class DoctroSchemeController extends BaseController {
        }
    }
    @RequestMapping(value="getTrackPatientIndexCountList",method = RequestMethod.GET)
    @ApiOperation("获取关注居民测量数据列表")
    public String getTrackPatientIndexCountList(Integer teamCode,String type,String startDate,String endDate,String keyword,Integer page,Integer size){
        try {
            return write(200, "查询成功", "data",doctorSchemeService.getTrackPatientIndexCountList(getUID(), teamCode, type, startDate, endDate, keyword, page, size));
        }catch (Exception e){
            error(e);
            //返回接口异常信息处理结果
            return error(-1, "查询失败");
        }
    }
}

+ 1 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/template/DoctorGuidanceTempController.java

@ -207,8 +207,6 @@ public class DoctorGuidanceTempController extends BaseController {
                        @ApiParam(value = "搜索关键字") String filter,
                        @RequestParam(required = true, defaultValue = "")
                        @ApiParam(value = "模板类型 1:系统 2:个人 3:团队摸版") String type,
                        @RequestParam(required = false)
                        @ApiParam(value = "3:团队摸版时 团队ID") Integer teamId,
                        @RequestParam(defaultValue = "10")
                        @ApiParam(value = "页展示数量") String pageSize,
                        @RequestParam(defaultValue = "1") @ApiParam(value = "当前页码") String pageNo) {
@ -217,7 +215,7 @@ public class DoctorGuidanceTempController extends BaseController {
            int pageno = Integer.parseInt(pageNo) - 1;
            List<Map<String, Object>> temps = null;
            if (StringUtils.isNotEmpty(type) && StringUtils.isNotEmpty(filter)){
                temps = guidanceTempService.listByTitle(filter,type,teamId,pagesize, pageno);
                temps = guidanceTempService.listByTitle(filter,type,pagesize, pageno);
            }else {
                return error(-1, "模板类型不能为空!");
            }

+ 19 - 15
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/device/PatientDeviceController.java

@ -123,22 +123,26 @@ public class PatientDeviceController extends BaseController {
                        throw new Exception("sn码" + newDeviceSN + "已被使用!");
                    }
                    //注册设备
                    Map<String, String> params = new HashMap<>();
                    params.put("deviceSn", newDeviceSN);
                    //调用服务
                    String response = HttpClientUtil.httpPost(url + registerDevice, HttpClientUtil.getSecretParams(params, appid, secret));
                    System.out.println("注册设备=" + response);
                    JSONObject json = new JSONObject(response);
                    String code = json.get("Code").toString();
                    //10000注册成功 10001已注册 -10000参数不通过(没传参数) -10001设备不存在 -10002设备未出库
                    if ("10000".equals(code) || "10001".equals(code)) {
                    } else {
                        String message = json.get("Message").toString();
                        return error(-1,message);
                    if(!patientDeviceService.checkDeviceSn(newDeviceSN)){
                        return error(-1,"设备不存在");
                    }
//                    //注册设备
//                    Map<String, String> params = new HashMap<>();
//                    params.put("deviceSn", newDeviceSN);
//
//                    //调用服务
//                    String response = HttpClientUtil.httpPost(url + registerDevice, HttpClientUtil.getSecretParams(params, appid, secret));
//                    System.out.println("注册设备=" + response);
//                    JSONObject json = new JSONObject(response);
//                    String code = json.get("Code").toString();
//                    //10000注册成功 10001已注册 -10000参数不通过(没传参数) -10001设备不存在 -10002设备未出库
//                    if ("10000".equals(code) || "10001".equals(code)) {
//
//                    } else {
//                        String message = json.get("Message").toString();
//                        return error(-1,message);
//                    }
                }
                if ("1".equals(categoryCode)) {
//                        先修改患者设备绑定表

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

@ -39,7 +39,7 @@ public class PatientHealthController extends BaseController {
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("患者最近的各项健康信息")
    @ApiOperation("更改接口(包括手动记录的修改和所有的删除)")
    public String modify(@RequestParam long id,
                         @RequestParam(required = false) String recordDate,
                         @RequestParam(required = false) String value1,

+ 1 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/scheme/PatientSchemeController.java

@ -104,4 +104,5 @@ public class PatientSchemeController extends BaseController {
            return error(-1, "查询失败");
        }
    }
}

+ 29 - 6
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/iot/IotDeviceController.java

@ -6,10 +6,12 @@ import com.yihu.wlyy.service.third.iot.IotDeviceService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
@ -34,7 +36,7 @@ public class IotDeviceController extends BaseController{
            js.put("device_name","血压计-康为A206G");
            js.put("device_model","血压计-康为A206G");
            js.put("idcard","350429198905194016");
            js.put("username","邹林");
            js.put("username","小李");
            js.put("manufacture_code","");
            js.put("manufacture_name","");
            js.put("owner_org_code","");
@ -55,6 +57,20 @@ public class IotDeviceController extends BaseController{
        }
    }
    @RequestMapping(value = "/upload",method = RequestMethod.POST)
    @ApiOperation("体征数据上传")
    public String upload(@ApiParam(name = "jsonStr",value = "jsonStr",defaultValue = "")
                         @RequestParam(value = "jsonStr",required = true) String jsonStr){
        try {
            JSONObject json = JSONObject.parseObject(jsonStr);
            String re = iotDeviceService.upload(json);
            return write(200, "体征数据上传成功!", "data", re);
        }catch (Exception e){
            error(e);
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "/upload1",method = RequestMethod.POST)
    @ApiOperation("不含居民身份的数据上传协议")
    public String upload1(){
@ -64,8 +80,13 @@ public class IotDeviceController extends BaseController{
            js.put("measure_time","2018-01-01 01:01:01");
            js.put("systolic","111");
            js.put("systolic_unit","mmHg");
            js.put("diastolic","60");
            js.put("diastolic_unit","mmHg");
            js.put("pulse","66");
            js.put("pulse_unit","bpm");
            js.put("del","1");
            js.put("status","0");
            JSONArray jsonArray = new JSONArray();
            jsonArray.add(js);
@ -77,7 +98,7 @@ public class IotDeviceController extends BaseController{
            String re = iotDeviceService.upload(json);
            return write(200, "注册设备成功!", "data", re);
            return write(200, "上传成功!", "data", re);
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
@ -85,25 +106,27 @@ public class IotDeviceController extends BaseController{
    }
    @RequestMapping(value = "/upload2",method = RequestMethod.POST)
    @ApiOperation("不含居民身份的数据上传协议")
    @ApiOperation("含居民身份的数据上传协议")
    public String upload2(){
        try {
            JSONObject json = new JSONObject();
            JSONObject js = new JSONObject();
            js.put("measure_time","2018-01-01 11:01:01");
            js.put("blood_sugar","6.7");
            js.put("blood_sugar_unit","mmol/L");
            js.put("del","1");
            js.put("status","0");
            JSONArray jsonArray = new JSONArray();
            jsonArray.add(js);
            json.put("data",jsonArray);
            json.put("data",jsonArray);
            json.put("sn","2638234828");
            json.put("ext_code","1");
            json.put("device_name","血压计-康为A206G");
            json.put("device_model","血压计-康为A206G");
            json.put("idcard","350429198905194016");
            json.put("username","邹林");
            json.put("username","小李");
            String re = iotDeviceService.upload(json);
            return write(200, "注册设备成功!", "data", re);
            return write(200, "上传成功!", "data", re);
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());

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

@ -114,9 +114,9 @@ public class EduArticleService {
        List<NewCategoryModel> secondList = jkeduCategoryDao.findCategory(2);
        String firstId = "";
        String firstName = "健康文章";
        if (firstList!=null && firstList.size()>0){
            for (NewCategoryModel newCategoryModel : firstList){
                if (newCategoryModel.getCategoryName().contains(firstName)){
        if (firstList != null && firstList.size() > 0) {
            for (NewCategoryModel newCategoryModel : firstList) {
                if (newCategoryModel.getCategoryName().contains(firstName)) {
                    firstId = newCategoryModel.getCategoryId();
                }
            }
@ -161,9 +161,9 @@ public class EduArticleService {
                            newArticleModel.setRoleType(2);
                            newArticleModel.setUserScope(1);
                            newArticleModel.setIsOld(1);
                            if (secondList!=null && secondList.size()>0){
                                for (NewCategoryModel newCategoryModel : secondList){
                                    if (newCategoryModel.getCategoryName().equals(newArticleModel.getKeyWord())){
                            if (secondList != null && secondList.size() > 0) {
                                for (NewCategoryModel newCategoryModel : secondList) {
                                    if (newCategoryModel.getCategoryName().equals(newArticleModel.getKeyWord())) {
                                        newArticleModel.setSecondLevelCategoryId(newCategoryModel.getCategoryId());
                                        newArticleModel.setSecondLevelCategoryName(newCategoryModel.getCategoryName());
                                    }
@ -369,13 +369,13 @@ public class EduArticleService {
            //5.查询出根据batch_no聚合后的每个批次号的数量
            String batchNoCountSql = "SELECT batch_no,COUNT(*) batchCount FROM wlyy_health_edu_article_patient_copy where admin_team_code IS NOT NULL AND  batch_no IS NOT NULL GROUP BY batch_no ";
            List<Map<String,Object>> batchNoCountMapList = jdbcTemplate.queryForList(batchNoCountSql);
            List<Map<String, Object>> batchNoCountMapList = jdbcTemplate.queryForList(batchNoCountSql);
            //6.清洗数据
            flag = CleanDateToEs(doctorMap,articleMap,wjwCode,firstId,firstName,secondList,batchNoCountMapList);
            flag = CleanDateToEs(doctorMap, articleMap, wjwCode, firstId, firstName, secondList, batchNoCountMapList);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
        }
@ -384,6 +384,7 @@ public class EduArticleService {
    /**
     * 清洗数据到es
     *
     * @param doctorMap
     * @param articleMap
     * @param wjwCode
@ -394,7 +395,7 @@ public class EduArticleService {
     * @return
     * @throws Exception
     */
    public boolean CleanDateToEs(Map<String,Doctor> doctorMap,Map<String,HealthEduArticle> articleMap,String wjwCode,String firstId,String firstName,List<NewCategoryModel> secondList,List<Map<String,Object>> batchNoCountMapList)throws Exception{
    public boolean CleanDateToEs(Map<String, Doctor> doctorMap, Map<String, HealthEduArticle> articleMap, String wjwCode, String firstId, String firstName, List<NewCategoryModel> secondList, List<Map<String, Object>> batchNoCountMapList) throws Exception {
        boolean flag = true;
        //1.查询es最新的时间记录
        String timeSql = "select createTime from " + esType + " order by createTime desc limit 0,1";
@ -447,7 +448,7 @@ public class EduArticleService {
                        HealthEduArticleES healthEduArticleES = new HealthEduArticleES();
                        //Map转对象
                        healthEduArticleES = MapListUtils.convertMap2Bean(map, HealthEduArticleES.class);
                        healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 1,firstId,firstName,secondList,batchNoCountMapList);
                        healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 1, firstId, firstName, secondList, batchNoCountMapList);
                        if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
                            healthEduArticleES.setDoctorCode(wjwCode);
                            //卫计委发送
@ -468,7 +469,7 @@ public class EduArticleService {
        List<Map<String, Object>> batchNoMap = jdbcTemplate.queryForList(batSql);
        List<String> batchNoList = new ArrayList<>();
        if (batchNoMap != null && batchNoMap.size() > 0) {
            for (Map<String,Object> map : batchNoMap){
            for (Map<String, Object> map : batchNoMap) {
                batchNoList.add(String.valueOf(map.get("batch_no")));
            }
            deleteData(2, batchNoList);
@ -500,7 +501,7 @@ public class EduArticleService {
                healthEduArticleES.setNewArricleFlag(false);
                //Map转对象
                healthEduArticleES = MapListUtils.convertMap2Bean(map, HealthEduArticleES.class);
                healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 2,firstId,firstName,secondList,batchNoCountMapList);
                healthEduArticleES = setDateToObj(healthEduArticleES, doctorMap, articleMap, wjwCode, 2, firstId, firstName, secondList, batchNoCountMapList);
                if (StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
                    healthEduArticleES.setDoctorCode(wjwCode);
                    //卫计委发送
@ -518,6 +519,7 @@ public class EduArticleService {
    /**
     * 封装Es存储对象
     *
     * @param healthEduArticleES
     * @param doctorMap
     * @param articleMap
@ -532,8 +534,8 @@ public class EduArticleService {
     */
    public HealthEduArticleES setDateToObj(HealthEduArticleES healthEduArticleES, Map<String, Doctor> doctorMap,
                                           Map<String, HealthEduArticle> articleMap, String wjwCode,
                                           Integer userType,String firstId,String firstName,
                                           List<NewCategoryModel> secondList,List<Map<String,Object>> batchNoCountMapList) throws Exception {
                                           Integer userType, String firstId, String firstName,
                                           List<NewCategoryModel> secondList, List<Map<String, Object>> batchNoCountMapList) throws Exception {
        //遍历医生
        Set<Map.Entry<String, Doctor>> doctorSet = doctorMap.entrySet();
        for (Map.Entry<String, Doctor> doctorEntry : doctorSet) {
@ -560,16 +562,16 @@ public class EduArticleService {
                HealthEduArticle healthEduArticle = articleEntry.getValue();
                healthEduArticleES.setArticleId(healthEduArticle.getCode());
                healthEduArticleES.setArticleTitle(healthEduArticle.getTitle());
                if (healthEduArticle.getContent().length()>=100){
                    healthEduArticleES.setArticleContent(healthEduArticle.getContent().substring(0,100));
                }else {
                if (healthEduArticle.getContent().length() >= 100) {
                    healthEduArticleES.setArticleContent(healthEduArticle.getContent().substring(0, 100));
                } else {
                    healthEduArticleES.setArticleContent(healthEduArticle.getContent());
                }
                healthEduArticleES.setFirstLevelCategoryId(firstId);
                healthEduArticleES.setFirstLevelCategoryName(firstName);
                if (secondList!=null && secondList.size()>0){
                    for (NewCategoryModel newCategoryModel : secondList){
                        if (newCategoryModel.getCategoryName().equals(healthEduArticle.getKeyword())){
                if (secondList != null && secondList.size() > 0) {
                    for (NewCategoryModel newCategoryModel : secondList) {
                        if (newCategoryModel.getCategoryName().equals(healthEduArticle.getKeyword())) {
                            healthEduArticleES.setSecondLevelCategoryId(newCategoryModel.getCategoryId());
                            healthEduArticleES.setSecondLevelCategoryName(newCategoryModel.getCategoryName());
                        }
@ -579,25 +581,25 @@ public class EduArticleService {
            }
        }
        //替换已读数据code
        if (userType==1){
        if (userType == 1) {
            //数据库中的isRead 0已读,1未读--->Es中isRead 0未读 1已读
            if (healthEduArticleES.getIsRead()==0){
            if (healthEduArticleES.getIsRead() == 0) {
                healthEduArticleES.setIsRead(1);
            }else{
            } else {
                healthEduArticleES.setCzrq(null);
                healthEduArticleES.setIsRead(0);
            }
        }
        //算出allCount
        if (batchNoCountMapList!=null && batchNoCountMapList.size()>0){
            for (Map<String,Object> map : batchNoCountMapList){
                if (healthEduArticleES.getBatchNo().equals(String.valueOf(map.get("batch_no")))){
        if (batchNoCountMapList != null && batchNoCountMapList.size() > 0) {
            for (Map<String, Object> map : batchNoCountMapList) {
                if (healthEduArticleES.getBatchNo().equals(String.valueOf(map.get("batch_no")))) {
                    healthEduArticleES.setAllCount(Integer.valueOf(String.valueOf(map.get("batchCount"))));
                }
            }
        }
        //如果是医生推送
        if (!StringUtils.isEmpty(healthEduArticleES.getDoctorName())){
        if (!StringUtils.isEmpty(healthEduArticleES.getDoctorName())) {
            //List<DoctorRole> roleList = doctorRoleDao.findUserRole(healthEduArticleES.getDoctorCode());
            int resultLevel = 4;
            /*if (roleList != null && roleList.size() > 0) {
@ -609,7 +611,7 @@ public class EduArticleService {
            }*/
            healthEduArticleES.setCurrentUserRoleCode(healthEduArticleES.getHospital());
            healthEduArticleES.setCurrentUserRoleLevel(String.valueOf(resultLevel));
        }else{
        } else {
            healthEduArticleES.setCurrentUserRoleCode(wjwCode);
            healthEduArticleES.setCurrentUserRoleLevel("2");
        }
@ -917,27 +919,23 @@ public class EduArticleService {
        JestClient jestClient = null;
        try {
            jestClient = elasticFactory.getJestClient();
            Integer i=0;
            //先根据条件查找出来
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(
                    new BoolQueryBuilder()
                            .must(QueryBuilders.matchQuery("quotaCode", doctorCode))
            ).size(500000);//一次取10000条
            Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(esIndex).addType(esType)
                    .build();
            SearchResult result = jestClient.execute(search);
            List<HealthEduArticleES> healthEduArticleESs = result.getSourceAsObjectList(HealthEduArticleES.class);
            //根据id批量删除
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            for (HealthEduArticleES obj : healthEduArticleESs) {
                Delete index = new Delete.Builder(obj.getId()).build();
                bulk.addAction(index);
            String sql = "select id from " + esIndex + " where doctorCode='" + doctorCode + "'";
            List<Map<String, Object>> returnList = elasticsearchUtil.excuteDataModel(sql);
            //根据id批量删除
            for (Map<String, Object> obj : returnList) {
                if (obj.containsKey("id")) {
                    i++;
                    Delete index = new Delete.Builder(obj.get("id").toString()).build();
                    bulk.addAction(index);
                }
            }
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("delete data count:" + healthEduArticleESs.size());
            logger.info("delete data count:" + i);
            logger.info("delete flag:" + br.isSucceeded());
        } catch (Exception e) {
            e.printStackTrace();
@ -999,7 +997,7 @@ public class EduArticleService {
        //3.转换成新的健康教育需要的数据
        List<HealthEduArticleES> healthEduArticleESSaveList = new ArrayList<>();
        //获取医生的角色
        Map<String,Object> roleMaps=  gcLabelService.fetchUserHighestAuthority(doctorCode);
        Map<String, Object> roleMaps = gcLabelService.fetchUserHighestAuthority(doctorCode);
        healthEduArticlePatientMap.keySet().stream().forEach(one -> {
            //获取患者数据
@ -1036,41 +1034,20 @@ public class EduArticleService {
                HealthEduArticle healthEduArticle = articleMap.get(healthEduArticlePatient.getArticle());
                healthEduArticleES.setArticleId(healthEduArticle.getCode());
                if (healthEduArticle.getContent().length()>=100){
                    healthEduArticleES.setArticleContent(healthEduArticle.getContent().substring(0,100));
                }else{
                    healthEduArticleES.setArticleContent(healthEduArticle.getContent());
                }
                healthEduArticleES.setArticleContent(healthEduArticle.getContent());
                healthEduArticleES.setArticleTitle(healthEduArticle.getTitle());
                healthEduArticleES.setIsRead(healthEduArticlePatient.getRead());
                healthEduArticleES.setOperatorId(doctorCode); //之前旧数据没有文章作者 默认是发送人
                healthEduArticleES.setArticleCover(healthEduArticle.getUrl());
                healthEduArticleES.setOperatorId(wjwCode); //之前旧数据没有文章作者 默认是卫计委
                healthEduArticleES.setArticleSource("厦门市卫生与计划生育委员会");//文章来源 旧数据默认是卫计委
                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());
                        }
                    }
                }
                //替换已读数据code
                //数据库中的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.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());
                if (adminTeam!=null){
                    healthEduArticleES.setAdminTeamCode(adminTeam.getId());
                    healthEduArticleES.setAdminTeamName(adminTeam.getName());
                }
                healthEduArticleES.setAllCount(healthEduArticlePatientTemps.size());
                healthEduArticleES.setCreateTime(new Date());
                healthEduArticleES.setUserType(1);//患者
@ -1145,10 +1122,11 @@ public class EduArticleService {
    /**
     * 删除Es里所有的旧数据
     *
     * @return
     * @throws Exception
     */
    public Map<String, Object> deleteEsOldArticlePatient () throws Exception {
    public Map<String, Object> deleteEsOldArticlePatient() throws Exception {
        Map<String, Object> returnMap = new HashedMap();
        int resultSize = 0;
@ -1191,42 +1169,27 @@ public class EduArticleService {
        JestClient jestClient = null;
        //List<HealthEduArticleES> saveModels = new ArrayList<>();
        try {
            int i = 0;
            jestClient = elasticFactory.getJestClient();
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.fetchSource("id","createTime").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);
            System.out.println("result----"+result.getErrorMessage());
            System.out.println("resultString:"+result.getSourceAsString());
            List<SearchResult.Hit<HealthEduArticleES,Void>> hitList = result.getHits(HealthEduArticleES.class);
            List<HealthEduArticleES> healthEduArticleESs = result.getSourceAsObjectList(HealthEduArticleES.class);
            System.out.println("Es old date count:"+healthEduArticleESs.size());
            /*if (healthEduArticleESs != null && healthEduArticleESs.size() > 0) {
                for (HealthEduArticleES healthEduArticleES : healthEduArticleESs) {
                    saveModels.add(healthEduArticleES);
                }
            }*/
            //根据id批量删除
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(esIndex).defaultType(esType);
            /*for (HealthEduArticleES obj : healthEduArticleESs) {
                if (obj != null) {
                    Delete index = new Delete.Builder(obj.getId()).build();
                    bulk.addAction(index);
                }
            }*/
            for (SearchResult.Hit<HealthEduArticleES,Void> hit : hitList) {
                if (hit != null) {
                    Delete index = new Delete.Builder(hit.id).build();
                    bulk.addAction(index);
            for (String batchNo : list) {
                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.error("delete es old data:"+br.getErrorMessage()+"-----JsonString:"+br.getJsonString());
            logger.info("delete data count:" + healthEduArticleESs.size());
            logger.info("delete data count:" + i);
            logger.info("delete flag:" + br.isSucceeded());
            return healthEduArticleESs.size();
            return i;
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
@ -1237,9 +1200,9 @@ public class EduArticleService {
        }
    }
    public Map<String ,Object> addBatchNo(String doctorCode){
        Map<String,Object> resultMap = new HashedMap();
        String sql ="SELECT " +
    public Map<String, Object> addBatchNo(String doctorCode) {
        Map<String, Object> resultMap = new HashedMap();
        String sql = "SELECT " +
                "  id, " +
                "  patient, " +
                "  article, " +
@ -1253,40 +1216,40 @@ public class EduArticleService {
                "  WHERE " +
                "  admin_team_code IS NOT NULL " +
                "  AND batch_no IS NULL " +
                "  AND doctor = '"+doctorCode+"' ORDER BY czrq ASC";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String,String>> sqlList = new ArrayList<>();
        if (list!=null && list.size()>0){
                "  AND doctor = '" + doctorCode + "' ORDER BY czrq ASC";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String, String>> sqlList = new ArrayList<>();
        if (list != null && list.size() > 0) {
            String oldArticleId = "";
            String oldTime = "";
            for (Map<String,Object> map : list){
                if (!(map.get("article")+"").equals(oldArticleId) || !(map.get("czrq")+"").equals(oldTime)){
                    oldArticleId = map.get("article")+"";
                    oldTime = map.get("czrq")+"";
                    Map<String,String> sqlMap = new HashedMap();
                    sqlMap.put("id",oldArticleId);
            for (Map<String, Object> map : list) {
                if (!(map.get("article") + "").equals(oldArticleId) || !(map.get("czrq") + "").equals(oldTime)) {
                    oldArticleId = map.get("article") + "";
                    oldTime = map.get("czrq") + "";
                    Map<String, String> sqlMap = new HashedMap();
                    sqlMap.put("id", oldArticleId);
                    sqlList.add(sqlMap);
                }
            }
        }
        int a = 0;
        if (sqlList!=null && sqlList.size()>0){
            for (Map<String,String> map : sqlList){
        if (sqlList != null && sqlList.size() > 0) {
            for (Map<String, String> map : sqlList) {
                String batchNo = String.valueOf(UUID.randomUUID());
                batchNo = batchNo.replace("-","");
                String id = map.get("id")+"";
                String updateSql ="UPDATE wlyy_health_edu_article_patient " +
                        " SET batch_no = '"+batchNo+"' " +
                batchNo = batchNo.replace("-", "");
                String id = map.get("id") + "";
                String updateSql = "UPDATE wlyy_health_edu_article_patient " +
                        " SET batch_no = '" + batchNo + "' " +
                        " WHERE " +
                        " admin_team_code IS NOT NULL " +
                        " AND batch_no IS NULL " +
                        " AND article = '"+id+"' " +
                        " AND doctor = '"+doctorCode+"'";
                a +=jdbcTemplate.update(updateSql);
                        " AND article = '" + id + "' " +
                        " AND doctor = '" + doctorCode + "'";
                a += jdbcTemplate.update(updateSql);
            }
        }
        resultMap.put("count",a);
        resultMap.put("count", a);
        return resultMap;
    }
}

+ 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图片地址
patient_wifi_pic_url = {server}/images/wifi.png
#居民wifi链接
patient_wifi_url = https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&amp;redirect_uri={server}%2fwx%2fhtml%2fintroduction%2fhtml%2fyygh.html&amp;response_type=code&amp;scope=snsapi_base&amp;state=code#wechat_redirect
patient_wifi_url = https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&amp;redirect_uri=http://www.baidu.com
#就诊记录
patient_visit_pic ={server}/images/visit.png
#检查检验