ContractProductMapper.xml 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.ContractProductMapper">
  4. <select id="getPage" resultType="com.fjhx.sale.entity.contract.vo.ContractProductVo">
  5. SELECT
  6. t1.id,
  7. t1.contract_id,
  8. t1.product_id,
  9. t2.`code` AS contractCode,
  10. t2.user_name AS userName,
  11. t2.version AS contractVersion,
  12. t1.expend_quantity expendQuantity,
  13. (SELECT create_time FROM claim_contract WHERE contract_id = t2.id ORDER BY create_time DESC LIMIT 1 ) AS claimTime
  14. FROM
  15. contract_product t1
  16. LEFT JOIN contract t2 ON t1.contract_id = t2.id
  17. ${ew.customSqlSegment}
  18. </select>
  19. <select id="getListByIds" resultType="com.fjhx.sale.entity.contract.vo.ContractProductVo">
  20. SELECT
  21. t1.id,
  22. t1.contract_id,
  23. t1.product_id,
  24. t2.`code` AS contractCode,
  25. t2.user_name AS userName,
  26. t2.version AS contractVersion,
  27. t1.expend_quantity expendQuantity
  28. FROM
  29. contract_product t1
  30. LEFT JOIN contract t2 ON t1.contract_id = t2.id
  31. ${ew.customSqlSegment}
  32. </select>
  33. <select id="getNoPackContractProductById" resultType="com.fjhx.sale.entity.contract.vo.ContractProductVo">
  34. SELECT
  35. *
  36. FROM
  37. (
  38. SELECT
  39. t1.*,
  40. t1.`code` AS contractCode,
  41. t2.quantity AS cpQuantity,
  42. t2.id AS contractProductId,
  43. ( SELECT IFNULL( SUM( quantity ), 0 ) FROM pack_detail_product WHERE contract_product_id = t2.id ) AS sumPackQuantity
  44. FROM
  45. contract t1
  46. LEFT JOIN contract_product t2 ON t1.id = t2.contract_id
  47. <where>
  48. <if test="customerId neq null and customerId neq '' ">
  49. buy_corporation_id = #{customerId}
  50. </if>
  51. </where>
  52. ) t1
  53. WHERE t1.sumPackQuantity &lt; t1.cpQuantity
  54. <if test="contractIds neq null and contractIds.size() > 0">
  55. <foreach collection="contractIds" item="contractId" open="AND t1.id IN (" separator="," close=")">
  56. #{contractId}
  57. </foreach>
  58. </if>
  59. </select>
  60. </mapper>