Quellcode durchsuchen

Merge remote-tracking branch 'origin/Payment-Configuration' into Payment-Configuration

xgb vor 1 Tag
Ursprung
Commit
b9882b7a0f

+ 11 - 5
fs-admin/src/main/java/com/fs/course/controller/FsCourseRedPacketLogController.java

@@ -105,20 +105,20 @@ public class FsCourseRedPacketLogController extends BaseController
         if (fsCourseRedPacketLog.getPhoneMk()!=null&&fsCourseRedPacketLog.getPhoneMk()!=""){
             fsCourseRedPacketLog.setPhone(encryptPhone(fsCourseRedPacketLog.getPhoneMk()));
         }
-        
+
         // 先查询符合条件的总数量
         long totalCount = fsCourseRedPacketLogService.selectFsCourseRedPacketLogListVOCount(fsCourseRedPacketLog);
-        
+
         // 设置最大导出数量限制
         int maxExportCount = 10000;
         if (totalCount > maxExportCount) {
             return AjaxResult.error("导出数据量过大,当前共有 " + totalCount + " 条记录,超过最大限制 " + maxExportCount + " 条。请缩小查询范围后重试。");
         }
-        
+
         List<FsCourseRedPacketLogListPVO> list = fsCourseRedPacketLogService.selectFsCourseRedPacketLogListVO(fsCourseRedPacketLog);
-        
+
         // 手机号解密已在 Service 层批量处理
-        
+
         ExcelUtil<FsCourseRedPacketLogListPVO> util = new ExcelUtil<FsCourseRedPacketLogListPVO>(FsCourseRedPacketLogListPVO.class);
         return util.exportExcel(list, "短链课程看课记录数据");
     }
@@ -227,5 +227,11 @@ public class FsCourseRedPacketLogController extends BaseController
         ExcelUtil<FsCourseRedPacketLogListVO> util = new ExcelUtil<FsCourseRedPacketLogListVO>(FsCourseRedPacketLogListVO.class);
         return util.exportExcel(list, "红包消耗统计导出");
     }
+    @GetMapping("/publicCourseList")
+    public R publicCourseList()
+    {
+        List<OptionsVO> optionsVOS = fsUserCourseMapper.selectFsUserCoursePublicList();
+        return R.ok().put("list", optionsVOS);
+    }
 
 }

+ 28 - 0
fs-service/src/main/java/com/fs/course/domain/FsPublicCourseTrafficLog.java

@@ -0,0 +1,28 @@
+package com.fs.course.domain;
+
+import com.fs.common.core.domain.BaseEntity;
+import lombok.Data;
+
+/**
+ * 公开课流量记录对象 fs_public_course_traffic_log
+ */
+@Data
+public class FsPublicCourseTrafficLog extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    private Long logId;
+
+    private String uuId;
+
+    private Long userId;
+
+    private Long courseId;
+
+    private Long videoId;
+
+    private Long internetTraffic;
+
+    private Integer status;
+
+    private  Long projectId;
+}

+ 42 - 0
fs-service/src/main/java/com/fs/course/mapper/FsPublicCourseTrafficLogMapper.java

@@ -0,0 +1,42 @@
+package com.fs.course.mapper;
+
+import com.fs.course.domain.FsPublicCourseTrafficLog;
+import com.fs.course.param.FsCourseTrafficLogParam;
+import com.fs.course.vo.FsCourseTrafficLogListVO;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * 公开课流量记录Mapper接口
+ */
+@Repository
+public interface FsPublicCourseTrafficLogMapper {
+
+    FsPublicCourseTrafficLog selectFsPublicCourseTrafficLogByLogId(Long logId);
+
+    int insertFsPublicCourseTrafficLog(FsPublicCourseTrafficLog fsPublicCourseTrafficLog);
+
+    int updateFsPublicCourseTrafficLog(FsPublicCourseTrafficLog fsPublicCourseTrafficLog);
+
+    @Select("select * from fs_public_course_traffic_log where uu_id = #{uuId}")
+    FsPublicCourseTrafficLog selectFsPublicCourseTrafficLogByUuId(@Param("uuId") String uuId);
+
+    void insertOrUpdateTrafficLog(FsPublicCourseTrafficLog trafficLog);
+
+    @Select("SELECT IFNULL(SUM(internet_traffic), 0) FROM fs_public_course_traffic_log " +
+            "WHERE DATE(create_time) = DATE(CURDATE()) AND company_id = #{companyId}")
+    Long getTodayTrafficLogCompanyId(@Param("companyId") Long companyId);
+
+    @Select("SELECT IFNULL(SUM(internet_traffic), 0) FROM fs_public_course_traffic_log " +
+            "WHERE DATE(create_time) = DATE(CURDATE() - INTERVAL 1 DAY) AND company_id = #{companyId}")
+    Long getYesterdayTrafficLogCompanyId(@Param("companyId") Long companyId);
+
+    @Select("SELECT IFNULL(SUM(internet_traffic), 0) FROM fs_public_course_traffic_log " +
+            "WHERE YEAR(create_time) = YEAR(CURDATE()) AND MONTH(create_time) = MONTH(CURDATE()) AND company_id = #{companyId}")
+    Long getMonthTrafficLogCompanyId(@Param("companyId") Long companyId);
+
+    List<FsCourseTrafficLogListVO> selectTrafficNew(FsCourseTrafficLogParam param);
+}

+ 3 - 0
fs-service/src/main/java/com/fs/course/mapper/FsUserCourseMapper.java

@@ -370,4 +370,7 @@ public interface FsUserCourseMapper
             "    GROUP BY course_id, course_name")
     List<OptionsVO> selectCourseOptionsList();
 
+    @Select("select course_id dict_value, course_name dict_label,img_url dict_imgUrl  from fs_user_course where is_del = 0 and is_private = 0 ")
+    List<OptionsVO> selectFsUserCoursePublicList();
+
 }

+ 8 - 0
fs-service/src/main/java/com/fs/course/service/IFsUserCourseVideoService.java

@@ -101,6 +101,14 @@ public interface IFsUserCourseVideoService extends IService<FsUserCourseVideo> {
 
     R getInternetTraffic(FsUserCourseVideoFinishUParam param);
 
+    /**
+     * 公开课流量统计
+     *
+     * @param param
+     * @return
+     */
+    R getPublicCourseInternetTraffic(FsUserCourseVideoFinishUParam param);
+
     R getIntegralByH5Video(FsUserCourseVideoFinishUParam param);
 
     R sendReward(FsCourseSendRewardUParam param);

+ 66 - 0
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -210,6 +210,8 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
     @Autowired
     private FsCourseTrafficLogMapper fsCourseTrafficLogMapper;
     @Autowired
+    private FsPublicCourseTrafficLogMapper fsPublicCourseTrafficLogMapper;
+    @Autowired
     private FsUserIntegralLogsMapper fsUserIntegralLogsMapper;
     @Autowired
     private FsUserMapper fsUserMapper;
@@ -1309,6 +1311,70 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
         return R.ok();
     }
 
+    @Override
+    public R getPublicCourseInternetTraffic(FsUserCourseVideoFinishUParam param) {
+        try {
+            if (param.getBufferRate() == null) {
+                logger.error("【公开课缓冲值空】参数: {}", param);
+                return R.error("缓冲值空");
+            }
+            FsPublicCourseTrafficLog trafficLog = new FsPublicCourseTrafficLog();
+            trafficLog.setCreateTime(new Date());
+            BeanUtils.copyProperties(param, trafficLog);
+
+            FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
+            if (video == null) {
+                return R.error("视频不存在");
+            }
+//            Company company = companyMapper.selectCompanyById(param.getCompanyId());
+//            if (company == null) {
+//                return R.error("公司不存在");
+//            }
+            FsUserCourse fsUserCourse = fsUserCourseMapper.selectFsUserCourseByCourseId(param.getCourseId());
+            if (fsUserCourse != null) {
+                trafficLog.setProjectId(fsUserCourse.getProject());
+            }
+            BigDecimal result = param.getBufferRate().divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP);
+            BigDecimal longAsBigDecimal = BigDecimal.valueOf(video.getFileSize());
+            long roundedResult = result.multiply(longAsBigDecimal).setScale(0, RoundingMode.HALF_UP).longValue();
+            trafficLog.setInternetTraffic(roundedResult);
+
+            if (StringUtils.isNotEmpty(trafficLog.getUuId())) {
+                fsPublicCourseTrafficLogMapper.insertOrUpdateTrafficLog(trafficLog);
+//                asyncDeductPublicCourseTraffic(company, trafficLog);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.error("【公开课插入或更新流量失败】参数: {}, 错误信息:{}", param, e.getMessage(), e);
+            return R.error();
+        }
+        return R.ok();
+    }
+
+//    public void asyncDeductPublicCourseTraffic(Company company, FsPublicCourseTrafficLog trafficLog) {
+//        try {
+//            FsPublicCourseTrafficLog existingLog = fsPublicCourseTrafficLogMapper.selectFsPublicCourseTrafficLogByUuId(trafficLog.getUuId());
+//            long recordedTraffic;
+//            if (existingLog != null) {
+//                recordedTraffic = trafficLog.getInternetTraffic() - existingLog.getInternetTraffic();
+//            } else {
+//                recordedTraffic = trafficLog.getInternetTraffic();
+//            }
+//            if (recordedTraffic <= 0) {
+//                return;
+//            }
+//            Long remainingTraffic = updateRedisCache(company, recordedTraffic / 1024);
+//
+//            if ("1".equals(configUtil.generateConfigByKey("watch.course.config").getString("doNotPlay")) && remainingTraffic <= 0) {
+//                logger.warn("公开课公司ID: {} 流量不足,当前剩余: {}", company.getCompanyId(), remainingTraffic);
+//                throw new Exception("流量不足");
+//            }
+//        } catch (Exception e) {
+//            logger.error("公开课异步扣除流量失败 - 公司ID: {}, 错误信息: {}",
+//                    company.getCompanyId(), e.getMessage(), e);
+//        }
+//    }
+
     public void asyncDeductTraffic(Company company, FsCourseTrafficLog trafficLog) {
         try {
             //根据uuid查询

+ 102 - 0
fs-service/src/main/resources/mapper/course/FsPublicCourseTrafficLogMapper.xml

@@ -0,0 +1,102 @@
+<?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.FsPublicCourseTrafficLogMapper">
+
+    <resultMap type="com.fs.course.domain.FsPublicCourseTrafficLog" id="FsPublicCourseTrafficLogResult">
+        <result property="logId" column="log_id"/>
+        <result property="uuId" column="uu_id"/>
+        <result property="userId" column="user_id"/>
+        <result property="courseId" column="course_id"/>
+        <result property="videoId" column="video_id"/>
+        <result property="internetTraffic" column="internet_traffic"/>
+        <result property="status" column="status"/>
+        <result property="createTime" column="create_time"/>
+        <result property="projectId" column="project_id"/>
+    </resultMap>
+
+    <sql id="selectFsPublicCourseTrafficLogVo">
+        select log_id,
+               uu_id,
+               user_id,
+               course_id,
+               video_id,
+               company_id,
+               internet_traffic,
+               status,
+               create_time,
+               project_id
+        from fs_public_course_traffic_log
+    </sql>
+
+    <select id="selectFsPublicCourseTrafficLogByLogId" parameterType="Long" resultMap="FsPublicCourseTrafficLogResult">
+        <include refid="selectFsPublicCourseTrafficLogVo"/>
+        where log_id = #{logId}
+    </select>
+
+    <insert id="insertFsPublicCourseTrafficLog" parameterType="com.fs.course.domain.FsPublicCourseTrafficLog"
+            useGeneratedKeys="true" keyProperty="logId">
+        insert into fs_public_course_traffic_log
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="uuId != null">uu_id,</if>
+            <if test="userId != null">user_id,</if>
+            <if test="courseId != null">course_id,</if>
+            <if test="videoId != null">video_id,</if>
+            <if test="internetTraffic != null">internet_traffic,</if>
+            <if test="status != null">status,</if>
+            create_time,
+            <if test="projectId != null">project_id,</if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="uuId != null">#{uuId},</if>
+            <if test="userId != null">#{userId},</if>
+            <if test="courseId != null">#{courseId},</if>
+            <if test="videoId != null">#{videoId},</if>
+            <if test="internetTraffic != null">#{internetTraffic},</if>
+            <if test="status != null">#{status},</if>
+            sysdate(),
+            <if test="projectId != null">#{projectId},</if>
+        </trim>
+    </insert>
+
+    <update id="updateFsPublicCourseTrafficLog" parameterType="com.fs.course.domain.FsPublicCourseTrafficLog">
+        update fs_public_course_traffic_log
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="uuId != null">uu_id = #{uuId},</if>
+            <if test="userId != null">user_id = #{userId},</if>
+            <if test="courseId != null">course_id = #{courseId},</if>
+            <if test="videoId != null">video_id = #{videoId},</if>
+            <if test="internetTraffic != null">internet_traffic = #{internetTraffic},</if>
+            <if test="status != null">status = #{status},</if>
+        </trim>
+        where log_id = #{logId}
+    </update>
+
+    <insert id="insertOrUpdateTrafficLog" parameterType="com.fs.course.domain.FsPublicCourseTrafficLog">
+        insert into fs_public_course_traffic_log (uu_id, user_id, course_id, video_id,
+                                                  internet_traffic, status, create_time, project_id)
+        values (#{uuId}, #{userId}, #{courseId}, #{videoId}, #{internetTraffic}, #{status}, sysdate(),
+                #{projectId}) ON DUPLICATE KEY
+        UPDATE
+            internet_traffic = internet_traffic + #{internetTraffic}
+    </insert>
+
+    <select id="selectTrafficNew" resultType="com.fs.course.vo.FsCourseTrafficLogListVO">
+        select
+        log.course_id,
+        SUM(log.internet_traffic) AS total_internet_traffic,
+        DATE_FORMAT(log.create_time, '%Y-%m-%d') AS `month`
+        FROM fs_public_course_traffic_log log
+        <where>
+            <if test="startDate != null and endDate != null">
+                and DATE_FORMAT(log.create_time, '%Y-%m-%d') between #{startDate} AND #{endDate}
+            </if>
+            <if test="courseId != null">
+                and log.course_id = ${courseId}
+            </if>
+        </where>
+        group by log.course_id,`month`
+    </select>
+
+</mapper>

+ 12 - 0
fs-user-app/src/main/java/com/fs/app/controller/course/CourseFsUserController.java

@@ -142,6 +142,18 @@ public class CourseFsUserController extends AppBaseController {
         return courseVideoService.getInternetTraffic(param);
     }
 
+    /**
+     * 获取公开课流量
+     * @return
+     */
+    @ApiOperation("获取公开课缓冲流量")
+    @PostMapping("/getPublicCourseInternetTraffic")
+    @Login
+    public R getPublicCourseInternetTraffic(@RequestBody FsUserCourseVideoFinishUParam param ){
+        param.setUserId(Long.parseLong(getUserId()));
+        return courseVideoService.getPublicCourseInternetTraffic(param);
+    }
+
 
     @ApiOperation("答题")
     @PostMapping("/courseAnswer")