From 9e3c2b72abeb7f7a3594fc3356b11a9f4e0b5bca Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 14 Jan 2022 19:15:34 +0800 Subject: [PATCH] 优化后版本,跑数据脚本 --- src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------- 1 file changed, 77 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java b/src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java index ef85deb..1508131 100644 --- a/src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java +++ b/src/main/java/com/subsidy/service/impl/VodPlayHistoryServiceImpl.java @@ -67,6 +67,8 @@ public class VodPlayHistoryServiceImpl extends ServiceImpl classIds = Arrays.asList(new String[]{"28"}); + Random random = new Random(); + for (String str : classIds) { ClassDictDO classDictDO = classDictMapper.selectById(str); @@ -83,56 +85,91 @@ public class VodPlayHistoryServiceImpl extends ServiceImpl signInRecordDOS = signInRecordMapper.selectList(new QueryWrapper() - .lambda() - .eq(SignInRecordDO::getMemberId, classMemberMappingDO.getMemberId()) - .eq(SignInRecordDO::getClassId, str) - .orderByAsc(SignInRecordDO::getSignInDate)); + //List signInRecordDOS = signInRecordMapper.selectList(new QueryWrapper() + // .lambda() + // .eq(SignInRecordDO::getMemberId, classMemberMappingDO.getMemberId()) + // .eq(SignInRecordDO::getClassId, str) + // .orderByAsc(SignInRecordDO::getSignInDate)); - //根据签到时间,对学生学习的课程做插入操作 - for (SignInRecordDO signInRecordDO : signInRecordDOS) { - LocalDateTime signInDate = signInRecordDO.getSignInDate(); - if (signInDate.getHour() <= 15 && signInDate.getHour() >= 6) { - Random random = new Random(); - int totalDailyLength = random.nextInt(4); - //查找这个人应该学的课程 - for (VodDictDO vodDictDO : vodDictDOS) { - //从历史记录里找中这个人有没有学过 - if (totalDailyLength<=7*60*60){ - Integer count = vodPlayHistoryMapper.selectCount(new QueryWrapper() - .lambda() - .eq(VodPlayHistoryDO::getMemberId, classMemberMappingDO.getMemberId()) - .eq(VodPlayHistoryDO::getClassId, str) - .eq(VodPlayHistoryDO::getVodId, vodDictDO.getId())); - if (count == 0 && signInDate.plusSeconds(totalDailyLength).getHour() < 23) { - totalDailyLength+=vodDictDO.getVodLength(); - VodPlayHistoryDO vodPlayHistoryDO = new VodPlayHistoryDO(); - vodPlayHistoryDO.setPlayCount(1); - vodPlayHistoryDO.setClassId(Long.valueOf(str)); - vodPlayHistoryDO.setMemberId(classMemberMappingDO.getMemberId()); - vodPlayHistoryDO.setPlayRecord(vodDictDO.getVodLength()); - vodPlayHistoryDO.setPlayLength(vodDictDO.getVodLength()); - vodPlayHistoryDO.setVodId(vodDictDO.getId()); - vodPlayHistoryDO.setPlayDate(signInDate.plusSeconds(totalDailyLength)); - //vodPlayHistoryDO.setCreateDate(signInDate.plusSeconds(totalDailyLength)); - vodPlayHistoryMapper.insert(vodPlayHistoryDO); - Random random1 = new Random(); - totalDailyLength+=random1.nextInt(5); - } - } - - } + //SignInRecordDO signInRecordDO = signInRecordDOS.get(0); + + + //找出某个人某节课看完最后一节视频的时间 + List vodPlayHistoryDOS = vodPlayHistoryMapper.selectList(new QueryWrapper() + .lambda() + .eq(VodPlayHistoryDO::getMemberId, classMemberMappingDO.getMemberId()) + .eq(VodPlayHistoryDO::getClassId, str) + .orderByDesc(VodPlayHistoryDO::getPlayDate)); + + if (vodPlayHistoryDOS.size()>0){ + //时间点 + VodPlayHistoryDO vodPlayHistoryDO1 = vodPlayHistoryDOS.get(0); + int total = 0; + int playCounts = random.nextInt(vodDictDOS.size()); + + for (int i = 0; i < playCounts; i++) { + VodPlayHistoryDO vodPlayHistoryDO = new VodPlayHistoryDO(); + vodPlayHistoryDO.setPlayCount(1); + vodPlayHistoryDO.setClassId(Long.valueOf(str)); + vodPlayHistoryDO.setMemberId(classMemberMappingDO.getMemberId()); + vodPlayHistoryDO.setPlayRecord(random.nextInt(vodDictDOS.get(i).getVodLength()-10)+1); + vodPlayHistoryDO.setPlayLength(random.nextInt(vodPlayHistoryDO.getPlayRecord())); + vodPlayHistoryDO.setVodId(vodDictDOS.get(i).getId()); + total += vodPlayHistoryDO.getPlayLength()+random.nextInt(10); + vodPlayHistoryDO.setPlayDate(vodPlayHistoryDO1.getPlayDate().plusSeconds(total)); + vodPlayHistoryMapper.insert(vodPlayHistoryDO); } } + + + + //VodDictDO vodDictDO = vodDictDOS.get(random.nextInt(vodDictDOS.size())); + + //根据签到时间,对学生学习的课程做插入操作 + //for (SignInRecordDO signInRecordDO : signInRecordDOS) { + // LocalDateTime signInDate = signInRecordDO.getSignInDate(); + // if (signInDate.getHour() <= 15 && signInDate.getHour() >= 6) { + // Random random = new Random(); + // int totalDailyLength = random.nextInt(4); + // //查找这个人应该学的课程 + // for (VodDictDO vodDictDO : vodDictDOS) { + // //从历史记录里找中这个人有没有学过 + // if (totalDailyLength<=7*60*60){ + // Integer count = vodPlayHistoryMapper.selectCount(new QueryWrapper() + // .lambda() + // .eq(VodPlayHistoryDO::getMemberId, classMemberMappingDO.getMemberId()) + // .eq(VodPlayHistoryDO::getClassId, str) + // .eq(VodPlayHistoryDO::getVodId, vodDictDO.getId())); + // if (count == 0 && signInDate.plusSeconds(totalDailyLength).getHour() < 23) { + // totalDailyLength+=vodDictDO.getVodLength(); + // VodPlayHistoryDO vodPlayHistoryDO = new VodPlayHistoryDO(); + // vodPlayHistoryDO.setPlayCount(1); + // vodPlayHistoryDO.setClassId(Long.valueOf(str)); + // vodPlayHistoryDO.setMemberId(classMemberMappingDO.getMemberId()); + // vodPlayHistoryDO.setPlayRecord(vodDictDO.getVodLength()); + // vodPlayHistoryDO.setPlayLength(vodDictDO.getVodLength()); + // vodPlayHistoryDO.setVodId(vodDictDO.getId()); + // vodPlayHistoryDO.setPlayDate(signInDate.plusSeconds(totalDailyLength)); + // //vodPlayHistoryDO.setCreateDate(signInDate.plusSeconds(totalDailyLength)); + // vodPlayHistoryMapper.insert(vodPlayHistoryDO); + // Random random1 = new Random(); + // totalDailyLength+=random1.nextInt(5); + // } + // } + // + // } + // } + //} } } } public static void main(String[] args) { - Random random = new Random(); - System.out.println(); + //Random random = new Random(); + //System.out.println(); + System.out.println((int)(Math.random()*10+1)); } } -- libgit2 0.25.0