MajorMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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.MajorMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.Major">
  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="business_object_type" property="businessObjectType" />
  18. <result column="special_type" property="specialType" />
  19. <result column="business_gener" property="businessGener" />
  20. <result column="evaluate_aim" property="evaluateAim" />
  21. <result column="entrust_again" property="entrustAgain" />
  22. <result column="multiple_removal" property="multipleRemoval" />
  23. <result column="informal_evaluate" property="informalEvaluate" />
  24. <result column="clientele_type" property="clienteleType" />
  25. <result column="clientele_id" property="clienteleId" />
  26. <result column="clientele_contact_id" property="clienteleContactId" />
  27. <result column="dispense_benefit" property="dispenseBenefit" />
  28. <result column="nonnative" property="nonnative" />
  29. <result column="refinance" property="refinance" />
  30. <result column="loan_limit" property="loanLimit" />
  31. <result column="loan_period" property="loanPeriod" />
  32. <result column="loan_nature" property="loanNature" />
  33. <result column="loan_aim" property="loanAim" />
  34. <result column="loan_expire" property="loanExpire" />
  35. <result column="bailor" property="bailor" />
  36. <result column="bailor_address" property="bailorAddress" />
  37. <result column="bailor_contact_name" property="bailorContactName" />
  38. <result column="bailor_contact_tel" property="bailorContactTel" />
  39. <result column="owner" property="owner" />
  40. <result column="owner_tel" property="ownerTel" />
  41. <result column="urgent" property="urgent" />
  42. <result column="terminal_clientele_id" property="terminalClienteleId" />
  43. <result column="terminal_clientele_type" property="terminalClienteleType" />
  44. <result column="terminal_clientele_contact_id" property="terminalClienteleContactId" />
  45. <result column="remark" property="remark" />
  46. <result column="members" property="members" />
  47. </resultMap>
  48. <!-- 通用查询结果列 -->
  49. <sql id="Base_Column_List">
  50. id,
  51. deleted,
  52. created,
  53. modified,
  54. name, order_id, financial, allot_type, client_manager_id, principal_id, department_id, business_object_type, special_type, business_gener,
  55. evaluate_aim, entrust_again, multiple_removal, informal_evaluate, clientele_type, clientele_id, clientele_contact_id, dispense_benefit,
  56. nonnative, refinance, loan_limit, loan_period, loan_nature, loan_aim, loan_expire, bailor, bailor_address, bailor_contact_name,
  57. bailor_contact_tel, owner, owner_tel, urgent, terminal_clientele_id, terminal_clientele_type, terminal_clientele_contact_id, remark,members,
  58. production_info,printing,printing_remark
  59. </sql>
  60. <resultMap id="majorVoMap" type="com.dayou.vo.MajorListVO">
  61. <result column="id" property="id" />
  62. <result column="created" property="created" />
  63. <result column="name" property="name" />
  64. <result column="order_id" property="orderId" />
  65. <result column="financial" property="financial" />
  66. <result column="allot_type" property="allotType" />
  67. <result column="client_manager_id" property="clientManagerId" />
  68. <result column="clientManager" property="clientManager" />
  69. <result column="principal_id" property="principalId" />
  70. <result column="principal" property="principal" />
  71. <result column="department_id" property="departmentId" />
  72. <result column="departmentName" property="departmentName" />
  73. <result column="business_object_type" property="businessObjectType" />
  74. <result column="clientele_id" property="clienteleId" />
  75. <result column="clientele" property="clientele" />
  76. <result column="clientele_contact_id" property="clienteleContactId" />
  77. <result column="clienteleContact" property="clienteleContact" />
  78. <result column="clienteleContactTel" property="clienteleContactTel" />
  79. <result column="currentNodeId" property="currentNodeId" />
  80. <result column="currentNodeName" property="currentNodeName" />
  81. <result column="cClienteleName" property="cClienteleName" />
  82. <result column="cClienteleSubName" property="cClienteleSubName" />
  83. <result column="cClienteleContactName" property="cClienteleContactName" />
  84. <result column="cMobile" property="cMobile" />
  85. <collection property="productions" ofType="com.dayou.vo.MajorProductionVO" select="selectProduction" column="id"/>
  86. </resultMap>
  87. <select id="getPage" parameterType="com.dayou.vo.MajorVO" resultMap="majorVoMap">
  88. SELECT
  89. DISTINCT
  90. m.id,
  91. m.created,
  92. m.name,
  93. m.order_id,
  94. m.financial,
  95. m.allot_type,
  96. m.client_manager_id,
  97. u.name as clientManager,
  98. m.principal_id,
  99. u1.name as principal,
  100. m.department_id,
  101. d.name as departmentName,
  102. m.business_object_type,
  103. m.clientele_id,
  104. m.clientele_contact_id,
  105. m.clientele_id as clientele,
  106. m.clientele_contact_id as clienteleContact,
  107. cc1.name as cClienteleName,
  108. cc2.name as cClienteleSubName,
  109. cl1.name as cClienteleContactName,
  110. cl1.mobile as cMobile
  111. FROM
  112. major m
  113. left join user u on u.id = m.client_manager_id
  114. left join user u1 on u1.id = m.principal_id
  115. left join department d on d.id = m.department_id
  116. inner join ( SELECT id, node_id, business_id, business_sub_id, state FROM work_flow_node_instance WHERE business_type = 'MAJOR_BUSINESS' and deleted = 0 and state='PENDING') wfni
  117. ON wfni.business_id = m.id
  118. left join customer_company cc1 on cc1.id = m.clientele_id
  119. left join customer_company cc2 on cc2.id = m.clientele_sub_id
  120. left join customer_linkman cl1 on cl1.id = m.clientele_contact_id
  121. where m.deleted = 0
  122. <if test="keyword!=null and keyword!='' ">
  123. and (
  124. m.name like concat ('%',#{keyword},'%')
  125. or m.order_id like concat('%',#{keyword},'%')
  126. or u.name like concat('%',#{keyword},'%')
  127. or u1.name like concat('%',#{keyword},'%')
  128. or cc2.name like concat('%',#{keyword},'%')
  129. or cc1.name like concat('%',#{keyword},'%')
  130. or cl1.name like concat('%',#{keyword},'%')
  131. or cl1.mobile like concat('%',#{keyword},'%')
  132. or m.business_object_type like concat('%',#{keyword},'%')
  133. or d.name like concat('%',#{keyword},'%')
  134. or m.allot_type like concat('%',#{keyword},'%')
  135. )
  136. </if>
  137. <if test="major!=null and major.financial!=null">
  138. and m.financial = #{major.financial}
  139. </if>
  140. <if test="major!=null and major.startDate!=null and major.startDate!=''">
  141. and m.created &gt;= #{major.startDate}
  142. </if>
  143. <if test="major!=null and major.endDate!=null and major.endDate!=''">
  144. and m.created &lt;= #{major.endDate}
  145. </if>
  146. ORDER BY
  147. created DESC
  148. </select>
  149. <select id="selectProduction" parameterType="java.lang.Long" resultType="com.dayou.vo.MajorProductionVO">
  150. select *,sum(amount) as realAmount from (SELECT
  151. mp.id,
  152. mp.report_no,
  153. mp.name,
  154. mp.client_name,
  155. mp.client_tel,
  156. mp.evaluate_acreage,
  157. mp.evaluate_amount,
  158. mp.repertory_state,
  159. mp.if_save_file,
  160. wfni.id AS currentNodeId,
  161. wn.name AS currentNodeName,
  162. wfni.state,
  163. mp.major_id,
  164. pf.real_amount as amount
  165. FROM
  166. (select * from major_production where major_id = #{id} and deleted = 0) mp left join
  167. ( SELECT id, node_id, business_id, business_sub_id, state FROM work_flow_node_instance WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 AND business_id = #{id} and state='PENDING' ) wfni
  168. ON ( wfni.business_id = mp.major_id AND mp.report_no = wfni.business_sub_id )
  169. LEFT JOIN (select id,name from work_node where deleted =0) wn ON wn.id = wfni.node_id
  170. left join (select business_id,business_sub_id,real_amount,production_type from production_fund where deleted = 0) pf on (pf.business_id = mp.major_id and pf.business_sub_id = mp.report_no and pf.production_type = mp.production)) t GROUP BY report_no
  171. order by id DESC
  172. </select>
  173. <select id="getDetail" parameterType="java.lang.Long" resultType="com.dayou.vo.MajorVO">
  174. SELECT
  175. m.id,
  176. m.created,
  177. m.NAME,
  178. m.order_id,
  179. m.financial,
  180. m.allot_type,
  181. m.client_manager_id,
  182. m.principal_id,
  183. m.department_id,
  184. m.business_object_type,
  185. m.special_type,
  186. m.business_gener,
  187. m.evaluate_aim,
  188. m.entrust_again,
  189. m.multiple_removal,
  190. m.informal_evaluate,
  191. m.clientele_type,
  192. m.clientele_id,
  193. m.clientele_sub_id,
  194. m.clientele_contact_id,
  195. m.dispense_benefit,
  196. m.nonnative,
  197. m.refinance,
  198. m.loan_limit,
  199. m.loan_period,
  200. m.loan_nature,
  201. m.loan_aim,
  202. m.loan_expire,
  203. m.bailor,
  204. m.bailor_address,
  205. m.bailor_contact_name,
  206. m.bailor_contact_tel,
  207. m.OWNER,
  208. m.owner_tel,
  209. m.urgent,
  210. m.terminal_clientele_id,
  211. m.terminal_clientele_type,
  212. m.terminal_clientele_contact_id,
  213. m.remark,
  214. m.members,
  215. m.feedback_info,
  216. u.NAME AS clientManager ,
  217. cc1.name as cClienteleName,
  218. cc2.name as cClienteleSubName,
  219. cl1.name as cClienteleContactName,
  220. cl1.mobile as cMobile,
  221. cl1.department as cDepartment,
  222. cl1.duty as cDuty,
  223. cc3.name as tTerminalClienteleName,
  224. cc3.phone as tCompanyMobile,
  225. cl2.name as tTerminalClienteleContactName,
  226. cl2.mobile as tMobile
  227. FROM
  228. major m
  229. LEFT JOIN user u ON u.id = m.client_manager_id
  230. left join customer_company cc1 on cc1.id = m.clientele_id
  231. left join customer_company cc2 on cc2.id = m.clientele_sub_id
  232. left join customer_linkman cl1 on cl1.id = m.clientele_contact_id
  233. left join customer_company cc3 on cc3.id = m.terminal_clientele_id
  234. left join customer_linkman cl2 on cl2.id = m.terminal_clientele_contact_id where m.id =#{id}
  235. </select>
  236. <select id="staticsInformation" resultType="com.dayou.dto.MajorStaticsDTO">
  237. SELECT
  238. (SELECT count(wfni.id) FROM
  239. work_task_record wtr
  240. LEFT JOIN work_node_task wnt ON wnt.id = wtr.task_id
  241. INNER JOIN (
  242. SELECT wfni.id FROM
  243. work_flow_node_instance wfni
  244. LEFT JOIN work_node wn ON wn.id = wfni.node_id
  245. WHERE
  246. wfni.business_type = 'MAJOR_BUSINESS'
  247. AND wfni.state = 'PENDING'
  248. AND wfni.deleted = 0
  249. AND wn.deleted = 0
  250. ) wfni ON wtr.instance_id = wfni.id WHERE
  251. wtr.handler_id =#{userId}
  252. AND wnt.deleted = 0
  253. AND wtr.deleted = 0 ) as majorToDo,
  254. (SELECT count(*) FROM work_flow_log WHERE handler_id = #{userId} and business_type='MAJOR_BUSINESS') as majorDone,
  255. ( SELECT count(*) FROM major_production WHERE deleted = 0 AND if_save_file = 1 ) AS saveFileCount,
  256. ( SELECT count(*) FROM work_flow_node_instance WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 AND state = 'PENDING' ) AS pending,
  257. ( SELECT count(*) FROM major_production WHERE deleted = 0 AND production = 'STATEMENT' and repertory_state is not null ) AS statementCount,
  258. ( SELECT count(*) FROM major_production WHERE deleted = 0 AND production = 'REPORT' and repertory_state is not null ) AS reportCount,
  259. ( SELECT count(*) FROM major_production WHERE deleted = 0 AND production = 'LETTER' and repertory_state is not null ) AS letterCount,
  260. ( SELECT count(*) FROM major_production WHERE deleted = 0 AND repertory_state = 0 ) AS inWarehouseCount
  261. </select>
  262. <select id="xPage" parameterType="com.dayou.vo.MajorVO" resultType="com.dayou.vo.MajorVO">
  263. SELECT
  264. wfni.currentNodeId AS id,
  265. wfni.nodeName,
  266. wfni.productionName,
  267. wfni.business_sub_id AS statementNo,
  268. wfni.business_min_id AS reportNo,
  269. m.id AS majorId,
  270. m.created,
  271. m.NAME,
  272. m.order_id,
  273. m.financial,
  274. m.allot_type,
  275. m.client_manager_id,
  276. u.NAME AS clientManager,
  277. m.principal_id,
  278. u1.NAME AS principal,
  279. m.department_id,
  280. d.NAME AS department,
  281. m.business_object_type,
  282. m.clientele_id,
  283. m.clientele_contact_id,
  284. m.clientele_id AS clientele,
  285. m.clientele_contact_id AS clienteleContact,
  286. cc1.NAME AS cClienteleName,
  287. cc2.NAME AS cClienteleSubName,
  288. cl1.NAME AS cClienteleContactName,
  289. cl1.mobile AS cMobile,
  290. wfni.client_name,
  291. wfni.client_tel,
  292. wfni.evaluate_amount,
  293. wfni.OWNER,
  294. wfni.HANDLER,
  295. wfni.nodeCode,
  296. wfni.currentNodeId
  297. FROM
  298. major m
  299. LEFT JOIN USER u ON u.id = m.client_manager_id
  300. LEFT JOIN USER u1 ON u1.id = m.principal_id
  301. LEFT JOIN department d ON d.id = m.department_id
  302. INNER JOIN (
  303. SELECT
  304. wf.id AS currentNodeId,
  305. wf.node_id,
  306. wf.business_id,
  307. wf.business_sub_id,
  308. wf.business_min_id,
  309. wf.state,
  310. wn.NAME AS nodeName,
  311. mp.NAME AS productionName,
  312. mp.client_name,
  313. mp.client_tel,
  314. mp.evaluate_amount,
  315. mp.OWNER,
  316. u.NAME AS HANDLER,
  317. wn.CODE AS nodeCode
  318. FROM
  319. work_flow_node_instance wf
  320. LEFT JOIN work_node wn ON wn.id = wf.node_id
  321. LEFT JOIN ( SELECT report_no, major_id, NAME, client_name, client_tel, evaluate_amount, OWNER FROM major_production WHERE deleted = 0 ) mp ON ( mp.major_id = wf.business_id AND mp.report_no = ifnull( wf.business_min_id, wf.business_sub_id ) )
  322. LEFT JOIN work_task_record wtr ON wtr.instance_id = wf.id
  323. LEFT JOIN USER u ON u.id = wtr.handler_id
  324. WHERE
  325. wf.business_type = 'MAJOR_BUSINESS'
  326. AND wf.deleted = 0
  327. AND wf.state = 'PENDING'
  328. ) wfni ON wfni.business_id = m.id
  329. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_id
  330. LEFT JOIN customer_company cc2 ON cc2.id = m.clientele_sub_id
  331. LEFT JOIN customer_linkman cl1 ON cl1.id = m.clientele_contact_id
  332. WHERE
  333. m.deleted = 0
  334. <if test="keyword!=null and keyword!='' ">
  335. and (
  336. m.name like concat ('%',#{keyword},'%')
  337. or m.order_id like concat('%',#{keyword},'%')
  338. or u.name like concat('%',#{keyword},'%')
  339. or u1.name like concat('%',#{keyword},'%')
  340. or cc2.name like concat('%',#{keyword},'%')
  341. or cc1.name like concat('%',#{keyword},'%')
  342. or cl1.name like concat('%',#{keyword},'%')
  343. or cl1.mobile like concat('%',#{keyword},'%')
  344. or m.business_object_type like concat('%',#{keyword},'%')
  345. or d.name like concat('%',#{keyword},'%')
  346. or m.allot_type like concat('%',#{keyword},'%')
  347. or wfni.client_name like concat('%',#{keyword},'%')
  348. or wfni.productionName like concat('%',#{keyword},'%')
  349. or wfni.business_sub_id like concat('%',#{keyword},'%')
  350. or wfni.owner like concat('%',#{keyword},'%')
  351. or wfni.business_min_id like concat('%',#{keyword},'%')
  352. )
  353. </if>
  354. <if test="major!=null and major.financial!=null">
  355. and m.financial = #{major.financial}
  356. </if>
  357. <if test="major!=null and major.startDate!=null and major.startDate!=''">
  358. and m.created &gt;= #{major.startDate}
  359. </if>
  360. <if test="major!=null and major.endDate!=null and major.endDate!=''">
  361. and m.created &lt;= #{major.endDate}
  362. </if>
  363. <if test="major!=null and major.nodeCode!=null and major.nodeCode!=''">
  364. and wfni.nodeCode = #{major.nodeCode}
  365. </if>
  366. <if test="major!=null and major.clientName!=null and major.clientName!=''">
  367. and wfni.client_name like concat('%',#{major.clientName},'%')
  368. </if>
  369. <if test="major!=null and major.clientManagerId!=null ">
  370. and m.client_manager_id = #{major.clientManagerId}
  371. </if>
  372. <if test="major!=null and major.principalId!=null ">
  373. and m.principal_id = #{major.principalId}
  374. </if>
  375. <if test="major!=null and major.businessObjectType!=null and major.businessObjectType!=''">
  376. and m.business_object_type = #{major.businessObjectType}
  377. </if>
  378. <if test="major!=null and major.departmentId!=null ">
  379. and m.department_id = #{major.departmentId}
  380. </if>
  381. <if test="major!=null and major.userIds!=null and major.userIds.size!=0">
  382. and (
  383. m.principal_id in
  384. <foreach collection="major.userIds" open="(" close=")" separator="," item="userId">
  385. #{userId}
  386. </foreach>
  387. or
  388. m.client_manager_id in
  389. <foreach collection="major.userIds" open="(" close=")" separator="," item="userId">
  390. #{userId}
  391. </foreach>
  392. )
  393. </if>
  394. or m.principal_id = #{currentUserId} or m.client_manager_id = #{currentUserId}
  395. or JSON_CONTAINS(JSON_EXTRACT(m.members, '$[*]'),CAST(#{currentUserId} AS CHAR))
  396. order by wfni.currentNodeId DESC
  397. </select>
  398. </mapper>