瀏覽代碼

绑定设备

zd_123 7 年之前
父節點
當前提交
5ed5968f90

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

@ -21,5 +21,5 @@ 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 updateAfterBinding(long adminTeam, String hospital, String isFirstBinding, Date grantTime,String deviceSn);
}

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

@ -27,10 +27,14 @@ public class WlyyDeviceDetailService extends BaseService {
	@Autowired
	private SignFamilyDao signFamilyDao;
	public DeviceDetail findBySn(String sn){
		return  wlyyDeviceDetailDao.findByDeviceSn(sn);
	}
	public void updateAfterBinding(String deviceSn, String idCard, String userType, Date grantTime)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";
@ -38,7 +42,7 @@ public class WlyyDeviceDetailService extends BaseService {
			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){

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

@ -109,11 +109,14 @@ public class DoctorDeviceController extends BaseController {
			//修改设备表中是否是首绑{"1":"1", "2":"1"}修改成{"1":"0", "2":"0"} 和其他绑定信息,
			wlyyDeviceDetailService.updateAfterBinding(device.getDeviceSn(),device.getUserIdcard(),device.getUserType(),new Date());
			//调用增加积分接口
			System.out.println("是否首次====="+flag);
			if (flag){
				Patient patient = patientService.findByCode(device.getUser());
				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);
				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");
@ -122,9 +125,9 @@ public class DoctorDeviceController extends BaseController {
                        String flagType = String.valueOf(list.get(0).get("flag"));
                        
                        //@TODO 调用发送微信模板接口
	                    Patient people = patientDao.findByCode(device.getUser());
	                    String openId = people.getOpenid();
	                    String name = people.getName();
	                    //Patient people = patientDao.findByCode(device.getUser());
	                    String openId = patient.getOpenid();
	                    String name = patient.getName();
	                    org.json.JSONObject sendJson = new org.json.JSONObject();
	                    String first = "";

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

@ -1,14 +1,23 @@
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.HttpClientUtil;
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;
@ -23,6 +32,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;
@ -47,6 +57,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 +208,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 +217,65 @@ public class PatientDeviceController extends BaseController {
            synchronized (sn.intern()){
                patientDeviceService.saveDevice(device);
            }
            //判断是否为积分设备
            DeviceDetail deviceDetail = wlyyDeviceDetailService.findBySn(device.getDeviceSn());
            if (deviceDetail!=null){
                //修改设备表中是否是首绑{"1":"1", "2":"1"}修改成{"1":"0", "2":"0"} 和其他绑定信息,
                wlyyDeviceDetailService.updateAfterBinding(device.getDeviceSn(),device.getUserIdcard(),device.getUserType(),new Date());
                if (flag){
                    Patient patient = patientService.findByCode(device.getUser());
                    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());
	                        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();
	                        String keyword1 = templateConfig.getKeyword1();
	                        sendJson.put("keyword1", keyword1);
	                        sendJson.put("keyword2", device.getCzrq());
	                        sendJson.put("first", first);
	                        sendJson.put("remark", remark);
	                        sendJson.put("url", templateConfig.getUrl());//带参数的模板跳转链接
	                        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);
//		                        }
//	                        }
                        }
                    }
                }
            }
            return success("设备保存成功!");
        } catch (Exception ex) {