综合办公系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CmcContractMapper.xml 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ruoyi.oa.mapper.CmcContractMapper">
  6. <resultMap type="CmcContract" id="CmcContractResult">
  7. <result property="contractId" column="contract_id" />
  8. <result property="contractName" column="contract_name" />
  9. <result property="contractCode" column="contract_code" />
  10. <result property="contractNumber" column="contract_number" />
  11. <result property="tenderId" column="tender_id" />
  12. <result property="partyAId" column="party_a_id" />
  13. <result property="amount" column="amount" />
  14. <result property="subAmount" column="sub_amount" />
  15. <result property="budgetAmount" column="budget_amount" />
  16. <result property="borrowAmount" column="borrow_amount" />
  17. <result property="settleAmount" column="settle_amount" />
  18. <result property="paidAmount" column="paid_amount" />
  19. <result property="paidPercentage" column="paid_percentage" />
  20. <result property="invoiceAmount" column="invoice_amount" />
  21. <result property="invoicePercentage" column="invoice_percentage" />
  22. <result property="deposit" column="deposit" />
  23. <result property="contractDocument" column="contract_document" />
  24. <result property="drafter" column="drafter" />
  25. <result property="draftTime" column="draft_time" />
  26. <result property="remark" column="remark" />
  27. <result property="signDate" column="sign_date" />
  28. <result property="signRemark" column="sign_remark" />
  29. <result property="signScan" column="sign_scan" />
  30. <result property="commentType" column="comment_type" />
  31. <result property="managerComment" column="manager_comment" />
  32. <result property="managerUserId" column="manager_user_id" />
  33. <result property="managerTime" column="manager_time" />
  34. <result property="gmUserId" column="gm_user_id" />
  35. <result property="gmTime" column="gm_time" />
  36. <result property="gmComment" column="gm_comment" />
  37. <result property="projectSource" column="project_source" />
  38. <association property="draftUser" javaType="SysUser" resultMap="DraftUserResult" />
  39. <association property="managerUser" javaType="SysUser" resultMap="ManagerUserResult" />
  40. <association property="gmUser" javaType="SysUser" resultMap="GmUserResult" />
  41. <association property="tender" javaType="CmcTender" resultMap="CmcTenderResult" />
  42. <association property="partyA" javaType="CmcPartyA" resultMap="CmcPartyAResult" />
  43. <association property="project" javaType="CmcProject" resultMap="CmcProjectResult" />
  44. <association property="contractWork" javaType="CmcContractWork" resultMap="CmcContractWorkResult" />
  45. </resultMap>
  46. <resultMap type="CmcTender" id="CmcTenderResult">
  47. <result property="tenderId" column="tender_id" />
  48. <result property="projectName" column="t_project_name" />
  49. </resultMap>
  50. <resultMap type="SysUser" id="DraftUserResult">
  51. <result property="userId" column="user_id" />
  52. <result property="nickName" column="draft_nick_name" />
  53. </resultMap>
  54. <resultMap type="SysUser" id="ManagerUserResult">
  55. <result property="userId" column="user_id" />
  56. <result property="nickName" column="manager_nick_name" />
  57. </resultMap>
  58. <resultMap type="SysUser" id="GmUserResult">
  59. <result property="userId" column="user_id" />
  60. <result property="nickName" column="gm_nick_name" />
  61. </resultMap>
  62. <resultMap type="CmcPartyA" id="CmcPartyAResult">
  63. <result property="partyAId" column="party_a_id" />
  64. <result property="partyAName" column="party_a_name" />
  65. </resultMap>
  66. <resultMap type="CmcProject" id="CmcProjectResult">
  67. <result property="projectId" column="project_id" />
  68. <result property="projectNumber" column="project_number" />
  69. <result property="projectName" column="project_name" />
  70. <result property="projectType" column="project_type" />
  71. </resultMap>
  72. <resultMap type="CmcContractWork" id="CmcContractWorkResult">
  73. <result property="contractId" column="contract_id" />
  74. <result property="content" column="content" />
  75. </resultMap>
  76. <sql id="selectCmcContractVo">
  77. select distinct c.contract_id, c.contract_code, c.contract_name, c.contract_number, c.tender_id, t.project_name as t_project_name,
  78. c.party_a_id, pa.party_a_name, t.a_person as a_person, t.a_phone as a_phone, t.agent as agent, t.agent_person as agent_person,
  79. sum(cp.paid_amount) as paid_amount, case c.amount when 0 then 0 else round(sum(cp.paid_amount) / c.amount * 100, 2) end as paid_percentage,
  80. sum(ci.invoice_amount) as invoice_amount, case c.amount when 0 then 0 else round(sum(ci.invoice_amount) / c.amount * 100, 2) end as invoice_percentage,
  81. t.agent_phone as agent_phone, c.amount, c.deposit, c.contract_document, c.drafter, u.nick_name as draft_nick_name, c.draft_time, c.remark, c.sign_date, c.sign_remark, c.sign_scan,
  82. c.comment_type, c.manager_comment, c.manager_user_id, u1.nick_name as manager_nick_name, c.manager_time, c.gm_user_id, u2.nick_name as gm_nick_name, c.gm_time, c.gm_comment from cmc_contract as c
  83. left join sys_user as u on u.user_id = c.drafter
  84. left join sys_user as u1 on u1.user_id = c.manager_user_id
  85. left join sys_user as u2 on u2.user_id = c.gm_user_id
  86. left join cmc_tender as t on t.tender_id = c.tender_id
  87. left join cmc_party_a as pa on pa.party_a_id = c.party_a_id
  88. left join cmc_contract_paid as cp on cp.contract_id = c.contract_id
  89. left join cmc_contract_invoice as ci on ci.contract_id = c.contract_id
  90. </sql>
  91. <select id="selectCmcContractList" parameterType="CmcContract" resultMap="CmcContractResult">
  92. <include refid="selectCmcContractVo"/>
  93. <where>
  94. <if test="contractId != null and contractId != ''"> and c.contract_id like concat('%', #{contractId}, '%')</if>
  95. <if test="contractName!= null and contractName != ''"> and c.contract_name like concat('%', #{contractName}, '%')</if>
  96. <if test="contractCode!= null and contractCode != ''"> and c.contract_code like concat('%', #{contractCode}, '%')</if>
  97. <if test="tenderId != null and tenderId != ''"> and c.tender_id = #{tenderId}</if>
  98. <if test="contractNumber != null and contractNumber != ''"> and c.contract_number = #{contractNumber}</if>
  99. <if test="partyAId != null and partyAId != ''"> and c.party_a_id = #{partyAId}</if>
  100. <if test="amount != null "> and c.amount = #{amount}</if>
  101. <if test="deposit != null "> and c.deposit = #{deposit}</if>
  102. <if test="contractDocument != null and contractDocument != ''"> and c.contract_document = #{contractDocument}</if>
  103. <if test="drafter != null "> and c.drafter = #{drafter}</if>
  104. <if test="draftTime != null "> and c.draft_time = #{draftTime}</if>
  105. <if test="signDate != null "> and YEAR(c.sign_date) = YEAR(#{signDate})</if>
  106. <if test="signRemark != null and signRemark != ''"> and c.sign_remark = #{signRemark}</if>
  107. <if test="signScan != null and signScan != ''"> and c.sign_scan = #{signScan}</if>
  108. <if test="commentType != null and commentType != ''"> and c.comment_type = #{commentType}</if>
  109. </where>
  110. group by c.contract_id
  111. order by c.draft_time desc
  112. </select>
  113. <select id="selectCmcContractListP" parameterType="CmcContract" resultMap="CmcContractResult">
  114. select distinct t1.contract_id, t1.contract_code, t1.contract_name, t1.contract_number, t1.tender_id, t.project_name as t_project_name, t1.party_a_id, pa.party_a_name, t.a_person,
  115. t.a_phone, t.agent, t.agent_person,t1.paid_amount, t1.paid_percentage, t2.invoice_amount, t2.invoice_percentage, p.project_number, p.project_name, p.project_source,
  116. t.agent_phone, t1.amount, t1.deposit, t1.contract_document, t1.drafter, u.nick_name as draft_nick_name, t1.draft_time, t1.remark, t1.sign_date, t1.sign_remark, t1.sign_scan,
  117. t1.comment_type, t1.manager_comment, t1.manager_user_id, u1.nick_name as manager_nick_name, t1.manager_time, t1.gm_user_id, u2.nick_name as gm_nick_name, t1.gm_time, t1.gm_comment from
  118. (select distinct c.contract_id, c.contract_code, c.contract_name, c.contract_number, c.party_a_id, c.tender_id,
  119. sum(cp.paid_amount) as paid_amount, case c.amount when 0 then 0 else round(sum(cp.paid_amount) / c.amount * 100, 2) end as paid_percentage,
  120. c.amount, c.deposit, c.contract_document, c.drafter, c.draft_time, c.remark, c.sign_date, c.sign_remark, c.sign_scan,
  121. c.comment_type, c.manager_comment, c.manager_user_id, c.manager_time, c.gm_user_id, c.gm_time, c.gm_comment from cmc_contract as c
  122. left join cmc_contract_paid as cp on cp.contract_id = c.contract_id
  123. group by c.contract_id)
  124. as t1
  125. left join
  126. (select distinct c.contract_id,
  127. sum(ci.invoice_amount) as invoice_amount, case c.amount when 0 then 0 else round(sum(ci.invoice_amount) / c.amount * 100, 2) end as invoice_percentage
  128. from cmc_contract as c
  129. left join cmc_contract_invoice as ci on ci.contract_id = c.contract_id
  130. group by c.contract_id)
  131. as t2 on t2.contract_id = t1.contract_id
  132. left join sys_user as u on u.user_id = t1.drafter
  133. left join sys_user as u1 on u1.user_id = t1.manager_user_id
  134. left join sys_user as u2 on u2.user_id = t1.gm_user_id
  135. left join cmc_tender as t on t.tender_id = t1.tender_id
  136. left join cmc_party_a as pa on pa.party_a_id = t1.party_a_id
  137. left join cmc_project_contract as pc on pc.contract_id = t1.contract_id
  138. left join cmc_project as p on pc.project_id = p.project_id
  139. <where>
  140. <if test="contractId != null and contractId != ''"> and t1.contract_id like concat('%', #{contractId}, '%')</if>
  141. <if test="contractName!= null and contractName != ''"> and t1.contract_name like concat('%', #{contractName}, '%')</if>
  142. <if test="contractCode!= null and contractCode != ''"> and t1.contract_code like concat('%', #{contractCode}, '%')</if>
  143. <if test="tenderId != null and tenderId != ''"> and t1.tender_id = #{tenderId}</if>
  144. <if test="contractNumber != null and contractNumber != ''"> and t1.contract_number = #{contractNumber}</if>
  145. <if test="partyAId != null and partyAId != ''"> and t1.party_a_id = #{partyAId}</if>
  146. <if test="amount != null "> and t1.amount = #{amount}</if>
  147. <if test="deposit != null "> and t1.deposit = #{deposit}</if>
  148. <if test="contractDocument != null and contractDocument != ''"> and t1.contract_document = #{contractDocument}</if>
  149. <if test="drafter != null "> and t1.drafter = #{drafter}</if>
  150. <if test="draftTime != null "> and t1.draft_time = #{draftTime}</if>
  151. <if test="signDate != null "> and YEAR(t1.sign_date) = YEAR(#{signDate})</if>
  152. <if test="signRemark != null and signRemark != ''"> and t1.sign_remark = #{signRemark}</if>
  153. <if test="signScan != null and signScan != ''"> and t1.sign_scan = #{signScan}</if>
  154. <if test="commentType != null and commentType != ''"> and t1.comment_type = #{commentType}</if>
  155. <if test="projectSource != null and projectSource != ''"> and p.project_source = #{projectSource}</if>
  156. <if test="projectName != null and projectName != ''"> and p.project_name like concat('%', #{projectName}, '%')</if>
  157. <if test="partyAName != null and partyAName != ''"> and pa.party_a_name like concat('%', #{partyAName}, '%')</if>
  158. </where>
  159. group by t1.contract_id
  160. order by t1.draft_time desc
  161. </select>
  162. <select id="selectCmcContractListFuzzy" parameterType="CmcContract" resultMap="CmcContractResult">
  163. select distinct c.contract_id, c.contract_code, c.contract_name, c.contract_number, c.tender_id, t.project_name as t_project_name,
  164. c.party_a_id, pa.party_a_name, t.a_person as a_person, t.a_phone as a_phone, t.agent as agent, t.agent_person as agent_person,
  165. t.agent_phone as agent_phone, c.amount, c.deposit, c.contract_document, c.drafter, u.nick_name as draft_nick_name, c.draft_time,
  166. c.remark, c.sign_date, c.sign_remark, c.sign_scan, c.comment_type, c.manager_comment, c.manager_user_id, u1.nick_name as manager_nick_name,
  167. c.manager_time, c.gm_user_id, u2.nick_name as gm_nick_name, c.gm_time, c.gm_comment, cw.content from cmc_contract as c
  168. left join sys_user as u on u.user_id = c.drafter
  169. left join sys_user as u1 on u1.user_id = c.manager_user_id
  170. left join sys_user as u2 on u2.user_id = c.gm_user_id
  171. left join cmc_tender as t on t.tender_id = c.tender_id
  172. left join cmc_party_a as pa on pa.party_a_id = c.party_a_id
  173. left join cmc_contract_work as cw on cw.contract_id = c.contract_id
  174. <where>
  175. cw.content like concat('%', #{queryString}, '%')
  176. <if test="contractId != null and contractId != ''"> and c.contract_id like concat('%', #{contractId}, '%')</if>
  177. <if test="contractName!= null and contractName != ''"> and c.contract_name like concat('%', #{contractName}, '%')</if>
  178. <if test="contractCode!= null and contractCode != ''"> and c.contract_code like concat('%', #{contractCode}, '%')</if>
  179. <if test="tenderId != null and tenderId != ''"> and c.tender_id = #{tenderId}</if>
  180. <if test="contractNumber != null and contractNumber != ''"> and c.contract_number = #{contractNumber}</if>
  181. <if test="partyAId != null and partyAId != ''"> and c.party_a_id = #{partyAId}</if>
  182. <if test="amount != null "> and c.amount = #{amount}</if>
  183. <if test="deposit != null "> and c.deposit = #{deposit}</if>
  184. <if test="contractDocument != null and contractDocument != ''"> and c.contract_document = #{contractDocument}</if>
  185. <if test="drafter != null "> and c.drafter = #{drafter}</if>
  186. <if test="draftTime != null "> and c.draft_time = #{draftTime}</if>
  187. <if test="signDate != null "> and YEAR(c.sign_date) = YEAR(#{signDate})</if>
  188. <if test="signRemark != null and signRemark != ''"> and c.sign_remark = #{signRemark}</if>
  189. <if test="signScan != null and signScan != ''"> and c.sign_scan = #{signScan}</if>
  190. <if test="commentType != null and commentType != ''"> and c.comment_type = #{commentType}</if>
  191. </where>
  192. group by c.contract_id
  193. order by c.draft_time desc
  194. </select>
  195. <select id="selectCmcContractListByRange" parameterType="CmcContract" resultMap="CmcContractResult">
  196. select distinct t3.*, p.project_number, p.project_name, p.project_source from
  197. (select t1.*, t2.invoice_amount, t2.invoice_percentage from (select distinct c.contract_id, c.contract_code, c.contract_name, c.contract_number, c.tender_id, t.project_name as t_project_name,c.party_a_id, pa.party_a_name,
  198. t.a_person as a_person, t.a_phone as a_phone, t.agent as agent, t.agent_person as agent_person, t.agent_phone as agent_phone,
  199. sum(cp.paid_amount) as paid_amount, case c.amount when 0 then 0 else round(sum(cp.paid_amount) / c.amount * 100, 2) end as paid_percentage,
  200. c.amount, c.deposit, c.contract_document, c.drafter, u.nick_name as draft_nick_name, c.draft_time, c.remark, c.sign_date, c.sign_remark, c.sign_scan,
  201. c.comment_type, c.manager_comment, c.manager_user_id, u1.nick_name as manager_nick_name, c.manager_time, c.gm_user_id, u2.nick_name as gm_nick_name, c.gm_time, c.gm_comment from cmc_contract as c
  202. left join sys_user as u on u.user_id = c.drafter
  203. left join sys_user as u1 on u1.user_id = c.manager_user_id
  204. left join sys_user as u2 on u2.user_id = c.gm_user_id
  205. left join cmc_tender as t on t.tender_id = c.tender_id
  206. left join cmc_party_a as pa on pa.party_a_id = c.party_a_id
  207. left join cmc_contract_paid as cp on cp.contract_id = c.contract_id
  208. group by c.contract_id) as t1
  209. left join
  210. (select distinct c.contract_id,
  211. sum(ci.invoice_amount) as invoice_amount, case c.amount when 0 then 0 else round(sum(ci.invoice_amount) / c.amount * 100, 2) end as invoice_percentage
  212. from cmc_contract as c
  213. left join cmc_contract_invoice as ci on ci.contract_id = c.contract_id
  214. group by c.contract_id) as t2
  215. on t1.contract_id = t2.contract_id)
  216. as t3
  217. left join cmc_project_contract as pc on pc.contract_id = t3.contract_id
  218. left join cmc_project as p on pc.project_id = p.project_id
  219. <where>
  220. <if test="contractId != null and contractId != ''"> and t3.contract_id like concat('%', #{contractId}, '%')</if>
  221. <if test="contractName!= null and contractName != ''"> and t3.contract_name like concat('%', #{contractName}, '%')</if>
  222. <if test="contractCode!= null and contractCode != ''"> and t3.contract_code like concat('%', #{contractCode}, '%')</if>
  223. <if test="tenderId != null and tenderId != ''"> and t3.tender_id = #{tenderId}</if>
  224. <if test="contractNumber != null and contractNumber != ''"> and t3.contract_number = #{contractNumber}</if>
  225. <if test="partyAId != null and partyAId != ''"> and t3.party_a_id = #{partyAId}</if>
  226. <if test="amount != null "> and t3.amount = #{amount}</if>
  227. <if test="deposit != null "> and t3.deposit = #{deposit}</if>
  228. <if test="contractDocument != null and contractDocument != ''"> and t3.contract_document = #{contractDocument}</if>
  229. <if test="drafter != null "> and t3.drafter = #{drafter}</if>
  230. <if test="draftTime != null "> and t3.draft_time = #{draftTime}</if>
  231. <if test="signDate != null"> and YEAR(t3.sign_date) = YEAR(#{signDate})</if>
  232. <if test="signRemark != null and signRemark != ''"> and t3.sign_remark = #{signRemark}</if>
  233. <if test="signScan != null and signScan != ''"> and t3.sign_scan = #{signScan}</if>
  234. <if test="commentType != null and commentType != ''"> and t3.comment_type = #{commentType}</if>
  235. <if test="projectSource != null and projectSource != ''"> and p.project_source = #{projectSource}</if>
  236. <if test="projectName != null and projectName != ''"> and p.project_name like concat('%', #{projectName}, '%')</if>
  237. <if test="partyAName != null and partyAName != ''"> and pa.party_a_name like concat('%', #{partyAName}, '%')</if>
  238. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  239. and date_format(t3.sign_date,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  240. </if>
  241. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  242. and date_format(t3.sign_date,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  243. </if>
  244. </where>
  245. group by t3.contract_id
  246. order by t3.draft_time desc
  247. </select>
  248. <select id="selectCmcContractStatistic" resultMap="CmcContractResult" >
  249. select t1.contract_id, t1.contract_name, t1.project_type, t1.project_number, IFNULL(t1.amount, 0) as amount, IFNULL(t2.sub_amount, 0) as sub_amount, IFNULL(t3.budget_amount, 0) as budget_amount, IFNULL(t4.borrow_amount, 0) as borrow_amount, IFNULL(t5.settle_amount, 0) as settle_amount from
  250. (select distinct c.contract_id, c.contract_name, p.project_type, p.project_number, c.amount from cmc_contract as c
  251. left join cmc_contract_sub_contract as csc on csc.contract_id = c.contract_id
  252. left join cmc_project_contract as pc on pc.contract_id = c.contract_id
  253. left join cmc_project as p on p.project_id = pc.project_id
  254. group by c.contract_id
  255. order by c.draft_time desc) as t1
  256. left join
  257. (select distinct c.contract_id, sum(sc.sub_amount) as sub_amount from cmc_contract as c
  258. left join cmc_contract_sub_contract as csc on csc.contract_id = c.contract_id
  259. left join cmc_sub_contract as sc on sc.sub_contract_id = csc.sub_contract_id
  260. group by c.contract_id) as t2
  261. on t1.contract_id = t2.contract_id
  262. left join
  263. (select distinct c.contract_id, sum(b.total_budget) as budget_amount from cmc_contract as c
  264. left join cmc_project_contract as pc on pc.contract_id = c.contract_id
  265. left join cmc_project as p on p.project_id = pc.project_id
  266. left join cmc_budget as b on b.project_id = p.project_id
  267. group by c.contract_id) as t3
  268. on t1.contract_id = t3.contract_id
  269. left join
  270. (select distinct c.contract_id, sum(b.manager_amount) as borrow_amount from cmc_contract as c
  271. left join cmc_project_contract as pc on pc.contract_id = c.contract_id
  272. left join cmc_project as p on p.project_id = pc.project_id
  273. left join cmc_borrow as b on b.project_id = p.project_id
  274. group by c.contract_id) as t4
  275. on t1.contract_id = t4.contract_id
  276. left join
  277. (select distinct c.contract_id, sum(ss.amount) as settle_amount from cmc_contract as c
  278. left join cmc_project_contract as pc on pc.contract_id = c.contract_id
  279. left join cmc_project as p on p.project_id = pc.project_id
  280. left join cmc_settle as s on s.project_id = p.project_id
  281. left join cmc_settle_summary as ss on ss.settle_id = s.settle_id
  282. where ss.content = '实际结算总金额'
  283. group by c.contract_id) as t5
  284. on t1.contract_id = t5.contract_id
  285. </select>
  286. <select id="selectCmcContractStatisticByContractId" parameterType="String" resultMap="CmcContractResult" >
  287. select t1.contract_id, t1.contract_name, t1.project_type, t1.project_number, IFNULL(t1.amount, 0) as amount, IFNULL(t2.sub_amount, 0) as sub_amount, IFNULL(t3.budget_amount, 0) as budget_amount, IFNULL(t4.borrow_amount, 0) as borrow_amount, IFNULL(t5.settle_amount, 0) as settle_amount from
  288. (select distinct c.contract_id, c.contract_name, p.project_type, p.project_number, c.amount from cmc_contract as c
  289. left join cmc_contract_sub_contract as csc on csc.contract_id = c.contract_id
  290. left join cmc_project_contract as pc on pc.contract_id = c.contract_id
  291. left join cmc_project as p on p.project_id = pc.project_id
  292. group by c.contract_id
  293. order by c.draft_time desc) as t1
  294. left join
  295. (select distinct c.contract_id, sum(sc.sub_amount) as sub_amount from cmc_contract as c
  296. left join cmc_contract_sub_contract as csc on csc.contract_id = c.contract_id
  297. left join cmc_sub_contract as sc on sc.sub_contract_id = csc.sub_contract_id
  298. group by c.contract_id) as t2
  299. on t1.contract_id = t2.contract_id
  300. left join
  301. (select distinct c.contract_id, sum(b.total_budget) as budget_amount from cmc_contract as c
  302. left join cmc_project_contract as pc on pc.contract_id = c.contract_id
  303. left join cmc_project as p on p.project_id = pc.project_id
  304. left join cmc_budget as b on b.project_id = p.project_id
  305. group by c.contract_id) as t3
  306. on t1.contract_id = t3.contract_id
  307. left join
  308. (select distinct c.contract_id, sum(b.manager_amount) as borrow_amount from cmc_contract as c
  309. left join cmc_project_contract as pc on pc.contract_id = c.contract_id
  310. left join cmc_project as p on p.project_id = pc.project_id
  311. left join cmc_borrow as b on b.project_id = p.project_id
  312. group by c.contract_id) as t4
  313. on t1.contract_id = t4.contract_id
  314. left join
  315. (select distinct c.contract_id, sum(ss.amount) as settle_amount from cmc_contract as c
  316. left join cmc_project_contract as pc on pc.contract_id = c.contract_id
  317. left join cmc_project as p on p.project_id = pc.project_id
  318. left join cmc_settle as s on s.project_id = p.project_id
  319. left join cmc_settle_summary as ss on ss.settle_id = s.settle_id
  320. where ss.content = '实际结算总金额'
  321. group by c.contract_id) as t5
  322. on t1.contract_id = t5.contract_id
  323. where t1.contract_id = #{param}
  324. </select>
  325. <select id="selectCmcContractByContractId" parameterType="String" resultMap="CmcContractResult">
  326. <include refid="selectCmcContractVo"/>
  327. where c.contract_id = #{contractId}
  328. group by c.contract_id
  329. </select>
  330. <insert id="insertCmcContract" parameterType="CmcContract">
  331. insert into cmc_contract
  332. <trim prefix="(" suffix=")" suffixOverrides=",">
  333. <if test="contractId != null">contract_id,</if>
  334. <if test="contractName != null">contract_name,</if>
  335. <if test="contractCode != null">contract_code,</if>
  336. <if test="tenderId != null">tender_id,</if>
  337. <if test="partyAId != null">party_a_id,</if>
  338. <if test="contractNumber != null">contract_number,</if>
  339. <if test="amount != null">amount,</if>
  340. <if test="deposit != null">deposit,</if>
  341. <if test="contractDocument != null">contract_document,</if>
  342. <if test="drafter != null">drafter,</if>
  343. <if test="draftTime != null">draft_time,</if>
  344. <if test="remark != null">remark,</if>
  345. <if test="signDate != null">sign_date,</if>
  346. <if test="signRemark != null">sign_remark,</if>
  347. <if test="signScan != null">sign_scan,</if>
  348. <if test="commentType != null">comment_type,</if>
  349. <if test="managerComment != null">manager_comment,</if>
  350. <if test="managerUserId != null">manager_user_id,</if>
  351. <if test="managerTime != null">manager_time,</if>
  352. <if test="gmUserId != null">gm_user_id,</if>
  353. <if test="gmTime != null">gm_time,</if>
  354. <if test="gmComment != null">gm_comment,</if>
  355. </trim>
  356. <trim prefix="values (" suffix=")" suffixOverrides=",">
  357. <if test="contractId != null">#{contractId},</if>
  358. <if test="contractName != null">#{contractName},</if>
  359. <if test="contractCode != null">#{contractCode},</if>
  360. <if test="tenderId != null">#{tenderId},</if>
  361. <if test="partyAId != null">#{partyAId},</if>
  362. <if test="contractNumber != null">#{contractNumber},</if>
  363. <if test="amount != null">#{amount},</if>
  364. <if test="deposit != null">#{deposit},</if>
  365. <if test="contractDocument != null">#{contractDocument},</if>
  366. <if test="drafter != null">#{drafter},</if>
  367. <if test="draftTime != null">#{draftTime},</if>
  368. <if test="remark != null">#{remark},</if>
  369. <if test="signDate != null">#{signDate},</if>
  370. <if test="signRemark != null">#{signRemark},</if>
  371. <if test="signScan != null">#{signScan},</if>
  372. <if test="commentType != null">#{commentType},</if>
  373. <if test="managerComment != null">#{managerComment},</if>
  374. <if test="managerUserId != null">#{managerUserId},</if>
  375. <if test="managerTime != null">#{managerTime},</if>
  376. <if test="gmUserId != null">#{gmUserId},</if>
  377. <if test="gmTime != null">#{gmTime},</if>
  378. <if test="gmComment != null">#{gmComment},</if>
  379. </trim>
  380. </insert>
  381. <update id="updateCmcContract" parameterType="CmcContract">
  382. update cmc_contract
  383. <trim prefix="SET" suffixOverrides=",">
  384. <if test="contractCode != null">contract_code = #{contractCode},</if>
  385. <if test="contractName != null">contract_name = #{contractName},</if>
  386. <if test="tenderId != null">tender_id = #{tenderId},</if>
  387. <if test="partyAId != null">party_a_id = #{partyAId},</if>
  388. <if test="contractNumber != null">contract_number = #{contractNumber},</if>
  389. <if test="amount != null">amount = #{amount},</if>
  390. <if test="deposit != null">deposit = #{deposit},</if>
  391. <if test="contractDocument != null">contract_document = #{contractDocument},</if>
  392. <if test="drafter != null">drafter = #{drafter},</if>
  393. <if test="draftTime != null">draft_time = #{draftTime},</if>
  394. <if test="remark != null">remark = #{remark},</if>
  395. <if test="signDate != null">sign_date = #{signDate},</if>
  396. <if test="signRemark != null">sign_remark = #{signRemark},</if>
  397. <if test="signScan != null">sign_scan = #{signScan},</if>
  398. <if test="commentType != null">comment_type = #{commentType},</if>
  399. <if test="managerComment != null">manager_comment = #{managerComment},</if>
  400. <if test="managerUserId != null">manager_user_id = #{managerUserId},</if>
  401. <if test="managerTime != null">manager_time = #{managerTime},</if>
  402. <if test="gmUserId != null">gm_user_id = #{gmUserId},</if>
  403. <if test="gmTime != null">gm_time = #{gmTime},</if>
  404. <if test="gmComment != null">gm_comment = #{gmComment},</if>
  405. </trim>
  406. where contract_id = #{contractId}
  407. </update>
  408. <delete id="deleteCmcContractByContractId" parameterType="String">
  409. delete from cmc_contract where contract_id = #{contractId}
  410. </delete>
  411. <delete id="deleteCmcContractByContractIds" parameterType="String">
  412. delete from cmc_contract where contract_id in
  413. <foreach item="contractId" collection="array" open="(" separator="," close=")">
  414. #{contractId}
  415. </foreach>
  416. </delete>
  417. </mapper>