ソースを参照

Merge branch 'dev' of zd_123/patient-co-management into dev

trick9191 7 年 前
コミット
1ed9e029f7

+ 19 - 25
common/common-entity/src/main/java/com/yihu/wlyy/entity/device/DeviceDetail.java

@ -31,19 +31,20 @@ public class DeviceDetail extends IdEntity{
    private String applicantMail;
    private Integer isGrant;
    private String grantAdminTeam;
    private String grantOrgCode;
    private Integer isBinding;
    private String grantHospital;
    private String bindingCount;
    private Date grantTime;
    private String deviceActivityType;
    /** default constructor */
    public DeviceDetail() {
    }
    /** full constructor */
    public DeviceDetail(String deviceName, String deviceModel, String deviceCode, String manufacturer, String applyDate, String orgName, String linkman, String tel, String serverIp, String manufacturerCode, String address, String representative, String applicantName, String applicantIdentity, String applicantTel, String applicantMail, Integer isGrant, String grantAdminTeam, String grantOrgCode, Integer isBinding, String bindingCount, Date grantTime) {
    public DeviceDetail(String deviceName, String deviceModel, String deviceCode, String manufacturer, String applyDate
            , String orgName, String linkman, String tel, String serverIp, String manufacturerCode, String address
            , String representative, String applicantName, String applicantIdentity, String applicantTel, String applicantMail) {
        this.deviceName = deviceName;
        this.deviceModel = deviceModel;
        this.deviceCode = deviceCode;
@ -60,15 +61,8 @@ public class DeviceDetail extends IdEntity{
        this.applicantIdentity = applicantIdentity;
        this.applicantTel = applicantTel;
        this.applicantMail = applicantMail;
        this.isGrant = isGrant;
        this.grantAdminTeam = grantAdminTeam;
        this.grantOrgCode = grantOrgCode;
        this.isBinding = isBinding;
        this.bindingCount = bindingCount;
        this.grantTime = grantTime;
    }
    @Column(name = "device_name")
    public String getDeviceName() {
        return deviceName;
@ -231,22 +225,13 @@ public class DeviceDetail extends IdEntity{
        this.grantAdminTeam = grantAdminTeam;
    }
    @Column(name = "grant_org_code")
    public String getGrantOrgCode() {
        return grantOrgCode;
    }
    public void setGrantOrgCode(String grantOrgCode) {
        this.grantOrgCode = grantOrgCode;
    }
    @Column(name = "is_binding")
    public Integer getIsBinding() {
        return isBinding;
    @Column(name = "grant_hospital")
    public String getGrantHospital() {
        return grantHospital;
    }
    public void setIsBinding(Integer isBinding) {
        this.isBinding = isBinding;
    public void setGrantHospital(String grantHospital) {
        this.grantHospital = grantHospital;
    }
    @Column(name = "binding_count")
@ -266,4 +251,13 @@ public class DeviceDetail extends IdEntity{
    public void setGrantTime(Date grantTime) {
        this.grantTime = grantTime;
    }
    @Column(name = "device_activity_type")
    public String getDeviceActivityType() {
        return deviceActivityType;
    }
    public void setDeviceActivityType(String deviceActivityType) {
        this.deviceActivityType = deviceActivityType;
    }
}

+ 72 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/device/DeviceWxMessage.java

@ -0,0 +1,72 @@
package com.yihu.wlyy.entity.device;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by zd on 2018/01/10.
 */
@Entity
@Table(name = "wlyy_device_wx_message")
public class DeviceWxMessage extends IdEntity{
    private String patient;
    private String deviceName;
    private String deviceSn;
    private Date czrq;
    /** default constructor */
    public DeviceWxMessage() {
    }
    /** full constructor */
    public DeviceWxMessage(String patient, String deviceName, String deviceSn, Date czrq) {
        this.patient = patient;
        this.deviceName = deviceName;
        this.deviceSn = deviceSn;
        this.czrq = czrq;
    }
    @Column(name = "device_name")
    public String getDeviceName() {
        return deviceName;
    }
    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }
    @Column(name = "device_sn")
    public String getDeviceSn() {
        return deviceSn;
    }
    public void setDeviceSn(String deviceSn) {
        this.deviceSn = deviceSn;
    }
    @Column(name = "patient")
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    @Column(name = "czrq")
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 1 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/message/Message.java

@ -35,6 +35,7 @@ public class Message extends IdEntity {
	 *  113入群消息、114群解散消息、115踢出群消息、116新的网络咨询、117网络咨询追问、
	 *  201医生拒绝签约、202医生同意签约、203医生申请取消签约、204医生同意取消签约、205医生拒绝取消签约、206新的问卷随访、207新的健康干预、
	 *  208请求添加好友消息、209入群消息、210群解散消息、211踢出群消息、212聊天消息提醒、213群聊天消息、214医生回复了网络咨询、215请求添加为家人)
	 *	301解绑消息
	 */
	private Integer type;
	private Integer platform;// 消息平台,1微信端/患者端,2医生APP端

+ 3 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/message/MessageDao.java

@ -120,4 +120,7 @@ public interface MessageDao extends PagingAndSortingRepository<Message, Long>, J
    @Modifying
    @Query("delete from Message a   where a.receiver = ?1 and a.data = ?2 and a.type in (14,15) ")
    int setMessageDel(String doctor, String articleCode);
    @Query(" select a from Message a where a.type=?2 and a.del='1' and a.read=1 and a.receiver=?1 and a.over='1' order by a.createTime desc ")
    List<Message> findUnReadByReceiverAndType(String receiver,Integer type);
}

+ 12 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/DeviceWxMessageDao.java

@ -0,0 +1,12 @@
package com.yihu.wlyy.repository.patient;
import com.yihu.wlyy.entity.device.DeviceWxMessage;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface DeviceWxMessageDao extends PagingAndSortingRepository<DeviceWxMessage, Long>, JpaSpecificationExecutor<DeviceWxMessage> {
}

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

@ -0,0 +1,29 @@
package com.yihu.wlyy.service.app.device;
import com.yihu.wlyy.repository.patient.DeviceWxMessageDao;
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.utils.Clock;
@Component
@Transactional(rollbackFor = Exception.class)
public class DeviceWxMessageService extends BaseService {
    private Clock clock = Clock.DEFAULT;
    @Autowired
    private DeviceWxMessageDao deviceWxMessageDao;
    @Autowired
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
}

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

@ -64,7 +64,7 @@ public class PatientDeviceLogService extends BaseService {
        patientDeviceLogDao.save(patientDeviceLog);
    }
    public Map<String,Object> getDevicesList(String noGaugeDay,String isBinding,String categoryCode,int pageNo,int pageSize){
    public Map<String,Object> getDevicesList(String noGaugeDay,String isBinding,String categoryCode,String isSend,int pageNo,int pageSize){
        List<Map<String,Object>> resultList =  new ArrayList<>();
        Map<String,Object> resultMap = new HashedMap();
        int start = (pageNo-1)*pageSize;
@ -73,7 +73,6 @@ public class PatientDeviceLogService extends BaseService {
                "  LEFT JOIN wlyy_sign_family sf ON pd.patient = sf.patient" +
                "  WHERE" +
                "   pd.is_del = 1" +
                "  AND sf.`status` > 0" +
                "  ORDER BY" +
                "  create_time DESC) a" +
                " GROUP BY a.device_sn) b" +
@ -104,7 +103,12 @@ public class PatientDeviceLogService extends BaseService {
        if (!StringUtils.isEmpty(noGaugeDay) && StringUtils.equals("4",noGaugeDay)){
            sql += " and b.patient NOT IN (SELECT user FROM device.wlyy_patient_health_index WHERE  DATE_SUB(CURDATE(), INTERVAL 1 MONTH) > DATE(record_date))";
        }
        //发送消息要筛选未发送消息的设备
        if (StringUtils.isNotEmpty(isSend)){
            sql += " and b.device_sn NOT IN (SELECT device_sn FROM wlyy_device_wx_message WHERE TO_DAYS(czrq) = TO_DAYS(NOW()))";
        }
        sql += " limit ?,?";
        resultList = jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
        resultMap.put("data",resultList);
        return resultMap;

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

@ -1123,17 +1123,17 @@ public class PatientDeviceService extends BaseService {
        }
        return name;
    }
    
    /**
     * 根据病种类型,搜索已绑定设备的居民设备SN码
     * @param type 1高血压 2糖尿病
     */
    public com.alibaba.fastjson.JSONObject iotSearchPatientDeviceSN(String type,Integer page,Integer pageSize){
    
        if(page != 0){
            page = page - 1;
        }
        
        StringBuffer sql = new StringBuffer("select t.device_sn from");
        sql.append("  ( SELECT DISTINCT d.* FROM wlyy_patient_device d, wlyy_sign_family f WHERE f.`status` > 0 AND f.patient = d.`user` ) t, ");
        sql.append("    wlyy_patient p " );
@ -1141,18 +1141,18 @@ public class PatientDeviceService extends BaseService {
        sql.append("   and l.`status`=1 AND l.label_type = 3 and l.label='"+type+"'");
        sql.append(" WHERE t.user = p. CODE limit "+page+","+pageSize);
        List<String> list = jdbcTemplate.queryForList(sql.toString(),String.class);
        
        Integer count = 0;
    
        StringBuffer countsql = new StringBuffer("select count(t.device_sn) total from");
        countsql.append("  ( SELECT DISTINCT d.* FROM wlyy_patient_device d, wlyy_sign_family f WHERE f.`status` > 0 AND f.patient = d.`user` ) t, ");
        countsql.append("    wlyy_patient p " );
        countsql.append("  LEFT JOIN wlyy_sign_patient_label_info l on  p. CODE = l.patient");
        countsql.append("   and l.`status`=1 AND l.label_type = 3 and l.label='"+type+"'");
        countsql.append(" WHERE t.user = p. CODE ");
    
        count = jdbcTemplate.queryForObject(countsql.toString(),Integer.class);
    
        com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
        result.put("total",count);
        result.put("list",list);

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

@ -206,6 +206,20 @@ public class MessageService extends BaseService {
            articleMesJson.put("amount", 0);
        }
        //解绑设备消息
        List<Message> deviceUnbindList = messageDao.findUnReadByReceiverAndType(doctor,301);
        JSONObject deviceMesJson = new JSONObject();
        if (deviceUnbindList != null && deviceUnbindList.size() > 0) {
            articleMesJson.put("amount", deviceUnbindList.size());
            JSONObject deviceJson = new JSONObject();
            deviceJson.put("title", "解绑消息");
            deviceJson.put("type", 301);
            deviceJson.put("msg", "你有"+deviceUnbindList.size()+"个居民解绑设备消息");
            deviceJson.put("msgTime", DateUtil.dateToStrLong(deviceUnbindList.get(0).getCreateTime()));
            deviceMesJson.put("lastMessage", deviceJson);
        }else{
            deviceMesJson.put("amount", 0);
        }
        JSONObject json = new JSONObject();
        json.put("imMsgCount", getImMsgAmount(doctor));//IM消息数量
@ -215,6 +229,7 @@ public class MessageService extends BaseService {
        json.put("prescription", prescriptionJson);//续方消息
        json.put("callService", callServiceMesJson);//协同服务消息
        json.put("articleCheck", articleMesJson);//健康文章审核消息
        json.put("deviceUnbind",deviceMesJson);//设备解绑消息
        return json;
    }
@ -665,4 +680,14 @@ public class MessageService extends BaseService {
            return false;
        }
    }
    public List<Map<String,Object>> getDevcieMessageByDoctorAndRead(String doctor,int read,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 ?,?";
        List<Map<String,Object>> messagelist = jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
        return messagelist;
    }
}

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

@ -3,6 +3,7 @@ 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.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
@ -30,11 +31,18 @@ import org.json.JSONArray;
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;
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 javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -52,16 +60,12 @@ public class DoctorDeviceController extends BaseController {
	@Autowired
	private PatientDeviceService patientDeviceService;
	@Autowired
	private DeviceDetailService deviceDetailService;
	@Autowired
	private AdminTeamService adminTeamService;
	@Autowired
	private CreditLogService creditLogService;
	@Autowired
	private WechatTemplateConfigDao templateConfigDao;
	@Autowired
@ -77,6 +81,11 @@ public class DoctorDeviceController extends BaseController {
	@Autowired
	private CommonUtil commonUtil;
	@Autowired
	private JmsTemplate jmsTemplate;
	@Value("${activemq.queue.deviceMeasurementRemindingQueue}")
	private String channelName;
	private ObjectMapper  objectMapper=new ObjectMapper();
	@ApiOperation("设备保存接口--医生端")
@ -104,8 +113,8 @@ public class DoctorDeviceController extends BaseController {
	@RequestMapping(value = "SavePatientDeviceAndCredit",method = RequestMethod.POST)
	@ResponseBody
	@ObserverRequired
	public String SavePatientDeviceAndCredit(@ApiParam(name="data",value="设备数据json",defaultValue = "{\"user\":\"915cca0a-5b1d-11e6-834 4-fa163e8aee56\",\"deviceId\": \"3\",\"deviceName\": \"血压计-优瑞恩\",\"deviceSn\": \"16C000337\",\"categoryCode\": \"1\",\"userType\": \"-1\",\"agreementPhoto\":\"www.baidu.com\"}")
							 @RequestParam(value="data",required = true) String data) {
	public String SavePatientDeviceAndCredit(@ApiParam(name="data",value="设备数据json",defaultValue = "{\"user\":\"915cca0a-5b1d-11e6-834 4-fa163e8aee56\",\"deviceId\": \"3\",\"deviceName\": \"血压计-优瑞恩\",\"deviceSn\": \"16C000337\",\"categoryCode\": \"1\",\"userType\": \"-1\"}") @RequestParam(value="data",required = true) String data,
											 @ApiParam(name = "agreementPhoto",value = "协议图片临时路径")@RequestParam(value = "agreementPhoto",required = true)String agreementPhoto) {
		try {
			PatientDevice device = objectMapper.readValue(data,PatientDevice.class);
			// 设置操作医生标识
@ -114,8 +123,8 @@ public class DoctorDeviceController extends BaseController {
			if (doctor!=null){
				device.setDoctorName(doctor.getName());
			}
			if (StringUtils.isNotEmpty(device.getAgreementPhoto())){
				device.setAgreementPhoto(commonUtil.copyTempImage(device.getAgreementPhoto()));
			if (StringUtils.isNotEmpty(agreementPhoto)){
				device.setAgreementPhoto(commonUtil.copyTempImage(agreementPhoto));
			}
			//首绑和设备类型判断  判断是否可以增加积分
			Map<String,Object> checkMap = patientDeviceService.checkBindingFirstAndType(device);
@ -400,9 +409,10 @@ public class DoctorDeviceController extends BaseController {
	@RequestMapping(value = "/getDevicesList",method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "医生端-设备管理中设备列表",notes = "设备列表")
	public String getDevicesList(@ApiParam(value = "未测量天数(1今日为测量 2七天未测量 3本月未测量 4超过一个月未测量)", name = "noGaugeDay") @RequestParam(value = "noGaugeDay",required = false)String noGaugeDay,
								 @ApiParam(value = "是否绑定(1绑定 2解绑)", name = "isBinding") @RequestParam(value = "isBinding",required = false)String isBinding,
								 @ApiParam(value = "设备类型(1血糖仪 2血压计)", name = "categoryCode") @RequestParam(value = "categoryCode",required = false)String categoryCode,
	public String getDevicesList(@ApiParam(value = "未测量天数(1今日为测量 2七天未测量 3本月未测量 4超过一个月未测量)", name = "noGaugeDay") @RequestParam(value = "noGaugeDay",required = true)String noGaugeDay,
								 @ApiParam(value = "是否绑定(1绑定 2解绑)", name = "isBinding") @RequestParam(value = "isBinding",required = true)String isBinding,
								 @ApiParam(value = "设备类型(1血糖仪 2血压计)", name = "categoryCode") @RequestParam(value = "categoryCode",required = true)String categoryCode,
								 @ApiParam(value = "今日是否发送消息(1未发送 2已发送)", name = "isSend") @RequestParam(value = "isSend",required = true)String isSend,
								 @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)) {
@ -412,10 +422,33 @@ public class DoctorDeviceController extends BaseController {
			page = "1";
		}
		try {
			return  write(200,"查找成功!","data",patientDeviceLogService.getDevicesList(noGaugeDay,isBinding,categoryCode,Integer.valueOf(page),Integer.valueOf(pageSize)));
			return  write(200,"查找成功!","data",patientDeviceLogService.getDevicesList(noGaugeDay,isBinding,categoryCode,isSend,Integer.valueOf(page),Integer.valueOf(pageSize)));
		} catch (Exception e) {
			error(e);
			return error( -1, "查询失败!");
		}
	}
	@RequestMapping(value = "/sendDeviceWxMessage",method = RequestMethod.POST)
	@ApiOperation("给没有测量的居民发送微信消息提醒")
	@ResponseBody
	public String sendDevcieWxMessage(){
		return "";
	}
	public void sender(List<DeviceWxMessage> deviceWxMessageList){
		//发送到队列
		deviceWxMessageList.stream().forEach(one->{
			jmsTemplate.send(channelName, new MessageCreator() {
				@Override
				public Message createMessage(Session session) throws JMSException {
					TextMessage textMessage = session.createTextMessage();
					textMessage.setText(net.sf.json.JSONObject.fromObject(one).toString());
					return textMessage;
				}
			});
		});
	}
}

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

@ -13,6 +13,7 @@ import com.yihu.wlyy.web.BaseController;
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.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -452,4 +453,23 @@ public class DoctorMessageController extends BaseController {
            return invalidUserException(ex, -1, ex.getMessage());
        }
    }
    @RequestMapping(value = "deviceMessageDetailList",method = RequestMethod.GET)
    @ApiOperation("解绑消息详情列表")
    @ResponseBody
    public String deviceMessageDetailList(@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)) {
            pageSize = "10";
        }
        if (page.equals("0")) {
            page = "1";
        }
        try {
           return write(200,"查询成功!","data",messageService.getDevcieMessageByDoctorAndRead(getUID(),1,Integer.valueOf(pageSize),Integer.valueOf(page)));
        }catch (Exception e){
            error(e);
            return error( -1, "查询失败!");
        }
    }
}

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

@ -4,10 +4,14 @@ 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;
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.deviece.PatientHealthTimeDao;
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.PatientDeviceLogService;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
@ -17,7 +21,6 @@ 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.wechat.util.WeiXinAccessTokenUtils;
import io.swagger.annotations.Api;
@ -36,10 +39,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;
import java.util.*;
/**
 * 患者端:设备管理控制类
@ -74,6 +74,10 @@ public class PatientDeviceController extends BaseController {
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    @Autowired
    private PatientDeviceLogService patientDeviceLogService;
    @Autowired
    private MessageDao messageDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Value("${yihu.yihu_OpenPlatform_url}")
    private String url;
@ -217,7 +221,7 @@ public class PatientDeviceController extends BaseController {
            Map<String,Object> checkMap = patientDeviceService.checkBindingFirstAndType(device);
            boolean flag = (Boolean)checkMap.get("flag");
            Patient patient = patientService.findByCode(device.getUser());
            Patient patient = patientService.findByCode(getRepUID());
            if(!getUID().equals(getRepUID())&&device.getId()==null){
                device.setAgent(getRepUID());
                device.setAgentName(patient.getName());
@ -378,6 +382,36 @@ public class PatientDeviceController extends BaseController {
                // 删除设备
                patientDeviceService.deleteDevice(id, getRepUID());
//                patientDeviceService.deleteDevice(id, getUID());
                //全部解绑后去判断就更新设备表中是否绑定字段
                deviceDetailService.unBindUpdateIsBinding(pd.getDeviceSn());
                patientDeviceLogService.savePatientDeviceLog(pd,pd.getDeviceSn(),2,2);
                //居民自主解绑设备时发送消息给医生
                Patient patient = patientService.findByCode(getRepUID());
                SignFamily signFamily = signFamilyDao.findByPatient(patient.getCode());
                String messageContent =  "您的居民"+patient.getName()+"解绑了";
                if ("1".equals(pd.getCategoryCode())){
                    messageContent +="血糖仪,点击下方查看居民详情";
                }else if ("2".equals(pd.getCategoryCode())){
                    messageContent +="血压计,点击下方查看居民详情";
                }
                Message message = new Message();
                message.setCzrq(new Date());
                message.setCreateTime(new Date());
                message.setContent(messageContent);
                message.setRead(1);//设置未读
                message.setReceiver(signFamily.getDoctor());//设置接受医生的code
                message.setSender("admin");//设置发送的用户
                message.setSenderName("系统");
                message.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
                message.setSenderPhoto("");
                message.setTitle("解绑设备消息");
                message.setType(301);//解绑设备消息
                message.setReadonly(1);//是否只读消息
                message.setSex(1);
                message.setOver("1");//未处理
                message.setData("");
                message.setDel("1");
                messageDao.save(message);
                return success("设备已删除!");
            } else {
                return error(-1, "不存在该设备!");