package org.jeecg.modules.tms.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import org.jeecg.common.api.vo.CommonGenericTree;
|
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.common.util.StrUtils;
|
import org.jeecg.modules.tms.entity.Warehouse;
|
import org.jeecg.modules.tms.entity.vo.DictVo;
|
import org.jeecg.modules.tms.mapper.WarehouseMapper;
|
import org.jeecg.modules.tms.service.IWarehouseService;
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import java.util.*;
|
|
/**
|
* @Description: tms_warehouse
|
* @Author: jeecg-boot
|
* @Date: 2025-05-06
|
* @Version: V1.0
|
*/
|
@Service
|
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse> implements IWarehouseService {
|
|
@Override
|
public List<CommonGenericTree<Warehouse>> loadTree() {
|
List<Warehouse> warehouseList = list(new LambdaQueryWrapper<Warehouse>()
|
.eq(Warehouse::getStatus, CommonConstant.STATUS_1).orderByAsc(Warehouse::getSeq));
|
return loadTree(warehouseList);
|
}
|
|
@Override
|
public IPage<Warehouse> queryPageList(Page<Warehouse> page, Map<String, String[]> parameterMap) {
|
QueryWrapper<Warehouse> queryWrapper = Wrappers.query();
|
String[] warehouseNames = parameterMap.get("warehouseName");
|
if (warehouseNames != null && warehouseNames.length > 0) {
|
queryWrapper.like("t.warehouse_name", warehouseNames[0]);
|
}
|
String[] parentIds = parameterMap.get("parentId");
|
if (parentIds != null && parentIds.length > 0) {
|
queryWrapper.eq("t.parent_id", parentIds[0]);
|
}
|
String[] beginTimes = parameterMap.get("beginTime");
|
String[] endTimes = parameterMap.get("endTime");
|
if (beginTimes != null && beginTimes.length > 0) {
|
queryWrapper.ge("t.create_time", beginTimes[0]);
|
}
|
if (endTimes != null && endTimes.length > 0) {
|
queryWrapper.le("t.create_time", endTimes[0]);
|
}
|
queryWrapper.orderByAsc("t.seq");
|
return this.baseMapper.queryPageList(page, queryWrapper);
|
}
|
|
@Override
|
public List<DictVo> queryWarehouseDictList() {
|
return this.baseMapper.queryWarehouseDictList();
|
}
|
|
private List<CommonGenericTree<Warehouse>> loadTree(List<Warehouse> warehouseList) {
|
Warehouse warehouse = new Warehouse();
|
List<CommonGenericTree<Warehouse>> list = new ArrayList<>();
|
Map<String, CommonGenericTree<Warehouse>> map = new HashMap<>();
|
CommonGenericTree<Warehouse> node = new CommonGenericTree<>();//手动创建根节点
|
node.setKey("-1");
|
node.setTitle("航宇救生");
|
node.setRField1("");
|
node.setRField2("");
|
node.setEntity(new Warehouse()
|
.setId("-1")
|
.setWarehouseId("-1")
|
.setWarehouseName("航宇救生")
|
.setLeafFlag("2"));
|
list.add(node);
|
if (CollectionUtils.isNotEmpty(warehouseList)) {
|
CommonGenericTree<Warehouse> tcNode;
|
for (Warehouse wh : warehouseList) {
|
if (StrUtils.isBlankOrNull(wh.getParentId()) || wh.getParentId().equals("-1")) {
|
tcNode = new CommonGenericTree<>();
|
tcNode.setKey(wh.getId());
|
tcNode.setTitle(wh.getWarehouseId() + "/" + wh.getWarehouseName());
|
tcNode.setParentId(node.getKey());
|
tcNode.setIcon("");
|
tcNode.setType(1);
|
tcNode.setValue(wh.getWarehouseName());
|
//tcNode.setDisabled(CommonConstant.STATUS_0.equals(wh.getStatus()) ? true : false);
|
tcNode.setRField1(wh.getWarehouseId());
|
tcNode.setRField2(getBaseParent(wh.getId(), 0).getWarehouseId());
|
tcNode.setEntity(wh);
|
node.addChildren(tcNode);
|
map.put(wh.getId(), tcNode);
|
}
|
}
|
CommonGenericTree<Warehouse> childNode;
|
for (Warehouse wh : warehouseList) {
|
Warehouse child = wh;
|
if (map.containsKey(child.getParentId())) {
|
if (StrUtils.isBlankOrNull(wh.getParentId()) || wh.getParentId().equals("-1")) {
|
warehouse = wh;
|
} else {
|
tcNode = map.get(child.getParentId());
|
childNode = new CommonGenericTree<>();
|
childNode.setKey(wh.getId());
|
childNode.setTitle(wh.getWarehouseId() + "/" + wh.getWarehouseName());
|
childNode.setParentId(wh.getParentId());
|
childNode.setIcon("");
|
childNode.setType(0);
|
childNode.setValue(wh.getWarehouseName());
|
//childNode.setDisabled(CommonConstant.STATUS_0.equals(wh.getStatus()) ? true : false);
|
childNode.setRField1(wh.getWarehouseId());
|
childNode.setRField2(getBaseParent(wh.getId(), 0).getWarehouseId());
|
childNode.setEntity(wh);
|
tcNode.addChildren(childNode);
|
map.put(child.getId(), childNode);
|
}
|
}
|
}
|
}
|
return list;
|
}
|
|
public Warehouse getBaseParent(String id, int index) {
|
Warehouse warehouse = null;
|
if (index < 99) {
|
warehouse = getById(id);
|
if (StrUtils.isNotBlankOrNull(warehouse.getParentId())) {
|
if (!warehouse.getParentId().equals("-1")) {
|
warehouse = getBaseParent(warehouse.getParentId(), index++);
|
}
|
}
|
}
|
return warehouse;
|
}
|
}
|