| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.fs.course.mapper.FsUserCourseCompanyStatisticsMapper">
- <resultMap type="FsUserCourseCompanyStatistics" id="FsUserCourseCompanyStatisticsResult">
- <result property="id" column="id" />
- <result property="projectId" column="project_id" />
- <result property="watchCount" column="watch_count" />
- <result property="answerCount" column="answer_count" />
- <result property="correctCount" column="correct_count" />
- <result property="receiveCount" column="receive_count" />
- <result property="receiveAmount" column="receive_amount" />
- <result property="userCount" column="user_count" />
- <result property="userBlacklistCount" column="user_blacklist_count" />
- <result property="companyId" column="company_id" />
- <result property="companyName" column="company_name" />
- <result property="createDate" column="create_date" />
- <result property="createTime" column="create_time" />
- <result property="updateTime" column="update_time" />
- <result property="createBy" column="create_by" />
- <result property="updateBy" column="update_by" />
- </resultMap>
- <sql id="selectFsUserCourseCompanyStatisticsVo">
- select id, project_id, complete_watch_count, watch_count, answer_count, correct_count,receive_count, receive_amount, user_count, user_blacklist_count, company_id, company_name, create_date, create_time, update_time, create_by, update_by from fs_user_course_company_statistics
- </sql>
- <select id="selectFsUserCourseCompanyStatisticsList" parameterType="FsUserCourseCompanyStatistics" resultMap="FsUserCourseCompanyStatisticsResult">
- <include refid="selectFsUserCourseCompanyStatisticsVo"/>
- <where>
- <if test="projectId != null "> and project_id = #{projectId}</if>
- <if test="watchCount != null "> and watch_count = #{watchCount}</if>
- <if test="answerCount != null "> and answer_count = #{answerCount}</if>
- <if test="correctCount != null "> and correct_count = #{correctCount}</if>
- <if test="receiveCount != null "> and receive_count = #{receiveCount}</if>
- <if test="receiveAmount != null "> and receive_amount = #{receiveAmount}</if>
- <if test="userCount != null "> and user_count = #{userCount}</if>
- <if test="userBlacklistCount != null "> and user_blacklist_count = #{userBlacklistCount}</if>
- <if test="companyId != null "> and company_id = #{companyId}</if>
- <if test="companyName != null and companyName != ''"> and company_name like concat('%', #{companyName}, '%')</if>
- <if test="createDate != null "> and create_date = #{createDate}</if>
- </where>
- </select>
- <select id="selectFsUserCourseCompanyStatisticsById" parameterType="Long" resultMap="FsUserCourseCompanyStatisticsResult">
- <include refid="selectFsUserCourseCompanyStatisticsVo"/>
- where id = #{id}
- </select>
- <insert id="insertFsUserCourseCompanyStatistics" parameterType="FsUserCourseCompanyStatistics" useGeneratedKeys="true" keyProperty="id">
- insert into fs_user_course_company_statistics
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="projectId != null">project_id,</if>
- <if test="watchCount != null">watch_count,</if>
- <if test="completeWatchCount != null">complete_watch_count,</if>
- <if test="answerCount != null">answer_count,</if>
- <if test="correctCount != null">correct_count,</if>
- <if test="receiveCount != null">receive_count,</if>
- <if test="receiveAmount != null">receive_amount,</if>
- <if test="userCount != null">user_count,</if>
- <if test="userBlacklistCount != null">user_blacklist_count,</if>
- <if test="companyId != null">company_id,</if>
- <if test="companyName != null">company_name,</if>
- <if test="createDate != null">create_date,</if>
- <if test="createTime != null">create_time,</if>
- <if test="updateTime != null">update_time,</if>
- <if test="createBy != null">create_by,</if>
- <if test="updateBy != null">update_by,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="projectId != null">#{projectId},</if>
- <if test="watchCount != null">#{watchCount},</if>
- <if test="completeWatchCount != null">#{completeWatchCount},</if>
- <if test="answerCount != null">#{answerCount},</if>
- <if test="correctCount != null">#{correctCount},</if>
- <if test="receiveCount != null">#{receiveCount},</if>
- <if test="receiveAmount != null">#{receiveAmount},</if>
- <if test="userCount != null">#{userCount},</if>
- <if test="userBlacklistCount != null">#{userBlacklistCount},</if>
- <if test="companyId != null">#{companyId},</if>
- <if test="companyName != null">#{companyName},</if>
- <if test="createDate != null">#{createDate},</if>
- <if test="createTime != null">#{createTime},</if>
- <if test="updateTime != null">#{updateTime},</if>
- <if test="createBy != null">#{createBy},</if>
- <if test="updateBy != null">#{updateBy},</if>
- </trim>
- </insert>
- <update id="updateFsUserCourseCompanyStatistics" parameterType="FsUserCourseCompanyStatistics">
- update fs_user_course_company_statistics
- <trim prefix="SET" suffixOverrides=",">
- <if test="projectId != null">project_id = #{projectId},</if>
- <if test="watchCount != null">watch_count = #{watchCount},</if>
- <if test="answerCount != null">answer_count = #{answerCount},</if>
- <if test="correctCount != null">correct_count = #{correctCount},</if>
- <if test="receiveCount != null">receive_count = #{receiveCount},</if>
- <if test="receiveAmount != null">receive_amount = #{receiveAmount},</if>
- <if test="userCount != null">user_count = #{userCount},</if>
- <if test="userBlacklistCount != null">user_blacklist_count = #{userBlacklistCount},</if>
- <if test="companyId != null">company_id = #{companyId},</if>
- <if test="companyName != null">company_name = #{companyName},</if>
- <if test="createDate != null">create_date = #{createDate},</if>
- <if test="createTime != null">create_time = #{createTime},</if>
- <if test="updateTime != null">update_time = #{updateTime},</if>
- <if test="createBy != null">create_by = #{createBy},</if>
- <if test="updateBy != null">update_by = #{updateBy},</if>
- </trim>
- where id = #{id}
- </update>
- <delete id="deleteFsUserCourseCompanyStatisticsById" parameterType="Long">
- delete from fs_user_course_company_statistics where id = #{id}
- </delete>
- <delete id="deleteFsUserCourseCompanyStatisticsByIds" parameterType="String">
- delete from fs_user_course_company_statistics where id in
- <foreach item="id" collection="array" open="(" separator="," close=")">
- #{id}
- </foreach>
- </delete>
- <select id="selectStatisticsByDate" resultType="FsUserCourseCompanyStatistics">
- WITH watch_stats AS (
- <!-- 看课统计-->
- SELECT
- project,
- COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS courseCompleteNum,
- COUNT(DISTINCT CASE WHEN log_type != 3 THEN user_id END) AS courseWatchNum
- FROM fs_course_watch_log
- WHERE create_time > #{startTime}
- AND create_time < #{endTime}
- AND company_id = #{companyId}
- GROUP BY project
- ),
- answer_stats AS (
- <!-- 答题统计-->
- SELECT
- l.project,
- COUNT(DISTINCT a.user_id) as answerNum,
- COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) as answerRightNum
- FROM fs_course_answer_logs a
- INNER JOIN fs_course_watch_log l ON a.watch_log_id = l.log_id
- WHERE a.create_time >= #{startTime}
- AND a.create_time < #{endTime}
- AND a.company_id = #{companyId}
- GROUP BY l.project
- ),
- redpacket_stats AS (
- <!-- 红包统计-->
- SELECT
- l.project,
- COUNT(r.log_id) as redPacketNum,
- IFNULL(SUM(r.amount), 0) as redPacketAmount
- FROM fs_course_red_packet_log r
- INNER JOIN fs_course_watch_log l ON r.watch_log_id = l.log_id
- WHERE r.create_time >= #{startTime}
- AND r.create_time < #{endTime}
- AND r.company_id = #{companyId}
- GROUP BY l.project
- ),
- user_stats AS (
- <!-- 用户统计-->
- SELECT
- project_id as project,
- COUNT(DISTINCT user_id) as userCount,
- COUNT(DISTINCT CASE WHEN status = 2 THEN user_id END) as blacklist
- FROM fs_user_company_user
- WHERE create_time >= #{startTime}
- AND create_time < #{endTime}
- AND company_id = #{companyId}
- GROUP BY project_id
- )
- <!-- 合并数据-->
- SELECT
- w.project AS projectId,
- w.courseCompleteNum AS completeWatchCount,
- w.courseWatchNum AS watchCount,
- COALESCE(a.answerNum, 0) AS answerCount,
- COALESCE(a.answerRightNum, 0) AS correctCount,
- COALESCE(r.redPacketNum, 0) AS receiveCount,
- COALESCE(r.redPacketAmount, 0) AS receiveAmount,
- COALESCE(u.userCount, 0) AS userCount,
- COALESCE(u.blacklist, 0) AS userBlacklistCount
- FROM watch_stats w
- LEFT JOIN answer_stats a ON w.project = a.project
- LEFT JOIN redpacket_stats r ON w.project = r.project
- LEFT JOIN user_stats u ON w.project = u.project
- </select>
- <select id="selectFsUserCourseCompanyStatisticsTotal" parameterType="FsUserCourseCompanyStatistics" resultType="FsUserCourseCompanyStatistics">
- SELECT
- id,
- project_id,
- COALESCE(SUM(complete_watch_count), 0) AS complete_watch_count,
- COALESCE(SUM(watch_count), 0) AS watch_count,
- COALESCE(SUM(answer_count), 0) AS answer_count,
- COALESCE(SUM(correct_count), 0) AS correct_count,
- COALESCE(SUM(receive_count), 0) AS receive_count,
- COALESCE(SUM(receive_amount), 0) AS receive_amount,
- COALESCE(SUM(user_count), 0) AS user_count,
- COALESCE(SUM(user_blacklist_count), 0) AS user_blacklist_count,
- company_id,
- company_name,
- create_date,
- create_time,
- update_time,
- create_by,
- update_by
- FROM fs_user_course_company_statistics
- <where>
- <if test="projectId != null">AND project_id = #{projectId}</if>
- <if test="watchCount != null">AND watch_count = #{watchCount}</if>
- <if test="answerCount != null">AND answer_count = #{answerCount}</if>
- <if test="correctCount != null">AND correct_count = #{correctCount}</if>
- <if test="receiveCount != null">AND receive_count = #{receiveCount}</if>
- <if test="receiveAmount != null">AND receive_amount = #{receiveAmount}</if>
- <if test="userCount != null">AND user_count = #{userCount}</if>
- <if test="userBlacklistCount != null">AND user_blacklist_count = #{userBlacklistCount}</if>
- <if test="companyId != null">AND company_id = #{companyId}</if>
- <if test="companyName != null and companyName != ''">
- AND company_name LIKE concat('%', #{companyName}, '%')
- </if>
- <if test="createDate != null">AND create_date = #{createDate}</if>
- <!-- ✅ 新增时间筛选 -->
- <if test="beginTime != null and beginTime != ''">
- AND DATE(create_date) <![CDATA[ >= ]]> #{beginTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND DATE(create_date) <![CDATA[ <= ]]> #{endTime}
- </if>
- </where>
- group by company_id,DATE(create_date)
- <!-- 排序:合计行放最后 -->
- ORDER BY create_time DESC
- </select>
- </mapper>
|