TaskOrderLeftJoinMapper.xml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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="cn.start.tz.module.pressure2.dal.mysql.taskordernontaxapply.TaskOrderLeftJoinMapper">
  4. <!--
  5. 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
  6. 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
  7. 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
  8. 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
  9. -->
  10. <select id="selectTaskOrderPaymentPage" resultType="cn.start.tz.module.pressure2.controller.admin.taskordernontaxapply.vo.TaskOrderPaymentRespVO">
  11. SELECT
  12. t.id,
  13. t.order_no AS orderNo,
  14. t.dept_id AS deptId,
  15. t.payer_contact_name AS payerContactName,
  16. t.payer_contact AS payerContact,
  17. t.actual_amount AS actualAmount,
  18. t.should_amount AS shouldAmount,
  19. t.service_amount AS serviceAmount,
  20. t.use_unit_id AS useUnitId,
  21. t.use_unit_name AS useUnitName,
  22. t.check_type AS checkType,
  23. t.equip_num AS equipNum,
  24. t.check_date AS checkDate,
  25. t.payment_status AS paymentStatus,
  26. t.no_tax_payment_status AS noTaxPaymentStatus,
  27. t.confirm_date AS confirmDate,
  28. t.reduction_radio AS reductionRadio,
  29. t.equip_main_type AS equipMainType,
  30. p.remark AS followRemark,
  31. p.creator AS followId,
  32. p.create_time AS followTime,
  33. c.Is_Exempt as IsExempt
  34. FROM pressure_task_order t
  35. LEFT JOIN pressure2_payment_follow_record p ON p.task_order_id = t.id AND p.deleted = 0
  36. AND p.id IN (
  37. SELECT id FROM pressure2_payment_follow_record
  38. WHERE deleted = 0
  39. AND (task_order_id, create_time) IN (
  40. SELECT task_order_id, MAX(create_time)
  41. FROM pressure2_payment_follow_record
  42. WHERE deleted = 0
  43. GROUP BY task_order_id
  44. )
  45. )
  46. left join system_client_unit c on c.CODE = t.UNIT_CODE and c.deleted = 0
  47. WHERE t.deleted = 0 AND t.equip_main_type in (200,300)
  48. AND t.task_status = 800
  49. <if test="reqVO.paymentStatus != null">
  50. AND t.payment_status = #{reqVO.paymentStatus}
  51. </if>
  52. <if test="reqVO.noTaxPaymentStatus != null">
  53. AND t.no_tax_payment_status = #{reqVO.noTaxPaymentStatus}
  54. </if>
  55. <if test="reqVO.feeType != null">
  56. AND t.fee_type = #{reqVO.feeType}
  57. </if>
  58. <if test="reqVO.checkType != null">
  59. AND t.check_type = #{reqVO.checkType}
  60. </if>
  61. <if test="reqVO.payerContactName != null and reqVO.payerContactName != ''">
  62. AND t.payer_contact_name LIKE CONCAT('%', #{reqVO.payerContactName}, '%')
  63. </if>
  64. <if test="reqVO.payerContact != null and reqVO.payerContact != ''">
  65. AND t.payer_contact LIKE CONCAT('%', #{reqVO.payerContact}, '%')
  66. </if>
  67. <if test="reqVO.useUnitName != null and reqVO.useUnitName != ''">
  68. AND t.use_unit_name LIKE CONCAT('%', #{reqVO.useUnitName}, '%')
  69. </if>
  70. <if test="reqVO.orderNo != null and reqVO.orderNo != ''">
  71. AND t.order_no LIKE CONCAT('%', #{reqVO.orderNo}, '%')
  72. </if>
  73. <if test="reqVO.followById != null and reqVO.followById != ''">
  74. AND p.creator = #{reqVO.followById}
  75. </if>
  76. <if test="reqVO.isExempt != null and reqVO.isExempt != ''">
  77. AND c.Is_Exempt = #{reqVO.isExempt}
  78. </if>
  79. <if test="reqVO.useUnitId != null">
  80. AND t.use_unit_id = #{reqVO.useUnitId}
  81. </if>
  82. <if test="reqVO.checkDate != null and reqVO.checkDate.length > 0">
  83. AND t.check_date BETWEEN #{reqVO.checkDate[0]} AND #{reqVO.checkDate[1]}
  84. </if>
  85. <if test="reqVO.deptId != null and reqVO.deptId != ''">
  86. AND t.dept_id = #{reqVO.deptId}
  87. </if>
  88. <if test="reqVO.equipMainType != null">
  89. AND t.equip_main_type = #{reqVO.equipMainType}
  90. </if>
  91. ORDER BY t.create_time DESC
  92. OFFSET ${(reqVO.pageNo - 1) * reqVO.pageSize} ROWS FETCH NEXT #{reqVO.pageSize} ROWS ONLY
  93. </select>
  94. <select id="selectTaskOrderPaymentCount" resultType="java.lang.Long">
  95. SELECT COUNT(DISTINCT t.id)
  96. FROM pressure_task_order t
  97. LEFT JOIN pressure2_payment_follow_record p ON p.task_order_id = t.id AND p.deleted = 0
  98. AND p.id IN (
  99. SELECT id FROM pressure2_payment_follow_record
  100. WHERE deleted = 0
  101. AND (task_order_id, create_time) IN (
  102. SELECT task_order_id, MAX(create_time)
  103. FROM pressure2_payment_follow_record
  104. WHERE deleted = 0
  105. GROUP BY task_order_id
  106. )
  107. )
  108. left join system_client_unit c on c.CODE = t.UNIT_CODE and c.deleted = 0
  109. WHERE t.deleted = 0 AND t.equip_main_type in (200,300)
  110. AND t.task_status = 800
  111. <if test="reqVO.paymentStatus != null">
  112. AND t.payment_status = #{reqVO.paymentStatus}
  113. </if>
  114. <if test="reqVO.noTaxPaymentStatus != null">
  115. AND t.no_tax_payment_status = #{reqVO.noTaxPaymentStatus}
  116. </if>
  117. <if test="reqVO.feeType != null">
  118. AND t.fee_type = #{reqVO.feeType}
  119. </if>
  120. <if test="reqVO.checkType != null">
  121. AND t.check_type = #{reqVO.checkType}
  122. </if>
  123. <if test="reqVO.payerContactName != null and reqVO.payerContactName != ''">
  124. AND t.payer_contact_name LIKE CONCAT('%', #{reqVO.payerContactName}, '%')
  125. </if>
  126. <if test="reqVO.payerContact != null and reqVO.payerContact != ''">
  127. AND t.payer_contact LIKE CONCAT('%', #{reqVO.payerContact}, '%')
  128. </if>
  129. <if test="reqVO.useUnitName != null and reqVO.useUnitName != ''">
  130. AND t.use_unit_name LIKE CONCAT('%', #{reqVO.useUnitName}, '%')
  131. </if>
  132. <if test="reqVO.orderNo != null and reqVO.orderNo != ''">
  133. AND t.order_no LIKE CONCAT('%', #{reqVO.orderNo}, '%')
  134. </if>
  135. <if test="reqVO.followById != null and reqVO.followById != ''">
  136. AND p.creator = #{reqVO.followById}
  137. </if>
  138. <if test="reqVO.isExempt != null and reqVO.isExempt != ''">
  139. AND c.Is_Exempt = #{reqVO.isExempt}
  140. </if>
  141. <if test="reqVO.useUnitId != null">
  142. AND t.use_unit_id = #{reqVO.useUnitId}
  143. </if>
  144. <if test="reqVO.deptId != null and reqVO.deptId != ''">
  145. AND t.dept_id = #{reqVO.deptId}
  146. </if>
  147. <if test="reqVO.equipMainType != null">
  148. AND t.equip_main_type = #{reqVO.equipMainType}
  149. </if>
  150. </select>
  151. </mapper>