ContractMapper.xml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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.sale.mapper.contract.ContractMapper">
  4. <select id="getPage" resultType="com.fjhx.sale.entity.contract.vo.ContractVo">
  5. SELECT *
  6. FROM
  7. (SELECT
  8. t1.*,
  9. IFNULL(t1.amount,0)*IFNULL(t1.rate,0) AS amountCNY,
  10. CASE
  11. WHEN (t1.amount - t1.sumClaimMoney) &lt;= 0 THEN
  12. 20
  13. WHEN t1.sumClaimMoney = 0 THEN
  14. 0
  15. ELSE 10
  16. END AS refundStatusNew
  17. FROM (SELECT t1.*,
  18. (SELECT IFNULL( SUM(IFNULL(money, 0) * IFNULL(rate,1) ), 0 ) FROM claim_contract
  19. WHERE contract_id = t1.id ) AS sumClaimMoney
  20. FROM contract t1) t1) t1
  21. ${ew.customSqlSegment}
  22. </select>
  23. <select id="getProfitClearingPage" resultType="com.fjhx.sale.entity.contract.vo.ContractBudgetVo">
  24. SELECT t1.id AS contractId,
  25. t1.*
  26. FROM contract t1
  27. ${ew.customSqlSegment}
  28. </select>
  29. <select id="getProfitBudgetPage" resultType="com.fjhx.sale.entity.contract.vo.ContractBudgetVo">
  30. SELECT
  31. (select GROUP_CONCAT(id) from contract_product WHERE contract_id = t1.id) AS contractProductIds,
  32. t1.id AS contractId,
  33. t1.`code`,
  34. t1.buy_corporation_id ,
  35. t1.user_name,
  36. t1.amount,
  37. t1.currency,
  38. t1.currency_rate_json,
  39. t2.*
  40. FROM
  41. contract t1
  42. LEFT JOIN contract_budget t2 ON t1.id = t2.contract_id
  43. ${ew.customSqlSegment}
  44. </select>
  45. <select id="getNoPackContractByCustomerId" resultType="com.fjhx.sale.entity.contract.vo.ContractVo">
  46. SELECT
  47. *
  48. FROM
  49. (
  50. SELECT
  51. t1.*,
  52. t2.quantity AS cpQuantity,
  53. ( SELECT IFNULL( SUM( quantity ), 0 ) FROM pack_detail_product WHERE contract_product_id = t2.id ) AS sumPackQuantity
  54. FROM
  55. contract t1
  56. LEFT JOIN contract_product t2 ON t1.id = t2.contract_id
  57. <where>
  58. <if test="customerId neq null and customerId neq '' ">
  59. buy_corporation_id = #{customerId}
  60. </if>
  61. </where>
  62. ) t1
  63. WHERE t1.sumPackQuantity &lt; t1.cpQuantity
  64. AND t1.`status`=30
  65. GROUP BY t1.id
  66. </select>
  67. <select id="getSalesTotal" resultType="com.fjhx.sale.entity.contract.vo.ContractVo">
  68. SELECT
  69. SUM(amount) amount,
  70. currency,
  71. count(*) contractCount
  72. FROM
  73. contract
  74. WHERE
  75. buy_corporation_id = #{id} and status = 30 and del_flag = 0
  76. GROUP BY
  77. buy_corporation_id
  78. </select>
  79. <select id="getAmount" resultType="com.fjhx.sale.entity.contract.vo.ContractVo">
  80. SELECT
  81. SUM(amount) amount,
  82. DATE_FORMAT(create_time,'%Y-%m') time
  83. FROM
  84. contract
  85. WHERE
  86. buy_corporation_id = #{id}
  87. and (DATE_FORMAT(create_time,'%Y-%m') >= #{beginTime} and #{endTime} >= DATE_FORMAT(create_time,'%Y-%m'))
  88. GROUP BY
  89. TIME
  90. </select>
  91. <select id="contractStatistics" resultType="com.fjhx.sale.entity.sale.vo.SaleQuotationVo">
  92. SELECT
  93. COUNT(*) count,
  94. ifnull(c.`status`,-1) status,
  95. ifnull(DATE_FORMAT(sq.create_time,'%Y-%m'),-1) time
  96. FROM
  97. bytesailing_customer.customer c
  98. left JOIN contract sq ON sq.buy_corporation_id = c.id
  99. ${ew.customSqlSegment}
  100. </select>
  101. <select id="countrySalesStatistics" resultType="com.fjhx.sale.entity.contract.dto.ContractDto">
  102. SELECT
  103. sum(cc.amount) amount,
  104. COUNT(cc.buy_country_id) count,
  105. ai.name countryName
  106. FROM
  107. contract cc
  108. LEFT JOIN bytesailing_base.customize_area ai ON cc.buy_country_id = ai.id
  109. ${ew.customSqlSegment}
  110. </select>
  111. <select id="customSalesStatistics" resultType="com.fjhx.sale.entity.contract.dto.ContractDto">
  112. SELECT
  113. sum(cc.amount) amount,
  114. bc.name corporationName
  115. FROM
  116. contract cc
  117. LEFT JOIN bytesailing_customer.customer bc ON cc.buy_corporation_id = bc.id
  118. ${ew.customSqlSegment}
  119. </select>
  120. <select id="salesmanSalesStatistics" resultType="com.fjhx.sale.entity.contract.dto.ContractDto">
  121. SELECT
  122. SUM(cc.amount) amount,
  123. su.nick_name userName
  124. FROM
  125. contract cc
  126. LEFT JOIN bytesailing_base.sys_user su ON cc.create_user = su.user_id
  127. ${ew.customSqlSegment}
  128. </select>
  129. <select id="productSalesStatistics" resultType="com.fjhx.sale.entity.contract.dto.ContractDto">
  130. SELECT
  131. SUM(cp.amount) amount,
  132. pi.name productName
  133. FROM
  134. contract_product cp
  135. LEFT JOIN bytesailing_item.product_info pi ON cp.product_id = pi.id
  136. ${ew.customSqlSegment}
  137. </select>
  138. <select id="salesVolumeStatistics" resultType="com.fjhx.sale.entity.contract.dto.ContractDto">
  139. SELECT SUM(cp.quantity) quantity,
  140. pi.name productName
  141. FROM contract_product cp
  142. LEFT JOIN bytesailing_item.product_info pi ON cp.product_id = pi.id
  143. ${ew.customSqlSegment}
  144. </select>
  145. <select id="getAccountRunningWaterByContractId"
  146. resultType="com.fjhx.account.entity.account.vo.AccountRunningWaterVo">
  147. SELECT arw.id,
  148. arw.create_time,
  149. ap.type,
  150. arw.currency,
  151. arw.amount,
  152. arw.remarks,
  153. am.`name` accountManagementName,
  154. am.account_opening accountManagementOpening,
  155. arw.`name`
  156. FROM contract c
  157. JOIN bytesailing_purchase.purchase p ON p.data_resource_id = c.id
  158. JOIN bytesailing_purchase.pay_detail pad
  159. ON pad.purchase_id = p.id
  160. JOIN bytesailing_purchase.pay pa ON pad.pay_id = pa.id
  161. JOIN bytesailing_account.account_payment ap ON ap.business_id = pa.id
  162. JOIN bytesailing_account.account_running_water arw ON arw.business_id = ap.id
  163. LEFT JOIN bytesailing_account.account_management am ON arw.account_management_id = am.id
  164. WHERE
  165. c.id = #{contractId}
  166. UNION ALL
  167. SELECT arw.id,
  168. arw.create_time,
  169. ap.type,
  170. arw.currency,
  171. arw.amount,
  172. arw.remarks,
  173. am.`name` accountManagementName,
  174. am.account_opening accountManagementOpening,
  175. arw.`name`
  176. FROM contract c
  177. JOIN bytesailing_account.account_request_funds_detail arfd ON arfd.contract_id = c.id
  178. JOIN bytesailing_account.account_payment ap ON ap.business_id = arfd.account_request_funds_id
  179. JOIN bytesailing_account.account_running_water arw ON arw.business_id = ap.id
  180. LEFT JOIN bytesailing_account.account_management am ON arw.account_management_id = am.id
  181. WHERE c.id = #{contractId}
  182. UNION ALL
  183. SELECT arw.id,
  184. arw.create_time,
  185. 30 type,
  186. arw.currency,
  187. clc.money,
  188. arw.remarks,
  189. am.`name` accountManagementName,
  190. am.account_opening accountManagementOpening,
  191. arw.`name`
  192. FROM bytesailing_account.account_running_water arw
  193. JOIN claim cl ON cl.business_id = arw.id
  194. JOIN claim_contract clc ON clc.claim_id = cl.id
  195. JOIN contract c ON clc.contract_id = c.id
  196. LEFT JOIN bytesailing_account.account_management am ON arw.account_management_id = am.id
  197. WHERE c.id = #{contractId}
  198. </select>
  199. </mapper>