SubscribeDetailMapper.xml 4.2 KB

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