CusFollowMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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.dk.mdm.mapper.mst.CusFollowMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. follow_id, cus_id, follow_status, follow_org, follow_staff, follow_time, follow_data, follow_time_len, stay_time_len, intention, invite_result, invite_time, design_staff, next_follow_plan, next_follow_time, annex_paths, measure_status, remarks, flg_valid, cp_id, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user
  8. </sql>
  9. <sql id="Base_Column_List_Join">
  10. tccf.follow_id, tccf.cus_id, tccf.follow_status, tccf.follow_org, tccf.follow_staff, tccf.follow_time, tccf.follow_data,
  11. tccf.follow_time_len, tccf.stay_time_len, tccf.intention, tccf.invite_result, tccf.invite_time, tccf.design_staff,
  12. tccf.next_follow_plan, tccf.next_follow_time,tccf.annex_paths, tccf.measure_status, tccf.remarks, tccf.flg_valid,
  13. tccf.cp_id
  14. </sql>
  15. <!-- 通用查询映射结果 -->
  16. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.CusFollow">
  17. <id column="follow_id" property="followId"/>
  18. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  19. <result column="follow_status" property="followStatus"/>
  20. <result column="follow_org" property="followOrg" typeHandler="UuidTypeHandler"/>
  21. <result column="follow_staff" property="followStaff" typeHandler="UuidTypeHandler"/>
  22. <result column="follow_time" property="followTime" typeHandler="TimestampTypeHandler"/>
  23. <result column="follow_data" property="followData"/>
  24. <result column="follow_time_len" property="followTimeLen"/>
  25. <result column="stay_time_len" property="stayTimeLen"/>
  26. <result column="intention" property="intention"/>
  27. <result column="invite_result" property="inviteResult"/>
  28. <result column="invite_time" property="inviteTime" typeHandler="TimestampTypeHandler"/>
  29. <result column="design_staff" property="designStaff" typeHandler="UuidTypeHandler"/>
  30. <result column="next_follow_plan" property="nextFollowPlan"/>
  31. <result column="next_follow_time" property="nextFollowTime" typeHandler="TimestampTypeHandler"/>
  32. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  33. <result column="measure_status" property="measureStatus"/>
  34. <result column="remarks" property="remarks"/>
  35. <result column="flg_valid" property="flgValid"/>
  36. <result column="cp_id" property="cpId"/>
  37. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  38. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  39. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  40. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  41. <result column="op_app_code" property="opAppCode"/>
  42. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  43. <result column="op_db_user" property="opDbUser"/>
  44. </resultMap>
  45. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.mst.CusFollowResponse">
  46. <id column="follow_id" property="followId"/>
  47. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  48. <result column="follow_status" property="followStatus"/>
  49. <result column="follow_org" property="followOrg" typeHandler="UuidTypeHandler"/>
  50. <result column="follow_staff" property="followStaff" typeHandler="UuidTypeHandler"/>
  51. <result column="follow_time" property="followTime" typeHandler="TimestampTypeHandler"/>
  52. <result column="follow_data" property="followData"/>
  53. <result column="follow_time_len" property="followTimeLen"/>
  54. <result column="stay_time_len" property="stayTimeLen"/>
  55. <result column="intention" property="intention"/>
  56. <result column="invite_result" property="inviteResult"/>
  57. <result column="invite_time" property="inviteTime" typeHandler="TimestampTypeHandler"/>
  58. <result column="design_staff" property="designStaff" typeHandler="UuidTypeHandler"/>
  59. <result column="next_follow_plan" property="nextFollowPlan"/>
  60. <result column="next_follow_time" property="nextFollowTime" typeHandler="TimestampTypeHandler"/>
  61. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  62. <result column="measure_status" property="measureStatus"/>
  63. <result column="remarks" property="remarks"/>
  64. <result column="flg_valid" property="flgValid"/>
  65. <result column="cp_id" property="cpId"/>
  66. <result column="sale_status" property="saleStatus"/>
  67. <result column="channel_id" property="channelId"/>
  68. <result column="cusName" property="cusName"/>
  69. <result column="cusCode" property="cusCode"/>
  70. <result column="orgName" property="orgName"/>
  71. <result column="staffName" property="staffName"/>
  72. <result column="follow_count" property="followCount"/>
  73. <result column="follow_staff_name" property="followStaffName"/>
  74. <result column="create_time" property="createTime" typeHandler="TimestampTypeHandler"/>
  75. <result column="follow_status_name" property="followStatusName"/>
  76. <result column="cus_name" property="cusName"/>
  77. <result column="cus_code" property="cusCode"/>
  78. <result column="cus_phone" property="cusPhone"/>
  79. <result column="address_full" property="addressFull"/>
  80. <result column="address_no" property="addressNo"/>
  81. <result column="address_name" property="addressName"/>
  82. <result column="intention_name" property="intentionName"/>
  83. <result column="stay_time_len_name" property="stayTimeLenName"/>
  84. <result column="address_area" property="addressArea" typeHandler="JsonTypeHandler"/>
  85. <result column="address_gcj02" property="addressGcj02" typeHandler="JsonTypeHandler"/>
  86. </resultMap>
  87. <!-- 通用条件列 -->
  88. <sql id="Condition">
  89. <where>
  90. <if test="cusId != null and cusId != ''">
  91. AND cus_id = #{cusId}
  92. </if>
  93. <if test="followStatus != null and followStatus != ''">
  94. AND follow_status = #{followStatus}
  95. </if>
  96. <if test="followOrg != null and followOrg != ''">
  97. AND follow_org = #{followOrg}
  98. </if>
  99. <if test="followStaff != null and followStaff != ''">
  100. AND follow_staff = #{followStaff}
  101. </if>
  102. <if test="followTime != null">
  103. AND follow_time = #{followTime}
  104. </if>
  105. <if test="followData != null and followData != ''">
  106. AND follow_data = #{followData}
  107. </if>
  108. <if test="followTimeLen != null">
  109. AND follow_time_len = #{followTimeLen}
  110. </if>
  111. <if test="stayTimeLen != null and stayTimeLen != ''">
  112. AND stay_time_len = #{stayTimeLen}
  113. </if>
  114. <if test="intention != null and intention != ''">
  115. AND intention = #{intention}
  116. </if>
  117. <if test="inviteResult != null and inviteResult != ''">
  118. AND invite_result = #{inviteResult}
  119. </if>
  120. <if test="inviteTime != null">
  121. AND invite_time = #{inviteTime}
  122. </if>
  123. <if test="designStaff != null and designStaff != ''">
  124. AND design_staff = #{designStaff}
  125. </if>
  126. <if test="nextFollowPlan != null and nextFollowPlan != ''">
  127. AND next_follow_plan = #{nextFollowPlan}
  128. </if>
  129. <if test="nextFollowTime != null">
  130. AND next_follow_time = #{nextFollowTime}
  131. </if>
  132. <if test="annexPaths != null and annexPaths != ''">
  133. AND annex_paths = #{annexPaths}
  134. </if>
  135. <if test="measureStatus != null and measureStatus != ''">
  136. AND measure_status = #{measureStatus}
  137. </if>
  138. <if test="remarks != null and remarks != ''">
  139. AND remarks = #{remarks}
  140. </if>
  141. <if test="flgValid != null">
  142. AND flg_valid = #{flgValid}
  143. </if>
  144. <if test="cpId != null">
  145. AND cp_id = #{cpId}
  146. </if>
  147. <if test="opCreateTime != null">
  148. AND op_create_time = #{opCreateTime}
  149. </if>
  150. <if test="opCreateUserId != null and opCreateUserId != ''">
  151. AND op_create_user_id = #{opCreateUserId}
  152. </if>
  153. <if test="opUpdateTime != null">
  154. AND op_update_time = #{opUpdateTime}
  155. </if>
  156. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  157. AND op_update_user_id = #{opUpdateUserId}
  158. </if>
  159. <if test="opAppCode != null and opAppCode != ''">
  160. AND op_app_code = #{opAppCode}
  161. </if>
  162. <if test="opTimestamp != null">
  163. AND op_timestamp = #{opTimestamp}
  164. </if>
  165. <if test="opDbUser != null and opDbUser != ''">
  166. AND op_db_user = #{opDbUser}
  167. </if>
  168. </where>
  169. </sql>
  170. <sql id="Condition_Join">
  171. <where>
  172. <if test="cusId != null and cusId != ''">
  173. AND tccf.cus_id = #{cusId}::uuid
  174. </if>
  175. <if test="followStatus != null and followStatus != ''">
  176. AND tccf.follow_status = #{followStatus}
  177. </if>
  178. <if test="followOrg != null and followOrg != ''">
  179. AND tccf.follow_org = #{followOrg}
  180. </if>
  181. <if test="followStaff != null and followStaff != ''">
  182. AND tccf.follow_staff = #{followStaff}
  183. </if>
  184. <if test="followTime != null">
  185. AND tccf.follow_time = #{followTime}
  186. </if>
  187. <if test="followData != null and followData != ''">
  188. AND tccf.follow_data = #{followData}
  189. </if>
  190. <if test="followTimeLen != null">
  191. AND tccf.follow_time_len = #{followTimeLen}
  192. </if>
  193. <if test="stayTimeLen != null and stayTimeLen != ''">
  194. AND tccf.stay_time_len = #{stayTimeLen}
  195. </if>
  196. <if test="intention != null and intention != ''">
  197. AND tccf.intention = #{intention}
  198. </if>
  199. <if test="inviteResult != null and inviteResult != ''">
  200. AND tccf.invite_result = #{inviteResult}
  201. </if>
  202. <if test="inviteTime != null">
  203. AND tccf.invite_time = #{inviteTime}
  204. </if>
  205. <if test="designStaff != null and designStaff != ''">
  206. AND tccf.design_staff = #{designStaff}
  207. </if>
  208. <if test="nextFollowPlan != null and nextFollowPlan != ''">
  209. AND tccf.next_follow_plan = #{nextFollowPlan}
  210. </if>
  211. <if test="nextFollowTime != null">
  212. AND tccf.next_follow_time = #{nextFollowTime}
  213. </if>
  214. <if test="annexPaths != null and annexPaths != ''">
  215. AND tccf.annex_paths = #{annexPaths}
  216. </if>
  217. <if test="measureStatus != null and measureStatus != ''">
  218. AND tccf.measure_status = #{measureStatus}
  219. </if>
  220. <if test="remarks != null and remarks != ''">
  221. AND tccf.remarks = #{remarks}
  222. </if>
  223. <if test="flgValid != null">
  224. AND tccf.flg_valid = #{flgValid}
  225. </if>
  226. <if test="cpId != null">
  227. AND tccf.cp_id = #{cpId}
  228. </if>
  229. </where>
  230. </sql>
  231. <sql id="idsForeach">
  232. <!-- 根据主键followId批量操作 -->
  233. WHERE follow_id in
  234. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  235. #{item}
  236. </foreach>
  237. </sql>
  238. <!-- 查询表t_crm_cus_follow,(条件查询+分页)列表 -->
  239. <select id="selectByCond" resultMap="BaseResultMapResponse">
  240. SELECT
  241. <include refid="Base_Column_List_Join"/>,
  242. (CASE
  243. WHEN tccf.follow_status = '跟进状态-接待' THEN '无联系人'
  244. ELSE tmc.cus_name END ) AS cus_name,
  245. tmc.cus_code as cus_code,
  246. tmc.cus_phone AS cus_phone,
  247. tmc.sale_status AS sale_status,
  248. tmc.channel_id AS channel_id,
  249. tmc.address_full AS address_full,
  250. tmc.address_area AS address_area,
  251. tmc.address_gcj02 AS address_gcj02,
  252. tmc.address_name AS address_name,
  253. tmc.address_no AS address_no,
  254. tmo.org_name AS "orgName",
  255. tms.staff_name AS "staffName",
  256. tmc.follow_count AS follow_count,
  257. tdk1.kind_name_i18n ->> 'zh_CN' AS "follow_status_name",
  258. tdk2.kind_name_i18n ->> 'zh_CN' AS intention_name,
  259. tdk3.kind_name_i18n ->> 'zh_CN' AS stay_time_len_name
  260. FROM dkic_b.t_crm_cus_follow tccf
  261. LEFT JOIN dkic_b.t_mst_customer tmc ON tmc.cus_id = tccf.cus_id
  262. LEFT JOIN dkic_b.t_mst_org tmo on tmo.org_id = tccf.follow_org
  263. LEFT JOIN dkic_b.t_mst_staff tms on tms.staff_id = tccf.follow_staff
  264. LEFT JOIN sys.t_data_kind tdk1 on tdk1.kind_code = tccf.follow_status
  265. LEFT JOIN sys.t_data_kind tdk2 on tdk2.kind_code = tccf.intention
  266. LEFT JOIN sys.t_data_kind tdk3 on tdk3.kind_code = tccf.stay_time_len
  267. <include refid="Condition_Join"/>
  268. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  269. limit #{end} offset #{start}
  270. </if>
  271. </select>
  272. <!--查询跟进记录-->
  273. <select id="selectByList" resultMap="BaseResultMapResponse">
  274. SELECT
  275. <include refid="Base_Column_List_Join"/>,
  276. tmc.cus_name AS "cusName",
  277. tmc.cus_code as "cusCode",
  278. tmc.cus_phone AS "cusPhone",
  279. tmc.address_full AS "addressFull",
  280. tmo.org_name AS "orgName",
  281. tms.staff_name AS "staffName",
  282. tmc.follow_count AS follow_count,
  283. tms.staff_name AS follow_staff_name,
  284. tccf.op_create_time AS create_time,
  285. tdk1.kind_name_i18n ->> 'zh_CN' AS "follow_status_name"
  286. FROM dkic_b.t_crm_cus_follow tccf
  287. LEFT JOIN dkic_b.t_mst_customer tmc ON tmc.cus_id = tccf.cus_id
  288. LEFT JOIN dkic_b.t_mst_org tmo on tmo.org_id = tccf.follow_org
  289. LEFT JOIN dkic_b.t_mst_staff tms on tms.staff_id = tccf.follow_staff
  290. LEFT JOIN sys.t_data_kind tdk1 on tdk1.kind_code = tccf.follow_status
  291. <include refid="Condition_Join"/>
  292. </select>
  293. <!-- 查询表t_crm_cus_follow,(条件查询)个数 -->
  294. <select id="countByCond" resultType="Long">
  295. SELECT
  296. count(1)
  297. FROM dkic_b.t_crm_cus_follow tccf
  298. <include refid="Condition_Join"/>
  299. </select>
  300. <!-- 根据主键查询表t_crm_cus_follow的一行数据 -->
  301. <select id="selectById" resultMap="BaseResultMap">
  302. SELECT
  303. <include refid="Base_Column_List"/>
  304. FROM dkic_b.t_crm_cus_follow
  305. WHERE follow_id = #{followId}::uuid
  306. </select>
  307. <!-- 根据主键锁定表t_crm_cus_follow的一行数据 -->
  308. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  309. SELECT
  310. <include refid="Base_Column_List"/>
  311. FROM dkic_b.t_crm_cus_follow
  312. WHERE follow_id = #{followId}
  313. for update
  314. </select>
  315. <!-- 根据主键锁定表t_crm_cus_follow的多行数据 -->
  316. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  317. SELECT
  318. <include refid="Base_Column_List"/>
  319. FROM dkic_b.t_crm_cus_follow
  320. <include refid="idsForeach"/>
  321. for update
  322. </select>
  323. <insert id="insertBatch">
  324. insert into dkic_b.t_crm_cus_follow
  325. (
  326. <trim suffixOverrides=",">
  327. cus_id,
  328. follow_status,
  329. follow_org,
  330. follow_staff,
  331. follow_time,
  332. follow_data,
  333. follow_time_len,
  334. stay_time_len,
  335. intention,
  336. invite_result,
  337. invite_time,
  338. design_staff,
  339. next_follow_plan,
  340. next_follow_time,
  341. annex_paths,
  342. measure_status,
  343. remarks,
  344. cp_id,
  345. op_app_code,
  346. </trim>
  347. )
  348. values
  349. <foreach collection="list" index="index" item="item" separator=",">
  350. (
  351. <trim suffixOverrides=",">
  352. #{item.cusId}::uuid,
  353. #{item.followStatus},
  354. #{item.followOrg}::uuid,
  355. #{item.followStaff}::uuid,
  356. #{item.followTime},
  357. #{item.followData},
  358. #{item.followTimeLen},
  359. #{item.stayTimeLen},
  360. #{item.intention},
  361. #{item.inviteResult},
  362. #{item.inviteTime},
  363. #{item.designStaff}::uuid,
  364. #{item.nextFollowPlan},
  365. #{item.nextFollowTime},
  366. #{item.annexPaths},
  367. #{item.measureStatus},
  368. #{item.remarks},
  369. #{item.cpId},
  370. #{item.opAppCode},
  371. </trim>
  372. )
  373. </foreach>
  374. </insert>
  375. </mapper>