mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 08:20:31 +08:00
elevator(service): 规则标签详情避免循环 labelService.detail,改用 getAll 索引
Made-with: Cursor
This commit is contained in:
+43
-12
@@ -11,6 +11,7 @@ import cn.cloudwalk.client.cwoscomponent.intelligent.imagestore.result.ImgStoreP
|
|||||||
import cn.cloudwalk.client.cwoscomponent.intelligent.imagestore.service.ImageStorePersonService;
|
import cn.cloudwalk.client.cwoscomponent.intelligent.imagestore.service.ImageStorePersonService;
|
||||||
import cn.cloudwalk.client.cwoscomponent.intelligent.imagestore.service.ImageStoreService;
|
import cn.cloudwalk.client.cwoscomponent.intelligent.imagestore.service.ImageStoreService;
|
||||||
import cn.cloudwalk.client.cwoscomponent.intelligent.label.param.LabelDetailParam;
|
import cn.cloudwalk.client.cwoscomponent.intelligent.label.param.LabelDetailParam;
|
||||||
|
import cn.cloudwalk.client.cwoscomponent.intelligent.label.param.LabelQueryParam;
|
||||||
import cn.cloudwalk.client.cwoscomponent.intelligent.label.result.LabelDetailResult;
|
import cn.cloudwalk.client.cwoscomponent.intelligent.label.result.LabelDetailResult;
|
||||||
import cn.cloudwalk.client.cwoscomponent.intelligent.label.result.LabelResult;
|
import cn.cloudwalk.client.cwoscomponent.intelligent.label.result.LabelResult;
|
||||||
import cn.cloudwalk.client.cwoscomponent.intelligent.label.service.LabelService;
|
import cn.cloudwalk.client.cwoscomponent.intelligent.label.service.LabelService;
|
||||||
@@ -321,13 +322,9 @@ public class ImageRuleRefServiceImpl extends AbstractAcsPassService implements I
|
|||||||
(ImageRuleRefDetailResult)BeanCopyUtils.copyProperties(byId, ImageRuleRefDetailResult.class);
|
(ImageRuleRefDetailResult)BeanCopyUtils.copyProperties(byId, ImageRuleRefDetailResult.class);
|
||||||
result.setRuleName(byId.getName());
|
result.setRuleName(byId.getName());
|
||||||
if (!CollectionUtils.isEmpty(includeLabels)) {
|
if (!CollectionUtils.isEmpty(includeLabels)) {
|
||||||
|
Map<String, LabelDetailResult> labelById = loadLabelDetailMap(context);
|
||||||
List<LabelDetailResult> labelDetailResultList = new ArrayList<>();
|
List<LabelDetailResult> labelDetailResultList = new ArrayList<>();
|
||||||
for (String label : includeLabels) {
|
fillLabelDetailsFromMap(includeLabels, labelById, labelDetailResultList, context);
|
||||||
LabelDetailParam labelDetailParam = new LabelDetailParam();
|
|
||||||
labelDetailParam.setId(label);
|
|
||||||
CloudwalkResult<LabelDetailResult> detail = this.labelService.detail(labelDetailParam, context);
|
|
||||||
labelDetailResultList.add(detail.getData());
|
|
||||||
}
|
|
||||||
result.setIncludeLabels(labelDetailResultList);
|
result.setIncludeLabels(labelDetailResultList);
|
||||||
}
|
}
|
||||||
if (!CollectionUtils.isEmpty(includeOrganizations)) {
|
if (!CollectionUtils.isEmpty(includeOrganizations)) {
|
||||||
@@ -613,6 +610,7 @@ public class ImageRuleRefServiceImpl extends AbstractAcsPassService implements I
|
|||||||
if (CollectionUtils.isEmpty(datas)) {
|
if (CollectionUtils.isEmpty(datas)) {
|
||||||
return detailResultList;
|
return detailResultList;
|
||||||
}
|
}
|
||||||
|
Map<String, LabelDetailResult> labelById = loadLabelDetailMap(context);
|
||||||
List<String> personSum =
|
List<String> personSum =
|
||||||
this.imageRuleRefDao.countPersonIdByZoneId(((ImageRuleRefResultDto)datas.get(0)).getZoneId());
|
this.imageRuleRefDao.countPersonIdByZoneId(((ImageRuleRefResultDto)datas.get(0)).getZoneId());
|
||||||
for (ImageRuleRefResultDto data : datas) {
|
for (ImageRuleRefResultDto data : datas) {
|
||||||
@@ -662,12 +660,7 @@ public class ImageRuleRefServiceImpl extends AbstractAcsPassService implements I
|
|||||||
}
|
}
|
||||||
if (!CollectionUtils.isEmpty(includeLabels)) {
|
if (!CollectionUtils.isEmpty(includeLabels)) {
|
||||||
List<LabelDetailResult> labelDetailResultList = new ArrayList<>();
|
List<LabelDetailResult> labelDetailResultList = new ArrayList<>();
|
||||||
for (String label : includeLabels) {
|
fillLabelDetailsFromMap(includeLabels, labelById, labelDetailResultList, context);
|
||||||
LabelDetailParam param = new LabelDetailParam();
|
|
||||||
param.setId(label);
|
|
||||||
CloudwalkResult<LabelDetailResult> detail = this.labelService.detail(param, context);
|
|
||||||
labelDetailResultList.add(detail.getData());
|
|
||||||
}
|
|
||||||
detailResult.setIncludeLabels(labelDetailResultList);
|
detailResult.setIncludeLabels(labelDetailResultList);
|
||||||
}
|
}
|
||||||
if (!CollectionUtils.isEmpty(includeOrganizations)) {
|
if (!CollectionUtils.isEmpty(includeOrganizations)) {
|
||||||
@@ -684,6 +677,44 @@ public class ImageRuleRefServiceImpl extends AbstractAcsPassService implements I
|
|||||||
return detailResultList;
|
return detailResultList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一次 {@link LabelService#getAll} 建 id→详情索引,避免规则详情/分页组装时对 {@link LabelService#detail} 的 N 次远程调用。
|
||||||
|
* 若某 id 不在全量列表中(数据不同步),回退单次 detail。
|
||||||
|
*/
|
||||||
|
private Map<String, LabelDetailResult> loadLabelDetailMap(CloudwalkCallContext context) throws ServiceException {
|
||||||
|
CloudwalkResult<List<LabelDetailResult>> all = this.labelService.getAll(new LabelQueryParam(), context);
|
||||||
|
if (all == null || !all.isSuccess() || all.getData() == null) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
Map<String, LabelDetailResult> map = new HashMap<>(Math.max(16, all.getData().size() * 2));
|
||||||
|
for (LabelDetailResult row : all.getData()) {
|
||||||
|
if (row != null && row.getId() != null) {
|
||||||
|
map.put(row.getId(), row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillLabelDetailsFromMap(List<String> labelIds, Map<String, LabelDetailResult> labelById,
|
||||||
|
List<LabelDetailResult> out, CloudwalkCallContext context) throws ServiceException {
|
||||||
|
if (CollectionUtils.isEmpty(labelIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String labelId : labelIds) {
|
||||||
|
LabelDetailResult cached = (labelById != null) ? labelById.get(labelId) : null;
|
||||||
|
if (cached != null) {
|
||||||
|
out.add(cached);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LabelDetailParam p = new LabelDetailParam();
|
||||||
|
p.setId(labelId);
|
||||||
|
CloudwalkResult<LabelDetailResult> detail = this.labelService.detail(p, context);
|
||||||
|
if (detail != null && detail.isSuccess() && detail.getData() != null) {
|
||||||
|
out.add(detail.getData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private CloudwalkPageAble<ImageStorePersonResult> getImageStorePerson(AcsPersonQueryParam param,
|
private CloudwalkPageAble<ImageStorePersonResult> getImageStorePerson(AcsPersonQueryParam param,
|
||||||
CloudwalkPageInfo pageInfo, CloudwalkCallContext context) throws ServiceException {
|
CloudwalkPageInfo pageInfo, CloudwalkCallContext context) throws ServiceException {
|
||||||
CloudwalkPageAble<ImageStorePersonResult> results = new CloudwalkPageAble();
|
CloudwalkPageAble<ImageStorePersonResult> results = new CloudwalkPageAble();
|
||||||
|
|||||||
Reference in New Issue
Block a user