Ejemplo n.º 1
0
        public static string MybatisDelete(CodeMakerGeneratCodeOut inModel)
        {
            var tableName = inModel.CodeMakerGeneratCodeIn.Table;
            var result    = new StringBuilder();

            if (!inModel.FieldDescriptions.Any())
            {
                return(string.Empty);
            }
            var field = new JlFieldDescription();

            if (inModel.FieldDescriptions.Count(f => f.ColumnKey == "PRI") == 1)
            {
                field = inModel.FieldDescriptions.First(f => f.ColumnKey == "PRI");
            }
            else
            {
                field = inModel.FieldDescriptions.FirstOrDefault();
            }

            result.AppendLine(string.Format(
                                  @"  <delete id=""deleteBy{1}"" parameterType=""{4}"">
    delete from {0}
    where {5} = #{{{2},jdbcType={3}}}
  </delete>", tableName, JlString.ToUpperFirst(field.Name), JlString.ToLowerFirst(field.SimpleName), JlDbTypeMap.Map4Mybatis_PostgreSql(field.DbType).ToUpper(), JlDbTypeMap.Map4J(field.DbType, true, inModel.databaseType), field.Name));

            return(result.ToString());
        }
Ejemplo n.º 2
0
        public static string MybatisUpdate(CodeMakerGeneratCodeOut inModel)
        {
            var className                   = inModel.CodeMakerGeneratCodeIn.ClassName;
            var tableName                   = inModel.CodeMakerGeneratCodeIn.Table;
            var result                      = new StringBuilder();
            var field_UpdateParams          = new StringBuilder();
            var field_UpdateParamsSelective = new StringBuilder();

            if (!inModel.FieldDescriptions.Any())
            {
                return(string.Empty);
            }
            inModel.FieldDescriptions.Where(f => f.ColumnKey != "PRI").ToList().ForEach(f =>
            {
                field_UpdateParams.Append(string.Format("{2} = #{{{0},jdbcType={1}}}, ", JlString.ToLowerFirst(f.SimpleName), JlDbTypeMap.Map4Mybatis_PostgreSql(f.DbType).ToUpper(), f.Name));
                if (field_UpdateParams.ToString().Split(new string[] { "\r\n" }, StringSplitOptions.None).Last().Length > 100)
                {
                    field_UpdateParams.Append("\r\n        ");
                }

                field_UpdateParamsSelective.AppendLine(string.Format(
                                                           @"      <if test=""{0} != null"">
        {1} = #{{{0},jdbcType={2}}},
      </if>", JlString.ToLowerFirst(f.SimpleName), f.Name, JlDbTypeMap.Map4Mybatis_PostgreSql(f.DbType).ToUpper()));
            });

            var field = new JlFieldDescription();

            if (inModel.FieldDescriptions.Count(f => f.ColumnKey == "PRI") == 1)
            {
                field = inModel.FieldDescriptions.First(f => f.ColumnKey == "PRI");
            }
            else
            {
                field = inModel.FieldDescriptions.FirstOrDefault();
            }

            result.AppendLine(string.Format(
                                  @"  <update id=""updateBy{7}"" parameterType=""{4}"">
    update {0}
    set {6}
    where {1} = #{{{2},jdbcType={3}}}
  </update>
  <update id=""updateBy{7}Selective"" parameterType=""{4}"">
    update {0}
    <set>
{5}    </set>
    where {1} = #{{{2},jdbcType={3}}}
  </update>", tableName, field.Name, JlString.ToLowerFirst(field.SimpleName), JlDbTypeMap.Map4Mybatis_PostgreSql(field.DbType).ToUpper(), string.Format(inModel.CodeMakerGeneratCodeIn.Package, "model") + "." + className,
                                  field_UpdateParamsSelective, field_UpdateParams.ToString().TrimEnd().Substring(0, field_UpdateParams.ToString().TrimEnd().Length - 1), JlString.ToUpperFirst(field.SimpleName)));
            return(result.ToString());
        }
Ejemplo n.º 3
0
        public static string MybatisSelect(CodeMakerGeneratCodeOut inModel)
        {
            var tableName = inModel.CodeMakerGeneratCodeIn.Table;
            var result    = new StringBuilder();

            if (inModel.FieldDescriptions.Any())
            {
                var field = new JlFieldDescription();
                if (inModel.FieldDescriptions.Any(f => f.ColumnKey == "PRI"))
                {
                    field = inModel.FieldDescriptions.First(f => f.ColumnKey == "PRI");
                }
                else
                {
                    field = inModel.FieldDescriptions.FirstOrDefault();
                }

                result.AppendLine(string.Format(
                                      @"  <select id=""{6}By{1}"" parameterType=""{4}"" resultMap=""BaseResultMap"">
    select
    <include refid=""Base_Column_List"" />
    from {0}
    where {5} = #{{{2},jdbcType={3}}}
  </select>
  <select id=""selectAll"" resultMap=""BaseResultMap"">
    select
    <include refid=""Base_Column_List"" />
    from {0}
  </select>
  <select id=""selectByPage"" parameterType=""{7}"" resultMap=""BaseResultMap"">
    select
    <include refid=""Base_Column_List"" />
    from {0}
    <trim prefix=""where"" prefixOverrides=""and | or"">
        <include refid = ""Where_Column_List""></include>
    </trim>
    LIMIT #{{length}} OFFSET #{{start}}
  </select>
  <select id=""selectByWhere"" parameterType=""{7}"" resultMap=""BaseResultMap"">
    select
    <include refid=""Base_Column_List"" />
    from {0}
    <trim prefix=""where"" prefixOverrides=""and | or"">
        <include refid = ""Where_Column_List""></include>
    </trim>
    LIMIT 1
  </select>
  <select id=""selectListByWhere"" parameterType=""{7}"" resultMap=""BaseResultMap"">
    select
    <include refid=""Base_Column_List"" />
    from {0}
    <trim prefix=""where"" prefixOverrides=""and | or"">
        <include refid = ""Where_Column_List""></include>
    </trim>
  </select>
  <select id=""count"" parameterType=""{7}"" resultType=""Integer"">
    select count(1)
    from {0}
    <trim prefix=""where"" prefixOverrides=""and | or"">
        <include refid = ""Where_Column_List""></include>
    </trim>
  </select>", tableName, JlString.ToUpperFirst(field.Name), JlString.ToLowerFirst(field.SimpleName), JlDbTypeMap.Map4Mybatis_PostgreSql(field.DbType).ToUpper(),
                                      JlDbTypeMap.Map4J(field.DbType, true, inModel.databaseType), field.Name,
                                      inModel.FieldDescriptions.Any(f => f.ColumnKey == "PRI") ? "select" : "selectList",
                                      string.Format(inModel.CodeMakerGeneratCodeIn.Package, "model") + "." + inModel.CodeMakerGeneratCodeIn.ClassName));
            }
            return(result.ToString());
        }
Ejemplo n.º 4
0
        public string RefMybatisMapper(CodeMakerGeneratCodeOut inModel)
        {
            var className        = inModel.CodeMakerGeneratCodeIn.ClassName;
            var tableName        = inModel.CodeMakerGeneratCodeIn.Table;
            var field_Basic      = new StringBuilder();
            var field_Add        = new StringBuilder();
            var fieldValue       = new StringBuilder();
            var fieldParams      = new StringBuilder();
            var field_SqlContent = new StringBuilder();
            var field            = new JlFieldDescription();

            if (inModel.FieldDescriptions.Any(f => f.ColumnKey == "PRI"))
            {
                field = inModel.FieldDescriptions.First(f => f.ColumnKey == "PRI");
            }
            else
            {
                field = inModel.FieldDescriptions.FirstOrDefault();
            }
            var codeStr = new StringBuilder();

            codeStr.AppendLine(string.Format(
                                   @"package {0};

import {1};
import java.util.List;

public interface I{2}Dao{{

    {7}By{3}({4} {5});

    List<{2}> selectAll();

    List<{2}> selectByPage({2} {6});

    {2} selectByWhere({2} {6});

    List<{2}> selectListByWhere({2} {6});

    int count({2} {6});

    int deleteBy{3}({4} {5});

    int updateBy{3}({2} {6});

    int updateBy{3}Selective({2} {6});

    int insert({2} {6});

    int insertSelective({2} {6});

    void batchInsert(List<{2}> {6}List);
    
}}",
                                   string.Format(inModel.CodeMakerGeneratCodeIn.Package, "dao"),
                                   string.Format(inModel.CodeMakerGeneratCodeIn.Package, "model") + "." + className,
                                   className,
                                   JlString.ToUpperFirst(field.SimpleName),
                                   JlDbTypeMap.Map4J(field.DbType, true, inModel.databaseType),
                                   JlString.ToLowerFirst(field.SimpleName),
                                   JlString.ToLowerFirst(className),
                                   inModel.FieldDescriptions.Any(f => f.ColumnKey == "PRI") ? className + " select" : "List<" + className + "> selectList"));

            return(codeStr.ToString());
        }