Exemple #1
0
    async def GetCmdSvc(self, pTenDataRcvd):

        ret = TenDataSend()
        # 检测是否初始化完毕
        if self.bIniting:
            ret.SetResult('Initing')  # 服务初始化中
            return json.dumps(ret.Get())

        pData = pTenDataRcvd.GetData()
        App = pData['App']

        # 检测是否需要强制升级
        szVersion = pTenDataRcvd.GetVer()
        if self.CheckUpgrade(App, szVersion):
            ret.SetResult('Upgrade')  # 强制升级
            return json.dumps(ret.Get())

        # 检测服务状态
        if App in self.pAppStatus:
            if self.pAppStatus[App] == 2:
                ret.SetResult('Maintain')  # 维护中
                return json.dumps(ret.Get())

        # 获取CmdSvc服务器列表
        data = []
        if App in self.pCmdMap:
            data = self.pCmdMap[App]

        ret.SetData(data)
        return json.dumps(ret.Get())
Exemple #2
0
    async def GetFriends(self, pTenDataRcvd):
        ret = TenDataSend()
        pData = pTenDataRcvd.GetData()
        szUserId = pData['Phone']
        iType = int(pData['Type'])
        szLookRid = pData['LookRid']
        iUpdateTime = int(pData['UpdateTime'])
        if szUserId == "":
            ret.SetFalse()
            ret.SetHints(u'Phone不能为空')
        pConnect = TenDbConnect(Const.g_pTenMySqlObj)
        b = await pConnect.GetConnect()
        if b == False:
            ret.SetFalse()
            return json.dumps(ret.Get())
        aParam = []
        if iType == 1:
            aParam.append(szUserId)
        else:
            aParam.append(szLookRid)
        aParam.append(iType)
        aParam.append(iUpdateTime)
        pProc = TenProc(Const.g_pTenMySqlObj,
                        pConnect,
                        'GetFriends',
                        aParam=aParam)
        b = await pProc.Proc()
        if b:
            tmpDialog = pProc.GetAppointData('Friends')
            tmpDialogData = pProc.ConvertToObj(tmpDialog['datas'],
                                               tmpDialog['cols_name'])

            tmpAllTask = pProc.GetAppointData('AllTask')
            tmpAllTaskData = pProc.ConvertToObj(tmpAllTask['datas'],
                                                tmpAllTask['cols_name'])
            self.__Public(pProc, ret, tmpDialogData, tmpAllTaskData)
        else:
            ret.SetFalse()

        await pConnect.Recovery()
        return json.dumps(ret.Get())
Exemple #3
0
 async def ReTasks(self, pTenDataRcvd):
     ret = TenDataSend()
     pData = pTenDataRcvd.GetData()
     szRid = pData['Phone']
     result = False
     ex = ''
     for item in self.aUser:
         if item['UserId'] == szRid:
             result, ex = await self.__PullData(szRid, item['Address'])
             break
     if result:
         ret.SetTrue()
     else:
         ret.SetHints(ex)
         ret.SetFalse()
     return json.dumps(ret.Get())
Exemple #4
0
    async def AddLog(self, pTenDataRcvd):
        ret = TenDataSend()
        pData = pTenDataRcvd.GetData()
        Type = pData['Type']
        Platform = pData['Platform']
        Log = pData['Log']
        App = pData['App']
        if len(App) <= 0:
            ret.SetFalse()
            ret.SetHints(u'App为空')
            return json.dumps(ret.Get())
        if len(Platform) <= 0:
            ret.SetFalse()
            ret.SetHints(u'Platform为空')
            return json.dumps(ret.Get())

        pConnect = TenDbConnect(self.Db)
        b = await pConnect.GetConnect()
        if b == False:
            ret.SetFalse()
            return json.dumps(ret.Get())
        try:
            pTable = TenTable(self.Db,
                              pConnect,
                              'Log',
                              szInsertFields='App,Log,LogType',
                              aInsertValue=[[App, Log, Type]])
            b = await pTable.Insert()
            if b == False:
                ret.SetFalse()
        except:
            ret.SetFalse()
            import traceback
            traceback.print_exc()

        await pConnect.Recovery()
        return json.dumps(ret.Get())
Exemple #5
0
    async def Login(self, pTenDataRcvd):
        ret = TenDataSend()
        ret.SetFalse()
        pData = pTenDataRcvd.GetData()
        iType = int(pData['Type'])
        App = pData['App']

        pConnect = TenDbConnect(self.Db)
        b = await pConnect.GetConnect()
        if b == False:
            ret.SetFalse()
            return json.dumps(ret.Get())

        if iType == 0:
            Phone = pData['Phone']
            if len(Phone) > 0:
                Code = pData['Code']
                pProc = TenProc(self.Db,
                                pConnect,
                                'LoginByCode',
                                aParam=[App, Phone, Code])
                b = await pProc.Proc()
                if b == False:
                    ret.SetFalse()
                else:
                    LoginResult = pProc.GetAppointData('Result')
                    LoginResultData = pProc.ConvertToObj(
                        LoginResult['datas'], LoginResult['cols_name'])
                    if len(LoginResultData) > 0:
                        tmp = LoginResultData[0]
                        if int(tmp['Result']) == 1:
                            ret.SetTrue()
                            szSession = tmp['Session']
                            ret.SetData({'Session': szSession})
                        else:
                            ret.SetFalse()
                            ret.SetHints(tmp['Err'])

            else:
                ret.SetFalse()
                ret.SetHints(u'手机格式不正确')
        else:
            ret.SetFalse()
            ret.SetHints(u'不支持的登录类型')

        await pConnect.Recovery()
        return json.dumps(ret.Get())
Exemple #6
0
    async def GetTasks(self, pTenDataRcvd):
        def Correct(pCur, iLevel=0):
            tmp = ''
            if 'nm' in pCur:
                pCur['nm'] = pCur['nm'].lstrip()
            tmp = pCur['nm']
            if 'ch' in pCur:
                chTxt = ''
                p = pCur['ch']
                iLen = len(p) - 1
                while iLen >= 0:
                    subTxt = Correct(p[iLen], iLevel=iLevel + 1)
                    chTxt += subTxt
                    if len(subTxt) <= 0:
                        # 移除
                        del p[iLen]
                    iLen -= 1
                if len(chTxt) <= 0:
                    del pCur['ch']
                tmp += chTxt
            return tmp

        ret = TenDataSend()
        szVersion = pTenDataRcvd.GetVer()
        pConnect = TenDbConnect(Const.g_pTenMySqlObj)
        pData = pTenDataRcvd.GetData()
        szUserId = pData['Phone']

        b = await pConnect.GetConnect()
        if b == False:
            ret.SetFalse()
            return json.dumps(ret.Get())
        try:
            pTable = TenTable(Const.g_pTenMySqlObj,
                              pConnect,
                              'User',
                              szQueryFields='TaskVer',
                              szQueryCon='UserId={}'.format(szUserId))
            b = await pTable.Query()
            data = {}

            if b:
                if pTable.Value != None:
                    if len(pTable.Value['datas']) > 0:
                        if pTable.Value['datas'][0][0] != szVersion:
                            pProc = TenProc(Const.g_pTenMySqlObj,
                                            pConnect,
                                            'GetTasks',
                                            aParam=[szVersion, szUserId])
                            data['Data'] = []
                            b = await pProc.Proc()
                            if b:
                                tmpAllTask = pProc.GetAppointData('AllTask')
                                tmpAllTaskData = pProc.ConvertToObj(
                                    tmpAllTask['datas'],
                                    tmpAllTask['cols_name'])

                                tmpLabel = pProc.GetAppointData('AllLabel')
                                tmpLabelData = pProc.ConvertToObj(
                                    tmpLabel['datas'], tmpLabel['cols_name'])

                                tD = []
                                if len(tmpAllTaskData) > 0:
                                    tD = tmpAllTaskData[0]['TaskDatas']
                                    tD = json.loads(tD)
                                # 递归算法恢复树形结构
                                tD = self.RecoveryTree(tD)

                                ppData = []
                                for item in tD:
                                    pp = {}
                                    pp['Txt'] = item
                                    # item['Txt'] = json.loads(item['Txt'])
                                    Txt = pp['Txt']
                                    # 将.Tip转为.TIP 并且生成标签
                                    if 'ch' in Txt:
                                        ch = Txt['ch']
                                        for tmpItem in ch:
                                            nm = tmpItem['nm']
                                            nm = nm.strip()
                                            if nm.upper() == '.TIP':
                                                tmpItem['nm'] = '.TIP'
                                    # 去除标签
                                    # Txt['nm'] = self.FilterLabel(Txt['nm'])
                                    if Correct(Txt) == '':
                                        pp['Valid'] = '0'
                                    else:
                                        pp['Valid'] = '1'

                                    szTaskId = item['TaskId']

                                    self.__AddLabels(pp['Txt'], tmpLabelData,
                                                     szTaskId)
                                    # 3级标签
                                    if 'ch' in Txt:
                                        ch = Txt['ch']
                                        for tmpItem in ch:
                                            self.__AddLabels(
                                                tmpItem, tmpLabelData,
                                                tmpItem['TaskId'])
                                            if 'ch' in tmpItem:
                                                ch1 = tmpItem['ch']
                                                for ttItem in ch1:
                                                    self.__AddLabels(
                                                        ttItem, tmpLabelData,
                                                        ttItem['TaskId'])

                                    # pp['Labels'] = []
                                    # for label in tmpLabelData:
                                    #     if label['TaskId'] == szTaskId:
                                    #         pp['Labels'].append({
                                    #             'Label': label['Label'],
                                    #             'Seq': label['Seq']
                                    #         })
                                    # 排序
                                    # item['Labels'] = sorted(item['Labels'], key=itemgetter('Seq'))
                                    ppData.append(pp)

                                data['Data'] = ppData
                            else:
                                ret.SetFalse()

                            szVersion = str(pTable.Value['datas'][0][0])
            else:
                ret.SetFalse()
        except:
            ret.SetFalse()
            import traceback
            traceback.print_exc()

        ret.SetVer(szVersion)
        ret.SetData(data)

        await pConnect.Recovery()

        return json.dumps(ret.Get())
Exemple #7
0
    async def ModifyTasks(self, pTenDataRcvd):
        ret = TenDataSend()
        szVersion = pTenDataRcvd.GetVer()
        pData = pTenDataRcvd.GetData()
        szUserId = pData['Phone']
        if szUserId == "":
            ret.SetFalse()
            ret.SetHints(u'Phone不能为空')
        pTaskData = pData['TaskData']
        iType = int(pTaskData['Type'])

        pConnect = TenDbConnect(Const.g_pTenMySqlObj)
        b = await pConnect.GetConnect()
        if b == False:
            ret.SetFalse()
            return json.dumps(ret.Get())

        b = False
        if iType == 0:  # 添加任务
            szNote = pTaskData['Note']
            szTxt = pTaskData['Txt']
            szTaskId = self.CreateUUid()
            SubLabel = []
            pProc = TenProc(Const.g_pTenMySqlObj,
                            pConnect,
                            'CreateTask',
                            aParam=[
                                szTaskId, szTxt,
                                json.dumps(SubLabel), szNote, szUserId
                            ])
            b = await pProc.Proc()
            if b == False:
                ret.SetFalse()
        elif iType == 1:  # 删除任务
            szTaskId = pTaskData['TaskId']
            pTable = TenTable(Const.g_pTenMySqlObj,
                              pConnect,
                              'TaskTable',
                              szDelCon='UserId={!r} and TaskId={!r}'.format(
                                  szUserId, szTaskId))
            b = await pTable.Del()
            if b == False:
                ret.SetFalse()
        elif iType == 2:  # 修改
            szTaskId = pTaskData['TaskId']

            tmpFilters = []
            tmpData = []
            if 'Txt' in pTaskData:
                tmpFilters.append('Txt')
                tmpData.append(pTaskData['Txt'])
            if 'SubLabel' in pTaskData:
                tmpFilters.append('SubLabel')
                tmpData.append(pTaskData['SubLabel'])
            if 'Note' in pTaskData:
                tmpFilters.append('Note')
                tmpData.append(pTaskData['Note'])

            if len(tmpData) > 0:
                pTable = TenTable(
                    Const.g_pTenMySqlObj,
                    pConnect,
                    'TaskTable',
                    szUpdateFields='=%s,'.join(tmpFilters) + '=%s',
                    szUpdateCon='UserId={!r} and TaskId={!r}'.format(
                        szUserId, szTaskId),
                    aUpdateVale=[tmpData])

                # str = ",".join(["(" + ",".join(["%s"] * cols) + ")"] * len(pTable.aIOUVale))

                b = await pTable.Update()
                if b == False:
                    ret.SetFalse()

        else:
            ret.SetFalse()
            ret.SetHints(u'Type不正确')

        await pConnect.Recovery()
        return json.dumps(ret.Get())
Exemple #8
0
    async def GetDialog(self, pTenDataRcvd):
        ret = TenDataSend()
        pData = pTenDataRcvd.GetData()
        szUserId = pData['Phone']
        iUpdateTime = int(pData['UpdateTime'])
        if szUserId == "":
            ret.SetFalse()
            ret.SetHints(u'Phone不能为空')
        pConnect = TenDbConnect(Const.g_pTenMySqlObj)
        b = await pConnect.GetConnect()
        if b == False:
            ret.SetFalse()
            return json.dumps(ret.Get())
        pProc = TenProc(Const.g_pTenMySqlObj,
                        pConnect,
                        'GetDialog',
                        aParam=[szUserId, iUpdateTime])
        b = await pProc.Proc()
        if b:
            tmpDialog = pProc.GetAppointData('Dialog')
            tmpDialogData = pProc.ConvertToObj(tmpDialog['datas'],
                                               tmpDialog['cols_name'])

            tmpAllTask = pProc.GetAppointData('AllTask')
            tmpAllTaskData = pProc.ConvertToObj(tmpAllTask['datas'],
                                                tmpAllTask['cols_name'])

            self.__Public(pProc, ret, tmpDialogData, tmpAllTaskData)
            # if pProc.Value != None:
            #     tmpDialog = pProc.GetAppointData('Dialog')
            #     tmpDialogData = pProc.ConvertToObj(tmpDialog['datas'], tmpDialog['cols_name'])
            #
            #     tmpAllTask = pProc.GetAppointData('AllTask')
            #     tmpAllTaskData = pProc.ConvertToObj(tmpAllTask['datas'], tmpAllTask['cols_name'])
            #     # 递归算法恢复树形结构
            #     tD = []
            #     if len(tmpAllTaskData) > 0:
            #         tD = tmpAllTaskData[0]['TaskDatas']
            #         tD = json.loads(tD)
            #     tD = self.RecoveryTree(tD)
            #
            #     for item in tmpDialogData:
            #         item['CreateTime'] = str(item['CreateTime'])
            #         Txt = item['Txt']
            #         item['Txt'] = {}
            #         CurTaskId = item['TaskId']
            #         for ppItem in tD:
            #             ppItem['NotTask'] = str(ppItem['NotTask'])
            #             if ppItem['TaskId'] == CurTaskId:
            #                 item['Txt'] = ppItem
            #                 break
            #     ret.SetData(tmpDialogData)
            #     iii = 1

            # if pProc.Value['datas'][0][0] != szVersion:
            #     pProc = TenProc(Const.g_pTenMySqlObj, pConnect, 'GetTasks', aParam=[szVersion, szUserId])
            #     data['Data'] = []
            #     b = await pProc.Proc()
            #     if b:
            #         tmpAllTask = pProc.GetAppointData('AllTask')
            #         tmpAllTaskData = pProc.ConvertToObj(tmpAllTask['datas'], tmpAllTask['cols_name'])
            #
            #         tmpLabel = pProc.GetAppointData('AllLabel')
            #         tmpLabelData = pProc.ConvertToObj(tmpLabel['datas'], tmpLabel['cols_name'])
            #
            # tD = []
            # if len(tmpAllTaskData) > 0:
            #     tD = tmpAllTaskData[0]['TaskDatas']
            #     tD = json.loads(tD)
            #         # 递归算法恢复树形结构
            #         tD = self.RecoveryTree(tD)
            #
            #         ppData = []
            #         for item in tD:
            #             pp = {}
            #             pp['Txt'] = item
            #             # item['Txt'] = json.loads(item['Txt'])
            #             Txt = pp['Txt']
            #             # 将.Tip转为.TIP 并且生成标签
            #             if 'ch' in Txt:
            #                 ch = Txt['ch']
            #                 for tmpItem in ch:
            #                     nm = tmpItem['nm']
            #                     nm = nm.strip()
            #                     if nm.upper() == '.TIP':
            #                         tmpItem['nm'] = '.TIP'
            #             # 去除标签
            #             # Txt['nm'] = self.FilterLabel(Txt['nm'])
            #             if Correct(Txt) == '':
            #                 pp['Valid'] = '0'
            #             else:
            #                 pp['Valid'] = '1'
            #
            #             szTaskId = item['TaskId']
            #
            #             self.__AddLabels(pp, tmpLabelData, szTaskId)
            #             # 3级标签
            #             if 'ch' in Txt:
            #                 ch = Txt['ch']
            #                 for tmpItem in ch:
            #                     self.__AddLabels(tmpItem, tmpLabelData, tmpItem['TaskId'])
            #
            #             # pp['Labels'] = []
            #             # for label in tmpLabelData:
            #             #     if label['TaskId'] == szTaskId:
            #             #         pp['Labels'].append({
            #             #             'Label': label['Label'],
            #             #             'Seq': label['Seq']
            #             #         })
            #             # 排序
            #             # item['Labels'] = sorted(item['Labels'], key=itemgetter('Seq'))
            #             ppData.append(pp)
            #
            #         data['Data'] = ppData
            #     else:
            #         ret.SetFalse()
            #
            #     szVersion = str(pTable.Value['datas'][0][0])
        else:
            ret.SetFalse()

        await pConnect.Recovery()
        return json.dumps(ret.Get())