ContractMapper.xml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.management.platform.mapper.ContractMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.management.platform.entity.Contract">
  6. <id column="id" property="id" />
  7. <result column="company_id" property="companyId" />
  8. <result column="creator_id" property="creatorId" />
  9. <result column="start_date" property="startDate" />
  10. <result column="end_date" property="endDate" />
  11. <result column="number" property="number" />
  12. <result column="project_id" property="projectId" />
  13. <result column="name" property="name" />
  14. <result column="amounts" property="amounts" />
  15. <result column="type_id" property="typeId" />
  16. <result column="checkerId" property="checkerId" />
  17. <result column="status" property="status" />
  18. <result column="indate" property="indate" />
  19. <result column="remarks" property="remarks" />
  20. <result column="payment" property="payment" />
  21. </resultMap>
  22. <!-- 通用查询结果列 -->
  23. <sql id="Base_Column_List">
  24. id, company_id, creator_id, start_date, end_date, number, project_id, name, amounts, type_id, checkerId, status, indate, remarks, payment
  25. </sql>
  26. <select id="selectContract" resultType="com.management.platform.entity.Contract">
  27. select contract.id,contract.company_id,contract.creator_id,contract.number,contract.name,contract.amounts,contract.type_id,contract_type.type_name,contract.status,contract.indate,contract.remarks,
  28. contract.start_date as startDate,contract.end_date as endDate,
  29. user.name as creatorName,user.corpwx_userid as creatorWxCorpId, contract.project_id, contract.payment, cp.pay_date AS next_payment_date, cp.amount AS next_payment_amount
  30. from contract
  31. left join contract_type
  32. on contract.type_id = contract_type.id
  33. LEFT JOIN (SELECT contract_id, pay_date, amount FROM contract_payment WHERE is_payed = 0 GROUP BY contract_id) cp ON cp.contract_id=contract.id
  34. left join user
  35. on contract.creator_id = user.id
  36. where contract.company_id = #{companyId}
  37. <if test="number!=null">
  38. and number like #{number}
  39. </if>
  40. <if test="name!=null">
  41. and contract.name like #{name}
  42. </if>
  43. <if test="typeName!=null">
  44. and contract_type.id = #{typeName}
  45. </if>
  46. <if test="status!=null">
  47. and status = #{status}
  48. </if>
  49. <if test="startDate!=null and endDate !=null">
  50. and indate between #{startDate} and #{endDate}
  51. </if>
  52. <if test="paymentStartDate != null and paymentEndDate != null">
  53. and cp.pay_date between #{paymentStartDate} and #{paymentEndDate}
  54. </if>
  55. order by contract.id desc
  56. <if test="pageStart!=null and pageSize!=null">
  57. limit #{pageStart},#{pageSize}
  58. </if>
  59. </select>
  60. <select id="selectContractCnt" resultType="java.lang.Long">
  61. select count(1) from contract
  62. left join contract_type
  63. on contract.type_id = contract_type.id
  64. LEFT JOIN (SELECT contract_id, pay_date, amount FROM contract_payment WHERE is_payed = 0 GROUP BY contract_id) cp ON cp.contract_id=contract.id
  65. left join user
  66. on contract.creator_id = user.id
  67. where contract.company_id = #{companyId}
  68. <if test="number!=null">
  69. and number like #{number}
  70. </if>
  71. <if test="name!=null">
  72. and contract.name like #{name}
  73. </if>
  74. <if test="typeName!=null">
  75. and contract_type.id = #{typeName}
  76. </if>
  77. <if test="status!=null">
  78. and status = #{status}
  79. </if>
  80. <if test="startDate!=null and endDate !=null">
  81. and indate between #{startDate} and #{endDate}
  82. </if>
  83. <if test="paymentStartDate != null and paymentEndDate != null">
  84. and cp.pay_date between #{paymentStartDate} and #{paymentEndDate}
  85. </if>
  86. </select>
  87. </mapper>