ProdStockVoMapper.xml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="cn.com.wingxi.biandan.mq.server.product.mapper.ProdStockVoMapper">
  6. <resultMap type="ProdStockVo" id="ProdStockVoResult">
  7. <result property="stockId" column="stockId" />
  8. <result property="prodId" column="prodId" />
  9. <result property="pprId" column="pprId" />
  10. <result property="vendorId" column="vendorId" />
  11. <result property="stockQty" column="stockQty" />
  12. <result property="availQty" column="availQty" />
  13. <result property="delFlag" column="delFlag" />
  14. <result property="createUser" column="createUser" />
  15. <result property="createTime" column="createTime" />
  16. <result property="updateUser" column="updateUser" />
  17. <result property="updateTime" column="updateTime" />
  18. <result property="prodkindId" column="prodkindId" />
  19. <result property="prodkindName" column="prodkindName" />
  20. <result property="prodName" column="prodName" />
  21. <result property="pprName" column="pprName" />
  22. </resultMap>
  23. <sql id="selectProdStockVo">
  24. select
  25. p.stockId,
  26. p.prodId,
  27. p.pprId,
  28. p.vendorId,
  29. p.stockQty,
  30. p.availQty,
  31. p.delFlag,
  32. p.createUser,
  33. p.createTime,
  34. p.updateUser,
  35. p.updateTime,
  36. pp.prodName,
  37. mp.prodkindId,
  38. pk.prodkindName,
  39. ppr.pprName
  40. from t_prod_stock p
  41. inner join m_prod pp on p.prodId = pp.prodId
  42. inner join m_merc_prod mp on p.prodId = mp.prodId and p.vendorId = mp.mercId
  43. inner join m_prodkind pk on mp.prodkindId = pk.prodkindId
  44. inner join m_prod_prop_relation ppr on p.pprId = ppr.pprId
  45. </sql>
  46. <select id="selectProdStockVoList" parameterType="ProdStockVo" resultMap="ProdStockVoResult">
  47. <include refid="selectProdStockVo"/>
  48. <where>
  49. <if test="prodkindId != null "> and mp.prodkindId = #{prodkindId}</if>
  50. <if test="prodId != null "> and p.prodId = #{prodId}</if>
  51. <if test="prodName != null and prodName != ''"> and pp.prodName like concat('%', #{prodName}, '%')</if>
  52. <if test="pprId != null "> and p.pprId = #{pprId}</if>
  53. <if test="vendorId != null "> and p.vendorId = #{vendorId}</if>
  54. <if test="stockQty != null "> and p.stockQty = #{stockQty}</if>
  55. <if test="availQty != null "> and p.availQty = #{availQty}</if>
  56. <if test="delFlag != null and delFlag != ''"> and p.delFlag = #{delFlag}</if>
  57. <if test="createUser != null and createUser != ''"> and p.createUser = #{createUser}</if>
  58. <if test="createTime != null "> and p.createTime = #{createTime}</if>
  59. <if test="updateUser != null and updateUser != ''"> and p.updateUser = #{updateUser}</if>
  60. <if test="updateTime != null "> and p.updateTime = #{updateTime}</if>
  61. </where>
  62. </select>
  63. <select id="selectProdStockVoByStockId" parameterType="Long" resultMap="ProdStockVoResult">
  64. <include refid="selectProdStockVo"/>
  65. where p.stockId = #{stockId}
  66. </select>
  67. <select id="selectProdStockVoByUnionId" parameterType="ProdStockVo" resultMap="ProdStockVoResult">
  68. select stockId, prodId, pprId, vendorId, stockQty, availQty, delFlag, createUser, createTime, updateUser, updateTime
  69. from t_prod_stock
  70. where prodId = #{prodId} and pprId = #{pprId} and vendorId = #{vendorId}
  71. limit 1
  72. </select>
  73. <update id="updateProdStockQty" parameterType="ProdStockVo">
  74. update t_prod_stock
  75. <trim prefix="SET" suffixOverrides=",">
  76. <if test='billType != null and billType == "1" and stockQty != null'>
  77. stockQty = ifnull(stockQty, 0) + #{stockQty},
  78. </if>
  79. <if test='billType != null and billType == "0" and stockQty != null'>
  80. stockQty = ifnull(stockQty, 0) - #{stockQty},
  81. </if>
  82. <if test='billType != null and billType == "1" and availQty != null'>
  83. availQty = ifnull(availQty, 0) + #{availQty},
  84. </if>
  85. <if test='billType != null and billType == "0" and availQty != null'>
  86. availQty = ifnull(availQty, 0) - #{availQty},
  87. </if>
  88. <if test="updateUser != null and updateUser != '' ">updateUser = #{updateUser},</if>
  89. <if test="updateTime != null">updateTime = #{updateTime},</if>
  90. </trim>
  91. where stockId = #{stockId}
  92. <if test='billType != null and billType == "0" and stockQty != null'>
  93. and stockQty - #{stockQty} >= 0
  94. </if>
  95. <if test='billType != null and billType == "0" and availQty != null'>
  96. and availQty - #{availQty} >= 0
  97. </if>
  98. </update>
  99. <update id="updateProdStockQtyByUnionId" parameterType="ProdStockVo">
  100. update t_prod_stock
  101. <trim prefix="SET" suffixOverrides=",">
  102. <if test='billType != null and billType == "1" and stockQty != null'>
  103. stockQty = ifnull(stockQty, 0) + #{stockQty},
  104. </if>
  105. <if test='billType != null and billType == "0" and stockQty != null'>
  106. stockQty = ifnull(stockQty, 0) - #{stockQty},
  107. </if>
  108. <if test='billType != null and billType == "1" and availQty != null'>
  109. availQty = ifnull(availQty, 0) + #{availQty},
  110. </if>
  111. <if test='billType != null and billType == "0" and availQty != null'>
  112. availQty = ifnull(availQty, 0) - #{availQty},
  113. </if>
  114. <if test="updateUser != null and updateUser != '' ">updateUser = #{updateUser},</if>
  115. <if test="updateTime != null">updateTime = #{updateTime},</if>
  116. </trim>
  117. where prodId = #{prodId} and pprId = #{pprId} and vendorId = #{vendorId}
  118. <if test='billType != null and billType == "0" and stockQty != null'>
  119. and stockQty - #{stockQty} >= 0
  120. </if>
  121. <if test='billType != null and billType == "0" and availQty != null'>
  122. and availQty - #{availQty} >= 0
  123. </if>
  124. </update>
  125. </mapper>