Ejemplo n.º 1
0
def _generate_entity4table(db_table, package_name, file_output_path):
    abs_path = os.path.abspath(file_output_path)
    if not os.path.exists(abs_path):
        os.makedirs(abs_path)

    entity_name = db_table.tableinfo.tablename
    if entity_name.startswith('t_'):
        entity_name = entity_name[2:]
    entity_name = convert(entity_name, '_', True)  # 实体类名称
    file_name = entity_name + 'DO.java'
    file_path = os.path.join(abs_path, file_name)
    file = open(file_path, 'w', encoding='utf-8')

    table_info = db_table.tableinfo
    table_columns = db_table.tablecolumns

    # package
    file.write('package %s.persistent.entity;\r\n' % package_name)
    # import
    file.write('import com.xiaoye.iworks.persistent.annotation.Column;\n')
    file.write('import com.xiaoye.iworks.persistent.annotation.Key;\n')
    file.write('import com.xiaoye.iworks.persistent.annotation.Table;\n')
    file.write('import com.xiaoye.iworks.persistent.entity.Entity;\n')
    file.write('import lombok.Data;\n')
    file.write('import lombok.EqualsAndHashCode;\n')
    if table_info.hasdecimal:
        file.write('import java.math.BigDecimal;\n')
    if table_info.hasdate:
        file.write('import java.util.Date;\n')

    file.write('\n/**\n')
    file.write(' * 功能描述: 实体类【%s】\n' % table_info.tabledesc)
    file.write(' * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')

    file.write('@Data\n')
    file.write('@EqualsAndHashCode(callSuper = false)\n')
    file.write('@Table(name = "%s", database = "%s")\n' %
               (table_info.tablename, table_info.dbname))
    file.write('public class %sDO extends Entity {\n' % entity_name)
    file.write('	private static final long serialVersionUID = 1L;\r\n')
    for table_column in table_columns:
        property_type = DB_JAVA_PROPERTY_TYPE_MAP[table_column.datatype]
        if table_column.primary:
            file.write('	@Key(name = "%s", comments = "%s")\n' %
                       (table_column.columnname, table_column.desc))
        else:
            file.write('	@Column(name = "%s", comments = "%s")\n' %
                       (table_column.columnname, table_column.desc))
        file.write('    private %s %s;\n' %
                   (property_type, convert(table_column.columnname, '_')))
    file.write('}')
    file.close()
Ejemplo n.º 2
0
def _generate_service_dto4table(db_table, package_name, file_output_path):
    abs_path = os.path.abspath(file_output_path) + '/api/dto'
    if not os.path.exists(abs_path):
        os.makedirs(abs_path)

    entity_name = db_table.tableinfo.tablename
    if entity_name.startswith('t_'):
        entity_name = entity_name[2:]
    entity_name = convert(entity_name, '_', True)  # 实体类名称
    file_name = entity_name + 'Dto.java'
    file_path = os.path.join(abs_path, file_name)
    file = open(file_path, 'w', encoding='utf-8')

    table_info = db_table.tableinfo
    table_columns = db_table.tablecolumns

    # package
    file.write('package %s.api.dto;\r\n' % package_name)
    # import
    file.write('import com.xiaoye.iworks.api.input.Input;\n')
    file.write('import java.io.Serializable;\n')
    file.write('import lombok.Data;\n')
    file.write('import lombok.EqualsAndHashCode;\n')
    if table_info.hasdecimal:
        file.write('import java.math.BigDecimal;\n')
    if table_info.hasdate:
        file.write('import java.util.Date;\n')

    file.write('\n/**\n')
    file.write(' * 功能描述: %s 查询入参\n' % table_info.tabledesc)
    file.write(' * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')

    file.write('@Data\n')
    file.write('@EqualsAndHashCode(callSuper = false)\n')
    file.write('public class %sDto implements Serializable {\n' % entity_name)
    file.write('    private static final long serialVersionUID = 1L;\r\n')

    for table_column in table_columns:
        property_type = DB_JAVA_PROPERTY_TYPE_MAP[table_column.datatype]
        file.write('    /** %s **/\n' % table_column.desc)
        file.write('    private %s %s;\n' %
                   (property_type, convert(table_column.columnname, '_')))

    file.write('}')
    file.close()
Ejemplo n.º 3
0
def _generate_service_constant4table(db_table, package_name, file_output_path):
    abs_path = os.path.abspath(file_output_path) + '/api/constant'
    if not os.path.exists(abs_path):
        os.makedirs(abs_path)

    entity_name = db_table.tableinfo.tablename
    if entity_name.startswith('t_'):
        entity_name = entity_name[2:]
    entity_name = convert(entity_name, '_', True)  # 实体类名称
    file_name = entity_name + 'Constant.java'
    if entity_name.endswith('constant'):
        file_name = entity_name + '.java'

    file_path = os.path.join(abs_path, file_name)
    file = open(file_path, 'w', encoding='utf-8')

    table_info = db_table.tableinfo

    # package
    file.write('package %s.api.constant;\r\n' % package_name)

    file.write('\n/**\n')
    file.write(' * 功能描述: 【%s】常量类\n' % table_info.tabledesc)
    file.write(' * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')

    file.write('public class %sConstant {\r\n' % entity_name)
    file.write('    public static interface State {\n')
    file.write('        public static final Integer NORMAL = 1;\n')
    file.write('        // TODO 其他状态类型\r\n')
    file.write('    }\n')
    file.write('}')
    file.close()
Ejemplo n.º 4
0
def _generate_controller_update4table(db_table, package_name,
                                      file_output_path):
    abs_path = os.path.abspath(file_output_path) + '/request'
    if not os.path.exists(abs_path):
        os.makedirs(abs_path)

    entity_name = db_table.tableinfo.tablename
    if entity_name.startswith('t_'):
        entity_name = entity_name[2:]
    entity_name = convert(entity_name, '_', True)  # 实体类名称
    file_name = entity_name + 'UpdateRequest.java'
    file_path = os.path.join(abs_path, file_name)
    file = open(file_path, 'w', encoding='utf-8')

    table_info = db_table.tableinfo

    # package
    file.write('package %s.request;\r\n' % package_name)
    # import
    file.write('import com.xiaoye.iworks.api.input.Input;\n')
    file.write('import lombok.Data;\n')
    file.write('import lombok.EqualsAndHashCode;\n')

    file.write('\n/**\n')
    file.write(' * 功能描述: %s 数据更新入参\n' % table_info.tabledesc)
    file.write(' * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')

    file.write('@Data\n')
    file.write('@EqualsAndHashCode(callSuper = false)\n')
    file.write('public class %sUpdateRequest extends Input {\n' % entity_name)
    file.write('    private static final long serialVersionUID = 1L;\r\n')

    file.write('}')
    file.close()
Ejemplo n.º 5
0
def _generate_criteria4table(db_table, package_name, file_output_path):
    abs_path = os.path.abspath(file_output_path)
    if not os.path.exists(abs_path):
        os.makedirs(abs_path)

    entity_name = db_table.tableinfo.tablename
    if entity_name.startswith('t_'):
        entity_name = entity_name[2:]
    entity_name = convert(entity_name, '_', True)  # 实体类名称
    file_name = entity_name + 'Criteria.java'
    file_path = os.path.join(abs_path, file_name)
    file = open(file_path, 'w', encoding='utf-8')

    table_info = db_table.tableinfo
    table_columns = db_table.tablecolumns

    # package
    file.write('package %s.persistent.entity;\r\n' % package_name)
    # import
    file.write('import com.google.common.collect.Lists;\n')
    file.write('import com.xiaoye.iworks.persistent.entity.Condition;\n')
    file.write('import com.xiaoye.iworks.persistent.entity.Entity;\n')
    file.write('import com.xiaoye.iworks.utils.CollectionUtils;\n')
    file.write('import com.xiaoye.iworks.utils.StringUtils;\n')
    if table_info.hasdecimal:
        file.write('import java.math.BigDecimal;\n')
    if table_info.hasdate:
        file.write('import java.util.Date;\n')
    file.write('import java.util.List;\n')

    file.write('\n/**\n')
    file.write(' * 功能描述: 实体类查询条件【%s】\n' % table_info.tabledesc)
    file.write(' * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')

    file.write('public class %sCriteria extends Condition {\r\n' % entity_name)
    file.write('    @Override\n')
    file.write('    public Class<? extends Entity> geEntityClass() {\n')
    file.write('        return %sDO.class;\n' % entity_name)
    file.write('    }\r\n')

    file.write('    public %sCriteria() {\n' % entity_name)
    file.write('        criterias = Lists.newArrayList();\n')
    file.write('    }\r\n')

    file.write('    public void or(GeneratedCriteria GeneratedCriteria) {\n')
    file.write('        criterias.add(GeneratedCriteria);\n')
    file.write('    }\r\n')

    file.write('    public GeneratedCriteria or() {\n')
    file.write(
        '        GeneratedCriteria generatedCriteria = createCriteriaInternal();\n'
    )
    file.write('        criterias.add(generatedCriteria);\n')
    file.write('        return generatedCriteria;\n')
    file.write('    }\r\n')

    file.write('    public GeneratedCriteria createCriteriaInternal() {\n')
    file.write(
        '        GeneratedCriteria generatedCriteria = new GeneratedCriteria();\n'
    )
    file.write('        if (criterias.size() == 0) {\n')
    file.write('            criterias.add(generatedCriteria);\n')
    file.write('        }\n')
    file.write('        return generatedCriteria;\n')
    file.write('    }\r\n')

    file.write('    public class GeneratedCriteria extends Criteria {\r\n')
    file.write('        protected GeneratedCriteria() {\n')
    file.write('            super();\n')
    file.write('            criterions = Lists.newArrayList();\n')
    file.write('        }\r\n')

    for table_column in table_columns:
        java_property = DB_JAVA_PROPERTY_TYPE_MAP[table_column.datatype]
        java_name = convert(table_column.columnname, '_')
        java_name_upper = convert(table_column.columnname, '_', True)
        file.write('        public GeneratedCriteria and%sIsNull() {\n' %
                   java_name_upper)
        file.write('            addCriterion("`%s` is null");\n' %
                   table_column.columnname)
        file.write('            return this;\n')
        file.write('        }\r\n')

        file.write('        public GeneratedCriteria and%sIsNotNull() {\n' %
                   java_name_upper)
        file.write('            addCriterion("`%s` is not null");\n' %
                   table_column.columnname)
        file.write('            return this;\n')
        file.write('        }\r\n')

        if java_property != 'String':
            file.write(
                '        public GeneratedCriteria and%sEqualTo(%s value) {\n' %
                (java_name_upper, java_property))
            file.write('            if(value == null) return this;\n')
            file.write('            addCriterion("`%s` =", value, "%s");\n' %
                       (table_column.columnname, java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')

            file.write(
                '        public GeneratedCriteria and%sNotEqualTo(%s value) {\n'
                % (java_name_upper, java_property))
            file.write('            if(value == null) return this;\n')
            file.write('            addCriterion("`%s` <>", value, "%s");\n' %
                       (table_column.columnname, java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')
        else:
            file.write(
                '        public GeneratedCriteria and%sEqualTo(%s value) {\n' %
                (java_name_upper, java_property))
            file.write(
                '            if(StringUtils.isBlank(value)) return this;\n')
            file.write('            addCriterion("`%s` =", value, "%s");\n' %
                       (table_column.columnname, java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')

            file.write(
                '        public GeneratedCriteria and%sNotEqualTo(%s value) {\n'
                % (java_name_upper, java_property))
            file.write(
                '            if(StringUtils.isBlank(value)) return this;\n')
            file.write('            addCriterion("`%s` <>", value, "%s");\n' %
                       (table_column.columnname, java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')

        if java_property != 'String':
            file.write(
                '        public GeneratedCriteria and%sGreaterThan(%s value) {\n'
                % (java_name_upper, java_property))
            file.write('            if(value == null) return this;\n')
            file.write('            addCriterion("`%s` >", value, "%s");\n' %
                       (table_column.columnname, java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')

            file.write(
                '        public GeneratedCriteria and%sGreaterThanOrEqualTo(%s value) {\n'
                % (java_name_upper, java_property))
            file.write('            if(value == null) return this;\n')
            file.write('            addCriterion("`%s` >=", value, "%s");\n' %
                       (table_column.columnname, java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')

            file.write(
                '        public GeneratedCriteria and%sLessThan(%s value) {\n'
                % (java_name_upper, java_property))
            file.write('            if(value == null) return this;\n')
            file.write('            addCriterion("`%s` <", value, "%s");\n' %
                       (table_column.columnname, java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')

            file.write(
                '        public GeneratedCriteria and%sLessThanOrEqualTo(%s value) {\n'
                % (java_name_upper, java_property))
            file.write('            if(value == null) return this;\n')
            file.write('            addCriterion("`%s` <=", value, "%s");\n' %
                       (table_column.columnname, java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')
        else:
            file.write(
                '        public GeneratedCriteria and%sLike(%s value) {\n' %
                (java_name_upper, java_property))
            file.write(
                '            if(StringUtils.isBlank(value)) return this;\n')
            file.write('            addCriterion("`%s` like", %s, "%s");\n' %
                       (table_column.columnname,
                        'String.format("%s%s%s", "%", value, "%")', java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')

            file.write(
                '        public GeneratedCriteria and%sNotLike(%s value) {\n' %
                (java_name_upper, java_property))
            file.write(
                '            if(StringUtils.isBlank(value)) return this;\n')
            file.write(
                '            addCriterion("`%s` not like", %s, "%s");\n' %
                (table_column.columnname,
                 'String.format("%s%s%s", "%", value, "%")', java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')

        file.write(
            '        public GeneratedCriteria and%sIn(List<%s> values) {\n' %
            (java_name_upper, java_property))
        file.write(
            '            if(CollectionUtils.isEmpty(values)) return this;\n')
        file.write('            addCriterion("`%s` in", values, "%s");\n' %
                   (table_column.columnname, java_name))
        file.write('            return this;\n')
        file.write('        }\r\n')

        file.write(
            '        public GeneratedCriteria and%sNotIn(List<%s> values) {\n'
            % (java_name_upper, java_property))
        file.write(
            '            if(CollectionUtils.isEmpty(values)) return this;\n')
        file.write('            addCriterion("`%s` not in", values, "%s");\n' %
                   (table_column.columnname, java_name))
        file.write('            return this;\n')
        file.write('        }\r\n')

        if java_property != 'String':
            file.write(
                '        public GeneratedCriteria and%sBetween(%s value1, %s value2) {\n'
                % (java_name_upper, java_property, java_property))
            file.write(
                '            if(value1 == null || value2 == null) return this;\n'
            )
            file.write(
                '            addCriterion("`%s` between", value1, value2, "%s");\n'
                % (table_column.columnname, java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')

            file.write(
                '        public GeneratedCriteria and%sNotBetween(%s value1, %s value2) {\n'
                % (java_name_upper, java_property, java_property))
            file.write(
                '            if(value1 == null || value2 == null) return this;\n'
            )
            file.write(
                '            addCriterion("`%s` not between", value1, value2, "%s");\n'
                % (table_column.columnname, java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')
        else:
            file.write(
                '        public GeneratedCriteria and%sBetween(%s value1, %s value2) {\n'
                % (java_name_upper, java_property, java_property))
            file.write(
                '            if(StringUtils.hasBlankString(value1, value2)) return this;\n'
            )
            file.write(
                '            addCriterion("`%s` between", value1, value2, "%s");\n'
                % (table_column.columnname, java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')

            file.write(
                '        public GeneratedCriteria and%sNotBetween(%s value1, %s value2) {\n'
                % (java_name_upper, java_property, java_property))
            file.write(
                '            if(StringUtils.hasBlankString(value1, value2)) return this;\n'
            )
            file.write(
                '            addCriterion("`%s` not between", value1, value2, "%s");\n'
                % (table_column.columnname, java_name))
            file.write('            return this;\n')
            file.write('        }\r\n')

    file.write('    }\n')
    file.write('}')
    file.close()
Ejemplo n.º 6
0
def _generate_controller4table(db_table, package_name, file_output_path):
    abs_path = os.path.abspath(file_output_path)
    if not os.path.exists(abs_path):
        os.makedirs(abs_path)

    entity_name = db_table.tableinfo.tablename
    if entity_name.startswith('t_'):
        entity_name = entity_name[2:]
    up_entity_name = convert(entity_name, '_', True)  # 实体类名称
    lo_entity_name = convert(entity_name, '_')  # 实体类名称
    file_name = up_entity_name + 'Controller.java'
    file_path = os.path.join(abs_path, file_name)
    file = open(file_path, 'w', encoding='utf-8')

    table_info = db_table.tableinfo

    # package
    file.write('package %s;\r\n' % package_name)
    file.write('import com.xiaoye.iworks.api.result.Response;\n')
    file.write('import %s.api.%sService;\n' % (package_name, up_entity_name))
    file.write('import %s.api.dto.%sDto;\n' % (package_name, up_entity_name))
    file.write('import %s.api.input.%sQueryInput;\n' %
               (package_name, up_entity_name))
    file.write('import %s.request.%sQueryRequest;\n' %
               (package_name, up_entity_name))
    file.write('import %s.request.%sUpdateRequest;\n' %
               (package_name, up_entity_name))
    file.write('import com.xiaoye.iworks.common.api.BasicController;\n')
    file.write(
        'import com.xiaoye.iworks.common.logger.annotation.RecordLogger;\n')
    file.write(
        'import com.xiaoye.iworks.common.session.annotation.CheckSession;\n')
    file.write(
        'import org.springframework.beans.factory.annotation.Autowired;\n')
    file.write('import org.springframework.web.bind.annotation.RequestBody;\n')
    file.write(
        'import org.springframework.web.bind.annotation.RequestMapping;\n')
    file.write(
        'import org.springframework.web.bind.annotation.RestController;\n')

    file.write('\n/**\n')
    file.write(' * 功能描述: 【%s】 控制器类\n' % table_info.tabledesc)
    file.write(' * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')

    file.write('@RestController\n')
    file.write(
        '@RequestMapping(value = "%s", produces = "application/json")\n' %
        entity_name)
    file.write('public class %sController extends BasicController {\r\n' %
               up_entity_name)

    file.write('    @Autowired\n')
    file.write('    private %sService %sService;\r\n' %
               (up_entity_name, lo_entity_name))

    file.write('    @RecordLogger\n')
    file.write('//    @CheckSession(permission = "")\n')
    file.write('    @RequestMapping(value = "list")\n')
    file.write(
        '    public Response list(@RequestBody %sQueryRequest request) {\n' %
        up_entity_name)
    file.write('        %sQueryInput queryInput = new %sQueryInput();\n' %
               (up_entity_name, up_entity_name))
    file.write('        // TODO 参数校验以及参数填充\r\n')
    file.write('        return %sService.list%ss(queryInput);\n' %
               (lo_entity_name, up_entity_name))
    file.write('    }\r\n')

    file.write('    @RecordLogger\n')
    file.write('//    @CheckSession(permission = "")\n')
    file.write('    @RequestMapping(value = "find")\n')
    file.write(
        '    public Response find(@RequestBody %sQueryRequest request) {\n' %
        up_entity_name)
    file.write('        %sQueryInput queryInput = new %sQueryInput();\n' %
               (up_entity_name, up_entity_name))
    file.write('        // TODO 参数校验以及参数填充\r\n')
    file.write('        return %sService.find%s(queryInput);\n' %
               (lo_entity_name, up_entity_name))
    file.write('    }\r\n')

    file.write('    @RecordLogger\n')
    file.write('//    @CheckSession(permission = "")\n')
    file.write('    @RequestMapping(value = "update")\n')
    file.write(
        '    public Response update(@RequestBody %sUpdateRequest request) {\n'
        % up_entity_name)
    file.write('        %sDto dto = new %sDto();\n' %
               (up_entity_name, up_entity_name))
    file.write('        // TODO 参数填充(判断新增or修改)\r\n')
    file.write('        if(dto.getPkid() == null) {\n')
    file.write('            return %sService.insert%s(dto);\n' %
               (lo_entity_name, up_entity_name))
    file.write('        } else {\n')
    file.write('            return %sService.update%s(dto);\n' %
               (lo_entity_name, up_entity_name))
    file.write('        }\n')
    file.write('    }\r\n')

    file.write('    @RecordLogger\n')
    file.write('//    @CheckSession(permission = "")\n')
    file.write('    @RequestMapping(value = "delete")\n')
    file.write(
        '    public Response delete(@RequestBody %sQueryRequest request) {\n' %
        up_entity_name)
    file.write('        %sQueryInput queryInput = new %sQueryInput();\n' %
               (up_entity_name, up_entity_name))
    file.write('        // TODO 参数校验以及参数填充\r\n')
    file.write('        return %sService.delete%s(queryInput);\n' %
               (lo_entity_name, up_entity_name))
    file.write('    }\r\n')

    file.write('}')
    file.close()
Ejemplo n.º 7
0
def _generate_mapper4table(db_table, package_name, file_output_path):
    abs_path = os.path.abspath(file_output_path)
    if not os.path.exists(abs_path):
        os.makedirs(abs_path)

    entity_name = db_table.tableinfo.tablename
    if entity_name.startswith('t_'):
        entity_name = entity_name[2:]
    entity_name = convert(entity_name, '_', True)  # 实体类名称
    file_name = entity_name + 'Mapper.java'
    file_path = os.path.join(abs_path, file_name)
    file = open(file_path, 'w', encoding='utf-8')

    table_info = db_table.tableinfo
    table_columns = db_table.tablecolumns

    # package
    file.write('package %s.persistent.mapper;\r\n' % package_name)
    # import
    file.write('import %s.persistent.entity.%sDO;\n' %
               (package_name, entity_name))
    file.write('import %s.persistent.entity.%sCriteria;\n' %
               (package_name, entity_name))
    file.write('import com.xiaoye.iworks.persistent.provider.SQLProvider;\n')
    file.write('import org.apache.ibatis.annotations.*;\n')
    file.write('import java.util.List;\n')

    file.write('\n/**\n')
    file.write(' * 功能描述: 实体类数据库接口【%s】\n' % table_info.tabledesc)
    file.write(' * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')

    file.write('@Mapper\n')
    file.write('public interface %sMapper {\r\n' % entity_name)

    file.write(
        '    @InsertProvider(method = "insert", type = SQLProvider.class)\n')
    if len(table_info.primarykeys) == 1:
        file.write(
            '    @Options(useGeneratedKeys = true, keyProperty = "%s", keyColumn = "%s")\n'
            % (convert(table_info.primarykeys[0],
                       '_'), table_info.primarykeys[0]))
    file.write('    public int insert(%sDO entity);\r\n' % entity_name)

    file.write(
        '    @InsertProvider(method = "insertSelective", type = SQLProvider.class)\n'
    )
    if len(table_info.primarykeys) == 1:
        file.write(
            '    @Options(useGeneratedKeys = true, keyProperty = "%s", keyColumn = "%s")\n'
            % (convert(table_info.primarykeys[0],
                       '_'), table_info.primarykeys[0]))
    file.write('    public int insertSelective(%sDO entity);\r\n' %
               entity_name)

    file.write(
        '    @UpdateProvider(method = "update", type = SQLProvider.class)\n')
    file.write('    public int update(%sDO entity);\r\n' % entity_name)

    file.write(
        '    @UpdateProvider(method = "updateSelective", type = SQLProvider.class)\n'
    )
    file.write('    public int updateSelective(%sDO entity);\r\n' %
               entity_name)

    file.write(
        '    @DeleteProvider(method = "deleteByCriteria", type = SQLProvider.class)\n'
    )
    file.write('    public int delete(%sCriteria criteria);\r\n' % entity_name)

    file.write(
        '    @SelectProvider(method = "selectByCriteria", type = SQLProvider.class)\n'
    )
    file.write('    @ResultMap("BasicResultMap")\n')
    file.write('    public %sDO selectForOne(%sCriteria criteria);\r\n' %
               (entity_name, entity_name))

    file.write(
        '    @SelectProvider(method = "selectByCriteria", type = SQLProvider.class)\n'
    )
    file.write('    @ResultMap("BasicResultMap")\n')
    file.write(
        '    public List<%sDO> selectForList(%sCriteria criteria);\r\n' %
        (entity_name, entity_name))

    file.write(
        '    @SelectProvider(method = "countByCriteria", type = SQLProvider.class)\n'
    )
    file.write('    @ResultMap("BasicResultMap")\n')
    file.write('    public int count(%sCriteria criteria);\n' % entity_name)

    file.write('}')
    file.close()
Ejemplo n.º 8
0
def _generate_mapping4table(db_table, package_name, file_output_path):
    abs_path = os.path.abspath(file_output_path)
    if not os.path.exists(abs_path):
        os.makedirs(abs_path)

    entity_name = db_table.tableinfo.tablename
    if entity_name.startswith('t_'):
        entity_name = entity_name[2:]
    entity_name = convert(entity_name, '_', True)  # 实体类名称
    file_name = entity_name + 'Mapping.xml'
    file_path = os.path.join(abs_path, file_name)
    file = open(file_path, 'w', encoding='utf-8')

    table_info = db_table.tableinfo
    table_columns = db_table.tablecolumns

    file.write('<?xml version="1.0" encoding="UTF-8"?>\r\n')
    # namespace
    file.write(
        '<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">\n'
    )
    file.write('<mapper namespace="%s.persistent.mapper.%sMapper">\r\n' %
               (package_name, entity_name))
    file.write(
        '	<resultMap id="BasicResultMap" type="%s.persistent.entity.%sDO">\n' %
        (package_name, entity_name))

    for table_column in table_columns:
        data_type = get_key(DB_COLUMN_DATA_TYPE_MAP, table_column.datatype)
        if data_type == 'datetime':
            data_type = 'TIMESTAMP'
        java_name = convert(table_column.columnname, '_')
        if table_column.primary:
            file.write(
                '	    <id column="%s" jdbcType="%s" property="%s" />\n' %
                (table_column.columnname, data_type.upper(), java_name))
        else:
            file.write(
                '	    <result column="%s" jdbcType="%s" property="%s" />\n' %
                (table_column.columnname, data_type.upper(), java_name))

    file.write('	</resultMap>\r\n')

    file.write('	<sql id="Basic_Where_Clause">\n')
    file.write('		<where>\n')
    file.write(
        '			<foreach collection="criterias" item="item" separator="or">\n')
    file.write('				<if test="item.valid">\n')
    file.write('					<trim prefix="(" prefixOverrides="and" suffix=")">\n')
    file.write(
        '						<foreach collection="item.criterions" item="criterion">\n')
    file.write('							<choose>\n')
    file.write('								<when test="criterion.noValue">\n')
    file.write('									and ${criterion.condition}\n')
    file.write('								</when>\n')
    file.write('								<when test="criterion.singleValue">\n')
    file.write('									and ${criterion.condition} #{criterion.value}\n')
    file.write('								</when>\n')
    file.write('								<when test="criterion.betweenValue">\n')
    file.write(
        '									and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}\n'
    )
    file.write('								</when>\n')
    file.write('								<when test="criterion.listValue">\n')
    file.write('									and ${criterion.condition}\n')
    file.write(
        '									<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">\n'
    )
    file.write('										#{listItem}\n')
    file.write('									</foreach>\n')
    file.write('								</when>\n')
    file.write('							</choose>\n')
    file.write('						</foreach>\n')
    file.write('					</trim>\n')
    file.write('				</if>\n')
    file.write('			</foreach>\n')
    file.write('		</where>\n')
    file.write('	</sql>\r\n')

    file.write('	<sql id="Basic_Columns">\n')
    file.write('		')
    length = len(table_columns)
    i = 1
    for table_column in table_columns:
        if i < length:
            file.write('`%s`,' % table_column.columnname)
        else:
            file.write('`%s`' % table_column.columnname)
        i += 1
    file.write('\n	</sql>\r\n')

    file.write('	<sql id="Database_Table_Choose">\n')
    file.write('		<choose>\n')
    file.write('			<when test="dbIndex == null and tbIndex == null">\n')
    file.write('				`%s`.`%s`\n' % (table_info.dbname, table_info.tablename))
    file.write('			</when>\n')
    file.write('			<when test="dbIndex != null and tbIndex == null">\n')
    file.write('				`%s_#{dbIndex}`.`%s`\n' %
               (table_info.dbname, table_info.tablename))
    file.write('			</when>\n')
    file.write('			<when test="dbIndex != null and tbIndex != null">\n')
    file.write('				`%s_#{dbIndex}`.`%s_#{tbIndex}`\n' %
               (table_info.dbname, table_info.tablename))
    file.write('			</when>\n')
    file.write('			<when test="dbIndex == null and tbIndex != null">\n')
    file.write('				`%s`.`%s_#{tbIndex}`\n' %
               (table_info.dbname, table_info.tablename))
    file.write('			</when>\n')
    file.write('		</choose>\n')
    file.write('	</sql>\n')
    file.write('</mapper>\n')
    file.close()
Ejemplo n.º 9
0
def _generate_service_impl4table(db_table, package_name, file_output_path):
    abs_path = os.path.abspath(file_output_path) + '/core'
    if not os.path.exists(abs_path):
        os.makedirs(abs_path)

    entity_name = db_table.tableinfo.tablename
    if entity_name.startswith('t_'):
        entity_name = entity_name[2:]
    up_entity_name = convert(entity_name, '_', True)  # 实体类名称
    lo_entity_name = convert(entity_name, '_')  # 实体类名称
    file_name = up_entity_name + 'ServiceImpl.java'
    file_path = os.path.join(abs_path, file_name)
    file = open(file_path, 'w', encoding='utf-8')

    table_info = db_table.tableinfo

    # package
    file.write('package %s.core;\r\n' % package_name)
    # import
    file.write('import com.xiaoye.iworks.api.result.DataResponse;\n')
    file.write('import com.xiaoye.iworks.api.result.PageResponse;\n')
    file.write('import %s.api.%sService;\n' % (package_name, up_entity_name))
    if entity_name.endswith('constant'):
        file.write('import %s.api.constant.%s;\n' %
                   (package_name, up_entity_name))
    else:
        file.write('import %s.api.constant.%sConstant;\n' %
                   (package_name, up_entity_name))
    file.write('import %s.api.dto.%sDto;\n' % (package_name, up_entity_name))
    file.write('import %s.api.input.%sQueryInput;\n' %
               (package_name, up_entity_name))
    file.write('import %s.core.exception.%sErrorCode;\n' %
               (package_name, up_entity_name))
    file.write('import %s.persistent.entity.%sCriteria;\n' %
               (package_name, up_entity_name))
    file.write('import %s.persistent.entity.%sDO;\n' %
               (package_name, up_entity_name))
    file.write('import %s.persistent.mapper.%sMapper;\n' %
               (package_name, up_entity_name))
    file.write(
        'import com.xiaoye.iworks.common.exception.BizServiceException;\n')
    file.write(
        'import com.xiaoye.iworks.persistent.constant.PersistentConstant;\n')
    file.write('import com.xiaoye.iworks.utils.CollectionUtils;\n')
    file.write('import com.xiaoye.iworks.utils.DateTimeUtils;\n')
    file.write('import com.xiaoye.iworks.utils.exception.ServiceException;\n')
    file.write('import org.slf4j.Logger;\n')
    file.write('import org.slf4j.LoggerFactory;\n')
    file.write('import org.springframework.beans.BeanUtils;\n')
    file.write('import org.springframework.stereotype.Service;\n')
    file.write('import javax.annotation.Resource;\n')
    file.write('import java.util.List;\n')

    file.write('\n/**\n')
    file.write(' * 功能描述: 实体类业务接口实现类【%s】\n' % table_info.tabledesc)
    file.write(' * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')

    file.write('@Service\n')
    file.write('public class %sServiceImpl implements %sService {\n' %
               (up_entity_name, up_entity_name))
    file.write(
        '    public final Logger LOGGER = LoggerFactory.getLogger(getClass());\r\n'
    )

    file.write('    @Resource\n')
    file.write('    private %sMapper %sMapper;\n' %
               (up_entity_name, lo_entity_name))

    file.write('    @Override\n')
    file.write(
        '    public PageResponse<%sDto> list%ss(%sQueryInput queryInput) {\n' %
        (up_entity_name, up_entity_name, up_entity_name))
    file.write(
        '        PageResponse<%sDto> response = new PageResponse<>();\n' %
        up_entity_name)
    file.write('        try {\n')
    file.write('            %sCriteria criteria = new %sCriteria();\n' %
               (up_entity_name, up_entity_name))
    file.write('            // TODO do something here \r\n')
    file.write('            if(queryInput.isPagenation()) {\n')
    file.write(
        '                criteria.setPagination(queryInput.isPagenation());\n')
    file.write('                criteria.setOffset(queryInput.getOffset());\n')
    file.write('                criteria.setLimit(queryInput.getLimit());\n')
    file.write('                Integer total = %sMapper.count(criteria);\n' %
               lo_entity_name)
    file.write(
        '                response.getData().setOffset(queryInput.getOffset());\n'
    )
    file.write(
        '                response.getData().setLimit(queryInput.getLimit());\n'
    )
    file.write('                response.getData().setTotal(total);\n')
    file.write('                if(total == 0) {\n')
    file.write('                    return response;\n')
    file.write('                }\n')
    file.write('            }\n')
    file.write(
        '            List<%sDO> results = %sMapper.selectForList(criteria);\n'
        % (up_entity_name, lo_entity_name))
    file.write(
        '            List<%sDto> datas = CollectionUtils.transform(results, (entity) -> {\n'
        % up_entity_name)
    file.write('                %sDto dto = new %sDto();\n' %
               (up_entity_name, up_entity_name))
    file.write('                BeanUtils.copyProperties(entity, dto);\n')
    file.write('                return dto;\n')
    file.write('            });\n')
    file.write('            response.getData().setDatas(datas);\n')
    file.write('        } catch (ServiceException e) {\n')
    file.write('            response.setRetcode(e.getCode());\n')
    file.write('            response.setMessage(e.getMessage());\n')
    file.write('            LOGGER.error(e.getCode(), e);\n')
    file.write('        } catch (Exception e) {\n')
    file.write(
        '            response.setRetcode(%sErrorCode.DATA_QRY_ERROR);\n' %
        up_entity_name)
    file.write('            response.setMessage("%s数据列表查询异常");\n' %
               table_info.tabledesc)
    file.write('            LOGGER.error(%sErrorCode.DATA_QRY_ERROR, e);\n' %
               up_entity_name)
    file.write('        }\n')
    file.write('        return response;\n')
    file.write('    }\r\n')

    file.write('    @Override\n')
    file.write(
        '    public DataResponse<%sDto> find%s(%sQueryInput queryInput) {\n' %
        (up_entity_name, up_entity_name, up_entity_name))
    file.write(
        '        DataResponse<%sDto> response = new DataResponse<>();\n' %
        up_entity_name)
    file.write('        try {\n')
    file.write('            // 必要参数校验\r\n')
    file.write('            %sCriteria criteria = new %sCriteria();\n' %
               (up_entity_name, up_entity_name))
    file.write('            // TODO do something here \r\n')
    file.write('            %sDO result = %sMapper.selectForOne(criteria);\n' %
               (up_entity_name, lo_entity_name))
    file.write('            if(result == null) {\n')
    file.write('                if(queryInput.isCheckNull()) {\n')
    file.write(
        '                    response.setRetcode(%sErrorCode.DATA_UNEXIST_ERROR);\n'
        % up_entity_name)
    file.write('                }\n')
    file.write('                response.setMessage("%s数据不存在");\n' %
               table_info.tabledesc)
    file.write('                return response;\n')
    file.write('            }\n')
    file.write('            %sDto dto = new %sDto();\n' %
               (up_entity_name, up_entity_name))
    file.write('            BeanUtils.copyProperties(result, dto);\n')
    file.write('            response.setData(dto);\n')
    file.write('        } catch (ServiceException e) {\n')
    file.write('            response.setRetcode(e.getCode());\n')
    file.write('            response.setMessage(e.getMessage());\n')
    file.write('            LOGGER.error(e.getCode(), e);\n')
    file.write('        } catch (Exception e) {\n')
    file.write(
        '            response.setRetcode(%sErrorCode.DATA_QRY_ERROR);\n' %
        up_entity_name)
    file.write('            response.setMessage("%s数据详情查询异常");\n' %
               table_info.tabledesc)
    file.write('            LOGGER.error(%sErrorCode.DATA_QRY_ERROR, e);\n' %
               up_entity_name)
    file.write('        }\n')
    file.write('        return response;\n')
    file.write('    }\r\n')

    file.write('    @Override\n')
    file.write('    public DataResponse<Long> insert%s(%sDto dto) {\n' %
               (up_entity_name, up_entity_name))
    file.write('        DataResponse<Long> response = new DataResponse<>();\n')
    file.write('        try {\n')
    file.write('            %sDO %sDO = new %sDO();\n' %
               (up_entity_name, lo_entity_name, up_entity_name))
    file.write('            BeanUtils.copyProperties(dto, %sDO);\n' %
               lo_entity_name)
    if entity_name.endswith('constant'):
        file.write('            %sDO.setState(%s.State.NORMAL);\n' %
                   (lo_entity_name, up_entity_name))
    else:
        file.write('            %sDO.setState(%sConstant.State.NORMAL);\n' %
                   (lo_entity_name, up_entity_name))
    file.write(
        '            %sDO.setLstate(PersistentConstant.Lstate.NORMAL);\n' %
        lo_entity_name)
    file.write(
        '            %sDO.setCreateTime(DateTimeUtils.currentDate());\n' %
        lo_entity_name)
    file.write(
        '            %sDO.setModifyTime(DateTimeUtils.currentDate());\n' %
        lo_entity_name)
    file.write('            %sMapper.insertSelective(%sDO);\n' %
               (lo_entity_name, lo_entity_name))
    file.write('            response.setData(%sDO.getPkid());\n' %
               lo_entity_name)
    file.write('        } catch (ServiceException e) {\n')
    file.write('            response.setRetcode(e.getCode());\n')
    file.write('            response.setMessage(e.getMessage());\n')
    file.write('            LOGGER.error(e.getCode(), e);\n')
    file.write('        } catch (Exception e) {\n')
    file.write(
        '            response.setRetcode(%sErrorCode.DATA_INSERT_ERROR);\n' %
        up_entity_name)
    file.write('            response.setMessage("%s数据新增异常");\n' %
               table_info.tabledesc)
    file.write(
        '            LOGGER.error(%sErrorCode.DATA_INSERT_ERROR, e);\n' %
        up_entity_name)
    file.write('        }\n')
    file.write('        return response;\n')
    file.write('    }\r\n')

    file.write('    @Override\n')
    file.write('    public DataResponse<Integer> update%s(%sDto dto) {\n' %
               (up_entity_name, up_entity_name))
    file.write(
        '        DataResponse<Integer> response = new DataResponse<>();\n')
    file.write('        try {\n')
    file.write('            // 必要参数校验\r\n')
    file.write('            %sDO %sDO = new %sDO();\n' %
               (up_entity_name, lo_entity_name, up_entity_name))
    file.write('            BeanUtils.copyProperties(dto, %sDO);\n' %
               lo_entity_name)
    file.write(
        '            %sDO.setModifyTime(DateTimeUtils.currentDate());\n' %
        lo_entity_name)
    file.write(
        '            Integer result = %sMapper.insertSelective(%sDO);\n' %
        (lo_entity_name, lo_entity_name))
    file.write('            response.setData(result);\n')
    file.write('        } catch (ServiceException e) {\n')
    file.write('            response.setRetcode(e.getCode());\n')
    file.write('            response.setMessage(e.getMessage());\n')
    file.write('            LOGGER.error(e.getCode(), e);\n')
    file.write('        } catch (Exception e) {\n')
    file.write(
        '            response.setRetcode(%sErrorCode.DATA_UPDATE_ERROR);\n' %
        up_entity_name)
    file.write('            response.setMessage("%s数据修改异常");\n' %
               table_info.tabledesc)
    file.write(
        '            LOGGER.error(%sErrorCode.DATA_UPDATE_ERROR, e);\n' %
        up_entity_name)
    file.write('        }\n')
    file.write('        return response;\n')
    file.write('    }\r\n')

    file.write('    @Override\n')
    file.write(
        '    public DataResponse<Integer> delete%s(%sQueryInput queryInput) {\n'
        % (up_entity_name, up_entity_name))
    file.write(
        '        DataResponse<Integer> response = new DataResponse<>();\n')
    file.write('        try {\n')
    file.write('            %sCriteria criteria = new %sCriteria();\n' %
               (up_entity_name, up_entity_name))
    file.write('            // TODO do something here \r\n')
    file.write('            Integer result = %sMapper.delete(criteria);\n' %
               lo_entity_name)
    file.write('            response.setData(result);\n')
    file.write('        } catch (ServiceException e) {\n')
    file.write('            response.setRetcode(e.getCode());\n')
    file.write('            response.setMessage(e.getMessage());\n')
    file.write('            LOGGER.error(e.getCode(), e);\n')
    file.write('        } catch (Exception e) {\n')
    file.write(
        '            response.setRetcode(%sErrorCode.DATA_DELETE_ERROR);\n' %
        up_entity_name)
    file.write('            response.setMessage("%s数据删除异常");\n' %
               table_info.tabledesc)
    file.write(
        '            LOGGER.error(%sErrorCode.DATA_DELETE_ERROR, e);\n' %
        up_entity_name)
    file.write('        }\n')
    file.write('        return response;\n')
    file.write('    }\n')
    file.write("}")
    file.close()
Ejemplo n.º 10
0
def _generate_service4table(db_table, package_name, file_output_path):
    abs_path = os.path.abspath(file_output_path)
    if not os.path.exists(abs_path):
        os.makedirs(abs_path)

    entity_name = db_table.tableinfo.tablename
    if entity_name.startswith('t_'):
        entity_name = entity_name[2:]
    entity_name = convert(entity_name, '_', True)  # 实体类名称
    file_name = entity_name + 'Service.java'
    file_path = os.path.join(abs_path, file_name)
    file = open(file_path, 'w', encoding='utf-8')

    table_info = db_table.tableinfo

    # package
    file.write('package %s.api;\r\n' % package_name)
    # import
    file.write('import %s.api.dto.%sDto;\n' % (package_name, entity_name))
    file.write('import %s.api.input.%sQueryInput;\n' %
               (package_name, entity_name))
    file.write('import com.xiaoye.iworks.api.result.DataResponse;\n')
    file.write('import com.xiaoye.iworks.api.result.PageResponse;\n')

    file.write('\n/**\n')
    file.write(' * 功能描述: 实体类业务接口【%s】\n' % table_info.tabledesc)
    file.write(' * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')

    file.write('public interface %sService {\r\n' % entity_name)

    file.write('    /**\n')
    file.write('     * 功能描述: 列表查询 <br>\n')
    file.write('     *     查询条件:\n')
    file.write('     * @param: queryInput\n')
    file.write('     * @return: \n')
    file.write('     * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')
    file.write(
        '    public PageResponse<%sDto> list%ss(%sQueryInput queryInput);\r\n'
        % (entity_name, entity_name, entity_name))

    file.write('    /**\n')
    file.write('     * 功能描述: 明细查询 <br>\n')
    file.write('     *     查询条件:\n')
    file.write('     * @param: queryInput\n')
    file.write('     * @return: \n')
    file.write('     * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')
    file.write(
        '    public DataResponse<%sDto> find%s(%sQueryInput queryInput);\r\n' %
        (entity_name, entity_name, entity_name))

    file.write('    /**\n')
    file.write('     * 功能描述: 数据新增 <br>\n')
    file.write('     * @param: \n')
    file.write('     * @return: 返回数据主键\n')
    file.write('     * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')
    file.write('    public DataResponse<Long> insert%s(%sDto dto);\r\n' %
               (entity_name, entity_name))

    file.write('    /**\n')
    file.write('     * 功能描述: 数据修改 <br>\n')
    file.write('     * @param: \n')
    file.write('     * @return: \n')
    file.write('     * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')
    file.write('    public DataResponse<Integer> update%s(%sDto dto);\r\n' %
               (entity_name, entity_name))

    file.write('    /**\n')
    file.write('     * 功能描述: 数据删除 <br>\n')
    file.write('     *     查询条件:\n')
    file.write('     * @param: queryInput\n')
    file.write('     * @return: \n')
    file.write('     * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')
    file.write(
        '    public DataResponse<Integer> delete%s(%sQueryInput queryInput);\r\n'
        % (entity_name, entity_name))

    file.write('}')
    file.close()
Ejemplo n.º 11
0
def _generate_service_exception4table(db_table, package_name,
                                      file_output_path):
    abs_path = os.path.abspath(file_output_path) + '/core/exception'
    if not os.path.exists(abs_path):
        os.makedirs(abs_path)

    entity_name = db_table.tableinfo.tablename
    if entity_name.startswith('t_'):
        entity_name = entity_name[2:]
    entity_name = convert(entity_name, '_', True)  # 实体类名称
    file_name = entity_name + 'ErrorCode.java'
    file_path = os.path.join(abs_path, file_name)
    file = open(file_path, 'w', encoding='utf-8')

    table_info = db_table.tableinfo

    # package
    file.write('package %s.core.exception;\r\n' % package_name)
    file.write('import com.xiaoye.iworks.common.exception.annotation.Error;\n')
    file.write('import com.xiaoye.iworks.utils.exception.ServiceErrorCode;\n')

    file.write('\n/**\n')
    file.write(' * 功能描述: 【%s】异常编码类【3624222019%s】\n' %
               (table_info.tabledesc, table_info.index))
    file.write(' * @auther: auto create by python \n')
    file.write(' * @date: %s \n' %
               time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    file.write(' */\n')

    file.write('public class %sErrorCode extends ServiceErrorCode {\r\n' %
               entity_name)
    file.write('    @Error(code = "3624222019%s01", desc = "%s数据查询异常")\n' %
               (table_info.index, table_info.tabledesc))
    file.write(
        '    public static final String DATA_QRY_ERROR = "3624222019%s01";\n' %
        table_info.index)
    file.write('    @Error(code = "3624222019%s02", desc = "%s数据已存在异常")\n' %
               (table_info.index, table_info.tabledesc))
    file.write(
        '    public static final String DATA_EXIST_ERROR = "3624222019%s02";\n'
        % table_info.index)
    file.write('    @Error(code = "3624222019%s03", desc = "%s数据不存在异常")\n' %
               (table_info.index, table_info.tabledesc))
    file.write(
        '    public static final String DATA_UNEXIST_ERROR = "3624222019%s03";\n'
        % table_info.index)
    file.write('    @Error(code = "3624222019%s04", desc = "%s数据新增异常")\n' %
               (table_info.index, table_info.tabledesc))
    file.write(
        '    public static final String DATA_INSERT_ERROR = "3624222019%s04";\n'
        % table_info.index)
    file.write('    @Error(code = "3624222019%s05", desc = "%s数据更新异常")\n' %
               (table_info.index, table_info.tabledesc))
    file.write(
        '    public static final String DATA_UPDATE_ERROR = "3624222019%s05";\n'
        % table_info.index)
    file.write('    @Error(code = "3624222019%s06", desc = "%s数据刪除异常")\n' %
               (table_info.index, table_info.tabledesc))
    file.write(
        '    public static final String DATA_DELETE_ERROR = "3624222019%s06";\n'
        % table_info.index)
    file.write('\n    public static final Class getCurrentClass(){\n')
    file.write('        return new Object(){\n')
    file.write('            public Class getClassForStatic(){\n')
    file.write('                return this.getClass();\n')
    file.write('            }\n')
    file.write('        }.getClassForStatic();\n')
    file.write('    }\n')
    file.write('}')
    file.close()