后端递归太多导致栈溢出
package com.example.springboot_erp.sys.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.springboot_erp.sys.entity.*;
import com.example.springboot_erp.sys.mapper.ProductMapper;
import com.example.springboot_erp.sys.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
* 服务实现类
* </p>
*
* @author Li
* @since 2023-11-18
*/
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {
@Autowired
private IProductSeqService productSeqService;
@Autowired
private IWorkshopService workshopService;
@Autowired
private IApsService apsService;
@Autowired
private IGroup1Service groupService;
@Autowired
private IEmployeeService employeeService;
@Override
public List<Map<String, Object>> getInforProduct() {
List<Product> productList = this.list();
List<Map<String,Object>> bbb = new ArrayList<>();
for (Product product : productList) {
HashMap<String, Object> productMap = new HashMap<>();
productMap.put("product_id",product.getProductId());
productMap.put("product_name",product.getProductName());
LambdaQueryWrapper<ProductSeq> prdouctWrapper = new LambdaQueryWrapper<>();
prdouctWrapper.eq(ProductSeq::getProductId, product.getProductId());
List<ProductSeq> ProductSeqList = productSeqService.list(prdouctWrapper);
List<Map<String,Object>> productSeqList = new ArrayList<>();
for (ProductSeq seq : ProductSeqList) {
HashMap<String, Object> productSeq = new HashMap<>();
productSeq.put("ps_id",seq.getPsId());
productSeq.put("ps_order",seq.getPsOrder());
LambdaQueryWrapper<Workshop> ps_work_list = new LambdaQueryWrapper<>();
ps_work_list.eq(Workshop::getPsId,seq.getPsId());
List<Workshop> workshopList = workshopService.list(ps_work_list);
List<Map<String,Object>> workShopList = new ArrayList<>();
for (Workshop workshop : workshopList) {
HashMap<String,Object> workShop = new HashMap<>();
workShop.put("ws_id",workshop.getWsId());
LambdaQueryWrapper<Aps> ApsWrapper = new LambdaQueryWrapper<>();
ApsWrapper.eq(Aps::getApsWsId,workshop.getWsId());
LambdaQueryWrapper<Group1> GroupWrapper = new LambdaQueryWrapper<>();
GroupWrapper.eq(Group1::getWsId,workshop.getWsId());
List<Group1> GroupList = groupService.list(GroupWrapper);
List<Aps> Aps_list = apsService.list(ApsWrapper);
List<Map<String,Object>> workShop_g_list = new ArrayList<>();
List<Map<String,Object>> workShop_A_list = new ArrayList<>();
for (Group1 group : GroupList) {
HashMap<String, Object> GroupMap = new HashMap<>();
Employee emplyeeOne = employeeService.getById(group.getPersonOneId());
Employee emplyeeTwo = employeeService.getById(group.getPersonTwoId());
GroupMap.put("one_id",emplyeeOne.getEmployeeId());
GroupMap.put("one_name",emplyeeOne.getEmployeeName());
GroupMap.put("two_id",emplyeeTwo.getEmployeeId());
GroupMap.put("two_name",emplyeeTwo.getEmployeeName());
GroupMap.put("machine_id",group.getMachineId());
GroupMap.put("group_id",group.getGroupId());
workShop_g_list.add(GroupMap);
}
for (Aps aps : Aps_list) {
HashMap<String, Object> ApsMap = new HashMap<>();
ApsMap.put("aps_id",aps.getApsId());
ApsMap.put("aps_startTime",aps.getApsStarttime());
ApsMap.put("aps_endTime",aps.getApsEndtime());
workShop_A_list.add(workShop);
}
workShop.put("Aps_list",workShop_A_list);
workShop.put("Group_list",workShop_g_list);
workShopList.add(workShop);
}
productSeq.put("Ps_workshop_list",workShopList);
productSeqList.add(productSeq);
}
productMap.put("Product_seq_list",productSeqList);
bbb.add(productMap);
}
return bbb;
}
}
这段代码
在搜索的过程中好像因为代码太繁琐导致的 还不知道怎么优化代码