Преглед на файлове

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

humingfen преди 7 години
родител
ревизия
7ef24e1003
променени са 41 файла, в които са добавени 2256 реда и са изтрити 642 реда
  1. BIN
      edu-article/JkEdu/WebRoot/WEB-INF/classes/com/yihu/jk/api/ArticleApiTest.class
  2. BIN
      edu-article/JkEdu/WebRoot/WEB-INF/classes/com/yihu/jk/dao/ArticleDao.class
  3. 14 2
      edu-article/JkEdu/src/com/yihu/jk/api/ArticleApiTest.java
  4. 29 6
      patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/service/DeviceService.java
  5. 4 2
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/controller/PrescriptionController.java
  6. 17 6
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/prescription/PrescriptionService.java
  7. 48 17
      patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/compute/ComputeHelper.java
  8. 2 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/prescription/PrescriptionDao.java
  9. 6 11
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/BaseService.java
  10. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java
  11. 17 5
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/DeviceDetailService.java
  12. 36 29
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/DeviceWxMessageService.java
  13. 2 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceLogService.java
  14. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceService.java
  15. 20 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthGuidanceService.java
  16. 543 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/bank/CreditLogService.java
  17. 78 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/bank/TaskRuleService.java
  18. 167 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/bank/TaskService.java
  19. 106 8
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/message/MessageService.java
  20. 23 9
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionInfoService.java
  21. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionService.java
  22. 299 124
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statisticsES/StatisticsESService.java
  23. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/specialist/SpecialistService.java
  24. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorTeamGuidanceService.java
  25. 0 330
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/health/bank/CreditLogService.java
  26. 4 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java
  27. 4 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/HttpClientUtil.java
  28. 5 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandlingController.java
  29. 17 9
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/device/DoctorDeviceController.java
  30. 5 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthGuidanceController.java
  31. 272 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/bank/ActivityController.java
  32. 20 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/message/DoctorMessageController.java
  33. 3 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/prescription/PrescriptionInfoController.java
  34. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/specialist/SpecialistController.java
  35. 4 4
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/device/PatientDeviceController.java
  36. 108 45
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/health/bank/CreditsLogController.java
  37. 131 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/bank/TaskController.java
  38. 16 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/prescription/PatientPrescriptionInfoController.java
  39. 165 15
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/EsStatisticsController.java
  40. 83 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/health/bank/AccountController.java
  41. 2 2
      patient-co/patient-co-wlyy/src/main/resources/application-devtest.yml

BIN
edu-article/JkEdu/WebRoot/WEB-INF/classes/com/yihu/jk/api/ArticleApiTest.class


BIN
edu-article/JkEdu/WebRoot/WEB-INF/classes/com/yihu/jk/dao/ArticleDao.class


+ 14 - 2
edu-article/JkEdu/src/com/yihu/jk/api/ArticleApiTest.java

@ -12,6 +12,9 @@ import com.coreframework.util.AppConfig;
import com.yihu.jk.utils.SecretUtil;
import com.yihu.wsgw.api.InterfaceMessage;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class ArticleApiTest {
	public static void main(String[] args) throws JSONException {
		// TODO Auto-generated method stub
@ -34,8 +37,9 @@ public class ArticleApiTest {
		// System.out.println(api.getCollectionArticalList(im));
		// System.out.println(api.getArticalById(im));
        saveBehavior();
//        saveBehavior();
//		System.out.printf("350200".substring(0,3));
		aa();
	}
	public static void initDB() {
@ -135,6 +139,14 @@ public class ArticleApiTest {
		}
	}
	public static void aa() {
		SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
		Calendar c = Calendar.getInstance();
		int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
		if (day_of_week == 0)
			day_of_week = 7;
		c.add(Calendar.DATE, -day_of_week + 1);
		System.out.println(df2.format(c.getTime()));
	}
}

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

@ -216,6 +216,17 @@ public class DeviceService extends BaseService{
        }
        return true;
    }
    /**
     * 判断当前指标偏高或偏低
     */
    private int checkHealthIndexDetail(Double current, Double max, Double min) {
        if (current > max ) {
            return 1;
        }else if(current < min || current < 0){
            return 2;
        }
        return 0;
    }
    /**************************************************************************************************************/
    /**
     * 设备数据查询接口
@ -997,8 +1008,12 @@ public class DeviceService extends BaseService{
            // 餐后
            if (index % 2 == 0) {
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter )) {
                    msgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L),请处理";
//                    msgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L),请处理";
                    if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==1){
                        msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏高</span>";
                    }else if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==2){
                        msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏低</span>";
                    }
                    //体征异常,更新体征数据状态
//                    data.setStatus(1);
//                    patientHealthIndexDao.save(data);
@ -1006,8 +1021,12 @@ public class DeviceService extends BaseService{
                }
            } else { //餐前
                if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueBefore, minValueBefore)) {
                    msgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L),请处理";
//                    msgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L),请处理";
                    if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==1){
                        msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏高</span>";
                    }else if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==2){
                        msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏低</span>";
                    }
                    //体征异常,更新体征数据状态
//                    data.setStatus(1);
//                    patientHealthIndexDao.save(data);
@ -1041,8 +1060,12 @@ public class DeviceService extends BaseService{
            }
            // 收缩压/舒张压校验
            if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY) || !checkHealthIndex(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)) {
                msgContent = patient.getName() + "血压异常(舒张压 " + value2 + "mmHg、收缩压 " + value1 + "mmHg),请处理";
//                msgContent = patient.getName() + "血压异常(舒张压 " + value2 + "mmHg、收缩压 " + value1 + "mmHg),请处理";
                if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY)==1||checkHealthIndexDetail(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)==1){
                    msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血压偏高</span>";
                }else if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY)==2||checkHealthIndexDetail(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)==2){
                    msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血压偏低</span>";
                }
                //体征异常,更新体征数据状态
//                data.setStatus(1);
//                patientHealthIndexDao.save(data);

Файловите разлики са ограничени, защото са твърде много
+ 4 - 2
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/controller/PrescriptionController.java


+ 17 - 6
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/prescription/PrescriptionService.java

@ -10,6 +10,7 @@ import com.yihu.wlyy.service.common.model.Result;
import com.yihu.wlyy.service.common.util.AmoutUtils;
import com.yihu.wlyy.service.common.util.CommonUtil;
import com.yihu.wlyy.service.common.util.DateUtil;
import com.yihu.wlyy.service.common.util.StringUtil;
import com.yihu.wlyy.service.dao.*;
import com.yihu.wlyy.service.dao.consult.ConsultTeamDao;
import com.yihu.wlyy.service.dao.prescription.*;
@ -697,15 +698,25 @@ public class PrescriptionService extends ZysoftBaseService{
     * @return
     * @throws Exception
     */
    public String getRecipe(String cardNo,String appointRecipeNo)  throws Exception
    public String getRecipe(String cardNo,String appointRecipeNo,String preCode)  throws Exception
    {
        Patient patient = patientDao.findBySsc(cardNo);
        SignFamily signFamily = signFamilyDao.findByPatient(patient.getCode());
        //
        String[] hospitalMapping = getHospitalMapping(signFamily.getHospital()); //获取机构映射
        String hospital = hospitalMapping[0];
        String licence = hospitalMapping[1];
        String hospital="";
        String licence="";
        if(signFamily!=null){
            String[] hospitalMapping = getHospitalMapping(signFamily.getHospital()); //获取机构映射
            hospital = hospitalMapping[0];
            licence = hospitalMapping[1];
        }else{
            //如果签约过期,重历史处方获取机构数据
            if(StringUtils.isNotBlank(preCode)){
                Prescription p = prescriptionDao.findByCode(preCode);
                String[] hospitalMapping = getHospitalMapping(p.getHospital()); //获取机构映射
                hospital = hospitalMapping[0];
                licence = hospitalMapping[1];
            }
        }
        Map<String,String> header = new HashMap<>();
        header.put("ORGCODE",hospital);

+ 48 - 17
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/compute/ComputeHelper.java

@ -4,6 +4,7 @@ import com.yihu.wlyy.entity.dimension.WlyyDimensionQuota;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.statistics.util.DateUtil;
import com.yihu.wlyy.statistics.vo.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@ -158,29 +159,53 @@ public class ComputeHelper {
        }
        //根据维度初始化数据
        for (int i = 0; i < dimensionQuotas.size(); i++) {
            Map<String, SaveModel> mapTemp = new HashMap<>();
            WlyyDimensionQuota dimensionQuota = dimensionQuotas.get(i);
            List<DictModel> dictModels = jdbcTemplate.query(dimensionQuota.getDictSql(), new BeanPropertyRowMapper(DictModel.class));
            for (Map.Entry<String, SaveModel> oneSaveModel : lastMaps.entrySet()) {
                for (int j = 0; j < dictModels.size(); j++) {
                    SaveModel saveModelTemp = new SaveModel();
                    DictModel dictModel = dictModels.get(j);
                    BeanUtils.copyProperties(oneSaveModel.getValue(), saveModelTemp);
                    SaveModel.class.getMethod("setSlaveKey" + (i + 1) + "Name", String.class).invoke(saveModelTemp, dictModel.getName());
                    SaveModel.class.getMethod("setSlaveKey" + (i + 1), String.class).invoke(saveModelTemp, dictModel.getCode());
                    //根据维度生成新的key
                    StringBuffer strKey = new StringBuffer(oneSaveModel.getKey() + "-" + dictModel.getCode());
                    mapTemp.put(strKey.toString(), saveModelTemp);
            for (int i = 0; i < dimensionQuotas.size(); i++) {
                Map<String, SaveModel> mapTemp = new HashMap<>();
                WlyyDimensionQuota dimensionQuota = dimensionQuotas.get(i);
//                List<DictModel> dictModels = jdbcTemplate.query(dimensionQuota.getDictSql(), new BeanPropertyRowMapper(DictModel.class));
                List<Map<String, Object>> listMap = jdbcTemplate.queryForList(dimensionQuota.getDictSql());
                for (Map.Entry<String, SaveModel> oneSaveModel : lastMaps.entrySet()) {
                    for (int j = 0; j < listMap.size(); j++) {
                        SaveModel saveModelTemp = new SaveModel();
                        Map<String, Object> dictModel = listMap.get(j);
                        BeanUtils.copyProperties(oneSaveModel.getValue(), saveModelTemp);
                        SaveModel.class.getMethod("setSlaveKey" + (i + 1) + "Name", String.class).invoke(saveModelTemp, dictModel.get("name"));
                        SaveModel.class.getMethod("setSlaveKey" + (i + 1), String.class).invoke(saveModelTemp, dictModel.get("code"));
                        //根据维度生成新的key
                        StringBuffer strKey = new StringBuffer(oneSaveModel.getKey() + "-" + dictModel.get("code"));
                        mapTemp.put(strKey.toString(), saveModelTemp);
                    }
                }
            }
            //如果字典长度是0 抛出异常
            if (dictModels.size() == 0) {
            if (listMap.size() == 0) {
                throw new Exception("dict size:0,sql:" + dimensionQuota.getDictSql());
            }
            lastMaps = mapTemp;
        }
//        for (int i = 0; i < dimensionQuotas.size(); i++) {
//            Map<String, SaveModel> mapTemp = new HashMap<>();
//            WlyyDimensionQuota dimensionQuota = dimensionQuotas.get(i);
//            List<DictModel> dictModels = jdbcTemplate.query(dimensionQuota.getDictSql(), new BeanPropertyRowMapper(DictModel.class));
//            for (Map.Entry<String, SaveModel> oneSaveModel : lastMaps.entrySet()) {
//                for (int j = 0; j < dictModels.size(); j++) {
//                    SaveModel saveModelTemp = new SaveModel();
//                    DictModel dictModel = dictModels.get(j);
//
//                    BeanUtils.copyProperties(oneSaveModel.getValue(), saveModelTemp);
//                    SaveModel.class.getMethod("setSlaveKey" + (i + 1) + "Name", String.class).invoke(saveModelTemp, dictModel.getName());
//                    SaveModel.class.getMethod("setSlaveKey" + (i + 1), String.class).invoke(saveModelTemp, dictModel.getCode());
//                    //根据维度生成新的key
//                    StringBuffer strKey = new StringBuffer(oneSaveModel.getKey() + "-" + dictModel.getCode());
//                    mapTemp.put(strKey.toString(), saveModelTemp);
//                }
//            }
//            //如果字典长度是0 抛出异常
//            if (dictModels.size() == 0) {
//                throw new Exception("dict size:0,sql:" + dimensionQuota.getDictSql());
//            }
//            lastMaps = mapTemp;
//        }
        //设置值
        for (Map.Entry<String, SaveModel> one : lastMaps.entrySet()) {
@ -196,6 +221,12 @@ public class ComputeHelper {
                SaveModel saveModel = one.getValue();
                saveModel.setResult1(result1);
                saveModel.setResult2(result2);
                if(dataModels.size()>0&& StringUtils.isNotEmpty(dataModels.get(0).getSlaveKey1())&&!StringUtils.isNotEmpty(saveModel.getSlaveKey1())){
                    saveModel.setSlaveKey1(dataModels.get(0).getSlaveKey1());
                }
                if(dataModels.size()>0&& StringUtils.isNotEmpty(dataModels.get(0).getSlaveKey2())&&!StringUtils.isNotEmpty(saveModel.getSlaveKey2())){
                    saveModel.setSlaveKey2(dataModels.get(0).getSlaveKey2());
                }
                returnList.add(saveModel);
            } else {
                returnList.add(one.getValue());

+ 2 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/prescription/PrescriptionDao.java

@ -38,4 +38,6 @@ public interface PrescriptionDao extends PagingAndSortingRepository<Prescription
    @Modifying
    @Query("update Prescription p set p.jwPayStatus=1 where p.code=?1")
    void updatejwPayStatus(String prescriptionCode);
    List<Prescription> findByPatient(String patient);
}

+ 6 - 11
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/BaseService.java

@ -1,21 +1,16 @@
package com.yihu.wlyy.service;
import java.security.KeyPair;
import java.util.Iterator;
import java.util.UUID;
import com.yihu.wlyy.entity.security.AccessToken;
import com.yihu.wlyy.service.common.account.AccessTokenService;
import com.yihu.wlyy.util.HttpUtil;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import com.yihu.wlyy.entity.security.RSA;
import com.yihu.wlyy.repository.security.RSADao;
import com.yihu.wlyy.service.common.account.AccessTokenService;
import com.yihu.wlyy.util.CommonUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.security.KeyPair;
import java.util.Iterator;
import java.util.UUID;
@Service
public class BaseService {

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java

@ -1233,7 +1233,7 @@ public class ConsultTeamService extends ConsultService {
     */
    public Prescription savePrescription(Prescription prescription,String jwCode,Doctor doctor,Patient p,ConsultTeam ct,String reason) throws Exception{
        //获取智业处方详细
        String response = jwPrescriptionService.getRecipe(jwCode,p.getSsc());
        String response = jwPrescriptionService.getRecipe(jwCode,p.getSsc(),null);
        com.alibaba.fastjson.JSONObject jsonObject = presModeAdapter.modelToSinglePrescription(response);
        //续方主表

+ 17 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/DeviceDetailService.java

@ -18,6 +18,7 @@ import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -44,6 +45,8 @@ public class DeviceDetailService extends BaseService {
	private DoctorDao doctorDao;
	@Autowired
	private PatientDeviceDao patientDeviceDao;
	@Autowired
	private JdbcTemplate jdbcTemplate;
	/**
@ -53,6 +56,7 @@ public class DeviceDetailService extends BaseService {
	 * @param isFirst
	 * @throws Exception
	 */
	@Transactional
	public void updateAfterBinding(PatientDevice patientDevice, Date grantTime,boolean isFirst)throws Exception{
		DeviceDetail deviceDetail = deviceDetailDao.findBySn(patientDevice.getDeviceSn());
		List<SignFamily> signFamilyList = signFamilyDao.findSSandJTByIdcard(patientDevice.getUserIdcard());
@ -84,11 +88,15 @@ public class DeviceDetailService extends BaseService {
		}
		if (isFirst){
			deviceDetailDao.updateAfterBindingFirst(String.valueOf(adminTeam),hospital,isFirstBind,grantTime,patientDevice.getDeviceSn());
			String updateFirstSql ="update device.wlyy_devices dd set dd.is_grant=1,dd.grant_admin_team=?,dd.grant_org_code=?,dd.binding_count=?,dd.grant_time = ?,dd.is_binding=1 where dd.device_code=?";
			jdbcTemplate.update(updateFirstSql,new Object[]{String.valueOf(adminTeam),hospital,isFirstBind,grantTime,patientDevice.getDeviceSn()});
			//deviceDetailDao.updateAfterBindingFirst(String.valueOf(adminTeam),hospital,isFirstBind,grantTime,patientDevice.getDeviceSn());
		}else {
			List<PatientDevice> patientDeviceList = patientDeviceDao.findByDeviceSn(patientDevice.getDeviceSn());
			int patientDeviceSize = patientDeviceList.size();
			deviceDetailDao.updateAfterBinding(String.valueOf(adminTeam),hospital,isFirstBind,patientDevice.getDeviceSn(),patientDeviceSize);
			String updateSql ="update device.wlyy_devices dd set dd.is_grant=1,dd.grant_admin_team=?,dd.grant_org_code=?,dd.binding_count=?,dd.is_binding=? where dd.device_code=?";
			jdbcTemplate.update(updateSql,new Object[]{String.valueOf(adminTeam),hospital,isFirstBind,patientDeviceSize,patientDevice.getDeviceSn()});
			//deviceDetailDao.updateAfterBinding(String.valueOf(adminTeam),hospital,isFirstBind,patientDevice.getDeviceSn(),patientDeviceSize);
		}
	}
@ -147,14 +155,18 @@ public class DeviceDetailService extends BaseService {
	 */
	public void unBindUpdateIsBinding(String deviceSn)throws Exception{
		List<PatientDevice> patientDeviceList = patientDeviceDao.findByDeviceSn(deviceSn);
		String sql = "update device.wlyy_devices dd set dd.is_binding=? where dd.device_code=?";
		if (patientDeviceList.size()==0){
			deviceDetailDao.updateUnbindAll(0,deviceSn);
			jdbcTemplate.update(sql,new Object[]{0,deviceSn});
			//deviceDetailDao.updateUnbindAll(0,deviceSn);
		}
		if (patientDeviceList.size()==1){
			deviceDetailDao.updateUnbindAll(1,deviceSn);
			jdbcTemplate.update(sql,new Object[]{1,deviceSn});
			//deviceDetailDao.updateUnbindAll(1,deviceSn);
		}
		if (patientDeviceList.size()>1){
			deviceDetailDao.updateUnbindAll(2,deviceSn);
			jdbcTemplate.update(sql,new Object[]{2,deviceSn});
			//deviceDetailDao.updateUnbindAll(2,deviceSn);
		}
	}
}

+ 36 - 29
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/DeviceWxMessageService.java

@ -7,6 +7,7 @@ import com.yihu.wlyy.repository.patient.DeviceWxMessageDao;
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.DateUtil;
import org.apache.commons.collections.map.HashedMap;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -18,6 +19,7 @@ import org.springside.modules.utils.Clock;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Component
@ -50,39 +52,44 @@ public class DeviceWxMessageService extends BaseService {
        }
        //批量插入数据
        deviceWxMessageDao.save(messageList);
        //放入队列的数据集
        List<DeviceWxMessageDTO> deviceWxMessageDTOS = new ArrayList<>();
        List<DeviceWxMessageDTO> deviceWxMessageDTOS1 = new ArrayList<>();
        //放入队列的数据集(相同用户不同设备各发一条  相同设备发一条)
        Map<String,List<String>> map = new HashedMap();
        for (DeviceWxMessage deviceWxMessage : messageList) {
            deviceWxMessageDTOS1.clear();
            deviceWxMessageDTOS1.addAll(deviceWxMessageDTOS);
            int i = 0;
            if (deviceWxMessageDTOS1.size()==0){
                DeviceWxMessageDTO deviceWxMessageDTO = new DeviceWxMessageDTO();
                deviceWxMessageDTO.setPatient(deviceWxMessage.getPatient());
                deviceWxMessageDTO.setDeviceType(Integer.valueOf(deviceWxMessage.getCategoryCode()));
                deviceWxMessageDTO.setCzrq(DateUtil.dateToStr(deviceWxMessage.getCzrq(),"yyyy-MM-dd HH:mm:ss"));
                deviceWxMessageDTOS.add(deviceWxMessageDTO);
            }else {
                for (DeviceWxMessageDTO wxMessageDto : deviceWxMessageDTOS1) {
                    i++;
                    //当居民没有重复的时候添加一条发送
                    if (i==deviceWxMessageDTOS1.size() && (!deviceWxMessage.getPatient().equals(wxMessageDto.getPatient()))){
                        DeviceWxMessageDTO deviceWxMessageDTO = new DeviceWxMessageDTO();
                        deviceWxMessageDTO.setPatient(deviceWxMessage.getPatient());
                        deviceWxMessageDTO.setDeviceType(Integer.valueOf(deviceWxMessage.getCategoryCode()));
                        deviceWxMessageDTO.setCzrq(DateUtil.dateToStr(deviceWxMessage.getCzrq(),"yyyy-MM-dd HH:mm:ss"));
                        deviceWxMessageDTOS.add(deviceWxMessageDTO);
            List<String> deviceTypeList = null;
            if (map.containsKey(deviceWxMessage.getPatient())){
                deviceTypeList = map.get(deviceWxMessage.getPatient());
                if (deviceTypeList==null){
                    deviceTypeList = new ArrayList<>();
                    deviceTypeList.add(deviceWxMessage.getCategoryCode());
                    map.put(deviceWxMessage.getPatient(),deviceTypeList);
                }else {
                    boolean flag = false;
                    if (!deviceTypeList.contains(deviceWxMessage.getCategoryCode())){
                        flag=true;
                    }
                    //当居民code重复且设备类型不重复也添加一条发送
                    if (deviceWxMessage.getPatient().equals(wxMessageDto.getPatient()) && Integer.valueOf(deviceWxMessage.getCategoryCode())!=wxMessageDto.getDeviceType()){
                        DeviceWxMessageDTO deviceWxMessageDTO = new DeviceWxMessageDTO();
                        deviceWxMessageDTO.setPatient(deviceWxMessage.getPatient());
                        deviceWxMessageDTO.setDeviceType(Integer.valueOf(deviceWxMessage.getCategoryCode()));
                        deviceWxMessageDTO.setCzrq(DateUtil.dateToStr(deviceWxMessage.getCzrq(),"yyyy-MM-dd HH:mm:ss"));
                        deviceWxMessageDTOS.add(deviceWxMessageDTO);
                    if (flag){
                        deviceTypeList.add(deviceWxMessage.getCategoryCode());
                        map.put(deviceWxMessage.getPatient(),deviceTypeList);
                    }
                }
            }else {
                deviceTypeList = new ArrayList<>();
                deviceTypeList.add(deviceWxMessage.getCategoryCode());
                map.put(deviceWxMessage.getPatient(),deviceTypeList);
            }
         }
        List<DeviceWxMessageDTO> deviceWxMessageDTOS = new ArrayList<>();
        for (Map.Entry<String, List<String>> entry : map.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
            String patient = entry.getKey();
            List<String> list = entry.getValue();
            for (String deviceType : list){
                DeviceWxMessageDTO deviceWxMessageDTO =  new DeviceWxMessageDTO();
                deviceWxMessageDTO.setPatient(patient);
                deviceWxMessageDTO.setDeviceType(Integer.valueOf(deviceType));
                deviceWxMessageDTO.setCzrq(DateUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm:ss"));
                deviceWxMessageDTOS.add(deviceWxMessageDTO);
            }
        }
        return deviceWxMessageDTOS;

+ 2 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceLogService.java

@ -40,6 +40,7 @@ public class PatientDeviceLogService extends BaseService {
     * @param operateCode
     * @throws Exception
     */
    @Transactional
    public void savePatientDeviceLog(PatientDevice patientDevice,String deviceSn,int role,int operateCode)throws Exception{
       if (patientDevice==null){
           patientDevice = patientDeviceDao.findByDeviceSn(deviceSn).get(0);
@ -72,7 +73,7 @@ public class PatientDeviceLogService extends BaseService {
                "  SELECT sf.name, pd.* FROM wlyy_patient_device_log pd" +
                "  LEFT JOIN wlyy_sign_family sf ON pd.patient = sf.patient" +
                "  WHERE" +
                "   pd.is_del = 1 and sf.doctor= ''" +doctor+"'"+
                "   pd.is_del = 1 and sf.doctor= '" +doctor+"'"+
                "  ORDER BY" +
                "  create_time DESC) a" +
                " GROUP BY a.device_sn) b" +

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

@ -155,7 +155,7 @@ public class PatientDeviceService extends BaseService {
            }
        }
        /*DeviceDetail deviceDetail = deviceDetailDao.findBySn(deviceSn);
        //if(deviceDetail != null){
        if(deviceDetail != null){
            flag = true;
        }*/
        return flag;

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

@ -27,6 +27,8 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * 健康指导业务处理类
@ -104,7 +106,7 @@ public class PatientHealthGuidanceService extends BaseService {
	 * @param guidance
	 * @return
	 */
	public PatientHealthGuidance add(PatientHealthGuidance guidance, String accessToken) throws Exception {
	public PatientHealthGuidance add(PatientHealthGuidance guidance, String accessToken,String tzCode) throws Exception {
		Doctor doctor = doctorDao.findByCode(guidance.getDoctor());
		Patient patient = patientDao.findByCode(guidance.getPatient());
		//家庭医生
@ -172,6 +174,23 @@ public class PatientHealthGuidanceService extends BaseService {
				}
			}
		}
		if(StringUtils.isNotEmpty(tzCode)){
			String sql = " select * from device.wlyy_patient_health_index where id in ("+tzCode+")";
			List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
			Date currentTime = new Date();
			long h24 = 60*60*24;
			for(Map<String, Object> one :list){
				String tempSql="";
				Date temp =(Date)one.get("czrq");
				if(currentTime.getTime()-temp.getTime()>h24){//有效干预
					tempSql = "update device.wlyy_patient_health_index set manage_result=1 where id="+one.get("id");
				}else{//无效干预
					tempSql = "update device.wlyy_patient_health_index set manage_result=2 where id="+one.get("id");
				}
				jdbcTemplate.execute(tempSql);
			}
		}
		return guidance;
	}

+ 543 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/bank/CreditLogService.java

@ -0,0 +1,543 @@
package com.yihu.wlyy.service.app.health.bank;/**
 * Created by nature of king on 2018/5/7.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.util.HttpClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author wangzhinan
 * @create 2018-05-07 9:24
 * @desc wlyy health bank service
 **/
@Service
@Transactional
public class CreditLogService {
    private Logger logger = LoggerFactory.getLogger(CreditLogService.class);
    private static String URL = "health:blank:url";
    //    private String baseUrl = "http://192.168.131.24:8088/svr-iot/";
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private PatientDeviceService patientDeviceService;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private SystemDictDao systemDictDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    /**
     * 获取url
     *
     * @return
     */
    public  String getBaseUrl(){
        String url = redisTemplate.opsForValue().get(URL);
        String url1 = systemDictDao.findByDictNameAndCode("HEALTH_BANK_URL","HEALTH_BANK_URL");
        if (url != null && url1.equalsIgnoreCase(url)){
            return url;
        }else {
            redisTemplate.opsForValue().set(URL,url1);
            return url1;
        }
    }
    /**
     * 调用第三方积分排名接口
     *
     * @param doctorId
     * @param page
     * @param name
     * @param size
     * @return
     */
    public JSONObject selectByRanking(String doctorId,String name, Integer page, Integer size){
        String sql = null;
        if (name == null || name == ""){
            sql  = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +doctorId + "' OR doctor_health = '" + doctorId +"')";
        } else if (name != null) {
            sql  = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +doctorId + "' OR doctor_health = '" + doctorId +"') AND name = '"+name+"'";
        }
        List<SignFamily> signFamilyList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamily.class));
        List<String>  patientIds = new ArrayList<>();
        if (signFamilyList != null && signFamilyList.size() != 0){
            for (SignFamily signFamily:signFamilyList){
                patientIds.add(signFamily.getPatient());
            }
        }
        JSONObject object = new JSONObject();
        object.put("filter",patientIds.toArray());
        object.put("page",page);
        object.put("size",size);
        String url = getBaseUrl() + "selectByRanking";
        String response = null;
        JSONArray data =null;
        JSONObject object1 = null;
        try {
            response = httpClientUtil.iotPostBody(url,object.toString());
            object1 = JSONObject.parseObject(response);
            JSONArray array = object1.getJSONArray("detailModelList");
            for (int i = 0;i<array.size();i++){
                JSONObject object2 = array.getJSONObject(i);
                String patientId = object2.getString("patientId");
                Patient patient = patientDao.findByCode(patientId);
                object2.put("patient",patient);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 调用添加积分接口
     *
     * @param object
     * @return
     */
    public JSONObject insert(JSONObject object) throws Exception {
        String response = null;
        String patientId = object.getString("patientId");
        Patient patient = patientDao.findByCode(patientId);
        if (patient == null){
            throw new Exception("该居民不存在");
        }
        object.put("name",patient.getName());
        object.put("idCard",patient.getIdcard());
        object.put("openId",patient.getOpenid());
        String url =getBaseUrl() + "createCreditsDetail";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 按条件查询积分
     *
     * @param object
     * @param page
     * @param size
     * @return
     */
    public JSONObject selectByCondition(JSONObject object,Integer page,Integer size){
        String response = null;
        String url =getBaseUrl() + "findCreditsLogInfo";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 查询账户积分详情
     *
     * @param object
     * @return
     */
    public JSONObject selectAccount(JSONObject object) throws Exception {
        String patientId = object.getString("patientId");
        Patient patient = patientDao.findByCode(patientId);
        if (patient == null){
            throw new Exception("该居民不存在");
        }
        object.put("name",patient.getName());
        String response = null;
        String url =getBaseUrl() + "selectAccount";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 查询任务完成情况
     *
     * @param object
     * @param page
     * @param size
     * @return
     */
    public JSONObject selectByTask(JSONObject object,Integer page,Integer size){
        JSONObject object1 = new JSONObject();
        String response = null;
        String url =getBaseUrl() + "findTask";
        Map<String,String> params = new HashMap<>();
        params.put("task",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        String patientId = object.getString("patientId");
        try {
            response = httpClientUtil.httpPost(url,params);
            Map<String,Object> taskInfo = patientDeviceService.getPatientDeviceTaskInfo(patientId);
            object1 = JSONObject.parseObject(response);
            JSONArray array = object1.getJSONArray("detailModelList");
            JSONArray array1 = new JSONArray();
            for (int i =0 ;i<array.size();i++){
                JSONObject jsonObject = array.getJSONObject(i);
                String taskCode = jsonObject.getString("taskCode");
                if (taskCode.equalsIgnoreCase("BIND")){
                    jsonObject.put("deviceCount",taskInfo.get("deviceCount"));
                }else if (taskCode.equalsIgnoreCase("MEASURE")){
                    jsonObject.put("resultHealty",taskInfo.get("resultHealty"));
                }
                array1.add(jsonObject);
            }
            object1.put("detailModelList",array1);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 查询银行账户信息
     *
     * @param object 账户对象
     * @param page 页码
     * @param size 每页大小
     * @return
     */
    public JSONObject selectByAccount(JSONObject object,Integer page,Integer size){
        String signSql = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND patient = '"+object.getString("patientId") +"'";
        List<SignFamily> signFamilyList1 = jdbcTemplate.query(signSql,new BeanPropertyRowMapper(SignFamily.class));
        String sql = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +signFamilyList1.get(0).getDoctor() + "' OR doctor_health = '" + signFamilyList1.get(0).getDoctor() +"')";
        List<SignFamily> signFamilyList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamily.class));
        List<String>  patientIds = new ArrayList<>();
        if (signFamilyList != null && signFamilyList.size() != 0){
            for (SignFamily signFamily:signFamilyList){
                patientIds.add(signFamily.getPatient());
            }
        }
        String response = null;
        String url =getBaseUrl() + "findAccount";
        object.put("patientIds",patientIds.toArray());
        Map<String,String> params = new HashMap<>();
        params.put("account",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        JSONObject object1 = null;
        try {
            response = httpClientUtil.httpPost(url,params);
            object1 = JSONObject.parseObject(response);
            JSONArray array = object1.getJSONArray("detailModelList");
            for (int i = 0;i<array.size();i++){
                JSONObject object2 = array.getJSONObject(i);
                String patientId = object2.getString("patientId");
                Patient patient = patientDao.findByCode(patientId);
                object2.put("patient",patient);
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 获取活动所有排名
     *
     * @param activityId 活动对象
     * @param page 页码
     * @param size
     * @return
     */
    public JSONObject selectByActivityRanking1(String activityId,Integer page,Integer size){
        String response = null;
        String url =getBaseUrl() + "selectByActivityRanking1";
        Map<String,String> params = new HashMap<>();
        params.put("activityId",activityId);
        params.put("page",page.toString());
        params.put("size",size.toString());
        JSONObject object1 = null;
        try {
            response = httpClientUtil.httpPost(url,params);
            object1 = JSONObject.parseObject(response);
            JSONArray array = object1.getJSONArray("detailModelList");
            for (int i = 0;i<array.size();i++){
                JSONObject object2 = array.getJSONObject(i);
                String patientId = object2.getString("patientId");
                Patient patient = patientDao.findByCode(patientId);
                object2.put("patient",patient);
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 查询参与活动
     *
     * @param object
     * @param page
     * @param size
     * @return
     */
    public JSONObject selectByPatient(JSONObject object,Integer page,Integer size){
        Patient patient = new Patient();
        if (object.getString("openId") != null){
            patient = patientDao.findByOpenid(object.getString("openId"));
        }else if (object.getString("patientId") != null){
            patient = patientDao.findByCode(object.getString("patientId"));
        }
        object.put("openId",patient.getOpenid());
        object.put("unionId",patient.getUnionid());
        object.put("patientIdcard",patient.getIdcard());
        String response = null;
        String url =getBaseUrl() + "selectByPatient";
        Map<String,String> params = new HashMap<>();
        params.put("activity",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 根据活动查找积分
     *
     * @param patientId 居民id
     *
     * @param activityId 活动id
     * @param page 页码
     *
     * @param size  分页大小
     * @return
     */
    public JSONObject selectByActivity(String patientId,String activityId,Integer page,Integer size){
        String response = null;
        String url =getBaseUrl() + "selectByActivity";
        Map<String,String> params = new HashMap<>();
        params.put("patientId",patientId);
        params.put("activityId",activityId);
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 按照活动排名
     *
     * @param activityId 活动id
     * @param doctorId 医生id
     * @param name 居民名称
     * @param page 页码
     * @param size 分页大小
     * @return
     */
    public JSONObject selectByActivityRanking(String activityId,String doctorId,String name, Integer page, Integer size){
        String sql = null;
        if (name == null || name ==""){
            sql  = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +doctorId + "' OR doctor_health = '" + doctorId +"')";
        } else if (name != null) {
            sql  = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +doctorId + "' OR doctor_health = '" + doctorId +"') AND name = '"+name+"'";
        }
        List<SignFamily> signFamilyList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamily.class));
        List<String>  patientOpenIds = new ArrayList<>();
        if (signFamilyList != null && signFamilyList.size() != 0){
            for (SignFamily signFamily:signFamilyList){
                patientOpenIds.add(signFamily.getOpenid());
            }
        }
        JSONObject object = new JSONObject();
        object.put("filter",patientOpenIds.toArray());
        object.put("activityId",activityId);
        object.put("page",page);
        object.put("size",size);
        String url = getBaseUrl() + "selectByActivityRanking";
        String response = null;
        JSONArray data =null;
        JSONObject object1 = null;
        try {
            response = httpClientUtil.iotPostBody(url,object.toString());
            object1 = JSONObject.parseObject(response);
            JSONArray array = object1.getJSONArray("detailModelList");
            for (int i = 0;i<array.size();i++){
                JSONObject object2 = array.getJSONObject(i);
                String patientId = object2.getString("patientId");
                Patient patient = patientDao.findByCode(patientId);
                object2.put("patient",patient);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 根据条件获取信息
     *
     * @param object 对象
     * @param page 页码
     * @param size 分页大小
     * @return
     */
    public JSONObject selectAccountByCondition(JSONObject object,Integer page,Integer size){
        String doctorId = object.getString("doctorId");
        String sql = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +doctorId + "' OR doctor_health = '" + doctorId +"')";
        List<SignFamily> signFamilyList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamily.class));
        List<String>  patientIds = new ArrayList<>();
        if (signFamilyList != null && signFamilyList.size() != 0){
            for (SignFamily signFamily:signFamilyList){
                patientIds.add(signFamily.getPatient());
            }
        }
        JSONObject object1 = new JSONObject();
        JSONArray array = object.getJSONArray("deviceTypes");
        object1.put("patientIds",patientIds.toArray());
        object1.put("bindStatus",object.getInteger("bindStatus"));
        object1.put("deviceTypes",array);
        object1.put("page",page);
        object1.put("size",size);
        String response = null;
        String url =getBaseUrl() + "findAccounByCondition";
        JSONObject object2 = null;
        try {
            response = httpClientUtil.iotPostBody(url,object1.toString());
            object2 = JSONObject.parseObject(response);
            JSONArray array1 = object2.getJSONArray("detailModelList");
            for (int i = 0;i<array1.size();i++){
                JSONObject object3 = array1.getJSONObject(i);
                String patientId = object3.getString("patientId");
                Patient patient = patientDao.findByCode(patientId);
                object3.put("patient",patient);
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object2;
    }
    /**
     * 医生添加积分
     *
     * @param object {patientIds:[],ruleId:"",description:""}
     * @return
     */
    public JSONObject doctorAddIntegrate(JSONObject object){
        String response = null;
        String url =getBaseUrl() + "doctorAddIntegrate";
        JSONArray array = object.getJSONArray("patientIds");
        JSONObject object1 = new JSONObject();
        object1.put("patientIds",array);
        object1.put("ruleId",object.getString("ruleId"));
        object1.put("description",object.getString("description"));
        JSONObject object2 = null;
        try {
            response = httpClientUtil.iotPostBody(url,object1.toString());
            object2 = JSONObject.parseObject(response);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object2;
    }
    /**
     * 步数获取积分
     *
     * @param object
     * @return
     * @throws Exception
     */
    public JSONObject stepAddIntegrate(JSONObject object) throws Exception {
        String response = null;
        String patientId = object.getString("patientId");
        Patient patient = patientDao.findByCode(patientId);
        if (patient == null){
            throw new Exception("该居民不存在");
        }
        object.put("name",patient.getName());
        object.put("idCard",patient.getIdcard());
        object.put("openId",patient.getOpenid());
        object.put("unionId",patient.getUnionid());
        String url =getBaseUrl() + "addStepIntegrate";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
}

+ 78 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/bank/TaskRuleService.java

@ -0,0 +1,78 @@
package com.yihu.wlyy.service.app.health.bank;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.util.HttpClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by wangzhinan on 2018/6/14.
 */
@Service
@Transactional
public class TaskRuleService {
    private Logger logger = LoggerFactory.getLogger(TaskRuleService.class);
    private static String URL = "health:blank:url";
    @Autowired
    private SystemDictDao systemDictDao;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 获取url
     *
     * @return
     */
    public  String getBaseUrl(){
        String url = redisTemplate.opsForValue().get(URL);
        String url1 = systemDictDao.findByDictNameAndCode("HEALTH_BANK_URL","HEALTH_BANK_URL");
        if (url != null && url1.equalsIgnoreCase(url)){
            return url;
        }else {
            redisTemplate.opsForValue().set(URL,url1);
            return url1;
        }
    }
    /**
     * 查找规则
     *
     * @param object 规则对象
     *
     * @param page 页码
     *
     * @param size 分页大小
     *
     * @return
     */
    public JSONObject selectTaskRule(JSONObject object, Integer page, Integer size){
        String response = null;
        String url =getBaseUrl() + "findTaskRule";
        Map<String,String> params = new HashMap<>();
        params.put("taskRule",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
}

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

@ -0,0 +1,167 @@
package com.yihu.wlyy.service.app.health.bank;/**
 * Created by nature of king on 2018/6/11.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.util.HttpClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author wangzhinan
 * @create 2018-06-11 8:54
 * @desc 健康银行活动
 **/
@Service
@Transactional
public class TaskService {
    private Logger logger = LoggerFactory.getLogger(TaskService.class);
    private static String URL = "health:blank:url";
    @Autowired
    private SystemDictDao systemDictDao;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private PatientDao patientDao;
    /**
     * 获取url
     *
     * @return
     */
    public  String getBaseUrl(){
        String url = redisTemplate.opsForValue().get(URL);
        String url1 = systemDictDao.findByDictNameAndCode("HEALTH_BANK_URL","HEALTH_BANK_URL");
        if (url != null && url1.equalsIgnoreCase(url)){
            return url;
        }else {
            redisTemplate.opsForValue().set(URL,url1);
            return url1;
        }
    }
    /**
     * 查看活动列表
     *
     * @param object
     * @return
     */
    public JSONObject selectActivity(JSONObject object,Integer page,Integer size){
        String response = null;
        String url =getBaseUrl() + "findActivity";
        Map<String,String> params = new HashMap<>();
        params.put("activity",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 查询任务获取积分
     *
     * @param taskCodeIds taskCode集合
     * @param patientId 居民id
     * @param page 页码
     * @param size 分页大小
     * @return
     */
    public JSONObject selectTask(JSONArray taskCodeIds,String patientId, Integer page, Integer size){
        String response = null;
        String url =getBaseUrl() + "selectByCode";
        JSONObject object = new JSONObject();
        object.put("taskCode",taskCodeIds.toJSONString());
        object.put("patientId",patientId);
        object.put("page",page.toString());
        object.put("size",size.toString());
        try {
            response = httpClientUtil.iotPostBody(url,object.toString());
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 参加任务
     *
     * @param object 参加任务JSON
     * @return
     */
    public JSONObject attendTask(JSONObject object){
        String response = null;
        Patient patient = patientDao.findByCode(object.getString("patientId"));
        String unionId = "1";
        patient.setUnionid(unionId);
        patientDao.save(patient);
        object.put("unionId",unionId);
        object.put("patientIdcard",patient.getIdcard());
        String url =getBaseUrl() + "attendTask";
        Map<String,String> params = new HashMap<>();
        params.put("taskPatientDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 根据openId获取用户数据
     *
     * @param openId 微信id
     *
     * @param page 页码
     *
     * @param size 分页大小
     *
     * @return
     */
    public JSONObject selectByOpenId(String openId, Integer page,Integer size){
        String sql = "select * from wlyy_patient where openid = '"+ openId +"' LIMIT "+(page-1)*size+","+size;
        List<Patient> patientList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(Patient.class));
        String sqlcount = "select * from wlyy_patient where openid = '"+ openId +"'";
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        JSONObject object = new JSONObject();
        object.put("patientList",patientList);
        object.put("total",count);
        object.put("page",page);
        object.put("size",size);
        return object;
    }
}

+ 106 - 8
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/message/MessageService.java

@ -5,6 +5,7 @@ import com.yihu.wlyy.entity.consult.ConsultTeam;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.entity.message.MessageNoticeSetting;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.health.repository.DevicePatientHealthIndexDao;
import com.yihu.wlyy.repository.consult.ConsultTeamDao;
import com.yihu.wlyy.repository.message.MessageDao;
@ -13,6 +14,8 @@ import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.IdCardUtil;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -360,8 +363,8 @@ public class MessageService extends BaseService {
    /**
     * 获取超标指标消息--根据患者分组
     */
    public List<Map<String, Object>> getHealthIndexMessage(String doctor) throws Exception {
        List<Map<String, Object>> re = new ArrayList<>();
    public Map<String,List<Map<String, Object>>> getHealthIndexMessage(String doctor) throws Exception {
        String sql = "select a.sender,a.tz_type,count(1) count,max(date_format(a.create_time,'%Y-%m-%d %H:%i:%s')) last_time,a.has_read from wlyy_Message a where a.receiver='" + doctor + "' and a.type='2' group by a.sender,a.tz_type,a.has_read order by last_time desc";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
@ -409,7 +412,7 @@ public class MessageService extends BaseService {
                System.out.print("not exit patient!code:" + patientCode);
            }
        }
        List<Map<String, Object>> re = new ArrayList<>();
        for (Map<String, Object> item : map.values()) {
            Map<String, Object> obj = new HashMap<>();
            String type = String.valueOf(item.get("type")); //1血糖,2血压,3体重,4腰
@ -422,6 +425,7 @@ public class MessageService extends BaseService {
            obj.put("sex", item.get("sex"));
            obj.put("birthday", item.get("birthday"));
            obj.put("photo", item.get("photo"));
            obj.put("count",count1);
            if ("1".equals(type)) {
                if(count1>0){
                    obj.put("message", "有" + count1 + "条血糖异常未读消息");
@ -437,6 +441,7 @@ public class MessageService extends BaseService {
            } else {
                break;
            }
            re.add(obj);
        }
        Collections.sort(re, new Comparator<Map<String, Object>>() {
@ -446,8 +451,18 @@ public class MessageService extends BaseService {
                return time2.compareTo(time1);
            }
        });
        return re;
        Map<String,List<Map<String, Object>>> result = new LinkedHashMap();
        for(Map<String, Object> one:re){
            String key = DateUtil.dateToStr(DateUtil.stringToDate(one.get("time")+"",DateUtil.YYYY_MM_DD_HH_MM_SS),DateUtil.YYYY_MM_DD);
            if(result.containsKey(key)&&result.get(key)!=null){
                List<Map<String, Object>> temp = result.get(key);
                temp.add(one);
                result.put(key,temp);
            }else{
                result.put(key,new ArrayList<>(Arrays.asList(one)));
            }
        }
        return result;
    }
    /**
@ -471,7 +486,7 @@ public class MessageService extends BaseService {
                map.put("type", type);
                map.put("read", String.valueOf(item.getRead()));
                map.put("sex", String.valueOf(item.getSex()));
                map.put("tzCode", String.valueOf(item.getTzCode()));
                map.put("czrq", DateUtil.dateToStrLong(item.getCreateTime()));
                DevicePatientHealthIndex data =devicePatientHealthIndexDao.findOne(Long.valueOf(item.getTzCode()));
@ -681,13 +696,96 @@ public class MessageService extends BaseService {
        }
    }
    public List<Map<String,Object>> getDevcieMessageByDoctorAndRead(String doctor,int read,int pageSize,int pageNo){
    public List<Map<String,Object>> getDevcieMessageByDoctor(String doctor,int pageSize,int pageNo){
        /*PageRequest pageRequest = new PageRequest(pageNo, pageSize);
        Page<Message> msgs = messageDao.deviceByReceiver(doctor, 1,pageRequest);
        */
        int start = (pageNo-1)*pageSize;
        String sql = "select * from wlyy_message a where a.type = 301 and a.has_read= "+ read+" and a.receiver='"+doctor+"' order by a.czrq desc limit ?,?";
        String sql = "select * from wlyy_message a where a.type = 301 and a.receiver='"+doctor+"' order by a.czrq desc limit ?,?";
        List<Map<String,Object>> messagelist = jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
        return messagelist;
    }
    public JSONObject getPatientInfo(String patientCode){
        JSONObject jsonObject = new JSONObject();
        Patient patient = patientDao.findByCode(patientCode);
        // 患者code
        jsonObject.put("code",patient.getCode());
        // 社保号
        jsonObject.put("ssc",patient.getSsc());
        // openid
        jsonObject.put("openid",StringUtils.isNotEmpty(patient.getOpenid()) ? patient.getOpenid() : "");
        // 性别
        jsonObject.put("sex",patient.getSex());
        // 患者手机号码
        jsonObject.put("mobile",patient.getMobile());
        // 头像
        jsonObject.put("photo",patient.getPhoto());
        // 身份证号码
        jsonObject.put("idcard",patient.getIdcard());
        // 患者名字
        jsonObject.put("name",patient.getName());
        // 患者年纪
        jsonObject.put("age",IdCardUtil.getAgeForIdcard(patient.getIdcard()));
        String sql = "SELECT sf.* FROM wlyy_sign_family sf LEFT JOIN wlyy_patient p ON sf.patient = p.`code` WHERE sf.`status`>0 and sf.patient='"+patientCode+"'";
        List<SignFamily> signFamilys = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(SignFamily.class));
        if (signFamilys!=null && signFamilys.size()>0){
            SignFamily signFamily = signFamilys.get(0);
            // 签约类型
            jsonObject.put("signType",signFamily.getType()== null ? "" : signFamily.getType());
            // 签约时间
            jsonObject.put("qyrq",signFamily.getApplyDate() != null ? DateUtil.dateToStr((signFamily.getApplyDate()),DateUtil.YYYY_MM_DD) : "");
            //紧急联系人
            jsonObject.put("emerMobile",signFamily.getEmerMobile() == null ? "" : signFamily.getEmerMobile());
            if (String.valueOf(signFamily.getType()).equals("2")) {
                // 缴费情况
                jsonObject.put("expensesStatus", signFamily.getExpensesStatus() != null ? String.valueOf(signFamily.getExpensesStatus()) : "0");
                // 缴费时间
                jsonObject.put("expensesTime", signFamily.getExpensesTime() != null ? DateUtil.dateToStr((signFamily.getExpensesTime()), DateUtil.YYYY_MM_DD_HH_MM) : "");
                // 缴费类型
                jsonObject.put("expensesType", signFamily.getExpensesType() != null ? String.valueOf(signFamily.getExpensesType()) : "");
                if (StringUtils.isEmpty(String.valueOf(signFamily.getExpensesStatus())) || String.valueOf(signFamily.getExpensesStatus()).equals("0")) {
                    boolean epTime = false;
                    try {
                        epTime = redisTemplate.opsForSet().isMember("expenses:remind:set", patient.getCode());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (!epTime) {
                        jsonObject.put("expensesRemindStatus", 0);
                    } else {
                        jsonObject.put("expensesRemindStatus", 1);
                    }
                }
            } else {
                // 缴费情况
                jsonObject.put("expensesStatus", "1");
            }
            boolean epTime = false;
            try {
                epTime = redisTemplate.opsForSet().isMember("wechat:focus:remind:set", patient.getCode());
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (!epTime) {
                jsonObject.put("wechatFocusRemind", 0);
            } else {
                jsonObject.put("wechatFocusRemind", 1);
            }
        }
        String devcieSql = "select group_concat(category_code) deviceType FROM wlyy_patient_device where user = '"+patientCode+"'";
        Map<String,Object> deviceMap = null;
        try {
            deviceMap = jdbcTemplate.queryForMap(devcieSql);
        }catch (Exception e){
            System.out.println(e.getMessage());
            deviceMap.put("devicrType",0);
        }
        /// 设备状态:0未绑定,1血糖仪,2血压仪,3血糖仪+血压仪
        jsonObject.put("deviceType",String.valueOf(deviceMap.get("deviceType")));
        return  jsonObject;
    }
}

+ 23 - 9
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionInfoService.java

@ -519,9 +519,9 @@ public class PrescriptionInfoService extends BaseService {
     * @param code
     * @return
     */
    public com.alibaba.fastjson.JSONObject getPrescription(String code,String patient) {
    public com.alibaba.fastjson.JSONObject getPrescription(String code,String patient,String preCode) {
        Patient p = patientDao.findByCode(patient);
        String rs = jwPrescriptionService.getRecipe(code, p.getSsc());
        String rs = jwPrescriptionService.getRecipe(code, p.getSsc(),preCode);
        com.alibaba.fastjson.JSONObject r = presModeAdapter.modelToSinglePrescription(rs);
    
        String rState = presCheckStateObj(code);
@ -559,14 +559,19 @@ public class PrescriptionInfoService extends BaseService {
            pp.put("mobile", p.getMobile());
            rs.put("patient", pp);
            SignFamily signFamily = signFamilyDao.findByIdcard(p.getIdcard());
            Map<String, Object> sf = new HashedMap();
            sf.put("doctor", signFamily.getDoctor());
            sf.put("hospital", signFamily.getHospital());
            sf.put("doctorName", signFamily.getDoctorName());
            sf.put("hospitalName", signFamily.getHospitalName());
            SignFamily signFamily = signFamilyDao.findByIdcard(p.getIdcard());
            if(signFamily!=null){
                sf.put("doctor", signFamily.getDoctor());
                sf.put("hospital", signFamily.getHospital());
                sf.put("doctorName", signFamily.getDoctorName());
                sf.put("hospitalName", signFamily.getHospitalName());
            }else{
                sf.put("doctor", prescription.getDoctor());
                sf.put("hospital", prescription.getHospital());
                sf.put("doctorName", prescription.getDoctorName());
                sf.put("hospitalName", prescription.getHospitalName());
            }
            rs.put("signFamily", sf);
        } else {
            rs.put("patient", "");
@ -1953,4 +1958,13 @@ public class PrescriptionInfoService extends BaseService {
			logger.info("续方取消,随访记录同步取消失败:"+e.getMessage());
		}
	}
    public Boolean checkPatientWithPrescription(String patient){
        List<Prescription> list =  prescriptionDao.findByPatient(patient);
        if(list!=null&&list.size()>0){
            return true;
        }else{
            return false;
        }
    }
}

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionService.java

@ -744,7 +744,7 @@ public class PrescriptionService extends BaseService {
        }
        if(org.apache.commons.lang.StringUtils.isNotBlank(RECIPE_NO)){
            String response = jwPrescriptionService.getRecipe(RECIPE_NO,patient.getSsc());
            String response = jwPrescriptionService.getRecipe(RECIPE_NO,patient.getSsc(),null);
            com.alibaba.fastjson.JSONObject jsonObject = presModeAdapter.modelToSinglePrescription(response);
            //药品
            com.alibaba.fastjson.JSONArray infos = jsonObject.getJSONArray("prescriptionInfo");

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

@ -376,10 +376,10 @@ public class StatisticsESService {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                long map1value = 0L;
                long map2value = 0L;
                if(o1.get("amount")!=null && o1.get("amount")+""!=""){
                     map1value = Long.valueOf(String.valueOf(o1.get("amount")));
                if (o1.get("amount") != null && o1.get("amount") + "" != "") {
                    map1value = Long.valueOf(String.valueOf(o1.get("amount")));
                }
                if(o2.get("amount")!=null && o2.get("amount")+""!=""){
                if (o2.get("amount") != null && o2.get("amount") + "" != "") {
                    map2value = Long.valueOf(String.valueOf(o2.get("amount")));
                }
@ -863,7 +863,7 @@ public class StatisticsESService {
     * @param index
     * @return
     */
    public JSONObject getDateTotal(String startDate, String endDate, int interval, String area, int level, String index, String lowCode, String year) throws Exception {
    public JSONObject getDateTotal(String startDate, String endDate, int interval, String area, int level, String index, String lowCode, String year, String timelevel) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        int taskNum = 0;
        JSONObject json = new JSONObject();
@ -876,7 +876,7 @@ public class StatisticsESService {
        }
//        }
        if (!org.springframework.util.StringUtils.isEmpty(lowCode)) {
             peopleNum = getPopulationBase(area, year);
            peopleNum = getPopulationBase(area, year);
            if (peopleNum != null) {
                if (lowCode.equals("3")) {
                    taskNum = peopleNum.getSixFiveTaskNum();
@ -890,15 +890,15 @@ public class StatisticsESService {
        json.put("taskNum", taskNum);
        if (interval == 1) {
            JSONArray jsonArray = dateTotalStatistics(startDate, endDate, area, level, index, lowCode);
            JSONArray jsonArray = dateTotalStatistics(startDate, endDate, area, level, index, lowCode, timelevel);
            json.put("data", jsonArray);
            return json;
        } else if (interval == 2) {
            JSONArray jsonArray = weekTotalStatistics(startDate, endDate, area, level, index, lowCode);
            JSONArray jsonArray = weekTotalStatistics(startDate, endDate, area, level, index, lowCode, timelevel);
            json.put("data", jsonArray);
            return json;
        } else if (interval == 3) {
            JSONArray jsonArray = monthTotalStatistics(startDate, endDate, area, level, index, lowCode);
            JSONArray jsonArray = monthTotalStatistics(startDate, endDate, area, level, index, lowCode, timelevel);
            json.put("data", jsonArray);
            return json;
        }
@ -917,15 +917,15 @@ public class StatisticsESService {
     * @return
     * @throws ParseException
     */
    public JSONArray dateTotalStatistics(String startDate, String endDate, String area, int level, String index, String lowCode) throws Exception {
    public JSONArray dateTotalStatistics(String startDate, String endDate, String area, int level, String index, String lowCode, String timelevel) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        List<SaveModel> saveModels = new ArrayList<>();
        //startDate = DateUtil.getNextDay(startDate,-1);
        if (StringUtils.isNotBlank(lowCode)) {
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate, endDate, area, level, index, SaveModel.timeLevel_DDL, SaveModel.interval_day, lowCode);
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate, endDate, area, level, index, timelevel, SaveModel.interval_day, lowCode);
        } else {
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, area, level, index, SaveModel.timeLevel_DDL, SaveModel.interval_day);
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, area, level, index, timelevel, SaveModel.interval_day);
        }
        List<JSONObject> result = new ArrayList<>();
        if (saveModels != null) {
@ -933,7 +933,7 @@ public class StatisticsESService {
            for (SaveModel saveModel : saveModels) {
                JSONObject json = new JSONObject();
                String range = null;
                if(saveModel.getQuotaDate()!=null){
                if (saveModel.getQuotaDate() != null) {
                    range = df.format(saveModel.getQuotaDate());
                }
                long amount = saveModel.getResult2().longValue();
@ -941,10 +941,10 @@ public class StatisticsESService {
                json.put("amount", amount);
                result.add(json);
            }
            if (saveModels!=null && saveModels.size()==1 && saveModels.get(0).getHospital()==null) {
                List<Map<String,Object>> resultList = DateUtil.findDates(dateFormat.parse(startDate), dateFormat.parse(DateUtil.getNextDay(endDate,1)));
            if (saveModels != null && saveModels.size() == 1 && saveModels.get(0).getHospital() == null) {
                List<Map<String, Object>> resultList = DateUtil.findDates(dateFormat.parse(startDate), dateFormat.parse(DateUtil.getNextDay(endDate, 1)));
                result.clear();
                for (Map<String,Object> map : resultList){
                for (Map<String, Object> map : resultList) {
                    JSONObject json = new JSONObject();
                    json.put("range", map.get("date"));
                    json.put("amount", 0);
@ -984,7 +984,7 @@ public class StatisticsESService {
     * @return
     * @throws Exception
     */
    private JSONArray weekTotalStatistics(String startDate, String endDate, String area, int level, String index, String lowCode) throws Exception {
    private JSONArray weekTotalStatistics(String startDate, String endDate, String area, int level, String index, String lowCode, String timelevel) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        // 起始日期
@ -1078,22 +1078,22 @@ public class StatisticsESService {
        List<SaveModel> saveModels = new ArrayList<>();
        if (StringUtils.isNotBlank(lowCode)) {
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate, endDate, area, level, index, SaveModel.timeLevel_DDL, SaveModel.interval_day, lowCode);
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate, endDate, area, level, index, timelevel, SaveModel.interval_day, lowCode);
        } else {
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, area, level, index, SaveModel.timeLevel_DDL, SaveModel.interval_day);
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, area, level, index, timelevel, SaveModel.interval_day);
        }
        if (saveModels != null) {
            // 计算结果
            for (SaveModel saveModel : saveModels) {
                String range = "";
                if (saveModel.getQuotaDate()!=null){
                if (saveModel.getQuotaDate() != null) {
                    range = df.format(saveModel.getQuotaDate());
                }
                JSONObject json = countResult.get(range);
                //因为上述时间集提前一天  但是前端是显示当前时间,所以这里给调整回去
                if(range.equals(df.format(temp.getTime()))){
                    json.put("range",endDate);
                if (range.equals(df.format(temp.getTime()))) {
                    json.put("range", endDate);
                }
                if (json != null) {
                    long amount = saveModel.getResult2().longValue();
@ -1135,7 +1135,7 @@ public class StatisticsESService {
     * @return
     * @throws Exception
     */
    private JSONArray monthTotalStatistics(String startDate, String endDate, String area, int level, String index, String lowCode) throws Exception {
    private JSONArray monthTotalStatistics(String startDate, String endDate, String area, int level, String index, String lowCode, String timelevel) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
@ -1206,22 +1206,22 @@ public class StatisticsESService {
        }
        List<SaveModel> saveModels = new ArrayList<>();
        if (StringUtils.isNotBlank(lowCode)) {
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate, endDate, area, level, index, SaveModel.timeLevel_DDL, SaveModel.interval_day, lowCode);
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate, endDate, area, level, index, timelevel, SaveModel.interval_day, lowCode);
        } else {
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, area, level, index, SaveModel.timeLevel_DDL, SaveModel.interval_day);
            saveModels = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, area, level, index, timelevel, SaveModel.interval_day);
        }
        if (saveModels != null) {
            // 计算结果
            for (SaveModel saveModel : saveModels) {
                String range = "";
                if (saveModel.getQuotaDate()!=null){
                if (saveModel.getQuotaDate() != null) {
                    range = df.format(saveModel.getQuotaDate());
                }
                JSONObject json = countResult.get(range);
                //因为上述时间集提前一天  但是前端是显示当前时间,所以这里给调整回去
                if(range.equals(df.format(temp.getTime()))){
                    json.put("range",endDate);
                if (range.equals(df.format(temp.getTime()))) {
                    json.put("range", endDate);
                }
                if (json != null) {
                    long amount = saveModel.getResult2().longValue();
@ -1369,9 +1369,9 @@ public class StatisticsESService {
        if (resultList != null) {
            String signTaskNum = "";
            if ("3".equals(lowCode)) {
                if ("2017".equals(year)){
                if ("2017".equals(year)) {
                    signTaskNum = systemDictService.getDictValueNoRedis("SIGN_TASKNUM_17_65", year);//2017年65岁以上的目标量
                }else if ("2016".equals(year)){
                } else if ("2016".equals(year)) {
                    signTaskNum = systemDictService.getDictValueNoRedis("SIGN_TASKNUM_16_65", year);
                }
            } else {
@ -2298,7 +2298,7 @@ public class StatisticsESService {
            }
            resultMaps.add(rs);
        }
        if (level == 4 ||"5".equals(low_level)) {
        if (level == 4 || "5".equals(low_level)) {
            Map<Integer, Map<String, Object>> leaders = getAllTeamLeaders();
            if (resultMaps != null && resultMaps.size() > 0) {
                for (Map<String, Object> r : resultMaps) {
@ -2459,7 +2459,7 @@ public class StatisticsESService {
        //获取结果集
        List<Map<String, Object>> resultList = null;
        if ("0".equals(type)) {
            resultList = DateUtil.findDates(dateFormat.parse(startDate), dateFormat.parse(DateUtil.getNextDay(endDate,1)));
            resultList = DateUtil.findDates(dateFormat.parse(startDate), dateFormat.parse(DateUtil.getNextDay(endDate, 1)));
        } else {
            resultList = DateUtil.findDateASWeeks(dateFormat.parse(startDate), dateFormat.parse(endDate));
        }
@ -4981,8 +4981,8 @@ public class StatisticsESService {
        //83:健康文章,84:健康指导
        List<SaveModel> list_83_84 = elasticsearchUtil.findListDateQuotaLevel0( endDate, area, level, "83,84", SaveModel.timeLevel_DDL, lowLevel);
        List<SaveModel> list_read_83_84 = elasticsearchUtil.findListDateQuotaLevel1(endDate,area,level,"83,84", SaveModel.timeLevel_DDL, lowLevel, "1");
        List<SaveModel> list_83_84 = elasticsearchUtil.findListDateQuotaLevel0(endDate, area, level, "83,84", SaveModel.timeLevel_DDL, lowLevel);
        List<SaveModel> list_read_83_84 = elasticsearchUtil.findListDateQuotaLevel1(endDate, area, level, "83,84", SaveModel.timeLevel_DDL, lowLevel, "1");
//        List<SaveModel> list_84 = elasticsearchUtil.findListDateQuotaLevel0(null, endDate, area, level, "84", SaveModel.timeLevel_ZL, lowLevel);
//        List<SaveModel> list_read_84 = elasticsearchUtil.findListDateQuotaLevel1(endDate,area,level,"84", SaveModel.timeLevel_DDL, lowLevel, "1");
@ -4991,68 +4991,68 @@ public class StatisticsESService {
        String readRate = "";
        DecimalFormat df = new DecimalFormat("0.00");
        List<Map<String, Object>> resultList = new ArrayList<>();
        for(SaveModel saveModel:list_83_84){
        for (SaveModel saveModel : list_83_84) {
            Map<String, Object> map = new HashMap<>();
            if (SaveModel.OrgLevel.equals(lowLevel)) {
                map.put("code", saveModel.getHospital());
                map.put("name", saveModel.getHospitalName());
                map.put("amount", saveModel.getResult1());
                Double readNum = 0.0;
                for(SaveModel saveModel2:list_read_83_84){
                    if(saveModel.getHospital().equals(saveModel2.getHospital())){
                for (SaveModel saveModel2 : list_read_83_84) {
                    if (saveModel.getHospital().equals(saveModel2.getHospital())) {
                        //获取阅读量
                        readNum = saveModel2.getResult1();
                        break;
                    }
                }
                readRate = df.format( readNum > 0.0? ((readNum)/(saveModel.getResult1() * 1.0000)*100):0.0);
                readRate = df.format(readNum > 0.0 ? ((readNum) / (saveModel.getResult1() * 1.0000) * 100) : 0.0);
                map.put("readNum", readNum.longValue());
                map.put("readRate", readRate+"%");
                map.put("readRate", readRate + "%");
            } else if (SaveModel.townLevel.equals(lowLevel)) {
                map.put("code", saveModel.getTown());
                map.put("name", saveModel.getTownName());
                map.put("amount", saveModel.getResult1());
                Double readNum = 0.0;
                for(SaveModel saveModel2:list_read_83_84){
                    if(saveModel.getTown().equals(saveModel2.getTown())){
                for (SaveModel saveModel2 : list_read_83_84) {
                    if (saveModel.getTown().equals(saveModel2.getTown())) {
                        //获取阅读量
                        readNum = saveModel2.getResult1();
                        break;
                    }
                }
                readRate = df.format( readNum > 0.0? ((readNum)/(saveModel.getResult1() * 1.0000)*100):0.0);
                readRate = df.format(readNum > 0.0 ? ((readNum) / (saveModel.getResult1() * 1.0000) * 100) : 0.0);
                map.put("readNum", readNum.longValue());
                map.put("readRate", readRate+"%");
                map.put("readRate", readRate + "%");
            } else if (SaveModel.cityLevel.equals(lowLevel)) {
                map.put("code", saveModel.getCity());
                map.put("name", saveModel.getCityName());
                map.put("amount", saveModel.getResult1());
                Double readNum = 0.0;
                for(SaveModel saveModel2:list_read_83_84){
                    if(saveModel.getCity().equals(saveModel2.getCity())){
                for (SaveModel saveModel2 : list_read_83_84) {
                    if (saveModel.getCity().equals(saveModel2.getCity())) {
                        //获取阅读量
                        readNum = saveModel2.getResult1();
                        break;
                    }
                }
                readRate = df.format( readNum > 0.0? ((readNum)/(saveModel.getResult1() * 1.0000)*100):0.0);
                readRate = df.format(readNum > 0.0 ? ((readNum) / (saveModel.getResult1() * 1.0000) * 100) : 0.0);
                map.put("readNum", readNum.longValue());
                map.put("readRate", readRate+"%");
                map.put("readRate", readRate + "%");
            } else if (SaveModel.teamLevel.equals(lowLevel)) {
                map.put("code", saveModel.getTeam());
                map.put("name", saveModel.getTeamName());
                map.put("amount", saveModel.getResult1());
                Double readNum = 0.0;
                for(SaveModel saveModel2:list_read_83_84){
                    if(saveModel.getTeam().equals(saveModel2.getTeam())){
                for (SaveModel saveModel2 : list_read_83_84) {
                    if (saveModel.getTeam().equals(saveModel2.getTeam())) {
                        //获取阅读量
                        readNum = saveModel2.getResult1();
                        break;
                    }
                }
                readRate = df.format( readNum > 0.0? ((readNum)/(saveModel.getResult1() * 1.0000)*100):0.0);
                readRate = df.format(readNum > 0.0 ? ((readNum) / (saveModel.getResult1() * 1.0000) * 100) : 0.0);
                map.put("readNum", readNum.longValue());
                map.put("readRate", readRate+"%");
                map.put("readRate", readRate + "%");
            }
            resultList.add(map);
        }
@ -5069,7 +5069,7 @@ public class StatisticsESService {
                        obj.put("name", town.getName());
                        obj.put("amount", "0");
                        obj.put("readNum", 0);
                        obj.put("readRate", Double.valueOf("0.00")+"%");
                        obj.put("readRate", Double.valueOf("0.00") + "%");
                        resultList.add(obj);
                    }
                }
@ -5092,7 +5092,7 @@ public class StatisticsESService {
                            obj.put("name", hos.getName());
                            obj.put("amount", "0");
                            obj.put("readNum", 0);
                            obj.put("readRate", Double.valueOf("0.00")+"%");
                            obj.put("readRate", Double.valueOf("0.00") + "%");
                            resultList.add(obj);
                        }
                    }
@ -5120,7 +5120,7 @@ public class StatisticsESService {
                            obj.put("name", team.getName());
                            obj.put("amount", "0");
                            obj.put("readNum", 0);
                            obj.put("readRate", Double.valueOf("0.00")+"%");
                            obj.put("readRate", Double.valueOf("0.00") + "%");
                            resultList.add(obj);
                        }
                    }
@ -5134,11 +5134,11 @@ public class StatisticsESService {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                long map1value = 0L;
                long map2value = 0L;
                if(o1.get("amount")!=null && o1.get("amount")+""!=""){
                    map1value = ((Double)o1.get("amount")).longValue();
                if (o1.get("amount") != null && o1.get("amount") + "" != "") {
                    map1value = ((Double) o1.get("amount")).longValue();
                }
                if(o2.get("amount")!=null && o2.get("amount")+""!=""){
                    map2value = ((Double)o2.get("amount")).longValue();
                if (o2.get("amount") != null && o2.get("amount") + "" != "") {
                    map2value = ((Double) o2.get("amount")).longValue();
                }
                if (map1value - map2value > 0) {
@ -5174,103 +5174,107 @@ public class StatisticsESService {
        return saveModel.getResult2().longValue();
    }
    public Map<String,Object> getLevelDeviceAndBinding(String area, int level, int sort, String lowLevel, String year,String deviceType) throws Exception {
    public Map<String, Object> getLevelDeviceAndBinding(String area, int level, int sort, String lowLevel, String year, String deviceType) throws Exception {
        String index_85 = "85";//设备发放量统计指标
        String index_86= "86";//设备绑定量统计指标
        String index_87= "87";//设备使用量统计指标
        String index_88= "88";//设备异常数据24H统计指标
        String index_86 = "86";//设备绑定量统计指标
        String index_87 = "87";//设备使用量统计指标
        String index_88 = "88";//设备异常数据24H统计指标
        //String lastDate = year + "-06-30";
        //String timeKey = elasticsearchUtil.getQuotaTime();
        String timeKey = DateUtil.getStringDateShort();//当前时间
        String mondayTime = DateUtil.getMondayOfThisDate(new Date());//本周一开始时间
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level + 1) : lowLevel);
        Map<String,Object> resultMap = new HashedMap();
        Map<String, Object> resultMap = new HashedMap();
        DecimalFormat df = new DecimalFormat("0.00");
        List<Map<String, Object>> resultList = new ArrayList<>();
        SaveModel grantSaveModel = null;
        SaveModel bindingSaveModel = null;
        List<SaveModel> useSaveModel = null;
        List<SaveModel> startUseSaveModel = null;
        List<SaveModel> endUseSaveModel = null;
        SaveModel anomalySaveModel = null;
        String allCountSql = "";
        String anomalyCountSql ="";
//        List<SaveModel> grantList = null;//发放量折线图
//        List<SaveModel> bindingList = null;//绑定量折线图
        String anomalyCountSql = "";
        List<SaveModel> allAmountList = null;//发放量列表
        List<SaveModel> bindingAmountList = null;//绑定量列表
        switch (deviceType){
        String areaCondition = "";
        if (SaveModel.OrgLevel.equals(level + "")) {
            areaCondition = " and d.grant_org_code like '" + area + "' ";
        } else if (SaveModel.townLevel.equals(level + "")) {
            areaCondition = " and d.grant_org_code like '" + area.substring(0, 4) + "%' ";
        } else if (SaveModel.cityLevel.equals(level + "")) {
            areaCondition = " and d.grant_org_code like '" + area.substring(0, 2) + "%' ";
        }
        switch (deviceType) {
            case "1": {
                grantSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey,area,level, index_85,SaveModel.timeLevel_DDL,"hemopiezometer");
                bindingSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey,area,level, index_86,SaveModel.timeLevel_DDL,"hemopiezometer");
                allCountSql = "SELECT COUNT(*) FROM device.wlyy_devices d where device_name like '%血压%'";
                useSaveModel = elasticsearchUtil.findDateQuotaLevel1(mondayTime,timeKey, area, level, index_87, SaveModel.timeLevel_ZL, "hemopiezometer", null, null);
                anomalySaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey,area,level, index_88,SaveModel.timeLevel_DDL,"hemopiezometer");
                anomalyCountSql =" SELECT COUNT(d.id) FROM device.wlyy_patient_health_index d where d.type =1 and d.status=1 and d.del=1";
//                grantList = elasticsearchUtil.findDateQuotaLevel1(timeKey,timeKey,area,level,index_85, SaveModel.timeLevel_DDL, "hemopiezometer", interval, null);
//                bindingList = elasticsearchUtil.findDateQuotaLevel1(timeKey,timeKey,area,level,index_86, SaveModel.timeLevel_DDL, "hemopiezometer", interval, null);
                allAmountList = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_85, SaveModel.timeLevel_DDL, "hemopiezometer","", low_level);
                bindingAmountList = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_86, SaveModel.timeLevel_DDL, "hemopiezometer","", low_level);
                grantSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey, area, level, index_85, SaveModel.timeLevel_DDL, "hemopiezometer");
                bindingSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey, area, level, index_86, SaveModel.timeLevel_DDL, "hemopiezometer");
                allCountSql = "SELECT COUNT(*) FROM device.wlyy_devices d where device_name like '%血压%' " + areaCondition;
                startUseSaveModel = elasticsearchUtil.findDateQuotaLevel1(mondayTime, mondayTime, area, level, index_87, SaveModel.timeLevel_DDL, "hemopiezometer", null, null);
                endUseSaveModel = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_87, SaveModel.timeLevel_DDL, "hemopiezometer", null, null);
                anomalySaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey, area, level, index_88, SaveModel.timeLevel_DDL, "hemopiezometer");
                anomalyCountSql = " SELECT COUNT(i.id) FROM device.wlyy_patient_health_index i left join device.wlyy_devices d on i.device_sn=d.device_code where i.type =1 and i.status=1 and i.del=1 " + areaCondition;
                allAmountList = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_85, SaveModel.timeLevel_DDL, "hemopiezometer", "", low_level);
                bindingAmountList = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_86, SaveModel.timeLevel_DDL, "hemopiezometer", "", low_level);
                break;
            }
            case "2": {
                grantSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey,area,level, index_85,SaveModel.timeLevel_DDL,"glucometer");
                bindingSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey,area,level, index_86,SaveModel.timeLevel_DDL,"glucometer");
                allCountSql = "SELECT COUNT(*) FROM device.wlyy_devices d where device_name like '%血糖%'";
                useSaveModel = elasticsearchUtil.findDateQuotaLevel1(mondayTime,timeKey, area, level, index_87, SaveModel.timeLevel_ZL, "glucometer", null, null);
                anomalySaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey,area,level, index_88,SaveModel.timeLevel_DDL,"glucometer");
                anomalyCountSql =" SELECT COUNT(d.id) FROM device.wlyy_patient_health_index d where d.type =2 and d.status=1 and d.del=1";
//                elasticsearchUtil.findDateQuotaLevel1(timeKey,timeKey,area,level,index_85, SaveModel.timeLevel_DDL, "glucometer", interval, null);
//                elasticsearchUtil.findDateQuotaLevel1(timeKey,timeKey,area,level,index_86, SaveModel.timeLevel_DDL, "glucometer", interval, null);
//                grantList = elasticsearchUtil.findDateQuotaLevel1(timeKey,timeKey,area,level,index_85, SaveModel.timeLevel_DDL, "hemopiezometer", interval, null);
//                bindingList = elasticsearchUtil.findDateQuotaLevel1(timeKey,timeKey,area,level,index_86, SaveModel.timeLevel_DDL, "hemopiezometer", interval, null);
                allAmountList = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_85, SaveModel.timeLevel_DDL, "glucometer","", low_level);
                bindingAmountList = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_86, SaveModel.timeLevel_DDL, "glucometer","", low_level);
                grantSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey, area, level, index_85, SaveModel.timeLevel_DDL, "glucometer");
                bindingSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey, area, level, index_86, SaveModel.timeLevel_DDL, "glucometer");
                allCountSql = "SELECT COUNT(*) FROM device.wlyy_devices d where device_name like '%血糖%' " + areaCondition;
                startUseSaveModel = elasticsearchUtil.findDateQuotaLevel1(mondayTime, mondayTime, area, level, index_87, SaveModel.timeLevel_DDL, "glucometer", null, null);
                endUseSaveModel = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_87, SaveModel.timeLevel_DDL, "glucometer", null, null);
                anomalySaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey, area, level, index_88, SaveModel.timeLevel_DDL, "glucometer");
                anomalyCountSql = " SELECT COUNT(i.id) FROM device.wlyy_patient_health_index i left join device.wlyy_devices d on i.device_sn=d.device_code where i.type =2 and i.status=1 and i.del=1 " + areaCondition;
                allAmountList = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_85, SaveModel.timeLevel_DDL, "glucometer", "", low_level);
                bindingAmountList = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_86, SaveModel.timeLevel_DDL, "glucometer", "", low_level);
                break;
            }
            default: {
                grantSaveModel = elasticsearchUtil.findOneDateQuotaLevel0(timeKey,area,level, index_85,SaveModel.timeLevel_DDL);
                bindingSaveModel = elasticsearchUtil.findOneDateQuotaLevel0(timeKey,area,level, index_86,SaveModel.timeLevel_DDL);
                anomalySaveModel = elasticsearchUtil.findOneDateQuotaLevel0(timeKey,area,level, index_88,SaveModel.timeLevel_DDL);
                allCountSql = "SELECT COUNT(*) FROM device.wlyy_devices d ";
                anomalyCountSql =" SELECT COUNT(d.id) FROM device.wlyy_patient_health_index d where  d.status=1 and d.del=1";
                useSaveModel = elasticsearchUtil.findDateQuotaLevel0(mondayTime,timeKey, area, level, index_87, SaveModel.timeLevel_ZL,  null, null);
//                grantList = elasticsearchUtil.findDateQuotaLevel0(timeKey,timeKey,area,level,index_85, SaveModel.timeLevel_DDL,  interval, null);
//                bindingList = elasticsearchUtil.findDateQuotaLevel0(timeKey,timeKey,area,level,index_86, SaveModel.timeLevel_DDL,  interval, null);
                allAmountList = elasticsearchUtil.findDateQuotaLevel0(timeKey, timeKey, area, level, index_85, SaveModel.timeLevel_DDL,"", low_level);
                grantSaveModel = elasticsearchUtil.findOneDateQuotaLevel0(timeKey, area, level, index_85, SaveModel.timeLevel_DDL);
                bindingSaveModel = elasticsearchUtil.findOneDateQuotaLevel0(timeKey, area, level, index_86, SaveModel.timeLevel_DDL);
                anomalySaveModel = elasticsearchUtil.findOneDateQuotaLevel0(timeKey, area, level, index_88, SaveModel.timeLevel_DDL);
                allCountSql = "SELECT COUNT(*) FROM device.wlyy_devices d where 1=1 " + areaCondition;
                anomalyCountSql = " SELECT COUNT(i.id) FROM device.wlyy_patient_health_index i left join device.wlyy_devices d on i.device_sn=d.device_code where  i.status=1 and i.del=1 " + areaCondition;
                startUseSaveModel = elasticsearchUtil.findDateQuotaLevel0(mondayTime, mondayTime, area, level, index_87, SaveModel.timeLevel_DDL, null, null);
                endUseSaveModel = elasticsearchUtil.findDateQuotaLevel0(timeKey, timeKey, area, level, index_87, SaveModel.timeLevel_DDL, null, null);
                allAmountList = elasticsearchUtil.findDateQuotaLevel0(timeKey, timeKey, area, level, index_85, SaveModel.timeLevel_DDL, "", low_level);
                bindingAmountList = elasticsearchUtil.findDateQuotaLevel0(timeKey, timeKey, area, level, index_86, SaveModel.timeLevel_DDL, "", low_level);
            }
        }
        Integer allCount = jdbcTemplate.queryForObject(allCountSql,Integer.class);
        Integer allCount = jdbcTemplate.queryForObject(allCountSql, Integer.class);
//        Long total = elasticsearchUtil.excuteForLong(countSql,esIndex, esType);
        resultMap.put("totalAll",allCount);//采购量
        resultMap.put("totalGrant",grantSaveModel.getResult1());//发放量
        resultMap.put("totalBinding",bindingSaveModel.getResult1());//绑定量
        resultMap.put("totalAll", allCount);//采购量
        resultMap.put("totalGrant", grantSaveModel.getResult1());//发放量
        resultMap.put("totalBinding", bindingSaveModel.getResult1());//绑定量
        if(allCount>0){
            resultMap.put("totalGrantRange",df.format( grantSaveModel.getResult1() > 0.0? ((grantSaveModel.getResult1())/(allCount * 1.0000)*100):0.0)+"%");//发放率
            resultMap.put("totalBindingRange",df.format( bindingSaveModel.getResult1() > 0.0? ((bindingSaveModel.getResult1())/(grantSaveModel.getResult1() * 1.0000)*100):0.0)+"%");//绑定率
        }else{
            resultMap.put("totalGrantRange",0.0+"%");//发放率
            resultMap.put("totalBindingRange",0.0+"%");//绑定率
        }
        Double totalUseAccount = useSaveModel.size()>0?useSaveModel.get(0).getResult1():0.0;
        resultMap.put("totalUse",totalUseAccount);//本周使用量
        if(grantSaveModel.getResult1()>0){
            resultMap.put("totalUseRange",df.format( totalUseAccount > 0.0? ((totalUseAccount)/(grantSaveModel.getResult1() * 1.0000)*100):0.0)+"%");//本周使用率
        }else{
            resultMap.put("totalUseRange",0.0+"%");//本周使用率
        if (allCount > 0) {
            resultMap.put("totalGrantRange", df.format(grantSaveModel.getResult1() > 0.0 ? ((grantSaveModel.getResult1()) / (allCount * 1.0000) * 100) : 0.0) + "%");//发放率
            resultMap.put("totalBindingRange", df.format(bindingSaveModel.getResult1() > 0.0 ? ((bindingSaveModel.getResult1()) / (grantSaveModel.getResult1() * 1.0000) * 100) : 0.0) + "%");//绑定率
        } else {
            resultMap.put("totalGrantRange", 0.0 + "%");//发放率
            resultMap.put("totalBindingRange", 0.0 + "%");//绑定率
        }
        Double startTotalUseAccount = startUseSaveModel.size() > 0 ? startUseSaveModel.get(0).getResult1() : 0.0;
        Double endTotalUseAccount = endUseSaveModel.size() > 0 ? endUseSaveModel.get(0).getResult1() : 0.0;
        Double totalUseAccount = endTotalUseAccount-startTotalUseAccount;
        resultMap.put("totalUse", endTotalUseAccount-startTotalUseAccount);//本周使用量
        if (grantSaveModel.getResult1() > 0) {
            resultMap.put("totalUseRange", df.format(totalUseAccount > 0.0 ? ((totalUseAccount) / (grantSaveModel.getResult1() * 1.0000) * 100) : 0.0) + "%");//本周使用率
        } else {
            resultMap.put("totalUseRange", 0.0 + "%");//本周使用率
        }
        Integer totalAnomaly = jdbcTemplate.queryForObject(anomalyCountSql,Integer.class);
        resultMap.put("totalAnomaly",totalAnomaly);//异常数据量
        resultMap.put("totalIntervene",anomalySaveModel.getResult1());//干预指导数
        if(totalAnomaly>0){
            resultMap.put("totalInterveneRange",df.format( anomalySaveModel.getResult1() > 0.0? ((anomalySaveModel.getResult1())/(totalAnomaly * 1.0000)*100):0.0)+"%");//异常数据24h干预指导率
        }else{
            resultMap.put("totalInterveneRange",0.0+"%");//异常数据24h干预指导率
        Integer totalAnomaly = jdbcTemplate.queryForObject(anomalyCountSql, Integer.class);
        resultMap.put("totalAnomaly", totalAnomaly);//异常数据量
        resultMap.put("totalIntervene", anomalySaveModel.getResult1());//干预指导数
        if (totalAnomaly > 0) {
            resultMap.put("totalInterveneRange", df.format(anomalySaveModel.getResult1() > 0.0 ? ((anomalySaveModel.getResult1()) / (totalAnomaly * 1.0000) * 100) : 0.0) + "%");//异常数据24h干预指导率
        } else {
            resultMap.put("totalInterveneRange", 0.0 + "%");//异常数据24h干预指导率
        }
@ -5344,14 +5348,185 @@ public class StatisticsESService {
                    }
                }
            });
            resultMap.put("list",resultList);
            resultMap.put("list", resultList);
            return resultMap;
        } else {
            return new HashedMap();
        }
    }
    //i健康活动统计1.4.8版本
    public Map<String, Object> statisticsActivity(String area, int level, int sort,String lowLevel,String slaveKey1) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        String index_89 = "89";//健康银行某个活动报名数(人次)
        String index_91 = "91";//健康银行全部活动报名数(人)
        String index_1 = "1";//签约已缴费指标(总人数按签约人数计算)
        String index_92 = "92";//健康银行活动参与数(人次)
        String timeKey = DateUtil.getStringDateShort();//当前时间
        String areaCondition = "";
        String areaCondition2 = "";
        //发布活动数
        if (SaveModel.OrgLevel.equals(level + "")) {
            areaCondition = " and d.area like '" + area + "' ";
            areaCondition2 = " and t.org_code like '" + area + "' ";
        } else if (SaveModel.townLevel.equals(level + "")) {
            areaCondition = " and d.area like '" + area.substring(0, 4) + "%' ";
            areaCondition2 = " and t.org_code like '" + area.substring(0, 4) + "%' ";
        } else if (SaveModel.cityLevel.equals(level + "")) {
            areaCondition = " and d.area like '" + area.substring(0, 2) + "%' ";
            areaCondition2 = " and t.org_code like '" + area.substring(0, 2) + "%' ";
        }
        String activitySql = "select count(1) from wlyy_health_bank_activity d where d.status=1  " + areaCondition;
        Integer activityCount = jdbcTemplate.queryForObject(activitySql, Integer.class);//发布活动数
        SaveModel activitySaveModel = null;//活动报名人次总量
        SaveModel participantSaveModel = null;//活动参与人次总量
        if(StringUtils.isNotEmpty(slaveKey1)){
            activitySaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey, area, level, index_89, SaveModel.timeLevel_DDL,slaveKey1);
            participantSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey, area, level, index_92, SaveModel.timeLevel_DDL,slaveKey1);
            resultMap = applyList(index_1,index_89,area,level, sort,lowLevel,slaveKey1,resultMap);//列表
        }else{
            activitySaveModel = elasticsearchUtil.findOneDateQuotaLevel0(timeKey, area, level, index_89, SaveModel.timeLevel_DDL);
            participantSaveModel = elasticsearchUtil.findOneDateQuotaLevel0(timeKey, area, level, index_92, SaveModel.timeLevel_DDL);
            resultMap = applyList(index_1,index_91,area,level, sort,lowLevel,slaveKey1,resultMap);//列表
        }
        if(!StringUtils.isNotEmpty(slaveKey1)){
            resultMap.put("activityCount",activityCount);//发布活动数
            resultMap.put("participantCount",participantSaveModel!=null?participantSaveModel.getResult1().intValue():0);//参与活动人数
        }else{
            String dayStart =  DateUtil.dateToStrLong(new Date(DateUtil.getDayStartTime(new Date()).getTime()));
            String currentTime  = DateUtil.getStringDate();
            String sql = " select count(1) from health_bank.wlyy_health_bank_active_record r join wlyy.wlyy_admin_team t on r.team_id=t.id where r.create_time>='"+dayStart+"' and r.create_time<='"+currentTime+"' r.activity_id='"+slaveKey1+"' "+areaCondition2;
            Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
            resultMap.put("dayActiveCount",count!=null?count.intValue():0);//今日活跃量
            resultMap.put("activityPatient",activitySaveModel.getResult1().intValue());//单个活动报名人数
        }
        //居民活跃统计
        resultMap.put("activityPatientRange","80%");//已报名
        resultMap.put("participantRange","60%");//已参与
        resultMap.put("expiryRange","20%");//已兑奖
        return resultMap;
    }
    /**
     * 获取活动信息
     *
     * @param id
     * @param area
     * @param level
     * @return
     */
    public List<Map<String, Object>> getAllAtivity(String id, String area, int level) {
        String condition = "";
        if (SaveModel.OrgLevel.equals(level + "")) {
            condition = " and a.area like '" + area + "' ";
        } else if (SaveModel.townLevel.equals(level + "")) {
            condition = " and a.area like '" + area.substring(0, 4) + "%' ";
        } else if (SaveModel.cityLevel.equals(level + "")) {
            condition = " and a.area like '" + area.substring(0, 2) + "%' ";
        }
        if (StringUtils.isNotEmpty(id)) {
            condition += " and a.id=" + id;
        }
        String sql = " select * from health_bank.wlyy_health_bank_activity a where a.status=1 " + condition;
        return jdbcTemplate.queryForList(sql);
    }
    //参与率列表
    public Map<String, Object> applyList(String index_all,String index_part,String area, int level, int sort, String lowLevel, String slaveKey1,Map<String, Object> resultMap) throws Exception {
//        String index_1 = "1";//签约已缴费指标(总人数按签约人数计算)
//        String index_91 = "91";//健康银行活动报名数
        String timeKey = DateUtil.getStringDateShort();//当前时间
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level + 1) : lowLevel);
//        Map<String, Object> resultMap = new HashedMap();//返回的结果
        List<SaveModel> allAmountList = null;//签约已缴费人数列表
        List<SaveModel> applyAmountList = null;//报名人数列表
        if (StringUtils.isNotEmpty(slaveKey1)) {
            allAmountList = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_all, SaveModel.timeLevel_DDL, slaveKey1, "", low_level);
            applyAmountList = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_part, SaveModel.timeLevel_DDL, slaveKey1, "", low_level);
        } else {
            allAmountList = elasticsearchUtil.findDateQuotaLevel0(timeKey, timeKey, area, level, index_all, SaveModel.timeLevel_DDL, "", low_level);
            applyAmountList = elasticsearchUtil.findDateQuotaLevel0(timeKey, timeKey, area, level, index_part, SaveModel.timeLevel_DDL, "", low_level);
        }
        Map<String, Integer> allMap = new HashMap<>(); //签约人数的的列表转map
        if (allAmountList != null && allAmountList.size() > 0) {
            for (SaveModel saveModel : allAmountList) {
                if ("3".equals(low_level) && saveModel.getTown() != null) {
                    allMap.put(saveModel.getTown(), saveModel.getResult2().intValue());
                } else if ("4".equals(low_level) && saveModel.getHospital() != null) {
                    allMap.put(saveModel.getHospital(), saveModel.getResult2().intValue());
                } else if ("5".equals(low_level) && saveModel.getTeam() != null) {
                    allMap.put(saveModel.getTeam(), saveModel.getResult2().intValue());
                } else {
                    continue;
                }
            }
        }
        //自建结果集
        List<Map<String, Object>> resultList = getLowLevelMapKey(level, low_level, area);
        if (resultList != null && resultList.size() > 0) {
            Map<String, SaveModel> applyMap = new HashMap<>();
            applyAmountList.stream().forEach(one -> {
                if ("5".equals(low_level)) {
                    applyMap.put(one.getTeam(), one);
                } else if ("4".equals(low_level)) {
                    applyMap.put(one.getHospital(), one);
                } else if ("3".equals(low_level)) {
                    applyMap.put(one.getTown(), one);
                }
            });
            for (Map<String, Object> reMap : resultList) {
                reMap.put("amount", reMap.get("amount") != null ? Long.valueOf(reMap.get("amount").toString()) : 0L);
                Integer allAmount = 0;
                int applyAmount = 0;
                //获取绑定数量
                if (applyMap != null && applyMap.size() > 0) {
                    SaveModel one = applyMap.get(reMap.get("code").toString());
                    if (one != null) {
                        applyAmount = one.getResult2().intValue();
                    }
                }
                if (allMap != null && allMap.size() > 0) {
                    allAmount = allMap.get(reMap.get("code").toString());
                    if (allAmount == null) {
                        allAmount = 0;
                    }
                }
                reMap.put("allNum", allAmount);
                reMap.put("applyNum", applyAmount);
                reMap.put("rate", getRange(applyAmount, allAmount, 2));//参与率是 报名数/签约数
                if ((level == 2 && "5".equals(lowLevel)) || (level == 4) || (level == 3 && "5".equals(lowLevel))) {
                    translateTeamLeaderName(resultList);
                }
                //对结果进行排序
                Collections.sort(resultList, new Comparator<Map<String, Object>>() {
                    public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                        int map1value = (int) o1.get("allNum");
                        int map2value = (int) o2.get("allNum");
                        if (map1value - map2value > 0) {
                            return sort == 1 ? -1 : 1;
                        } else if (map1value - map2value < 0) {
                            return sort == 1 ? 1 : -1;
                        } else {
                            return 0;
                        }
                    }
                });
            }
            resultMap.put("list", resultList);
            return resultMap;
        } else {
            return new HashedMap();
        }
    }

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/specialist/SpecialistService.java

@ -315,7 +315,7 @@ public class SpecialistService extends BaseService {
        param.put("nameKey",nameKey);
        param.put("page",page);
        param.put("size",size);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"getDoctorPatientByName",param);
        HttpResponse response = HttpUtils.doGet(specialistUrl+"svr-specialist/getDoctorPatientByName",param);
        JSONObject  rs = new JSONObject(response.getContent());
        if("succes".equals(rs.getString("message"))){
            return rs.getJSONArray("obj");

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorTeamGuidanceService.java

@ -484,7 +484,7 @@ public class DoctorTeamGuidanceService extends BaseService {
        guidance.setImages(image);
        // 保存
        if (patientHealthGuidanceService.add(guidance, accessToken) != null) {
        if (patientHealthGuidanceService.add(guidance, accessToken,null) != null) {
            String sendImgs = "";
            if (StringUtils.isNotBlank(image)) {
                sendImgs = image;

+ 0 - 330
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/health/bank/CreditLogService.java

@ -1,330 +0,0 @@
package com.yihu.wlyy.service.third.health.bank;/**
 * Created by nature of king on 2018/5/7.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author wangzhinan
 * @create 2018-05-07 9:24
 * @desc wlyy health bank service
 **/
@Service
@Transactional
public class CreditLogService {
    private Logger logger = LoggerFactory.getLogger(CreditLogService.class);
    @Value("${healthBank.url}")
    private String baseUrl;
    //    private String baseUrl = "http://192.168.131.24:8088/svr-iot/";
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private PatientDeviceService patientDeviceService;
    
    @Autowired
    private PatientService patientService;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    @Autowired
    private PatientDao patientDao;
    /**
     * 调用第三方积分排名接口
     *
     * @param doctorId
     * @param page
     * @param size
     * @return
     */
    public JSONObject selectByRanking(String doctorId, Integer page, Integer size){
        String sql = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND ( doctor = '" +doctorId + "' OR doctor_health = '" + doctorId +"')";
        List<SignFamily> signFamilyList = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamily.class));
        List<String>  patientIds = new ArrayList<>();
        if (signFamilyList != null && signFamilyList.size() != 0){
            for (SignFamily signFamily:signFamilyList){
                patientIds.add(signFamily.getPatient());
            }
        }
        JSONObject object = new JSONObject();
        object.put("filter",patientIds.toArray());
        object.put("page",page);
        object.put("size",size);
        String url = baseUrl + "selectByRanking";
        String response = null;
        JSONArray data =null;
        JSONObject object1 = null;
        try {
            response = httpClientUtil.iotPostBody(url,object.toString());
            object1 = JSONObject.parseObject(response);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 调用添加积分接口
     *
     * @param object
     * @return
     */
    public JSONObject insert(JSONObject object) throws Exception {
    
        JSONObject result = new JSONObject();
        
        init();
        String response = null;
        String integrate = getIntegrate("health:blank:integrate:"+object.getString("flag"));
        String patientId = object.getString("patientId");
        Patient patient = patientDao.findByCode(patientId);
        if (patient == null){
            throw new Exception("该居民不存在");
        }
        object.put("name",patient.getName());
        object.put("integrate",integrate);
        String url =baseUrl + "createCreditsDetail";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
    
        result = JSONObject.parseObject(response);
    
    
        String status = result.getString("status");
    
        logger.info("健康银行居民新增积分:"+result.toString());
        if ("200".equals(status)){
            List<Map<String,Object>> list = (List<Map<String,Object>>)result.get("detailModelList");
            if (list!=null && list.size()>0){
                //积分
                String integrateresult = String.valueOf(list.get(0).get("integrate"));
                String patientid = String.valueOf(list.get(0).get("patientId"));
                String total = String.valueOf(list.get(0).get("total"));
            
            
                try {
                    //@TODO 获取积分调用发送微信模板接口
                    Patient people = patientDao.findByCode(patientid);
                    String openId = people.getOpenid();
                    String name = people.getName();
                
                    org.json.JSONObject sendJson = new org.json.JSONObject();
                    String first = "";
                    String remark = "";
                    String urlresult = "";
                
                    WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_healthbank_credit","jfdztz");
                    first = templateConfig.getFirst();
                    remark = templateConfig.getRemark();
//                    String keyword1 = templateConfig.getKeyword1();
                
                    sendJson.put("keyword1", integrateresult);
                    sendJson.put("keyword2", DateUtil.getStringDate());
                    sendJson.put("keyword3", total);
                    sendJson.put("first", first);
                    sendJson.put("remark", remark);
                    urlresult = templateConfig.getUrl();
                    urlresult = urlresult.replace("key1",(integrate==null?"":integrate));
                    sendJson.put("url", urlresult);//带参数的模板跳转链接
                    System.out.println(sendJson.toString());
                    pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 23, openId, name, sendJson);
//	                    //发送代理人
//	                    jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openId);
//	                    if (jsonArray != null && jsonArray.length() > 0) {
//		                    for (int i = 0; i < jsonArray.length(); i++) {
//			                    org.json.JSONObject j = jsonArray.getJSONObject(i);
//			                    Patient member = (Patient) j.get("member");
//			                    int start = url.indexOf("&toUser=");
//			                    int end = url.indexOf("&", start + 1);
//			                    String touser = url.substring(start, end);
//			                    url = url.replace(touser, "&toUser=" + member.getCode());
//			                    //name患者姓名
//			                    sendJson.put("first", weiXinOpenIdUtils.getTitleMes(people, (int) j.get("relation"), name) + first);
//			                    sendJson.put("url", url);
//			                    pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 19, member.getOpenid(), name, sendJson);
//		                    }
//	                    }
                }catch (Exception e){
                    logger.info("健康银行居民新增积分,微信模板消息发送失败:"+e.getMessage());
//	                        e.printStackTrace();
                }
            
            }
        }
        return result;
    }
    /**
     * 按条件查询积分
     *
     * @param object
     * @param page
     * @param size
     * @return
     */
    public JSONObject selectByCondition(JSONObject object,Integer page,Integer size){
        String response = null;
        String url =baseUrl + "findCreditsLogInfo";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 查询账户积分详情
     *
     * @param object
     * @return
     */
    public JSONObject selectAccount(JSONObject object) throws Exception {
        String patientId = object.getString("patientId");
        Patient patient = patientDao.findByCode(patientId);
        if (patient == null){
            throw new Exception("该居民不存在");
        }
        object.put("name",patient.getName());
        String response = null;
        String url =baseUrl + "selectAccount";
        Map<String,String> params = new HashMap<>();
        params.put("creditsDetail",object.toJSONString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    /**
     * 查询任务完成情况
     *
     * @param object
     * @param page
     * @param size
     * @return
     */
    public JSONObject selectByTask(JSONObject object,Integer page,Integer size){
        JSONObject object1 = new JSONObject();
        String response = null;
        String url =baseUrl + "findTask";
        Map<String,String> params = new HashMap<>();
        params.put("task",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        String patientId = object.getString("patientId");
        try {
            response = httpClientUtil.httpPost(url,params);
            Map<String,Object> taskInfo = patientDeviceService.getPatientDeviceTaskInfo(patientId);
            object1 = JSONObject.parseObject(response);
            JSONArray array = object1.getJSONArray("detailModelList");
            JSONArray array1 = new JSONArray();
            for (int i =0 ;i<array.size();i++){
                JSONObject jsonObject = array.getJSONObject(i);
                String taskCode = jsonObject.getString("taskCode");
                if (taskCode.equalsIgnoreCase("BIND")){
                    jsonObject.put("deviceCount",taskInfo.get("deviceCount"));
                }else if (taskCode.equalsIgnoreCase("MEASURE")){
                    jsonObject.put("resultHealty",taskInfo.get("resultHealty"));
                }
                array1.add(jsonObject);
            }
            object1.put("detailModelList",array1);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return object1;
    }
    /**
     * 查询银行账户信息
     *
     * @param object 账户对象
     * @param page 页码
     * @param size 每页大小
     * @return
     */
    public JSONObject selectByAccount(JSONObject object,Integer page,Integer size){
        String response = null;
        String url =baseUrl + "findAccount";
        Map<String,String> params = new HashMap<>();
        params.put("account",object.toJSONString());
        params.put("page",page.toString());
        params.put("size",size.toString());
        try {
            response = httpClientUtil.httpPost(url,params);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return JSONObject.parseObject(response);
    }
    public void init(){
        redisTemplate.opsForValue().set("health:blank:integrate:BIND","1");
        redisTemplate.opsForValue().set("health:blank:integrate:MEASURE","1");
    }
    public String getIntegrate(String key){
        return redisTemplate.opsForValue().get(key);
    }
}

+ 4 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java

@ -225,11 +225,14 @@ public class JwPrescriptionService {
     * @param cardNo
     * @return
     */
    public String getRecipe(String recipeNo,String cardNo){
    public String getRecipe(String recipeNo,String cardNo,String preCode){
        String url = jwUrl + "/third/prescription/getRecipe";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("recipeNo", recipeNo));
        params.add(new BasicNameValuePair("cardNo", cardNo));
        if(StringUtils.isNotBlank(preCode)){
            params.add(new BasicNameValuePair("preCode", preCode));
        }
        String response = httpClientUtil.post(url, params, "UTF-8");

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

@ -4,6 +4,7 @@ import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
@ -121,8 +122,11 @@ public class HttpClientUtil {
     */
    public  String httpPost(String url, Map<String, String> params) throws Exception {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(30000).setConnectTimeout(10000).build();//设置请求和传输超时时间
        try {
            HttpPost httpPost = new HttpPost(url);
            httpPost.setConfig(requestConfig);
            if (params != null && params.size() > 0) {
                List<NameValuePair> valuePairs = new ArrayList<NameValuePair>(params.size());
                for (Map.Entry<String, String> entry : params.entrySet()) {

+ 5 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandlingController.java

@ -276,4 +276,9 @@ public class DataHandlingController extends BaseController {
            return write(0, "清洗数据失败!");
        }
    }
    //将wlyy_patient_device的数据清洗至wlyy_patietn_devcie_log
    //将devcie库中wlyy_device新增的字段补充完整
}

+ 17 - 9
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/device/DoctorDeviceController.java

@ -3,7 +3,6 @@ package com.yihu.wlyy.web.doctor.device;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.device.DeviceWxMessage;
import com.yihu.wlyy.entity.device.PatientDevice;
import com.yihu.wlyy.entity.device.vo.DeviceWxMessageDTO;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
@ -11,15 +10,15 @@ import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.app.device.DeviceDetailService;
import com.yihu.wlyy.service.app.device.DeviceWxMessageService;
import com.yihu.wlyy.service.app.device.PatientDeviceLogService;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.service.app.health.bank.CreditLogService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.health.bank.CreditLogService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.CommonUtil;
import com.yihu.wlyy.util.DateUtil;
@ -35,11 +34,13 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.jms.JMSException;
import javax.jms.Message;
@ -84,6 +85,8 @@ public class DoctorDeviceController extends BaseController {
	private CommonUtil commonUtil;
	@Autowired
	private DeviceWxMessageService deviceWxMessageService;
	@Autowired
	private PatientDeviceDao patientDeviceDao;
	@Autowired
	private JmsTemplate jmsTemplate;
@ -142,7 +145,7 @@ public class DoctorDeviceController extends BaseController {
			deviceDetailService.updateAfterBinding(device,new Date(),flag);
			Patient patient = patientDao.findByCode(device.getUser());
			//调用增加积分接口  海沧区的居民才能添加积分
			if (flag && "350205".equals(patient.getTown())){
			if (flag){
				String creditDetail = "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"BIND\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+device.getUser()+"\",\"hospital\":\""+patient.getTown()+"\"}";
				JSONObject jsonObject = JSONObject.parseObject(creditDetail);
				JSONObject response = creditLogService.insert(jsonObject);
@ -236,8 +239,8 @@ public class DoctorDeviceController extends BaseController {
				if(StringUtils.isNotBlank(pd.getDoctor())&&StringUtils.equals(pd.getDoctor(), getUID())){
					List<com.alibaba.fastjson.JSONObject> objects = patientDeviceService.deleteDevice(id,getUID());
					//全部解绑后去判断就更新设备表中是否绑定字段
					deviceDetailService.unBindUpdateIsBinding(pd.getDeviceSn());
					patientDeviceLogService.savePatientDeviceLog(pd,pd.getDeviceSn(),1,2);
					deviceDetailService.unBindUpdateIsBinding(pd.getDeviceSn());
					return write(200,"","data",objects);
				}
				else if(StringUtils.isNotBlank(pd.getDoctor())&&!StringUtils.equals(pd.getDoctor(), getUID())){
@ -249,8 +252,8 @@ public class DoctorDeviceController extends BaseController {
					}
					if(bo){//同行政团队
						List<com.alibaba.fastjson.JSONObject> objects = patientDeviceService.deleteDevice(id,getUID());
						deviceDetailService.unBindUpdateIsBinding(pd.getDeviceSn());
						patientDeviceLogService.savePatientDeviceLog(pd,pd.getDeviceSn(),1,2);
						deviceDetailService.unBindUpdateIsBinding(pd.getDeviceSn());
						return write(200,"","data",objects);
					}else{
						return error(-1, "只允许删除自己及自己行政团队绑定的设备!");
@ -280,10 +283,15 @@ public class DoctorDeviceController extends BaseController {
						@ApiParam(name="type",value="设备类型")
						@RequestParam(value="type",required = true) String type) {
		try{
			List<PatientDevice> patientDevices = patientDeviceDao.findByDeviceSnAndCategoryCode(deviceSn, type);
			PatientDevice patientDevice = new PatientDevice();
			if (patientDevices!=null && patientDevices.size()>0){
				patientDevice = patientDevices.get(0);
			}
			patientDeviceService.deleteDevices(deviceSn,type,getUID());
			//全部解绑后去判断就更新设备表中是否绑定字段
			patientDeviceLogService.savePatientDeviceLog(patientDevice,deviceSn,1,2);
			deviceDetailService.unBindUpdateIsBinding(deviceSn);
			patientDeviceLogService.savePatientDeviceLog(null,deviceSn,1,2);
			return write(200,"解绑成功!");
		}catch (Exception e){
			error(e);

+ 5 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthGuidanceController.java

@ -143,7 +143,8 @@ public class DoctorHealthGuidanceController extends WeixinBaseController {
                      @RequestParam String content,
                      @RequestParam(required = false) String modelCode,
                      @RequestParam(required = false) String images,
                      @RequestParam(required = false) String voice) {
                      @RequestParam(required = false) String voice,
                      @RequestParam(required = false) String tzCode) {
        String imageUrls = "";
        String imageRow = "";
@ -186,11 +187,12 @@ public class DoctorHealthGuidanceController extends WeixinBaseController {
                guidance.setImages(images);
                // 保存到居民端健康指导
                if (patientHealthGuidanceService.add(guidance, getAccessToken()) != null) {
                if (patientHealthGuidanceService.add(guidance, getAccessToken(),tzCode) != null) {
                    Patient p = patientService.findByCode(patient);
                    String imcotent = "{\"title\":\"健康指导\",\"type\":2,\"id\":\"" + guidance.getId() + "\",\"img\":\"" + guidance.getImages() + "\",\"content\":\"" + CommonUtil.getSubString(guidance.getContent(), 0, 30) + "\"}";
                    consultService.sendMucMessageBySingnType(getUID(), doctor.getName(), patient, imcotent, "4", p.getName());
                    BusinessLogs.info(BusinessLogs.BusinessType.guidance, getUID(), patient, new JSONObject(guidance));
                    return success("保存成功!");
                } else {
                    return error(-1, "居民签约已到期,请使用文字回复。");
@ -233,7 +235,7 @@ public class DoctorHealthGuidanceController extends WeixinBaseController {
                guidance.setImages(images);
                // 保存
                if (patientHealthGuidanceService.add(guidance, getAccessToken()) != null) {
                if (patientHealthGuidanceService.add(guidance, getAccessToken(),tzCode) != null) {
                    String sendImgs = "";
                    if (StringUtils.isNotBlank(images)) {
                        sendImgs = images;

+ 272 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/bank/ActivityController.java

@ -0,0 +1,272 @@
package com.yihu.wlyy.web.doctor.health.bank;/**
 * Created by nature of king on 2018/6/13.
 */
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.service.app.health.bank.CreditLogService;
import com.yihu.wlyy.service.app.health.bank.TaskRuleService;
import com.yihu.wlyy.service.app.health.bank.TaskService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * @authorwangzhinan
 * @create 2018-06-13 15:04
 * @desc 活动广场
 **/
@RestController
@RequestMapping(value = "/doctor/healthBank", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "医生端-健康广场")
public class ActivityController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(ActivityController.class);
    @Autowired
    private CreditLogService service;
    @Autowired
    private TaskService taskService;
    @Autowired
    private TaskRuleService taskRuleService;
    /**
     * 查询活动排名
     * @param doctorId 医生id
     *
     * @param activityId 活动id
     * @param page 页码
     *
     * @param size 分页大小
     * @return
     */
    @RequestMapping(value = "/findActivityRanking",method = RequestMethod.POST)
    @ApiOperation("查询活动排名")
    public String getById(@ApiParam(name = "doctorId",value = "医生Id")
                          @RequestParam(name = "doctorId")String doctorId,
                          @ApiParam(name = "activityId",value = "活动id")
                          @RequestParam(name = "activityId") String activityId,
                          @ApiParam(name = "name",value = "居民名称")
                          @RequestParam(name = "name",required = false)String name,
                          @ApiParam(name = "page", value = "第几页,从1开始")
                          @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                          @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                          @RequestParam(value = "size", required = false)Integer size){
        try {
            return write(200,"查询成功","data",service.selectByActivityRanking(activityId,doctorId,name,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 查询积分排名
     *
     * @param doctorId
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/findCreditRanking",method = RequestMethod.POST)
    @ApiOperation("查询积分排名")
    public String getById(@ApiParam(name = "doctorId",value = "医生Id")
                          @RequestParam(name = "doctorId")String doctorId,
                          @ApiParam(name = "name",value = "居民名称")
                          @RequestParam(name = "name",required = false)String name,
                          @ApiParam(name = "page", value = "第几页,从1开始")
                          @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                          @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                          @RequestParam(value = "size", required = false)Integer size){
        try {
            return write(200,"查询成功","data",service.selectByRanking(doctorId,name,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 活动广场
     *
     * @param task
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/selectTask",method = RequestMethod.POST)
    @ApiOperation("活动列表")
    public String selectByCondition(@ApiParam(name = "task",value = "任务JSON")
                                    @RequestParam(name = "task") String task,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                    @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                    @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(task);
            object.put("openId",getOpenid());
            return write(200,"查询成功","data",taskService.selectActivity(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 查看任务规则
     *
     * @param taskRule 任务规则对象
     * @param page 页码
     * @param size 分页大小
     * @return
     */
    @RequestMapping(value = "/selectTaskRule",method = RequestMethod.POST)
    @ApiOperation("查看任务规则")
    public String selectByTaskRule(@ApiParam(name = "taskRule",value = "规则JSON")
                                    @RequestParam(name = "taskRule") String taskRule,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                    @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                    @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(taskRule);
            return write(200,"查询成功","data",taskRuleService.selectTaskRule(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 根据条件查找用户信息
     *
     * @param condition {"doctorId":,"bindStatus":"","deviceTypes":[]}
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/selectAccountByCondition",method = RequestMethod.POST)
    @ApiOperation("根据条件查找用户信息")
    public String selectAccountByCondition(@ApiParam(name = "condition",value = "条件JSON")
                                   @RequestParam(name = "condition") String condition,
                                   @ApiParam(name = "page", value = "第几页,从1开始")
                                   @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                   @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                   @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(condition);
            return write(200,"查询成功","data",service.selectAccountByCondition(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 医生添加积分
     *
     * @param object {"patientIds":["915cc456-5b1d-11e6-8344-fa163e8aee56"],"ruleId":"4028037363fc550f0163fc633a1a0007","description":"321321"}
     * @return
     */
    @RequestMapping(value = "/doctorAddInteger",method = RequestMethod.POST)
    @ApiOperation("医生添加积分")
    public String doctorAddInteger(@ApiParam(name = "object",value = "object")
                                   @RequestParam(name = "object") String object){
        try {
            JSONObject object1 = JSONObject.parseObject(object);
            return write(200,"查询成功","data",service.doctorAddIntegrate(object1));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * find credits log details
     *
     * @param creditsLogDo
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/selectDetails",method = RequestMethod.POST)
    @ApiOperation("积分详情")
    public String selectByCondition1(@ApiParam(name = "creditsLogDo",value = "积分JSON")
                                    @RequestParam(name = "creditsLogDo") String creditsLogDo,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                    @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                    @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(creditsLogDo);
            return write(200,"查询成功","data",service.selectByCondition(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     *  根据条件查看银行账户信息
     *
     * @param account 银行账户
     * @param page 页码
     * @param size 每页大小
     * @return
     */
    @RequestMapping(value = "/findAccount",method = RequestMethod.POST)
    @ApiOperation("银行账户信息")
    public String selectByAccount(@ApiParam(name = "account",value = "任务JSON")
                                  @RequestParam(name = "account") String account,
                                  @ApiParam(name = "page", value = "第几页,从1开始")
                                  @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                  @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                  @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(account);
            return write(200,"查询成功","data",service.selectByAccount(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 医生端查询居民参与活动
     *
     * @param patientId 居民id
     * @param page 页码
     * @param size 分页大小
     * @return
     */
    @RequestMapping(value = "/selectByPatient",method = RequestMethod.POST)
    @ApiOperation("参与活动列表")
    public String selectByPatient(@ApiParam(name = "patientId",value = "居民id")
                                      @RequestParam(value = "patientId") String patientId,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                  @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                  @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                  @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = new JSONObject();
            object.put("patientId",patientId);
            return write(200,"查询成功","data",service.selectByPatient(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
}

+ 20 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/message/DoctorMessageController.java

@ -25,6 +25,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -243,7 +245,7 @@ public class DoctorMessageController extends BaseController {
    @ApiOperation("获取超标指标消息--根据患者分组")
    public String getHealthIndexMessage() throws Exception {
        try {
            List<Map<String, Object>> list = messageService.getHealthIndexMessage(getUID());     //"D20161008003"
            Map<String,List<Map<String, Object>>> list = messageService.getHealthIndexMessage(getUID());     //"D20161008003"
            return write(200, "获取超标指标消息成功", "data", list);
        } catch (Exception ex) {
@ -466,10 +468,26 @@ public class DoctorMessageController extends BaseController {
            page = "1";
        }
        try {
           return write(200,"查询成功!","data",messageService.getDevcieMessageByDoctorAndRead(getUID(),1,Integer.valueOf(pageSize),Integer.valueOf(page)));
           return write(200,"查询成功!","data",messageService.getDevcieMessageByDoctor(getUID(),Integer.valueOf(pageSize),Integer.valueOf(page)));
        }catch (Exception e){
            error(e);
            return error( -1, "查询失败!");
        }
    }
    @RequestMapping(value = "getDevcieMessageDetailToInfo",method = RequestMethod.POST)
    @ApiOperation("点击具体的设备解绑的消息跳转至具名详情页")
    @ResponseBody
    public String getDeviceMessageDetailToInfo(@ApiParam(name = "msgid",value = "消息主键id")@RequestParam(value = "msgid",required = true)long msgid,
                                               @ApiParam(name = "patientCode",value = "居民code")@RequestParam(value = "patientCode",required = true)String patientCode){
        try {
            messageService.readHealth(msgid);
            return write(200,"获取成功!","data",messageService.getPatientInfo(patientCode));
        }catch (Exception e){
            error(e);
            return error( -1, "操作失败!");
        }
    }
}

+ 3 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/prescription/PrescriptionInfoController.java

@ -527,9 +527,10 @@ public class PrescriptionInfoController extends BaseController {
    @RequestMapping(value = "/getPrescription", method = RequestMethod.GET)
    @ApiOperation(value = "获取长处方详细信息")
    public String getPrescription(@RequestParam(required = true) @ApiParam(name = "code", value = "处方CODE") String code
            ,@RequestParam(required = true) @ApiParam(name = "patient", value = "居民CODE") String  patient) {
            ,@RequestParam(required = true) @ApiParam(name = "patient", value = "居民CODE") String  patient,
                                  @RequestParam(required = false) @ApiParam(name = "preCode", value = "续方CODE")String preCode) {
        try {
            return write(200, "查询成功!", "data", prescriptionInfoService.getPrescription(code,patient));
            return write(200, "查询成功!", "data", prescriptionInfoService.getPrescription(code,patient,preCode));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/specialist/SpecialistController.java

@ -175,7 +175,7 @@ public class SpecialistController extends BaseController {
    @RequestMapping(value = "getDoctorPatientByName", method = RequestMethod.GET)
    @ApiOperation("搜索专科医生下的居民")
    public String getDoctorPatientByName(@ApiParam(name = "doctor", value = "医生code") @RequestParam(required = true)String doctor,
                                         @ApiParam(name = "name", value = "居民姓名模糊") @RequestParam(required = false)String nameKey,
                                         @ApiParam(name = "nameKey", value = "居民姓名模糊") @RequestParam(required = false)String nameKey,
                                         @ApiParam(name = "page", value = "第几页,1开始") @RequestParam(required = true)Integer page,
                                         @ApiParam(name = "size", value = "每页大小") @RequestParam(required = true)Integer size) {
        try {

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

@ -1,7 +1,6 @@
package com.yihu.wlyy.web.patient.device;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.device.DeviceDetail;
import com.yihu.wlyy.entity.device.PatientDevice;
import com.yihu.wlyy.entity.device.PatientHealthTime;
import com.yihu.wlyy.entity.message.Message;
@ -13,12 +12,12 @@ import com.yihu.wlyy.repository.message.MessageDao;
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.app.device.DeviceDetailService;
import com.yihu.wlyy.service.app.device.PatientDeviceLogService;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.service.app.device.DeviceDetailService;
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
import com.yihu.wlyy.service.app.health.bank.CreditLogService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.health.bank.CreditLogService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.web.BaseController;
@ -235,7 +234,7 @@ public class PatientDeviceController extends BaseController {
                patientDeviceService.saveDevice(device);
                patientDeviceLogService.savePatientDeviceLog(device,device.getDeviceSn(),2,1);
            }
            //修改设备表中{"1":"0", "2":"0"}的绑定次数 和其他绑定信息,
            //修改设备表中{"1":"0", "2":"0"}的绑定次数 和其他绑定信息
            deviceDetailService.updateAfterBinding(device,new Date(),flag);
            if (flag && "350205".equals(patient.getTown())){
                String creditDetail = "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"BIND\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+device.getUser()+"\",\"hospital\":\""+patient.getTown()+"\"}";
@ -409,6 +408,7 @@ public class PatientDeviceController extends BaseController {
                message.setType(301);//解绑设备消息
                message.setReadonly(1);//是否只读消息
                message.setSex(1);
                message.setRelationCode(patient.getCode());
                message.setOver("1");//未处理
                message.setData("");
                message.setDel("1");

+ 108 - 45
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/health/bank/CreditsLogController.java

@ -1,20 +1,11 @@
/**
 * Created by nature of king on 2018/5/7.
 */
package com.yihu.wlyy.web.third.health.bank;
import com.alibaba.fastjson.JSONArray;
package com.yihu.wlyy.web.patient.health.bank;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.health.bank.CreditLogService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.service.app.health.bank.CreditLogService;
import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.web.doctor.device.DoctorDeviceController;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -22,10 +13,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author wangzhinan
@ -33,7 +24,7 @@ import java.util.Map;
 * @desc credit log controller
 **/
@RestController
@RequestMapping(value = "/healthBank",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = "/patient/healthBank",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "积分处理机制")
public class CreditsLogController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(CreditsLogController.class);
@ -50,7 +41,7 @@ public class CreditsLogController extends BaseController {
     * @param size
     * @return
     */
    @RequestMapping(value = "/findCreditRanking",method = RequestMethod.POST)
    /*@RequestMapping(value = "/findCreditRanking",method = RequestMethod.POST)
    @ApiOperation("查询积分排名")
    public String getById(@ApiParam(name = "doctorId",value = "医生Id")
                              @RequestParam(name = "doctorId")String doctorId,
@ -64,7 +55,7 @@ public class CreditsLogController extends BaseController {
            error(e);
            return error(-1,e.getMessage());
        }
    }
    }*/
    /**
@ -75,7 +66,7 @@ public class CreditsLogController extends BaseController {
     */
    @RequestMapping(value = "/insertCredits",method = RequestMethod.POST)
    @ApiOperation("添加积分")
    public String insert(@ApiParam(name = "creditsDetail",value = "居民id集合")
    public String insert(@ApiParam(name = "creditsDetail",value = "居民对象JSON")
                          @RequestParam(name = "creditsDetail") String creditsDetail){
        try {
            JSONObject object = JSONObject.parseObject(creditsDetail);
@ -87,6 +78,8 @@ public class CreditsLogController extends BaseController {
        }
    }
    /**
     * find credits log details
     *
@ -132,54 +125,124 @@ public class CreditsLogController extends BaseController {
    }
    /**
     * 查询任务完成情况
     *  根据条件查看银行账户信息
     *
     * @param task
     * @param page
     * @param size
     * @param account 银行账户
     * @param page 页码
     * @param size 每页大小
     * @return
     */
    @RequestMapping(value = "/selectTasks",method = RequestMethod.POST)
    @ApiOperation("任务完成情况")
    public String selectByTask(@ApiParam(name = "task",value = "任务JSON")
                                    @RequestParam(name = "task") String task,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
    @RequestMapping(value = "/findAccount",method = RequestMethod.POST)
    @ApiOperation("银行账户信息")
    public String selectByAccount(@ApiParam(name = "account",value = "任务JSON")
                               @RequestParam(name = "account") String account,
                               @ApiParam(name = "page", value = "第几页,从1开始")
                               @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                               @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                               @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(account);
            return write(200,"查询成功","data",service.selectByAccount(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    @RequestMapping(value = "/selectByActivityRanking1",method = RequestMethod.POST)
    @ApiOperation("获取活动所有排名")
    public String selectByActivityRanking1(@ApiParam(name = "activityId",value = "活动id")
                                  @RequestParam(name = "activityId") String activityId,
                                  @ApiParam(name = "page", value = "第几页,从1开始")
                                  @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                  @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                  @RequestParam(value = "size", required = false)Integer size){
        try {
            return write(200,"查询成功","data",service.selectByActivityRanking1(activityId,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     *  参与活动列表
     *
     * @param page 页码
     *
     * @param size 分页大小
     *
     * @return
     */
    @RequestMapping(value = "/selectByPatient",method = RequestMethod.POST)
    @ApiOperation("参与活动列表")
    public String selectByPatient(@ApiParam(name = "page", value = "第几页,从1开始")
                                    @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                    @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(task);
            return write(200,"查询成功","data",service.selectByTask(object,page,size));
            JSONObject object = new JSONObject();
            object.put("openId",getOpenid());
            return write(200,"查询成功","data",service.selectByPatient(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     *  根据条件查看银行账户信息
     * 根据活动查积分
     *
     * @param activityId 活动id
     *
     * @param patientId 居民id
     *
     * @param account 银行账户
     * @param page 页码
     * @param size 每页大小
     *
     * @param size 分页大小
     *
     * @return
     */
    @RequestMapping(value = "/findAccount",method = RequestMethod.POST)
    @ApiOperation("银行账户信息")
    public String selectByAccount(@ApiParam(name = "account",value = "任务JSON")
                               @RequestParam(name = "account") String account,
                               @ApiParam(name = "page", value = "第几页,从1开始")
                               @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                               @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                               @RequestParam(value = "size", required = false)Integer size){
    @RequestMapping(value = "/selectByActivity",method = RequestMethod.POST)
    @ApiOperation("根据活动查积分")
    public String selectByActivity(@ApiParam(name = "activityId",value = "活动id")
                                  @RequestParam(name = "activityId") String activityId,
                                   @ApiParam(name = "patientId",value = "居民id")
                                   @RequestParam(name = "patientId") String patientId,
                                  @ApiParam(name = "page", value = "第几页,从1开始")
                                  @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                  @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                  @RequestParam(value = "size", required = false)Integer size){
        try {
            return write(200,"查询成功","data",service.selectByActivity(patientId,activityId,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
            JSONObject object = JSONObject.parseObject(account);
            return write(200,"查询成功","data",service.selectByAccount(object,page,size));
    /**
     * 步数获取积分
     *
     * @param creditsDetail {"patientId":"","transactionId":"","stepNumber":""}
     * @return
     */
    @RequestMapping(value = "/stepAddIntegrate",method = RequestMethod.POST)
    @ApiOperation("步数获取积分")
    public String stepAddIntegrate(@ApiParam(name = "creditsDetail",value = "对象JSON")
                         @RequestParam(name = "creditsDetail") String creditsDetail){
        try {
            JSONObject object = JSONObject.parseObject(creditsDetail);
            JSONObject result = service.insert(object);
            return write(200,"获取成功","data",result);
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
}

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

@ -0,0 +1,131 @@
package com.yihu.wlyy.web.patient.health.bank;/**
 * Created by nature of king on 2018/6/11.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.service.app.health.bank.TaskService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
/**
 * @author wangzhinan
 * @create 2018-06-11 10:49
 * @desc 健康任务
 **/
@RestController
@RequestMapping(value = "/patient/healthBank",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "健康活动")
public class TaskController extends BaseController{
    @Autowired
    private TaskService service;
    /**
     * 活动广场
     *
     * @param task
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/selectTask",method = RequestMethod.POST)
    @ApiOperation("活动列表")
    public String selectByCondition(@ApiParam(name = "task",value = "任务JSON")
                                    @RequestParam(name = "task") String task,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                    @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                    @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(task);
            object.put("openId",getOpenid());
            return write(200,"查询成功","data",service.selectActivity(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 查看任务列表
     *
     * @param task (taskCode:[],patientId:")
     *
     * @param page 页码
     *
     * @param size 分页大小
     *
     * @return
     */
    @RequestMapping(value = "/selectTasks",method = RequestMethod.POST)
    @ApiOperation("任务列表")
    public String selectByTask(@ApiParam(name = "task", value = "任务JSON")
                                    @RequestParam(name ="task" )String task,
                                    @ApiParam(name = "page", value = "第几页,从1开始")
                                    @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                    @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                    @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(task);
            JSONArray array = object.getJSONArray("taskCode");
            String patientId = object.getString("patientId");
            return write(200,"查询成功","data",service.selectTask(array,patientId,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 参加任务
     *
     * @param taskPatientDetail
     * @return
     */
    @RequestMapping(value = "/attendTask",method = RequestMethod.POST)
    @ApiOperation("参加任务")
    public String attendTask(@ApiParam(name = "taskPatientDetail",value = "参与活动JSON")
                             @RequestParam(name = "taskPatientDetail")String taskPatientDetail){
        try {
            JSONObject object = JSONObject.parseObject(taskPatientDetail);
            object.put("patientOpenid",getOpenid());
            return write(200,"报名成功","data",service.attendTask(object));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    /**
     * 获取用户信息
     *
     * @param page 页码
     *
     * @param size  分页大小
     *
     * @return
     */
    @RequestMapping(value = "/selectByOpenId",method = RequestMethod.POST)
    @ApiOperation("获取用户信息")
    public String selectByOpenId( @ApiParam(name = "page", value = "第几页,从1开始")
                                      @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                  @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                      @RequestParam(value = "size", required = false)Integer size){
        try {
            return write(200,"添加成功","data",service.selectByOpenId(getOpenid(),page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
}

+ 16 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/prescription/PatientPrescriptionInfoController.java

@ -77,9 +77,10 @@ public class PatientPrescriptionInfoController extends BaseController {
    @RequestMapping(value = "/getPrescription" ,method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取长处方详细信息")
    public String getPrescription(@RequestParam(required = true)@ApiParam(name="code",value="处方CODE")String code){
    public String getPrescription(@RequestParam(required = true)@ApiParam(name="code",value="处方CODE")String code,
                                  @RequestParam(required = false)@ApiParam(name="preCode",value="续方CODE")String preCode){
        try {
            return write(200, "查询成功!", "data", prescriptionInfoService.getPrescription(code,getRepUID()));
            return write(200, "查询成功!", "data", prescriptionInfoService.getPrescription(code,getRepUID(),preCode));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");
@ -157,5 +158,18 @@ public class PatientPrescriptionInfoController extends BaseController {
            return error(-1, e.getMessage());
        }
    }
    @ApiOperation("判断患者是否有续方记录")
    @ResponseBody
    @RequestMapping(value = "checkPatientWithPrescription", method = RequestMethod.GET)
    public String checkPatientWithPrescription(){
        try {
            return write(200, "获取信息成功!", "data",prescriptionInfoService.checkPatientWithPrescription(getUID()));
        }catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
}

+ 165 - 15
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/EsStatisticsController.java

@ -517,7 +517,7 @@ public class EsStatisticsController extends BaseController {
                    if ("13".equals(idx)) {
                        idx = "1";
                    }
                    JSONObject json = statisticsESService.getDateTotal(startDate, endDate, interval, area, level, idx, lowCode, year);
                    JSONObject json = statisticsESService.getDateTotal(startDate, endDate, interval, area, level, idx, lowCode, year,SaveModel.timeLevel_DDL);
                    result.put("index_" + idx, json);
                }
            }
@ -2177,7 +2177,7 @@ public class EsStatisticsController extends BaseController {
    @ApiOperation("设备绑定统计")
    @ResponseBody
    public String lowlevel_device(
            @RequestParam(required = false) String deviceType,//1血压 2血糖 不传是所有设备
            @RequestParam(required = false,defaultValue = "") String deviceType,//1血压 2血糖 不传是所有设备
            @RequestParam(required = true) String area,
            @RequestParam(required = true) int level,
            @RequestParam(required = true) int sort,
@ -2201,24 +2201,174 @@ public class EsStatisticsController extends BaseController {
        }
    }
    @RequestMapping("/lowlevel_activity")
    @ApiOperation("健康银行活动统计")
    @ResponseBody
    public String lowlevel_activity(@ApiParam(name = "id", value = "活动id") @RequestParam(required = false) String activityCode,
                                    @ApiParam(name = "area", value = "地区code") @RequestParam(required = true) String area,
                                    @ApiParam(name = "level", value = "地区级别,1 团队,2 机构,3 区,4 市") @RequestParam(required = true) int level,
                                    @ApiParam(name = "sort", value = "排序 1倒叙 2是 正序")@RequestParam(required = true) int sort,
                                    @ApiParam(name = "lowLevel", value = "(下一个级别)只有可能是 1,2,3,不传默认是level-1;") @RequestParam(required = false) String lowLevel,
                                    @RequestParam(required = false) String year){
        try{
            level = elasticsearchUtil.changeLevel(level);
            Map<String, Object> resultMap = statisticsESService.statisticsActivity(area,level,sort,lowLevel,activityCode);
            return write(200, "查询成功", "data", resultMap);
        }catch (Exception e){
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "/getAllAtivity",method = RequestMethod.GET)
    @ApiOperation("获取所有活动信息")
    @ResponseBody
    public String getAllAtivity(@ApiParam(name = "id", value = "活动id")
                                @RequestParam(value = "id", required = false)String id,
                                @ApiParam(name = "area", value = "地区code")
                                @RequestParam(value = "area", required = false)String area,
                                @ApiParam(name = "level", value = "地区级别,1 团队,2 机构,3 区,4 市")
                                @RequestParam(value = "level", required = false)int level){
        try{
            level = elasticsearchUtil.changeLevel(level);
            List<Map<String, Object>> list = statisticsESService.getAllAtivity(id,area,level);
            return write(200, "查询成功", "data", list);
        }catch (Exception e){
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    /**
     * 获取绑定和发放量的折线图
     * 健康银行活动人数增长曲线
     *
     * @param startDate
     * @param endDate
     * @param type      0 按周,1 按月
     * @param startDate 起始日期
     * @param endDate   结束时间
     * @param interval  时间间隔
     * @param area      区域或机构
     * @param level     级别
     * @param lowCode   子维度
     * @param year      查询年份
     * @return
     *//*
    @RequestMapping("/getDeviceLine")
     */
    @RequestMapping(value = "/activity_increase",method = RequestMethod.GET)
    @ResponseBody
    public String getDeviceLine(@RequestParam(required = true) String startDate,
                                 @RequestParam(required = true) String endDate,
                                 @RequestParam(required = true) String type) {
    public String activityIncrease(@RequestParam(required = true) String startDate,
                                     @RequestParam(required = true) String endDate,
                                     @RequestParam(required = true) int interval,
                                     @RequestParam(required = true) String area,
                                     @RequestParam(required = true) int level,
                                     @RequestParam(required = false) String lowCode,
                                     @RequestParam(required = false) String year) {
        try {
            return write(200, "查询成功", "data", statisticsESService.getSignCountLineByType(getUID(), type, startDate, endDate));
            //89指标
            level = elasticsearchUtil.changeLevel(level);
            JSONObject result = new JSONObject();
            if (org.springframework.util.StringUtils.isEmpty(year)) {
                year =  Constant.getNowYearByDate(endDate);
            }
            JSONObject json = statisticsESService.getDateTotal(startDate, endDate, interval, area, level, "89", lowCode, year,SaveModel.timeLevel_ZL);
            result.put("index_89", json);
            return write(200, "查询成功!", "data", result);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
            e.printStackTrace();
            return error(-1, "查询失败!");
        }
    }
    /**
     * 健康银行活跃人数增长曲线
     *
     * @param startDate 起始日期
     * @param endDate   结束时间
     * @param interval  时间间隔
     * @param area      区域或机构
     * @param level     级别
     * @param lowCode   子维度
     * @param year      查询年份
     * @return
     */
    @RequestMapping(value = "/active_statistics",method = RequestMethod.GET)
    @ResponseBody
    public String activeStatistics(@RequestParam(required = true) String startDate,
                                   @RequestParam(required = true) String endDate,
                                   @RequestParam(required = true) int interval,
                                   @RequestParam(required = true) String area,
                                   @RequestParam(required = true) int level,
                                   @RequestParam(required = false) String lowCode,
                                   @RequestParam(required = false) String year) {
        try {
            //89指标
            level = elasticsearchUtil.changeLevel(level);
            JSONObject result = new JSONObject();
            if (org.springframework.util.StringUtils.isEmpty(year)) {
                year =  Constant.getNowYearByDate(endDate);
            }
            JSONObject json = statisticsESService.getDateTotal(startDate, endDate, interval, area, level, "90", lowCode, year,SaveModel.timeLevel_ZL);
            result.put("index_90", json);
            return write(200, "查询成功!", "data", result);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败!");
        }
    }*/
    }
    /**
     * 报名量与活跃度到达量曲线
     *
     * @param startDate 起始日期
     * @param endDate   结束时间
     * @param interval  时间间隔
     * @param area      区域或机构
     * @param level     级别
     * @param activityCode   子维度
     * @param year      查询年份
     * @return
     */
    @RequestMapping(value = "/active_apply_statistics",method = RequestMethod.GET)
    @ResponseBody
    public String applyAndactiveStatistics(@ApiParam(name = "startDate", value = "开始时间") @RequestParam(required = true) String startDate,
                                           @ApiParam(name = "endDate", value = "结束时间") @RequestParam(required = true) String endDate,
                                           @ApiParam(name = "interval", value = "1日 2周 3月") @RequestParam(required = true) int interval,
                                           @ApiParam(name = "area", value = "地区") @RequestParam(required = true) String area,
        //                                   @RequestParam(required = true) String index,
                                           @ApiParam(name = "level", value = "地区级别,1 团队,2 机构,3 区,4 市") @RequestParam(required = true) int level,
                                           @ApiParam(name = "activityCode", value = "活动的id") @RequestParam(required = false) String activityCode,
                                           @RequestParam(required = false) String year) {
        try {
            level = elasticsearchUtil.changeLevel(level);
            JSONObject result = new JSONObject();
//            JSONObject json = statisticsESService.getDateTotal(startDate, endDate, interval, area, level, "90", lowCode, year,SaveModel.timeLevel_ZL);
//            result.put("index_89", json);
            String index = "";
            if(StringUtils.isNotEmpty(activityCode)){
                index="91,90";
            }else{
                index="89,90";
            }
            if (index != null) {
                if (org.springframework.util.StringUtils.isEmpty(year)) {
                    year =  Constant.getNowYearByDate(endDate);
                }
                String[] indexes = index.split(",");
                for (String idx : indexes) {
                    JSONObject json = statisticsESService.getDateTotal(startDate, endDate, interval, area, level, idx, activityCode, year,SaveModel.timeLevel_DDL);
                    result.put("index_"+idx, json);
                }
            }
            return write(200, "查询成功!", "data", result);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败!");
        }
    }
}

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

@ -0,0 +1,83 @@
/**
 * Created by nature of king on 2018/5/7.
 */
package com.yihu.wlyy.web.third.health.bank;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.service.app.health.bank.CreditLogService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author wangzhinan
 * @create 2018-05-07 8:50
 * @desc credit log controller
 **/
@RestController
@RequestMapping(value = "/healthBank",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "小程序")
public class AccountController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(AccountController.class);
    @Autowired
    private CreditLogService service;
    /**
     *  根据条件查看银行账户信息
     *
     * @param account 银行账户
     * @param page 页码
     * @param size 每页大小
     * @return
     */
    @RequestMapping(value = "/findAccount",method = RequestMethod.POST)
    @ApiOperation("银行账户信息")
    public String selectByAccount(@ApiParam(name = "account",value = "任务JSON")
                               @RequestParam(name = "account") String account,
                               @ApiParam(name = "page", value = "第几页,从1开始")
                               @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                               @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                               @RequestParam(value = "size", required = false)Integer size){
        try {
            JSONObject object = JSONObject.parseObject(account);
            return write(200,"查询成功","data",service.selectByAccount(object,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    @RequestMapping(value = "/selectByActivityRanking1",method = RequestMethod.POST)
    @ApiOperation("获取活动所有排名")
    public String selectByActivityRanking1(@ApiParam(name = "activityId",value = "活动id")
                                  @RequestParam(name = "activityId") String activityId,
                                  @ApiParam(name = "page", value = "第几页,从1开始")
                                  @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
                                  @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
                                  @RequestParam(value = "size", required = false)Integer size){
        try {
            return write(200,"查询成功","data",service.selectByActivityRanking1(activityId,page,size));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
}

+ 2 - 2
patient-co/patient-co-wlyy/src/main/resources/application-devtest.yml

@ -113,8 +113,8 @@ images:
sign:
  check_upload: http://172.19.103.88:8011/wlyy_service
  #check_upload: 192.168.131.24:8081
  #check_upload: http://172.19.103.88:8011/wlyy_service
  check_upload: localhost:8070/wlyy_service
express: