Ejemplo n.º 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())
Ejemplo n.º 2
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())
Ejemplo n.º 3
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())