修改 我的日志查询方法
This commit is contained in:
parent
822da5435d
commit
f652b25812
@ -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.PageParam;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
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.mapper.BaseMapperX;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
|
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,
|
default IPage<LogInstanceRespVO> selectPageResult(@Param("page") IPage<LogInstanceRespVO> page,
|
||||||
@Param("reqVO") LogInstancePageReqVO reqVO,
|
@Param("reqVO") LogInstancePageReqVO reqVO,
|
||||||
@Param("userId") Long userId,
|
@Param("userId") Long userId,
|
||||||
@Param("pagingType") Integer pagingType,
|
|
||||||
@Param("userIds") List<Long> userIds) {
|
@Param("userIds") List<Long> userIds) {
|
||||||
|
|
||||||
|
|
||||||
MPJLambdaWrapperX<LogInstanceDO> queryWrapper = new MPJLambdaWrapperX<>();
|
MPJLambdaWrapperX<LogInstanceDO> queryWrapper = new MPJLambdaWrapperX<>();
|
||||||
queryWrapper.selectAll(LogInstanceDO.class);
|
queryWrapper.selectAll(LogInstanceDO.class);
|
||||||
queryWrapper.selectAs("e.read_status", LogInstanceRespVO::getReadStatus);
|
queryWrapper.selectAs("e.read_status", LogInstanceRespVO::getReadStatus);
|
||||||
queryWrapper.selectAs("COALESCE(c.readCount, 0)", LogInstanceRespVO::getReadCount);
|
queryWrapper.selectAs("COALESCE(c.readCount, 0)", LogInstanceRespVO::getReadCount);
|
||||||
queryWrapper.selectAs("COALESCE(d.unreadCount, 0)", LogInstanceRespVO::getUnreadCount);
|
queryWrapper.selectAs("COALESCE(d.unreadCount, 0)", LogInstanceRespVO::getUnreadCount);
|
||||||
queryWrapper.selectAs("COALESCE(b.comment, 0)", LogInstanceRespVO::getComment);
|
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
|
queryWrapper.leftJoin(LogReadDo.class, "e", on -> on
|
||||||
.eq(LogReadDo::getLogInstanceId, LogInstanceDO::getId)
|
.eq(LogReadDo::getLogInstanceId, LogInstanceDO::getId)
|
||||||
.eq(LogReadDo::getReadUserId, userId)
|
.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 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 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.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::getDeptId, reqVO.getDeptId());
|
||||||
queryWrapper.eqIfPresent(LogInstanceDO::getFormId, reqVO.getFormId());
|
queryWrapper.eqIfPresent(LogInstanceDO::getFormId, reqVO.getFormId());
|
||||||
queryWrapper.eqIfPresent(LogInstanceDO::getStartUserId, reqVO.getStartUserId());
|
queryWrapper.eqIfPresent(LogInstanceDO::getStartUserId, reqVO.getStartUserId());
|
||||||
queryWrapper.betweenIfPresent(LogInstanceDO::getTime, reqVO.getCreateTime());
|
queryWrapper.betweenIfPresent(LogInstanceDO::getTime, reqVO.getCreateTime());
|
||||||
queryWrapper.inIfPresent(LogInstanceDO::getStartUserId, userIds);
|
queryWrapper.inIfPresent(LogInstanceDO::getStartUserId, userIds);
|
||||||
|
queryWrapper.ne(LogInstanceDO::getStartUserId, userId);
|
||||||
|
|
||||||
if (reqVO.getReadStatus() != null) {
|
if (reqVO.getReadStatus() != null) {
|
||||||
queryWrapper.eq("e.read_status", reqVO.getReadStatus());
|
queryWrapper.eq("e.read_status", reqVO.getReadStatus());
|
||||||
@ -82,40 +86,15 @@ public interface LogInstanceMapper extends BaseMapperX<LogInstanceDO> {
|
|||||||
}
|
}
|
||||||
queryWrapper.groupBy(LogInstanceDO::getId);
|
queryWrapper.groupBy(LogInstanceDO::getId);
|
||||||
queryWrapper.orderByDesc(LogInstanceDO::getTime);
|
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.orderByAsc(PostDO::getSort);
|
||||||
}
|
|
||||||
queryWrapper.orderByDesc(LogInstanceDO::getCreateTime);
|
queryWrapper.orderByDesc(LogInstanceDO::getCreateTime);
|
||||||
|
|
||||||
return selectJoinPage(page, LogInstanceRespVO.class, queryWrapper);
|
return selectJoinPage(page, LogInstanceRespVO.class, queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
default PageResult<LogInstanceDO> selectPage(LogInstancePageReqVO reqVO, Long userId,
|
IPage<LogInstanceRespVO> selectMyPageResult(@Param("page") IPage<LogInstanceRespVO> page,
|
||||||
Integer pagingType, List<Long> userIds) {
|
@Param("reqVO") LogInstancePageReqVO reqVO,
|
||||||
|
@Param("userId") Long userId);
|
||||||
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));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@DataPermission(enable = false)
|
@DataPermission(enable = false)
|
||||||
List<LogReadUserRespDTO> selectRaedUser(@Param("userId")Long userId, @Param("deptId")Long deptId);
|
List<LogReadUserRespDTO> selectRaedUser(@Param("userId")Long userId, @Param("deptId")Long deptId);
|
||||||
|
@ -245,7 +245,13 @@ public class LogInstanceServiceImpl implements LogInstanceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Page<LogInstanceRespVO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
|
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();
|
List<LogInstanceRespVO> records = pageList.getRecords();
|
||||||
if (!records.isEmpty()) {
|
if (!records.isEmpty()) {
|
||||||
|
|
||||||
|
@ -153,70 +153,37 @@
|
|||||||
limit 1
|
limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- <select id="selectPageResult" resultType="cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceRespVO">-->
|
<select id="selectMyPageResult" resultType="cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceRespVO">
|
||||||
<!-- SELECT-->
|
SELECT
|
||||||
<!-- a.*,-->
|
a.*,
|
||||||
<!-- e.read_status as readStatus,-->
|
e.read_status as readStatus,
|
||||||
<!-- COALESCE(c.readCount, 0) as readCount,-->
|
COALESCE(c.readCount, 0) as readCount,
|
||||||
<!-- COALESCE(d.unreadCount, 0) as unReadCount,-->
|
COALESCE(d.unreadCount, 0) as unReadCount,
|
||||||
<!-- COALESCE(b.comment, 0) as comment-->
|
COALESCE(b.comment, 0) as comment
|
||||||
<!-- FROM-->
|
FROM
|
||||||
<!-- system_user_post userPost,-->
|
work_log_instance_ext as a
|
||||||
<!-- system_dept dept,-->
|
LEFT JOIN work_log_read as e ON a.id = e.log_instance_id and e.read_user_id = #{userId}
|
||||||
<!-- system_post post,-->
|
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
|
||||||
<!-- work_log_instance_ext as a-->
|
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 work_log_read as e ON a.id = e.log_instance_id and e.read_user_id = #{userId}-->
|
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
|
||||||
<!-- 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-->
|
<where>
|
||||||
<!-- 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-->
|
a.deleted = 0
|
||||||
<!-- 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-->
|
and a.start_user_id = #{userId}
|
||||||
<!-- <where>-->
|
<if test="reqVO.formId != null">
|
||||||
<!-- a.deleted = 0-->
|
and a.form_id = #{reqVO.formId}
|
||||||
<!-- AND a.start_user_id = userPost.user_id-->
|
</if>
|
||||||
<!-- AND userPost.post_id = post.id-->
|
<if test="reqVO.createTime != null and reqVO.createTime.length > 0">
|
||||||
<!-- AND a.dept_id = dept.id-->
|
<if test="reqVO.createTime[0] != null">
|
||||||
<!-- <if test="reqVO.isProduce == 1">-->
|
and a.time >= #{reqVO.createTime[0]}
|
||||||
<!-- AND dept.flag LIKE '%166%'-->
|
</if>
|
||||||
<!-- </if>-->
|
<if test="reqVO.createTime[1] != null">
|
||||||
<!-- <if test="reqVO.isProduce == 2">-->
|
and a.time <= #{reqVO.createTime[1]}
|
||||||
<!-- AND dept.flag NOT LIKE '%166%'-->
|
</if>
|
||||||
<!-- </if>-->
|
</if>
|
||||||
<!-- <if test="reqVO.formId != null">-->
|
</where>
|
||||||
<!-- and a.form_id = #{reqVO.formId}-->
|
GROUP BY a.id
|
||||||
<!-- </if>-->
|
ORDER BY
|
||||||
<!-- <if test="reqVO.deptId != null">-->
|
a.time DESC,
|
||||||
<!-- and a.dept_id = #{reqVO.deptId}-->
|
a.create_time DESC
|
||||||
<!-- </if>-->
|
</select>
|
||||||
<!-- <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 >= #{reqVO.createTime[0]}-->
|
|
||||||
<!-- </if>-->
|
|
||||||
<!-- <if test="reqVO.createTime[1] != null">-->
|
|
||||||
<!-- and a.time <= #{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>-->
|
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue
Block a user