DailySalesReportMapper.xml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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 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 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 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 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 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 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 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 != '' and share_type=0 and status != 1 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. t1.dataCount,
  231. t2.yearFollowNo,t2.yearVisitNo,t2.yearTelNo,
  232. t2.monthFollowNo,t2.monthVisitNo,t2.monthTelNo,
  233. t2.weeklyFollowNo,t2.weeklyVisitNo,t2.weeklyTelNo,
  234. t2.dayFollowNo,t2.dayVisitNo,t2.dayTelNo ,
  235. t2.dayFollowNo/t1.departmentNumber as dayAVG
  236. from(
  237. select
  238. a.department_id as departmentId,
  239. b.name as departmentName,
  240. c.name as departmentManagerName,
  241. a.count2 as privateCustomersCount,
  242. d.count3 as departmentNumber,
  243. a.dataCount
  244. from ( select
  245. z.department_id,
  246. sum( y.count1 ) as count2
  247. ,ifnull(sum(y2.dataCount),0) as dataCount
  248. from
  249. ( select aid, count( aid ) as count1
  250. from user
  251. where aid is not null and aid !=''
  252. and share_type=0
  253. and status != 1
  254. group by aid
  255. ) y left join admin z on
  256. y.aid = z.id left join (select aid,count(0) as dataCount from user
  257. where create_time &gt; date_sub(curdate(),interval 2 day)
  258. and create_time &lt; curdate()
  259. group by aid) y2 on y2.aid=z.id
  260. group by z.department_id
  261. ) a left join department b
  262. on a.department_id = b.id left join admin c
  263. on b.manager_id=c.id left join (select department_id,count(0) as count3 from admin group by department_id)d
  264. on a.department_id = d.department_id
  265. where a.department_id is not null
  266. <if test="depId != null">
  267. and a.department_id = #{depId,jdbcType=VARCHAR}
  268. </if>
  269. )t1
  270. left join (
  271. select m.department_id as departmentId,sum(n.dayFollowNo)as dayFollowNo,sum(n.dayVisitNo)as dayVisitNo,sum(n.dayTelNo) as dayTelNo
  272. ,sum(n.weeklyFollowNo)as weeklyFollowNo,sum(n.weeklyVisitNo)as weeklyVisitNo,sum(n.weeklyTelNo) as weeklyTelNo
  273. ,sum(n.monthFollowNo)as monthFollowNo,sum(n.monthVisitNo)as monthVisitNo,sum(n.monthTelNo) as monthTelNo
  274. ,sum(n.yearFollowNo)as yearFollowNo,sum(n.yearVisitNo)as yearVisitNo,sum(n.yearTelNo) as yearTelNo
  275. from admin m left join
  276. (select x.aid,x.yearFollowNo,x.yearVisitNo,x.yearTelNo,
  277. y.monthFollowNo,y.monthVisitNo,y.monthTelNo,
  278. z.weeklyFollowNo,z.weeklyVisitNo,z.weeklyTelNo,
  279. w.dayFollowNo,w.dayVisitNo,dayTelNo
  280. from (
  281. select
  282. aid,
  283. count(0) as yearFollowNo,
  284. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as yearVisitNo,
  285. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as yearTelNo
  286. from user_follow where 1=1
  287. and create_time &gt; #{yearStart,jdbcType=VARCHAR}
  288. and create_time &lt; #{yearEnd,jdbcType=VARCHAR}
  289. group by aid
  290. )x left join (
  291. select
  292. aid,
  293. count(0) as monthFollowNo,
  294. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as monthVisitNo,
  295. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as monthTelNo
  296. from user_follow where 1=1
  297. and create_time &gt; #{monthStart,jdbcType=VARCHAR}
  298. and create_time &lt; #{monthEnd,jdbcType=VARCHAR}
  299. group by aid
  300. )y on x.aid = y.aid
  301. left join (
  302. select
  303. aid,
  304. count(0) as weeklyFollowNo,
  305. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as weeklyVisitNo,
  306. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as weeklyTelNo
  307. from user_follow where 1=1
  308. and create_time &gt; #{weeklyStart,jdbcType=VARCHAR}
  309. and create_time &lt; #{weeklyEnd,jdbcType=VARCHAR}
  310. group by aid
  311. )z on y.aid = z.aid
  312. left join (
  313. select
  314. aid,
  315. count(0) as dayFollowNo,
  316. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as dayVisitNo,
  317. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as dayTelNo
  318. from user_follow where 1=1
  319. and create_time &gt; #{dayStart,jdbcType=VARCHAR}
  320. and create_time &lt; #{dayEnd,jdbcType=VARCHAR}
  321. group by aid
  322. )w on y.aid = w.aid) n on m.id=n.aid
  323. where m.department_id is not null and m.department_id !=''
  324. group by m.department_id
  325. )t2 on t1.departmentId = t2.departmentId
  326. ORDER by t1.departmentName
  327. </select>
  328. <select id="privateCustomersCount" parameterType="string" resultType="com.goafanti.report.bo.CountMarketingStatisticsBo">
  329. select SUM( n.privateCustomersCount )as privateCustomersCount,
  330. SUM( m.dayFollowNo )as dayFollowNo,
  331. SUM( m.dayVisitNo )as dayVisitNo,
  332. SUM( m.dayTelNo )as dayTelNo,
  333. SUM( m.weeklyFollowNo )as weeklyFollowNo,
  334. SUM( m.weeklyVisitNo )as weeklyVisitNo,
  335. SUM( m.weeklyTelNo )as weeklyTelNo,
  336. SUM( m.monthFollowNo )as monthFollowNo,
  337. SUM( m.monthVisitNo )as monthVisitNo,
  338. SUM( m.monthTelNo )as monthTelNo,
  339. SUM( m.yearFollowNo )as yearFollowNo,
  340. SUM( m.yearVisitNo )as yearVisitNo,
  341. SUM( m.yearTelNo )as yearTelNo
  342. from(
  343. select a.id,sum(e.privateCustomersCount) as privateCustomersCount
  344. from admin a left join user_role b
  345. on a.id=b.uid left join role c
  346. on b.rid=c.id left join (select aid,count(0) as privateCustomersCount from user where aid is not null and aid !=''
  347. and share_type=0 and status != 1 group by aid)e
  348. on a.id=e.aid where c.role_name in ('营销员','营销经理','营销管理员')
  349. <if test="depId != null">
  350. and a.department_id = #{depId,jdbcType=VARCHAR}
  351. </if>
  352. GROUP by a.id
  353. ) n left join (
  354. select x.aid,x.yearFollowNo,x.yearVisitNo,x.yearTelNo,
  355. y.monthFollowNo,y.monthVisitNo,y.monthTelNo,
  356. z.weeklyFollowNo,z.weeklyVisitNo,z.weeklyTelNo,
  357. w.dayFollowNo,w.dayVisitNo,w.dayTelNo
  358. from (
  359. select
  360. aid,
  361. count(0) as yearFollowNo,
  362. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as yearVisitNo,
  363. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as yearTelNo
  364. from user_follow where 1=1
  365. and create_time &gt; #{yearStart,jdbcType=VARCHAR}
  366. and create_time &lt; #{yearEnd,jdbcType=VARCHAR}
  367. group by aid
  368. )x left join (
  369. select
  370. aid,
  371. count(0) as monthFollowNo,
  372. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as monthVisitNo,
  373. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as monthTelNo
  374. from user_follow where 1=1
  375. and create_time &gt; #{monthStart,jdbcType=VARCHAR}
  376. and create_time &lt; #{monthEnd,jdbcType=VARCHAR}
  377. group by aid
  378. )y on x.aid = y.aid
  379. left join (
  380. select
  381. aid,
  382. count(0) as weeklyFollowNo,
  383. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as weeklyVisitNo,
  384. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as weeklyTelNo
  385. from user_follow where 1=1
  386. and create_time &gt; #{weeklyStart,jdbcType=VARCHAR}
  387. and create_time &lt; #{weeklyEnd,jdbcType=VARCHAR}
  388. group by aid
  389. )z on y.aid = z.aid
  390. left join (
  391. select
  392. aid,
  393. count(0) as dayFollowNo,
  394. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as dayVisitNo,
  395. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as dayTelNo
  396. from user_follow where 1=1
  397. and create_time &gt; #{dayStart,jdbcType=VARCHAR}
  398. and create_time &lt; #{dayEnd,jdbcType=VARCHAR}
  399. group by aid
  400. )w on y.aid = w.aid
  401. )m on n.id=m.aid
  402. </select>
  403. <select id="privateCustomersDepCount" parameterType="String" resultType="com.goafanti.report.bo.CountMarketingStatisticsBo">
  404. select sum(t1.privateCustomersCount) as privateCustomersCount,sum(t1.departmentNumber) as departmentNumber,
  405. sum(t1.dataCount) as dataCount,
  406. sum(t2.yearFollowNo) as yearFollowNo,sum(t2.yearVisitNo) as yearVisitNo,sum(t2.yearTelNo) as yearTelNo,
  407. sum(t2.monthFollowNo) as monthFollowNo,sum(t2.monthVisitNo) as monthVisitNo,sum(t2.monthTelNo) as monthTelNo,
  408. sum(t2.weeklyFollowNo) as weeklyFollowNo,sum(t2.weeklyVisitNo) as weeklyVisitNo,sum(t2.weeklyTelNo) as weeklyTelNo,
  409. sum(t2.dayFollowNo) as dayFollowNo,sum(t2.dayVisitNo) as dayVisitNo,sum(t2.dayTelNo) as dayTelNo
  410. ,sum(t2.dayFollowNo)/sum(t1.departmentNumber) as dayAVG
  411. from(select
  412. a.department_id as departmentId,
  413. b.name as departmentName,
  414. c.name as departmentManagerName,
  415. a.count2 as privateCustomersCount,
  416. a.dataCount ,
  417. d.count3 as departmentNumber
  418. from ( select
  419. z.department_id,
  420. sum( y.count1 ) as count2
  421. ,ifnull(sum(y2.dataCount),0) as dataCount
  422. from
  423. ( select aid, count( aid ) as count1
  424. from user
  425. where aid is not null and aid !=''
  426. and share_type=0 and status != 1
  427. group by aid
  428. ) y left join admin z on
  429. y.aid = z.id left join (select aid,count(0) as dataCount from user
  430. where create_time &gt; date_sub(curdate(),interval 2 day)
  431. and create_time &lt; curdate()
  432. group by aid) y2 on y2.aid=z.id
  433. group by
  434. z.department_id
  435. ) a left join department b
  436. on a.department_id = b.id left join admin c
  437. on b.manager_id=c.id left join (select department_id,count(0) as count3 from admin group by department_id)d
  438. on a.department_id = d.department_id
  439. where a.department_id is not null
  440. <if test="depId != null">
  441. and a.department_id = #{depId,jdbcType=VARCHAR}
  442. </if>
  443. )t1
  444. left join (
  445. select m.department_id as departmentId,sum(n.dayFollowNo)as dayFollowNo,sum(n.dayVisitNo)as dayVisitNo,sum(n.dayTelNo) as dayTelNo
  446. ,sum(n.weeklyFollowNo)as weeklyFollowNo,sum(n.weeklyVisitNo)as weeklyVisitNo,sum(n.weeklyTelNo) as weeklyTelNo
  447. ,sum(n.monthFollowNo)as monthFollowNo,sum(n.monthVisitNo)as monthVisitNo,sum(n.monthTelNo) as monthTelNo
  448. ,sum(n.yearFollowNo)as yearFollowNo,sum(n.yearVisitNo)as yearVisitNo,sum(n.yearTelNo) as yearTelNo
  449. from admin m left join
  450. (select x.aid,x.yearFollowNo,x.yearVisitNo,x.yearTelNo,
  451. y.monthFollowNo,y.monthVisitNo,y.monthTelNo,
  452. z.weeklyFollowNo,z.weeklyVisitNo,z.weeklyTelNo,
  453. w.dayFollowNo,w.dayVisitNo,w.dayTelNo
  454. from (
  455. select
  456. aid,
  457. count(0) as yearFollowNo,
  458. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as yearVisitNo,
  459. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as yearTelNo
  460. from user_follow where 1=1
  461. and create_time &gt; #{yearStart,jdbcType=VARCHAR}
  462. and create_time &lt; #{yearEnd,jdbcType=VARCHAR}
  463. group by aid
  464. )x left join (
  465. select
  466. aid,
  467. count(0) as monthFollowNo,
  468. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as monthVisitNo,
  469. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as monthTelNo
  470. from user_follow where 1=1
  471. and create_time &gt; #{monthStart,jdbcType=VARCHAR}
  472. and create_time &lt; #{monthEnd,jdbcType=VARCHAR}
  473. group by aid
  474. )y on x.aid = y.aid
  475. left join (
  476. select
  477. aid,
  478. count(0) as weeklyFollowNo,
  479. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as weeklyVisitNo,
  480. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as weeklyTelNo
  481. from user_follow where 1=1
  482. and create_time &gt; #{weeklyStart,jdbcType=VARCHAR}
  483. and create_time &lt; #{weeklyEnd,jdbcType=VARCHAR}
  484. group by aid
  485. )z on y.aid = z.aid
  486. left join (
  487. select
  488. aid,
  489. count(0) as dayFollowNo,
  490. ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as dayVisitNo,
  491. ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as dayTelNo
  492. from user_follow where 1=1
  493. and create_time &gt; #{dayStart,jdbcType=VARCHAR}
  494. and create_time &lt; #{dayEnd,jdbcType=VARCHAR}
  495. group by aid
  496. )w on y.aid = w.aid) n on m.id=n.aid
  497. where m.department_id is not null and m.department_id !=''
  498. group by m.department_id
  499. )t2 on t1.departmentId = t2.departmentId
  500. </select>
  501. <select id="sometimeMarketingStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
  502. select a.id,a.name,d.id as departmentId,d.name as departmentName,role_name as roleName,ifnull(e.telNo,0)as countTelNo,
  503. ifnull(e.visitNo,0)as countVisitNo,ifnull(e.followNo,0)as countFollowNo
  504. <if test="startTime !=null and endTime !=null">
  505. ,e.followNo/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as dayAVG
  506. </if>
  507. from admin a left join user_role b on
  508. a.id = b.uid left join role c on
  509. b.rid = c.id left join department d on
  510. a.department_id = d.id left join ( select
  511. a.aid,
  512. count( 0 ) as followNo,
  513. ifnull(
  514. sum( case when a.contact_type = 0 then 1 else 0 end ),
  515. 0
  516. ) as visitNo,
  517. ifnull(
  518. sum( case when a.contact_type = 1 then 1 else 0 end ),
  519. 0
  520. ) as telNo
  521. from user_follow a
  522. where
  523. 1 = 1
  524. <if test="startTime !=null">
  525. and a.create_time &gt; #{startTime,jdbcType=VARCHAR}
  526. </if>
  527. <if test="endTime !=null">
  528. and a.create_time &lt; #{endTime,jdbcType=VARCHAR}
  529. </if>
  530. GROUP BY a.aid)e on a.id=e.aid
  531. where c.role_name in ('营销员','营销经理','营销管理员')
  532. <if test="depId != null">
  533. and a.department_id= #{depId,jdbcType=VARCHAR}
  534. </if>
  535. order by a.name
  536. </select>
  537. <select id="sometimeMarketingDepStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
  538. select z.id,z.name as departmentName,y.name as departmentManagerName,
  539. x.followNo as countFollowNo,x.visitNo as countVisitNo,x.telNo as countTelNo
  540. <if test="startTime !=null and endTime !=null">
  541. ,x.followNo/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as dayAVG
  542. </if>
  543. from (select a.id, a.name,a.manager_id
  544. from department a left join admin b on a.id=b.department_id
  545. left join user_role c on b.id = c.uid
  546. left join role d on c.rid = d.id
  547. where d.role_name in ('营销员','营销经理','营销管理员')
  548. <if test="depId != null">
  549. and a.id=#{depId,jdbcType=VARCHAR}
  550. </if>
  551. group by a.id) z left join (select b.department_id as departmentId,sum(a.followNo) as followNo,sum(a.visitNo)as visitNo,sum(a.telNo)as telNo
  552. from (select
  553. aid,
  554. count( 0 ) as followNo,
  555. ifnull(
  556. sum( case when contact_type = 0 then 1 else 0 end ),
  557. 0
  558. ) as visitNo,
  559. ifnull(
  560. sum( case when contact_type = 1 then 1 else 0 end ),
  561. 0
  562. ) as telNo
  563. from user_follow a where 1 = 1
  564. <if test="startTime !=null">
  565. and a.create_time &gt; #{startTime,jdbcType=VARCHAR}
  566. </if>
  567. <if test="endTime !=null">
  568. and a.create_time &lt; #{endTime,jdbcType=VARCHAR}
  569. </if>
  570. GROUP BY aid)a left join admin b on a.aid=b.id
  571. left join department c on b.department_id=c.id
  572. where b.department_id is not null and b.department_id !=''
  573. GROUP by b.department_id
  574. ) x on x.departmentId=z.id
  575. left join admin y on z.manager_id=y.id
  576. </select>
  577. <select id="countsometimeMarketingStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
  578. select
  579. count( 0 ) as countFollowNo,
  580. ifnull(
  581. sum( case when a.contact_type = 0 then 1 else 0 end ),
  582. 0
  583. ) as countVisitNo,
  584. ifnull(
  585. sum( case when a.contact_type = 1 then 1 else 0 end ),
  586. 0
  587. ) as countTelNo
  588. <if test="startTime !=null and endTime !=null">
  589. ,count( 0 )/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as dayAVG
  590. </if>
  591. from
  592. user_follow a left join admin b on
  593. a.aid = b.id left join department c on
  594. b.department_id = c.id left join user_role d on
  595. b.id = d.uid left join role e on
  596. d.rid = e.id
  597. where 1 = 1
  598. and( e.role_name = '营销员' or e.role_name = '营销经理' or e.role_name = '营销管理员')
  599. <if test="startTime !=null">
  600. and a.create_time &gt; #{startTime,jdbcType=VARCHAR}
  601. </if>
  602. <if test="endTime !=null">
  603. and a.create_time &lt; #{endTime,jdbcType=VARCHAR}
  604. </if>
  605. <if test="depId != null">
  606. and b.department_id= #{depId,jdbcType=VARCHAR}
  607. </if>
  608. </select>
  609. <select id="countsometimeMarketingDepStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
  610. select
  611. count( 0 ) as countFollowNo,
  612. ifnull(
  613. sum( case when a.contact_type = 0 then 1 else 0 end ),
  614. 0
  615. ) as countVisitNo,
  616. ifnull(
  617. sum( case when a.contact_type = 1 then 1 else 0 end ),
  618. 0
  619. ) as countTelNo
  620. <if test="startTime !=null and endTime !=null">
  621. ,count( 0 )/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as A
  622. </if>
  623. from
  624. user_follow a left join admin b on
  625. a.aid = b.id left join department c on
  626. b.department_id = c.id left join user_role d on
  627. b.id = d.uid left join role e on
  628. d.rid = e.id
  629. where 1 = 1
  630. and( e.role_name = '营销员' or e.role_name = '营销经理' or e.role_name = '营销管理员')
  631. <if test="depId != null">
  632. and a.department_id= #{depId,jdbcType=VARCHAR}
  633. </if>
  634. </select>
  635. <select id="technicalDepStatistics" parameterType='String' resultType="com.goafanti.report.bo.technicalDepStatisticsListBo">
  636. select
  637. d.nickname as OrgName,f.name as orderDep,c.sign_total_amount as signTotalAmount,
  638. date_format( c.sign_time, '%Y-%m-%d' ) as signTime,c.contract_no as contractNo,
  639. c.order_remarks as orderRemarks, g.contacts, g.contact_mobile as contactMobile,
  640. a.commodity_name as commodityName, date_format( a.task_distribution_time, '%Y-%m-%d %H:%i:%S' ) as taskDistributionTime,
  641. i.name as dutyDep, h.name as dutyName, h.contact_mobile as dutyContactMobile,
  642. (case when a.task_status = 0 then '未分配' when a.task_status = 1 then '已派单'
  643. when a.task_status = 2 then '材料已启动' when a.task_status = 3 then '材料已完成'end ) as taskStatus,
  644. a.finish_time as finishTime, a.task_comment as taskComment,
  645. (case when a.publish_status = 0 then '已公示' when a.publish_status = 1 then '未公示'
  646. when a.publish_status = 2 then '待公示' when a.publish_status = 3 then '抽查中' end) as publishStatus,
  647. a.publish_time as publishTime, e.name as salesmanName
  648. from
  649. contract_task a left join contract b on
  650. a.contract_id = b.id left join user d on
  651. b.uid = d.id left join t_order c on
  652. b.order_no = c.order_no left join admin e on
  653. c.salesman_id = e.id left join department f on
  654. e.department_id = f.id left join organization_identity g on
  655. d.id = g.uid left join admin h on
  656. a.task_receiver = h.id left join department i on
  657. h.department_id = i.id
  658. where 1=1
  659. <if test="depId != null">
  660. and e.department_id= #{depId,jdbcType=VARCHAR}
  661. </if>
  662. <if test="taskStatus != null">
  663. and a.task_status = #{taskStatus,jdbcType=VARCHAR}
  664. </if>
  665. <if test="publishStatus != null">
  666. and a.publish_status= #{publishStatus,jdbcType=VARCHAR}
  667. </if>
  668. <if test="startTime !=null">
  669. and c.sign_time &gt; #{startTime,jdbcType=VARCHAR}
  670. </if>
  671. <if test="endTime !=null">
  672. and c.sign_time &lt; #{endTime,jdbcType=VARCHAR}
  673. </if>
  674. order by c.sign_time desc,f.name
  675. </select>
  676. </mapper>