|
|
@@ -27,39 +27,340 @@
|
|
|
LEFT JOIN company_dept AS cd ON ci.company_id = cd.company_id AND cd.STATUS = 0
|
|
|
LEFT JOIN company_user AS cu ON cu.dept_id = cd.dept_id AND cu.del_flag = 0
|
|
|
WHERE ci.is_del = 0 AND cd.del_flag = 0
|
|
|
+ <if test="companyId != null">
|
|
|
+ and ci.company_id = #{companyId}
|
|
|
+ </if>
|
|
|
</select>
|
|
|
|
|
|
<select id="getStatisticNum" resultType="com.fs.company.dto.CompanyDeptUserInfoDTO">
|
|
|
- with t1 as (
|
|
|
+ WITH t1 AS (
|
|
|
SELECT
|
|
|
- qec.id,
|
|
|
- qec.company_user_id,
|
|
|
- qec.fs_user_id,
|
|
|
- qec.qw_user_id,
|
|
|
- qec.user_id
|
|
|
+ count(*) AS lineNum
|
|
|
FROM
|
|
|
- qw_external_contact AS qec
|
|
|
+ qw_external_contact AS qec
|
|
|
WHERE
|
|
|
- date_format(qec.create_time,'%y%m%d') >= date_format(now(),'%y%m%d') and
|
|
|
- qec.create_time <= now()
|
|
|
- and qec.company_user_id IN (
|
|
|
- <foreach collection="userIds" item="i" separator=",">
|
|
|
- #{i}
|
|
|
- </foreach>
|
|
|
- )
|
|
|
- ),t2 as (
|
|
|
- select count(t1.id) as lineNum from t1
|
|
|
- ),t3 as (
|
|
|
- select count(t1.id) as activeNum from t1 where t1.fs_user_id is not null
|
|
|
- ),t4 as(
|
|
|
- select count(fcwl.qw_external_contact_id) as completeNum from t1 inner join fs_course_watch_log as fcwl on t1.id = fcwl.qw_external_contact_id where fcwl.log_type = 2
|
|
|
- ),t5 as (
|
|
|
- select count(fcal.log_id) as answerNum from t1 inner join fs_course_answer_logs as fcal where fcal.user_id = t1.user_id
|
|
|
- ), t6 as (
|
|
|
- select count(fcrpl.log_id) as redPacketNum from t1 inner join fs_course_red_packet_log as fcrpl where fcrpl.user_id = t1.user_id
|
|
|
+ date_format( qec.create_time, '%y%m%d' ) = date_format(now(), '%y%m%d' )
|
|
|
+ AND qec.company_user_id = 327
|
|
|
+ ),
|
|
|
+ t2 AS (
|
|
|
+ SELECT
|
|
|
+ count( qec.fs_user_id ) AS actvieNUm
|
|
|
+ FROM
|
|
|
+ qw_external_contact AS qec
|
|
|
+ WHERE
|
|
|
+ date_format( qec.create_time, '%y%m%d' ) = date_format(now(), '%y%m%d' )
|
|
|
+ AND qec.fs_user_id IS NOT NULL
|
|
|
+ AND qec.company_user_id = 327
|
|
|
+ ),
|
|
|
+ t3 AS ( SELECT count(*) AS completeNum FROM fs_course_watch_log AS fcwl WHERE date_format(fcwl.create_time, '%y%m%d' ) = date_format( now(), '%y%m%d') and fcwl.log_type = 2 AND fcwl.company_user_id = 327 ),
|
|
|
+ t4 AS ( SELECT count(*) AS answerNum FROM fs_course_answer_logs AS fcal WHERE date_format(fcal.create_time, '%y%m%d' ) = date_format( now(), '%y%m%d') and fcal.company_user_id = 327 ),
|
|
|
+ t5 AS ( SELECT count(*) AS redPacketNum FROM fs_course_red_packet_log AS fcrpl WHERE date_format(fcrpl.create_time, '%y%m%d' ) = date_format( now(), '%y%m%d' ) and fcrpl.company_user_id = 327 )
|
|
|
+ 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
|
|
|
+ ci.company_id,
|
|
|
+ ci.company_name
|
|
|
+ FROM
|
|
|
+ company AS ci
|
|
|
+ WHERE
|
|
|
+ ci.is_del = 0
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 基础字段映射(复用) -->
|
|
|
+ <sql id="Base_Column_List">
|
|
|
+ id, company_id, company_name, dept_id, dept_name,
|
|
|
+ user_id, user_name, nick_name, statistics_time,
|
|
|
+ line_num, active_num, complete_num, answer_num,
|
|
|
+ red_packet_num, red_packet_amount, create_time, update_time
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <!-- 1. 插入数据(全字段插入) -->
|
|
|
+ <insert id="insert" parameterType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
+ INSERT INTO user_daily_stats (
|
|
|
+ company_id, company_name, dept_id, dept_name,
|
|
|
+ user_id, user_name, nick_name, statistics_time,
|
|
|
+ line_num, active_num, complete_num, answer_num,
|
|
|
+ red_packet_num, red_packet_amount, create_time, update_time
|
|
|
+ ) VALUES (
|
|
|
+ #{companyId}, #{companyName}, #{deptId}, #{deptName},
|
|
|
+ #{userId}, #{userName}, #{nickName}, #{statisticsTime},
|
|
|
+ #{lineNum}, #{activeNum}, #{completeNum}, #{answerNum},
|
|
|
+ #{redPacketNum}, #{redPacketAmount}, #{createTime}, #{updateTime}
|
|
|
)
|
|
|
- select t2.lineNum, t3.activeNum, t4.completeNum, t5.answerNum, t6.redPacketNum from t2, t3, t4, t5, t6
|
|
|
+ </insert>
|
|
|
+
|
|
|
+ <!-- 2. 插入或更新(根据唯一索引uk_user_date,存在则更新,不存在则插入) -->
|
|
|
+ <insert id="insertOrUpdate" parameterType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
+ INSERT INTO user_daily_stats (
|
|
|
+ company_id, company_name, dept_id, dept_name,
|
|
|
+ user_id, user_name, nick_name, statistics_time,
|
|
|
+ line_num, active_num, complete_num, answer_num,
|
|
|
+ red_packet_num, red_packet_amount, create_time, update_time
|
|
|
+ ) VALUES (
|
|
|
+ #{companyId}, #{companyName}, #{deptId}, #{deptName},
|
|
|
+ #{userId}, #{userName}, #{nickName}, #{statisticsTime},
|
|
|
+ #{lineNum}, #{activeNum}, #{completeNum}, #{answerNum},
|
|
|
+ #{redPacketNum}, #{redPacketAmount}, NOW(), NOW()
|
|
|
+ ) ON DUPLICATE KEY UPDATE
|
|
|
+ company_id = VALUES(company_id),
|
|
|
+ company_name = VALUES(company_name),
|
|
|
+ dept_id = VALUES(dept_id),
|
|
|
+ dept_name = VALUES(dept_name),
|
|
|
+ user_name = VALUES(user_name),
|
|
|
+ nick_name = VALUES(nick_name),
|
|
|
+ line_num = VALUES(line_num),
|
|
|
+ active_num = VALUES(active_num),
|
|
|
+ complete_num = VALUES(complete_num),
|
|
|
+ answer_num = VALUES(answer_num),
|
|
|
+ red_packet_num = VALUES(red_packet_num),
|
|
|
+ red_packet_amount = VALUES(red_packet_amount),
|
|
|
+ update_time = NOW()
|
|
|
+ </insert>
|
|
|
+
|
|
|
+ <!-- 3. 根据ID更新数据(全字段更新) -->
|
|
|
+ <update id="updateById" parameterType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
+ UPDATE user_daily_stats
|
|
|
+ SET
|
|
|
+ company_id = #{companyId},
|
|
|
+ company_name = #{companyName},
|
|
|
+ dept_id = #{deptId},
|
|
|
+ dept_name = #{deptName},
|
|
|
+ user_id = #{userId},
|
|
|
+ user_name = #{userName},
|
|
|
+ nick_name = #{nickName},
|
|
|
+ statistics_time = #{statisticsTime},
|
|
|
+ line_num = #{lineNum},
|
|
|
+ active_num = #{activeNum},
|
|
|
+ complete_num = #{completeNum},
|
|
|
+ answer_num = #{answerNum},
|
|
|
+ red_packet_num = #{redPacketNum},
|
|
|
+ red_packet_amount = #{redPacketAmount},
|
|
|
+ update_time = NOW()
|
|
|
+ WHERE id = #{id}
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <!-- 4. 根据用户ID和统计日期更新(部分字段更新,按需调整) -->
|
|
|
+ <update id="updateByUserAndDate" parameterType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
+ UPDATE user_daily_stats
|
|
|
+ SET
|
|
|
+ line_num = #{lineNum},
|
|
|
+ active_num = #{activeNum},
|
|
|
+ complete_num = #{completeNum},
|
|
|
+ answer_num = #{answerNum},
|
|
|
+ red_packet_num = #{redPacketNum},
|
|
|
+ red_packet_amount = #{redPacketAmount},
|
|
|
+ update_time = NOW()
|
|
|
+ WHERE user_id = #{userId} AND statistics_time = #{statisticsTime}
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <!-- 5. 根据ID查询 -->
|
|
|
+ <select id="selectById" resultType="com.fs.company.domain.ComprehensiveDailyStats" parameterType="java.lang.Long">
|
|
|
+ SELECT <include refid="Base_Column_List"/> FROM user_daily_stats WHERE id = #{id}
|
|
|
</select>
|
|
|
|
|
|
+ <!-- 6. 根据用户ID和统计日期查询 -->
|
|
|
+ <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}
|
|
|
+ </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>
|
|
|
+
|
|
|
+ <!-- 8. 根据部门ID和日期范围查询 -->
|
|
|
+ <select id="selectByDeptAndDateRange" resultType="com.fs.company.domain.ComprehensiveDailyStats">
|
|
|
+ SELECT <include refid="Base_Column_List"/>
|
|
|
+ FROM user_daily_stats
|
|
|
+ WHERE dept_id = #{deptId}
|
|
|
+ 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}
|
|
|
+ </delete>
|
|
|
+
|
|
|
+ <!-- 10. 删除数据(根据用户ID和统计日期) -->
|
|
|
+ <delete id="deleteByUserAndDate">
|
|
|
+ DELETE FROM user_daily_stats WHERE user_id = #{userId} AND statistics_time = #{statisticsTime}
|
|
|
+ </delete>
|
|
|
|
|
|
</mapper>
|