You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
10 KiB

11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  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.xujie.sys.modules.pms.mapper.InventoryStockMapper">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.xujie.sys.modules.pms.entity.InventoryStockEntity" id="inventoryStockMap">
  6. <result property="site" column="site"/>
  7. <result property="warehouseId" column="warehouse_id"/>
  8. <result property="partNo" column="part_no"/>
  9. <result property="batchNo" column="batch_no"/>
  10. <result property="locationId" column="location_id"/>
  11. <result property="firstInDate" column="first_in_date"/>
  12. <result property="latestOutDate" column="latest_out_date"/>
  13. <result property="latestInDate" column="latest_in_date"/>
  14. <result property="activeDate" column="active_date"/>
  15. <result property="inQty" column="in_qty"/>
  16. <result property="outQty" column="out_qty"/>
  17. <result property="qtyOnHand" column="qty_on_hand"/>
  18. <result property="qtyReserved" column="qty_reserved"/>
  19. <result property="inStandardValue" column="in_standard_value"/>
  20. <result property="inActualValue" column="in_actual_value"/>
  21. <result property="outStandardValue" column="out_standard_value"/>
  22. <result property="outActualValue" column="out_actual_value"/>
  23. <result property="partnerId" column="partner_id"/>
  24. <result property="partnerType" column="partner_type"/>
  25. <result property="latestCountDate" column="latest_count_date"/>
  26. <result property="freezeFlag" column="freeze_flag"/>
  27. <result property="qtyTmp" column="qty_tmp"/>
  28. <result property="manuFactureDate" column="manu_facture_date"/>
  29. <result property="expiredDate" column="expired_date"/>
  30. <result property="qtyToIssue" column="qty_to_issue"/>
  31. <result property="id" column="id"/>
  32. <result property="citemCode" column="citem_code"/>
  33. <result property="qtyOfPo" column="qty_of_po"/>
  34. </resultMap>
  35. <select id="queryPage" resultType="com.xujie.sys.modules.pms.entity.InventoryStockVoData">
  36. SELECT
  37. a.citem_code,
  38. min(A.id) id,
  39. A.site,
  40. min(A.warehouse_id) AS warehouse_id,
  41. A.part_no,min(A.batch_no) as batch_no,
  42. min(A.location_id) AS location_id,
  43. sum(isnull(A.in_qty, 0)) AS inQty,
  44. sum(isnull(A.out_qty, 0)) AS outQty,
  45. sum(isnull(A.qty_on_hand, 0)) AS qtyOnHand,
  46. B.part_description,
  47. min(B.spec) AS spec,
  48. B.min_stock,
  49. B.max_stock,
  50. min(A.partner_id) AS partner_id,
  51. min(A.first_in_date) AS first_in_date,
  52. B.average_price,
  53. B.umid,
  54. (sum(isnull(A.qty_on_hand, 0)) * B.average_price) as totalCost,
  55. dbo.get_bu_desc(A.site, A.citem_code) buDesc
  56. from inventory_stock A
  57. left join part_spare B on A.site = B.site and A.part_no = B.part_no and a.citem_code = b.bu_no
  58. <where>
  59. A.site in (select site from eam_access_site where username = #{query.username})
  60. and (A.site + '-' + A.citem_code) in (select * from dbo.query_bu(#{query.username}))
  61. and A.batch_no is not null and b.part_no is not null
  62. <if test="query.buDesc != null and query.buDesc != ''">
  63. AND dbo.get_bu_desc (a.site, a.citem_code) = #{query.buDesc}
  64. </if>
  65. <if test="query.active != null and query.active != ''">
  66. and B.active = #{query.active}
  67. </if>
  68. <if test="query.batchNo != null and query.batchNo != ''">
  69. and A.batch_no like '%'+#{query.batchNo}+'%'
  70. </if>
  71. <if test="query.warehouseId != null and query.warehouseId != ''">
  72. and A.warehouse_id like '%'+#{query.warehouseId}+'%'
  73. </if>
  74. <if test="query.locationId != null and query.locationId != ''">
  75. and A.location_id like '%'+#{query.locationId}+'%'
  76. </if>
  77. <if test="query.partNo != null and query.partNo != ''">
  78. and A.part_no like '%'+#{query.partNo}+'%'
  79. </if>
  80. <if test="query.partDescription != null and query.partDescription != ''">
  81. and B.part_description like '%'+#{query.partDescription}+'%'
  82. </if>
  83. <if test="query.spec != null and query.spec != '' ">
  84. and B.spec like '%'+#{query.spec}+'%'
  85. </if>
  86. <if test="query.startFirstInDate != null and query.startFirstInDate != ''">
  87. and A.first_in_date >= #{query.startFirstInDate}
  88. </if>
  89. <if test="query.endFirstInDate != null and query.endFirstInDate != ''">
  90. and A.first_in_date <![CDATA[<=]]> #{query.endFirstInDate}
  91. </if>
  92. <if test="query.startQtyOnHand != null ">
  93. and A.qty_on_hand >= #{query.startQtyOnHand}
  94. </if>
  95. <if test="query.endQtyOnHand !=null ">
  96. and A.qty_on_hand <![CDATA[<=]]> #{query.endQtyOnHand}
  97. </if>
  98. <if test="query.safetyStock == '安全'">
  99. and A.qty_on_hand <![CDATA[>]]> B.min_stock
  100. </if>
  101. <if test="query.safetyStock == '不安全'">
  102. and A.qty_on_hand <![CDATA[<=]]> B.min_stock
  103. </if>
  104. </where>
  105. GROUP BY
  106. <if test="query.groupType == 0">
  107. A.site, A.part_no, B.part_description, A.batch_no, b.min_stock, b.max_stock, B.average_price, B.umid, a.citem_code
  108. </if>
  109. <if test="query.groupType == 1">
  110. A.site, A.part_no, B.part_description, b.min_stock, b.max_stock, B.average_price, B.umid, a.citem_code
  111. </if>
  112. </select>
  113. <update id="updateQtyOfPoByIdOfAdd">
  114. update inventory_stock set qty_of_po = isnull(qty_of_po,0) + #{qtyOfPo} where id = #{id}
  115. </update>
  116. <update id="updateQtyOnHandByIdOfAdd">
  117. update inventory_stock set qty_on_hand = isnull(qty_on_hand,0) + #{qtyOfPo}, qty_of_po = isnull(qty_of_po,0) - #{qtyOfPo} where id = #{id}
  118. </update>
  119. <update id="updateQtyOfPoByIdOfSub">
  120. update inventory_stock set qty_of_po = isnull(qty_of_po,0) - #{qtyOfPo} where id = #{id}
  121. </update>
  122. <select id="queryPageByPo" resultType="com.xujie.sys.modules.pms.entity.InventoryStockVoData">
  123. SELECT
  124. A.citem_code,
  125. min(A.id) as id,
  126. A.site,
  127. min(A.warehouse_id) AS warehouse_id,
  128. A.part_no,min(A.batch_no) as batch_no,
  129. min(A.location_id) AS location_id,
  130. sum(isnull( A.in_qty , 0 )) AS inQty,
  131. sum(isnull( A.out_qty , 0 )) AS outQty,
  132. sum(isnull( A.qty_on_hand , 0 )) AS qtyOnHand,
  133. B.part_description,
  134. min(B.spec) AS spec,
  135. B.min_stock,
  136. B.max_stock,
  137. min(A.partner_id) AS partner_id,
  138. min(A.first_in_date) AS first_in_date,
  139. B.average_price,
  140. B.umid,
  141. sum(isnull(A.qty_of_po,0)) as qty_of_po,
  142. (sum(isnull( A.qty_on_hand , 0 )) * B.average_price) as totalCost,
  143. dbo.get_bu_desc( A.site,A.citem_code) buDesc
  144. from inventory_stock A
  145. left join part_spare B on A.site = B.site and A.part_no = B.part_no and a.citem_code = b.bu_no
  146. <where>
  147. A.site in (select site from eam_access_site where username = #{query.username})
  148. and (A.site + '-' + A.citem_code) in (select * from dbo.query_bu(#{query.username}))
  149. and A.batch_no is not null and b.part_no is not null
  150. <if test="query.buDesc != null and query.buDesc != ''">
  151. AND dbo.get_bu_desc (a.site, a.citem_code) = #{query.buDesc}
  152. </if>
  153. <if test="query.active != null and query.active != ''">
  154. and B.active = #{query.active}
  155. </if>
  156. <if test="query.buNo != null and query.buNo != ''">
  157. and a.citem_code = #{query.buNo}
  158. </if>
  159. <if test="query.batchNo != null and query.batchNo != ''">
  160. and A.batch_no like '%'+#{query.batchNo}+'%'
  161. </if>
  162. <if test="query.warehouseId != null and query.warehouseId != ''">
  163. and A.warehouse_id like '%'+#{query.warehouseId}+'%'
  164. </if>
  165. <if test="query.locationId != null and query.locationId != ''">
  166. and A.location_id like '%'+#{query.locationId}+'%'
  167. </if>
  168. <if test="query.partNo != null and query.partNo != ''">
  169. and A.part_no like '%'+#{query.partNo}+'%'
  170. </if>
  171. <if test="query.partDescription != null and query.partDescription != ''">
  172. and B.part_description like '%'+#{query.partDescription}+'%'
  173. </if>
  174. <if test="query.spec != null and query.spec != '' ">
  175. and B.spec like '%'+#{query.spec}+'%'
  176. </if>
  177. <if test="query.startFirstInDate != null and query.startFirstInDate != ''">
  178. and A.first_in_date >= #{query.startFirstInDate}
  179. </if>
  180. <if test="query.endFirstInDate != null and query.endFirstInDate != ''">
  181. and A.first_in_date <![CDATA[<=]]> #{query.endFirstInDate}
  182. </if>
  183. <if test="query.startQtyOnHand != null ">
  184. and A.qty_on_hand >= #{query.startQtyOnHand}
  185. </if>
  186. <if test="query.endQtyOnHand !=null ">
  187. and A.qty_on_hand <![CDATA[<=]]> #{query.endQtyOnHand}
  188. </if>
  189. <if test="query.safetyStock == '安全'">
  190. and A.qty_on_hand <![CDATA[>]]> B.min_stock
  191. </if>
  192. </where>
  193. GROUP BY
  194. <if test="query.groupType == 0">
  195. A.site, A.part_no, B.part_description, A.batch_no, b.min_stock, b.max_stock, B.average_price, B.umid,a.citem_code
  196. </if>
  197. <if test="query.groupType == 1">
  198. A.site, A.part_no, B.part_description, b.min_stock, b.max_stock, B.average_price, B.umid,a.citem_code
  199. </if>
  200. <if test="query.safetyStock == '不安全' and (query.securityMethod == '库存' or query.securityMethod == '' or query.securityMethod == null )">
  201. having sum(A.qty_on_hand) <![CDATA[<]]> B.min_stock
  202. </if>
  203. <if test="query.safetyStock == '不安全' and query.securityMethod == '库存和在途'">
  204. having sum(A.qty_on_hand) + sum(isnull(A.qty_of_po,0.0)) <![CDATA[<]]> B.min_stock
  205. </if>
  206. </select>
  207. </mapper>