Example #1
0
    def test_project_update_projectName_success(self):
        '''修改项目名称'''
        project_list = ProjectSelect().project_select(projectStatus='0',projectName=self.projectName).json()[
            'content'][ 'dataList']
        if project_list != [] and len(project_list) == 1:
            for project in project_list:
                self.customerId = project['custId']
        else:
            self.logger.error('Please check the results of the project for error')

        self.projectName_update = '修改项目'
        project_update_list = ProjectSelect().project_select(projectStatus='0', projectName=self.projectName_update).json()[
            'content']['dataList']
        if project_update_list != [] and len(project_update_list) == 1:
            sql = 'DELETE FROM YD_TMS_PROJECT WHERE projectName = \'{0}\'and partnerNo = \'{1}\''.format(
                self.projectName_update, self.config['partnerNo'])
            self.DBUtil = DBUtil(host=self.config['db_host'], port=self.config['db_port'],
                                 user=self.config['db_user'], passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'], charset=self.config['db_charset'])
            self.DBUtil.execute_sql(sql)
        else:
            self.logger.error('Please check the results of the project for error')

        response = ProjectUpdate().project_update(projectId=self.projectId,updateType='1',
                                                  projectName=self.projectName_update,custId=self.customerId,
                                                  startTime =self.startTime,endTime=self.endTime)
        self.logger.info('修改项目名称返回状态码:{0}'.format(response))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['code'], 0)
        self.logger.info('修改项目名称返回:{0}'.format(response.json()))
        response_get = ProjectGet().project_get(self.projectId)
        self.assertEqual(self.projectName_update, response_get.json()['content']['projectName'], 'Project updated fail!')
Example #2
0
 def is_have_payment_select_waybill(self, driver, driverConfirm='1'):
     '''司机是否有支付查询的运单'''
     try:
         driver_mobile = self.select_driver_mobile(driver)
         self.DBUtil = DBUtil(host=self.config['db_host'],
                              port=self.config['db_port'],
                              user=self.config['db_user'],
                              passwd=self.config['db_passwd'],
                              dbname=self.config['db_dbname'],
                              charset=self.config['db_charset'])
         sql = 'SELECT t.id FROM YD_APP_TRANSPORTCASH t ' \
               'LEFT JOIN YD_TMS_PAY_DETAIL pd ON t.id = pd.wayBillId ' \
               'WHERE (t.partnerNo =\'{0}\' AND t.mobile = \'{1}\' AND t.delStatus = 0 ' \
               'AND t.driverConfirm = {2}))) ORDER BY t.id desc'.format(self.config['partnerNo'], driver_mobile, driverConfirm)
         waybillId = self.DBUtil.excute_select_one_record(sql)
         sql2 = 'SELECT t.id, t.tmsBillCode FROM YD_APP_TRANSPORTCASH t ' \
               'LEFT JOIN YD_TMS_PAY_DETAIL pd ON t.id = pd.wayBillId ' \
               'WHERE (t.partnerNo =\'{0}\' AND t.mobile = \'{1}\' AND t.delStatus = 0 ' \
               'AND t.driverConfirm = {2}))) ORDER BY t.id desc'.format(self.config['partnerNo'], driver_mobile,
                                                                        driverConfirm)
         tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
         return waybillId, tmsBillCode, driver_mobile
     except Exception as e:
         self.logger.error('司机是否有支付查询的运单发生异常:{0}'.format(e))
         return None
Example #3
0
class CompanyProject(object):
    def __init__(self):
        self.logger = Log()
        self.config = ReadYaml(FileUtil.getProjectObsPath() +
                               '/config/config.yaml').getValue()
        self.db = DBUtil(host=self.config['Mysql_host'],
                         port=self.config['Mysql_port'],
                         user=self.config['Mysql_user'],
                         passwd=self.config['Mysql_passwd'],
                         dbname=self.config['Mysql_dbname'],
                         charset=self.config['Mysql_charset'])
        self.today = str(datetime.date.today())
        self.endDate = str(datetime.date.today() + datetime.timedelta(days=1))
        self.partnerNo = self.config['partnerNo']

    def select_project(self):
        sql = 'SELECT projectId, projectName FROM YD_TMS_PROJECT where partnerNo = \'{0}\' '.format(
            self.config['partnerNo'])
        project_list = self.db.execute_select_many_record(sql)[0]
        return project_list

    def add_project(self):
        header = HeaderDict().wuliuyun_header()
        url = 'https://{0}/api/tms/customer/addProject'.format(
            self.config['tms_api_host'])
        body_dict = {
            "projectName": "自动化测试",  # 项目名称,必填,长度大于0不超过20的字符串,唯一性校验:一个公司下的项目名唯一
            "custId": '',  # 客户ID,非必填
            "startTime": self.today,  # 开始日期,必填,格式:'yyyy-MM-dd'
            "endTime": self.endDate  # 结束日期,必填,格式:'yyyy-MM-dd'
        }
        try:
            response = HttpClient().post_json(url=url,
                                              header_dict=header,
                                              body_dict=body_dict)
            self.logger.info('#####  请求消息头:{0}  #####'.format(
                response.request.headers))
            self.logger.info('#####  请求消息体:{0}  #####'.format(
                response.request.body))
            self.logger.info('#####  返回消息体:{0}  #####'.format(response.json()))
            return response
        except Exception as error:
            self.logger.info(
                '####  发生错误:{0}  ####\t\t####  返回None  ####'.format(error))
            return None

    def get_project(self):
        projects_list = self.select_project()
        if projects_list:
            # 更新项目有效时间,使项目生效,返回生效项目列表
            project_id = projects_list[0]
            sql = 'UPDATE YD_TMS_PROJECT set endTime=\'{0}\'  where partnerNo = \'{1}\' and projectId = \'{2}\''.format(
                self.endDate, self.config['partnerNo'], project_id)
            self.db.execute_sql(sql)
            the_project = self.select_project()
            return the_project
        else:
            self.add_project()
            the_project = self.select_project()
            return the_project
Example #4
0
 def is_have_completed_waybill(self, driver, driverConfirm=''):
     '''司机是否有已完成的运单'''
     try:
         driver_mobile = self.select_driver_mobile(driver)
         self.DBUtil = DBUtil(host=self.config['db_host'],
                              port=self.config['db_port'],
                              user=self.config['db_user'],
                              passwd=self.config['db_passwd'],
                              dbname=self.config['db_dbname'],
                              charset=self.config['db_charset'])
         if driverConfirm == '0' or driverConfirm == '1':
             sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'C\' and ' \
                   'delStatus = \'0\' and partnerNo = \'{1}\' and driverConfirm = \'{2}\' ORDER BY id desc'.format(
                    driver_mobile, self.config['partnerNo'], driverConfirm)
             waybillId = self.DBUtil.excute_select_one_record(sql)
             sql2 = 'SELECT tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'C\' and ' \
                    'delStatus = \'0\' and partnerNo = \'{1}\' and driverConfirm = \'{2}\' ORDER BY id desc'.format(
                     driver_mobile, self.config['partnerNo'], driverConfirm)
             tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
         else:
             sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'C\' and ' \
                   'delStatus = \'0\' and partnerNo = \'{1}\' ORDER BY id desc'.format(driver_mobile, self.config['partnerNo'])
             waybillId = self.DBUtil.excute_select_one_record(sql)
             sql2 = 'SELECT tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'C\' and ' \
                    'delStatus = \'0\' and partnerNo = \'{1}\' ORDER BY id desc'.format(driver_mobile, self.config['partnerNo'])
             tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
         self.logger.info(
             '查询司机是否有已完成的运单query result, waybillId:{0},tmsBillCode:{1}'.
             format(waybillId, tmsBillCode))
         return waybillId, tmsBillCode, driver_mobile
     except Exception as e:
         self.logger.error('司机是否有已完成的运单发生异常:{0}'.format(e))
         return None
Example #5
0
class CreateCustomer(object):
    '''新增客户'''
    def __init__(self):
        self.logger = Log()
        self.config = ReadYaml(FileUtil.getProjectObsPath() +
                               '/config/config.yaml').getValue()

    def create_customer(self, customerName, customerCode, phone,
                        customerDeveloper):
        '''新增客户'''
        try:
            response = CustomerCreate().customer_create(
                customerName=customerName,
                customerCode=customerCode,
                phone=phone,
                customerDeveloper=customerDeveloper)
            self.logger.info('新增的客户名称是: {0}'.format(customerName))
            # 判断客户名称和客户编号是否重复
            if response.json()['code'] == 0:
                return response.json()['content']
            elif response.json()['code'] == 9020103:
                sql = 'DELETE FROM YD_TMS_CUSTOMER WHERE customerName = \'{0}\' and partnerNo = \'{1}\''.format(
                    customerName, self.config['partnerNo'])
                self.DBUtil = DBUtil(host=self.config['db_host'],
                                     port=self.config['db_port'],
                                     user=self.config['db_user'],
                                     passwd=self.config['db_passwd'],
                                     dbname=self.config['db_dbname'],
                                     charset=self.config['db_charset'])
                self.DBUtil.execute_sql(sql)
                customerId = CustomerCreate().customer_create(
                    customerName=customerName,
                    customerCode=customerCode,
                    phone=phone,
                    customerDeveloper=customerDeveloper).json()['content']
                return customerId
            elif response.json()['code'] == 9020104:
                sql = 'DELETE FROM YD_TMS_CUSTOMER WHERE customerCode = \'{0}\'and partnerNo = \'{1}\''.format(
                    customerCode, self.config['partnerNo'])
                self.DBUtil = DBUtil(host=self.config['db_host'],
                                     port=self.config['db_port'],
                                     user=self.config['db_user'],
                                     passwd=self.config['db_passwd'],
                                     dbname=self.config['db_dbname'],
                                     charset=self.config['db_charset'])
                self.DBUtil.execute_sql(sql)
                customerId = CustomerCreate().customer_create(
                    customerName=customerName,
                    customerCode=customerCode,
                    phone=phone,
                    customerDeveloper=customerDeveloper).json()['content']
                return customerId
            else:
                self.logger.info('新增客户返回错误:{0}'.format(response.json()))
                return None
        except Exception as e:
            self.logger.error('新增客户发生异常:{0}'.format(e))
            return None
Example #6
0
 def __init__(self):
     self.config = ReadYaml(FileUtil.getProjectObsPath() +
                            '/config/config.yaml').getValue()
     self.db = DBUtil(host=self.config['Mysql_host'],
                      port=self.config['Mysql_port'],
                      user=self.config['Mysql_user'],
                      passwd=self.config['Mysql_passwd'],
                      dbname=self.config['Mysql_dbname'],
                      charset=self.config['Mysql_charset'])
Example #7
0
 def delete_waybill(self):
     # 删除待发车运单
     db = DBUtil(host=self.config['Mysql_host'],
                 port=self.config['Mysql_port'],
                 user=self.config['Mysql_user'],
                 passwd=self.config['Mysql_passwd'],
                 dbname=self.config['Mysql_dbname'],
                 charset=self.config['Mysql_charset'])
     sql = 'UPDATE YD_APP_TRANSPORTCASH SET delStatus = 1 where mobile = \'{0}\' AND partnerNo = \'{1}\' AND billStatus = \'W\' AND delStatus = 0'.format(
         self.mobile, self.partnerNo)
     db.execute_sql(sql)
Example #8
0
 def query_waybill_status(self,tmsBillCode):
     '''查询运单状态'''
     try:
         self.DBUtil = DBUtil(host=self.config['db_host'], port=self.config['db_port'],
                              user=self.config['db_user'], passwd=self.config['db_passwd'],
                              dbname=self.config['db_dbname'], charset=self.config['db_charset'])
         sql = 'SELECT transStatus FROM YD_APP_TRANSPORTCASH WHERE tmsBillCode = \'{0}\''.format(tmsBillCode)
         trans_status = self.DBUtil.excute_select_one_record(sql)
         return trans_status
     except Exception as e:
         self.logger.error('查询运单状态发生异常:{0}'.format(e))
         return None
Example #9
0
class TestProjectUpdate(unittest.TestCase):
    '''修改项目'''
    def setUp(self):
        self.logger = Log()
        self.config = ReadYaml(FileUtil.getProjectObsPath() + '/config/config.yaml').getValue()
        self.logger.info('########################### TestProjectUpdate START ###########################')
        self.projectName = '测试项目'
        self.startTime = time.strftime('%Y-%M-%d')
        self.endTime = time.strftime('%Y-%m-%d', time.localtime(time.time() + 86400))
        self.customerName = '测试之家'
        self.customerCode = 'CSZJ201710200001'
        self.phone = DataUtil().createmoble()
        self.projectId = CreateProject().create_project(self.projectName,self.startTime,self.endTime,self.customerName,
                                                        self.customerCode,self.phone,'黄经理')


    def tearDown(self):
        self.logger.info('############################ TestProjectUpdate END ############################')


    def test_project_update_projectName_success(self):
        '''修改项目名称'''
        project_list = ProjectSelect().project_select(projectStatus='0',projectName=self.projectName).json()[
            'content'][ 'dataList']
        if project_list != [] and len(project_list) == 1:
            for project in project_list:
                self.customerId = project['custId']
        else:
            self.logger.error('Please check the results of the project for error')

        self.projectName_update = '修改项目'
        project_update_list = ProjectSelect().project_select(projectStatus='0', projectName=self.projectName_update).json()[
            'content']['dataList']
        if project_update_list != [] and len(project_update_list) == 1:
            sql = 'DELETE FROM YD_TMS_PROJECT WHERE projectName = \'{0}\'and partnerNo = \'{1}\''.format(
                self.projectName_update, self.config['partnerNo'])
            self.DBUtil = DBUtil(host=self.config['db_host'], port=self.config['db_port'],
                                 user=self.config['db_user'], passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'], charset=self.config['db_charset'])
            self.DBUtil.execute_sql(sql)
        else:
            self.logger.error('Please check the results of the project for error')

        response = ProjectUpdate().project_update(projectId=self.projectId,updateType='1',
                                                  projectName=self.projectName_update,custId=self.customerId,
                                                  startTime =self.startTime,endTime=self.endTime)
        self.logger.info('修改项目名称返回状态码:{0}'.format(response))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['code'], 0)
        self.logger.info('修改项目名称返回:{0}'.format(response.json()))
        response_get = ProjectGet().project_get(self.projectId)
        self.assertEqual(self.projectName_update, response_get.json()['content']['projectName'], 'Project updated fail!')
Example #10
0
 def select_waybill(self):
     # 查找待发车运单
     db = DBUtil(host=self.config['Mysql_host'],
                 port=self.config['Mysql_port'],
                 user=self.config['Mysql_user'],
                 passwd=self.config['Mysql_passwd'],
                 dbname=self.config['Mysql_dbname'],
                 charset=self.config['Mysql_charset'])
     sql = 'SELECT * from YD_APP_TRANSPORTCASH where mobile = \'{0}\' AND partnerNo = \'{1}\' AND billStatus = \'W\' AND delStatus = 0'.format(
         self.mobile, self.partnerNo)
     waybill = db.execute_select_one_record(sql)
     if waybill:
         return waybill[0]
Example #11
0
 def __init__(self):
     self.logger = Log()
     self.config = ReadYaml(FileUtil.getProjectObsPath() +
                            '/config/config.yaml').getValue()
     self.db = DBUtil(host=self.config['Mysql_host'],
                      port=self.config['Mysql_port'],
                      user=self.config['Mysql_user'],
                      passwd=self.config['Mysql_passwd'],
                      dbname=self.config['Mysql_dbname'],
                      charset=self.config['Mysql_charset'])
     self.today = str(datetime.date.today())
     self.endDate = str(datetime.date.today() + datetime.timedelta(days=1))
     self.partnerNo = self.config['partnerNo']
    def jump_waybill_submit(self,
                            project='',
                            driver='',
                            supplier='',
                            index='1',
                            totalAmt='1000',
                            income='2000',
                            preAmt='0.01',
                            oilAmt='0.01',
                            destAmt='0.01',
                            lastAmt='0.01',
                            photoAirWay='',
                            content=''):
        '''创建运单'''
        waybillId, tmsBillCode, driver_mobile = ISHaveWaybill(
        ).is_have_wait_departure_waybill(driver=driver)
        # 判断是否存在未发车的运单
        if waybillId != None:
            self.logger.info("存在未发车确认的运单ID:{0}".format(waybillId))
            DepartureConfirmApi().departure_confirm_api(str(waybillId[0]))

        self.input_default_field(project, index, totalAmt, income, preAmt,
                                 oilAmt, destAmt, lastAmt, photoAirWay,
                                 content)
        # 选择司机、车辆
        HeplerWaybill().set_value_select_input(self.driver, "id->realName",
                                               driver)
        # 选择供应商
        HeplerWaybill().set_value_select_input(
            self.driver, 'id->TMS-billModel-supplierName', supplier)
        # 输入有无回单
        self.driver.select('id->TMS-billModel-hasReceipt',
                           "index->{0}".format(index))
        self.submit()

        # 获取创建运单运单号、运单ID
        self.DBUtil = DBUtil(host=self.config['db_host'],
                             port=self.config['db_port'],
                             user=self.config['db_user'],
                             passwd=self.config['db_passwd'],
                             dbname=self.config['db_dbname'],
                             charset=self.config['db_charset'])
        sql1 = 'SELECT airWayBillNo ,tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and billStatus = \'W\' ' \
               'and delStatus = \'0\' and partnerNo = \'{1}\''.format(driver_mobile, self.config['partnerNo'])
        waybillId, tmsBillCode = self.DBUtil.excute_select_one_record(sql1)
        return waybillId, tmsBillCode
Example #13
0
 def create_order_submit(self,
                         project='',
                         orderRemark='',
                         upOrderPlanNo=''):
     '''创建订单'''
     self.input_order(project=project,
                      orderRemark=orderRemark,
                      upOrderPlanNo=upOrderPlanNo)
     self.create_order_confirm()
     # 获取创建运单的订单号
     self.DBUtil = DBUtil(host=self.config['db_host'],
                          port=self.config['db_port'],
                          user=self.config['db_user'],
                          passwd=self.config['db_passwd'],
                          dbname=self.config['db_dbname'],
                          charset=self.config['db_charset'])
     sql = 'SELECT planNo FROM YD_TMS_ORDERPLAN WHERE orderStatus = \'0\' and partnerNo = \'{0}\''.format(
         self.config['partnerNo'])
     planNo = self.DBUtil.excute_select_one_record(sql)
     return planNo
 def create_project(self, projectName, startTime, endTime, customerName,
                    customerCode, phone, customerDeveloper):
     '''新增项目'''
     try:
         customerId = CreateCustomer().create_customer(
             customerName=customerName,
             customerCode=customerCode,
             phone=phone,
             customerDeveloper=customerDeveloper)
         response = ProjectCreate().project_create(projectName=projectName,
                                                   custId=customerId,
                                                   startTime=startTime,
                                                   endTime=endTime)
         self.logger.info('新增的项目名称是: {0}'.format(projectName))
         # 判断项目名称是否重复
         if response.json()['code'] == 0:
             return response.json()['content']
         elif response.json()['code'] == 9020502:
             sql = 'DELETE FROM YD_TMS_PROJECT WHERE projectName = \'{0}\'and partnerNo = \'{1}\''.format(
                 projectName, self.config['partnerNo'])
             self.DBUtil = DBUtil(host=self.config['db_host'],
                                  port=self.config['db_port'],
                                  user=self.config['db_user'],
                                  passwd=self.config['db_passwd'],
                                  dbname=self.config['db_dbname'],
                                  charset=self.config['db_charset'])
             self.DBUtil.execute_sql(sql)
             projectId = ProjectCreate().project_create(
                 projectName=projectName,
                 custId=customerId,
                 startTime=startTime,
                 endTime=endTime).json()['content']
             return projectId
         else:
             self.logger.info('新增的项目名称返回错误:{0}'.format(response.json()))
             return None
     except Exception as e:
         self.logger.error('新增项目发生异常:{0}'.format(e))
         return None
Example #15
0
 def is_have_payment_departure_waybill(self, driver, driverConfirm='1'):
     '''司机是否有可发车支付的运单'''
     try:
         driver_mobile = self.select_driver_mobile(driver)
         self.DBUtil = DBUtil(host=self.config['db_host'],
                              port=self.config['db_port'],
                              user=self.config['db_user'],
                              passwd=self.config['db_passwd'],
                              dbname=self.config['db_dbname'],
                              charset=self.config['db_charset'])
         sql = 'SELECT t.id FROM YD_APP_TRANSPORTCASH t ' \
               'LEFT JOIN YD_TMS_PAY_DETAIL pd ON t.id = pd.wayBillId ' \
               'WHERE (t.partnerNo =\'{0}\' AND t.mobile = \'{1}\' AND t.delStatus = 0 ' \
               'AND t.billStatus != \'W\' AND t.billStatus != \'Q\' ' \
               'AND (pd.cashPayStatus = \'UNPAID\' OR pd.cashPayStatus = \'FAIL\') ' \
               'AND (((pd.cashLoanSchedule != \'FAIL\' OR pd.cashLoanSchedule IS NULL) ' \
               'AND (pd.oilFeeLoanSchedule != \'FAIL\' OR pd.oilFeeLoanSchedule IS NULL) ' \
               'AND (pd.destAmtLoanSchedule != \'FAIL\' OR pd.destAmtLoanSchedule IS NULL) ' \
               'AND (pd.retAmtLoanSchedule != \'FAI\L\' OR pd.retAmtLoanSchedule IS NULL)' \
               'AND t.driverConfirm = {2}))) ORDER BY t.id desc'.format(self.config['partnerNo'],driver_mobile,driverConfirm)
         waybillId = self.DBUtil.excute_select_one_record(sql)
         sql2 = 'SELECT t.tmsBillCode FROM YD_APP_TRANSPORTCASH t ' \
               'LEFT JOIN YD_TMS_PAY_DETAIL pd ON t.id = pd.wayBillId ' \
               'WHERE (t.partnerNo =\'{0}\' AND t.mobile = \'{1}\' AND t.delStatus = 0 ' \
               'AND t.billStatus != \'W\' AND t.billStatus != \'Q\' ' \
               'AND (pd.cashPayStatus = \'UNPAID\' OR pd.cashPayStatus = \'FAIL\') ' \
               'AND (((pd.cashLoanSchedule != \'FAIL\' OR pd.cashLoanSchedule IS NULL) ' \
               'AND (pd.oilFeeLoanSchedule != \'FAIL\' OR pd.oilFeeLoanSchedule IS NULL) ' \
               'AND (pd.destAmtLoanSchedule != \'FAIL\' OR pd.destAmtLoanSchedule IS NULL) ' \
               'AND (pd.retAmtLoanSchedule != \'FAI\L\' OR pd.retAmtLoanSchedule IS NULL)' \
               'AND t.driverConfirm = {2}))) ORDER BY t.id desc'.format(self.config['partnerNo'], driver_mobile, driverConfirm)
         tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
         self.logger.info(
             '查询司机是否有可发车支付的运单query result, waybillId:{0},tmsBillCode:{1}'.
             format(waybillId, tmsBillCode))
         return waybillId, tmsBillCode, driver_mobile
     except Exception as e:
         self.logger.error('机是否有可发车支付的运单发生异常:{0}'.format(e))
         return None
    def create_waybill_submit(self,
                              project='',
                              driver='',
                              supplier='',
                              index='1',
                              totalAmt='1000',
                              income='2000',
                              preAmt='0.01',
                              oilAmt='0.01',
                              destAmt='0.01',
                              lastAmt='0.01',
                              photoAirWay='',
                              content=''):
        '''创建运单'''
        waybillId, tmsBillCode, driver_mobile = ISHaveWaybill(
        ).is_have_wait_departure_waybill(driver=driver)
        # 判断是否存在未发车的运单
        if waybillId != None:
            self.logger.info("已认证外请车存在未发车确认的运单ID:{0}".format(waybillId))
            DepartureConfirmApi().departure_confirm_api(str(waybillId[0]))

        # 创建运单
        self.input_fee_car_waybill(project, driver_mobile, supplier, index,
                                   totalAmt, income, preAmt, oilAmt, destAmt,
                                   lastAmt, photoAirWay, content)
        self.create_waybill_confirm()

        # 获取创建运单运单号、运单ID
        self.DBUtil = DBUtil(host=self.config['db_host'],
                             port=self.config['db_port'],
                             user=self.config['db_user'],
                             passwd=self.config['db_passwd'],
                             dbname=self.config['db_dbname'],
                             charset=self.config['db_charset'])
        sql = 'SELECT airWayBillNo ,tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and billStatus = \'W\' ' \
              'and delStatus = \'0\' and partnerNo = \'{1}\''.format(driver_mobile, self.config['partnerNo'])
        waybillId, tmsBillCode = self.DBUtil.excute_select_one_record(sql)
        return waybillId, tmsBillCode
Example #17
0
 def is_have_wait_departure_waybill(self, driver):
     '''查询司机是否有未发车的运单'''
     try:
         driver_mobile = self.select_driver_mobile(driver)
         self.DBUtil = DBUtil(host=self.config['db_host'],
                              port=self.config['db_port'],
                              user=self.config['db_user'],
                              passwd=self.config['db_passwd'],
                              dbname=self.config['db_dbname'],
                              charset=self.config['db_charset'])
         sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'D\' and ' \
               'delStatus = \'0\' and partnerNo = \'{1}\''.format(driver_mobile, self.config['partnerNo'])
         waybillId = self.DBUtil.excute_select_one_record(sql)
         sql2 = 'SELECT tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'D\' and ' \
                'delStatus = \'0\' and partnerNo = \'{1}\''.format(driver_mobile, self.config['partnerNo'])
         tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
         self.logger.info(
             '查询司机是否有未发车的运单query result, waybillId:{0},tmsBillCode:{1}'.
             format(waybillId, tmsBillCode))
         return waybillId, tmsBillCode, driver_mobile
     except Exception as e:
         self.logger.error('查询司机是否有未发车的运单发生异常:{0}'.format(e))
         return None
Example #18
0
class QueryWaybill(object):
    '''查询运单'''
    def __init__(self):
        self.config = ReadYaml(FileUtil.getProjectObsPath() + '/config/config.yaml').getValue()
        self.logger = Log()

    def query_waybill_status(self,tmsBillCode):
        '''查询运单状态'''
        try:
            self.DBUtil = DBUtil(host=self.config['db_host'], port=self.config['db_port'],
                                 user=self.config['db_user'], passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'], charset=self.config['db_charset'])
            sql = 'SELECT transStatus FROM YD_APP_TRANSPORTCASH WHERE tmsBillCode = \'{0}\''.format(tmsBillCode)
            trans_status = self.DBUtil.excute_select_one_record(sql)
            return trans_status
        except Exception as e:
            self.logger.error('查询运单状态发生异常:{0}'.format(e))
            return None
Example #19
0
class DbOperation(object):
    def __init__(self):
        self.config = ReadYaml(FileUtil.getProjectObsPath() +
                               '/config/config.yaml').getValue()
        self.db = DBUtil(host=self.config['Mysql_host'],
                         port=self.config['Mysql_port'],
                         user=self.config['Mysql_user'],
                         passwd=self.config['Mysql_passwd'],
                         dbname=self.config['Mysql_dbname'],
                         charset=self.config['Mysql_charset'])

    def select_driver_info(self, mobile):
        data_dict = {}
        sql = 'SELECT idNo,name,isCertifacate,pyAuthFlag,carNo,isCarCertificate from YD_APP_USER where mobile = \'{0}\' and source = \'register\''.format(
            mobile)
        data = self.db.execute_select_one_record(sql)
        data_dict['idNo'] = data[0]
        data_dict['name'] = data[1]
        data_dict['isCertifacate'] = data[2]
        data_dict['AuthFlag'] = data[3]
        data_dict['carNo'] = data[4]
        data_dict['isCarCertificate'] = data[5]
        return data_dict

    def initialize_driver_info(self, mobile):
        sql = 'UPDATE `YD_APP_USER` SET `carNo`=NULL, `idNo`=NULL, `name`=NULL, `portraitId`=NULL, `coreLoginId`=NULL,' \
              ' `custId`=\'0\', `isCarCertificate`=NULL, `isCardBindFlag`=NULL, `isCertifacate`=NULL, `portrait`=NULL,' \
              ' `pyAuthFlag`=NULL, `pyAuthResult`=NULL, `clientId`=NULL, `introducerPhone`=NULL WHERE (`mobile`=\'{0}\'' \
              ' and `source`=\'register\')'.format(mobile)
        self.db.execute_sql(sql)

    def update_driver_info(self):
        custId = self.config['custId_unregister']
        mobile = self.config['mobile_unregister']
        name = self.config['name_unregister']
        idNo = self.config['idNo_unregister']
        sql = 'UPDATE `YD_APP_USER` SET `carNo`=NULL, `idNo`={0}, `name`=\'{1}\', `portraitId`=NULL, `coreLoginId`={0},' \
              ' `custId`={2}, `isCarCertificate`=NULL, `isCardBindFlag`=NULL, `isCertifacate`=\'Y\', `portrait`=NULL,' \
              ' `pyAuthFlag`=\'0\', `pyAuthResult`=NULL, `clientId`=NULL, `introducerPhone`=NULL WHERE (`mobile`={3}' \
              ' and `source`=\'register\')'.format(idNo, name, custId, mobile)
        self.db.execute_sql(sql)

    def certificate_driver_info(self, mobile):
        custId = self.config['custId_unregister']
        name = self.config['name_unregister']
        idNo = self.config['idNo_unregister']
        sql = 'UPDATE `YD_APP_USER` SET `carNo`=\'皖A12345\', `idNo`={0}, `name`=\'{1}\', `portraitId`=NULL, `coreLoginId`={0},' \
              ' `custId`={2}, `isCarCertificate`=\'Y\', `isCardBindFlag`=NULL, `isCertifacate`=\'Y\', `portrait`=NULL,' \
              ' `pyAuthFlag`=\'0\', `pyAuthResult`=NULL, `clientId`=NULL, `introducerPhone`=NULL WHERE (`mobile`={3}' \
              ' and `source`=\'register\')'.format(idNo, name, custId, mobile)
        self.db.execute_sql(sql)

    def select_wallet_state(self, mobile):
        # 查询手机号已开通钱包个数
        sql_select = 'select COUNT(*) FROM YD_APP_MYBANK_OPEN_ACCOUNT where mobile = \'{0}\' and accountOpened = 1'.format(
            mobile)
        state = self.db.execute_select_one_record(sql_select)[0]
        return state

    def delete_wallet_driver(self, mobile):
        sql_select = 'SELECT id from YD_APP_MYBANK_OPEN_ACCOUNT where mobile =\'{0}\''.format(
            mobile)
        ids = self.db.execute_select_many_record(sql_select)
        if ids:
            for id in ids:
                sql_del = 'DELETE FROM `YD_APP_MYBANK_OPEN_ACCOUNT` WHERE id=\'{0}\' '.format(
                    id[0])
                self.db.execute_sql(sql_del)

    def delete_waybill_driver(self, mobile):
        sql_select = 'SELECT id from YD_APP_TRANSPORTCASH where mobile = {0} and delStatus = 0'.format(
            mobile)
        waybill_list = self.db.execute_select_many_record(sql_select)
        for waybill_id in waybill_list:
            id = waybill_id[0]
            sql_del = 'UPDATE YD_APP_TRANSPORTCASH SET delStatus = 1 WHERE id = {0}'.format(
                id)
            self.db.execute_sql(sql_del)

    def select_waybill_state(self, mobile):
        # 返回运单状态数组
        sql_select = 'SELECT billStatus from YD_APP_TRANSPORTCASH where mobile = {0} and delStatus = 0 and partnerNo = \'jUTViKluU\''.format(
            mobile)
        state = self.db.execute_select_one_record(sql_select)
        return state

    def add_wallet_consignor(self, mobile):
        sql_select = 'SELECT loginId from YD_APP_USER where mobile = {0} and source = \'register\''.format(
            mobile)
        loginId = self.db.execute_select_one_record(sql_select)[0]
        sql_consignor = 'SELECT id FROM YD_APP_PAYMENT_RECEIVER WHERE loginId = \'{}\' ORDER BY id DESC LIMIT 1'.format(
            loginId)
        consignor_id = self.db.execute_select_one_record(sql_consignor)
        if consignor_id:
            sql_update = 'UPDATE YD_APP_PAYMENT_RECEIVER SET isAvailable = 1 , isDelete = 0 WHERE id = {0}'.format(
                consignor_id[0])
            self.db.execute_sql(sql_update)
        else:
            sql_insert = 'INSERT INTO YD_APP_PAYMENT_RECEIVER (`createDate`, `isOpenPayMent`, `loginId`, `receiverId`, ' \
                         '`receiverIdNo`, `receiverMobile`, `receiverName`, `receiverRelation`, `updateDate`, `comfirm`, ' \
                         '`isAvailable`, `receiverLoginId`, `isDelete`) VALUES (\'2018-11-01 15:16:18\', NULL, \'{0}\', ' \
                         'NULL, \'320621199210280523\', \'18020329066\', \'王燕\', \'其它\', NULL, 1, 1, ' \
                         '\'APP20170418150043iFVLP\', \'0\')'.format(loginId)
            self.db.execute_insert_sql(sql_insert)

    def delete_wallet_consignor(self, mobile):
        sql_select = 'SELECT loginId from YD_APP_USER where mobile = {0} and source = \'register\''.format(
            mobile)
        loginId = self.db.execute_select_one_record(sql_select)[0]
        sql_consignor = 'SELECT id from YD_APP_PAYMENT_RECEIVER where loginId = \'{0}\' and isAvailable = 1 and isDelete = 0'.format(
            loginId)
        consignor_list = self.db.execute_select_many_record(sql_consignor)
        for id in consignor_list:
            sql_delete = 'UPDATE YD_APP_PAYMENT_RECEIVER SET isAvailable = 0,isDelete = 1 WHERE id = {0}'.format(
                id[0])
            self.db.execute_sql(sql_delete)

    def update_wallet_card_state(self, mobile):
        sql_select = 'SELECT c.id from YD_APP_MYBANK_OPEN_ACCOUNT a LEFT JOIN YD_APP_USER b on a.loginId = b.loginId  LEFT JOIN YD_APP_MYBANK_BIND_CARD c on a.mybankId = c.mybankId where b.mobile = \'{}\' ORDER BY c.id DESC LIMIT 1'.format(
            mobile)
        card_id = self.db.execute_select_one_record(sql_select)[0]
        sql_update = 'UPDATE YD_APP_MYBANK_BIND_CARD SET ifBindCardSuccess = 1, isUsable = 1 WHERE id = {}'.format(
            card_id)
        self.db.execute_sql(sql_update)

    def shipper_bankcard_del(self, shipper_mobile):
        # 将用户已绑定银行卡设置为失效
        sql_select = 'SELECT a.id from YD_APP_SPECIAL_BANK_BIND a LEFT JOIN YD_APP_APPROVAL_USER b on a.loginId = b.loginId where b.mobile = \'{0}\''.format(
            shipper_mobile)
        bankcard_ids = self.db.execute_select_many_record(sql_select)
        if bankcard_ids:
            for card_id in bankcard_ids:
                sql_update = 'UPDATE YD_APP_SPECIAL_BANK_BIND SET  cardStatus=\'N\' WHERE (id=\'{0}\')'.format(
                    card_id[0])
                self.db.execute_sql(sql_update)

    def shipper_bankcard_add(self, shipper_mobile):
        # 将用户之前绑定的第一张银行卡设置为生效
        sql_select = 'SELECT a.id from YD_APP_SPECIAL_BANK_BIND a LEFT JOIN YD_APP_APPROVAL_USER b on a.loginId = b.loginId where b.mobile = \'{0}\''.format(
            shipper_mobile)
        bankcard_ids = self.db.execute_select_many_record(sql_select)
        if bankcard_ids:
            sql_update = 'UPDATE YD_APP_SPECIAL_BANK_BIND SET  cardStatus=\'V\' WHERE (id=\'{0}\')'.format(
                bankcard_ids[0][0])
            self.db.execute_sql(sql_update)
        else:
            sql_insert = 'INSERT INTO YD_APP_SPECIAL_BANK_BIND (`acctName`, `bankCity`, `bankName`, `bankPrinc`, `cardName`, `cardNo`, `cardStatus`, `cardType`, `createTime`, `idNo`, `idType`, `loginId`, `logoUrl`, `mobile`, `orgCode`, `subbranchBankName`, `bank`) VALUES (\'刘新宇\', \'340100\', \'建设银行\', \'340000\', \'龙卡通\', \'6217001630031143297\', \'V\', \'借记卡\', \'2018-11-09 13:48:22\', \'142201199305027054\', \'01\', \'APPSHIPPER20180829100001MgiIm\', \'http://yudian.ufile.ucloud.com.cn/019bd30c-39bb-4680-a32c-1d8703f90136.jpg?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=pPx9/MwLLhB80/JgqSS8UPOeIh8=\', \'18056070532\', \'01050000\', \'测试建设支行\', \'建设银行\')'
            self.db.execute_sql(sql_insert)
Example #20
0
class ISHaveOrder(object):
    '''查询是否存在订单'''
    def __init__(self):
        self.config = ReadYaml(FileUtil.getProjectObsPath() + '/config/config.yaml').getValue()
        self.DBUtil = DBUtil(host=self.config['db_host'], port=self.config['db_port'],
                             user=self.config['db_user'], passwd=self.config['db_passwd'],
                             dbname=self.config['db_dbname'], charset=self.config['db_charset'])
        self.logger = Log()

    def is_have_order(self,orderStatus='0'):
        '''查询企业是否有订单'''
        try:
            if orderStatus =='0':
                # 查询企业是否有未派车的订单
                sql = 'SELECT planNo FROM YD_TMS_ORDERPLAN WHERE orderStatus = \'0\' and partnerNo = \'{0}\' ' \
                      'ORDER BY id desc '.format(self.config['partnerNo'])
                planNo = self.DBUtil.excute_select_one_record(sql)
                self.logger.info('Query result:{0}'.format(planNo))
                return planNo
            elif orderStatus == '1':
                # 查询企业是否有派车中的订单
                sql = 'SELECT planNo FROM YD_TMS_ORDERPLAN WHERE orderStatus = \'1\' and partnerNo = \'{0}\'' \
                      'ORDER BY id desc '.format(self.config['partnerNo'])
                planNo = self.DBUtil.excute_select_one_record(sql)
                self.logger.info('Query result:{0}'.format(planNo))
                return planNo
            elif orderStatus == '2':
                # 查询企业是否有已派车的订单
                sql = 'SELECT planNo FROM YD_TMS_ORDERPLAN WHERE orderStatus = \'2\' and partnerNo = \'{0}\'' \
                      'ORDER BY id desc '.format(self.config['partnerNo'])
                planNo = self.DBUtil.excute_select_one_record(sql)
                self.logger.info('Query result:{0}'.format(planNo))
                return planNo
            elif orderStatus == '-1':
                # 查询企业是否有已取消的订单
                sql = 'SELECT planNo FROM YD_TMS_ORDERPLAN WHERE orderStatus = \'-1\' and partnerNo = \'{0}\'' \
                      'ORDER BY id desc '.format(self.config['partnerNo'])
                planNo = self.DBUtil.excute_select_one_record(sql)
                self.logger.info('Query result:{0}'.format(planNo))
                return planNo
            elif orderStatus == 'all':
                # 查询企业是否有订单
                sql = 'SELECT planNo FROM YD_TMS_ORDERPLAN WHERE partnerNo = \'{0}\' ORDER BY id desc '.format(
                    self.config['partnerNo'])
                planNo = self.DBUtil.excute_select_one_record(sql)
                self.logger.info('Query result:{0}'.format(planNo))
                return planNo
            else:
                self.logger.error('查询企业的订单状态错误:{0}'.format(orderStatus))
        except Exception as e:
            self.logger.error('查询企业是否有订单发生异常:{0}'.format(e))
            return None

    # def is_have_noSend_order(self):
    #     '''查询企业是否有未派车的订单'''
    #     try:
    #         sql = 'SELECT planNo FROM YD_TMS_ORDERPLAN WHERE orderStatus = \'0\' and partnerNo = \'{0}\''.format(
    #             self.config['partnerNo'])
    #         planNo = self.DBUtil.excute_select_one_record(sql)
    #         return planNo
    #     except Exception as e:
    #         self.logger.error('查询企业是否有未派车的订单发生异常:{0}'.format(e))
    #         return None
    #
    # def is_have_sending_order(self):
    #     '''查询企业是否有派车中的订单'''
    #     try:
    #         sql = 'SELECT planNo FROM YD_TMS_ORDERPLAN WHERE orderStatus = \'1\' and partnerNo = \'{0}\''.format(
    #             self.config['partnerNo'])
    #         planNo = self.DBUtil.excute_select_one_record(sql)
    #         return planNo
    #     except Exception as e:
    #         self.logger.error('查询企业是否有未派车的订单发生异常:{0}'.format(e))
    #         return None
    #
    # def is_have_sent_order(self):
    #     '''查询企业是否有已派车的订单'''
    #     try:
    #         sql = 'SELECT planNo FROM YD_TMS_ORDERPLAN WHERE orderStatus = \'2\' and partnerNo = \'{0}\''.format(
    #             self.config['partnerNo'])
    #         planNo = self.DBUtil.excute_select_one_record(sql)
    #         return planNo
    #     except Exception as e:
    #         self.logger.error('查询企业是否有已派车的订单发生异常:{0}'.format(e))
    #         return None
    #
    # def is_have_canceled_order(self):
    #     '''查询企业是否有已取消的订单'''
    #     try:
    #         sql = 'SELECT planNo FROM YD_TMS_ORDERPLAN WHERE orderStatus = \'-1\' and partnerNo = \'{0}\''.format(
    #             self.config['partnerNo'])
    #         planNo = self.DBUtil.excute_select_one_record(sql)
    #         return planNo
    #     except Exception as e:
    #         self.logger.error('查询企业是否有已取消的订单发生异常:{0}'.format(e))
    #         return None
Example #21
0
 def __init__(self):
     self.config = ReadYaml(FileUtil.getProjectObsPath() + '/config/config.yaml').getValue()
     self.DBUtil = DBUtil(host=self.config['db_host'], port=self.config['db_port'],
                          user=self.config['db_user'], passwd=self.config['db_passwd'],
                          dbname=self.config['db_dbname'], charset=self.config['db_charset'])
     self.logger = Log()
class PageWaybillCreate(Page):
    '''我要录单页面'''
    def open_waybill_manage(self):
        # 打开运单管理模块
        HeplerWaybill().open_menu(
            self.driver, 'xpath->//*[@id="menu"]/div/nav/ul/li[4]/label/a')

    def input_default_field(self, project, index, totalAmt, income, preAmt,
                            oilAmt, destAmt, lastAmt, photoAirWay, content):
        '''输入默认字段'''

        #输入用车日期
        self.driver.retry_find_click("id->applyDate")
        self.driver.retry_find_click(
            "xpath->//*[@id='waybillAddForm']/div[1]/div[2]/div/div[2]/div/div/div/div/div/ul/li[2]/span/button[1]"
        )

        #选择项目
        HeplerWaybill().set_value_select_input(self.driver, "id->projectId",
                                               project)
        #输入始发地
        HeplerWaybill().set_value_address(self.driver, "id->sendProvince",
                                          "xpath->//*[@id='_citys0']/a[1]",
                                          "xpath->//*[@id='_citys1']/a",
                                          "xpath->//*[@id='_citys2']/a[1]")
        #输入到达地
        HeplerWaybill().set_value_address(self.driver, "id->arriveProvince",
                                          "xpath->//*[@id='_citys0']/a[2]",
                                          "xpath->//*[@id='_citys1']/a",
                                          "xpath->//*[@id='_citys2']/a[1]")

        #输入途径地1
        self.driver.click('xpath->//*[@id="TMS-addStation-"]/span')
        HeplerWaybill().set_value_address(self.driver, "id->showStationA",
                                          "xpath->//*[@id='_citys0']/a[3]",
                                          "xpath->//*[@id='_citys1']/a[1]",
                                          "xpath->//*[@id='_citys2']/a[1]")
        #输入途径地2
        self.driver.click('xpath->//*[@id="TMS-addStation-"]/span')
        HeplerWaybill().set_value_address(self.driver, "id->showStationB",
                                          "xpath->//*[@id='_citys0']/a[3]",
                                          "xpath->//*[@id='_citys1']/a[2]",
                                          "xpath->//*[@id='_citys2']/a[1]")

        # 输入总运费
        self.driver.type('id->totalAmt', totalAmt)
        # 输入发车收入
        self.driver.type('id->incomeId', income)
        # 输入预付
        self.driver.type('id->TMS-billModel-preAmt', preAmt)
        # 输入油卡
        self.driver.type('id->TMS-billModel-oilAmt', oilAmt)
        # 输入到付
        self.driver.type('id->TMS-billModel-destAmt', destAmt)
        # 输入尾款'''
        self.driver.type('id->TMS-billModel-lastAmt', lastAmt)
        # 输入运输协议照片
        self.driver.type('xpath->//*[@id="picOfTransport"]/div/div/div',
                         photoAirWay)
        # 输入运单备注
        self.driver.type('id->TMS-billModel-content', content)

    def input_system_defined_field(
        self,
        order='',
        oilCardNo='',
        handlingFee='',
        deliveryFee='',
        oilCardDeposit='',
        otherFee='',
    ):
        '''输入预设字段'''
        #订单号
        self.driver.type("id->upWayBillId", order)
        #油卡卡号
        self.driver.type('id->oilCardNo', oilCardNo)
        #装卸费
        self.driver.type('id->TMS-billModel-handlingFee', handlingFee)
        #送货费
        self.driver.type('id->TMS-billModel-deliveryFee', deliveryFee)
        #油卡押金
        self.driver.type('id->TMS-billModel-oilCardDeposit', oilCardDeposit)
        #其他费用
        self.driver.type('id->TMS-billModel-otherFee', otherFee)

    def input_user_defined_field(self):
        '''输入自定义字段'''
        return None

    def input_cargo(self,
                    cargoName='',
                    cargoWeight='',
                    cargoVolume='',
                    cargoCount='',
                    unit='',
                    cargoNo='',
                    cargoWorth='',
                    insuranceCosts=''):
        # 输入货物明细
        HeplerWaybill().set_value_cargo(self.driver, cargoName, cargoWeight,
                                        cargoVolume, cargoCount, unit, cargoNo,
                                        cargoWorth, insuranceCosts)

    def input_own_car_waybill(self,
                              project='',
                              driver='',
                              carNo='',
                              index='0',
                              totalAmt='',
                              income='',
                              preAmt='',
                              oilAmt='',
                              destAmt='',
                              lastAmt='',
                              photoAirWay='',
                              content=''):
        '''选择自有车录单'''
        # 打开我要录单页面
        HeplerWaybill().open_menu(
            self.driver,
            'xpath->//*[@id="menu"]/div/nav/ul/li[4]/div/ul/li[2]/a/span')
        #选择公司车
        self.driver.click("xpath->//*[@id='carOne']/i")
        #输入默认字段
        self.input_default_field(project, index, totalAmt, income, preAmt,
                                 oilAmt, destAmt, lastAmt, photoAirWay,
                                 content)
        #选择司机
        HeplerWaybill().set_value_select_input(self.driver, "id->realName",
                                               driver)
        #选择车辆
        HeplerWaybill().set_value_select_input(self.driver, "id->innerCarNoId",
                                               carNo)
        # 输入有无回单
        self.driver.select('id->TMS-billModel-hasReceipt',
                           "index->{0}".format(index))

    def input_fee_car_waybill(self,
                              project='',
                              driver='',
                              supplier='',
                              index='0',
                              totalAmt='',
                              income='',
                              preAmt='',
                              oilAmt='',
                              destAmt='',
                              lastAmt='',
                              photoAirWay='',
                              content=''):
        '''选择外请车录单'''
        # 打开我要录单页面
        HeplerWaybill().open_menu(
            self.driver,
            'xpath->//*[@id="menu"]/div/nav/ul/li[4]/div/ul/li[2]/a/span')

        self.input_default_field(project, index, totalAmt, income, preAmt,
                                 oilAmt, destAmt, lastAmt, photoAirWay,
                                 content)
        #选择司机、车辆
        HeplerWaybill().set_value_select_input(self.driver, "id->realName",
                                               driver)
        # 选择供应商
        HeplerWaybill().set_value_select_input(
            self.driver, 'id->TMS-billModel-supplierName', supplier)
        # 输入有无回单
        self.driver.select('id->TMS-billModel-hasReceipt',
                           "index->{0}".format(index))

    def update_car(self, carNo, carLength, carModel):
        '''修改车辆信息'''
        self.driver.type("id->innerCarNoId", carNo)
        self.driver.type("id->selectCarLengthId", carLength)
        self.driver.type("id->selectCarModelId", carModel)

    def submit(self):
        '''提交按钮'''
        self.driver.click('id->onlySubmit')

    def continue_submit(self):
        '''继续提交按钮'''
        self.driver.click('id->SubmitAndContinue')

    def empty_content(self):
        '''清空内容'''
        self.driver.click('id->TMS-清空内容')

    def cancel(self):
        '''取消按钮'''
        self.driver.click(
            'xpath->//*[@id="addWayBillDiv"]/div/form/div[5]/div/button[3]')

    def create_waybill_confirm(self):
        '''创建运单成功 确定按钮'''
        current_window = self.driver.driver.current_window_handle
        self.driver.click('id->onlySubmit', secs=10)
        self.driver.element_is_not_visible('class->loading-bar-background')
        time.sleep(5)
        all_windows = self.driver.driver.window_handles
        for window in all_windows:
            if window != current_window:
                self.driver.driver.switch_to.window(window)
        self.driver.retry_find_click(
            'xpath->//*[@id="myModal"]/div/div/div[3]/button', secs=10)

    def create_waybill_success(self):
        '''创建运单成功'''
        self.driver.element_is_not_visible('class->loading-bar-background')
        return self.driver.get_text('xpath->//*[@id="myModal"]/div/div/div[2]')

    def create_waybill_submit(self,
                              project='',
                              driver='',
                              supplier='',
                              index='1',
                              totalAmt='1000',
                              income='2000',
                              preAmt='0.01',
                              oilAmt='0.01',
                              destAmt='0.01',
                              lastAmt='0.01',
                              photoAirWay='',
                              content=''):
        '''创建运单'''
        waybillId, tmsBillCode, driver_mobile = ISHaveWaybill(
        ).is_have_wait_departure_waybill(driver=driver)
        # 判断是否存在未发车的运单
        if waybillId != None:
            self.logger.info("已认证外请车存在未发车确认的运单ID:{0}".format(waybillId))
            DepartureConfirmApi().departure_confirm_api(str(waybillId[0]))

        # 创建运单
        self.input_fee_car_waybill(project, driver_mobile, supplier, index,
                                   totalAmt, income, preAmt, oilAmt, destAmt,
                                   lastAmt, photoAirWay, content)
        self.create_waybill_confirm()

        # 获取创建运单运单号、运单ID
        self.DBUtil = DBUtil(host=self.config['db_host'],
                             port=self.config['db_port'],
                             user=self.config['db_user'],
                             passwd=self.config['db_passwd'],
                             dbname=self.config['db_dbname'],
                             charset=self.config['db_charset'])
        sql = 'SELECT airWayBillNo ,tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and billStatus = \'W\' ' \
              'and delStatus = \'0\' and partnerNo = \'{1}\''.format(driver_mobile, self.config['partnerNo'])
        waybillId, tmsBillCode = self.DBUtil.excute_select_one_record(sql)
        return waybillId, tmsBillCode

    def jump_waybill_submit(self,
                            project='',
                            driver='',
                            supplier='',
                            index='1',
                            totalAmt='1000',
                            income='2000',
                            preAmt='0.01',
                            oilAmt='0.01',
                            destAmt='0.01',
                            lastAmt='0.01',
                            photoAirWay='',
                            content=''):
        '''创建运单'''
        waybillId, tmsBillCode, driver_mobile = ISHaveWaybill(
        ).is_have_wait_departure_waybill(driver=driver)
        # 判断是否存在未发车的运单
        if waybillId != None:
            self.logger.info("存在未发车确认的运单ID:{0}".format(waybillId))
            DepartureConfirmApi().departure_confirm_api(str(waybillId[0]))

        self.input_default_field(project, index, totalAmt, income, preAmt,
                                 oilAmt, destAmt, lastAmt, photoAirWay,
                                 content)
        # 选择司机、车辆
        HeplerWaybill().set_value_select_input(self.driver, "id->realName",
                                               driver)
        # 选择供应商
        HeplerWaybill().set_value_select_input(
            self.driver, 'id->TMS-billModel-supplierName', supplier)
        # 输入有无回单
        self.driver.select('id->TMS-billModel-hasReceipt',
                           "index->{0}".format(index))
        self.submit()

        # 获取创建运单运单号、运单ID
        self.DBUtil = DBUtil(host=self.config['db_host'],
                             port=self.config['db_port'],
                             user=self.config['db_user'],
                             passwd=self.config['db_passwd'],
                             dbname=self.config['db_dbname'],
                             charset=self.config['db_charset'])
        sql1 = 'SELECT airWayBillNo ,tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and billStatus = \'W\' ' \
               'and delStatus = \'0\' and partnerNo = \'{1}\''.format(driver_mobile, self.config['partnerNo'])
        waybillId, tmsBillCode = self.DBUtil.excute_select_one_record(sql1)
        return waybillId, tmsBillCode
Example #23
0
class PageOrderCreate(Page):
    '''新建订单页面'''
    def open_order_manage(self):
        # 打开订单管理模块
        HeplerWaybill().open_menu(
            self.driver, 'xpath->//*[@id="menu"]/div/nav/ul/li[3]/label/a')

    def input_cargo(self,
                    cargoName='',
                    cargoWeight='',
                    cargoVolume='',
                    cargoCount='',
                    unit='',
                    cargoNo='',
                    cargoWorth='',
                    insuranceCosts=''):
        # 输入货物明细
        HeplerWaybill().set_value_cargo(self.driver, cargoName, cargoWeight,
                                        cargoVolume, cargoCount, unit, cargoNo,
                                        cargoWorth, insuranceCosts)

    def input_order(self, project='', orderRemark='', upOrderPlanNo=''):
        # 打开新建订单页面
        HeplerWaybill().open_menu(
            self.driver,
            'xpath->//*[@id="menu"]/div/nav/ul/li[3]/div/ul/li[2]/a/span')
        # 选择项目
        self.driver.retry_find_click('id->projectId')
        self.driver.element_is_not_visible('class->loading-bar-background')
        self.driver.type('id->TMS-queryProjects-selectProject', project)
        self.driver.move_to_click('id->TMS-selectProject-')

        self.driver.type('id->planRemark', orderRemark)
        self.driver.type('id->TMS-billModel-upOrderPlanNo', upOrderPlanNo)

    def submit(self):
        '''提交按钮'''
        self.driver.click('id->TMS-saveOrderPlan-')

    def cancel(self):
        '''取消按钮'''
        self.driver.click('id->TMS-clearParams-')

    def create_order_confirm(self):
        '''创建订单成功 确定按钮'''
        current_window = self.driver.driver.current_window_handle
        self.driver.click('id->TMS-saveOrderPlan-', secs=10)
        self.driver.element_is_not_visible('class->loading-bar-background')
        all_windows = self.driver.driver.window_handles
        for window in all_windows:
            if window != current_window:
                self.driver.driver.switch_to.window(window)
        self.driver.retry_find_click(
            'xpath->//*[@id="myModal"]/div/div/div[3]/button', secs=10)

    def create_order_success(self):
        '''创建订单成功'''
        self.driver.element_is_not_visible('class->loading-bar-background')
        return self.driver.get_text('xpath->//*[@id="myModal"]/div/div/div[2]')

    def create_order_submit(self,
                            project='',
                            orderRemark='',
                            upOrderPlanNo=''):
        '''创建订单'''
        self.input_order(project=project,
                         orderRemark=orderRemark,
                         upOrderPlanNo=upOrderPlanNo)
        self.create_order_confirm()
        # 获取创建运单的订单号
        self.DBUtil = DBUtil(host=self.config['db_host'],
                             port=self.config['db_port'],
                             user=self.config['db_user'],
                             passwd=self.config['db_passwd'],
                             dbname=self.config['db_dbname'],
                             charset=self.config['db_charset'])
        sql = 'SELECT planNo FROM YD_TMS_ORDERPLAN WHERE orderStatus = \'0\' and partnerNo = \'{0}\''.format(
            self.config['partnerNo'])
        planNo = self.DBUtil.excute_select_one_record(sql)
        return planNo
    def create_waybill_register(self,
                                handlingFee='',
                                deliveryFee='',
                                oilCardDeposit='',
                                otherFee=''):
        """ 使用已认证司机新建运单 """
        try:

            applyDate = time.strftime('%Y-%m-%d')
            photoAirWay = FileUtil.getProjectObsPath(
            ) + '/image/photoAirWay.jpg'
            upWayBillId = time.strftime('%Y%m%d%H%M%S',
                                        time.localtime(time.time()))[2:] + str(
                                            random.randint(100, 999))
            project = CreateWayBill().project_choice()
            supplier = CreateWayBill().supplier_choice()
            # 随机选择一个已认证的外请车
            mobile_certificate = self.config['mobile_certificate']
            mobile_certificate = random.sample(mobile_certificate, 1)[0]
            # 获取认证司机的信息
            driver = DriverMobileSelect().driver_mobile_select(
                mobile_certificate).json()['content'][0]
            self.logger.info('获取已认证司机信息:{0}'.format(driver))
            # 判断司机是否有未发车的运单
            sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and billStatus = \'W\' and ' \
                  'delStatus = \'0\' and partnerNo = \'{1}\''.format(driver['mobile'], self.config['partnerNo'])
            self.DBUtil = DBUtil(host=self.config['db_host'],
                                 port=self.config['db_port'],
                                 user=self.config['db_user'],
                                 passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'],
                                 charset=self.config['db_charset'])
            waybillId_ = self.DBUtil.excute_select_one_record(sql)
            self.logger.info("已认证外请车存在未发车确认的运单ID:{0}".format(waybillId_))
            if waybillId_ == None:
                pass
            else:
                WayBillDepartureConfirm().waybill_departure_confirm(
                    waybillId_[0])
            # 创建运单
            response = WayBillCreate().waybill_create(
                '2',
                applyDate,
                project['projectName'],
                project['projectId'],
                supplier['name'],
                supplier['supplierId'],
                driver['name'],
                driver['idNo'],
                driver['mobile'],
                driver['carNo'],
                driver['carLength'],
                driver['carModel'],
                photoAirWay,
                driver['loginId'],
                sendProvince='北京',
                sendCity='北京',
                sendDistrict='',
                arriveProvince='天津',
                arriveCity='天津',
                arriveDistrict='',
                income='1000',
                totalAmt='0.05',
                preAmt='0.01',
                oilAmt='0.01',
                destAmt='0.01',
                lastAmt='0.01',
                hasReceipt='1',
                content='auto备注测试',
                source='TMS',
                cargoName='零担',
                cargoWeight='10',
                cargoVolume='100',
                cargoNumberOfCases='1000',
                cargoWorth='10000',
                insuranceCosts='10000',
                handlingFee=handlingFee,
                deliveryFee=deliveryFee,
                oilCardDeposit=oilCardDeposit,
                otherFee=otherFee,
                upWayBillId=upWayBillId,
                oilCardNo='YK001',
                vehicleIdNo='LSVAM4187C2184847',
                driverCardNo='6222810001000',
                depositBank='中国银行合肥分行',
                accountName='auto张三')
            wayBillId = response.json()['content']
            self.logger.info('使用已认证司机创建的运单ID是:{0}'.format(wayBillId))
            #司机发车确认
            confirmMsg = WayBillDriverConfirm().waybill_driver_confirm(
                wayBillId,
                totalAmt='0.05',
                preAmt='0.01',
                oilAmt='0.01',
                destAmt='0.01',
                lastAmt='0.01')
            self.logger.info('运单ID{0},司机确认发车返回结果:{1}'.format(
                wayBillId, confirmMsg.json()))
            return wayBillId
        except Exception as e:
            self.logger.info('新建已认证外请车运单公共模块发生异常:{0}'.format(e))
            return None
class CreateWayBill(object):
    '''我要录单'''
    def __init__(self):
        self.logger = Log()
        self.config = ReadYaml(FileUtil.getProjectObsPath() +
                               '/config/config.yaml').getValue()

    @staticmethod
    def my_print(msg):
        logger = Log()
        logger.info(msg)

    # 选择项目
    @staticmethod
    def project_choice(projectName='德邦物流',
                       customerName='德邦集团',
                       customerCode='DB20171101100',
                       phone='13077327043',
                       customerDeveloper='张经理'):
        project_list = ProjectSelect().project_select(
            rows='1000', projectStatus='1').json()['content']['dataList']
        if project_list == []:
            startTime = time.strftime('%Y-%m-%d')
            endTime = time.strftime('%Y-%m-%d',
                                    time.localtime(time.time() + 2592000))
            projectId = CreateProject().create_project(projectName, startTime,
                                                       endTime, customerName,
                                                       customerCode, phone,
                                                       customerDeveloper)
            project = {'projectId': projectId, 'projectName': projectName}
            CreateWayBill.my_print('新建的项目名称是: {0}'.format(
                project['projectName']))
        else:
            project = random.sample(project_list, 1)[0]
            CreateWayBill.my_print('选择的项目名称是: {0}'.format(
                project['projectName']))
        return project

    # 选择指定项目
    @staticmethod
    def project_one_choice(projectName, startTime, endTime, customerName,
                           customerCode, phone, customerDeveloper):
        project_list = ProjectSelect().project_select(
            rows='1000', projectStatus='1').json()['content']['dataList']
        if project_list != []:
            L = []
            for project in project_list:
                if project['projectName'] == projectName:
                    L.append(project['projectName'])
                    return project
            if len(L) == 0:
                projectId = CreateProject().create_project(
                    projectName, startTime, endTime, customerName,
                    customerCode, phone, customerDeveloper)
                project = {'projectId': projectId, 'projectName': projectName}
                return project
        else:
            projectId = CreateProject().create_project(projectName, startTime,
                                                       endTime, customerName,
                                                       customerCode, phone,
                                                       customerDeveloper)
            project = {'projectId': projectId, 'projectName': projectName}
            return project

    #选择供应商
    @staticmethod
    def supplier_choice(name='哇哈哈', type='1', contactPersonName='李经理'):
        supplier_list = SupplierSelect().supplier_select(
            rows='1000').json()['content']['dataList']
        if supplier_list == []:
            contactPersonMobile = DataUtil().createmoble()
            contactPersonIdNo = DataUtil().genneratorIdNo()
            contactPersonIdCardPhoto = "http://yudian.ufile.ucloud.com.cn/18d4d203-3712-43c7-93d9-9b791aa4806d.jpg?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=CGRGouKFXGdBh3aI4+gK+nA5XmU="
            businessLicencePhoto = "http://yudian.ufile.ucloud.com.cn/9503b68e-6e0b-40df-b30f-c7af545da878.jpg?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=42hC+hmiXMNbRIoR8H4wipW0SI8="
            businessPermitPhoto = "http://yudian.ufile.ucloud.com.cn/8539002d-b90f-4a1a-b19c-22b2135cbf6b.jpg?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=hwTz+Pk8yffBXUwEbgSsoVU9QT4="
            taxRegistrationCertificatePhoto = "http://yudian.ufile.ucloud.com.cn/b117b5e1-e4d5-47f6-8e81-50bb344c3896.jpg?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=4+YLofibFNAqF1PhOFoNSqu4CN4="
            contractPhoto = "http://yudian.ufile.ucloud.com.cn/b2098698-56e7-425e-9186-61dbb966310a.jpg?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=IknyOZi+hHvHpyajfp8HI3aANqA="
            supplierId = CreateSupplier().create_supplier(
                name, type, contactPersonName, contactPersonMobile,
                contactPersonIdNo, contactPersonIdCardPhoto,
                businessLicencePhoto, businessPermitPhoto,
                taxRegistrationCertificatePhoto, contractPhoto)
            supplier = {'name': name, 'supplierId': supplierId}
            CreateWayBill.my_print('新建的供应商名称是: {0}'.format(supplier['name']))
        else:
            supplier = random.sample(supplier_list, 1)[0]
            CreateWayBill.my_print('选择的供应商名称是: {0}'.format(supplier['name']))
        return supplier

    # 选择司机
    @staticmethod
    def driver_choice(name='王师傅'):
        driver_list = MyDriverSelect().my_driver_select(
            rows='1000').json()['content']['dataList']
        if driver_list == []:
            mobile = DataUtil().createmoble()
            idNo = DataUtil().genneratorIdNo()
            photoDriverCard = 'http://yudian.ufile.ucloud.com.cn/a0e806f9-c3d3-479d-bca4-e992a0c7412c.jpg?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=BOj9MjmPyxmvu0wzzlJVGoueyx8='
            frontIdCard = 'http://yudian.ufile.ucloud.com.cn/df03e2a2-6751-488e-9f1f-ec60a1da49fa.jpg?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=b3XzoIcs67/0D6ZExdG0fWbjUzc='
            backIdCard = 'http://yudian.ufile.ucloud.com.cn/4acb87e0-8c0d-44a9-a1b3-b8cb7ca103d1.jpg?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=XfbOAUgpkjIe1FJU/hxiMqfsWno='
            CreateMyDriver().create_my_driver(mobile, name, idNo,
                                              photoDriverCard, frontIdCard,
                                              backIdCard)
            driver = {
                'name': name,
                'idNo': idNo,
                'mobile': mobile,
            }
            CreateWayBill.my_print('新建的司机手机号是: {0}'.format(driver['mobile']))
        else:
            driver = random.sample(driver_list, 1)[0]
            CreateWayBill.my_print('选择的司机手机号是: {0}'.format(driver['mobile']))
        return driver

    # 选择车辆
    @staticmethod
    def car_choice(carLoad='10', carAge='', carBrand='长城'):
        car_list = MyCarSelect().my_car_select(
            rows='1000').json()['content']['dataList']
        if car_list == []:
            carNo = DataUtil().genneratorCarNo()
            carModel = DataUtil().genneratorCarTypeInfo()
            carLength = DataUtil().genneratorCarLength()
            buycarTime = time.strftime('%Y-%m-%d')
            photoDriverCard = 'http://yudian.ufile.ucloud.com.cn/a0e806f9-c3d3-479d-bca4-e992a0c7412c.jpg?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=BOj9MjmPyxmvu0wzzlJVGoueyx8='
            photoCar = 'http://yudian.ufile.ucloud.com.cn/69eec140-f95d-4af7-9aaf-c57b8442d799.jpg?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=bPzioEVJ8i4E3iXi+Yx7KQSeHvw='
            CreateMyCar().create_my_car(carNo, carModel, carLength, carLoad,
                                        carAge, buycarTime, carBrand,
                                        photoDriverCard, photoCar)
            car = {
                'carNo': carNo,
                'carLength': carLength,
                'carModel': carModel
            }
            CreateWayBill.my_print('新建的车牌号是: {0}'.format(car['carNo']))
        else:
            car = random.sample(car_list, 1)[0]
            CreateWayBill.my_print('选择的车牌号是: {0}'.format(car['carNo']))
        return car

    #选择外请车
    @staticmethod
    def outCar_choice(name='张三三', carLoad='10'):
        outCar_list = DriverSelect().driver_select().json()['content']
        if outCar_list == []:
            mobile = DataUtil().createmoble()
            idNo = DataUtil().genneratorIdNo()
            carNo = DataUtil().genneratorCarNo()
            carLength = DataUtil().genneratorCarLength()
            carModel = DataUtil().genneratorCarTypeInfo()
            photoIdFront = FileUtil.getProjectObsPath(
            ) + os.path.sep + 'image' + os.path.sep + 'frontIdCard.jpg'
            photoIdReserve = FileUtil.getProjectObsPath(
            ) + os.path.sep + 'image' + os.path.sep + 'backIdCard.jpg'
            photoDriverCard = FileUtil.getProjectObsPath(
            ) + os.path.sep + 'image' + os.path.sep + 'photoDriverCard.jpg'
            photoTransPort = FileUtil.getProjectObsPath(
            ) + os.path.sep + 'image' + os.path.sep + 'photoTransPort.jpg'
            loginId, Id = CreateDriver().create_driver(
                name, mobile, idNo, photoIdFront, photoIdReserve,
                photoDriverCard, photoTransPort, carNo, carLength, carModel,
                carLoad)
            outCar = {
                'loginId': loginId,
                'name': name,
                'idNo': idNo,
                'mobile': mobile,
                'carNo': carNo,
                'carLength': carLength,
                'carModel': carModel
            }
        else:
            outCar = random.sample(outCar_list, 1)[0]
            CreateWayBill.my_print('选择的外请车车牌号是: {0}'.format(outCar['carNo']))
        return outCar

    #创建运单
    def create_waybill(self, carType, applyDate, photoAirWay, sendProvince,
                       sendCity, sendDistrict, arriveProvince, arriveCity,
                       arriveDistrict, income, totalAmt, preAmt, oilAmt,
                       destAmt, lastAmt, hasReceipt, content, source,
                       cargoName, cargoWeight, cargoVolume, cargoNumberOfCases,
                       cargoWorth, insuranceCosts, handlingFee, deliveryFee,
                       oilCardDeposit, otherFee, upWayBillId, oilCardNo,
                       vehicleIdNo, driverCardNo, depositBank, accountName):
        try:
            project = CreateWayBill().project_choice()
            supplier = CreateWayBill().supplier_choice()
            if carType == '1':
                car = CreateWayBill.car_choice()
                driver = CreateWayBill.driver_choice()
                response = WayBillCreate().waybill_create(
                    carType, applyDate, project['projectName'],
                    project['projectId'], supplier['name'],
                    supplier['supplierId'], driver['name'], driver['idNo'],
                    driver['mobile'], car['carNo'], car['carLength'],
                    car['carModel'], photoAirWay, '', sendProvince, sendCity,
                    sendDistrict, arriveProvince, arriveCity, arriveDistrict,
                    income, totalAmt, preAmt, oilAmt, destAmt, lastAmt,
                    hasReceipt, content, source, cargoName, cargoWeight,
                    cargoVolume, cargoNumberOfCases, cargoWorth,
                    insuranceCosts, handlingFee, deliveryFee, oilCardDeposit,
                    otherFee, upWayBillId, oilCardNo, '', '', '', '')
                self.logger.info("公司车创建运单公共模块response:{0}".format(
                    response.json()))
                if response.json()['code'] == 0:
                    return response.json()['content'],driver['mobile'],driver['name'],driver['idNo'],car['carNo'],\
                           car['carLength'],car['carModel'],project['projectName'],project['projectId'],\
                           supplier['name'], supplier['supplierId']

                elif response.json()['code'] == 9040104 and response.json()['msg'] == \
                        '此手机号已有未确认的订单,不可重复提交,请发车确认后再录单':
                    sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and billStatus = \'W\' and  ' \
                          'delStatus = \'0\' and partnerNo = \'{1}\''.format(driver['mobile'], self.config['partnerNo'])
                    self.DBUtil = DBUtil(host=self.config['db_host'],
                                         port=self.config['db_port'],
                                         user=self.config['db_user'],
                                         passwd=self.config['db_passwd'],
                                         dbname=self.config['db_dbname'],
                                         charset=self.config['db_charset'])
                    waybillId_ = self.DBUtil.excute_select_one_record(sql)
                    self.logger.info("公司车存在未发车确认的运单ID:{0}".format(
                        waybillId_[0]))
                    response_departure_confirm = WayBillDepartureConfirm(
                    ).waybill_departure_confirm(waybillId_[0])
                    self.logger.info("发车确认返回结果:{0}".format(
                        response_departure_confirm.json()))
                    response_ = WayBillCreate().waybill_create(
                        carType, applyDate, project['projectName'],
                        project['projectId'], supplier['name'],
                        supplier['supplierId'], driver['name'], driver['idNo'],
                        driver['mobile'], car['carNo'], car['carLength'],
                        car['carModel'], photoAirWay, '', sendProvince,
                        sendCity, sendDistrict, arriveProvince, arriveCity,
                        arriveDistrict, income, totalAmt, preAmt, oilAmt,
                        destAmt, lastAmt, hasReceipt, content, source,
                        cargoName, cargoWeight, cargoVolume,
                        cargoNumberOfCases, cargoWorth, insuranceCosts,
                        handlingFee, deliveryFee, oilCardDeposit, otherFee,
                        upWayBillId, oilCardNo, '', '', '', '')
                    self.logger.info("公司车发车确认后,再次录单返回结果:{0}".format(
                        response_.json()))
                    waybillId = response_.json()['content']
                    return waybillId,driver['mobile'],driver['name'],driver['idNo'],car['carNo'],\
                           car['carLength'],car['carModel'],project['projectName'],project['projectId'],\
                           supplier['name'],supplier['supplierId']

                else:
                    self.logger.info("创建公司车运单公共模块失败!")
                    return None, None, None, None, None, None, None, None, None, None, None

            elif carType == '2':
                outCar = CreateWayBill().outCar_choice()
                driver_info = DriverBankVINGet().driver_bank_VIN_get(
                    outCar['mobile'], ).json()['content']
                response = WayBillCreate().waybill_create(
                    carType, applyDate, project['projectName'],
                    project['projectId'], supplier['name'],
                    supplier['supplierId'], outCar['name'], outCar['idNo'],
                    outCar['mobile'], outCar['carNo'], outCar['carLength'],
                    outCar['carModel'], photoAirWay, outCar['loginId'],
                    sendProvince, sendCity, sendDistrict, arriveProvince,
                    arriveCity, arriveDistrict, income, totalAmt, preAmt,
                    oilAmt, destAmt, lastAmt, hasReceipt, content, source,
                    cargoName, cargoWeight, cargoVolume, cargoNumberOfCases,
                    cargoWorth, insuranceCosts, handlingFee, deliveryFee,
                    oilCardDeposit, otherFee, upWayBillId, oilCardNo,
                    driver_info['vehicleIdNo'], driver_info['cardNo'],
                    driver_info['driverCardBank'], driver_info['accountName'])
                self.logger.info("外请车创建运单公共模块response:{0}".format(
                    response.json()))
                if response.json()['code'] == 0:
                    return response.json()['content'],outCar['mobile'],outCar['name'],outCar['idNo'],outCar['carNo'],\
                           outCar['carLength'],outCar['carModel'],project['projectName'], project['projectId'],\
                           supplier['name'], supplier['supplierId']

                elif response.json()['code'] == 9040104 and response.json()['msg'] ==\
                          '此手机号已有未确认的订单,不可重复提交,请发车确认后再录单':
                    sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and billStatus = \'W\' and ' \
                          'delStatus = \'0\' and partnerNo = \'{1}\''.format(outCar['mobile'], self.config['partnerNo'])
                    self.DBUtil = DBUtil(host=self.config['db_host'],
                                         port=self.config['db_port'],
                                         user=self.config['db_user'],
                                         passwd=self.config['db_passwd'],
                                         dbname=self.config['db_dbname'],
                                         charset=self.config['db_charset'])
                    waybillId_ = self.DBUtil.excute_select_one_record(sql)
                    self.logger.info("公司车存在未发车确认的运单ID:{0}".format(
                        waybillId_[0]))
                    response_departure_confirm = WayBillDepartureConfirm(
                    ).waybill_departure_confirm(waybillId_[0])
                    self.logger.info("发车确认返回结果:{0}".format(
                        response_departure_confirm.json()))
                    response_ = WayBillCreate().waybill_create(
                        carType, applyDate, project['projectName'],
                        project['projectId'], supplier['name'],
                        supplier['supplierId'], outCar['name'], outCar['idNo'],
                        outCar['mobile'], outCar['carNo'], outCar['carLength'],
                        outCar['carModel'], photoAirWay, outCar['loginId'],
                        sendProvince, sendCity, sendDistrict, arriveProvince,
                        arriveCity, arriveDistrict, income, totalAmt, preAmt,
                        oilAmt, destAmt, lastAmt, hasReceipt, content, source,
                        cargoName, cargoWeight, cargoVolume,
                        cargoNumberOfCases, cargoWorth, insuranceCosts,
                        handlingFee, deliveryFee, oilCardDeposit, otherFee,
                        upWayBillId, oilCardNo, driver_info['vehicleIdNo'],
                        driver_info['cardNo'], driver_info['driverCardBank'],
                        driver_info['accountName'])
                    self.logger.info("公司车发车确认后,再次录单返回结果:{0}".format(
                        response_.json()))
                    waybillId = response_.json()['content']
                    return waybillId, outCar['mobile'],outCar['name'],outCar['idNo'],outCar['carNo'],outCar['carLength'],\
                           outCar['carModel'],project['projectName'], project['projectId'],supplier['name'], \
                           supplier['supplierId']
                else:
                    self.logger.info("创建外请车运单公共模块失败")
                    return None, None, None, None, None, None, None, None, None, None, None
            else:
                self.logger.error('外请车类型错误: {0}'.format(carType))
                return None, None, None, None, None, None, None, None, None, None, None
        except Exception as e:
            self.logger.error('新增运单公共模块发生异常:{0}'.format(e))
            return None

    # def create_waybill_register1(self):
    #     '''使用已认证司机录单,并发车确认'''
    #     applyDate = time.strftime('%Y-%m-%d')
    #     photoAirWay = FileUtil.getProjectObsPath() + '/image/photoAirWay.jpg'
    #     sendProvince = '浙江'
    #     sendCity = '杭州'
    #     sendDistrict = ''
    #     arriveProvince = '安徽'
    #     arriveCity = '合肥'
    #     arriveDistrict = ''
    #     stationAProvince= '上海'
    #     stationACity = '上海'
    #     stationADistrict = ''
    #     stationBProvince = ''
    #     stationBCity = ''
    #     income = random.uniform(0,99999)
    #     totalAmt = random.uniform(0,99999)
    #     preAmt = random.uniform(0,99999)
    #     oilAmt = random.uniform(0,99999)
    #     destAmt = random.uniform(0,99999)
    #     lastAmt = random.uniform(0,99999)
    #     CreateWayBill().create_waybill('2', applyDate, photoAirWay,sendProvince, sendCity, sendDistrict,arriveProvince,
    #         arriveCity, arriveDistrict,income, totalAmt, preAmt, oilAmt, destAmt, lastAmt,hasReceipt, content, source,
    #         cargoName, cargoWeight, cargoVolume,cargoNumberOfCases, cargoWorth, insuranceCosts, handlingFee, deliveryFee,
    #         oilCardDeposit,otherFee, upWayBillId, oilCardNo, vehicleIdNo,driverCardNo, depositBank, accountName)

    def create_waybill_register(self,
                                handlingFee='',
                                deliveryFee='',
                                oilCardDeposit='',
                                otherFee=''):
        """ 使用已认证司机新建运单 """
        try:

            applyDate = time.strftime('%Y-%m-%d')
            photoAirWay = FileUtil.getProjectObsPath(
            ) + '/image/photoAirWay.jpg'
            upWayBillId = time.strftime('%Y%m%d%H%M%S',
                                        time.localtime(time.time()))[2:] + str(
                                            random.randint(100, 999))
            project = CreateWayBill().project_choice()
            supplier = CreateWayBill().supplier_choice()
            # 随机选择一个已认证的外请车
            mobile_certificate = self.config['mobile_certificate']
            mobile_certificate = random.sample(mobile_certificate, 1)[0]
            # 获取认证司机的信息
            driver = DriverMobileSelect().driver_mobile_select(
                mobile_certificate).json()['content'][0]
            self.logger.info('获取已认证司机信息:{0}'.format(driver))
            # 判断司机是否有未发车的运单
            sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and billStatus = \'W\' and ' \
                  'delStatus = \'0\' and partnerNo = \'{1}\''.format(driver['mobile'], self.config['partnerNo'])
            self.DBUtil = DBUtil(host=self.config['db_host'],
                                 port=self.config['db_port'],
                                 user=self.config['db_user'],
                                 passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'],
                                 charset=self.config['db_charset'])
            waybillId_ = self.DBUtil.excute_select_one_record(sql)
            self.logger.info("已认证外请车存在未发车确认的运单ID:{0}".format(waybillId_))
            if waybillId_ == None:
                pass
            else:
                WayBillDepartureConfirm().waybill_departure_confirm(
                    waybillId_[0])
            # 创建运单
            response = WayBillCreate().waybill_create(
                '2',
                applyDate,
                project['projectName'],
                project['projectId'],
                supplier['name'],
                supplier['supplierId'],
                driver['name'],
                driver['idNo'],
                driver['mobile'],
                driver['carNo'],
                driver['carLength'],
                driver['carModel'],
                photoAirWay,
                driver['loginId'],
                sendProvince='北京',
                sendCity='北京',
                sendDistrict='',
                arriveProvince='天津',
                arriveCity='天津',
                arriveDistrict='',
                income='1000',
                totalAmt='0.05',
                preAmt='0.01',
                oilAmt='0.01',
                destAmt='0.01',
                lastAmt='0.01',
                hasReceipt='1',
                content='auto备注测试',
                source='TMS',
                cargoName='零担',
                cargoWeight='10',
                cargoVolume='100',
                cargoNumberOfCases='1000',
                cargoWorth='10000',
                insuranceCosts='10000',
                handlingFee=handlingFee,
                deliveryFee=deliveryFee,
                oilCardDeposit=oilCardDeposit,
                otherFee=otherFee,
                upWayBillId=upWayBillId,
                oilCardNo='YK001',
                vehicleIdNo='LSVAM4187C2184847',
                driverCardNo='6222810001000',
                depositBank='中国银行合肥分行',
                accountName='auto张三')
            wayBillId = response.json()['content']
            self.logger.info('使用已认证司机创建的运单ID是:{0}'.format(wayBillId))
            #司机发车确认
            confirmMsg = WayBillDriverConfirm().waybill_driver_confirm(
                wayBillId,
                totalAmt='0.05',
                preAmt='0.01',
                oilAmt='0.01',
                destAmt='0.01',
                lastAmt='0.01')
            self.logger.info('运单ID{0},司机确认发车返回结果:{1}'.format(
                wayBillId, confirmMsg.json()))
            return wayBillId
        except Exception as e:
            self.logger.info('新建已认证外请车运单公共模块发生异常:{0}'.format(e))
            return None

    def create_temp_waybill(self,
                            file,
                            projectName,
                            customerName,
                            customerCode,
                            phone='130773271234',
                            customerDeveloper='张经理'):
        '''批量录单 导入运单'''
        startTime = time.strftime('%Y-%m-%d')
        endTime = time.strftime('%Y-%m-%d',
                                time.localtime(time.time() + 2592000))
        try:
            project = self.project_one_choice(projectName, startTime, endTime,
                                              customerName, customerCode,
                                              phone, customerDeveloper)
            response = WayBillTempImport().waybill_temp_import(file)
            if response.json()['code'] == 0:
                temp_waybillId = response.json()['content']
                return temp_waybillId
            else:
                self.logger.error('批量导入运单报错:{0}'.format(response.json()))
                return None
        except Exception as e:
            self.logger.error('批量导入运单发生异常:{0}'.format(e))
            return None
    def create_waybill(self, carType, applyDate, photoAirWay, sendProvince,
                       sendCity, sendDistrict, arriveProvince, arriveCity,
                       arriveDistrict, income, totalAmt, preAmt, oilAmt,
                       destAmt, lastAmt, hasReceipt, content, source,
                       cargoName, cargoWeight, cargoVolume, cargoNumberOfCases,
                       cargoWorth, insuranceCosts, handlingFee, deliveryFee,
                       oilCardDeposit, otherFee, upWayBillId, oilCardNo,
                       vehicleIdNo, driverCardNo, depositBank, accountName):
        try:
            project = CreateWayBill().project_choice()
            supplier = CreateWayBill().supplier_choice()
            if carType == '1':
                car = CreateWayBill.car_choice()
                driver = CreateWayBill.driver_choice()
                response = WayBillCreate().waybill_create(
                    carType, applyDate, project['projectName'],
                    project['projectId'], supplier['name'],
                    supplier['supplierId'], driver['name'], driver['idNo'],
                    driver['mobile'], car['carNo'], car['carLength'],
                    car['carModel'], photoAirWay, '', sendProvince, sendCity,
                    sendDistrict, arriveProvince, arriveCity, arriveDistrict,
                    income, totalAmt, preAmt, oilAmt, destAmt, lastAmt,
                    hasReceipt, content, source, cargoName, cargoWeight,
                    cargoVolume, cargoNumberOfCases, cargoWorth,
                    insuranceCosts, handlingFee, deliveryFee, oilCardDeposit,
                    otherFee, upWayBillId, oilCardNo, '', '', '', '')
                self.logger.info("公司车创建运单公共模块response:{0}".format(
                    response.json()))
                if response.json()['code'] == 0:
                    return response.json()['content'],driver['mobile'],driver['name'],driver['idNo'],car['carNo'],\
                           car['carLength'],car['carModel'],project['projectName'],project['projectId'],\
                           supplier['name'], supplier['supplierId']

                elif response.json()['code'] == 9040104 and response.json()['msg'] == \
                        '此手机号已有未确认的订单,不可重复提交,请发车确认后再录单':
                    sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and billStatus = \'W\' and  ' \
                          'delStatus = \'0\' and partnerNo = \'{1}\''.format(driver['mobile'], self.config['partnerNo'])
                    self.DBUtil = DBUtil(host=self.config['db_host'],
                                         port=self.config['db_port'],
                                         user=self.config['db_user'],
                                         passwd=self.config['db_passwd'],
                                         dbname=self.config['db_dbname'],
                                         charset=self.config['db_charset'])
                    waybillId_ = self.DBUtil.excute_select_one_record(sql)
                    self.logger.info("公司车存在未发车确认的运单ID:{0}".format(
                        waybillId_[0]))
                    response_departure_confirm = WayBillDepartureConfirm(
                    ).waybill_departure_confirm(waybillId_[0])
                    self.logger.info("发车确认返回结果:{0}".format(
                        response_departure_confirm.json()))
                    response_ = WayBillCreate().waybill_create(
                        carType, applyDate, project['projectName'],
                        project['projectId'], supplier['name'],
                        supplier['supplierId'], driver['name'], driver['idNo'],
                        driver['mobile'], car['carNo'], car['carLength'],
                        car['carModel'], photoAirWay, '', sendProvince,
                        sendCity, sendDistrict, arriveProvince, arriveCity,
                        arriveDistrict, income, totalAmt, preAmt, oilAmt,
                        destAmt, lastAmt, hasReceipt, content, source,
                        cargoName, cargoWeight, cargoVolume,
                        cargoNumberOfCases, cargoWorth, insuranceCosts,
                        handlingFee, deliveryFee, oilCardDeposit, otherFee,
                        upWayBillId, oilCardNo, '', '', '', '')
                    self.logger.info("公司车发车确认后,再次录单返回结果:{0}".format(
                        response_.json()))
                    waybillId = response_.json()['content']
                    return waybillId,driver['mobile'],driver['name'],driver['idNo'],car['carNo'],\
                           car['carLength'],car['carModel'],project['projectName'],project['projectId'],\
                           supplier['name'],supplier['supplierId']

                else:
                    self.logger.info("创建公司车运单公共模块失败!")
                    return None, None, None, None, None, None, None, None, None, None, None

            elif carType == '2':
                outCar = CreateWayBill().outCar_choice()
                driver_info = DriverBankVINGet().driver_bank_VIN_get(
                    outCar['mobile'], ).json()['content']
                response = WayBillCreate().waybill_create(
                    carType, applyDate, project['projectName'],
                    project['projectId'], supplier['name'],
                    supplier['supplierId'], outCar['name'], outCar['idNo'],
                    outCar['mobile'], outCar['carNo'], outCar['carLength'],
                    outCar['carModel'], photoAirWay, outCar['loginId'],
                    sendProvince, sendCity, sendDistrict, arriveProvince,
                    arriveCity, arriveDistrict, income, totalAmt, preAmt,
                    oilAmt, destAmt, lastAmt, hasReceipt, content, source,
                    cargoName, cargoWeight, cargoVolume, cargoNumberOfCases,
                    cargoWorth, insuranceCosts, handlingFee, deliveryFee,
                    oilCardDeposit, otherFee, upWayBillId, oilCardNo,
                    driver_info['vehicleIdNo'], driver_info['cardNo'],
                    driver_info['driverCardBank'], driver_info['accountName'])
                self.logger.info("外请车创建运单公共模块response:{0}".format(
                    response.json()))
                if response.json()['code'] == 0:
                    return response.json()['content'],outCar['mobile'],outCar['name'],outCar['idNo'],outCar['carNo'],\
                           outCar['carLength'],outCar['carModel'],project['projectName'], project['projectId'],\
                           supplier['name'], supplier['supplierId']

                elif response.json()['code'] == 9040104 and response.json()['msg'] ==\
                          '此手机号已有未确认的订单,不可重复提交,请发车确认后再录单':
                    sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and billStatus = \'W\' and ' \
                          'delStatus = \'0\' and partnerNo = \'{1}\''.format(outCar['mobile'], self.config['partnerNo'])
                    self.DBUtil = DBUtil(host=self.config['db_host'],
                                         port=self.config['db_port'],
                                         user=self.config['db_user'],
                                         passwd=self.config['db_passwd'],
                                         dbname=self.config['db_dbname'],
                                         charset=self.config['db_charset'])
                    waybillId_ = self.DBUtil.excute_select_one_record(sql)
                    self.logger.info("公司车存在未发车确认的运单ID:{0}".format(
                        waybillId_[0]))
                    response_departure_confirm = WayBillDepartureConfirm(
                    ).waybill_departure_confirm(waybillId_[0])
                    self.logger.info("发车确认返回结果:{0}".format(
                        response_departure_confirm.json()))
                    response_ = WayBillCreate().waybill_create(
                        carType, applyDate, project['projectName'],
                        project['projectId'], supplier['name'],
                        supplier['supplierId'], outCar['name'], outCar['idNo'],
                        outCar['mobile'], outCar['carNo'], outCar['carLength'],
                        outCar['carModel'], photoAirWay, outCar['loginId'],
                        sendProvince, sendCity, sendDistrict, arriveProvince,
                        arriveCity, arriveDistrict, income, totalAmt, preAmt,
                        oilAmt, destAmt, lastAmt, hasReceipt, content, source,
                        cargoName, cargoWeight, cargoVolume,
                        cargoNumberOfCases, cargoWorth, insuranceCosts,
                        handlingFee, deliveryFee, oilCardDeposit, otherFee,
                        upWayBillId, oilCardNo, driver_info['vehicleIdNo'],
                        driver_info['cardNo'], driver_info['driverCardBank'],
                        driver_info['accountName'])
                    self.logger.info("公司车发车确认后,再次录单返回结果:{0}".format(
                        response_.json()))
                    waybillId = response_.json()['content']
                    return waybillId, outCar['mobile'],outCar['name'],outCar['idNo'],outCar['carNo'],outCar['carLength'],\
                           outCar['carModel'],project['projectName'], project['projectId'],supplier['name'], \
                           supplier['supplierId']
                else:
                    self.logger.info("创建外请车运单公共模块失败")
                    return None, None, None, None, None, None, None, None, None, None, None
            else:
                self.logger.error('外请车类型错误: {0}'.format(carType))
                return None, None, None, None, None, None, None, None, None, None, None
        except Exception as e:
            self.logger.error('新增运单公共模块发生异常:{0}'.format(e))
            return None
Example #27
0
class ISHaveWaybill(object):
    '''查询是否存在运单'''
    def __init__(self):
        self.config = ReadYaml(FileUtil.getProjectObsPath() +
                               '/config/config.yaml').getValue()
        self.logger = Log()

    def select_driver_mobile(self, driver):
        '''
        选择司机
        @driver: 货运司机
        '''
        try:
            mobile = re.compile(
                '^1(30|31|32|33|34|35|36|37|38|39|45|47|50|51|52|53|55|56|57|58|59|66|70|71|73|75|76|77|78|80|81|82|83|84|85|86|87|88|89|98|99)[0-9]{8}$'
            )
            if driver == mobile:
                driver_mobile = driver
            elif driver == '' or driver == '18056070532':
                driver_mobile = self.config['driver_mobile']
            else:
                driver_mobile = DriverSelectApi().driver_select_api(
                    name=driver).json()['content']['dataList']['mobile']
            self.logger.info("选择司机的手机号:{0}".format(driver_mobile))
            return driver_mobile
        except Exception as e:
            self.logger.error('选择司机的手机号发生异常:{0}'.format(e))
            return None

    def is_have_waybill(self, driver, driverConfirm=''):
        '''
        查询司机是否有运单
         driverConfirm  '0'司机未发车确认 '1'司机发车确认  ''不区分是否司机发车确认
        '''
        try:
            driver_mobile = self.select_driver_mobile(driver)
            self.DBUtil = DBUtil(host=self.config['db_host'],
                                 port=self.config['db_port'],
                                 user=self.config['db_user'],
                                 passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'],
                                 charset=self.config['db_charset'])
            if driverConfirm == '0' or driverConfirm == '1':
                sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and delStatus = \'0\' and ' \
                      'partnerNo = \'{1}\' and driverConfirm = \'{2}\' ORDER BY id desc'.format(
                    driver_mobile, self.config['partnerNo'], driverConfirm)
                waybillId = self.DBUtil.excute_select_one_record(sql)
                sql2 = 'SELECT tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and delStatus = \'0\' and ' \
                       'partnerNo = \'{1}\'and driverConfirm = \'{2}\' ORDER BY id desc'.format(
                    driver_mobile, self.config['partnerNo'], driverConfirm)
                tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            else:
                sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and delStatus = \'0\' and ' \
                      'partnerNo = \'{1}\' ORDER BY id desc'.format(driver_mobile, self.config['partnerNo'])
                waybillId = self.DBUtil.excute_select_one_record(sql)
                sql2 = 'SELECT tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and delStatus = \'0\' and ' \
                       'partnerNo = \'{1}\' ORDER BY id desc'.format(driver_mobile, self.config['partnerNo'])
                tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            self.logger.info(
                '查询司机是否有运单query result, waybillId:{0},tmsBillCode:{1}'.format(
                    waybillId, tmsBillCode))
            return waybillId, tmsBillCode, driver_mobile
        except Exception as e:
            self.logger.error('查询司机是否有运单发生异常:{0}'.format(e))
            return None

    def is_have_wait_departure_waybill(self, driver):
        '''查询司机是否有未发车的运单'''
        try:
            driver_mobile = self.select_driver_mobile(driver)
            self.DBUtil = DBUtil(host=self.config['db_host'],
                                 port=self.config['db_port'],
                                 user=self.config['db_user'],
                                 passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'],
                                 charset=self.config['db_charset'])
            sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'D\' and ' \
                  'delStatus = \'0\' and partnerNo = \'{1}\''.format(driver_mobile, self.config['partnerNo'])
            waybillId = self.DBUtil.excute_select_one_record(sql)
            sql2 = 'SELECT tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'D\' and ' \
                   'delStatus = \'0\' and partnerNo = \'{1}\''.format(driver_mobile, self.config['partnerNo'])
            tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            self.logger.info(
                '查询司机是否有未发车的运单query result, waybillId:{0},tmsBillCode:{1}'.
                format(waybillId, tmsBillCode))
            return waybillId, tmsBillCode, driver_mobile
        except Exception as e:
            self.logger.error('查询司机是否有未发车的运单发生异常:{0}'.format(e))
            return None

    def is_have_in_transit_waybill(self, driver, driverConfirm=''):
        '''司机是否有运输中的运单'''
        try:
            driver_mobile = self.select_driver_mobile(driver)
            self.DBUtil = DBUtil(host=self.config['db_host'],
                                 port=self.config['db_port'],
                                 user=self.config['db_user'],
                                 passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'],
                                 charset=self.config['db_charset'])
            if driverConfirm == '0' or driverConfirm == '1':
                sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'E\' and ' \
                      'delStatus = \'0\' and partnerNo = \'{1}\'and driverConfirm = \'{2}\' ORDER BY id desc'.format(
                    driver_mobile, self.config['partnerNo'], driverConfirm)
                waybillId = self.DBUtil.excute_select_one_record(sql)
                sql2 = 'SELECT tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'E\' and ' \
                       'delStatus = \'0\' and partnerNo = \'{1}\'and driverConfirm = \'{2}\' ORDER BY id desc'.format(
                    driver_mobile, self.config['partnerNo'], driverConfirm)
                tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            else:
                sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'E\' and ' \
                      'delStatus = \'0\' and partnerNo = \'{1}\' ORDER BY id desc'.format(driver_mobile, self.config['partnerNo'])
                waybillId = self.DBUtil.excute_select_one_record(sql)
                sql2 = 'SELECT tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'E\' and ' \
                       'delStatus = \'0\' and partnerNo = \'{1}\' ORDER BY id desc'.format(driver_mobile, self.config['partnerNo'])
                tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            self.logger.info(
                '查询司机是否有运输中运单query result, waybillId:{0},tmsBillCode:{1}'.
                format(waybillId, tmsBillCode))
            return waybillId, tmsBillCode, driver_mobile
        except Exception as e:
            self.logger.error('司机是否有运输中的运单发生异常:{0}'.format(e))
            return None

    def is_have_arrived_waybill(self, driver, driverConfirm=''):
        '''司机是否有已到达的运单'''
        try:
            driver_mobile = self.select_driver_mobile(driver)
            self.DBUtil = DBUtil(host=self.config['db_host'],
                                 port=self.config['db_port'],
                                 user=self.config['db_user'],
                                 passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'],
                                 charset=self.config['db_charset'])
            if driverConfirm == '0' or driverConfirm == '1':
                sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'A\' and ' \
                      'delStatus = \'0\' and partnerNo = \'{1}\'and driverConfirm = \'{2}\' ORDER BY id desc'.format(
                       driver_mobile, self.config['partnerNo'], driverConfirm)
                waybillId = self.DBUtil.excute_select_one_record(sql)
                sql2 = 'SELECT tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'A\' and ' \
                       'delStatus = \'0\' and partnerNo = \'{1}\'and driverConfirm = \'{2}\' ORDER BY id desc'.format(
                        driver_mobile, self.config['partnerNo'], driverConfirm)
                tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            else:
                sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'A\' and ' \
                      'delStatus = \'0\' and partnerNo = \'{1}\' ORDER BY id desc'.format(driver_mobile, self.config['partnerNo'])
                waybillId = self.DBUtil.excute_select_one_record(sql)
                sql2 = 'SELECT tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'A\' and ' \
                       'delStatus = \'0\' and partnerNo = \'{1}\' ORDER BY id desc'.format(driver_mobile, self.config['partnerNo'])
                tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            self.logger.info(
                '查询司机是否有已到达的运单query result, waybillId:{0},tmsBillCode:{1}'.
                format(waybillId, tmsBillCode))
            return waybillId, tmsBillCode, driver_mobile
        except Exception as e:
            self.logger.error('司机是否有已到达的运单发生异常:{0}'.format(e))
            return None

    def is_have_completed_waybill(self, driver, driverConfirm=''):
        '''司机是否有已完成的运单'''
        try:
            driver_mobile = self.select_driver_mobile(driver)
            self.DBUtil = DBUtil(host=self.config['db_host'],
                                 port=self.config['db_port'],
                                 user=self.config['db_user'],
                                 passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'],
                                 charset=self.config['db_charset'])
            if driverConfirm == '0' or driverConfirm == '1':
                sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'C\' and ' \
                      'delStatus = \'0\' and partnerNo = \'{1}\' and driverConfirm = \'{2}\' ORDER BY id desc'.format(
                       driver_mobile, self.config['partnerNo'], driverConfirm)
                waybillId = self.DBUtil.excute_select_one_record(sql)
                sql2 = 'SELECT tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'C\' and ' \
                       'delStatus = \'0\' and partnerNo = \'{1}\' and driverConfirm = \'{2}\' ORDER BY id desc'.format(
                        driver_mobile, self.config['partnerNo'], driverConfirm)
                tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            else:
                sql = 'SELECT id FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'C\' and ' \
                      'delStatus = \'0\' and partnerNo = \'{1}\' ORDER BY id desc'.format(driver_mobile, self.config['partnerNo'])
                waybillId = self.DBUtil.excute_select_one_record(sql)
                sql2 = 'SELECT tmsBillCode FROM YD_APP_TRANSPORTCASH WHERE mobile = \'{0}\' and transStatus = \'C\' and ' \
                       'delStatus = \'0\' and partnerNo = \'{1}\' ORDER BY id desc'.format(driver_mobile, self.config['partnerNo'])
                tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            self.logger.info(
                '查询司机是否有已完成的运单query result, waybillId:{0},tmsBillCode:{1}'.
                format(waybillId, tmsBillCode))
            return waybillId, tmsBillCode, driver_mobile
        except Exception as e:
            self.logger.error('司机是否有已完成的运单发生异常:{0}'.format(e))
            return None

    def is_have_payment_departure_waybill(self, driver, driverConfirm='1'):
        '''司机是否有可发车支付的运单'''
        try:
            driver_mobile = self.select_driver_mobile(driver)
            self.DBUtil = DBUtil(host=self.config['db_host'],
                                 port=self.config['db_port'],
                                 user=self.config['db_user'],
                                 passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'],
                                 charset=self.config['db_charset'])
            sql = 'SELECT t.id FROM YD_APP_TRANSPORTCASH t ' \
                  'LEFT JOIN YD_TMS_PAY_DETAIL pd ON t.id = pd.wayBillId ' \
                  'WHERE (t.partnerNo =\'{0}\' AND t.mobile = \'{1}\' AND t.delStatus = 0 ' \
                  'AND t.billStatus != \'W\' AND t.billStatus != \'Q\' ' \
                  'AND (pd.cashPayStatus = \'UNPAID\' OR pd.cashPayStatus = \'FAIL\') ' \
                  'AND (((pd.cashLoanSchedule != \'FAIL\' OR pd.cashLoanSchedule IS NULL) ' \
                  'AND (pd.oilFeeLoanSchedule != \'FAIL\' OR pd.oilFeeLoanSchedule IS NULL) ' \
                  'AND (pd.destAmtLoanSchedule != \'FAIL\' OR pd.destAmtLoanSchedule IS NULL) ' \
                  'AND (pd.retAmtLoanSchedule != \'FAI\L\' OR pd.retAmtLoanSchedule IS NULL)' \
                  'AND t.driverConfirm = {2}))) ORDER BY t.id desc'.format(self.config['partnerNo'],driver_mobile,driverConfirm)
            waybillId = self.DBUtil.excute_select_one_record(sql)
            sql2 = 'SELECT t.tmsBillCode FROM YD_APP_TRANSPORTCASH t ' \
                  'LEFT JOIN YD_TMS_PAY_DETAIL pd ON t.id = pd.wayBillId ' \
                  'WHERE (t.partnerNo =\'{0}\' AND t.mobile = \'{1}\' AND t.delStatus = 0 ' \
                  'AND t.billStatus != \'W\' AND t.billStatus != \'Q\' ' \
                  'AND (pd.cashPayStatus = \'UNPAID\' OR pd.cashPayStatus = \'FAIL\') ' \
                  'AND (((pd.cashLoanSchedule != \'FAIL\' OR pd.cashLoanSchedule IS NULL) ' \
                  'AND (pd.oilFeeLoanSchedule != \'FAIL\' OR pd.oilFeeLoanSchedule IS NULL) ' \
                  'AND (pd.destAmtLoanSchedule != \'FAIL\' OR pd.destAmtLoanSchedule IS NULL) ' \
                  'AND (pd.retAmtLoanSchedule != \'FAI\L\' OR pd.retAmtLoanSchedule IS NULL)' \
                  'AND t.driverConfirm = {2}))) ORDER BY t.id desc'.format(self.config['partnerNo'], driver_mobile, driverConfirm)
            tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            self.logger.info(
                '查询司机是否有可发车支付的运单query result, waybillId:{0},tmsBillCode:{1}'.
                format(waybillId, tmsBillCode))
            return waybillId, tmsBillCode, driver_mobile
        except Exception as e:
            self.logger.error('机是否有可发车支付的运单发生异常:{0}'.format(e))
            return None

    def is_have_payment_arrival_waybill(self, driver, driverConfirm='1'):
        '''司机是否有可到达支付的运单'''
        try:
            driver_mobile = self.select_driver_mobile(driver)
            self.DBUtil = DBUtil(host=self.config['db_host'],
                                 port=self.config['db_port'],
                                 user=self.config['db_user'],
                                 passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'],
                                 charset=self.config['db_charset'])
            sql = 'SELECT t.id FROM YD_APP_TRANSPORTCASH t ' \
                  'LEFT JOIN YD_TMS_PAY_DETAIL pd ON t.id = pd.wayBillId ' \
                  'WHERE (t.partnerNo =\'{0}\' AND t.mobile = \'{1}\' AND t.delStatus = 0 ' \
                  'AND t.destAmtConfirm IS NOT NULL AND pd.cashPayStatus = \'SUCCESS\' ' \
                  'AND (pd.destAmtPayStatus = \'UNPAID\' OR pd.destAmtPayStatus = \'FAIL\') ' \
                  'AND (((pd.cashLoanSchedule != \'FAIL\' OR pd.cashLoanSchedule IS NULL) ' \
                  'AND (pd.oilFeeLoanSchedule != \'FAIL\' OR pd.oilFeeLoanSchedule IS NULL) ' \
                  'AND (pd.destAmtLoanSchedule != \'FAIL\' OR pd.destAmtLoanSchedule IS NULL) ' \
                  'AND (pd.retAmtLoanSchedule != \'FAI\L\' OR pd.retAmtLoanSchedule IS NULL)' \
                  'AND t.driverConfirm = {2}))) ORDER BY t.id desc'.format(self.config['partnerNo'], driver_mobile, driverConfirm)
            waybillId = self.DBUtil.excute_select_one_record(sql)
            sql2 = 'SELECT t.tmsBillCode FROM YD_APP_TRANSPORTCASH t ' \
                  'LEFT JOIN YD_TMS_PAY_DETAIL pd ON t.id = pd.wayBillId ' \
                  'WHERE (t.partnerNo =\'{0}\' AND t.mobile = \'{1}\' AND t.delStatus = 0 ' \
                  'AND t.destAmtConfirm IS NOT NULL AND pd.cashPayStatus = \'SUCCESS\' ' \
                  'AND (pd.destAmtPayStatus = \'UNPAID\' OR pd.destAmtPayStatus = \'FAIL\') ' \
                  'AND (((pd.cashLoanSchedule != \'FAIL\' OR pd.cashLoanSchedule IS NULL) ' \
                  'AND (pd.oilFeeLoanSchedule != \'FAIL\' OR pd.oilFeeLoanSchedule IS NULL) ' \
                  'AND (pd.destAmtLoanSchedule != \'FAIL\' OR pd.destAmtLoanSchedule IS NULL) ' \
                  'AND (pd.retAmtLoanSchedule != \'FAI\L\' OR pd.retAmtLoanSchedule IS NULL)' \
                  'AND t.driverConfirm = {2}))) ORDER BY t.id desc'.format(self.config['partnerNo'], driver_mobile, driverConfirm)
            tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            return waybillId, tmsBillCode, driver_mobile
        except Exception as e:
            self.logger.error('司机是否有已完成的运单发生异常:{0}'.format(e))
            return None

    def is_have_payment_lastAmt_waybill(self, driver, driverConfirm='1'):
        '''司机是否有可尾款支付的运单'''
        try:
            driver_mobile = self.select_driver_mobile(driver)
            self.DBUtil = DBUtil(host=self.config['db_host'],
                                 port=self.config['db_port'],
                                 user=self.config['db_user'],
                                 passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'],
                                 charset=self.config['db_charset'])
            sql = 'SELECT t.id FROM YD_APP_TRANSPORTCASH t ' \
                  'LEFT JOIN YD_TMS_PAY_DETAIL pd ON t.id = pd.wayBillId ' \
                  'WHERE (t.partnerNo =\'{0}\' AND t.mobile = \'{1}\' AND t.delStatus = 0 ' \
                  'AND t.retAmtConfirm IS NOT NULL AND pd.retAmtPayStatus = \'SUCCESS\' ' \
                  'AND (pd.retAmtPayStatus = \'UNPAID\' OR pd.retAmtPayStatus = \'FAIL\') ' \
                  'AND (((pd.cashLoanSchedule != \'FAIL\' OR pd.cashLoanSchedule IS NULL) ' \
                  'AND (pd.oilFeeLoanSchedule != \'FAIL\' OR pd.oilFeeLoanSchedule IS NULL) ' \
                  'AND (pd.destAmtLoanSchedule != \'FAIL\' OR pd.destAmtLoanSchedule IS NULL) ' \
                  'AND (pd.retAmtLoanSchedule != \'FAI\L\' OR pd.retAmtLoanSchedule IS NULL)' \
                  'AND t.driverConfirm = {2}))) ORDER BY t.id desc'.format(self.config['partnerNo'], driver_mobile, driverConfirm)
            waybillId = self.DBUtil.excute_select_one_record(sql)
            sql2 = 'SELECT t.id, t.tmsBillCode FROM YD_APP_TRANSPORTCASH t ' \
                  'LEFT JOIN YD_TMS_PAY_DETAIL pd ON t.id = pd.wayBillId ' \
                  'WHERE (t.partnerNo =\'{0}\' AND t.mobile = \'{1}\' AND t.delStatus = 0 ' \
                  'AND t.retAmtConfirm IS NOT NULL AND pd.retAmtPayStatus = \'SUCCESS\' ' \
                  'AND (pd.retAmtPayStatus = \'UNPAID\' OR pd.retAmtPayStatus = \'FAIL\') ' \
                  'AND (((pd.cashLoanSchedule != \'FAIL\' OR pd.cashLoanSchedule IS NULL) ' \
                  'AND (pd.oilFeeLoanSchedule != \'FAIL\' OR pd.oilFeeLoanSchedule IS NULL) ' \
                  'AND (pd.destAmtLoanSchedule != \'FAIL\' OR pd.destAmtLoanSchedule IS NULL) ' \
                  'AND (pd.retAmtLoanSchedule != \'FAI\L\' OR pd.retAmtLoanSchedule IS NULL)' \
                  'AND t.driverConfirm = {2}))) ORDER BY t.id desc'.format(self.config['partnerNo'], driver_mobile,driverConfirm)
            tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            return waybillId, tmsBillCode, driver_mobile
        except Exception as e:
            self.logger.error('司机是否有可尾款支付的运单发生异常:{0}'.format(e))
            return None

    def is_have_payment_select_waybill(self, driver, driverConfirm='1'):
        '''司机是否有支付查询的运单'''
        try:
            driver_mobile = self.select_driver_mobile(driver)
            self.DBUtil = DBUtil(host=self.config['db_host'],
                                 port=self.config['db_port'],
                                 user=self.config['db_user'],
                                 passwd=self.config['db_passwd'],
                                 dbname=self.config['db_dbname'],
                                 charset=self.config['db_charset'])
            sql = 'SELECT t.id FROM YD_APP_TRANSPORTCASH t ' \
                  'LEFT JOIN YD_TMS_PAY_DETAIL pd ON t.id = pd.wayBillId ' \
                  'WHERE (t.partnerNo =\'{0}\' AND t.mobile = \'{1}\' AND t.delStatus = 0 ' \
                  'AND t.driverConfirm = {2}))) ORDER BY t.id desc'.format(self.config['partnerNo'], driver_mobile, driverConfirm)
            waybillId = self.DBUtil.excute_select_one_record(sql)
            sql2 = 'SELECT t.id, t.tmsBillCode FROM YD_APP_TRANSPORTCASH t ' \
                  'LEFT JOIN YD_TMS_PAY_DETAIL pd ON t.id = pd.wayBillId ' \
                  'WHERE (t.partnerNo =\'{0}\' AND t.mobile = \'{1}\' AND t.delStatus = 0 ' \
                  'AND t.driverConfirm = {2}))) ORDER BY t.id desc'.format(self.config['partnerNo'], driver_mobile,
                                                                           driverConfirm)
            tmsBillCode = self.DBUtil.excute_select_one_record(sql2)
            return waybillId, tmsBillCode, driver_mobile
        except Exception as e:
            self.logger.error('司机是否有支付查询的运单发生异常:{0}'.format(e))
            return None
    def create_user(self,roleName,menuJson,name,userName,mobile,isLoginApp,carType):
        '''新增账号'''
        try:
            #选择角色
            role_list = RoleCompanyGet().role_company_get().json()['content']
            if role_list == []:
                roleId = CreateRole().create_role(roleName,menuJson)
                self.logger.info('公司没有角色时新增角色,新增角色名称是:{0}'.format(roleName))
            else:
                roleId = random.choice(role_list)['roleId']
                self.logger.info('新增账号的角色ID是:{0}'.format(roleId))

            #选择项目数据权限
            projectId = CreateProject().project_data_permission_choice()

            #新增账号
            response = UserCreate().user_create(roleId,name,userName,mobile,isLoginApp,projectId,carType)
            if response.json()['code'] == 0:
                return response.json()['content'],roleId
            # 需求变动(已删除的子账号不能再新建)
            # elif response.json()['code'] == 9110028:
            #     user_list = UserSelect().user_select().json()['content']['dataList']
            #     for user in user_list:
            #         if user['userName'] == userName:
            #             UserDelete().user_delete(user['loginId'])
            #     userId = UserCreate().user_create(roleId,name,userName,mobile,isLoginApp,projectId,carType).json()['content']
            #     return userId,roleId
            # elif response.json()['code'] == 9110029:
            #     user_list = UserSelect().user_select().json()['content']['dataList']
            #     for user in user_list:
            #         if user['mobile'] == mobile:
            #             UserDelete().user_delete(user['loginId'])
            #     userId = UserCreate().user_create(roleId,name,userName,mobile,isLoginApp,projectId,carType).json()['content']
            #     return userId,roleId
            elif response.json()['code'] == 9110028:
                sql = 'DELETE FROM YD_APP_APPROVAL_USER WHERE userName = \'{0}\' and partnerNo = \'{1}\''.format(
                    userName,self.config['partnerNo'])
                self.DBUtil = DBUtil(host=self.config['db_host'], port=self.config['db_port'],
                                     user=self.config['db_user'], passwd=self.config['db_passwd'],
                                     dbname=self.config['db_dbname'], charset=self.config['db_charset'])
                print(sql)
                self.DBUtil.execute_sql(sql)
                userId = UserCreate().user_create(roleId, name, userName, mobile, isLoginApp, projectId, carType
                                                  ).json()[ 'content']
                return userId, roleId
            elif response.json()['code'] == 9110029:
                sql = 'DELETE FROM YD_APP_APPROVAL_USER WHERE mobile = \'{0}\' and partnerNo = \'{1}\''.format(mobile,
                                                                                             self.config['partnerNo'])
                self.DBUtil = DBUtil(host=self.config['db_host'], port=self.config['db_port'],
                                     user=self.config['db_user'], passwd=self.config['db_passwd'],
                                     dbname=self.config['db_dbname'], charset=self.config['db_charset'])
                print(sql)
                self.DBUtil.execute_sql(sql)
                print(sql)
                userId = UserCreate().user_create(roleId, name, userName, mobile, isLoginApp, projectId, carType
                                                  ).json()['content']
                return userId, roleId
            else:
                self.logger.info('新增账号返回错误:{0}'.format(response.json()))
                return None,None
        except Exception as e:
            self.logger.error('新增账号发生异常:{0}'.format(e))
            return None
class CreateProject(object):
    '''新增项目'''
    def __init__(self):
        self.logger = Log()
        self.config = ReadYaml(FileUtil.getProjectObsPath() +
                               '/config/config.yaml').getValue()

    def create_project(self, projectName, startTime, endTime, customerName,
                       customerCode, phone, customerDeveloper):
        '''新增项目'''
        try:
            customerId = CreateCustomer().create_customer(
                customerName=customerName,
                customerCode=customerCode,
                phone=phone,
                customerDeveloper=customerDeveloper)
            response = ProjectCreate().project_create(projectName=projectName,
                                                      custId=customerId,
                                                      startTime=startTime,
                                                      endTime=endTime)
            self.logger.info('新增的项目名称是: {0}'.format(projectName))
            # 判断项目名称是否重复
            if response.json()['code'] == 0:
                return response.json()['content']
            elif response.json()['code'] == 9020502:
                sql = 'DELETE FROM YD_TMS_PROJECT WHERE projectName = \'{0}\'and partnerNo = \'{1}\''.format(
                    projectName, self.config['partnerNo'])
                self.DBUtil = DBUtil(host=self.config['db_host'],
                                     port=self.config['db_port'],
                                     user=self.config['db_user'],
                                     passwd=self.config['db_passwd'],
                                     dbname=self.config['db_dbname'],
                                     charset=self.config['db_charset'])
                self.DBUtil.execute_sql(sql)
                projectId = ProjectCreate().project_create(
                    projectName=projectName,
                    custId=customerId,
                    startTime=startTime,
                    endTime=endTime).json()['content']
                return projectId
            else:
                self.logger.info('新增的项目名称返回错误:{0}'.format(response.json()))
                return None
        except Exception as e:
            self.logger.error('新增项目发生异常:{0}'.format(e))
            return None

    #选择项目
    def project_choice(self,
                       projectName='德邦物流',
                       customerName='德邦集团',
                       customerCode='DB20171101100',
                       phone='13077327043',
                       customerDeveloper='张经理'):
        project_list = ProjectSelect().project_select(
            rows='1000', projectStatus='1').json()['content']['dataList']
        if project_list == []:
            startTime = time.strftime('%Y-%m-%d')
            endTime = time.strftime('%Y-%m-%d',
                                    time.localtime(time.time() + 2592000))
            projectId = CreateProject().create_project(projectName, startTime,
                                                       endTime, customerName,
                                                       customerCode, phone,
                                                       customerDeveloper)
            project = {'projectId': projectId, 'projectName': projectName}
            self.logger.info('新建的项目是: {0}'.format(project))
        else:
            project = random.sample(project_list, 1)[0]
            self.logger.info('选择的项目是: {0}'.format(project))
        return project

    ##选择项目数据权限
    def project_data_permission_choice(self):
        project_list = ProjectSelect().project_select(
            rows='1000', projectStatus='1').json()['content']['dataList']
        if project_list == []:
            projectId = ''
            self.logger.info('项目数据权限选择不限')
        else:
            project = random.sample(project_list, 1)[0]
            projectId = project['projectId']
            self.logger.info('项目数据权限选择: {0}'.format(project['projectName']))
        return projectId