Sfoglia il codice sorgente

理疗视频,流量计算

wjj 1 settimana fa
parent
commit
59ec4f3de5

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

@@ -27,4 +27,7 @@ public interface FsVideoResourceMapper extends BaseMapper<FsVideoResource> {
 
     @Select("select * from fs_video_resource where file_key = #{fileKey} limit 1")
     FsVideoResource selectByFileKey(String fileKey);
+
+    @Select("select * from fs_video_resource where video_url = #{videoUrl}  and is_del = 0")
+    FsVideoResource selectVideoByVideoUrl(String videoUrl);
 }

+ 15 - 0
fs-service/src/main/java/com/fs/his/domain/FsProject.java

@@ -63,5 +63,20 @@ public class FsProject extends BaseEntity{
     @Excel(name = "第四字段内容")
     private String fourthContent;
 
+    /**
+     * 视频地址
+     */
+    private String videoUrl;
+
+    /**
+     * 音频地址
+     */
+    private String soundUrl;
+
+    /**
+     * 音频开关 0-关 1-开
+     */
+    private Integer soundStatus;
+
 
 }

+ 6 - 0
fs-service/src/main/java/com/fs/his/mapper/FsProjectMapper.java

@@ -66,4 +66,10 @@ public interface FsProjectMapper extends BaseMapper<FsProject>{
      */
     @Select("SELECT id,CONCAT_WS('-',project_name,day_name) project_name  FROM fs_project ")
     List<FsProject> selectFsProjectListOptions();
+
+    /**
+     * 未生成音频的理疗
+     */
+    @Select("SELECT * FROM fs_project WHERE sound_url IS NULL")
+    List<FsProject> selectFsProjecNoSoundtList();
 }

+ 5 - 0
fs-service/src/main/java/com/fs/his/service/IFsProjectService.java

@@ -64,4 +64,9 @@ public interface IFsProjectService extends IService<FsProject>{
      * @return
      */
     List<FsProject> selectFsProjectListOptions();
+
+    /**
+     * 生成声音
+     */
+    void generateSound(FsProject fsProject);
 }

+ 41 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsProjectServiceImpl.java

@@ -2,8 +2,16 @@ package com.fs.his.service.impl;
 
 import java.util.Collections;
 import java.util.List;
+
+import com.fs.aiSoundReplication.param.TtsRequest;
+import com.fs.aiSoundReplication.service.TtsService;
 import com.fs.common.utils.DateUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fs.fastgptApi.vo.AudioVO;
+import com.fs.huifuPay.sdk.opps.core.utils.StringUtil;
+import org.jsoup.Jsoup;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.fs.his.mapper.FsProjectMapper;
@@ -19,8 +27,13 @@ import com.fs.his.service.IFsProjectService;
 @Service
 public class FsProjectServiceImpl extends ServiceImpl<FsProjectMapper, FsProject> implements IFsProjectService {
 
+    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
+
     @Autowired
     private FsProjectMapper fsProjectMapper;
+
+    @Autowired
+    private TtsService ttsService;
     /**
      * 查询理疗配置
      * 
@@ -99,4 +112,32 @@ public class FsProjectServiceImpl extends ServiceImpl<FsProjectMapper, FsProject
     public List<FsProject> selectFsProjectListOptions() {
         return fsProjectMapper.selectFsProjectListOptions();
     }
+
+    @Override
+    public void generateSound(FsProject fsProject) {
+        try {
+            StringBuilder buffer = new StringBuilder();
+            if (!StringUtil.isEmpty(fsProject.getFirstField())) {
+                buffer.append(fsProject.getFirstField()).append(": ").append(Jsoup.parse(fsProject.getFirstContent()).text());
+            }
+            if (!StringUtil.isEmpty(fsProject.getSecondField())) {
+                buffer.append(fsProject.getSecondField()).append(": ").append(Jsoup.parse(fsProject.getSecondContent()).text());
+            }
+            if (!StringUtil.isEmpty(fsProject.getThirdField())) {
+                buffer.append(fsProject.getThirdField()).append(": ").append(Jsoup.parse(fsProject.getThirdContent()).text());
+            }
+            if (!StringUtil.isEmpty(fsProject.getFourthField())) {
+                buffer.append(fsProject.getFourthField()).append(": ").append(Jsoup.parse(fsProject.getFourthContent()).text());
+            }
+            String text = buffer.toString();
+            logger.info("文字数据: {}",text);
+            TtsRequest ttsRequest = new TtsRequest(null,null,null,text);
+            AudioVO audioVO = ttsService.textToSound(ttsRequest);
+            FsProject map = new FsProject();
+            map.setId(fsProject.getId());
+            map.setSoundUrl(audioVO.getWavUrl());
+        } catch (Exception e) {
+            logger.info("理疗生成音频失败,理疗id:{},失败原因:{}",fsProject.getId(),e.getMessage());
+        }
+    }
 }

+ 14 - 0
fs-service/src/main/java/com/fs/patient/param/FsProjectVideoFinishUParam.java

@@ -0,0 +1,14 @@
+package com.fs.patient.param;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class FsProjectVideoFinishUParam {
+
+    private String videoUrl;
+    private BigDecimal bufferRate;
+    private String uuId;
+    private Long userId;
+}

+ 6 - 0
fs-service/src/main/java/com/fs/patient/service/IFsPatientBaseInfoService.java

@@ -8,6 +8,7 @@ import com.fs.his.vo.FsPatientBaseInfoListDVO;
 import com.fs.patient.domain.FsPatientBaseInfo;
 import com.fs.patient.param.BindPatientParam;
 import com.fs.patient.param.FsProjectSendRewardUParam;
+import com.fs.patient.param.FsProjectVideoFinishUParam;
 
 /**
  * 患者基本信息Service接口
@@ -91,4 +92,9 @@ public interface IFsPatientBaseInfoService extends IService<FsPatientBaseInfo>{
 
     //总后台审核
     int check(FsPatientBaseInfo param);
+
+    /**
+     * 计算理疗流量
+     */
+    R getInternetTraffic(FsProjectVideoFinishUParam param);
 }

+ 54 - 1
fs-service/src/main/java/com/fs/patient/service/impl/FsPatientBaseInfoServiceImpl.java

@@ -1,6 +1,7 @@
 package com.fs.patient.service.impl;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.Date;
 import java.util.List;
 import java.util.Objects;
@@ -18,6 +19,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.company.domain.CompanyUser;
 import com.fs.company.mapper.CompanyUserMapper;
 import com.fs.core.config.WxMaConfiguration;
+import com.fs.course.domain.FsCourseTrafficLog;
+import com.fs.course.domain.FsVideoResource;
+import com.fs.course.mapper.FsCourseTrafficLogMapper;
+import com.fs.course.mapper.FsVideoResourceMapper;
 import com.fs.his.domain.*;
 import com.fs.his.mapper.FsProjectRedDetailMapper;
 import com.fs.his.mapper.FsUserMapper;
@@ -28,12 +33,12 @@ import com.fs.his.service.IFsDoctorService;
 import com.fs.his.service.IFsProjectService;
 import com.fs.his.service.IFsStorePaymentService;
 import com.fs.his.service.IFsUserWxService;
-import com.fs.his.utils.PhoneUtil;
 import com.fs.his.vo.FsPatientBaseInfoListDVO;
 import com.fs.patient.domain.FsProjectRedPacketRecord;
 import com.fs.patient.mapper.FsProjectRedPacketRecordMapper;
 import com.fs.patient.param.BindPatientParam;
 import com.fs.patient.param.FsProjectSendRewardUParam;
+import com.fs.patient.param.FsProjectVideoFinishUParam;
 import com.fs.patient.vo.PatientBaseInfoVO;
 import com.fs.qw.mapper.QwExternalContactMapper;
 import com.fs.system.oss.CloudStorageService;
@@ -43,6 +48,8 @@ import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxErrorException;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -62,6 +69,8 @@ import org.springframework.util.ObjectUtils;
 @Service
 public class FsPatientBaseInfoServiceImpl extends ServiceImpl<FsPatientBaseInfoMapper, FsPatientBaseInfo> implements IFsPatientBaseInfoService {
 
+    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
+
     @Autowired
     private RedisCache redisCache;
 
@@ -97,6 +106,12 @@ public class FsPatientBaseInfoServiceImpl extends ServiceImpl<FsPatientBaseInfoM
 
     @Autowired
     private QwExternalContactMapper qwExternalContactMapper;
+
+    @Autowired
+    private FsVideoResourceMapper fsVideoResourceMapper;
+
+    @Autowired
+    private FsCourseTrafficLogMapper fsCourseTrafficLogMapper;
     /**
      * 查询患者基本信息
      * 
@@ -329,6 +344,10 @@ public class FsPatientBaseInfoServiceImpl extends ServiceImpl<FsPatientBaseInfoM
         FsProject fsProject = projectService.selectFsProjectById(projectId);
         if (fsProject != null) {
             patientBaseInfoVO.setProject(fsProject);
+            FsVideoResource resource = fsVideoResourceMapper.selectVideoByVideoUrl(fsProject.getVideoUrl());
+            if (resource != null) {
+                patientBaseInfoVO.setDuration(resource.getDuration());
+            }
         }
 
         //红包配置信息
@@ -500,6 +519,40 @@ public class FsPatientBaseInfoServiceImpl extends ServiceImpl<FsPatientBaseInfoM
         return fsPatientBaseInfoMapper.updateFsPatientBaseInfo(map);
     }
 
+    @Override
+    public R getInternetTraffic(FsProjectVideoFinishUParam param) {
+        try {
+            if (param.getBufferRate()==null){
+                logger.error("【缓冲值空】参数: {}",param);
+                return R.error("缓冲值空");
+            }
+            FsCourseTrafficLog trafficLog = new FsCourseTrafficLog();
+            trafficLog.setCreateTime(new Date());
+            BeanUtils.copyProperties(param, trafficLog);
+            FsVideoResource resource = fsVideoResourceMapper.selectVideoByVideoUrl(param.getVideoUrl());
+            if (resource == null) {
+                return R.error("视频源不存在");
+            }
+            // 计算流量
+            BigDecimal result = param.getBufferRate().divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP);
+            BigDecimal longAsBigDecimal = BigDecimal.valueOf(resource.getFileSize());
+            long roundedResult = result.multiply(longAsBigDecimal).setScale(0, RoundingMode.HALF_UP).longValue();
+            trafficLog.setInternetTraffic( Math.round(roundedResult * 1.4));
+
+            // 处理 UUID 为空的情况
+            if (StringUtils.isNotEmpty(trafficLog.getUuId())) {
+                // 插入或更新
+                fsCourseTrafficLogMapper.insertOrUpdateTrafficLog(trafficLog);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            // 打印参数param和异常信息
+            logger.error("【插入或更新流量失败】参数: {}, 错误信息:{}", param, e.getMessage(), e);
+            return R.error();
+        }
+        return R.ok();
+    }
+
 
     private R sendProjectRedPacket(FsProjectSendRewardUParam param,FsUser user,CompanyUser companyUser){
         //默认0.1红包数据

+ 2 - 0
fs-service/src/main/java/com/fs/patient/vo/PatientBaseInfoVO.java

@@ -64,4 +64,6 @@ public class PatientBaseInfoVO {
 
     //打卡方式 0无需 1图片 2视频
     private Integer type;
+
+    private Integer duration; //时长
 }

+ 16 - 1
fs-service/src/main/resources/mapper/his/FsProjectMapper.xml

@@ -19,10 +19,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="secondContent"    column="second_content"    />
         <result property="thirdContent"    column="third_content"    />
         <result property="fourthContent"    column="fourth_content"    />
+        <result property="videoUrl"    column="video_url"    />
+        <result property="soundUrl"    column="sound_url"    />
+        <result property="soundStatus"    column="sound_status"    />
     </resultMap>
 
     <sql id="selectFsProjectVo">
-        select id, project_name, day_name, create_time, update_time, meridians_img_url, first_field, second_field, third_field, fourth_field, first_content, second_content, third_content, fourth_content from fs_project
+        select id, project_name, day_name, create_time, update_time, meridians_img_url
+             , first_field, second_field, third_field, fourth_field, first_content
+             , second_content, third_content, fourth_content,video_url
+             , sound_url, sound_status from fs_project
     </sql>
 
     <select id="selectFsProjectList" parameterType="FsProject" resultMap="FsProjectResult">
@@ -63,6 +69,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="secondContent != null">second_content,</if>
             <if test="thirdContent != null">third_content,</if>
             <if test="fourthContent != null">fourth_content,</if>
+            <if test="videoUrl != null">video_url,</if>
+            <if test="soundUrl != null">sound_url,</if>
+            <if test="soundStatus != null">sound_status,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="projectName != null">#{projectName},</if>
@@ -78,6 +87,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="secondContent != null">#{secondContent},</if>
             <if test="thirdContent != null">#{thirdContent},</if>
             <if test="fourthContent != null">#{fourthContent},</if>
+            <if test="videoUrl != null">#{videoUrl},</if>
+            <if test="soundUrl != null">#{soundUrl},</if>
+            <if test="soundStatus != null">#{soundStatus},</if>
          </trim>
     </insert>
 
@@ -97,6 +109,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="secondContent != null">second_content = #{secondContent},</if>
             <if test="thirdContent != null">third_content = #{thirdContent},</if>
             <if test="fourthContent != null">fourth_content = #{fourthContent},</if>
+            <if test="videoUrl != null">video_url = #{videoUrl},</if>
+            <if test="soundUrl != null">sound_url = #{soundUrl},</if>
+            <if test="soundStatus != null">sound_status = #{soundStatus},</if>
         </trim>
         where id = #{id}
     </update>

+ 9 - 0
fs-user-app/src/main/java/com/fs/app/controller/PatientBaseInfoController.java

@@ -5,6 +5,7 @@ import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.domain.R;
 import com.fs.patient.param.BindPatientParam;
 import com.fs.patient.param.FsProjectSendRewardUParam;
+import com.fs.patient.param.FsProjectVideoFinishUParam;
 import com.fs.patient.service.IFsPatientBaseInfoService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -44,4 +45,12 @@ public class PatientBaseInfoController extends  AppBaseController {
         param.setUserId(Long.parseLong(getUserId()));
         return fsPatientBaseInfoService.sendProjectReward(param);
     }
+
+    @Login
+    @ApiOperation("获取缓冲流量")
+    @PostMapping("/getInternetTraffic")
+    public R getInternetTraffic(@RequestBody FsProjectVideoFinishUParam param){
+        param.setUserId(Long.parseLong(getUserId()));
+        return fsPatientBaseInfoService.getInternetTraffic(param);
+    }
 }