PmsSkuStockMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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.yonge.cooleshow.mbg.mapper.PmsSkuStockMapper">
  4. <resultMap id="BaseResultMap" type="com.yonge.cooleshow.mbg.model.PmsSkuStock">
  5. <id column="id" jdbcType="BIGINT" property="id" />
  6. <result column="product_id" jdbcType="BIGINT" property="productId" />
  7. <result column="sku_code" jdbcType="VARCHAR" property="skuCode" />
  8. <result column="price" jdbcType="DECIMAL" property="price" />
  9. <result column="stock" jdbcType="INTEGER" property="stock" />
  10. <result column="low_stock" jdbcType="INTEGER" property="lowStock" />
  11. <result column="pic" jdbcType="VARCHAR" property="pic" />
  12. <result column="sale" jdbcType="INTEGER" property="sale" />
  13. <result column="promotion_price" jdbcType="DECIMAL" property="promotionPrice" />
  14. <result column="lock_stock" jdbcType="INTEGER" property="lockStock" />
  15. <result column="sp_data" jdbcType="VARCHAR" property="spData" />
  16. <result column="delete_status" jdbcType="INTEGER" property="deleteStatus" />
  17. </resultMap>
  18. <sql id="Example_Where_Clause">
  19. <where>
  20. <foreach collection="oredCriteria" item="criteria" separator="or">
  21. <if test="criteria.valid">
  22. <trim prefix="(" prefixOverrides="and" suffix=")">
  23. <foreach collection="criteria.criteria" item="criterion">
  24. <choose>
  25. <when test="criterion.noValue">
  26. and ${criterion.condition}
  27. </when>
  28. <when test="criterion.singleValue">
  29. and ${criterion.condition} #{criterion.value}
  30. </when>
  31. <when test="criterion.betweenValue">
  32. and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
  33. </when>
  34. <when test="criterion.listValue">
  35. and ${criterion.condition}
  36. <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
  37. #{listItem}
  38. </foreach>
  39. </when>
  40. </choose>
  41. </foreach>
  42. </trim>
  43. </if>
  44. </foreach>
  45. </where>
  46. </sql>
  47. <sql id="Update_By_Example_Where_Clause">
  48. <where>
  49. <foreach collection="example.oredCriteria" item="criteria" separator="or">
  50. <if test="criteria.valid">
  51. <trim prefix="(" prefixOverrides="and" suffix=")">
  52. <foreach collection="criteria.criteria" item="criterion">
  53. <choose>
  54. <when test="criterion.noValue">
  55. and ${criterion.condition}
  56. </when>
  57. <when test="criterion.singleValue">
  58. and ${criterion.condition} #{criterion.value}
  59. </when>
  60. <when test="criterion.betweenValue">
  61. and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
  62. </when>
  63. <when test="criterion.listValue">
  64. and ${criterion.condition}
  65. <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
  66. #{listItem}
  67. </foreach>
  68. </when>
  69. </choose>
  70. </foreach>
  71. </trim>
  72. </if>
  73. </foreach>
  74. </where>
  75. </sql>
  76. <sql id="Base_Column_List">
  77. id, product_id, sku_code, price, stock, low_stock, pic, sale, promotion_price, lock_stock, delete_status,
  78. sp_data
  79. </sql>
  80. <select id="selectByExample" parameterType="com.yonge.cooleshow.mbg.model.PmsSkuStockExample" resultMap="BaseResultMap">
  81. select
  82. <if test="distinct">
  83. distinct
  84. </if>
  85. <include refid="Base_Column_List" />
  86. from pms_sku_stock
  87. <if test="_parameter != null">
  88. <include refid="Example_Where_Clause" />
  89. </if>
  90. <if test="orderByClause != null">
  91. order by ${orderByClause}
  92. </if>
  93. </select>
  94. <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
  95. select
  96. <include refid="Base_Column_List" />
  97. from pms_sku_stock
  98. where id = #{id,jdbcType=BIGINT}
  99. </select>
  100. <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
  101. update pms_sku_stock set delete_status = 1
  102. where id = #{id,jdbcType=BIGINT}
  103. </delete>
  104. <delete id="deleteByExample" parameterType="com.yonge.cooleshow.mbg.model.PmsSkuStockExample">
  105. update pms_sku_stock set delete_status = 1
  106. <if test="_parameter != null">
  107. <include refid="Example_Where_Clause" />
  108. </if>
  109. </delete>
  110. <insert id="insert" parameterType="com.yonge.cooleshow.mbg.model.PmsSkuStock">
  111. <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
  112. SELECT LAST_INSERT_ID()
  113. </selectKey>
  114. insert into pms_sku_stock (product_id, sku_code, price,
  115. stock, low_stock, pic,
  116. sale, promotion_price, lock_stock,
  117. sp_data)
  118. values (#{productId,jdbcType=BIGINT}, #{skuCode,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL},
  119. #{stock,jdbcType=INTEGER}, #{lowStock,jdbcType=INTEGER}, #{pic,jdbcType=VARCHAR},
  120. #{sale,jdbcType=INTEGER}, #{promotionPrice,jdbcType=DECIMAL}, #{lockStock,jdbcType=INTEGER},
  121. #{spData,jdbcType=VARCHAR})
  122. </insert>
  123. <insert id="insertSelective" parameterType="com.yonge.cooleshow.mbg.model.PmsSkuStock">
  124. <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
  125. SELECT LAST_INSERT_ID()
  126. </selectKey>
  127. insert into pms_sku_stock
  128. <trim prefix="(" suffix=")" suffixOverrides=",">
  129. <if test="productId != null">
  130. product_id,
  131. </if>
  132. <if test="skuCode != null">
  133. sku_code,
  134. </if>
  135. <if test="price != null">
  136. price,
  137. </if>
  138. <if test="stock != null">
  139. stock,
  140. </if>
  141. <if test="lowStock != null">
  142. low_stock,
  143. </if>
  144. <if test="pic != null">
  145. pic,
  146. </if>
  147. <if test="sale != null">
  148. sale,
  149. </if>
  150. <if test="promotionPrice != null">
  151. promotion_price,
  152. </if>
  153. <if test="lockStock != null">
  154. lock_stock,
  155. </if>
  156. <if test="spData != null">
  157. sp_data,
  158. </if>
  159. </trim>
  160. <trim prefix="values (" suffix=")" suffixOverrides=",">
  161. <if test="productId != null">
  162. #{productId,jdbcType=BIGINT},
  163. </if>
  164. <if test="skuCode != null">
  165. #{skuCode,jdbcType=VARCHAR},
  166. </if>
  167. <if test="price != null">
  168. #{price,jdbcType=DECIMAL},
  169. </if>
  170. <if test="stock != null">
  171. #{stock,jdbcType=INTEGER},
  172. </if>
  173. <if test="lowStock != null">
  174. #{lowStock,jdbcType=INTEGER},
  175. </if>
  176. <if test="pic != null">
  177. #{pic,jdbcType=VARCHAR},
  178. </if>
  179. <if test="sale != null">
  180. #{sale,jdbcType=INTEGER},
  181. </if>
  182. <if test="promotionPrice != null">
  183. #{promotionPrice,jdbcType=DECIMAL},
  184. </if>
  185. <if test="lockStock != null">
  186. #{lockStock,jdbcType=INTEGER},
  187. </if>
  188. <if test="spData != null">
  189. #{spData,jdbcType=VARCHAR},
  190. </if>
  191. </trim>
  192. </insert>
  193. <select id="countByExample" parameterType="com.yonge.cooleshow.mbg.model.PmsSkuStockExample" resultType="java.lang.Long">
  194. select count(*) from pms_sku_stock
  195. <if test="_parameter != null">
  196. <include refid="Example_Where_Clause" />
  197. </if>
  198. </select>
  199. <update id="updateByExampleSelective" parameterType="map">
  200. update pms_sku_stock
  201. <set>
  202. <if test="record.id != null">
  203. id = #{record.id,jdbcType=BIGINT},
  204. </if>
  205. <if test="record.productId != null">
  206. product_id = #{record.productId,jdbcType=BIGINT},
  207. </if>
  208. <if test="record.skuCode != null">
  209. sku_code = #{record.skuCode,jdbcType=VARCHAR},
  210. </if>
  211. <if test="record.price != null">
  212. price = #{record.price,jdbcType=DECIMAL},
  213. </if>
  214. <if test="record.stock != null">
  215. stock = #{record.stock,jdbcType=INTEGER},
  216. </if>
  217. <if test="record.lowStock != null">
  218. low_stock = #{record.lowStock,jdbcType=INTEGER},
  219. </if>
  220. <if test="record.pic != null">
  221. pic = #{record.pic,jdbcType=VARCHAR},
  222. </if>
  223. <if test="record.sale != null">
  224. sale = #{record.sale,jdbcType=INTEGER},
  225. </if>
  226. <if test="record.promotionPrice != null">
  227. promotion_price = #{record.promotionPrice,jdbcType=DECIMAL},
  228. </if>
  229. <if test="record.lockStock != null">
  230. lock_stock = #{record.lockStock,jdbcType=INTEGER},
  231. </if>
  232. <if test="record.spData != null">
  233. sp_data = #{record.spData,jdbcType=VARCHAR},
  234. </if>
  235. </set>
  236. <if test="_parameter != null">
  237. <include refid="Update_By_Example_Where_Clause" />
  238. </if>
  239. </update>
  240. <update id="updateByExample" parameterType="map">
  241. update pms_sku_stock
  242. set id = #{record.id,jdbcType=BIGINT},
  243. product_id = #{record.productId,jdbcType=BIGINT},
  244. sku_code = #{record.skuCode,jdbcType=VARCHAR},
  245. price = #{record.price,jdbcType=DECIMAL},
  246. stock = #{record.stock,jdbcType=INTEGER},
  247. low_stock = #{record.lowStock,jdbcType=INTEGER},
  248. pic = #{record.pic,jdbcType=VARCHAR},
  249. sale = #{record.sale,jdbcType=INTEGER},
  250. promotion_price = #{record.promotionPrice,jdbcType=DECIMAL},
  251. lock_stock = #{record.lockStock,jdbcType=INTEGER},
  252. sp_data = #{record.spData,jdbcType=VARCHAR}
  253. <if test="_parameter != null">
  254. <include refid="Update_By_Example_Where_Clause" />
  255. </if>
  256. </update>
  257. <update id="updateByPrimaryKeySelective" parameterType="com.yonge.cooleshow.mbg.model.PmsSkuStock">
  258. update pms_sku_stock
  259. <set>
  260. <if test="productId != null">
  261. product_id = #{productId,jdbcType=BIGINT},
  262. </if>
  263. <if test="skuCode != null">
  264. sku_code = #{skuCode,jdbcType=VARCHAR},
  265. </if>
  266. <if test="price != null">
  267. price = #{price,jdbcType=DECIMAL},
  268. </if>
  269. <if test="stock != null">
  270. stock = #{stock,jdbcType=INTEGER},
  271. </if>
  272. <if test="lowStock != null">
  273. low_stock = #{lowStock,jdbcType=INTEGER},
  274. </if>
  275. <if test="pic != null">
  276. pic = #{pic,jdbcType=VARCHAR},
  277. </if>
  278. <if test="sale != null">
  279. sale = #{sale,jdbcType=INTEGER},
  280. </if>
  281. <if test="promotionPrice != null">
  282. promotion_price = #{promotionPrice,jdbcType=DECIMAL},
  283. </if>
  284. <if test="lockStock != null">
  285. lock_stock = #{lockStock,jdbcType=INTEGER},
  286. </if>
  287. <if test="spData != null">
  288. sp_data = #{spData,jdbcType=VARCHAR},
  289. </if>
  290. </set>
  291. where id = #{id,jdbcType=BIGINT}
  292. </update>
  293. <update id="updateByPrimaryKey" parameterType="com.yonge.cooleshow.mbg.model.PmsSkuStock">
  294. update pms_sku_stock
  295. set product_id = #{productId,jdbcType=BIGINT},
  296. sku_code = #{skuCode,jdbcType=VARCHAR},
  297. price = #{price,jdbcType=DECIMAL},
  298. stock = #{stock,jdbcType=INTEGER},
  299. low_stock = #{lowStock,jdbcType=INTEGER},
  300. pic = #{pic,jdbcType=VARCHAR},
  301. sale = #{sale,jdbcType=INTEGER},
  302. promotion_price = #{promotionPrice,jdbcType=DECIMAL},
  303. lock_stock = #{lockStock,jdbcType=INTEGER},
  304. sp_data = #{spData,jdbcType=VARCHAR}
  305. where id = #{id,jdbcType=BIGINT}
  306. </update>
  307. <update id="lockStock">
  308. <!-- update pms_sku_stock set lock_stock = lock_stock + #{quantity} where id = #{productSkuId} and stock &gt;= ( lock_stock + #{quantity})-->
  309. update pms_sku_stock set lock_stock = lock_stock where id = #{productSkuId}
  310. </update>
  311. <select id="getSkuStockByProductIds" resultType="com.yonge.cooleshow.mbg.dto.PmsSkuStockDto$PmsSkuStockStock">
  312. select t.product_sku_id as id,
  313. t.product_id as productId,
  314. sum(t.internal_stock - t.internal_sale_stock) as internalStock,
  315. sum(t.tax_stock - t.tax_sale_stock) as taxStock
  316. from pms_product_sku_stock_record t
  317. left join pms_sku_stock t1 on t1.id = t.product_sku_id
  318. where t.product_id in
  319. <foreach collection="productIds" item="productId" open="(" separator="," close=")">
  320. #{productId}
  321. </foreach>
  322. and t1.delete_status = 0
  323. group by t.product_sku_id, t.product_id
  324. </select>
  325. </mapper>