Esempio n. 1
0
def test():
    status = ErrorCode.SUCCESS
    
    seq = str(int(time.time()*1000))[-4:]
    args = DotDict(seq=seq,
                   tid='jiabind')
    response = GFSenderHelper.forward(GFSenderHelper.URLS.UNBIND, args)
    response = json_decode(response)
    print 'response', response 
    if response['success'] == ErrorCode.SUCCESS:
        logging.info("[ADMIN] Umobile: %s, tid: %s, tmobile:%s GPRS unbind successfully",
                    pmobile, terminal.tid, tmobile)
    else:
        status = response['success']
    print 'status', status
Esempio n. 2
0
    def post(self):
        status = ErrorCode.SUCCESS
        try:
            data = DotDict(json_decode(self.request.body))
            logging.info("[UWEB] batch delete request: %s, corp_id: %s",
                         data, self.current_user.cid)
        except Exception as e:
            status = ErrorCode.ILLEGAL_DATA_FORMAT
            logging.exception("[UWEB] Invalid data format. Exception: %s",
                              e.args)
            self.write_ret(status)
            return

        try:
            status = ErrorCode.SUCCESS
            tids = list(data.tids)
            flag = data.flag
            res = []
            for tid in tids:
                r = DotDict(tid=tid,
                            status=ErrorCode.SUCCESS)

                terminal = QueryHelper.get_available_terminal(tid, self.db)
                if not terminal:
                    r.status = ErrorCode.SUCCESS
                    res.append(r)
                    logging.error(
                        "[UWEB] The terminal with tid: %s does not exist!", tid)
                    continue

                key = get_del_data_key(tid)
                self.redis.set(key, flag)
                biz_type = QueryHelper.get_biz_type_by_tmobile(
                    terminal.mobile, self.db)
                if int(biz_type) == UWEB.BIZ_TYPE.YDWQ:
                    delete_terminal(tid, self.db, self.redis)
                    res.append(r)
                    continue
                elif int(biz_type) == UWEB.BIZ_TYPE.YDWS:
                    if terminal.login != GATEWAY.TERMINAL_LOGIN.ONLINE:
                        if terminal.mobile == tid:
                            delete_terminal(tid, self.db, self.redis)
                        else:
                            r.status = self.send_jb_sms(
                                terminal.mobile, terminal.owner_mobile, tid)
                        res.append(r)
                        continue

                # NOT: unbind. TODO: It should be re-factor some day.
                seq = str(int(time.time() * 1000))[-4:]
                args = DotDict(seq=seq,
                               tid=tid)
                response = GFSenderHelper.forward(
                    GFSenderHelper.URLS.UNBIND, args)
                response = json_decode(response)
                if response['success'] == ErrorCode.SUCCESS:
                    logging.info("[UWEB] uid:%s, tid: %s, tmobile:%s GPRS unbind successfully",
                                 self.current_user.uid, tid, terminal.mobile)
                    res.append(r)
                else:
                    # unbind failed. clear sessionID for relogin, then unbind
                    # it again
                    sessionID_key = get_terminal_sessionID_key(tid)
                    self.redis.delete(sessionID_key)
                    logging.error('[UWEB] uid:%s, tid: %s, tmobile:%s GPRS unbind failed, message: %s, send JB sms...',
                                  self.current_user.uid, tid, terminal.mobile, ErrorCode.ERROR_MESSAGE[response['success']])
                    unbind_sms = SMSCode.SMS_UNBIND
                    biz_type = QueryHelper.get_biz_type_by_tmobile(
                        terminal.mobile, self.db)
                    if biz_type != UWEB.BIZ_TYPE.YDWS:
                        ret = DotDict(status=ErrorCode.SUCCESS)
                    else:
                        ret = SMSHelper.send_to_terminal(
                            terminal.mobile, unbind_sms)
                        ret = DotDict(json_decode(ret))
                    if ret.status == ErrorCode.SUCCESS:
                        res.append(r)
                        self.db.execute("UPDATE T_TERMINAL_INFO"
                                        "  SET service_status = %s"
                                        "  WHERE id = %s",
                                        UWEB.SERVICE_STATUS.TO_BE_UNBIND,
                                        terminal.id)
                        logging.info("[UWEB] uid: %s, tid: %s, tmobile: %s SMS unbind successfully.",
                                     self.current_user.uid, tid, terminal.mobile)
                    else:
                        r.status = ErrorCode.FAILED
                        res.append(r)
                        logging.error("[UWEB] uid: %s, tid: %s, tmobile: %s SMS unbind failed. Message: %s",
                                      self.current_user.uid, tid, terminal.mobile, ErrorCode.ERROR_MESSAGE[status])

            self.write_ret(status, dict_=DotDict(res=res))
        except Exception as e:
            logging.exception("[UWEB] cid: %s batch delete failed. Exception: %s",
                              self.current_user.cid, e.args)
            status = ErrorCode.ILLEGAL_FILE
            self.write_ret(status)
Esempio n. 3
0
    def post(self, tmobile, pmobile, is_clear):
        """Delete a terminal. 
        
        @param: tmobile // terminal's mobile
        @param: pmobile // owner_mobile
        @param: is_clear: 清除// 1: 清除历史数据; 0: 不清楚历史数据

        """
        status = ErrorCode.SUCCESS
        try:
            terminal = self.db.get("SELECT id, login, mobile, tid"
                                   " FROM T_TERMINAL_INFO"
                                   "  WHERE mobile = %s",
                                   tmobile)
            tid = terminal.tid
            #NOTE: record whether clear history in redis
            key = get_del_data_key(tid)
            self.redis.set(key, is_clear)
            biz_type = QueryHelper.get_biz_type_by_tmobile(tmobile, self.db) 
            if int(biz_type) == UWEB.BIZ_TYPE.YDWS:
                if terminal.login != GATEWAY.TERMINAL_LOGIN.ONLINE: # offline
                    if terminal.mobile == tid:
                        delete_terminal_new(tid, self.db, self.redis)
                        logging.info('[ADMIN] Delete terminal. umobile:%s, tid: %s, tmobile:%s.', 
                                     pmobile, tid, tmobile)
                    else:
                        delete_terminal_new(tid, self.db, self.redis)
                        unbind_sms = SMSCode.SMS_UNBIND  
                        ret = SMSHelper.send_to_terminal(tmobile, unbind_sms)
                        ret = DotDict(json_decode(ret))
                        logging.info('[ADMIN] Send JB sms. umobile:%s, tid: %s, tmobile:%s.', 
                                     pmobile, tid, tmobile)
                    self.write_ret(status)
                    return
            else: 
                delete_terminal_new(tid, self.db, self.redis)
                self.write_ret(status)
                return

            # unbind terminal
            seq = str(int(time.time()*1000))[-4:]
            args = DotDict(seq=seq,
                           tid=terminal.tid)
            response = GFSenderHelper.forward(GFSenderHelper.URLS.UNBIND, args)
            response = json_decode(response)
            if response['success'] == ErrorCode.SUCCESS:
                logging.info("[ADMIN] Umobile: %s, tid: %s, tmobile:%s"
                             "  GPRS unbind successfully", 
                             pmobile, terminal.tid, tmobile)
            else:
                status = response['success']
                # unbind failed. clear sessionID for relogin, then unbind it again
                sessionID_key = get_terminal_sessionID_key(terminal.tid)
                self.redis.delete(sessionID_key)
                logging.error("[ADMIN] Umobile:%s, tid: %s, tmobile:%s"
                              "  GPRS unbind failed, message: %s, send JB sms...", 
                              pmobile, terminal.tid, tmobile, 
                              ErrorCode.ERROR_MESSAGE[status])
                unbind_sms = SMSCode.SMS_UNBIND  
                biz_type = QueryHelper.get_biz_type_by_tmobile(tmobile, self.db)
                if biz_type != UWEB.BIZ_TYPE.YDWS:
                    ret = DotDict(status=ErrorCode.SUCCESS)
                else:
                    ret = SMSHelper.send_to_terminal(tmobile, unbind_sms)
                    ret = DotDict(json_decode(ret))
                status = ret.status
                if ret.status == ErrorCode.SUCCESS:
                    self.db.execute("UPDATE T_TERMINAL_INFO"
                                    "  SET service_status = %s"
                                    "  WHERE id = %s",
                                    UWEB.SERVICE_STATUS.TO_BE_UNBIND,
                                    terminal.id)
                    logging.info("[ADMIN] umobile: %s, tid: %s, tmobile: %s"
                                 "  SMS unbind successfully.",
                                 pmobile, terminal.tid, tmobile)
                else:
                    logging.error("[ADMIN] umobile: %s, tid: %s, tmobile: %s"
                                  "  SMS unbind failed. Message: %s",
                                  pmobile, terminal.tid, tmobile, 
                                  ErrorCode.ERROR_MESSAGE[status])

        except Exception as e:
            status = ErrorCode.FAILED
            logging.exception("[ADMIN] Delete service failed."
                              " tmobile: %s, owner mobile: %s, Exception: %s", 
                              tmobile, pmobile, e.args)
        self.write_ret(status)
Esempio n. 4
0
    def post(self, ecmobile):
        """Delete the corp.
        """
        status = ErrorCode.SUCCESS
        try:
            ec = self.get_ecbusiness_info(ecmobile)
            groups = self.db.query(
                "SELECT id FROM T_GROUP WHERE corp_id = %s", ec.cid)
            groups = [group.id for group in groups]
            terminals = self.db.query("SELECT id, tid, mobile, owner_mobile"
                                      "  FROM T_TERMINAL_INFO WHERE group_id IN %s",
                                      tuple(groups + DUMMY_IDS))
            for terminal in terminals:

                # unbind terminal
                seq = str(int(time.time() * 1000))[-4:]
                args = DotDict(seq=seq,
                               tid=terminal.tid)
                response = GFSenderHelper.forward(
                    GFSenderHelper.URLS.UNBIND, args)
                response = json_decode(response)
                if response['success'] == ErrorCode.SUCCESS:
                    logging.info("[ADMIN] umobile: %s, tid: %s, tmobile:%s"
                                 "  GPRS unbind successfully",
                                 terminal.owner_mobile, terminal.tid,
                                 terminal.mobile)
                else:
                    status = response['success']
                    # unbind failed. clear sessionID for relogin, then unbind
                    # it again
                    sessionID_key = get_terminal_sessionID_key(terminal.tid)
                    self.redis.delete(sessionID_key)
                    logging.error("[ADMIN] umobile:%s, tid: %s, tmobile:%s"
                                  "  GPRS unbind failed, message: %s, send JB sms...",
                                  terminal.owner_mobile, terminal.tid,
                                  terminal.mobile, ErrorCode.ERROR_MESSAGE[status])
                    unbind_sms = SMSCode.SMS_UNBIND
                    biz_type = QueryHelper.get_biz_type_by_tmobile(
                        terminal.mobile, self.db)
                    if biz_type != UWEB.BIZ_TYPE.YDWS:
                        ret = DotDict(status=ErrorCode.SUCCESS)
                    else:
                        ret = SMSHelper.send_to_terminal(
                            terminal.mobile, unbind_sms)
                        ret = DotDict(json_decode(ret))
                    status = ret.status
                    if ret.status == ErrorCode.SUCCESS:
                        self.db.execute("UPDATE T_TERMINAL_INFO"
                                        "  SET service_status = %s"
                                        "  WHERE id = %s",
                                        UWEB.SERVICE_STATUS.TO_BE_UNBIND,
                                        terminal.id)
                        logging.info("[ADMIN] umobile: %s, tid: %s, tmobile: %s"
                                     "  SMS unbind successfully.",
                                     terminal.owner_mobile, terminal.tid,
                                     terminal.mobile)
                    else:
                        logging.error("[ADMIN] umobile: %s, tid: %s, tmobile: %s"
                                      " SMS unbind failed. Message: %s",
                                      terminal.owner_mobile, terminal.tid,
                                      terminal.mobile, ErrorCode.ERROR_MESSAGE[status])

            self.db.execute("DELETE FROM T_CORP WHERE cid = %s", ec.cid)

        except Exception as e:
            status = ErrorCode.FAILED
            logging.exception("Delete service failed. ecmobile: %s, Exception: %s.",
                              ecmobile, e.args)
        self.write_ret(status)
Esempio n. 5
0
    def delete(self):
        """Delete a terminal.
        """
        try:
            status = ErrorCode.SUCCESS
            tid = self.get_argument('tid', None)
            flag = self.get_argument('flag', 0)
            logging.info("[UWEB] Corp delete terminal request. tid: %s, flag: %s, cid: %s",
                         tid, flag, self.current_user.cid)

            terminal = QueryHelper.get_available_terminal(tid, self.db)
            if not terminal:
                logging.error("[UWEB] The terminal with tid: %s does not exist!", 
                              tid)
                status = ErrorCode.TERMINAL_NOT_EXISTED
                self.write_ret(status)
                return

            t_info = QueryHelper.get_terminal_basic_info(tid, self.db)
            key = get_del_data_key(tid)
            self.redis.set(key, flag)
            biz_type = QueryHelper.get_biz_type_by_tmobile(
                terminal.mobile, self.db)
            if int(biz_type) == UWEB.BIZ_TYPE.YDWS:
                if terminal.login != GATEWAY.TERMINAL_LOGIN.ONLINE:
                    if terminal.mobile == tid:
                        delete_terminal(tid, self.db, self.redis)
                    else:
                        status = self.send_jb_sms(
                            terminal.mobile, terminal.owner_mobile, tid)

                    if status == ErrorCode.SUCCESS:
                        WSPushHelper.pushS3(tid, self.db, self.redis, t_info)
                    self.write_ret(status)
                    return
            else:
                delete_terminal(tid, self.db, self.redis)
                if status == ErrorCode.SUCCESS:
                    WSPushHelper.pushS3(tid, self.db, self.redis, t_info)
                self.write_ret(status)
                return

            # unbind terminal
            seq = str(int(time.time() * 1000))[-4:]
            args = DotDict(seq=seq,
                           tid=tid)
            response = GFSenderHelper.forward(GFSenderHelper.URLS.UNBIND, args)
            response = json_decode(response)
            logging.info(
                "[UWEB] UNBind terminal: %s, response: %s", tid, response)
            if response['success'] == ErrorCode.SUCCESS:
                logging.info("[UWEB] uid:%s, tid: %s, tmobile:%s GPRS unbind successfully",
                             self.current_user.uid, tid, terminal.mobile)
            else:
                status = response['success']
                # unbind failed. clear sessionID for relogin, then unbind it
                # again
                clear_sessionID(self.redis, tid)
                logging.error('[UWEB] uid:%s, tid: %s, tmobile:%s GPRS unbind failed, message: %s, send JB sms...',
                              self.current_user.uid, tid, terminal.mobile,
                              ErrorCode.ERROR_MESSAGE[status])
                status = self.send_jb_sms(
                    terminal.mobile, terminal.owner_mobile, tid)

            if status == ErrorCode.SUCCESS:
                WSPushHelper.pushS3(tid, self.db, self.redis, t_info)
            self.write_ret(status)
        except Exception as e:
            logging.exception("[UWEB] Delete terminal failed. cid: %s, Exception: %s",
                              self.current_user.cid, e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)