示例#1
0
def query(sql, resultfile_name):
    resultfile = open(resultfile_name, "a")
    try:
        cur, conn = getConnect()
        qryHead, qryResult = dbOper.qryData(cur, sql)

        resultbody = []
        #resulthead =[]

        # for j in range(0,len(qryHead)):
        #     resulthead.append(str(qryHead[j]))
        # if not os.path.getsize(resultfile_name):
        #     logger.error("--写入数据头")
        #     resultfile.write('|'.join(resulthead) + "\n")

        if qryResult.__len__():
            for i in range(0, qryResult.__len__()):
                #查询结果
                resultbody.append([])  #长度+1
                for ii in range(0, len(qryResult[i])):
                    resultbody[i].append(str(qryResult[i][ii]))
            for i in range(0, len(resultbody)):
                resultfile.write('|'.join(resultbody[i]) + "\n")
        else:
            logger.error("查询结果为空:%s" % sql)
    except Exception as e:
        logger.error("%s \n--------执行失败" % sql)
        logger.error(e)
示例#2
0
    def qry(self, sql, res_file, connectInfo):

        historyResult = res_file
        resultbody = []
        time.sleep(5)
        print connectInfo
        try:
            logger.info(sql)
            cur, conn = connectInfo
            qryHead, qryResult = dbOper.qryData(cur, sql)

            if self.count == 0:
                resulthead = []
                for j in range(0, len(qryHead)):
                    resulthead.append(str(qryHead[j]))
                historyResult.write(','.join(resulthead) + "\n")
            self.count += len(qryResult)
            for i in range(0, qryResult.__len__()):
                # 查询结果
                resultbody.append([])  # 长度+1
                for ii in range(0, len(qryResult[i])):
                    resultbody[i].append(str(qryResult[i][ii]))
            cur.close()
            conn.close()
        except Exception as e:
            self.logger.error(e)
        for i in range(0, len(resultbody)):
            historyResult.write('|sp'.join(resultbody[i]) + "\n")
        return resultbody
示例#3
0
    def getPhoneFile(self, ):
        phone_file = self.phone_dir + str(os.sep) + self.phoneFileName
        if os.path.exists(r'%s' % (phone_file)):
            print "号码文件:%s" % phone_file
            logger.info("号码文件已经生成,请注意是否需要重新生成,号码文件:%s" % phone_file)
        else:
            conn_data = dataBase
            logger.info("开始连接数据库")
            try:
                cur, conn = dbOper.conn_db(conn_data)  # 获取数据库连接cur
                logger.info("连接数据库成功")
            except Exception as e:
                logger.info("连接数据库失败")
            try:
                sql = self.getSql()
                logger.info("Query starting with sql : " + sql)
                head, result = dbOper.qryData(cur, sql)
                logger.info("Query end ")
                logger.info('开始生成号码文件')
                try:
                    with open(phone_file, "a") as phoneFile:
                        for res in result:
                            phoneFile.write(",".join(map(str, res)))
                            phoneFile.write("\n")
                except Exception as e:
                    print e
                print "号码文件生成结束:%s" % phone_file
                phoneFile.close()
            except Exception as e:
                print("查询数据失败")

        return phone_file
示例#4
0
    def query(self, phones):

        for phone in phones:

            sql = """update td_padm_login_info set valid_flag = 1 where CONTACT_PHONE = %s """ % phone
            logger.info(sql)

            try:
                dbOper.qryData(self.cur, sql)
                self.conn.commit()
            except Exception as e:
                self.logger.error(e)
                self.logger.error("销户失败:%s" % e.__str__())
            sql = """select valid_flag,CONTACT_PHONE from  td_padm_login_info  where CONTACT_PHONE = %s """ % phone
            logger.info(sql)
            qryHead, qryResult = dbOper.qryData(self.cur, sql)
            logger.info(list(qryResult))
            print qryResult
示例#5
0
    def query(self, roles):
        result = []

        for role in roles:
            historyResultFile = '%s/jcy/result/%s.csv' % (BASE_DIR, role)
            historyResult = open(historyResultFile,
                                 "a")  # 记录查询历史的文件history,也可以用来存输出结果。
            sql = """select
            r.ROLE_NAME 角色 ,b1.NAVI_NAME 一级菜单,b2.NAVI_NAME 二级菜单,b3.NAVI_NAME 三级菜单 ,ai.APP_NAME,a.APP_VERSION_URL,a.VERSION_CREATE_DATE 创建时间
            from td_padm_role r
            
            LEFT JOIN  td_padm_role_function_rel ra ON r.ROLE_ID= ra.ROLE_ID
            LEFT JOIN  td_padm_app_version a ON ( ra.APP_ID =a.APP_ID and ra.APP_VERSION= a.APP_VERSION )
            LEFT JOIN  td_padm_app_channel_rel an ON ( a.APP_ID = an.APP_ID and a.APP_VERSION = an.APP_VERSION)
            
            LEFT JOIN td_padm_portal_nav b3 ON an.NAVI_IDS =b3.NAVI_ID
            LEFT JOIN td_padm_portal_nav b2 ON b3.PARENT_NAVI_ID=b2.NAVI_ID
            LEFT JOIN td_padm_portal_nav b1 ON b2.PARENT_NAVI_ID=b1.NAVI_ID
            LEFT JOIN td_padm_app_info ai ON a.APP_ID =ai.APP_ID
            where #a.APP_VERSION_TYPE ='1' and 
            r.ROLE_NAME like '%%'
            ORDER BY r.ROLE_ID , b1.NAVI_PRIORITY DESC,  b1.NAVI_ID , b2.NAVI_PRIORITY DESC,  b2.NAVI_ID , b3.NAVI_PRIORITY DESC,  b3.NAVI_ID ,ai.APP_NAME
                    """ % (role)
            logger.info(sql)

            try:
                qryHead, qryResult = dbOper.qryData(self.cur, sql)

            except Exception as e:
                self.logger.error(e)
                self.logger.error("查询失败")
            resultbody = []
            resulthead = []
            for j in range(0, len(qryHead)):
                resulthead.append(str(qryHead[j]))
            result.append(','.join(resulthead))  # 首先写入头信息
            historyResult.write(','.join(resulthead) + "\n")
            print(','.join(resulthead) + "\n")
            count = len(qryResult)

            for i in range(0, qryResult.__len__()):
                # 查询结果
                resultbody.append([])  # 长度+1
                for ii in range(0, len(qryResult[i])):
                    resultbody[i].append("'" + str(qryResult[i][ii]) + "'")
            for i in range(0, len(resultbody)):
                result.append(','.join(resultbody[i]))
                historyResult.write(','.join(resultbody[i]) + "\n")
                print(','.join(resultbody[i]) + "\n")

        time.sleep(0.05)
        self.logger.error("Query finished")
        logger.error("计数:" + str(count))
        historyResult.close()
        return result
示例#6
0
    def query(self, phones):
        result = []

        for phone in phones:
            historyResultFile = '%s/jcy/result/%s.csv' % (BASE_DIR, phone)
            historyResult = open(historyResultFile,
                                 "a")  # 记录查询历史的文件history,也可以用来存输出结果。
            sql = """select l.VALID_FLAG, l.LOGIN_NAME as 姓名, 
            l.LOGIN_NO as 账号编号, l.CONTACT_PHONE 电话,l.UPDATE_TIME,l.EMAIL ,ar.AREA_NAME as 所属机构,sh.SHOP_NAME 商户, r.ROLE_NAME as 角色,l.CREATE_TIME 账号创建时间 
            FROM td_padm_login_info l 
            LEFT JOIN td_padm_login_role_rel lr ON l.LOGIN_ID= lr.LOGIN_ID
            LEFT JOIN td_padm_role r on lr.ROLE_ID=r.ROLE_ID
            LEFT JOIN td_padm_login_shop s ON l.LOGIN_ID= s.LOGIN_ID
            LEFT JOIN td_padm_shop sh on s.SHOP_ID =sh.SHOP_ID
            LEFT JOIN td_padm_area ar ON l.AREA_IDS =ar.AREA_CODE
            where 
            #l.CONTACT_PHONE='%s'
                    """ % (phone)
            logger.info(sql)

            try:
                qryHead, qryResult = dbOper.qryData(self.cur, sql)

            except Exception as e:
                self.logger.error(e)
                self.logger.error("查询失败")
            resultbody = []
            resulthead = []
            for j in range(0, len(qryHead)):
                resulthead.append(str(qryHead[j]))
            result.append(','.join(resulthead))  # 首先写入头信息
            historyResult.write(','.join(resulthead) + "\n")
            print(','.join(resulthead) + "\n")
            count = len(qryResult)

            for i in range(0, qryResult.__len__()):
                # 查询结果
                resultbody.append([])  # 长度+1
                for ii in range(0, len(qryResult[i])):
                    resultbody[i].append("'" + str(qryResult[i][ii]) + "'")
            for i in range(0, len(resultbody)):
                result.append(','.join(resultbody[i]))
                historyResult.write(','.join(resultbody[i]) + "\n")
                print(','.join(resultbody[i]) + "\n")

        time.sleep(0.05)
        self.logger.error("Query finished")
        logger.error("计数:" + str(count))
        historyResult.close()
        return result
示例#7
0
 def query(self, batch_id):
     result = []
     historyResult = open(historyResultFile,
                          "a")  # 记录查询历史的文件history,也可以用来存输出结果。
     for cur in self.cur:
         for databaseNum in range(1, 6):  #range(1,6)---> 序号1到5的数据库
             for phoneTail in range(0, 10):  #号码尾号0-9
                 sql = """SELECT  BIND_NO 领取号码,BIND_TIME 领取时间,BIND_AREA 省份, use_date 账期,
                         target_no
                         受赠账号, LIFECYCLE_ST
                         当前状态, USE_TIME
                         使用时间, USE_ORDER_ID
                         使用订单 ,PCARD_CASH
                         面额
                         from  echnmarketdb%d.td_pcard_info_%s 
                         where BATCH_ID in (%s) and LIFECYCLE_ST = '9' and BIND_TIME>='2018-07-01 00:00:00' """ % (
                     databaseNum, phoneTail, batch_id)
                 logger.info(sql)
                 #and LIFECYCLE_ST = '10'
                 #print sql
                 try:
                     qryHead, qryResult = dbOper.qryData(cur, sql)
                     resultbody = []
                     if self.count == 0:
                         resulthead = []
                         for j in range(0, len(qryHead)):
                             resulthead.append(str(qryHead[j]))
                         result.append('|'.join(resulthead))  # 首先写入头信息
                         historyResult.write(','.join(resulthead) + "\n")
                     self.count += len(qryResult)
                     for i in range(0, qryResult.__len__()):
                         #查询结果
                         resultbody.append([])  #长度+1
                         for ii in range(0, len(qryResult[i])):
                             resultbody[i].append("'" +
                                                  str(qryResult[i][ii]) +
                                                  "'")
                 except Exception as e:
                     self.logger.error(e)
                 for i in range(0, len(resultbody)):
                     #print('|'.join(resultbody[i]))#打印查询结果到控制台,logger.error 会打印时间戳,看起来乱
                     result.append('|'.join(resultbody[i]))
                     historyResult.write(','.join(resultbody[i]) + "\n")
     time.sleep(0.05)
     self.logger.error("Query finished")
     logger.error("计数:" + str(self.count))
     historyResult.close()
     return result
示例#8
0
    def getPhoneFile(self):
        phone_file = '%s/%s.dat' % (self.resData, self.phoneFileName)
        logger = self.logger
        if os.path.exists(r'%s' % (phone_file)):
            print '号码文件已经生成,请注意是否需要重新生成'
            print "号码文件:%s" % phone_file
            logger.info("号码文件已经生成,请注意是否需要重新生成")
            print "sql is:" + self.getSql()
        else:
            conn_data = dataBase
            optSeq = self.getOptSeq()
            # print conn_data
            # 调用数据库连接模块,生成数据库连接cur
            print '开始连接数据库'
            logger.info("开始连接数据库")
            try:
                cur, conn = dbOper.conn_db(conn_data)  # 获取数据库连接cur
                print '连接数据库成功:'
                print cur, conn
                logger.info("连接数据库成功")
            except Exception as e:
                print("连接数据库失败")
                print e
                logger.info("连接数据库失败")
                logger.info(e)

            try:
                sql = self.getSql()
                logger.info("sql is" + sql)
                print 'getSql()\'s result :' + sql
                print "查询开始" + sql, self.pcardName
                head, result = dbOper.qryData(cur, sql)
                print "查询完成"
                # 写号码文件
                print '开始生成号码文件'
                with open(phone_file, "a") as phoneFile:
                    for res in result:
                        print(res)
                        print(type(res))
                        phoneFile.write("%s,%s,%s" % (res[0], res[1], optSeq))
                        phoneFile.write("\n")
                print "号码文件生成结束:%s" % phone_file
                phoneFile.close()
            except Exception as e:
                print("查询数据失败")

        return '%s/%s' % (self.resData, self.phoneFileName)
示例#9
0
    def query(self, funcs):
        result = []

        for func in funcs:
            historyResultFile = '%s/jcy/result/%s.csv' % (BASE_DIR, func)
            historyResult = open(historyResultFile,
                                 "a")  # 记录查询历史的文件history,也可以用来存输出结果。
            sql = """select r.ROLE_ID,r.ROLE_NAME ,a.APP_NAME 
            from td_padm_role r 
            LEFT JOIN td_padm_role_function_rel rf ON r.ROLE_ID= rf.ROLE_ID
            LEFT JOIN td_padm_app_info a ON rf.APP_ID= a.APP_ID
            where 
            a.APP_NAME LIKE '\%%s\%'
            r.ROLE_NAME LIKE '%商城省份客服%'""" % (func)
            logger.info(sql)

            try:
                qryHead, qryResult = dbOper.qryData(self.cur, sql)

            except Exception as e:
                self.logger.error(e)
                self.logger.error("查询失败")
            resultbody = []
            resulthead = []
            for j in range(0, len(qryHead)):
                resulthead.append(str(qryHead[j]))
            result.append(','.join(resulthead))  # 首先写入头信息
            historyResult.write(','.join(resulthead) + "\n")
            print(','.join(resulthead) + "\n")
            count = len(qryResult)

            for i in range(0, qryResult.__len__()):
                # 查询结果
                resultbody.append([])  # 长度+1
                for ii in range(0, len(qryResult[i])):
                    resultbody[i].append("'" + str(qryResult[i][ii]) + "'")
            for i in range(0, len(resultbody)):
                result.append(','.join(resultbody[i]))
                historyResult.write(','.join(resultbody[i]) + "\n")
                print(','.join(resultbody[i]) + "\n")

        time.sleep(0.05)
        self.logger.error("Query finished")
        logger.error("计数:" + str(count))
        historyResult.close()
        return result
示例#10
0
def query(connect_info, sql_list, qry_resultfile_name):

    resultfile = open(qry_resultfile_name, "w")
    print qry_resultfile_name
    miss = open(qry_resultfile_name + "_miss", "w")
    cur, conn = getConnect(connect_info)
    not_null_count = 0
    null_count = 0
    result_line_count = 0
    for sql in sql_list:
        try:
            qryHead, qryResult = dbOper.qryData(cur, sql)
            print "woshi sql " + sql
            resultbody = []
            if qryResult.__len__():
                not_null_count += 1
                result_line_count += qryResult.__len__()
                for i in range(0, qryResult.__len__()):
                    #查询结果
                    resultbody.append([])  #长度+1
                    for ii in range(0, len(qryResult[i])):
                        if qryResult[i][ii] is None:
                            qryResult[i][ii] = 'null'
                        resultbody[i].append("'%s'" % qryResult[i][ii])
                for i in range(0, len(resultbody)):
                    resultfile.write('\t'.join(resultbody[i]) + "\n")
            else:
                logger.error("查询结果为空:%s" % sql)
                null_count += 1
                miss.write(sql + '\n')
        except Exception as e:
            logger.error("%s \n--------执行失败" % sql)
            logger.error(e)
    try:
        resultfile.close()
        miss.close()
        #conn.close()
        logger.info(" query finished ,conn closed")

    except Exception as e:
        logger.error(e)
    try:
        return "执行查询次数 [%s],结果数 [%s],结果总行数 [%s],无结果数 [%s]  " % (
            len(sql_list), not_null_count, result_line_count, null_count)
    except Exception as e:
        return "查询异常 %s" % e
示例#11
0
    def query(self, batch_Id, xiaodongxi):
        batch_Id = batch_Id.strip()
        result = []

        try:

            batchId = batch_Id
            batchsql = " select * from echnmarketdb.td_def_pcard_batch  where  BATCH_ID =" + batchId
            batchhead, batchResult = dbOper.qryData(self.cur[0], batchsql)

            # 卡券信息head拼接,只拼接一次
            head = []
            body = []
            if 1 == 1:
                for j in range(0, len(batchhead)):
                    #print(str(batchhead[j]))
                    head.append(str(batchhead[j]))
            else:
                pass

            #卡券信息body拼接
            for k in range(0, len(batchResult[0])):
                #print(str(batchResult[0][k]))
                body.append(str(batchResult[0][k]))
            print('|'.join(head))
            print('|'.join(body))

        except Exception as e:
            logger.exception("Exception Logged run")
            self.falseCount += 1
            self.failedUser.append(batch_Id)
            self.logger.error(e)
            self.logger.error(
                "Phone:%s Failed to Query -------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
                % batch_Id)
        return result  #这个返回,,以后可能有用。
示例#12
0
    def getInfo(self, phone):
        cur = self.cur
        sql = self.getSql(phone)
        print "查询开始"
        head, result = dbOper.qryData(cur, sql)
        print "查询完成"
        #exception = []
        if result.__len__() > 0:

            flag = 1
            login_id = result[0][0]

            #判断账号是否同时含有客服主管和客服角色
            for res in result:
                #判断同一个手机号是否存在多个工号
                if login_id != res[0]:

                    print("该号码" + phone.__str__() + "存在不一致工号" + str(login_id) +
                          "和" + str(res[0]))
                    #exception .append("该号码" + phone.__str__() + "存在不一致工号" + str(login_id) + "和" + str(res[0]))
                    return
                try:
                    flag *= res[-2]
                except Exception as e:
                    flag = 0
                roleName = res[-1]
                shopid = res[3]
                print("login_id:%s  role:%s  shop_id:%s") % (login_id,
                                                             roleName, shopid)
            print "flag is :" + flag.__str__()

            if flag == -1:
                agent_type = '0'
                print("该账号只含客服角色")
            elif flag < -1:
                agent_type = '0,1'
                print("该账号同时包含客服和其他角色")
            elif flag > 1:
                agent_type = '1'
                print("该账号不含客服角色")
            else:
                print("我不知道这是咋地了")
                return
                #return
            #print("没有在线客服角色我还执行了")
            agentType = agent_type
            print "agentType will be " + agentType
            loginId = login_id.encode('utf8')  #result[0][0]
            #misassperId = quote((result[0][1]).encode('utf8'),safe=string.printable),params 如果是字符串拼接的用这个
            misassperId = (result[0][1]).encode('utf8')
            phone = (result[0][2]).encode('utf8')
            shop_id = (result[0][3])
            if shop_id == None:
                pass
            else:
                shop_id = (result[0][3]).encode('utf8')

            finalInfo = {
                'agentType': agentType,
                'loginId': loginId,
                'misassperId': misassperId,
                'phone': phone,
                'shopId': shop_id
            }
            return finalInfo
        else:
            print("该号码在基础域工号表不存在在线客服类角色:" + phone.__str__())
            return
示例#13
0
    def query(self, phone, kami, xiaodongxi):
        phone = phone.strip()
        result = []
        if re.match(r'1\d{10}$', phone):
            self.logger.info("我是手机号")
            module = int(phone[6:7])
            databaseNum = module % 5 + 1
            tableNum = (phone[-1])

            if module <= 4:
                cur = self.cur[0]
            else:
                cur = self.cur[1]

            sql = "select EXPIRE_TIME,BIND_NO as '领券号码' ,BIND_TIME as '领取时间', PCARD_PASSWD as '卡密' ,LIFECYCLE_ST as '状态' ,LOCK_TIME AS  '锁定时间',USE_TIME as '使用时间',USE_ORDER_ID as '充值订单号' from echnmarketdb%d.td_pcard_info_%s where bind_no ='%s' and PCARD_PASSWD=%s" % (
                databaseNum, tableNum, phone, kami)
            #logger.error(sql)
            # sql = "select BIND_NO, PCARD_PASSWD ,LIFECYCLE_ST ,BIND_TIME,USE_TIME,USE_DATE,TARGET_NO from echnmarketdb%d.td_pcard_info_%s where bind_no ='%s'" % (databaseNum, tableNum, phone)
        elif re.match(r'^[\w-]+@[0-9a-zA-Z-]{1,13}(\.\w{2,})+$', phone):

            self.logger.info("我是邮箱")
            cur = self.cur[1]
            #,TARGET_NO as '转赠号码'
            sql = "select BIND_NO as '领券号码' , PCARD_PASSWD as '卡密' ,LIFECYCLE_ST as '状态' ,BIND_TIME as '领取时间',USE_TIME as '使用时间'',USE_ORDER_ID as '充值订单号',BATCH_ID as '批次id'  from echnmarketdb.td_pcard_info_u where bind_no ='%s'" % (
                phone)
            #logger.error(sql)
        else:
            self.logger.error("号码格式不对:" + phone + ' 长度:' + str(len(phone)))
            self.falseCount += 1
            self.failedUser.append(phone)
            return
        #self.logger.error(sql)
        try:

            qryHead, qryResult = dbOper.qryData(cur, sql)

            if qryResult == [] or qryResult == None:
                self.falseCount += 1
                self.failedUser.append(phone)
                self.logger.error("No result for user:"******"'" + str(qryResult[i][ii]))

                #输出结果
                historyRuslt = open(historyResultFile,
                                    "a")  #记录查询历史的文件history,也可以用来存输出结果。
                result.append('|'.join(resulthead))  #首先写入头信息
                if xiaodongxi == 0:
                    print(sql)
                    time.sleep(0.001)
                    print('|'.join(resulthead))
                    historyRuslt.write(','.join(resulthead) + "\n")

                for i in range(0, len(resultbody)):
                    print('|'.join(
                        resultbody[i]))  #打印查询结果到控制台,logger.error 会打印时间戳,看起来乱
                    result.append('|'.join(resultbody[i]))
                    historyRuslt.write(','.join(resultbody[i]) + "\n")

                historyRuslt.close()

        except Exception as e:
            logger.exception("Exception Logged run")
            self.falseCount += 1
            self.failedUser.append(phone)
            self.logger.error(e)
            self.logger.error(
                "Phone:%s Failed to Query -------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
                % phone)
        return result  #这个返回,,以后可能有用。
示例#14
0
    def query(self,phone,xiaodongxi):
        phone =phone.strip()
        result =[]
        if re.match(r'1\d{10}$',phone):
            self.logger.info ("我是手机号")
            module = int(phone[6:7])
            databaseNum = module%5 + 1
            tableNum =(phone[-1])

            if  module <= 4 :
                cur =self.cur[0]
            else:
                cur =self.cur[1]

            sql = "select serial_NUMber, EXPIRE_TIME,BIND_NO as '领券号码' ,BIND_TIME as '领取时间', PCARD_PASSWD as '卡密' ,LIFECYCLE_ST as '状态' ,LOCK_TIME AS  '锁定时间',USE_TIME as '使用时间',USE_ORDER_ID as '充值订单号',TARGET_NO as '转赠号码',BATCH_ID as '批次id' from echnmarketdb%d.td_pcard_info_%s where bind_no ='%s'  " % (databaseNum, tableNum, phone)
            logger.error(sql)
            # sql = "select BIND_NO, PCARD_PASSWD ,LIFECYCLE_ST ,BIND_TIME,USE_TIME,USE_DATE,TARGET_NO from echnmarketdb%d.td_pcard_info_%s where bind_no ='%s'" % (databaseNum, tableNum, phone)
        elif re.match(r'^[\w-]+@[0-9a-zA-Z-]{1,13}(\.\w{2,})+$',phone):

            self.logger.info("我是邮箱")
            cur =self.cur[1]
            sql = "select BIND_NO as '领券号码' , PCARD_PASSWD as '卡密' ,LIFECYCLE_ST as '状态' ,BIND_TIME as '领取时间',USE_TIME as '使用时间'',USE_ORDER_ID as '充值订单号',TARGET_NO as '转赠号码',BATCH_ID as '批次id'  from echnmarketdb.td_pcard_info_u where bind_no ='%s'" % (phone)
            #logger.info(sql)
        else:
            self.logger.error("号码格式不对:"+phone+' 长度:'+str(len(phone)))
            self.falseCount += 1
            self.failedUser.append(phone)
            return
        #self.logger.error(sql)
        try:

            qryHead,qryResult = dbOper.qryData(cur, sql)
            if qryResult==[] or qryResult==None :
                self.falseCount += 1
                self.failedUser.append(phone)
                self.logger.error("No result for user:"******" select t.PCARD_NAME as '卡券类型',t.PCARD_INFO as '卡券信息', p.PCARD_NAME as '卡券名称',t.PCARD_CASH as '面额', p.PCARD_ACT_NAME as '活动名称' from echnmarketdb.td_def_pcard_batch t LEFT JOIN echnmarketdb.td_def_pcard_info p ON t.PCARD_ID=p.PCARD_ID where t.BATCH_ID ="+batchId
                    batchhead,batchResult = dbOper.qryData(self.cur[0], batchsql)

                    # 卡券信息head拼接,只拼接一次
                    if i == 0:
                        for j in range(0, len(batchhead)):
                            resulthead.append(str(batchhead[j]))
                    else:
                        pass


                    #用户卡券数据拼接
                    resultbody.append([]) #元素列表+1
                    for ii in range(0,len(qryResult[i])):
                        resultbody[i].append(str(qryResult[i][ii]))

                    #卡券信息body拼接

                    for k in range(0,len(batchResult[0])):
                        resultbody[i].append(str(batchResult[0][k]))


                #输出结果
                result.append('|'.join(resulthead))#首先写入头信息
                if xiaodongxi ==0 :
                    print(sql)
                    time.sleep(0.001)
                    print( '|'.join(resulthead))


                historyRuslt = open(historyResultFile, "a")#记录查询历史的文件history,也可以用来存输出结果。
                for i in range(0,len(resultbody)):
                    print('|'.join(resultbody[i]))#打印查询结果到控制台,logger.error 会打印时间戳,看起来乱
                    result.append('|'.join(resultbody[i]))
                    historyRuslt.write('|'.join(resultbody[i])+"\n")

                historyRuslt.close()




        except Exception as e:
            logger.exception("Exception Logged run")
            self.falseCount += 1
            self.failedUser.append(phone)
            self.logger.error(e)
            self.logger.error ("Phone:%s Failed to Query -------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"%phone)
        return result #这个返回,,以后可能有用。