|
|
@ -47,7 +47,7 @@ public class ItembasicServiceImpl implements ItembasicService { |
|
|
|
public void updateItembasic(ItembasicUpdateReqVO updateReqVO) { |
|
|
|
// 校验存在
|
|
|
|
validateItembasicExists(updateReqVO.getId()); |
|
|
|
// codeExists(updateReqVO.getCode());
|
|
|
|
codeExists(null,updateReqVO.getCode()); |
|
|
|
statusExists(updateReqVO.getStatus()); |
|
|
|
uomExists(updateReqVO.getUom()); |
|
|
|
isStdPackExists(updateReqVO.getIsStdPack()); |
|
|
@ -191,47 +191,37 @@ public class ItembasicServiceImpl implements ItembasicService { |
|
|
|
return itembasicMapper.selectList(exportReqVO); |
|
|
|
} |
|
|
|
|
|
|
|
public ItembasicImportRespVO importUserList(List<ItembasicImportExcelVo> importItembasics, Integer mode, boolean updatePart) { |
|
|
|
public List<ItembasicImportExcelVo> importUserList(List<ItembasicImportExcelVo> importItembasics, Integer mode, boolean updatePart) { |
|
|
|
if (CollUtil.isEmpty(importItembasics)) { |
|
|
|
throw exception(USER_IMPORT_LIST_IS_EMPTY); |
|
|
|
} |
|
|
|
ItembasicImportRespVO respVO = ItembasicImportRespVO.builder().createItembasics(new ArrayList<>()) |
|
|
|
.updateItembasics(new ArrayList<>()).failureItembasics(new LinkedHashMap<>()).build(); |
|
|
|
importItembasics.forEach(itembasic -> { |
|
|
|
List<ItembasicImportExcelVo> errorList = new ArrayList<>(); |
|
|
|
importItembasics.forEach(importItembasic -> { |
|
|
|
// 校验,判断是否有不符合的原因
|
|
|
|
try { |
|
|
|
if(mode == 2){ |
|
|
|
validateUserForCreateOrUpdate(null,itembasic.getCode()); |
|
|
|
validateUserForCreateOrUpdate(null,importItembasic.getCode()); |
|
|
|
} |
|
|
|
} catch (ServiceException ex) { |
|
|
|
respVO.getFailureItembasics().put(itembasic.getCode(), ex.getMessage()); |
|
|
|
errorList.add(importItembasic); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 判断如果不存在,在进行插入
|
|
|
|
ItembasicDO existItembasic = itembasicMapper.selectByCode(itembasic.getCode()); |
|
|
|
ItembasicDO existItembasic = itembasicMapper.selectByCode(importItembasic.getCode()); |
|
|
|
if (existItembasic == null&& mode != 3) { |
|
|
|
itembasicMapper.insert(ItembasicConvert.INSTANCE.convert(itembasic)); |
|
|
|
respVO.getCreateItembasics().add(itembasic.getCode()); |
|
|
|
itembasicMapper.insert(ItembasicConvert.INSTANCE.convert(importItembasic)); |
|
|
|
} |
|
|
|
else if (existItembasic != null && mode != 2) {// 如果存在,判断是否允许更新
|
|
|
|
ItembasicDO itembasicDO = ItembasicConvert.INSTANCE.convert(itembasic); |
|
|
|
ItembasicDO itembasicDO = ItembasicConvert.INSTANCE.convert(importItembasic); |
|
|
|
itembasicDO.setId(existItembasic.getId()); |
|
|
|
itembasicMapper.updateById(itembasicDO); |
|
|
|
respVO.getUpdateItembasics().add(itembasic.getCode()); |
|
|
|
} |
|
|
|
}); |
|
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
if(respVO.getUpdateItembasics().isEmpty() && !updatePart) { |
|
|
|
respVO.setUpdateItembasics(new ArrayList<>()); |
|
|
|
respVO.setCreateItembasics(new ArrayList<>()); |
|
|
|
if(!errorList.isEmpty() && !updatePart) { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
} |
|
|
|
List<String> importResult = new ArrayList<>(); |
|
|
|
importResult.add("createItembasics"); |
|
|
|
importResult.add("updateItembasics"); |
|
|
|
importResult.add("failureItembasics"); |
|
|
|
respVO.setImportResult(importResult); |
|
|
|
return respVO; |
|
|
|
return errorList; |
|
|
|
} |
|
|
|
|
|
|
|
private void validateUserForCreateOrUpdate(Long id,String code) { |
|
|
|