diff --git a/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/controller/admin/aiassistantreport/AiAssistantReportController.java b/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/controller/admin/aiassistantreport/AiAssistantReportController.java index 58703a5..68e6a1c 100644 --- a/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/controller/admin/aiassistantreport/AiAssistantReportController.java +++ b/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/controller/admin/aiassistantreport/AiAssistantReportController.java @@ -25,6 +25,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -85,6 +86,15 @@ public class AiAssistantReportController { return success(aiAssistantReportService.getMyReportPage(reqVO)); } + @GetMapping("/dept-daily-list") + @Operation(summary = "按部门+统计日查询全员汇报(单次查询,用于日志填报汇总)") + public CommonResult> listDeptDailyReports( + @Parameter(description = "部门编号", required = true) @RequestParam("deptId") Long deptId, + @Parameter(description = "统计日", required = true) @RequestParam("reportDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate reportDate, + @Parameter(description = "模块编码(可选)") @RequestParam(value = "moduleCode", required = false) String moduleCode) { + return success(aiAssistantReportService.listDeptDailyReports(deptId, reportDate, moduleCode)); + } + @GetMapping("/report-count-by-date") @Operation(summary = "按日期聚合报告提交数量(用于轨迹图)") public CommonResult> getReportCountByDate( @@ -111,6 +121,13 @@ public class AiAssistantReportController { return success(aiAssistantReportDetailService.listByReportId(reportId, loginUserId)); } + @GetMapping("/detail/list-for-manage") + @Operation(summary = "按每日汇报主键查询详表(管理端:日志填报汇总等,与 dept-daily-list 同权限)") + public CommonResult> getDetailListForManage( + @Parameter(description = "每日汇报主表 ID", required = true) @RequestParam("reportId") Long reportId) { + return success(aiAssistantReportDetailService.listByReportIdForManage(reportId)); + } + @PostMapping("/detail/save-batch") @Operation(summary = "批量保存详表(全量替换:先删后插,与主表保存分步调用)") public CommonResult saveDetailBatch(@Valid @RequestBody AiAssistantReportDetailBatchSaveReqVO reqVO) { diff --git a/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/dal/mysql/aiassistantreport/AiAssistantReportMapper.java b/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/dal/mysql/aiassistantreport/AiAssistantReportMapper.java index 37e4ac1..be0a2fc 100644 --- a/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/dal/mysql/aiassistantreport/AiAssistantReportMapper.java +++ b/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/dal/mysql/aiassistantreport/AiAssistantReportMapper.java @@ -5,12 +5,15 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.ydoyun.controller.admin.aiassistantreport.vo.AiAssistantReportPageReqVO; import cn.iocoder.yudao.module.ydoyun.controller.admin.aiassistantreport.vo.ReportCountByDateVO; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.module.ydoyun.dal.dataobject.aiassistantreport.AiAssistantReportDO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.time.LocalDate; +import java.util.Collection; +import java.util.Collections; import java.util.List; /** @@ -38,6 +41,22 @@ public interface AiAssistantReportMapper extends BaseMapperX selectListByReporterIdsAndReportDate( + Collection reporterIds, String moduleCode, LocalDate reportDate) { + if (CollUtil.isEmpty(reporterIds)) { + return Collections.emptyList(); + } + return selectList(new LambdaQueryWrapperX() + .in(AiAssistantReportDO::getReporterId, reporterIds) + .eqIfPresent(AiAssistantReportDO::getModuleCode, moduleCode) + .eq(AiAssistantReportDO::getReportTime, reportDate) + .orderByDesc(AiAssistantReportDO::getReportTime) + .orderByDesc(AiAssistantReportDO::getCreateTime)); + } + /** * 当前租户下某模块(页面)全部店长的历史汇报,用于 Dify 知识库聚合 */ diff --git a/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportDetailService.java b/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportDetailService.java index f31d62c..469f392 100644 --- a/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportDetailService.java +++ b/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportDetailService.java @@ -19,6 +19,11 @@ public interface AiAssistantReportDetailService { */ List listByReportId(@NotNull Long reportId, @NotNull Long loginUserId); + /** + * 按主表 ID 查询详表(管理端:仅校验主表存在;租户由框架隔离;需接口权限) + */ + List listByReportIdForManage(@NotNull Long reportId); + /** * 批量保存(删除该主表下旧明细后插入新行) */ diff --git a/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportDetailServiceImpl.java b/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportDetailServiceImpl.java index 5fce982..44b5eb4 100644 --- a/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportDetailServiceImpl.java +++ b/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportDetailServiceImpl.java @@ -46,6 +46,16 @@ public class AiAssistantReportDetailServiceImpl implements AiAssistantReportDeta return BeanUtils.toBean(list, AiAssistantReportDetailRespVO.class); } + @Override + public List listByReportIdForManage(Long reportId) { + AiAssistantReportDO report = aiAssistantReportMapper.selectById(reportId); + if (report == null) { + throw exception(BAD_REQUEST); + } + List list = aiAssistantReportDetailMapper.selectListByReportId(reportId); + return BeanUtils.toBean(list, AiAssistantReportDetailRespVO.class); + } + @Override public void saveBatch(AiAssistantReportDetailBatchSaveReqVO reqVO, Long loginUserId) { Long reportId = reqVO.getReportId(); diff --git a/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportService.java b/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportService.java index f8783ba..117bc21 100644 --- a/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportService.java +++ b/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportService.java @@ -81,4 +81,14 @@ public interface AiAssistantReportService { * @param reporterId 当前登录用户 ID,须与记录一致 */ void deleteMyReportToday(Long id, Long reporterId); + + /** + * 按部门 + 统计日查询该部门下全员汇报(单次 DB 查询,避免前端按人 N 次请求) + * + * @param deptId 部门编号(与系统用户 dept_id 一致,不含子部门) + * @param reportDate 报告日期 + * @param moduleCode 模块编码(可选) + * @return 汇报列表 + */ + List listDeptDailyReports(Long deptId, LocalDate reportDate, String moduleCode); } diff --git a/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportServiceImpl.java b/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportServiceImpl.java index 1291a58..350befc 100644 --- a/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportServiceImpl.java +++ b/yudao-module-ydoyun/src/main/java/cn/iocoder/yudao/module/ydoyun/service/aiassistantreport/AiAssistantReportServiceImpl.java @@ -1,7 +1,11 @@ package cn.iocoder.yudao.module.ydoyun.service.aiassistantreport; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.service.dept.DeptService; +import cn.iocoder.yudao.module.system.service.user.AdminUserService; import cn.iocoder.yudao.module.ydoyun.controller.admin.aiassistantreport.vo.AiAssistantReportPageReqVO; import cn.iocoder.yudao.module.ydoyun.controller.admin.aiassistantreport.vo.AiAssistantReportRespVO; import cn.iocoder.yudao.module.ydoyun.controller.admin.aiassistantreport.vo.AiAssistantReportSaveReqVO; @@ -13,8 +17,12 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDate; +import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.FORBIDDEN; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -32,6 +40,10 @@ public class AiAssistantReportServiceImpl implements AiAssistantReportService { private AiAssistantReportMapper aiAssistantReportMapper; @Resource private AiAssistantReportDetailService aiAssistantReportDetailService; + @Resource + private AdminUserService adminUserService; + @Resource + private DeptService deptService; @Override public Long saveReport(AiAssistantReportSaveReqVO saveReqVO) { @@ -95,6 +107,21 @@ public class AiAssistantReportServiceImpl implements AiAssistantReportService { return aiAssistantReportMapper.selectReportCountByDate(reporterId, moduleCode, startDate, endDate); } + @Override + public List listDeptDailyReports(Long deptId, LocalDate reportDate, String moduleCode) { + // 含本部门及所有下级部门用户(与左侧部门树父节点选中场景一致;仅 dept_id=deptId 会漏掉子部门用户) + Set deptScope = new HashSet<>(deptService.getChildDeptIdListFromCache(deptId)); + deptScope.add(deptId); + List users = adminUserService.getUserListByDeptIds(deptScope); + if (CollUtil.isEmpty(users)) { + return Collections.emptyList(); + } + List reporterIds = convertList(users, AdminUserDO::getId); + List list = aiAssistantReportMapper.selectListByReporterIdsAndReportDate( + reporterIds, moduleCode, reportDate); + return BeanUtils.toBean(list, AiAssistantReportRespVO.class); + } + @Override public void deleteMyReportToday(Long id, Long reporterId) { if (id == null || reporterId == null) {