ContractMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. <result column="sec_type_id" property="secTypeId" />
  22. <result column="department_id" property="departmentId" />
  23. </resultMap>
  24. <!-- 通用查询结果列 -->
  25. <sql id="Base_Column_List">
  26. id, company_id, creator_id, start_date, end_date, number, project_id, name, amounts, type_id, checkerId, status, indate, remarks, payment, sec_type_id
  27. </sql>
  28. <select id="selectContract" resultType="com.management.platform.entity.Contract">
  29. select contract.id,contract.company_id,contract.creator_id,contract.number,contract.name,contract.amounts,contract.type_id,sys_dict.name typeName,contract.status,contract.indate,contract.remarks,
  30. contract.start_date as startDate,contract.end_date as endDate,contract_type_sec.sec_type_name,contract.sec_type_id,
  31. 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,
  32. contract.plate1,contract.plate2,contract.plate3,contract.plate4,contract.plate5,contract.need_pin,contract.pin_time,contract.department_id
  33. from contract
  34. left join sys_dict on contract.type_id = sys_dict.id
  35. left join contract_type_sec on contract.sec_type_id = contract_type_sec.id
  36. 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
  37. left join user
  38. on contract.creator_id = user.id
  39. left join contract_custom cc on cc.contract_id=contract.id
  40. where contract.company_id = #{companyId}
  41. <if test="number!=null">
  42. and number like CONCAT('%', #{number}, '%')
  43. </if>
  44. <if test="name!=null">
  45. and contract.name like CONCAT('%', #{name}, '%')
  46. </if>
  47. <if test="typeName!=null">
  48. and sys_dict.name = #{typeName}
  49. </if>
  50. <if test="secTypeId!=null">
  51. and contract.sec_type_id = #{secTypeId}
  52. </if>
  53. <if test="status!=null">
  54. and status = #{status}
  55. </if>
  56. <if test="startDate!=null and endDate !=null">
  57. and indate between #{startDate} and #{endDate}
  58. </if>
  59. <if test="paymentStartDate != null and paymentEndDate != null">
  60. and cp.pay_date between #{paymentStartDate} and #{paymentEndDate}
  61. </if>
  62. <if test="finishStatus!=null">
  63. and cc.finish_status = #{finishStatus}
  64. </if>
  65. <if test="customerOrg!=null">
  66. and cc.customer_org like CONCAT('%', #{customerOrg}, '%')
  67. </if>
  68. order by contract.id desc
  69. <if test="pageStart!=null and pageSize!=null">
  70. limit #{pageStart},#{pageSize}
  71. </if>
  72. </select>
  73. <select id="selectContractCnt" resultType="java.lang.Long">
  74. select count(1) from contract
  75. left join contract_type
  76. on contract.type_id = contract_type.id
  77. 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
  78. left join user
  79. on contract.creator_id = user.id
  80. left join contract_custom cc on cc.contract_id=contract.id
  81. where contract.company_id = #{companyId}
  82. <if test="number!=null">
  83. and number like CONCAT('%', #{number}, '%')
  84. </if>
  85. <if test="name!=null">
  86. and contract.name like CONCAT('%', #{name}, '%')
  87. </if>
  88. <if test="typeName!=null">
  89. and contract_type.id = #{typeName}
  90. </if>
  91. <if test="secTypeId!=null">
  92. and contract.sec_type_id = #{secTypeId}
  93. </if>
  94. <if test="status!=null">
  95. and status = #{status}
  96. </if>
  97. <if test="startDate!=null and endDate !=null">
  98. and indate between #{startDate} and #{endDate}
  99. </if>
  100. <if test="paymentStartDate != null and paymentEndDate != null">
  101. and cp.pay_date between #{paymentStartDate} and #{paymentEndDate}
  102. </if>
  103. <if test="finishStatus!=null">
  104. and cc.finish_status = #{finishStatus}
  105. </if>
  106. <if test="customerOrg!=null">
  107. and cc.customer_org like CONCAT('%', #{customerOrg}, '%')
  108. </if>
  109. </select>
  110. <select id="selectContractByPin" resultType="com.management.platform.entity.Contract">
  111. select contract.id,contract.company_id,contract.creator_id,contract.number,contract.name,contract.amounts,contract.type_id,sys_dict.name typeName,contract.status,contract.indate,contract.remarks,
  112. contract.start_date as startDate,contract.end_date as endDate,contract_type_sec.sec_type_name,contract.sec_type_id,
  113. 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,
  114. contract.plate1,contract.plate2,contract.plate3,contract.plate4,contract.plate5,contract.need_pin,contract.pin_time
  115. from contract
  116. left join sys_dict on contract.type_id = sys_dict.id
  117. left join contract_type_sec on contract.sec_type_id = contract_type_sec.id
  118. 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
  119. left join user
  120. on contract.creator_id = user.id
  121. left join contract_custom cc on cc.contract_id=contract.id
  122. where contract.company_id = #{companyId}
  123. <if test="number!=null">
  124. and number like CONCAT('%', #{number}, '%')
  125. </if>
  126. <if test="name!=null">
  127. and contract.name like CONCAT('%', #{name}, '%')
  128. </if>
  129. <if test="typeName!=null">
  130. and sys_dict.name = #{typeName}
  131. </if>
  132. <if test="secTypeId!=null">
  133. and contract.sec_type_id = #{secTypeId}
  134. </if>
  135. <if test="status!=null">
  136. and status = #{status}
  137. </if>
  138. <if test="startDate!=null and endDate !=null">
  139. and indate between #{startDate} and #{endDate}
  140. </if>
  141. <if test="paymentStartDate != null and paymentEndDate != null">
  142. and cp.pay_date between #{paymentStartDate} and #{paymentEndDate}
  143. </if>
  144. <if test="finishStatus!=null">
  145. and cc.finish_status = #{finishStatus}
  146. </if>
  147. <if test="customerOrg!=null">
  148. and cc.customer_org like CONCAT('%', #{customerOrg}, '%')
  149. </if>
  150. order by contract.need_pin desc,contract.pin_time desc,contract.id desc
  151. <if test="pageStart!=null and pageSize!=null">
  152. limit #{pageStart},#{pageSize}
  153. </if>
  154. </select>
  155. <select id="selectContractWithType" resultType="com.management.platform.entity.Contract">
  156. select contract.id,contract.company_id,contract.creator_id,contract.number,contract.name,contract.amounts,contract.type_id,sys_dict.name typeName,contract.status,contract.indate,contract.remarks,
  157. contract.start_date as startDate,contract.end_date as endDate,contract_type_sec.sec_type_name,contract.sec_type_id,
  158. 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,
  159. contract.plate1,contract.plate2,contract.plate3,contract.plate4,contract.plate5,contract.need_pin,contract.pin_time,contract.department_id,d.department_name as departmentName
  160. from contract
  161. left join sys_dict on contract.type_id = sys_dict.id
  162. left join contract_type_sec on contract.sec_type_id = contract_type_sec.id
  163. 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
  164. left join user
  165. on contract.creator_id = user.id
  166. left join contract_custom cc on cc.contract_id=contract.id
  167. left join department d on d.department_id=contract.department_id
  168. where contract.company_id = #{companyId}
  169. <if test="number!=null">
  170. and number like CONCAT('%', #{number}, '%')
  171. </if>
  172. <if test="name!=null">
  173. and contract.name like CONCAT('%', #{name}, '%')
  174. </if>
  175. <if test="typeName!=null">
  176. and sys_dict.name = #{typeName}
  177. </if>
  178. <if test="secTypeId!=null">
  179. and contract.sec_type_id = #{secTypeId}
  180. </if>
  181. <if test="status!=null">
  182. and status = #{status}
  183. </if>
  184. <if test="startDate!=null and endDate !=null">
  185. and indate between #{startDate} and #{endDate}
  186. </if>
  187. <if test="paymentStartDate != null and paymentEndDate != null">
  188. and cp.pay_date between #{paymentStartDate} and #{paymentEndDate}
  189. </if>
  190. <if test="finishStatus!=null">
  191. and cc.finish_status = #{finishStatus}
  192. </if>
  193. <if test="customerOrg!=null">
  194. and cc.customer_org like CONCAT('%', #{customerOrg}, '%')
  195. </if>
  196. <if test="type == 2 and dept!=null">
  197. and contract.department_id=#{dept}
  198. </if>
  199. <if test="type == 3 and userId!=null">
  200. and contract.creator_id=#{userId}
  201. </if>
  202. order by contract.id desc
  203. <if test="pageStart!=null and pageSize!=null">
  204. limit #{pageStart},#{pageSize}
  205. </if>
  206. </select>
  207. <select id="selectContractCntWithType" resultType="java.lang.Long">
  208. select count(1) from contract
  209. left join contract_type
  210. on contract.type_id = contract_type.id
  211. 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
  212. left join user
  213. on contract.creator_id = user.id
  214. left join contract_custom cc on cc.contract_id=contract.id
  215. left join department d on d.department_id=contract.department_id
  216. where contract.company_id = #{companyId}
  217. <if test="number!=null">
  218. and number like CONCAT('%', #{number}, '%')
  219. </if>
  220. <if test="name!=null">
  221. and contract.name like CONCAT('%', #{name}, '%')
  222. </if>
  223. <if test="typeName!=null">
  224. and contract_type.id = #{typeName}
  225. </if>
  226. <if test="secTypeId!=null">
  227. and contract.sec_type_id = #{secTypeId}
  228. </if>
  229. <if test="status!=null">
  230. and status = #{status}
  231. </if>
  232. <if test="startDate!=null and endDate !=null">
  233. and indate between #{startDate} and #{endDate}
  234. </if>
  235. <if test="paymentStartDate != null and paymentEndDate != null">
  236. and cp.pay_date between #{paymentStartDate} and #{paymentEndDate}
  237. </if>
  238. <if test="finishStatus!=null">
  239. and cc.finish_status = #{finishStatus}
  240. </if>
  241. <if test="customerOrg!=null">
  242. and cc.customer_org like CONCAT('%', #{customerOrg}, '%')
  243. </if>
  244. <if test="type == 2 and dept!=null">
  245. and contract.department_id=#{dept}
  246. </if>
  247. <if test="type == 3 and userId!=null">
  248. and contract.creator_id=#{userId}
  249. </if>
  250. </select>
  251. </mapper>