This commit is contained in:
mashuai 2025-08-24 18:15:36 +08:00
parent 877c06a088
commit 6bc468201a
3 changed files with 59 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import com.bonus.material.basic.domain.vo.MaTypeSelectInfo;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @Author ma_sh * @Author ma_sh
@ -159,4 +160,6 @@ public interface ComplexQueryMapper {
* @return * @return
*/ */
List<RetainedEquipmentInfo> getPersonNum(RetainedEquipmentInfo bean); List<RetainedEquipmentInfo> getPersonNum(RetainedEquipmentInfo bean);
List<UseStorageInfo> batchSelectInfo(@Param("list") Set<Long> leaseIds);
} }

View File

@ -375,12 +375,9 @@ public class ComplexQueryServiceImpl implements ComplexQueryService {
@Override @Override
public List<UseStorageInfo> getUserRecords(UseStorageInfo bean) { public List<UseStorageInfo> getUserRecords(UseStorageInfo bean) {
try { try {
// 查询库管员
UseStorageInfo info = complexQueryMapper.selectMaTypeName(bean);
List<UseStorageInfo> list = complexQueryMapper.getUserRecords(bean); List<UseStorageInfo> list = complexQueryMapper.getUserRecords(bean);
if (CollectionUtils.isNotEmpty(list)) { if (CollectionUtils.isNotEmpty(list)) {
for (UseStorageInfo useStorageInfo : list) { /*for (UseStorageInfo useStorageInfo : list) {
useStorageInfo.setMaKeeper(info.getMaKeeper() == null ? "" : info.getMaKeeper());
// 查询出库信息 // 查询出库信息
if (useStorageInfo.getLeaseId() != null) { if (useStorageInfo.getLeaseId() != null) {
UseStorageInfo dto = complexQueryMapper.selectInFo(useStorageInfo); UseStorageInfo dto = complexQueryMapper.selectInFo(useStorageInfo);
@ -389,7 +386,35 @@ public class ComplexQueryServiceImpl implements ComplexQueryService {
useStorageInfo.setOutTime(dto.getOutTime()); useStorageInfo.setOutTime(dto.getOutTime());
} }
} }
}*/
// 提取所有非空的leaseId批量查询出库信息
Set<Long> leaseIds = list.stream()
.map(UseStorageInfo::getLeaseId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
// 批量查询并缓存结果减少数据库交互
Map<Long, UseStorageInfo> leaseInfoMap = Collections.emptyMap();
if (!leaseIds.isEmpty()) {
leaseInfoMap = complexQueryMapper.batchSelectInfo(leaseIds).stream()
.collect(Collectors.toMap(
UseStorageInfo::getLeaseId,
info -> info,
(existing, replacement) -> existing // 遇到重复key时保留第一个值
));
} }
// 批量设置出库信息
Map<Long, UseStorageInfo> finalLeaseInfoMap = leaseInfoMap;
list.forEach(useStorageInfo -> {
Object leaseId = useStorageInfo.getLeaseId();
if (leaseId != null) {
UseStorageInfo dto = finalLeaseInfoMap.get(leaseId);
if (dto != null) {
useStorageInfo.setCreator(dto.getCreator());
useStorageInfo.setOutTime(dto.getOutTime());
}
}
});
String keyWord = bean.getKeyWord(); String keyWord = bean.getKeyWord();
// 如果关键字不为空进行过滤 // 如果关键字不为空进行过滤
if (!com.bonus.common.core.utils.StringUtils.isBlank(keyWord)) { if (!com.bonus.common.core.utils.StringUtils.isBlank(keyWord)) {

View File

@ -550,7 +550,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mm.ma_code AS maCode, mm.ma_code AS maCode,
bp.pro_name AS projectName, bp.pro_name AS projectName,
sai.lease_id AS leaseId, sai.lease_id AS leaseId,
sai.type_id AS typeId sai.type_id AS typeId,
GROUP_CONCAT( DISTINCT su.nick_name ORDER BY su.nick_name SEPARATOR ', ' ) AS maKeeper
FROM FROM
slt_agreement_info sai slt_agreement_info sai
LEFT JOIN ma_type mt ON mt.type_id = sai.type_id LEFT JOIN ma_type mt ON mt.type_id = sai.type_id
@ -558,6 +559,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN ma_machine mm ON mm.ma_id = sai.ma_id LEFT JOIN ma_machine mm ON mm.ma_id = sai.ma_id
LEFT JOIN bm_agreement_info bai ON bai.agreement_id = sai.agreement_id LEFT JOIN bm_agreement_info bai ON bai.agreement_id = sai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
LEFT JOIN ma_type_keeper mtk ON sai.type_id = mtk.type_id
LEFT JOIN sys_user su ON mtk.user_id = su.user_id
WHERE WHERE
sai.`status` = '0' sai.`status` = '0'
AND sai.end_time IS NULL AND sai.end_time IS NULL
@ -566,6 +569,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="typeId != null"> <if test="typeId != null">
AND sai.type_id = #{typeId} AND sai.type_id = #{typeId}
</if> </if>
GROUP BY
sai.type_id,
sai.ma_id,
bp.pro_id
</select> </select>
<select id="getRepairRecordList" resultType="com.bonus.material.basic.domain.RepairStorageInfo"> <select id="getRepairRecordList" resultType="com.bonus.material.basic.domain.RepairStorageInfo">
@ -1169,5 +1176,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and mt.type_name like concat('%',#{typeModelName},'%') and mt.type_name like concat('%',#{typeModelName},'%')
</if> </if>
</select> </select>
<select id="batchSelectInfo" resultType="com.bonus.material.basic.domain.UseStorageInfo">
SELECT
lod.create_time AS outTime,
GROUP_CONCAT(DISTINCT
CASE
WHEN lod.create_by REGEXP '^[0-9]+$' THEN su.nick_name -- 如果是纯数字,使用昵称
ELSE lod.create_by -- 否则直接使用create_by的值
END
) AS creator
FROM
lease_out_details lod
LEFT JOIN sys_user su ON lod.create_by = su.user_id
WHERE
lod.parent_id IN
<foreach item="item" collection="list" index="index" separator="," close=")" open="(">
#{item}
</foreach>
GROUP BY lod.parent_id
</select>
</mapper> </mapper>