SubscribeDetailMapper.xml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.fjhx.purchase.mapper.subscribe.SubscribeDetailMapper">
  4. <select id="getPage" resultType="com.fjhx.purchase.entity.subscribe.vo.SubscribeDetailVo">
  5. SELECT *
  6. FROM ((SELECT t1.*,
  7. t2.`code` AS subscribeCode,
  8. t2.subcribe_content AS subscribeContent,
  9. t2.subcribe_time AS subcribeTime,
  10. t2.subcribe_name AS subcribeName,
  11. t2.id AS subcribeId,
  12. t2.required_arrival_time AS requiredArrivalTime,
  13. t2.put_warehouse_id AS putWarehouseId,
  14. t2.flow_id,
  15. t2.company_id AS corporationId,
  16. null AS prodTag,
  17. NULL AS prodRemark,
  18. t2.is_in_stock
  19. FROM subscribe_detail t1
  20. LEFT JOIN subscribe t2 ON t1.subscribe_id = t2.id
  21. AND t1.data_type = 0
  22. WHERE t1.data_type = 0)
  23. UNION ALL
  24. (SELECT t1.*,
  25. t2.`code` AS subscribeCode,
  26. null AS subscribeContent,
  27. t1.create_time AS subcribeTime,
  28. null AS subcribeName,
  29. t2.id AS subcribeId,
  30. null AS requiredArrivalTime,
  31. null AS putWarehouseId,
  32. t2.flow_id,
  33. null AS corporationId,
  34. t2.prod_tag AS prodTag,
  35. t2.prod_remark AS prodRemark,
  36. null as is_in_stock
  37. FROM subscribe_detail t1
  38. LEFT JOIN contract t2 ON t1.contract_id = t2.id
  39. WHERE t1.data_type = 1)) t2
  40. LEFT JOIN product_info pi ON t2.product_id = pi.id
  41. ${ew.customSqlSegment}
  42. </select>
  43. <select id="getDetail" resultType="com.fjhx.purchase.entity.subscribe.vo.SubscribeDetailVo">
  44. SELECT
  45. t1.*,
  46. IFNULL( SUM( t2.quantity ), 0 ) AS purchaseCount
  47. FROM
  48. subscribe_detail t1
  49. LEFT JOIN ehsd_purchase_product t2 ON t1.id = t2.subscribe_detail_id
  50. <where>
  51. <if test="ids neq null and ids.size() > 0">
  52. <foreach collection="ids" item="id" open="t1.id IN (" separator="," close=")">
  53. #{id}
  54. </foreach>
  55. </if>
  56. </where>
  57. GROUP BY
  58. t1.id
  59. </select>
  60. <select id="subscribeStatistics" resultType="com.fjhx.purchase.entity.subscribe.vo.SubscribeDetailVo">
  61. SELECT count(DISTINCT (pi.id)) typeCount,
  62. count(DISTINCT (su.id)) counts,
  63. ifnull(pi.type, -1) type
  64. FROM subscribe su
  65. LEFT JOIN subscribe_detail sd ON su.id = sd.subscribe_id
  66. LEFT JOIN product_info pi ON sd.bussiness_id = pi.id
  67. ${ew.customSqlSegment}
  68. </select>
  69. <select id="getPurchaseCountByIds" resultType="com.fjhx.purchase.entity.subscribe.po.SubscribeDetail">
  70. SELECT
  71. pp.subscribe_detail_id AS id,
  72. sum( pp.quantity ) AS `Count`
  73. FROM
  74. ehsd_purchase_product pp
  75. JOIN ehsd_purchase p ON pp.purchase_id = p.id
  76. <where>
  77. p.`status` IN ( 10, 30, 99 )
  78. <foreach collection="ids" item="id" open="and pp.subscribe_detail_id IN (" separator="," close=")">
  79. #{id}
  80. </foreach>
  81. </where>
  82. GROUP BY
  83. pp.subscribe_detail_id
  84. </select>
  85. <select id="getContractCountByContractIds"
  86. resultType="com.fjhx.purchase.entity.subscribe.vo.SubscribeDetailVo">
  87. SELECT
  88. cpb.contract_id,
  89. cpb.material_id AS productId,
  90. sum( cpb.quantity * cp.quantity ) AS count
  91. FROM
  92. contract_product_bom cpb
  93. LEFT JOIN contract_product cp ON cpb.contract_product_id = cp.id
  94. <where>
  95. <foreach collection="ids" item="id" open="cpb.contract_id IN (" separator="," close=")">
  96. #{id}
  97. </foreach>
  98. </where>
  99. GROUP BY
  100. cpb.contract_id,
  101. cpb.material_id
  102. </select>
  103. </mapper>