DailySalesReportMapper.xml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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.goafanti.common.dao.DailySalesReportMapper">
  4. <resultMap id="BaseResultMap" type="com.goafanti.common.model.DailySalesReport">
  5. <id column="id" jdbcType="INTEGER" property="id" />
  6. <result column="admin_id" jdbcType="VARCHAR" property="adminId" />
  7. <result column="dep_id" jdbcType="VARCHAR" property="depId" />
  8. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  9. <result column="order_count" jdbcType="INTEGER" property="orderCount" />
  10. <result column="order_amount" jdbcType="DECIMAL" property="orderAmount" />
  11. </resultMap>
  12. <sql id="Base_Column_List">
  13. id, admin_id, dep_id, create_time, order_count, order_amount
  14. </sql>
  15. <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  16. select
  17. <include refid="Base_Column_List" />
  18. from daily_sales_report
  19. where id = #{id,jdbcType=INTEGER}
  20. </select>
  21. <select id="selectAdmins" resultMap="BaseResultMap">
  22. select a.id as admin_id, dm.id as dep_id
  23. from admin a
  24. left join department_management dm on dm.id = a.department_id
  25. </select>
  26. <select id="selectPersonalByPage" resultType="com.goafanti.report.bo.PersonalSalesReportBO">
  27. SELECT a.id, a.name, dm.name as departmentName, a.position, a.create_time as enrollTime
  28. FROM admin a
  29. left join department_management dm on dm.id = a.department_id
  30. where 1=1
  31. <if test="depName != null">
  32. and dm.name like concat(#{depName,jdbcType=VARCHAR},'%')
  33. </if>
  34. <if test="name != null">
  35. and a.name like concat(#{name,jdbcType=VARCHAR},'%')
  36. </if>
  37. <if test="position != null">
  38. and a.position like concat(#{position,jdbcType=VARCHAR},'%')
  39. </if>
  40. order by a.name asc
  41. <if test="pageNo != null and pageSize != null">
  42. limit #{pageNo,jdbcType=INTEGER}, #{pageSize,jdbcType=INTEGER}
  43. </if>
  44. </select>
  45. <select id="selectDailySalesReports" resultMap="BaseResultMap">
  46. SELECT o.salesman_id as admin_id, a.department_id as dep_id,
  47. count(o.order_no) as order_count, sum(o.sign_total_amount) as order_amount
  48. FROM aft.t_order o
  49. left join aft.admin a on o.salesman_id=a.id
  50. where o.order_status=3 and o.sign_time &gt;= #{startTime,jdbcType=TIMESTAMP} and o.sign_time &lt; #{endTime,jdbcType=TIMESTAMP}
  51. group by o.salesman_id, a.department_id;
  52. </select>
  53. <delete id="deleteByDate">
  54. delete from daily_sales_report
  55. where create_time = #{createTime,jdbcType=TIMESTAMP}
  56. </delete>
  57. <insert id="insertBatch" parameterType="com.goafanti.common.model.DailySalesReport" >
  58. insert into daily_sales_report (admin_id, dep_id, order_count, order_amount, create_time)
  59. values
  60. <foreach item="item" index="index" collection="list" separator=",">
  61. (#{item.adminId,jdbcType=VARCHAR},
  62. #{item.depId,jdbcType=VARCHAR},
  63. #{item.orderCount,jdbcType=INTEGER},
  64. #{item.orderAmount,jdbcType=DECIMAL},
  65. #{item.createTime,jdbcType=TIMESTAMP})
  66. </foreach>
  67. </insert>
  68. <select id="selectSalesPersonalReports" resultType="com.goafanti.report.bo.PersonalSalesReportBO">
  69. SELECT a.id, a.name, dm.name as departmentName, a.position, a.create_time as enrollTime,
  70. sum(dsr.order_count) as ${countField}, sum(dsr.order_amount) as ${amountField}
  71. FROM admin a
  72. left join daily_sales_report dsr on dsr.admin_id = a.id
  73. left join department_management dm on dm.id = dsr.dep_id
  74. where dsr.create_time &gt;= #{startTime,jdbcType=TIMESTAMP} and dsr.create_time &lt; #{endTime,jdbcType=TIMESTAMP}
  75. <if test="depName != null">
  76. and dm.name like concat(#{depName,jdbcType=VARCHAR},'%')
  77. </if>
  78. <if test="name != null">
  79. and a.name like concat(#{name,jdbcType=VARCHAR},'%')
  80. </if>
  81. <if test="position != null">
  82. and a.position like concat(#{position,jdbcType=VARCHAR},'%')
  83. </if>
  84. group by a.id, dsr.dep_id, dm.id
  85. order by ${orderField} ${order}, a.name asc
  86. <if test="pageNo != null and pageSize != null">
  87. limit #{pageNo,jdbcType=INTEGER}, #{pageSize,jdbcType=INTEGER}
  88. </if>
  89. </select>
  90. <select id="selectSalesPersonalReportsCount" resultType="java.lang.Long">
  91. SELECT count(distinct(a.id))
  92. FROM admin a
  93. <if test="startTime != null and endTime != null">
  94. left join daily_sales_report dsr on dsr.admin_id = a.id
  95. </if>
  96. <if test="depName != null">
  97. left join department_management dm on dm.id = a.department_id
  98. </if>
  99. where 1=1
  100. <if test="startTime != null and endTime != null">
  101. and dsr.create_time &gt;= #{startTime,jdbcType=TIMESTAMP} and dsr.create_time &lt; #{endTime,jdbcType=TIMESTAMP}
  102. </if>
  103. <if test="depName != null">
  104. and dm.name like concat(#{depName,jdbcType=VARCHAR},'%')
  105. </if>
  106. <if test="name != null">
  107. and a.name like concat(#{name,jdbcType=VARCHAR},'%')
  108. </if>
  109. <if test="position != null">
  110. and a.position like concat(#{position,jdbcType=VARCHAR},'%')
  111. </if>
  112. </select>
  113. <select id="selectSalesPersonalExtraReports" resultType="org.springframework.ui.ModelMap">
  114. SELECT dsr.admin_id as id, sum(dsr.order_count) as order_count, sum(dsr.order_amount) as order_amount
  115. FROM daily_sales_report dsr
  116. where dsr.create_time &gt;= #{startTime,jdbcType=TIMESTAMP} and dsr.create_time &lt; #{endTime,jdbcType=TIMESTAMP}
  117. <if test="ids != null">
  118. and dsr.admin_id in
  119. <foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
  120. #{item}
  121. </foreach>
  122. </if>
  123. group by dsr.admin_id
  124. </select>
  125. <select id="selectSalesDepartmentReports" resultType="com.goafanti.report.bo.DepartmentSalesReportBO">
  126. SELECT dm.id, a.name as managerName, dm.name as departmentName, count(a2.id) as memberCount, dm.super_id as superId
  127. FROM department_management dm
  128. left join admin a2 on a2.department_id = dm.id
  129. left join admin a on a.id = dm.manager_id
  130. group by dm.id, a.id
  131. order by dm.name asc
  132. </select>
  133. <select id="selectSalesDepartmentExtraReports" resultType="org.springframework.ui.ModelMap">
  134. SELECT dsr.dep_id as id, sum(dsr.order_count) as order_count, sum(dsr.order_amount) as order_amount
  135. FROM daily_sales_report dsr
  136. where dsr.create_time &gt;= #{startTime,jdbcType=TIMESTAMP} and dsr.create_time &lt; #{endTime,jdbcType=TIMESTAMP}
  137. group by dsr.dep_id
  138. </select>
  139. <select id="selectTotalReports" resultType="org.springframework.ui.ModelMap">
  140. SELECT sum(dsr.order_count) as totalCount, sum(dsr.order_amount) as totalAmount
  141. FROM admin a
  142. left join daily_sales_report dsr on dsr.admin_id = a.id
  143. <if test="depName != null">
  144. left join department_management dm on dm.id = a.department_id
  145. </if>
  146. where dsr.create_time &gt;= #{startTime,jdbcType=TIMESTAMP} and dsr.create_time &lt; #{endTime,jdbcType=TIMESTAMP}
  147. <if test="depName != null">
  148. and dm.name like concat(#{depName,jdbcType=VARCHAR},'%')
  149. </if>
  150. <if test="name != null">
  151. and a.name like concat(#{name,jdbcType=VARCHAR},'%')
  152. </if>
  153. <if test="position != null">
  154. and a.position like concat(#{position,jdbcType=VARCHAR},'%')
  155. </if>
  156. </select>
  157. <select id="findmarketingStatisticsList" parameterType="String" resultType="com.goafanti.report.bo.marketingESBo">
  158. select t1.id,t1.name,t1.departmentId,t1.departmentName,t1.manager_id,t1.departmentManagerName,
  159. t1.roleName,t1.privateCustomersCount,t1.entryTime,
  160. t2.yearFollowNo,t2.yearVisitNo,t2.yearTelNo,
  161. t2.monthFollowNo,t2.monthVisitNo,t2.monthTelNo,
  162. t2.weeklyFollowNo,t2.weeklyVisitNo,t2.weeklyTelNo,
  163. t2.dayFollowNo,t2.dayVisitNo,t2.dayTelNo
  164. from(
  165. select a.id as id,a.name as name,a.department_id as departmentId,d.name as departmentName,d.manager_id,f.name as departmentManagerName,
  166. c.role_name as roleName,ifnull(e.privateCustomersCount,0)as privateCustomersCount,a.create_time as entryTime
  167. from admin a left join user_role b
  168. on a.id=b.uid left join role c
  169. on b.rid=c.id left join department_management d
  170. on a.department_id=d.id left join (select aid,count(0) as privateCustomersCount from user where aid is not null and aid != '' group by aid)e
  171. on a.id=e.aid left join admin f
  172. on d.manager_id=f.id
  173. where c.role_name in ('营销员' ,'营销经理','营销管理员')
  174. <if test="depId != null">
  175. and a.department_id = #{depId,jdbcType=VARCHAR}
  176. </if>
  177. )t1
  178. left join (
  179. select x.aid,x.yearFollowNo,x.yearVisitNo,x.yearTelNo,
  180. y.monthFollowNo,y.monthVisitNo,y.monthTelNo,
  181. z.weeklyFollowNo,z.weeklyVisitNo,z.weeklyTelNo,
  182. w.dayFollowNo,w.dayVisitNo,dayTelNo
  183. from (
  184. select
  185. aid,
  186. count(0) as yearFollowNo,
  187. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as yearVisitNo,
  188. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as yearTelNo
  189. from user_follow where 1=1
  190. and create_time &gt; #{yearStart,jdbcType=VARCHAR}
  191. and create_time &lt; #{yearEnd,jdbcType=VARCHAR}
  192. group by aid
  193. )x left join (
  194. select
  195. aid,
  196. count(0) as monthFollowNo,
  197. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as monthVisitNo,
  198. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as monthTelNo
  199. from user_follow where 1=1
  200. and create_time &gt; #{monthStart,jdbcType=VARCHAR}
  201. and create_time &lt; #{monthEnd,jdbcType=VARCHAR}
  202. group by aid
  203. )y on x.aid = y.aid
  204. left join (
  205. select
  206. aid,
  207. count(0) as weeklyFollowNo,
  208. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as weeklyVisitNo,
  209. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as weeklyTelNo
  210. from user_follow where 1=1
  211. and create_time &gt; #{weeklyStart,jdbcType=VARCHAR}
  212. and create_time &lt; #{weeklyEnd,jdbcType=VARCHAR}
  213. group by aid
  214. )z on y.aid = z.aid
  215. left join (
  216. select
  217. aid,
  218. count(0) as dayFollowNo,
  219. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as dayVisitNo,
  220. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as dayTelNo
  221. from user_follow where 1=1
  222. and create_time &gt; #{dayStart,jdbcType=VARCHAR}
  223. and create_time &lt; #{dayEnd,jdbcType=VARCHAR}
  224. group by aid
  225. )w on y.aid = w.aid
  226. )t2 on t1.id = t2.aid
  227. </select>
  228. <select id="marketingDepStatisticsList" parameterType="String" resultType="com.goafanti.report.bo.marketingESBo">
  229. select t1.departmentId,t1.departmentName,t1.departmentManagerName,t1.privateCustomersCount,t1.departmentNumber,
  230. t2.yearFollowNo,t2.yearVisitNo,t2.yearTelNo,
  231. t2.monthFollowNo,t2.monthVisitNo,t2.monthTelNo,
  232. t2.weeklyFollowNo,t2.weeklyVisitNo,t2.weeklyTelNo,
  233. t2.dayFollowNo,t2.dayVisitNo,t2.dayTelNo ,
  234. t2.dayFollowNo/t1.departmentNumber as dayAVG
  235. from(select
  236. a.department_id as departmentId,
  237. b.name as departmentName,
  238. c.name as departmentManagerName,
  239. a.count2 as privateCustomersCount,
  240. d.count3 as departmentNumber
  241. from ( select
  242. z.department_id,
  243. sum( y.count1 ) as count2 from
  244. ( select aid, count( aid ) as count1
  245. from user
  246. where aid is not null and aid !=''
  247. group by aid
  248. ) y left join admin z on
  249. y.aid = z.id
  250. group by
  251. z.department_id
  252. ) a left join department_management b
  253. on a.department_id = b.id left join admin c
  254. on b.manager_id=c.id left join (select department_id,count(0) as count3 from admin group by department_id)d
  255. on a.department_id = d.department_id
  256. where a.department_id is not null
  257. <if test="depId != null">
  258. and a.department_id = #{depId,jdbcType=VARCHAR}
  259. </if>
  260. )t1
  261. left join (
  262. select m.department_id as departmentId,sum(n.dayFollowNo)as dayFollowNo,sum(n.dayVisitNo)as dayVisitNo,sum(n.dayTelNo) as dayTelNo
  263. ,sum(n.weeklyFollowNo)as weeklyFollowNo,sum(n.weeklyVisitNo)as weeklyVisitNo,sum(n.weeklyTelNo) as weeklyTelNo
  264. ,sum(n.monthFollowNo)as monthFollowNo,sum(n.monthVisitNo)as monthVisitNo,sum(n.monthTelNo) as monthTelNo
  265. ,sum(n.yearFollowNo)as yearFollowNo,sum(n.yearVisitNo)as yearVisitNo,sum(n.yearTelNo) as yearTelNo
  266. from admin m left join
  267. (select x.aid,x.yearFollowNo,x.yearVisitNo,x.yearTelNo,
  268. y.monthFollowNo,y.monthVisitNo,y.monthTelNo,
  269. z.weeklyFollowNo,z.weeklyVisitNo,z.weeklyTelNo,
  270. w.dayFollowNo,w.dayVisitNo,dayTelNo
  271. from (
  272. select
  273. aid,
  274. count(0) as yearFollowNo,
  275. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as yearVisitNo,
  276. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as yearTelNo
  277. from user_follow where 1=1
  278. and create_time &gt; #{yearStart,jdbcType=VARCHAR}
  279. and create_time &lt; #{yearEnd,jdbcType=VARCHAR}
  280. group by aid
  281. )x left join (
  282. select
  283. aid,
  284. count(0) as monthFollowNo,
  285. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as monthVisitNo,
  286. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as monthTelNo
  287. from user_follow where 1=1
  288. and create_time &gt; #{monthStart,jdbcType=VARCHAR}
  289. and create_time &lt; #{monthEnd,jdbcType=VARCHAR}
  290. group by aid
  291. )y on x.aid = y.aid
  292. left join (
  293. select
  294. aid,
  295. count(0) as weeklyFollowNo,
  296. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as weeklyVisitNo,
  297. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as weeklyTelNo
  298. from user_follow where 1=1
  299. and create_time &gt; #{weeklyStart,jdbcType=VARCHAR}
  300. and create_time &lt; #{weeklyEnd,jdbcType=VARCHAR}
  301. group by aid
  302. )z on y.aid = z.aid
  303. left join (
  304. select
  305. aid,
  306. count(0) as dayFollowNo,
  307. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as dayVisitNo,
  308. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as dayTelNo
  309. from user_follow where 1=1
  310. and create_time &gt; #{dayStart,jdbcType=VARCHAR}
  311. and create_time &lt; #{dayEnd,jdbcType=VARCHAR}
  312. group by aid
  313. )w on y.aid = w.aid) n on m.id=n.aid
  314. where m.department_id is not null and m.department_id !=''
  315. group by m.department_id
  316. )t2 on t1.departmentId = t2.departmentId
  317. ORDER by t1.departmentName
  318. </select>
  319. <select id="privateCustomersCount" parameterType="string" resultType="com.goafanti.report.bo.CountMarketingStatisticsBo">
  320. select SUM( n.privateCustomersCount )as privateCustomersCount,
  321. SUM( m.dayFollowNo )as dayFollowNo,
  322. SUM( m.dayVisitNo )as dayVisitNo,
  323. SUM( m.dayTelNo )as dayTelNo,
  324. SUM( m.weeklyFollowNo )as weeklyFollowNo,
  325. SUM( m.weeklyVisitNo )as weeklyVisitNo,
  326. SUM( m.weeklyTelNo )as weeklyTelNo,
  327. SUM( m.monthFollowNo )as monthFollowNo,
  328. SUM( m.monthVisitNo )as monthVisitNo,
  329. SUM( m.monthTelNo )as monthTelNo,
  330. SUM( m.yearFollowNo )as yearFollowNo,
  331. SUM( m.yearVisitNo )as yearVisitNo,
  332. SUM( m.yearTelNo )as yearTelNo
  333. from(
  334. select a.id,sum(e.privateCustomersCount) as privateCustomersCount
  335. from admin a left join user_role b
  336. on a.id=b.uid left join role c
  337. on b.rid=c.id left join (select aid,count(0) as privateCustomersCount from user group by aid)e
  338. on a.id=e.aid where c.role_name in ('营销员','营销经理','营销管理员')
  339. <if test="depId != null">
  340. and a.department_id = #{depId,jdbcType=VARCHAR}
  341. </if>
  342. GROUP by a.id
  343. ) n left join (
  344. select x.aid,x.yearFollowNo,x.yearVisitNo,x.yearTelNo,
  345. y.monthFollowNo,y.monthVisitNo,y.monthTelNo,
  346. z.weeklyFollowNo,z.weeklyVisitNo,z.weeklyTelNo,
  347. w.dayFollowNo,w.dayVisitNo,w.dayTelNo
  348. from (
  349. select
  350. aid,
  351. count(0) as yearFollowNo,
  352. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as yearVisitNo,
  353. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as yearTelNo
  354. from user_follow where 1=1
  355. and create_time &gt; #{yearStart,jdbcType=VARCHAR}
  356. and create_time &lt; #{yearEnd,jdbcType=VARCHAR}
  357. group by aid
  358. )x left join (
  359. select
  360. aid,
  361. count(0) as monthFollowNo,
  362. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as monthVisitNo,
  363. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as monthTelNo
  364. from user_follow where 1=1
  365. and create_time &gt; #{monthStart,jdbcType=VARCHAR}
  366. and create_time &lt; #{monthEnd,jdbcType=VARCHAR}
  367. group by aid
  368. )y on x.aid = y.aid
  369. left join (
  370. select
  371. aid,
  372. count(0) as weeklyFollowNo,
  373. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as weeklyVisitNo,
  374. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as weeklyTelNo
  375. from user_follow where 1=1
  376. and create_time &gt; #{weeklyStart,jdbcType=VARCHAR}
  377. and create_time &lt; #{weeklyEnd,jdbcType=VARCHAR}
  378. group by aid
  379. )z on y.aid = z.aid
  380. left join (
  381. select
  382. aid,
  383. count(0) as dayFollowNo,
  384. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as dayVisitNo,
  385. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as dayTelNo
  386. from user_follow where 1=1
  387. and create_time &gt; #{dayStart,jdbcType=VARCHAR}
  388. and create_time &lt; #{dayEnd,jdbcType=VARCHAR}
  389. group by aid
  390. )w on y.aid = w.aid
  391. )m on n.id=m.aid
  392. </select>
  393. <select id="privateCustomersDepCount" parameterType="String" resultType="com.goafanti.report.bo.CountMarketingStatisticsBo">
  394. select sum(t1.privateCustomersCount) as privateCustomersCount,sum(t1.departmentNumber) as departmentNumber,
  395. sum(t2.yearFollowNo) as yearFollowNo,sum(t2.yearVisitNo) as yearVisitNo,sum(t2.yearTelNo) as yearTelNo,
  396. sum(t2.monthFollowNo) as monthFollowNo,sum(t2.monthVisitNo) as monthVisitNo,sum(t2.monthTelNo) as monthTelNo,
  397. sum(t2.weeklyFollowNo) as weeklyFollowNo,sum(t2.weeklyVisitNo) as weeklyVisitNo,sum(t2.weeklyTelNo) as weeklyTelNo,
  398. sum(t2.dayFollowNo) as dayFollowNo,sum(t2.dayVisitNo) as dayVisitNo,sum(t2.dayTelNo) as dayTelNo
  399. ,sum(t2.dayFollowNo)/sum(t1.departmentNumber) as dayAVG
  400. from(select
  401. a.department_id as departmentId,
  402. b.name as departmentName,
  403. c.name as departmentManagerName,
  404. a.count2 as privateCustomersCount,
  405. d.count3 as departmentNumber
  406. from ( select
  407. z.department_id,
  408. sum( y.count1 ) as count2 from
  409. ( select aid, count( aid ) as count1
  410. from user
  411. where aid is not null and aid !=''
  412. group by aid
  413. ) y left join admin z on
  414. y.aid = z.id
  415. group by
  416. z.department_id
  417. ) a left join department_management b
  418. on a.department_id = b.id left join admin c
  419. on b.manager_id=c.id left join (select department_id,count(0) as count3 from admin group by department_id)d
  420. on a.department_id = d.department_id
  421. where a.department_id is not null
  422. <if test="depId != null">
  423. and a.department_id = #{depId,jdbcType=VARCHAR}
  424. </if>
  425. )t1
  426. left join (
  427. select m.department_id as departmentId,sum(n.dayFollowNo)as dayFollowNo,sum(n.dayVisitNo)as dayVisitNo,sum(n.dayTelNo) as dayTelNo
  428. ,sum(n.weeklyFollowNo)as weeklyFollowNo,sum(n.weeklyVisitNo)as weeklyVisitNo,sum(n.weeklyTelNo) as weeklyTelNo
  429. ,sum(n.monthFollowNo)as monthFollowNo,sum(n.monthVisitNo)as monthVisitNo,sum(n.monthTelNo) as monthTelNo
  430. ,sum(n.yearFollowNo)as yearFollowNo,sum(n.yearVisitNo)as yearVisitNo,sum(n.yearTelNo) as yearTelNo
  431. from admin m left join
  432. (select x.aid,x.yearFollowNo,x.yearVisitNo,x.yearTelNo,
  433. y.monthFollowNo,y.monthVisitNo,y.monthTelNo,
  434. z.weeklyFollowNo,z.weeklyVisitNo,z.weeklyTelNo,
  435. w.dayFollowNo,w.dayVisitNo,dayTelNo
  436. from (
  437. select
  438. aid,
  439. count(0) as yearFollowNo,
  440. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as yearVisitNo,
  441. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as yearTelNo
  442. from user_follow where 1=1
  443. and create_time &gt; #{yearStart,jdbcType=VARCHAR}
  444. and create_time &lt; #{yearEnd,jdbcType=VARCHAR}
  445. group by aid
  446. )x left join (
  447. select
  448. aid,
  449. count(0) as monthFollowNo,
  450. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as monthVisitNo,
  451. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as monthTelNo
  452. from user_follow where 1=1
  453. and create_time &gt; #{monthStart,jdbcType=VARCHAR}
  454. and create_time &lt; #{monthEnd,jdbcType=VARCHAR}
  455. group by aid
  456. )y on x.aid = y.aid
  457. left join (
  458. select
  459. aid,
  460. count(0) as weeklyFollowNo,
  461. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as weeklyVisitNo,
  462. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as weeklyTelNo
  463. from user_follow where 1=1
  464. and create_time &gt; #{weeklyStart,jdbcType=VARCHAR}
  465. and create_time &lt; #{weeklyEnd,jdbcType=VARCHAR}
  466. group by aid
  467. )z on y.aid = z.aid
  468. left join (
  469. select
  470. aid,
  471. count(0) as dayFollowNo,
  472. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as dayVisitNo,
  473. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as dayTelNo
  474. from user_follow where 1=1
  475. and create_time &gt; #{dayStart,jdbcType=VARCHAR}
  476. and create_time &lt; #{dayEnd,jdbcType=VARCHAR}
  477. group by aid
  478. )w on y.aid = w.aid) n on m.id=n.aid
  479. where m.department_id is not null and m.department_id !=''
  480. group by m.department_id
  481. )t2 on t1.departmentId = t2.departmentId
  482. </select>
  483. <select id="sometimeMarketingStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
  484. select a.id,a.name,d.name as departmentName,role_name as roleName,ifnull(e.telNo,0)as countTelNo,
  485. ifnull(e.visitNo,0)as countVisitNo,ifnull(e.followNo,0)as countFollowNo
  486. <if test="startTime !=null and endTime !=null">
  487. ,e.followNo/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as dayAVG
  488. </if>
  489. from admin a left join user_role b on
  490. a.id = b.uid left join role c on
  491. b.rid = c.id left join department_management d on
  492. a.department_id = d.id left join ( select
  493. a.aid,
  494. count( 0 ) as followNo,
  495. ifnull(
  496. sum( case when a.contact_type = 0 then 1 else 0 end ),
  497. 0
  498. ) as visitNo,
  499. ifnull(
  500. sum( case when a.contact_type = 1 then 1 else 0 end ),
  501. 0
  502. ) as telNo
  503. from user_follow a
  504. where
  505. 1 = 1
  506. <if test="startTime !=null">
  507. and a.create_time &gt; #{startTime,jdbcType=VARCHAR}
  508. </if>
  509. <if test="endTime !=null">
  510. and a.create_time &lt; #{endTime,jdbcType=VARCHAR}
  511. </if>
  512. GROUP BY a.aid)e on a.id=e.aid
  513. where c.role_name in ('营销员','营销经理','营销管理员')
  514. <if test="depId != null">
  515. and a.department_id= #{depId,jdbcType=VARCHAR}
  516. </if>
  517. order by a.name
  518. </select>
  519. <select id="sometimeMarketingDepStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
  520. select z.id,z.name as departmentName,y.name as departmentManagerName,
  521. x.followNo as countFollowNo,x.visitNo as countVisitNo,x.telNo as countTelNo
  522. <if test="startTime !=null and endTime !=null">
  523. ,x.followNo/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as dayAVG
  524. </if>
  525. from (select b.department_id as departmentId,sum(a.followNo) as followNo,sum(a.visitNo)as visitNo,sum(a.telNo)as telNo
  526. from (select
  527. aid,
  528. count( 0 ) as followNo,
  529. ifnull(
  530. sum( case when contact_type = 0 then 1 else 0 end ),
  531. 0
  532. ) as visitNo,
  533. ifnull(
  534. sum( case when contact_type = 1 then 1 else 0 end ),
  535. 0
  536. ) as telNo
  537. from user_follow a where 1 = 1
  538. <if test="startTime !=null">
  539. and a.create_time &gt; #{startTime,jdbcType=VARCHAR}
  540. </if>
  541. <if test="endTime !=null">
  542. and a.create_time &lt; #{endTime,jdbcType=VARCHAR}
  543. </if>
  544. GROUP BY aid)a left join admin b on a.aid=b.id
  545. left join department_management c on b.department_id=c.id
  546. where b.department_id is not null and b.department_id !=''
  547. <if test="depId != null">
  548. and b.department_id=#{depId,jdbcType=VARCHAR}
  549. </if>
  550. GROUP by b.department_id
  551. ) x left join department_management z on x.departmentId=z.id
  552. left join admin y on z.manager_id=y.id
  553. </select>
  554. <select id="countsometimeMarketingStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
  555. select
  556. count( 0 ) as countFollowNo,
  557. ifnull(
  558. sum( case when a.contact_type = 0 then 1 else 0 end ),
  559. 0
  560. ) as countVisitNo,
  561. ifnull(
  562. sum( case when a.contact_type = 1 then 1 else 0 end ),
  563. 0
  564. ) as countTelNo
  565. <if test="startTime !=null and endTime !=null">
  566. ,count( 0 )/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as A
  567. </if>
  568. from
  569. user_follow a left join admin b on
  570. a.aid = b.id left join department_management c on
  571. b.department_id = c.id left join user_role d on
  572. b.id = d.uid left join role e on
  573. d.rid = e.id
  574. where 1 = 1
  575. and( e.role_name = '营销员' or e.role_name = '营销经理' or e.role_name = '营销管理员')
  576. <if test="depId != null">
  577. and a.department_id= #{depId,jdbcType=VARCHAR}
  578. </if>
  579. </select>
  580. <select id="countsometimeMarketingDepStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
  581. select
  582. count( 0 ) as countFollowNo,
  583. ifnull(
  584. sum( case when a.contact_type = 0 then 1 else 0 end ),
  585. 0
  586. ) as countVisitNo,
  587. ifnull(
  588. sum( case when a.contact_type = 1 then 1 else 0 end ),
  589. 0
  590. ) as countTelNo
  591. <if test="startTime !=null and endTime !=null">
  592. ,count( 0 )/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as A
  593. </if>
  594. from
  595. user_follow a left join admin b on
  596. a.aid = b.id left join department_management c on
  597. b.department_id = c.id left join user_role d on
  598. b.id = d.uid left join role e on
  599. d.rid = e.id
  600. where 1 = 1
  601. and( e.role_name = '营销员' or e.role_name = '营销经理' or e.role_name = '营销管理员')
  602. <if test="depId != null">
  603. and a.department_id= #{depId,jdbcType=VARCHAR}
  604. </if>
  605. </select>
  606. </mapper>