Browse Source

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

humingfen 7 years ago
parent
commit
86edb46363
16 changed files with 991 additions and 688 deletions
  1. 27 2
      common/common-entity/src/main/java/com/yihu/wlyy/entity/wechat/WechatTemplate.java
  2. 7 1
      patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/controller/DeviceController.java
  3. 704 0
      patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/service/AsyncService.java
  4. 28 660
      patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/service/DeviceService.java
  5. 79 4
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/bank/CreditLogService.java
  6. 79 12
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/bank/TaskService.java
  7. 2 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java
  8. 2 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/SignWebService.java
  9. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statisticsES/StatisticsESService.java
  10. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/HttpClientUtil.java
  11. 13 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/account/PatientController.java
  12. 15 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/bank/TaskController.java
  13. 20 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/health/bank/AccountController.java
  14. 6 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/WechatCoreController.java
  15. 6 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/process/WeiXinEventProcess.java
  16. 1 0
      patient-co/patient-co-wlyy/src/main/resources/application-dev.yml

+ 27 - 2
common/common-entity/src/main/java/com/yihu/wlyy/entity/wechat/WechatTemplate.java

@ -31,7 +31,17 @@ public class WechatTemplate extends IdEntity {
     * 详细内容
     */
    private Map<String,WechatTemplateData> data;
    
    /**
     * 所需跳转到的小程序appid
     */
    private String appId;
    /**
     * 所需跳转到小程序的具体页面路径,支持带参数
     */
    private String pagePath;
    public String getTemplate_id() {
        return template_id;
    }
@ -62,5 +72,20 @@ public class WechatTemplate extends IdEntity {
    public void setData(Map<String, WechatTemplateData> data) {
        this.data = data;
    }
    
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    public String getPagePath() {
        return pagePath;
    }
    public void setPagePath(String pagePath) {
        this.pagePath = pagePath;
    }
}

+ 7 - 1
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/controller/DeviceController.java

@ -8,6 +8,8 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -26,6 +28,8 @@ import java.util.Map;
@Api(value = "设备相关服务", description = "设备相关服务")
public class DeviceController {
    private static Logger logger = LoggerFactory.getLogger(DeviceController.class);
    @Resource(name = DeviceService.BEAN_ID)
    DeviceService deviceService;
@ -55,7 +59,7 @@ public class DeviceController {
            @RequestParam(value = "data", required = true)  String data)
    {
        try{
            System.out.println("typeId="+typeId+";data="+data);
            logger.info("typeId="+typeId+";data="+data);
            return deviceService.uploadDevicesData(data);
        }
@ -113,6 +117,7 @@ public class DeviceController {
            json.put("pul",pul);
            json.put("ano",ano);
            json.put("time",time);
            logger.info("三诺血压="+json.toString());
            return deviceService.threeNodeUpload("2",json);
        }
        catch (Exception ex)
@ -157,6 +162,7 @@ public class DeviceController {
            json.put("testTime",testTime);
            json.put("tempTur",tempTur);
            json.put("codenum",codenum);
            logger.info("三诺血糖="+json.toString());
            return deviceService.threeNodeUpload("1",json);
        }
        catch (Exception ex)

+ 704 - 0
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/service/AsyncService.java

@ -0,0 +1,704 @@
package com.yihu.hos.device.service;
import com.alibaba.fastjson.JSON;
import com.yihu.hos.device.common.configuration.HealthStandardConfig;
import com.yihu.hos.device.common.configuration.SystemConfig;
import com.yihu.hos.device.common.dao.*;
import com.yihu.hos.device.common.http.HttpClientUtil;
import com.yihu.hos.device.common.http.HttpHelper;
import com.yihu.hos.device.common.http.HttpResponse;
import com.yihu.hos.device.common.util.DateUtil;
import com.yihu.hos.device.common.util.ImUtill;
import com.yihu.hos.device.common.util.MessageType;
import com.yihu.hos.device.model.*;
import com.yihu.hos.device.task.PushMsgTask;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.*;
/**
 * 异步方法,减少体征数据接收主线程压力
 * @author yeshijie on 2018/7/27.
 */
@Service("AsyncService")
public class AsyncService extends BaseService{
    private static Logger logger = LoggerFactory.getLogger(AsyncService.class);
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private PatientDeviceDao patientDeviceDao;
    @Value("${systemConfig.server_url}")
    private String wlyyService;
    @Autowired
    private HttpClientUtil HttpClientUtil;
    @Autowired
    private ConsultTeamDao consultTeamDao;
    @Autowired
    private ImUtill ImUtill;
    @Autowired
    private IotDeviceService iotDeviceService;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private DoctorSwitchDao doctorSwitchDao;
    @Autowired
    private TrackPatientDao trackPatientDao;
    @Autowired
    private PatientAimBloodSuggerDao patientAimBloodSuggerDao;
    @Autowired
    private PatientAimBloodPressureDao patientAimBloodPressureDao;
    @Autowired
    private SystemConfig systemConfig;
    @Autowired
    private HttpHelper httpHelper;
    @Autowired
    private PatientHealthStandardDao patientHealthStandardDao;
    @Autowired
    private HealthStandardConfig healthStandardConfig;
    @Autowired
    private MessageService messageService;
    @Autowired
    private MessageDao messageDao;
    @Autowired
    private PushMsgTask pushMsgTask;
    /**
     * 校验指标是否超标,发送消息
     */
    @Async
    public void verifyHealthIndex(PatientHealthIndex data) {
        try{
            //指标信息
            String patientCode = data.getUser();
            //患者信息
            Patient patient = patientDao.findByCode(patientCode);
            int type = data.getType();
            String msgContent = "";
            //血糖校验
            if (type == 1) {
                // 血糖记录,查询患者血糖预警值
                PatientHealthStandard standard = patientHealthStandardDao.findByPatientType(patientCode, 1);
                Double maxValueBefore = healthStandardConfig.getXt_max_before();
                Double minValueBefore = healthStandardConfig.getXt_min_before();
                Double maxValueAfter = healthStandardConfig.getXt_max_after();
                Double minValueAfter = healthStandardConfig.getXt_min_after();
                if (standard != null) {
                    if (standard.getMaxValue1() > 0) {
                        maxValueBefore = standard.getMaxValue1();
                    }
                    if (standard.getMinValue1() > 0) {
                        minValueBefore = standard.getMinValue1();
                    }
                    if (standard.getMaxValue2() > 0) {
                        maxValueAfter = standard.getMaxValue2();
                    }
                    if (standard.getMinValue2() > 0) {
                        minValueAfter = standard.getMinValue2();
                    }
                }
                int index = Integer.valueOf(data.getValue2());
                String value1 = data.getValue1();
                // 餐后
                if (index % 2 == 0) {
                    if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter )) {
//                    msgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L),请处理";
                        if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==1){
                            msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏高</span>";
                        }else if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==2){
                            msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏低</span>";
                        }
                        //体征异常,更新体征数据状态
//                    data.setStatus(1);
//                    patientHealthIndexDao.save(data);
                        iotDeviceService.updateStatus(data);
                    }
                } else { //餐前
                    if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueBefore, minValueBefore)) {
//                    msgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L),请处理";
                        if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==1){
                            msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏高</span>";
                        }else if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==2){
                            msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏低</span>";
                        }
                        //体征异常,更新体征数据状态
//                    data.setStatus(1);
//                    patientHealthIndexDao.save(data);
                        iotDeviceService.updateStatus(data);
                    }
                }
            }
            //血压校验
            else if (type == 2) {
                String value1 = data.getValue1();
                String value2 = data.getValue2();
                // 血压记录,查询患者血压预警值
                PatientHealthStandard standard = patientHealthStandardDao.findByPatientType(patientCode, 2);
                Double maxValueSSY = healthStandardConfig.getSsy_max();
                Double minValueSSY = healthStandardConfig.getSsy_min();
                Double maxValueSZY = healthStandardConfig.getSzy_max();
                Double minValueSZY = healthStandardConfig.getSzy_min();
                if (standard != null) {
                    if (standard.getMaxValue1() > 0) {
                        maxValueSSY = standard.getMaxValue1();
                    }
                    if (standard.getMinValue1() > 0) {
                        minValueSSY = standard.getMinValue1();
                    }
                    if (standard.getMaxValue2() > 0) {
                        maxValueSZY = standard.getMaxValue2();
                    }
                    if (standard.getMinValue2() > 0) {
                        minValueSZY = standard.getMinValue2();
                    }
                }
                // 收缩压/舒张压校验
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY) || !checkHealthIndex(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)) {
//                msgContent = patient.getName() + "血压异常(舒张压 " + value2 + "mmHg、收缩压 " + value1 + "mmHg),请处理";
                    if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY)==1||checkHealthIndexDetail(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)==1){
                        msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血压偏高</span>";
                    }else if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY)==2||checkHealthIndexDetail(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)==2){
                        msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血压偏低</span>";
                    }
                    //体征异常,更新体征数据状态
//                data.setStatus(1);
//                patientHealthIndexDao.save(data);
                    iotDeviceService.updateStatus(data);
                }
            }
            //超标则发送消息
            if (msgContent != null && msgContent.length() > 0) {
                sendMessage(msgContent, patient, data);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 判断当前指标是否正常
     */
    private boolean checkHealthIndex(Double current, Double max, Double min) {
        if (current > max || current < min || current < 0) {
            return false;
        }
        return true;
    }
    /**
     * 判断当前指标偏高或偏低
     */
    private int checkHealthIndexDetail(Double current, Double max, Double min) {
        if (current > max ) {
            return 1;
        }else if(current < min || current < 0){
            return 2;
        }
        return 0;
    }
    /**
     * 推送信息
     */
    private void sendMessage(String content, Patient patient, PatientHealthIndex model) {
        String patientCode = patient.getCode();
        // 消息接收者
        List<String> receivers = new ArrayList<String>();
        // 查询病人家庭签约的健康管理师
        SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patientCode);
        String healthDoctorFamily = "";
        String doctorFamily = "";
        if (signFamily != null) {
            healthDoctorFamily = signFamily.getDoctorHealth();
            doctorFamily = signFamily.getDoctor();
            if (StringUtils.isNotEmpty(healthDoctorFamily)) {
                // 添加到消息接收人列表
                receivers.add(healthDoctorFamily);
            } else if (StringUtils.isNotEmpty(doctorFamily)){
                // 添加到消息接收人列表
                receivers.add(doctorFamily);
            }
        }
        // 查询病人三师签约中的健康管理师
        SignFamily signFamilySS = signFamilyDao.findBySanshiPatientYes(patientCode);
        if (signFamilySS != null) {
            String healthDoctorTeam = signFamilySS.getDoctorHealth();
            // 判断是否是否是同一个健康管理师
            if (StringUtils.isNotEmpty(healthDoctorTeam) && !StringUtils.equals(healthDoctorFamily, healthDoctorTeam)) {
                // 添加到消息接收人列表
                receivers.add(healthDoctorTeam);
            }
            if (StringUtils.isNotEmpty(signFamilySS.getDoctor())){
                receivers.add(signFamilySS.getDoctor());
            }
        }
        List<Message> messages = new ArrayList<Message>();
        JSONArray array = new JSONArray();
        for (String receiver : receivers) {
            if (StringUtils.isEmpty(receiver)) {
                continue;
            }
            // 保存异常消息
            Message message = new Message();
            message.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
            message.setCzrq(new Date());
            message.setCreateTime(new Date());
            message.setRead(1);
            message.setOver("1");
            message.setReceiver(receiver);
            message.setSender(patientCode);
            message.setSex(patient.getSex());
            message.setSenderName(patient.getName());
            message.setSenderPhoto(patient.getPhoto());
            message.setTitle("预警值信息");
            message.setContent(content);
            message.setType(2);
            message.setValue1(Double.valueOf(model.getValue1()));
            message.setValue2(Double.valueOf(model.getValue2()));
            message.setTzCode(String.valueOf(model.getId()));//消息关联的体征id
            message.setTzType(String.valueOf(model.getType()));//体征类别 (1血糖,2血压,3体重,4腰围)
            messages.add(message);
            if(messageService.getMessageNoticeSettingByMessageType(receiver,"1",MessageNoticeSetting.MessageTypeEnum.healthSignSwitch.getValue())){
                // 异常通知
                JSONObject json = new JSONObject();
                json.put("receiver", receiver);
                json.put("type", MessageType.MESSAGE_TYPE_DOCTOR_HEALTH_INDEX.D_HI_01.name());
                json.put("title", MessageType.MESSAGE_TYPE_DOCTOR_HEALTH_INDEX.体征指标.name());
                json.put("msg", content);
                json.put("data", "");
                array.add(json);
            }
        }
        // 批量保存消息
        messageDao.save(messages);
        // 推送消息给医生
        pushMsgTask.put(array);
    }
    /**
     * 指标数据上传基卫
     */
    @Async
    public void uploadHealthIndex(PatientHealthIndex data) {
        try {
            String url = systemConfig.getJwServer() + "/third/archives/uploadHealthIndex";
            Map<String, Object> params = new HashedMap();
            params.put("id", data.getId());
            HttpResponse response = httpHelper.post(url, params);
            if (response != null && response.getStatusCode() == 200) {
                JSONObject json = JSONObject.fromObject(response.getBody());
                if (!"200".equals(json.optString("status"))) {
                    throw new Exception(json.optString("msg"));
                }
            } else {
                throw new Exception("接口调用错误!" + response.getBody());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    /**
     * 预警
     * @param patientCode
     * @param patient
     */
    @Async
    public void yujing(String patientCode,Patient patient){
        try{
            String patientsql = "select group_concat(label) disease from wlyy.wlyy_sign_patient_label_info where label_type = 3 and status=1 and (label = 1 or label = 2) and patient = '"+patient.getCode()+"' GROUP BY patient";
            String patientdisease = jdbcTemplate.queryForObject(patientsql,String.class);
            //连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----START
            int bloodPressureBbnormalCount = 0;//血压异常次数
            int bloodSuggurBbnormalCount = 0;//血糖异常次数
            int stdbloodPressureBbnormalCount = 0;//血压次数
            int stdbloodSuggurBbnormalCount = 0;//血糖次数
            List<PatientHealthIndex> bloodPressurepatientHealthIndices = new ArrayList<>();
            List<PatientHealthIndex> bloodSuggurpatientHealthIndices = new ArrayList<>();
//            bloodPressurepatientHealthIndices = patientHealthIndexDao.findByPatientAndTypeByPage(patientCode,2);
//            bloodSuggurpatientHealthIndices = patientHealthIndexDao.findByPatientAndTypeByPage(patientCode,1);
            bloodPressurepatientHealthIndices = iotDeviceService.findByPatientAndTypeByPage(patientCode,2);
            bloodSuggurpatientHealthIndices = iotDeviceService.findByPatientAndTypeByPage(patientCode,1);
            if(!bloodPressurepatientHealthIndices.isEmpty()){
                stdbloodPressureBbnormalCount = bloodPressurepatientHealthIndices.size();
            }
            if(!bloodSuggurpatientHealthIndices.isEmpty()){
                stdbloodSuggurBbnormalCount = bloodSuggurpatientHealthIndices.size();
            }
            for (PatientHealthIndex index1 : bloodPressurepatientHealthIndices) {
                if(index1.getStatus() != null && 1 == index1.getStatus()){
                    bloodPressureBbnormalCount++;
                }
            }
            for (PatientHealthIndex index2 : bloodSuggurpatientHealthIndices) {
                if(index2.getStatus() != null && 1 == index2.getStatus()){
                    bloodSuggurBbnormalCount++;
                }
            }
            //连续3次异常,修改用户为预警状态
            if( (bloodPressureBbnormalCount >=3 || bloodSuggurBbnormalCount >=3)){
                patient.setStandardStatus(1);
                //1.4.2加入重点关注逻辑
                setTrackPatientByDoctor(patientCode);
            }else{
                Date end = new Date();
                Date start = DateUtil.setDateTime(end,-7);
                //计算血糖或者血压一周内的异常记录数量
//                int errorCount = patientHealthIndexDao.getCountByTimeAndStatus(start,end,1,patientCode);
                int errorCount = iotDeviceService.getCountByTimeAndStatus(start,end,1,patientCode);
                if(errorCount >= 5){//超过5次,记为预警状态
                    patient.setStandardStatus(1);
                    //1.4.2加入重点关注逻辑
                    setTrackPatientByDoctor(patientCode);
                }
            }
            //连续5次正常,修改用户为非预警状态
            if(StringUtils.isNotBlank(patientdisease)){
                if("1".equals(patientdisease)){
                    if(stdbloodPressureBbnormalCount==5&&0 == bloodPressureBbnormalCount){
                        patient.setStandardStatus(0);
                        //1.4.2加入重点关注逻辑
                        cancalTrackPatientByDoctor(patientCode);
                    }
                }else if("2".equals(patientdisease)){
                    if(stdbloodSuggurBbnormalCount==5&&0 == bloodSuggurBbnormalCount){
                        patient.setStandardStatus(0);
                        //1.4.2加入重点关注逻辑
                        cancalTrackPatientByDoctor(patientCode);
                    }
                }else if( "1,2".equals(patientdisease) || "2,1".equals(patientdisease)){
                    if(stdbloodSuggurBbnormalCount==5&&stdbloodPressureBbnormalCount==5&&0 == bloodSuggurBbnormalCount && 0 == bloodPressureBbnormalCount){
                        patient.setStandardStatus(0);
                        //1.4.2加入重点关注逻辑
                        cancalTrackPatientByDoctor(patientCode);
                    }
                }
            }else{
                patient.setStandardStatus(0);
                //1.4.2加入重点关注逻辑
                cancalTrackPatientByDoctor(patientCode);
            }
            patientDao.save(patient);
            //连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----END
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 判断是否有未结束的续方咨询,发送消息给对应的医生
     * @param result
     * @param patient
     */
    @Async
    public void sendPrescriptionHealthIndexMsgresult(PatientHealthIndex result, Patient patient) {
        try{
            List<ConsultTeam> consultTeams = consultTeamDao.findUnfinishedConsult(patient.getCode());
            for (ConsultTeam consultTeam:consultTeams) {
                if(consultTeam.getHealthindexType() != null){
                    org.json.JSONObject contentPatient = new org.json.JSONObject();
                    //患者发送的消息
                    contentPatient.put("title", "【本消息为系统提醒】:");
                    if(1 == result.getType()){
                        contentPatient.put("tzMsg", "体征记录:血糖 "+result.getValue1()+" mmol/L");
                        contentPatient.put("type",2);
                    }else if(2 == result.getType()){
                        contentPatient.put("tzMsg", "体征记录:血压 "+result.getValue1()+"/"+result.getValue2()+" mmHg");
                        contentPatient.put("type",1);
                    }else{}
                    contentPatient.put("tzTime", "检测时间:"+DateUtil.dateToStrLong(result.getRecordDate()));
                    contentPatient.put("tzAlert","温馨提示:本条体征为居民上传的健康体征数据,您可以");
                    contentPatient.put("needUpload","false");
                    contentPatient.put("healthindexid",result.getId());//体征记录 ID
                    //患者发送Im消息
                    ImUtill.sendTopicIM(patient.getCode(), patient.getName(), consultTeam.getConsult(), "16", contentPatient.toString(), null);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 添加积分
     * @param deviceSn
     * @param type
     * @param userType
     * @param patientCode
     * @param deviceType
     */
    @Async
    public void addIntegral(String deviceSn,String type,String userType,String patientCode,Integer deviceType){
        try {
            SignFamily signFamily = signFamilyDao.findByPatient(patientCode);
            String hospital = "";
            if (signFamily!=null){
                hospital = signFamily.getHospital();
            }
            String flagStr = "";
            if (deviceType==1){
                flagStr="BP_MEASURE";
            }else if (deviceType==2){
                flagStr="GLU_MEASURE";
            }
            int dataUoloadCount = 0;
            PatientDevice patientDevice = patientDeviceDao.findByDeviceSnAndCategoryCodeAndUserType(deviceSn,type,userType);
            if (patientDevice!=null){
                String today = DateUtil.getStringDateShort();
                String startTime = today+" 00:00:00";
                String endTime = today+" 23:59:59";
                int dateType =1;
                if (deviceType==1){
                    dateType=2;
                }else if (deviceType==2){
                    dateType=1;
                }
                String countSql = "SELECT count(*) num FROM device.wlyy_patient_health_index where `user`='"+patientDevice.getUser()+"' and type = "+dateType+" AND record_date >'"+startTime+"' and record_date <= '"+endTime+"'";
                Map<String,Object> countMap = jdbcTemplate.queryForMap(countSql);
                dataUoloadCount = Integer.valueOf(String.valueOf(countMap.get("num")));
            }
            //增加积分
            if (dataUoloadCount == 0 && "350205".equals(hospital.substring(0,6))){
                String sql = "select count(*) num from device.wlyy_devices where device_code = '"+deviceSn+"'";
                Map<String,Object> deviceCountMap = jdbcTemplate.queryForMap(sql);
                if (Integer.valueOf(String.valueOf(deviceCountMap.get("num")))>0){
                    String url = wlyyService + "healthBank/insertCredits";
                    List<NameValuePair> params = new ArrayList<>();
                    params.add(new BasicNameValuePair("creditsDetail", "{\"tradeType\":\"ACTIVITY_TASK\",\"flag\":\""+flagStr+"\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+patientCode+"\",\"hospital\":\"350205\"}"));
                    String response = HttpClientUtil.post(url, params, "UTF-8");
                    com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
                    String status = jsonObject.getString("status");
                    if (!"200".equals(status)){
                        logger.error(jsonObject.getString("msg"));
                    }
                }
            }
            //增加活跃度
            if (dataUoloadCount == 0){
                String url = wlyyService + "healthBank/createActiveRecord";
                List<NameValuePair> params = new ArrayList<>();
                params.add(new BasicNameValuePair("activeRecord", "{\"taskCode\":\""+flagStr+"\",\"patientId\":\""+patientCode+"\"}"));
                String response = HttpClientUtil.post(url, params, "UTF-8");
                if (StringUtils.isNotEmpty(response)){
                    com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(response);
                    if (!"200".equals(jsonObject.getString("status"))){
                        logger.info("添加活跃度失败!");
                    }
                }
            }
        }catch (Exception e){
            logger.error(e.getMessage());
        }
    }
    /**
     * 设置
     * @param patient
     * @return
     */
    public int setTrackPatientByDoctor(String patient){
        SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patient);
        if(signFamily==null){
            return -1;
        }
        Patient p = patientDao.findByCode(patient);
        if(p==null){
            return -1;
        }
        //医生是否自动追踪居民
        DoctorSwitch sw =  doctorSwitchDao.findByDoctor(signFamily.getDoctor());
        DoctorSwitch swh =  doctorSwitchDao.findByDoctor(signFamily.getDoctorHealth());
        if(sw!=null){
            if("1".equals(sw.getAlertPatientSwitch())){
                //查询是否与医生建立重点跟踪关系,诺无关系则建立
                TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctor(),patient);
                if(trackPatient == null){
                    TrackPatient t = new TrackPatient();
                    t.setCreateTime(new Date());
                    t.setDoctorCode(signFamily.getDoctor());
                    t.setDoctorName(signFamily.getDoctorName());
                    t.setIdcard(signFamily.getIdcard());
                    t.setSsc(signFamily.getSsc());
                    t.setTeamCode(signFamily.getAdminTeamId().intValue());
                    t.setPatientCode(patient);
                    t.setPatientName(p.getName());
                    t.setDel("1");
                    trackPatientDao.save(t);
                }else{
                    trackPatient.setDel("1");
                    trackPatientDao.save(trackPatient);
                }
            }
        }
        if(swh!=null){
            if("1".equals(swh.getAlertPatientSwitch())){
                //查询是否与医生建立重点跟踪关系,诺无关系则建立
                TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctorHealth(),patient);
                if(trackPatient == null){
                    TrackPatient t = new TrackPatient();
                    t.setCreateTime(new Date());
                    t.setDoctorCode(signFamily.getDoctorHealth());
                    t.setDoctorName(signFamily.getDoctorHealthName());
                    t.setIdcard(signFamily.getIdcard());
                    t.setSsc(signFamily.getSsc());
                    t.setTeamCode(signFamily.getAdminTeamId().intValue());
                    t.setPatientCode(patient);
                    t.setPatientName(p.getName());
                    t.setDel("1");
                    trackPatientDao.save(t);
                }else{
                    trackPatient.setDel("1");
                    trackPatientDao.save(trackPatient);
                }
            }
        }
        return 1;
    }
    public int cancalTrackPatientByDoctor(String patient){
        SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patient);
        if(signFamily==null){
            return -1;
        }
        Patient p = patientDao.findByCode(patient);
        if(p==null){
            return -1;
        }
        //医生是否自动追踪居民
        DoctorSwitch sw =  doctorSwitchDao.findByDoctor(signFamily.getDoctor());
        DoctorSwitch swh =  doctorSwitchDao.findByDoctor(signFamily.getDoctorHealth());
        if(sw!=null){
            if("1".equals(sw.getAlertPatientSwitch())){
                //查询是否与医生建立重点跟踪关系,诺无关系则建立
                TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctor(),patient);
                if(trackPatient == null){
                    TrackPatient t = new TrackPatient();
                    t.setCreateTime(new Date());
                    t.setDoctorCode(signFamily.getDoctor());
                    t.setDoctorName(signFamily.getDoctorName());
                    t.setIdcard(signFamily.getIdcard());
                    t.setSsc(signFamily.getSsc());
                    t.setTeamCode(signFamily.getAdminTeamId().intValue());
                    t.setPatientCode(patient);
                    t.setPatientName(p.getName());
                    t.setDel("0");
                    trackPatientDao.save(t);
                    //设置默认控制目标
                    setDefaultAim(patient);
                }else{
                    trackPatient.setDel("0");
                    trackPatientDao.save(trackPatient);
                }
            }
        }
        if(swh!=null){
            if("1".equals(swh.getAlertPatientSwitch())){
                //查询是否与医生建立重点跟踪关系,诺无关系则建立
                TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctorHealth(),patient);
                if(trackPatient == null){
                    TrackPatient t = new TrackPatient();
                    t.setCreateTime(new Date());
                    t.setDoctorCode(signFamily.getDoctorHealth());
                    t.setDoctorName(signFamily.getDoctorHealthName());
                    t.setIdcard(signFamily.getIdcard());
                    t.setSsc(signFamily.getSsc());
                    t.setTeamCode(signFamily.getAdminTeamId().intValue());
                    t.setPatientCode(patient);
                    t.setPatientName(p.getName());
                    t.setDel("0");
                    trackPatientDao.save(t);
                    //设置默认控制目标
                    setDefaultAim(patient);
                }else{
                    trackPatient.setDel("0");
                    trackPatientDao.save(trackPatient);
                }
            }
        }
        return 1;
    }
    /**
     * 设置默认监控方案
     * @param patient
     * @return
     */
    public String setDefaultAim(String patient){
        PatientAimBloodSugger patientAimBloodSugger = patientAimBloodSuggerDao.findByPatientcode(patient);
        PatientAimBloodPressure patientAimBloodPressure =  patientAimBloodPressureDao.findByPatientcode(patient);
        if(patientAimBloodSugger==null){
            PatientAimBloodSugger pa = new PatientAimBloodSugger();
            pa.setPatientcode(patient);
            pa.setCode(getCode());
            pa.setCreateTime(new Date());
            pa.setUnit("mmol/L");
            pa.setFbg("7.0");
            pa.setHpg("11.1");
            pa.setFbgMin("4.0");
            pa.setHpgMin("4.0");
            patientAimBloodSuggerDao.save(pa);
        }
        if(patientAimBloodPressure==null){
            PatientAimBloodPressure pa = new PatientAimBloodPressure();
            pa.setPatientcode(patient);
            pa.setCode(getCode());
            pa.setCreateTime(new Date());
            pa.setSbp("140");
            pa.setSbpMin("90");
            pa.setDbp("90");
            pa.setDbpMin("60");
            pa.setUnit("mmHg");
            patientAimBloodPressureDao.save(pa);
        }
        return "1";
    }
}

+ 28 - 660
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/service/DeviceService.java

@ -1,28 +1,21 @@
package com.yihu.hos.device.service;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.hos.device.common.configuration.HealthStandardConfig;
import com.yihu.hos.device.common.configuration.SystemConfig;
import com.yihu.hos.device.common.dao.*;
import com.yihu.hos.device.common.http.HttpClientUtil;
import com.yihu.hos.device.common.http.HttpHelper;
import com.yihu.hos.device.common.http.HttpResponse;
import com.yihu.hos.device.common.util.*;
import com.yihu.hos.device.common.util.DateUtil;
import com.yihu.hos.device.common.util.ETLConstantData;
import com.yihu.hos.device.common.util.StringUtil;
import com.yihu.hos.device.model.*;
import com.yihu.hos.device.task.PushMsgTask;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
@ -40,54 +33,26 @@ public class DeviceService extends BaseService{
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private DeviceDetailDao deviceDetailDao;
//    @Autowired
//    private PatientHealthIndexDao patientHealthIndexDao;
    /*@Autowired
    private BloodSuggerConfiguration bloodSuggerConfiguration;*/
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private PatientHealthStandardDao patientHealthStandardDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private MessageDao messageDao;
    @Autowired
    private HealthStandardConfig healthStandardConfig;
    @Autowired
    private HttpHelper httpHelper;
    @Autowired
    private HttpClientUtil HttpClientUtil;
    @Autowired
    private SystemConfig systemConfig;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private  PatientBloodSuggerDao patientBloodSuggerDao;
    @Autowired
    private PatientHealthTimeDao patientHealthTimeDao;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private ConsultTeamDao consultTeamDao;
    @Autowired
    private ImUtill ImUtill;
    @Autowired
    private MessageService messageService;
    @Autowired
    private DoctorSwitchDao doctorSwitchDao;
    @Autowired
    private TrackPatientDao trackPatientDao;
    @Value("${systemConfig.server_url}")
    private String wlyyService;
    @Autowired
    private PatientAimBloodSuggerDao patientAimBloodSuggerDao;
    @Autowired
    private PatientAimBloodPressureDao patientAimBloodPressureDao;
    @Autowired
    private IotDeviceService iotDeviceService;
    @Autowired
    private SystemDictDao systemDictDao;
    private AsyncService asyncService;
    private static Logger logger = LoggerFactory.getLogger(DeviceService.class);
    private ObjectMapper objectMapper = new ObjectMapper();
@ -188,17 +153,7 @@ public class DeviceService extends BaseService{
        return "1";//"空腹血糖"
    }
    /*   private Boolean isInArea(String time, String[] timeArea) {
           String date = DateUtil.getDateFromDateTime(time);
           Long beginTime = DateUtil.compareDateTime(DateUtil.toTimestamp(time), DateUtil.toTimestamp(date + " " + timeArea[0] + ":00"));
           Long endTime = DateUtil.compareDateTime(DateUtil.toTimestamp(time), DateUtil.toTimestamp(date + " " + timeArea[1] + ":00"));
           if (beginTime > 0 && endTime < 0) {
               return true;
           } else {
               return false;
           }
       }*/
// 判断时间是否在对应时间段
    // 判断时间是否在对应时间段
    private Boolean isInArea(String time,String begin,String end) {
        String date = DateUtil.getDateFromDateTime(time);
        Long beginTime = DateUtil.compareDateTime(DateUtil.toTimestamp(time), DateUtil.toTimestamp(date + " " + begin ));
@ -210,26 +165,17 @@ public class DeviceService extends BaseService{
        }
    }
    /**
     * 判断当前指标是否正常
     */
    private boolean checkHealthIndex(Double current, Double max, Double min) {
        if (current > max || current < min || current < 0) {
            return false;
        }
        return true;
    }
    /**
     * 判断当前指标偏高或偏低
     */
    private int checkHealthIndexDetail(Double current, Double max, Double min) {
        if (current > max ) {
            return 1;
        }else if(current < min || current < 0){
            return 2;
        }
        return 0;
    }
    /*   private Boolean isInArea(String time, String[] timeArea) {
           String date = DateUtil.getDateFromDateTime(time);
           Long beginTime = DateUtil.compareDateTime(DateUtil.toTimestamp(time), DateUtil.toTimestamp(date + " " + timeArea[0] + ":00"));
           Long endTime = DateUtil.compareDateTime(DateUtil.toTimestamp(time), DateUtil.toTimestamp(date + " " + timeArea[1] + ":00"));
           if (beginTime > 0 && endTime < 0) {
               return true;
           } else {
               return false;
           }
       }*/
    /**************************************************************************************************************/
    /**
     * 设备数据查询接口
@ -336,11 +282,11 @@ public class DeviceService extends BaseService{
            //血糖、血压数据需校验,如果超标,需要发送消息给医生
            if (paramMap.get("type").equals("1") || paramMap.get("type").equals("2")) {
                verifyHealthIndex(result);
                asyncService.verifyHealthIndex(result);
            }
            //指标数据上传基卫
            uploadHealthIndex(result);
            asyncService.uploadHealthIndex(result);
            System.out.println(result);
        } catch (Exception e) {
@ -410,18 +356,16 @@ public class DeviceService extends BaseService{
                Patient patient = patientDao.findByCode(patientCode);
                //血糖、血压数据需校验,如果超标,需要发送消息给医生
                verifyHealthIndex(result);
                asyncService.verifyHealthIndex(result);
                //发送华三demo推送
                //判断是否有未结束的续方咨询,发送消息给对应的医生----huangwenjie--2017.11.06
                sendPrescriptionHealthIndexMsgresult(result,patient);
                asyncService.sendPrescriptionHealthIndexMsgresult(result,patient);
                //指标数据上传基卫
                uploadHealthIndex(result);
                asyncService.uploadHealthIndex(result);
                System.out.println(result);
                yujing(patientCode,patient);
                asyncService.yujing(patientCode,patient);
            }
        } catch (Exception e) {
            e.printStackTrace();
@ -475,101 +419,31 @@ public class DeviceService extends BaseService{
                userType = "-1";
            }
            int dataUoloadCount = 0;
            try {
                PatientDevice patientDevice = patientDeviceDao.findByDeviceSnAndCategoryCodeAndUserType(deviceSn,type,userType);
                if (patientDevice!=null){
                    String today = DateUtil.getStringDateShort();
                    String startTime = today+" 00:00:00";
                    String endTime = today+" 23:59:59";
                    int dateType =1;
                    if (deviceType==1){
                        dateType=2;
                    }else if (deviceType==2){
                        dateType=1;
                    }
                    String countSql = "SELECT count(*) num FROM device.wlyy_patient_health_index where `user`='"+patientDevice.getUser()+"' and type = "+dateType+" AND record_date >'"+startTime+"' and record_date <= '"+endTime+"'";
                    Map<String,Object> countMap = jdbcTemplate.queryForMap(countSql);
                    dataUoloadCount = Integer.valueOf(String.valueOf(countMap.get("num")));
                }else {
                    throw new Exception("This device is not relate patient!");
                }
            }catch (Exception e){
                logger.error(e.getMessage());
            }
            PatientHealthIndex result = savePatientDeviceData(deviceSn, type, data, uploadTime, userType, json);
            if (result == null) {
                throw new Exception("This device is not relate patient!");
            } else {
                //患者信息
                String patientCode = result.getUser();
                SignFamily signFamily = signFamilyDao.findByPatient(patientCode);
                Patient patient = patientDao.findByCode(patientCode);
                String hospital = "";
                if (signFamily!=null){
                    hospital = signFamily.getHospital();
                }
                String flagStr = "";
                if (deviceType==1){
                    flagStr="BP_MEASURE";
                }else if (deviceType==2){
                    flagStr="GLU_MEASURE";
                }
                try {
                    //增加积分
                    if (dataUoloadCount == 0 && "350205".equals(hospital.substring(0,6))){
                        String sql = "select count(*) num from device.wlyy_devices where device_code = '"+deviceSn+"'";
                        Map<String,Object> deviceCountMap = jdbcTemplate.queryForMap(sql);
                        if (Integer.valueOf(String.valueOf(deviceCountMap.get("num")))>0){
                            String url = wlyyService + "healthBank/insertCredits";
                            List<NameValuePair> params = new ArrayList<>();
                            params.add(new BasicNameValuePair("creditsDetail", "{\"tradeType\":\"ACTIVITY_TASK\",\"flag\":\""+flagStr+"\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+result.getUser()+"\",\"hospital\":\"350205\"}"));
                            String response = HttpClientUtil.post(url, params, "UTF-8");
                            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
                            String status = jsonObject.getString("status");
                            if (!"200".equals(status)){
                                logger.error(jsonObject.getString("msg"));
                            }
                        }
                    }
                    //增加活跃度
                    if (dataUoloadCount == 0){
                        String url = wlyyService + "healthBank/createActiveRecord";
                        List<NameValuePair> params = new ArrayList<>();
                        params.add(new BasicNameValuePair("activeRecord", "{\"taskCode\":\""+flagStr+"\",\"patientId\":\""+result.getUser()+"\"}"));
                        String response = HttpClientUtil.post(url, params, "UTF-8");
                        if (StringUtils.isNotEmpty(response)){
                            com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(response);
                            if (!"200".equals(jsonObject.getString("status"))){
                                logger.info("添加活跃度失败!");
                            }
                        }
                    }
                }catch (Exception e){
                    logger.error(e.getMessage());
                }
                Patient patient = patientDao.findByCode(patientCode);
                asyncService.addIntegral(deviceSn,type,userType,patientCode,deviceType);
                //血糖、血压数据需校验,如果超标,需要发送消息给医生
	            if (1 == deviceType || 2 == deviceType) {
		            verifyHealthIndex(result);
                    asyncService.verifyHealthIndex(result);
		            //发送华三demo推送
//                    messagePush(result);
		
		            //判断是否有未结束的续方咨询,发送消息给对应的医生----huangwenjie--2017.11.06
		            sendPrescriptionHealthIndexMsgresult(result,patient);
                    asyncService.sendPrescriptionHealthIndexMsgresult(result,patient);
	            }
                //指标数据上传基卫
                uploadHealthIndex(result);
                asyncService.uploadHealthIndex(result);
                System.out.println(result);
                yujing(patientCode,patient);
                asyncService.yujing(patientCode,patient);
            }
        } catch (Exception e) {
            e.printStackTrace();
@ -579,269 +453,6 @@ public class DeviceService extends BaseService{
        return Result.success("Device data incoming success");
    }
    /**
     * 预警
     * @param patientCode
     * @param patient
     */
    public void yujing(String patientCode,Patient patient){
        try{
            String patientsql = "select group_concat(label) disease from wlyy.wlyy_sign_patient_label_info where label_type = 3 and status=1 and (label = 1 or label = 2) and patient = '"+patient.getCode()+"' GROUP BY patient";
            String patientdisease = jdbcTemplate.queryForObject(patientsql,String.class);
            //连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----START
            int bloodPressureBbnormalCount = 0;//血压异常次数
            int bloodSuggurBbnormalCount = 0;//血糖异常次数
            int stdbloodPressureBbnormalCount = 0;//血压次数
            int stdbloodSuggurBbnormalCount = 0;//血糖次数
            List<PatientHealthIndex> bloodPressurepatientHealthIndices = new ArrayList<>();
            List<PatientHealthIndex> bloodSuggurpatientHealthIndices = new ArrayList<>();
//            bloodPressurepatientHealthIndices = patientHealthIndexDao.findByPatientAndTypeByPage(patientCode,2);
//            bloodSuggurpatientHealthIndices = patientHealthIndexDao.findByPatientAndTypeByPage(patientCode,1);
            bloodPressurepatientHealthIndices = iotDeviceService.findByPatientAndTypeByPage(patientCode,2);
            bloodSuggurpatientHealthIndices = iotDeviceService.findByPatientAndTypeByPage(patientCode,1);
            if(!bloodPressurepatientHealthIndices.isEmpty()){
                stdbloodPressureBbnormalCount = bloodPressurepatientHealthIndices.size();
            }
            if(!bloodSuggurpatientHealthIndices.isEmpty()){
                stdbloodSuggurBbnormalCount = bloodSuggurpatientHealthIndices.size();
            }
            for (PatientHealthIndex index1 : bloodPressurepatientHealthIndices) {
                if(index1.getStatus() != null && 1 == index1.getStatus()){
                    bloodPressureBbnormalCount++;
                }
            }
            for (PatientHealthIndex index2 : bloodSuggurpatientHealthIndices) {
                if(index2.getStatus() != null && 1 == index2.getStatus()){
                    bloodSuggurBbnormalCount++;
                }
            }
            //连续3次异常,修改用户为预警状态
            if( (bloodPressureBbnormalCount >=3 || bloodSuggurBbnormalCount >=3)){
                patient.setStandardStatus(1);
                //1.4.2加入重点关注逻辑
                setTrackPatientByDoctor(patientCode);
            }else{
                Date end = new Date();
                Date start = DateUtil.setDateTime(end,-7);
                //计算血糖或者血压一周内的异常记录数量
//                int errorCount = patientHealthIndexDao.getCountByTimeAndStatus(start,end,1,patientCode);
                int errorCount = iotDeviceService.getCountByTimeAndStatus(start,end,1,patientCode);
                if(errorCount >= 5){//超过5次,记为预警状态
                    patient.setStandardStatus(1);
                    //1.4.2加入重点关注逻辑
                    setTrackPatientByDoctor(patientCode);
                }
            }
            //连续5次正常,修改用户为非预警状态
            if(StringUtils.isNotBlank(patientdisease)){
                if("1".equals(patientdisease)){
                    if(stdbloodPressureBbnormalCount==5&&0 == bloodPressureBbnormalCount){
                        patient.setStandardStatus(0);
                        //1.4.2加入重点关注逻辑
                        cancalTrackPatientByDoctor(patientCode);
                    }
                }else if("2".equals(patientdisease)){
                    if(stdbloodSuggurBbnormalCount==5&&0 == bloodSuggurBbnormalCount){
                        patient.setStandardStatus(0);
                        //1.4.2加入重点关注逻辑
                        cancalTrackPatientByDoctor(patientCode);
                    }
                }else if( "1,2".equals(patientdisease) || "2,1".equals(patientdisease)){
                    if(stdbloodSuggurBbnormalCount==5&&stdbloodPressureBbnormalCount==5&&0 == bloodSuggurBbnormalCount && 0 == bloodPressureBbnormalCount){
                        patient.setStandardStatus(0);
                        //1.4.2加入重点关注逻辑
                        cancalTrackPatientByDoctor(patientCode);
                    }
                }
            }else{
                patient.setStandardStatus(0);
                //1.4.2加入重点关注逻辑
                cancalTrackPatientByDoctor(patientCode);
            }
            patientDao.save(patient);
            //连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----END
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 设置默认监控方案
     * @param patient
     * @return
     */
    public String setDefaultAim(String patient){
        PatientAimBloodSugger patientAimBloodSugger = patientAimBloodSuggerDao.findByPatientcode(patient);
        PatientAimBloodPressure patientAimBloodPressure =  patientAimBloodPressureDao.findByPatientcode(patient);
        if(patientAimBloodSugger==null){
            PatientAimBloodSugger pa = new PatientAimBloodSugger();
            pa.setPatientcode(patient);
            pa.setCode(getCode());
            pa.setCreateTime(new Date());
            pa.setUnit("mmol/L");
            pa.setFbg("7.0");
            pa.setHpg("11.1");
            pa.setFbgMin("4.0");
            pa.setHpgMin("4.0");
            patientAimBloodSuggerDao.save(pa);
        }
        if(patientAimBloodPressure==null){
            PatientAimBloodPressure pa = new PatientAimBloodPressure();
            pa.setPatientcode(patient);
            pa.setCode(getCode());
            pa.setCreateTime(new Date());
            pa.setSbp("140");
            pa.setSbpMin("90");
            pa.setDbp("90");
            pa.setDbpMin("60");
            pa.setUnit("mmHg");
            patientAimBloodPressureDao.save(pa);
        }
        return "1";
    }
    /**
     * 设置
     * @param patient
     * @return
     */
    public int setTrackPatientByDoctor(String patient){
        SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patient);
        if(signFamily==null){
            return -1;
        }
        Patient p = patientDao.findByCode(patient);
        if(p==null){
            return -1;
        }
        //医生是否自动追踪居民
        DoctorSwitch sw =  doctorSwitchDao.findByDoctor(signFamily.getDoctor());
        DoctorSwitch swh =  doctorSwitchDao.findByDoctor(signFamily.getDoctorHealth());
        if(sw!=null){
            if("1".equals(sw.getAlertPatientSwitch())){
                //查询是否与医生建立重点跟踪关系,诺无关系则建立
                TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctor(),patient);
                if(trackPatient == null){
                    TrackPatient t = new TrackPatient();
                    t.setCreateTime(new Date());
                    t.setDoctorCode(signFamily.getDoctor());
                    t.setDoctorName(signFamily.getDoctorName());
                    t.setIdcard(signFamily.getIdcard());
                    t.setSsc(signFamily.getSsc());
                    t.setTeamCode(signFamily.getAdminTeamId().intValue());
                    t.setPatientCode(patient);
                    t.setPatientName(p.getName());
                    t.setDel("1");
                    trackPatientDao.save(t);
                }else{
                    trackPatient.setDel("1");
                    trackPatientDao.save(trackPatient);
                }
            }
        }
        if(swh!=null){
            if("1".equals(swh.getAlertPatientSwitch())){
                //查询是否与医生建立重点跟踪关系,诺无关系则建立
                TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctorHealth(),patient);
                if(trackPatient == null){
                    TrackPatient t = new TrackPatient();
                    t.setCreateTime(new Date());
                    t.setDoctorCode(signFamily.getDoctorHealth());
                    t.setDoctorName(signFamily.getDoctorHealthName());
                    t.setIdcard(signFamily.getIdcard());
                    t.setSsc(signFamily.getSsc());
                    t.setTeamCode(signFamily.getAdminTeamId().intValue());
                    t.setPatientCode(patient);
                    t.setPatientName(p.getName());
                    t.setDel("1");
                    trackPatientDao.save(t);
                }else{
                    trackPatient.setDel("1");
                    trackPatientDao.save(trackPatient);
                }
            }
        }
        return 1;
    }
    public int cancalTrackPatientByDoctor(String patient){
        SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patient);
        if(signFamily==null){
            return -1;
        }
        Patient p = patientDao.findByCode(patient);
        if(p==null){
            return -1;
        }
        //医生是否自动追踪居民
        DoctorSwitch sw =  doctorSwitchDao.findByDoctor(signFamily.getDoctor());
        DoctorSwitch swh =  doctorSwitchDao.findByDoctor(signFamily.getDoctorHealth());
        if(sw!=null){
            if("1".equals(sw.getAlertPatientSwitch())){
                //查询是否与医生建立重点跟踪关系,诺无关系则建立
                TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctor(),patient);
                if(trackPatient == null){
                    TrackPatient t = new TrackPatient();
                    t.setCreateTime(new Date());
                    t.setDoctorCode(signFamily.getDoctor());
                    t.setDoctorName(signFamily.getDoctorName());
                    t.setIdcard(signFamily.getIdcard());
                    t.setSsc(signFamily.getSsc());
                    t.setTeamCode(signFamily.getAdminTeamId().intValue());
                    t.setPatientCode(patient);
                    t.setPatientName(p.getName());
                    t.setDel("0");
                    trackPatientDao.save(t);
                    //设置默认控制目标
                    setDefaultAim(patient);
                }else{
                    trackPatient.setDel("0");
                    trackPatientDao.save(trackPatient);
                }
            }
        }
        if(swh!=null){
            if("1".equals(swh.getAlertPatientSwitch())){
                //查询是否与医生建立重点跟踪关系,诺无关系则建立
                TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctorHealth(),patient);
                if(trackPatient == null){
                    TrackPatient t = new TrackPatient();
                    t.setCreateTime(new Date());
                    t.setDoctorCode(signFamily.getDoctorHealth());
                    t.setDoctorName(signFamily.getDoctorHealthName());
                    t.setIdcard(signFamily.getIdcard());
                    t.setSsc(signFamily.getSsc());
                    t.setTeamCode(signFamily.getAdminTeamId().intValue());
                    t.setPatientCode(patient);
                    t.setPatientName(p.getName());
                    t.setDel("0");
                    trackPatientDao.save(t);
                    //设置默认控制目标
                    setDefaultAim(patient);
                }else{
                    trackPatient.setDel("0");
                    trackPatientDao.save(trackPatient);
                }
            }
        }
        return 1;
    }
    /**
     * 保存设备数据
     */
@ -1014,195 +625,7 @@ public class DeviceService extends BaseService{
        return obj;
    }
    /**
     * 校验指标是否超标,发送消息
     */
    private void verifyHealthIndex(PatientHealthIndex data) {
        //指标信息
        String patientCode = data.getUser();
        //患者信息
        Patient patient = patientDao.findByCode(patientCode);
        int type = data.getType();
        String msgContent = "";
        //血糖校验
        if (type == 1) {
            // 血糖记录,查询患者血糖预警值
            PatientHealthStandard standard = patientHealthStandardDao.findByPatientType(patientCode, 1);
            Double maxValueBefore = healthStandardConfig.getXt_max_before();
            Double minValueBefore = healthStandardConfig.getXt_min_before();
            Double maxValueAfter = healthStandardConfig.getXt_max_after();
            Double minValueAfter = healthStandardConfig.getXt_min_after();
            if (standard != null) {
                if (standard.getMaxValue1() > 0) {
                    maxValueBefore = standard.getMaxValue1();
                }
                if (standard.getMinValue1() > 0) {
                    minValueBefore = standard.getMinValue1();
                }
                if (standard.getMaxValue2() > 0) {
                    maxValueAfter = standard.getMaxValue2();
                }
                if (standard.getMinValue2() > 0) {
                    minValueAfter = standard.getMinValue2();
                }
            }
            int index = Integer.valueOf(data.getValue2());
            String value1 = data.getValue1();
            // 餐后
            if (index % 2 == 0) {
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter )) {
//                    msgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L),请处理";
                    if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==1){
                        msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏高</span>";
                    }else if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==2){
                        msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏低</span>";
                    }
                    //体征异常,更新体征数据状态
//                    data.setStatus(1);
//                    patientHealthIndexDao.save(data);
                    iotDeviceService.updateStatus(data);
                }
            } else { //餐前
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueBefore, minValueBefore)) {
//                    msgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L),请处理";
                    if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==1){
                        msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏高</span>";
                    }else if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==2){
                        msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏低</span>";
                    }
                    //体征异常,更新体征数据状态
//                    data.setStatus(1);
//                    patientHealthIndexDao.save(data);
                    iotDeviceService.updateStatus(data);
                }
            }
        }
        //血压校验
        else if (type == 2) {
            String value1 = data.getValue1();
            String value2 = data.getValue2();
            // 血压记录,查询患者血压预警值
            PatientHealthStandard standard = patientHealthStandardDao.findByPatientType(patientCode, 2);
            Double maxValueSSY = healthStandardConfig.getSsy_max();
            Double minValueSSY = healthStandardConfig.getSsy_min();
            Double maxValueSZY = healthStandardConfig.getSzy_max();
            Double minValueSZY = healthStandardConfig.getSzy_min();
            if (standard != null) {
                if (standard.getMaxValue1() > 0) {
                    maxValueSSY = standard.getMaxValue1();
                }
                if (standard.getMinValue1() > 0) {
                    minValueSSY = standard.getMinValue1();
                }
                if (standard.getMaxValue2() > 0) {
                    maxValueSZY = standard.getMaxValue2();
                }
                if (standard.getMinValue2() > 0) {
                    minValueSZY = standard.getMinValue2();
                }
            }
            // 收缩压/舒张压校验
            if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY) || !checkHealthIndex(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)) {
//                msgContent = patient.getName() + "血压异常(舒张压 " + value2 + "mmHg、收缩压 " + value1 + "mmHg),请处理";
                if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY)==1||checkHealthIndexDetail(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)==1){
                    msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血压偏高</span>";
                }else if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY)==2||checkHealthIndexDetail(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)==2){
                    msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血压偏低</span>";
                }
                //体征异常,更新体征数据状态
//                data.setStatus(1);
//                patientHealthIndexDao.save(data);
                iotDeviceService.updateStatus(data);
            }
        }
        //超标则发送消息
        if (msgContent != null && msgContent.length() > 0) {
            sendMessage(msgContent, patient, data);
        }
    }
    /**
     * 推送信息
     */
    private void sendMessage(String content, Patient patient, PatientHealthIndex model) {
        String patientCode = patient.getCode();
        // 消息接收者
        List<String> receivers = new ArrayList<String>();
        // 查询病人家庭签约的健康管理师
        SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patientCode);
        String healthDoctorFamily = "";
        String doctorFamily = "";
        if (signFamily != null) {
            healthDoctorFamily = signFamily.getDoctorHealth();
            doctorFamily = signFamily.getDoctor();
            if (StringUtils.isNotEmpty(healthDoctorFamily)) {
                // 添加到消息接收人列表
                receivers.add(healthDoctorFamily);
            } else if (StringUtils.isNotEmpty(doctorFamily)){
                // 添加到消息接收人列表
                receivers.add(doctorFamily);
            }
        }
        // 查询病人三师签约中的健康管理师
        SignFamily signFamilySS = signFamilyDao.findBySanshiPatientYes(patientCode);
        if (signFamilySS != null) {
            String healthDoctorTeam = signFamilySS.getDoctorHealth();
            // 判断是否是否是同一个健康管理师
            if (StringUtils.isNotEmpty(healthDoctorTeam) && !StringUtils.equals(healthDoctorFamily, healthDoctorTeam)) {
                // 添加到消息接收人列表
                receivers.add(healthDoctorTeam);
            }
            if (StringUtils.isNotEmpty(signFamilySS.getDoctor())){
                receivers.add(signFamilySS.getDoctor());
            }
        }
        List<Message> messages = new ArrayList<Message>();
        JSONArray array = new JSONArray();
        for (String receiver : receivers) {
            if (StringUtils.isEmpty(receiver)) {
                continue;
            }
            // 保存异常消息
            Message message = new Message();
            message.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
            message.setCzrq(new Date());
            message.setCreateTime(new Date());
            message.setRead(1);
            message.setOver("1");
            message.setReceiver(receiver);
            message.setSender(patientCode);
            message.setSex(patient.getSex());
            message.setSenderName(patient.getName());
            message.setSenderPhoto(patient.getPhoto());
            message.setTitle("预警值信息");
            message.setContent(content);
            message.setType(2);
            message.setValue1(Double.valueOf(model.getValue1()));
            message.setValue2(Double.valueOf(model.getValue2()));
            message.setTzCode(String.valueOf(model.getId()));//消息关联的体征id
            message.setTzType(String.valueOf(model.getType()));//体征类别 (1血糖,2血压,3体重,4腰围)
            messages.add(message);
            if(messageService.getMessageNoticeSettingByMessageType(receiver,"1",MessageNoticeSetting.MessageTypeEnum.healthSignSwitch.getValue())){
                // 异常通知
                JSONObject json = new JSONObject();
                json.put("receiver", receiver);
                json.put("type", MessageType.MESSAGE_TYPE_DOCTOR_HEALTH_INDEX.D_HI_01.name());
                json.put("title", MessageType.MESSAGE_TYPE_DOCTOR_HEALTH_INDEX.体征指标.name());
                json.put("msg", content);
                json.put("data", "");
                array.add(json);
            }
        }
        // 批量保存消息
        messageDao.save(messages);
        // 推送消息给医生
        pushMsgTask.put(array);
    }
    /**
     * 华三demo数据推送
@ -1268,61 +691,6 @@ public class DeviceService extends BaseService{
        }
    }
    /**
     * 指标数据上传基卫
     */
    private void uploadHealthIndex(PatientHealthIndex data) {
        try {
            String url = systemConfig.getJwServer() + "/third/archives/uploadHealthIndex";
            Map<String, Object> params = new HashedMap();
            params.put("id", data.getId());
            HttpResponse response = httpHelper.post(url, params);
            if (response != null && response.getStatusCode() == 200) {
                JSONObject json = JSONObject.fromObject(response.getBody());
                if (!"200".equals(json.optString("status"))) {
                    throw new Exception(json.optString("msg"));
                }
            } else {
                throw new Exception("接口调用错误!" + response.getBody());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    /**
     * 判断是否有未结束的续方咨询,发送消息给对应的医生
     * @param result
     * @param patient
     */
    private void sendPrescriptionHealthIndexMsgresult(PatientHealthIndex result, Patient patient) {
        List<ConsultTeam> consultTeams = consultTeamDao.findUnfinishedConsult(patient.getCode());
    
        for (ConsultTeam consultTeam:consultTeams) {
            if(consultTeam.getHealthindexType() != null){
                org.json.JSONObject contentPatient = new org.json.JSONObject();
                //患者发送的消息
                contentPatient.put("title", "【本消息为系统提醒】:");
                if(1 == result.getType()){
                    contentPatient.put("tzMsg", "体征记录:血糖 "+result.getValue1()+" mmol/L");
                    contentPatient.put("type",2);
                }else if(2 == result.getType()){
                    contentPatient.put("tzMsg", "体征记录:血压 "+result.getValue1()+"/"+result.getValue2()+" mmHg");
                    contentPatient.put("type",1);
                }else{}
            
                contentPatient.put("tzTime", "检测时间:"+DateUtil.dateToStrLong(result.getRecordDate()));
                contentPatient.put("tzAlert","温馨提示:本条体征为居民上传的健康体征数据,您可以");
                contentPatient.put("needUpload","false");
                contentPatient.put("healthindexid",result.getId());//体征记录 ID
            
                //患者发送Im消息
                ImUtill.sendTopicIM(patient.getCode(), patient.getName(), consultTeam.getConsult(), "16", contentPatient.toString(), null);
            }
        }
    }
}

File diff suppressed because it is too large
+ 79 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/bank/CreditLogService.java


+ 79 - 12
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/bank/TaskService.java

@ -12,7 +12,10 @@ import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientFamilyMemberDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.statistics.WlyySignFamilyCodeDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -57,7 +60,12 @@ public class TaskService {
    private SignFamilyDao signFamilyDao;
    @Autowired
    private WlyySignFamilyCodeDao signFamilyCodeDao;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    /**
     * 获取url
@ -84,14 +92,14 @@ public class TaskService {
     */
    public JSONObject selectActivity(JSONObject object,Integer page,Integer size){
        String response = null;
	    if(object.containsKey("patientid")){
		    Patient patient = patientDao.findByCode(object.getString("patientId"));
		    if (patient != null){
			    object.put("patientIdcard",patient.getIdcard());
			    object.put("unionId",patient.getUnionid());
			    object.remove("patientId");
		    }
	    }
        if(object.containsKey("patientId")){
            Patient patient = patientDao.findByCode(object.getString("patientId"));
            if (patient != null){
                object.put("patientIdcard",patient.getIdcard());
                object.put("unionId",patient.getUnionid());
                object.remove("patientId");
            }
        }
        String url =getBaseUrl() + "findActivity";
        Map<String,String> params = new HashMap<>();
@ -99,10 +107,7 @@ public class TaskService {
        params.put("activity",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        
        params.put("activity",object.toJSONString());
        
        try {
            response = httpClientUtil.httpPost(url,params);
@ -170,11 +175,15 @@ public class TaskService {
        object.put("unionId",unionId);
        object.put("patientIdcard",patient.getIdcard());
        object.put("patientOpenid",patient.getOpenid());
        object.put("name",patient.getName());
        object.put("hospital",signFamily.getHospital());
        object.put("hospitalName",signFamily.getHospitalName());
        String url =getBaseUrl() + "attendTask";
        Map<String,String> params = new HashMap<>();
        params.put("taskPatientDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
@ -277,4 +286,62 @@ public class TaskService {
        }
    }
    /*public JSONObject sendTemplateMessage(String patientId,String activityId){
        String response = null;
        Patient patient = patientDao.findByCode(patientId);
        try {
            JSONObject object = new JSONObject();
            if (patient != null){
                object.put("patientIdcard",patient.getIdcard());
                object.put("unionId",patient.getUnionid());
            }
            String url =getBaseUrl() + "findActivity";
            Map<String,String> params = new HashMap<>();
            params.put("activity",object.toJSONString());
            params.put("page","1");
            params.put("size","1");
            String response1 = httpClientUtil.httpPost(url,params);
            JSONObject response2 = JSONObject.parseObject(response1);
            String openId = patient.getOpenid();
            String name = patient.getName();
            org.json.JSONObject sendJson = new org.json.JSONObject();
            String first = "";
            String remark = "";
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_healthbank_activity","bmcgtx");
            first = templateConfig.getFirst();
            remark = templateConfig.getRemark();
            sendJson.put("keyword1", integrate);
            sendJson.put("keyword2", DateUtil.getStringDate());
            sendJson.put("keyword3", total);
            sendJson.put("first", first);
            sendJson.put("remark", remark);
            sendJson.put("appId","wx0e663ce069b5170c");
            sendJson.put("pagePath","pages/index/index");
            System.out.println(sendJson.toString());
            pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 23, openId, name, sendJson);
//	                    //发送代理人
//	                    jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openId);
//	                    if (jsonArray != null && jsonArray.length() > 0) {
//		                    for (int i = 0; i < jsonArray.length(); i++) {
//			                    org.json.JSONObject j = jsonArray.getJSONObject(i);
//			                    Patient member = (Patient) j.get("member");
//			                    int start = url.indexOf("&toUser=");
//			                    int end = url.indexOf("&", start + 1);
//			                    String touser = url.substring(start, end);
//			                    url = url.replace(touser, "&toUser=" + member.getCode());
//			                    //name患者姓名
//			                    sendJson.put("first", weiXinOpenIdUtils.getTitleMes(people, (int) j.get("relation"), name) + first);
//			                    sendJson.put("url", url);
//			                    pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 19, member.getOpenid(), name, sendJson);
//		                    }
//
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }*/
}

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

@ -3986,7 +3986,7 @@ public class FamilyContractService extends BaseService {
        SignFamily sf = new SignFamily();
        String sql = "SELECT t.doctor,t.team_code teamCode,t.admin_team_code adminTeamCode,t.mobile FROM wlyy_sign_family t WHERE t.patient ='" + patient + "' AND t.status=-4 AND t.expenses_status='1' AND t.sign_year ='" + (DateUtil.getSignYear() - 1) + "'";
        String sql = "SELECT t.doctor,t.doctor_health,t.team_code teamCode,t.admin_team_code adminTeamCode,t.mobile FROM wlyy_sign_family t WHERE t.patient ='" + patient + "' AND t.status=-4 AND t.expenses_status='1' AND t.sign_year ='" + (DateUtil.getSignYear() - 1) + "'";
        List<Map<String, Object>> signs = jdbcTemplate.queryForList(sql);
        if (signs == null || signs.size() == 0) {
@ -3994,7 +3994,7 @@ public class FamilyContractService extends BaseService {
        }
        Map<String, Object> sign = signs.get(0);
        //判断续签医生是否一致
        if (doctor.equals(sign.get("doctor"))) {
        if (doctor.equals(sign.get("doctor_health"))) {
            //如果一致保存团队信息
            sf.setRenewFlag("1");
            sf.setTeamCode((String) sign.get("teamCode"));

+ 2 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/SignWebService.java

@ -2820,8 +2820,8 @@ public class SignWebService extends BaseService {
        //新建全科医生成员
        DoctorTeamMember dmb = new DoctorTeamMember();
        dmb.setName(renew.getDoctorName());
        dmb.setMemberCode(renew.getDoctor());
        dmb.setName(d.getName());
        dmb.setMemberCode(d.getCode());
        dmb.setCode(getCode());
        dmb.setDel("1");
        dmb.setCzrq(new Date());

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statisticsES/StatisticsESService.java

@ -1379,7 +1379,7 @@ public class StatisticsESService {
        //因为统计时间是统计到当前时间的前一天,所以这里的时间是提前一天
        Calendar temp = Calendar.getInstance();
        temp.setTime(DateUtil.strToDate(endDate, DateUtil.YYYY_MM_DD));
        temp.add(Calendar.DAY_OF_MONTH, -1);
//        temp.add(Calendar.DAY_OF_MONTH, -1);
        end.setTime(temp.getTime());
        // 日期集合

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/HttpClientUtil.java

@ -146,7 +146,7 @@ public class HttpClientUtil {
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
            return e.getMessage();
        } finally {
            httpclient.close();
        }

+ 13 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/account/PatientController.java

@ -1059,4 +1059,17 @@ public class PatientController extends WeixinBaseController {
            return error( -1, "查询失败!");
        }
    }
    @RequestMapping(value = "/getDoctorActivityPath")
    @ResponseBody
    public String getDoctorActivityPath(String code){
        try {
            Doctor d = doctorService.findDoctorByCode(code);
            return write(200, "获取成功!", "data", d.getActivityPath());
        }catch (Exception e){
            error(e);
            return error(-1, "获取地址失败");
        }
    }
}

+ 15 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/bank/TaskController.java

@ -121,4 +121,19 @@ public class TaskController extends BaseController{
    }
    @RequestMapping(value = "/sendTempleMessage",method = RequestMethod.POST)
    @ApiOperation("获取用户信息")
    public String sendTempleMessage(@ApiParam(name = "patientId",value = "居民id")
                                    @RequestParam(name = "patientId")String patientId,
                                    @ApiParam(name = "activityId",value = "活动id")
                                    @RequestParam(name = "activituId")String activityId){
        try {
            return write(200,"查询成功","data",service.selectByOpenId(getOpenid(),getUID()));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
}

+ 20 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/health/bank/AccountController.java

@ -130,7 +130,7 @@ public class AccountController extends WeixinBaseController {
        try {
            JSONObject object = JSONObject.parseObject(activeRecord);
            JSONObject result = taskService.createActiveRecord(object);
            return write(200,"获取成功","data",result);
            return write(200,"添加成功","data",result);
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
@ -154,6 +154,7 @@ public class AccountController extends WeixinBaseController {
        }
    }
    @RequestMapping(value = "/insertCredits",method = RequestMethod.POST)
    @ApiOperation("添加积分")
    public String insert(@ApiParam(name = "creditsDetail",value = "居民id集合")
@ -171,4 +172,22 @@ public class AccountController extends WeixinBaseController {
            return error(-1,e.getMessage());
        }
    }
    @RequestMapping(value = "/weekReward",method = RequestMethod.POST)
    @ApiOperation("周奖励")
    public String weekReward(@ApiParam(name = "creditsDetail",value = "居民信息")
                                 @RequestParam(name = "creditsDetail") String creditsDetail){
        try {
            JSONObject object = JSONObject.parseObject(creditsDetail);
            JSONObject object1 = service.weekReward(object);
            return write(200,"添加成功","data",object1);
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
}

+ 6 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/WechatCoreController.java

@ -1,5 +1,7 @@
package com.yihu.wlyy.web.wx;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.weixin.WeiXinCoreService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.HttpUtil;
@ -16,6 +18,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -45,6 +48,8 @@ public class WechatCoreController extends WeixinBaseController {
    private HttpUtil HttpUtil;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private DoctorService doctorService;
    /**
     * 微信接口验证
@ -225,4 +230,5 @@ public class WechatCoreController extends WeixinBaseController {
        String s = new String(tempArr);
        return s;
    }
}

+ 6 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/process/WeiXinEventProcess.java

@ -915,13 +915,17 @@ public class WeiXinEventProcess {
    public void setDoctorActivity(String doctor,List<Map<String, String>> articles,Properties systemConf){
        Doctor d = doctorDao.findByCode(doctor);
        if(d!=null&&StringUtils.isNotBlank(d.getActivityPath())){
            logger.info("setDoctorActivity:"+d.getActivityPath());
            String url = systemDictDao.findByDictName("DOCTOR_ACTIVITY_PATH").get(0).getCode();
            url = url.replace("{server}", wechat_base_url)
                    .replace("{appId}", appId)
                    .replace("{data}",doctor);
            logger.info("setDoctorActivity:"+url);
            // 图文消息图片URL
            String activityPath = systemConf.getProperty("doctor_activity_url");
            activityPath = activityPath.replace("{server}", serverUrl);
            Map<String, String> articleConsult = new HashMap<>();
            articleConsult.put("Url", d.getActivityPath());
            articleConsult.put("Url", url);
            articleConsult.put("Title", "家庭医生签约,红包来助力");
            articleConsult.put("Description", "数量有限,先到先得");
            articleConsult.put("PicUrl", activityPath);

+ 1 - 0
patient-co/patient-co-wlyy/src/main/resources/application-dev.yml

@ -116,6 +116,7 @@ images:
sign:
  check_upload: http://172.19.103.87:8011/wlyy_service
  check_upload_sign: http://172.19.103.88:8011/wlyy_sign
express:
  sf_url: http://218.17.248.244:11080/bsp-oisp/sfexpressService