BusinessOpportunityMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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="product_id" property="productId" />
  12. <result column="amount_of_money" property="amountOfMoney" />
  13. <result column="expected_transaction_date" property="expectedTransactionDate" />
  14. <result column="stage_id" property="stageId" />
  15. <result column="create_time" property="createTime" />
  16. <result column="edit_time" property="editTime" />
  17. <result column="creator_id" property="creatorId" />
  18. <result column="incharger_id" property="inchargerId" />
  19. <result column="remark" property="remark" />
  20. <result column="is_delete" property="isDelete" />
  21. <result column="plate1" property="plate1" />
  22. <result column="plate2" property="plate2" />
  23. <result column="plate3" property="plate3" />
  24. <result column="plate4" property="plate4" />
  25. <result column="plate5" property="plate5" />
  26. </resultMap>
  27. <!-- 通用查询结果列 -->
  28. <sql id="Base_Column_List">
  29. 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, plate1, plate2, plate3, plate4, plate5
  30. </sql>
  31. <select id="selectAllList" resultType="com.management.platform.entity.BusinessOpportunity">
  32. select
  33. <include refid="Base_Column_List"></include>,
  34. (select `name` from stage where id = stage_id) stageValue,
  35. (select custom_name from custom where id = customer_id) customerName,
  36. (select `name` from contacts where id = contacts_id) contactsName,
  37. (select `name` from `user` where id = incharger_id) inchargerName,
  38. (select `name` from `user` where id = creator_id) creatorName,
  39. (SELECT sum(total) from business_product WHERE business_id = id) total
  40. from business_opportunity
  41. where company_id = #{companyId}
  42. and is_delete = #{isDelete}
  43. <if test="name != null and name != ''">
  44. and `name` LIKE CONCAT('%', #{name}, '%')
  45. </if>
  46. <if test="inchargerId != null and inchargerId != '' ">
  47. and incharger_id = #{inchargerId}
  48. </if>
  49. <if test="startTime != null and endTime != null ">
  50. and create_time BETWEEN #{startTime} and #{endTime}
  51. </if>
  52. <if test="contactsName != null and contactsName != ''">
  53. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{contactsName}, '%'))
  54. </if>
  55. <if test="customerName != null and customerName != ''">
  56. and customer_id in (select id from custom where `custom_name`LIKE CONCAT('%', #{customerName}, '%'))
  57. </if>
  58. <if test="stageId != null ">
  59. and stage_id = #{stageId}
  60. </if>
  61. <if test="productId != null ">
  62. and id in (select business_id from business_product where product_id = #{productId})
  63. </if>
  64. ORDER BY id DESC
  65. limit #{pageIndex},#{pageFrom}
  66. </select>
  67. <select id="getTotal" resultType="java.lang.Integer">
  68. select
  69. count(id)
  70. from business_opportunity
  71. where company_id = #{companyId}
  72. and is_delete = #{isDelete}
  73. <if test="name != null and name != ''">
  74. and `name` LIKE CONCAT('%', #{name}, '%')
  75. </if>
  76. <if test="inchargerId != null and inchargerId != ''">
  77. and incharger_id = #{inchargerId}
  78. </if>
  79. <if test="startTime != null and endTime != null ">
  80. and create_time BETWEEN #{startTime} and #{endTime}
  81. </if>
  82. <if test="contactsName != null and contactsName != ''">
  83. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{contactsName}, '%'))
  84. </if>
  85. <if test="customerName != null and customerName != ''">
  86. and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{customerName}, '%'))
  87. </if>
  88. <if test="stageId != null ">
  89. and stage_id = #{stageId}
  90. </if>
  91. <if test="productId != null ">
  92. and id in (select business_id from business_product where product_id = #{productId})
  93. </if>
  94. </select>
  95. <select id="selectAllList1" resultType="com.management.platform.entity.BusinessOpportunity">
  96. select
  97. <include refid="Base_Column_List"></include>,
  98. (select `name` from stage where id = stage_id) stageValue,
  99. (select custom_name from custom where id = customer_id) customerName,
  100. (select `name` from contacts where id = contacts_id) contactsName,
  101. (select `name` from `user` where id = incharger_id) inchargerName,
  102. (select `name` from `user` where id = creator_id) creatorName,
  103. (SELECT sum(total) from business_product WHERE business_id = id)
  104. from business_opportunity
  105. where company_id = #{bo.companyId}
  106. and is_delete = #{bo.isDelete}
  107. and (incharger_id in
  108. (SELECT id from `user` WHERE department_id = (SELECT department_id from `user` WHERe id = #{userId}))
  109. or incharger_id is null)
  110. <if test="bo.name != null and bo.name != ''">
  111. and `name` LIKE CONCAT('%', #{bo.name}, '%')
  112. </if>
  113. <if test="bo.inchargerId != null ">
  114. and incharger_id = #{bo.inchargerId}
  115. </if>
  116. <if test="bo.startTime != null and bo.endTime != null ">
  117. and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
  118. </if>
  119. <if test="bo.contactsName != null and bo.contactsName != ''">
  120. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
  121. </if>
  122. <if test="bo.customerName != null and bo.customerName != ''">
  123. and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
  124. </if>
  125. <if test="bo.stageId != null ">
  126. and stage_id = #{bo.stageId}
  127. </if>
  128. <if test="bo.productId != null ">
  129. and id in (select business_id from business_product where product_id = #{bo.productId})
  130. </if>
  131. ORDER BY id DESC
  132. limit #{bo.pageIndex},#{bo.pageFrom}
  133. </select>
  134. <select id="getTotal1" resultType="java.lang.Integer">
  135. select
  136. count(id)
  137. from business_opportunity
  138. where company_id = #{bo.companyId}
  139. and is_delete = #{bo.isDelete}
  140. and (incharger_id in
  141. (SELECT id from `user` WHERE department_id = (SELECT department_id from `user` WHERe id = #{userId}))
  142. or incharger_id is null)
  143. <if test="bo.name != null and bo.name != ''">
  144. and `name` LIKE CONCAT('%', #{bo.name}, '%')
  145. </if>
  146. <if test="bo.inchargerId != null ">
  147. and incharger_id = #{bo.inchargerId}
  148. </if>
  149. <if test="bo.startTime != null and bo.endTime != null ">
  150. and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
  151. </if>
  152. <if test="bo.contactsName != null and bo.contactsName != ''">
  153. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
  154. </if>
  155. <if test="bo.customerName != null and bo.customerName != ''">
  156. and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
  157. </if>
  158. <if test="bo.stageId != null ">
  159. and stage_id = #{bo.stageId}
  160. </if>
  161. <if test="bo.productId != null ">
  162. and id in (select business_id from business_product where product_id = #{bo.productId})
  163. </if>
  164. </select>
  165. <select id="selectAllList2" resultType="com.management.platform.entity.BusinessOpportunity">
  166. select
  167. <include refid="Base_Column_List"></include>,
  168. (select `name` from stage where id = stage_id) stageValue,
  169. (select custom_name from custom where id = customer_id) customerName,
  170. (select `name` from contacts where id = contacts_id) contactsName,
  171. (select `name` from `user` where id = incharger_id) inchargerName,
  172. (select `name` from `user` where id = creator_id) creatorName,
  173. (SELECT sum(total) from business_product WHERE business_id = id)
  174. from business_opportunity
  175. where company_id = #{bo.companyId}
  176. and is_delete = #{bo.isDelete}
  177. and (incharger_id = #{userId} or incharger_id is null)
  178. <if test="bo.name != null and bo.name != ''">
  179. and `name` LIKE CONCAT('%', #{bo.name}, '%')
  180. </if>
  181. <if test="bo.inchargerId != null ">
  182. and incharger_id = #{bo.inchargerId}
  183. </if>
  184. <if test="bo.startTime != null and bo.endTime != null ">
  185. and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
  186. </if>
  187. <if test="bo.contactsName != null and bo.contactsName != ''">
  188. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
  189. </if>
  190. <if test="bo.customerName != null and bo.customerName != ''">
  191. and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
  192. </if>
  193. <if test="bo.stageId != null ">
  194. and stage_id = #{bo.stageId}
  195. </if>
  196. <if test="bo.productId != null ">
  197. and id in (select business_id from business_product where product_id =#{bo.productId})
  198. </if>
  199. ORDER BY id DESC
  200. limit #{bo.pageIndex},#{bo.pageFrom}
  201. </select>
  202. <select id="getTotal2" resultType="java.lang.Integer">
  203. select
  204. count(id)
  205. from business_opportunity
  206. where company_id = #{bo.companyId}
  207. and is_delete = #{bo.isDelete}
  208. and (incharger_id = #{userId} or incharger_id is null)
  209. <if test="bo.name != null and bo.name != ''">
  210. and `name` LIKE CONCAT('%', #{bo.name}, '%')
  211. </if>
  212. <if test="bo.inchargerId != null ">
  213. and incharger_id = #{bo.inchargerId}
  214. </if>
  215. <if test="bo.startTime != null and bo.endTime != null ">
  216. and create_time BETWEEN #{bo.startTime} and #{bo.endTime}
  217. </if>
  218. <if test="bo.contactsName != null and bo.contactsName != ''">
  219. and contacts_id in (select id from contacts where `name`LIKE CONCAT('%', #{bo.contactsName}, '%'))
  220. </if>
  221. <if test="bo.customerName != null and bo.customerName != ''">
  222. and customer_id in (select id from custom where `name`LIKE CONCAT('%', #{bo.customerName}, '%'))
  223. </if>
  224. <if test="bo.stageId != null ">
  225. and stage_id = #{bo.stageId}
  226. </if>
  227. <if test="bo.productId != null ">
  228. and id in (select business_id from business_product where product_id = #{bo.productId})
  229. </if>
  230. </select>
  231. <select id="selectByIdToInfo" resultType="com.management.platform.entity.BusinessOpportunity">
  232. SELECT *,
  233. (select `name` from stage where id = stage_id) stageValue,
  234. (select custom_name from custom where id = customer_id) customerName,
  235. (select `name` from contacts where id = contacts_id) contactsName,
  236. (select `name` from `user` where id = incharger_id) inchargerName,
  237. (select `name` from `user` where id = creator_id) creatorName,
  238. (SELECT sum(total) from business_product WHERE business_id = id)
  239. from business_opportunity
  240. where id = #{id}
  241. </select>
  242. <select id="getDataSummary" resultType="java.util.Map">
  243. SELECT COUNT(*) newNum,SUM(bo.amount_of_money) AS allAmountOfMoney,SUM(s.name='赢单') winning,SUM(s.name='输单') losting FROM business_opportunity bo
  244. LEFT JOIN stage s ON bo.stage_id=s.id
  245. WHERE bo.company_id=#{companyId} and is_delete=0
  246. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  247. and DATE_FORMAT(bo.create_time,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
  248. </if>
  249. <if test="userId!=null and userId!=''">
  250. and incharger_id=#{userId}
  251. </if>
  252. <if test="list!=null and list.size()>0">
  253. and incharger_id in
  254. <foreach collection="list" separator="," open="(" close=")" item="item">
  255. #{item}
  256. </foreach>
  257. </if>
  258. </select>
  259. <select id="getDataStage" resultType="java.util.Map">
  260. SELECT IFNULL(s.name,'未分配') AS stageName,COUNT(1) AS num FROM business_opportunity bo
  261. LEFT JOIN stage s ON bo.stage_id=s.id
  262. WHERE bo.company_id=#{companyId} AND bo.is_delete=0
  263. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  264. and DATE_FORMAT(bo.create_time,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
  265. </if>
  266. <if test="userId!=null and userId!=''">
  267. and incharger_id=#{userId}
  268. </if>
  269. <if test="list!=null and list.size()>0">
  270. and incharger_id in
  271. <foreach collection="list" separator="," open="(" close=")" item="item">
  272. #{item}
  273. </foreach>
  274. </if>
  275. GROUP BY s.id
  276. </select>
  277. <select id="getAllList" resultType="com.management.platform.entity.BusinessOpportunity">
  278. select
  279. id,
  280. name
  281. from business_opportunity
  282. where company_id = #{companyId}
  283. and is_delete = 0
  284. </select>
  285. <select id="getAllList1" resultType="com.management.platform.entity.BusinessOpportunity">
  286. select
  287. id,
  288. name
  289. from business_opportunity
  290. where company_id = #{companyId}
  291. and is_delete = 0
  292. and (incharger_id in
  293. (SELECT id from `user` WHERE department_id = (SELECT department_id from `user` WHERe id = #{id}))
  294. or incharger_id is null)
  295. </select>
  296. <select id="getAllList2" resultType="com.management.platform.entity.BusinessOpportunity">
  297. select id,
  298. name
  299. from business_opportunity
  300. where company_id = #{companyId}
  301. and is_delete = 0
  302. and (incharger_id = #{id} or incharger_id is null)
  303. </select>
  304. </mapper>