|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.vincent.rsf.framework.exception.CoolException; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.Loc; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.WarehouseAreas; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.mapper.WarehouseMapper; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.Warehouse; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.WarehouseAreasService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.WarehouseService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service("warehouseService") | 
|---|
|  |  |  | public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse> implements WarehouseService { | 
|---|
|  |  |  | 
|---|
|  |  |  | private WarehouseAreasService warehouseAreasService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Warehouse> getAllWarehouseAreas() { | 
|---|
|  |  |  | List<Warehouse> warehouses = this.list(new LambdaQueryWrapper<>()); | 
|---|
|  |  |  | public List<Warehouse> getAllWarehouseAreas(Map<String, Object> param) { | 
|---|
|  |  |  | List<Warehouse> filters = new ArrayList<>(); | 
|---|
|  |  |  | List<Long> wareIds = new ArrayList<>(); | 
|---|
|  |  |  | Object name = param.get("name"); | 
|---|
|  |  |  | boolean isEmpty = !Objects.isNull(name) && !StringUtils.isBlank(name.toString()); | 
|---|
|  |  |  | if (isEmpty) { | 
|---|
|  |  |  | filters = this.baseMapper.selectByName(name.toString()); | 
|---|
|  |  |  | wareIds =  filters.stream().map(Warehouse::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Warehouse> warehouses  = this.list(new LambdaQueryWrapper<Warehouse>().in(!wareIds.isEmpty(), Warehouse::getId, wareIds)); | 
|---|
|  |  |  | if (warehouses.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("仓库为空,请添加仓库后再操作!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<WarehouseAreas> warehouseAreas = warehouseAreasService.list(new LambdaQueryWrapper<>()); | 
|---|
|  |  |  | List<Long> list = warehouses.stream().map(Warehouse::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | List<WarehouseAreas> warehouseAreas = warehouseAreasService.list(new LambdaQueryWrapper<WarehouseAreas>() | 
|---|
|  |  |  | .like(isEmpty, WarehouseAreas::getName, !Objects.isNull(name) ? name.toString() : "") | 
|---|
|  |  |  | .in(!warehouses.isEmpty(), WarehouseAreas::getWarehouseId, list) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if (warehouseAreas.isEmpty()) { | 
|---|
|  |  |  | return warehouses; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | warehouses.forEach(warehouse -> { | 
|---|
|  |  |  | warehouse.setFlagWare(1); | 
|---|
|  |  |  | //仓库ID和库区ID有可能重复,拼接仓库ID,组成唯一索引 | 
|---|
|  |  |  | warehouse.setIndex(warehouse.getId()); | 
|---|
|  |  |  | List<WarehouseAreas> areas = new ArrayList<>(); | 
|---|
|  |  |  | warehouseAreas.forEach(warehouseAreas1 -> { | 
|---|
|  |  |  | if (warehouse.getId().equals(warehouseAreas1.getWarehouseId())) { | 
|---|
|  |  |  | warehouseAreas1.setFlagWare(0); | 
|---|
|  |  |  | //仓库ID和库区ID有可能重复,拼接仓库ID,组成唯一索引 | 
|---|
|  |  |  | String s = warehouseAreas1.getId() + "" + warehouseAreas1.getWarehouseId(); | 
|---|
|  |  |  | warehouseAreas1.setIndex(Long.parseLong(s)); | 
|---|
|  |  |  | areas.add(warehouseAreas1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|