From 60311724f9afc274f15cd07320947aca8adf27e4 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期五, 01 八月 2025 16:53:08 +0800
Subject: [PATCH] 班次利用率算法调整
---
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductMixServiceImpl.java | 180 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 172 insertions(+), 8 deletions(-)
diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductMixServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductMixServiceImpl.java
index 9e0d90f..ef68867 100644
--- a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductMixServiceImpl.java
+++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductMixServiceImpl.java
@@ -3,16 +3,17 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
-import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
-import org.jeecg.modules.dnc.entity.ProductMix;
+import org.jeecg.modules.dnc.entity.*;
import org.jeecg.modules.dnc.mapper.ProductMixMapper;
-import org.jeecg.modules.dnc.service.IPermissionStreamNewService;
-import org.jeecg.modules.dnc.service.IProductMixService;
+import org.jeecg.modules.dnc.service.*;
import org.jeecg.modules.dnc.utils.TreeBuilder;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
-import java.util.List;
+
+import java.util.*;
+import java.util.stream.Collectors;
@Service
public class ProductMixServiceImpl extends ServiceImpl<ProductMixMapper, ProductMix> implements IProductMixService {
@@ -20,16 +21,179 @@
@Autowired
private IPermissionStreamNewService permissionStreamNewService;
+ @Autowired
+ @Lazy
+ private IDeviceTypeService deviceTypeService;
+
+ @Autowired
+ @Lazy
+ private IDeviceManagementService deviceManagementService;
+
+ @Autowired
+ @Lazy
+ private IDocInfoService docInfoService;
+
+ @Autowired
+ @Lazy
+ private IDocRelativeService docRelativeService;
+ /**
+ * 榛樿缁撴瀯鏍戞煡璇�
+ * @return
+ */
@Override
public List<ProductMix> getTree() {
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
- List<ProductMix> rawData = permissionStreamNewService.loadProductMix(loginUser.getId());
+ List<ProductMix> rawData = new ArrayList<>();
+ if (loginUser.getUsername().equals("admin")) {
+ //涓嶉渶瑕佹潈闄愯繃婊�
+ rawData=permissionStreamNewService.loadProductMixAll(loginUser.getId());
+ }else{
+ //闇�瑕佹潈闄愯繃婊�
+ String productIds = loginUser.getProductionIds();
+ if (productIds != null && !productIds.isEmpty()) {
+ List<String> productIdList = Arrays.asList(productIds.split(","));
+ rawData = permissionStreamNewService.loadProductMix(loginUser.getId(),productIdList);
+ }
+ }
TreeBuilder builder = new TreeBuilder();
TreeBuilder.CleanResult cleanResult = builder.preprocessData(rawData);
List<ProductMix> sorted = builder.topologicalSort(
cleanResult.getValidNodes(),
cleanResult.getNodeMap()
);
- return builder.assembleTree(sorted, cleanResult.getNodeMap());
+ List<ProductMix> result =builder.assembleTree(sorted, cleanResult.getNodeMap());
+ result.sort(Comparator.comparing(ProductMix::getCreateTime, Comparator.nullsLast(Date::compareTo)));
+ return result;
}
-}
\ No newline at end of file
+
+ @Override
+ public List<ProductMix> getParentList(String id) {
+ List<ProductMix> parentList = new ArrayList<>();
+ // 1. 鏍规嵁ID鏌ヨ褰撳墠鑺傜偣
+ ProductMix current = this.getById(id);
+ if (current == null) {
+ return parentList; // 鑺傜偣涓嶅瓨鍦ㄦ椂杩斿洖绌哄垪琛�
+ }
+ // 2. 浠庡綋鍓嶈妭鐐瑰紑濮嬪悜涓婃煡鎵剧埗鑺傜偣
+ Long parentId = current.getParentId();
+ while ( parentId != 0L) {
+ ProductMix parent = this.getById(parentId.toString());
+ if (parent == null) {
+ break;
+ }
+ parentList.add(parent);
+ parentId = parent.getParentId();
+ }
+
+ return parentList;
+ }
+
+ @Override
+ public List<ProductMix> getChildrenList(String id) {
+ List<ProductMix> childrenList = new ArrayList<>();
+ ProductMix current = this.getById(id);
+ if (current == null) {
+ return childrenList;
+ }
+
+ // 浣跨敤闃熷垪杩涜BFS
+ Queue<ProductMix> queue = new LinkedList<>();
+ queue.add(current); // 鍔犲叆褰撳墠鑺傜偣浣滀负璧风偣
+
+ // 璁板綍宸茶闂妭鐐圭殑ID锛岄伩鍏嶅惊鐜紩鐢�
+ Set<String> visited = new HashSet<>();
+ visited.add(id); // 璧峰鑺傜偣宸茶闂�
+
+ while (!queue.isEmpty()) {
+ ProductMix node = queue.poll();
+ // 璺宠繃璧峰鑺傜偣锛堝嵆浼犲叆鐨勮妭鐐癸級锛屼笉鍔犲叆缁撴灉鍒楄〃
+ if (!node.getId().toString().equals(id)) {
+ childrenList.add(node);
+ }
+
+ // 鏌ヨ褰撳墠鑺傜偣鐨勭洿鎺ュ瓙鑺傜偣
+ List<ProductMix> directChildren = this.lambdaQuery().eq(ProductMix::getParentId, node.getId()).list();
+ if (directChildren != null && !directChildren.isEmpty()) {
+ for (ProductMix child : directChildren) {
+ String childId = child.getId().toString();
+ // 濡傛灉璇ュ瓙鑺傜偣杩樻湭璁块棶杩�
+ if (!visited.contains(childId)) {
+ visited.add(childId);
+ queue.add(child);
+ }
+ // 鍚﹀垯蹇界暐锛岄伩鍏嶅惊鐜紩鐢ㄥ鑷寸殑姝诲惊鐜�
+ }
+ }
+ }
+ return childrenList;
+ }
+
+ /**
+ * 鏌ヨ浜у搧缁撴瀯鏍戯紙鍖呮嫭璁惧绫讳笌nc鏂囦欢锛�
+ * @return
+ */
+ @Override
+ public List<ProductMix> getProductMixTree() {
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+ List<ProductMix> rawData = new ArrayList<>();
+ if (loginUser.getUsername().equals("admin")) {
+ //涓嶉渶瑕佹潈闄愯繃婊�
+ rawData = permissionStreamNewService.loadProductMixAll(loginUser.getId());
+ } else {
+ //闇�瑕佹潈闄愯繃婊�
+ String productIds = loginUser.getProductionIds();
+ if (productIds != null && !productIds.isEmpty()) {
+ List<String> productIdList = Arrays.asList(productIds.split(","));
+ rawData = permissionStreamNewService.loadProductMix(loginUser.getId(), productIdList);
+ }
+ }
+ List<Long> ids = rawData.stream()
+ .filter(p -> p.getType() != null)
+ .filter(productMix -> productMix.getType() == 5 || productMix.getType() == 6)
+ .map(ProductMix::getId)
+ .collect(Collectors.toList());
+ if (ids.isEmpty()) {
+ return rawData;
+ }
+ //杩囨护璁惧绫诲叧鑱斾俊鎭�
+ List<DeviceType> deviceTypeList = deviceTypeService.list(new QueryWrapper<DeviceType>()
+ .in("attribution_id", ids));
+ List<ProductMix> productMixList = new ArrayList<>();
+ deviceTypeList.forEach(item->{
+ ProductMix productMix = new ProductMix();
+ productMix.setId(Long.parseLong(item.getId()));
+ productMix.setParentId(Long.parseLong(item.getAttributionId()));
+ DeviceManagement deviceManagement=deviceManagementService.getById(item.getDeviceManagementId());
+ productMix.setTreeCode(deviceManagement.getDeviceManagementCode());
+ productMix.setTreeName(deviceManagement.getDeviceManagementName());
+ productMix.setType(7);
+ productMixList.add(productMix);
+ });
+ rawData.addAll(productMixList);
+ //杩囨护鏂囨。鍏宠仈淇℃伅
+ List<String> deviceTypeIds = deviceTypeList.stream().map(DeviceType::getId).collect(Collectors.toList());
+ List<DocRelative> relativeList = docRelativeService.list(new QueryWrapper<DocRelative>()
+ .in("attribution_id", deviceTypeIds));
+ List<ProductMix> docList = new ArrayList<>();
+ relativeList.forEach(item->{
+ ProductMix productMix = new ProductMix();
+ productMix.setId(Long.parseLong(item.getId()));
+ productMix.setParentId(Long.parseLong(item.getAttributionId()));
+ DocInfo docInfo = docInfoService.getById(item.getDocId());
+ productMix.setTreeCode(docInfo.getDocSuffix());
+ productMix.setTreeName(docInfo.getDocName());
+ productMix.setType(99);
+ docList.add(productMix);
+ });
+ rawData.addAll(docList);
+ TreeBuilder builder = new TreeBuilder();
+ TreeBuilder.CleanResult cleanResult = builder.preprocessData(rawData);
+ List<ProductMix> sorted = builder.topologicalSort(
+ cleanResult.getValidNodes(),
+ cleanResult.getNodeMap()
+ );
+ List<ProductMix> result =builder.assembleTree(sorted, cleanResult.getNodeMap());
+ result.sort(Comparator.comparing(ProductMix::getCreateTime, Comparator.nullsLast(Date::compareTo)));
+ return result;
+ }
+}
--
Gitblit v1.9.3