diff --git a/src/main/java/com/subsidy/controller/MemberStudyLengthController.java b/src/main/java/com/subsidy/controller/MemberStudyLengthController.java new file mode 100644 index 0000000..3b49989 --- /dev/null +++ b/src/main/java/com/subsidy/controller/MemberStudyLengthController.java @@ -0,0 +1,22 @@ +package com.subsidy.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.Api; + +/** + *

+ * 前端控制器 + *

+ * + * @author DengMin + * @since 2022-01-28 + */ +@RestController +@Api(tags = "") +@RequestMapping("/member-study-length-do") +public class MemberStudyLengthController { + +} diff --git a/src/main/java/com/subsidy/controller/VodPlayHistoryController.java b/src/main/java/com/subsidy/controller/VodPlayHistoryController.java index 85eb0ff..95dfe80 100644 --- a/src/main/java/com/subsidy/controller/VodPlayHistoryController.java +++ b/src/main/java/com/subsidy/controller/VodPlayHistoryController.java @@ -4,6 +4,7 @@ package com.subsidy.controller; import com.alibaba.fastjson.JSON; import com.subsidy.common.ResponseData; import com.subsidy.common.ResponseVO; +import com.subsidy.dto.vod.RemainSecondsDTO; import com.subsidy.dto.vod.SignDatePlaysDTO; import com.subsidy.dto.vod.FixDataTwoDTO; import com.subsidy.model.VodPlayHistoryDO; @@ -46,12 +47,20 @@ public class VodPlayHistoryController { } @PostMapping("dataFix") + @ApiOperation("每个视频都看一次") public void dadaFix(@RequestBody SignDatePlaysDTO dataFixDTO){ vodPlayHistoryService.dataFix(dataFixDTO); } @PostMapping("signDatePlays") + @ApiOperation("每天接着看几个视频 接dataFix的") public void signDatePlays(@RequestBody SignDatePlaysDTO signDatePlaysDTO ){ vodPlayHistoryService.signDatePlays(signDatePlaysDTO); } + + @PostMapping("remainSeconds") + @ApiOperation("每个视频先看一下,然后剩余时长分配到每天里") + public void remainSeconds(@RequestBody RemainSecondsDTO remainSecondsDTO){ + vodPlayHistoryService.remainSeconds(remainSecondsDTO); + } } diff --git a/src/main/java/com/subsidy/dto/vod/RemainSecondsDTO.java b/src/main/java/com/subsidy/dto/vod/RemainSecondsDTO.java new file mode 100644 index 0000000..2a5c466 --- /dev/null +++ b/src/main/java/com/subsidy/dto/vod/RemainSecondsDTO.java @@ -0,0 +1,10 @@ +package com.subsidy.dto.vod; + +import lombok.Data; + +@Data +public class RemainSecondsDTO { + + private Long classId; + +} diff --git a/src/main/java/com/subsidy/mapper/MemberStudyLengthMapper.java b/src/main/java/com/subsidy/mapper/MemberStudyLengthMapper.java new file mode 100644 index 0000000..baf8f13 --- /dev/null +++ b/src/main/java/com/subsidy/mapper/MemberStudyLengthMapper.java @@ -0,0 +1,18 @@ +package com.subsidy.mapper; + +import com.subsidy.model.MemberStudyLengthDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.springframework.stereotype.Repository; + +/** + *

+ * Mapper 接口 + *

+ * + * @author DengMin + * @since 2022-01-28 + */ + @Repository +public interface MemberStudyLengthMapper extends BaseMapper { + +} diff --git a/src/main/java/com/subsidy/model/MemberStudyLengthDO.java b/src/main/java/com/subsidy/model/MemberStudyLengthDO.java new file mode 100644 index 0000000..3d1295b --- /dev/null +++ b/src/main/java/com/subsidy/model/MemberStudyLengthDO.java @@ -0,0 +1,33 @@ +package com.subsidy.model; + +import com.subsidy.util.BaseModel; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * + *

+ * + * @author DengMin + * @since 2022-01-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("member_study_length") +public class MemberStudyLengthDO extends BaseModel { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + private Long memberId; + + private Integer totalLength; + + +} diff --git a/src/main/java/com/subsidy/service/MemberStudyLengthService.java b/src/main/java/com/subsidy/service/MemberStudyLengthService.java new file mode 100644 index 0000000..17639a3 --- /dev/null +++ b/src/main/java/com/subsidy/service/MemberStudyLengthService.java @@ -0,0 +1,16 @@ +package com.subsidy.service; + +import com.subsidy.model.MemberStudyLengthDO; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author DengMin + * @since 2022-01-28 + */ +public interface MemberStudyLengthService extends IService { + +} diff --git a/src/main/java/com/subsidy/service/VodPlayHistoryService.java b/src/main/java/com/subsidy/service/VodPlayHistoryService.java index 04830dd..5e1fa20 100644 --- a/src/main/java/com/subsidy/service/VodPlayHistoryService.java +++ b/src/main/java/com/subsidy/service/VodPlayHistoryService.java @@ -1,5 +1,6 @@ package com.subsidy.service; +import com.subsidy.dto.vod.RemainSecondsDTO; import com.subsidy.dto.vod.SignDatePlaysDTO; import com.subsidy.dto.vod.FixDataTwoDTO; import com.subsidy.model.VodPlayHistoryDO; @@ -22,4 +23,6 @@ public interface VodPlayHistoryService extends IService { void dataFix(SignDatePlaysDTO dataFixDTO); void signDatePlays(SignDatePlaysDTO dataFixDTO); + + void remainSeconds(RemainSecondsDTO remainSecondsDTO); } diff --git a/src/main/java/com/subsidy/service/impl/MemberStudyLengthServiceImpl.java b/src/main/java/com/subsidy/service/impl/MemberStudyLengthServiceImpl.java new file mode 100644 index 0000000..503401b --- /dev/null +++ b/src/main/java/com/subsidy/service/impl/MemberStudyLengthServiceImpl.java @@ -0,0 +1,20 @@ +package com.subsidy.service.impl; + +import com.subsidy.model.MemberStudyLengthDO; +import com.subsidy.mapper.MemberStudyLengthMapper; +import com.subsidy.service.MemberStudyLengthService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author DengMin + * @since 2022-01-28 + */ +@Service +public class MemberStudyLengthServiceImpl extends ServiceImpl implements MemberStudyLengthService { + +} diff --git a/src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java b/src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java index 6b67fba..7ba00d2 100644 --- a/src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java +++ b/src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java @@ -81,7 +81,7 @@ public class SignInRecordServiceImpl extends ServiceImpl classDictDOS = classMemberMappingMapper.getMemberClass(signInRecordDO.getMemberId()); for (ClassDictDO classDictDO : classDictDOS) { - redisUtil.set(RedisPrefixConstant.SUBSIDY_SIGN_INFO_PREFIX + signInRecordDO.getMemberId() + ":classId:" + classDictDO.getId() + ":" + DateFormatUtil.format(new Date(), "yyyyMMdd") + ":" + System.currentTimeMillis(), null); + redisUtil.set(RedisPrefixConstant.SUBSIDY_SIGN_INFO_PREFIX + signInRecordDO.getMemberId() + ":classId:" + classDictDO.getId() + ":" + DateFormatUtil.format(new Date(), "yyyy-MM-dd") + ":" + System.currentTimeMillis(), null); } return ConstantUtils.ADD_SUCCESS; @@ -152,6 +152,8 @@ public class SignInRecordServiceImpl extends ServiceImpl vodDictDOS) { - - Random random = new Random(); - int counts = random.nextInt(3) + 1; - for (int i = 0; i < counts; i++) { - VodPlayHistoryDO vodPlayHistoryDO = new VodPlayHistoryDO(); - Random random1 = new Random(); - int j = random1.nextInt(vodDictDOS.size()); - vodPlayHistoryDO.setPlayCount(1); - vodPlayHistoryDO.setClassId(classId); - vodPlayHistoryDO.setMemberId(memberId); -// vodPlayHistoryDO.setPlayRecord(h); - vodPlayHistoryDO.setPlayLength(new Random().nextInt(vodPlayHistoryDO.getPlayRecord())); - playLength += vodPlayHistoryDO.getPlayLength(); - vodPlayHistoryDO.setVodId(vodId); - vodPlayHistoryDO.setPlayDate(localDateTime.plusSeconds(playLength)); - vodPlayHistoryMapper.insert(vodPlayHistoryDO); + public void remainSeconds(RemainSecondsDTO remainSecondsDTO) { + + Long classId = remainSecondsDTO.getClassId(); + + ClassDictDO classDictDO = classDictMapper.selectById(classId); + + //找到班级里的学生 + List classMemberMappingDOS = classMemberMappingMapper.selectList(new QueryWrapper() + .lambda() + .eq(ClassMemberMappingDO::getClassId, Long.valueOf(classId))); + //查找课程里的所有视频 + List vodDictDOS = courseContentMapper.getCourseVods(classDictDO.getCourseId()); + + + //查看每个人看视频的时长 + for (ClassMemberMappingDO classMemberMappingDO : classMemberMappingDOS) { + + //查看每个人的剩余时长 + MemberStudyLengthDO memberStudyLengthDO = memberStudyLengthMapper.selectOne(new QueryWrapper() + .lambda() + .eq(MemberStudyLengthDO::getMemberId, classMemberMappingDO.getMemberId())); + + + //查询这个人 这节课 签到记录 排序 + List signInRecordDOS = signInRecordMapper.selectList(new QueryWrapper() + .lambda() + .eq(SignInRecordDO::getMemberId, classMemberMappingDO.getMemberId()) + .eq(SignInRecordDO::getClassId, classId)); + + for (SignInRecordDO signInRecordDO : signInRecordDOS) { + + //查看当天这人已经看的视频时长 + List vodPlayHistoryDOS = vodPlayHistoryMapper.exPlayInfo(classMemberMappingDO.getMemberId(), String.valueOf(classId), signInRecordDO.getSignInDate()); + + //查看学生一看视频时长 + int totalLength = 0; + System.out.println("111111111111111"); + List vodPlayHistoryDOS1 = vodPlayHistoryMapper.selectList(new QueryWrapper() + .lambda() + .eq(VodPlayHistoryDO::getMemberId, classMemberMappingDO.getMemberId()) + .eq(VodPlayHistoryDO::getClassId, classId)); + for (VodPlayHistoryDO vodPlayHistoryDO : vodPlayHistoryDOS1) { + totalLength += vodPlayHistoryDO.getPlayLength(); + } + + int leftLength = 0 ; + + System.out.println("22222222222222222222222"); + if (memberStudyLengthDO!=null){ + //这个人还剩多少时长 + leftLength = memberStudyLengthDO.getTotalLength() - totalLength; + } + + System.out.println("2.5==============================="); + //当天已经看了多少时间视频 + int playLength = 0; + + for (int m = 0; m < vodPlayHistoryDOS.size(); m++) { + playLength += vodPlayHistoryDOS.get(m).getPlayLength(); + } + + System.out.println("33333333333333333333"); + if (leftLength > 0) { + //随机看几个视频 + int playCounts = new Random().nextInt(4)+2; + System.out.println("4444444444444444"); + for (int i = 0; i < playCounts; i++) { + VodPlayHistoryDO vodPlayHistoryDO = new VodPlayHistoryDO(); + Random random1 = new Random(); + System.out.println("55555555555555555555"); + int j = random1.nextInt(vodDictDOS.size()); + vodPlayHistoryDO.setPlayCount(1); + vodPlayHistoryDO.setClassId(classId); + vodPlayHistoryDO.setMemberId(classMemberMappingDO.getMemberId()); + int h = new Random().nextInt(vodDictDOS.get(j).getVodLength() - 10) + 1; + System.out.println("666666666666666666"); + vodPlayHistoryDO.setPlayRecord(new Random().nextInt(h)); + if (leftLength - h > 0) { + vodPlayHistoryDO.setPlayLength(h); + playLength += h; + vodPlayHistoryDO.setVodId(vodDictDOS.get(j).getId()); + vodPlayHistoryDO.setPlayDate(signInRecordDO.getSignInDate().plusSeconds(playLength)); + leftLength = leftLength - h; + vodPlayHistoryMapper.insert(vodPlayHistoryDO); + } else { + vodPlayHistoryDO.setPlayLength(leftLength); + playLength+=leftLength; + vodPlayHistoryDO.setVodId(vodDictDOS.get(j).getId()); + vodPlayHistoryDO.setPlayDate(signInRecordDO.getSignInDate().plusSeconds(playLength)); + vodPlayHistoryMapper.insert(vodPlayHistoryDO); + break; + } + } + } + } } - return 0; } public static void main(String[] args) { - while (true){ + while (true) { System.out.println(new Random().nextInt(4)); } // int m = 0; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index dbc0753..cf4411d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,7 @@ # 环境配置 -spring.profiles.active=prod +spring.profiles.active=dev # 端口号 -spring.server.port=23459 +spring.server.port=23457 #嵌入tomcat配置 #和CPU数 spring.server.acceptorThreadCount=600 diff --git a/src/main/resources/mapper/CourseContentMapper.xml b/src/main/resources/mapper/CourseContentMapper.xml index dceb6f7..aa5e885 100644 --- a/src/main/resources/mapper/CourseContentMapper.xml +++ b/src/main/resources/mapper/CourseContentMapper.xml @@ -40,7 +40,7 @@ t.delete_date IS NULL AND t2.delete_date IS NULL and t.course_id = #{courseId} - and t2.id is not null + and t2.id is not null