修改 我的日志查询方法

This commit is contained in:
furongxin 2024-09-23 00:29:35 +08:00
parent 822da5435d
commit f652b25812
3 changed files with 50 additions and 98 deletions

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.dal.mysql.worklog;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
import cn.iocoder.yudao.framework.datapermission.core.aop.DataPermissionContextHolder;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
@ -48,15 +49,18 @@ public interface LogInstanceMapper extends BaseMapperX<LogInstanceDO> {
default IPage<LogInstanceRespVO> selectPageResult(@Param("page") IPage<LogInstanceRespVO> page,
@Param("reqVO") LogInstancePageReqVO reqVO,
@Param("userId") Long userId,
@Param("pagingType") Integer pagingType,
@Param("userIds") List<Long> userIds) {
MPJLambdaWrapperX<LogInstanceDO> queryWrapper = new MPJLambdaWrapperX<>();
queryWrapper.selectAll(LogInstanceDO.class);
queryWrapper.selectAs("e.read_status", LogInstanceRespVO::getReadStatus);
queryWrapper.selectAs("COALESCE(c.readCount, 0)", LogInstanceRespVO::getReadCount);
queryWrapper.selectAs("COALESCE(d.unreadCount, 0)", LogInstanceRespVO::getUnreadCount);
queryWrapper.selectAs("COALESCE(b.comment, 0)", LogInstanceRespVO::getComment);
queryWrapper.innerJoin(UserPostDO.class, "userPost", UserPostDO::getUserId, LogInstanceDO::getStartUserId);
queryWrapper.innerJoin(DeptDO.class, "dept", DeptDO::getId, LogInstanceDO::getDeptId);
queryWrapper.innerJoin(PostDO.class, "post", PostDO::getId, UserPostDO::getPostId);
queryWrapper.leftJoin(LogReadDo.class, "e", on -> on
.eq(LogReadDo::getLogInstanceId, LogInstanceDO::getId)
.eq(LogReadDo::getReadUserId, userId)
@ -64,12 +68,12 @@ public interface LogInstanceMapper extends BaseMapperX<LogInstanceDO> {
queryWrapper.leftJoin("(SELECT log_instance_id, COUNT(log_instance_id) AS readCount FROM work_log_read where read_status = 1 GROUP BY log_instance_id) c on t.id = c.log_instance_id");
queryWrapper.leftJoin("(SELECT log_instance_id, COUNT(log_instance_id) AS unReadCount FROM work_log_read where read_status = 0 GROUP BY log_instance_id) AS d ON t.id = d.log_instance_id");
queryWrapper.leftJoin("(SELECT work_log_id, COUNT(work_log_id) AS comment FROM work_log_comment GROUP BY work_log_id) AS b ON t.id = b.work_log_id");
// queryWrapper.eq(pagingType == 1, LogInstanceDO::getStartUserId, userId);
queryWrapper.eqIfPresent(LogInstanceDO::getDeptId, reqVO.getDeptId());
queryWrapper.eqIfPresent(LogInstanceDO::getFormId, reqVO.getFormId());
queryWrapper.eqIfPresent(LogInstanceDO::getStartUserId, reqVO.getStartUserId());
queryWrapper.betweenIfPresent(LogInstanceDO::getTime, reqVO.getCreateTime());
queryWrapper.inIfPresent(LogInstanceDO::getStartUserId, userIds);
queryWrapper.ne(LogInstanceDO::getStartUserId, userId);
if (reqVO.getReadStatus() != null) {
queryWrapper.eq("e.read_status", reqVO.getReadStatus());
@ -82,40 +86,15 @@ public interface LogInstanceMapper extends BaseMapperX<LogInstanceDO> {
}
queryWrapper.groupBy(LogInstanceDO::getId);
queryWrapper.orderByDesc(LogInstanceDO::getTime);
if (pagingType == 0) {
queryWrapper.innerJoin(UserPostDO.class, "userPost", UserPostDO::getUserId, LogInstanceDO::getStartUserId);
queryWrapper.innerJoin(DeptDO.class, "dept", DeptDO::getId, LogInstanceDO::getDeptId);
queryWrapper.innerJoin(PostDO.class, "post", PostDO::getId, UserPostDO::getPostId);
queryWrapper.ne(LogInstanceDO::getStartUserId, userId);
queryWrapper.orderByAsc(PostDO::getSort);
}
queryWrapper.orderByDesc(LogInstanceDO::getCreateTime);
return selectJoinPage(page, LogInstanceRespVO.class, queryWrapper);
}
default PageResult<LogInstanceDO> selectPage(LogInstancePageReqVO reqVO, Long userId,
Integer pagingType, List<Long> userIds) {
LambdaQueryWrapperX<LogInstanceDO> queryWrapper = new LambdaQueryWrapperX<LogInstanceDO>()
.eqIfPresent(LogInstanceDO::getFormId, reqVO.getFormId())
.eqIfPresent(LogInstanceDO::getDeptId, reqVO.getDeptId())
.eqIfPresent(LogInstanceDO::getStartUserId, reqVO.getStartUserId())
.betweenIfPresent(LogInstanceDO::getTime, reqVO.getCreateTime());
if (pagingType == 0) {
queryWrapper.ne(LogInstanceDO::getStartUserId, userId);
} else if (pagingType == 1) {
queryWrapper.eq(LogInstanceDO::getStartUserId, userId);
}
if (reqVO.getIsBoss() != null && reqVO.getIsProduce() == null) {
queryWrapper.inIfPresent(LogInstanceDO::getStartUserId, userIds);
}
return selectPage(reqVO, queryWrapper.orderByDesc(LogInstanceDO::getTime));
}
IPage<LogInstanceRespVO> selectMyPageResult(@Param("page") IPage<LogInstanceRespVO> page,
@Param("reqVO") LogInstancePageReqVO reqVO,
@Param("userId") Long userId);
@DataPermission(enable = false)
List<LogReadUserRespDTO> selectRaedUser(@Param("userId")Long userId, @Param("deptId")Long deptId);

View File

@ -245,7 +245,13 @@ public class LogInstanceServiceImpl implements LogInstanceService {
}
Page<LogInstanceRespVO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
IPage<LogInstanceRespVO> pageList = logInstanceMapper.selectPageResult(page, pageReqVO, getLoginUserId(), pagingType, leaderUserIds);
IPage<LogInstanceRespVO> pageList = new Page<>();
if (pagingType == 0) {
pageList = logInstanceMapper.selectPageResult(page, pageReqVO, getLoginUserId(), leaderUserIds);
}else if (pagingType == 1) {
pageList = logInstanceMapper.selectMyPageResult(page, pageReqVO, getLoginUserId());
}
List<LogInstanceRespVO> records = pageList.getRecords();
if (!records.isEmpty()) {

View File

@ -153,70 +153,37 @@
limit 1
</select>
<!-- <select id="selectPageResult" resultType="cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceRespVO">-->
<!-- SELECT-->
<!-- a.*,-->
<!-- e.read_status as readStatus,-->
<!-- COALESCE(c.readCount, 0) as readCount,-->
<!-- COALESCE(d.unreadCount, 0) as unReadCount,-->
<!-- COALESCE(b.comment, 0) as comment-->
<!-- FROM-->
<!-- system_user_post userPost,-->
<!-- system_dept dept,-->
<!-- system_post post,-->
<!-- work_log_instance_ext as a-->
<!-- LEFT JOIN work_log_read as e ON a.id = e.log_instance_id and e.read_user_id = #{userId}-->
<!-- LEFT JOIN (SELECT log_instance_id, COUNT(log_instance_id) AS readCount FROM work_log_read where read_status = 1 AND deleted = 0 GROUP BY log_instance_id ) AS c ON a.id = c.log_instance_id-->
<!-- LEFT JOIN (SELECT log_instance_id, COUNT(log_instance_id) AS unReadCount FROM work_log_read where read_status = 0 AND deleted = 0 GROUP BY log_instance_id ) AS d ON a.id = d.log_instance_id-->
<!-- LEFT JOIN (SELECT work_log_id, COUNT(work_log_id) AS comment FROM work_log_comment where deleted = 0 GROUP BY work_log_id) AS b ON a.id = b.work_log_id-->
<!-- <where>-->
<!-- a.deleted = 0-->
<!-- AND a.start_user_id = userPost.user_id-->
<!-- AND userPost.post_id = post.id-->
<!-- AND a.dept_id = dept.id-->
<!-- <if test="reqVO.isProduce == 1">-->
<!-- AND dept.flag LIKE '%166%'-->
<!-- </if>-->
<!-- <if test="reqVO.isProduce == 2">-->
<!-- AND dept.flag NOT LIKE '%166%'-->
<!-- </if>-->
<!-- <if test="reqVO.formId != null">-->
<!-- and a.form_id = #{reqVO.formId}-->
<!-- </if>-->
<!-- <if test="reqVO.deptId != null">-->
<!-- and a.dept_id = #{reqVO.deptId}-->
<!-- </if>-->
<!-- <if test="reqVO.startUserId != null">-->
<!-- and a.start_user_id = #{reqVO.startUserId}-->
<!-- </if>-->
<!-- <if test="reqVO.createTime != null and reqVO.createTime.length > 0">-->
<!-- <if test="reqVO.createTime[0] != null">-->
<!-- and a.time &gt;= #{reqVO.createTime[0]}-->
<!-- </if>-->
<!-- <if test="reqVO.createTime[1] != null">-->
<!-- and a.time &lt;= #{reqVO.createTime[1]}-->
<!-- </if>-->
<!-- </if>-->
<!-- <if test="reqVO.readStatus != null">-->
<!-- and e.read_status = #{reqVO.readStatus}-->
<!-- </if>-->
<!-- <if test="pagingType == 0">-->
<!-- and a.start_user_id != #{userId}-->
<!-- </if>-->
<!-- <if test="pagingType == 1">-->
<!-- and a.start_user_id = #{userId}-->
<!-- </if>-->
<!-- <if test="reqVO.isBoss != null and reqVO.isProduce == null">-->
<!-- and a.start_user_id in-->
<!-- <foreach collection="userIds" item="userId" open="(" close=")" separator=",">-->
<!-- #{userId}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- </where>-->
<!-- GROUP BY a.id-->
<!-- ORDER BY-->
<!-- a.time DESC,-->
<!-- post.sort,-->
<!-- a.create_time DESC-->
<!-- </select>-->
<select id="selectMyPageResult" resultType="cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceRespVO">
SELECT
a.*,
e.read_status as readStatus,
COALESCE(c.readCount, 0) as readCount,
COALESCE(d.unreadCount, 0) as unReadCount,
COALESCE(b.comment, 0) as comment
FROM
work_log_instance_ext as a
LEFT JOIN work_log_read as e ON a.id = e.log_instance_id and e.read_user_id = #{userId}
LEFT JOIN (SELECT log_instance_id, COUNT(log_instance_id) AS readCount FROM work_log_read where read_status = 1 AND deleted = 0 GROUP BY log_instance_id ) AS c ON a.id = c.log_instance_id
LEFT JOIN (SELECT log_instance_id, COUNT(log_instance_id) AS unReadCount FROM work_log_read where read_status = 0 AND deleted = 0 GROUP BY log_instance_id ) AS d ON a.id = d.log_instance_id
LEFT JOIN (SELECT work_log_id, COUNT(work_log_id) AS comment FROM work_log_comment where deleted = 0 GROUP BY work_log_id) AS b ON a.id = b.work_log_id
<where>
a.deleted = 0
and a.start_user_id = #{userId}
<if test="reqVO.formId != null">
and a.form_id = #{reqVO.formId}
</if>
<if test="reqVO.createTime != null and reqVO.createTime.length > 0">
<if test="reqVO.createTime[0] != null">
and a.time &gt;= #{reqVO.createTime[0]}
</if>
<if test="reqVO.createTime[1] != null">
and a.time &lt;= #{reqVO.createTime[1]}
</if>
</if>
</where>
GROUP BY a.id
ORDER BY
a.time DESC,
a.create_time DESC
</select>
</mapper>