OrderMapper.xml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.order.mapper.IOrderMapper">
  4. <resultMap id="resultMap" type="com.fdkankan.order.entity.Order">
  5. <id column="id" jdbcType="VARCHAR" property="id" />
  6. <result column="order_sn" jdbcType="VARCHAR" property="orderSn" />
  7. <result column="order_time" jdbcType="TIMESTAMP" property="orderTime" />
  8. <result column="trade_num" jdbcType="VARCHAR" property="tradeNum" />
  9. <result column="user_id" jdbcType="VARCHAR" property="userId" />
  10. <result column="goods_total_count" jdbcType="INTEGER" property="goodsTotalCount" />
  11. <result column="goods_amount" jdbcType="DECIMAL" property="goodsAmount" />
  12. <result column="total_amount" jdbcType="DECIMAL" property="totalAmount" />
  13. <result column="order_status" jdbcType="VARCHAR" property="orderStatus" />
  14. <result column="payment_status" jdbcType="VARCHAR" property="paymentStatus" />
  15. <result column="shipping_status" jdbcType="VARCHAR" property="shippingStatus" />
  16. <result column="paid_amount" jdbcType="DECIMAL" property="paidAmount" />
  17. <result column="payment_type_name" jdbcType="INTEGER" property="paymentTypeName" />
  18. <result column="express_amount" jdbcType="DECIMAL" property="expressAmount" />
  19. <result column="delivery_type_name" jdbcType="VARCHAR" property="deliveryTypeName" />
  20. <result column="ship_address" jdbcType="VARCHAR" property="shipAddress" />
  21. <result column="ship_area" jdbcType="VARCHAR" property="shipArea" />
  22. <result column="ship_area_path" jdbcType="VARCHAR" property="shipAreaPath" />
  23. <result column="ship_mobile" jdbcType="VARCHAR" property="shipMobile" />
  24. <result column="ship_name" jdbcType="VARCHAR" property="shipName" />
  25. <result column="ship_phone" jdbcType="VARCHAR" property="shipPhone" />
  26. <result column="ship_zip_code" jdbcType="VARCHAR" property="shipZipCode" />
  27. <result column="finish_time" jdbcType="TIMESTAMP" property="finishTime" />
  28. <result column="memo" jdbcType="VARCHAR" property="memo" />
  29. <result column="comment" jdbcType="VARCHAR" property="comment" />
  30. <result column="abroad" jdbcType="INTEGER" property="abroad" />
  31. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  32. <result column="rec_status" jdbcType="VARCHAR" property="recStatus" />
  33. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  34. <result column="tb_status" jdbcType="INTEGER" property="tbStatus" />
  35. </resultMap>
  36. <sql id="columnList">
  37. id,order_sn,order_time,trade_num,user_id,goods_total_count,goods_amount,total_amount,order_status,payment_status,shipping_status,paid_amount,payment_type_name,express_amount,delivery_type_name,ship_address,ship_area,ship_area_path,ship_mobile,ship_name,ship_phone,ship_zip_code,finish_time,memo,comment,abroad,create_time,rec_status,update_time,tb_status </sql>
  38. <insert id="insert" useGeneratedKeys="true" keyProperty="entity.id">
  39. INSERT INTO ${tableName} (
  40. order_sn, order_time, trade_num, user_id, goods_total_count, goods_amount, total_amount, order_status, payment_status, shipping_status, paid_amount, payment_type_name, express_amount, delivery_type_name, ship_address, ship_area, ship_area_path, ship_mobile, ship_name, ship_phone, ship_zip_code, finish_time, memo, comment, abroad, rec_status
  41. ) VALUES (
  42. #{entity.orderSn}, #{entity.orderTime}, #{entity.tradeNum}, #{entity.userId}, #{entity.goodsTotalCount}, #{entity.goodsAmount}, #{entity.totalAmount}, #{entity.orderStatus}, #{entity.paymentStatus}, #{entity.shippingStatus}, #{entity.paidAmount}, #{entity.paymentTypeName}, #{entity.expressAmount}, #{entity.deliveryTypeName}, #{entity.shipAddress}, #{entity.shipArea}, #{entity.shipAreaPath}, #{entity.shipMobile}, #{entity.shipName}, #{entity.shipPhone}, #{entity.shipZipCode}, #{entity.finishTime}, #{entity.memo}, #{entity.comment}, #{entity.abroad}, #{entity.recStatus}
  43. ) </insert>
  44. <insert id="insertByBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id" >
  45. INSERT INTO ${tableName} (
  46. order_sn, order_time, trade_num, user_id, goods_total_count, goods_amount, total_amount, order_status, payment_status, shipping_status, paid_amount, payment_type_name, express_amount, delivery_type_name, ship_address, ship_area, ship_area_path, ship_mobile, ship_name, ship_phone, ship_zip_code, finish_time, memo, comment, abroad, rec_status
  47. ) VALUES
  48. <foreach collection="list" item="entity" index="index" separator=",">
  49. (#{entity.orderSn}, #{entity.orderTime}, #{entity.tradeNum}, #{entity.userId}, #{entity.goodsTotalCount}, #{entity.goodsAmount}, #{entity.totalAmount}, #{entity.orderStatus}, #{entity.paymentStatus}, #{entity.shippingStatus}, #{entity.paidAmount}, #{entity.paymentTypeName}, #{entity.expressAmount}, #{entity.deliveryTypeName}, #{entity.shipAddress}, #{entity.shipArea}, #{entity.shipAreaPath}, #{entity.shipMobile}, #{entity.shipName}, #{entity.shipPhone}, #{entity.shipZipCode}, #{entity.finishTime}, #{entity.memo}, #{entity.comment}, #{entity.abroad}, #{entity.recStatus})
  50. </foreach>
  51. </insert>
  52. <update id="update" parameterType="java.util.List" >
  53. <foreach collection="list" item="entity" index="index" separator=";">
  54. UPDATE ${tableName} SET
  55. order_sn=#{entity.orderSn}, order_time=#{entity.orderTime}, trade_num=#{entity.tradeNum}, user_id=#{entity.userId}, goods_total_count=#{entity.goodsTotalCount}, goods_amount=#{entity.goodsAmount}, total_amount=#{entity.totalAmount}, order_status=#{entity.orderStatus}, payment_status=#{entity.paymentStatus}, shipping_status=#{entity.shippingStatus}, paid_amount=#{entity.paidAmount}, payment_type_name=#{entity.paymentTypeName}, express_amount=#{entity.expressAmount}, delivery_type_name=#{entity.deliveryTypeName}, ship_address=#{entity.shipAddress}, ship_area=#{entity.shipArea}, ship_area_path=#{entity.shipAreaPath}, ship_mobile=#{entity.shipMobile}, ship_name=#{entity.shipName}, ship_phone=#{entity.shipPhone}, ship_zip_code=#{entity.shipZipCode}, finish_time=#{entity.finishTime}, memo=#{entity.memo}, comment=#{entity.comment}, abroad=#{entity.abroad}, rec_status=#{entity.recStatus}, tb_status=#{entity.tbStatus}
  56. WHERE
  57. id = #{entity.id}
  58. </foreach>
  59. </update>
  60. <update id="updateByBatch" >
  61. UPDATE ${tableName} SET
  62. ${field}
  63. <where>
  64. <foreach collection="condition" index="key" item="value">
  65. ${value} ${key}
  66. </foreach>
  67. </where>
  68. </update>
  69. <select id="getById" parameterType="java.lang.Integer" resultMap="resultMap">
  70. select
  71. <include refid="columnList" />
  72. from ${tableName}
  73. where id = #{id}
  74. </select>
  75. <select id="getOne" parameterType="java.util.Map" resultMap="resultMap">
  76. select
  77. <if test="field == null">
  78. <include refid="columnList" />
  79. </if>
  80. <if test="field != null">
  81. ${field}
  82. </if>
  83. from ${tableName}
  84. <where>
  85. <foreach collection="condition" index="key" item="value">
  86. ${value} ${key}
  87. </foreach>
  88. </where>
  89. limit 1;
  90. </select>
  91. <select id="getCount" parameterType="java.util.Map" resultType="java.lang.Integer">
  92. select
  93. count(id)
  94. from ${tableName}
  95. <where>
  96. <foreach collection="condition" index="key" item="value">
  97. ${value} ${key}
  98. </foreach>
  99. </where>
  100. </select>
  101. <!-- 这部分为根据传递参数,自动生成SQL -->
  102. <select id="getList" parameterType="java.util.Map" resultMap="resultMap">
  103. select
  104. <if test="field == null">
  105. <include refid="columnList" />
  106. </if>
  107. <if test="field != null">
  108. ${field}
  109. </if>
  110. from ${tableName}
  111. <where>
  112. <foreach collection="condition" index="key" item="value">
  113. ${value} ${key}
  114. </foreach>
  115. </where>
  116. <if test="order != null">
  117. order by ${order}
  118. </if>
  119. <if test="limit != 0">
  120. <if test="offset != 0">
  121. limit ${offset}, ${limit}
  122. </if>
  123. <if test="offset == 0">
  124. limit ${limit}
  125. </if>
  126. </if>
  127. </select>
  128. <!-- 判断表格是否存在,如果不存在可以配合createTable使用,用于动态创建表格 -->
  129. <select id="existTable" parameterType="String" resultType="java.lang.Integer">
  130. select count(table_name) from information_schema.TABLES WHERE table_name=#{tableName} ;
  131. </select>
  132. <update id="createTable" parameterType="String">
  133. <!-- 这里是创建表格的SQL,复制过来,表名作为参数传递 -->
  134. <!-- create table ${tableName} ( // 表名要这样写 -->
  135. </update>
  136. </mapper>