From 04198fa7061d27bb9742cb31a54f5863f331abcb Mon Sep 17 00:00:00 2001 From: typ Date: Sun, 20 Feb 2022 11:28:20 +0800 Subject: [PATCH] 签到逻辑,签到数大于等于当日可签到数就表示已经签过到了 --- src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 182 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java b/src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java index 5b1de68..7d70fb4 100644 --- a/src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java +++ b/src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java @@ -339,10 +339,10 @@ public class VodPlayHistoryServiceImpl extends ServiceImpl 0) { //随机看几个视频 - int playCounts = new Random().nextInt(4)+2; + int playCounts = new Random().nextInt(4) + 2; System.out.println("4444444444444444"); for (int i = 0; i < playCounts; i++) { VodPlayHistoryDO vodPlayHistoryDO = new VodPlayHistoryDO(); @@ -380,7 +380,7 @@ public class VodPlayHistoryServiceImpl extends ServiceImpl classMemberMappingDOS = classMemberMappingMapper.selectList(new QueryWrapper() + .lambda() + .eq(ClassMemberMappingDO::getClassId, classDictDO.getId())); + + //查找课程里的所有视频 + List vodDictDOS = courseContentMapper.getCourseVods(classDictDO.getCourseId()); + + //查看每个人看视频的时长 + for (ClassMemberMappingDO classMemberMappingDO : classMemberMappingDOS) { + + //查看签到次数,得到学习时长 + //查询这个人 这节课 签到记录 排序 + List signInRecordDOS = signInRecordMapper.selectList(new QueryWrapper() + .lambda() + .eq(SignInRecordDO::getMemberId, classMemberMappingDO.getMemberId()) + .eq(SignInRecordDO::getClassId, classDictDO.getId()) + .orderByAsc(SignInRecordDO::getSignInDate)); + + List localDateTimes = new ArrayList<>(); + for (SignInRecordDO signInrecord : signInRecordDOS) { + if (signInrecord.getSignInDate().getHour() >= 6 && signInrecord.getSignInDate().getHour() < 15) { + localDateTimes.add(signInrecord.getSignInDate()); + } + } + int signInrecord = localDateTimes.size(); + int vodSize = vodDictDOS.size(); + + LinkedHashMap hashMap = new LinkedHashMap<>(); + List integers = new ArrayList<>(); + + int m = 0; + + int rdm_total = 0; + for (int k = 0; k < signInrecord; k++) { + int n = getRandom(); + rdm_total += n; + if ((m + n) < vodSize && k != signInrecord - 1) { + m += n; + //if (n > 11 || n < 5) { + // System.out.println("error" + "==================="); + //} + hashMap.put(localDateTimes.get(k), n); + integers.add(localDateTimes.get(k)); + } else { + //if (vodSize - rdm_total + n > 10 || vodSize - rdm_total + n < 5) { + // System.out.println("error+=================="); + //} + hashMap.put(localDateTimes.get(k), vodSize - rdm_total + n); + integers.add(localDateTimes.get(k)); + break; + } + } + + //是否是最后一天的 + int key_index = 0; +// for (LocalDateTime localDateTime : hashMap.keySet()){ +// if (hashMap.get(localDateTime)>10||hashMap.get(localDateTime)<5){ +// System.out.println("================"); +// } +// } + + for (LocalDateTime localDateTime : localDateTimes) { + + //今天应该看多久视频 + int totalPlayLength = 0; + if (signInRecordDOS.size() == 3) { + totalPlayLength = _3times(); + } else if (signInRecordDOS.size() == 4) { + totalPlayLength = _4times(); + } else if (signInRecordDOS.size() == 5) { + totalPlayLength = _5times(); + } else if (signInRecordDOS.size() == 6) { + totalPlayLength = _6times(); + } else { + totalPlayLength = _7times(); + } + + //今天已看视频时长 + int totalPlay = 0; + + //先续播前一天未看完的视频 + List vodPlayHistoryDOS = vodPlayHistoryMapper.selectList(new QueryWrapper() + .lambda() + .eq(VodPlayHistoryDO::getMemberId, classMemberMappingDO.getMemberId()) + .eq(VodPlayHistoryDO::getClassId, classDictDO.getId()) + .orderByDesc(VodPlayHistoryDO::getPlayDate)); + //续播 + if (vodPlayHistoryDOS.size() > 0) { + VodPlayHistoryDO vodPlayHistoryDO1 = vodPlayHistoryDOS.get(0); + VodDictDO vodDictDO = vodDictMapper.selectById(vodPlayHistoryDO1.getVodId()); + //剩下的学习时长 + int leftLength = vodDictDO.getVodLength() - vodPlayHistoryDO1.getPlayLength(); + if (leftLength > 0) { + totalPlay += leftLength; + VodPlayHistoryDO vodPlayHistoryDO = new VodPlayHistoryDO(); + vodPlayHistoryDO.setPlayCount(1); + vodPlayHistoryDO.setClassId(classDictDO.getId()); + vodPlayHistoryDO.setMemberId(classMemberMappingDO.getMemberId()); + vodPlayHistoryDO.setPlayRecord(vodDictDO.getVodLength()); + vodPlayHistoryDO.setPlayLength(leftLength); + vodPlayHistoryDO.setVodId(vodDictDO.getId()); + vodPlayHistoryDO.setPlayDate(localDateTime.plusSeconds(leftLength)); + vodPlayHistoryMapper.insert(vodPlayHistoryDO); + } + } + + //查找这个人应该学的课程 + for (VodDictDO vodDictDO : vodDictDOS) { + //从历史记录里找中这个人有没有学过 + Integer count = vodPlayHistoryMapper.selectCount(new QueryWrapper() + .lambda() + .eq(VodPlayHistoryDO::getMemberId, classMemberMappingDO.getMemberId()) + .eq(VodPlayHistoryDO::getClassId, classDictDO.getId()) + .eq(VodPlayHistoryDO::getVodId, vodDictDO.getId())); + //表示这个视频没有学过 + if (count == 0) { + if (totalPlayLength > totalPlay) { //说明今天还可以学 + VodPlayHistoryDO vodPlayHistoryDO = new VodPlayHistoryDO(); + vodPlayHistoryDO.setPlayCount(1); + vodPlayHistoryDO.setClassId(classDictDO.getId()); + vodPlayHistoryDO.setMemberId(classMemberMappingDO.getMemberId()); + vodPlayHistoryDO.setPlayRecord(vodDictDO.getVodLength()); + if (totalPlay+vodDictDO.getVodLength()<=totalPlayLength){ + vodPlayHistoryDO.setPlayLength(vodDictDO.getVodLength()); + }else { + vodPlayHistoryDO.setPlayLength(totalPlayLength-totalPlay); + } + vodPlayHistoryDO.setVodId(vodDictDO.getId()); + vodPlayHistoryDO.setPlayDate(localDateTime.plusSeconds(totalPlay)); + vodPlayHistoryMapper.insert(vodPlayHistoryDO); + } + } + } + key_index++; + } + } + } + + //19为基数的话,3次签到6.5到8,4次签到4.8-6, + // 5次4-6,6次3.2-6,7次及以上2.5-6吧 - //按照视频顺序依次学习完 每天学习时长不得超过8小时 + //int randNumber =rand.nextInt(MAX - MIN + 1) + MIN; + + /** + * 3次签到 23400---28800 + */ + public Integer _3times() { + return new Random().nextInt(28800 - 23400 + 1) + 23400; + } + + /** + * 4次签到 23400---28800 + */ + public Integer _4times() { + return new Random().nextInt(6 * 60 * 60 - 48 * 6 * 60 + 1) + 48 * 6 * 60; + } + + /** + * 5次签到 23400---28800 + */ + public Integer _5times() { + return new Random().nextInt(6 * 60 * 60 - 4 * 60 * 60 + 1) + 4 * 60 * 60; + } + + /** + * 6次签到 23400---28800 + */ + public Integer _6times() { + return new Random().nextInt(6 * 60 * 60 - 32 * 6 * 60 + 1) + 32 * 60 * 6; + } + /** + * 7次签到 23400---28800 + */ + public Integer _7times() { + return new Random().nextInt(6 * 60 * 60 - 25 * 6 * 60 + 1) + 25 * 6 * 60; } public static void main(String[] args) { -- libgit2 0.25.0