工作日志功能优化:实现分页查询和个人分页查询
本次提交实现了工作日志模块的分页查询功能,允许用户高效地查询与其相关的上一个或下一个日志实例。通过新增`getMyNextOrUp`方法及相应的SQL映射,支持基于用户个性化需求的日志实例检索。同时,对`getNextOrUp`方法进行了默认实现调整,以支持更灵活的日志数据检索需求。这些改进提升了用户在工作日志模块的交互体验,并增强了系统的整体性能。
This commit is contained in:
parent
9c30d82029
commit
e362850576
@ -15,6 +15,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogInstanceDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogReadDo;
|
||||
import cn.iocoder.yudao.module.system.service.worklog.dto.LogReadUserRespDTO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@ -107,9 +108,76 @@ public interface LogInstanceMapper extends BaseMapperX<LogInstanceDO> {
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
LogInstanceRespVO getNextOrUp(@Param("reqVO") LogInstancePageReqVO dto,
|
||||
LogInstanceRespVO getMyNextOrUp(@Param("reqVO") LogInstancePageReqVO dto,
|
||||
@Param("id") Long id, @Param("userId") Long userId,
|
||||
@Param("type") Integer type,
|
||||
@Param("pagingType") Integer pagingType,
|
||||
@Param("userIds") List<Long> userIds);
|
||||
|
||||
default IPage<LogInstanceRespVO> getNextOrUp(@Param("reqVO") LogInstancePageReqVO reqVO,
|
||||
@Param("id") Long id,
|
||||
@Param("userId") Long userId,
|
||||
@Param("type") Integer type,
|
||||
@Param("userIds") List<Long> userIds){
|
||||
|
||||
String sql = "";
|
||||
|
||||
MPJLambdaWrapperX<LogInstanceDO> queryWrapper = new MPJLambdaWrapperX<>();
|
||||
queryWrapper.selectAs(LogInstanceDO::getId, LogInstanceRespVO::getId);
|
||||
queryWrapper.selectAs(LogInstanceDO::getName, LogInstanceRespVO::getName);
|
||||
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);
|
||||
if (type == 1) {
|
||||
sql = " (t.time > tt.time) or\n" +
|
||||
" (t.time = tt.time and tt.sort > post.sort) or\n" +
|
||||
" (t.time = tt.time and tt.sort = post.sort and tt.create_time < t.create_time)";
|
||||
|
||||
queryWrapper.orderByAsc(LogInstanceDO::getTime);
|
||||
queryWrapper.orderByDesc(PostDO::getSort);
|
||||
queryWrapper.orderByAsc(LogInstanceDO::getCreateTime);
|
||||
}
|
||||
if (type == 0) {
|
||||
sql = " (t.time < tt.time) or\n" +
|
||||
" (t.time = tt.time and tt.sort < post.sort) or\n" +
|
||||
" (t.time = tt.time and tt.sort = post.sort and tt.create_time > t.create_time)";
|
||||
|
||||
queryWrapper.orderByDesc(LogInstanceDO::getTime);
|
||||
queryWrapper.orderByAsc(PostDO::getSort);
|
||||
queryWrapper.orderByDesc(LogInstanceDO::getCreateTime);
|
||||
}
|
||||
queryWrapper.innerJoin("(\n" +
|
||||
"SELECT \n" +
|
||||
" a.id,\n" +
|
||||
" a.name,\n" +
|
||||
" a.time,\n" +
|
||||
" d.sort,\n" +
|
||||
" a.create_time\n" +
|
||||
"FROM \n" +
|
||||
" work_log_instance_ext a\n" +
|
||||
" INNER JOIN system_user_post b ON (b.user_id = a.start_user_id) \n" +
|
||||
" INNER JOIN system_dept c ON (c.id = a.dept_id) \n" +
|
||||
" INNER JOIN system_post d ON (d.id = b.post_id) \n" +
|
||||
"WHERE \n" +
|
||||
" a.id = " + id + "\n" +
|
||||
" AND a.deleted = 0 \n" +
|
||||
" AND b.deleted = 0 \n" +
|
||||
" AND c.deleted = 0 \n" +
|
||||
" AND d.deleted = 0\n" +
|
||||
") tt on \n" + sql);
|
||||
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.getIsProduce() != null && reqVO.getIsProduce() == 1) {
|
||||
queryWrapper.like(DeptDO::getFlag, "166");
|
||||
}
|
||||
if (reqVO.getIsProduce() != null && reqVO.getIsProduce() == 2) {
|
||||
queryWrapper.notLike(DeptDO::getFlag, "166");
|
||||
}
|
||||
|
||||
return selectJoinPage(new Page<>(1, 1), LogInstanceRespVO.class, queryWrapper);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.service.worklog;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
@ -256,14 +257,14 @@ public class LogInstanceServiceImpl implements LogInstanceService {
|
||||
if (!records.isEmpty()) {
|
||||
|
||||
//模版ids过滤
|
||||
List<Long> workFormIds = records.stream().map(LogInstanceRespVO::getFormId).collect(Collectors.toList());
|
||||
Set<Long> workFormIds = records.stream().map(LogInstanceRespVO::getFormId).collect(Collectors.toSet());
|
||||
|
||||
// 查询模版列表
|
||||
List<LogFormDO> formList = logFormService.getFormList(workFormIds);
|
||||
Map<Long, LogFormDO> formMap = formList.stream().collect(Collectors.toMap(LogFormDO::getId, item -> item));
|
||||
|
||||
//查询用户信息列表
|
||||
List<Long> userIds = records.stream().map(LogInstanceRespVO::getStartUserId).collect(Collectors.toList());
|
||||
Set<Long> userIds = records.stream().map(LogInstanceRespVO::getStartUserId).collect(Collectors.toSet());
|
||||
Map<Long, AdminUserDO> userMap = adminUserService.getUserMap(userIds);
|
||||
|
||||
//遍历
|
||||
@ -400,10 +401,26 @@ public class LogInstanceServiceImpl implements LogInstanceService {
|
||||
//以及岗位为总监或副总监的用户
|
||||
leaderUserIds = adminUserService.getUserByBoss();
|
||||
}
|
||||
LogInstanceRespVO upLogInstance = logInstanceMapper.getNextOrUp(dto, id, getLoginUserId(), 1, pagingType, leaderUserIds);
|
||||
LogInstanceRespVO nextLogInstance = logInstanceMapper.getNextOrUp(dto, id, getLoginUserId(), 0, pagingType, leaderUserIds);
|
||||
vo.setUpLogInstance(upLogInstance);
|
||||
vo.setNextLogInstance(nextLogInstance);
|
||||
if (pagingType == 0) {
|
||||
IPage<LogInstanceRespVO> upLogInstances = logInstanceMapper.getNextOrUp(dto, id, getLoginUserId(), 1, leaderUserIds);
|
||||
IPage<LogInstanceRespVO> nextLogInstances = logInstanceMapper.getNextOrUp(dto, id, getLoginUserId(), 0, leaderUserIds);
|
||||
|
||||
if (CollectionUtil.isNotEmpty(upLogInstances.getRecords())) {
|
||||
vo.setUpLogInstance(upLogInstances.getRecords().get(0));
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(nextLogInstances.getRecords())) {
|
||||
vo.setNextLogInstance(nextLogInstances.getRecords().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
if (pagingType == 1) {
|
||||
LogInstanceRespVO upLogInstance = logInstanceMapper.getMyNextOrUp(dto, id, getLoginUserId(), 1, leaderUserIds);
|
||||
LogInstanceRespVO nextLogInstance = logInstanceMapper.getMyNextOrUp(dto, id, getLoginUserId(), 0, leaderUserIds);
|
||||
|
||||
vo.setUpLogInstance(upLogInstance);
|
||||
vo.setNextLogInstance(nextLogInstance);
|
||||
}
|
||||
|
||||
//获取日志详情
|
||||
return vo;
|
||||
}
|
||||
|
@ -94,61 +94,66 @@
|
||||
or result.data_scope = 1 )
|
||||
</select>
|
||||
|
||||
<select id="getNextOrUp"
|
||||
<select id="getMyNextOrUp"
|
||||
resultType="cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceRespVO">
|
||||
SELECT
|
||||
a.id,
|
||||
a.name
|
||||
t.id,
|
||||
t.name
|
||||
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}
|
||||
work_log_instance_ext AS t
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
a.time,
|
||||
a.create_time
|
||||
FROM
|
||||
work_log_instance_ext a
|
||||
WHERE
|
||||
a.id = #{id}
|
||||
) tt ON
|
||||
<if test="type == 1">
|
||||
( t.time > tt.time )
|
||||
OR ( t.time = tt.time AND tt.create_time < t.create_time )
|
||||
</if>
|
||||
<if test="type == 0">
|
||||
( t.time < tt.time )
|
||||
OR ( t.time = tt.time AND tt.create_time > t.create_time )
|
||||
</if>
|
||||
<where>
|
||||
a.deleted = 0
|
||||
<if test="type == 0">
|
||||
and a.id < #{id}
|
||||
</if>
|
||||
<if test="type == 1">
|
||||
and a.id > #{id}
|
||||
</if>
|
||||
t.deleted = 0
|
||||
AND t.start_user_id = #{userId}
|
||||
<if test="reqVO.type != null">
|
||||
and a.type = #{reqVO.type}
|
||||
and t.type = #{reqVO.type}
|
||||
</if>
|
||||
<if test="reqVO.deptId != null">
|
||||
and a.dept_id = #{reqVO.deptId}
|
||||
and t.dept_id = #{reqVO.deptId}
|
||||
</if>
|
||||
<if test="reqVO.startUserId != null">
|
||||
and a.start_user_id = #{reqVO.startUserId}
|
||||
and t.start_user_id = #{reqVO.startUserId}
|
||||
</if>
|
||||
<if test="reqVO.createTime != null and reqVO.createTime.length > 0">
|
||||
<if test="reqVO.createTime[0] != null">
|
||||
and a.create_time >= #{reqVO.createTime[0]}
|
||||
and t.create_time >= #{reqVO.createTime[0]}
|
||||
</if>
|
||||
<if test="reqVO.createTime[1] != null">
|
||||
and a.create_time <= #{reqVO.createTime[1]}
|
||||
and t.create_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 a.start_user_id in
|
||||
and t.start_user_id in
|
||||
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
<if test="type == 0">
|
||||
order by id desc
|
||||
ORDER BY
|
||||
t.time DESC,
|
||||
t.create_time DESC
|
||||
</if>
|
||||
<if test="type == 1">
|
||||
order by id asc
|
||||
ORDER BY
|
||||
t.time,
|
||||
t.create_time
|
||||
</if>
|
||||
limit 1
|
||||
</select>
|
||||
@ -156,13 +161,11 @@
|
||||
<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
|
||||
|
Loading…
Reference in New Issue
Block a user