Browse Source

平板端,

liubing 3 years ago
parent
commit
f9f4b6994d
20 changed files with 1603 additions and 19 deletions
  1. 9 0
      business/im-service/src/main/java/com/yihu/jw/im/util/ImUtil.java
  2. 49 0
      common/common-entity/sql记录
  3. 255 0
      common/common-entity/src/main/java/com/yihu/jw/entity/care/birthday/BirthDayWishesToPatient.java
  4. 112 0
      common/common-entity/src/main/java/com/yihu/jw/entity/care/birthday/BirthdayWishesTemplate.java
  5. 2 0
      common/common-entity/src/main/java/com/yihu/jw/entity/hospital/message/SystemMessageDO.java
  6. 154 0
      common/common-util/src/main/java/com/yihu/jw/util/healthIndex/HealthIndexUtil.java
  7. 12 0
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/birthday/BirthDayWishesToPatientDao.java
  8. 29 0
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/birthday/BirthdayWishesTemplateDao.java
  9. 271 0
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/doctor/DoctorBirthdayWishesEndpoint.java
  10. 17 1
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/message/PatientMessageEndpoint.java
  11. 12 0
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/patient/PatientContactsEndpoint.java
  12. 1 1
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/sign/SignEndpoint.java
  13. 465 0
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/birthday/BirthdayWishesService.java
  14. 20 0
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/contacts/ContactsService.java
  15. 1 1
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/label/PatientLableService.java
  16. 19 4
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/message/PatientMessageService.java
  17. 8 3
      svr/svr-cloud-care/src/main/java/com/yihu/jw/care/util/MessageUtil.java
  18. 1 1
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/DeviceController.java
  19. 95 7
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/DeviceService.java
  20. 71 1
      svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/DeviceUploadService.java

+ 9 - 0
business/im-service/src/main/java/com/yihu/jw/im/util/ImUtil.java

@ -90,6 +90,15 @@ public class ImUtil {
		return response;
	}
	public String sendPatientSystemMessage(String targetUserId, String message) {
		String imAddr = im_host + "api/v2/message/patientSystemMessage";
		JSONObject params = new JSONObject();
		params.put("targetUserId", targetUserId);
		params.put("message", message);
		String response = HttpClientUtil.postBody(imAddr,params);
		return response;
	}
	/**
	 * 发送消息
	 * @param senderId 发送者的code

+ 49 - 0
common/common-entity/sql记录

@ -1094,6 +1094,55 @@ ALTER table base.dm_device add column need_register tinyint(2) DEFAULT '0' COMME
ALTER TABLE wlyy_patient_rehabilitation_plan add COLUMN  `admin_team_code` int(11) DEFAULT NULL COMMENT '家签行政团队Id';
-- 2021-07-12 lb
ALTER table base.dm_device modify column need_register varchar(255) DEFAULT NULL COMMENT '注册至iot接口,为空表示不注册'
-- 2021-07-16 lb
CREATE TABLE `wlyy_birthday_wishes_template` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(50) DEFAULT NULL,
  `type` int(2) DEFAULT NULL COMMENT '类型(1系统模板、2服务人员创建)',
  `applicable_range` int(2) DEFAULT NULL COMMENT '适用范围(1未成年、2成年、3老年人)',
  `content` text COMMENT '祝福语',
  `del` int(2) DEFAULT NULL COMMENT '是否删除(0是、1否)',
  `create_user` varchar(50) DEFAULT NULL COMMENT '创建人(系统模板为null)',
  `create_user_name` varchar(50) DEFAULT NULL COMMENT '创建人名称',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `is_default` int(2) DEFAULT '0' COMMENT '是否为默认模板(1是 0否)',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=4474 DEFAULT CHARSET=utf8mb4 COMMENT='生日祝福模板';
CREATE TABLE `birthday_wishes_to_patient` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `batch_no` varchar(50) DEFAULT NULL comment '批次号记录发送所属批次',
  `patient_code` varchar(50) DEFAULT NULL comment '患者标识',
  `patient_name` varchar(50) DEFAULT NULL comment '患者名称',
  `doctor_code` varchar(50) DEFAULT NULL comment '发送人code',
  `doctor_name` varchar(50) DEFAULT NULL comment '发送人名称',
  `user_type` int(2) DEFAULT NULL comment '1、患者,2医生',
  `send_pic` varchar(100) DEFAULT NULL comment '发送人头像',
  `send_sex` varchar(50) DEFAULT NULL comment '发送人性别',
  `admin_team_code` int(50) DEFAULT NULL comment '医生所在',
  `admin_team_name` varchar(50) DEFAULT NULL comment '行政团队名称',
  `hospital` varchar(50) DEFAULT NULL comment '所属机构',
  `hospital_name` varchar(50) DEFAULT NULL comment '所属机构名称',
  `town` varchar(50) DEFAULT NULL comment '所属区划',
  `town_name` varchar(50) DEFAULT NULL comment '所属区划名称',
  `send_type` int(3) DEFAULT NULL comment '发送类型 1医生发送 2管理员',
  `send_level` int(3) DEFAULT NULL comment '发送人级别 1社区医生,2助老员, 3教师 4管理员',
  `current_user_role_code` varchar(255) DEFAULT NULL comment '当前登录角色code ',
  `current_user_role_level` varchar(255) DEFAULT NULL comment 		'当前登录的角色级别,1、省,2、市,3、区,4、机构',
  `send_source` int(11) DEFAULT NULL comment '发送平台',
  `all_count` int(11) DEFAULT NULL comment '批次发送排序',
  `openid_set` text comment '本次批号推送openid集合',
  `birthday` varchar(10) DEFAULT NULL comment '居民生日 MM-dd',
  `template_id` int(15) DEFAULT NULL comment '生日模板id',
  `content` text comment '生日祝福内容',
  `create_time` varchar(20) DEFAULT NULL comment '创建时间',
  PRIMARY KEY (`id`),
	KEY index_pd(patient_code,doctor_code) USING BTREE,
	KEY index_time(create_time) USING BTREE,
	KEY index_birthday(birthday)USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COMMENT='生日祝福发送记录';
ALTER table base.dm_device modify column need_register varchar(255) DEFAULT NULL COMMENT '注册至iot接口,为空表示不注册';

+ 255 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/birthday/BirthDayWishesToPatient.java

@ -0,0 +1,255 @@
package com.yihu.jw.entity.care.birthday;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * 生日祝福推送记录表
 * Created by humingfen on 2018/10/24.
 */
@Entity
@Table(name = "birthday_wishes_to_patient")
public class BirthDayWishesToPatient extends IdEntity {
    //说明:如医生推送生日祝福给5个居民,则保存5条userType=1的记录和1条userType=2的记录(共6条)batchNo批次号一样。
    private String batchNo;//批次号记录发送所属批次(ES:必填)
    private String patientCode; // 患者标识(ES)(根据userType的值,userType=1,必填;userType=2,为空)
    private String patientName; // 患者名称(ES)(根据userType的值,userType=1,必填;userType=2,为空)
    private String doctorCode;  //发送人code(doctor表中的code)(ES:必填)
    private String doctorName;  //发送人名称(doctor表中的name)(ES:必填)
    private Integer userType; // 1、患者,2医生(ES:必填)
    //备注:从发送人的信息中获取(doctor表获取)
    private String sendPic;   // 发送人头像(ES)
    private String sendSex;   // 发送人性别(ES)
    private Long adminTeamCode;// 行政团队(ES)
    private String adminTeamName;// 行政团队(ES)
    private String hospital; // 所属机构(ES)
    private String hospitalName; // 所属机构(ES)
    private String town; // 所属区划(ES)
    private String townName; // 所属区划(ES)
    private Integer sendType;//发送类型 1医生发送 2(管理员)卫纪委发送(ES:必填)
    private Integer sendLevel;   // 发送人级别  1专科医生,2全科医生,3健康管理师 4 管理员(ES)
    //说明:如普通医生推送则保存doctor表中的hospital字段,如管理员推送则保存当前角色的code(取wlyy_user_role表中的role字段)
    private String currentUserRoleCode;//发送者当前登录的角色code(ES:必填)
    private String currentUserRoleLevel;//发送者当前登录的角色级别,1、省,2、市,3、区,4、机构(ES:必填)
    private Integer sendSource; //1或者为空 i健康后台推送  2PC端推送(默认旧数据为1)(为后续平台推送统计做备用字段)
    private Integer allCount;//所有的推送数目(ES:必填)
    private String openidSet;//本次发送生日祝福的openid的总集合
    //生日祝福
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM-dd")
    private String birthday;  // 居民生日(ES:必填)
    private Long templateId; //生日模板id
    private String content; //生日祝福内容 (ES:必填)
    private String createTime;  // 创建时间(ES:必填)
    public String getBatchNo() {
        return batchNo;
    }
    public void setBatchNo(String batchNo) {
        this.batchNo = batchNo;
    }
    public String getPatientCode() {
        return patientCode;
    }
    public void setPatientCode(String patientCode) {
        this.patientCode = patientCode;
    }
    public String getPatientName() {
        return patientName;
    }
    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }
    public String getDoctorCode() {
        return doctorCode;
    }
    public void setDoctorCode(String doctorCode) {
        this.doctorCode = doctorCode;
    }
    public String getDoctorName() {
        return doctorName;
    }
    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }
    public Integer getUserType() {
        return userType;
    }
    public void setUserType(Integer userType) {
        this.userType = userType;
    }
    public String getSendPic() {
        return sendPic;
    }
    public void setSendPic(String sendPic) {
        this.sendPic = sendPic;
    }
    public String getSendSex() {
        return sendSex;
    }
    public void setSendSex(String sendSex) {
        this.sendSex = sendSex;
    }
    public Long getAdminTeamCode() {
        return adminTeamCode;
    }
    public void setAdminTeamCode(Long adminTeamCode) {
        this.adminTeamCode = adminTeamCode;
    }
    public String getAdminTeamName() {
        return adminTeamName;
    }
    public void setAdminTeamName(String adminTeamName) {
        this.adminTeamName = adminTeamName;
    }
    public String getHospital() {
        return hospital;
    }
    public void setHospital(String hospital) {
        this.hospital = hospital;
    }
    public String getHospitalName() {
        return hospitalName;
    }
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    public String getTown() {
        return town;
    }
    public void setTown(String town) {
        this.town = town;
    }
    public String getTownName() {
        return townName;
    }
    public void setTownName(String townName) {
        this.townName = townName;
    }
    public String getCurrentUserRoleCode() {
        return currentUserRoleCode;
    }
    public void setCurrentUserRoleCode(String currentUserRoleCode) {
        this.currentUserRoleCode = currentUserRoleCode;
    }
    public String getCurrentUserRoleLevel() {
        return currentUserRoleLevel;
    }
    public void setCurrentUserRoleLevel(String currentUserRoleLevel) {
        this.currentUserRoleLevel = currentUserRoleLevel;
    }
    public Integer getSendSource() {
        return sendSource;
    }
    public void setSendSource(Integer sendSource) {
        this.sendSource = sendSource;
    }
    public Integer getAllCount() {
        return allCount;
    }
    public void setAllCount(Integer allCount) {
        this.allCount = allCount;
    }
    public String getBirthday() {
        return birthday;
    }
    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public String getCreateTime() {
        return createTime;
    }
    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }
    public Integer getSendType() {
        return sendType;
    }
    public void setSendType(Integer sendType) {
        this.sendType = sendType;
    }
    public Integer getSendLevel() {
        return sendLevel;
    }
    public void setSendLevel(Integer sendLevel) {
        this.sendLevel = sendLevel;
    }
    public String getOpenidSet() {
        return openidSet;
    }
    public void setOpenidSet(String openidSet) {
        this.openidSet = openidSet;
    }
    public Long getTemplateId() {
        return templateId;
    }
    public void setTemplateId(Long templateId) {
        this.templateId = templateId;
    }
}

+ 112 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/birthday/BirthdayWishesTemplate.java

@ -0,0 +1,112 @@
package com.yihu.jw.entity.care.birthday;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * 生日祝福语模板
 *
 * @author humingfen
 */
@Entity
@Table(name = "wlyy_birthday_wishes_template")
public class BirthdayWishesTemplate extends IdEntity {
    private String code;//业务主键
    private Integer type;//类型(1系统模板、2服务人员创建)
    private Integer applicableRange;//适用范围(1小孩、2中年、3老年人)
    private String content;//祝福语
    private Integer del;//是否删除(0否、1是)
    private String createUser;//创建人(系统模板值为空)
    private String createUserName;//创建人姓名
    private Date createTime;//创建时间
    private Integer isDefault;//是否为默认模板(1是 0否)
    @Column(name = "code")
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    @Column(name = "type")
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    @Column(name = "applicable_range")
    public Integer getApplicableRange() {
        return applicableRange;
    }
    public void setApplicableRange(Integer applicableRange) {
        this.applicableRange = applicableRange;
    }
    @Column(name = "content")
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    @Column(name = "del")
    public Integer getDel() {
        return del;
    }
    public void setDel(Integer del) {
        this.del = del;
    }
    @Column(name = "create_user")
    public String getCreateUser() {
        return createUser;
    }
    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }
    @Column(name = "create_user_name")
    public String getCreateUserName() {
        return createUserName;
    }
    public void setCreateUserName(String createUserName) {
        this.createUserName = createUserName;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "create_time")
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Integer getIsDefault() {
        return isDefault;
    }
    public void setIsDefault(Integer isDefault) {
        this.isDefault = isDefault;
    }
}

+ 2 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/hospital/message/SystemMessageDO.java

@ -19,6 +19,8 @@ public class SystemMessageDO extends UuidIdentityEntity {
    /**
     *消息类型 上门服务400开头,生活照料500开头 ,安防监控600开头, 上门辅导700开头,紧急救助800开头
     * 人文关怀系统消息 41
     * 体征设备测量系统消息 42
     * 家属紧急预警系统消息 50
     * 新生儿在线咨询 850
     * 老人在线咨询 851

+ 154 - 0
common/common-util/src/main/java/com/yihu/jw/util/healthIndex/HealthIndexUtil.java

@ -0,0 +1,154 @@
package com.yihu.jw.util.healthIndex;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Component;
/**
 * Created by Bing on 2021/7/20.
 * 体征数据
 */
@Component
public class HealthIndexUtil {
    // 血糖餐前最小值
    public static final double HEALTH_STANDARD_ST_MIN_BEFORE = 4;
    // 血糖餐前最大值
    public static final double HEALTH_STANDARD_ST_MAX_BEFORE = 7;
    // 血糖餐后最小值
    public static final double HEALTH_STANDARD_ST_MIN_AFTER = 4;
    // 血糖餐后最大值
    public static final double HEALTH_STANDARD_ST_MAX_AFTER = 11.1;
    // 舒张压最小值
    public static final double HEALTH_STANDARD_SZY_MIN = 60;
    // 舒张压最大值
    public static final double HEALTH_STANDARD_SZY_MAX = 90;
    // 收缩压最小值
    public static final double HEALTH_STANDARD_SSY_MIN = 90;
    // 收缩压最大值
    public static final double HEALTH_STANDARD_SSY_MAX = 140;
    //最小值
    public static final double HEALTH_STANDARD_HEART_RATE_MIN = 60;
    //最大值
    public static final double HEALTH_STANDARD_HEART_RATE_MAX = 100;
    /**
     * type:1血糖2血压,3体重/身高/BMI,4腰围,5心率,6体温
     * @return
     */
    public JSONArray verifyHealthIndex(Integer type, String ...values) {
        //血糖校验
        JSONArray result = new JSONArray();
        JSONObject tmp = new JSONObject();
        if (1 ==type) {
            // 血糖记录,查询患者血糖预警值
            Double maxValueBefore = HEALTH_STANDARD_ST_MAX_BEFORE;
            Double minValueBefore = HEALTH_STANDARD_ST_MIN_BEFORE;
            Double maxValueAfter = HEALTH_STANDARD_ST_MAX_AFTER;
            Double minValueAfter = HEALTH_STANDARD_ST_MIN_AFTER;
            int index = Integer.valueOf(values[1]);
            String value1 = values[0];
            // 餐后
            if (index % 2 == 0) {
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueAfter, minValueAfter)) {
                    tmp.put("value1",value1);
                    tmp.put("indexName","血糖");
                    tmp.put("error",true);
                }else {
                    tmp.put("value1",value1);
                    tmp.put("indexName","血糖");
                    tmp.put("error",false);
                }
            } else { //餐前
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueBefore, minValueBefore)) {
                    tmp.put("value1",value1);
                    tmp.put("indexName","血糖");
                    tmp.put("error",true);
                }else {
                    tmp.put("value1",value1);
                    tmp.put("indexName","血糖");
                    tmp.put("error",false);
                }
            }
            result.add(tmp);
        }
        //血压校验
        else if (type == 2) {
            String value1 = values[0];//收缩压
            String value2 = values[1];//舒张压
            String value3 = values[2];//脉搏
            // 血压记录,查询患者血压预警值
            Double maxValueSSY = HEALTH_STANDARD_SSY_MAX;
            Double minValueSSY = HEALTH_STANDARD_SSY_MIN;
            Double maxValueSZY = HEALTH_STANDARD_SZY_MAX;
            Double minValueSZY = HEALTH_STANDARD_SZY_MIN;
            // 收缩压/舒张压校验
            if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY) ) {
                tmp.put("value1",value1);
                tmp.put("indexName","收缩压");
                tmp.put("error",true);
            }else {
                tmp.put("value1",value1);
                tmp.put("indexName","收缩压");
                tmp.put("error",false);
            }
            result.add(tmp);
            //舒张压校验
            tmp = new JSONObject();
            if (!checkHealthIndex(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)){
                tmp.put("value1",value1);
                tmp.put("indexName","舒张压");
                tmp.put("error",true);
            }else {
                tmp.put("value1",value1);
                tmp.put("indexName","舒张压");
                tmp.put("error",false);
            }
            result.add(tmp);
            tmp = new JSONObject();
            //脉搏检验
            if (StringUtils.isNotBlank(value3)){
                if (!checkHealthIndex(NumberUtils.toDouble(value3), HEALTH_STANDARD_HEART_RATE_MAX, HEALTH_STANDARD_HEART_RATE_MIN)){
                    tmp.put("value1",value1);
                    tmp.put("indexName","脉搏");
                    tmp.put("error",true);
                }else {
                    tmp.put("value1",value1);
                    tmp.put("indexName","脉搏");
                    tmp.put("error",false);
                }
                result.add(tmp);
            }
        }
        else if (type == 5) {//心率
            String value1 = values[0];//心率
            if (!checkHealthIndex(NumberUtils.toDouble(value1), HEALTH_STANDARD_HEART_RATE_MAX, HEALTH_STANDARD_HEART_RATE_MIN)){
                tmp.put("value1",value1);
                tmp.put("indexName","心率");
                tmp.put("error",true);
            }else {
                tmp.put("value1",value1);
                tmp.put("indexName","心率");
                tmp.put("error",false);
            }
            result.add(tmp);
        }
        return result;
    }
    /**
     * 判断当前值是否在区间内
     */
    private boolean checkHealthIndex(Double current, Double max, Double min) {
        if (current > max || current < min || current < 0) {
            return false;
        }
        return true;
    }
}

+ 12 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/birthday/BirthDayWishesToPatientDao.java

@ -0,0 +1,12 @@
package com.yihu.jw.care.dao.birthday;
import com.yihu.jw.entity.care.birthday.BirthDayWishesToPatient;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Bing on 2021/7/16.
 */
public interface BirthDayWishesToPatientDao extends PagingAndSortingRepository<BirthDayWishesToPatient,Long>,
        JpaSpecificationExecutor<BirthDayWishesToPatient> {
}

+ 29 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/birthday/BirthdayWishesTemplateDao.java

@ -0,0 +1,29 @@
package com.yihu.jw.care.dao.birthday;
import com.yihu.jw.entity.care.birthday.BirthdayWishesTemplate;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by humingfen on 2018/10/26.
 */
public interface BirthdayWishesTemplateDao extends PagingAndSortingRepository<BirthdayWishesTemplate, Long> {
    @Query("SELECT t from BirthdayWishesTemplate t where t.applicableRange = ?2 and (t.createUser = ?1 or t.createUser is null ) and t.del = 1 ORDER BY t.isDefault desc,t.type, t.createTime desc ")
    List<BirthdayWishesTemplate> getTemplateByDoctorAndApplicableRange(String doctor, Integer applicableRange);
    @Query("SELECT t from BirthdayWishesTemplate t where (t.createUser = ?1 or t.createUser is null ) and t.del = 1 ORDER BY t.isDefault desc,t.type, t.createTime desc ")
    List<BirthdayWishesTemplate> getTemplateByDoctor(String doctor);
    @Query("select t from BirthdayWishesTemplate t where t.applicableRange = ?1 and t.type = 1 and t.del = 1")
    BirthdayWishesTemplate getTemplateByApplicableRange(Integer applicableRange);
    @Query("update BirthdayWishesTemplate t set t.isDefault = ?2 where t.id = ?1")
    @Modifying
    void setDefalutTemplateById(Long id, Integer isDefault);
    BirthdayWishesTemplate findByCreateUserAndApplicableRangeAndIsDefault(String doctor,Integer applicableRange, int isDefault);
}

+ 271 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/doctor/DoctorBirthdayWishesEndpoint.java

@ -0,0 +1,271 @@
package com.yihu.jw.care.endpoint.doctor;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.yihu.jw.care.endpoint.BaseController;
import com.yihu.jw.care.service.birthday.BirthdayWishesService;
import com.yihu.jw.care.util.MessageUtil;
import com.yihu.jw.entity.care.birthday.BirthDayWishesToPatient;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.util.date.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * Created by Bing on 2021/7/16.
 */
@RestController
@RequestMapping(value = "doctor/birthday")
@Api(tags = "医生生日祝福", description = "医生生日祝福")
public class DoctorBirthdayWishesEndpoint extends BaseController {
    @Autowired
    private BirthdayWishesService birthdayWishesService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private MessageUtil messageUtil;
    @Value("${wechat.id}")
    private String wxId;
    @Autowired
    private SystemMessageDao systemMessageDao;
    @Autowired
    private ImUtil imUtil;
    @RequestMapping(value = "/createTemplate", method = RequestMethod.POST)
    @ApiOperation(value = "创建模板")
    public String createTemplate(@ApiParam(name = "content", value = "医生新建的祝福语")
                                 @RequestParam(required = false) String content,
                                 @ApiParam(name = "applicableRange", value = "适用人群")
                                 @RequestParam(required = false) Integer applicableRange,
                                 @ApiParam(name = "id", value = "模板ID")
                                 @RequestParam(required = false) Long id,
                                 @ApiParam(name = "isDefault", value = "是否是默认模板")
                                 @RequestParam(required = false) Integer isDefault) {
        try {
            return write(200, "更新成功!", "data", birthdayWishesService.create(getUID(), content, applicableRange, id, isDefault));
        } catch (Exception e) {
            return errorResult(e);
        }
    }
    @RequestMapping(value = "/getTemplateByDoctor", method = RequestMethod.GET)
    @ApiOperation(value = "获取系统模板和当前医生创建的模板")
    public String getTemplateByDoctor(@ApiParam(name = "doctor", value = "医生code")
                                      @RequestParam(required = false) String doctor) {
        try {
            if(StringUtils.isBlank(doctor)){
                doctor = getUID();
            }
            return write(200, "查询成功!", "data", birthdayWishesService.getTemplateByDoctor(doctor));
        } catch (Exception e) {
            return errorResult(e);
        }
    }
    @RequestMapping(value = "/getTemplateById", method = RequestMethod.GET)
    @ApiOperation(value = "根据模板id获取祝福内容")
    public String getTemplateById(@ApiParam(name = "id", value = "模板id")
                                  @RequestParam(required = true) Long id) {
        try {
            return write(200, "查询成功!", "data", birthdayWishesService.getTemplateById(id));
        } catch (Exception e) {
            return errorResult(e);
        }
    }
    @RequestMapping(value = "/deleteTemplateById", method = RequestMethod.POST)
    @ApiOperation(value = "根据模板id删除祝福模板")
    public String deleteTemplateById(@ApiParam(name = "id", value = "模板id")
                                     @RequestParam(required = true) Long id) {
        try {
            birthdayWishesService.deleteTemplateById(id);
            return write(200, "删除成功!");
        } catch (Exception e) {
            return errorResult(e);
        }
    }
    @RequestMapping(value = "/setDefalutTemplateById", method = RequestMethod.POST)
    @ApiOperation(value = "设置默认模板")
    public String setDefalutTemplateById(
            @ApiParam(name = "id", value = "模板ID",required = true)
            @RequestParam Long id) {
        try {
            return write(200, "设置成功!", "data", birthdayWishesService.setDefalutTemplateById(getUID(), id));
        } catch (Exception e) {
            return errorResult(e);
        }
    }
    @ApiOperation("获取医生签约患者当天生日未发生")
    @RequestMapping(value = "getPatientByDoctor", method = RequestMethod.GET)
    public String getPatientByDoctor(){
        try {
            return write(200, "查询成功", "data", birthdayWishesService.getPatientByDoctor(getUID()));
        } catch (Exception e) {
            return errorResult(e);
        }
    }
    @ApiOperation("获取生日居民列表")
    @RequestMapping(value = "getBirthdayPatientList", method = RequestMethod.GET)
    public String getBirthdayPatientList(@ApiParam(name = "patientName", value = "居民姓名")
                                         @RequestParam(required = false) String patientName,
                                         @ApiParam(name = "signYear", value = "签约年度")
                                         @RequestParam(required = false) Integer signYear,
                                         @ApiParam(name = "startDate", value = "生日开始日期yyyy-MM-dd")
                                         @RequestParam String startDate,
                                         @ApiParam(name = "endDate", value = "生日截止日期yyyy-MM-dd")
                                         @RequestParam String endDate,
                                         @ApiParam(name = "status", value = "状态(1、已发送,2、未发送)")
                                         @RequestParam(required = false) Integer status,
                                         @ApiParam(name = "currentUserRole", value = "登录角色")
                                         @RequestParam(value = "currentUserRole", required = false) String currentUserRole,
                                         @ApiParam(name = "currentUserRoleLevel", value = "登录角色等级(1省2市3区4社区、机构)")
                                         @RequestParam(value = "currentUserRoleLevel", required = false)String currentUserRoleLevel,
                                         @ApiParam(name = "roleType", value = "1、普通医生,2、管理员")
                                         @RequestParam(value = "roleType") Integer roleType,
                                         @ApiParam(name = "teamId", value = "医生所在团队")
                                         @RequestParam(value = "teamId", required = false) Integer teamId,
                                         @ApiParam(name = "isLeader", value = "是否是团队长,0不是、1是")
                                         @RequestParam(value = "isLeader", required = false) Integer isLeader,
                                         @ApiParam(name = "page", value = "第几页,从1开始")
                                         @RequestParam Integer page,
                                         @ApiParam(name = "pageSize", value = "页面大小")
                                         @RequestParam Integer pageSize){
        try {
            return write(200, "查询成功", "data", birthdayWishesService.getBirthdayPatientList(getUID(), patientName, signYear, startDate, endDate, status, currentUserRole, currentUserRoleLevel, roleType, page, pageSize, teamId, isLeader));
        } catch (Exception e) {
            return errorResult(e);
        }
    }
    @RequestMapping(value = "/doctorSendBirthdayWishes", method = RequestMethod.POST)
    @ApiOperation(value = "医生发送生日祝福")
    public String pushBirthdayWishes(@ApiParam(name = "patient", value = "发送人群集合")
                                     @RequestParam(required = true) String patient,
                                     @ApiParam(name = "templateId", value = "生日祝福模板id")
                                     @RequestParam(required = false) Long templateId,
                                     @ApiParam(name = "content", value = "医生新建的祝福语")
                                     @RequestParam(required = false) String content,
                                     @ApiParam(name = "applicableRange", value = "适用人群")
                                     @RequestParam(required = false) Integer applicableRange,
                                     @ApiParam(name = "isSave", value = "是否保存")
                                     @RequestParam(required = false) Integer isSave,
                                     @RequestParam(value = "currentUserRole", required = false) String currentUserRole,
                                     @RequestParam(value = "currentUserRoleLevel", required = false)String currentUserRoleLevel) {
        try {
            Date currentTime = new Date();
            SimpleDateFormat format = new SimpleDateFormat("MM月dd日");
            String dateString = format.format(currentTime);
            if(StringUtils.isEmpty(currentUserRole)){
                currentUserRole = getCurrentRoleCode();
            }
            if(StringUtils.isEmpty(currentUserRoleLevel)){
                currentUserRoleLevel = getCurrentRoleLevel();
            }
            JSONObject json = new JSONObject();
            json.put("patient", patient);
            json.put("doctorCode", getUID());
            json.put("sendType", 1);
            json.put("birthday", dateString);
            json.put("currentUserRole", currentUserRole);
            json.put("currentUserRoleLevel", currentUserRoleLevel);
            if(templateId != null) {
                json.put("templateId", templateId);
                json.put("isSave", 1);
            }else {
                json.put("content", content);
                json.put("isSave", 0);
            }
            List<BirthDayWishesToPatient> birthDayWishesToPatientESList = birthdayWishesService.saveBirthdayWishesES(json);
            new Thread(() -> {
                sender(birthDayWishesToPatientESList);
            }).start();
            return write(200, "发送成功!");
        } catch (Exception e) {
            return errorResult(e);
        }
    }
    /**
     * 发送消息
     *
     */
    public void sender(List<BirthDayWishesToPatient> birthDayWishesToPatient) {
        //发送到队列
        birthDayWishesToPatient.stream().forEach(one -> {
            //根据openid进行发送祝福
            String patient = one.getPatientCode();
            if (StringUtils.isNotBlank(patient)){
                String sql = " select p.id as patient,p.name,we.openid from base_patient p inner join  base_patient_wechat we on p.id = we.patient_id " +
                        "and we.patient_id = '"+patient+"' " +
                        "  order by we.create_time desc  ";
                List<Map<String,Object>> patients = jdbcTemplate.queryForList(sql);
                if (patients.size()>0){//发送生日祝福
                    Map<String,Object> tmp = patients.get(0);
                    com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
                    String first = "助老员key1为您发送生日祝福,请点击查看。";
                    first = first.replace("key1",one.getDoctorName());
                    json.put("doctorName", one.getDoctorName());
                    json.put("toUser", patient);
                    json.put("name", tmp.get("name").toString());
                    json.put("content", one.getContent());
                    json.put("openid",tmp.get("openid").toString());
                    json.put("represented","");//被代理人
                    boolean success =  messageUtil.putTemplateWxMessage(wxId,"template_success_notice","srzf",tmp.get("openid").toString(),first,
                            null,one.getContent(),26,json,"已发送", DateUtil.dateToChineseTime(new Date()));
                    if (success){
                        SystemMessageDO messageDO = new SystemMessageDO();
                        messageDO.setTitle("收到来自"+one.getDoctorName()+"的关怀祝福:祝您"+tmp.get("name").toString()+"节日快乐!");
                        messageDO.setType("41");//41人文关怀
                        messageDO.setSender(one.getDoctorCode());
                        messageDO.setSenderName(one.getDoctorName());
                        messageDO.setRelationCode(one.getId()+"");
                        messageDO.setReceiver(patient);
                        messageDO.setReceiverName(tmp.get("name").toString());
                        messageDO.setOver("1");
                        messageDO.setCode("1");//1生日祝福
                        messageDO.setData(one.getContent());
                        messageDO.setDel("1");
                        messageDO.setCreateTime(new Date());
                        systemMessageDao.save(messageDO);
                        //推送socket
                        com.alibaba.fastjson.JSONObject message = new com.alibaba.fastjson.JSONObject();
                        message.put("title",messageDO.getTitle());
                        message.put("code",messageDO.getCode());
                        message.put("content",messageDO.getData());
                        message.put("relation_code",messageDO.getRelationCode());
                        message.put("content_type",41);
                        message.put("content_notice","");
                        String content_notice = null;
                        imUtil.sendPatientSystemMessage(messageDO.getReceiver(), JSON.toJSONString(messageDO, SerializerFeature.WriteMapNullValue));
                    }
                }
            }
        });
    }
}

+ 17 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/message/PatientMessageEndpoint.java

@ -76,7 +76,23 @@ public class PatientMessageEndpoint extends EnvelopRestEndpoint {
                                            @RequestParam(value = "type")String type
                                            ){
        try {
            return ListEnvelop.getSuccess("查询成功",patientMessageService.getSystemMessageList(patient,type));
            return ListEnvelop.getSuccess("查询成功",patientMessageService.getSystemMessageList(patient,type,null));
        }catch (Exception e){
            return failedListEnvelopException2(e);
        }
    }
    @GetMapping(value = "getSystemMessageListPad")
    @ApiOperation("居民平板端获取消息列表(生日祝福,体征设备)")
    public ListEnvelop getUnreadSystemMessageListPad(@ApiParam(name = "patient",required = true)
                                            @RequestParam(value = "patient")String patient,
                                            @ApiParam(name = "type",required = true)
                                            @RequestParam(value = "type",defaultValue = "41,42")String type,
                                            @ApiParam(name = "isRead",required = false,value = "1:为已读,0:未读")
                                            @RequestParam(value = "isRead",required = false)String isRead
    ){
        try {
            return ListEnvelop.getSuccess("查询成功",patientMessageService.getSystemMessageList(patient,type,isRead));
        }catch (Exception e){
            return failedListEnvelopException2(e);
        }

+ 12 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/patient/PatientContactsEndpoint.java

@ -4,10 +4,12 @@ import com.alibaba.fastjson.JSONArray;
import com.yihu.jw.care.service.contacts.ContactsService;
import com.yihu.jw.entity.base.org.BaseOrgDO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -117,4 +119,14 @@ public class PatientContactsEndpoint extends EnvelopRestEndpoint {
        }
    }
    @RequestMapping(value = "getAllOrgListWithSignFlag",method = RequestMethod.GET)
    @ApiOperation(value = "获取所有服务站列表--带是否签约标识")
    public ListEnvelop getAllOrgList(@ApiParam(name="patient",value = "居民id")
                                     @RequestParam(value = "patient",required = false)String patient){
        try {
            return ListEnvelop.getSuccess("获取成功",contactsService.getAllOrgListWithSignFlag(patient));
        }catch (Exception e){
            return failedListEnvelopException2(e);
        }
    }
}

+ 1 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/sign/SignEndpoint.java

@ -51,7 +51,7 @@ public class SignEndpoint extends EnvelopRestEndpoint {
    @GetMapping(value = "findSignOrg")
    @ApiOperation(value = "查找签约机构")
    public ListEnvelop findSignOrg (
            @ApiParam(name = "patient", value = "医生code", required = true)
            @ApiParam(name = "patient", value = "患者code", required = true)
            @RequestParam(value = "patient",required = true) String patient,
            @ApiParam(name = "name", value = "机构名称", required = false)
            @RequestParam(value = "name",required = false) String name,

+ 465 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/birthday/BirthdayWishesService.java

@ -0,0 +1,465 @@
package com.yihu.jw.care.service.birthday;
import com.yihu.jw.care.dao.birthday.BirthDayWishesToPatientDao;
import com.yihu.jw.care.dao.birthday.BirthdayWishesTemplateDao;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.birthday.BirthDayWishesToPatient;
import com.yihu.jw.entity.care.birthday.BirthdayWishesTemplate;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import org.apache.commons.lang.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
 * Created by Bing on 2021/7/16.
 */
@Service
public class BirthdayWishesService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    private static LinkedBlockingQueue<JSONObject> queue = new LinkedBlockingQueue<>();
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private BasePatientDao patientDao;
    @Autowired
    private BirthdayWishesTemplateDao bwTemplateDao;
    @Autowired
    private BirthDayWishesToPatientDao bwToPatientDao;
    @Autowired
    private BaseDoctorHospitalDao hospitalDao;
    @Autowired
    private RedisTemplate redisTemplate;
//    /**
//     * 发送到mq
//     *
//     */
//    public void sender(List<BirthDayWishesToPatientES> birthDayWishesToPatientES) {
//        //发送到队列
//        birthDayWishesToPatientES.stream().forEach(one -> {
//            jmsTemplate.send(channelName, new MessageCreator() {
//                @Override
//                public Message createMessage(Session session) throws JMSException {
//                    TextMessage textMessage = session.createTextMessage();
//                    textMessage.setText(net.sf.json.JSONObject.fromObject(one).toString());
//                    return textMessage;
//                }
//            });
//        });
//    }
    /**
     * 医生端--新建祝福语模板
     * @param doctor
     * @param content
     * @param applicableRange
     * @param id
     * @param isDefault
     */
    public Long create(String doctor, String content, Integer applicableRange, Long id, Integer isDefault) {
        BaseDoctorDO doctorDO = doctorDao.findById(doctor);
        BirthdayWishesTemplate template = null;
        //判断是编辑还是创建
        if(id != null){
            template = bwTemplateDao.findOne(id);
        }else {
            template = new BirthdayWishesTemplate();
            template.setCode(UUID.randomUUID().toString().replace("-",""));
            template.setType(2);
            template.setDel(1);
            template.setCreateUser(doctor);
            template.setCreateUserName(doctorDO.getName());
        }
        template.setApplicableRange(applicableRange);
        template.setContent(content);
        template.setCreateTime(new Date());
        if(isDefault != null) {
            if(isDefault == 1){
                //先取消该医生自创的默认模板
                BirthdayWishesTemplate docTemplate = bwTemplateDao.findByCreateUserAndApplicableRangeAndIsDefault(doctor, applicableRange, 1);
                if(docTemplate != null){
                    bwTemplateDao.setDefalutTemplateById(docTemplate.getId(), 0);
                }
            }
            template.setIsDefault(isDefault);
        }else if(id == null || template.getIsDefault() == null){
            template.setIsDefault(0);
        }
        bwTemplateDao.save(template);
        return template.getId();
    }
    /**
     * 获取系统模板和医生创建模板
     * @return
     */
    public List<BirthdayWishesTemplate> getTemplateByDoctor(String doctor) {
        return bwTemplateDao.getTemplateByDoctor(doctor);
    }
    /**
     * 根据id获取模板消息
     * @param id
     * @return
     */
    public BirthdayWishesTemplate getTemplateById(Long id) {
        return bwTemplateDao.findOne(id);
    }
    public void deleteTemplateById(Long id) {
        bwTemplateDao.delete(id);
    }
    /**
     * 根据ID设置为默认模板
     *
     * @param doctor
     * @param id
     * @return
     */
    @Transactional
    public BirthdayWishesTemplate setDefalutTemplateById(String doctor, Long id) {
        BirthdayWishesTemplate template = bwTemplateDao.findOne(id);
        //先取消该医生自创的默认模板
        BirthdayWishesTemplate docTemplate = bwTemplateDao.findByCreateUserAndApplicableRangeAndIsDefault(doctor, template.getApplicableRange(), 1);
        if(docTemplate != null){
            bwTemplateDao.setDefalutTemplateById(docTemplate.getId(), 0);
        }
        //如果不是系统模板,就添加默认模板标识
        if(template.getType() != 1){
            bwTemplateDao.setDefalutTemplateById(id, 1);
        }
        return template;
    }
    /**
     * 获取医生当天未发送生日祝福居民信息
     * @param doctor
     * @return
     */
    public List<Map<String, Object>> getPatientByDoctor(String doctor) throws Exception{
        //es日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String createTime = sdf.format(new Date()) + " 00:00:00";
        //今日推送的居民
        Set<String> sendPatients = (Set<String>) redisTemplate.opsForValue().get("birthday:wish:sendPatient");
        Date currentTime = new Date();
        SimpleDateFormat format = new SimpleDateFormat("MMdd");
        String dateString = format.format(currentTime);
        //获取当天0点
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        String now = f.format(new Date());
        String sql = "SELECT p.id patient, p.`name`, " +
                "CASE p.sex WHEN 1 THEN '男' WHEN 2 THEN '女' END sex," +
                "p.idcard, p.photo," +
                " CASE LENGTH(p.idcard) WHEN  18 then SUBSTR(p.idcard,11,4) when 15 then SUBSTR(p.idcard, 9,4) END date " +
                "from wlyy_archive a,base_patient p WHERE  a.patient = p.id and a.sign_status = 1 and EXISTS( " +
                "SELECT DISTINCT sr.patient from base_service_package_sign_record sr,base_service_package_record r, " +
                "base_service_package_item i,base_team_member m " +
                "WHERE  sr.id = r.sign_id and sr.patient = a.patient  and r.service_package_id = i.service_package_id " +
                "and i.del = 1 and m.team_code = i.team_code and m.doctor_code = '"+doctor+"' ) "+
                " and (p.archive_status<>2 or p.archive_status is null) " +
                "AND CASE LENGTH(p.idcard) WHEN  18 then SUBSTR(p.idcard,11,4) when 15 then SUBSTR(p.idcard, 9,4) END =  '" + dateString + "' " ;
        List<Map<String, Object>> patientInfos =  jdbcTemplate.queryForList(sql);
        //整理未发送居民信息
        for(Map<String, Object> map : patientInfos){
            if (sendPatients == null || !sendPatients.contains(map.get("patient"))) {
                int age = IdCardUtil.getAgeForIdcard(map.get("idcard") + "");
                Date birthday = IdCardUtil.getBirthdayForIdcard(map.get("idcard") + "");
                map.put("age", age);
                map.put("birthday", DateUtil.dateToStr(birthday, "yyyy-MM-dd"));
            }
        }
        return patientInfos;
    }
    /**
     * 获取医生生日列表
     */
    public Map<String, Object> getBirthdayPatientList(String doctorCode, String patientName, Integer signYear, String startDate, String endDate, Integer status, String currentUserRole, String currentUserRoleLevel,
                                                      Integer roleType, Integer page, Integer pageSize, Integer teamId, Integer isLeader) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        List<Map<String, Object>> resultList = new ArrayList();
        Long allCount = 0l;
        //判断是否筛选推送条件,若未筛选则从数据库直接查生日居民,再进行匹配是否推送,若选择已推送则从推送记录查,若未发送则从未推送表查
        //助老员签约患者
        String sql = " SELECT Distinct p.id patient,p.idcard,p.mobile,p.name,p.sex,p.id,p.photo," +
                "CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END birthday  " ;
        String sqlCount = "SELECT count(distinct p.idcard) ";
        String whereSql = "from wlyy_archive a,base_patient p WHERE  a.patient = p.id and a.sign_status = 1 and EXISTS( " +
                "SELECT DISTINCT sr.patient from base_service_package_sign_record sr,base_service_package_record r, " +
                "base_service_package_item i,base_team_member m " +
                "WHERE  sr.id = r.sign_id and sr.patient = a.patient  and r.service_package_id = i.service_package_id " +
                "and i.del = 1 and m.team_code = i.team_code ";
        //根据权限获取生日居民列表
        if (roleType == 1) {
            whereSql += " and m.doctor_code = '"+doctorCode+"' ";
        } else {//管理员
            switch (currentUserRoleLevel) {
                case "1": {//省
                    whereSql += " and i.org_code in ( select org.code from base_org org where org.province_code = '"+currentUserRole+"' and org.del=1 )  ";
                    break;
                }
                case "2": {//市
                    whereSql += " and i.org_code in ( select org.code from base_org org where org.city_code = '"+currentUserRole+"' and org.del=1 )  ";
                    break;
                }
                case "3": {//区
                    whereSql += " and i.org_code in ( select org.code from base_org org where org.town_code = '"+currentUserRole+"' and org.del=1 )  ";
                    break;
                }
                case "4": {//社区机构
                    whereSql += " and i.org_code = '" + currentUserRole + "' ";
                    break;
                }
            }
        }
        if (StringUtils.isNotBlank(patientName)) {
            whereSql += "and p.name like '%" + patientName + "%' ";
        }
        //根据签约年限来获取生日居民
        if ( null==  signYear|| signYear == DateUtil.getNowYear()) {//当前年度
            whereSql += " and sr.status=1 ";
        } else {//
            whereSql += " and sr.status=-1 and sr.start_time >='" + signYear+" 01-01:00:00:00" + "' and sr.start_time <='" + signYear+" 12-31:23:59:59" + "'  ";
        }
        if (StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)) {
            String start = startDate.substring(4).replace("-", "");
            String end = endDate.substring(4).replace("-", "");
            Integer birStart = Integer.parseInt(start);
            Integer birEnd = Integer.parseInt(end);
            //判断生日日期
            if(birEnd > birStart) {
                whereSql += "AND CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END >= '" + start + "' " +
                        "AND CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END <= '" + end + "' ";
            }else if(birEnd < birStart){
                whereSql += "AND CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END >= '" + end + "' " +
                        "AND CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END <= '" + start + "' ";
            }else {
                whereSql += "AND CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END = '" + end + "' ";
            }
        }
        whereSql += "and DATE_FORMAT(sr.create_time,'%m%d')< CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END ";
        sql = sql + whereSql + " ) order by birthday limit "+(page-1)*pageSize + "," + pageSize;
        sqlCount = sqlCount + whereSql+")";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        allCount = jdbcTemplate.queryForObject(sqlCount, Long.class);
        resultMap.put("total", allCount);
        //获取生日居民code
        String patientString = "";
        for (Map<String, Object> map : list) {
            patientString += "'"+ map.get("patient") + "',";
        }
        if(patientString.length() > 0) {
            //查询该居民是否有推送过
            String es = "SELECT patient_code patientCode,doctor_name doctorName,content,birthday,create_time createTime FROM birthday_wishes_to_patient where patient_code in (" + patientString.substring(0, patientString.length() - 1) + ") and user_type =1 and create_time > '" + startDate + " 00:00:00' and create_time < '" + endDate + " 23:59:59'";
            List<Map<String, Object>> sendPatientList = jdbcTemplate.queryForList(es);
            Set<String> patientSet = new HashSet<>();
            for (Map<String, Object> map : list) {
                String patientCode = map.get("patient") + "";
                //判断是否在推送记录里
                if( null == status || 1 == status  ) {
                    for (Map<String, Object> esMap : sendPatientList) {
                        if (patientCode.equals(esMap.get("patientCode") + "")) {
                            map.put("birthday", esMap.get("birthday") + "");
                            map.put("doctorName", esMap.get("doctorName") + "");
                            map.put("content", esMap.get("content") + "");
                            map.put("createTime", (esMap.get("createTime") + "").replace("T", " ").replace("+0800", ""));
                            map.put("status", "已发送");
                            patientSet.add(patientCode);
                            resultList.add(map);
                        }
                    }
                }
            }
            if(null == status || 2 == status) {
                //存取未发送居民
                for (Map<String, Object> map : list) {
                    String patientCode = map.get("patient") + "";
                    if (!patientSet.contains(patientCode)) {
                        String birthday = map.get("birthday")+"日";
                        StringBuilder bir = new StringBuilder(birthday);
                        bir.insert(2, "月");
//                            int age = IdCardUtil.getAgeForIdcard(map.get("idcard") + "");
                        map.put("birthday", bir.toString());
//                        int age = IdCardUtil.getAgeForIdcard(map.get("idcard") + "");
//                        map.put("age", age);
                        map.put("status", "未发送");
                        resultList.add(map);
                    }
                }
            }
        }
        resultMap.put("detailModelList", resultList);
        resultMap.put("total", allCount);
        resultMap.put("pageCount", allCount%pageSize == 0 ?allCount/pageSize : allCount/pageSize +1);
        return resultMap;
    }
    /**
     * 将发送祝福的居民相关信息存到es
     * @param json
     * @return
     */
    public List<BirthDayWishesToPatient> saveBirthdayWishesES(JSONObject json) {
        List<BirthDayWishesToPatient> list = new ArrayList<>();
        List<BirthDayWishesToPatient> birthdayWishesList = new ArrayList<>();
        String p = json.get("patient") + "";
        String doctorCode = json.get("doctorCode") + "";
        Integer sendType = (Integer) json.get("sendType");
        String currentUserRole = json.has("currentUserRole")?json.get("currentUserRole") + "":null;
        String currentUserRoleLevel = json.has("currentUserRoleLevel")?json.get("currentUserRoleLevel") + "":null;
        String dateString = json.get("birthday") + "";
        Integer isSave = (Integer) json.get("isSave");
        Long templateId = null;
        String content = null;
        if(isSave == 1) {
            templateId = (Long) json.get("templateId");
            BirthdayWishesTemplate birthdayWishesTemplate = bwTemplateDao.findOne(templateId);
            content = birthdayWishesTemplate.getContent();
        }else if(isSave == 0){
            content = json.get("content") + "";
        }
        Set<String> patientSet = new HashSet<>();
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createTime = f.format(new Date());
        //医生今日推送的居民
        List<BirthDayWishesToPatient> sendPatientList = findSendPatientByCreateTime(p.toString(),createTime);
        Set<String> sendPatient = sendPatientList.stream().map(BirthDayWishesToPatient::getPatientCode).collect(Collectors.toSet());
        Set<String> openidSet = new HashSet<>();
        BaseDoctorDO doctor = doctorDao.findById(doctorCode);
        String sql = " select * from ( select p.id as patient,p.name,we.openid from base_patient p inner join  base_patient_wechat we on p.id = we.patient_id and we.patient_id in ( "+p.toString()+") " +
                "  order by we.create_time desc )A group by A.patient  ";
        List<Map<String, Object>> patientInfos = jdbcTemplate.queryForList(sql);
        //批量发送要属于同一批次
        String batchNo = UUID.randomUUID().toString();
        for (Map<String, Object> patientInfo : patientInfos) {
            String s = patientInfo.get("patient") + "";
            //已推送则不再重复推送
            if(!sendPatient.contains(s)) {
                patientSet.add(s);
                //获取已推送居民
                sendPatient.add(s);
            }else {
                continue;
            }
            openidSet.add(patientInfo.get("openid") + "");
            BirthDayWishesToPatient es = new BirthDayWishesToPatient();
            es.setBatchNo(batchNo);
            es.setPatientCode(s);
            es.setPatientName(patientInfo.get("name") + "");
            es.setDoctorCode(doctor.getId());
            es.setDoctorName(doctor.getName());
            es.setUserType(1);
            List<BaseDoctorHospitalDO> hospitalDOs = hospitalDao.findByDoctorCode(doctorCode);
            //存储发送人信息
            es.setSendPic(doctor.getPhoto());
            es.setSendSex(doctor.getSex()+"");
//            es.setAdminTeamName(patientInfo.get("teamName") + "");
//            es.setAdminTeamCode(Long.valueOf(patientInfo.get("admin_team_code")+""));
            if (hospitalDOs.size()>0){
                es.setHospital(hospitalDOs.get(0).getOrgCode());
                es.setHospitalName(hospitalDOs.get(0).getOrgName());
            }
            es.setTown(doctor.getTownCode());
            es.setTownName(doctor.getTownName());
            es.setSendType(sendType);
            es.setSendLevel(doctor.getLevel());
            if (StringUtils.isNotBlank(currentUserRole)){
                es.setCurrentUserRoleCode(currentUserRole);
            }
            if (StringUtils.isNotBlank(currentUserRoleLevel)){
                es.setCurrentUserRoleLevel(currentUserRoleLevel);
            }
            es.setAllCount(patientSet.size());
            es.setOpenidSet(openidSet.toString());
            //生日祝福信息
            es.setBirthday(dateString);
            es.setTemplateId(templateId);
            es.setContent(content);
            es.setCreateTime(DateUtil.getStringDate());
            list.add(es);
        }
        if(list.size()>0){
            //保存到ES中
//            elastricSearchSave.save(list, esIndex, esType);
            //另存一条发送祝福的医生信息,便于查询医生发送祝福的居民列表
            BirthDayWishesToPatient e = new BirthDayWishesToPatient();
            BeanUtils.copyProperties(list.get(0), e);
            e.setUserType(2);
            e.setPatientCode(null);
            e.setPatientName(null);
            list.add(e);
            bwToPatientDao.save(list);
//            System.out.println("ES保存成功!");
            //将发送生日祝福的居民code存起来
            Calendar today = Calendar.getInstance();
            today.set(Calendar.HOUR, 23);
            today.set(Calendar.MINUTE, 59);
            today.set(Calendar.SECOND, 59);
            today.set(Calendar.MILLISECOND, 999);
            redisTemplate.opsForValue().set("birthday:wish:sendPatient", sendPatient);
            redisTemplate.expire("birthday:wish:sendPatient", today.getTimeInMillis() - Calendar.getInstance().getTimeInMillis(), TimeUnit.MILLISECONDS);
        }
        return list;
    }
    /**
     * 获取今日已推送居民
     * @param
     * @return
     */
    public List<BirthDayWishesToPatient> findSendPatientByCreateTime(String patient,String createTime) {
        StringBuffer sql = new StringBuffer("select patient_code patientCode from  birthday_wishes_to_patient  "+
                " where user_type=1 and create_time>'" + createTime + "' ");
        if (StringUtils.isNotBlank(patient)){
            sql.append(" and patient_code in ( "+patient+" ) ") ;
        }
        sql.append(" limit 0,500000 ");
        List<BirthDayWishesToPatient> patientList = jdbcTemplate.queryForList(sql.toString(), BirthDayWishesToPatient.class);
        return patientList;
    }
}

+ 20 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/contacts/ContactsService.java

@ -182,4 +182,24 @@ public class ContactsService {
        return result;
    }
    /**
     * 服务站列表(平台内所有养老机构)
     *
     */
    public List<Map<String,Object>> getAllOrgListWithSignFlag(String patient){
        List<Map<String,Object>> result = new ArrayList<>();
        String sql =  "select * from base_org org  " ;
        if (StringUtils.isNotBlank(patient)){
            sql +=" LEFT JOIN ( " +
                    "SELECT  DISTINCT i.org_code,'1' as signFlag FROM  base_service_package_sign_record sr,  base_service_package_record r, " +
                    " base_service_package_item i WHERE  sr.id = r.sign_id and sr.status=1 and sr.patient = '"+patient+"'" +
                    " AND r.service_package_id = i.service_package_id " +
                    " AND i.del = 1  AND sr.`status` = 1)A on org.code = A.org_code ";
        }
        sql +=  " where org.del=1 and org.type=3 " ;
        result = jdbcTemplate.queryForList(sql);
        return result;
    }
}

+ 1 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/label/PatientLableService.java

@ -59,7 +59,7 @@ public class PatientLableService extends BaseJpaService<WlyyPatientLabelDO, Wlyy
     */
    public PageEnvelop<List<Map<String,Object>>> findSignPatientLabelListByTeamCode(String teamCode, String labelCode, String name, int page, int size){
        String sql = "SELECT DISTINCT p.id,p.name,p.photo,p.idcard,p.mobile,p.openid,p.sex " ;
        String countSql = "SELECT count(p.id) ";
        String countSql = "SELECT count(DISTINCT p.id) ";
        String filters = "from base_service_package_sign_record sr,base_service_package_record r,  " +
                "                base_service_package_item i,base_patient p,wlyy_patient_label l " +
                "                WHERE sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id  " +

+ 19 - 4
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/message/PatientMessageService.java

@ -76,16 +76,31 @@ public class PatientMessageService {
    public List<Map<String,Object>> getSystemMessage(String patient){
        String sql = " select A.*,B.notRead from " +
                "(select  count(1) as 'all',type,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') create_time " +
                "from base_system_message where receiver = '"+patient+"' and del=1 and type='50' GROUP BY type ORDER BY create_time desc)A " +
                "from base_system_message where receiver = '"+patient+"' and del=1  GROUP BY type ORDER BY create_time desc)A " +
                "LEFT JOIN (select count(1) notRead,type " +
                "from base_system_message where receiver = '"+patient+"' and is_read=0 and del=1 and type='50' GROUP BY type)B on A.type = B.type " +
                "from base_system_message where receiver = '"+patient+"' and is_read=0 and del=1  GROUP BY type)B on A.type = B.type " +
                "ORDER BY A.create_time desc ";
        return jdbcTemplate.queryForList(sql);
    }
    public List<Map<String,Object>> getSystemMessageList(String patient,String type){
    /**
     *
     * @param patient
     * @param type
     * type=50,code:20紧急救助 22安防监护
     * type=41,code:1 生日祝福
     * type=42,code与体征类型对应 体征设备数据
     *
     * @return
     */
    public List<Map<String,Object>> getSystemMessageList(String patient,String type,String isRead){
        String typeIn = " '"+type.replace(",","','")+"' ";
        String sql = " select id,title,type,relation_code,sender,sender_name,is_read,code,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') create_time " +
                "from base_system_message where receiver = '"+patient+"' and del=1 and type='"+type+"'  ORDER BY create_time desc";
                "from base_system_message where receiver = '"+patient+"' and del=1 and type in ("+typeIn+" )  " ;
        if (StringUtils.isNotBlank(isRead)){
            sql += " and is_read = '"+isRead+"'";
        }
         sql +=  "ORDER BY create_time desc";
        return jdbcTemplate.queryForList(sql);
    }

+ 8 - 3
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/util/MessageUtil.java

@ -96,7 +96,7 @@ public class MessageUtil {
     * @param json 用于对跳转连接的修改,
     * @param keywords
     */
    public void putTemplateWxMessage(String wechatId, String templateName, String scene, String openId, String first
    public boolean putTemplateWxMessage(String wechatId, String templateName, String scene, String openId, String first
            ,String url, String remark, Integer type,JSONObject json,String ...keywords) {
        try {
            System.out.println(wechatId);
@ -104,14 +104,14 @@ public class MessageUtil {
            if (wxAccessTokenDO == null) {
                logger.info("wx_access_token表获取为空,wechatId" + wechatId);
                return;
                return false;
            }
            WxTemplateConfigDO templateConfig = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId, templateName, scene, 1);
            WxTemplateConfigDO newConfig = new WxTemplateConfigDO();
            BeanUtils.copyProperties(templateConfig,newConfig);
            if (newConfig == null) {
                logger.info("微信模板不存在!请确认wechatId:" + wechatId + ",templateName:" + templateName + ",scene:" + scene);
                return;
                return false;
            }
            logger.info("微信模板推送前");
            if (StringUtils.isNoneBlank(first)){
@ -163,9 +163,11 @@ public class MessageUtil {
            //发起微信消息模板推送
            weixinMessagePushUtils.putWxMsg(wxAccessTokenDO.getAccessToken(), openId, newConfig);
            logger.info("微信模板消息推送后");
            return true;
        } catch (Exception e) {
            logger.info("微信模板推送异常");
            e.printStackTrace();
            return false;
        }
    }
@ -207,6 +209,9 @@ public class MessageUtil {
                }
                wxTemplateConfigDO.setUrl(url + urlStr );
                break;
            case 26://生日祝福
                wxTemplateConfigDO.setUrl(wxTemplateConfigDO.getUrl()+"?openid=" + openid + "&content=" + json.getString("content") + "&doctorName=" + json.getString("doctorName") + "&toUser=" + json.getString("toUser")  + "&toName=" + json.getString("name") + "&represented=" + (StringUtils.isNotEmpty(json.getString("represented"))?json.getString("represented"):""));
                break;
            case 30:
                //反馈通知 测试 TPbq9m0SAiVfRhXtXq17SDmYIfrJ8Whp2NpSrq9wlfI
                if(json.containsKey("consult")) {

+ 1 - 1
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/DeviceController.java

@ -226,7 +226,7 @@ public class DeviceController {
        }
    }
    @ApiOperation("柏颐设备步数接收")
    @ApiOperation("设备步数接收")
    @RequestMapping(value = "bySteps", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String bySteps(
            @ApiParam(name="imei",required = false,value="15位设备唯一序号",defaultValue = "")

+ 95 - 7
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/DeviceService.java

@ -1,7 +1,9 @@
package com.yihu.jw.care.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.yihu.jw.care.config.AqgConfig;
import com.yihu.jw.care.dao.device.DevicePatientHealthIndexDao;
import com.yihu.jw.care.dao.device.DeviceSosLogDao;
@ -10,11 +12,15 @@ import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.DevicePatientHealthIndex;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.device.DeviceSosLogDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.entity.util.AesEncryptUtils;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.util.common.GpsUtil;
import com.yihu.jw.util.common.LatitudeUtils;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.healthIndex.HealthIndexUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
@ -64,6 +70,12 @@ public class DeviceService {
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private GpsUtil gpsUtil;
    @Autowired
    private SystemMessageDao systemMessageDao;
    @Autowired
    private HealthIndexUtil healthIndexUtil;
    @Autowired
    private ImUtil imUtil;
    /**
     * 获取爱牵挂管理员cookie
@ -329,9 +341,9 @@ public class DeviceService {
    @Async
    public void byHeartRate(String imei,String time_begin,int heartrate,int theshold_heartrate_h,int theshold_heartrate_l) {
        try {
            if(StringUtils.isNotBlank(imei)){
            if(StringUtils.isNotBlank(imei)) {
                List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(imei);
                if (devicePatientDeviceDos.size()>0){
                if (devicePatientDeviceDos.size() > 0) {
                    DevicePatientDevice devicePatientDevice = devicePatientDeviceDos.get(0);
                    BasePatientDO patientDO = patientDao.findById(devicePatientDevice.getUser());
                    DevicePatientHealthIndex patientHealthIndex = new DevicePatientHealthIndex();
@ -339,23 +351,61 @@ public class DeviceService {
                    patientHealthIndex.setDeviceSn(imei);
                    patientHealthIndex.setUser(devicePatientDevice.getUser());
                    patientHealthIndex.setIdcard(devicePatientDevice.getUserIdcard());
                    patientHealthIndex.setValue1(heartrate+"");
                    patientHealthIndex.setValue1(heartrate + "");
                    patientHealthIndex.setType(5);
                    Date recordDate = DateUtil.strToDate(time_begin);
                    patientHealthIndex.setRecordDate(recordDate);
                    patientHealthIndex.setSortDate(recordDate);
                    patientHealthIndex.setCzrq(new Date());
                    if (heartrate>=theshold_heartrate_h||heartrate<=theshold_heartrate_l){
                    if (heartrate >= theshold_heartrate_h || heartrate <= theshold_heartrate_l) {
                        patientHealthIndex.setStatus(1);
                    }
                    else {
                    } else {
                        patientHealthIndex.setStatus(0);
                    }
                    patientHealthIndex.setDel("1");
                    healthIndexDao.save(patientHealthIndex);
                    SystemMessageDO messageDO = new SystemMessageDO();
                    String typeName = "您有新的心率测量记录。心率:" + patientHealthIndex.getValue1() + "次/min";
                    messageDO.setTitle(typeName);
                    messageDO.setType("52");//52体征测量
                    messageDO.setSender("system");
                    messageDO.setSenderName("养护助手");
                    messageDO.setRelationCode(patientHealthIndex.getId() + "");
                    messageDO.setReceiver(patientDO.getId());
                    messageDO.setReceiverName(patientDO.getName());
                    messageDO.setOver("1");
                    messageDO.setCode("5");//与体征类型对应
                    JSONArray errorIndex = healthIndexUtil.verifyHealthIndex(5,patientHealthIndex.getValue1(),patientHealthIndex.getValue2(),
                            patientHealthIndex.getValue3(),patientHealthIndex.getValue4(),patientHealthIndex.getValue5(),patientHealthIndex.getValue6(),
                            patientHealthIndex.getValue7());
                    messageDO.setData(JSON.toJSONString(errorIndex,SerializerFeature.WriteNullStringAsEmpty));
                    messageDO.setDel("1");
                    messageDO.setCreateTime(new Date());
                    systemMessageDao.save(messageDO);
                    //推送socket
                    com.alibaba.fastjson.JSONObject message = new com.alibaba.fastjson.JSONObject();
                    message.put("title","您刚刚测量了一次心率");
                    message.put("code",messageDO.getCode());
                    message.put("content",messageDO.getData());
                    message.put("relation_code",messageDO.getRelationCode());
                    message.put("content_type",42);
                    message.put("content_notice","");
                    String content_notice = null;
                    for (int i=0;i<errorIndex.size();i++){
                        com.alibaba.fastjson.JSONObject tmp = errorIndex.getJSONObject(i);
                        if (tmp.getBooleanValue("error")){
                            content_notice += tmp.getString("indexName"+"、");
                        }
                    }
                    if (org.apache.commons.lang3.StringUtils.isNotBlank(content_notice)){
                        content_notice.substring(0,content_notice.length()-2);
                        message.put("content_notice","您的key1过高,请注意饮食,尽量食用少油少盐食物".replace("key1",content_notice));
                    }
                    imUtil.sendPatientSystemMessage(messageDO.getReceiver(),JSON.toJSONString(messageDO,SerializerFeature.WriteMapNullValue));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
@ -398,6 +448,44 @@ public class DeviceService {
                    }
                    patientHealthIndex.setDel("1");
                    healthIndexDao.save(patientHealthIndex);
                    SystemMessageDO messageDO = new SystemMessageDO();
                    String typeName = "您有新的血压测量记录:收缩压:"+patientHealthIndex.getValue1()+"mmHg,收缩压:"
                            +patientHealthIndex.getValue2()+"mmHg,脉搏:"+patientHealthIndex.getValue3()+"次/min";
                    messageDO.setTitle(typeName);
                    messageDO.setType("52");//52体征测量
                    messageDO.setSender("system");
                    messageDO.setSenderName("养护助手");
                    messageDO.setRelationCode(patientHealthIndex.getId() + "");
                    messageDO.setReceiver(patientDO.getId());
                    messageDO.setReceiverName(patientDO.getName());
                    messageDO.setOver("1");
                    messageDO.setCode("2");//与体征类型对应
                    JSONArray errorIndex = healthIndexUtil.verifyHealthIndex(2,patientHealthIndex.getValue1(),patientHealthIndex.getValue2(),patientHealthIndex.getValue3());
                    messageDO.setData(JSON.toJSONString(errorIndex,SerializerFeature.WriteNullStringAsEmpty));
                    messageDO.setDel("1");
                    messageDO.setCreateTime(new Date());
                    systemMessageDao.save(messageDO);
                    //推送socket
                    com.alibaba.fastjson.JSONObject message = new com.alibaba.fastjson.JSONObject();
                    message.put("title","您刚刚测量了一次血压");
                    message.put("code",messageDO.getCode());
                    message.put("content",messageDO.getData());
                    message.put("relation_code",messageDO.getRelationCode());
                    message.put("content_type",42);
                    message.put("content_notice","");
                    String content_notice = null;
                    for (int i=0;i<errorIndex.size();i++){
                        com.alibaba.fastjson.JSONObject tmp = errorIndex.getJSONObject(i);
                        if (tmp.getBooleanValue("error")){
                            content_notice += tmp.getString("indexName"+"、");
                        }
                    }
                    if (org.apache.commons.lang3.StringUtils.isNotBlank(content_notice)){
                        content_notice.substring(0,content_notice.length()-2);
                        message.put("content_notice","您的key1过高,请注意饮食,尽量食用少油少盐食物".replace("key1",content_notice));
                    }
                    imUtil.sendPatientSystemMessage(messageDO.getReceiver(),JSON.toJSONString(messageDO,SerializerFeature.WriteMapNullValue));
                }
            }

+ 71 - 1
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/DeviceUploadService.java

@ -1,5 +1,8 @@
package com.yihu.jw.care.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.care.dao.device.DeviceDetailDao;
import com.yihu.jw.care.dao.device.DeviceInfoDao;
@ -11,9 +14,14 @@ import com.yihu.jw.entity.care.device.DeviceDetail;
import com.yihu.jw.entity.care.device.DeviceInfo;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.device.DevicePatientHealthIndex;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.healthIndex.HealthIndexUtil;
import com.yihu.jw.utils.StringUtil;
import jdk.management.resource.internal.inst.FileOutputStreamRMHooks;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@ -44,8 +52,14 @@ public class DeviceUploadService {
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private DevicePatientHealthIndexDao patientHealthIndexDao;
    @Autowired
    private SystemMessageDao systemMessageDao;
    @Autowired
    private HealthIndexUtil healthIndexUtil;
    @Autowired
    private ImUtil imUtil;
    public Result uploadDevicesData(String dataJson) {
    public Result uploadDevicesData(String dataJson)throws Exception {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            Map<String, Object> map = objectMapper.readValue(dataJson, Map.class);
@ -102,6 +116,62 @@ public class DeviceUploadService {
                logger.info("This device is not relate patient!:====="+dataJson);
                throw new Exception("This device is not relate patient!");
            }
            //保存消息
            BasePatientDO patientDO = patientDao.findById(result.getUser());
            if (null != patientDO){
                SystemMessageDO messageDO = new SystemMessageDO();
                String typeName = null;
                String typeName2 = null;
                switch (type){
                    case "1":
                        typeName = "您有新的血糖测量记录:血糖浓度:"+result.getValue1()+"mmol/L";
                        typeName2 = "您刚刚测量了一次血糖";
                        break;
                    case "2":
                        typeName = "您有新的血压测量记录:收缩压:"+result.getValue1()+"mmHg,收缩压:"
                                +result.getValue2()+"mmHg,脉搏:"+result.getValue3()+"次/min";
                        typeName2 = "您刚刚测量了一次血压";
                        break;
                }
                if (StringUtils.isNotBlank(typeName)){
                    messageDO.setTitle(typeName);
                    messageDO.setType("42");//42体征设备测量
                    messageDO.setSender("system");
                    messageDO.setSenderName("养护助手");
                    messageDO.setRelationCode(result.getId()+"");
                    messageDO.setReceiver(patientDO.getId());
                    messageDO.setReceiverName(patientDO.getName());
                    messageDO.setOver("1");
                    messageDO.setCode(type);//与体征类型对应
                    JSONArray errorIndex = healthIndexUtil.verifyHealthIndex(Integer.parseInt(type),result.getValue1(),result.getValue2(),
                            result.getValue3(),result.getValue4(),result.getValue5(),result.getValue6(),
                            result.getValue7());
                    messageDO.setData(JSON.toJSONString(errorIndex,SerializerFeature.WriteNullStringAsEmpty));
                    messageDO.setDel("1");
                    messageDO.setCreateTime(new Date());
                    systemMessageDao.save(messageDO);
                    //推送socket
                    com.alibaba.fastjson.JSONObject message = new com.alibaba.fastjson.JSONObject();
                    message.put("title",typeName2);
                    message.put("code",messageDO.getCode());
                    message.put("content",messageDO.getData());
                    message.put("relation_code",messageDO.getRelationCode());
                    message.put("content_type",42);
                    message.put("content_notice","");
                    String content_notice = null;
                    for (int i=0;i<errorIndex.size();i++){
                        com.alibaba.fastjson.JSONObject tmp = errorIndex.getJSONObject(i);
                        if (tmp.getBooleanValue("error")){
                            content_notice += tmp.getString("indexName"+"、");
                        }
                    }
                    if (StringUtils.isNotBlank(content_notice)){
                        content_notice.substring(0,content_notice.length()-2);
                        message.put("content_notice","您的key1过高,请注意饮食,尽量食用少油少盐食物".replace("key1",content_notice));
                    }
                    imUtil.sendPatientSystemMessage(messageDO.getReceiver(),JSON.toJSONString(messageDO,SerializerFeature.WriteMapNullValue));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());