工作日志统计记录-按用户分组查询优化

优化了工作日志统计记录的查询逻辑,按用户分组时不再依赖特定的姓名和部门名称字段。重构了数据库映射,
将查询结果映射为更通用的LogStatisticsDetailsVO对象,从而提高了代码的复用性和维护性。
This commit is contained in:
aikai 2024-08-15 23:30:21 +08:00
parent abef64022e
commit 82fab6cf68
4 changed files with 6 additions and 12 deletions

View File

@ -7,10 +7,4 @@ import lombok.Data;
@Data @Data
public class LogStatisticsGroupByUserVO extends LogStatisticsDetailsVO { public class LogStatisticsGroupByUserVO extends LogStatisticsDetailsVO {
@Schema(description = "姓名")
private String nickName;
@Schema(description = "部门名称")
private String deptName;
} }

View File

@ -91,5 +91,5 @@ public interface LogStatisticsMapper extends BaseMapperX<LogStatisticsDO> {
* @param dto * @param dto
* @return * @return
*/ */
List<LogStatisticsGroupByUserVO> getStatisticsGroupByUser(@Param("dto") LogStatisticsDetailsListGroupByUserDTO dto); List<LogStatisticsDetailsVO> getStatisticsGroupByUser(@Param("dto") LogStatisticsDetailsListGroupByUserDTO dto);
} }

View File

@ -407,12 +407,12 @@ public class LogStatisticsServiceImpl implements LogStatisticsService {
} }
dto.setDateList(dateList); dto.setDateList(dateList);
// 获取到所有数据 然后在java代码中分组 // 获取到所有数据 然后在java代码中分组
List<LogStatisticsGroupByUserVO> vos = logStatisticsMapper.getStatisticsGroupByUser(dto); List<LogStatisticsDetailsVO> vos = logStatisticsMapper.getStatisticsGroupByUser(dto);
// 根据用户id/部门id分组 // 根据用户id/部门id分组
Map<String, List<LogStatisticsGroupByUserVO>> map = vos.stream().collect(Collectors.groupingBy(a -> a.getUserId() + "_" + a.getDeptId() + "_" + a.getType())); Map<String, List<LogStatisticsDetailsVO>> map = vos.stream().collect(Collectors.groupingBy(a -> a.getUserId() + "_" + a.getDeptId() + "_" + a.getType()));
for (Map.Entry<String, List<LogStatisticsGroupByUserVO>> entry : map.entrySet()) { for (Map.Entry<String, List<LogStatisticsDetailsVO>> entry : map.entrySet()) {
LogStatisticsDetailsListGroupByUserVO vo = new LogStatisticsDetailsListGroupByUserVO(); LogStatisticsDetailsListGroupByUserVO vo = new LogStatisticsDetailsListGroupByUserVO();
vo.setNickName(entry.getValue().get(0).getNickName()); vo.setNickName(entry.getValue().get(0).getNickname());
vo.setDeptName(entry.getValue().get(0).getDeptName()); vo.setDeptName(entry.getValue().get(0).getDeptName());
vo.setType(entry.getValue().get(0).getType()); vo.setType(entry.getValue().get(0).getType());
vo.setShould(entry.getValue().size()); vo.setShould(entry.getValue().size());

View File

@ -152,7 +152,7 @@
</where> </where>
</select> </select>
<select id="getStatisticsGroupByUser" <select id="getStatisticsGroupByUser"
resultType="cn.iocoder.yudao.module.system.controller.admin.worklog.vo.statisticsrecord.LogStatisticsGroupByUserVO"> resultType="cn.iocoder.yudao.module.system.controller.admin.worklog.vo.statistics.LogStatisticsDetailsVO">
SELECT SELECT
a.nickname as nickName, a.nickname as nickName,
c.`name` as deptName, c.`name` as deptName,