PreSaleMapper.xml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.fdkankan.user.mapper.IPreSaleMapper">
  4. <resultMap id="resultMap" type="com.fdkankan.user.entity.PreSale">
  5. <id column="id" jdbcType="VARCHAR" property="id" />
  6. <result column="user_name" jdbcType="VARCHAR" property="userName" />
  7. <result column="phone" jdbcType="VARCHAR" property="phone" />
  8. <result column="scene_index" jdbcType="INTEGER" property="sceneIndex" />
  9. <result column="description" jdbcType="VARCHAR" property="description" />
  10. <result column="weixin" jdbcType="VARCHAR" property="weixin" />
  11. <result column="enterprise_name" jdbcType="VARCHAR" property="enterpriseName" />
  12. <result column="count" jdbcType="INTEGER" property="count" />
  13. <result column="order_time" jdbcType="TIMESTAMP" property="orderTime" />
  14. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  15. <result column="rec_status" jdbcType="VARCHAR" property="recStatus" />
  16. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  17. <result column="tb_status" jdbcType="INTEGER" property="tbStatus" />
  18. </resultMap>
  19. <sql id="columnList">
  20. id,user_name,phone,scene_index,description,weixin,enterprise_name,count,order_time,create_time,rec_status,update_time,tb_status </sql>
  21. <insert id="insert" useGeneratedKeys="true" keyProperty="entity.id">
  22. INSERT INTO ${tableName} (
  23. user_name, phone, scene_index, description, weixin, enterprise_name, count, order_time, rec_status
  24. ) VALUES (
  25. #{entity.userName}, #{entity.phone}, #{entity.sceneIndex}, #{entity.description}, #{entity.weixin}, #{entity.enterpriseName}, #{entity.count}, #{entity.orderTime}, #{entity.recStatus}
  26. ) </insert>
  27. <insert id="insertByBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id" >
  28. INSERT INTO ${tableName} (
  29. user_name, phone, scene_index, description, weixin, enterprise_name, count, order_time, rec_status
  30. ) VALUES
  31. <foreach collection="list" item="entity" index="index" separator=",">
  32. (#{entity.userName}, #{entity.phone}, #{entity.sceneIndex}, #{entity.description}, #{entity.weixin}, #{entity.enterpriseName}, #{entity.count}, #{entity.orderTime}, #{entity.recStatus})
  33. </foreach>
  34. </insert>
  35. <update id="update" parameterType="java.util.List" >
  36. <foreach collection="list" item="entity" index="index" separator=";">
  37. UPDATE ${tableName} SET
  38. user_name=#{entity.userName}, phone=#{entity.phone}, scene_index=#{entity.sceneIndex}, description=#{entity.description}, weixin=#{entity.weixin}, enterprise_name=#{entity.enterpriseName}, count=#{entity.count}, order_time=#{entity.orderTime}, rec_status=#{entity.recStatus}, tb_status=#{entity.tbStatus}
  39. WHERE
  40. id = #{entity.id}
  41. </foreach>
  42. </update>
  43. <update id="updateByBatch" >
  44. UPDATE ${tableName} SET
  45. ${field}
  46. <where>
  47. <foreach collection="condition" index="key" item="value">
  48. ${value} ${key}
  49. </foreach>
  50. </where>
  51. </update>
  52. <select id="getById" parameterType="java.lang.Integer" resultMap="resultMap">
  53. select
  54. <include refid="columnList" />
  55. from ${tableName}
  56. where id = #{id}
  57. </select>
  58. <select id="getOne" parameterType="java.util.Map" resultMap="resultMap">
  59. select
  60. <if test="field == null">
  61. <include refid="columnList" />
  62. </if>
  63. <if test="field != null">
  64. ${field}
  65. </if>
  66. from ${tableName}
  67. <where>
  68. <foreach collection="condition" index="key" item="value">
  69. ${value} ${key}
  70. </foreach>
  71. </where>
  72. limit 1;
  73. </select>
  74. <select id="getCount" parameterType="java.util.Map" resultType="java.lang.Integer">
  75. select
  76. count(id)
  77. from ${tableName}
  78. <where>
  79. <foreach collection="condition" index="key" item="value">
  80. ${value} ${key}
  81. </foreach>
  82. </where>
  83. </select>
  84. <!-- 这部分为根据传递参数,自动生成SQL -->
  85. <select id="getList" parameterType="java.util.Map" resultMap="resultMap">
  86. select
  87. <if test="field == null">
  88. <include refid="columnList" />
  89. </if>
  90. <if test="field != null">
  91. ${field}
  92. </if>
  93. from ${tableName}
  94. <where>
  95. <foreach collection="condition" index="key" item="value">
  96. ${value} ${key}
  97. </foreach>
  98. </where>
  99. <if test="order != null">
  100. order by ${order}
  101. </if>
  102. <if test="limit != 0">
  103. <if test="offset != 0">
  104. limit ${offset}, ${limit}
  105. </if>
  106. <if test="offset == 0">
  107. limit ${limit}
  108. </if>
  109. </if>
  110. </select>
  111. <!-- 判断表格是否存在,如果不存在可以配合createTable使用,用于动态创建表格 -->
  112. <select id="existTable" parameterType="String" resultType="java.lang.Integer">
  113. select count(table_name) from information_schema.TABLES WHERE table_name=#{tableName} ;
  114. </select>
  115. <update id="createTable" parameterType="String">
  116. <!-- 这里是创建表格的SQL,复制过来,表名作为参数传递 -->
  117. <!-- create table ${tableName} ( // 表名要这样写 -->
  118. </update>
  119. </mapper>