还原日志分页查询 sql

This commit is contained in:
furongxin 2024-09-17 11:44:06 +08:00
parent 01d45d5fc4
commit 9b0b73cc75
3 changed files with 131 additions and 50 deletions

View File

@ -9,8 +9,10 @@ import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.Lo
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.metadata.IPage;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List; import java.util.List;
@ -39,9 +41,15 @@ public interface LogInstanceMapper extends BaseMapperX<LogInstanceDO> {
.in(LogInstanceDO::getTime, dateList)); .in(LogInstanceDO::getTime, dateList));
} }
List<LogInstanceRespVO> selectPageResult( @Param("reqVO") LogInstancePageReqVO reqVO, // List<LogInstanceRespVO> selectPageResult( @Param("reqVO") LogInstancePageReqVO reqVO,
// @Param("userId") Long userId,
// @Param("ids") List<Long> ids);
IPage<LogInstanceRespVO> selectPageResult(@Param("page") IPage<LogInstanceRespVO> page,
@Param("reqVO") LogInstancePageReqVO reqVO,
@Param("userId") Long userId, @Param("userId") Long userId,
@Param("ids") List<Long> ids); @Param("pagingType") Integer pagingType,
@Param("userIds") List<Long> userIds);
default PageResult<LogInstanceDO> selectPage(LogInstancePageReqVO reqVO, Long userId, default PageResult<LogInstanceDO> selectPage(LogInstancePageReqVO reqVO, Long userId,
Integer pagingType, List<Long> userIds) { Integer pagingType, List<Long> userIds) {

View File

@ -244,8 +244,12 @@ public class LogInstanceServiceImpl implements LogInstanceService {
leaderUserIds = adminUserService.getUserByBoss(); leaderUserIds = adminUserService.getUserByBoss();
} }
PageResult<LogInstanceDO> pageList = logInstanceMapper.selectPage(pageReqVO, getLoginUserId(), pagingType, leaderUserIds); // PageResult<LogInstanceDO> pageList = logInstanceMapper.selectPage(pageReqVO, getLoginUserId(), pagingType, leaderUserIds);
List<LogInstanceRespVO> records = logInstanceMapper.selectPageResult(pageReqVO, getLoginUserId(), convertList(pageList.getList(), LogInstanceDO::getId)); // List<LogInstanceRespVO> records = logInstanceMapper.selectPageResult(pageReqVO, getLoginUserId(), convertList(pageList.getList(), LogInstanceDO::getId));
Page<LogInstanceRespVO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
IPage<LogInstanceRespVO> pageList = logInstanceMapper.selectPageResult(page, pageReqVO, getLoginUserId(), pagingType, leaderUserIds);
List<LogInstanceRespVO> records = pageList.getRecords();
if (!records.isEmpty()) { if (!records.isEmpty()) {
//模版ids过滤 //模版ids过滤

View File

@ -94,52 +94,54 @@
or result.data_scope = 1 ) or result.data_scope = 1 )
</select> </select>
<select id="selectPageResult" resultType="cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceRespVO"> <!-- <select id="selectPageResult" 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, <!-- system_user_post userPost,-->
system_dept dept, <!-- system_dept dept,-->
system_post post, <!-- system_post post,-->
work_log_instance_ext as a <!-- 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 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 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 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 <!-- 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"> <!-- <if test="ids != null and ids.size > 0">-->
and a.id in <!-- and a.id in-->
<foreach collection="ids" item="ids" open="(" close=")" separator=","> <!-- <foreach collection="ids" item="ids" open="(" close=")" separator=",">-->
#{ids} <!-- #{ids}-->
</foreach> <!-- </foreach>-->
</if> <!-- </if>-->
<if test="ids == null or ids.size == 0"> <!-- <if test="ids == null or ids.size == 0">-->
and a.id = null <!-- and a.id = null-->
</if> <!-- </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-->
<if test="reqVO.isProduce == 1"> <!-- <if test="reqVO.isProduce == 1">-->
AND dept.flag LIKE '%166%' <!-- AND dept.flag LIKE '%166%'-->
</if> <!-- </if>-->
<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.readStatus != null"> <!-- <if test="reqVO.readStatus != null">-->
and e.read_status = #{reqVO.readStatus} <!-- and e.read_status = #{reqVO.readStatus}-->
</if> <!-- </if>-->
</where> <!-- </where>-->
GROUP BY a.id <!-- GROUP BY a.id-->
ORDER BY <!-- ORDER BY-->
a.time DESC, <!-- a.time DESC,-->
post.sort, <!-- post.sort,-->
a.start_user_id <!-- a.start_user_id-->
</select> <!-- </select>-->
<select id="getNextOrUp" <select id="getNextOrUp"
resultType="cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceRespVO"> resultType="cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceRespVO">
SELECT SELECT
@ -198,4 +200,71 @@
</if> </if>
limit 1 limit 1
</select> </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.start_user_id
</select>
</mapper> </mapper>