KwmCooperateMapper.xml 16 KB

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