AssetsMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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.dayou.mapper.AssetsMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.Assets">
  6. <result column="id" property="id"/>
  7. <result column="deleted" property="deleted"/>
  8. <result column="created" property="created"/>
  9. <result column="modified" property="modified"/>
  10. <result column="name" property="name"/>
  11. <result column="order_id" property="orderId"/>
  12. <result column="financial" property="financial"/>
  13. <result column="allot_type" property="allotType"/>
  14. <result column="client_manager_id" property="clientManagerId"/>
  15. <result column="principal_id" property="principalId"/>
  16. <result column="department_id" property="departmentId"/>
  17. <result column="assets_business_gener" property="assetsBusinessGener"/>
  18. <result column="entrust_again" property="entrustAgain"/>
  19. <result column="clientele_type" property="clienteleType"/>
  20. <result column="clientele_id" property="clienteleId"/>
  21. <result column="clientele_sub_id" property="clienteleSubId"/>
  22. <result column="clientele_contact_id" property="clienteleContactId"/>
  23. <result column="security" property="security"/>
  24. <result column="significant_assets_reorganization" property="significantAssetsReorganization"/>
  25. <result column="state_assets" property="stateAssets"/>
  26. <result column="foreign_assets_involved" property="foreignAssetsInvolved"/>
  27. <result column="dispense_benefit" property="dispenseBenefit"/>
  28. <result column="bailor" property="bailor"/>
  29. <result column="bailor_address" property="bailorAddress"/>
  30. <result column="bailor_contact_name" property="bailorContactName"/>
  31. <result column="bailor_contact_tel" property="bailorContactTel"/>
  32. <result column="terminal_clientele_id" property="terminalClienteleId"/>
  33. <result column="terminal_clientele_type" property="terminalClienteleType"/>
  34. <result column="terminal_clientele_contact_id" property="terminalClienteleContactId"/>
  35. <result column="members" property="members"/>
  36. <result column="remark" property="remark"/>
  37. </resultMap>
  38. <!-- 通用查询结果列 -->
  39. <sql id="Base_Column_List">
  40. id,
  41. deleted,
  42. created,
  43. modified,
  44. name, order_id, financial, allot_type, client_manager_id, principal_id, department_id, assets_business_gener, entrust_again, clientele_type, clientele_id, clientele_sub_id, clientele_contact_id, security, significant_assets_reorganization, state_assets, foreign_assets_involved, dispense_benefit, bailor, bailor_address, bailor_contact_name, bailor_contact_tel, terminal_clientele_id, terminal_clientele_type, terminal_clientele_contact_id, members, remark
  45. </sql>
  46. <!--条件查询资产任务列表-->
  47. <select id="selectPage" resultType="com.dayou.vo.AssetsVO">
  48. SELECT (@i := @i + 1) AS id,
  49. assets.id AS assetsId,
  50. assets.name,
  51. order_id,
  52. assets_business_gener,
  53. allot_type,
  54. production_no,
  55. clientele_id,
  56. customer.name AS customerName,
  57. bailor,
  58. bailor_contact_tel,
  59. assets.created,
  60. #查询客户经理
  61. (SELECT name FROM user WHERE id = assets.client_manager_id) AS clientManagerName,
  62. #查询项目负责人
  63. (SELECT name FROM user WHERE id = assets.principal_id) AS principalName,
  64. #查询业务来源(即子级客户)
  65. (SELECT customer_company.name FROM customer_company WHERE customer_company.id = clientele_sub_id) AS customerSubName,
  66. nodeInfo.businessId,
  67. nodeInfo.currentNodeName,
  68. nodeInfo.currentNodeCode,
  69. nodeInfo.handlerName,
  70. production_type
  71. FROM (SELECT @i := 0) AS sort,assets
  72. LEFT JOIN assets_production AS production ON production.business_id = assets.id
  73. LEFT JOIN user ON user.id = assets.principal_id
  74. LEFT JOIN customer_company AS customer ON customer.id = assets.clientele_id
  75. #查询当前进行的节点信息(并使用左连接)
  76. LEFT JOIN (SELECT nodeInstance.id AS currentNodeId,
  77. user.name AS handlerName,
  78. node.name AS currentNodeName,
  79. node.code AS currentNodeCode,
  80. nodeInstance.business_id AS businessId
  81. FROM work_flow_node_instance AS nodeInstance,
  82. work_task_record AS record,
  83. user,
  84. work_node AS node
  85. WHERE state = 'PENDING'
  86. AND nodeInstance.node_id = node.id
  87. AND record.handler_id = user.id
  88. AND nodeInstance.deleted = 0
  89. AND record.instance_id = nodeInstance.id
  90. # 根据处理节点查询(节点code)
  91. <if test="assetsSelectDTO != null and assetsSelectDTO.nodeCode != null and assetsSelectDTO.nodeCode != '' ">
  92. AND node.`code` = #{assetsSelectDTO.nodeCode}
  93. </if>
  94. ) AS nodeInfo ON nodeInfo.businessId = assets.id
  95. WHERE assets.deleted = 0
  96. #评估业务类别(业务类型)查询
  97. <if test="assetsSelectDTO != null and assetsSelectDTO.assetsBusinessGener != null and assetsSelectDTO.assetsBusinessGener != '' ">
  98. AND assets.assets_business_gener = #{assetsSelectDTO.assetsBusinessGener}
  99. </if>
  100. #项目负责人查询
  101. <if test="assetsSelectDTO != null and assetsSelectDTO.principalId != null">
  102. AND assets.principal_id = #{assetsSelectDTO.principalId}
  103. </if>
  104. #客户经理查询
  105. <if test="assetsSelectDTO != null and assetsSelectDTO.clientManagerId != null">
  106. AND assets.client_manager_id = #{assetsSelectDTO.clientManagerId}
  107. </if>
  108. #关键字模糊查询
  109. <if test="assetsSelectDTO != null and assetsSelectDTO.keyWord != null and assetsSelectDTO.keyWord != '' ">
  110. AND (
  111. assets.order_id LIKE CONCAT('%',#{assetsSelectDTO.keyWord},'%') OR
  112. assets.name LIKE CONCAT('%',#{assetsSelectDTO.keyWord},'%') OR
  113. production.production_no LIKE CONCAT('%',#{assetsSelectDTO.keyWord},'%') OR
  114. customer.name LIKE CONCAT('%',#{assetsSelectDTO.keyWord},'%')
  115. )
  116. </if>
  117. ORDER BY assets.created DESC
  118. </select>
  119. <!--条件查询我的资产任务订单列表-->
  120. <select id="selectMyOrderPage" resultType="com.dayou.vo.AssetsVO">
  121. SELECT (@i := @i + 1) AS id,
  122. assets.id AS assetsId,
  123. assets.name,
  124. assets.order_id,
  125. assets_business_gener,
  126. allot_type,
  127. production.production_no,
  128. clientele_id,
  129. customer.name AS customerName,
  130. bailor,
  131. bailor_contact_name,
  132. bailor_contact_tel,
  133. assets.created,
  134. ( SELECT SUM(estimated_value) FROM assets_evaluation_target WHERE assets_evaluation_target.assets_id = assets.id ) AS estimated_value,
  135. fund.should_amount,
  136. fund.real_amount,
  137. fund.discount,
  138. pFund.standard_amount,
  139. invoice.real_amount AS invoiceRealAmount,
  140. #查询客户经理
  141. (SELECT name FROM user WHERE id = assets.client_manager_id) AS clientManagerName,
  142. #查询项目负责人
  143. (SELECT name FROM user WHERE id = assets.principal_id) AS principalName,
  144. #查询业务来源(即子级客户)
  145. (SELECT customer_company.name FROM customer_company WHERE customer_company.id = clientele_sub_id) AS customerSubName,
  146. nodeInfo.businessId,
  147. nodeInfo.currentNodeName,
  148. nodeInfo.currentNodeCode,
  149. nodeInfo.handlerName,
  150. production.production_type
  151. FROM (SELECT @i := 0) AS sort,assets
  152. LEFT JOIN assets_production AS production ON production.business_id = assets.id
  153. LEFT JOIN user ON user.id = assets.principal_id
  154. LEFT JOIN customer_company AS customer ON customer.id = assets.clientele_id
  155. LEFT JOIN order_fund AS fund ON fund.business_id = assets.id
  156. LEFT JOIN production_fund AS pFund ON pFund.business_id = assets.id
  157. LEFT JOIN finance_invoice AS invoice ON pFund.order_fund_id = fund.id
  158. #查询当前进行的节点信息
  159. LEFT JOIN (SELECT nodeInstance.id AS currentNodeId,
  160. user.name AS handlerName,
  161. node.name AS currentNodeName,
  162. node.code AS currentNodeCode,
  163. nodeInstance.business_id AS businessId
  164. FROM work_flow_node_instance AS nodeInstance,
  165. work_task_record AS record,
  166. user,
  167. work_node AS node
  168. WHERE state = 'PENDING'
  169. AND nodeInstance.node_id = node.id
  170. AND record.handler_id = user.id
  171. AND nodeInstance.deleted = 0
  172. AND record.instance_id = nodeInstance.id
  173. ) AS nodeInfo ON nodeInfo.businessId = assets.id
  174. WHERE assets.deleted = 0
  175. AND assets.client_manager_id = #{assetsSelectDTO.clientManagerId}
  176. #送达状态查询
  177. <if test="assetsSelectDTO != null and assetsSelectDTO.delivery != null">
  178. AND production.delivery = #{assetsSelectDTO.delivery}
  179. </if>
  180. #项目负责人查询
  181. <if test="assetsSelectDTO != null and assetsSelectDTO.principalId != null">
  182. AND assets.principal_id = #{assetsSelectDTO.principalId}
  183. </if>
  184. #关键字模糊查询
  185. <if test="assetsSelectDTO != null and assetsSelectDTO.keyWord != null and assetsSelectDTO.keyWord != '' ">
  186. AND (
  187. assets.order_id LIKE CONCAT('%',#{assetsSelectDTO.keyWord},'%') OR
  188. assets.name LIKE CONCAT('%',#{assetsSelectDTO.keyWord},'%') OR
  189. production.production_no LIKE CONCAT('%',#{assetsSelectDTO.keyWord},'%') OR
  190. customer.name LIKE CONCAT('%',#{assetsSelectDTO.keyWord},'%')
  191. )
  192. </if>
  193. ORDER BY assets.created DESC
  194. </select>
  195. <!--根据业务id获取资产业务详情-->
  196. <select id="getAssetsDetailById" resultType="com.dayou.vo.AssetsVO">
  197. SELECT assets.id,
  198. #查询客户经理
  199. (SELECT name FROM user WHERE id = assets.client_manager_id) AS clientManagerName,
  200. user.name AS principalName,
  201. allot_type,
  202. assets.department_id,
  203. assets.order_id,
  204. assets.name,
  205. assets.assets_business_gener,
  206. assets.entrust_again,
  207. assets.clientele_type,
  208. assets.principal_id,
  209. customer.id AS clienteleId,
  210. customer.name AS customerName,
  211. linkman.id AS clienteleContactId,
  212. linkman.name AS linkmanName,
  213. linkman.department AS linkmanDepartment,
  214. linkman.duty AS linkmanDuty,
  215. linkman.mobile AS linkmanMobile,
  216. assets.security,
  217. assets.significant_assets_reorganization,
  218. assets.state_assets,
  219. assets.foreign_assets_involved,
  220. assets.dispense_benefit,
  221. assets.bailor,
  222. assets.bailor_address,
  223. assets.bailor_contact_name,
  224. assets.bailor_contact_tel,
  225. assets.terminal_clientele_id,
  226. assets.terminal_clientele_type,
  227. assets.remark,
  228. tLinkman.id AS tLinkmanId,
  229. tLinkman.name AS tLinkmanName,
  230. tLinkman.mobile AS tLinkmanMobile,
  231. assets.members AS members,
  232. #查询终端客户名称
  233. (SELECT customer_company.name FROM customer_company WHERE customer_company.id = assets.terminal_clientele_id) AS
  234. terminalClienteleName,
  235. assets.clientele_sub_id
  236. FROM assets
  237. LEFT JOIN user ON user.id = assets.principal_id
  238. LEFT JOIN department ON department.id = assets.department_id
  239. LEFT JOIN customer_company AS customer ON customer.id = assets.clientele_id
  240. LEFT JOIN customer_linkman AS linkman ON linkman.id = assets.clientele_contact_id
  241. LEFT JOIN (SELECT tLinkman.id, tLinkman.name, tLinkman.mobile FROM customer_linkman AS tLinkman) AS tLinkman ON
  242. tLinkman.id = assets.terminal_clientele_contact_id
  243. <where>
  244. <if test="id != null">
  245. AND assets.id = #{id}
  246. </if>
  247. </where>
  248. </select>
  249. <!--根据业务id获取资产业务款项信息-->
  250. <select id="getOrderFundInvoiceById" resultType="com.dayou.vo.AssetsOrderFundInvoiceVO">
  251. SELECT order_fund.id,
  252. business_id,
  253. should_amount,
  254. order_fund.real_amount,
  255. title,
  256. type,
  257. tax_no,
  258. bank_name,
  259. bank_account,
  260. bank_address,
  261. bank_tel
  262. FROM order_fund
  263. LEFT JOIN finance_invoice ON finance_invoice.order_fund_id = order_fund.id
  264. WHERE order_fund.business_id = #{id}
  265. AND order_fund.deleted = 0
  266. </select>
  267. <!--根据业务类型与取号类型获取业务取号信息-->
  268. <select id="getBusinessNum" resultType="com.dayou.entity.BusinessNumber">
  269. SELECT id, year, month, next_no
  270. FROM business_number
  271. WHERE take_type = #{takeType}
  272. AND business_type = #{businessType}
  273. AND year = #{year}
  274. AND deleted = 0
  275. </select>
  276. <!--新增取号信息-->
  277. <insert id="addBusinessNum">
  278. INSERT INTO business_number(id, take_type, business_type, year, month, next_no)
  279. VALUE (NULL, #{takeType}, #{businessType}, #{year}, #{month}, #{nextNo})
  280. </insert>
  281. <!--更新取号信息-->
  282. <update id="updateBusinessNum">
  283. UPDATE business_number
  284. SET month = #{month},
  285. next_no = #{nextNo}
  286. WHERE id = #{id}
  287. </update>
  288. </mapper>