工作日志分页查询逻辑重构及属性扩展
重构工作日志(LogInstance)的分页查询方法,以提高查询效率和可读性。在LogInstanceDO中添加新属性readStatus、comment、readCount和unreadCount,以支持额外的业务需求。调整LogInstanceMapper中的SQL映射,以适配这些新增的属性。在LogInstanceServiceImpl中修改分页查询逻辑,使用新增的属性,并优化查询参数的传递。
This commit is contained in:
parent
3c38492f8e
commit
c459f0d0d5
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -75,4 +76,28 @@ public class LogInstanceDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
private List<UploadUserFile> fileItems ;
|
private List<UploadUserFile> fileItems ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阅读状态, 0:未读、1:已读
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String readStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论数
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Integer comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已读人数
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Integer readCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未读人数
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Integer unreadCount;
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,12 @@ 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.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.QueryWrapperX;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstancePageReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstancePageReqVO;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceRespVO;
|
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceRespVO;
|
||||||
import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogInstanceDO;
|
import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogInstanceDO;
|
||||||
import cn.iocoder.yudao.module.system.service.worklog.dto.LogReadUserRespDTO;
|
import cn.iocoder.yudao.module.system.service.worklog.dto.LogReadUserRespDTO;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
@ -41,11 +43,32 @@ public interface LogInstanceMapper extends BaseMapperX<LogInstanceDO> {
|
|||||||
.in(LogInstanceDO::getTime, dateList));
|
.in(LogInstanceDO::getTime, dateList));
|
||||||
}
|
}
|
||||||
|
|
||||||
IPage<LogInstanceRespVO> selectPageResult(@Param("page") Page<LogInstanceRespVO> page,
|
List<LogInstanceRespVO> selectPageResult( @Param("reqVO") LogInstancePageReqVO reqVO,
|
||||||
@Param("reqVO") LogInstancePageReqVO reqVO,
|
|
||||||
@Param("userId") Long userId,
|
@Param("userId") Long userId,
|
||||||
@Param("pagingType") Integer pagingType,
|
@Param("ids") List<Long> ids);
|
||||||
@Param("userIds") List<Long> userIds);
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@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);
|
||||||
|
@ -244,10 +244,8 @@ public class LogInstanceServiceImpl implements LogInstanceService {
|
|||||||
leaderUserIds = adminUserService.getUserByBoss();
|
leaderUserIds = adminUserService.getUserByBoss();
|
||||||
}
|
}
|
||||||
|
|
||||||
Page<LogInstanceRespVO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
|
PageResult<LogInstanceDO> pageList = logInstanceMapper.selectPage(pageReqVO, getLoginUserId(), pagingType, leaderUserIds);
|
||||||
IPage<LogInstanceRespVO> pageList = logInstanceMapper.selectPageResult(page, pageReqVO, getLoginUserId(), pagingType, leaderUserIds);
|
List<LogInstanceRespVO> records = logInstanceMapper.selectPageResult(pageReqVO, getLoginUserId(), convertList(pageList.getList(), LogInstanceDO::getId));
|
||||||
|
|
||||||
List<LogInstanceRespVO> records = pageList.getRecords();
|
|
||||||
if (!records.isEmpty()) {
|
if (!records.isEmpty()) {
|
||||||
|
|
||||||
//模版ids过滤
|
//模版ids过滤
|
||||||
@ -307,7 +305,10 @@ public class LogInstanceServiceImpl implements LogInstanceService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return pageList;
|
IPage<LogInstanceRespVO> pageListVO = new Page<>();
|
||||||
|
pageListVO.setRecords(records);
|
||||||
|
pageListVO.setTotal(pageList.getTotal());
|
||||||
|
return pageListVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -112,6 +112,15 @@
|
|||||||
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 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>
|
<where>
|
||||||
a.deleted = 0
|
a.deleted = 0
|
||||||
|
<if test="ids != null and ids.size > 0">
|
||||||
|
and a.id in
|
||||||
|
<foreach collection="ids" item="ids" open="(" close=")" separator=",">
|
||||||
|
#{ids}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="ids == null or ids.size == 0">
|
||||||
|
and a.id = null
|
||||||
|
</if>
|
||||||
AND a.start_user_id = userPost.user_id
|
AND a.start_user_id = userPost.user_id
|
||||||
AND userPost.post_id = post.id
|
AND userPost.post_id = post.id
|
||||||
AND a.dept_id = dept.id
|
AND a.dept_id = dept.id
|
||||||
@ -121,38 +130,9 @@
|
|||||||
<if test="reqVO.isProduce == 2">
|
<if test="reqVO.isProduce == 2">
|
||||||
AND dept.flag NOT LIKE '%166%'
|
AND dept.flag NOT LIKE '%166%'
|
||||||
</if>
|
</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 >= #{reqVO.createTime[0]}
|
|
||||||
</if>
|
|
||||||
<if test="reqVO.createTime[1] != null">
|
|
||||||
and a.time <= #{reqVO.createTime[1]}
|
|
||||||
</if>
|
|
||||||
</if>
|
|
||||||
<if test="reqVO.readStatus != null">
|
<if test="reqVO.readStatus != null">
|
||||||
and e.read_status = #{reqVO.readStatus}
|
and e.read_status = #{reqVO.readStatus}
|
||||||
</if>
|
</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>
|
</where>
|
||||||
GROUP BY a.id
|
GROUP BY a.id
|
||||||
ORDER BY
|
ORDER BY
|
||||||
|
Loading…
Reference in New Issue
Block a user