|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.win.module.wms.service.itembasic; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
|
import com.win.framework.datapermission.core.util.DataPermissionUtils; |
|
|
@ -9,20 +10,17 @@ import com.win.module.wms.convert.itembasic.ItembasicConvert; |
|
|
|
import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; |
|
|
|
import com.win.module.wms.dal.mysql.itembasic.ItembasicMapper; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
|
import static com.win.module.system.enums.ErrorCodeConstants.USER_IMPORT_LIST_IS_EMPTY; |
|
|
|
import static com.win.module.system.enums.ErrorCodeConstants.USER_USERNAME_EXISTS; |
|
|
|
import static com.win.module.wms.enums.itembasic.ErrorCodeConstants.ITEMBASIC_NOT_EXISTS; |
|
|
|
import static com.win.module.wms.enums.itembasic.ErrorCodeConstants.ITEMBASIC_NOT_RIGHT; |
|
|
|
import static com.win.module.wms.enums.workstation.ErrorCodeConstants.CODE_EXISTS; |
|
|
|
|
|
|
|
/** |
|
|
|
* 物品基本信息 Service 实现类 |
|
|
@ -49,7 +47,7 @@ public class ItembasicServiceImpl implements ItembasicService { |
|
|
|
public void updateItembasic(ItembasicUpdateReqVO updateReqVO) { |
|
|
|
// 校验存在
|
|
|
|
validateItembasicExists(updateReqVO.getId()); |
|
|
|
codeExists(updateReqVO.getCode()); |
|
|
|
// codeExists(updateReqVO.getCode());
|
|
|
|
statusExists(updateReqVO.getStatus()); |
|
|
|
uomExists(updateReqVO.getUom()); |
|
|
|
isStdPackExists(updateReqVO.getIsStdPack()); |
|
|
@ -81,10 +79,24 @@ public class ItembasicServiceImpl implements ItembasicService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void codeExists(String code) { |
|
|
|
private void codeExists(Long id,String code) { |
|
|
|
if (code.isEmpty()) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
if (StrUtil.isBlank(code)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
ItembasicDO itembasic = itembasicMapper.selectByCode(code); |
|
|
|
if (itembasic == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
// 如果 id 为空,说明不用比较是否为相同 id 的用户
|
|
|
|
if (id == null) { |
|
|
|
throw exception(CODE_EXISTS); |
|
|
|
} |
|
|
|
if (!itembasic.getId().equals(id)) { |
|
|
|
throw exception(CODE_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void statusExists(String status) { |
|
|
@ -179,47 +191,54 @@ public class ItembasicServiceImpl implements ItembasicService { |
|
|
|
return itembasicMapper.selectList(exportReqVO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
|
public ItembasicImportRespVO importUserList(List<ItembasicImportExcelVo> importItembasics, boolean isUpdateSupport) { |
|
|
|
public ItembasicImportRespVO 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(importItembasic -> { |
|
|
|
importItembasics.forEach(itembasic -> { |
|
|
|
// 校验,判断是否有不符合的原因
|
|
|
|
try { |
|
|
|
validateUserForCreateOrUpdate(importItembasic.getCode()); |
|
|
|
if(mode == 2){ |
|
|
|
validateUserForCreateOrUpdate(null,itembasic.getCode()); |
|
|
|
} |
|
|
|
} catch (ServiceException ex) { |
|
|
|
respVO.getFailureItembasics().put(importItembasic.getCode(), ex.getMessage()); |
|
|
|
respVO.getFailureItembasics().put(itembasic.getCode(), ex.getMessage()); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 判断如果不存在,在进行插入
|
|
|
|
ItembasicDO existItembasic = itembasicMapper.selectByCode(importItembasic.getCode()); |
|
|
|
if (existItembasic == null) { |
|
|
|
itembasicMapper.insert(ItembasicConvert.INSTANCE.convert(importItembasic)); // 设置默认密码及空岗位编号数组
|
|
|
|
respVO.getCreateItembasics().add(importItembasic.getCode()); |
|
|
|
return; |
|
|
|
ItembasicDO existItembasic = itembasicMapper.selectByCode(itembasic.getCode()); |
|
|
|
if (existItembasic == null&& mode != 3) { |
|
|
|
itembasicMapper.insert(ItembasicConvert.INSTANCE.convert(itembasic)); |
|
|
|
respVO.getCreateItembasics().add(itembasic.getCode()); |
|
|
|
} |
|
|
|
// 如果存在,判断是否允许更新
|
|
|
|
if (!isUpdateSupport) { |
|
|
|
respVO.getFailureItembasics().put(importItembasic.getCode(), USER_USERNAME_EXISTS.getMsg()); |
|
|
|
return; |
|
|
|
else if (existItembasic != null && mode != 2) {// 如果存在,判断是否允许更新
|
|
|
|
ItembasicDO itembasicDO = ItembasicConvert.INSTANCE.convert(itembasic); |
|
|
|
itembasicDO.setId(existItembasic.getId()); |
|
|
|
itembasicMapper.updateById(itembasicDO); |
|
|
|
respVO.getUpdateItembasics().add(itembasic.getCode()); |
|
|
|
} |
|
|
|
ItembasicDO updateUser = ItembasicConvert.INSTANCE.convert(importItembasic); |
|
|
|
updateUser.setId(existItembasic.getId()); |
|
|
|
itembasicMapper.updateById(updateUser); |
|
|
|
respVO.getUpdateItembasics().add(importItembasic.getCode()); |
|
|
|
}); |
|
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
if(respVO.getUpdateItembasics().isEmpty() && !updatePart) { |
|
|
|
respVO.setUpdateItembasics(new ArrayList<>()); |
|
|
|
respVO.setCreateItembasics(new ArrayList<>()); |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
} |
|
|
|
List<String> importResult = new ArrayList<>(); |
|
|
|
importResult.add("createItembasics"); |
|
|
|
importResult.add("updateItembasics"); |
|
|
|
importResult.add("failureItembasics"); |
|
|
|
respVO.setImportResult(importResult); |
|
|
|
return respVO; |
|
|
|
} |
|
|
|
|
|
|
|
private void validateUserForCreateOrUpdate(String code) { |
|
|
|
private void validateUserForCreateOrUpdate(Long id,String code) { |
|
|
|
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
|
|
|
DataPermissionUtils.executeIgnore(() -> { |
|
|
|
// 校验code唯一
|
|
|
|
codeExists(code); |
|
|
|
codeExists(id,code); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|