ContractsMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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="cn.com.ty.lift.business.contract.dao.mapper.ContractsMapper">
  4. <resultMap id="BaseResultMap" type="cn.com.ty.lift.business.contract.dao.entity.Contracts">
  5. <id column="id" property="id" jdbcType="BIGINT"/>
  6. <!--这个地方要关联查询-->
  7. <result column="project_id" property="projectId" jdbcType="BIGINT"/>
  8. <result column="mt_company_id" property="mtCompanyId" jdbcType="BIGINT"/>
  9. <!--合同自定义id-->
  10. <result column="code" property="code" jdbcType="VARCHAR"/>
  11. <result column="source" property="source" jdbcType="INTEGER"/>
  12. <result column="pay_mode" property="payMode" jdbcType="VARCHAR"/>
  13. <result column="lift_num" property="liftNum" jdbcType="INTEGER"/>
  14. <result column="moneys" property="moneys" jdbcType="DECIMAL"/>
  15. <!--应收金额-->
  16. <result column="plan_money_total" property="planMoneyTotal" jdbcType="DECIMAL"/>
  17. <!--实收-->
  18. <result column="work_money_total" property="workMoneyTotal" jdbcType="DECIMAL"/>
  19. <!--开票金额-->
  20. <result column="invoice_money_total" property="invoiceMoneyTotal" jdbcType="DECIMAL"/>
  21. <result column="type" property="type" jdbcType="INTEGER"/>
  22. <result column="status" property="status" jdbcType="INTEGER"/>
  23. <result column="given_date" property="givenDate" jdbcType="TIMESTAMP"/>
  24. <result column="given_user" property="givenUser" jdbcType="VARCHAR"/>
  25. <result column="star_date" property="starDate" jdbcType="TIMESTAMP"/>
  26. <result column="end_date" property="endDate" jdbcType="TIMESTAMP"/>
  27. <result column="create_date" property="createDate" jdbcType="TIMESTAMP"/>
  28. <result column="next_id" property="nextId" jdbcType="BIGINT"/>
  29. <result column="accessory_url" property="accessoryUrl" jdbcType="LONGVARCHAR"/>
  30. <result column="end_reason" property="endReason" jdbcType="LONGVARCHAR"/>
  31. <!--新增开始-->
  32. <result column="parts_rules" property="partsRules" jdbcType="LONGVARCHAR"/>
  33. <!--新增结束-->
  34. <result column="remarks" property="remarks" jdbcType="LONGVARCHAR"/>
  35. <result column="previous_id" property="previousId" jdbcType="BIGINT"/>
  36. </resultMap>
  37. <sql id="Base_Column_List">
  38. id, project_id, mt_company_id, code, source, pay_mode, lift_num, moneys, type, status,
  39. given_date, given_user, star_date, end_date, create_date, next_id, previous_id, accessory_url, end_reason, remarks,
  40. parts_rules
  41. </sql>
  42. <!-- 根据项目、合同号、合同类型、合同状态查询合同管理列表-->
  43. <select id="findByCondition"
  44. resultType="cn.com.ty.lift.business.contract.dao.entity.model.response.ContractResponse"
  45. parameterType="cn.com.ty.lift.business.contract.dao.entity.model.request.ContractRequest">
  46. SELECT
  47. c.id AS id,
  48. c.code AS contractCode,
  49. c.next_id AS nextId,
  50. c.source AS contractSource,
  51. c.type AS contractType,
  52. c.star_date AS starDate,
  53. c.end_date AS endDate,
  54. c.lift_num AS liftNum,
  55. c.moneys AS moneys,
  56. c.given_date AS givenDate,
  57. c.given_user AS givenUser,
  58. c.accessory_url AS accessoryUrl,
  59. c.remarks AS remarks,
  60. c.parts_rules AS partsRules,
  61. c.status AS contractStatus,
  62. p.project_name AS projectName,
  63. c.is_check AS isCheck
  64. FROM contracts c
  65. LEFT JOIN project p ON c.project_id = p.id
  66. WHERE c.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  67. <if test="request.contractCode!=null and request.contractCode!=''">
  68. AND c.code LIKE CONCAT('%',#{request.contractCode,jdbcType=VARCHAR},'%')
  69. </if>
  70. <if test="request.contractType!=null and request.contractType!=''">
  71. AND c.type = #{request.contractType,jdbcType=INTEGER}
  72. </if>
  73. <if test="request.contractStatus!=null and request.contractStatus!=''">
  74. AND c.status = #{request.contractStatus,jdbcType=INTEGER}
  75. </if>
  76. <if test="request.projectName!=null and request.projectName!=''">
  77. AND p.project_name LIKE CONCAT('%',#{request.projectName,jdbcType=VARCHAR},'%')
  78. </if>
  79. <!--新增时间搜索-->
  80. <!--开始时间-->
  81. <if test="request.starDate!=null and request.starDate!=''">
  82. AND c.star_date >=#{request.starDate}
  83. </if>
  84. <!--结束时间-->
  85. <if test="request.endDate!=null and request.endDate!=''">
  86. AND c.end_date >=#{request.endDate}
  87. </if>
  88. </select>
  89. <select id="findAllContracts"
  90. parameterType="cn.com.ty.lift.business.contract.dao.entity.model.request.ContractRequest"
  91. resultType="cn.com.ty.lift.business.contract.dao.entity.model.response.ContractExportDto">
  92. select
  93. <!--合同编号-->
  94. c.code as contractCode,
  95. <!--客户名称-->
  96. (select name from property_company where id=p.pp_company_id) as memberName,
  97. <!--收款类型-->
  98. case when pay.type = 1 then '维保费' else '大修费' end as payType,
  99. <!--收款编号-->
  100. pay.code as paycode,
  101. <!--项目名称-->
  102. p.project_name as projectName,
  103. <!--项目内容-->
  104. CONCAT(c.lift_num,'台',case when pay.periods = '' or pay.periods is null then '1' else pay.periods
  105. end,'期',p.start_date,'至',p.end_date) as projectContent,
  106. <!--本期应收-->
  107. pay.plan_money as nowMoney,
  108. <!--合同金额-->
  109. c.moneys as moneys,
  110. <!--应收日期-->
  111. pay.plan_date as planDate,
  112. <!--期数-->
  113. pay.periods as periods,
  114. <!--收款责任人-->
  115. pay.collection_man as collectionMan,
  116. <!--区域-->
  117. (select area_name from region where region.id=p.region_id) as regionName,
  118. <!--帐龄-->
  119. pay.work_date - pay.plan_date as paymentDays,
  120. <!--开票金额-->
  121. pay.amount_invoice as amountInvoice,
  122. <!--开票时间-->
  123. pay.billing_date as billingDate,
  124. <!--发票类型-->
  125. pay.invoice_type as invoiceType,
  126. <!--到账日期-->
  127. pay.work_date as workDate,
  128. <!--实收金额-->
  129. pay.work_money as workMoney
  130. <!--表关联-->
  131. from project p
  132. LEFT JOIN
  133. contracts c on c.project_id=p.id
  134. left join payment pay on pay.contracts_id=c.id
  135. <!--筛选条件-->
  136. WHERE c.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  137. <if test="request.contractCode!=null and request.contractCode!=''">
  138. AND c.code LIKE CONCAT('%',#{request.contractCode,jdbcType=VARCHAR},'%')
  139. </if>
  140. <if test="request.contractType!=null and request.contractType!=''">
  141. AND c.type = #{request.contractType,jdbcType=INTEGER}
  142. </if>
  143. <if test="request.contractStatus!=null and request.contractStatus!=''">
  144. AND c.status = #{request.contractStatus,jdbcType=INTEGER}
  145. </if>
  146. <if test="request.projectName!=null and request.projectName!=''">
  147. AND p.project_name LIKE CONCAT('%',#{request.projectName,jdbcType=VARCHAR},'%')
  148. </if>
  149. <!--新增时间搜索-->
  150. <!--开始时间-->
  151. <if test="request.starDate!=null and request.starDate!=''">
  152. AND c.star_date >=#{request.starDate}
  153. </if>
  154. <!--结束时间-->
  155. <if test="request.endDate!=null and request.endDate!=''">
  156. AND c.end_date >=#{request.endDate}
  157. </if>
  158. </select>
  159. <select id="findAllErContracts"
  160. parameterType="cn.com.ty.lift.business.contract.dao.entity.model.request.ContractRequest"
  161. resultType="cn.com.ty.lift.business.contract.dao.entity.model.response.ContractExportDto">
  162. select
  163. <!--合同编号-->
  164. c.code as contractCode,
  165. <!--客户名称-->
  166. (select name from property_company where id=p.pp_company_id) as memberName,
  167. <!--收款类型 默认T修理-->
  168. CONCAT('T修理')as payType,
  169. <!--收款编号 无-->
  170. <!--项目名称-->
  171. p.project_name as projectName,
  172. <!--项目内容-->
  173. CONCAT(p.project_name,emr.caller_fault_description) as projectContent,
  174. <!--本期应收-->
  175. erc.cost_money as nowMoney,
  176. <!--合同金额-->
  177. c.moneys as moneys,
  178. <!--应收日期-->
  179. erc.cost_date as planDate,
  180. <!--期数-->
  181. <!--收款责任人-->
  182. erc.collection_man as collectionMan,
  183. <!--区域-->
  184. (select area_name from region where region.id=p.region_id) as regionName,
  185. <!--帐龄-->
  186. erc.pay_date - erc.cost_date as paymentDays,
  187. <!--开票金额-->
  188. erc.invoice_money as amountInvoice,
  189. <!--开票时间-->
  190. erc.invoice_date as billingDate,
  191. <!--发票类型-->
  192. erc.invoice_type as invoiceType,
  193. <!--到账时间-->
  194. erc.pay_date as workDate,
  195. <!--到账金额-->
  196. erc.pay_money as workMoney
  197. <!--表关联-->
  198. from er_record_cost erc
  199. LEFT JOIN emergency_repair emr on erc.er_record_id=emr.id
  200. LEFT JOIN project p on emr.project_id=p.id
  201. left join contracts c on c.project_id=p.id
  202. <!--筛选条件-->
  203. WHERE c.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  204. <if test="request.contractCode!=null and request.contractCode!=''">
  205. AND c.code LIKE CONCAT('%',#{request.contractCode,jdbcType=VARCHAR},'%')
  206. </if>
  207. <if test="request.contractType!=null and request.contractType!=''">
  208. AND c.type = #{request.contractType,jdbcType=INTEGER}
  209. </if>
  210. <if test="request.contractStatus!=null and request.contractStatus!=''">
  211. AND c.status = #{request.contractStatus,jdbcType=INTEGER}
  212. </if>
  213. <if test="request.projectName!=null and request.projectName!=''">
  214. AND p.project_name LIKE CONCAT('%',#{request.projectName,jdbcType=VARCHAR},'%')
  215. </if>
  216. <!--新增时间搜索-->
  217. <!--开始时间-->
  218. <if test="request.starDate!=null and request.starDate!=''">
  219. AND c.star_date >=#{request.starDate}
  220. </if>
  221. <!--结束时间-->
  222. <if test="request.endDate!=null and request.endDate!=''">
  223. AND c.end_date >=#{request.endDate}
  224. </if>
  225. </select>
  226. <!--导出合同管理数据-大修/维保数据-->
  227. <select id="findAllContractsManageData"
  228. parameterType="cn.com.ty.lift.business.contract.dao.entity.model.request.ContractRequest"
  229. resultType="cn.com.ty.lift.business.contract.dao.entity.model.response.ContractManageExportDto">
  230. select
  231. <!--项目名称-->
  232. p.project_name as projectName,
  233. <!--客户名称-->
  234. (select name from property_company where id=p.pp_company_id) as memberName,
  235. <!--区域-->
  236. (select area_name from region where region.id=p.region_id) as regionName,
  237. <!--合同编号-->
  238. c.code as contractCode,
  239. <!--合同来源-->
  240. case c.source when 1 then '商保新增' when 2 then '免保转签' when 3 then '续签' when 4 then '免保' else '暂无' end,
  241. <!--合同类型-->
  242. case c.type when 1 then '半包' when 2 then '半包' when 3 then '清包' when 4 then '全包' when 5 then '大修' else '暂无' end,
  243. <!--合同开始时间-->
  244. c.star_date as starDate,
  245. <!--合同结束时间-->
  246. c.end_date as endDate,
  247. <!--台量-->
  248. c.lift_num as liftNum,
  249. <!--合同金额-->
  250. c.moneys as moneys,
  251. <!--签约时间-->
  252. c.given_date as givenDate,
  253. <!--签约人-->
  254. c.given_user as givenUser,
  255. <!--实收金额-->
  256. pay.work_money as workMoney
  257. <!--未收-->
  258. pay.plan_money - pay.work_money as NoPayMoney,
  259. <!--配件条款-->
  260. c.parts_rules as partsRules
  261. <!--表关联-->
  262. from project p
  263. LEFT JOIN
  264. contracts c on c.project_id=p.id
  265. left join payment pay on pay.contracts_id=c.id
  266. <!--筛选条件-->
  267. WHERE c.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  268. <if test="request.contractCode!=null and request.contractCode!=''">
  269. AND c.code LIKE CONCAT('%',#{request.contractCode,jdbcType=VARCHAR},'%')
  270. </if>
  271. <if test="request.contractType!=null and request.contractType!=''">
  272. AND c.type = #{request.contractType,jdbcType=INTEGER}
  273. </if>
  274. <if test="request.contractStatus!=null and request.contractStatus!=''">
  275. AND c.status = #{request.contractStatus,jdbcType=INTEGER}
  276. </if>
  277. <if test="request.projectName!=null and request.projectName!=''">
  278. AND p.project_name LIKE CONCAT('%',#{request.projectName,jdbcType=VARCHAR},'%')
  279. </if>
  280. <!--新增时间搜索-->
  281. <!--开始时间-->
  282. <if test="request.starDate!=null and request.starDate!=''">
  283. AND c.star_date >=#{request.starDate}
  284. </if>
  285. <!--结束时间-->
  286. <if test="request.endDate!=null and request.endDate!=''">
  287. AND c.end_date >=#{request.endDate}
  288. </if>
  289. </select>
  290. <!--急修合同合同数据-->
  291. <select id="findAllErContractsManageData"
  292. parameterType="cn.com.ty.lift.business.contract.dao.entity.model.request.ContractRequest"
  293. resultType="cn.com.ty.lift.business.contract.dao.entity.model.response.ContractManageExportDto">
  294. select
  295. <!--项目名称-->
  296. p.project_name as projectName,
  297. <!--客户名称-->
  298. (select name from property_company where id=p.pp_company_id) as memberName,
  299. <!--区域-->
  300. (select area_name from region where region.id=p.region_id) as regionName,
  301. <!--合同编号-->
  302. c.code as contractCode,
  303. <!--合同来源-->
  304. case c.source when 1 then '商保新增' when 2 then '免保转签' when 3 then '续签' when 4 then '免保' else '暂无' end,
  305. <!--合同类型-->
  306. case c.type when 1 then '半包' when 2 then '半包' when 3 then '清包' when 4 then '全包' when 5 then '大修' else '暂无' end,
  307. <!--合同开始时间-->
  308. c.star_date as starDate,
  309. <!--合同结束时间-->
  310. c.end_date as endDate,
  311. <!--台量-->
  312. c.lift_num as liftNum,
  313. <!--合同金额-->
  314. c.moneys as moneys,
  315. <!--签约时间-->
  316. c.given_date as givenDate,
  317. <!--签约人-->
  318. c.given_user as givenUser,
  319. <!--到账金额-->
  320. erc.pay_money as workMoney
  321. <!--未收-->
  322. erc.cost_money - erc.pay_money as NoPayMoney,
  323. <!--配件条款-->
  324. c.parts_rules as partsRules
  325. <!--表关联-->
  326. from er_record_cost erc
  327. LEFT JOIN emergency_repair emr on erc.er_record_id=emr.id
  328. LEFT JOIN project p on emr.project_id=p.id
  329. left join contracts c on c.project_id=p.id
  330. <!--筛选条件-->
  331. WHERE c.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  332. <if test="request.contractCode!=null and request.contractCode!=''">
  333. AND c.code LIKE CONCAT('%',#{request.contractCode,jdbcType=VARCHAR},'%')
  334. </if>
  335. <if test="request.contractType!=null and request.contractType!=''">
  336. AND c.type = #{request.contractType,jdbcType=INTEGER}
  337. </if>
  338. <if test="request.contractStatus!=null and request.contractStatus!=''">
  339. AND c.status = #{request.contractStatus,jdbcType=INTEGER}
  340. </if>
  341. <if test="request.projectName!=null and request.projectName!=''">
  342. AND p.project_name LIKE CONCAT('%',#{request.projectName,jdbcType=VARCHAR},'%')
  343. </if>
  344. <!--新增时间搜索-->
  345. <!--开始时间-->
  346. <if test="request.starDate!=null and request.starDate!=''">
  347. AND c.star_date >=#{request.starDate}
  348. </if>
  349. <!--结束时间-->
  350. <if test="request.endDate!=null and request.endDate!=''">
  351. AND c.end_date >=#{request.endDate}
  352. </if>
  353. </select>
  354. </mapper>