package com.fs.qw.controller;

import com.alibaba.fastjson.JSONObject;
import com.fs.common.core.domain.R;
import com.fs.common.utils.DateUtils;
import com.fs.common.utils.http.HttpUtils;
import com.fs.qw.config.SocketConfig;
import com.fs.qw.domain.*;
import com.fs.qw.dto.QwMessageDTO;
import com.fs.qw.dto.QwOnlineStatusDTO;
import com.fs.qw.event.*;
import com.fs.qw.service.*;
import com.fs.qw.service.impl.QwEventMessageServiceImpl;
import com.fs.qw.service.impl.QwMessageServiceImpl;
import com.fs.qw.utils.QwAllUtil;
import com.fs.qw.utils.QwDownloadUtil;
import com.fs.qw.vo.*;
import com.fs.qw.config.MsgBean;

import com.fs.system.oss.CloudStorageService;
import com.fs.system.oss.OSSFactory;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/qwEvent")
public class QwEventController {

    @Autowired
    private IQwUserService qwUserService;
    @Autowired
    private IQwEventAuthService qwEventAuthService;
    @Autowired
    private IQwAccountService qwAccountService;

    @Autowired
    private IQwEventMessageService eventMessageService;

    @Autowired
    private IQwContactService qwContactService;
    @Autowired
    private IQwLabelService qwLabelService;
    @Autowired
    private IQwRoomService qwRoomService;
    @Autowired
    private IQwRoomMemberService qwRoomMemberService;
    @Autowired
    private IQwMessageService qwMessageService;

//    @Autowired
//    WebSocketServer webSocketServer;

    Logger logger= LoggerFactory.getLogger(getClass());

    @PostMapping("/event/download")
    public R CDNDownLoad() throws Exception{
        String deviceId = "4eea1292408044beb49c02d3197871b0";
//        List<QwLabelVO> list = labelList(map,deviceId);
//        System.out.println(list);
        QwCDNDownload cdnDownload = new QwCDNDownload();
        cdnDownload.setFileId("30690201020462306002010002049674a89b02030f59b10204b616fa710204652e1e5a042433346439313937372d653261322d346535312d613462332d64356233373461663136613802010002030371500410caff6b67ef15aee6c89412b0002db3440201020201000400");
        cdnDownload.setAesKey("776a13ac1e0b773ac91b529b3865b4d1");
        cdnDownload.setFileSize(225616L);
        cdnDownload.setMd5("caff6b67ef15aee6c89412b0002db344");
        cdnDownload.setFileName(UUID.randomUUID().toString().replaceAll("-", "")+".jpg");
        cdnDownload.setFileType(2);
        Map<String,Object> map = cdnDownload.toMap();
        byte[] fileBytes = QwDownloadUtil.cdnDownload(map,deviceId);
        String suffix = cdnDownload.getFileName().substring(cdnDownload.getFileName().lastIndexOf("."));
        CloudStorageService storage = OSSFactory.build();
        String url = storage.uploadSuffix(fileBytes, suffix);
        System.out.println(url);
        return R.ok().put("url",url);
    }

    @PostMapping("/message/voice")
    public R sendMessageVoice(@RequestBody QwMessageDTO qwMessageDTO){
        return qwMessageService.sendMessageVoice(qwMessageDTO);
    }

    /**
     * 扫码状态变更通知
     */
    @PostMapping("/event/auth/qrcode")
    public R EventAuthqrcode(HttpServletRequest request,@RequestBody EventAuthqrcode authqrcode){
        String deviceId = request.getHeader("X-Device-Id");
        if(authqrcode.getStatus()==4){
//            MsgBean msgBean=new MsgBean();
//            msgBean.setCmd("verifyCode");
//            msgBean.setMsg(JSONObject.toJSONString(authqrcode));
//            webSocketServer.sendInfo("r:"+deviceId,JSONObject.toJSONString(msgBean));
            sendSocket("verifyCode",JSONObject.toJSONString(authqrcode),deviceId);
        }
        return qwEventAuthService.EventAuthqrcode(deviceId,authqrcode);
    }

    /**
     * 账号上线通知
     */
    @PostMapping("/event/auth/online")
    public R EventAuthOnline(HttpServletRequest request, @RequestBody QwUser qwUser){
        String deviceId = request.getHeader("X-Device-Id");
        qwUser.setDeviceId(deviceId);
        int count  = qwUserService.selectBangDingDeviceId(deviceId);
        //首次登录同步全部的联系人、标签、群聊
        if (count == 0){
            qwEventAuthService.EventAuthOnline(deviceId,qwUser);
        }else {
            qwEventAuthService.ContactChangedLogs(qwUser.getUserId(),deviceId);
        }

        QwOnline online = QwAllUtil.check(deviceId);
        QwOnlineStatusDTO qwOnlineStatusDTO = new QwOnlineStatusDTO();
        qwOnlineStatusDTO.setDeviceId(deviceId);
        qwOnlineStatusDTO.setOnlineTime(DateUtils.getNowDate());
        qwOnlineStatusDTO.setAuthCheck(online.getOnline());
        qwAccountService.updateAuthCheckByDeviceId(qwOnlineStatusDTO);
        sendSocket("loginSucc",JSONObject.toJSONString(qwUser),deviceId);
        return R.ok();
    }

    /**
     * 账号下线通知
     */
    @PostMapping("/event/auth/offline")
    public R EventAuthOffline(HttpServletRequest request, @RequestBody QwOnline qwOnline) throws IOException {
        String deviceId = request.getHeader("X-Device-Id");
        QwOnline online = QwAllUtil.check(deviceId);
        QwOnlineStatusDTO qwOnlineStatusDTO = new QwOnlineStatusDTO();
        qwOnlineStatusDTO.setDeviceId(deviceId);
        qwOnlineStatusDTO.setOfflineTime(DateUtils.getNowDate());
        qwOnlineStatusDTO.setAuthCheck(online.getOnline());
        if (qwOnline.getReason().equals("会话已过期")){
            qwOnlineStatusDTO.setOfflineType(1); //表示自动下线
        }else {
            qwOnlineStatusDTO.setOfflineType(0); //表示主动下线
        }
        qwAccountService.updateAuthCheckByDeviceId(qwOnlineStatusDTO);
        MsgBean msgBean=new MsgBean();
        msgBean.setCmd("offline");
        sendSocket("offline","",deviceId);
        return R.ok();
    }


    /**
     * 群组名称变更通知
     */
    @PostMapping("/event/room/nameChanged")
    public R roomNameChanged(HttpServletRequest request,@RequestBody EventRoomNameChanged roomChanged){
        String deviceId = request.getHeader("X-Device-Id");
        QwRoom qwRoom = qwRoomService.selectRoomByRoomId(roomChanged.getRoomId());
        if (qwRoom!=null &&(!qwRoom.getRoomName().equals(roomChanged.getRoomName()))){
            qwRoom.setRoomName(roomChanged.getRoomName());
            qwRoomService.updateQwRoom(qwRoom);
        }
        return R.ok();
    }

    /**
     * 群主转让通知
     */
    @PostMapping("/event/room/ownerChanged")
    public R roomOwnerChanged(HttpServletRequest request,@RequestBody EventRoomOwnerChanged roomOwnerChanged){
        String deviceId = request.getHeader("X-Device-Id");
        QwRoom qwRoom = qwRoomService.selectRoomByRoomId(roomOwnerChanged.getRoomId());
        if (qwRoom != null &&(!qwRoom.getOwnerId().equals(roomOwnerChanged.getOwnerId()))){
            qwRoom.setOwnerId(roomOwnerChanged.getOwnerId());
            qwRoomService.updateQwRoom(qwRoom);
        }
        return R.ok();
    }

    /**
     * 新增群组通知
     */
    @PostMapping("/event/room/created")
    public R roomCreated(HttpServletRequest request,@RequestBody EventRoomCreated roomCreated){
        String deviceId = request.getHeader("X-Device-Id");
        QwRoom qwRoom = qwRoomService.selectRoomByRoomId(roomCreated.getRoomId());
        if (qwRoom == null){
            QwRoom qwRoom1 = new QwRoom();
            BeanUtils.copyProperties(roomCreated,qwRoom1);
            List<QwRoomMember> roomMembers = roomCreated.getMemberList();
            for (QwRoomMember qwRoomMember:roomMembers){
                qwRoomMember.setRoomId(roomCreated.getRoomId());
                qwRoomMemberService.insertQwRoomMember(qwRoomMember);
            }
            qwRoomService.insertQwRoom(qwRoom1);
        }
        return R.ok();
    }
    @PostMapping("/event/room/exited")
    public R roomExited(HttpServletRequest request,@RequestBody EventRoomMemberUpdate roomMemberUpdate){
        QwRoom qwRoom = qwRoomService.selectRoomByRoomId(roomMemberUpdate.getRoomId());
        if (qwRoom!=null){
            QwRoomMember qwRoomMember1 = qwRoomMemberService.selectQwRoomMemberById(roomMemberUpdate.getUserId(),roomMemberUpdate.getRoomId());
            if (qwRoomMember1!=null){
                qwRoomMemberService.deleteQwRoomMemberById(roomMemberUpdate.getUserId(),roomMemberUpdate.getRoomId());
            }
        }
        return R.ok();
    }

    @PostMapping("/event/room/memberAdded")
    public R roomMemberAdded(HttpServletRequest request,@RequestBody EventRoomMemberUpdate roomMemberUpdate){
        QwRoom qwRoom = qwRoomService.selectRoomByRoomId(roomMemberUpdate.getRoomId());
        if (qwRoom!=null){
           List<QwRoomMember> qwRoomMembers = roomMemberUpdate.getUserList();
           for (QwRoomMember qwRoomMember : qwRoomMembers){
               QwRoomMember qwRoomMember1 = qwRoomMemberService.selectQwRoomMemberById(qwRoomMember.getUserId(),qwRoomMember.getRoomId());
               if (qwRoomMember1==null) {
                   qwRoomMember.setRoomId(roomMemberUpdate.getRoomId());
                   qwRoomMemberService.insertQwRoomMember(qwRoomMember);
               }
           }
        }
        return R.ok();
    }

    @PostMapping("/event/room/memberRemoved")
    public R roomMemberRemoved(HttpServletRequest request,@RequestBody EventRoomMemberRemoved roomMemberRemoved){
        QwRoom qwRoom = qwRoomService.selectRoomByRoomId(roomMemberRemoved.getRoomId());
        if (qwRoom!=null){
            List<Long> userList = roomMemberRemoved.getUserList();
            for (Long userId : userList){
                QwRoomMember qwRoomMember1 = qwRoomMemberService.selectQwRoomMemberById(userId,roomMemberRemoved.getRoomId());
                if (qwRoomMember1!=null) {
                    qwRoomMemberService.deleteQwRoomMemberById(userId,roomMemberRemoved.getRoomId());
                }
            }
        }
        return R.ok();
    }


    /**
     * 解散群通知
     */
    @PostMapping("/event/room/dismissed")
    public R roomDismissed(HttpServletRequest request, @RequestBody EventRoomDismissed roomDismissed){
        QwRoom qwRoom = qwRoomService.selectRoomByRoomId(roomDismissed.getRoomId());
        if (qwRoom!=null){
            qwRoomService.deleteQwRoomById(roomDismissed.getRoomId());
        }
        return R.ok();
    }

    /**
     * 联系人变更通知
     */
    @PostMapping("/event/contact/changed")
    public R EventContactChanged(HttpServletRequest request,@RequestBody EventContactChanged contactChanged){
        String deviceId = request.getHeader("X-Device-Id");
        return eventMessageService.contactChanged(deviceId,contactChanged);
    }

    /**
     *好友申请通知
     */
    @PostMapping("/event/contact/addFriend")
    public R EventContactAddFriend(HttpServletRequest request,@RequestBody EventContactAddFriend contactAddFriend){
        String deviceId = request.getHeader("X-Device-Id");
        System.out.println(contactAddFriend);
        return R.ok();
    }

    /**
     * 文本消息通知
     */
    @PostMapping("/event/message/text")
    public R EventMessageText(HttpServletRequest request,@RequestBody EventMessageText messageText){
        String deviceId = request.getHeader("X-Device-Id");
        R eventR=eventMessageService.EventMessageText(deviceId,messageText);
        System.out.println("QXJ EventMessageText:"+JSONObject.toJSONString(messageText));
        if(eventR.containsKey("QwMessage")){
            QwMessage qwMessage= (QwMessage) eventR.get("QwMessage");
            if (qwMessage.getId()!=null){
                QwMessageListVO listVO = new QwMessageListVO();
                listVO.setId(qwMessage.getId().toString());
                listVO.setToContactId(qwMessage.getConversationId());
                listVO.setType("text");
                listVO.setStatus("succeed");
                listVO.setContent(messageText.getContent());
                listVO.setSendTime(messageText.getSendTime()*1000);
                //获取fromUser
                QWFromUser fromUser=new QWFromUser();
                fromUser.setId(qwMessage.getSenderId());
                QwUser qwUser=qwUserService.selectQwUserById(qwMessage.getSenderId());
                if(qwUser!=null){
                    fromUser.setAvatar(qwUser.getAvatar());
                    fromUser.setDisplayName(qwUser.getNickName());
                }else{
                    QwContact qwContact=qwContactService.selectQwContactByUserId(qwMessage.getSenderId());
                    fromUser.setAvatar(qwContact.getAvatar());
                    fromUser.setDisplayName(qwContact.getNickName());
                }
                listVO.setFromUser(fromUser);
                sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
                qwUser=qwUserService.selectQwUserById(messageText.getReceiverId());
                if(qwUser!=null){  //如果qwUser不为空 发给接收人
                    deviceId=qwUser.getDeviceId();
                    sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
                }else{
                    sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
                }
            }
        }
        return eventR;
    }

    /**
     * 图片消息通知
     */
    @PostMapping("/event/message/image")
    public R EventMessageImage(HttpServletRequest request,@RequestBody EventMessageImage messageImage) throws IOException {
        String deviceId = request.getHeader("X-Device-Id");
        R eventR =  eventMessageService.EventMessageImage(deviceId,messageImage);
        if(eventR.containsKey("QwMessage")){
            QwMessage qwMessage= (QwMessage) eventR.get("QwMessage");
            if (qwMessage.getId()!=null){
                QwMessageListVO listVO = new QwMessageListVO();
                listVO.setId(qwMessage.getId().toString());
                listVO.setToContactId(qwMessage.getConversationId());
                listVO.setType("image");
                listVO.setStatus("succeed");
                listVO.setContent(qwMessage.getUrl());
                listVO.setSendTime(messageImage.getSendTime()*1000);
                //获取fromUser
                QWFromUser fromUser=new QWFromUser();
                fromUser.setId(qwMessage.getSenderId());
                QwUser qwUser=qwUserService.selectQwUserById(qwMessage.getSenderId());
                if(qwUser!=null){
                    fromUser.setAvatar(qwUser.getAvatar());
                    fromUser.setDisplayName(qwUser.getNickName());
                }else{
                    QwContact qwContact=qwContactService.selectQwContactByUserId(qwMessage.getSenderId());
                    fromUser.setAvatar(qwContact.getAvatar());
                    fromUser.setDisplayName(qwContact.getNickName());
                }
                listVO.setFromUser(fromUser);
                sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
                qwUser=qwUserService.selectQwUserById(messageImage.getReceiverId());
                if(qwUser!=null){
                    deviceId=qwUser.getDeviceId();
                    sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
                }
            }
        }
        return eventR;
    }

    /**
     * 视频消息通知
     */
    @PostMapping("/event/message/video")
    public R EventMessageVideo(HttpServletRequest request,@RequestBody EventMessageVideo messageVideo){
        String deviceId = request.getHeader("X-Device-Id");
        R eventR =  eventMessageService.EventMessageVideo(deviceId,messageVideo);
        if(eventR.containsKey("QwMessage")){
            QwMessage qwMessage= (QwMessage) eventR.get("QwMessage");
            if (qwMessage.getId()!=null){
                QwMessageListVO listVO = new QwMessageListVO();
                listVO.setId(qwMessage.getId().toString());
                listVO.setToContactId(qwMessage.getConversationId());
                listVO.setType("video");
                listVO.setStatus("succeed");
                listVO.setContent(qwMessage.getUrl());
                listVO.setImageUrl(qwMessage.getImageUrl());
                listVO.setSendTime(messageVideo.getSendTime()*1000);
                //获取fromUser
                QWFromUser fromUser=new QWFromUser();
                fromUser.setId(qwMessage.getSenderId());
                QwUser qwUser=qwUserService.selectQwUserById(qwMessage.getSenderId());
                if(qwUser!=null){
                    fromUser.setAvatar(qwUser.getAvatar());
                    fromUser.setDisplayName(qwUser.getNickName());
                }else{
                    QwContact qwContact=qwContactService.selectQwContactByUserId(qwMessage.getSenderId());
                    fromUser.setAvatar(qwContact.getAvatar());
                    fromUser.setDisplayName(qwContact.getNickName());
                }
                listVO.setFromUser(fromUser);
                sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
                qwUser=qwUserService.selectQwUserById(messageVideo.getReceiverId());
                if(qwUser!=null){
                    deviceId=qwUser.getDeviceId();
                    sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
                }
            }
        }
        return eventR;
    }

    /**
     * 语音消息通知
     */
    @PostMapping("/event/message/voice")
    public R EventMessageVoice(HttpServletRequest request,@RequestBody EventMessageVoice messageVoice){
        String deviceId = request.getHeader("X-Device-Id");
        R eventR =  eventMessageService.EventMessageVoice(deviceId,messageVoice);
        if(eventR.containsKey("QwMessage")){
            QwMessage qwMessage= (QwMessage) eventR.get("QwMessage");
            if (qwMessage.getId()!=null){
                QwMessageListVO listVO = new QwMessageListVO();
                listVO.setId(qwMessage.getId().toString());
                listVO.setToContactId(qwMessage.getConversationId());
                listVO.setType("voice");
                listVO.setStatus("succeed");
                listVO.setContent(qwMessage.getUrl());
                listVO.setDuration(qwMessage.getDuration());
                listVO.setSendTime(messageVoice.getSendTime()*1000);
                //获取fromUser
                QWFromUser fromUser=new QWFromUser();
                fromUser.setId(qwMessage.getSenderId());
                QwUser qwUser=qwUserService.selectQwUserById(qwMessage.getSenderId());
                if(qwUser!=null){
                    fromUser.setAvatar(qwUser.getAvatar());
                    fromUser.setDisplayName(qwUser.getNickName());
                }else{
                    QwContact qwContact=qwContactService.selectQwContactByUserId(qwMessage.getSenderId());
                    fromUser.setAvatar(qwContact.getAvatar());
                    fromUser.setDisplayName(qwContact.getNickName());
                }
                listVO.setFromUser(fromUser);
                sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
                qwUser=qwUserService.selectQwUserById(messageVoice.getReceiverId());
                if(qwUser!=null){
                    deviceId=qwUser.getDeviceId();
                    sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
                }
            }
        }
        return eventR;
    }

    /**
     * 文件消息通知
     */
    @PostMapping("/event/message/file")
    public R EventMessageFile(HttpServletRequest request,@RequestBody EventMessageFile messageFile) {
        String deviceId = request.getHeader("X-Device-Id");
        R eventR =  eventMessageService.EventMessageFile(deviceId,messageFile);
        if(eventR.containsKey("QwMessage")){
            QwMessage qwMessage= (QwMessage) eventR.get("QwMessage");
            if (qwMessage.getId()!=null){
                QwMessageListVO listVO = new QwMessageListVO();
                listVO.setId(qwMessage.getId().toString());
                listVO.setToContactId(qwMessage.getConversationId());
                listVO.setType("file");
                listVO.setStatus("succeed");
                listVO.setContent(qwMessage.getUrl());
                listVO.setFileShowType(qwMessage.getFileShowType());
                listVO.setFileName(qwMessage.getFileName());
                listVO.setFileSize(qwMessage.getFileSize());
                listVO.setSendTime(messageFile.getSendTime()*1000);
                //获取fromUser
                QWFromUser fromUser=new QWFromUser();
                fromUser.setId(qwMessage.getSenderId());
                QwUser qwUser=qwUserService.selectQwUserById(qwMessage.getSenderId());
                if(qwUser!=null){
                    fromUser.setAvatar(qwUser.getAvatar());
                    fromUser.setDisplayName(qwUser.getNickName());
                }else{
                    QwContact qwContact=qwContactService.selectQwContactByUserId(qwMessage.getSenderId());
                    fromUser.setAvatar(qwContact.getAvatar());
                    fromUser.setDisplayName(qwContact.getNickName());
                }
                listVO.setFromUser(fromUser);
                sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
                qwUser=qwUserService.selectQwUserById(messageFile.getReceiverId());
                if(qwUser!=null){
                    deviceId=qwUser.getDeviceId();
                    sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
                }
            }
        }
        return eventR;
    }


    /**
     * 小程序消息通知
     */
    @PostMapping("/event/message/app")
    public R EventMessageApp(@RequestBody EventMessageApp messageApp){
        System.out.println(messageApp);
        return R.ok();
    }

    /**
     * 表情消息通知
     */
    @PostMapping("/event/message/emoji")
    public R EventMessageEmoji(HttpServletRequest request,@RequestBody EventMessageEmoji messageEmoji){
        String deviceId = request.getHeader("X-Device-Id");
        R eventR = eventMessageService.EventMessageEmoji(deviceId,messageEmoji);
        if(eventR.containsKey("QwMessage")){
            QwMessage qwMessage= (QwMessage) eventR.get("QwMessage");
            QwMessageListVO listVO = new QwMessageListVO();
            listVO.setId(qwMessage.getId().toString());
            listVO.setToContactId(qwMessage.getConversationId());
            listVO.setType("image");
            listVO.setStatus("succeed");
            listVO.setContent(qwMessage.getUrl());
            listVO.setSendTime(messageEmoji.getSendTime()*1000);
            //获取fromUser
            QWFromUser fromUser=new QWFromUser();
            fromUser.setId(qwMessage.getSenderId());
            QwUser qwUser=qwUserService.selectQwUserById(qwMessage.getSenderId());
            if(qwUser!=null){
                fromUser.setAvatar(qwUser.getAvatar());
                fromUser.setDisplayName(qwUser.getNickName());
            }else{
                QwContact qwContact=qwContactService.selectQwContactByUserId(qwMessage.getSenderId());
                fromUser.setAvatar(qwContact.getAvatar());
                fromUser.setDisplayName(qwContact.getNickName());
            }
            listVO.setFromUser(fromUser);
            qwUser=qwUserService.selectQwUserById(messageEmoji.getReceiverId());
            if(qwUser!=null){
                deviceId=qwUser.getDeviceId();
                sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
            }
            listVO.setFromUser(fromUser);
            sendSocket("receiveMsg",JSONObject.toJSONString(listVO),deviceId);
        }
        return eventR;
    }

    /**
     * 链接消息通知
     */
    @PostMapping("/event/message/link")
    public R EventMessageLink(@RequestBody EventMessageLink messageLink){
        System.out.println(messageLink);
        return R.ok();
    }

    /**
     * 消息撤回通知
     */
    @PostMapping("/event/message/revoked")
    public R EventMessageRevoked(@RequestBody EventMessageRevoked messageRevoked){
        System.out.println(messageRevoked);
        return R.ok();
    }

    @Autowired
    private SocketConfig socketConfig;

    public void sendSocket(String cmd,String messageText,String deviceId){
        MsgBean msgBean=new MsgBean();
        msgBean.setCmd(cmd);
        msgBean.setMsg(messageText);
        JSONObject params=new JSONObject();
        params.put("id","r:"+deviceId);
        params.put("message",JSONObject.toJSONString(msgBean));
        String url = socketConfig.getSocketUrl();
//      HttpUtils.doPost("http://localhost:7018/sendInfo",JSONObject.toJSONString(params));
        HttpUtils.doPost(url,JSONObject.toJSONString(params));
    }


}
