package com.qianwen.smartman.modules.cps.service.impl;
|
|
import cn.hutool.core.lang.Snowflake;
|
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.google.common.collect.Lists;
|
import com.google.common.collect.Sets;
|
import java.lang.invoke.SerializedLambda;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Random;
|
import java.util.Set;
|
import java.util.function.Function;
|
import java.util.stream.Collectors;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import com.qianwen.smartman.common.constant.CommonGroupConstant;
|
import com.qianwen.smartman.common.constant.ExcelConstant;
|
import com.qianwen.smartman.common.constant.ToolingConstant;
|
import com.qianwen.smartman.common.enums.CommonGroupTypeEnum;
|
import com.qianwen.smartman.common.utils.MessageUtils;
|
import com.qianwen.smartman.common.websocket.entity.FmsArea;
|
import com.qianwen.core.excel.util.ExcelUtil;
|
import com.qianwen.core.mp.service.impl.BladeServiceImpl;
|
import com.qianwen.core.oss.model.BladeFile;
|
import com.qianwen.core.secure.utils.AuthUtil;
|
import com.qianwen.core.tool.support.Kv;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.cps.convert.TrayStorageConvert;
|
import com.qianwen.smartman.modules.cps.dto.RemoveIdsDTO;
|
import com.qianwen.smartman.modules.cps.entity.CommonGroupOfItem;
|
import com.qianwen.smartman.modules.cps.entity.Tray;
|
import com.qianwen.smartman.modules.cps.entity.TrayStorage;
|
import com.qianwen.smartman.modules.cps.entity.WarehouseArea;
|
import com.qianwen.smartman.modules.cps.entity.WarehouseStation;
|
import com.qianwen.smartman.modules.cps.excel.TrayStorageImport;
|
import com.qianwen.smartman.modules.cps.mapper.TrayStorageMapper;
|
import com.qianwen.smartman.modules.cps.service.ICommonGroupOfItemService;
|
import com.qianwen.smartman.modules.cps.service.ITrayService;
|
import com.qianwen.smartman.modules.cps.service.ITrayStorageService;
|
import com.qianwen.smartman.modules.cps.service.IWarehouseAreaService;
|
import com.qianwen.smartman.modules.cps.service.IWarehouseStationService;
|
import com.qianwen.smartman.modules.cps.utils.StringUtils;
|
import com.qianwen.smartman.modules.cps.utils.ThrowFun;
|
import com.qianwen.smartman.modules.cps.vo.TrayFixRemoveVO;
|
import com.qianwen.smartman.modules.cps.vo.TrayStorageAddVO;
|
import com.qianwen.smartman.modules.cps.vo.TrayStorageVO;
|
import com.qianwen.smartman.modules.cps.vo.WareTrayStorageVO;
|
import com.qianwen.smartman.modules.cps.vo.WarehouseAreaStationVO;
|
import com.qianwen.smartman.modules.fms.entity.FmsRealTimeTray;
|
import com.qianwen.smartman.modules.fms.enums.PositionTypeEnum;
|
import com.qianwen.smartman.modules.fms.service.IFmsRealTimeTrayService;
|
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.multipart.MultipartFile;
|
|
@Service
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/cps/service/impl/TrayStorageServiceImpl.class */
|
public class TrayStorageServiceImpl extends BladeServiceImpl<TrayStorageMapper, TrayStorage> implements ITrayStorageService {
|
private static final Logger log = LoggerFactory.getLogger(TrayStorageServiceImpl.class);
|
@Autowired
|
@Lazy
|
private ITrayService trayService;
|
@Autowired
|
@Lazy
|
private IWarehouseAreaService warehouseAreaService;
|
@Autowired
|
@Lazy
|
private IWarehouseStationService warehouseStationService;
|
@Autowired
|
private OssBuilder ossBuilder;
|
@Autowired
|
private IFmsRealTimeTrayService fmsRealTimeTrayService;
|
@Autowired
|
private ICommonGroupOfItemService itemService;
|
|
private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
|
String implMethodName = lambda.getImplMethodName();
|
boolean z = true;
|
switch (implMethodName.hashCode()) {
|
case -927447111:
|
if (implMethodName.equals("getTrayCode")) {
|
z = false;
|
break;
|
}
|
break;
|
case -75622813:
|
if (implMethodName.equals("getCode")) {
|
z = true;
|
break;
|
}
|
break;
|
case 98245393:
|
if (implMethodName.equals("getId")) {
|
z = true;
|
break;
|
}
|
break;
|
case 1929248666:
|
if (implMethodName.equals("getWarehouseCode")) {
|
z = true;
|
break;
|
}
|
break;
|
case 1956157548:
|
if (implMethodName.equals("getInUse")) {
|
z = true;
|
break;
|
}
|
break;
|
}
|
switch (z) {
|
case false:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/fms/entity/FmsRealTimeTray") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getTrayCode();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Tray") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getInUse();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Tray") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getInUse();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/WarehouseStation") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getWarehouseCode();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getId();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getId();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/WarehouseArea") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getCode();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Tray") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getCode();
|
};
|
}
|
break;
|
}
|
throw new IllegalArgumentException("Invalid lambda deserialization");
|
}
|
|
@Override // org.springblade.modules.cps.service.ITrayStorageService
|
public List<WareTrayStorageVO> listTray(Long id) {
|
return this.baseMapper.listTray(id);
|
}
|
|
@Override // org.springblade.modules.cps.service.ITrayStorageService
|
@Transactional(rollbackFor = {Exception.class})
|
public List<TrayStorageVO> addTrayStorage(TrayStorageAddVO vo) {
|
List<Long> trayIds = vo.getTrayIds();
|
Long warehouseStationId = vo.getWarehouseStationId();
|
List<TrayStorage> storages = (List) trayIds.stream().map(c -> {
|
return new TrayStorage().setTrayId(c).setWarehouseStationId(warehouseStationId);
|
}).collect(Collectors.toList());
|
saveBatch(storages);
|
this.trayService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
|
return v0.getInUse();
|
}, ToolingConstant.TOOLING_IN_USE)).in((v0) -> {
|
return v0.getId();
|
}, trayIds));
|
saveFmsRealTimeTray(storages);
|
return TrayStorageConvert.INSTANCE.convert(storages);
|
}
|
|
private void saveFmsRealTimeTray(List<TrayStorage> trayStorages) {
|
List<FmsRealTimeTray> fmsRealTimeTrays = Lists.newArrayList();
|
Set<Long> trayIds = Sets.newHashSet();
|
Set<Long> warehouseStationIds = Sets.newHashSet();
|
trayStorages.forEach(trayStorage -> {
|
trayIds.add(trayStorage.getTrayId());
|
warehouseStationIds.add(trayStorage.getWarehouseStationId());
|
});
|
Map<Long, String> trayMap = (Map) this.trayService.listByIds(trayIds).stream().collect(Collectors.toMap((v0) -> {
|
return v0.getId();
|
}, (v0) -> {
|
return v0.getCode();
|
}));
|
Map<Long, String> warehouseStationMap = (Map) this.warehouseStationService.getWarehouseStationList(warehouseStationIds).stream().collect(Collectors.toMap((v0) -> {
|
return v0.getId();
|
}, (v0) -> {
|
return v0.getWarehouseAreaCode();
|
}));
|
trayStorages.forEach(trayStorage2 -> {
|
FmsRealTimeTray fmsRealTimeTray = new FmsRealTimeTray().setTrayCode((String) trayMap.get(trayStorage2.getTrayId())).setCurrentPosition((String) warehouseStationMap.get(trayStorage2.getWarehouseStationId())).setCurrentType(PositionTypeEnum.LOCATION.getType());
|
fmsRealTimeTrays.add(fmsRealTimeTray);
|
});
|
this.fmsRealTimeTrayService.saveBatch(fmsRealTimeTrays);
|
}
|
|
@Override // org.springblade.modules.cps.service.ITrayStorageService
|
@Transactional(rollbackFor = {Exception.class})
|
public Boolean removeBind(TrayFixRemoveVO vo) {
|
List<RemoveIdsDTO> ids = vo.getIds();
|
if (Func.isEmpty(ids)) {
|
return false;
|
}
|
List<Long> idList = Lists.newArrayList();
|
List<Long> trayIds = Lists.newArrayList();
|
ids.forEach(s -> {
|
idList.add(s.getId());
|
trayIds.add(s.getOthersId());
|
});
|
int count = this.trayService.removeFaceFixture(trayIds);
|
ThrowFun.isTrue(count > 0).throwMessage(MessageUtils.message("cps.tray.face.banding.fixture", new Object[0]));
|
boolean remove = removeByIds(idList);
|
boolean update = this.trayService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
|
return v0.getInUse();
|
}, ToolingConstant.TOOLING_NOT_USE)).in((v0) -> {
|
return v0.getId();
|
}, trayIds));
|
Boolean fmsRealTimeTrayFlag = removeFmsRealTimeTray(trayIds);
|
return Boolean.valueOf(remove && update && fmsRealTimeTrayFlag.booleanValue());
|
}
|
|
private Boolean removeFmsRealTimeTray(List<Long> trayIds) {
|
List<Tray> trays = this.trayService.listByIds(trayIds);
|
List<String> trayCodes = (List) trays.stream().map((v0) -> {
|
return v0.getCode();
|
}).collect(Collectors.toList());
|
return Boolean.valueOf(this.fmsRealTimeTrayService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getTrayCode();
|
}, trayCodes)));
|
}
|
|
@Override // org.springblade.modules.cps.service.ITrayStorageService
|
public List<WarehouseAreaStationVO> areaStationTree() {
|
return this.warehouseAreaService.areaStationTree();
|
}
|
|
@Override // org.springblade.modules.cps.service.ITrayStorageService
|
public List<FmsArea> fmsAreaStationTree() {
|
return this.warehouseAreaService.fmsAreaStationTree();
|
}
|
|
@Override // org.springblade.modules.cps.service.ITrayStorageService
|
@Transactional(rollbackFor = {Exception.class})
|
public BladeFile importTrayStorage(MultipartFile file) {
|
List<TrayStorageImport> rawData = ExcelUtil.read(file, 0, 2, TrayStorageImport.class);
|
ThrowFun.isTrue(Func.isEmpty(rawData)).throwMessage(MessageUtils.message("excel.import.data.can.not.be.null", new Object[0]));
|
ThrowFun.isTrue(rawData.size() > 200).throwMessage(MessageUtils.message("excel.import.size.failed", new Object[0]));
|
Map<String, WarehouseArea> areaMap = Kv.newMap();
|
List<WarehouseArea> needSaveArea = Lists.newArrayList();
|
Map<String, WarehouseStation> warehouseStationMap = Kv.newMap();
|
List<WarehouseStation> needSaveStation = Lists.newArrayList();
|
Map<String, Tray> trayMap = Kv.newMap();
|
List<Tray> needSaveTray = Lists.newArrayList();
|
getTrayStorage(rawData, areaMap, warehouseStationMap, trayMap);
|
List<TrayStorageImport> failExcel = Lists.newArrayList();
|
for (TrayStorageImport data : rawData) {
|
boolean validImport = validImport(data, failExcel, areaMap, needSaveArea, warehouseStationMap, needSaveStation, trayMap, needSaveTray);
|
if (validImport) {
|
break;
|
}
|
}
|
if (Func.isNotEmpty(failExcel)) {
|
return exportFailFile(failExcel);
|
}
|
Map<String, WarehouseArea> needSaveAreaMap = (Map) needSaveArea.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getCode();
|
}, Function.identity(), v1, v2 -> {
|
return v1;
|
}));
|
Map<String, WarehouseStation> needSaveStationMap = (Map) needSaveStation.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getWarehouseCode();
|
}, Function.identity(), v12, v22 -> {
|
return v12;
|
}));
|
if (Func.isNotEmpty(needSaveArea)) {
|
this.warehouseAreaService.saveBatch(needSaveAreaMap.values());
|
areaMap.putAll(needSaveAreaMap);
|
}
|
if (Func.isNotEmpty(needSaveStation)) {
|
this.warehouseStationService.saveBatch(needSaveStationMap.values());
|
warehouseStationMap.putAll(needSaveStationMap);
|
}
|
if (Func.isNotEmpty(needSaveTray)) {
|
this.trayService.saveBatch(needSaveTray);
|
List<CommonGroupOfItem> items = (List) needSaveTray.stream().map(tray -> {
|
return CommonGroupOfItem.builder().groupId(105L).itemId(tray.getId()).groupType(CommonGroupTypeEnum.TRAY.getName()).groupCategory(CommonGroupConstant.DEFAULT_CATEGORY).build();
|
}).collect(Collectors.toList());
|
this.itemService.saveBatch(items);
|
trayMap.putAll((Map) needSaveTray.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getCode();
|
}, v -> {
|
return v;
|
})));
|
}
|
saveTrayStorage(rawData, warehouseStationMap, trayMap);
|
return null;
|
}
|
|
private void saveTrayStorage(List<TrayStorageImport> rawData, Map<String, WarehouseStation> warehouseStationMap, Map<String, Tray> trayMap) {
|
List<TrayStorage> trayStorageList = Lists.newArrayList();
|
List<Tray> trays = Lists.newArrayList();
|
rawData.forEach(data -> {
|
WarehouseStation warehouseStation = (WarehouseStation) warehouseStationMap.get(data.getLocationCode());
|
Tray tray = (Tray) trayMap.get(data.getTrayCode());
|
tray.setInUse(ToolingConstant.TOOLING_IN_USE);
|
trays.add(tray);
|
TrayStorage trayStorage = new TrayStorage().setTrayId(tray.getId()).setWarehouseStationId(warehouseStation.getId());
|
trayStorageList.add(trayStorage);
|
});
|
List<TrayStorage> trayStorages = list();
|
Map<String, TrayStorage> trayFixtureMap = (Map) trayStorages.stream().collect(Collectors.toMap(k -> {
|
return StringUtils.getKey(k.getTrayId(), k.getWarehouseStationId());
|
}, v -> {
|
return v;
|
}));
|
List<TrayStorage> collect = (List) trayStorageList.stream().distinct().filter(c -> {
|
return !trayFixtureMap.containsKey(StringUtils.getKey(c.getTrayId(), c.getWarehouseStationId()));
|
}).collect(Collectors.toList());
|
if (Func.isNotEmpty(collect)) {
|
saveBatch(collect);
|
saveFmsRealTimeTray(collect);
|
}
|
if (Func.isNotEmpty(trays)) {
|
this.trayService.updateBatchById(trays);
|
}
|
}
|
|
private BladeFile exportFailFile(List<TrayStorageImport> failExcel) {
|
MultipartFile multipartFile = ExcelUtil.exportFillTemplateToMultipartFile(ExcelConstant.DIRECTORY + "trayStorageFailTemplate" + ExcelConstant.SUFFIX, MessageUtils.message("excel.import.failed.report.name", new Object[0]) + ExcelConstant.SUFFIX, ExcelConstant.SHEET, failExcel, (Object) null, (AbstractMergeStrategy) null);
|
return this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
|
}
|
|
public boolean validImport(TrayStorageImport data, List<TrayStorageImport> failExcel, Map<String, WarehouseArea> areaMap, List<WarehouseArea> needSaveArea, Map<String, WarehouseStation> stationMap, List<WarehouseStation> needSaveStation, Map<String, Tray> trayMap, List<Tray> needSaveTray) {
|
Snowflake snowflake = new Snowflake(new Random().nextInt(4) + 1, new Random().nextInt(4) + 1, true);
|
String areaCode = data.getAreaCode();
|
if (Func.isBlank(areaCode)) {
|
data.setFailReason(MessageUtils.message("excel.export.area.code.not.null", new Object[0]));
|
failExcel.add(data);
|
return true;
|
}
|
String areaName = data.getAreaName();
|
if (Func.isBlank(areaName)) {
|
data.setFailReason(MessageUtils.message("excel.export.area.name.not.null", new Object[0]));
|
failExcel.add(data);
|
return true;
|
}
|
WarehouseArea area = areaMap.get(areaCode);
|
if (Func.isNull(area)) {
|
WarehouseArea houseArea = new WarehouseArea().setTenantId(AuthUtil.getTenantId()).setCode(areaCode).setName(areaName).setParentId(1L);
|
houseArea.setId(Long.valueOf(snowflake.nextId()));
|
needSaveArea.add(houseArea);
|
int size = 0;
|
for (WarehouseArea warehouseArea : needSaveArea) {
|
String code = warehouseArea.getCode();
|
String name = warehouseArea.getName();
|
if (code.equals(areaCode) && !name.equals(areaName)) {
|
size++;
|
}
|
}
|
if (size > 0) {
|
data.setFailReason(MessageUtils.message("excel.export.file.area.code.name.system.exists", new Object[0]));
|
failExcel.add(data);
|
return true;
|
}
|
area = houseArea;
|
} else if (!areaName.equals(area.getName())) {
|
data.setFailReason(MessageUtils.message("excel.export.area.code.name.system.exists", new Object[0]));
|
failExcel.add(data);
|
return true;
|
}
|
String locationCode = data.getLocationCode();
|
if (Func.isBlank(locationCode)) {
|
data.setFailReason(MessageUtils.message("excel.export.station.code.not.be.null", new Object[0]));
|
failExcel.add(data);
|
return true;
|
}
|
String locationName = data.getLocationName();
|
if (Func.isBlank(locationName)) {
|
data.setFailReason(MessageUtils.message("excel.export.station.name.not.be.null", new Object[0]));
|
failExcel.add(data);
|
return true;
|
}
|
WarehouseStation station = stationMap.get(locationCode);
|
if (Func.isNull(station)) {
|
WarehouseStation houseStation = new WarehouseStation().setTenantId(AuthUtil.getTenantId()).setAreaId(area.getId()).setWarehouseAreaName(areaName).setWarehouseAreaCode(areaCode).setWarehouseName(locationName).setWarehouseCode(locationCode);
|
houseStation.setId(Long.valueOf(snowflake.nextId()));
|
needSaveStation.add(houseStation);
|
int size2 = 0;
|
for (WarehouseStation warehouseStation : needSaveStation) {
|
String code2 = warehouseStation.getWarehouseCode();
|
String name2 = warehouseStation.getWarehouseName();
|
if (code2.equals(locationCode) && !name2.equals(locationName)) {
|
size2++;
|
}
|
}
|
if (size2 > 0) {
|
data.setFailReason(MessageUtils.message("excel.export.file.station.code.name.system.exists", new Object[0]));
|
failExcel.add(data);
|
return true;
|
}
|
} else if (!locationName.equals(station.getWarehouseName())) {
|
data.setFailReason(MessageUtils.message("excel.export.station.system.exists", new Object[0]));
|
failExcel.add(data);
|
return true;
|
}
|
String trayCode = data.getTrayCode();
|
if (Func.isBlank(trayCode)) {
|
data.setFailReason(MessageUtils.message("excel.export.tray.code.not.be.null", new Object[0]));
|
failExcel.add(data);
|
return true;
|
}
|
Tray tray = trayMap.get(trayCode);
|
if (Func.isEmpty(tray)) {
|
String trayName = data.getTrayName();
|
Tray newTray = new Tray().setCode(trayCode).setName(Func.isBlank(trayName) ? trayCode : trayName).setTrayStatus(1).setInUse(0).setAvailability(1);
|
needSaveTray.add(newTray);
|
int size3 = 0;
|
for (Tray trays : needSaveTray) {
|
String code3 = trays.getCode();
|
if (code3.equals(trayCode)) {
|
size3++;
|
}
|
}
|
if (size3 > 1) {
|
data.setFailReason(MessageUtils.message("excel.export.file.tray.code.name.system.exists", new Object[0]));
|
failExcel.add(data);
|
return true;
|
}
|
return false;
|
} else if (Func.isNotBlank(data.getTrayName()) && !tray.getName().equals(data.getTrayName())) {
|
data.setFailReason(MessageUtils.message("excel.export.tray.code.system.exists", new Object[0]));
|
failExcel.add(data);
|
return true;
|
} else if (ToolingConstant.TOOLING_IN_USE.equals(tray.getInUse())) {
|
data.setFailReason(MessageUtils.message("excel.export.tray.in.use", new Object[0]));
|
failExcel.add(data);
|
return true;
|
} else {
|
return false;
|
}
|
}
|
|
private void getTrayStorage(List<TrayStorageImport> rawData, Map<String, WarehouseArea> areaMap, Map<String, WarehouseStation> warehouseStationMap, Map<String, Tray> trayMap) {
|
Wrapper lambdaQuery = Wrappers.lambdaQuery();
|
Wrapper lambdaQuery2 = Wrappers.lambdaQuery();
|
Wrapper lambdaQuery3 = Wrappers.lambdaQuery();
|
boolean flag1 = false;
|
boolean flag2 = false;
|
boolean flag3 = false;
|
for (TrayStorageImport data : rawData) {
|
if (requiredArea(data)) {
|
if (flag1) {
|
lambdaQuery.or();
|
}
|
flag1 = true;
|
lambdaQuery.eq((v0) -> {
|
return v0.getCode();
|
}, data.getAreaCode());
|
}
|
if (requiredLocation(data)) {
|
if (flag2) {
|
lambdaQuery2.or();
|
}
|
flag2 = true;
|
lambdaQuery2.eq((v0) -> {
|
return v0.getWarehouseCode();
|
}, data.getLocationCode());
|
}
|
if (requiredTray(data)) {
|
if (flag3) {
|
lambdaQuery3.or();
|
}
|
flag3 = true;
|
lambdaQuery3.eq((v0) -> {
|
return v0.getCode();
|
}, data.getTrayCode());
|
}
|
}
|
String sqlSegment1 = lambdaQuery.getSqlSegment();
|
if (Func.isNotEmpty(sqlSegment1)) {
|
List<WarehouseArea> areaList = this.warehouseAreaService.list(lambdaQuery);
|
if (Func.isNotEmpty(areaList)) {
|
Map<String, WarehouseArea> map = (Map) areaList.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getCode();
|
}, v -> {
|
return v;
|
}));
|
areaMap.putAll(map);
|
}
|
}
|
String sqlSegment2 = lambdaQuery2.getSqlSegment();
|
if (Func.isNotEmpty(sqlSegment2)) {
|
List<WarehouseStation> warehouseStations = this.warehouseStationService.list(lambdaQuery2);
|
if (Func.isNotEmpty(warehouseStations)) {
|
Map<String, WarehouseStation> map1 = (Map) warehouseStations.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getWarehouseCode();
|
}, v2 -> {
|
return v2;
|
}));
|
warehouseStationMap.putAll(map1);
|
}
|
}
|
String sqlSegment3 = lambdaQuery3.getSqlSegment();
|
if (Func.isNotEmpty(sqlSegment3)) {
|
List<Tray> trays = this.trayService.list(lambdaQuery3);
|
if (Func.isNotEmpty(trays)) {
|
Map<String, Tray> map2 = (Map) trays.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getCode();
|
}, v3 -> {
|
return v3;
|
}));
|
trayMap.putAll(map2);
|
}
|
}
|
}
|
|
private boolean requiredArea(TrayStorageImport data) {
|
return Func.isNotBlank(data.getAreaCode()) && Func.isNotBlank(data.getAreaName());
|
}
|
|
private boolean requiredLocation(TrayStorageImport data) {
|
return Func.isNotBlank(data.getLocationCode()) && Func.isNotBlank(data.getLocationName());
|
}
|
|
private boolean requiredTray(TrayStorageImport data) {
|
return Func.isNotBlank(data.getTrayCode());
|
}
|
}
|