查询优化

This commit is contained in:
Vinjor 2025-12-01 11:59:47 +08:00
parent 80d8a3b752
commit b3cf44e961
2 changed files with 19 additions and 12 deletions

View File

@ -70,10 +70,27 @@ public class CusMainServiceImpl extends ServiceImpl<CusMainMapper,CusMain> impl
@DataScope(deptAlias = "cm", userAlias = "cm")
public IPage<MainVO> queryListPage(MainVO pageReqVO, Page<CusMain> page) {
IPage<MainVO> list = cusMainMapper.queryListPage(pageReqVO, page);
List<String> cusIdList = list.getRecords().stream().map(MainVO::getId).collect(Collectors.toList());
//公司信息
List<CusCompany> companyList = cusCompanyService.list(new LambdaQueryWrapper<CusCompany>().in(CusCompany::getCusId, cusIdList).eq(DlBaseEntity::getDelFlag,'0'));
Map<String, CusCompany> companyMap = companyList.stream().collect(Collectors.toMap(CusCompany::getCusId, Function.identity()));
//联系人信息
List<CusContacts> contacts = cusContactsService.list(new LambdaQueryWrapper<CusContacts>().in(CusContacts::getCusId, cusIdList).eq(DlBaseEntity::getDelFlag,'0').eq(CusContacts::getIfDefault,true));
Map<String, CusContacts> contactsMap = contacts.stream().collect(Collectors.toMap(CusContacts::getCusId, Function.identity()));
list.getRecords().forEach(item->{
if(StringUtils.isNotEmpty(item.getCusLabels())){
item.setCusLabelList(JSON.parseArray(item.getCusLabels()));
}
if(companyMap.containsKey(item.getId())){
CusCompany company = companyMap.get(item.getId());
item.setCusFrom(company.getCusFrom());
item.setCusLevel(company.getCusLevel());
item.setBusiType(company.getBusiType());
item.setContactAddress(company.getContactAddress());
}
if(contactsMap.containsKey(item.getId())){
item.setContactName(contactsMap.get(item.getId()).getName());
}
});
return list;
}

View File

@ -55,25 +55,15 @@
<select id="queryListPage" parameterType="com.ruoyi.cus.vo.MainVO" resultType="com.ruoyi.cus.vo.MainVO">
SELECT
cm.*,
cc.cus_from AS cusFrom,
cc.cus_level AS cusLevel,
cc.busi_type AS busiType,
cc.contact_address AS contactAddress,
cct.`name` AS contactName
cm.*
FROM
cus_main cm
LEFT JOIN cus_company cc ON cm.id = cc.cus_id
AND cc.del_flag = '0'
LEFT JOIN cus_contacts cct ON cm.id = cct.cus_id
AND cct.if_default = 1
AND cct.del_flag = '0'
WHERE
cm.del_flag = '0'
<if test="entity.cusCode!=null and entity.cusCode!=''">
AND cm.cus_code = #{entity.cusCode}
</if>
<if test="entity.fullName!=null and entity.cusCode!=''">
<if test="entity.fullName!=null and entity.fullName!=''">
AND cm.full_name LIKE CONCAT('%',#{entity.fullName},'%')
</if>
<if test="entity.shortName!=null and entity.shortName!=''">