Commit 23ad0e36 by jiangxuming

feat: 增加预过滤逻辑并使用Redis缓存

fix: 修复entrustCode查询条件的逻辑错误
parent 091fa49d
package com.patzn.cloud.service.lims.hmhj.mapper;
import com.baomidou.mybatisplus.annotations.SqlParser;
import com.patzn.cloud.commons.mapper.BatchMapper;
import com.patzn.cloud.service.hmhj.entity.OriginalRecord;
import com.patzn.cloud.service.hmhj.vo.OriginalRecordVO;
......@@ -19,6 +20,7 @@ import java.util.Map;
*/
public interface OriginalRecordMapper extends BatchMapper<OriginalRecord> {
@SqlParser(filter = true)
List<OriginalRecordVO> selectPageVO(RowBounds rowBounds, @Param("vo") OriginalRecordVO vo);
Map<String,String> selectOriginalFileKey(@Param("entrustId") Long entrustId, @Param("recordId") Long recordId);
......
......@@ -19,9 +19,12 @@ import com.patzn.cloud.service.lims.hmhj.common.consts.HmConst;
import com.patzn.cloud.service.lims.hmhj.service.IEntrustService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -54,6 +57,9 @@ public class UserInfoServiceImpl {
@Autowired
private ILmsMsgService lmsMsgService;
@Resource
private RedisTemplate<String, String> redisTemplate;
public List<LmsUserGroup> getGroupList(Long userId) {
if (null == userId) {
return OTHER_GROUP_LIST;
......@@ -71,7 +77,17 @@ public class UserInfoServiceImpl {
}
public List<String> getCurGroupNameList() {
return getGroupNameList(LoginHelper.getAccount().getUserId());
final String curGroupNameList = "curGroupNameList#%s";
String str = redisTemplate.opsForValue().get(String.format(curGroupNameList, LoginHelper.getAccount().getUserId()));
if (StringUtils.isNotBlank(str)) {
List<String> list = Arrays.asList(str.split(Symbol.COMMA));
return list;
} else {
List<String> groupNameList = getGroupNameList(LoginHelper.getAccount().getUserId());
redisTemplate.opsForValue().set(String.format(curGroupNameList, LoginHelper.getAccount().getUserId()), StringUtils.join(groupNameList, Symbol.COMMA), 24, TimeUnit.HOURS);
return groupNameList;
}
}
public String getCurGroupNames() {
......
......@@ -3,51 +3,65 @@
<mapper namespace="com.patzn.cloud.service.lims.hmhj.mapper.OriginalRecordMapper">
<select id="selectPageVO" resultType="com.patzn.cloud.service.hmhj.vo.OriginalRecordVO">
select
r.ID,
MAX ( r.original_record_id ) "original_record_id",
MAX ( r.entrust_id ) "entrust_id",
MAX ( r.template_id ) "template_id",
MAX ( r.title ) "title",
MAX ( r.company_id ) "company_id",
MAX ( r.uid ) "uid",
MAX ( r.ctime ) "ctime",
MAX ( r.lid ) "lid",
MAX ( r.ltime ) "ltime",
MAX ( r.deleted ) "deleted",
MAX ( r.uname ) "uname",
MAX ( r.remark ) "remark",
MAX ( r.object_key ) "object_key",
MAX ( r.pdf_object_key ) "pdf_object_key",
MAX ( r.entrust_ids ) "entrust_ids",
string_agg(e.code,',') "entrustCode"
from original_record r
join entrust e on (e.id = r.entrust_id or strpos(r.entrust_ids,e.id::varchar) > 0) and e.deleted = 0
where r.deleted = 0
<if test="null != vo.title">
AND r.title LIKE CONCAT('%',#{vo.title},'%')
</if>
<if test="null != vo.entrustId">
AND e.id = #{vo.entrustId}
WITH target_items AS (
-- 预过滤entrust_sample_item关联数据
SELECT DISTINCT rr.record_id
FROM entrust_sample_item i
JOIN item_rel_original_record rr ON rr.item_id = i.id AND rr.deleted = 0
WHERE i.deleted = 0
<if test="vo.testerId != null">
AND i.tester_id = #{vo.testerId}
</if>
<if test="null != vo.entrustCode">
AND e.code LIKE CONCAT('%',#{vo.entrustCode},'%')
<if test="vo.itemStatus != null">
AND i.status = #{vo.itemStatus}
</if>
<if test="null != vo.testerId || null != vo.itemStatus">
AND exists (
select 1 from entrust_sample_item i,item_rel_original_record rr
where i.deleted = 0 and rr.deleted = 0 and rr.item_id = i.id
and r.id = rr.record_id
<if test="null != vo.testerId">
and i.tester_id = #{vo.testerId}
),
filtered_records AS (
-- 预过滤original_record主表
SELECT id
FROM original_record
WHERE deleted = 0
<if test="vo.title != null">
AND title LIKE CONCAT('%', #{vo.title}, '%')
</if>
<if test="null != vo.itemStatus">
and i.status = #{vo.itemStatus}
AND id IN (SELECT record_id FROM target_items) -- 关联预过滤结果
<if test="vo.entrustId != null">
AND entrust_id = #{vo.entrustId} -- 直接过滤entrust_id
</if>
)
SELECT
r.ID,
MAX(r.original_record_id) AS "original_record_id",
MAX(r.entrust_id) AS "entrust_id",
MAX(r.template_id) AS "template_id",
MAX(r.title) AS "title",
MAX(r.company_id) AS "company_id",
MAX(r.uid) AS "uid",
MAX(r.ctime) AS "ctime",
MAX(r.lid) AS "lid",
MAX(r.ltime) AS "ltime",
MAX(r.deleted) AS "deleted",
MAX(r.uname) AS "uname",
MAX(r.remark) AS "remark",
MAX(r.object_key) AS "object_key",
MAX(r.pdf_object_key) AS "pdf_object_key",
MAX(r.entrust_ids) AS "entrust_ids",
STRING_AGG(e.code, ',') AS "entrustCode"
FROM filtered_records fr
JOIN original_record r ON r.id = fr.id
JOIN entrust e ON e.deleted = 0
AND (
e.id = r.entrust_id
OR r.entrust_ids LIKE CONCAT('%', e.id, '%') -- 替换strpos为LIKE
)
<if test="vo.entrustId != null">
AND e.id = #{vo.entrustId} -- 二次确认entrust_id
</if>
<if test="vo.entrustCode != null">
AND e.code LIKE CONCAT('%', #{vo.entrustCode}, '%')
</if>
group by r.id
order by r.id desc
GROUP BY r.id
ORDER BY r.id DESC
</select>
<!--查询原始记录对应的原始文件Key-->
<select id="selectOriginalFileKey" resultType="java.util.Map">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment