浏览代码

Merge branch 'dev' of wujunjie/patient-management into dev

trick9191 8 年之前
父节点
当前提交
2d63bc69f0
共有 19 个文件被更改,包括 1091 次插入877 次删除
  1. 4 4
      patient-co-wlyy/src/main/java/com/yihu/wlyy/event/ApplicationEvent.java
  2. 13 14
      patient-co-wlyy/src/main/java/com/yihu/wlyy/job/SignAgainJob.java
  3. 15 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/deviece/PatientHealthTimeDao.java
  4. 2 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/dict/MedicinesDao.java
  5. 21 9
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientHealthRecordDietDao.java
  6. 20 9
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientHealthRecordMedicationDao.java
  7. 20 9
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientHealthRecordSportsDao.java
  8. 35 21
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceService.java
  9. 141 73
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java
  10. 57 31
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelInfoService.java
  11. 91 12
      patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SendNews.java
  12. 5 60
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/account/WechatController.java
  13. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/account/DoctorController.java
  14. 63 49
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java
  15. 16 16
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/device/PatientDeviceController.java
  16. 579 547
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/PatientHealthController.java
  17. 0 2
      patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/process/WeiXinEventProcess.java
  18. 0 16
      patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/util/WeiXinMessageReplyUtils.java
  19. 8 4
      patient-co-wlyy/src/main/resources/system.properties

+ 4 - 4
patient-co-wlyy/src/main/java/com/yihu/wlyy/event/ApplicationEvent.java

@ -40,13 +40,13 @@ public class ApplicationEvent implements ApplicationListener<ContextRefreshedEve
                System.out.println("evaluate_score_job exist");
            }
             //启动群发续签图文消息
            if (!quartzHelper.isExistJob("sign_again_job")) {
//            if (!quartzHelper.isExistJob("sign_again_job")) {
                String trigger = SystemConf.getInstance().getSystemProperties().getProperty("sign_again_job_trigger");
                quartzHelper.addJob(SignAgainJob.class, trigger, "sign_again_job", new HashMap<String, Object>());
                System.out.println("sign_again_job start success");
            } else {
                System.out.println("sign_again_job exist");
            }
//            } else {
//                System.out.println("sign_again_job exist");
//            }
        } catch (Exception e) {
            System.out.println("sign end job start failed");
        }

+ 13 - 14
patient-co-wlyy/src/main/java/com/yihu/wlyy/job/SignAgainJob.java

@ -1,9 +1,13 @@
package com.yihu.wlyy.job;
import com.google.zxing.datamatrix.encoder.SymbolShapeHint;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.SendNews;
import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.web.WeixinBaseController;
import com.yihu.wlyy.web.common.account.WechatController;
import com.yihu.wlyy.wechat.process.WeiXinEventProcess;
import com.yihu.wlyy.wechat.util.WeiXinMessageReplyUtils;
@ -23,27 +27,22 @@ import java.util.Map;
/**
 * Created by Reece on 2017/5/18.
 */
public class SignAgainJob implements Job {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private PatientService patientService;
public class SignAgainJob extends WeixinBaseController implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        try {
            System.out.println("sign again job start1 SignAgainJob");
            System.out.println("sign again job start");
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
//            Calendar today = Calendar.getInstance();
            WechatController wechatController = new WechatController();
            wechatController.sendNews();
            System.out.println("sign again job end1 SignAgainJob");
            System.out.println(" ============job ===========>");
            String accessToken = getAccessToken();
//            SendNews sendNews = new SendNews();
            SendNews.sendNews(accessToken);
            System.out.println(" ==============================>");
            System.out.println("sign again job end");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("sign end job failed1 SignAgainJob");
            System.out.println("sign end job failed");
        }
    }
}

+ 15 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/deviece/PatientHealthTimeDao.java

@ -1,6 +1,7 @@
package com.yihu.wlyy.repository.deviece;
import com.yihu.wlyy.entity.device.PatientHealthTime;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
@ -12,4 +13,18 @@ public interface PatientHealthTimeDao extends PagingAndSortingRepository<Patient
    @Query(value = "select t.* from wlyy_patient_health_time t where t.del = 1 and t.user = ?1 and t.device_sn = ?2 ", nativeQuery = true)
    PatientHealthTime findByUserAndSN(String user, String deviceSN);
    //    根据居民和设备sn码修改自定义的血糖时间段
    @Modifying
    @Query("update PatientHealthTime t set t.fastingStart = ?1,t.fastingEnd = ?2,t.afterBreakfastStart = ?3,t.afterBreakfastEnd = ?4," +
            "t.beforeLunchStart = ?5 ,t.beforeLunchEnd = ?6 ,t.afterLunchStart = ?7,t.afterLunchEnd = ?8 ,t.beforeDinnerStart = ?9,t.beforeDinnerEnd = ?10," +
            "t.afterDinnerStart = ?11,t.afterDinnerEnd = ?12,t.beforeSleepStart = ?13,t.beforeSleepEnd = ?14 where t.del = 1 and t.user = ?15 and t.deviceSN = ?16 ")
    int modifyByUserAndSN(String fastingStart, String fastingEnd, String afterBreakfastStart, String afterBreakfastEnd, String beforeLunchStart, String beforeLunchEnd,
                          String afterLunchStart, String afterLunchEnd, String beforeDinnerStart, String beforeDinnerEnd, String afterDinnerStart, String afterDinnerEnd,
                          String beforeSleepStart, String beforeSleepEnd, String user, String deviceSN);
    //    根据居民和设备sn码删除自定义的血糖时间段
    @Modifying
    @Query("update PatientHealthTime t set t.del = 0 where t.user = ?1 and t.deviceSN = ?2 ")
    int deleteByUserAndSN(String user, String deviceSN);
}

+ 2 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/dict/MedicinesDao.java

@ -18,4 +18,6 @@ public interface MedicinesDao extends PagingAndSortingRepository<Medicines, Long
	@Query("select a from Medicines a where a.type = ?1 and a.del = '1'")
	List<Medicines> findAll(int type);
	Medicines findByCode(String code);
}

+ 21 - 9
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientHealthRecordDietDao.java

@ -3,23 +3,35 @@ package com.yihu.wlyy.repository.patient;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.yihu.wlyy.entity.patient.PatientHealthRecordDiet;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Date;
public interface PatientHealthRecordDietDao extends PagingAndSortingRepository<PatientHealthRecordDiet, Long>, JpaSpecificationExecutor<PatientHealthRecordDiet> {
	// 查询患者标识健康记录
	@Query("select a from PatientHealthRecordDiet a where a.patient = ?1 and a.del = '1'")
	Iterable<PatientHealthRecordDiet> findByPatient(String patient);
	
	// 查询最近的健康记录
	@Query("SELECT a FROM PatientHealthRecordDiet a WHERE a.patient = ?1 and a.del = '1' ORDER BY a.czrq DESC")
	Page<PatientHealthRecordDiet> findRecentByPatient(String patient, Pageable pageRequest);
    // 查询患者标识健康记录
    @Query("select a from PatientHealthRecordDiet a where a.patient = ?1 and a.del = '1'")
    Iterable<PatientHealthRecordDiet> findByPatient(String patient);
	@Query("SELECT a FROM PatientHealthRecordDiet a WHERE a.patient = ?1 and a.recordDate >= ?2 and a.recordDate <= ?3 and a.del = '1' ORDER BY a.recordDate DESC")
	Page<PatientHealthRecordDiet> findDietByPatient(String patient, Date start, Date end, Pageable pageRequest);
    // 查询最近的健康记录
    @Query("SELECT a FROM PatientHealthRecordDiet a WHERE a.patient = ?1 and a.del = '1' ORDER BY a.czrq DESC")
    Page<PatientHealthRecordDiet> findRecentByPatient(String patient, Pageable pageRequest);
    @Query("SELECT a FROM PatientHealthRecordDiet a WHERE a.patient = ?1 and a.recordDate >= ?2 and a.recordDate <= ?3 and a.del = '1' ORDER BY a.recordDate DESC")
    Page<PatientHealthRecordDiet> findDietByPatient(String patient, Date start, Date end, Pageable pageRequest);
    //	修改饮食记录
    @Modifying
    @Query("update PatientHealthRecordDiet a set a.recordDate = ?2,a.content = ?3,a.images= ?4 where a.id= ?1 ")
    void modifyDiet(long id,Date value1, String value2, String value3);
    //	删除饮食记录
    @Modifying
    @Query("update PatientHealthRecordDiet a set a.del = 0 where a.id= ?1 ")
    void deleteDiet(long id);
}

+ 20 - 9
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientHealthRecordMedicationDao.java

@ -3,6 +3,7 @@ package com.yihu.wlyy.repository.patient;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
@ -12,14 +13,24 @@ import java.util.Date;
public interface PatientHealthRecordMedicationDao extends PagingAndSortingRepository<PatientHealthRecordMedication, Long>, JpaSpecificationExecutor<PatientHealthRecordMedication> {
	// 查询患者标识健康记录
	@Query("select a from PatientHealthRecordMedication a where a.patient = ?1 and a.del = '1'")
	Iterable<PatientHealthRecordMedication> findByPatient(String patient);
	
	// 查询最近的健康记录
	@Query("SELECT a FROM PatientHealthRecordMedication a WHERE a.patient = ?1 and a.del = '1' ORDER BY a.czrq DESC")
	Page<PatientHealthRecordMedication> findRecentByPatient(String patient, Pageable pageRequest);
    // 查询患者标识健康记录
    @Query("select a from PatientHealthRecordMedication a where a.patient = ?1 and a.del = '1'")
    Iterable<PatientHealthRecordMedication> findByPatient(String patient);
	@Query("SELECT a FROM PatientHealthRecordMedication a WHERE a.patient = ?1 and a.recordDate >= ?2 and a.recordDate <= ?3 and a.del = '1' ORDER BY a.recordDate DESC")
	Page<PatientHealthRecordMedication> findMedicalByPatient(String patient, Date start,Date end, Pageable pageRequest);
    // 查询最近的健康记录
    @Query("SELECT a FROM PatientHealthRecordMedication a WHERE a.patient = ?1 and a.del = '1' ORDER BY a.czrq DESC")
    Page<PatientHealthRecordMedication> findRecentByPatient(String patient, Pageable pageRequest);
    @Query("SELECT a FROM PatientHealthRecordMedication a WHERE a.patient = ?1 and a.recordDate >= ?2 and a.recordDate <= ?3 and a.del = '1' ORDER BY a.recordDate DESC")
    Page<PatientHealthRecordMedication> findMedicalByPatient(String patient, Date start, Date end, Pageable pageRequest);
    //	修改用药记录
    @Modifying
    @Query("update PatientHealthRecordMedication a set a.recordDate = ?2,a.medicines = ?3,a.medicinesName= ?4 where a.id= ?1 ")
    void modifyMedication(long id, Date value1, String value2,String medicationName);
    //	删除用药记录
    @Modifying
    @Query("update PatientHealthRecordMedication a set a.del = 0 where a.id= ?1 ")
    void deleteMedication(long id);
}

+ 20 - 9
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientHealthRecordSportsDao.java

@ -3,6 +3,7 @@ package com.yihu.wlyy.repository.patient;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
@ -12,15 +13,25 @@ import java.util.Date;
public interface PatientHealthRecordSportsDao extends PagingAndSortingRepository<PatientHealthRecordSports, Long>, JpaSpecificationExecutor<PatientHealthRecordSports> {
	// 查询患者标识健康记录
	@Query("select a from PatientHealthRecordSports a where a.patient = ?1 and a.del = '1'")
	Iterable<PatientHealthRecordSports> findByPatient(String patient);
	
	// 查询最近的健康记录
	@Query("SELECT a FROM PatientHealthRecordSports a WHERE a.patient = ?1 and a.del = '1' ORDER BY a.czrq DESC")
	Page<PatientHealthRecordSports> findRecentByPatient(String patient, Pageable pageRequest);
    // 查询患者标识健康记录
    @Query("select a from PatientHealthRecordSports a where a.patient = ?1 and a.del = '1'")
    Iterable<PatientHealthRecordSports> findByPatient(String patient);
	@Query("select a from PatientHealthRecordSports a where a.patient = ?1 and a.recordDate >= ?2 and a.recordDate <= ?3 and a.del = '1' order by a.recordDate desc")
	Page<PatientHealthRecordSports> findSportsByPatient(String patient, Date start, Date end, Pageable pageRequest);
    // 查询最近的健康记录
    @Query("SELECT a FROM PatientHealthRecordSports a WHERE a.patient = ?1 and a.del = '1' ORDER BY a.czrq DESC")
    Page<PatientHealthRecordSports> findRecentByPatient(String patient, Pageable pageRequest);
    @Query("select a from PatientHealthRecordSports a where a.patient = ?1 and a.recordDate >= ?2 and a.recordDate <= ?3 and a.del = '1' order by a.recordDate desc")
    Page<PatientHealthRecordSports> findSportsByPatient(String patient, Date start, Date end, Pageable pageRequest);
    //	修改运动记录
    @Modifying
    @Query("update PatientHealthRecordSports a set a.recordDate = ?2,a.sportsTime= ?3 ,a.sportsType = ?4,a.sportsTypeName= ?5,a.sports = ?6 ,a.sportsName= ?7 where a.id= ?1 ")
    void modifySports(long id, Date value1, Double value2, String value3, String typeName, String value4, String sportName);
    //	删除运动记录
    @Modifying
    @Query("update PatientHealthRecordSports a set a.del = 0 where a.id= ?1 ")
    void deleteSports(long id);
}

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

@ -505,27 +505,41 @@ public class PatientDeviceService extends BaseService {
     */
    public void setBloodTime(String user, String deviceSN, String fastingStart, String fastingEnd, String afterBreakfastStart, String afterBreakfastEnd, String beforeLunchStart, String beforeLunchEnd,
                             String afterLunchStart, String afterLunchEnd, String beforeDinnerStart, String beforeDinnerEnd, String afterDinnerStart, String afterDinnerEnd,
                             String beforeSleepStart, String beforeSleepEnd) throws  Exception{
        PatientHealthTime patientHealthTime = new PatientHealthTime();
        patientHealthTime.setUser(user);
        patientHealthTime.setDeviceSN(deviceSN);
        patientHealthTime.setFastingStart(fastingStart);
        patientHealthTime.setFastingEnd(fastingEnd);
        patientHealthTime.setAfterBreakfastStart(afterBreakfastStart);
        patientHealthTime.setAfterBreakfastEnd(afterBreakfastEnd);
        patientHealthTime.setBeforeLunchStart(beforeLunchStart);
        patientHealthTime.setBeforeLunchEnd(beforeLunchEnd);
        patientHealthTime.setAfterLunchStart(afterLunchStart);
        patientHealthTime.setAfterLunchEnd(afterLunchEnd);
        patientHealthTime.setBeforeDinnerStart(beforeDinnerStart);
        patientHealthTime.setBeforeDinnerEnd(beforeDinnerEnd);
        patientHealthTime.setAfterDinnerStart(afterDinnerStart);
        patientHealthTime.setAfterDinnerEnd(afterDinnerEnd);
        patientHealthTime.setBeforeSleepStart(beforeSleepStart);
        patientHealthTime.setBeforeSleepEnd(beforeSleepEnd);
        patientHealthTime.setDel(1);
        patientHealthTime.setCzrq(new Date());
        patientHealthTimeDao.save(patientHealthTime);
                             String beforeSleepStart, String beforeSleepEnd) throws Exception {
        if (StringUtils.isEmpty(fastingStart) && StringUtils.isEmpty(fastingEnd) && StringUtils.isEmpty(afterBreakfastStart) && StringUtils.isEmpty(afterBreakfastEnd) && StringUtils.isEmpty(beforeLunchStart)
                && StringUtils.isEmpty(beforeLunchEnd) && StringUtils.isEmpty(afterLunchStart) && StringUtils.isEmpty(afterLunchEnd) && StringUtils.isEmpty(beforeDinnerStart) && StringUtils.isEmpty(beforeDinnerEnd) && StringUtils.isEmpty(afterDinnerStart)
                && StringUtils.isEmpty(afterDinnerEnd) && StringUtils.isEmpty(beforeSleepStart) && StringUtils.isEmpty(beforeSleepEnd)) {
            patientHealthTimeDao.deleteByUserAndSN(user,deviceSN);
            return;
        }
        PatientHealthTime healthTime = patientHealthTimeDao.findByUserAndSN(user, deviceSN);
        if (healthTime == null) {
            PatientHealthTime patientHealthTime = new PatientHealthTime();
            patientHealthTime.setUser(user);
            patientHealthTime.setDeviceSN(deviceSN);
            patientHealthTime.setFastingStart(fastingStart);
            patientHealthTime.setFastingEnd(fastingEnd);
            patientHealthTime.setAfterBreakfastStart(afterBreakfastStart);
            patientHealthTime.setAfterBreakfastEnd(afterBreakfastEnd);
            patientHealthTime.setBeforeLunchStart(beforeLunchStart);
            patientHealthTime.setBeforeLunchEnd(beforeLunchEnd);
            patientHealthTime.setAfterLunchStart(afterLunchStart);
            patientHealthTime.setAfterLunchEnd(afterLunchEnd);
            patientHealthTime.setBeforeDinnerStart(beforeDinnerStart);
            patientHealthTime.setBeforeDinnerEnd(beforeDinnerEnd);
            patientHealthTime.setAfterDinnerStart(afterDinnerStart);
            patientHealthTime.setAfterDinnerEnd(afterDinnerEnd);
            patientHealthTime.setBeforeSleepStart(beforeSleepStart);
            patientHealthTime.setBeforeSleepEnd(beforeSleepEnd);
            patientHealthTime.setDel(1);
            patientHealthTime.setCzrq(new Date());
            patientHealthTimeDao.save(patientHealthTime);
        } else {
            int rows = patientHealthTimeDao.modifyByUserAndSN(fastingStart, fastingEnd, afterBreakfastStart, afterBreakfastEnd, beforeLunchStart, beforeLunchEnd,
                    afterLunchStart, afterLunchEnd, beforeDinnerStart, beforeDinnerEnd, afterDinnerStart, afterDinnerEnd, beforeSleepStart, beforeSleepEnd, user, deviceSN);
            int str = rows;
        }
    }

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

@ -3,17 +3,20 @@ package com.yihu.wlyy.service.app.health;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.device.PatientDevice;
import com.yihu.wlyy.entity.dict.Medicines;
import com.yihu.wlyy.entity.education.Sports;
import com.yihu.wlyy.entity.education.SportsType;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientHealthStandard;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.health.entity.DevicePatientHealthIndex;
import com.yihu.wlyy.health.repository.DevicePatientHealthIndexDao;
import com.yihu.wlyy.repository.dict.MedicinesDao;
import com.yihu.wlyy.repository.education.SportsDao;
import com.yihu.wlyy.repository.education.SportsTypeDao;
import com.yihu.wlyy.repository.message.MessageDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.repository.patient.PatientHealthStandardDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.patient.*;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.task.HealthIndexUploadTask;
@ -70,9 +73,72 @@ public class PatientHealthIndexService extends BaseService {
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private DoctorWorkTimeService doctorWorkTimeService;
    @Autowired
    private PatientHealthRecordDietDao patientHealthRecordDietDao;
    @Autowired
    private PatientHealthRecordSportsDao patientHealthRecordSportsDao;
    @Autowired
    private PatientHealthRecordMedicationDao patientHealthRecordMedicationDao;
    @Autowired
    private SportsTypeDao sportsTypeDao;
    @Autowired
    private SportsDao sportsDao;
    @Autowired
    private MedicinesDao medicinesDao;
    /**
     * 更改保健记录(包括手动记录的修改和所有的删除)
     *
     * @param id
     * @param type   饮食1,运动2,用药3
     * @param value1 记录时间
     * @param value2 饮食内容CONTETN  时长 用药
     * @param value3 上传图片 强度
     * @param value4 运动项目
     */
    public void modifyHealthCare(long id, int type, String value1, String value2, String value3, String value4) throws Exception {
        //value类字段值均为空为删除
        if (StringUtils.isEmpty(value1) && StringUtils.isEmpty(value2) && StringUtils.isEmpty(value3) && StringUtils.isEmpty(value4)) {
            switch (type) {
                case 1:
                    patientHealthRecordDietDao.deleteDiet(id);
                    break;
                case 2:
                    patientHealthRecordSportsDao.deleteSports(id);
                    break;
                case 3:
                    patientHealthRecordMedicationDao.deleteMedication(id);
                    break;
            }
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date recordDate = sdf.parse(value1);
            switch (type) {
                case 1:
                    patientHealthRecordDietDao.modifyDiet(id, recordDate, value2, value3);
                    break;
                case 2:
                    SportsType sportsType = sportsTypeDao.findByCode(value3);
                    String typeName = sportsType.getName();
                    Sports sport = sportsDao.findByCode(value4);
                    String sportName = sport.getName();
                    Double sportsTime = Double.parseDouble(value2);
                    patientHealthRecordSportsDao.modifySports(id, recordDate, sportsTime, value3, typeName, value4, sportName);
                    break;
                case 3:
                    Medicines medicines = medicinesDao.findByCode(value2);
                    String medicinesName = medicines.getName();
                    patientHealthRecordMedicationDao.modifyMedication(id, recordDate, value2, medicinesName);
                    break;
            }
        }
    }
    //更改接口(包括手动记录的修改和所有的删除)
    public void modify(long id, String value1, String value2, String value3, String value4) {
    public void modify(long id, String recordDate, String value1, String value2, String value3, String value4) throws Exception {
        Date record = null;
        Date time = new Date();
        String sql = "";
//            字段值均为空为删除
@ -81,20 +147,24 @@ public class PatientHealthIndexService extends BaseService {
            jdbcTemplate.update(sql, id);
        }
        sql = " update device.wlyy_patient_health_index a set ";
        if (StringUtils.isNotEmpty(recordDate)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            record = sdf.parse(recordDate);
        }
        if (StringUtils.isNotEmpty(value1)) {
            sql += " a.value1 = " +value1+" , ";
            sql += " a.value1 = " + value1 + " , ";
        }
        if (StringUtils.isNotEmpty(value2)) {
            sql +=  " a.value2 = " +value2+" , ";
            sql += " a.value2 = " + value2 + " , ";
        }
        if (StringUtils.isNotEmpty(value3)) {
            sql +=  " a.value3 = " +value3+" , ";
            sql += " a.value3 = " + value3 + " , ";
        }
        if (StringUtils.isNotEmpty(value4)) {
            sql += " a.value4 = " +value4+", ";
            sql += " a.value4 = " + value4 + ", ";
        }
         sql += " a.czrq = ?  where a.device_sn is null and a.id =? ";
        jdbcTemplate.update(sql, time, id);
        sql += "  a.record_date = ? ,a.czrq = ?  where a.device_sn is null and a.id =? ";
        jdbcTemplate.update(sql, record, time, id);
    }
    /**
@ -438,57 +508,57 @@ public class PatientHealthIndexService extends BaseService {
     */
    private com.alibaba.fastjson.JSONObject getPatientXT_Json(String patient, String dateString) {
        com.alibaba.fastjson.JSONObject obj = new com.alibaba.fastjson.JSONObject();
        obj.put("user",patient);
        obj.put("user", patient);
        boolean hadData = false;
        Date date = DateUtil.strToDateShort(dateString);
        /***************** 按时间排序 ***************************/
        List<DevicePatientHealthIndex> list = patientHealthIndexDao.findByDateNative(patient, dateString);
        if (list != null && list.size() > 0) {
            obj.put("type",1);
            obj.put("czrq",date);
            obj.put("recordDate",date);
            obj.put("sortDate",date);
            obj.put("type", 1);
            obj.put("czrq", date);
            obj.put("recordDate", date);
            obj.put("sortDate", date);
            for (DevicePatientHealthIndex item : list) {
                String data = item.getValue1();
                String dataType = item.getValue2();
                String recordDate =DateUtil.dateToStr(item.getRecordDate(), DateUtil.YYYY_MM_DD_HH_MM_SS);
                String recordDate = DateUtil.dateToStr(item.getRecordDate(), DateUtil.YYYY_MM_DD_HH_MM_SS);
                Long id = item.getId();
                if (data != null && dataType != null) {
                    if (dataType.equals("1")) {
                        obj.put("value1",data);
                        obj.put("time1",recordDate);
                        obj.put("id1",id);
                        obj.put("value1", data);
                        obj.put("time1", recordDate);
                        obj.put("id1", id);
                        hadData = true;
                    } else if (dataType.equals("2")) {
                        obj.put("value2",data);
                        obj.put("time2",recordDate);
                        obj.put("id2",id);
                        obj.put("value2", data);
                        obj.put("time2", recordDate);
                        obj.put("id2", id);
                        hadData = true;
                    } else if (dataType.equals("3")) {
                        obj.put("value3",data);
                        obj.put("time3",recordDate);
                        obj.put("id3",id);
                        obj.put("value3", data);
                        obj.put("time3", recordDate);
                        obj.put("id3", id);
                        hadData = true;
                    } else if (dataType.equals("4")) {
                        obj.put("value4",data);
                        obj.put("time4",recordDate);
                        obj.put("id4",id);
                        obj.put("value4", data);
                        obj.put("time4", recordDate);
                        obj.put("id4", id);
                        hadData = true;
                    } else if (dataType.equals("5")) {
                        obj.put("value5",data);
                        obj.put("time5",recordDate);
                        obj.put("id5",id);
                        obj.put("value5", data);
                        obj.put("time5", recordDate);
                        obj.put("id5", id);
                        hadData = true;
                    } else if (dataType.equals("6")) {
                        obj.put("value6",data);
                        obj.put("time6",recordDate);
                        obj.put("id6",id);
                        obj.put("value6", data);
                        obj.put("time6", recordDate);
                        obj.put("id6", id);
                        hadData = true;
                    } else if (dataType.equals("7")) {
                        obj.put("value7",data);
                        obj.put("time7",recordDate);
                        obj.put("id7",id);
                        obj.put("value7", data);
                        obj.put("time7", recordDate);
                        obj.put("id7", id);
                        hadData = true;
                    }
                }
@ -595,6 +665,7 @@ public class PatientHealthIndexService extends BaseService {
     */
    public DevicePatientHealthIndex addPatientHealthIndex(String data, String type, String patientCode, String deviceSn) throws Exception {
        Map<String, String> map = (Map<String, String>) objectMapper.readValue(data, Map.class);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        DevicePatientHealthIndex obj = new DevicePatientHealthIndex();
        Date currentTime = new Date();
@ -602,7 +673,9 @@ public class PatientHealthIndexService extends BaseService {
        obj.setDel("1");
        Date time = currentTime;
        if (map.containsKey("time")) {
            time = DateUtil.strToDate(map.get("time"));
            String da = map.get("time");
//            time = DateUtil.strToDate(da);
            time = sdf.parse(da);
        }
        obj.setRecordDate(time);    //记录时间
        obj.setSortDate(time);      //排序时间
@ -738,27 +811,27 @@ public class PatientHealthIndexService extends BaseService {
    /**
     * 按时间段查询患者健康指标
     *
     * @param type  健康指标类型(1血糖,2血压,3体重,4腰围)
     * @param type    健康指标类型(1血糖,2血压,3体重,4腰围)
     * @param gi_type 血糖就餐时间段(早餐前,早餐后等)
     * @param begin 开始时间
     * @param end   结束时间
     * @param begin   开始时间
     * @param end     结束时间
     * @return
     */
    public List<DevicePatientHealthIndex> findChartByPatient(String patient, int type,int gi_type, String begin, String end) {
    public List<DevicePatientHealthIndex> findChartByPatient(String patient, int type, int gi_type, String begin, String end) {
        List<DevicePatientHealthIndex> re = new ArrayList<>();
        Date startDate = DateUtil.strToDate(begin, DateUtil.YYYY_MM_DD_HH_MM_SS);
        Date endDate = DateUtil.strToDate(end, DateUtil.YYYY_MM_DD_HH_MM_SS);
        if(gi_type != 0){
        if (gi_type != 0) {
            Sort sort = new Sort(Direction.ASC, "recordDate");
            PageRequest pageRequest = new PageRequest(0, 1000, sort);
            re = patientHealthIndexDao.findIndexByPatientNative(patient, type,gi_type+"", startDate, endDate, pageRequest.getOffset(),pageRequest.getPageSize());
            re = patientHealthIndexDao.findIndexByPatientNative(patient, type, gi_type + "", startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize());
        }else{
        } else {
            // 排序
            Sort sort = new Sort(Direction.ASC, "recordDate");
            PageRequest pageRequest = new PageRequest(0, 1000, sort);
            re = patientHealthIndexDao.findIndexByPatientNative(patient, type, startDate, endDate, pageRequest.getOffset(),pageRequest.getPageSize());
            re = patientHealthIndexDao.findIndexByPatientNative(patient, type, startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize());
        }
        return re;
@ -787,7 +860,7 @@ public class PatientHealthIndexService extends BaseService {
        {
            PageRequest pageRequest = new PageRequest(page, pageSize);
            //根据时间过滤排序
            List<String> dateList = patientHealthIndexDao.findDateList(patient, startDate, endDate, pageRequest.getOffset(),pageRequest.getPageSize());
            List<String> dateList = patientHealthIndexDao.findDateList(patient, startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize());
            if (dateList != null && dateList.size() > 0) {
                for (String dateString : dateList) {
                    DevicePatientHealthIndex obj = getPatientXT(patient, dateString);
@ -800,7 +873,7 @@ public class PatientHealthIndexService extends BaseService {
            // 排序
            Sort sort = new Sort(Direction.DESC, "recordDate");
            PageRequest pageRequest = new PageRequest(page, pageSize, sort);
            List<DevicePatientHealthIndex> list = patientHealthIndexDao.findIndexByPatientNative(patient, type, startDate, endDate, pageRequest.getOffset(),pageRequest.getPageSize());
            List<DevicePatientHealthIndex> list = patientHealthIndexDao.findIndexByPatientNative(patient, type, startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize());
            re = list;
        }
        return re;
@ -830,7 +903,7 @@ public class PatientHealthIndexService extends BaseService {
        {
            PageRequest pageRequest = new PageRequest(page, pageSize);
            //根据时间过滤排序
            List<String> dateList = patientHealthIndexDao.findDateList(patient, startDate, endDate, pageRequest.getOffset(),pageRequest.getPageSize());
            List<String> dateList = patientHealthIndexDao.findDateList(patient, startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize());
            if (dateList != null && dateList.size() > 0) {
                for (String dateString : dateList) {
                    com.alibaba.fastjson.JSONObject obj = getPatientXT_Json(patient, dateString);
@ -919,48 +992,48 @@ public class PatientHealthIndexService extends BaseService {
                JSONObject json = new JSONObject();
                // 设置健康指标类型(1血糖,2血压,3体重,4腰围)
                json.put("type", phi.getType());
                if(1== phi.getType()&&StringUtils.isNotBlank(phi.getValue2())){
                if (1 == phi.getType() && StringUtils.isNotBlank(phi.getValue2())) {
                    int gi_type = Integer.parseInt(phi.getValue2());
                    switch (gi_type) {
                        case 1:
                            // 设置血糖/收缩压/体重/腰围/早餐前空腹
                            json.put("value1", phi.getValue1());
                            json.put("time1",phi.getRecordDate());
                            json.put("time1", phi.getRecordDate());
                            break;
                        case 2:
                            // 设置舒张压/早餐后血糖
                            json.put("value2", phi.getValue2());
                            json.put("time2",phi.getRecordDate());
                            json.put("time2", phi.getRecordDate());
                            break;
                        case 3:
                            // 设置午餐前血糖
                            json.put("value3", phi.getValue3());
                            json.put("time3",phi.getRecordDate());
                            json.put("time3", phi.getRecordDate());
                            break;
                        case 4:
                            // 设置午餐后血糖
                            json.put("value4", phi.getValue4());
                            json.put("time4",phi.getRecordDate());
                            json.put("time4", phi.getRecordDate());
                            break;
                        case 5:
                            // 设置晚餐前血糖
                            json.put("value5", phi.getValue5());
                            json.put("time5",phi.getRecordDate());
                            json.put("time5", phi.getRecordDate());
                            break;
                        case 6:
                            // 设置晚餐后血糖
                            json.put("value6", phi.getValue6());
                            json.put("time6",phi.getRecordDate());
                            json.put("time6", phi.getRecordDate());
                            break;
                        case 7:
                            // 设置睡前血糖
                            json.put("value7", phi.getValue7());
                            json.put("time7",phi.getRecordDate());
                            json.put("time7", phi.getRecordDate());
                            break;
                    }
                }else{
                    json.put("value1",phi.getValue1());
                    json.put("value2",phi.getValue2());
                } else {
                    json.put("value1", phi.getValue1());
                    json.put("value2", phi.getValue2());
                    // 设置午餐前血糖
                    json.put("value3", phi.getValue3());
                    // 设置午餐后血糖
@ -974,11 +1047,6 @@ public class PatientHealthIndexService extends BaseService {
                }
                json.put("date", DateUtil.dateToStrShort(phi.getRecordDate()));
                array.put(json);
            }
@ -1045,15 +1113,15 @@ public class PatientHealthIndexService extends BaseService {
//                return null;
//            }
            return obj;
        } else if(type ==2) {  //其他指标
        } else if (type == 2) {  //其他指标
            return patientHealthIndexDao.findLastData(patientCode, 2);
        }else{
        } else {
            return patientHealthIndexDao.findLastData(patientCode, type);
        }
    }
    public com.alibaba.fastjson.JSONObject findLastBypatient(String patientCode, int type){
        if(type==1){
    public com.alibaba.fastjson.JSONObject findLastBypatient(String patientCode, int type) {
        if (type == 1) {
            DevicePatientHealthIndex obj = patientHealthIndexDao.findLastData(patientCode, 1);
            if (obj != null) {
                String dateString = DateUtil.dateToStrShort(obj.getRecordDate());
@ -1061,11 +1129,11 @@ public class PatientHealthIndexService extends BaseService {
            } else {
                return null;
            }
        }else{
        } else {
            DevicePatientHealthIndex obj = patientHealthIndexDao.findLastData(patientCode, type);
            if(obj != null){
            if (obj != null) {
                return JSON.parseObject(JSON.toJSONString(obj));
            }else {
            } else {
                return null;
            }
        }

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

@ -206,18 +206,18 @@ public class SignPatientLabelInfoService extends BaseService {
            json.put("wechatFocusRemind", 1);
        }
        String timeKey = DateUtil.dateToStr(new Date(),"yyyyMMdd");
        String flag = redisTemplate.opsForValue().get("renew:"+timeKey+":"+patient);
        if(StringUtils.isNotBlank(flag)){
            json.put("isRemindRenew","1");
        }else{
            json.put("isRemindRenew","0");
        String timeKey = DateUtil.dateToStr(new Date(), "yyyyMMdd");
        String flag = redisTemplate.opsForValue().get("renew:" + timeKey + ":" + patient);
        if (StringUtils.isNotBlank(flag)) {
            json.put("isRemindRenew", "1");
        } else {
            json.put("isRemindRenew", "0");
        }
        String sql = "SELECT t.czrq FROM wlyy_sign_family_renew t WHERE t.status>=0 AND t.is_valid =0";
        List<Map<String,Object>> renews =  jdbcTemplate.queryForList(sql);
        if(renews!=null&&renews.size()>0){
            Map<String,Object> renew = renews.get(0);
            json.put("renewTime",renew.get("czrq"));
        List<Map<String, Object>> renews = jdbcTemplate.queryForList(sql);
        if (renews != null && renews.size() > 0) {
            Map<String, Object> renew = renews.get(0);
            json.put("renewTime", renew.get("czrq"));
        }
        return json;
@ -1275,7 +1275,7 @@ public class SignPatientLabelInfoService extends BaseService {
     * @return
     * @throws Exception
     */
    public List findNoHealthSignFamilyHealth(String filter, Long teamCode,int page,int pagesize) throws Exception {
    public List findNoHealthSignFamilyHealth(String filter, Long teamCode, int page, int pagesize) throws Exception {
        List list = new ArrayList();
        String sql = "SELECT  DISTINCT " +
                "  p.photo photo, " +
@ -1295,19 +1295,19 @@ public class SignPatientLabelInfoService extends BaseService {
                " AND ( sf.doctor_health is null or sf.doctor_health ='' ) " +
                "  AND (p.name like ? or p.address like ? or p.idcard like ? ) " +
                " ORDER BY  p.name DESC,p.address DESC, p.idcard DESC " +
                " limit "+(page-1)*pagesize+","+pagesize;
                " limit " + (page - 1) * pagesize + "," + pagesize;
        List<Map<String, Object>> datas = jdbcTemplate.queryForList(sql, teamCode, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%");
        if (datas != null && datas.size() > 0) {
            for (Map<String, Object> map : datas) {
                Map ma = new HashMap();
                ma.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard")==null?"":map.get("idcard").toString()));
                ma.put("photo",map.get("photo")==null?"":map.get("photo").toString());
                ma.put("name",map.get("name")==null?"":map.get("name").toString());
                ma.put("code",map.get("code")==null?"":map.get("code").toString());
                ma.put("sex",map.get("sex")==null?"":map.get("sex").toString());
                ma.put("address",map.get("address")==null?"":map.get("address").toString());
                ma.put("idcard",map.get("idcard")==null?"":map.get("idcard").toString());
                ma.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard") == null ? "" : map.get("idcard").toString()));
                ma.put("photo", map.get("photo") == null ? "" : map.get("photo").toString());
                ma.put("name", map.get("name") == null ? "" : map.get("name").toString());
                ma.put("code", map.get("code") == null ? "" : map.get("code").toString());
                ma.put("sex", map.get("sex") == null ? "" : map.get("sex").toString());
                ma.put("address", map.get("address") == null ? "" : map.get("address").toString());
                ma.put("idcard", map.get("idcard") == null ? "" : map.get("idcard").toString());
                list.add(ma);
            }
        }
@ -1542,24 +1542,50 @@ public class SignPatientLabelInfoService extends BaseService {
        Object[] args = null;
        String sql = "";
        //String reg = "(^\\d{15}$)|(^\\d{17}([0-9]|X)$)";
        String reg = "^(\\d+)([0-9]|X|x)$";
//        String reg = "^(\\d+)([0-9]|X|x)$";
//        匹配数字字符串
        String reg = "[0-9]{1,}";
        Pattern pattern = Pattern.compile(reg);
        Matcher matcher = pattern.matcher(filter);
        if (matcher.find()) {
            sql = " select DISTINCT t.* " +
                    " from" +
                    "     wlyy_sign_family t join wlyy_patient p " +
                    "     on t.patient = p.code " +
                    (StringUtils.isNotEmpty(labelCode) ? (" join wlyy_sign_patient_label_info l " +
                            " on t.patient = l.patient ") : "") +
                    " where " +
                    "    (t.doctor = ? or t.doctor_health = ?) " +
                    (teamCode > 0 ? ("    and t.admin_team_code = " + teamCode) : "") +
                    (StringUtils.isNotEmpty(labelCode) ? " and l.label = ? and l.label_type = ? " : "") +
                    "     and p.idcard like ? ";
//            sql = " select DISTINCT t.* " +
//                    " from" +
//                    "     wlyy_sign_family t join wlyy_patient p " +
//                    "     on t.patient = p.code " +
//                    (StringUtils.isNotEmpty(labelCode) ? (" join wlyy_sign_patient_label_info l " +
//                            " on t.patient = l.patient ") : "") +
//                    " where " +
//                    "    (t.doctor = ? or t.doctor_health = ?) " +
//                    (teamCode > 0 ? ("    and t.admin_team_code = " + teamCode) : "") +
//                    (StringUtils.isNotEmpty(labelCode) ? " and l.label = ? and l.label_type = ? " : "") +
//                    "     and p.idcard like ? ";
//            if (StringUtils.isNotEmpty(labelCode)) {
//                args = new Object[]{doctor, doctor, labelCode, labelType, "%" + filter + "%"};
//            } else {
//                args = new Object[]{doctor, doctor, "%" + filter + "%"};
//            }
            sql = "select " +
                    "    DISTINCT t1.* " +
                    " FROM " +
                    "    wlyy_sign_family t1 " +
                    (StringUtils.isNotEmpty(labelCode) ?
                            " join " : " left join ") +
                    "    wlyy_sign_patient_label_info t2 " +
                    " ON t1.patient = t2.patient " +
                    (teamCode > 0 ? " join (select * from wlyy_sign_patient_label where label_type != '4' or team_code = " + teamCode + " or (label_type = '4' and (label_code in (1,2)))) lb on t2.label = lb.label_code and t2.label_type = lb.label_type " : "") +
                    " WHERE " +
                    "    (t1.doctor = ? or t1.doctor_health = ?) " +
                    "    AND t1.status > 0 " +
                    "    AND (" + (StringUtils.isNotEmpty(labelCode) || StringUtils.isNotEmpty(labelType) ? "" : " t2.patient is null OR ") + " t2.status = 1) " +
                    (StringUtils.isNotEmpty(labelCode) ? " AND t2.label = ? " : "") +
                    (StringUtils.isNotEmpty(labelType) ? " AND t2.label_type = ? " : "") +
                    (teamCode > 0 ? (" AND admin_team_code = " + teamCode) : "") +
                    "  AND (t1.idcard like ?) ";
            if (StringUtils.isNotEmpty(labelCode)) {
                args = new Object[]{doctor, doctor, labelCode, labelType, "%" + filter + "%"};
            } else if (StringUtils.isEmpty(labelCode) && StringUtils.isNotEmpty(labelType)) {
                args = new Object[]{doctor, doctor, labelType, "%" + filter + "%"};
            } else {
                args = new Object[]{doctor, doctor, "%" + filter + "%"};
            }

+ 91 - 12
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SendNews.java

@ -1,16 +1,37 @@
package com.yihu.wlyy.util;
import com.yihu.wlyy.entity.security.AccessToken;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.security.AccessTokenDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.common.account.AccessTokenService;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springside.modules.utils.Clock;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import static sun.management.Agent.error;
/**
 * Created by Reece on 2017/5/20.
 */
@Component
public class SendNews {
    private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
@ -107,33 +128,91 @@ public class SendNews {
    /**
     * 上传图文消息文字素材
     *
     * @param accessToken
     * @param data 图文消息文字素材内容
     * @param data        图文消息文字素材内容
     * @return
     */
    public static String uploadNesText(String accessToken,String url,JSONObject data){
        url = url.replaceFirst("ACCESS_TOKEN",accessToken);
    public static String uploadNesText(String accessToken, String url, JSONObject data) throws Exception {
        url = url.replaceFirst("ACCESS_TOKEN", accessToken);
        //上传的图文消息数据,其中thumb_media_id是文件上传图片上传的id
//        data = "{\"articles\": [{\"thumb_media_id\":\"BW4eDIdYSvO7AFjfsZKsQ9ujNma_TkCj3VSo3JNTQkYmk_iPuhpUKm48oZ4umHED\",\"author\":\"xxx\",\"title\":\"Happy Day\",\"content_source_url\":\"www.qq.com\",\"content\":\"content\",\"digest\":\"digest\",\"show_cover_pic\":\"0\"}]}";
        String result = HttpClientUtil.postBody(url,data);
        String result = HttpClientUtil.postBody(url, data);
        return result;
    }
    /**
     * 发送图文消息
     *
     * @param accessToken
     * @param openidData  群发图文消息内容
     * @return
     */
    public static String sendNewspMessage(String accessToken,String url, JSONObject openidData){
        url = url.replace("ACCESS_TOKEN",accessToken);
        String group1data = "{\"filter\":{\"is_to_all\":false,\"group_id\":\"2\"},\"text\":{\"content\":\"群发消息测试\"},\"msgtype\":\"text\"}\";";
        String openid1data = "{\"touser\":[\"obGXiwHTGN_4HkR2WToFj_3uaEKY\",\"obGXiwNu0z2o_RRWaODvaZctdWEM\"],\"msgtype\": \"text\",\"text\": {\"content\": \"测试文本消息\"}}";
        String openid2data = "{\"touser\":[\"obGXiwHTGN_4HkR2WToFj_3uaEKY\",\"obGXiwNu0z2o_RRWaODvaZctdWEM\"], \"voice\": {\"media_id\":\"UfMRvSiXAD5_iUS8u0Gc3JrKGWOABE9ivQbgrX6i-mVrKGBRL9KnKlioK1BxTPc3\"},\"msgtype\":\"voice\"}";
        String openid3data = "{\"touser\":[\"obGXiwHTGN_4HkR2WToFj_3uaEKY\",\"obGXiwNu0z2o_RRWaODvaZctdWEM\"], \"image\": {\"media_id\":\"fNUzGbYzTRui4N7-eyx9e3viP8uJuzztAvA32lIdjX4Cucj7mGN_1jpWjn7O80c8\"},\"msgtype\":\"image\"}";
        String json = HttpClientUtil.postBody(url,openidData);
    public static String sendNewspMessage(String accessToken, String url, JSONObject openidData) throws Exception {
        url = url.replace("ACCESS_TOKEN", accessToken);
        String json = HttpClientUtil.postBody(url, openidData);
        return json;
    }
    public static String sendNews(String accessToken) throws Exception {
        // 配置信息
        Properties systemConf = SystemConf.getInstance().getSystemProperties();
        //本地上传图片的路径
        /*String renewPath = systemConf.getProperty("patient_sign_again_pic_url");
        String renewUrl = systemConf.getProperty("patient_sign_again_url");
        String signPath = systemConf.getProperty("doctor_qrcode_pic_url");
        String signUrl = systemConf.getProperty("doctor_subscribe_url");
        String sendUrl = "http://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN&type=image";
        String mediaurl = "https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=ACCESS_TOKEN";//ACCESS_TOKEN是获取到的access_token
        String groupUrl = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=ACCESS_TOKEN";//根据openid发群发消息地址
        sendUrl = sendUrl.replace("ACCESS_TOKEN", accessToken);
        String renewImage = SendNews.uploadImage(sendUrl, renewPath);
        String signImage = SendNews.uploadImage(sendUrl, signPath);
        JSONObject newsTextData = new JSONObject();
        JSONArray newsText = new JSONArray();
//            续签图文
        JSONObject data = new JSONObject();
        data.put("thumb_media_id", new JSONObject(renewImage).get("url"));
        data.put("author", "作者");
        data.put("content_source_url", renewUrl);
        data.put("content", "续签图文消息内容");
        data.put("digest", "续签图文消息描述");
        data.put("show_cover_pic", 1);
//            签约图文
        JSONObject data1 = new JSONObject();
        data1.put("thumb_media_id", new JSONObject(signImage).get("url"));
//            data1.put("author","作者");
        data1.put("content_source_url", signUrl);
        data1.put("content", "签约图文消息内容");
//            data1.put("digest","签约图文消息描述");
//            data1.put("show_cover_pic",1);
        newsText.put(data1);
        newsText.put(data);
        newsTextData.put("articles", newsText);
        String media = SendNews.uploadNesText(accessToken, mediaurl, newsTextData);
        JSONObject news = new JSONObject();
        JSONObject mapnews = new JSONObject();
        mapnews.put("media_id", new JSONObject(media).get("media_id"));*/
       /* String sql = "select distinct p.openid from Patient p where p.openid is not null and p.openid <> '' ";
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        List<String> openIds = jdbcTemplate.queryForList(sql, String.class);*/
//        List<String> openIds = patientDao.findOpenids();
       /* news.put("touser", openIds);
        news.put("mpnews", mapnews);
        news.put("msgtype", "mpnews");
        news.put("send_ignore_reprint", 1);
        SendNews.sendNewspMessage(accessToken, groupUrl, news);*/
        return null;
    }
}

+ 5 - 60
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/account/WechatController.java

@ -7,11 +7,13 @@ import java.util.*;
import com.yihu.wlyy.entity.login.LoginLog;
import com.yihu.wlyy.entity.patient.PatientFamilyMember;
import com.yihu.wlyy.entity.patient.SocialSecurityInfo;
import com.yihu.wlyy.entity.security.AccessToken;
import com.yihu.wlyy.logs.BusinessLogs;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SocialSecurityInfoDao;
import com.yihu.wlyy.service.app.family.FamilyMemberService;
import com.yihu.wlyy.service.app.family.FamilyService;
import com.yihu.wlyy.service.common.account.AccessTokenService;
import com.yihu.wlyy.service.common.login.LoginLogService;
import com.yihu.wlyy.util.*;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
@ -61,6 +63,8 @@ public class WechatController extends WeixinBaseController {
    private FamilyMemberService familyMemberService;
    @Autowired
    WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    AccessTokenService accessTokenService;
    /**
@ -575,7 +579,7 @@ public class WechatController extends WeixinBaseController {
                map.put("noncestr", noncestr);
                map.put("timestamp", timestamp);
                map.put("signature", signature);
                return write(200, "获取签名成功", "data", map);
                return write(200, "获取签名成功", "data", "map");
            } else
                return error(-1, "获取签名失败");
@ -725,63 +729,4 @@ public class WechatController extends WeixinBaseController {
        }
    }
    /**
     * 根据openID群发图文消息
     *
     * @return
     */
    @RequestMapping(value = "/sendNews")
    @ResponseBody
    public String sendNews() {
        try {
            String accessToken = getAccessToken();
//            本地上传图片的路径
            String filePath = SystemConf.getInstance().getChatPath();
            String sendUrl = "http://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN&type=image";
            String mediaurl = "https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=ACCESS_TOKEN";//ACCESS_TOKEN是获取到的access_token
            String groupUrl = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=ACCESS_TOKEN";//根据openid发群发消息地址
            sendUrl = sendUrl.replace("ACCESS_TOKEN", accessToken);
            String image = SendNews.uploadImage(sendUrl, filePath);
            JSONObject newsTextData = new JSONObject();
            JSONArray newsText = new JSONArray();
//            续签图文
            JSONObject data = new JSONObject();
            data.put("thumb_media_id", new JSONObject(image).get("url"));
            data.put("author", "作者");
            data.put("content_source_url", "图文跳转链接");
            data.put("content", "图文消息内容");
            data.put("digest", "图文消息描述");
            data.put("show_cover_pic", 1);
//            签约图文
//            JSONObject data1 = new JSONObject();
//            data1.put("thumb_media_id",new JSONObject(image).get("url"));
//            data1.put("author","作者");
//            data1.put("content_source_url","图文跳转链接");
//            data1.put("content","图文消息内容");
//            data1.put("digest","图文消息描述");
//            data1.put("show_cover_pic",1);
            newsText.put(data);
//            newsText.put(data1);
            newsTextData.put("articles", newsText);
            String media = SendNews.uploadNesText(accessToken, mediaurl, newsTextData);
            JSONObject news = new JSONObject();
            JSONObject mapnews = new JSONObject();
            mapnews.put("media_id", new JSONObject(media).get("media_id"));
            List<String> openIds = patientDao.findOpenids();
            news.put("touser", openIds);
            news.put("mpnews", mapnews);
            news.put("msgtype", "mpnews");
            news.put("send_ignore_reprint", 1);
            SendNews.sendNewspMessage(accessToken, groupUrl, news);
            return write(200, "群发图文成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "群发图文失败!");
        }
    }
}

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/account/DoctorController.java

@ -1812,7 +1812,7 @@ public class DoctorController extends BaseController {
            @RequestParam(required = false) String typeId) {
        try {
            Long teamCode = Long.parseLong(teamId);
//            patients不为空是由团队中搜索居民 否则是分组分配健管师
//            patients不为空是由团队中分配及转移的搜索居民 转移健管师 否则是分组分配健管师
            if (StringUtils.isNotEmpty(patients)) {
                String result = updateTeamHealthDoctors(newDoctorCode, oldDoctorCode, patients, null);
                return result;

+ 63 - 49
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java

@ -8,7 +8,6 @@ import java.util.concurrent.TimeUnit;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.entity.patient.SignFamilyRenew;
import com.yihu.wlyy.logs.BusinessLogs;
import com.yihu.wlyy.repository.doctor.SignPatientLabelDao;
import com.yihu.wlyy.service.app.account.PatientInfoService;
@ -77,7 +76,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
     *
     * @param filter
     * @param teamCode
     * @param doctor 健管师编码
     * @param doctor   健管师编码
     * @param page
     * @param pagesize
     * @return
@ -212,7 +211,6 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            JSONObject list = familyContractService.getPatientByLable(doctorcode, labelType, level, team);
            return write(200, "查询成功", "data", list);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
@ -234,13 +232,13 @@ public class DoctorFamilyContractController extends WeixinBaseController {
                JSONArray jsonArray = list.getJSONArray(label.getLabelName());
                List codes = new ArrayList();
                for (int i = 0 ;i<jsonArray.length();i++){
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject json = jsonArray.getJSONObject(i);
                    Map info = new HashMap();
                    String code = json.getString("code");
                    String name = json.getString("name");
                    info.put("code",code);
                    info.put("name",name);
                    info.put("code", code);
                    info.put("name", name);
                    codes.add(info);
                }
                int length = codes.size();
@ -248,14 +246,13 @@ public class DoctorFamilyContractController extends WeixinBaseController {
                map.put("codes", codes);
                map.put("number", length);
                listNum.add(map);
                count+=length;
                count += length;
            }
            Map map = new HashMap();
            map.put("count",count);
            map.put("patients",listNum);
            map.put("count", count);
            map.put("patients", listNum);
            return write(200, "查询成功", "data", map);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
@ -513,7 +510,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
                        }
                    }
                } catch (Exception e) {
                    error(e);
                    e.printStackTrace();
                }
            }
@ -749,7 +746,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
//                    }
//                }
            } catch (Exception e) {
                error(e);
                e.printStackTrace();
            }
            result = familyContractService.getSanshiSingInfoByPatientIdCard(idCard);
@ -761,7 +758,6 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            return write(200, "查询成功!", "data", result);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");
        }
    }
@ -800,7 +796,6 @@ public class DoctorFamilyContractController extends WeixinBaseController {
                return write(-1, "不存在该患者签约");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "更新失败");
        }
    }
@ -839,12 +834,12 @@ public class DoctorFamilyContractController extends WeixinBaseController {
                // 设置患者联系电话
                json.put("phone", temp.getPhone());
                // 设置患者居住省份
                json.put("provinceName", temp.getProvinceName()==null?"":temp.getProvinceName());
                json.put("cityName", temp.getCityName()==null?"":temp.getCityName());
                json.put("townName", temp.getTownName()==null?"":temp.getTownName());
                json.put("streetName", temp.getStreetName()==null?"":temp.getStreetName());
                json.put("provinceName", temp.getProvinceName());
                json.put("cityName", temp.getCityName());
                json.put("townName", temp.getTownName());
                json.put("streetName", temp.getStreetName());
                // 设置患者地址
                json.put("address", temp.getAddress()==null?"":temp.getAddress());
                json.put("address", temp.getAddress());
                //设置患者医保号
                json.put("ssc", temp.getSsc());
@ -871,7 +866,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
                return error(-1, "患者信息查询失败!");
            }
        } catch (Exception e) {
            error(e);
            e.printStackTrace();
            return error(-1, "患者信息查询失败");
        }
    }
@ -942,7 +937,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
                return error(-1, "患者信息查询失败!");
            }
        } catch (Exception e) {
            error(e);
            e.printStackTrace();
            return error(-1, "患者信息查询失败");
        }
    }
@ -975,7 +970,6 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            return write(200, "查询成功", "data", json);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
@ -1001,7 +995,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            return write(200, "查询成功", "data", new JSONObject(signFamily));
        } catch (Exception e) {
            error(e);
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
@ -1035,7 +1029,6 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            }
            return write(200, "更新成功");
        } catch (Exception e) {
            error(e);
            return error(-1, "更新失败");
        }
    }
@ -1057,45 +1050,71 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            Map patients = new HashMap();
            JSONObject list = familyContractService.findNoHealthSignFamilyHealth(getUID(), labelType, patientName, teamCode);
            List<SignFamily> signFamily = familyContractService.findNoHealthSignFamilyNum(teamCode);
            if (!"4".equals(labelType)){
            if (!"4".equals(labelType)) {
                List<SignPatientLabel> s = labelDao.findByLabelTypeAndStatusAndTeamCode(labelType, 1, teamCode);
                for (SignPatientLabel label : s) {
                    Map map = new HashMap();
                    String labelName = label.getLabelName();
                    JSONArray jsonArray = list.getJSONArray(label.getLabelName());
               /* List codes = new ArrayList();
                for (Object patient:jsonArray) {
                    JSONObject jsonObject = new JSONObject(patient.toString());
                    String code = jsonObject.get("code").toString();
                    codes.add(code);
                }*/
                    List codes = new ArrayList();
                    for (Object patient : jsonArray) {
                        Map tempmap = new HashMap();
                        JSONObject jsonObject = new JSONObject(patient.toString());
                        String code = jsonObject.get("code").toString();
                        tempmap.put("code",code);
                        codes.add(tempmap);
                    }
                    int length = jsonArray.length();
                    map.put("label", labelName);
                    map.put("number", length);
//                map.put("codes", codes);
                    map.put("codes", codes);
                    listNum.add(map);
                }
            }else {
            } else {
                JSONArray jsonArray = list.getJSONArray("孕产妇");
                Map map = new HashMap();
                map.put("label", "孕产妇");
                List temp = new ArrayList();
                for (Object str : jsonArray) {
                    Map tempmap = new HashMap();
                    Object code = new JSONObject(str.toString()).get("code");
                    tempmap.put("code",code);
                    temp.add(tempmap);
                }
                map.put("codes", temp);
                map.put("number", jsonArray.length());
                listNum.add(map);
                JSONArray jsonArray1 = list.getJSONArray("未标注");
                Map map1 = new HashMap();
                map1.put("label", "未标注");
                List temp1 = new ArrayList();
                for (Object str : jsonArray1) {
                    Map tempmap = new HashMap();
                    Object code = new JSONObject(str.toString()).get("code");
                    tempmap.put("code",code);
                    temp1.add(tempmap);
                }
                map1.put("codes", temp1);
                map1.put("number", jsonArray1.length());
                listNum.add(map1);
                JSONArray jsonArray2 = list.getJSONArray("儿童");
                Map map2 = new HashMap();
                map2.put("label", "儿童");
                List temp2 = new ArrayList();
                for (Object str : jsonArray2) {
                    Map tempmap = new HashMap();
                    Object code = new JSONObject(str.toString()).get("code");
                    tempmap.put("code",code);
                    temp2.add(tempmap);
                }
                map2.put("codes", temp2);
                map2.put("number", jsonArray2.length());
                listNum.add(map2);
            }
            patients.put("count",list.length());
            patients.put("count",signFamily.size());
            patients.put("patients",listNum);
            patients.put("count", list.length());
            patients.put("count", signFamily.size());
            patients.put("patients", listNum);
            return write(200, "查询成功!", "data", patients);
        } catch (Exception e) {
            error(e);
@ -1119,7 +1138,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            JSONObject list = familyContractService.findNoHealthSignFamilyHealth(getUID(), labelType, patientName, teamCode);
            return write(200, "签约数据加载成功!", "data", list);
        } catch (Exception e) {
            error(e);
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
@ -1139,7 +1158,6 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            JSONObject list = familyContractService.findNoHealthSignFamilyHealthByParams(getUID(), teamCode, params);
            return write(200, "签约数据加载成功!", "data", list);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
@ -1159,7 +1177,6 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            JSONObject list = familyContractService.findByParamsWithDoctor(doctor, teamCode, params, level);
            return write(200, "签约数据加载成功!", "data", list);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
@ -1184,7 +1201,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            }
            return write(200, "查询成功", "data", jo);
        } catch (Exception e) {
            error(e);
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
@ -1255,7 +1272,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            }
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            error(e);
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
@ -1280,7 +1297,6 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            JSONObject result = familyContractService.isPatientAndDoctorExistSign(patient, doctor);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
@ -1305,7 +1321,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            JSONObject result = familyContractService.isPatientAndDoctorCanSign(patient, doctor);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            error(e);
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
@ -1326,7 +1342,6 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            JSONObject result = familyContractService.getPatientDoctors(patient, getUID());
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
@ -1347,7 +1362,6 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            JSONObject result = familyContractService.getTeamDoctors(sessionId, getUID());
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
@ -1366,7 +1380,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            JSONObject result = familyContractService.getPatientSignDoctors(patient);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            error(e);
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
@ -1384,7 +1398,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            JSONObject result = familyContractService.getPatientSignDoctorsByTeam(sessionId);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            error(e);
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
@ -1401,7 +1415,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            JSONObject result = familyContractService.getPatientAndDoctorTeams(patient, getUID());
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            error(e);
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
@ -1469,7 +1483,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            }
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            error(e);
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }

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

@ -38,7 +38,7 @@ public class PatientDeviceController extends BaseController {
    /**
     * 设置血糖仪时间段
     * 设置及修改血糖仪时间段
     * 默认时间段如下
     * fasting: 00:00-07:59
     * afterBreakfast: 08:00-09:59
@ -48,23 +48,23 @@ public class PatientDeviceController extends BaseController {
     * afterDinner: 18:00-19:59
     * beforeSleep: 20:00-23:59
     */
    @ApiOperation("设置血糖仪时间段")
    @ApiOperation("设置修改血糖仪时间段")
    @RequestMapping(value = "/setBloodTime", method = RequestMethod.GET)
    @ResponseBody
    public String setBloodTime(@RequestParam String fastingStart,
                               @RequestParam String fastingEnd,
                               @RequestParam String afterBreakfastStart,
                               @RequestParam String afterBreakfastEnd,
                               @RequestParam String beforeLunchStart,
                               @RequestParam String beforeLunchEnd,
                               @RequestParam String afterLunchStart,
                               @RequestParam String afterLunchEnd,
                               @RequestParam String beforeDinnerStart,
                               @RequestParam String beforeDinnerEnd,
                               @RequestParam String afterDinnerStart,
                               @RequestParam String afterDinnerEnd,
                               @RequestParam String beforeSleepStart,
                               @RequestParam String beforeSleepEnd,
    public String setBloodTime(@RequestParam(required = false) String fastingStart,
                               @RequestParam(required = false) String fastingEnd,
                               @RequestParam(required = false) String afterBreakfastStart,
                               @RequestParam(required = false) String afterBreakfastEnd,
                               @RequestParam(required = false) String beforeLunchStart,
                               @RequestParam(required = false) String beforeLunchEnd,
                               @RequestParam(required = false) String afterLunchStart,
                               @RequestParam(required = false) String afterLunchEnd,
                               @RequestParam(required = false) String beforeDinnerStart,
                               @RequestParam(required = false) String beforeDinnerEnd,
                               @RequestParam(required = false) String afterDinnerStart,
                               @RequestParam(required = false) String afterDinnerEnd,
                               @RequestParam(required = false)String beforeSleepStart,
                               @RequestParam(required = false)String beforeSleepEnd,
                               @RequestParam String deviceSN) {
        try {

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

@ -1,9 +1,11 @@
package com.yihu.wlyy.web.patient.health;
import java.text.SimpleDateFormat;
import java.util.*;
import com.alibaba.fastjson.JSON;
import com.yihu.wlyy.health.entity.DevicePatientHealthIndex;
import com.yihu.wlyy.util.SendNews;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -30,576 +32,606 @@ import com.yihu.wlyy.web.BaseController;
@Api(description = "患者指标")
public class PatientHealthController extends BaseController {
	@Autowired
	private PatientHealthIndexService healthIndexService;
    @Autowired
    private PatientHealthIndexService healthIndexService;
	/**
	 * 更改接口(包括手动记录的修改和所有的删除)
	 * 血糖  value1 血糖值 value2 1234567血糖时间段
	 * 血压  value1 高压 value2 低压 value3脉搏 value4心率不齐(0否 1是)
	 * 体重 value1 体重值
	 * 腰围 value1 腰围值
	 *
	 * @param id
	 * @param value1 字段值
	 * @return
	 */
	@RequestMapping(value = "/modify", method = RequestMethod.GET)
	@ResponseBody
	public String modify(@RequestParam long id,
						 @RequestParam(required = false) String value1,
						 @RequestParam(required = false) String value2,
						 @RequestParam(required = false) String value3,
						 @RequestParam(required = false) String value4) {
		try {
			healthIndexService.modify(id, value1, value2, value3, value4);
			return write(200, "更改成功!");
		} catch (Exception e) {
			error(e);
			return invalidUserException(e, -1, "更改失败!");
		}
	}
    /**
     * 更改接口(包括手动记录的修改和所有的删除)
     * 血糖  value1 血糖值 value2 1234567血糖时间段
     * 血压  value1 高压 value2 低压 value3脉搏 value4心率不齐(0否 1是)
     * 体重 value1 体重值
     * 腰围 value1 腰围值
     *
     * @param id
     * @param recordDate 记录时间
     * @param value1 字段值
     * @return
     */
    @RequestMapping(value = "/modify", method = RequestMethod.GET)
    @ResponseBody
    public String modify(@RequestParam long id,
                         @RequestParam(required = false) String recordDate,
                         @RequestParam(required = false) String value1,
                         @RequestParam(required = false) String value2,
                         @RequestParam(required = false) String value3,
                         @RequestParam(required = false) String value4) {
        try {
            healthIndexService.modify(id,recordDate, value1, value2, value3, value4);
            return write(200, "更改成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "更改失败!");
        }
    }
	/**
	 * 患者最近的各项健康信息
	 *
	 * @return
	 */
	@RequestMapping(value = "/getRecentData")
	@ResponseBody
	public String getRecentData() {
		try {
			List list = new ArrayList();
			String patient = getUID();
    /**
     * 保健记录更改接口(包括手动记录的修改和所有的删除)
     *
     * @param id
     * @param type   饮食1,运动2,用药3
     * @param value1 记录时间
     * @param value2 饮食内容CONTETN  时长 用药
     * @param value3 上传图片 强度
     * @param value4 运动项目
     * @return
     */
    @RequestMapping(value = "/modifyHealthCare", method = RequestMethod.GET)
    @ResponseBody
    public String modifyHealthCare(@RequestParam long id,
                                   @RequestParam int type,
                                   @RequestParam(required = false) String value1,
                                   @RequestParam(required = false) String value2,
                                   @RequestParam(required = false) String value3,
                                   @RequestParam(required = false) String value4) {
        try {
            healthIndexService.modifyHealthCare(id, type, value1, value2, value3, value4);
            return write(200, "更改成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "更改失败!");
        }
    }
    /**
     * 患者最近的各项健康信息
     *
     * @return
     */
    @RequestMapping(value = "/getRecentData")
    @ResponseBody
    public String getRecentData() {
        try {
            List list = new ArrayList();
            String patient = getUID();
//            健康指标类型(1血糖,2血压,3体重,4腰围)
			Map map = healthIndexService.findDataByPatient(patient, 1);
			Map map1 = healthIndexService.findDataByPatient(patient, 2);
			Map map2 = healthIndexService.findDataByPatient(patient, 3);
			Map map3 = healthIndexService.findDataByPatient(patient, 4);
            Map map = healthIndexService.findDataByPatient(patient, 1);
            Map map1 = healthIndexService.findDataByPatient(patient, 2);
            Map map2 = healthIndexService.findDataByPatient(patient, 3);
            Map map3 = healthIndexService.findDataByPatient(patient, 4);
//            血糖各个时间段取值
			if (map.size() != 0) {
				Map sugar = new HashMap();
				Object time = map.get("time");
				String isDevice = map.get("isDevice").toString();
				Object value1 = map.get("value1");
				Object value2 = map.get("value2");
				Object value3 = map.get("value3");
				Object value4 = map.get("value4");
				Object value5 = map.get("value5");
				Object value6 = map.get("value6");
				Object value7 = map.get("value7");
				sugar.put("type", 1);
				sugar.put("isDevice", isDevice);
				if (time != null) {
					sugar.put("time", time);
				}
				if (value1 != null) {
					sugar.put("value1", value1);
				}
				if (value2 != null) {
					sugar.put("value2", value2);
				}
				if (value3 != null) {
					sugar.put("value3", value3);
				}
				if (value4 != null) {
					sugar.put("value4", value4);
				}
				if (value5 != null) {
					sugar.put("value5", value5);
				}
				if (value6 != null) {
					sugar.put("value6", value6);
				}
				if (value7 != null) {
					sugar.put("value7", value7);
				}
				list.add(sugar);
			}
            if (map.size() != 0) {
                Map sugar = new HashMap();
                Object time = map.get("time");
                String isDevice = map.get("isDevice").toString();
                Object value1 = map.get("value1");
                Object value2 = map.get("value2");
                Object value3 = map.get("value3");
                Object value4 = map.get("value4");
                Object value5 = map.get("value5");
                Object value6 = map.get("value6");
                Object value7 = map.get("value7");
                sugar.put("type", 1);
                sugar.put("isDevice", isDevice);
                if (time != null) {
                    sugar.put("time", time);
                }
                if (value1 != null) {
                    sugar.put("value1", value1);
                }
                if (value2 != null) {
                    sugar.put("value2", value2);
                }
                if (value3 != null) {
                    sugar.put("value3", value3);
                }
                if (value4 != null) {
                    sugar.put("value4", value4);
                }
                if (value5 != null) {
                    sugar.put("value5", value5);
                }
                if (value6 != null) {
                    sugar.put("value6", value6);
                }
                if (value7 != null) {
                    sugar.put("value7", value7);
                }
                list.add(sugar);
            }
//            血压  value1高压 value2低压 value3脉搏 value4心率不齐
			if (map1.size() != 0) {
				Map pa = new HashMap();
				Object time = map1.get("time");
				String isDevice = map1.get("isDevice").toString();
				Object value1 = map1.get("value1");
				Object value2 = map1.get("value2");
				Object value3 = map1.get("value3");
				Object value4 = map1.get("value4");
				Object value5 = map1.get("value5");
				Object value6 = map1.get("value6");
				Object value7 = map1.get("value7");
				pa.put("type", 2);
				pa.put("isDevice", isDevice);
				if (time != null) {
					pa.put("time", time);
				}
				if (value1 != null) {
					pa.put("value1", value1);
				}
				if (value2 != null) {
					pa.put("value2", value2);
				}
				if (value3 != null) {
					pa.put("value3", value3);
				}
				if (value4 != null) {
					pa.put("value4", value4);
				}
				if (value5 != null) {
					pa.put("value5", value5);
				}
				if (value6 != null) {
					pa.put("value6", value6);
				}
				if (value7 != null) {
					pa.put("value7", value7);
				}
				list.add(pa);
			}
            if (map1.size() != 0) {
                Map pa = new HashMap();
                Object time = map1.get("time");
                String isDevice = map1.get("isDevice").toString();
                Object value1 = map1.get("value1");
                Object value2 = map1.get("value2");
                Object value3 = map1.get("value3");
                Object value4 = map1.get("value4");
                Object value5 = map1.get("value5");
                Object value6 = map1.get("value6");
                Object value7 = map1.get("value7");
                pa.put("type", 2);
                pa.put("isDevice", isDevice);
                if (time != null) {
                    pa.put("time", time);
                }
                if (value1 != null) {
                    pa.put("value1", value1);
                }
                if (value2 != null) {
                    pa.put("value2", value2);
                }
                if (value3 != null) {
                    pa.put("value3", value3);
                }
                if (value4 != null) {
                    pa.put("value4", value4);
                }
                if (value5 != null) {
                    pa.put("value5", value5);
                }
                if (value6 != null) {
                    pa.put("value6", value6);
                }
                if (value7 != null) {
                    pa.put("value7", value7);
                }
                list.add(pa);
            }
//            体重 value1 体重
			if (map2.size() != 0) {
				Map weight = new HashMap();
				Object time = map2.get("time");
				String isDevice = map2.get("isDevice").toString();
				Object value1 = map2.get("value1");
				Object value2 = map2.get("value2");
				Object value3 = map2.get("value3");
				Object value4 = map2.get("value4");
				Object value5 = map2.get("value5");
				Object value6 = map2.get("value6");
				Object value7 = map2.get("value7");
				weight.put("type", 3);
				weight.put("isDevice", isDevice);
				if (time != null) {
					weight.put("time", time);
				}
				if (value1 != null) {
					weight.put("value1", value1);
				}
				if (value2 != null) {
					weight.put("value2", value2);
				}
				if (value3 != null) {
					weight.put("value3", value3);
				}
				if (value4 != null) {
					weight.put("value4", value4);
				}
				if (value5 != null) {
					weight.put("value5", value5);
				}
				if (value6 != null) {
					weight.put("value6", value6);
				}
				if (value7 != null) {
					weight.put("value7", value7);
				}
				list.add(weight);
			}
            if (map2.size() != 0) {
                Map weight = new HashMap();
                Object time = map2.get("time");
                String isDevice = map2.get("isDevice").toString();
                Object value1 = map2.get("value1");
                Object value2 = map2.get("value2");
                Object value3 = map2.get("value3");
                Object value4 = map2.get("value4");
                Object value5 = map2.get("value5");
                Object value6 = map2.get("value6");
                Object value7 = map2.get("value7");
                weight.put("type", 3);
                weight.put("isDevice", isDevice);
                if (time != null) {
                    weight.put("time", time);
                }
                if (value1 != null) {
                    weight.put("value1", value1);
                }
                if (value2 != null) {
                    weight.put("value2", value2);
                }
                if (value3 != null) {
                    weight.put("value3", value3);
                }
                if (value4 != null) {
                    weight.put("value4", value4);
                }
                if (value5 != null) {
                    weight.put("value5", value5);
                }
                if (value6 != null) {
                    weight.put("value6", value6);
                }
                if (value7 != null) {
                    weight.put("value7", value7);
                }
                list.add(weight);
            }
//            腰围 value1腰围
			if (map3.size() != 0) {
				Map waist = new HashMap();
				Object time = map3.get("time");
				String isDevice = map3.get("isDevice").toString();
				Object value1 = map3.get("value1");
				Object value2 = map3.get("value2");
				Object value3 = map3.get("value3");
				Object value4 = map3.get("value4");
				Object value5 = map3.get("value5");
				Object value6 = map3.get("value6");
				Object value7 = map3.get("value7");
				waist.put("type", 4);
				waist.put("isDevice", isDevice);
				if (time != null) {
					waist.put("time", time);
				}
				if (value1 != null) {
					waist.put("value1", value1);
				}
				if (value2 != null) {
					waist.put("value2", value2);
				}
				if (value3 != null) {
					waist.put("value3", value3);
				}
				if (value4 != null) {
					waist.put("value4", value4);
				}
				if (value5 != null) {
					waist.put("value5", value5);
				}
				if (value6 != null) {
					waist.put("value6", value6);
				}
				if (value7 != null) {
					waist.put("value7", value7);
				}
				list.add(waist);
			}
			return write(200, "查询成功", "data", list);
		} catch (Exception e) {
			error(e);
			return error(-1, "查询失败");
		}
	}
            if (map3.size() != 0) {
                Map waist = new HashMap();
                Object time = map3.get("time");
                String isDevice = map3.get("isDevice").toString();
                Object value1 = map3.get("value1");
                Object value2 = map3.get("value2");
                Object value3 = map3.get("value3");
                Object value4 = map3.get("value4");
                Object value5 = map3.get("value5");
                Object value6 = map3.get("value6");
                Object value7 = map3.get("value7");
                waist.put("type", 4);
                waist.put("isDevice", isDevice);
                if (time != null) {
                    waist.put("time", time);
                }
                if (value1 != null) {
                    waist.put("value1", value1);
                }
                if (value2 != null) {
                    waist.put("value2", value2);
                }
                if (value3 != null) {
                    waist.put("value3", value3);
                }
                if (value4 != null) {
                    waist.put("value4", value4);
                }
                if (value5 != null) {
                    waist.put("value5", value5);
                }
                if (value6 != null) {
                    waist.put("value6", value6);
                }
                if (value7 != null) {
                    waist.put("value7", value7);
                }
                list.add(waist);
            }
            return write(200, "查询成功", "data", list);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
	/**
	 * 患者最近填写的健康指标
	 *
	 * @return
	 */
	@RequestMapping(value = "recent")
	@ResponseBody
	public String recent() {
		try {
			JSONArray array = healthIndexService.findRecentByPatient(getUID());
			if (array != null) {
				return write(200, "查询成功", "list", array);
			} else {
				return error(-1, "查询失败");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "查询失败");
		}
	}
    /**
     * 患者最近填写的健康指标
     *
     * @return
     */
    @RequestMapping(value = "recent")
    @ResponseBody
    public String recent() {
        try {
            JSONArray array = healthIndexService.findRecentByPatient(getUID());
            if (array != null) {
                return write(200, "查询成功", "list", array);
            } else {
                return error(-1, "查询失败");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
	/**
	 * 获取患者最后填写的健康指标(新)
	 *
	 * @return
	 */
	@RequestMapping(value = "last")
	@ResponseBody
	public String last() {
		try {
			Map<String, Object> map = new HashMap<>();
			String patient = getUID();
			DevicePatientHealthIndex xt = healthIndexService.findLastByPatien(patient, 1);
			if (xt != null) {
				map.put("xt", xt);
			}
			DevicePatientHealthIndex xy = healthIndexService.findLastByPatien(patient, 2);
			if (xy != null) {
				map.put("xy", xy);
			}
			DevicePatientHealthIndex tz = healthIndexService.findLastByPatien(patient, 3);
			if (tz != null) {
				map.put("tz", tz);
			}
			DevicePatientHealthIndex sg = healthIndexService.findLastByPatien(patient, 4);
			if (sg != null) {
				map.put("sg", sg);
			}
			return write(200, "查询成功", "data", map);
		} catch (Exception ex) {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
    /**
     * 获取患者最后填写的健康指标(新)
     *
     * @return
     */
    @RequestMapping(value = "last")
    @ResponseBody
    public String last() {
        try {
            Map<String, Object> map = new HashMap<>();
            String patient = getUID();
            DevicePatientHealthIndex xt = healthIndexService.findLastByPatien(patient, 1);
            if (xt != null) {
                map.put("xt", xt);
            }
            DevicePatientHealthIndex xy = healthIndexService.findLastByPatien(patient, 2);
            if (xy != null) {
                map.put("xy", xy);
            }
            DevicePatientHealthIndex tz = healthIndexService.findLastByPatien(patient, 3);
            if (tz != null) {
                map.put("tz", tz);
            }
            DevicePatientHealthIndex sg = healthIndexService.findLastByPatien(patient, 4);
            if (sg != null) {
                map.put("sg", sg);
            }
            return write(200, "查询成功", "data", map);
        } catch (Exception ex) {
            return invalidUserException(ex, -1, ex.getMessage());
        }
    }
	/**
	 * 保存患者健康指标 (旧)
	 *
	 * @param intervene 干预标志
	 * @param time      记录时间
	 * @param value1    血糖/收缩压/体重/腰围/早餐前空腹
	 * @param value2    舒张压/早餐后空腹
	 * @param value3    午餐空腹
	 * @param value4    午餐后
	 * @param value5    晚餐空腹
	 * @param value6    晚餐后
	 * @param value7    睡前
	 * @param type      健康指标类型(1血糖,2血压,3体重,4腰围)
	 * @return 操作结果
	 */
	@RequestMapping(value = "add")
	@ResponseBody
	public String add(@RequestParam(required = false) String intervene, String time, String value1, String value2, String value3, String value4, String value5, String value6, String value7, int type) {
		try {
    /**
     * 保存患者健康指标 (旧)
     *
     * @param intervene 干预标志
     * @param time      记录时间
     * @param value1    血糖/收缩压/体重/腰围/早餐前空腹
     * @param value2    舒张压/早餐后空腹
     * @param value3    午餐空腹
     * @param value4    午餐后
     * @param value5    晚餐空腹
     * @param value6    晚餐后
     * @param value7    睡前
     * @param type      健康指标类型(1血糖,2血压,3体重,4腰围)
     * @return 操作结果
     */
    @RequestMapping(value = "add")
    @ResponseBody
    public String add(@RequestParam(required = false) String intervene, String time, String value1, String value2, String value3, String value4, String value5, String value6, String value7, int type) {
        try {
			DevicePatientHealthIndex healthIndex = null;
			if (type == 1) {
				// 血糖等一天只能存在一条数据
				Iterable<DevicePatientHealthIndex> list = healthIndexService.findByPatienDate(getUID(), type, DateUtil.strToDate(time, DateUtil.YYYY_MM_DD));
				if (list != null) {
					for (DevicePatientHealthIndex model : list) {
						healthIndex = model;
					}
				}
			}
			if (healthIndex == null) {
				healthIndex = new DevicePatientHealthIndex();
			}
			// 设置患者标识
			healthIndex.setUser(getUID());
			// 设置干预标识,默认为NULL
			healthIndex.setIntervene(intervene);
            DevicePatientHealthIndex healthIndex = null;
            if (type == 1) {
                // 血糖等一天只能存在一条数据
                Iterable<DevicePatientHealthIndex> list = healthIndexService.findByPatienDate(getUID(), type, DateUtil.strToDate(time, DateUtil.YYYY_MM_DD));
                if (list != null) {
                    for (DevicePatientHealthIndex model : list) {
                        healthIndex = model;
                    }
                }
            }
            if (healthIndex == null) {
                healthIndex = new DevicePatientHealthIndex();
            }
            // 设置患者标识
            healthIndex.setUser(getUID());
            // 设置干预标识,默认为NULL
            healthIndex.setIntervene(intervene);
			int index = 0;
			double value = 0;
            int index = 0;
            double value = 0;
			// 设置血糖/收缩压/体重/腰围/早餐前空腹
			if (NumberUtils.toDouble(value1, 0) > 0) {
				healthIndex.setValue1(value1);
				index = 1;
				value = NumberUtils.toDouble(value1, 0);
			}
			// 设置 舒张压/早餐后血糖
			if (NumberUtils.toDouble(value2, 0) > 0) {
				healthIndex.setValue2(value2);
				index = 2;
				value = NumberUtils.toDouble(value2, 0);
			}
			// 设置午餐前血糖
			if (NumberUtils.toDouble(value3, 0) > 0) {
				healthIndex.setValue3(value3);
				index = 3;
				value = NumberUtils.toDouble(value3, 0);
			}
			// 设置午餐后血糖
			if (NumberUtils.toDouble(value4, 0) > 0) {
				healthIndex.setValue4(value4);
				index = 4;
				value = NumberUtils.toDouble(value4, 0);
			}
			// 设置晚餐前血糖
			if (NumberUtils.toDouble(value5, 0) > 0) {
				healthIndex.setValue5(value5);
				index = 5;
				value = NumberUtils.toDouble(value5, 0);
			}
			// 设置晚餐后血糖
			if (NumberUtils.toDouble(value6, 0) > 0) {
				healthIndex.setValue6(value6);
				index = 6;
				value = NumberUtils.toDouble(value6, 0);
			}
			// 设置睡前血糖
			if (NumberUtils.toDouble(value7, 0) > 0) {
				healthIndex.setValue7(value7);
				index = 7;
				value = NumberUtils.toDouble(value7, 0);
			}
			// 设置健康指标类型(1血糖,2血压,3体重,4腰围)
			healthIndex.setType(type);
			// 设置记录时间
			if (type == 2) {
				healthIndex.setRecordDate(DateUtil.strToDate(time, DateUtil.YYYY_MM_DD_HH_MM_SS));
			} else {
				healthIndex.setRecordDate(DateUtil.strToDate(time, DateUtil.YYYY_MM_DD));
			}
			healthIndex.setSortDate(DateUtil.strToDateAppendNowTime(time, DateUtil.YYYY_MM_DD_HH_MM_SS));
			// 保存到数据库
			healthIndex = healthIndexService.save(healthIndex, index, value, getUID());
			if (healthIndex == null) {
				return error(-1, "保存失败!");
			}
			return success("保存成功!");
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "保存失败!");
		}
	}
            // 设置血糖/收缩压/体重/腰围/早餐前空腹
            if (NumberUtils.toDouble(value1, 0) > 0) {
                healthIndex.setValue1(value1);
                index = 1;
                value = NumberUtils.toDouble(value1, 0);
            }
            // 设置 舒张压/早餐后血糖
            if (NumberUtils.toDouble(value2, 0) > 0) {
                healthIndex.setValue2(value2);
                index = 2;
                value = NumberUtils.toDouble(value2, 0);
            }
            // 设置午餐前血糖
            if (NumberUtils.toDouble(value3, 0) > 0) {
                healthIndex.setValue3(value3);
                index = 3;
                value = NumberUtils.toDouble(value3, 0);
            }
            // 设置午餐后血糖
            if (NumberUtils.toDouble(value4, 0) > 0) {
                healthIndex.setValue4(value4);
                index = 4;
                value = NumberUtils.toDouble(value4, 0);
            }
            // 设置晚餐前血糖
            if (NumberUtils.toDouble(value5, 0) > 0) {
                healthIndex.setValue5(value5);
                index = 5;
                value = NumberUtils.toDouble(value5, 0);
            }
            // 设置晚餐后血糖
            if (NumberUtils.toDouble(value6, 0) > 0) {
                healthIndex.setValue6(value6);
                index = 6;
                value = NumberUtils.toDouble(value6, 0);
            }
            // 设置睡前血糖
            if (NumberUtils.toDouble(value7, 0) > 0) {
                healthIndex.setValue7(value7);
                index = 7;
                value = NumberUtils.toDouble(value7, 0);
            }
            // 设置健康指标类型(1血糖,2血压,3体重,4腰围)
            healthIndex.setType(type);
            // 设置记录时间
            if (type == 2) {
                healthIndex.setRecordDate(DateUtil.strToDate(time, DateUtil.YYYY_MM_DD_HH_MM_SS));
            } else {
                healthIndex.setRecordDate(DateUtil.strToDate(time, DateUtil.YYYY_MM_DD));
            }
            healthIndex.setSortDate(DateUtil.strToDateAppendNowTime(time, DateUtil.YYYY_MM_DD_HH_MM_SS));
            // 保存到数据库
            healthIndex = healthIndexService.save(healthIndex, index, value, getUID());
            if (healthIndex == null) {
                return error(-1, "保存失败!");
            }
            return success("保存成功!");
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "保存失败!");
        }
    }
	@RequestMapping(value = "addPatientHealthIndex", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("新增患者指标")
	public String addPatientHealthIndex(@ApiParam(name = "data", value = "指标数据", defaultValue = "{\"gi\":\"5.5\",\"gi_type\":\"1\"}")
										@RequestParam(value = "data", required = true) String data,
										@ApiParam(name = "type", value = "指标类型", defaultValue = "1")
										@RequestParam(value = "type", required = true) String type) {
		try {
			DevicePatientHealthIndex obj = healthIndexService.addPatientHealthIndex(data, type, getUID(), null);
			//血糖和血压需要校验
			if (type.equals("1") || type.equals("2")) {
				healthIndexService.verifyHealthIndex(obj.getId());
			}
    @RequestMapping(value = "addPatientHealthIndex", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("新增患者指标")
    public String addPatientHealthIndex(@ApiParam(name = "data", value = "指标数据", defaultValue = "{\"gi\":\"5.5\",\"gi_type\":\"1\"}")
                                        @RequestParam(value = "data", required = true) String data,
                                        @ApiParam(name = "type", value = "指标类型", defaultValue = "1")
                                        @RequestParam(value = "type", required = true) String type) {
        try {
            DevicePatientHealthIndex obj = healthIndexService.addPatientHealthIndex(data, type, getUID(), null);
            //血糖和血压需要校验
            if (type.equals("1") || type.equals("2")) {
                healthIndexService.verifyHealthIndex(obj.getId());
            }
			return success("新增患者指标成功!");
		} catch (Exception ex) {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
            return success("新增患者指标成功!");
        } catch (Exception ex) {
            return invalidUserException(ex, -1, ex.getMessage());
        }
    }
	@RequestMapping(value = "verifyPatientHealthIndex", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("校验患者指标")
	public String verifyPatientHealthIndex(@ApiParam(name = "id", value = "指标id", defaultValue = "")
										   @RequestParam(value = "id", required = true) Long id) {
		try {
			healthIndexService.verifyHealthIndex(id);
    @RequestMapping(value = "verifyPatientHealthIndex", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("校验患者指标")
    public String verifyPatientHealthIndex(@ApiParam(name = "id", value = "指标id", defaultValue = "")
                                           @RequestParam(value = "id", required = true) Long id) {
        try {
            healthIndexService.verifyHealthIndex(id);
			return success("校验患者指标成功!");
		} catch (Exception ex) {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
            return success("校验患者指标成功!");
        } catch (Exception ex) {
            return invalidUserException(ex, -1, ex.getMessage());
        }
    }
	/**
	 * 根据患者标志获取健康指标
	 *
	 * @param type 健康指标类型(1血糖,2血压,3体重,4腰围)
	 * @return 操作结果
	 */
	@RequestMapping(value = "chart", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("根据患者标志获取健康指标(图表)")
	public String getHealthIndexChartByPatient(@ApiParam(name = "type", value = "指标类型", defaultValue = "1")
											   @RequestParam(value = "type", required = true) int type,
											   @ApiParam(name = "gi_type", value = "就餐类型", defaultValue = "1")
											   @RequestParam(value = "gi_type", required = false) int gi_type,
											   @ApiParam(name = "begin", value = "开始时间", defaultValue = "2016-08-23 00:00:00")
											   @RequestParam(value = "begin", required = true) String begin,
											   @ApiParam(name = "end", value = "结束时间", defaultValue = "2016-09-23 00:00:00")
											   @RequestParam(value = "end", required = true) String end) {
		try {
			List<DevicePatientHealthIndex> list =
					healthIndexService.findChartByPatient(getUID(), type, gi_type, begin, end);
    /**
     * 根据患者标志获取健康指标
     *
     * @param type 健康指标类型(1血糖,2血压,3体重,4腰围)
     * @return 操作结果
     */
    @RequestMapping(value = "chart", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("根据患者标志获取健康指标(图表)")
    public String getHealthIndexChartByPatient(@ApiParam(name = "type", value = "指标类型", defaultValue = "1")
                                               @RequestParam(value = "type", required = true) int type,
                                               @ApiParam(name = "gi_type", value = "就餐类型", defaultValue = "1")
                                               @RequestParam(value = "gi_type", required = false) int gi_type,
                                               @ApiParam(name = "begin", value = "开始时间", defaultValue = "2016-08-23 00:00:00")
                                               @RequestParam(value = "begin", required = true) String begin,
                                               @ApiParam(name = "end", value = "结束时间", defaultValue = "2016-09-23 00:00:00")
                                               @RequestParam(value = "end", required = true) String end) {
        try {
            List<DevicePatientHealthIndex> list =
                    healthIndexService.findChartByPatient(getUID(), type, gi_type, begin, end);
			if (list == null) {
				return success("查询成功!");
			}
			JSONArray jsonArray = new JSONArray();
			for (DevicePatientHealthIndex model : list) {
				JSONObject modelJson = new JSONObject();
				modelJson.put("patient", model.getUser());
				modelJson.put("value1", model.getValue1());
				modelJson.put("value2", model.getValue2());
				modelJson.put("value3", model.getValue3());
				modelJson.put("value4", model.getValue4());
				modelJson.put("value5", model.getValue5());
				modelJson.put("value6", model.getValue6());
				modelJson.put("value7", model.getValue7());
				modelJson.put("type", model.getType());
				if (type == 2) {
					modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD_HH_MM_SS));
				} else {
					modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD));
				}
				modelJson.put("czrq", DateUtil.dateToStr(model.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
				jsonArray.put(modelJson);
			}
			return write(200, "查询成功", "list", jsonArray);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
            if (list == null) {
                return success("查询成功!");
            }
            JSONArray jsonArray = new JSONArray();
            for (DevicePatientHealthIndex model : list) {
                JSONObject modelJson = new JSONObject();
                modelJson.put("patient", model.getUser());
                modelJson.put("value1", model.getValue1());
                modelJson.put("value2", model.getValue2());
                modelJson.put("value3", model.getValue3());
                modelJson.put("value4", model.getValue4());
                modelJson.put("value5", model.getValue5());
                modelJson.put("value6", model.getValue6());
                modelJson.put("value7", model.getValue7());
                modelJson.put("type", model.getType());
                if (type == 2) {
                    modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD_HH_MM_SS));
                } else {
                    modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD));
                }
                modelJson.put("czrq", DateUtil.dateToStr(model.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
                jsonArray.put(modelJson);
            }
            return write(200, "查询成功", "list", jsonArray);
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "查询失败!");
        }
    }
	/**
	 * 根据患者标志获取健康指标
	 *
	 * @param type     健康指标类型(1血糖,2血压,3体重,4腰围)
	 * @param pagesize 页数
	 * @return 操作结果
	 */
	@RequestMapping(value = "list", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("患者获取健康指标")
	public String getHealthIndexByPatient(@ApiParam(name = "type", value = "指标类型", defaultValue = "1")
										  @RequestParam(value = "type", required = true) int type,
										  @ApiParam(name = "start", value = "开始时间", defaultValue = "2016-07-23 00:00:00")
										  @RequestParam(value = "start", required = true) String start,
										  @ApiParam(name = "end", value = "结束时间", defaultValue = "2016-08-23 00:00:00")
										  @RequestParam(value = "end", required = true) String end,
										  @ApiParam(name = "page", value = "第几页", defaultValue = "1")
										  @RequestParam(value = "page", required = true) int page,
										  @ApiParam(name = "pagesize", value = "每页几行", defaultValue = "10")
										  @RequestParam(value = "pagesize", required = true) int pagesize) {
		try {
			JSONArray jsonArray = new JSONArray();
			if (type == 1) {
				List<Object> list = healthIndexService.findIndexByPatient2(getUID(), type, start, end, page, pagesize);
				jsonArray = new JSONArray(list);
			}else{
				List<DevicePatientHealthIndex> list = healthIndexService.findIndexByPatient(getUID(), type, start, end, page, pagesize);
				if (list != null) {
					for (DevicePatientHealthIndex model : list) {
						JSONObject modelJson = new JSONObject();
						modelJson.put("id", model.getId());
						modelJson.put("patient", model.getUser());
						modelJson.put("value1", model.getValue1());
						modelJson.put("value2", model.getValue2());
						modelJson.put("value3", model.getValue3());
						modelJson.put("value4", model.getValue4());
						modelJson.put("value5", model.getValue5());
						modelJson.put("value6", model.getValue6());
						modelJson.put("value7", model.getValue7());
						modelJson.put("type", model.getType());
						if (type == 2) {
							modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD_HH_MM_SS));
						} else {
							modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD));
						}
						modelJson.put("sortDate", DateUtil.dateToStrLong(model.getSortDate()));
						modelJson.put("czrq", DateUtil.dateToStr(model.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
						jsonArray.put(modelJson);
					}
				}
			}
    /**
     * 根据患者标志获取健康指标
     *
     * @param type     健康指标类型(1血糖,2血压,3体重,4腰围)
     * @param pagesize 页数
     * @return 操作结果
     */
    @RequestMapping(value = "list", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("患者获取健康指标")
    public String getHealthIndexByPatient(@ApiParam(name = "type", value = "指标类型", defaultValue = "1")
                                          @RequestParam(value = "type", required = true) int type,
                                          @ApiParam(name = "start", value = "开始时间", defaultValue = "2016-07-23 00:00:00")
                                          @RequestParam(value = "start", required = true) String start,
                                          @ApiParam(name = "end", value = "结束时间", defaultValue = "2016-08-23 00:00:00")
                                          @RequestParam(value = "end", required = true) String end,
                                          @ApiParam(name = "page", value = "第几页", defaultValue = "1")
                                          @RequestParam(value = "page", required = true) int page,
                                          @ApiParam(name = "pagesize", value = "每页几行", defaultValue = "10")
                                          @RequestParam(value = "pagesize", required = true) int pagesize) {
        try {
            JSONArray jsonArray = new JSONArray();
            if (type == 1) {
                List<Object> list = healthIndexService.findIndexByPatient2(getUID(), type, start, end, page, pagesize);
                jsonArray = new JSONArray(list);
            } else {
                List<DevicePatientHealthIndex> list = healthIndexService.findIndexByPatient(getUID(), type, start, end, page, pagesize);
                if (list != null) {
                    for (DevicePatientHealthIndex model : list) {
                        JSONObject modelJson = new JSONObject();
                        modelJson.put("id", model.getId());
                        modelJson.put("patient", model.getUser());
                        modelJson.put("value1", model.getValue1());
                        modelJson.put("value2", model.getValue2());
                        modelJson.put("value3", model.getValue3());
                        modelJson.put("value4", model.getValue4());
                        modelJson.put("value5", model.getValue5());
                        modelJson.put("value6", model.getValue6());
                        modelJson.put("value7", model.getValue7());
                        modelJson.put("type", model.getType());
                        if (type == 2) {
                            modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD_HH_MM_SS));
                        } else {
                            modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD));
                        }
                        modelJson.put("sortDate", DateUtil.dateToStrLong(model.getSortDate()));
                        modelJson.put("czrq", DateUtil.dateToStr(model.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
                        jsonArray.put(modelJson);
                    }
                }
            }
			return write(200, "查询成功", "list", jsonArray);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
            return write(200, "查询成功", "list", jsonArray);
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "查询失败!");
        }
    }
	/**
	 * 患者健康指标预警值查询
	 *
	 * @return
	 */
	@RequestMapping(value = "standard")
	@ResponseBody
	public String standard() {
		try {
			JSONArray standardArray = new JSONArray();
			JSONArray userArray = new JSONArray();
			Iterable<PatientHealthStandard> iterable = healthIndexService.findStandardByPatient(getUID());
			Iterator<PatientHealthStandard> iterator = null;
			if (iterable != null) {
				iterator = iterable.iterator();
			}
			// 预警值未设置,返回默认值
			StringBuffer sb = new StringBuffer();
			sb.append("[");
			// 默认血糖(餐前,餐后二小时)
			sb.append("{min_value_1:3.9, max_value_1:6.1, min_value_2:4.4, max_value_2:7.8, type:1},");
			// 默认血压(收缩压,舒张压)
			sb.append("{min_value_1:90, max_value_1:139, min_value_2:60, max_value_2:89, type:2}");
			sb.append("]");
			standardArray = new JSONArray(sb.toString());
			if (iterator != null) {
				while (iterator.hasNext()) {
					PatientHealthStandard phs = iterator.next();
					if (phs == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					// 最低安全值(血糖餐前\收缩压\体重\腰围)
					json.put("min_value_1", phs.getMinValue1());
					// 最高安全值(血糖餐前\收缩压\体重\腰围)
					json.put("max_value_1", phs.getMaxValue1());
					// 最低安全值(血糖餐后\舒张压)
					json.put("min_value_2", phs.getMinValue2());
					// 最高安全值(血糖餐后\舒张压)
					json.put("max_value_2", phs.getMaxValue2());
					// 健康指标类型:1血糖,2血压,3体重,4腰围
					json.put("type", phs.getType());
					userArray.put(json);
				}
			}
			JSONObject json = new JSONObject();
			json.put("standard", standardArray);
			json.put("custom", userArray);
			return write(200, "查询成功", "data", json);
		} catch (Exception e) {
			error(e);
			return invalidUserException(e, -1, "查询失败!");
		}
	}
    /**
     * 患者健康指标预警值查询
     *
     * @return
     */
    @RequestMapping(value = "standard")
    @ResponseBody
    public String standard() {
        try {
            JSONArray standardArray = new JSONArray();
            JSONArray userArray = new JSONArray();
            Iterable<PatientHealthStandard> iterable = healthIndexService.findStandardByPatient(getUID());
            Iterator<PatientHealthStandard> iterator = null;
            if (iterable != null) {
                iterator = iterable.iterator();
            }
            // 预警值未设置,返回默认值
            StringBuffer sb = new StringBuffer();
            sb.append("[");
            // 默认血糖(餐前,餐后二小时)
            sb.append("{min_value_1:3.9, max_value_1:6.1, min_value_2:4.4, max_value_2:7.8, type:1},");
            // 默认血压(收缩压,舒张压)
            sb.append("{min_value_1:90, max_value_1:139, min_value_2:60, max_value_2:89, type:2}");
            sb.append("]");
            standardArray = new JSONArray(sb.toString());
            if (iterator != null) {
                while (iterator.hasNext()) {
                    PatientHealthStandard phs = iterator.next();
                    if (phs == null) {
                        continue;
                    }
                    JSONObject json = new JSONObject();
                    // 最低安全值(血糖餐前\收缩压\体重\腰围)
                    json.put("min_value_1", phs.getMinValue1());
                    // 最高安全值(血糖餐前\收缩压\体重\腰围)
                    json.put("max_value_1", phs.getMaxValue1());
                    // 最低安全值(血糖餐后\舒张压)
                    json.put("min_value_2", phs.getMinValue2());
                    // 最高安全值(血糖餐后\舒张压)
                    json.put("max_value_2", phs.getMaxValue2());
                    // 健康指标类型:1血糖,2血压,3体重,4腰围
                    json.put("type", phs.getType());
                    userArray.put(json);
                }
            }
            JSONObject json = new JSONObject();
            json.put("standard", standardArray);
            json.put("custom", userArray);
            return write(200, "查询成功", "data", json);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
}

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

@ -523,12 +523,10 @@ public class WeiXinEventProcess {
        List<Map<String, String>> articles = new ArrayList<>();
        Map videoText = getNews("doctor_subscribe_url", "doctor_qrcode_pic_url", "欢迎关注厦门i健康,快来签约家庭医生吧~", null);
        Map videoText1 = getNews("patient_sign_again_url", "patient_sign_again_pic_url", "家庭医生续签提醒", null);
        System.out.println("255");
        articles.add(videoText);
        articles.add(videoText1);
        // 构建回复消息XML
        result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"), message.get("ToUserName"), articles);
        System.out.println("256");
        return result;
    }

+ 0 - 16
patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/util/WeiXinMessageReplyUtils.java

@ -49,20 +49,4 @@ public class WeiXinMessageReplyUtils {
        return result.toString();
    }
    /**
     * 公众号群发图文消息
     *
     * @param toUser
     * @param fromUser
     * @param articles
     * @return
     * @throws Exception
     */
    public static String mapNewsMessage(String toUser,String fromUser,List<Map<String,String>> articles) throws Exception {
//1.上传图片到微信服务器
//2.上传图文消息素材到微信服务器
// 3.根据openID列表群发
        return null;
    }
}

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

@ -36,11 +36,13 @@ patient_operatinginstrutions_pic_url={server}/images/operatinginstructions.png
patient_booking_pic_url={server}/images/booking.png
patient_device_pic_url={server}/images/device.png
patient_family_pic_url={server}/images/myfamily.png
patient_sign_again_pic_url={server}/images/renew.png
patient_consult_url=https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&amp;redirect_uri={server}%2fwx%2fhtml%2fintroduction%2fhtml%2fyszx.html&amp;response_type=code&amp;scope=snsapi_base&amp;state=code#wechat_redirect
patient_booking_url=https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&amp;redirect_uri={server}%2fwx%2fhtml%2fintroduction%2fhtml%2fyygh.html&amp;response_type=code&amp;scope=snsapi_base&amp;state=code#wechat_redirect
patient_device_url=https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&amp;redirect_uri={server}%2fwx%2fhtml%2fintroduction%2fhtml%2ftzsb.html&amp;response_type=code&amp;scope=snsapi_base&amp;state=code#wechat_redirect
patient_family_url=https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&amp;redirect_uri={server}%2fwx%2fhtml%2fintroduction%2fhtml%2ffamily.html&amp;response_type=code&amp;scope=snsapi_base&amp;state=code#wechat_redirect
patient_sign_again_url=https://open.weixin.qq.com/connect/oauth2/authorize?appid={appId}&amp;redirect_uri={server}%2fwx%2fhtml%2fxuqian%2fhtml%2finformation.html&amp;response_type=code&amp;scope=snsapi_base&amp;state=code#wechat_redirect
# SMS短信配置
yihu_sms_url=https://smsapi.ums86.com:9600/sms/Api/Send.do
@ -64,6 +66,9 @@ admin_token=0a5c5258-8863-4b07-a3f9-88c768528ab4
# 签约到期JOB触发时间
sign_end_job_trigger=0 0 0 * * ?
# 续签提醒JOB触发时间 (每5分钟一次)
sign_again_job_trigger=0 0/1 * * * ?
evaluate_score_job = 59 59 23 * * ?
#-------------------------开发环境配置-------------------------#
@ -82,8 +87,7 @@ chat_server=http://weixin.xmtyw.cn/res/chat/
sign_check_upload=http://172.19.103.87:8011/wlyy_service
# IM配置
#im_list_get=http://172.19.103.88:3000/
im_list_get=http://192.168.131.107:3000/
im_list_get=http://172.19.103.88:3000/
im_group_server=http://172.19.103.29:3000/api/v1/chats/gm
msg_push_server=http://172.19.103.29:3000/api/v1/chats/sm
@ -185,10 +189,10 @@ fastdfs_file_url=http://172.19.103.54:80/
#template_doctor_change=V5h0F84t972kUzQvWy8qYrgdaYGJVj10pFeFVl19Nb8
#问卷调查
#template_doctor_survey=OqQXrb-e43_TJpq_70_K_y6vYJgY5mpjFYY4c5RWFP4
#
## FastDFS文件Http访问地址
#fastdfs_file_url=http://172.19.103.54:80/
#
##健康之路开放平台
#yihu_OpenPlatform_url=http://ssotest.yihu.cn/OpenPlatform/cgiBin/1.0/
#yihu_OpenPlatform_appId=9000276