Ejemplo n.º 1
0
def chooseBank(driver, detail):
    times = 0
    maxTimes = int(LOAD_PAGE_TIMEOUT / WHILE_WAIT_SLEEP)
    while times < maxTimes:
        time.sleep(ACTION_WAIT_SLEEP_LONG)
        select2ZzkmContainer = driver.find_element_by_id(
            'select2-zkm-container')
        if select2ZzkmContainer != None:
            break
        # elements = driver.find_elements_by_class_name('select2-selection')
        times = times + 1
        if times == maxTimes:
            log.e("等待弹出框超时——选择银行")
            return 1
        time.sleep(WHILE_WAIT_SLEEP)
        # ActionChains(driver).move_to_element(
        #     driver.find_element_by_class_name('sz-zkm')).click().perform()

        driver.find_element_by_class_name('sz-zkm').click()
    driver.find_element_by_id('select2-zkm-container').click()

    time.sleep(ACTION_WAIT_SLEEP_LONG)
    driver.find_element_by_class_name('select2-search__field').send_keys(
        detail.account_code)

    maxTimes = int(LOAD_PAGE_TIMEOUT / WHILE_WAIT_SLEEP)
    times = 0
    while times < maxTimes:
        result = driver.find_element_by_class_name(
            'select2-results__option').text
        if result == 'No results found':
            log.w('银行不存在', detail.account_code)

            driver.find_element_by_id('select2-zkm-container').click()

            time.sleep(ACTION_WAIT_SLEEP_SHORT)
            addNewBank(driver, detail.account_name)
            chooseBank(driver, detail)
        elif detail.account_code + '--' in driver.find_element_by_class_name(
                'select2-results__option').text:
            driver.switch_to.active_element.send_keys(Keys.DOWN)
            driver.switch_to.active_element.send_keys(Keys.ENTER)
            driver.find_element_by_id('zkm_sub').click()
            break
        times = times + 1
        time.sleep(WHILE_WAIT_SLEEP)
Ejemplo n.º 2
0
def waitNotice(driver, element):
    for i in range(10):
        try:
            element.tag_name
            alert = WebDriverWait(driver, 1, poll_frequency=0.2).until(
                lambda x: x.find_element_by_id("gritter-notice-wrapper"))
            log.w(alert.text)
            return 0
        except StaleElementReferenceException:
            # log.w('StaleElementReferenceException')
            return 1

        except TimeoutException:
            continue
        except:
            log.exception('凭证列表-批量处理等待异常')
            return 0
        time.sleep(0.1)
    log.w('凭证列表-批量处理等待超时')
    return 0
Ejemplo n.º 3
0
def main():
    # while 1:
    #     log.i('选择项目(crm,third,)','\n')
    #     table = input()
    #     if table == 'crm' or table == 'third':
    #         break
    while 1:
        log.i('输入id', '\n')
        id = input()
        try:
            id = int(id)
            break
        except:
            log.w('输入id转换失败\n')
    # log.i('参数:', table, str(id))
    ret, af, bf, msg = mySqlHelper.getThirdLog(id)
    if ret != 0:
        return 1
    log.i('参数:', af, bf)
    option = webdriver.ChromeOptions()
    option.add_argument('disable-infobars')
    driver = webdriver.Chrome(options=option)
    driver.set_window_size(config.window_size_w, config.window_size_h)
    driver.implicitly_wait(5)
    commonSelenium.toPage(driver, 'https://www.sojson.com/jsondiff.html')

    ActionChains(driver).move_to_element(
        driver.find_elements_by_class_name('CodeMirror-sizer')
        [0]).double_click().perform()
    commonSelenium.clearElement(driver.switch_to.active_element)
    pyperclip.copy(af)
    driver.switch_to.active_element.send_keys(Keys.Ct)

    ActionChains(driver).move_to_element(
        driver.find_elements_by_class_name('CodeMirror-sizer')
        [1]).double_click().perform()
    commonSelenium.clearElement(driver.switch_to.active_element)
    driver.switch_to.active_element.send_keys(bf)

    log.i('参数:', af, bf)
Ejemplo n.º 4
0
def waitToast(driver, functionName, successMsg):
    times = 0
    maxTimes = int(LOAD_PAGE_TIMEOUT / WHILE_WAIT_SLEEP)
    while times < maxTimes:
        try:
            alert = WebDriverWait(driver, 10, poll_frequency=0.2).until(
                lambda x: x.find_element_by_id("gritter-notice-wrapper"))
            # log.w(alert.text)
            if successMsg in alert.text:
                log.w(functionName, successMsg, alert.text)
                return 0
        except TimeoutException:
            log.w(functionName, 'TimeoutException')
            return 1
        except:
            log.exception(functionName)
            return 1

        times = times + 1
        if times == maxTimes:
            log.e(functionName, '等待超时')
            return 1
        time.sleep(WHILE_WAIT_SLEEP)
Ejemplo n.º 5
0
def run(driver):
    log.d('录入凭证')
    try:
        ret, documents, msg = read_documentInput()
        if ret != 0:
            log.e('加载凭证文件失败', msg)
            return 1
        if len(documents) == 0:
            log.w('加载凭证文件数量为0')
            return 1
        spCount = 0
        cpCount = 0
        nblzCount = 0
        for document in documents:
            if document[0].type == 1:
                spCount = spCount + 1
            if document[0].type == 2:
                cpCount = cpCount + 1
            if document[0].type == 3:
                nblzCount = nblzCount + 1

        document = documents[0]
        if commonSelenium.toPage(
                driver, config.domain +
                "/cs-third/cer/certificate/toCertificateInput"):
            log.w('加载凭证录入页面超时')
            return 1

        driver.find_element_by_id('uniformCreditCode').send_keys(
            config.caseTaxId)
        driver.find_element_by_id('currentDate').click()
        years = config.caseCurrentAccountYear - int(
            driver.find_elements_by_class_name('datepicker-switch')[1].text)

        if years < 0:
            for i in range(-1 * years):  # <<
                ActionChains(driver).move_to_element(
                    driver.find_elements_by_class_name('prev')
                    [1]).click().perform()
                time.sleep(ACTION_WAIT_SLEEP_SHORT)
        if years > 0:
            for i in range(years):  # >>
                ActionChains(driver).move_to_element(
                    driver.find_elements_by_class_name('next')
                    [1]).click().perform()
                time.sleep(ACTION_WAIT_SLEEP_SHORT)
        months = driver.find_elements_by_class_name('month')
        for month in months:
            if str(config.caseCurrentAccountMonth) in month.text:
                ActionChains(driver).move_to_element(month).click().perform()
                break
        isOpenOriginCertificate = 0
        isCsInfoFileUploadSp = 0
        isCsInfoFileUploadCp = 0
        isCsInfoFileUploadNblz = 0
        for documentIndex in range(len(documents)):

            document = documents[documentIndex]
            ActionChains(driver).move_to_element(
                driver.find_elements_by_class_name('iCheck-helper')[
                    document[0].type - 1]).click().perform()

            driver.find_element_by_class_name("btn-success").send_keys(
                Keys.ENTER)
            # print('原始凭证',driver.find_element_by_class_name('allcount').text.split('   ')[1] )

            if isOpenOriginCertificate == 0:  # 打开原始凭证
                isOpenOriginCertificate = 1
                driver.find_element_by_id("originCertificate").send_keys(
                    Keys.ENTER)
                driver.find_element_by_id(
                    "originCertificateConfirm").send_keys(Keys.ENTER)
                handles = driver.window_handles
                time.sleep(ACTION_WAIT_SLEEP_LONG)

                driver.switch_to.window(handles[0])
                # switch back to main screen

                time.sleep(ACTION_WAIT_SLEEP_LONG)
            count = int(
                driver.find_element_by_class_name('allcount').text.split('   ')
                [1][4:])

            if isCsInfoFileUploadSp == 0 and document[
                    0].type == 1 and count < spCount:
                isCsInfoFileUploadSp = 1
                log.w('原始凭证收票数量不足', '当前数量:', count, '需要数量', spCount)
                if csInfoFileUpload.run(config.caseTaxId, document[0].type,
                                        spCount - count):  # 文件上传失败
                    return 1
            if isCsInfoFileUploadCp == 0 and document[
                    0].type == 2 and count < cpCount:
                isCsInfoFileUploadCp = 1
                log.w('原始凭证出票数量不足', '当前数量:', count, '需要数量', cpCount)
                if csInfoFileUpload.run(config.caseTaxId, document[0].type,
                                        cpCount - count):  # 文件上传失败
                    return 1
            if isCsInfoFileUploadNblz == 0 and document[
                    0].type == 3 and count < nblzCount:
                isCsInfoFileUploadNblz = 1
                log.w('原始凭证内部流转数量不足', '当前数量:', count, '需要数量', nblzCount)
                if csInfoFileUpload.run(config.caseTaxId, document[0].type,
                                        nblzCount - count):  # 文件上传失败
                    return 1
            divBtn = driver.find_element_by_id('divBtn')
            ActionChains(driver).move_to_element(divBtn).perform()
            time.sleep(ACTION_WAIT_SLEEP_LONG)

            smallClasses = driver.find_elements_by_xpath(
                "//ul[@class = 'dropspan-ul']/li")
            for i in range(len(smallClasses)):
                ActionChains(driver).move_to_element(smallClasses[i]).perform()
                templates = driver.find_elements_by_xpath(
                    "//ul[@class = 'dropspan-ul']/li[" + str(i + 1) +
                    "]/ul/li")
                isbreak = 0
                for j in range(len(templates)):
                    if templates[j].text == document[0].TEMPLATED_NAME:
                        ActionChains(driver).move_to_element(
                            templates[j]).click().perform()
                        isbreak = 1
                        break
                if isbreak == 1:
                    break
                if i == len(smallClasses) - 1:
                    print('模板未找到', document[0].TEMPLATED_NAME)
                    return 1, '模板未找到', document[0].TEMPLATED_NAME
                time.sleep(ACTION_WAIT_SLEEP_SHORT)
            time.sleep(ACTION_WAIT_SLEEP_LONG)

            ret_getFile, dataTemplates, msg = getTemplateSubjectById(
                document[0].TEMPLATED_ID)
            if ret_getFile != 0 or len(dataTemplates) == 0:
                log.e('加载模板失败', msg)
                return 1
            # ActionChains(driver).move_to_element(
            #     driver.find_element_by_class_name('sz-zkm')).click().perform()
            # time.sleep(ACTION_WAIT_SLEEP_LONG)

            sj = 1
            hasBank = 0
            for detail in document:
                for template in dataTemplates:
                    isSum = 0
                    if template.kmCode in detail.account_code:
                        if (template.subjectType == 1 or template.subjectType
                                == 2) and template.jdType == 0:
                            isSum = 1
                        if template.subjectType == 3 and template.jdType == 1:
                            isSum = 1
                        if (template.subjectType == 4
                                or template.subjectType == 5) and sj == 1:
                            isSum = 1
                            sj == 0
                        id = 'ts' + str(template.tsId)
                        if isSum == 0:
                            elementInput = driver.find_element_by_id(id)
                            # if elementInput.text!='':
                            clearElement(elementInput)
                            if template.jdType == 0:
                                elementInput.send_keys(
                                    str(detail.credit_amount))
                            else:
                                elementInput.send_keys(str(
                                    detail.debit_amount))
                        # else:
                        if getFeatureCdByCode(template.kmCode) == 2:  # 银行
                            hasBank = 1
                            # sz_zkm=driver.find_element(By.CLASS_NAME,'sz-zkm')
                            sz_zkm = driver.find_element_by_class_name(
                                'sz-zkm')
                            print(
                                'location',
                                driver.find_element_by_class_name(
                                    'sz-zkm').location['x'],
                                driver.find_element_by_class_name(
                                    'sz-zkm').location['y'])
                            # mouseRightClick(driver,driver.find_element_by_class_name('sz-zkm').location['x'],
                            #       driver.find_element_by_class_name('sz-zkm').location['y'])
                            # driver.execute_script(
                            #     "arguments[0].setAttribute('style', arguments[1]);",
                            #     driver.find_element_by_class_name('sz-zkm'),
                            #     "border: 1px solid red;"  # 边框border:2px; red红色
                            # )
                            # ActionChains(driver).move_to_element(
                            #     driver.find_element_by_class_name('sz-zkm')).context_click().perform()
                            time.sleep(ACTION_WAIT_SLEEP_LONG)
                            driver.find_element_by_class_name('sz-zkm').click()
                            time.sleep(ACTION_WAIT_SLEEP_LONG)

                            try:
                                alert = WebDriverWait(
                                    driver, 1, poll_frequency=0.2).until(
                                        lambda x: x.find_element_by_id(
                                            "zkmNoData"))
                                log.w(alert.text)
                                if '暂无子科目数据' in alert.text and alert.is_displayed(
                                ):
                                    addNewBank(driver, detail.account_name)
                                else:

                                    chooseBank(driver, detail)

                            except TimeoutException:
                                log.w(alert.text)

                                chooseBank(driver, detail)

                            except:
                                log.exception('凭证录入-点击银行等待异常')
                                return 1
                        elif getFeatureCdByCode(
                                template.kmCode) == 4 or getFeatureCdByCode(
                                    template.kmCode) == 5:  # 往来
                            count = 0
                            # ActionChains(driver).move_to_element(
                            #     driver.find_element_by_class_name('sz-wldw')).click().perform()
                            element = driver.find_element_by_css_selector(
                                'div[class*="sz-wldw"]')
                            driver.execute_script("arguments[0].click();",
                                                  element)
                            # driver.find_element_by_class_name('sz-wldw').click()
                            time.sleep(ACTION_WAIT_SLEEP_LONG)
                            if hasBank == 1:
                                elements = driver.find_elements_by_class_name(
                                    'select2-selection')
                                times = 0
                                maxTimes = int(LOAD_PAGE_TIMEOUT /
                                               WHILE_WAIT_SLEEP)
                                while times < maxTimes:
                                    time.sleep(WHILE_WAIT_SLEEP)

                                    if len(elements) == 2:
                                        break
                                    elements = driver.find_elements_by_class_name(
                                        'select2-selection')
                                    times = times + 1
                                    if times == maxTimes:
                                        log.e("等待弹出框超时——选择往来")
                                        return 1
                                    time.sleep(WHILE_WAIT_SLEEP)
                                for i in range(len(elements)):
                                    aria_labelledby = elements[
                                        i].get_attribute('aria-labelledby')
                                    if aria_labelledby == 'select2-wldw-container':
                                        ActionChains(driver).move_to_element(
                                            elements[i]).click().perform()
                            else:
                                select2_selection = driver.find_element_by_class_name(
                                    'select2-selection')
                                ActionChains(driver).move_to_element(
                                    driver.find_element_by_class_name(
                                        'select2-selection')).click().perform(
                                        )

                            time.sleep(ACTION_WAIT_SLEEP_LONG)
                            driver.find_element_by_class_name(
                                'select2-search__field').send_keys(
                                    detail.partner_name)
                            time.sleep(ACTION_WAIT_SLEEP_LONG)
                            times = 0
                            maxTimes = int(LOAD_PAGE_TIMEOUT /
                                           WHILE_WAIT_SLEEP)
                            while times < maxTimes:
                                partner = driver.find_element_by_class_name(
                                    'select2-results__option').text
                                if detail.partner_name == partner or '公司--' + detail.partner_name == partner:
                                    driver.switch_to.active_element.send_keys(
                                        Keys.DOWN)
                                    driver.switch_to.active_element.send_keys(
                                        Keys.ENTER)
                                    break
                                if partner == 'No results found':
                                    log.w('往来单位不存在', detail.partner_name)

                                    ActionChains(driver).move_to_element(
                                        driver.find_element_by_class_name(
                                            'select2-selection')).click(
                                            ).perform()

                                    time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
                                    driver.find_element_by_id(
                                        'wldw_add_sub').click()

                                    time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
                                    driver.find_element_by_id(
                                        'partnerName').send_keys(
                                            detail.partner_name)

                                    time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
                                    driver.find_element_by_id(
                                        'add_wldw_sub').click()

                                    time.sleep(config.ACTION_WAIT_SLEEP_LONG)
                                    if detail.partner_name not in driver.find_element_by_class_name(
                                            'select2-selection').text:

                                        log.i('添加往来_关联科目失败',
                                              detail.partner_name)
                                        return 1
                                    # waitToast(driver,'新增往来单位','保存成功')
                                    break
                                times = times + 1
                                if times == maxTimes:
                                    log.e(documentIndex, '录入凭证——添加往来等待超时',
                                          detail.document_id)
                                    return 1
                                time.sleep(WHILE_WAIT_SLEEP)

                            time.sleep(ACTION_WAIT_SLEEP_LONG)
                            driver.find_element_by_id('wldw_sub').click()
            currentImgIdOld = driver.get_cookie('current_img_id')['value']
            driver.find_element_by_id("remark").send_keys("selenium 录入")

            time.sleep(ACTION_WAIT_SLEEP_LONG)
            driver.find_element_by_id('save').click()

            time.sleep(ACTION_WAIT_SLEEP_LONG)
            times = 0
            maxTimes = int(LOAD_PAGE_TIMEOUT / WHILE_WAIT_SLEEP)
            while times < maxTimes:
                try:
                    alert = WebDriverWait(driver, 1, poll_frequency=0.2).until(
                        lambda x: x.find_element_by_id("gritter-notice-wrapper"
                                                       ))
                    # log.w(alert.text)
                    if '保存成功' in alert.text:
                        log.i(documentIndex, '录入凭证成功')
                        break

                except TimeoutException:
                    pass
                except:
                    log.exception('录入凭证异常')
                    return 1
                currentImgIdNew = driver.get_cookie('current_img_id')['value']

                log.d('点击保存等待', times, 'currentImgIdNew', currentImgIdNew,
                      'currentImgIdOld', currentImgIdOld)
                if currentImgIdNew != currentImgIdOld:
                    # print('currentImgIdNew', currentImgIdNew, 'currentImgIdOld', currentImgIdOld)
                    log.i(documentIndex, '录入凭证成功', detail.document_id)
                    break
                times = times + 1
                if times == maxTimes:
                    log.e(documentIndex, '录入凭证保存等待超时', detail.document_id)
                    return 1
                time.sleep(WHILE_WAIT_SLEEP)

            time.sleep(ACTION_WAIT_SLEEP_LONG)

        log.i('录入凭证结束')
        return 0
    except BaseException as e:
        r = requests.get(driver.current_url, allow_redirects=False)
        log.exception('录入凭证异常', r.status_code)
        return 1
Ejemplo n.º 6
0
def run(driver):
    log.d('资产负债表')
    dictsApi = {}
    try:
        params = {
            'origin': 'zidh',
            'taxNo': config.caseTaxId,
            'year': config.caseCurrentAccountYear,
            'month': config.caseCurrentAccountMonth
        }

        log.i('API 资产负债表获取', config.domain_api)
        response = requests.get(config.domain_api + '/api/report/balancesheet',
                                params=params,
                                allow_redirects=False)
        response.encoding = 'utf-8'
        if response.status_code == 200:
            ret = json.loads(response.text)
            if str(ret['code']) == '200':
                dictsApi = ret['data']
            else:

                log.e('API 资产负债表获取失败:', response.text)
                return 1
        else:
            log.e('API 资产负债表获取失败HTTP:', response.status_code)
            return 1
        log.i('API 资产负债表获取成功')
        if toThird.run(driver, config.caseCompanyName, config.caseTaxId):
            time.sleep(config.FAIL_WAIT_SLEEP)
            return 1
        if commonSelenium.toPage(
                driver,
                config.domain + "/cs-third/cer/balanceSheet/balanceSheetList"):
            return 1

        driver.find_element_by_id('currentDate').click()
        time.sleep(config.ACTION_WAIT_SLEEP_LONG)

        months = driver.find_elements_by_class_name('month')
        for month in months:
            if str(config.caseCurrentAccountMonth) + '月' in month.text:
                ActionChains(driver).move_to_element(month).click().perform()
                time.sleep(config.ACTION_WAIT_SLEEP_LONG)
                break

        time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
        shutil.rmtree(config.FILE_DOWNLOAD)
        os.mkdir(config.FILE_DOWNLOAD)
        driver.find_element_by_id('downloadBtn').click()
        times = 0
        maxTimes = int(config.LOAD_PAGE_TIMEOUT / config.WHILE_WAIT_SLEEP)
        while times < maxTimes:
            time.sleep(config.ACTION_WAIT_SLEEP_LONG)
            if '数据导出并下载成功' in driver.find_element_by_class_name(
                    'bootbox-body').text:
                btns = driver.find_elements_by_class_name('btn-primary')
                for btn in btns:
                    if btn.text == "OK":
                        btn.click()
                break
            if times == maxTimes:
                log.e("资产负债表-资产负债表下载超时")
                return 1
            times = times + 1

            log.w("资产负债表-资产负债表下载等待", times)
        time.sleep(config.ACTION_WAIT_SLEEP_LONG)
        time.sleep(config.ACTION_WAIT_SLEEP_LONG)
        retCode, dictsDownload = excelTools.read_balanceSheetList()
        if retCode != 0:
            time.sleep(config.FAIL_WAIT_SLEEP)
            log.e('资产负债表下载失败:')
            return 1
        if len(dictsDownload) != len(dictsApi) - 1:
            log.e('API资产负债表数量与下载数量不一致 dictsDownload:', str(len(dictsDownload)),
                  'listsApi:', str(len(dictsApi)))

            return 1

        time.sleep(config.ACTION_WAIT_SLEEP_LONG)

        time.sleep(config.ACTION_WAIT_SLEEP_LONG)
        rows = driver.find_elements_by_xpath(
            "//table[@id='customerTable']/tbody/tr")
        for i in range(len(rows)):
            if i < 1:
                continue
            tdsSum = rows[i].find_elements_by_tag_name("td")

            if tdsSum[1].text != '' and tdsSum[1].text != '11':
                line = tdsSum[1].text
                qm = tdsSum[2].text.replace(',', '')
                nc = tdsSum[3].text.replace(',', '')
                # log.e('tdsSum[1]:\t', line)
                if dictsApi['r' + line + 'qm'] == dictsDownload[
                        'r' + line + 'qm'] == qm == '' and dictsApi[
                            'r' + line + 'nc'] == dictsDownload[
                                'r' + line + 'nc'] == nc == '':
                    pass
                elif not (float(dictsApi['r' + line + 'qm']) == float(
                        dictsDownload['r' + line + 'qm']) == float(qm)
                          and float(dictsApi['r' + line + 'nc']) == float(
                              dictsDownload['r' + line + 'nc']) == float(nc)):
                    log.e('比较失败——行次', line, '\n页面:\t'
                          '期末余额', qm, '年初余额', nc, '\nAPI:\t',
                          dictsApi['r' + line + 'qm'], '年初余额',
                          dictsApi['r' + line + 'nc'], '\n文件:\t',
                          dictsDownload['r' + line + 'qm'], '年初余额',
                          dictsDownload['r' + line + 'nc'])

                    return 1
                # else:
                #     log.d('行次',line,'期末余额', qm, '年初余额', nc )
            if tdsSum[5].text != '':
                line = tdsSum[5].text
                qm = tdsSum[6].text.replace(',', '')
                nc = tdsSum[7].text.replace(',', '')

                # log.e('tdsSum[5]:\t', line)
                if dictsApi['r' + line + 'qm'] == dictsDownload[
                        'r' + line + 'qm'] == qm == '' and dictsApi[
                            'r' + line + 'nc'] == dictsDownload[
                                'r' + line + 'nc'] == nc == '':
                    pass
                elif not (float(dictsApi['r' + line + 'qm']) == float(
                        dictsDownload['r' + line + 'qm']) == float(qm)
                          and float(dictsApi['r' + line + 'nc']) == float(
                              dictsDownload['r' + line + 'nc']) == float(nc)):
                    log.e('比较失败——行次', line, '\n页面:\t'
                          '期末余额', qm, '年初余额', nc, '\nAPI:\t',
                          dictsApi['r' + line + 'qm'], '年初余额',
                          dictsApi['r' + line + 'nc'], '\n文件:\t',
                          dictsDownload['r' + line + 'qm'], '年初余额',
                          dictsDownload['r' + line + 'nc'])

                    return 1
                # else:
                #     log.d('行次', line, '期末余额', qm, '年初余额', nc)
        if dictsApi['r30qm'] != dictsApi['r53qm'] or dictsApi[
                'r30nc'] != dictsApi['r53nc']:
            log.e('资产负债不平衡')

            return 1
        log.i('资产负债表页面接口对比通过')
        return 0
    except:

        r = requests.get(driver.current_url, allow_redirects=False)
        log.exception('资产负债表', r.status_code)

        return 1
Ejemplo n.º 7
0
def runBack(driver):
    log.d('反结账')
    try:
        if toThird.run(driver, config.caseCompanyName, config.caseTaxId):
            time.sleep(config.FAIL_WAIT_SLEEP)
            return 1
        if commonSelenium.toPage(
                driver,
                config.domain + "/cs-third/st/settle/toSettleAccounts"):
            return 1
        lastSettleDate = driver.find_element_by_class_name('marked_words').text

        if lastSettleDate == '上次结账: 无数据':
            log.i(lastSettleDate, '测试会计月:', config.caseCurrentAccountMonth)
            return 0
        lastSettleDate = lastSettleDate.replace('上次结账至:', '')
        driver.find_element_by_id('dateTime').click()
        time.sleep(config.ACTION_WAIT_SLEEP_LONG)
        # years = document[0].year - int(driver.find_elements_by_class_name('datepicker-switch')[1].text)
        #
        # if years < 0:
        #     for i in range(-1 * years):  # <<
        #         ActionChains(driver).move_to_element(driver.find_elements_by_class_name('prev')[1]).click().perform()
        #         time.sleep(ACTION_WAIT_SLEEP_SHORT)
        # if years > 0:
        #     for i in range(years):  # >>
        #         ActionChains(driver).move_to_element(driver.find_elements_by_class_name('next')[1]).click().perform()
        #         time.sleep(ACTION_WAIT_SLEEP_SHORT)

        lastSettleYear = int(lastSettleDate.split('-')[0])
        lastSettleMonth = int(lastSettleDate.split('-')[1])
        months = driver.find_elements_by_class_name('month')
        if config.caseCurrentAccountYear * 100000 + config.caseCurrentAccountMonth <= lastSettleYear * 100000 + lastSettleMonth:

            for month in months:
                if str(lastSettleMonth) + '月' in month.text:
                    ActionChains(driver).move_to_element(
                        month).click().perform()
                    times = 0
                    maxTimes = int(config.LOAD_PAGE_TIMEOUT /
                                   config.WHILE_WAIT_SLEEP)
                    while times < maxTimes:
                        time.sleep(config.ACTION_WAIT_SLEEP_LONG)

                        if driver.find_element_by_id('checkBtn').text == '反结账':
                            driver.find_element_by_id('checkBtn').click()

                            time.sleep(config.ACTION_WAIT_SLEEP_LONG)
                            alert = driver.find_element_by_class_name(
                                'bootbox-body')

                            if alert.text == '反结账成功':
                                log.i("反结账成功", str(lastSettleDate), '月')
                                btns = driver.find_elements_by_class_name(
                                    'btn-primary')
                                for btn in btns:
                                    if btn.text == 'OK':
                                        btn.click()
                                if runBack(driver) == 0:
                                    return 0

                        else:
                            log.w(driver.find_element_by_id('checkBtn').text)
                        times = times + 1
                        if times == maxTimes:
                            log.e('反结账月份选择后等待超时')
                            return 1
        else:
            log.w(lastSettleDate, "反结账")
            return 0

        return 1

    except:
        r = requests.get(driver.current_url, allow_redirects=False)
        log.exception('反结账', r.status_code)

        return 1
Ejemplo n.º 8
0
def run(driver):
    log.d('结账')
    try:
        if toThird.run(driver, config.caseCompanyName, config.caseTaxId):
            time.sleep(config.FAIL_WAIT_SLEEP)
            return 1
        if commonSelenium.toPage(
                driver,
                config.domain + "/cs-third/st/settle/toSettleAccounts"):
            return 1

        lastSettleMonth = driver.find_element_by_class_name(
            'marked_words').text
        if lastSettleMonth != '上次结账: 无数据' and int(
                lastSettleMonth.split('-')
            [1]) >= config.caseCurrentAccountMonth:
            log.w(lastSettleMonth, "不需结账")
            return 0
        driver.find_element_by_id('checkBtn').click()

        times = 0
        maxTimes = int(config.LOAD_PAGE_TIMEOUT / config.WHILE_WAIT_SLEEP)
        while times < maxTimes:
            time.sleep(config.ACTION_WAIT_SLEEP_LONG)

            if driver.find_element_by_id('checkBtn').text == '继续结账':
                driver.find_element_by_id('checkBtn').click()

                time.sleep(config.ACTION_WAIT_SLEEP_LONG)
                alert = driver.find_element_by_class_name('bootbox-body')

                if alert.text == '结账成功':
                    log.i("结账成功")
                    btns = driver.find_elements_by_class_name('btn-primary')
                    for btn in btns:
                        if btn.text == 'OK':
                            btn.click()
                    return 0
                else:

                    log.i("结账成功22222", alert.text)
            elif driver.find_element_by_id('checkBtn').text == '重新检查':

                log.e("马上检查未通过")
                lis = driver.find_elements_by_xpath(
                    "//div[@class='ckPannel']/div[3]/div/ul/li")
                for i in range(len(lis)):
                    li = driver.find_element_by_xpath(
                        "//div[@class='ckPannel']/div[3]/div/ul/li[" +
                        str(i + 1) + "]/i")
                    if li.get_attribute('class') == 'describe_i error':
                        log.w(
                            driver.find_element_by_xpath(
                                "//div[@class='ckPannel']/div[3]/div/ul/li[" +
                                str(i + 1) + "]/span[1]").text,
                            driver.find_element_by_xpath(
                                "//div[@class='ckPannel']/div[3]/div/ul/li[" +
                                str(i + 1) + "]/span[2]").text)
                return 1
            if times == maxTimes:
                log.e("结账失败-马上检查超时")
                return 1
            times = times + 1

    except:
        r = requests.get(driver.current_url, allow_redirects=False)
        log.exception('结账', r.status_code)

        return 1
Ejemplo n.º 9
0
def run():
    CONN_RATE_THRESHOLD = 50  # 数据库连接使用率(%)50
    CREATE_PZ_WAIT_COUNT_THRESHOLD = 20  # 自动创建凭证积压时间(分钟)20
    HE_HE_WAIT_TIME_THRESHOLD = 120  # 合合识别积压时间(分钟)120
    PDF_WAIT_THRESHOLD = 30  # 凭证生成pdf等待数量 30
    SLEEP = 300  # 执行周期(秒)300
    while True:
        mailMsg = ''
        hour = datetime.now().hour
        if hour > 6 and hour < 21:

            log.i('数据库状态监控' + '\n数据库连接使用率警告阈值(%)' + str(CONN_RATE_THRESHOLD) +
                  '\n自动创建凭证积压时间警告阈值(分钟)' +
                  str(CREATE_PZ_WAIT_COUNT_THRESHOLD) + '\n合合识别积压时间警告阈值(分钟)' +
                  str(HE_HE_WAIT_TIME_THRESHOLD) + '\n凭证生成pdf等待数量警告阈值' +
                  str(PDF_WAIT_THRESHOLD) + '\n执行周期(秒)' + str(SLEEP) + '\n')
            try:
                retCode, warnMsg = checkConn(CONN_RATE_THRESHOLD)
                if retCode != 0:
                    # log.w(warnMsg)
                    mailMsg = mailMsg + warnMsg + '\n'
                else:

                    log.d(warnMsg)
                retCode, minutes, msg = mySqlHelper.getUnCreateWaitTime()
                if retCode != 0:
                    mailMsg = mailMsg + '自动生成凭证等待查询出错 :' + msg + '\n'
                elif retCode == 0 and minutes > CREATE_PZ_WAIT_COUNT_THRESHOLD:

                    mailMsg = mailMsg + "自动生成凭证等待时间\t" + str(minutes) + '分钟\n'
                else:
                    log.d("自动生成凭证等待时间\t" + str(minutes) + '分钟')

                retCode, minutes, msg = mySqlHelper.getUnHeHeWaitTime()
                if retCode != 0:
                    mailMsg = mailMsg + '合合识别积压查询出错 :' + msg + '\n'
                elif retCode == 0 and minutes > HE_HE_WAIT_TIME_THRESHOLD:
                    mailMsg = mailMsg + "合合识别等待时间\t" + str(minutes) + '分钟\n'
                else:
                    log.d("合合识别等待时间\t" + str(minutes) + '分钟')

                retCode, count, msg = mySqlHelper.getUnPdfCount()
                if retCode != 0:
                    # log.w(warnMsg)
                    mailMsg = mailMsg + '凭证生成pdf积压查询出错 :' + msg + '\n'
                elif retCode == 0 and count > PDF_WAIT_THRESHOLD:
                    log.w('pdfCount:', count)
                    mailMsg = mailMsg + "凭证生成pdf积压数量\t" + str(count) + '\n'
                else:
                    log.d("凭证生成pdf积压数量\t" + str(count))
                # retCode, msg = loadByHeaders('20171009-102958-845')
                # if retCode != 200:
                #     log.w('status_code:', retCode, 'msg:', msg)
                #     mailMsg = mailMsg + "third调用 code:" + str(retCode) + "  " + msg + '\n'
                retCode, msg = pageStatus()
                if retCode != 0:
                    # log.w(warnMsg)
                    mailMsg = mailMsg + '页面调用出错 :' + msg + '\n'

                if len(mailMsg) > 0:
                    mail.send("财税警告", mailMsg)
                    log.e("财税警告", mailMsg)
                else:
                    log.i('状态正常\n')
            except:
                # exc_type, exc_obj, exc_tb = sys.exc_info()
                # fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
                # print(exc_type, fname, exc_tb.tb_lineno)
                msg = log.exception('状态监控异常')

                mail.send("财税警告_状态监控异常", msg)
        time.sleep(SLEEP)
Ejemplo n.º 10
0
def runDelete(driver):
    log.d('原始凭证-删除凭证')
    try:

        if commonSelenium.toPage(
                driver, config.domain +
                "/cs-third/cer/certificate/toCertificateInput"):
            log.w('加载凭证录入页面超时')
            return 1

        driver.find_element_by_id('uniformCreditCode').send_keys(
            config.caseTaxId)
        driver.find_element_by_id('currentDate').click()
        years = config.caseCurrentAccountYear - int(
            driver.find_elements_by_class_name('datepicker-switch')[1].text)

        if years < 0:
            for i in range(-1 * years):  # <<
                ActionChains(driver).move_to_element(
                    driver.find_elements_by_class_name('prev')
                    [1]).click().perform()
                time.sleep(ACTION_WAIT_SLEEP_SHORT)
        if years > 0:
            for i in range(years):  # >>
                ActionChains(driver).move_to_element(
                    driver.find_elements_by_class_name('next')
                    [1]).click().perform()
                time.sleep(ACTION_WAIT_SLEEP_SHORT)
        months = driver.find_elements_by_class_name('month')
        for month in months:
            if str(config.caseCurrentAccountMonth) in month.text:
                ActionChains(driver).move_to_element(month).click().perform()
                break
        isOpenOriginCertificate = 0
        for type in range(3):

            ActionChains(driver).move_to_element(
                driver.find_elements_by_class_name('iCheck-helper')
                [type]).click().perform()

            driver.find_element_by_class_name("btn-success").send_keys(
                Keys.ENTER)
            count = int(
                driver.find_element_by_class_name('allcount').text.split('   ')
                [1][4:])

            if count == 0:
                continue
            mainWindow = driver.current_window_handle  # 保存主页面句柄

            if isOpenOriginCertificate == 0:  # 打开原始凭证
                isOpenOriginCertificate = 1
                driver.find_element_by_id("originCertificate").send_keys(
                    Keys.ENTER)
                driver.find_element_by_id(
                    "originCertificateConfirm").send_keys(Keys.ENTER)

                time.sleep(ACTION_WAIT_SLEEP_LONG)

            toHandle = driver.window_handles
            for handle in toHandle:
                if handle == mainWindow:
                    continue
                driver.switch_to.window(handle)

            for i in range(count):
                driver.find_element_by_class_name('delete').click()

                times = 0
                maxTimes = int(config.LOAD_PAGE_TIMEOUT /
                               config.WHILE_WAIT_SLEEP)
                while times < maxTimes:
                    time.sleep(config.ACTION_WAIT_SLEEP_LONG)
                    btn = driver.switch_to.active_element
                    if btn.tag_name == 'button' and btn.text == 'OK':

                        btn.click()
                        break
                    if times == maxTimes:
                        log.e("原始凭证-删除凭证等待确认超时")
                        return 1
                    times = times + 1
                time.sleep(ACTION_WAIT_SLEEP_LONG)
            driver.close()
            isOpenOriginCertificate = 0
            driver.switch_to.window(mainWindow)
            time.sleep(config.ACTION_WAIT_SLEEP_LONG)

        log.i('原始凭证-删除凭证结束')
        return 0
    except BaseException as e:
        r = requests.get(driver.current_url, allow_redirects=False)
        log.exception('原始凭证-删除凭证异常', r.status_code)
        return 1
Ejemplo n.º 11
0
def run(driver):
    log.d('新增凭证')
    ret, documents, msg = read_documentAdd()
    if ret != 0:
        log.e('加载凭证文件失败', msg)
        return 1
    if len(documents) == 0:
        log.w('加载凭证文件数量为0')
        return 1
    # if toThird.run(driver, documents[0][0].company_name, documents[0][0].tax_id):
    if toThird.run(driver, config.caseCompanyName, config.caseTaxId):
        print('进账簿失败', ret)
        return 1
    if toPage(driver,
              config.domain + "/cs-third/cer/certificate/toAddCertificate"):
        return 1
    # alertDiv = driver.find_element_by_id('alertDiv')
    # startX = alertDiv.location['x'] + 100 + 135
    # startY = alertDiv.location['y'] + 150

    for document in documents:

        # mouseLeftDoubleClick(driver, startX, startY)
        # driver.find_element_by_class_name('zy-text').d
        # driver.find_elements_by_class_name('zy-text')[0].

        time.sleep(config.ACTION_WAIT_SLEEP_LONG)
        ActionChains(driver).move_to_element(
            driver.find_elements_by_class_name('zy-text')
            [0]).double_click().perform()
        time.sleep(config.ACTION_WAIT_SLEEP_LONG)
        for index in range(len(document)):
            documentDetail = document[index]
            clearElement(driver.switch_to.active_element)
            driver.switch_to.active_element.send_keys(documentDetail.summary)
            driver.switch_to.active_element.send_keys(Keys.TAB)

            driver.switch_to.active_element.send_keys(
                documentDetail.account_code)

            elements = driver.find_elements_by_class_name(
                'select2-results__option')
            if len(elements) == 0:
                log.e('科目不存在', documentDetail.account_code)
                return 1
            for element in elements:
                if element.text.split(' ')[0] == documentDetail.account_code:
                    element.click()
            # driver.switch_to.active_element.send_keys(Keys.TAB)
            if documentDetail.partner_name != '\\N':  # 往来类型
                time.sleep(config.ACTION_WAIT_SLEEP_LONG)
                # driver.find_element_by_id('select2-wldw-container').click()
                time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
                ActionChains(driver).move_to_element(
                    driver.find_element_by_id(
                        'select2-wldw-container')).click().perform()

                time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
                driver.find_element_by_class_name(
                    'select2-search__field').send_keys(
                        documentDetail.partner_name)
                elements = driver.find_elements_by_class_name(
                    'select2-results__option')
                if len(elements) == 0 or (len(elements) == 1
                                          and elements[0].text
                                          == 'No results found'):
                    log.w('往来单位不存在', documentDetail.account_code,
                          documentDetail.partner_name)

                    driver.find_element_by_id('add_wldw').click()

                    time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
                    driver.find_element_by_id('partnerName').send_keys(
                        documentDetail.partner_name)

                    time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
                    driver.find_element_by_id('add_wldw_sub').click()
                    # return 1
                else:
                    for element in elements:
                        if element.text == documentDetail.partner_name:
                            element.click()

                driver.find_element_by_id('wldw_sub').click()

            time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
            # driver.switch_to.active_element.send_keys(Keys.TAB)
            if documentDetail.debit_amount != '\\N':  # 钱在借方
                elements = driver.find_elements_by_class_name('jf-je-text')
                time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
                elements[index].click()
                clearElement(driver.switch_to.active_element)
                driver.switch_to.active_element.send_keys(
                    str(documentDetail.debit_amount))  # 如果钱在借方。 tab时直接换行
            else:
                elements = driver.find_elements_by_class_name('df-je-text')
                time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
                elements[index].click()
                # clearElement(driver.switch_to.active_element)  # 清空借方默认金额
                # driver.switch_to.active_element.send_keys(Keys.TAB)
                clearElement(driver.switch_to.active_element)
                driver.switch_to.active_element.send_keys(
                    str(documentDetail.credit_amount))
            if (index != len(document) - 1):
                driver.switch_to.active_element.send_keys(Keys.TAB)

        time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
        driver.find_element_by_id('btn_xzpz_add_and_save').send_keys(
            Keys.ENTER)
        time.sleep(config.ACTION_WAIT_SLEEP_SHORT)
        times = 0
        maxTimes = int(LOAD_PAGE_TIMEOUT / WHILE_WAIT_SLEEP)
        while (times < maxTimes):
            if ('零元整' == driver.find_element_by_id('hjjesx').text):
                break
            times = times + 1
            if times == maxTimes:
                log.e('新增凭证保存等待 超时')
                return 1
            time.sleep(WHILE_WAIT_SLEEP)

    log.i('新增凭证完成')
    return 0
Ejemplo n.º 12
0
def set_host(host):
    global domain
    global domain_cs_info
    global domain_api
    global dbHost
    global dbPort
    global dbUser
    global dbPasswd
    global dbPlatform
    global dbLog
    global hostSource
    hostSource = host
    if host==HOST_SOURCE_ON_LINE:

        log.i('设置环境参数-生产环境')
        domain = 'http://sstax.cn:1000/'

        domain_cs_info = 'http://sstax.cn:1000/'
        domain_api = 'http://sstax.cn:1000/'
        dbHost = '222.73.99.99'
        dbPort = 3030
        dbUser = '******'
        dbPasswd = 'Pwd!2018@db'
        dbPlatform = 'cs_platform'
        dbLog = 'cs-log'
    elif host==HOST_SOURCE_PRE:


        log.i('设置环境参数-预发布环境')
        # domain = 'http://pre.sstax.cn:81/'
        # domain = 'http://61.153.190.93:18080'
        # domain_cs_info = 'http://61.153.190.93:18080'
        # domain_cs_info = 'pre.sstax.cn:81'
        domain = 'http://101.89.137.10:48080'
        domain_cs_info = 'http://101.89.137.10:48080'
        # domain_api = 'http://pre.sstax.cn:81'
        domain_api = 'http://sstax.cn:1000/'
        dbHost = '222.73.99.99'
        dbPort = 3031
        dbUser = '******'
        dbPasswd = 'Pwd2018db'
        dbPlatform = 'pre_cs_platform'

        dbLog = 'pre-cs-log'
    elif host == HOST_SOURCE_ON_XI_AN:


        log.i('设置环境参数-西安环境')
        domain = 'http://101.89.137.10:48080'
        domain_cs_info = 'http://101.89.137.10:48080'
        # domain_api = 'http://pre.sstax.cn:81'
        domain_api = 'http://sstax.cn:1000/'
        dbHost = '222.73.99.99'
        dbPort = 3031
        dbUser = '******'
        dbPasswd = 'Pwd2018db'
        dbPlatform = 'pre_cs_platform'

        dbLog = 'pre-cs-log'
    elif host == HOST_SOURCE_ON_YUN_NAN:

        log.i('设置环境参数-云南环境')
        domain = 'http://61.153.190.93:18080'
        domain_cs_info = 'http://61.153.190.93:18080'
        domain_api = 'http://61.153.190.93:18080/'
        dbHost = '222.73.99.99'
        dbPort = 3031
        dbUser = '******'
        dbPasswd = 'Pwd2018db'
        dbPlatform = 'pre_cs_platform'
        dbLog = 'pre-cs-log'
    elif host == HOST_SOURCE_ON_JIN_KAI_QU:

        log.i('设置环境参数-金开区环境')
        domain = 'http://101.91.230.16:28080'
        domain_cs_info = 'http://101.91.230.16:28080'
        domain_api = 'http://101.91.230.16:28080/'
        dbHost = '222.73.99.99'
        dbPort = 3031
        dbUser = '******'
        dbPasswd = 'Pwd2018db'
        dbPlatform = 'pre_cs_platform'
        dbLog = 'pre-cs-log'
    elif host == HOST_SOURCE_ON_NAN_CHANG:

        log.i('设置环境参数-南昌环境')
        domain = 'http://183.134.73.180:18080'
        domain_cs_info ='http://183.134.73.180:18080'
        domain_api = 'http://183.134.73.180:18080'
        dbHost = '222.73.99.99'
        dbPort = 3031
        dbUser = '******'
        dbPasswd = 'Pwd2018db'
        dbPlatform = 'pre_cs_platform'
        dbLog = 'pre-cs-log'
    else:
        log.w('未设置环境参数 ')

        hostSource = None
    dbHost = '222.73.99.99'
    dbPort = 3030
    dbUser = '******'
    dbPasswd = 'Pwd!2018@db'
    dbPlatform = 'fs-admin'
    dbLog = 'cs-log'