|
@@ -0,0 +1,66 @@
|
|
|
|
|
+package com.yr.warehouse.admin.service.operator.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.yr.bluecat.common.entity.utils.StringUtils;
|
|
|
|
|
+import com.yr.warehouse.admin.component.auth.OperatorComponent;
|
|
|
|
|
+import com.yr.warehouse.admin.component.auth.vo.OrgOperatorVo;
|
|
|
|
|
+import com.yr.warehouse.admin.operator.face.OperatorNameFace;
|
|
|
|
|
+import com.yr.warehouse.admin.service.operator.OperatorBuildService;
|
|
|
|
|
+import jakarta.annotation.Resource;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+public class OperatorBuildServiceImpl implements OperatorBuildService {
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private OperatorComponent operatorComponent;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void buildOperatorName(List<? extends OperatorNameFace> operatorNameFaces) {
|
|
|
|
|
+ if (CollectionUtils.isEmpty(operatorNameFaces)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> operatorIds = operatorNameFaces.stream().map(OperatorNameFace::getOperatorId).distinct().toList();
|
|
|
|
|
+ Map<Long, OrgOperatorVo> operatorVoMap = operatorComponent.queryOperatorMapByIdList(operatorIds);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(operatorVoMap)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> superOperatorIds = operatorNameFaces.stream().filter(aware -> Objects.nonNull(aware.getOperatorChain()))
|
|
|
|
|
+ .map(aware -> aware.getOperatorChain().split("-"))
|
|
|
|
|
+ .flatMap(array -> Arrays.stream(array).map(Long::parseLong)).distinct().toList();
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtils.isEmpty(superOperatorIds)) {
|
|
|
|
|
+ Map<Long, OrgOperatorVo> superOperatorMap = operatorVoMap.values().stream().collect(Collectors.toMap(OrgOperatorVo::getId, vo -> vo, (v1, v2) -> v1));
|
|
|
|
|
+ operatorNameFaces.forEach(face -> {
|
|
|
|
|
+ OrgOperatorVo operatorVo = superOperatorMap.get(face.getOperatorId());
|
|
|
|
|
+ face.setOperatorName(operatorVo.getOperatorName());
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<Long, OrgOperatorVo> orgOperators = operatorComponent.queryOperatorMapByIdList(superOperatorIds);
|
|
|
|
|
+ for (OperatorNameFace operatorNameFace : operatorNameFaces) {
|
|
|
|
|
+
|
|
|
|
|
+ OrgOperatorVo operatorVo = operatorVoMap.get(operatorNameFace.getOperatorId());
|
|
|
|
|
+ String operatorChain = operatorNameFace.getOperatorChain();
|
|
|
|
|
+ if (StringUtils.isBlank(operatorChain)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String[] operatorIdArray = operatorChain.split("-");
|
|
|
|
|
+ List<String> operatorChainName = new ArrayList<>();
|
|
|
|
|
+ for (String operatorId : operatorIdArray) {
|
|
|
|
|
+ long id = Long.parseLong(operatorId);
|
|
|
|
|
+ if (id == 0) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ OrgOperatorVo orgOperatorVo = orgOperators.get(id);
|
|
|
|
|
+ operatorChainName.add(Objects.nonNull(orgOperatorVo) ? orgOperatorVo.getOperatorName() : "");
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ operatorNameFace.setOperatorName(operatorVo.getOperatorName());
|
|
|
|
|
+ operatorNameFace.setOperatorChainName(String.join(">>", operatorChainName));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|