KwmCooperateMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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.sckw.manage.dao.KwmCooperateMapper">
  6. <select id="findList" parameterType="com.sckw.manage.model.dto.req.CooperateManageQueryReqDto"
  7. resultType="com.sckw.manage.model.dto.res.CooperateManageQueryResDto">
  8. SELECT a.id,
  9. b.status,
  10. group_concat(b.type) types,
  11. min(a.ent_id) entId,
  12. min(a.invitee_ent_id) inviteeEntId,
  13. min(a.inviter_ent_id) inviterEntId,
  14. min(a.invitee_contacts) inviteeContacts,
  15. min(a.inviter_contacts) inviterContacts,
  16. min(a.invitee_contacts_id) inviteeContactsId,
  17. min(a.inviter_contacts_id) inviterContactsId,
  18. min(a.invitee_phone) inviteePhone,
  19. min(a.inviter_phone) inviterPhone,
  20. min(b.create_time) createTime,
  21. min(b.create_by) createBy,
  22. min(a.remark) remark,
  23. min(a.approval_remark) approvalRemark,
  24. case when min(a.ent_id) = #{reqDto.currentEntId} then min(a.invitee_ent_id) else min(a.inviter_ent_id) end targetEntId,
  25. case when min(a.ent_id) = #{reqDto.currentEntId} then min(a.inviter_ent_id) else min(a.invitee_ent_id) end ourEntId,
  26. case when min(a.ent_id) = #{reqDto.currentEntId} then 1 else 2 end applyTypeCode
  27. FROM kwm_cooperate a
  28. LEFT JOIN kwm_cooperate_type b ON a.id = b.cooperate_id
  29. WHERE a.del_flag = 0
  30. and ((a.invitee_ent_id in
  31. <foreach collection="reqDto.currentEntIdList" item="item" open="(" close=")" separator=",">
  32. #{item}
  33. </foreach>
  34. <if test="reqDto.targetEntIdList != null and reqDto.targetEntIdList.size() > 0">
  35. and (a.inviter_ent_id in
  36. <foreach collection="reqDto.targetEntIdList" item="item" open="(" close=")" separator=",">
  37. #{item}
  38. </foreach>
  39. or a.inviter_contacts like concat('%', #{reqDto.keywords}, '%') or
  40. a.inviter_phone like concat('%', #{reqDto.keywords}, '%')
  41. )
  42. </if>
  43. ) OR
  44. (a.inviter_ent_id in
  45. <foreach collection="reqDto.currentEntIdList" item="item" open="(" close=")" separator=",">
  46. #{item}
  47. </foreach>
  48. <if test="reqDto.targetEntIdList != null and reqDto.targetEntIdList.size() > 0">
  49. and (a.invitee_ent_id in
  50. <foreach collection="reqDto.targetEntIdList" item="item" open="(" close=")" separator=",">
  51. #{item}
  52. </foreach>
  53. or a.invitee_contacts like concat('%', #{reqDto.keywords}, '%') or
  54. a.invitee_phone like concat('%', #{reqDto.keywords}, '%')
  55. )
  56. </if>
  57. ))
  58. <if test="reqDto.startTime != null">
  59. and b.create_time >= #{reqDto.startTime}
  60. </if>
  61. <if test="reqDto.endTime != null">
  62. and b.create_time &lt; date_add(#{reqDto.endTime}, INTERVAL 1 DAY)
  63. </if>
  64. <if test="reqDto.applyTypeCode != null and reqDto.applyTypeCode == 1">
  65. and b.create_by in
  66. <foreach collection="reqDto.currentUserIdList" item="item" open="(" close=")" separator=",">
  67. #{item}
  68. </foreach>
  69. </if>
  70. <if test="reqDto.applyTypeCode != null and reqDto.applyTypeCode == 2">
  71. and b.create_by not in
  72. <foreach collection="reqDto.currentUserIdList" item="item" open="(" close=")" separator=",">
  73. #{item}
  74. </foreach>
  75. </if>
  76. <if test="reqDto.cooperateTypes != null and reqDto.cooperateTypes.size() > 0">
  77. and exists (select 1
  78. from kwm_cooperate_type c
  79. where c.cooperate_id = a.id
  80. and c.status = b.status
  81. and c.del_flag = 0
  82. and c.type in
  83. <foreach collection="reqDto.cooperateTypes" item="item" open="(" close=")" separator=",">
  84. #{item}
  85. </foreach>
  86. )
  87. </if>
  88. <if test="reqDto.status != null and reqDto.status.size() > 0">
  89. and b.status in
  90. <foreach collection="reqDto.status" item="item" open="(" close=")" separator=",">
  91. #{item}
  92. </foreach>
  93. </if>
  94. <if test="reqDto.keywords != null and (reqDto.targetEntIdList == null or reqDto.targetEntIdList.size() == 0)">
  95. and (a.invitee_contacts like concat('%', #{reqDto.keywords}, '%') or
  96. a.inviter_contacts like concat('%', #{reqDto.keywords}, '%') or
  97. a.invitee_phone like concat('%', #{reqDto.keywords}, '%') or
  98. a.inviter_phone like concat('%', #{reqDto.keywords}, '%')
  99. )
  100. </if>
  101. <if test="reqDto.ids != null and reqDto.ids.size() > 0">
  102. and a.id in
  103. <foreach collection="reqDto.ids" item="item" open="(" close=")" separator=",">
  104. #{item}
  105. </foreach>
  106. </if>
  107. group by a.id, b.status
  108. order by a.create_time desc
  109. </select>
  110. <select id="findCooperateByEnt" resultType="com.sckw.manage.model.entity.KwmCooperate">
  111. select a.*
  112. from kwm_cooperate a
  113. where a.del_flag = 0
  114. and a.status = 1
  115. and ((a.inviter_ent_id = #{entId}
  116. <if test="targetEntId != null">
  117. and a.invitee_ent_id = #{targetEntId}
  118. </if>
  119. )
  120. or
  121. (a.invitee_ent_id = #{entId}
  122. <if test="targetEntId != null">
  123. and a.inviter_ent_id = #{targetEntId}
  124. </if>
  125. ))
  126. <!-- <if test="cooperateType != null">-->
  127. <!-- and exists (select 1-->
  128. <!-- from kwm_cooperate_type c-->
  129. <!-- where c.cooperate_id = a.id-->
  130. <!-- and c.del_flag = 0-->
  131. <!-- and c.type = #{cooperateType}-->
  132. <!-- )-->
  133. <!-- </if>-->
  134. </select>
  135. <select id="findManageList" resultType="com.sckw.manage.model.dto.res.CooperateManageQueryResDto">
  136. SELECT a.id,
  137. min(a.status) status,
  138. group_concat(concat(b.type, '#', b.create_by)) types,
  139. min(a.ent_id) entId,
  140. min(a.invitee_ent_id) inviteeEntId,
  141. min(a.inviter_ent_id) inviterEntId,
  142. min(a.invitee_contacts) inviteeContacts,
  143. min(a.inviter_contacts) inviterContacts,
  144. min(a.invitee_contacts_id) inviteeContactsId,
  145. min(a.inviter_contacts_id) inviterContactsId,
  146. min(a.invitee_phone) inviteePhone,
  147. min(a.inviter_phone) inviterPhone,
  148. min(b.create_time) createTime,
  149. min(b.create_by) createBy,
  150. group_concat(b.create_by) createByStr,
  151. min(a.remark) remark,
  152. min(a.approval_remark) approvalRemark,
  153. case when min(a.ent_id) = #{reqDto.currentEntId} then min(a.invitee_ent_id) else min(a.inviter_ent_id) end targetEntId,
  154. case when min(a.ent_id) = #{reqDto.currentEntId} then min(a.inviter_ent_id) else min(a.invitee_ent_id) end ourEntId,
  155. case when min(a.ent_id) = #{reqDto.currentEntId} then 1 else 2 end applyTypeCode
  156. FROM kwm_cooperate a
  157. LEFT JOIN kwm_cooperate_type b ON a.id = b.cooperate_id and b.status = 1 and b.del_flag = 0
  158. WHERE a.del_flag = 0
  159. and ((a.invitee_ent_id in
  160. <foreach collection="reqDto.currentEntIdList" item="item" open="(" close=")" separator=",">
  161. #{item}
  162. </foreach>
  163. <if test="reqDto.targetEntIdList != null and reqDto.targetEntIdList.size() > 0">
  164. and (a.inviter_ent_id in
  165. <foreach collection="reqDto.targetEntIdList" item="item" open="(" close=")" separator=",">
  166. #{item}
  167. </foreach>
  168. or a.inviter_contacts like concat('%', #{reqDto.keywords}, '%') or
  169. a.inviter_phone like concat('%', #{reqDto.keywords}, '%')
  170. )
  171. </if>
  172. )
  173. OR (a.inviter_ent_id in
  174. <foreach collection="reqDto.currentEntIdList" item="item" open="(" close=")" separator=",">
  175. #{item}
  176. </foreach>
  177. <if test="reqDto.targetEntIdList != null and reqDto.targetEntIdList.size() > 0">
  178. and (a.invitee_ent_id in
  179. <foreach collection="reqDto.targetEntIdList" item="item" open="(" close=")" separator=",">
  180. #{item}
  181. </foreach>
  182. or a.invitee_contacts like concat('%', #{reqDto.keywords}, '%') or
  183. a.invitee_phone like concat('%', #{reqDto.keywords}, '%')
  184. )
  185. </if>
  186. ))
  187. <if test="reqDto.startTime != null">
  188. and b.create_time >= #{reqDto.startTime}
  189. </if>
  190. <if test="reqDto.endTime != null">
  191. and b.create_time &lt; date_add(#{reqDto.endTime}, INTERVAL 1 DAY)
  192. </if>
  193. <if test="reqDto.applyTypeCode != null and reqDto.applyTypeCode == 1">
  194. and b.create_by in
  195. <foreach collection="reqDto.currentUserIdList" item="item" open="(" close=")" separator=",">
  196. #{item}
  197. </foreach>
  198. </if>
  199. <if test="reqDto.applyTypeCode != null and reqDto.applyTypeCode == 2">
  200. and b.create_by not in
  201. <foreach collection="reqDto.currentUserIdList" item="item" open="(" close=")" separator=",">
  202. #{item}
  203. </foreach>
  204. </if>
  205. <if test="reqDto.cooperateTypes != null and reqDto.cooperateTypes.size() > 0">
  206. and exists (select 1
  207. from kwm_cooperate_type c
  208. where c.cooperate_id = a.id
  209. and c.status = 1
  210. and c.del_flag = 0
  211. and c.type in
  212. <foreach collection="reqDto.cooperateTypes" item="item" open="(" close=")" separator=",">
  213. #{item}
  214. </foreach>
  215. )
  216. </if>
  217. <if test="reqDto.status != null and reqDto.status.size() > 0">
  218. and a.status in
  219. <foreach collection="reqDto.status" item="item" open="(" close=")" separator=",">
  220. #{item}
  221. </foreach>
  222. </if>
  223. <if test="reqDto.keywords != null and (reqDto.targetEntIdList == null or reqDto.targetEntIdList.size() == 0)">
  224. and (a.invitee_contacts like concat('%', #{reqDto.keywords}, '%') or
  225. a.inviter_contacts like concat('%', #{reqDto.keywords}, '%') or
  226. a.invitee_phone like concat('%', #{reqDto.keywords}, '%') or
  227. a.inviter_phone like concat('%', #{reqDto.keywords}, '%')
  228. )
  229. </if>
  230. <if test="reqDto.ids != null and reqDto.ids.size() > 0">
  231. and a.id in
  232. <foreach collection="reqDto.ids" item="item" open="(" close=")" separator=",">
  233. #{item}
  234. </foreach>
  235. </if>
  236. group by a.id
  237. order by a.create_time desc
  238. </select>
  239. <select id="findEntCooperate" resultType="com.sckw.manage.model.entity.KwmCooperate">
  240. select a.* from kwm_cooperate a
  241. where a.del_flag = 0
  242. and a.status = 1
  243. and ((a.inviter_ent_id = #{id}
  244. <if test="targetEntId != null">
  245. and a.invitee_ent_id = #{targetEntId}
  246. </if>) or
  247. (a.invitee_ent_id = #{id}
  248. <if test="targetEntId != null">
  249. and a.inviter_ent_id = #{targetEntId}
  250. </if>)
  251. )
  252. </select>
  253. <select id="queryAllCooperateInfoList"
  254. resultType="com.sckw.manage.model.dto.res.CooperateManageQueryResDto">
  255. SELECT a.id,
  256. min(a.status) status,
  257. group_concat(b.type) types,
  258. min(a.ent_id) entId,
  259. min(a.invitee_ent_id) inviteeEntId,
  260. min(a.inviter_ent_id) inviterEntId,
  261. min(a.invitee_contacts) inviteeContacts,
  262. min(a.inviter_contacts) inviterContacts,
  263. min(a.invitee_contacts_id) inviteeContactsId,
  264. min(a.inviter_contacts_id) inviterContactsId,
  265. min(a.invitee_phone) inviteePhone,
  266. min(a.inviter_phone) inviterPhone,
  267. min(b.create_time) createTime,
  268. min(b.update_time) updateTime,
  269. min(b.create_by) createBy,
  270. min(a.remark) remark
  271. FROM kwm_cooperate a
  272. LEFT JOIN kwm_cooperate_type b ON a.id = b.cooperate_id and b.status = 1 and b.del_flag = 0
  273. WHERE a.del_flag = 0
  274. and a.status in (1,2)
  275. <if test="reqDto.cooperateTypes != null and reqDto.cooperateTypes.size() > 0">
  276. and exists (select 1
  277. from kwm_cooperate_type c
  278. where c.cooperate_id = a.id
  279. and c.status = b.status
  280. and c.del_flag = 0
  281. and c.type in
  282. <foreach collection="reqDto.cooperateTypes" item="item" open="(" close=")" separator=",">
  283. #{item}
  284. </foreach>
  285. )
  286. </if>
  287. <if test="reqDto.startTime != null">
  288. and b.create_time >= #{reqDto.startTime}
  289. </if>
  290. <if test="reqDto.endTime != null">
  291. and b.create_time &lt; date_add(#{reqDto.endTime}, INTERVAL 1 DAY)
  292. </if>
  293. <if test="reqDto.ids != null and reqDto.ids.size() > 0">
  294. and a.id in
  295. <foreach collection="reqDto.ids" separator="," open="(" close=")" item="item">
  296. #{item}
  297. </foreach>
  298. </if>
  299. <if test="reqDto.queryEntIdList != null and reqDto.queryEntIdList.size() > 0">
  300. and (a.inviter_ent_id in
  301. <foreach collection="reqDto.queryEntIdList" item="item" open="(" close=")" separator=",">
  302. #{item}
  303. </foreach>
  304. or
  305. a.invitee_ent_id in
  306. <foreach collection="reqDto.queryEntIdList" item="item" open="(" close=")" separator=",">
  307. #{item}
  308. </foreach>
  309. )
  310. </if>
  311. <if test="reqDto.keywords != null and (reqDto.queryEntIdList == null or reqDto.queryEntIdList.size() == 0)">
  312. and (a.invitee_contacts like concat('%', #{reqDto.keywords}, '%') or
  313. a.inviter_contacts like concat('%', #{reqDto.keywords}, '%') or
  314. a.invitee_phone like concat('%', #{reqDto.keywords}, '%') or
  315. a.inviter_phone like concat('%', #{reqDto.keywords}, '%')
  316. )
  317. </if>
  318. group by a.id
  319. order by a.create_time desc
  320. </select>
  321. </mapper>