From 49f6b357d372aa68e19e16d88e0bec9b2638f963 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Mon, 7 Jun 2021 16:11:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=95=99=E5=AD=A6?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=9F=A5=E7=9C=8B=E4=BD=BF=E7=94=A8=E6=97=B6?= =?UTF-8?q?=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/20210607-thesai.sql | 3 + .../rtss/controller/OrgController.java | 93 +++++++------- .../rtss/dao/UserSimulationStatsDAO.java | 6 +- .../rtss/dao/UserTrainingStatsMapper.java | 25 ++++ .../rtss/entity/UserSimulationStats.java | 34 ++++- .../entity/UserSimulationStatsExample.java | 121 ++++++++++++++++++ .../joylink/rtss/services/ILessonService.java | 2 + .../rtss/services/IUserUsageStatsService.java | 3 + .../joylink/rtss/services/LessonService.java | 3 +- .../rtss/services/UserUsageStatsService.java | 5 + .../rtss/services/org/IOrgService.java | 6 +- .../rtss/services/org/IOrgUserService.java | 3 + .../joylink/rtss/services/org/OrgService.java | 2 + .../rtss/services/org/OrgUserService.java | 46 ++++++- .../user/IUserSimulationStatService.java | 4 + .../user/UserSimulationStatService.java | 9 ++ .../client/org/StudentsUsageStatisticsVO.java | 50 ++++++++ .../rtss/vo/client/org/UsageQueryVO.java | 27 ++++ .../mybatis/mapper/UserSimulationStatsDAO.xml | 80 ++++++++++-- 19 files changed, 453 insertions(+), 69 deletions(-) create mode 100644 sql/20210607-thesai.sql create mode 100644 src/main/java/club/joylink/rtss/vo/client/org/StudentsUsageStatisticsVO.java create mode 100644 src/main/java/club/joylink/rtss/vo/client/org/UsageQueryVO.java diff --git a/sql/20210607-thesai.sql b/sql/20210607-thesai.sql new file mode 100644 index 000000000..b2a0f6544 --- /dev/null +++ b/sql/20210607-thesai.sql @@ -0,0 +1,3 @@ +ALTER TABLE `user_simulation_stats` +ADD COLUMN `end_time` datetime NOT NULL DEFAULT '1970-01-01 01:01:01' ON UPDATE CURRENT_TIMESTAMP AFTER `fake`; + diff --git a/src/main/java/club/joylink/rtss/controller/OrgController.java b/src/main/java/club/joylink/rtss/controller/OrgController.java index 76f354433..2b3a1b8a2 100644 --- a/src/main/java/club/joylink/rtss/controller/OrgController.java +++ b/src/main/java/club/joylink/rtss/controller/OrgController.java @@ -19,6 +19,7 @@ import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.LessonVO; import club.joylink.rtss.vo.client.Node; import club.joylink.rtss.vo.client.PageVO; +import club.joylink.rtss.vo.client.UserRankStatsVO; import club.joylink.rtss.vo.client.org.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -290,49 +291,55 @@ public class OrgController { return iOrgService.adminQueryOrgTree(orgId); } - @Transactional - @ApiOperation("数据处理接口,用后即删") - @PutMapping("/data/data") - public void data() { - OrgUserExample orgUserExample = new OrgUserExample(); - orgUserExample.createCriteria().andRoleEqualTo(BusinessConsts.OrgRole.Student.name()); - List ous = orgUserDAO.selectByExample(orgUserExample); - Set orgIdSet = new HashSet<>(); - Map> userId_orgIdSet_map = new HashMap<>(); - ous.forEach(ou -> { - orgIdSet.add(ou.getOrgId()); - Set userOrgIdSet = userId_orgIdSet_map.computeIfAbsent(ou.getUserId(), k -> new HashSet<>()); - userOrgIdSet.add(ou.getOrgId()); - }); - List orgList = iOrgService.findEntities(new ArrayList<>(orgIdSet), null); - Map orgId_rootId_map = orgList.stream().collect(Collectors.toMap(Org::getId, Org::getRootId)); - Map topOrgMap = iOrgService.findEntities(new ArrayList<>(orgId_rootId_map.values()), null) - .stream().collect(Collectors.toMap(Org::getId, Function.identity())); - List users = iSysUserService.findEntities(new ArrayList<>(userId_orgIdSet_map.keySet()), null); - Set nonRootOrgIds = new HashSet<>(); - users.forEach(user -> { - Set userOrgIdSet = userId_orgIdSet_map.get(user.getId()); - String orgCode = null; - Long rootId = null; - for (Long orgId : userOrgIdSet) { - rootId = orgId_rootId_map.get(orgId); - if (rootId == null) { - nonRootOrgIds.add(rootId); - } else { - Org org = topOrgMap.get(rootId); - if (orgCode == null) { - orgCode = org.getCode(); - } else { - BusinessExceptionAssertEnum.DATA_ERROR.assertEquals(orgCode, org.getCode(), userOrgIdSet.toString()); - } - } - } - BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(orgCode, user.getId() + "无所属顶级组织"); - user.setAccount(user.getAccount().substring(0, user.getAccount().indexOf(orgCode))); - user.setOrgId(rootId); - sysUserDAO.updateByPrimaryKey(user); - }); - System.out.println(nonRootOrgIds.toString()); + @ApiOperation("获取学生实训使用时长") + @GetMapping("/usage/students") + public List statisticUsage(@Validated UsageQueryVO queryVO) { + return iOrgUserService.statisticUsage(queryVO); } +// @Transactional +// @ApiOperation("数据处理接口,用后即删") +// @PutMapping("/data/data") +// public void data() { +// OrgUserExample orgUserExample = new OrgUserExample(); +// orgUserExample.createCriteria().andRoleEqualTo(BusinessConsts.OrgRole.Student.name()); +// List ous = orgUserDAO.selectByExample(orgUserExample); +// Set orgIdSet = new HashSet<>(); +// Map> userId_orgIdSet_map = new HashMap<>(); +// ous.forEach(ou -> { +// orgIdSet.add(ou.getOrgId()); +// Set userOrgIdSet = userId_orgIdSet_map.computeIfAbsent(ou.getUserId(), k -> new HashSet<>()); +// userOrgIdSet.add(ou.getOrgId()); +// }); +// List orgList = iOrgService.findEntities(new ArrayList<>(orgIdSet), null); +// Map orgId_rootId_map = orgList.stream().collect(Collectors.toMap(Org::getId, Org::getRootId)); +// Map topOrgMap = iOrgService.findEntities(new ArrayList<>(orgId_rootId_map.values()), null) +// .stream().collect(Collectors.toMap(Org::getId, Function.identity())); +// List users = iSysUserService.findEntities(new ArrayList<>(userId_orgIdSet_map.keySet()), null); +// Set nonRootOrgIds = new HashSet<>(); +// users.forEach(user -> { +// Set userOrgIdSet = userId_orgIdSet_map.get(user.getId()); +// String orgCode = null; +// Long rootId = null; +// for (Long orgId : userOrgIdSet) { +// rootId = orgId_rootId_map.get(orgId); +// if (rootId == null) { +// nonRootOrgIds.add(rootId); +// } else { +// Org org = topOrgMap.get(rootId); +// if (orgCode == null) { +// orgCode = org.getCode(); +// } else { +// BusinessExceptionAssertEnum.DATA_ERROR.assertEquals(orgCode, org.getCode(), userOrgIdSet.toString()); +// } +// } +// } +// BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(orgCode, user.getId() + "无所属顶级组织"); +// user.setAccount(user.getAccount().substring(0, user.getAccount().indexOf(orgCode))); +// user.setOrgId(rootId); +// sysUserDAO.updateByPrimaryKey(user); +// }); +// System.out.println(nonRootOrgIds.toString()); +// } + } diff --git a/src/main/java/club/joylink/rtss/dao/UserSimulationStatsDAO.java b/src/main/java/club/joylink/rtss/dao/UserSimulationStatsDAO.java index b48006746..af2d9b31d 100644 --- a/src/main/java/club/joylink/rtss/dao/UserSimulationStatsDAO.java +++ b/src/main/java/club/joylink/rtss/dao/UserSimulationStatsDAO.java @@ -5,11 +5,13 @@ import club.joylink.rtss.entity.UserSimulationStatsExample; import club.joylink.rtss.vo.client.UserRankStatsVO; import club.joylink.rtss.vo.client.UserSimulationStatsListVO; import club.joylink.rtss.vo.client.UserSimulationStatsQueryVO; +import club.joylink.rtss.vo.client.org.StudentsUsageStatisticsVO; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Update; import org.springframework.stereotype.Repository; +import java.time.LocalDateTime; import java.util.List; /** @@ -108,4 +110,6 @@ public interface UserSimulationStatsDAO extends MyBatisBaseDao queryUsage(long mapId, List userIds, LocalDateTime startTime, LocalDateTime endTime); +} diff --git a/src/main/java/club/joylink/rtss/dao/UserTrainingStatsMapper.java b/src/main/java/club/joylink/rtss/dao/UserTrainingStatsMapper.java index d981e4e4d..8a44379f8 100644 --- a/src/main/java/club/joylink/rtss/dao/UserTrainingStatsMapper.java +++ b/src/main/java/club/joylink/rtss/dao/UserTrainingStatsMapper.java @@ -75,6 +75,31 @@ public interface UserTrainingStatsMapper { "") UserRankStatsVO selectRank(LocalDateTime startTime, LocalDateTime endTime, List lessonIds, Long userId); + @Select("") + List selectUsage(LocalDateTime startTime, LocalDateTime endTime, List lessonIds, List userIds); + @Select("