DailySalesReportMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 a.id ,a.name,a.department_id as departmentId,d.name as departmentName,d.manager_id,f.name as departmentManagerName,
  159. c.role_name as roleName,ifnull(e.privateCustomersCount,0)as privateCustomersCount,a.create_time as entryTime
  160. from admin a left join user_role b
  161. on a.id=b.uid left join role c
  162. on b.rid=c.id left join department_management d
  163. on a.department_id=d.id left join (select aid,count(0) as privateCustomersCount from user group by aid)e
  164. on a.id=e.aid left join admin f
  165. on d.manager_id=f.id
  166. where 1=1
  167. and (c.role_name='营销员' or c.role_name='营销经理'or c.role_name='营销管理员')
  168. <if test="depId != null">
  169. and a.department_id = #{depId,jdbcType=VARCHAR}
  170. </if>
  171. order by a.name desc
  172. </select>
  173. <select id="marketingDepStatisticsList" parameterType="String" resultType="com.goafanti.report.bo.marketingESBo">
  174. select
  175. a.department_id as departmentId,
  176. b.name as departmentName,
  177. b.manager_id,
  178. c.name as departmentManagerName,
  179. a.count2 as privateCustomersCount,
  180. d.count3 as departmentNumber
  181. from
  182. (
  183. select
  184. z.department_id,
  185. sum( y.count1 ) as count2
  186. from
  187. (
  188. select
  189. a.id,
  190. count( a.id ) as count1
  191. from
  192. admin a left join user b on
  193. a.id = b.aid
  194. group by
  195. a.id
  196. ) y left join admin z on
  197. y.id = z.id
  198. group by
  199. z.department_id
  200. ) a left join department_management b
  201. on a.department_id = b.id left join admin c
  202. on b.manager_id=c.id left join (select department_id,count(0) as count3 from admin group by department_id)d
  203. on a.department_id = d.department_id
  204. where 1=1
  205. <if test="depId != null">
  206. and a.department_id = #{depId,jdbcType=VARCHAR}
  207. </if>
  208. order by b.name desc
  209. </select>
  210. <select id="privateCustomersCount" parameterType="string" resultType="com.goafanti.report.bo.CountMarketingStatisticsBo">
  211. select sum(e.privateCustomersCount) as privateCustomersCount
  212. from admin a left join user_role b
  213. on a.id=b.uid left join role c
  214. on b.rid=c.id left join department_management d
  215. on a.department_id=d.id left join (select aid,count(0) as privateCustomersCount from user group by aid)e
  216. on a.id=e.aid where 1=1
  217. <if test="depId != null">
  218. and a.department_id = #{depId,jdbcType=VARCHAR}
  219. </if>
  220. and (c.role_name='营销员' or c.role_name='营销经理'or c.role_name='营销管理员')
  221. </select>
  222. <select id="privateCustomersDepCount" parameterType="String" resultType="com.goafanti.report.bo.CountDepMarketingStatisticsBo">
  223. select
  224. sum(a.count2) as privateCustomersCount,
  225. sum(d.count3) as departmentNumber
  226. from
  227. (
  228. select
  229. z.department_id,
  230. sum( y.count1 ) as count2
  231. from
  232. (
  233. select
  234. a.id,
  235. count( a.id ) as count1
  236. from
  237. admin a left join user b on
  238. a.id = b.aid
  239. group by
  240. a.id
  241. ) y left join admin z on
  242. y.id = z.id
  243. group by
  244. z.department_id
  245. ) a left join department_management b
  246. on a.department_id = b.id left join admin c
  247. on b.manager_id=c.id left join (select department_id,count(0) as count3 from admin group by department_id)d
  248. on a.department_id = d.department_id
  249. where 1=1
  250. <if test="depId != null">
  251. and a.department_id = #{depId,jdbcType=VARCHAR}
  252. </if>
  253. </select>
  254. <select id="sometimeMarketingStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
  255. select a.id,a.name,d.name as departmentName,role_name as roleName,ifnull(e.telNo,0)as countTelNo,
  256. ifnull(e.visitNo,0)as countVisitNo,ifnull(e.followNo,0)as countFollowNo
  257. <if test="startTime !=null and endTime !=null">
  258. ,countFollowNo/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as AVG
  259. </if>
  260. from admin a left join user_role b on
  261. a.id = b.uid left join role c on
  262. b.rid = c.id left join department_management d on
  263. a.department_id = d.id left join ( select
  264. a.aid,
  265. count( 0 ) as followNo,
  266. ifnull(
  267. sum( case when a.contact_type = 0 then 1 else 0 end ),
  268. 0
  269. ) as visitNo,
  270. ifnull(
  271. sum( case when a.contact_type = 1 then 1 else 0 end ),
  272. 0
  273. ) as telNo
  274. from user_follow a
  275. where
  276. 1 = 1
  277. <if test="startTime !=null">
  278. and a.create_time &gt; #{startTime,jdbcType=VARCHAR}
  279. </if>
  280. <if test="endTime !=null">
  281. and a.create_time &lt; #{endTime,jdbcType=VARCHAR}
  282. </if>
  283. GROUP BY a.aid)e on a.id=e.aid
  284. where
  285. 1 = 1
  286. and(
  287. c.role_name = '营销员'
  288. or c.role_name = '营销经理'
  289. or c.role_name = '营销管理员'
  290. )
  291. <if test="depId != null">
  292. and a.department_id= #{depId,jdbcType=VARCHAR}
  293. </if>
  294. </select>
  295. <select id="sometimeMarketingDepStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
  296. select
  297. a.department_id as departmentId,
  298. d.name as departmentName,
  299. f.name as departmentManagerName,
  300. d.manager_id,
  301. ifnull(e.telNo,0) as countTelNo,
  302. ifnull(e.visitNo,0) as countVisitNo,
  303. ifnull(e.followNo,0) as countFollowNo
  304. <if test="startTime !=null and endTime !=null">
  305. ,e.followNo/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as AVG
  306. </if>
  307. from admin a left join user_role b on
  308. a.id = b.uid left join role c on
  309. b.rid = c.id left join department_management d on
  310. a.department_id = d.id left join admin f on
  311. d.manager_id=f.id left join (select
  312. b.department_id,
  313. count( 0 ) as followNo,
  314. ifnull(
  315. sum( case when a.contact_type = 0 then 1 else 0 end ),
  316. 0
  317. ) as visitNo,
  318. ifnull(
  319. sum( case when a.contact_type = 1 then 1 else 0 end ),
  320. 0
  321. ) as telNo
  322. from user_follow a left join admin b on a.aid=b.id
  323. left join department_management c on b.department_id=c.id
  324. where
  325. 1 = 1
  326. <if test="startTime !=null">
  327. and a.create_time &gt; #{startTime,jdbcType=VARCHAR}
  328. </if>
  329. <if test="endTime !=null">
  330. and a.create_time &lt; #{endTime,jdbcType=VARCHAR}
  331. </if>
  332. GROUP BY b.department_id)e on a.department_id=e.department_id
  333. where
  334. 1 = 1
  335. and(
  336. c.role_name = '营销员'
  337. or c.role_name = '营销经理'
  338. or c.role_name = '营销管理员'
  339. )
  340. <if test="depId != null">
  341. and a.department_id= #{depId,jdbcType=VARCHAR}
  342. </if>
  343. group by a.department_id
  344. </select>
  345. <select id="countsometimeMarketingStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
  346. select
  347. count( 0 ) as countFollowNo,
  348. ifnull(
  349. sum( case when a.contact_type = 0 then 1 else 0 end ),
  350. 0
  351. ) as countVisitNo,
  352. ifnull(
  353. sum( case when a.contact_type = 1 then 1 else 0 end ),
  354. 0
  355. ) as countTelNo
  356. <if test="startTime !=null and endTime !=null">
  357. ,count( 0 )/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as A
  358. </if>
  359. from
  360. user_follow a left join admin b on
  361. a.aid = b.id left join department_management c on
  362. b.department_id = c.id left join user_role d on
  363. b.id = d.uid left join role e on
  364. d.rid = e.id
  365. where 1 = 1
  366. and( e.role_name = '营销员' or e.role_name = '营销经理' or e.role_name = '营销管理员')
  367. <if test="depId != null">
  368. and a.department_id= #{depId,jdbcType=VARCHAR}
  369. </if>
  370. </select>
  371. </mapper>