提交 de90b512 authored 作者: zjm's avatar zjm

Merge branch 'master' of git.yfzx.zjtys.com.cn:matrix/device-back into dev

......@@ -259,222 +259,224 @@ public class StorageBillController {
return ResultUtil.success(DeviceSeqUtil.createDeviceSeqs(s,num));
}
// @ApiOperation(value = "选择入库型号数量", notes = "可以通过这个接口选择入库型号数量")
// @PostMapping(value = "/addStorageDetail")
// public ResponseEntity addStorageDetail(@RequestBody List<StorageBillDetailVo> list) {
// //存放所有的列装
// List<PackingLibrary> libraryEntities = new ArrayList<>();
//
// Map<Integer, List<PackingLibrary>> map = new HashMap<>();
// //所有的序列号
// List<String> seqs = new ArrayList<>();
// for (StorageBillDetailVo s : list) {
// if (s.getStorageCount()>0) {
// //序列号区间
// List<String> strings = DeviceSeqUtil.createDeviceSeqs(s.getSeqInterval(), s.getStorageCount());
// //生产号区间
// List<String> strings3 = DeviceSeqUtil.createDeviceSeqs(s.getProdInterval(), s.getStorageCount());
// List<List<String>> sons = new ArrayList<>();
// List<List<String>> sons2 = new ArrayList<>();
// List<List<String>> sons3 = new ArrayList<>();
// List<List<String>> sons4 = new ArrayList<>();
// int count = 1;
// //入库的数量
// Integer deviceNum = s.getStorageCount();
//
// while (deviceNum >= count) {
// PackingLibrary packingLibraryEntity = new PackingLibrary();
// BeanUtils.copyProperties(packingLibraryService.getOne(s.getPackingId()), packingLibraryEntity);
// packingLibraryEntity.setCorresponding(count);
//// packingLibraryEntity.setIsSinglePart(1);
// if (!strings3.isEmpty()) {
// packingLibraryEntity.setProdNumber(strings3.get(0));
// strings3.remove(0);
// }
// if (!strings.isEmpty()) {
// if (deviceLibraryDao.getAllBySeqNumber(strings.get(0)).size() > 0) {
// throw new ApiException("序列号" + strings.get(0) + "已存在");
// }
// if (seqs.contains(strings.get(0))){
// throw new ApiException("序列号" + strings.get(0) + "不能重复");
// }
// packingLibraryEntity.setSeq(strings.get(0));
// strings.remove(0);
// }
// seqs.add(packingLibraryEntity.getSeq());
// libraryEntities.add(packingLibraryEntity);
// if (s.getList() != null && s.getList().size() != 0) {
// for (int j = 0; j < s.getList().size(); j++) {
// StorageBillDetailVo s2 = s.getList().get(j);
// if (j >= sons.size()) {
// sons.add(DeviceSeqUtil.createDeviceSeqs(s2.getSeqInterval(), s2.getStorageCount()));
// sons2.add(DeviceSeqUtil.createDeviceSeqs(s2.getProdInterval(), s2.getStorageCount()));
// }
// packingLibraryEntity = packingLibraryService.getOne(s2.getPackingId());
// List<String> strings2 = sons.get(j);
// List<String> strings1 = sons2.get(j);
// if (s2.getStorageCount() >= count) {
// packingLibraryEntity.setIsSinglePart(0);
// packingLibraryEntity.setCorresponding(count);
// if (!strings2.isEmpty()) {
// if (deviceLibraryDao.getAllBySeqNumber(strings2.get(0)).size() > 0) {
// throw new ApiException("序列号" + strings2.get(0) + "已存在");
// }
// if (seqs.contains(strings2.get(0))){
// throw new ApiException("序列号" + strings2.get(0) + "不能重复");
// }
// packingLibraryEntity.setSeq(strings2.get(0));
// strings2.remove(0);
// }
// if (!strings1.isEmpty()) {
// packingLibraryEntity.setProdNumber(strings1.get(0));
// strings1.remove(0);
// }
// seqs.add(packingLibraryEntity.getSeq());
// libraryEntities.add(packingLibraryEntity);
// }
// if (s2.getStorageCount() - strings2.size() == deviceNum) {
// List<PackingLibrary> packingLibraries = new ArrayList<>();
// for (int i = 0; i < s2.getStorageCount() - deviceNum; i++) {
// packingLibraryEntity = packingLibraryService.getOne(s2.getPackingId());
// packingLibraryEntity.setCorresponding(0);
//// packingLibraryEntity.setIsSinglePart(1);
//
// if (!strings2.isEmpty()) {
// if (deviceLibraryDao.getAllBySeqNumber(strings2.get(0)).size() > 0) {
// throw new ApiException("序列号" + strings2.get(0) + "已存在");
// }
// if (seqs.contains(strings2.get(0))){
// throw new ApiException("序列号" + strings2.get(0) + "不能重复");
// }
// packingLibraryEntity.setSeq(strings2.get(0));
// strings2.remove(0);
// }
// if (!strings1.isEmpty()) {
// packingLibraryEntity.setProdNumber(strings1.get(0));
// strings1.remove(0);
// }
// seqs.add(packingLibraryEntity.getSeq());
// packingLibraries.add(packingLibraryEntity);
// }
// map.put(s2.getPackingId(), packingLibraries);
// }
// if (s2.getList() != null && s2.getList().size() != 0) {
// for (int k = 0; k < s2.getList().size(); k++) {
// StorageBillDetailVo s3 = s2.getList().get(k);
// if (k >= sons3.size()) {
// sons3.add(DeviceSeqUtil.createDeviceSeqs(s3.getSeqInterval(), s3.getStorageCount()));
// sons4.add(DeviceSeqUtil.createDeviceSeqs(s3.getProdInterval(), s3.getStorageCount()));
// }
// packingLibraryEntity = packingLibraryService.getOne(s3.getPackingId());
// List<String> strings4 = sons3.get(k);
// List<String> strings5 = sons4.get(k);
// if (s3.getStorageCount() >= count) {
//// packingLibraryEntity.setIsSinglePart(0);
// packingLibraryEntity.setCorresponding(count);
//
// if (!strings4.isEmpty()) {
// if (deviceLibraryDao.getAllBySeqNumber(strings4.get(0)).size() > 0) {
// throw new ApiException("序列号" + strings4.get(0) + "已存在");
// }
// if (seqs.contains(strings4.get(0))){
// throw new ApiException("序列号" + strings4.get(0) + "不能重复");
// }
// packingLibraryEntity.setSeq(strings4.get(0));
// strings4.remove(0);
// }
// if (!strings5.isEmpty()) {
// packingLibraryEntity.setProdNumber(strings5.get(0));
// strings5.remove(0);
// }
// seqs.add(packingLibraryEntity.getSeq());
// libraryEntities.add(packingLibraryEntity);
// }
// if (s3.getStorageCount() - strings4.size() == deviceNum) {
// List<PackingLibrary> packingLibraries = new ArrayList<>();
// for (int i = 0; i < s3.getStorageCount() - deviceNum; i++) {
// packingLibraryEntity = packingLibraryService.getOne(s3.getPackingId());
// packingLibraryEntity.setCorresponding(0);
//// packingLibraryEntity.setIsSinglePart(1);
//
//
// if (!strings4.isEmpty()) {
// if (deviceLibraryDao.getAllBySeqNumber(strings4.get(0)).size() > 0) {
// throw new ApiException("序列号" + strings4.get(0) + "已存在");
// }
// if (seqs.contains(strings4.get(0))){
// throw new ApiException("序列号" + strings4.get(0) + "不能重复");
// }
// packingLibraryEntity.setSeq(strings4.get(0));
// strings4.remove(0);
// }
// if (!strings5.isEmpty()) {
// packingLibraryEntity.setProdNumber(strings5.get(0));
// strings5.remove(0);
// }
// seqs.add(packingLibraryEntity.getSeq());
// packingLibraries.add(packingLibraryEntity);
// }
// map.put(s3.getPackingId(), packingLibraries);
// }
// }
//
// }
// }
//
// }
// count = count + 1;
// }
// }
// }
// for (Integer i : map.keySet()) {
// libraryEntities.addAll(map.get(i));
// }
// return ResultUtil.success(libraryEntities);
// }
@ApiOperation(value = "选择入库型号数量", notes = "可以通过这个接口选择入库型号数量")
@PostMapping(value = "/addStorageDetail")
public ResponseEntity<List<BackCreateSeqVo>> addStorageDetail(@RequestBody List<CreateSeqVo> createSeqVos) {
List<BackCreateSeqVo> backCreateSeqVos = new ArrayList<>();
//当手动输入序列号的时候 需要进行遍历成集合
createSeqVos.forEach(createSeqVo -> {
if(createSeqVo.getSeqList().isEmpty()){
List<String> deviceSeqs = DeviceSeqUtil.selectDeviceSeqs(createSeqVo.getSeqInterval());
createSeqVo.setSeqList(deviceSeqs);
}
});
//做校验 数量跟序列号
createSeqVos.forEach(createSeqVo -> {
if (createSeqVo.getStorageCount()!=createSeqVo.getSeqList().size()){
throw new ApiException("序列号与入库数量不匹配");
}
});
//做校验 检查序列号是否重复
//1.查询出所有的序列号
List<String> allSeqList =
cacheLibraryService.getAllDeviceLibraryList().stream().map(DeviceLibrary::getSeqNumber).collect(Collectors.toList());
createSeqVos.forEach(createSeqVo -> {
List<String> seqList = createSeqVo.getSeqList();
seqList.forEach(s -> {
if (allSeqList.contains(s)){
throw new ApiException("序列号"+s+"已存在");
public ResponseEntity addStorageDetail(@RequestBody List<StorageBillDetailVo> list) {
//存放所有的列装
List<PackingLibrary> libraryEntities = new ArrayList<>();
Map<Integer, List<PackingLibrary>> map = new HashMap<>();
//所有的序列号
List<String> seqs = new ArrayList<>();
for (StorageBillDetailVo s : list) {
if (s.getStorageCount()>0) {
//序列号区间
List<String> strings = DeviceSeqUtil.createDeviceSeqs(s.getSeqInterval(), s.getStorageCount());
//生产号区间
List<String> strings3 = DeviceSeqUtil.createDeviceSeqs(s.getProdInterval(), s.getStorageCount());
List<List<String>> sons = new ArrayList<>();
List<List<String>> sons2 = new ArrayList<>();
List<List<String>> sons3 = new ArrayList<>();
List<List<String>> sons4 = new ArrayList<>();
int count = 1;
//入库的数量
Integer deviceNum = s.getStorageCount();
while (deviceNum >= count) {
PackingLibrary packingLibraryEntity = new PackingLibrary();
BeanUtils.copyProperties(packingLibraryService.getOne(s.getPackingId()), packingLibraryEntity);
packingLibraryEntity.setCorresponding(count);
packingLibraryEntity.setIsSinglePart(1);
if (!strings3.isEmpty()) {
packingLibraryEntity.setProdNumber(strings3.get(0));
strings3.remove(0);
}
if (!strings.isEmpty()) {
if (deviceLibraryDao.getAllBySeqNumber(strings.get(0)).size() > 0) {
throw new ApiException("序列号" + strings.get(0) + "已存在");
}
if (seqs.contains(strings.get(0))){
throw new ApiException("序列号" + strings.get(0) + "不能重复");
}
packingLibraryEntity.setSeq(strings.get(0));
strings.remove(0);
}
seqs.add(packingLibraryEntity.getSeq());
libraryEntities.add(packingLibraryEntity);
if (s.getList() != null && s.getList().size() != 0) {
for (int j = 0; j < s.getList().size(); j++) {
StorageBillDetailVo s2 = s.getList().get(j);
if (j >= sons.size()) {
sons.add(DeviceSeqUtil.createDeviceSeqs(s2.getSeqInterval(), s2.getStorageCount()));
sons2.add(DeviceSeqUtil.createDeviceSeqs(s2.getProdInterval(), s2.getStorageCount()));
}
packingLibraryEntity = packingLibraryService.getOne(s2.getPackingId());
List<String> strings2 = sons.get(j);
List<String> strings1 = sons2.get(j);
if (s2.getStorageCount() >= count) {
packingLibraryEntity.setIsSinglePart(0);
packingLibraryEntity.setCorresponding(count);
if (!strings2.isEmpty()) {
if (deviceLibraryDao.getAllBySeqNumber(strings2.get(0)).size() > 0) {
throw new ApiException("序列号" + strings2.get(0) + "已存在");
}
if (seqs.contains(strings2.get(0))){
throw new ApiException("序列号" + strings2.get(0) + "不能重复");
}
packingLibraryEntity.setSeq(strings2.get(0));
strings2.remove(0);
}
if (!strings1.isEmpty()) {
packingLibraryEntity.setProdNumber(strings1.get(0));
strings1.remove(0);
}
seqs.add(packingLibraryEntity.getSeq());
libraryEntities.add(packingLibraryEntity);
}
if (s2.getStorageCount() - strings2.size() == deviceNum) {
List<PackingLibrary> packingLibraries = new ArrayList<>();
for (int i = 0; i < s2.getStorageCount() - deviceNum; i++) {
packingLibraryEntity = packingLibraryService.getOne(s2.getPackingId());
packingLibraryEntity.setCorresponding(0);
packingLibraryEntity.setIsSinglePart(1);
if (!strings2.isEmpty()) {
if (deviceLibraryDao.getAllBySeqNumber(strings2.get(0)).size() > 0) {
throw new ApiException("序列号" + strings2.get(0) + "已存在");
}
if (seqs.contains(strings2.get(0))){
throw new ApiException("序列号" + strings2.get(0) + "不能重复");
}
packingLibraryEntity.setSeq(strings2.get(0));
strings2.remove(0);
}
if (!strings1.isEmpty()) {
packingLibraryEntity.setProdNumber(strings1.get(0));
strings1.remove(0);
}
seqs.add(packingLibraryEntity.getSeq());
packingLibraries.add(packingLibraryEntity);
}
map.put(s2.getPackingId(), packingLibraries);
}
if (s2.getList() != null && s2.getList().size() != 0) {
for (int k = 0; k < s2.getList().size(); k++) {
StorageBillDetailVo s3 = s2.getList().get(k);
if (k >= sons3.size()) {
sons3.add(DeviceSeqUtil.createDeviceSeqs(s3.getSeqInterval(), s3.getStorageCount()));
sons4.add(DeviceSeqUtil.createDeviceSeqs(s3.getProdInterval(), s3.getStorageCount()));
}
packingLibraryEntity = packingLibraryService.getOne(s3.getPackingId());
List<String> strings4 = sons3.get(k);
List<String> strings5 = sons4.get(k);
if (s3.getStorageCount() >= count) {
packingLibraryEntity.setIsSinglePart(0);
packingLibraryEntity.setCorresponding(count);
if (!strings4.isEmpty()) {
if (deviceLibraryDao.getAllBySeqNumber(strings4.get(0)).size() > 0) {
throw new ApiException("序列号" + strings4.get(0) + "已存在");
}
if (seqs.contains(strings4.get(0))){
throw new ApiException("序列号" + strings4.get(0) + "不能重复");
}
packingLibraryEntity.setSeq(strings4.get(0));
strings4.remove(0);
}
if (!strings5.isEmpty()) {
packingLibraryEntity.setProdNumber(strings5.get(0));
strings5.remove(0);
}
seqs.add(packingLibraryEntity.getSeq());
libraryEntities.add(packingLibraryEntity);
}
if (s3.getStorageCount() - strings4.size() == deviceNum) {
List<PackingLibrary> packingLibraries = new ArrayList<>();
for (int i = 0; i < s3.getStorageCount() - deviceNum; i++) {
packingLibraryEntity = packingLibraryService.getOne(s3.getPackingId());
packingLibraryEntity.setCorresponding(0);
packingLibraryEntity.setIsSinglePart(1);
if (!strings4.isEmpty()) {
if (deviceLibraryDao.getAllBySeqNumber(strings4.get(0)).size() > 0) {
throw new ApiException("序列号" + strings4.get(0) + "已存在");
}
if (seqs.contains(strings4.get(0))){
throw new ApiException("序列号" + strings4.get(0) + "不能重复");
}
packingLibraryEntity.setSeq(strings4.get(0));
strings4.remove(0);
}
if (!strings5.isEmpty()) {
packingLibraryEntity.setProdNumber(strings5.get(0));
strings5.remove(0);
}
seqs.add(packingLibraryEntity.getSeq());
packingLibraries.add(packingLibraryEntity);
}
map.put(s3.getPackingId(), packingLibraries);
}
}
}
}
}
count = count + 1;
}
});
});
// 开始拆分装备
for (CreateSeqVo createSeqVo : createSeqVos) {
List<String> seqList = createSeqVo.getSeqList();
for (int i = 0; i < seqList.size(); i++) {
BackCreateSeqVo backCreateSeqVo = new BackCreateSeqVo();
BeanUtils.copyProperties(createSeqVo,backCreateSeqVo);
backCreateSeqVo.setSeqNumber(seqList.get(i));
backCreateSeqVos.add(backCreateSeqVo);
}
}
return ResponseEntity.ok(backCreateSeqVos);
for (Integer i : map.keySet()) {
libraryEntities.addAll(map.get(i));
}
return ResultUtil.success(libraryEntities);
}
// @ApiOperation(value = "选择入库型号数量", notes = "可以通过这个接口选择入库型号数量")
// @PostMapping(value = "/addStorageDetail")
// public ResponseEntity<List<BackCreateSeqVo>> addStorageDetail(@RequestBody List<CreateSeqVo> createSeqVos) {
// List<BackCreateSeqVo> backCreateSeqVos = new ArrayList<>();
// //当手动输入序列号的时候 需要进行遍历成集合
// createSeqVos.forEach(createSeqVo -> {
// if(createSeqVo.getSeqList().isEmpty()){
// List<String> deviceSeqs = DeviceSeqUtil.selectDeviceSeqs(createSeqVo.getSeqInterval());
// createSeqVo.setSeqList(deviceSeqs);
// }
// });
// //做校验 数量跟序列号
// createSeqVos.forEach(createSeqVo -> {
// if (createSeqVo.getStorageCount()!=createSeqVo.getSeqList().size()){
// throw new ApiException("序列号与入库数量不匹配");
// }
// });
// //做校验 检查序列号是否重复
// //1.查询出所有的序列号
// List<String> allSeqList =
// cacheLibraryService.getAllDeviceLibraryList().stream().map(DeviceLibrary::getSeqNumber).collect(Collectors.toList());
// createSeqVos.forEach(createSeqVo -> {
// List<String> seqList = createSeqVo.getSeqList();
// seqList.forEach(s -> {
// if (allSeqList.contains(s)){
// throw new ApiException("序列号"+s+"已存在");
// }
// });
// });
// // 开始拆分装备
// for (CreateSeqVo createSeqVo : createSeqVos) {
// List<String> seqList = createSeqVo.getSeqList();
// for (int i = 0; i < seqList.size(); i++) {
// BackCreateSeqVo backCreateSeqVo = new BackCreateSeqVo();
// BeanUtils.copyProperties(createSeqVo,backCreateSeqVo);
// backCreateSeqVo.setSeqNumber(seqList.get(i));
// backCreateSeqVos.add(backCreateSeqVo);
// }
// }
// return ResponseEntity.ok(backCreateSeqVos);
//
// }
@ApiOperation(value = "办结后添加其他单据", notes = "办结后添加其他单据")
@PostMapping(value = "/addOtherFiles/{taskId}")
public ResponseEntity addOtherFiles(@PathVariable("taskId") int taskId, @RequestBody List<FileRet> fileRets){
......@@ -560,243 +562,248 @@ public class StorageBillController {
String currentUserUnitName = userUtils.getCurrentUserUnitName();
StopWatch stopWatch = new StopWatch();
stopWatch.start();
//保存不需要绑定的装备集合
List<DeviceLibrary> batchEntitiesIsBinding1 = new ArrayList<>();
//保存需要绑定总的集合
List<DeviceLibrary> batchEntitiesIsBinding0 = new ArrayList<>();
//保存单独的配件的集合
List<DeviceLibrary> batchEntitiesSinglePart = new ArrayList<>();
//保存父子集合
List<DeviceLibrary> batchEntities = new ArrayList<>();
// for (DeviceLibrarySaveVo d : storageBillSaveVo.getDeviceLibrarySaveVoList()) {
// if (d.getRfidCardId()==null|| "".equals(d.getRfidCardId()) ||deviceLibraryDao.getAllByRfidCardId(d.getRfidCardId()).size()==0) {
// DeviceLibrary saveEntity = new DeviceLibrary();
// DeviceLibrary deviceLibraryEntity = new DeviceLibrary();
// PackingLibrary packingLibraryEntity = packingLibraryService.getOne(d.getPackingId());
// BeanUtils.copyProperties(packingLibraryEntity, deviceLibraryEntity);
// deviceLibraryEntity.setId(null);
// deviceLibraryEntity.setLifeStatus(2);//设置为在库状态
// BeanUtils.copyProperties(d, deviceLibraryEntity);
// deviceLibraryEntity.setStorageBillId(storageBillId);
// deviceLibraryEntity.setLocationUnit(currentUserUnitName);
// deviceLibraryEntity.setOwnUnit(currentUserUnitName);
// deviceLibraryEntity.setPartParentId(null);
//
// //如果不是单独的配件,设置父装备id为上一个装备的id 0-不是,1-是 0 装备 1 配件
// if (d.getIsBinding() == 0){
// if (d.getIsSinglePart() == 0) {
// //0 不是,1:是
// if (deviceLibraryEntity.getIsPart() == 0) {
// saveEntity = deviceLibraryService.addEntity(deviceLibraryEntity);
// }
// if (deviceLibraryEntity.getIsPart() == 1) {
// if (parentPackingId!=null) {
// for (int i = saveDevices.size()-1;i>=0;i--){
// if (packingLibraryEntity.getPartParentId().equals(saveDevices.get(i).getPackingId())){
// deviceLibraryEntity.setPartParentId(saveDevices.get(i).getId());
// break;
// }
// }
// //保存不需要绑定的装备集合
// List<DeviceLibrary> batchEntitiesIsBinding1 = new ArrayList<>();
// //保存需要绑定总的集合
// List<DeviceLibrary> batchEntitiesIsBinding0 = new ArrayList<>();
// //保存单独的配件的集合
// List<DeviceLibrary> batchEntitiesSinglePart = new ArrayList<>();
// //保存父子集合
// List<DeviceLibrary> batchEntities = new ArrayList<>();
for (DeviceLibrarySaveVo d : storageBillSaveVo.getDeviceLibrarySaveVoList()) {
if (d.getRfidCardId()==null|| "".equals(d.getRfidCardId()) ||deviceLibraryDao.getAllByRfidCardId(d.getRfidCardId()).size()==0) {
DeviceLibrary saveEntity = new DeviceLibrary();
DeviceLibrary deviceLibraryEntity = new DeviceLibrary();
PackingLibrary packingLibraryEntity = packingLibraryService.getOne(d.getPackingId());
BeanUtils.copyProperties(packingLibraryEntity, deviceLibraryEntity);
deviceLibraryEntity.setId(null);
deviceLibraryEntity.setLifeStatus(2);//设置为在库状态
BeanUtils.copyProperties(d, deviceLibraryEntity);
deviceLibraryEntity.setStorageBillId(storageBillId);
deviceLibraryEntity.setLocationUnit(currentUserUnitName);
deviceLibraryEntity.setOwnUnit(currentUserUnitName);
deviceLibraryEntity.setPartParentId(null);
//如果不是单独的配件,设置父装备id为上一个装备的id 0-不是,1-是 0 装备 1 配件
if (d.getIsBinding() == 0){
if (d.getIsSinglePart() == 0) {
//0 不是,1:是
if (deviceLibraryEntity.getIsPart() == 0) {
saveEntity = deviceLibraryService.addEntity(deviceLibraryEntity);
}
if (deviceLibraryEntity.getIsPart() == 1) {
if (parentPackingId!=null) {
for (int i = saveDevices.size()-1;i>=0;i--){
if (packingLibraryEntity.getPartParentId().equals(saveDevices.get(i).getPackingId())){
deviceLibraryEntity.setPartParentId(saveDevices.get(i).getId());
break;
}
}
}
saveEntity = deviceLibraryService.addEntity(deviceLibraryEntity);
}
}
else {
saveEntity = deviceLibraryService.addEntity(deviceLibraryEntity);
}
}
// if (d.getIsSinglePart() == 0) {
// //0 不是,1:是
// if (deviceLibraryEntity.getIsPart() == 0) {
// saveEntity = deviceLibraryService.addEntity(deviceLibraryEntity);
// }
// if (deviceLibraryEntity.getIsPart() == 1) {
// if (parentPackingId!=null) {
// for (int i = saveDevices.size()-1;i>=0;i--){
// if (packingLibraryEntity.getPartParentId().equals(saveDevices.get(i).getPackingId())){
// deviceLibraryEntity.setPartParentId(saveDevices.get(i).getId());
// }
// saveEntity = deviceLibraryService.addEntity(deviceLibraryEntity);
// }
// }
// else {
// saveEntity = deviceLibraryService.addEntity(deviceLibraryEntity);
// }
// }
//// if (d.getIsSinglePart() == 0) {
//// //0 不是,1:是
//// if (deviceLibraryEntity.getIsPart() == 0) {
//// saveEntity = deviceLibraryService.addEntity(deviceLibraryEntity);
//// }
//// if (deviceLibraryEntity.getIsPart() == 1) {
//// if (parentPackingId!=null) {
//// for (int i = saveDevices.size()-1;i>=0;i--){
//// if (packingLibraryEntity.getPartParentId().equals(saveDevices.get(i).getPackingId())){
//// deviceLibraryEntity.setPartParentId(saveDevices.get(i).getId());
//// }
//// }
//// }
//// saveEntity = deviceLibraryService.addEntity(deviceLibraryEntity);
//// }
//// }
// //如果是单独的配件,不用设置父装备id
// else {
// saveEntity = deviceLibraryService.addEntity(deviceLibraryEntity);
// }
// saveDevices.add(saveEntity);
//// parentId = saveEntity.getId();
// parentPackingId = packingLibraryEntity.getId();
// saveEntities.add(saveEntity);
// stringBuffer.append(saveEntity.getId());
// //存装备日志
// DeviceLogDto deviceLogDto = new DeviceLogDto(saveEntity.getId(), logMessage, fileVoList,null,taskEntity1.getId());
// deviceLogDtos.add(deviceLogDto);
// stringBuffer.append("x");
// //申请业务列装入库数量+1
// if (map.get(d.getPackingId())!=null){
// ApplyBillDetailVo applyBillDetailVo = map.get(d.getPackingId());
// applyBillDetailVo.setCompleteCount(applyBillDetailVo.getCompleteCount()+1);
// map.put(d.getPackingId(),applyBillDetailVo);
// }
// }
// else {
// throw new ApiException("系统中已存在rfid卡号为"+d.getRfidCardId()+"的装备!");
// }
// }
for (DeviceLibrarySaveVo d : storageBillSaveVo.getDeviceLibrarySaveVoList()) {
if (d.getRfidCardId()==null|| "".equals(d.getRfidCardId()) ||deviceLibraryDao.getAllByRfidCardId(d.getRfidCardId()).size()==0) {
DeviceLibrary deviceLibraryEntity = new DeviceLibrary();
PackingLibrary packingLibraryEntity = packingLibraryService.getOne(d.getPackingId());
BeanUtils.copyProperties(packingLibraryEntity, deviceLibraryEntity);
deviceLibraryEntity.setId(null);
deviceLibraryEntity.setLifeStatus(2);//设置为在库状态
BeanUtils.copyProperties(d, deviceLibraryEntity);
deviceLibraryEntity.setStorageBillId(storageBillId);
deviceLibraryEntity.setLocationUnit(currentUserUnitName);
deviceLibraryEntity.setOwnUnit(currentUserUnitName);
deviceLibraryEntity.setPartParentId(null);
//自己的逻辑
//1.将装备全部保存
//1.1不需要绑定
//1.2需要绑定保存以后,将附件的父id进行赋值
//如果不是单独的配件,设置父装备id为上一个装备的id 0-不是,1-是 0 装备 1 配件
if (d.getIsBinding() == 0){
//存放父子集合
batchEntities.add(deviceLibraryEntity);
//如果是单独的配件,不用设置父装备id
else {
saveEntity = deviceLibraryService.addEntity(deviceLibraryEntity);
}
else {
batchEntitiesIsBinding1.add(deviceLibraryEntity);
saveDevices.add(saveEntity);
// parentId = saveEntity.getId();
parentPackingId = packingLibraryEntity.getId();
saveEntities.add(saveEntity);
stringBuffer.append(saveEntity.getId());
//存装备日志
DeviceLogDto deviceLogDto = new DeviceLogDto(saveEntity.getId(), logMessage, fileVoList,null,taskEntity1.getId());
deviceLogDtos.add(deviceLogDto);
stringBuffer.append("x");
//申请业务列装入库数量+1
if (map.get(d.getPackingId())!=null){
ApplyBillDetailVo applyBillDetailVo = map.get(d.getPackingId());
applyBillDetailVo.setCompleteCount(applyBillDetailVo.getCompleteCount()+1);
map.put(d.getPackingId(),applyBillDetailVo);
}
}
//申请业务列装入库数量+1
if (map.get(d.getPackingId())!=null){
ApplyBillDetailVo applyBillDetailVo = map.get(d.getPackingId());
applyBillDetailVo.setCompleteCount(applyBillDetailVo.getCompleteCount()+1);
map.put(d.getPackingId(),applyBillDetailVo);
else {
throw new ApiException("系统中已存在rfid卡号为"+d.getRfidCardId()+"的装备!");
}
}
else {
throw new ApiException("系统中已存在rfid卡号为"+d.getRfidCardId()+"的装备!");
}
}
// 批量保存
batchEntities = deviceLibraryService.batchDevices(batchEntities);
//将父子集合的进行赋值 然后更新
//思路: 1.拿到所有的附件 2.拿到所有的装备 3.判断附件中的列装的id的父id是不是等于装备的列装id
List<DeviceLibrary> parts = batchEntities.stream().filter(deviceLibrary -> deviceLibrary.getIsPart() == 1)
.collect(Collectors.toList());
List<DeviceLibrary> saveParts = new ArrayList<>();
List<DeviceLibrary> devs = batchEntities.stream().filter(deviceLibrary -> deviceLibrary.getIsPart() == 0)
.collect(Collectors.toList());
Map<String, List<DeviceLibrary>> modelsDev = devs.stream().collect(groupingBy(DeviceLibrary::getModel));
Map<String, List<DeviceLibrary>> modelsPart = parts.stream().collect(groupingBy(DeviceLibrary::getModel));
//存放附件
List<DeviceLibrary> deviceLibraries2 = new ArrayList<>();
for (String model : modelsDev.keySet()) {
if (modelsPart.get(model)!=null){
//说明同型号的附件存在
//装备集合
List<DeviceLibrary> deviceLibraries = modelsDev.get(model);
//附件集合
List<DeviceLibrary> deviceLibraries1 = modelsPart.get(model);
if (deviceLibraries.size()>deviceLibraries1.size()){
deviceLibraries = deviceLibraries.subList(0,deviceLibraries1.size());
}
if (deviceLibraries.size()<deviceLibraries1.size()){
//将长度设为一致 截取和装备集合相同数量
// deviceLibraries2 = deviceLibraries1.subList(0, deviceLibraries.size());
List<DeviceLibrary> deviceLibraries3 = deviceLibraries1.subList(0, deviceLibraries.size());
deviceLibraries2.addAll(deviceLibraries3);
deviceLibraries1.removeAll(deviceLibraries2);
//处理多余的附件
saveParts.addAll(deviceLibraries1);
}
if (deviceLibraries2.size()>0){
if (deviceLibraries.size() == deviceLibraries2.size()){
for (int i = 0; i < deviceLibraries.size(); i++) {
for (int j = 0; j < deviceLibraries2.size(); j++) {
if(deviceLibraries.get(i).getPackingId().equals(packingLibraryService.getOne(deviceLibraries2.get(j).getPackingId()).getPartParentId())){
deviceLibraries2.get(j).setPartParentId(deviceLibraries.get(i).getId());
saveParts.add(deviceLibraries2.get(j));
i++;
}
}
}
}
}else {
if (deviceLibraries.size() == deviceLibraries1.size()){
for (int i = 0; i < deviceLibraries1.size(); i++) {
for (int j = 0; j < deviceLibraries1.size(); j++) {
if(deviceLibraries.get(i).getPackingId().equals(packingLibraryService.getOne(deviceLibraries1.get(j).getPackingId()).getPartParentId())){
deviceLibraries1.get(j).setPartParentId(deviceLibraries.get(i).getId());
saveParts.add(deviceLibraries1.get(j));
i++;
}
}
}
}
}
}
}
// if (!devs.isEmpty()){
// if (!parts.isEmpty()){
// if (devs.size()>parts.size()){
// devs = devs.subList(0,parts.size());
// for (DeviceLibrarySaveVo d : storageBillSaveVo.getDeviceLibrarySaveVoList()) {
// if (d.getRfidCardId()==null|| "".equals(d.getRfidCardId()) ||deviceLibraryDao.getAllByRfidCardId(d.getRfidCardId()).size()==0) {
// DeviceLibrary deviceLibraryEntity = new DeviceLibrary();
// PackingLibrary packingLibraryEntity = packingLibraryService.getOne(d.getPackingId());
// BeanUtils.copyProperties(packingLibraryEntity, deviceLibraryEntity);
// deviceLibraryEntity.setId(null);
// deviceLibraryEntity.setLifeStatus(2);//设置为在库状态
// BeanUtils.copyProperties(d, deviceLibraryEntity);
// deviceLibraryEntity.setStorageBillId(storageBillId);
// deviceLibraryEntity.setLocationUnit(currentUserUnitName);
// deviceLibraryEntity.setOwnUnit(currentUserUnitName);
// deviceLibraryEntity.setPartParentId(null);
// //自己的逻辑
// //1.将装备全部保存
// //1.1不需要绑定
// //1.2需要绑定保存以后,将附件的父id进行赋值
// //如果不是单独的配件,设置父装备id为上一个装备的id 0-不是,1-是 0 装备 1 配件
// if (d.getIsBinding() == 0){
// //存放父子集合
// batchEntities.add(deviceLibraryEntity);
// }
// if (devs.size()<parts.size()){
// //将长度设为一致
// List<DeviceLibrary> deviceLibraries = parts.subList(0, devs.size());
// parts.removeAll(deviceLibraries);
// saveParts.addAll(parts);
// else {
// batchEntitiesIsBinding1.add(deviceLibraryEntity);
// }
// //申请业务列装入库数量+1
// if (map.get(d.getPackingId())!=null){
// ApplyBillDetailVo applyBillDetailVo = map.get(d.getPackingId());
// applyBillDetailVo.setCompleteCount(applyBillDetailVo.getCompleteCount()+1);
//
// if (devs.size() == parts.size()){
// for (int i = 0; i < devs.size(); i++) {
// for (int j = 0; j < parts.size(); j++) {
// if(devs.get(i).getPackingId().equals(packingLibraryService.getOne(parts.get(j).getPackingId()).getPartParentId())){
// parts.get(j).setPartParentId(devs.get(i).getId());
// saveParts.add(parts.get(j));
// i++;
// map.put(d.getPackingId(),applyBillDetailVo);
// }
// }
// else {
// throw new ApiException("系统中已存在rfid卡号为"+d.getRfidCardId()+"的装备!");
// }
// }
//// 批量保存
// batchEntities = deviceLibraryService.batchDevices(batchEntities);
// //将父子集合的进行赋值 然后更新
// //思路: 1.拿到所有的附件 2.拿到所有的装备 3.判断附件中的列装的id的父id是不是等于装备的列装id
// List<DeviceLibrary> parts = batchEntities.stream().filter(deviceLibrary -> deviceLibrary.getIsPart() == 1)
// .collect(Collectors.toList());
// List<DeviceLibrary> saveParts = new ArrayList<>();
// List<DeviceLibrary> devs = batchEntities.stream().filter(deviceLibrary -> deviceLibrary.getIsPart() == 0)
// .collect(Collectors.toList());
// Map<String, List<DeviceLibrary>> modelsDev = devs.stream().collect(groupingBy(DeviceLibrary::getModel));
// Map<String, List<DeviceLibrary>> modelsPart = parts.stream().collect(groupingBy(DeviceLibrary::getModel));
// //存放附件
// List<DeviceLibrary> deviceLibraries2 = new ArrayList<>();
// for (String model : modelsDev.keySet()) {
// if (modelsPart.get(model)!=null){
// //说明同型号的附件存在
// //装备集合
// List<DeviceLibrary> deviceLibraries = modelsDev.get(model);
// //附件集合
// List<DeviceLibrary> deviceLibraries1 = modelsPart.get(model);
// if (deviceLibraries.size()>deviceLibraries1.size()){
// deviceLibraries = deviceLibraries.subList(0,deviceLibraries1.size());
// }
// if (deviceLibraries.size()<deviceLibraries1.size()){
// //将长度设为一致 截取和装备集合相同数量
//// deviceLibraries2 = deviceLibraries1.subList(0, deviceLibraries.size());
// List<DeviceLibrary> deviceLibraries3 = deviceLibraries1.subList(0, deviceLibraries.size());
// deviceLibraries2.addAll(deviceLibraries3);
// deviceLibraries1.removeAll(deviceLibraries2);
// //处理多余的附件
// saveParts.addAll(deviceLibraries1);
// }
// if (deviceLibraries2.size()>0){
// if (deviceLibraries.size() == deviceLibraries2.size()){
// for (int i = 0; i < deviceLibraries.size(); i++) {
// for (int j = 0; j < deviceLibraries2.size(); j++) {
// if(deviceLibraries.get(i).getPackingId().equals(packingLibraryService.getOne(deviceLibraries2.get(j).getPackingId()).getPartParentId())){
// deviceLibraries2.get(j).setPartParentId(deviceLibraries.get(i).getId());
// saveParts.add(deviceLibraries2.get(j));
// i++;
// }
// }
// }
// }
// }else {
// if (deviceLibraries.size() == deviceLibraries1.size()){
// for (int i = 0; i < deviceLibraries1.size(); i++) {
// for (int j = 0; j < deviceLibraries1.size(); j++) {
// if(deviceLibraries.get(i).getPackingId().equals(packingLibraryService.getOne(deviceLibraries1.get(j).getPackingId()).getPartParentId())){
// deviceLibraries1.get(j).setPartParentId(deviceLibraries.get(i).getId());
// saveParts.add(deviceLibraries1.get(j));
// i++;
// }
// }
// }
// }
// }
//
//
// }
// }
//批量更新
List<DeviceLibrary> updateParts = deviceLibraryService.batchDevices(saveParts);
batchEntitiesIsBinding0.addAll(updateParts);
batchEntitiesIsBinding0.addAll(devs);
batchEntitiesIsBinding0.addAll(batchEntitiesSinglePart);
if (!batchEntitiesIsBinding1.isEmpty()){
saveDevices.addAll(batchEntitiesIsBinding1);
saveEntities.addAll(batchEntitiesIsBinding1);
}else {
saveDevices.addAll(batchEntitiesIsBinding0);
saveEntities.addAll(batchEntitiesIsBinding0);
}
if (!batchEntitiesIsBinding1.isEmpty()){
batchEntitiesIsBinding1.forEach(deviceLibrary -> {
stringBuffer.append(deviceLibrary.getId());
//存装备日志
DeviceLogDto deviceLogDto = new DeviceLogDto(deviceLibrary.getId(), logMessage, fileVoList,null,taskEntity1.getId());
deviceLogDtos.add(deviceLogDto);
stringBuffer.append("x");
});
}else if (!batchEntitiesIsBinding0.isEmpty()){
batchEntitiesIsBinding0.forEach(deviceLibrary -> {
stringBuffer.append(deviceLibrary.getId());
//存装备日志
DeviceLogDto deviceLogDto = new DeviceLogDto(deviceLibrary.getId(), logMessage, fileVoList,null,taskEntity1.getId());
deviceLogDtos.add(deviceLogDto);
stringBuffer.append("x");
});
}
stopWatch.stop();
//// if (!devs.isEmpty()){
//// if (!parts.isEmpty()){
//// if (devs.size()>parts.size()){
//// devs = devs.subList(0,parts.size());
//// }
//// if (devs.size()<parts.size()){
//// //将长度设为一致
//// List<DeviceLibrary> deviceLibraries = parts.subList(0, devs.size());
//// parts.removeAll(deviceLibraries);
//// saveParts.addAll(parts);
//// }
////
//// if (devs.size() == parts.size()){
//// for (int i = 0; i < devs.size(); i++) {
//// for (int j = 0; j < parts.size(); j++) {
//// if(devs.get(i).getPackingId().equals(packingLibraryService.getOne(parts.get(j).getPackingId()).getPartParentId())){
//// parts.get(j).setPartParentId(devs.get(i).getId());
//// saveParts.add(parts.get(j));
//// i++;
//// }
//// }
//// }
//// }
////
//// }
//// }
// //批量更新
// List<DeviceLibrary> updateParts = deviceLibraryService.batchDevices(saveParts);
// batchEntitiesIsBinding0.addAll(updateParts);
// batchEntitiesIsBinding0.addAll(devs);
// batchEntitiesIsBinding0.addAll(batchEntitiesSinglePart);
// if (!batchEntitiesIsBinding1.isEmpty()){
// saveDevices.addAll(batchEntitiesIsBinding1);
// saveEntities.addAll(batchEntitiesIsBinding1);
// }else {
// saveDevices.addAll(batchEntitiesIsBinding0);
// saveEntities.addAll(batchEntitiesIsBinding0);
// }
// if (!batchEntitiesIsBinding1.isEmpty()){
// batchEntitiesIsBinding1.forEach(deviceLibrary -> {
// stringBuffer.append(deviceLibrary.getId());
// //存装备日志
// DeviceLogDto deviceLogDto = new DeviceLogDto(deviceLibrary.getId(), logMessage, fileVoList,null,taskEntity1.getId());
// deviceLogDtos.add(deviceLogDto);
// stringBuffer.append("x");
// });
// }else if (!batchEntitiesIsBinding0.isEmpty()){
// batchEntitiesIsBinding0.forEach(deviceLibrary -> {
// stringBuffer.append(deviceLibrary.getId());
// //存装备日志
// DeviceLogDto deviceLogDto = new DeviceLogDto(deviceLibrary.getId(), logMessage, fileVoList,null,taskEntity1.getId());
// deviceLogDtos.add(deviceLogDto);
// stringBuffer.append("x");
// });
// }
// stopWatch.stop();
log.info("存放所有save的装备时间:{}",stopWatch.getTotalTimeMillis()+"ms");
//若要打印标签
if(storageBillSaveVo.getIsPrint()==1){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论