|
|
@@ -58,173 +58,6 @@
|
|
|
SELECT * FROM t1,t2,t3,t4,t5
|
|
|
</select>
|
|
|
|
|
|
- <select id="getStatisticNumByPersonal" resultType="com.fs.company.dto.ComprehensiveStatisticsDTO">
|
|
|
- WITH RECURSIVE date_range AS (
|
|
|
- SELECT #{startTime} AS dt
|
|
|
- UNION ALL
|
|
|
- SELECT DATE_ADD(dt, INTERVAL 1 DAY)
|
|
|
- FROM date_range
|
|
|
- WHERE dt < #{endTime}
|
|
|
- ),
|
|
|
- t1 AS (
|
|
|
- SELECT
|
|
|
- COUNT(qec.id) AS t1_count,
|
|
|
- d.dt AS create_time
|
|
|
- FROM date_range d
|
|
|
- LEFT JOIN qw_external_contact qec
|
|
|
- ON DATE(qec.create_time) = d.dt
|
|
|
- <if test="userIds != null">
|
|
|
- <if test="dimension == 1">
|
|
|
- <choose>
|
|
|
- <when test="userIds.length > 1 ">
|
|
|
- AND qec.company_user_id IN (
|
|
|
- <foreach collection="userIds" item="i" separator=",">
|
|
|
- #{i}
|
|
|
- </foreach>
|
|
|
- )
|
|
|
- </when>
|
|
|
- <otherwise>
|
|
|
- AND qec.company_user_id = #{userIds[0]}
|
|
|
- </otherwise>
|
|
|
- </choose>
|
|
|
- </if>
|
|
|
- <if test="dimension == 2">
|
|
|
- AND qec.company_id = #{userIds[0]}
|
|
|
- </if>
|
|
|
- </if>
|
|
|
- GROUP BY d.dt
|
|
|
- ),
|
|
|
- t2 AS (
|
|
|
- SELECT
|
|
|
- COUNT(qec.id) AS t2_count,
|
|
|
- d.dt AS create_time
|
|
|
- FROM date_range d
|
|
|
- LEFT JOIN qw_external_contact qec
|
|
|
- ON DATE(qec.create_time) = d.dt
|
|
|
- <if test="userIds != null">
|
|
|
- <if test="dimension == 1">
|
|
|
- <choose>
|
|
|
- <when test="userIds.length > 1 ">
|
|
|
- AND qec.company_user_id IN (
|
|
|
- <foreach collection="userIds" item="i" separator=",">
|
|
|
- #{i}
|
|
|
- </foreach>
|
|
|
- )
|
|
|
- </when>
|
|
|
- <otherwise>
|
|
|
- AND qec.company_user_id = #{userIds[0]}
|
|
|
- </otherwise>
|
|
|
- </choose>
|
|
|
- </if>
|
|
|
- <if test="dimension == 2">
|
|
|
- AND qec.company_id = #{userIds[0]}
|
|
|
- </if>
|
|
|
- </if>
|
|
|
- AND qec.fs_user_id IS NOT NULL
|
|
|
- GROUP BY d.dt
|
|
|
- ),
|
|
|
- t4 AS (
|
|
|
- SELECT
|
|
|
- d.dt AS create_time,
|
|
|
- COUNT(fcwl.qw_external_contact_id) AS completeNum
|
|
|
- FROM
|
|
|
- date_range d
|
|
|
- LEFT JOIN fs_course_watch_log AS fcwl
|
|
|
- ON DATE(fcwl.create_time) = d.dt
|
|
|
- AND fcwl.log_type = 2
|
|
|
- <if test="userIds != null">
|
|
|
- <if test="dimension == 1">
|
|
|
- <choose>
|
|
|
- <when test="userIds.length > 1 ">
|
|
|
- AND fcwl.company_user_id IN (
|
|
|
- <foreach collection="userIds" item="i" separator=",">
|
|
|
- #{i}
|
|
|
- </foreach>
|
|
|
- )
|
|
|
- </when>
|
|
|
- <otherwise>
|
|
|
- AND fcwl.company_user_id = #{userIds[0]}
|
|
|
- </otherwise>
|
|
|
- </choose>
|
|
|
- </if>
|
|
|
- <if test="dimension == 2">
|
|
|
- AND fcwl.company_id = #{userIds[0]}
|
|
|
- </if>
|
|
|
- </if>
|
|
|
- GROUP BY d.dt
|
|
|
- ),
|
|
|
- t5 AS (
|
|
|
- SELECT
|
|
|
- d.dt AS create_time,
|
|
|
- COUNT(fcal.log_id) AS answerNum
|
|
|
- FROM
|
|
|
- date_range d
|
|
|
- LEFT JOIN fs_course_answer_logs AS fcal
|
|
|
- ON DATE(fcal.create_time) = d.dt
|
|
|
- <if test="userIds != null">
|
|
|
- <if test="dimension == 1">
|
|
|
- <choose>
|
|
|
- <when test="userIds.length > 1 ">
|
|
|
- AND fcal.company_user_id IN (
|
|
|
- <foreach collection="userIds" item="i" separator=",">
|
|
|
- #{i}
|
|
|
- </foreach>
|
|
|
- )
|
|
|
- </when>
|
|
|
- <otherwise>
|
|
|
- AND fcal.company_user_id = #{userIds[0]}
|
|
|
- </otherwise>
|
|
|
- </choose>
|
|
|
- </if>
|
|
|
- <if test="dimension == 2">
|
|
|
- AND fcal.company_id = #{userIds[0]}
|
|
|
- </if>
|
|
|
- </if>
|
|
|
- GROUP BY d.dt
|
|
|
- ),
|
|
|
- t6 AS (
|
|
|
- SELECT
|
|
|
- d.dt AS create_time,
|
|
|
- COUNT(fcrpl.log_id) AS redPacketNum
|
|
|
- FROM
|
|
|
- date_range d
|
|
|
- LEFT JOIN fs_course_red_packet_log AS fcrpl
|
|
|
- ON DATE(fcrpl.create_time) = d.dt
|
|
|
- <if test="userIds != null">
|
|
|
- <if test="dimension == 1">
|
|
|
- <choose>
|
|
|
- <when test="userIds.length > 1 ">
|
|
|
- AND fcrpl.company_user_id IN (
|
|
|
- <foreach collection="userIds" item="i" separator=",">
|
|
|
- #{i}
|
|
|
- </foreach>
|
|
|
- )
|
|
|
- </when>
|
|
|
- <otherwise>
|
|
|
- AND fcrpl.company_user_id = #{userIds[0]}
|
|
|
- </otherwise>
|
|
|
- </choose>
|
|
|
- </if>
|
|
|
- <if test="dimension == 2">
|
|
|
- AND fcrpl.company_id = #{userIds[0]}
|
|
|
- </if>
|
|
|
- </if>
|
|
|
- GROUP BY d.dt
|
|
|
- )
|
|
|
- SELECT
|
|
|
- t1.create_time as dateStr,
|
|
|
- t1.t1_count as lineNum,
|
|
|
- t2.t2_count as activeNum,
|
|
|
- t4.completeNum,
|
|
|
- t5.answerNum,
|
|
|
- t6.redPacketNum
|
|
|
- FROM t1
|
|
|
- INNER JOIN t2 ON t1.create_time = t2.create_time
|
|
|
- INNER JOIN t4 ON t1.create_time = t4.create_time
|
|
|
- INNER JOIN t5 ON t1.create_time = t5.create_time
|
|
|
- INNER JOIN t6 ON t1.create_time = t6.create_time
|
|
|
- ORDER BY t1.create_time
|
|
|
- </select>
|
|
|
|
|
|
<select id="getCompanyInfo" resultType="com.fs.company.domain.CompanyDeptUserInfo">
|
|
|
SELECT
|
|
|
@@ -244,6 +77,33 @@
|
|
|
red_packet_num, red_packet_amount, create_time, update_time
|
|
|
</sql>
|
|
|
|
|
|
+ <select id="getStatisticNumByPersonal" resultType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
+ select <include refid="Base_Column_List"/> from user_daily_stats as uds
|
|
|
+ <where>
|
|
|
+ uds.user_id = #{userIds[0]}
|
|
|
+ and statistics_time >=date_format(#{startTime},'%y%m%d')
|
|
|
+ and statistics_time <= date_format(#{endTime},'%y%m%d')
|
|
|
+ </where>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="getStatisticNumByDeptId" resultType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
+ select <include refid="Base_Column_List"/> from user_daily_stats as uds
|
|
|
+ <where>
|
|
|
+ uds.dept_id = #{deptIds[0]}
|
|
|
+ and statistics_time >=date_format(#{startTime},'%y%m%d')
|
|
|
+ and statistics_time <= date_format(#{endTime},'%y%m%d')
|
|
|
+ </where>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="getStatisticNumByCompanyId" resultType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
+ select <include refid="Base_Column_List"/> from user_daily_stats as uds
|
|
|
+ <where>
|
|
|
+ uds.company_id = #{companyIds[0]}
|
|
|
+ and statistics_time >=date_format(#{startTime},'%y%m%d')
|
|
|
+ and statistics_time <= date_format(#{endTime},'%y%m%d')
|
|
|
+ </where>
|
|
|
+ </select>
|
|
|
+
|
|
|
<!-- 1. 插入数据(全字段插入) -->
|
|
|
<insert id="insert" parameterType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
INSERT INTO user_daily_stats (
|
|
|
@@ -259,7 +119,7 @@
|
|
|
)
|
|
|
</insert>
|
|
|
|
|
|
- <!-- 2. 插入或更新(根据唯一索引uk_user_date,存在则更新,不存在则插入) -->
|
|
|
+ <!-- 2. 插入或更新(根据唯一索引uk_user_date,存在则更新,不存在则插入) 已经删除了索引,有时候用户id是空的 -->
|
|
|
<insert id="insertOrUpdate" parameterType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
INSERT INTO user_daily_stats (
|
|
|
company_id, company_name, dept_id, dept_name,
|
|
|
@@ -320,7 +180,7 @@
|
|
|
red_packet_num = #{redPacketNum},
|
|
|
red_packet_amount = #{redPacketAmount},
|
|
|
update_time = NOW()
|
|
|
- WHERE user_id = #{userId} AND statistics_time = #{statisticsTime}
|
|
|
+ WHERE user_id = #{userId} AND statistics_time = date_format(#{statisticsTime},'%y%m%d')
|
|
|
</update>
|
|
|
|
|
|
<!-- 5. 根据ID查询 -->
|
|
|
@@ -332,16 +192,22 @@
|
|
|
<select id="selectByUserAndDate" resultType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
SELECT <include refid="Base_Column_List"/>
|
|
|
FROM user_daily_stats
|
|
|
- WHERE user_id = #{userId} AND statistics_time = #{statisticsTime}
|
|
|
+ WHERE user_id = #{userId} AND statistics_time =date_format(#{statisticsTime},'%y%m%d')
|
|
|
</select>
|
|
|
|
|
|
- <!-- 7. 根据公司ID和日期范围查询 -->
|
|
|
- <select id="selectByCompanyAndDateRange" resultType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
+ <!-- 6. 根据用户ID和统计日期查询 -->
|
|
|
+ <select id="countByUserAndDate" resultType="java.lang.Integer">
|
|
|
+ SELECT count(id)
|
|
|
+ FROM user_daily_stats
|
|
|
+ WHERE user_id = #{userId} AND statistics_time = date_format(#{statisticsTime},'%y%m%d')
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 8. 根据部门ID和日期查询 -->
|
|
|
+ <select id="selectByDeptAndDate" resultType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
SELECT <include refid="Base_Column_List"/>
|
|
|
FROM user_daily_stats
|
|
|
- WHERE company_id = #{companyId}
|
|
|
- AND statistics_time BETWEEN #{startTime} AND #{endTime}
|
|
|
- ORDER BY statistics_time ASC
|
|
|
+ WHERE dept_id = #{deptId}
|
|
|
+ AND statistics_time = date_format(#{statisticsTime},'%y%m%d')
|
|
|
</select>
|
|
|
|
|
|
<!-- 8. 根据部门ID和日期范围查询 -->
|
|
|
@@ -353,6 +219,15 @@
|
|
|
ORDER BY statistics_time ASC
|
|
|
</select>
|
|
|
|
|
|
+ <!-- 7. 根据公司ID和日期范围查询 -->
|
|
|
+ <select id="selectByCompanyAndDateRange" resultType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
+ SELECT <include refid="Base_Column_List"/>
|
|
|
+ FROM user_daily_stats
|
|
|
+ WHERE company_id = #{companyId}
|
|
|
+ AND statistics_time BETWEEN #{startTime} AND #{endTime}
|
|
|
+ ORDER BY statistics_time ASC
|
|
|
+ </select>
|
|
|
+
|
|
|
<!-- 9. 删除数据(根据ID) -->
|
|
|
<delete id="deleteById" parameterType="java.lang.Long">
|
|
|
DELETE FROM user_daily_stats WHERE id = #{id}
|
|
|
@@ -360,7 +235,7 @@
|
|
|
|
|
|
<!-- 10. 删除数据(根据用户ID和统计日期) -->
|
|
|
<delete id="deleteByUserAndDate">
|
|
|
- DELETE FROM user_daily_stats WHERE user_id = #{userId} AND statistics_time = #{statisticsTime}
|
|
|
+ DELETE FROM user_daily_stats WHERE user_id = #{userId} AND statistics_time = date_format(#{statisticsTime},'%y%m%d')
|
|
|
</delete>
|
|
|
|
|
|
</mapper>
|