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.

482 lines
19 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years 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.xjfast.mapper.MrpPlanDataMapper">
  4. <resultMap id="BaseResultMap" type="com.xjfast.entity.MrpPlanData">
  5. <result column="id" jdbcType="INTEGER" property="id"/>
  6. <result column="site" jdbcType="VARCHAR" property="site"/>
  7. <result column="ware_house_id" jdbcType="VARCHAR" property="wareHouseId"/>
  8. <result column="part_no" jdbcType="VARCHAR" property="partNo"/>
  9. <result column="calculation_type" jdbcType="VARCHAR" property="calculationType"/>
  10. <result column="plan_date" jdbcType="TIMESTAMP" property="planDate"/>
  11. <result column="plan_qty" jdbcType="FLOAT" property="planQty"/>
  12. <result column="plan_desc" jdbcType="VARCHAR" property="planDesc"/>
  13. <result column="order_ref1" jdbcType="VARCHAR" property="orderRef1"/>
  14. <result column="order_ref2" jdbcType="VARCHAR" property="orderRef2"/>
  15. <result column="order_ref3" jdbcType="VARCHAR" property="orderRef3"/>
  16. </resultMap>
  17. <!--添加库存记录-->
  18. <insert id="insertMrpInventoryStock" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  19. INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site,
  20. plan_date,direction,calculation_type,plan_desc,created_by) SELECT
  21. i.WarehouseID as ware_house_id,
  22. i.PartNo as part_no,
  23. i.QtyOnHand as plan_qty,
  24. i.site as site,
  25. CONVERT(VARCHAR (10), GETDATE(), 120) as plan_date,
  26. '+' as direction,
  27. #{calculationType} as calculation_type,
  28. '库存' as plan_desc,
  29. #{otherGroup2} as created_by
  30. FROM InventoryStock i
  31. LEFT JOIN WareHouse wh on ( i.WarehouseID = wh.WarehouseID)
  32. LEFT JOIN part p ON ( p.PartNo = i.PartNo )
  33. <where>
  34. wh.WareHouseType_DB = #{wareHouseTypeDb}
  35. <if test="partNo != null and partNo != ''">
  36. and i.PartNo = #{partNo}
  37. </if>
  38. <if test="otherGroup2 != null and otherGroup2 != ''">
  39. and p.OtherGroup2 = #{otherGroup2}
  40. </if>
  41. <if test="wareHouseId != null and wareHouseId != ''">
  42. and i.WarehouseID = #{wareHouseId}
  43. </if>
  44. <if test="wareHouseId != null and wareHouseId != ''">
  45. and i.WarehouseID = #{wareHouseId}
  46. </if>
  47. <if test="site != null and site != ''">
  48. and i.site =#{site}
  49. </if>
  50. </where>
  51. </insert>
  52. <!-- 添加在途信息记录 -->
  53. <insert id="insertMrpCode" parameterType="com.xjfast.entity.query.CodelheaderQuery">
  54. INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site, plan_date,
  55. direction,calculation_type,plan_desc,created_by)
  56. SELECT cd.WarehouseID AS ware_house_id,
  57. cd.PartNo AS part_no,
  58. cd.ShipQty AS plan_qty,
  59. cd.site AS site,
  60. ch.DelDate AS plan_date,
  61. '+' as direction,
  62. #{calculationType} as calculation_type,
  63. '在途' as plan_desc,
  64. #{otherGroup2} as created_by
  65. FROM CODelDetail cd
  66. JOIN CODelHeader ch on (cd.DelNo = ch.DelNo)
  67. LEFT JOIN part p ON ( cd.PartNo = p.PartNo )
  68. <where>
  69. <if test="partNo != null and partNo != ''">
  70. cd.PartNo = #{partNo}
  71. </if>
  72. <if test="otherGroup2 != null and otherGroup2 != ''">
  73. and p.OtherGroup2 = #{otherGroup2}
  74. </if>
  75. <if test="warehouseId != null and warehouseId != ''">
  76. and cd.WarehouseID = #{warehouseId}
  77. </if>
  78. </where>
  79. </insert>
  80. <!--获取所有sku的日消耗 -->
  81. <insert id="insertDaysMrp" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  82. INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site, plan_date, direction,
  83. calculation_type,plan_desc,created_by)
  84. SELECT ppi.ware_house_id AS ware_house_id,
  85. ppi.part_no AS part_no,
  86. ppi.average_consume_qty AS plan_qty,
  87. ppi.site AS site,
  88. #{planDate} AS plan_date,
  89. '-' AS direction,
  90. #{calculationType} as calculation_type,
  91. '日消耗' as plan_desc,
  92. #{otherGroup2} as created_by
  93. FROM part_plan_info ppi
  94. LEFT JOIN WareHouse wh on(ppi.ware_house_id = wh.WareHouseID)
  95. LEFT JOIN part p ON (ppi.part_no = p.PartNo )
  96. <where>
  97. wh.WareHouseType_DB = #{wareHouseTypeDb}
  98. <if test="otherGroup2 != null and otherGroup2 != ''">
  99. and p.OtherGroup2 = #{otherGroup2}
  100. </if>
  101. <if test="site != null and site != ''">
  102. and site = #{site}
  103. </if>
  104. <if test="partNo != null and partNo != ''">
  105. and ppi.part_no = #{partNo}
  106. </if>
  107. <if test="wareHouseId != null and wareHouseId != ''">
  108. and ppi.ware_house_id = #{wareHouseId}
  109. </if>
  110. </where>
  111. </insert>
  112. <!--库存需要保留安全位数-->
  113. <insert id="insertInventoryMaintain" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  114. INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site, plan_date, direction,
  115. calculation_type,plan_desc,created_by)
  116. SELECT ppi.ware_house_id AS ware_house_id,
  117. ppi.part_no AS part_no,
  118. ppi.average_consume_qty * cover_days AS plan_qty,
  119. ppi.site AS site,
  120. #{planDate} AS plan_date,
  121. '-' AS direction,
  122. #{calculationType} AS calculation_type,
  123. '库存安全数' AS plan_desc,
  124. #{otherGroup2} as created_by
  125. FROM part_plan_info ppi
  126. LEFT JOIN WareHouse wh on(ppi.ware_house_id = wh.WareHouseID)
  127. LEFT JOIN part p ON (ppi.part_no = p.PartNo )
  128. <where>
  129. wh.WareHouseType_DB = #{wareHouseTypeDb}
  130. <if test="otherGroup2 != null and otherGroup2 != ''">
  131. and p.OtherGroup2 = #{otherGroup2}
  132. </if>
  133. <if test="partNo != null and partNo != ''">
  134. and part_no = #{partNo}
  135. </if>
  136. <if test="wareHouseId != null and wareHouseId != ''">
  137. and ware_house_id = #{wareHouseId}
  138. </if>
  139. <if test="site != null and site != ''">
  140. and wh.site =#{site}
  141. </if>
  142. </where>
  143. </insert>
  144. <!-- 导入补货建议单 -->
  145. <insert id="insertMpsPlan" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  146. INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site, plan_date, direction, calculation_type,
  147. plan_desc,created_by)
  148. SELECT ware_house_id AS ware_house_id,
  149. part_no AS part_no,
  150. MAX(qty_required) AS plan_qty,
  151. site AS site,
  152. MIN(need_date) AS plan_date,
  153. '-' AS direction,
  154. #{calculationType} AS calculation_type,
  155. '备货' AS plan_desc,
  156. #{otherGroup2} as created_by
  157. FROM delivery_requisition d
  158. <where>
  159. status = '创建'
  160. <if test="partNo != null and partNo != ''">
  161. and part_no = #{partNo}
  162. </if>
  163. <if test="site != null and site != ''">
  164. and site =#{site}
  165. </if>
  166. </where>
  167. GROUP BY ware_house_id,
  168. part_no,
  169. site,
  170. created_by,
  171. status,
  172. site
  173. </insert>
  174. <!-- 生成生产计划单 -->
  175. <insert id="insertShopOrderRequisition" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  176. INSERT INTO shop_order_requisition ( site, part_no, need_date, status, qty_required, created_by, created_date )
  177. SELECT
  178. site,
  179. part_no,
  180. MIN(plan_date) AS need_date,
  181. '创建' AS status,
  182. - SUM ( CASE WHEN direction = '+' THEN + plan_qty ELSE - plan_qty END ) AS qty_required,
  183. 'admin' AS created_by,
  184. GETDATE( ) AS created_date
  185. FROM
  186. mrp_plan_data
  187. <where>
  188. calculation_type = 'MPS' AND plan_desc != '建议生产'
  189. <if test="partNo != null and partNo != ''">
  190. and part_no = #{partNo}
  191. </if>
  192. </where>
  193. GROUP BY
  194. part_no,
  195. site
  196. HAVING
  197. SUM ( CASE WHEN direction = '+' THEN + plan_qty ELSE - plan_qty END ) <![CDATA[ <=]]> 0
  198. </insert>
  199. <!--临时补货 (虚拟记录)-->
  200. <insert id="insertTemporaryStocking" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  201. INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site, plan_date, direction,
  202. calculation_type, plan_desc, created_by)
  203. SELECT ware_house_id,
  204. part_no,
  205. -SUM(CASE WHEN direction = '+' THEN + plan_qty ELSE - plan_qty END) AS qty_required,
  206. site,
  207. #{planDate} AS plan_date,
  208. '+' direction,
  209. #{calculationType} calculation_type,
  210. '临时补货' plan_desc,
  211. #{otherGroup2} as created_by
  212. FROM mrp_plan_data
  213. where plan_date <![CDATA[<=]]> #{planDate}
  214. and calculation_type = #{calculationType}
  215. and site = #{site}
  216. GROUP BY ware_house_id,
  217. part_no,
  218. site
  219. HAVING SUM(CASE WHEN direction = '+' THEN + plan_qty ELSE - plan_qty END)<![CDATA[ <=]]> 0
  220. </insert>
  221. <insert id="addDelivryRequisition" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  222. INSERT INTO delivery_requisition (qty_required, ware_house_id, part_no, need_date, site, status, created_date,
  223. created_by)
  224. SELECT SUM(plan_qty) AS qty_required,
  225. ware_house_id,
  226. part_no,
  227. MIN(plan_date) AS need_date,
  228. site,
  229. '创建' status,
  230. CONVERT(VARCHAR (10), GETDATE(), 120) created_date,
  231. #{createdBy} created_by
  232. FROM mrp_plan_data
  233. <where>
  234. plan_desc = #{planDesc}
  235. <if test="wareHouseId != null and wareHouseId != ''">
  236. and ware_house_id =#{wareHouseId}
  237. </if>
  238. <if test="partNo != null and partNo != ''">
  239. and part_no = #{partNo}
  240. </if>
  241. </where>
  242. GROUP BY ware_house_id,
  243. part_no,
  244. site
  245. </insert>
  246. <insert id="addMrpPlanData" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  247. INSERT INTO mrp_plan_data (ware_house_id, part_no, plan_qty, site, plan_date, direction, calculation_type,
  248. plan_desc,created_by)
  249. SELECT ware_house_id,
  250. part_no,
  251. SUM(plan_qty) AS plan_qty,
  252. site,
  253. MIN(plan_date) AS plan_date,
  254. '+' AS direction,
  255. 'MS' calculation_type,
  256. '建议备货' plan_desc,
  257. #{otherGroup2} as created_by
  258. FROM mrp_plan_data
  259. <where>
  260. plan_desc = #{planDesc}
  261. <if test="site != null and site != ''">
  262. and site = #{site}
  263. </if>
  264. <if test="wareHouseId != null and wareHouseId != ''">
  265. and ware_house_id =#{wareHouseId}
  266. </if>
  267. <if test="partNo != null and partNo != ''">
  268. and part_no = #{partNo}
  269. </if>
  270. </where>
  271. GROUP BY ware_house_id,
  272. part_no,
  273. site
  274. </insert>
  275. <insert id="insertShopMrp" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  276. INSERT INTO mrp_plan_data ( part_no, plan_qty, site, plan_date, direction, calculation_type,
  277. plan_desc,created_by ) SELECT
  278. PartNo AS part_no,
  279. ISNULL(LotSize,0) -ISNULL(FinishedQty, 0) AS plan_qty,
  280. NeedDate plan_date,
  281. Site AS site,
  282. '+' AS direction,
  283. 'MPS' AS calculation_type,
  284. '库存' AS plan_desc,
  285. #{otherGroup2} as created_by
  286. FROM
  287. ShopOrder
  288. <where>
  289. Status != '已取消' AND Status != '已结束' AND NeedDate <![CDATA[<=]]> #{planDate}
  290. <if test=" site!=null and site!='' ">
  291. and Site = #{site}
  292. </if>
  293. <if test=" partNo!=null and partNo!='' ">
  294. and PartNo = #{partNo}
  295. </if>
  296. </where>
  297. </insert>
  298. <!--添加计算生产计划-->
  299. <insert id="insertMrpShopOrder" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  300. INSERT INTO mrp_plan_data ( part_no, plan_qty, site, plan_date, direction, calculation_type,
  301. plan_desc,created_by )
  302. SELECT
  303. part_no,
  304. - SUM ( CASE WHEN direction = '+' THEN + plan_qty ELSE - plan_qty END ) AS plan_qty,
  305. site,
  306. MIN(plan_date),
  307. '+' AS direction,
  308. 'MPS' AS calculation_type,
  309. '建议生产' AS plan_desc,
  310. #{otherGroup2} as created_by
  311. FROM
  312. mrp_plan_data
  313. <where>
  314. calculation_type = 'MPS' and plan_desc != '建议生产'
  315. <if test="partNo != null and partNo != ''">
  316. and part_no = #{partNo}
  317. </if>
  318. </where>
  319. GROUP BY
  320. part_no,
  321. site
  322. HAVING
  323. SUM ( CASE WHEN direction = '+' THEN + plan_qty ELSE - plan_qty END ) <![CDATA[<=]]> 0
  324. </insert>
  325. <!-- 没有维护安全库存的 活动物料-->
  326. <insert id="insertMrpPlanList" parameterType="collection">
  327. INSERT INTO mrp_plan_data ( part_no, plan_qty, site,ware_house_id, plan_date, direction, calculation_type,
  328. plan_desc,created_by )
  329. VALUES
  330. <foreach collection="list" item="item" index="index" separator=",">
  331. (
  332. #{item.partNo},
  333. #{item.planQty},
  334. #{item.site},
  335. #{item.wareHouseId},
  336. #{item.planDate},
  337. #{item.direction},
  338. #{item.calculationType},
  339. #{item.planDesc},
  340. #{item.createdBy}
  341. )
  342. </foreach>
  343. </insert>
  344. <!--更具活动时间范围 修改 mrp_plan_data 表对对应 的数据-->
  345. <update id="updateMrpHis" parameterType="com.xjfast.entity.vo.PromotionHistVo">
  346. UPDATE mrp_plan_data
  347. SET plan_qty = #{averageConsumeQty},
  348. direction = '-',
  349. calculation_type = 'MS',
  350. plan_desc = '活动消耗'
  351. WHERE plan_date <![CDATA[>=]]> #{startDate}
  352. AND plan_date <![CDATA[<=]]> #{finishDate}
  353. AND ware_house_id = #{wareHouseId}
  354. AND part_no = #{partNo}
  355. AND plan_desc = '日消耗'
  356. AND site = #{site}
  357. </update>
  358. <select id="selectInvetorySum" parameterType="com.xjfast.entity.query.MrpPlanDataQuery"
  359. resultType="com.xjfast.entity.vo.MrpPlanDataVo">
  360. SELECT mpd.ware_house_id, mpd.part_no, SUM(mpd.plan_qty) , SUM(mpd.plan_qty) - ppi.average_consume_qty as
  361. difference
  362. FROM mrp_plan_data mpd
  363. LEFT JOIN part_plan_info ppi on (mpd.ware_house_id = ppi.ware_house_id and mpd.part_no = ppi.part_no)
  364. <where>
  365. <if test="partNo != null and partNo != ''">
  366. mpd.part_no = #{partNo}
  367. </if>
  368. <if test="wareHouseId != null and wareHouseId != ''">
  369. and mpd.ware_house_id = #{wareHouseId}
  370. </if>
  371. </where>
  372. GROUP BY mpd.ware_house_id, mpd.part_no, ppi.average_consume_qty
  373. HAVING SUM(mpd.plan_qty) <![CDATA[<]]> ppi.average_consume_qty
  374. </select>
  375. <select id="searchMrpPlanDataList" resultType="com.xjfast.entity.vo.MrpPlanDataVo">
  376. select m.*, p.PartDescription, w.WareHouseName
  377. from mrp_plan_data m
  378. left join Part p on (m.part_no = p.PartNo)
  379. left join WareHouse w on (w.WareHouseID = m.ware_house_id)
  380. <where>
  381. m.site = #{site}
  382. <if test="planDesc != null and planDesc != ''">
  383. and m.plan_desc != #{planDesc}
  384. </if>
  385. <if test="partNo != null and partNo != ''">
  386. and m.part_no = #{partNo}
  387. </if>
  388. <if test="wareHouseId != null and wareHouseId != ''">
  389. and m.ware_house_id = #{wareHouseId}
  390. </if>
  391. <if test="deliveryRequisitionId != null and deliveryRequisitionId != ''">
  392. and m.delivery_requisition_id = #{deliveryRequisitionId}
  393. </if>
  394. <if test="calculationType != null and calculationType != ''">
  395. and m.calculation_type = #{calculationType}
  396. </if>
  397. </where>
  398. order by m.plan_date
  399. </select>
  400. <!-- 删除mrp记录表信息-->
  401. <delete id="removeMrpPlan" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  402. DELETE FROM mrp_plan_data
  403. <where>
  404. <if test="otherGroup2 != null and otherGroup2 != ''">
  405. and created_by =#{otherGroup2}
  406. </if>
  407. <if test="site != null and site != ''">
  408. and site =#{site}
  409. </if>
  410. <if test="partNo != null and partNo != '' ">
  411. and part_no = #{partNo}
  412. </if>
  413. <if test="wareHouseId != null and wareHouseId != '' ">
  414. and ware_house_id = #{wareHouseId}
  415. </if>
  416. <if test="id != null and id != ''">
  417. and id = #{id}
  418. </if>
  419. <if test="calculationType != null and calculationType != ''">
  420. and calculation_type = #{calculationType}
  421. </if>
  422. </where>
  423. </delete>
  424. <delete id="removeDelivryRequisition" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  425. DELETE FROM delivery_requisition
  426. <where>
  427. status = '创建'
  428. <if test="site != null and site != ''">
  429. and site =#{site}
  430. </if>
  431. <if test="otherGroup2 != null and otherGroup2 != ''">
  432. and created_by =#{otherGroup2}
  433. </if>
  434. <if test="partNo != null and partNo != ''">
  435. and part_no = #{partNo}
  436. </if>
  437. <if test="wareHouseId != null and wareHouseId != '' ">
  438. and ware_house_id = #{wareHouseId}
  439. </if>
  440. </where>
  441. </delete>
  442. <!--删除生产计划单-->
  443. <delete id="reomveShopOrderRequisition" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  444. DELETE FROM shop_order_requisition
  445. <where>
  446. status = '创建'
  447. <if test="partNo != null and partNo != ''">
  448. AND part_no = #{partNo}
  449. </if>
  450. <if test="site != null and site != ''">
  451. and site =#{site}
  452. </if>
  453. </where>
  454. </delete>
  455. <delete id="removeMrpPlanLs" parameterType="com.xjfast.entity.query.MrpPlanDataQuery">
  456. DELETE FROM mrp_plan_data
  457. <where>
  458. plan_desc = '临时补货'
  459. <if test="site != null and site != ''">
  460. and site =#{site}
  461. </if>
  462. <if test="otherGroup2 != null and otherGroup2 != ''">
  463. and created_by =#{otherGroup2}
  464. </if>
  465. <if test="partNo != null and partNo != ''">
  466. and part_no = #{partNo}
  467. </if>
  468. <if test="wareHouseId != null and wareHouseId != '' ">
  469. and ware_house_id = #{wareHouseId}
  470. </if>
  471. </where>
  472. </delete>
  473. </mapper>