Forráskód Böngészése

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

yeshijie 7 éve
szülő
commit
bf98aad37e
25 módosított fájl, 670 hozzáadás és 81 törlés
  1. 46 0
      patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/common/http/HttpClientUtil.java
  2. 33 15
      patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/service/DeviceService.java
  3. 1 1
      patient-co-service/wlyy_device/src/main/resources/application.yml
  4. 1 1
      patient-co/patient-co-wlyy/pom.xml
  5. 5 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/deviece/WlyyDeviceDetailDao.java
  6. 13 4
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/PatientInfoService.java
  7. 44 26
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceService.java
  8. 19 6
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/WlyyDeviceDetailService.java
  9. 1 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java
  10. 6 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/SignWebService.java
  11. 11 4
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statisticsES/StatisticsESService.java
  12. 39 7
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/health/bank/CreditLogService.java
  13. 38 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java
  14. 2 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/Constant.java
  15. 62 9
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/device/DoctorDeviceController.java
  16. 10 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/PatientInfoController.java
  17. 95 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/device/PatientDeviceController.java
  18. 89 1
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/health/bank/CreditsLogController.java
  19. 6 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/WechatCoreController.java
  20. 36 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/WechatMenuController.java
  21. 4 0
      patient-co/patient-co-wlyy/src/main/resources/application-dev.yml
  22. 4 0
      patient-co/patient-co-wlyy/src/main/resources/application-devtest.yml
  23. 8 0
      patient-co/patient-co-wlyy/src/main/resources/application-prod.yml
  24. 5 1
      patient-co/patient-co-wlyy/src/main/resources/application-test.yml
  25. 92 0
      patient-co/patient-co-wlyy/src/main/resources/wechat/weixin_menu_haicang.txt

+ 46 - 0
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/common/http/HttpClientUtil.java

@ -2,10 +2,12 @@ package com.yihu.hos.device.common.http;
import org.apache.http.Consts;
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.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.URLEncodedUtils;
@ -23,6 +25,7 @@ import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -197,4 +200,47 @@ public class HttpClientUtil {
        org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<String>(params.toString(), headers);
        restTemplate.put(url, formEntity, String.class);
    }
    /**
     * 发送post请求
     *
     * @param url     请求地址
     * @param params  请求参数
     * @param chatSet 编码格式
     * @return
     */
    public  String post(String url, List<NameValuePair> params, String chatSet) {
        // 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
        HttpPost httppost = new HttpPost(url);
        UrlEncodedFormEntity uefEntity;
        try {
            uefEntity = new UrlEncodedFormEntity(params, chatSet);
            httppost.setEntity(uefEntity);
            CloseableHttpResponse response = httpclient.execute(httppost);
            try {
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    return EntityUtils.toString(entity, chatSet);
                }
            } finally {
                response.close();
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭连接,释放资源
            try {
                httpclient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}

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

@ -15,6 +15,10 @@ import net.sf.json.JSONObject;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
@ -82,6 +86,7 @@ public class DeviceService extends BaseService{
    @Autowired
    private IotDeviceService iotDeviceService;
    private static Logger logger = LoggerFactory.getLogger(DeviceService.class);
    private ObjectMapper objectMapper = new ObjectMapper();
    private Integer aStart;
@ -465,23 +470,35 @@ public class DeviceService extends BaseService{
                Patient patient = patientDao.findByCode(patientCode);
                //增加积分
                String url = wlyyService + "/healthBank/insertCredits";
                org.json.JSONObject params = new org.json.JSONObject();
                String creditDetail = "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"MEASURE\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+result.getUser()+"\",\"hospital\":\""+patient.getTown()+"\"}";
                params.put("creditsDetail", creditDetail);
                String response = HttpClientUtil.postBody(url, params);
                com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
                String status = jsonObject.getString("status");
                if ("200".equals(status)){
                    List<Map<String,Object>> list = (List<Map<String,Object>>)jsonObject.get("detailModelList");
                    if (list!=null && list.size()>0){
                        String integrate = String.valueOf(list.get(0).get("integrate"));
                        String flagType = String.valueOf(list.get(0).get("flag"));
                        //@TODO 调用发送微信模板接口
                String sql = "select count(*) num from wlyy.wlyy_devices where device_code = '"+deviceSn+"'";
                Map<String,Object> deviceCountMap = jdbcTemplate.queryForMap(sql);
                if (Integer.valueOf(String.valueOf(deviceCountMap.get("num")))>0){
                    String url = wlyyService + "healthBank/insertCredits";
                    List<NameValuePair> params = new ArrayList<>();
                    params.add(new BasicNameValuePair("creditsDetail", "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"MEASURE\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+result.getUser()+"\",\"hospital\":\"350205\"}"));
                    String response = HttpClientUtil.post(url, params, "UTF-8");
                    System.out.println(response);
                    com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
                    String status = jsonObject.getString("status");
                    if (!"200".equals(status)){
                        logger.error(jsonObject.getString("msg"));
                    }
                /*if (Integer.valueOf(String.valueOf(deviceCountMap.get("num")))>0){
                    String url = wlyyService + "/healthBank/insertCredits";
                    org.json.JSONObject params = new org.json.JSONObject();
                    String creditDetail = "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"MEASURE\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+result.getUser()+"\",\"hospital\":\""+patient.getTown()+"\"}";
                    params.put("creditsDetail", creditDetail);
                    String response = HttpClientUtil.postBody(url, params);
                    com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
                    String status = jsonObject.getString("status");
                    if (!"200".equals(status)){
                        logger.error(jsonObject.getString("msg"));
                    }
                }*/
                }
	            //血糖、血压数据需校验,如果超标,需要发送消息给医生
                //血糖、血压数据需校验,如果超标,需要发送消息给医生
	            if (1 == deviceType || 2 == deviceType) {
		            verifyHealthIndex(result);
		            //发送华三demo推送
@ -500,6 +517,7 @@ public class DeviceService extends BaseService{
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return Result.success("Device data incoming success");

+ 1 - 1
patient-co-service/wlyy_device/src/main/resources/application.yml

@ -134,4 +134,4 @@ systemConfig:
  msg_push_server: http://127.0.0.1:3000/system/sendmsg.im
  jw_server: http://59.61.92.90:8072/wlyy_service
  socket_server: http://27.155.101.77:3000
  server_url: http://www.yihu.com/wlyy/
  server_url: http://www.xmtyw.cn/wlyy/

+ 1 - 1
patient-co/patient-co-wlyy/pom.xml

@ -562,7 +562,7 @@
                    <target>1.8</target>
                    <compilerArguments>
                        <verbose/>
                        <bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jar</bootclasspath>
                        <bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>
                    </compilerArguments>
                </configuration>
                <version>3.1</version>

+ 5 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/deviece/WlyyDeviceDetailDao.java

@ -21,5 +21,9 @@ public interface WlyyDeviceDetailDao extends PagingAndSortingRepository<DeviceDe
	@Modifying
	@Query("update DeviceDetail dd set dd.isGrant=1,dd.grantAdminTeam=?1,dd.grantHospital=?2,dd.bindingCount=?3,dd.grantTime = ?4 where dd.deviceCode=?5")
	void updateAfterBinding(String adminTeam, String hospital, String isFirstBinding, Date grantTime,String deviceSn);
	void updateAfterBindingFirst(String adminTeam, String hospital, String isFirstBinding, Date grantTime,String deviceSn);
	@Modifying
	@Query("update DeviceDetail dd set dd.isGrant=1,dd.grantAdminTeam=?1,dd.grantHospital=?2,dd.bindingCount=?3 where dd.deviceCode=?4")
	void updateAfterBinding(String adminTeam, String hospital, String isFirstBinding,String deviceSn);
}

+ 13 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/PatientInfoService.java

@ -1743,18 +1743,27 @@ public class PatientInfoService extends BaseService {
        }
    }
    public List<Map<String,Object>> getPatientSignByNameOrIdCard(String keyWord,String doctorId,int pageNo,int pageSize){
    public List<Map<String,Object>> getPatientSignByNameOrIdCard(String keyWord,String deviceSn,String doctorId,int pageNo,int pageSize)throws Exception{
        Doctor doctor = doctorDao.findByCode(doctorId);
        String hospital = doctor.getHospital();
        int start = (pageNo-1)*pageSize;
        List<Map<String,Object>> patientList = new ArrayList<>();
        String sql = "SELECT p.code,p.name,CASE p.sex WHEN 1 THEN '男' WHEN 2 THEN '女' END sex,p.idcard,d.del,f.doctor_name" +
       /* String sql = "SELECT p.code,p.name,CASE p.sex WHEN 1 THEN '男' WHEN 2 THEN '女' END sex,p.idcard,f.doctor_name" +
                " FROM wlyy_patient p  LEFT JOIN wlyy_sign_family f ON p.code = f.patient" +
                " LEFT JOIN wlyy_patient_device d ON p.code = d.user" +
                " WHERE f.status = 1 AND p.name LIKE '%"+keyWord+"%' OR p.idcard LIKE '%"+keyWord+"%' and f.hospital = '"+hospital+"'"+" limit ?,?";
                " WHERE f.status = 1 AND p.name LIKE '%"+keyWord+"%' OR p.idcard LIKE '%"+keyWord+"%' and f.hospital = '"+hospital+"'"+" limit ?,?";*/
       String sql ="SELECT f.patient as code,f.name,f.idcard,f.doctor_name FROM wlyy_sign_family f where f.status > 0 AND f.hospital = '"+hospital+"' AND f.name LIKE '%"+keyWord+"%' OR f.idcard LIKE '%"+keyWord+"%' limit ?,?";
        patientList = jdbcTemplate.queryForList(sql ,new Object[]{start,pageSize});
        String patientDeviceSql = "SELECT user as patientCode FROM wlyy_patient_device WHERE device_sn='"+deviceSn+"'";
        List<Map<String,Object>> patientDeviceList = jdbcTemplate.queryForList(patientDeviceSql);
        for (Map<String,Object> map : patientList){
            map.put("age",IdCardUtil.getAgeForIdcard(String.valueOf(map.get("idcard"))));
            map.put("sex",Constant.getLevelSexName(IdCardUtil.getSexForIdcard_new(String.valueOf(map.get("idcard")))));
            for (Map<String,Object> patientDeviceMap : patientDeviceList){
                if (String.valueOf(map.get("code")).equals(String.valueOf(patientDeviceMap.get("patientCode")))){
                    map.put("del",0);
                }
            }
        }
        return patientList;
    }

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

@ -156,6 +156,10 @@ public class PatientDeviceService extends BaseService {
                flag = true;
            }
        }
        /*DeviceDetail deviceDetail = deviceDetailDao.findBySn(deviceSn);
        //if(deviceDetail != null){
            flag = true;
        }*/
        return flag;
    }
@ -1159,7 +1163,7 @@ public class PatientDeviceService extends BaseService {
    public Map<String,Object> getDeviceByDeviceSn(String deviceSn)throws Exception {
        Map<String,Object> map  = new HashedMap();
        String sql = "SELECT d.id,d.device_name deviceName,d.device_model deviceMode,d.device_activity_type deviceActivityType,e.is_multi_user isMultiUser,e.category_code as deviceType,e.multi_user multiUser FROM wlyy_devices d LEFT JOIN dm_device e ON d.device_model = e.model WHERE d.device_code='"+deviceSn+"'";
        String sql = "SELECT d.id,d.device_name deviceName,d.device_model deviceMode,d.sim,d.device_activity_type deviceActivityType,e.is_multi_user isMultiUser,e.category_code as deviceType,e.multi_user multiUser,e.id as device_id FROM wlyy_devices d LEFT JOIN dm_device e ON d.device_model = e.model WHERE d.device_code='"+deviceSn+"'";
        List<Map<String,Object>> mapSqlList = jdbcTemplate.queryForList(sql);
        if (mapSqlList!=null && mapSqlList.size()>0){
            map = mapSqlList.get(0);
@ -1180,12 +1184,16 @@ public class PatientDeviceService extends BaseService {
        return map;
    }
    public boolean isFirstNewBinding(String deviceSn,String userType){
    public boolean isFirstNewBinding(String deviceSn,String userType)throws Exception{
        boolean flag = true;
        String keyType = "1";
        if("2".equals(userType)){
            keyType = "2";
        }
        com.yihu.wlyy.entity.device.DeviceDetail deviceDetail = wlyyWlyyDeviceDetailDao.findByDeviceSn(deviceSn);
        if (deviceDetail!=null){
            JSONObject jsonObject =new JSONObject(deviceDetail.getBindingCount());
            if (jsonObject.getInt(userType)>0){
            if (jsonObject.getInt(keyType)>0){
                flag=false;
            }
@ -1209,33 +1217,43 @@ public class PatientDeviceService extends BaseService {
        //调用服务
        String response = HttpClientUtil.httpPost(url + registerDevice, HttpClientUtil.getSecretParams(params, appid, secret));
        System.out.println("注册设备=" + response);
        JSONObject json = new JSONObject(response);
        String code = json.get("Code").toString();
        //10000注册成功 10001已注册 -10000参数不通过(没传参数) -10001设备不存在 -10002设备未出库
        if ("10000".equals(code) || "10001".equals(code)) {
            flag = true;
        }else {
            String sql ="select count(*) num from wlyy_devices where device_code = '"+deviceSn+"'";
            Map<String,Object> map  = jdbcTemplate.queryForMap(sql);
            if (Integer.valueOf(String.valueOf(map.get("num")))>0){
                flag = true ;
                /*if (patientDeviceDao.findByDeviceSn(deviceSn)==null){
        if (!StringUtils.isEmpty(response)){
            JSONObject json = new JSONObject(response);
            String code = json.get("Code").toString();
            //10000注册成功 10001已注册 -10000参数不通过(没传参数) -10001设备不存在 -10002设备未出库
            if ("10000".equals(code) || "10001".equals(code)) {
                flag = true;
            }else {
                String sql ="select count(*) num from wlyy_devices where device_code = '"+deviceSn+"'";
                Map<String,Object> map  = jdbcTemplate.queryForMap(sql);
                if (Integer.valueOf(String.valueOf(map.get("num")))>0){
                    flag = true ;
                    message="设备可以绑定";
                }else {
                    resultCode = -10000;
                    message="已经被绑定了!";
                }*/
            }else {
                resultCode = -10001;
                message="没有该设备!";
                    resultCode = -10001;
                    message="没有该设备!";
                }
            }
        }else {
            resultCode=-1;
            message = "福州接口调用报错!";
            flag = false;
        }
        Map<String,Object> map = new HashedMap();
        map.put("code",resultCode);
        map.put("message",message);
        map.put("flag",flag);
        return map;
        String sql ="select count(*) num from wlyy_devices where device_code = '"+deviceSn+"'";
        Map<String,Object> map  = jdbcTemplate.queryForMap(sql);
        if (Integer.valueOf(String.valueOf(map.get("num")))>0){
            flag = true ;
        }else {
            resultCode = -10001;
            message="没有该设备!";
        }
        Map<String,Object> map1 = new HashedMap();
        map1.put("code",resultCode);
        map1.put("message",message);
        map1.put("flag",flag);
        return map1;
    }
    public Map<String,Object> getPatientDeviceTaskInfo(String patientCode)throws Exception{

+ 19 - 6
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/WlyyDeviceDetailService.java

@ -17,6 +17,7 @@ import java.util.List;
/**
 * 设备管理
 * zd
 */
@Component
@Transactional(rollbackFor = Exception.class)
@ -27,26 +28,38 @@ public class WlyyDeviceDetailService extends BaseService {
	@Autowired
	private SignFamilyDao signFamilyDao;
	public void updateAfterBinding(String deviceSn, String idCard, String userType, Date grantTime)throws Exception{
	public DeviceDetail findBySn(String sn){
		return  wlyyDeviceDetailDao.findByDeviceSn(sn);
	}
	public void updateAfterBinding(String deviceSn, String idCard, String userType, Date grantTime,boolean isFirst)throws Exception{
		DeviceDetail deviceDetail = wlyyDeviceDetailDao.findByDeviceSn(deviceSn);
		List<SignFamily> signFamilyList = signFamilyDao.findSSandJTByIdcard(idCard);
		String adminTeam="";
		long adminTeam=0L;
		String hospital = "";
		String isFirstBind = "";
		String keyType = "1";
		if ("2".equals(userType)){
			keyType="2";
		}
		if (signFamilyList!=null && signFamilyList.size()>0){
			adminTeam = signFamilyList.get(0).getTeamCode();
			adminTeam = signFamilyList.get(0).getAdminTeamId();
			hospital = signFamilyList.get(0).getHospital();
		}
		if (deviceDetail!=null){
			isFirstBind = deviceDetail.getBindingCount();
			if (StringUtils.isNotBlank(isFirstBind)){
				JSONObject jsonObject = JSON.parseObject(isFirstBind);
				int bindCount = Integer.valueOf(String.valueOf(jsonObject.get(userType)));
				jsonObject.replace(userType,userType+1);
				int bindCount = Integer.valueOf(String.valueOf(jsonObject.get(keyType)));
				jsonObject.replace(keyType,bindCount+1+"");
				isFirstBind = jsonObject.toJSONString();
			}
		}
		wlyyDeviceDetailDao.updateAfterBinding(adminTeam,hospital,isFirstBind,grantTime,deviceSn );
		if (isFirst){
			wlyyDeviceDetailDao.updateAfterBindingFirst(String.valueOf(adminTeam),hospital,isFirstBind,grantTime,deviceSn);
		}else {
			wlyyDeviceDetailDao.updateAfterBinding(String.valueOf(adminTeam),hospital,isFirstBind,deviceSn);
		}
	}
}

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

@ -3996,7 +3996,7 @@ public class FamilyContractService extends BaseService {
                jo.put("name", doctorHealth.getName());
                jo.put("photo", doctorHealth.getPhoto());
                jo.put("hosptialName", doctorHealth.getHospitalName());
                jo.put("level", doctorHealth.getLevel());
                jo.put("level", 3);
                jo.put("signType", "2");//三师签约
                jo.put("signStatus", jtSignFamily.getStatus());
                jo.put("jobName", doctorHealth.getJobName());

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

@ -1892,6 +1892,8 @@ public class SignWebService extends BaseService {
                Patient patient = patientService.findByCode(renew.getPatient());
                if (patient != null && StringUtils.isNotBlank(patient.getOpenid())) {
                    data.put("agent","0");
                    if ("0".equals(state)) {
                        if (StringUtils.isNotEmpty(refuseReason)){
                            data.put("content", refuseReason);
@ -1903,6 +1905,7 @@ public class SignWebService extends BaseService {
                        first = first.replace("key1",(renew.getName()==null?"":renew.getName())).replace("br","\n");
                        String remark = templateConfig.getRemark();
                        data.put("first", first);
                        data.put("remark", remark);
                        /*data.put("first", renew.getName() + ",您好!\n" +
@ -1915,7 +1918,6 @@ public class SignWebService extends BaseService {
                        first = first.replace("key1",(renew.getName()==null?"":renew.getName())).replace("br","\n");
                        String remark = templateConfig.getRemark();
                        String keyword4 = templateConfig.getKeyword4();
                        data.put("first", first);
                        data.put("remark", remark);
                        data.put("content", keyword4);
@ -1929,6 +1931,9 @@ public class SignWebService extends BaseService {
                }else {
                    //发送代理人
                    JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
                    data.put("agent","1");
                    if (jsonArray != null && jsonArray.length() > 0) {
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject j = jsonArray.getJSONObject(i);

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

@ -5159,8 +5159,9 @@ public class StatisticsESService {
    public Map<String,Object> getLevelDeviceAndBinding(String area, int level, int sort, String lowLevel, String year) throws Exception {
        String index_85 = "85";
        String index_86= "86";
        String lastDate = year + "-06-30";
        String timeKey = elasticsearchUtil.getQuotaTime();
        //String lastDate = year + "-06-30";
        //String timeKey = elasticsearchUtil.getQuotaTime();
        String timeKey = DateUtil.getStringDateShort();
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level + 1) : lowLevel);
        List<Map<String, Object>> resultList = new ArrayList<>();
        Map<String,Object> resultMap = new HashedMap();
@ -5169,8 +5170,14 @@ public class StatisticsESService {
        List<SaveModel> allAmountList = elasticsearchUtil.findDateQuotaLevel0(timeKey, timeKey, area, level, index_85, SaveModel.timeLevel_DDL, "", low_level);
        //绑定量
        List<SaveModel> bindingAmountList = elasticsearchUtil.findDateQuotaLevel0(timeKey, timeKey, area, level, index_86, SaveModel.timeLevel_DDL, "", low_level);
        Integer totalAllNum = allAmountList.get(0).getResult2().intValue();
        Integer totalBindingNum = bindingAmountList.get(0).getResult2().intValue();
        Integer totalAllNum = 0;
        Integer totalBindingNum = 0;
        for (SaveModel totalSaveModel : allAmountList){
            totalAllNum += totalSaveModel.getResult2().intValue();
        }
        for (SaveModel bindSaveModel : bindingAmountList){
            totalBindingNum += bindSaveModel.getResult2().intValue();
        }
        resultMap.put("totalAll",totalAllNum);
        resultMap.put("totalBinding",totalBindingNum);
        resultMap.put("totalRange",getRange(totalBindingNum, totalAllNum, 2));

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

@ -4,7 +4,9 @@ package com.yihu.wlyy.service.third.health.bank;/**
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.patient.PatientDao;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.util.HttpClientUtil;
import org.slf4j.Logger;
@ -44,6 +46,10 @@ public class CreditLogService {
    private StringRedisTemplate redisTemplate;
    @Autowired
    private PatientDeviceService patientDeviceService;
    @Autowired
    private PatientDao patientDao;
    /**
     * 调用第三方积分排名接口
@ -54,7 +60,7 @@ public class CreditLogService {
     * @return
     */
    public JSONObject selectByRanking(String doctorId, Integer page, Integer size){
        String sql = "SELECT * FROM wlyy_sign_family WHERE status = 1 AND doctor = '" +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){
@ -86,10 +92,16 @@ public class CreditLogService {
     * @param object
     * @return
     */
    public JSONObject insert(JSONObject object){
    public JSONObject insert(JSONObject object) throws Exception {
        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<>();
@ -136,7 +148,13 @@ public class CreditLogService {
     * @param object
     * @return
     */
    public JSONObject selectAccount(JSONObject object){
    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<>();
@ -161,6 +179,7 @@ public class CreditLogService {
     * @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<>();
@ -171,12 +190,25 @@ public class CreditLogService {
        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 JSONObject.parseObject(response);
        return object1;
    }
    /**
@ -205,8 +237,8 @@ public class CreditLogService {
    }
    public void init(){
        redisTemplate.opsForValue().set("health:blank:integrate:BIND","20");
        redisTemplate.opsForValue().set("health:blank:integrate:MEASURE","20");
        redisTemplate.opsForValue().set("health:blank:integrate:BIND","1");
        redisTemplate.opsForValue().set("health:blank:integrate:MEASURE","1");
    }
    public String getIntegrate(String key){

+ 38 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java

@ -79,6 +79,10 @@ public class PushMsgTask {
    private String doctor_invitel_template;
    @Value("${wechat.message.template_deal_with}")
    private String template_deal_with;
    @Value("${wechat.message.template_patient_bind_device}")
    private String template_patient_bind_device;
    @Value("${wechat.message.template_healthbank_credit}")
    private String template_healthbank_credit;
    @Autowired
    private StringRedisTemplate redisTemplate;
@ -802,6 +806,40 @@ public class PushMsgTask {
                keyword5.setColor("#000000");
                keyword5.setValue(json.getString("keyword5"));
                m.put("keyword5", keyword5);
            }else if (type == 22) {//设备绑定
                if (json.has("url")) {
                    temp.setUrl(url + json.getString("url"));
                }
                temp.setTemplate_id(template_patient_bind_device);
                WechatTemplateData keyword1 = new WechatTemplateData();
                keyword1.setColor("#000000");
                keyword1.setValue(json.getString("keyword1"));
                m.put("keyword1", keyword1);
                WechatTemplateData keyword2 = new WechatTemplateData();
                keyword2.setColor("#000000");
                keyword2.setValue(json.getString("keyword2"));
                m.put("keyword2", keyword2);
                WechatTemplateData keyword3 = new WechatTemplateData();
                keyword3.setColor("#000000");
                keyword3.setValue(json.getString("keyword3"));
                m.put("keyword3", keyword3);
            }else if (type == 23) {//健康银行积分提醒
                if (json.has("url")) {
                    temp.setUrl(url + json.getString("url"));
                }
                temp.setTemplate_id(template_healthbank_credit);
                WechatTemplateData keyword1 = new WechatTemplateData();
                keyword1.setColor("#000000");
                keyword1.setValue(json.getString("keyword1"));
                m.put("keyword1", keyword1);
                WechatTemplateData keyword2 = new WechatTemplateData();
                keyword2.setColor("#000000");
                keyword2.setValue(json.getString("keyword2"));
                m.put("keyword2", keyword2);
                WechatTemplateData keyword3 = new WechatTemplateData();
                keyword3.setColor("#000000");
                keyword3.setValue(json.getString("keyword3"));
                m.put("keyword3", keyword3);
            }
            temp.setData(m);

+ 2 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/Constant.java

@ -15,8 +15,8 @@ public class Constant {
    public static String level_sex_1="1";
    public static String level_sex_2="2";
    public static String level_sex_3="3";
    public static String level_sex_1_name="女";
    public static String level_sex_2_name="男";
    public static String level_sex_1_name="男";
    public static String level_sex_2_name="女";
    public static String level_sex_3_name="未知";
    //二级维度的年龄

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

@ -6,17 +6,25 @@ import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.device.PatientDevice;
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.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.app.device.WlyyDeviceDetailService;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
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;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
@ -36,6 +44,7 @@ import java.util.Map;
@RequestMapping(value = "doctor/device", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "患者设备管理--医生端", description = "患者设备管理--医生端")
public class DoctorDeviceController extends BaseController {
	private static Logger logger = LoggerFactory.getLogger(DoctorDeviceController.class);
	@Autowired
	private PatientDeviceService patientDeviceService;
@ -51,6 +60,14 @@ public class DoctorDeviceController extends BaseController {
	@Autowired
	private PatientService patientService;
	@Autowired
	private WechatTemplateConfigDao templateConfigDao;
	@Autowired
	private PushMsgTask pushMsgTask;
	@Autowired
	private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
	@Autowired
	private PatientDao patientDao;
	private ObjectMapper  objectMapper=new ObjectMapper();
@ -93,8 +110,8 @@ public class DoctorDeviceController extends BaseController {
			//绑定
			patientDeviceService.saveDevice(device);
			//修改设备表中是否是首绑{"1":"1", "2":"1"}修改成{"1":"0", "2":"0"} 和其他绑定信息,
			wlyyDeviceDetailService.updateAfterBinding(device.getDeviceSn(),device.getUserIdcard(),device.getUserType(),new Date());
			//修改设备表中{"1":"0", "2":"0"}绑定次数 和其他绑定信息,
			wlyyDeviceDetailService.updateAfterBinding(device.getDeviceSn(),device.getUserIdcard(),device.getUserType(),new Date(),flag);
			//调用增加积分接口
			if (flag){
				Patient patient = patientService.findByCode(device.getUser());
@ -102,16 +119,52 @@ public class DoctorDeviceController extends BaseController {
				JSONObject jsonObject = JSONObject.parseObject(creditDetail);
				JSONObject response = creditLogService.insert(jsonObject);
				String status = response.getString("status");
				if ("200".equals(status)){
                    List<Map<String,Object>> list = (List<Map<String,Object>>)response.get("detailModelList");
                    if (list!=null && list.size()>0){
                        String integrate = String.valueOf(list.get(0).get("integrate"));
                        String flagType = String.valueOf(list.get(0).get("flag"));
                        //@TODO 调用发送微信模板接口
                    }
				if (!"200".equals(status)){
					logger.info("添加积分失败!");
                }
			}
			try {
				Patient people = patientDao.findByCode(device.getUser());
				String openId = people.getOpenid();
				String name = people.getName();
				org.json.JSONObject sendJson = new org.json.JSONObject();
				String first = "";
				String remark = "";
				String deviceName = device.getDeviceName();
				WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_patient_bind_device","bdsb");
				first = templateConfig.getFirst();
				first = first.replace("key1",(deviceName==null?"":deviceName));
				remark = templateConfig.getRemark();
				sendJson.put("keyword1", deviceName);
				sendJson.put("keyword2", DateUtil.dateToStrLong(device.getCzrq()));
				sendJson.put("keyword3", templateConfig.getKeyword3());
				sendJson.put("first", first);
				sendJson.put("remark", remark);
				sendJson.put("url", templateConfig.getUrl());//带参数的模板跳转链接
				System.out.println(sendJson.toString());
				pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 22, 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 success("设备保存成功!");
		}
		catch (Exception ex) {

+ 10 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/PatientInfoController.java

@ -517,10 +517,19 @@ public class PatientInfoController extends BaseController {
        }
    }
    /**
     *
     * @param keyWord
     * @param deviceSn
     * @param page
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/getPatientSignByNameOrIdCard",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("在绑定设备的时候查找患者(带签约信息)")
    public String getPatientSignByNameOrIdCard(@ApiParam(value = "关键搜索词", name = "keyWord") @RequestParam(value = "keyWord",required = true)String keyWord,
                                               @ApiParam(value = "设备sn码", name = "deviceSn") @RequestParam(value = "deviceSn",required = true)String deviceSn,
                                                @ApiParam(name="page",value="第几页",defaultValue = "1") @RequestParam(value="page",required = true) String page,
                                                @ApiParam(name="pageSize",value="",defaultValue = "10") @RequestParam(value="pageSize",required = true) String pageSize){
        if (StringUtils.isBlank(pageSize)) {
@ -530,7 +539,7 @@ public class PatientInfoController extends BaseController {
            page = "1";
        }
        try {
            return  write(200,"查找成功!","data",patientInfoService.getPatientSignByNameOrIdCard(keyWord,getUID(),Integer.valueOf(page),Integer.valueOf(pageSize)));
            return  write(200,"查找成功!","data",patientInfoService.getPatientSignByNameOrIdCard(keyWord,deviceSn,getUID(),Integer.valueOf(page),Integer.valueOf(pageSize)));
        } catch (Exception e) {
            error(e);
            return error( -1, "查询失败!");

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

@ -1,19 +1,32 @@
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.patient.Patient;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.deviece.PatientHealthTimeDao;
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.service.app.device.WlyyDeviceDetailService;
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
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.util.HttpClientUtil;
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;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
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.domain.Page;
@ -23,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -36,6 +50,7 @@ import java.util.Map;
@RequestMapping(value = "patient/device")
@Api(value = "患者设备管理", description = "患者设备管理")
public class PatientDeviceController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(PatientDeviceController.class);
    @Autowired
    private PatientDeviceService patientDeviceService;
@ -47,6 +62,18 @@ public class PatientDeviceController extends BaseController {
    private HttpClientUtil HttpClientUtil;
    @Autowired
    private PatientHealthIndexService patientHealthIndexService;
    @Autowired
    private WlyyDeviceDetailService wlyyDeviceDetailService;
    @Autowired
    private CreditLogService creditLogService;
    @Autowired
    private PatientService patientService;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    @Value("${yihu.yihu_OpenPlatform_url}")
    private String url;
@ -186,6 +213,8 @@ public class PatientDeviceController extends BaseController {
            // 设置患者标识
            device.setUser(getRepUID());
//            device.setUser(getUID());
            //首绑加分判断
            boolean flag = patientDeviceService.isFirstNewBinding(device.getDeviceSn(),device.getUserType());
            if(!getUID().equals(getRepUID())&&device.getId()==null){
                device.setAgent(getRepUID());
            }
@ -193,6 +222,72 @@ public class PatientDeviceController extends BaseController {
            synchronized (sn.intern()){
                patientDeviceService.saveDevice(device);
            }
            //判断是否为积分设备
            DeviceDetail deviceDetail = wlyyDeviceDetailService.findBySn(device.getDeviceSn());
            if (deviceDetail!=null){
                //修改设备表中{"1":"0", "2":"0"}的绑定次数 和其他绑定信息,
                wlyyDeviceDetailService.updateAfterBinding(device.getDeviceSn(),device.getUserIdcard(),device.getUserType(),new Date(),flag);
                Patient patient = patientService.findByCode(device.getUser());
                if (flag){
                    String creditDetail = "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"BIND\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+device.getUser()+"\",\"hospital\":\""+patient.getTown()+"\"}";
                    com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(creditDetail);
                    com.alibaba.fastjson.JSONObject response = creditLogService.insert(jsonObject);
                    System.out.println("添加积分返回数据======"+response.toJSONString());
                    String status = response.getString("status");
                    if ("200".equals(status)){
                        List<Map<String,Object>> list = (List<Map<String,Object>>)response.get("detailModelList");
                        if (list!=null && list.size()>0){
                            String integrate = String.valueOf(list.get(0).get("integrate"));
                            String flagType = String.valueOf(list.get(0).get("flag"));
                            //@TODO 调用发送微信模板接口
	                        //Patient people = patientDao.findByCode(device.getUser());
                        }
                    }
                }
    
                try {
                    String openId = patient.getOpenid();
                    String name = patient.getName();
        
                    org.json.JSONObject sendJson = new org.json.JSONObject();
                    String first = "";
                    String remark = "";
                    String deviceName = device.getDeviceName();
                    WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_patient_bind_device","bdsb");
                    first = templateConfig.getFirst();
                    first = first.replace("key1",(deviceName==null?"":deviceName));
                    remark = templateConfig.getRemark();
        
                    sendJson.put("keyword1", deviceName);
                    sendJson.put("keyword2", DateUtil.dateToStrLong(device.getCzrq()));
                    sendJson.put("keyword3", templateConfig.getKeyword3());
                    sendJson.put("first", first);
                    sendJson.put("remark", remark);
                    sendJson.put("url", templateConfig.getUrl());//带参数的模板跳转链接
                    System.out.println(sendJson.toString());
                    pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 22, 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 success("设备保存成功!");
        } catch (Exception ex) {

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

@ -4,15 +4,29 @@
package com.yihu.wlyy.web.third.health.bank;
import com.alibaba.fastjson.JSONArray;
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.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;
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;
/**
 * @author wangzhinan
 * @create 2018-05-07 8:50
@ -22,9 +36,20 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping(value = "/healthBank",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "积分处理机制")
public class CreditsLogController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(CreditsLogController.class);
    @Autowired
    private CreditLogService service;
    @Autowired
    private PatientService patientService;
    @Autowired
    private WechatTemplateConfigDao templateConfigDao;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    @Autowired
    private PatientDao patientDao;
    /**
     * 查询积分排名
@ -63,7 +88,70 @@ public class CreditsLogController extends BaseController {
                          @RequestParam(name = "creditsDetail") String creditsDetail){
        try {
            JSONObject object = JSONObject.parseObject(creditsDetail);
            return write(200,"添加成功","data",service.insert(object));
            JSONObject result = service.insert(object);
    
            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 integrate = 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 url = "";
    
                        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_healthbank_credit","jfdztz");
                        first = templateConfig.getFirst();
                        remark = templateConfig.getRemark();
//                    String keyword1 = templateConfig.getKeyword1();
    
                        sendJson.put("keyword1", integrate);
                        sendJson.put("keyword2", DateUtil.getStringDate());
                        sendJson.put("keyword3", total);
                        sendJson.put("first", first);
                        sendJson.put("remark", remark);
                        url = templateConfig.getUrl();
                        url = url.replace("key1",(integrate==null?"":integrate));
                        sendJson.put("url", url);//带参数的模板跳转链接
                        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 write(200,"添加成功","data",result);
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());

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

@ -7,6 +7,8 @@ import com.yihu.wlyy.web.WeixinBaseController;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
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.http.MediaType;
@ -30,6 +32,7 @@ import java.util.Arrays;
@Api(description = "微信")
public class WechatCoreController extends WeixinBaseController {
    private Logger logger= LoggerFactory.getLogger(WeixinBaseController.class);
    @Autowired
    private WeiXinCoreService weiXinCoreService;
    @Value("${wechat.wechat_token}")
@ -103,6 +106,9 @@ public class WechatCoreController extends WeixinBaseController {
                    response.setHeader("Content-type", "text/html;charset=UTF-8");
                    //这句话的意思,是告诉servlet用UTF-8转码,而不是用默认的ISO8859
                    response.setCharacterEncoding("UTF-8");
                    logger.info(xmlStr);
                    response.getWriter().print(xmlStr);
                }
            } else {

+ 36 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/WechatMenuController.java

@ -115,6 +115,42 @@ public class WechatMenuController extends BaseController {
            return error(-1, "创建失败");
        }
    }
    
    /**
     * 海沧区微信特色菜单菜单创建
     *
     * @return
     */
    @ApiOperation(value = "海沧区微信特色菜单菜单创建")
    @RequestMapping(value = "/menu/create/haicang", method = RequestMethod.GET)
    public String createMenuTestHaicang() {
        try {
            String filePath = WechatCoreController.class.getResource("/").getPath() +
                    File.separator + "wechat" + File.separator + "weixin_menu_haicang.txt";
            String url = " https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=" + weiXinAccessTokenUtils.getAccessToken();
            // 读取微信菜单配置文件
            InputStreamReader reader = new InputStreamReader(new FileInputStream(filePath), "utf-8");
            BufferedReader bufferedReader = new BufferedReader(reader);
            String params = "";
            String readTxt = "";
            // 读取微信菜单
            while ((readTxt = bufferedReader.readLine()) != null) {
                System.out.println(readTxt);
                params += readTxt;
            }
            
            bufferedReader.close();
            reader.close();
            // 替换服务器地址、APPID
            params = params.replaceAll("server_url", wechat_base_url);
            params = params.replaceAll("appId", appId);
            // 请求微信接口创建菜单
            String jsonStr = HttpUtil.sendPost(url, params);
            return write(200, "创建成功!", "data", jsonStr);
        } catch (Exception e) {
            return error(-1, "创建失败");
        }
    }
    /**
     * 医生助手微信菜单创建

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

@ -83,6 +83,10 @@ wechat:
   template_physical_examination:  jTsvKU3iFw0yiJi5ESyFGDTmFSVcWlMot3yHier39Vc
   #处理结果通知
   template_deal_with:  VagkqFW_LFqLKE3gP2wmPtUfDWQOah40XMloipfi1do
    #设备绑定结果通知
   template_patient_bind_device: 1GWPw6LFcSuz2LFTo6LhE-YY8abtmcKRvor1fUzfxBE
    #积分到账通知
   template_healthbank_credit: A2L6WBm1p6bDPYGkGnUmoMvpWlRruP2lapYwHfLV7Rg
yihu:
  yihu_OpenPlatform_url: http://ssotest.yihu.cn/OpenPlatform/cgiBin/1.0/

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

@ -84,6 +84,10 @@ wechat:
    template_physical_examination:  tlsPJlgA90-I73j2QudyMG7C-LmrMn1lC4_UnJPyWSM
    #处理结果通知
    template_deal_with:  VagkqFW_LFqLKE3gP2wmPtUfDWQOah40XMloipfi1do
    #设备绑定结果通知
    template_patient_bind_device: 1GWPw6LFcSuz2LFTo6LhE-YY8abtmcKRvor1fUzfxBE
    #积分到账通知
    template_healthbank_credit: A2L6WBm1p6bDPYGkGnUmoMvpWlRruP2lapYwHfLV7Rg
yihu:

+ 8 - 0
patient-co/patient-co-wlyy/src/main/resources/application-prod.yml

@ -35,6 +35,9 @@ im:
#物联网配置
iot:
  url: http://192.168.131.24:8088/svr-iot/
#健康银行配置
healthBank:
  url: http://192.168.120.167:8661/svr-wlyy-health-bank/svr-health-bank/
#康复计划配置
rehabilitation:
@ -79,6 +82,11 @@ wechat:
   template_physical_examination:  jTsvKU3iFw0yiJi5ESyFGDTmFSVcWlMot3yHier39Vc
   #处理结果通知
   template_deal_with:  GyXCmXVYCD7PXi0IbHdPOD8apa-RQoSrSw-4-0pj9Go
   #设备绑定结果通知
   template_patient_bind_device: 1GWPw6LFcSuz2LFTo6LhE-YY8abtmcKRvor1fUzfxBE
   #积分到账通知
   template_healthbank_credit: A2L6WBm1p6bDPYGkGnUmoMvpWlRruP2lapYwHfLV7Rg
yihu:

+ 5 - 1
patient-co/patient-co-wlyy/src/main/resources/application-test.yml

@ -33,7 +33,7 @@ iot:
  url: http://172.19.103.33:8088/svr-iot/
#健康银行配置
healthBank:
  url: http://172.19.103.33:8660/svr-health-bank/
  url: http://172.19.103.33:8660/svr-wlyy-health-bank/svr-health-bank/
#康复计划配置
rehabilitation:
@ -78,6 +78,10 @@ wechat:
   template_physical_examination:  tlsPJlgA90-I73j2QudyMG7C-LmrMn1lC4_UnJPyWSM
   #处理结果通知
   template_deal_with:  VagkqFW_LFqLKE3gP2wmPtUfDWQOah40XMloipfi1do
   #设备绑定结果通知
   template_patient_bind_device: 1GWPw6LFcSuz2LFTo6LhE-YY8abtmcKRvor1fUzfxBE
   #积分到账通知
   template_healthbank_credit: A2L6WBm1p6bDPYGkGnUmoMvpWlRruP2lapYwHfLV7Rg
yihu:
  yihu_OpenPlatform_url: http://ssotest.yihu.cn/OpenPlatform/cgiBin/1.0/

+ 92 - 0
patient-co/patient-co-wlyy/src/main/resources/wechat/weixin_menu_haicang.txt

@ -0,0 +1,92 @@
{
"button":[
   {
	  "name":"家庭医生",
	  "sub_button":[
		  {
			"type":"view",
			"name":"签约管理",
			"url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fqygl%2fhtml%2fsigning_management.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
		  },
		  {
			"type":"view",
			"name":"医生咨询",
			"url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fyszx%2fhtml%2fdoctor-consultation.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
		  },
		  {
			"type":"view",
			"name":"医生指导",
			"url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fyszd%2fhtml%2fdoctor-guidance.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
		  },
		  {
            "type":"view",
            "name":"健教文库",
            "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fjkjy%2fhtml%2farticle_list.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
          }
	  ]
   },
   {
	  "name":"健康管理",
	  "sub_button":[
		 {
			  "type":"view",
			  "name":"预约挂号",
			  "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fwdyy%2fhtml%2fappointment-register.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
		 },
		 {
               "type":"view",
               "name":"健康记录",
               "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fjkjl%2fhtml%2fhealth-record.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
         },
		{
			"type":"click",
			"name":"健康档案",
			"key":"jiankangdangan"
		},
         {
            "type":"view",
            "name":"慢病管理",
            "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fjbsq%2fhtml%2fslow-disease-manage.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
                  },
        {
            "type":"click",
            "name":"妇幼保健",
            "key":"fuyoubaojian"
        }
	  ]
   },
   {
	  "name":"我的",
	  "sub_button":[
		{
           "type":"view",
           "name":"电子健康卡",
           "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fgrzx%2fhtml%2fmy-health-card.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
        },
		{
		   "type":"view",
		   "name":"我的资料",
		   "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fgrzx%2fhtml%2fmy-detail.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
		},
        {
           "type":"view",
           "name":"我的家庭",
           "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fjtgx%2fhtml%2ffamily.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
        },
		{
		   "type":"view",
		   "name":"我的设备",
		   "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fwdsb%2fhtml%2fmy-equipments.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
		},
		{
		   "type":"view",
		   "name":"健康银行",
		   "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fjkjf%2fhtml%2findex.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
		}
	 ]
  }],
    "matchrule":{
      "tag_id":"104"
      }
}