|
@@ -5,63 +5,12 @@ import java.util.List;
|
|
|
import org.geek.szbay.assistant.code.generator.helpper.TableHelpper;
|
|
|
import org.geek.szbay.assistant.utils.StringUtils;
|
|
|
|
|
|
-
|
|
|
- * <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC
|
|
|
- * "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
- * "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
- * <mapper namespace="com.travel.pay.dao.write.pay.PayOrderLogDao">
|
|
|
- *
|
|
|
- * <insert id="save" useGeneratedKeys="true" keyProperty="id" parameterType=
|
|
|
- * "com.travel.pay.model.pay.PayOrderLogDO"> insert into pay_order_log
|
|
|
- * <trim prefix="(" suffix=")" suffixOverrides=",">
|
|
|
- * <if test="payOrderId != null" > pay_order_id, </if> <if test="type != null" >
|
|
|
- * type, </if> <if test="result != null" > result, </if>
|
|
|
- * <if test="input != null" > input, </if> <if test="output != null" > output,
|
|
|
- * </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
|
- * <if test="payOrderId != null" > #{payOrderId}, </if>
|
|
|
- * <if test="type != null" > #{type}, </if> <if test="result != null" >
|
|
|
- * #{result}, </if> <if test="input != null" > #{input}, </if>
|
|
|
- * <if test="output != null" > #{output}, </if> </trim> </insert>
|
|
|
- *
|
|
|
- * <update id="update" parameterType="com.travel.pay.model.pay.PayOrderLogDO">
|
|
|
- * update pay_order_log <set> <if test="payOrderId != null" > pay_order_id =
|
|
|
- * #{payOrderId}, </if> <if test="type != null" > type = #{type}, </if>
|
|
|
- * <if test="result != null" > result = #{result}, </if>
|
|
|
- * <if test="input != null" > input = #{input}, </if>
|
|
|
- * <if test="output != null" > output = #{output}, </if> </set> where id = #{id}
|
|
|
- * </update>
|
|
|
- *
|
|
|
- * <resultMap id="payOrderLogMap" type="com.travel.pay.model.pay.PayOrderLogDO">
|
|
|
- * <id column="id" property="id"/>
|
|
|
- * <result column="pay_order_id" property="payOrderId"/>
|
|
|
- * <result column="type" property="type"/>
|
|
|
- * <result column="result" property="result"/>
|
|
|
- * <result column="input" property="input"/>
|
|
|
- * <result column="output" property="output"/>
|
|
|
- * <result column="gmt_create" property="gmtCreate"/>
|
|
|
- * <result column="gmt_modified" property="gmtModified"/> </resultMap>
|
|
|
- *
|
|
|
- * <sql id="allField">
|
|
|
- * id,pay_order_id,type,result,input,output,gmt_create,gmt_modified </sql>
|
|
|
- *
|
|
|
- * <select id="getById" parameterType="java.lang.Long" resultMap=
|
|
|
- * "payOrderLogMap"> select <include refid="allField"/> from pay_order_log where
|
|
|
- * id = #{id} </select>
|
|
|
- *
|
|
|
- * </mapper>
|
|
|
- *
|
|
|
- * @author wutianbin
|
|
|
- * @Time:2017年5月18日 下午7:31:51
|
|
|
- * @version 1.0
|
|
|
- */
|
|
|
public class MapperXmlMaker {
|
|
|
|
|
|
- public static final String parse(String authorName, String tableName, String tableComment,
|
|
|
- String key, String outPath,
|
|
|
- String entityFullClassName, String entityClassName,
|
|
|
- String daoFullClassName, String daoClassName,
|
|
|
- List<String> attrNames, List<String> colNames,
|
|
|
- List<String> colTypes, List<String> colComments) {
|
|
|
+ public static final String parse(String authorName, String tableName, String tableComment, String key,
|
|
|
+ String outPath, String entityFullClassName, String entityClassName, String daoFullClassName,
|
|
|
+ String daoClassName, List<String> attrNames, List<String> colNames, List<String> colTypes,
|
|
|
+ List<String> colComments) {
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
String className = TableHelpper.columnNameToAttrName(tableName);
|
|
|
String keyAttr = TableHelpper.columnNameToAttrName(key);
|
|
@@ -71,14 +20,17 @@ public class MapperXmlMaker {
|
|
|
parseResultMap(sb, key, keyAttr, className, entityFullClassName, colNames, attrNames);
|
|
|
parseAllField(sb, colNames);
|
|
|
|
|
|
+ parseInsert(sb, key, keyAttr, tableName, entityFullClassName, colNames, attrNames, colTypes);
|
|
|
+
|
|
|
+ parseUpdate(sb, key, keyAttr, tableName, entityFullClassName, colNames, attrNames, colTypes);
|
|
|
+ parseUpdateByExample(sb, key, keyAttr, tableName, entityFullClassName, colNames, attrNames, colTypes);
|
|
|
+
|
|
|
parseDelete(sb, key, keyAttr, tableName, entityFullClassName, colNames, attrNames);
|
|
|
parseDeleteByKey(sb, key, keyAttr, tableName, entityFullClassName, colNames, attrNames);
|
|
|
- parseInsert(sb, key, keyAttr, tableName, entityFullClassName, colNames, attrNames);
|
|
|
- parseUpdate(sb, key, keyAttr, tableName, entityFullClassName, colNames, attrNames);
|
|
|
- parseUpdateByExample(sb, key, keyAttr, tableName, entityFullClassName, colNames, attrNames);
|
|
|
+ parseDeleteByExample(sb, key, keyAttr, tableName, entityFullClassName, colNames, attrNames, colTypes);
|
|
|
|
|
|
- parseCountByExample(sb, key, keyAttr, className, tableName, colNames, attrNames);
|
|
|
- parseListByExample(sb, key, keyAttr, className, tableName, colNames, attrNames);
|
|
|
+ parseCountByExample(sb, key, keyAttr, className, tableName, colNames, attrNames, colTypes);
|
|
|
+ parseListByExample(sb, key, keyAttr, className, tableName, colNames, attrNames, colTypes);
|
|
|
|
|
|
parseGetByKey(sb, key, keyAttr, className, tableName);
|
|
|
|
|
@@ -157,8 +109,27 @@ public class MapperXmlMaker {
|
|
|
sb.append("\r\n");
|
|
|
}
|
|
|
|
|
|
+ private static void parseDeleteByExample(StringBuffer sb, String key, String keyAttr, String tableName,
|
|
|
+ String entityFullClassName, List<String> colNames, List<String> attrNames, List<String> colTypes) {
|
|
|
+ sb.append(" <delete id=\"deleteByExample\"> \r\n");
|
|
|
+ sb.append(" delete from " + tableName + "\r\n");
|
|
|
+ sb.append(" where 1 = 1 \r\n");
|
|
|
+
|
|
|
+ for (int i = 0; i < colNames.size(); i++) {
|
|
|
+ String column = colNames.get(i);
|
|
|
+ String attr = attrNames.get(i);
|
|
|
+
|
|
|
+ sb.append(" <if test=\"example.").append(attr).append(" != null\" >\r\n");
|
|
|
+ sb.append(" and ").append(column).append(" = #{example.").append(attr).append("} \r\n");
|
|
|
+ sb.append(" </if>\r\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ sb.append(" </delete>\r\n");
|
|
|
+ sb.append("\r\n");
|
|
|
+ }
|
|
|
+
|
|
|
private static final void parseInsert(StringBuffer sb, String key, String keyAttr, String tableName,
|
|
|
- String entityFullClassName, List<String> colNames, List<String> attrNames) {
|
|
|
+ String entityFullClassName, List<String> colNames, List<String> attrNames, List<String> colTypes) {
|
|
|
sb.append(" <insert id=\"save\" useGeneratedKeys=\"");
|
|
|
if ("id".equals(key)) {
|
|
|
sb.append("true\" ");
|
|
@@ -174,13 +145,20 @@ public class MapperXmlMaker {
|
|
|
for (int i = 0; i < colNames.size(); i++) {
|
|
|
String column = colNames.get(i);
|
|
|
String attr = attrNames.get(i);
|
|
|
+ boolean typeIsString = TableHelpper.colTypeIsString(colTypes.get(i));
|
|
|
|
|
|
if (column.equals(key) && "id".equals(key)) {
|
|
|
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- sb.append(" <if test=\"").append(attr).append(" != null\" >\r\n");
|
|
|
+ if (typeIsString) {
|
|
|
+ sb.append(" <if test=\"").append(attr).append(" != null").append(" and ").append(attr)
|
|
|
+ .append(" != ''\" >\r\n");
|
|
|
+ } else {
|
|
|
+ sb.append(" <if test=\"").append(attr).append(" != null\" >\r\n");
|
|
|
+ }
|
|
|
+
|
|
|
sb.append(" ").append(column).append(", \r\n");
|
|
|
sb.append(" </if>\r\n");
|
|
|
}
|
|
@@ -191,11 +169,19 @@ public class MapperXmlMaker {
|
|
|
|
|
|
for (int i = 0; i < colNames.size(); i++) {
|
|
|
String attr = attrNames.get(i);
|
|
|
+ boolean typeIsString = TableHelpper.colTypeIsString(colTypes.get(i));
|
|
|
+
|
|
|
if (attr.equals("id")) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- sb.append(" <if test=\"").append(attr).append(" != null\" >\r\n");
|
|
|
+ if (typeIsString) {
|
|
|
+ sb.append(" <if test=\"").append(attr).append(" != null").append(" and ").append(attr)
|
|
|
+ .append(" != ''\" >\r\n");
|
|
|
+ } else {
|
|
|
+ sb.append(" <if test=\"").append(attr).append(" != null\" >\r\n");
|
|
|
+ }
|
|
|
+
|
|
|
sb.append(" #{").append(attr).append("}, \r\n");
|
|
|
sb.append(" </if>\r\n");
|
|
|
}
|
|
@@ -207,7 +193,7 @@ public class MapperXmlMaker {
|
|
|
}
|
|
|
|
|
|
private static final void parseUpdate(StringBuffer sb, String key, String keyAttr, String tableName,
|
|
|
- String entityFullClassName, List<String> colNames, List<String> attrNames) {
|
|
|
+ String entityFullClassName, List<String> colNames, List<String> attrNames, List<String> colTypes) {
|
|
|
sb.append(" <update id=\"update\"");
|
|
|
sb.append(" parameterType=\"").append(entityFullClassName).append("\">\r\n");
|
|
|
|
|
@@ -224,6 +210,7 @@ public class MapperXmlMaker {
|
|
|
}
|
|
|
|
|
|
sb.append(" <if test=\"").append(attr).append(" != null\" >\r\n");
|
|
|
+
|
|
|
sb.append(" ").append(column).append(" = #{").append(attr).append("}, \r\n");
|
|
|
sb.append(" </if>\r\n");
|
|
|
}
|
|
@@ -238,27 +225,31 @@ public class MapperXmlMaker {
|
|
|
|
|
|
private static final void parseGetByKey(StringBuffer sb, String key, String keyAttr, String className,
|
|
|
String tableName) {
|
|
|
- sb.append(" <select id=\"getByKey\" ")
|
|
|
- .append("resultMap=\"").append(StringUtils.firstToLowerCase(className))
|
|
|
+ sb.append(" <select id=\"getByKey\" ").append("resultMap=\"").append(StringUtils.firstToLowerCase(className))
|
|
|
.append("Map\">").append("\r\n");
|
|
|
sb.append(" select <include refid=\"allField\"/>\r\n");
|
|
|
- sb.append(" from ").append(tableName).append(" where ").append(key)
|
|
|
- .append(" = #{key}\r\n");
|
|
|
+ sb.append(" from ").append(tableName).append(" where ").append(key).append(" = #{key}\r\n");
|
|
|
sb.append(" </select>\r\n");
|
|
|
sb.append("\r\n");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private static void parseCountByExample(StringBuffer sb, String key, String keyAttr, String className,
|
|
|
- String tableName, List<String> colNames, List<String> attrNames) {
|
|
|
- sb.append(" <select id=\"countByExample\"")
|
|
|
- .append(" resultType=\"java.lang.Integer\"").append("> \r\n");
|
|
|
+ String tableName, List<String> colNames, List<String> attrNames, List<String> colTypes) {
|
|
|
+ sb.append(" <select id=\"countByExample\"").append(" resultType=\"java.lang.Integer\"").append("> \r\n");
|
|
|
sb.append(" select count(*) ").append("from ").append(tableName).append(" where 1 = 1 ").append("\r\n");
|
|
|
|
|
|
for (int i = 0; i < colNames.size(); i++) {
|
|
|
String column = colNames.get(i);
|
|
|
String attr = attrNames.get(i);
|
|
|
+ boolean typeIsString = TableHelpper.colTypeIsString(colTypes.get(i));
|
|
|
+
|
|
|
+ if (typeIsString) {
|
|
|
+ sb.append(" <if test=\"example.").append(attr).append(" != null").append(" and example.")
|
|
|
+ .append(attr).append(" != ''\" >\r\n");
|
|
|
+ } else {
|
|
|
+ sb.append(" <if test=\"example.").append(attr).append(" != null\" >\r\n");
|
|
|
+ }
|
|
|
|
|
|
- sb.append(" <if test=\"example.").append(attr).append(" != null\" >\r\n");
|
|
|
sb.append(" and ").append(column).append(" = #{example.").append(attr).append("} \r\n");
|
|
|
sb.append(" </if>\r\n");
|
|
|
}
|
|
@@ -268,7 +259,7 @@ public class MapperXmlMaker {
|
|
|
}
|
|
|
|
|
|
private static void parseUpdateByExample(StringBuffer sb, String key, String keyAttr, String tableName,
|
|
|
- String entityFullClassName, List<String> colNames, List<String> attrNames) {
|
|
|
+ String entityFullClassName, List<String> colNames, List<String> attrNames, List<String> colTypes) {
|
|
|
sb.append(" <update id=\"updateByExample\">\r\n");
|
|
|
sb.append(" update ").append(tableName).append("\r\n");
|
|
|
sb.append(" <set>\r\n");
|
|
@@ -304,7 +295,7 @@ public class MapperXmlMaker {
|
|
|
}
|
|
|
|
|
|
private static final void parseListByExample(StringBuffer sb, String key, String keyAttr, String className,
|
|
|
- String tableName, List<String> colNames, List<String> attrNames) {
|
|
|
+ String tableName, List<String> colNames, List<String> attrNames, List<String> colTypes) {
|
|
|
sb.append(" <select id=\"listByExample\" ").append(" resultMap=\"")
|
|
|
.append(StringUtils.firstToLowerCase(className)).append("Map\">").append("\r\n");
|
|
|
sb.append(" select <include refid=\"allField\" />\r\n");
|
|
@@ -313,14 +304,21 @@ public class MapperXmlMaker {
|
|
|
for (int i = 0; i < colNames.size(); i++) {
|
|
|
String column = colNames.get(i);
|
|
|
String attr = attrNames.get(i);
|
|
|
+ boolean typeIsString = TableHelpper.colTypeIsString(colTypes.get(i));
|
|
|
+
|
|
|
+ if (typeIsString) {
|
|
|
+ sb.append(" <if test=\"example.").append(attr).append(" != null").append(" and example.")
|
|
|
+ .append(attr).append(" != ''\" >\r\n");
|
|
|
+ } else {
|
|
|
+ sb.append(" <if test=\"example.").append(attr).append(" != null\" >\r\n");
|
|
|
+ }
|
|
|
|
|
|
- sb.append(" <if test=\"example.").append(attr).append(" != null\" >\r\n");
|
|
|
sb.append(" and ").append(column).append(" = #{example.").append(attr).append("} \r\n");
|
|
|
sb.append(" </if>\r\n");
|
|
|
}
|
|
|
|
|
|
sb.append(" limit ${pageSize} offset ${(page - 1) * pageSize}").append("\r\n");
|
|
|
-
|
|
|
+
|
|
|
sb.append(" </select>\r\n");
|
|
|
sb.append("\r\n");
|
|
|
}
|