ContractMapper.xml 12 KB

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