CustomMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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.management.platform.mapper.CustomMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.management.platform.entity.Custom">
  6. <id column="id" property="id" />
  7. <result column="company_id" property="companyId" />
  8. <result column="custom_name" property="customName" />
  9. <result column="custom_source_id" property="customSourceId" />
  10. <result column="customer_industry_id" property="customerIndustryId" />
  11. <result column="customer_level_id" property="customerLevelId" />
  12. <result column="email" property="email" />
  13. <result column="owner_id" property="ownerId" />
  14. <result column="custom_code" property="customCode" />
  15. <result column="tel_phone" property="telPhone" />
  16. <result column="fax" property="fax" />
  17. <result column="country_billing" property="countryBilling" />
  18. <result column="province_billing" property="provinceBilling" />
  19. <result column="city_billing" property="cityBilling" />
  20. <result column="street_billing" property="streetBilling" />
  21. <result column="country_delivery" property="countryDelivery" />
  22. <result column="province_delivery" property="provinceDelivery" />
  23. <result column="city_delivery" property="cityDelivery" />
  24. <result column="street_delivery" property="streetDelivery" />
  25. <result column="create_time" property="createTime" />
  26. <result column="plate1" property="plate1" />
  27. <result column="plate2" property="plate2" />
  28. <result column="plate3" property="plate3" />
  29. <result column="plate4" property="plate4" />
  30. <result column="plate5" property="plate5" />
  31. <result column="creator_id" property="creatorId" />
  32. <result column="custom_desc" property="customDesc" />
  33. <result column="is_delete" property="isDelete" />
  34. <result column="company_phone" property="companyPhone" />
  35. <result column="incharger_id" property="inchargerId" />
  36. <result column="address" property="address" />
  37. <result column="close_deal" property="closeDeal" />
  38. </resultMap>
  39. <!-- 通用查询结果列 -->
  40. <sql id="Base_Column_List">
  41. id, company_id, custom_name, custom_source_id, customer_industry_id, customer_level_id, email, owner_id, custom_code, tel_phone, fax, country_billing, province_billing, city_billing, street_billing, country_delivery, province_delivery, city_delivery, street_delivery, create_time, plate1, plate2, plate3, plate4, plate5, creator_id, custom_desc, is_delete, company_phone, incharger_id, address, close_deal
  42. </sql>
  43. <select id="getList" resultType="com.management.platform.entity.Custom">
  44. select
  45. c.id,
  46. c.contacts_name,
  47. c.custom_name,
  48. c.email,
  49. c.company_phone,
  50. c.create_time,
  51. c.customer_level_id,
  52. (select name from sys_dict where customer_level_id = id and code = 'CustomLevel') customerLevelValue,
  53. c.customer_industry_id,
  54. (select name from sys_dict where customer_industry_id = id and code = 'CustomIndustry') customerIndustryValue,
  55. c.custom_source_id,
  56. (select name from sys_dict where custom_source_id = id) customSourceValue,
  57. c.incharger_id,
  58. (select `name` from `user` where id = incharger_id) inchargerName,
  59. c.creator_id,
  60. (select `name` from `user` where id = creator_id) creatorName
  61. from custom c
  62. left join sys_dict sd on c.customer_level_id = sd.id
  63. where c.company_id = #{companyId}
  64. and c.is_delete =#{isDelete}
  65. <if test="inchargerId != null and inchargerId != '' ">
  66. and c.incharger_id =#{inchargerId}
  67. </if>
  68. <if test="startTime != null and endTime != null ">
  69. and c.create_time BETWEEN #{startTime} and #{endTime}
  70. </if>
  71. <if test="customName != null and customName != '' ">
  72. and c.custom_name LIKE CONCAT('%', #{customName}, '%')
  73. </if>
  74. <if test="email != null and email != '' ">
  75. and c.email LIKE CONCAT('%', #{email}, '%')
  76. </if>
  77. <if test="companyPhone != null ">
  78. and c.company_phone = #{companyPhone}
  79. </if>
  80. <if test="customerLevelId != null ">
  81. and c.customer_level_id = #{customerLevelId}
  82. </if>
  83. <if test="customSourceId != null ">
  84. and c.custom_source_id = #{customSourceId}
  85. </if>
  86. <if test="customerIndustryId != null ">
  87. and c.customer_industry_id = #{customerIndustryId}
  88. </if>
  89. ORDER BY
  90. <choose>
  91. <when test="isDesc == null ">
  92. c.id DESC
  93. </when>
  94. <when test="isDesc == 0">
  95. sd.seq ASC, c.id DESC
  96. </when>
  97. <when test="isDesc == 1">
  98. sd.seq DESC, c.id DESC
  99. </when>
  100. <otherwise>
  101. c.id DESC
  102. </otherwise>
  103. </choose>
  104. Limit #{pageIndex},#{pageFrom}
  105. </select>
  106. <select id="getTotal" resultType="java.lang.Integer">
  107. select count(id)
  108. from custom
  109. where company_id = #{companyId}
  110. and is_delete =#{isDelete}
  111. <if test="inchargerId != null and inchargerId != '' ">
  112. and incharger_id =#{inchargerId}
  113. </if>
  114. <if test="startTime != null and endTime != null ">
  115. and create_time BETWEEN #{startTime} and #{endTime}
  116. </if>
  117. <if test="customName != null and customName != '' ">
  118. and custom_name = #{customName}
  119. </if>
  120. <if test="email != null and email != '' ">
  121. and email = #{email}
  122. </if>
  123. <if test="companyPhone != null ">
  124. and company_phone = #{companyPhone}
  125. </if>
  126. <if test="customerLevelId != null ">
  127. and customer_level_id = #{customerLevelId}
  128. </if>
  129. <if test="customSourceId != null ">
  130. and custom_source_id = #{customSourceId}
  131. </if>
  132. <if test="customerIndustryId != null ">
  133. and customer_industry_id = #{customerIndustryId}
  134. </if>
  135. </select>
  136. <select id="getList1" resultType="com.management.platform.entity.Custom">
  137. select c.id,
  138. c.custom_name,
  139. c.email,
  140. c.company_phone,
  141. c.create_time,
  142. c.customer_level_id,
  143. (select name from sys_dict where customer_level_id = id and code = 'CustomLevel') customerLevelValue,
  144. c.customer_industry_id,
  145. (select name from sys_dict where customer_industry_id = id and code = 'CustomIndustry') customerIndustryValue,
  146. c.custom_source_id,
  147. (select name from sys_dict where custom_source_id = id ) customSourceValue,
  148. c.incharger_id,
  149. (select `name` from `user` where id = incharger_id) inchargerName,
  150. c.creator_id,
  151. (select `name` from `user` where id = creator_id) creatorName
  152. from custom c
  153. left join sys_dict sd on c.customer_level_id = sd.id
  154. where c.company_id = #{companyId}
  155. and c.is_delete =#{isDelete}
  156. and c.incharger_id in
  157. (SELECT id from `user` WHERE department_id = (SELECT department_id from `user` WHERE id = #{userId}))
  158. or c.incharger_id is null
  159. <if test="inchargerId != null and inchargerId != '' ">
  160. and c.incharger_id =#{inchargerId}
  161. </if>
  162. <if test="startTime != null and endTime != null ">
  163. and c.create_time BETWEEN #{startTime} and #{endTime}
  164. </if>
  165. <if test="customName != null and customName != '' ">
  166. and c.custom_name LIKE CONCAT('%', #{customName}, '%')
  167. </if>
  168. <if test="email != null and email != '' ">
  169. and c.email LIKE CONCAT('%', #{email}, '%')
  170. </if>
  171. <if test="companyPhone != null ">
  172. and c.company_phone = #{companyPhone}
  173. </if>
  174. <if test="customerLevelId != null ">
  175. and c.customer_level_id = #{customerLevelId}
  176. </if>
  177. <if test="customSourceId != null ">
  178. and c.custom_source_id = #{customSourceId}
  179. </if>
  180. <if test="customerIndustryId != null ">
  181. and c.customer_industry_id = #{customerIndustryId}
  182. </if>
  183. ORDER BY
  184. <choose>
  185. <when test="isDesc == null ">
  186. c.id DESC
  187. </when>
  188. <when test="isDesc == 0">
  189. sd.seq ASC, c.id DESC
  190. </when>
  191. <when test="isDesc == 1">
  192. sd.seq DESC, c.id DESC
  193. </when>
  194. <otherwise>
  195. c.id DESC
  196. </otherwise>
  197. </choose>
  198. Limit #{pageIndex},#{pageFrom}
  199. </select>
  200. <select id="getTotal1" resultType="java.lang.Integer">
  201. select count(id)
  202. from custom
  203. where company_id = #{companyId}
  204. and is_delete =#{isDelete}
  205. and incharger_id in
  206. (SELECT id from `user` WHERE department_id = (SELECT department_id from `user` WHERe id = #{userId}))
  207. or incharger_id is null
  208. <if test="inchargerId != null and inchargerId != '' ">
  209. and incharger_id =#{inchargerId}
  210. </if>
  211. <if test="startTime != null and endTime != null ">
  212. and create_time BETWEEN #{startTime} and #{endTime}
  213. </if>
  214. <if test="customName != null and customName != '' ">
  215. and custom_name = #{customName}
  216. </if>
  217. <if test="email != null and email != '' ">
  218. and email = #{email}
  219. </if>
  220. <if test="companyPhone != null ">
  221. and company_phone = #{companyPhone}
  222. </if>
  223. <if test="customerLevelId != null ">
  224. and customer_level_id = #{customerLevelId}
  225. </if>
  226. <if test="customSourceId != null ">
  227. and custom_source_id = #{customSourceId}
  228. </if>
  229. <if test="customerIndustryId != null ">
  230. and customer_industry_id = #{customerIndustryId}
  231. </if>
  232. </select>
  233. <select id="getList2" resultType="com.management.platform.entity.Custom">
  234. select id,
  235. custom_name,
  236. email,
  237. company_phone,
  238. create_time,
  239. customer_level_id,
  240. (select name from sys_dict where customer_level_id = id and code = 'CustomLevel') customerLevelValue,
  241. customer_industry_id,
  242. (select name from sys_dict where customer_industry_id = id and code = 'CustomIndustry') customerIndustryValue,
  243. custom_source_id,
  244. (select name from sys_dict where custom_source_id = id ) customSourceValue,
  245. incharger_id,
  246. (select `name` from `user` where id = incharger_id) inchargerName,
  247. creator_id,
  248. (select `name` from `user` where id = creator_id) creatorName
  249. from custom
  250. where company_id = #{companyId}
  251. and is_delete =#{isDelete}
  252. and incharger_id = #{inchargerId}
  253. or incharger_id is null
  254. <if test="inchargerId != null and inchargerId != '' ">
  255. and incharger_id =#{inchargerId}
  256. </if>
  257. <if test="startTime != null and endTime != null ">
  258. and create_time BETWEEN #{startTime} and #{endTime}
  259. </if>
  260. <if test="customName != null and customName != '' ">
  261. and custom_name LIKE CONCAT('%', #{customName}, '%')
  262. </if>
  263. <if test="email != null and email != '' ">
  264. and email LIKE CONCAT('%', #{email}, '%')
  265. </if>
  266. <if test="companyPhone != null ">
  267. and company_phone = #{companyPhone}
  268. </if>
  269. <if test="customerLevelId != null ">
  270. and customer_level_id = #{customerLevelId}
  271. </if>
  272. <if test="customSourceId != null ">
  273. and custom_source_id = #{customSourceId}
  274. </if>
  275. <if test="customerIndustryId != null ">
  276. and customer_industry_id = #{customerIndustryId}
  277. </if>
  278. ORDER BY id desc
  279. Limit #{pageIndex},#{pageFrom}
  280. </select>
  281. <select id="getTotal2" resultType="java.lang.Integer">
  282. select count(id)
  283. from custom
  284. where company_id = #{companyId}
  285. and is_delete = #{isDelete}
  286. and incharger_id = #{inchargerId}
  287. or incharger_id is null
  288. <if test="inchargerId != null and inchargerId != '' ">
  289. and incharger_id =#{inchargerId}
  290. </if>
  291. <if test="startTime != null and endTime != null ">
  292. and create_time BETWEEN #{startTime} and #{endTime}
  293. </if>
  294. <if test="customName != null and customName != '' ">
  295. and custom_name = #{customName}
  296. </if>
  297. <if test="email != null and email != '' ">
  298. and email = #{email}
  299. </if>
  300. <if test="companyPhone != null ">
  301. and company_phone = #{companyPhone}
  302. </if>
  303. <if test="customerLevelId != null ">
  304. and customer_level_id = #{customerLevelId}
  305. </if>
  306. <if test="customSourceId != null ">
  307. and custom_source_id = #{customSourceId}
  308. </if>
  309. <if test="customerIndustryId != null ">
  310. and customer_industry_id = #{customerIndustryId}
  311. </if>
  312. </select>
  313. <select id="getInfo" resultType="com.management.platform.entity.Custom">
  314. select id,
  315. custom_name,
  316. contacts_name,
  317. custom_source_id,
  318. customer_industry_id,
  319. customer_level_id,
  320. email,
  321. tel_phone,
  322. address,
  323. custom_code,
  324. tel_phone,
  325. fax,
  326. create_time,
  327. plate1,
  328. plate2,
  329. plate3,
  330. plate4,
  331. plate5,
  332. creator_id,
  333. custom_desc,
  334. is_delete,
  335. (select `name` from sys_dict where customer_level_id = id and code = 'CustomLevel') customerLevelValue,
  336. (select `name` from sys_dict where customer_industry_id = id and code = 'CustomIndustry') customerIndustryValue,
  337. (select `name` from sys_dict where custom_source_id = id ) customSourceValue,
  338. (select `name` from `user` where id = incharger_id) inchargerName,
  339. (select `name` from `user` where id = creator_id) creatorName
  340. from custom
  341. where id = #{id}
  342. </select>
  343. <select id="getDataSummary" resultType="java.util.Map">
  344. SELECT COUNT(*) newNum,SUM(close_deal=1) closeDealNum FROM custom
  345. WHERE company_id=#{companyId} and is_delete=0
  346. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  347. and DATE_FORMAT(create_time,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
  348. </if>
  349. <if test="userId!=null and userId!=''">
  350. and incharger_id=#{userId}
  351. </if>
  352. <if test="list!=null and list.size()>0">
  353. and incharger_id in
  354. <foreach collection="list" separator="," open="(" close=")" item="item">
  355. #{item}
  356. </foreach>
  357. </if>
  358. </select>
  359. </mapper>