コード例 #1
0
def format_php_data_params():
    global _table_list
    global _db_name
    global _file_path
    global _db
    tableNames = get_db_table_list(_db_name)
    print(tableNames)
    if None == tableNames:
        print('NULL INFO')
    tab = '\t'
    linesep = file_utils.get_line_sep()
    for tableName in tableNames:
        tbname = tableName['TABLE_NAME']
        if tbname not in _table_list:
            continue
        sqlInfo = u'SELECT '
        tableColumns = get_db_table_column_list(_db_name,
                                                tableName['TABLE_NAME'])
        print(tableColumns)
        if None == tableColumns:
            continue
        for column in tableColumns:
            sqlInfo = '%s \'%s\' => $%s , %s' % (
                sqlInfo, column['COLUMN_NAME'], column['COLUMN_NAME'],
                os.linesep)
        sqlInfo = '%s FROM `%s` AS a ' % (sqlInfo[0:-1],
                                          tableName['TABLE_NAME'])
        file_utils.write_file(_file_path + tableName['TABLE_NAME'] + '.log',
                              sqlInfo + os.linesep, 'a')
コード例 #2
0
def format_column_list():
    global _table_list
    global _db_name
    global _file_path
    global _db
    tableNames = get_db_table_list(_db_name)
    print(tableNames)
    if None == tableNames:
        print('NULL INFO')
    tab = '\t'
    linesep = file_utils.get_line_sep()
    for tableName in tableNames:
        tbname = tableName['TABLE_NAME']
        if tbname not in _table_list and len(_table_list) > 0:
            continue
        sqlInfo = u'['
        tableColumns = get_db_table_column_list(_db_name,
                                                tableName['TABLE_NAME'])
        print(tableColumns)
        if None == tableColumns:
            continue
        for column in tableColumns:
            sqlInfo = "%s'%s', " % (sqlInfo, column['COLUMN_NAME'])
        sqlInfo = '%s ]' % (sqlInfo[0:-2])
        file_utils.write_file(_file_path + tableName['TABLE_NAME'] + '.log',
                              sqlInfo + os.linesep, 'a')
コード例 #3
0
def format_php_info_object():
    global _table_list
    global _db_name
    global _file_path
    global _db
    tableNames = get_db_table_list(_db_name)
    print(tableNames)
    if None == tableNames:
        print('NULL INFO')
    tab = '\t'
    linesep = file_utils.get_line_sep()
    for tableName in tableNames:
        if tableName['TABLE_NAME'] not in _table_list:
            continue
        tableColumns = get_db_table_column_list(_db_name,
                                                tableName['TABLE_NAME'])
        print(tableColumns)
        if None == tableColumns:
            continue
        classInfo = ''
        for column in tableColumns:
            classInfo = '''%s%s//%s%s%s$item->%s = %s;%s''' % (
                classInfo, tab, column['COLUMN_COMMENT'], linesep, tab,
                column['COLUMN_NAME'], '""', linesep)

        file_utils.write_file(_file_path + tableName['TABLE_NAME'] + '.log',
                              classInfo + os.linesep, 'a')
コード例 #4
0
def build_config():
    global _excel_file, _config_file, _config_map_file

    wb = excel_utils.open_excel(_excel_file)
    sheetnames = wb.get_sheet_names()

    configList = []
    configMap = {}
    configListObj = {}

    for name in sheetnames:
        ws = wb.get_sheet_by_name(name)
        info = load_type_info(ws)
        titleList = load_config_item_title(ws)
        items = load_config_item_info(ws, titleList)

        if len(items) > 0:
            info['items'] = items
            configList.append(info)
            configMap[info['code']] = info

    configListObj['version'] = int(time.time())
    configListObj['default'] = configList[0]['code']
    configListObj['items'] = configList
    file_utils.write_file(_config_file,
                          json.dumps(configListObj, ensure_ascii=False))
    file_utils.write_file(_config_map_file,
                          json.dumps(configMap, ensure_ascii=False))

    return configList
コード例 #5
0
def format_update_sql():
    global _table_list
    global _db_name
    global _file_path
    global _db
    global _sql_params_type
    tableNames = get_db_table_list(_db_name)
    print(tableNames)
    if None == tableNames:
        print('NULL INFO')
    tab = '\t'
    linesep = file_utils.get_line_sep()
    for tableName in tableNames:
        tbname = tableName['TABLE_NAME']
        if tbname not in _table_list and len(_table_list) > 0:
            continue
        sqlInfo = u'UPDATE `%s` SET ' % (tableName['TABLE_NAME'])
        pinfo = ''
        tableColumns = get_db_table_column_list(_db_name,
                                                tableName['TABLE_NAME'])
        print(tableColumns)
        if None == tableColumns:
            continue
        for column in tableColumns:
            # sqlInfo = '%s `%s` = ? ,' % (sqlInfo, column['COLUMN_NAME'])
            if _sql_params_type == 2:
                sqlInfo = sqlInfo + '`' + column['COLUMN_NAME'] + '` = %s ,'
            else:
                sqlInfo = sqlInfo + '`' + column[
                    'COLUMN_NAME'] + '` = {' + column['COLUMN_NAME'] + '} ,'
        # sqlInfo = '%s ) VALUES (%s) ' % (sqlInfo[0:-1], pinfo[0:-1])
        sqlInfo = sqlInfo[0:-1]
        file_utils.write_file(_file_path + tableName['TABLE_NAME'] + '.log',
                              sqlInfo + os.linesep, 'a')
コード例 #6
0
def format_domain():
    global _table_list
    global _db_name
    global _file_path
    global _db

    tableNames = get_db_table_list(_db_name)
    print(tableNames)
    if None == tableNames:
        print('NULL INFO')
    tab = '\t'
    linesep = file_utils.get_line_sep()
    for tableName in tableNames:
        tbname = tableName['TABLE_NAME']
        if tbname not in _table_list and len(_table_list) > 0:
            continue
        classInfo = u'public class %s { %s' % (tableName['TABLE_NAME'],
                                               linesep)
        tableColumns = get_db_table_column_list(_db_name,
                                                tableName['TABLE_NAME'])
        print(tableColumns)
        if None == tableColumns:
            continue
        for column in tableColumns:
            t = 'UnKnow'
            c = column['DATA_TYPE'].lower()
            if c in [
                    'varchar', 'text', 'char', 'longtext', 'enum',
                    'mediumtext', 'tinytext'
            ]:
                t = 'String'
            elif c in ['int', 'tinyint', 'smallint', 'mediumint', 'bit']:
                t = 'Integer'
            elif c in ['bigint']:
                t = 'Long'
            elif c in ['float', 'double', 'boolean', 'decimal', 'peal']:
                t = 'Double'
            elif c in ['date', 'datetime', 'timestamp', 'time', 'year']:
                t = 'Date'

            classInfo = '''%s%s%s/* %s%s * %s%s%s */%s%sprivate %s %s;%s''' % (
                classInfo, linesep, tab, linesep, tab,
                column['COLUMN_COMMENT'], linesep, tab, linesep, tab, t,
                column['COLUMN_NAME'], linesep)

        classInfo = '%s}' % (classInfo)

        file_utils.write_file(_file_path + tableName['TABLE_NAME'] + '.log',
                              classInfo + os.linesep, 'a')
コード例 #7
0
def run():
    global jj, exr

    # print(exr)

    exrs = exr.split('\n')
    fc = ''
    for k in jj.keys():
        content = k
        for ex in exrs:
            exs = ex.split('\t')
            if len(exs) != 2:
                continue
            if k != exs[1]:
                continue
            content += '\t' + '\t'.join(exs[0].split(' ', 1))
        fc += content + '\n'

    file_utils.write_file('d:\\a.txt', fc)
コード例 #8
0
ファイル: test.py プロジェクト: treeyh/soc-python-common
def export_card_data_sql(path: str, product_line: str, partner_code: str,
                         partner_card_category_id: str, start_id: int):
    filePaths = file_utils.walk2(path)
    # print(filePaths)

    id = start_id
    content = ''
    for filePath in filePaths:
        if len(filePath) != 2:
            continue
        card_no = filePath[1].replace('.json', '')
        cid = int(card_no[8:], 16)
        sql = ''' INSERT INTO `oscm_card_data` (`id`, `product_line_code`, `partner_code`, `partner_card_category_id`, `card_no`, `uid`, `card_info`, `backup_info`, `active_time`, `effective_time`, `task_batch_id`, `renew_count`, `card_id`, `issuer_biz_id`, `backup_biz_id`, `remark`, `status`, `create_time`, `update_time`, `version`, `del_flag`) VALUES (%s, '%s', '%s', %s, '%d', %d, '%s', '', '2021-12-28 14:50:12', '2099-01-01 00:00:00', 0, 0, 0, 0, 0, '', 1, '2021-12-28 14:50:12', '2021-12-28 14:50:12', 1, 2);
    ''' % (id, product_line, partner_code, partner_card_category_id, cid, cid,
           file_utils.read_all_file(os.path.join(filePath[0],
                                                 filePath[1])).strip())
        id += 1
        content += sql
    file_utils.write_file('d:\\card_' + product_line + '.sql', content)
コード例 #9
0
    def generate_po_bo_file(self, conf: config_model.DataSourceConfig):
        """生成bo po文件

    Args:
        conf (config_model.DataSourceConfig): [description]
        ds (ds_model.DataSourceModel): [description]

    Returns:
        [type]: [description]
    """
        ds = mysql_export_db_model.MysqlExportDbModel().export_model(conf)
        poPath = os.path.join(self.exportPath, conf.code, 'po')
        boPath = os.path.join(self.exportPath, conf.code, 'bo')
        file_utils.mkdirs(poPath, True)
        file_utils.mkdirs(boPath, True)
        tables = {}
        fields = {}
        for db in ds.dbs:
            # dbPath = os.path.join(dsPath, db.name)
            # file_util.mkdirs(dsPath, True)
            for table in db.tables:
                # filePath = os.path.join(dbPath, table.name + '_po.go')
                poFilePath = os.path.join(
                    poPath,
                    table.go_model_file_name() + '_po.go')
                poContent = self.poTemplate.render(tb=table)
                file_utils.write_file(filePath=poFilePath, content=poContent)

                boFilePath = os.path.join(
                    boPath,
                    table.go_model_file_name() + '_bo.go')
                boContent = self.boTemplate.render(tb=table)
                file_utils.write_file(filePath=boFilePath, content=boContent)

                tables['Tn' + table.go_model_name()] = table.name
                for field in table.fields:
                    fields['Cn' + field.go_field_name()] = field.name

        poTableFilePath = os.path.join(poPath, 'table_name.go')
        poContent = self.tableNameTemplate.render(tables=tables)
        file_utils.write_file(filePath=poTableFilePath, content=poContent)

        poColumnFilePath = os.path.join(poPath, 'column_name.go')
        poContent = self.columnNameTemplate.render(fields=fields)
        file_utils.write_file(filePath=poColumnFilePath, content=poContent)
        return poPath
コード例 #10
0
    def generate_model_file(self, conf: config_model.DataSourceConfig):
        """生成bo po文件

    Args:
        conf (config_model.DataSourceConfig): [description]
        ds (ds_model.DataSourceModel): [description]

    Returns:
        [type]: [description]
    """
        ds = mysql_export_db_model.MysqlExportDbModel().export_model(conf)
        print(ds)
        modelPath = os.path.join(self.exportPath, conf.code, 'model')
        file_utils.mkdirs(modelPath, True)
        for db in ds.dbs:
            for table in db.tables:
                modelFilePath = os.path.join(
                    modelPath,
                    table.go_model_file_name() + '.py')
                modelContent = self.modelTemplate.render(tb=table)
                file_utils.write_file(filePath=modelFilePath,
                                      content=modelContent)

        return modelPath
コード例 #11
0
def format_php_data_domain():
    global _table_list
    global _db_name
    global _file_path
    global _db
    tableNames = get_db_table_list(_db_name)
    print(tableNames)
    if None == tableNames:
        print('NULL TABLE')

    temp = file_utils.read_all_file('./temp.php')
    linesep = file_utils.get_line_sep()
    for tableName in tableNames:
        tbname = tableName['TABLE_NAME']
        if tbname not in _table_list:
            continue

        tbs = tbname.split('_')
        tbs2 = []
        for tb in tbs:
            tbs2.append(tb.capitalize())
        dmName = 'Data' + ''.join(tbs2)

        tableColumns = get_db_table_column_list(_db_name, tbname)
        if None == tableColumns:
            continue
        fields = ''
        fid = tableColumns[0]['COLUMN_NAME']
        fname = tableColumns[0]['COLUMN_NAME']

        for column in tableColumns:
            t = 'string'
            c = column['DATA_TYPE'].lower()
            if c in [
                    'varchar', 'text', 'char', 'longtext', 'enum',
                    'mediumtext', 'tinytext'
            ]:
                t = "string"
            elif c in ['int', 'tinyint', 'smallint', 'mediumint', 'bit']:
                t = 'int'
            elif c in ['bigint']:
                t = 'int'
            elif c in ['float', 'double', 'boolean', 'decimal', 'peal']:
                t = 'float'
            elif c in ['date', 'datetime', 'timestamp', 'time', 'year']:
                t = "string"

            if 'name' == column['COLUMN_NAME']:
                fname = column['COLUMN_NAME']
            if 'title' == column['COLUMN_NAME']:
                fname = column['COLUMN_NAME']
            fields = '''%s%s        $fields['%s'] = $this->setFieldInfo('%s' ,'%s' ,0 , '%s'); ''' % (
                fields, linesep, column['COLUMN_NAME'], column['COLUMN_NAME'],
                t, column['COLUMN_COMMENT'])

        domain = temp.replace('{DomainName}', dmName)
        domain = domain.replace('{TableName}', tbname)
        domain = domain.replace('{fields}', fields)
        domain = domain.replace('{id}', fid)
        domain = domain.replace('{name}', fname)
        file_utils.write_file(_file_path + dmName + '.php',
                              domain + os.linesep, 'a')

    return
コード例 #12
0
def format_go_bo_domain():
    global _table_list
    global _db_name
    global _db

    tableNames = get_db_table_list(_db_name)
    if None == tableNames:
        logging.info('NULL INFO')
        return

    _file_path = os.path.split(os.path.realpath(
        __file__))[0] + os.sep + 'template' + os.sep + 'bo' + os.sep
    file_utils.mkdirs(_file_path, True)

    tab = ' ' * 4
    linesep = str_utils.get_line_sep()
    for tableName in tableNames:
        tbname = tableName['TABLE_NAME']
        if tbname not in _table_list and len(_table_list) > 0:
            continue

        className = str_utils.under_score_case_to_camel_case(
            format_table_pre(tableName['TABLE_NAME'])) + 'Bo'

        classInfo = u'''package bo

import "time"

type %s struct { %s''' % (className, linesep)
        tableColumns = get_db_table_column_list(_db_name,
                                                tableName['TABLE_NAME'])

        if tableColumns is None:
            continue
        for column in tableColumns:
            t = 'UnKnow'
            c = '{}'.format(str(column['DATA_TYPE']).lower())
            columnName = str_utils.under_score_case_to_camel_case(
                column['COLUMN_NAME'])
            comment = '{}'.format(str(column['COLUMN_COMMENT']))
            columnType = '{}'.format(str(column['COLUMN_TYPE']))
            size = column['CHARACTER_MAXIMUM_LENGTH']
            key = column['COLUMN_KEY']
            sizeScale = 0
            default = column['COLUMN_DEFAULT']
            isNull = column['IS_NULLABLE']

            extra = ''

            if c in [
                    'varchar', 'text', 'char', 'longtext', 'enum',
                    'mediumtext', 'tinytext'
            ]:
                t = 'string'
            elif c in ['int', 'tinyint', 'smallint', 'mediumint', 'bit']:
                t = 'int'
                size = column['NUMERIC_PRECISION']
            elif c in ['bigint']:
                t = 'int64'
                size = column['NUMERIC_PRECISION']
            elif c in ['float', 'double', 'boolean', 'decimal', 'peal']:
                t = 'float'
                size = column['NUMERIC_PRECISION']
                sizeScale = column['NUMERIC_SCALE']
            elif c in ['date', 'datetime', 'timestamp', 'time', 'year']:
                t = 'time.Time'
                extra = column['EXTRA']

            classInfo = '''%s
%s// %s %s
%s%s %s %s %s `json:"%s"`
''' % (classInfo, tab, columnName, comment, tab, columnName, tab,
            format_go_db_type_is_null(
            isNull, key, t), tab, columnName[:1].lower() + columnName[1:])

        classInfo = '%s}' % (classInfo)

        file_utils.write_file(
            _file_path + format_table_pre(tableName['TABLE_NAME']) + '_bo.go',
            classInfo + os.linesep, 'w')