GoodsProcurementMapper.xml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.biz.dal.dao.GoodsProcurementDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.GoodsProcurement" id="GoodsProcurement">
  9. <result column="id_" property="id" />
  10. <result column="goods_id_" property="goodsId" />
  11. <result column="goods_category_id_" property="goodsCategoryId" />
  12. <result column="supply_channel_" property="supplyChannel" />
  13. <result column="discount_price_" property="discountPrice" />
  14. <result column="agree_cost_price_" property="agreeCostPrice" />
  15. <result column="stock_count_" property="stockCount" />
  16. <result column="tax_stock_count_" property="taxStockCount" />
  17. <result column="operator_id_" property="operatorId" />
  18. <result column="batch_no_" property="batchNo" />
  19. <result column="stock_sold_num_" property="stockSoldNum"/>
  20. <result column="tax_stock_sold_num_" property="taxStockSoldNum"/>
  21. <result column="create_time_" property="createTime" />
  22. <result column="update_time_" property="updateTime" />
  23. <result column="tenant_id_" property="tenantId"/>
  24. </resultMap>
  25. <!-- 根据主键查询一条记录 -->
  26. <select id="get" resultMap="GoodsProcurement" >
  27. SELECT * FROM goods_procurement WHERE id_ = #{id}
  28. </select>
  29. <!-- 全查询 -->
  30. <select id="findAll" resultMap="GoodsProcurement">
  31. SELECT * FROM goods_procurement where tenant_id_ = #{tenantId} ORDER BY id_
  32. </select>
  33. <!-- 向数据库增加一条记录 -->
  34. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.GoodsProcurement" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  35. INSERT INTO goods_procurement (goods_id_,goods_category_id_,supply_channel_,discount_price_,agree_cost_price_,stock_count_,tax_stock_count_,operator_id_,batch_no_,create_time_,update_time_,tenant_id_)
  36. VALUES(#{goodsId},#{goodsCategoryId},#{supplyChannel},#{discountPrice},#{agreeCostPrice},#{stockCount},#{taxStockCount},#{operatorId},#{batchNo},NOW(),NOW(),#{tenantId})
  37. </insert>
  38. <insert id="batchInsert" parameterType="com.ym.mec.biz.dal.entity.GoodsProcurement" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  39. INSERT INTO goods_procurement (goods_id_,goods_category_id_,supply_channel_,discount_price_,agree_cost_price_,stock_count_,tax_stock_count_,operator_id_,batch_no_,create_time_,update_time_,tenant_id_)
  40. VALUE
  41. <foreach collection="goodsProcurements" item="gp" separator=",">
  42. (#{gp.goodsId},#{gp.goodsCategoryId},#{gp.supplyChannel},#{gp.discountPrice},#{gp.agreeCostPrice},#{gp.stockCount},#{gp.taxStockCount},#{gp.operatorId},#{gp.batchNo},NOW(),NOW(),#{gp.tenantId})
  43. </foreach>
  44. </insert>
  45. <!-- 根据主键查询一条记录 -->
  46. <update id="update" parameterType="com.ym.mec.biz.dal.entity.GoodsProcurement">
  47. UPDATE goods_procurement
  48. <set>
  49. <if test="operatorId != null">
  50. operator_id_ = #{operatorId},
  51. </if>
  52. <if test="agreeCostPrice != null">
  53. agree_cost_price_ = #{agreeCostPrice},
  54. </if>
  55. <if test="id != null">
  56. id_ = #{id},
  57. </if>
  58. <if test="goodsCategoryId != null">
  59. goods_category_id_ = #{goodsCategoryId},
  60. </if>
  61. <if test="taxStockCount != null">
  62. tax_stock_count_ = #{taxStockCount},
  63. </if>
  64. <if test="supplyChannel != null">
  65. supply_channel_ = #{supplyChannel},
  66. </if>
  67. <if test="discountPrice != null">
  68. discount_price_ = #{discountPrice},
  69. </if>
  70. <if test="stockCount != null">
  71. stock_count_ = #{stockCount},
  72. </if>
  73. <if test="goodsId != null">
  74. goods_id_ = #{goodsId},
  75. </if>
  76. <if test="batchNo != null">
  77. batch_no_ = #{batchNo},
  78. </if>
  79. <if test="stockSoldNum != null">
  80. stock_sold_num_ = #{stockSoldNum},
  81. </if>
  82. <if test="taxStockSoldNum != null">
  83. tax_stock_sold_num_ = #{taxStockSoldNum},
  84. </if>
  85. update_time_ = NOW(),
  86. </set> WHERE id_ = #{id} and tenant_id_ = #{tenantId}
  87. </update>
  88. <update id="batchUpdate" parameterType="java.util.List">
  89. <foreach collection="goodsProcurements" item="item" index="index" open="" close="" separator=";">
  90. UPDATE goods_procurement
  91. <set>
  92. <if test="item.operatorId != null">
  93. operator_id_ = #{item.operatorId},
  94. </if>
  95. <if test="item.agreeCostPrice != null">
  96. agree_cost_price_ = #{item.agreeCostPrice},
  97. </if>
  98. <if test="item.id != null">
  99. id_ = #{item.id},
  100. </if>
  101. <if test="item.goodsCategoryId != null">
  102. goods_category_id_ = #{item.goodsCategoryId},
  103. </if>
  104. <if test="item.taxStockCount != null">
  105. tax_stock_count_ = #{item.taxStockCount},
  106. </if>
  107. <if test="item.supplyChannel != null">
  108. supply_channel_ = #{item.supplyChannel},
  109. </if>
  110. <if test="item.discountPrice != null">
  111. discount_price_ = #{item.discountPrice},
  112. </if>
  113. <if test="item.stockCount != null">
  114. stock_count_ = #{item.stockCount},
  115. </if>
  116. <if test="item.goodsId != null">
  117. goods_id_ = #{item.goodsId},
  118. </if>
  119. <if test="item.batchNo != null">
  120. batch_no_ = #{item.batchNo},
  121. </if>
  122. <if test="item.stockSoldNum != null">
  123. stock_sold_num_ = #{item.stockSoldNum},
  124. </if>
  125. <if test="item.taxStockSoldNum != null">
  126. tax_stock_sold_num_ = #{item.taxStockSoldNum},
  127. </if>
  128. update_time_ = NOW(),
  129. </set> WHERE id_ = #{item.id} and tenant_id_ = #{item.tenantId}
  130. </foreach>
  131. </update>
  132. <!-- 根据主键删除一条记录 -->
  133. <delete id="delete" >
  134. DELETE FROM goods_procurement WHERE id_ = #{id}
  135. </delete>
  136. <sql id="queryCondition">
  137. <where>
  138. tenant_id_ = #{tenantId}
  139. <if test="goodsId!=null">
  140. AND goods_id_ = #{goodsId}
  141. </if>
  142. <if test="enterStorageStartTime!=null and enterStorageEndTime!=null">
  143. AND DATE_FORMAT(create_time_, '%Y-%m-%d') BETWEEN #{enterStorageStartTime} AND #{enterStorageEndTime}
  144. </if>
  145. <if test="search!=null and search!=''">
  146. AND supply_channel_ LIKE CONCAT('%', #{search}, '%')
  147. </if>
  148. </where>
  149. </sql>
  150. <select id="queryGoodsProcurements" resultMap="GoodsProcurement" parameterType="map">
  151. SELECT * FROM goods_procurement
  152. <include refid="queryCondition"></include>
  153. ORDER BY id_ DESC <include refid="global.limit"/>
  154. </select>
  155. <select id="countGoodsProcurements" resultType="int">
  156. SELECT COUNT(*) FROM goods_procurement
  157. <include refid="queryCondition"></include>
  158. </select>
  159. <!-- 分页查询 -->
  160. <select id="queryPage" resultMap="GoodsProcurement" parameterType="map">
  161. SELECT * FROM goods_procurement where tenant_id_ = #{tenantId}
  162. ORDER BY id_ DESC <include refid="global.limit"/>
  163. </select>
  164. <!-- 查询当前表的总记录数 -->
  165. <select id="queryCount" resultType="int">
  166. SELECT COUNT(*) FROM goods_procurement where tenant_id_ = #{tenantId}
  167. </select>
  168. <select id="getWithStockSurplusProcurement" resultMap="GoodsProcurement" useCache="false" flushCache="true">
  169. SELECT * FROM goods_procurement WHERE goods_id_ = #{goodsId} AND stock_count_>stock_sold_num_ ORDER BY create_time_ LIMIT 1
  170. </select>
  171. <select id="getWithTaxStockSurplusProcurement" resultMap="GoodsProcurement" useCache="false" flushCache="true">
  172. SELECT * FROM goods_procurement WHERE goods_id_ = #{goodsId} AND tax_stock_count_>tax_stock_sold_num_ ORDER BY create_time_ LIMIT 1
  173. </select>
  174. <select id="getWithGoodsAndBatchNo" resultMap="GoodsProcurement">
  175. SELECT * FROM goods_procurement WHERE goods_id_ = #{goodsId} AND batch_no_=#{batchNo}
  176. </select>
  177. </mapper>