BusinessOpportunityMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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.BusinessOpportunityMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.management.platform.entity.BusinessOpportunity">
  6. <id column="id" property="id" />
  7. <result column="company_id" property="companyId" />
  8. <result column="name" property="name" />
  9. <result column="contacts_id" property="contactsId" />
  10. <result column="customer_id" property="customerId" />
  11. <result column="amount_of_money" property="amountOfMoney" />
  12. <result column="expected_transaction_date" property="expectedTransactionDate" />
  13. <result column="stage_id" property="stageId" />
  14. <result column="create_time" property="createTime" />
  15. <result column="edit_time" property="editTime" />
  16. <result column="creator_id" property="creatorId" />
  17. <result column="incharger_id" property="inchargerId" />
  18. <result column="remark" property="remark" />
  19. <result column="is_delete" property="isDelete" />
  20. <result column="plate1" property="plate1" />
  21. <result column="plate2" property="plate2" />
  22. <result column="plate3" property="plate3" />
  23. <result column="plate4" property="plate4" />
  24. <result column="plate5" property="plate5" />
  25. <result column="clue_id" property="clueId" />
  26. <result column="reason" property="reason" />
  27. <result column="seq" property="seq" />
  28. </resultMap>
  29. <!-- 通用查询结果列 -->
  30. <sql id="Base_Column_List">
  31. id, company_id, name, contacts_id, customer_id, amount_of_money, expected_transaction_date, stage_id, create_time, edit_time, creator_id, incharger_id, remark, is_delete,seq, plate1, plate2, plate3, plate4, plate5,need_pin ,pin_time
  32. </sql>
  33. <select id="selectAllList" resultType="com.management.platform.entity.BusinessOpportunity">
  34. select
  35. <include refid="Base_Column_List"></include>,
  36. (select `name` from stage where id = stage_id) stageValue,
  37. (select custom_name from custom where id = customer_id) customerName,
  38. (select `name` from contacts where id = contacts_id) contactsName,
  39. (select `name` from `user` where id = incharger_id) inchargerName,
  40. (select `name` from `user` where id = creator_id) creatorName
  41. from business_opportunity
  42. where company_id = #{companyId}
  43. and is_delete = #{isDelete}
  44. <if test="name != null and name != ''">
  45. and `name` LIKE CONCAT('%', #{name}, '%')
  46. </if>
  47. <if test="inchargerId != null and inchargerId != '' ">
  48. and incharger_id = #{inchargerId}
  49. </if>
  50. <if test="startTime != null and endTime != null ">
  51. and create_time BETWEEN #{startTime} and #{endTime}
  52. </if>
  53. <if test="contactsName != null and contactsName != ''">
  54. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{contactsName}, '%'))
  55. </if>
  56. <if test="customerName != null and customerName != ''">
  57. and customer_id in (select id from custom where `custom_name`LIKE CONCAT('%', #{customerName}, '%'))
  58. </if>
  59. <if test="stageId != null ">
  60. and stage_id = #{stageId}
  61. </if>
  62. <if test="productId != null ">
  63. and id in (select business_id from business_item_product where product_id = #{productId})
  64. </if>
  65. ORDER BY id DESC
  66. <if test="pageIndex!=null and pageFrom !=null">
  67. limit #{pageIndex},#{pageFrom}
  68. </if>
  69. </select>
  70. <select id="getTotal" resultType="java.lang.Integer">
  71. select
  72. count(id)
  73. from business_opportunity
  74. where company_id = #{companyId}
  75. and is_delete = #{isDelete}
  76. <if test="name != null and name != ''">
  77. and `name` LIKE CONCAT('%', #{name}, '%')
  78. </if>
  79. <if test="inchargerId != null and inchargerId != ''">
  80. and incharger_id = #{inchargerId}
  81. </if>
  82. <if test="startTime != null and endTime != null ">
  83. and create_time BETWEEN #{startTime} and #{endTime}
  84. </if>
  85. <if test="contactsName != null and contactsName != ''">
  86. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{contactsName}, '%'))
  87. </if>
  88. <if test="customerName != null and customerName != ''">
  89. and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{customerName}, '%'))
  90. </if>
  91. <if test="stageId != null ">
  92. and stage_id = #{stageId}
  93. </if>
  94. <if test="productId != null ">
  95. and id in (select business_id from business_item_product where product_id = #{productId})
  96. </if>
  97. </select>
  98. <select id="selectAllList1" resultType="com.management.platform.entity.BusinessOpportunity">
  99. select
  100. <include refid="Base_Column_List"></include>,
  101. (select `name` from stage where id = stage_id) stageValue,
  102. (select custom_name from custom where id = customer_id) customerName,
  103. (select `name` from contacts where id = contacts_id) contactsName,
  104. (select `name` from `user` where id = incharger_id) inchargerName,
  105. (select `name` from `user` where id = creator_id) creatorName
  106. from business_opportunity
  107. where company_id = #{bo.companyId}
  108. and is_delete = #{bo.isDelete}
  109. and (incharger_id in
  110. (SELECT id from `user` WHERE department_id = (SELECT department_id from `user` WHERe id = #{userId}))
  111. or incharger_id is null)
  112. <if test="bo.name != null and bo.name != ''">
  113. and `name` LIKE CONCAT('%', #{bo.name}, '%')
  114. </if>
  115. <if test="bo.inchargerId != null ">
  116. and incharger_id = #{bo.inchargerId}
  117. </if>
  118. <if test="bo.startTime != null and bo.endTime != null ">
  119. and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
  120. </if>
  121. <if test="bo.contactsName != null and bo.contactsName != ''">
  122. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
  123. </if>
  124. <if test="bo.customerName != null and bo.customerName != ''">
  125. and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
  126. </if>
  127. <if test="bo.stageId != null ">
  128. and stage_id = #{bo.stageId}
  129. </if>
  130. <if test="bo.productId != null ">
  131. and id in (select business_id from business_item_product where product_id = #{bo.productId})
  132. </if>
  133. ORDER BY id DESC
  134. <if test="bo.pageIndex!=null and bo.pageFrom !=null">
  135. limit #{bo.pageIndex},#{bo.pageFrom}
  136. </if>
  137. </select>
  138. <select id="getTotal1" resultType="java.lang.Integer">
  139. select
  140. count(id)
  141. from business_opportunity
  142. where company_id = #{bo.companyId}
  143. and is_delete = #{bo.isDelete}
  144. and (incharger_id in
  145. (SELECT id from `user` WHERE department_id = (SELECT department_id from `user` WHERe id = #{userId}))
  146. or incharger_id is null)
  147. <if test="bo.name != null and bo.name != ''">
  148. and `name` LIKE CONCAT('%', #{bo.name}, '%')
  149. </if>
  150. <if test="bo.inchargerId != null ">
  151. and incharger_id = #{bo.inchargerId}
  152. </if>
  153. <if test="bo.startTime != null and bo.endTime != null ">
  154. and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
  155. </if>
  156. <if test="bo.contactsName != null and bo.contactsName != ''">
  157. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
  158. </if>
  159. <if test="bo.customerName != null and bo.customerName != ''">
  160. and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
  161. </if>
  162. <if test="bo.stageId != null ">
  163. and stage_id = #{bo.stageId}
  164. </if>
  165. <if test="bo.productId != null ">
  166. and id in (select business_id from business_item_product where product_id = #{bo.productId})
  167. </if>
  168. </select>
  169. <select id="selectAllList2" resultType="com.management.platform.entity.BusinessOpportunity">
  170. select
  171. <include refid="Base_Column_List"></include>,
  172. (select `name` from stage where id = stage_id) stageValue,
  173. (select custom_name from custom where id = customer_id) customerName,
  174. (select `name` from contacts where id = contacts_id) contactsName,
  175. (select `name` from `user` where id = incharger_id) inchargerName,
  176. (select `name` from `user` where id = creator_id) creatorName
  177. from business_opportunity
  178. where company_id = #{bo.companyId}
  179. and is_delete = #{bo.isDelete}
  180. and (incharger_id = #{userId} or incharger_id is null)
  181. <if test="bo.name != null and bo.name != ''">
  182. and `name` LIKE CONCAT('%', #{bo.name}, '%')
  183. </if>
  184. <if test="bo.inchargerId != null ">
  185. and incharger_id = #{bo.inchargerId}
  186. </if>
  187. <if test="bo.startTime != null and bo.endTime != null ">
  188. and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
  189. </if>
  190. <if test="bo.contactsName != null and bo.contactsName != ''">
  191. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
  192. </if>
  193. <if test="bo.customerName != null and bo.customerName != ''">
  194. and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
  195. </if>
  196. <if test="bo.stageId != null ">
  197. and stage_id = #{bo.stageId}
  198. </if>
  199. <if test="bo.productId != null ">
  200. and id in (select business_id from business_item_product where product_id =#{bo.productId})
  201. </if>
  202. ORDER BY id DESC
  203. <if test="bo.pageIndex!=null and bo.pageFrom !=null">
  204. limit #{bo.pageIndex},#{bo.pageFrom}
  205. </if>
  206. </select>
  207. <select id="getTotal2" resultType="java.lang.Integer">
  208. select
  209. count(id)
  210. from business_opportunity
  211. where company_id = #{bo.companyId}
  212. and is_delete = #{bo.isDelete}
  213. and (incharger_id = #{userId} or incharger_id is null)
  214. <if test="bo.name != null and bo.name != ''">
  215. and `name` LIKE CONCAT('%', #{bo.name}, '%')
  216. </if>
  217. <if test="bo.inchargerId != null ">
  218. and incharger_id = #{bo.inchargerId}
  219. </if>
  220. <if test="bo.startTime != null and bo.endTime != null ">
  221. and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
  222. </if>
  223. <if test="bo.contactsName != null and bo.contactsName != ''">
  224. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
  225. </if>
  226. <if test="bo.customerName != null and bo.customerName != ''">
  227. and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
  228. </if>
  229. <if test="bo.stageId != null ">
  230. and stage_id = #{bo.stageId}
  231. </if>
  232. <if test="bo.productId != null ">
  233. and id in (select business_id from business_item_product where product_id = #{bo.productId})
  234. </if>
  235. </select>
  236. <select id="selectByIdToInfo" resultType="com.management.platform.entity.BusinessOpportunity">
  237. SELECT *,
  238. (select `name` from stage where id = stage_id) stageValue,
  239. (select custom_name from custom where id = customer_id) customerName,
  240. (select `name` from contacts where id = contacts_id) contactsName,
  241. (select `name` from `user` where id = incharger_id) inchargerName,
  242. (select `name` from `user` where id = creator_id) creatorName
  243. from business_opportunity
  244. where id = #{id}
  245. </select>
  246. <select id="getDataSummary" resultType="java.util.Map">
  247. SELECT COUNT(*) newNum,SUM(bo.amount_of_money) AS allAmountOfMoney,SUM(s.name='赢单') winning,SUM(s.name='输单') losting FROM business_opportunity bo
  248. LEFT JOIN stage s ON bo.stage_id=s.id
  249. WHERE bo.company_id=#{companyId} and is_delete=0
  250. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  251. and DATE_FORMAT(bo.create_time,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
  252. </if>
  253. <if test="userId!=null and userId!=''">
  254. and incharger_id=#{userId}
  255. </if>
  256. <if test="list!=null and list.size()>0">
  257. and incharger_id in
  258. <foreach collection="list" separator="," open="(" close=")" item="item">
  259. #{item}
  260. </foreach>
  261. </if>
  262. </select>
  263. <select id="getDataStage" resultType="java.util.Map">
  264. SELECT IFNULL(s.name,'未分配') AS stageName,COUNT(1) AS num FROM business_opportunity bo
  265. LEFT JOIN stage s ON bo.stage_id=s.id
  266. WHERE bo.company_id=#{companyId} AND bo.is_delete=0
  267. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  268. and DATE_FORMAT(bo.create_time,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
  269. </if>
  270. <if test="userId!=null and userId!=''">
  271. and incharger_id=#{userId}
  272. </if>
  273. <if test="list!=null and list.size()>0">
  274. and incharger_id in
  275. <foreach collection="list" separator="," open="(" close=")" item="item">
  276. #{item}
  277. </foreach>
  278. </if>
  279. GROUP BY s.id
  280. </select>
  281. <select id="getAllList" resultType="com.management.platform.entity.BusinessOpportunity">
  282. select *
  283. from business_opportunity
  284. where company_id = #{companyId}
  285. and is_delete = 0
  286. order by create_time desc
  287. </select>
  288. <select id="getAllList1" resultType="com.management.platform.entity.BusinessOpportunity">
  289. select *
  290. from business_opportunity
  291. where company_id = #{companyId}
  292. and is_delete = 0
  293. and (incharger_id in
  294. (SELECT id from `user` WHERE department_id = (SELECT department_id from `user` WHERe id = #{id}))
  295. or incharger_id is null)
  296. order by create_time desc
  297. </select>
  298. <select id="getAllList2" resultType="com.management.platform.entity.BusinessOpportunity">
  299. select *
  300. from business_opportunity
  301. where company_id = #{companyId}
  302. and is_delete = 0
  303. and (incharger_id = #{id} or incharger_id is null)
  304. order by create_time desc
  305. </select>
  306. <select id="selectAllListByPin" resultType="com.management.platform.entity.BusinessOpportunity">
  307. select
  308. <include refid="Base_Column_List"></include>,
  309. (select `name` from stage where id = stage_id) stageValue,
  310. (select `color` from stage where id = stage_id) stageColor,
  311. (select custom_name from custom where id = customer_id) customerName,
  312. (select `name` from contacts where id = contacts_id) contactsName,
  313. (select `name` from `user` where id = incharger_id) inchargerName,
  314. (select `name` from `user` where id = creator_id) creatorName,need_pin,pin_time
  315. from business_opportunity
  316. where company_id = #{companyId}
  317. and is_delete = #{isDelete}
  318. <if test="name != null and name != ''">
  319. and `name` LIKE CONCAT('%', #{name}, '%')
  320. </if>
  321. <if test="inchargerId != null and inchargerId != '' ">
  322. and incharger_id = #{inchargerId}
  323. </if>
  324. <if test="startTime != null and endTime != null ">
  325. and create_time BETWEEN #{startTime} and #{endTime}
  326. </if>
  327. <if test="contactsName != null and contactsName != ''">
  328. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{contactsName}, '%'))
  329. </if>
  330. <if test="customerName != null and customerName != ''">
  331. and customer_id in (select id from custom where `custom_name`LIKE CONCAT('%', #{customerName}, '%'))
  332. </if>
  333. <if test="stageId != null ">
  334. and stage_id = #{stageId}
  335. </if>
  336. <if test="productId != null ">
  337. and id in (select business_id from business_item_product where product_id = #{productId})
  338. </if>
  339. ORDER BY need_pin desc,pin_time desc,id DESC
  340. <if test="pageIndex!=null and pageFrom !=null">
  341. limit #{pageIndex},#{pageFrom}
  342. </if>
  343. </select>
  344. <select id="selectAllList1ByPin" resultType="com.management.platform.entity.BusinessOpportunity">
  345. select
  346. <include refid="Base_Column_List"></include>,
  347. (select `name` from stage where id = stage_id) stageValue,
  348. (select `color` from stage where id = stage_id) stageColor,
  349. (select custom_name from custom where id = customer_id) customerName,
  350. (select `name` from contacts where id = contacts_id) contactsName,
  351. (select `name` from `user` where id = incharger_id) inchargerName,
  352. (select `name` from `user` where id = creator_id) creatorName,need_pin,pin_time
  353. from business_opportunity
  354. where company_id = #{bo.companyId}
  355. and is_delete = #{bo.isDelete}
  356. and (incharger_id in
  357. (SELECT id from `user` WHERE department_id = (SELECT department_id from `user` WHERe id = #{userId}))
  358. or incharger_id is null)
  359. <if test="bo.name != null and bo.name != ''">
  360. and `name` LIKE CONCAT('%', #{bo.name}, '%')
  361. </if>
  362. <if test="bo.inchargerId != null ">
  363. and incharger_id = #{bo.inchargerId}
  364. </if>
  365. <if test="bo.startTime != null and bo.endTime != null ">
  366. and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
  367. </if>
  368. <if test="bo.contactsName != null and bo.contactsName != ''">
  369. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
  370. </if>
  371. <if test="bo.customerName != null and bo.customerName != ''">
  372. and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
  373. </if>
  374. <if test="bo.stageId != null ">
  375. and stage_id = #{bo.stageId}
  376. </if>
  377. <if test="bo.productId != null ">
  378. and id in (select business_id from business_item_product where product_id = #{bo.productId})
  379. </if>
  380. ORDER BY need_pin desc,pin_time desc,id DESC
  381. <if test="bo.pageIndex!=null and bo.pageFrom !=null">
  382. limit #{bo.pageIndex},#{bo.pageFrom}
  383. </if>
  384. </select>
  385. <select id="selectAllList2ByPin" resultType="com.management.platform.entity.BusinessOpportunity">
  386. select
  387. <include refid="Base_Column_List"></include>,
  388. (select `name` from stage where id = stage_id) stageValue,
  389. (select `color` from stage where id = stage_id) stageColor,
  390. (select custom_name from custom where id = customer_id) customerName,
  391. (select `name` from contacts where id = contacts_id) contactsName,
  392. (select `name` from `user` where id = incharger_id) inchargerName,
  393. (select `name` from `user` where id = creator_id) creatorName,need_pin,pin_time
  394. from business_opportunity
  395. where company_id = #{bo.companyId}
  396. and is_delete = #{bo.isDelete}
  397. and (incharger_id = #{userId} or incharger_id is null)
  398. <if test="bo.name != null and bo.name != ''">
  399. and `name` LIKE CONCAT('%', #{bo.name}, '%')
  400. </if>
  401. <if test="bo.inchargerId != null ">
  402. and incharger_id = #{bo.inchargerId}
  403. </if>
  404. <if test="bo.startTime != null and bo.endTime != null ">
  405. and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
  406. </if>
  407. <if test="bo.contactsName != null and bo.contactsName != ''">
  408. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
  409. </if>
  410. <if test="bo.customerName != null and bo.customerName != ''">
  411. and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
  412. </if>
  413. <if test="bo.stageId != null ">
  414. and stage_id = #{bo.stageId}
  415. </if>
  416. <if test="bo.productId != null ">
  417. and id in (select business_id from business_item_product where product_id =#{bo.productId})
  418. </if>
  419. ORDER BY need_pin desc,pin_time desc,id DESC
  420. <if test="bo.pageIndex!=null and bo.pageFrom !=null">
  421. limit #{bo.pageIndex},#{bo.pageFrom}
  422. </if>
  423. </select>
  424. </mapper>