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
Former-commit-id: d3de42bd28
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.ImageStoreService;
|
||||
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.LabelResult;
|
||||
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);
|
||||
result.setRuleName(byId.getName());
|
||||
if (!CollectionUtils.isEmpty(includeLabels)) {
|
||||
Map<String, LabelDetailResult> labelById = loadLabelDetailMap(context);
|
||||
List<LabelDetailResult> labelDetailResultList = new ArrayList<>();
|
||||
for (String label : includeLabels) {
|
||||
LabelDetailParam labelDetailParam = new LabelDetailParam();
|
||||
labelDetailParam.setId(label);
|
||||
CloudwalkResult<LabelDetailResult> detail = this.labelService.detail(labelDetailParam, context);
|
||||
labelDetailResultList.add(detail.getData());
|
||||
}
|
||||
fillLabelDetailsFromMap(includeLabels, labelById, labelDetailResultList, context);
|
||||
result.setIncludeLabels(labelDetailResultList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(includeOrganizations)) {
|
||||
@@ -613,6 +610,7 @@ public class ImageRuleRefServiceImpl extends AbstractAcsPassService implements I
|
||||
if (CollectionUtils.isEmpty(datas)) {
|
||||
return detailResultList;
|
||||
}
|
||||
Map<String, LabelDetailResult> labelById = loadLabelDetailMap(context);
|
||||
List<String> personSum =
|
||||
this.imageRuleRefDao.countPersonIdByZoneId(((ImageRuleRefResultDto)datas.get(0)).getZoneId());
|
||||
for (ImageRuleRefResultDto data : datas) {
|
||||
@@ -662,12 +660,7 @@ public class ImageRuleRefServiceImpl extends AbstractAcsPassService implements I
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(includeLabels)) {
|
||||
List<LabelDetailResult> labelDetailResultList = new ArrayList<>();
|
||||
for (String label : includeLabels) {
|
||||
LabelDetailParam param = new LabelDetailParam();
|
||||
param.setId(label);
|
||||
CloudwalkResult<LabelDetailResult> detail = this.labelService.detail(param, context);
|
||||
labelDetailResultList.add(detail.getData());
|
||||
}
|
||||
fillLabelDetailsFromMap(includeLabels, labelById, labelDetailResultList, context);
|
||||
detailResult.setIncludeLabels(labelDetailResultList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(includeOrganizations)) {
|
||||
@@ -684,6 +677,44 @@ public class ImageRuleRefServiceImpl extends AbstractAcsPassService implements I
|
||||
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,
|
||||
CloudwalkPageInfo pageInfo, CloudwalkCallContext context) throws ServiceException {
|
||||
CloudwalkPageAble<ImageStorePersonResult> results = new CloudwalkPageAble();
|
||||
|
||||
Reference in New Issue
Block a user