KwmCooperateMapper.xml 15 KB

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