فهرست منبع

feat:个微课程链接登录,注册成为会员

caoliqin 1 ماه پیش
والد
کامیت
a03317f0ed

+ 55 - 0
fs-service-system/src/main/java/com/fs/course/param/newfs/FsUserCourseAddCompanyUserParam.java

@@ -0,0 +1,55 @@
+package com.fs.course.param.newfs;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+@Data
+public class FsUserCourseAddCompanyUserParam implements Serializable {
+
+
+    // todo 需要调整
+    /**
+    * 视频小节id
+    */
+    @NotNull(message = "视频参数不能为空")
+    private Long videoId;
+
+
+    /**
+    * 登录的小程序id
+    */
+    private Long userId;
+
+    /**
+    * 公司id
+    */
+    private String corpId;
+
+    /**
+    *   companyUserId
+    */
+    private Long companyUserId;
+    /**
+    * 公司id
+    */
+    private Long companyId;
+
+    /**
+     * 视频课程id
+     */
+    @NotNull(message = "课程参数不能为空")
+    private Long courseId;
+
+
+    private Integer sendType; //归属发送方式:1 个微  2 企微
+
+    private Integer linkType; //链接类型
+
+
+    private Long linkId;
+
+    private Integer isRoom;
+
+}

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

@@ -114,4 +114,7 @@ public interface IFsUserCourseVideoService
      * @return list
      */
     List<FsUserVideoListVO> getListCourseVideo(UserCourseVideoPageParam param);
+
+    ResponseResult<Boolean> isAddCompanyUser(FsUserCourseVideoAddKfUParam param);
+
 }

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

@@ -826,4 +826,9 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
             return videoListVO;
         }).collect(Collectors.toList());
     }
+
+    @Override
+    public ResponseResult<Boolean> isAddCompanyUser(FsUserCourseVideoAddKfUParam param) {
+        return null;
+    }
 }

+ 175 - 0
fs-user-app/src/main/java/com/fs/app/controller/CourseWxH5Controller.java

@@ -0,0 +1,175 @@
+package com.fs.app.controller;
+
+
+import cn.hutool.json.JSONUtil;
+import com.fs.app.annotation.Login;
+import com.fs.common.core.domain.R;
+import com.fs.common.core.domain.ResponseResult;
+import com.fs.common.utils.StringUtils;
+import com.fs.course.config.CourseConfig;
+import com.fs.course.domain.FsCourseQuestionBank;
+import com.fs.course.domain.FsCourseWatchLog;
+import com.fs.course.param.FsUserCourseVideoAddKfUParam;
+import com.fs.course.param.FsUserCourseVideoFinishUParam;
+import com.fs.course.service.*;
+import com.fs.course.vo.FsUserCourseVideoH5DVO;
+import com.fs.course.vo.FsUserCourseVideoH5VO;
+import com.fs.course.vo.FsUserCourseVideoQuestionVO;
+import com.fs.system.service.ISysConfigService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.List;
+
+@Api("个微-h5看课接口")
+@RestController
+@RequestMapping(value="/app/course/wx/h5")
+public class CourseWxH5Controller extends  AppBaseController{
+    Logger logger= LoggerFactory.getLogger(getClass());
+    @Autowired
+    private IFsUserCourseService courseService;
+
+    @Autowired
+    private IFsUserCourseVideoService courseVideoService;
+
+    @Autowired
+    private ISysConfigService configService;
+
+    @Autowired
+    private IFsCourseLinkService courseLinkService;
+
+    @Autowired
+    private IFsCourseWatchLogService courseWatchLogService;
+
+    @Autowired
+    private IFsCourseQuestionBankService questionBankService;
+
+
+    @Login
+    @ApiOperation("判断是否添加客服(是否关联销售)")
+    @PostMapping("/isAddCompanyUser")
+    public ResponseResult<Boolean> isAddCompanyUser(@RequestBody FsUserCourseVideoAddKfUParam param) {
+        Long userId = Long.parseLong(getUserId());
+        param.setUserId(userId);
+        return courseVideoService.isAddCompanyUser(param);
+    }
+
+//    @ApiOperation("h5课程简介")
+//    @GetMapping("/getH5CourseByVideoId")
+//    public R getCourseByVideoId(@RequestParam("videoId") Long videoId,HttpServletRequest request)
+//    {
+//        FsUserCourseVideoH5VO course = courseService.selectFsUserCourseVideoH5VOByVideoId(videoId);
+//        return R.ok().put("data",course);
+//    }
+//
+//    @ApiOperation("h5课程详情")
+//    @GetMapping("/getH5CourseVideoDetails")
+//    public R getCourseVideoDetails(FsUserCourseVideoFinishUParam param)
+//    {
+//        String json = configService.selectConfigByKey("course.config");
+//        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
+//        FsUserCourseVideoH5DVO course = courseService.selectFsUserCourseVideoH5DVOByVideoId(param.getVideoId());
+//
+//        List<FsUserCourseVideoQuestionVO> questionVOList = new ArrayList<>();
+//        if (StringUtils.isNotEmpty(course.getQuestionBankId())){
+//            String[] questionIds = course.getQuestionBankId().split(",");
+//            for (String questionId : questionIds){
+//                FsUserCourseVideoQuestionVO vo = new FsUserCourseVideoQuestionVO();
+//                FsCourseQuestionBank questionBank = questionBankService.selectFsCourseQuestionBankById(Long.parseLong(questionId));
+//                if (questionBank!=null&&questionBank.getStatus()!=0){
+//                    BeanUtils.copyProperties(questionBank,vo);
+//                    questionVOList.add(vo);
+//                }
+//            }
+//        }
+//        Long duration = 0L;
+//        long tipsTime = 0L;
+//        int isFinish = 0;
+//        if (param.getLinkType()!=null&&param.getLinkType()==1){
+//            return R.ok().put("course",course).put("questions",questionVOList).put("config",config).put("playDuration",duration).put("tipsTime",tipsTime).put("maxBufferLength",config.getMaxBufferLength());
+//        }
+//        // 从Redis中获取观看时长
+//        String redisKey = "h5user:watch:duration:" + param.getQwUserId()+ ":" + param.getQwExternalId() + ":" + param.getVideoId();
+//        String durationStr = redisCache.getCacheObject(redisKey);
+//        FsCourseWatchLog log = courseWatchLogService.getWatchCourseVideoH5(param.getVideoId(),param.getQwUserId(),param.getQwExternalId());
+//        //redis取不到查库
+//        if (durationStr != null) {
+//            duration = Long.parseLong(durationStr);
+//        }else {
+//            duration = log.getDuration();
+//        }
+//
+//        if (course.getDuration()!=null){
+//            tipsTime = course.getDuration()/2;
+//        }
+//        //判断是否完课
+//        if (log.getLogType()==2){
+//           isFinish=1;
+//        }
+//
+//        //将视频时长也存到redis
+//        String videoRedisKey = "h5user:video:duration:" + param.getVideoId();
+//        Long videoDuration = redisCache.getCacheObject(videoRedisKey);
+//        if (videoDuration==null){
+//            redisCache.setCacheObject(videoRedisKey,course.getDuration());
+//        }
+//
+//        return R.ok().put("course",course).put("questions",questionVOList).put("config",config).put("playDuration",duration).put("tipsTime",tipsTime).put("maxBufferLength",config.getMaxBufferLength()).put("isFinish",isFinish);    }
+//
+//
+//
+//    @ApiOperation("获取真实链接")
+//    @GetMapping("/getRealLink")
+//    public R getRealLink(@RequestParam("sortLink")String link)
+//    {
+//        return courseLinkService.getRealLink(link);
+//    }
+//
+//
+//    @ApiOperation("更新看课时长")
+//    @PostMapping("/updateWatchDuration")
+//    public R updateWatchDuration(@RequestBody FsUserCourseVideoFinishUParam param)
+//    {
+//        return courseVideoService.updateWatchDuration(param);
+//    }
+//
+//
+//    @ApiOperation("获取缓冲流量")
+//    @PostMapping("/getInternetTraffic")
+//    public R getInternetTraffic(@RequestBody FsUserCourseVideoFinishUParam param) {
+//        return courseVideoService.getInternetTraffic(param);
+//    }
+
+//    @ApiOperation("答题")
+//    @PostMapping("/courseAnswer")
+//    public R courseAnswer(@RequestBody FsCourseQuestionAnswerUParam param)
+//    {
+//        logger.info("zyp \n【答题】:{}",param.getQuestions());
+//        if (param.getDuration()==null){
+//            logger.info("zyp \n【未识别到时长】:{}",param.getUserId());
+//        }
+//        return questionBankService.courseAnswer(param);
+//    }
+
+//    @ApiOperation("发放奖励")
+//    @PostMapping("/sendReward")
+//    @RepeatSubmit
+//    public R sendReward(@RequestBody FsCourseSendRewardUParam param)
+//    {
+//        logger.info("zyp \n【发放奖励】:{}",param);
+//        return courseVideoService.sendReward(param);
+//    }
+//
+//    @PostMapping("/getErrMsg")
+//    public void getErrMsg(@RequestParam("msg") String msg) {
+//        logger.error("zyp \n【h5看课中途报错】:{}",msg);
+//    }
+
+}

+ 109 - 0
fs-user-app/src/main/java/com/fs/app/controller/WxH5MpController.java

@@ -0,0 +1,109 @@
+package com.fs.app.controller;
+
+import cn.hutool.core.date.DateTime;
+import com.fs.app.param.FsUserLoginByMpParam;
+import com.fs.app.utils.JwtUtils;
+import com.fs.common.core.domain.R;
+import com.fs.common.core.redis.RedisCache;
+import com.fs.course.mapper.FsCourseSopLogsMapper;
+import com.fs.course.mapper.FsCourseWatchLogMapper;
+import com.fs.qw.mapper.QwExternalContactMapper;
+import com.fs.store.domain.FsUser;
+import com.fs.store.service.IFsUserService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.Synchronized;
+import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
+import me.chanjar.weixin.common.bean.menu.WxMenu;
+import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.mp.api.WxMpMenuService;
+import me.chanjar.weixin.mp.api.WxMpService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+@Api("个微-h5-微信相关接口")
+@RestController
+@RequestMapping("/app/wx/h5/mp")
+@Slf4j
+public class WxH5MpController {
+    Logger logger = LoggerFactory.getLogger(getClass());
+    @Autowired
+    private WxMpService wxMpService;
+    private static final String MP_TOKEN = "U2qmxEbsp0PJFoLRvUDvIjVi9XPzuVc2";
+
+    private static final String EncodingAESKey = "P3HE7Gd1PJVQqCLoOMop5uYfjx9LwfY53rnC3VUuLZS";
+
+    @Autowired
+    private IFsUserService userService;
+
+    @Autowired
+    JwtUtils jwtUtils;
+    @Autowired
+    RedisCache redisCache;
+
+    @Autowired
+    FsCourseWatchLogMapper fsCourseWatchLogMapper;
+    @Autowired
+    QwExternalContactMapper qwExternalContactMapper;
+    @Autowired
+    private FsCourseSopLogsMapper courseSopLogsMapper;
+
+
+    @ApiOperation("课程分享链接公众号登录")
+    @PostMapping("/loginByMp")
+    public R loginByMp(@Valid @RequestBody FsUserLoginByMpParam param) {
+        try {
+            //获取微信用户信息
+            WxOAuth2AccessToken wxMpOAuth2AccessToken = wxMpService.getOAuth2Service().getAccessToken(param.getCode());
+            WxOAuth2UserInfo wxMpUser = wxMpService.getOAuth2Service().getUserInfo(wxMpOAuth2AccessToken, null);
+            FsUser user = userService.selectFsUserByUnionid(wxMpUser.getUnionId());
+            if (user != null) {
+                //修改
+                FsUser userMap = new FsUser();
+                userMap.setUserId(user.getUserId());
+                userMap.setMpOpenId(wxMpUser.getOpenid());
+                userMap.setUpdateTime(new DateTime());
+                userMap.setNickname(wxMpUser.getNickname());
+                userService.updateFsUser(userMap);
+            } else {
+                //新增
+                user = new FsUser();
+                user.setNickname(wxMpUser.getNickname());
+                user.setAvatar(wxMpUser.getHeadImgUrl());
+                user.setStatus(1);
+                user.setMpOpenId(wxMpUser.getOpenid());
+                user.setUnionId(wxMpUser.getUnionId());
+                user.setCreateTime(new Date());
+                user.setCompanyId(param.getCompanyId());
+                user.setCompanyUserId(param.getCompanyUserId());
+                userService.insertFsUser(user);
+            }
+            log.error("用户信息user: {}, 用户id: {}", user, user.getUserId());
+            String token = jwtUtils.generateToken(user.getUserId());
+            redisCache.setCacheObject("token:" + user.getUserId(), token, 604800, TimeUnit.SECONDS);
+            Map<String, Object> map = new HashMap<>();
+            map.put("token", token);
+            map.put("user", user);
+            return R.ok(map);
+        } catch (WxErrorException e) {
+            if (e.getError().getErrorCode() == 40163) {
+                return R.error(40163, e.getError().getErrorMsg());
+            } else {
+                return R.error("授权失败," + e.getMessage());
+            }
+        }
+
+    }
+
+
+}

+ 10 - 0
fs-user-app/src/main/java/com/fs/app/param/FsUserLoginByMpParam.java

@@ -1,8 +1,10 @@
 package com.fs.app.param;
 
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 
 @Data
@@ -10,4 +12,12 @@ public class FsUserLoginByMpParam implements Serializable {
     @NotBlank(message = "code参数缺失")
     private String code;
     private Long videoId;
+
+    @NotNull(message = "公司id不能为空")
+    @ApiModelProperty(value = "公司id")
+    private Long companyId;
+
+    @NotNull(message = "销售id不能为空")
+    @ApiModelProperty(value = "销售id")
+    private Long companyUserId;
 }