|
|
@ -2,6 +2,7 @@ package com.win.module.wms.service.itembasic; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.google.common.annotations.VisibleForTesting; |
|
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
|
import com.win.framework.datapermission.core.util.DataPermissionUtils; |
|
|
@ -14,12 +15,13 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.*; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
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.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.itembasic.ErrorCodeConstants.*; |
|
|
|
import static com.win.module.wms.enums.workstation.ErrorCodeConstants.CODE_EXISTS; |
|
|
|
|
|
|
|
/** |
|
|
@ -46,20 +48,9 @@ public class ItembasicServiceImpl implements ItembasicService { |
|
|
|
@Override |
|
|
|
public void updateItembasic(ItembasicUpdateReqVO updateReqVO) { |
|
|
|
// 校验存在
|
|
|
|
validateItembasicExists(updateReqVO.getId()); |
|
|
|
codeExists(null,updateReqVO.getCode()); |
|
|
|
statusExists(updateReqVO.getStatus()); |
|
|
|
uomExists(updateReqVO.getUom()); |
|
|
|
isStdPackExists(updateReqVO.getIsStdPack()); |
|
|
|
enableBuyExists(updateReqVO.getEnableBuy()); |
|
|
|
enableMakeExists(updateReqVO.getEnableMake()); |
|
|
|
enableOutsouringExists(updateReqVO.getEnableOutsourcing()); |
|
|
|
isRecycledExists(updateReqVO.getIsRecycled()); |
|
|
|
isPhantomExists(updateReqVO.getIsPhantom()); |
|
|
|
abcClassExists(updateReqVO.getAbcClass()); |
|
|
|
typeExists(updateReqVO.getType()); |
|
|
|
validityDaysExists(updateReqVO.getValidityDays()); |
|
|
|
availableExists(updateReqVO.getAvailable()); |
|
|
|
validateItembasicForCreateOrUpdate(updateReqVO.getId(),updateReqVO.getCode(),updateReqVO.getStatus(),updateReqVO.getUom(),updateReqVO.getIsStdPack(),updateReqVO.getEnableBuy() |
|
|
|
,updateReqVO.getEnableMake(),updateReqVO.getEnableOutsourcing(),updateReqVO.getIsRecycled(),updateReqVO.getIsPhantom(),updateReqVO.getAbcClass(),updateReqVO.getType() |
|
|
|
,updateReqVO.getValidityDays(),updateReqVO.getAvailable()); |
|
|
|
// 更新
|
|
|
|
ItembasicDO updateObj = ItembasicConvert.INSTANCE.convert(updateReqVO); |
|
|
|
itembasicMapper.updateById(updateObj); |
|
|
@ -68,107 +59,11 @@ public class ItembasicServiceImpl implements ItembasicService { |
|
|
|
@Override |
|
|
|
public void deleteItembasic(Long id) { |
|
|
|
// 校验存在
|
|
|
|
validateItembasicExists(id); |
|
|
|
// 删除
|
|
|
|
itembasicMapper.deleteById(id); |
|
|
|
} |
|
|
|
|
|
|
|
private void validateItembasicExists(Long id) { |
|
|
|
if (itembasicMapper.selectById(id) == null) { |
|
|
|
if(itembasicMapper.selectById(999) == null){ |
|
|
|
throw exception(ITEMBASIC_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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) { |
|
|
|
if (status.isEmpty()) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void uomExists(String uom) { |
|
|
|
if (uom.isEmpty()) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void isStdPackExists(String stdPack) { |
|
|
|
if (stdPack == null) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void enableBuyExists(String enableBuy) { |
|
|
|
if (enableBuy == null) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void enableMakeExists(String enableMark) { |
|
|
|
if (enableMark == null) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void enableOutsouringExists(String enblOutsouring) { |
|
|
|
if (enblOutsouring == null) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void isRecycledExists(String isRecycled) { |
|
|
|
if (isRecycled == null) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void isPhantomExists(String isPhantom) { |
|
|
|
if (isPhantom == null) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void abcClassExists(String abcClass) { |
|
|
|
if (abcClass.isEmpty()) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void typeExists(String type) { |
|
|
|
if (type.isEmpty()) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void validityDaysExists(Integer validityDays) { |
|
|
|
if (validityDays == null) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void availableExists(String available) { |
|
|
|
if (available == null) { |
|
|
|
throw exception(ITEMBASIC_NOT_RIGHT); |
|
|
|
} |
|
|
|
// 删除
|
|
|
|
itembasicMapper.deleteById(id); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -200,7 +95,10 @@ public class ItembasicServiceImpl implements ItembasicService { |
|
|
|
// 校验,判断是否有不符合的原因
|
|
|
|
try { |
|
|
|
if(mode == 2){ |
|
|
|
validateUserForCreateOrUpdate(null,importItembasic.getCode()); |
|
|
|
validateItembasicForCreateOrUpdate(null,importItembasic.getCode(),importItembasic.getStatus(),importItembasic.getUom(),importItembasic.getIsStdPack() |
|
|
|
,importItembasic.getEnableBuy(),importItembasic.getEnableMake(),importItembasic.getEnableOutsourcing() |
|
|
|
,importItembasic.getIsRecycled(),importItembasic.getIsPhantom(),importItembasic.getAbcClass() |
|
|
|
,importItembasic.getType(),importItembasic.getValidityDays(),importItembasic.getAvailable()); |
|
|
|
} |
|
|
|
} catch (ServiceException ex) { |
|
|
|
errorList.add(importItembasic); |
|
|
@ -224,12 +122,128 @@ public class ItembasicServiceImpl implements ItembasicService { |
|
|
|
return errorList; |
|
|
|
} |
|
|
|
|
|
|
|
private void validateUserForCreateOrUpdate(Long id,String code) { |
|
|
|
|
|
|
|
private void validateItembasicForCreateOrUpdate(Long id,String code,String status,String uom,String isStdPack,String enableBuy,String enableMake, |
|
|
|
String enableOutsouring,String isRecycled, String isPhantom,String abcClass,String type,Integer validityDays,String available) { |
|
|
|
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
|
|
|
DataPermissionUtils.executeIgnore(() -> { |
|
|
|
validateItembasicExists(id); |
|
|
|
// 校验code唯一
|
|
|
|
codeExists(id,code); |
|
|
|
validateCodeExists(id,code); |
|
|
|
validateStatusExists(status); |
|
|
|
validateUomExists(uom); |
|
|
|
validateIsStdPackExists(isStdPack); |
|
|
|
validateEnableBuyExists(enableMake); |
|
|
|
validateEnableMakeExists(enableBuy); |
|
|
|
validateEnableOutsouringExists(enableOutsouring); |
|
|
|
validateIsRecycledExists(isRecycled); |
|
|
|
validateIsPhantomExists(isPhantom); |
|
|
|
validateAbcClassExists(abcClass); |
|
|
|
validateTypeExists(type); |
|
|
|
validateValidityDaysExists(validityDays); |
|
|
|
validateAvailableExists(available); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@VisibleForTesting |
|
|
|
private void validateItembasicExists(Long id) { |
|
|
|
if (id == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
ItembasicDO itembasic = itembasicMapper.selectById(id); |
|
|
|
if (itembasic == null) { |
|
|
|
throw exception(ITEMBASIC_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateCodeExists(Long id,String code) { |
|
|
|
if (code.isEmpty()) { |
|
|
|
throw exception(CODE_NOT_EXISTS); |
|
|
|
} |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateStatusExists(String status) { |
|
|
|
if (status.isEmpty()) { |
|
|
|
throw exception(STATUS_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateUomExists(String uom) { |
|
|
|
if (uom.isEmpty()) { |
|
|
|
throw exception(UOM_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateIsStdPackExists(String stdPack) { |
|
|
|
if (stdPack == null) { |
|
|
|
throw exception(IS_STDPACK_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateEnableBuyExists(String enableBuy) { |
|
|
|
if (enableBuy == null) { |
|
|
|
throw exception(ENABLE_BUY_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateEnableMakeExists(String enableMark) { |
|
|
|
if (enableMark == null) { |
|
|
|
throw exception(ENABLE_MAKE_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateEnableOutsouringExists(String enblOutsouring) { |
|
|
|
if (enblOutsouring == null) { |
|
|
|
throw exception(ENABLE_OUTSOURING_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateIsRecycledExists(String isRecycled) { |
|
|
|
if (isRecycled == null) { |
|
|
|
throw exception(IS_RECYCLED_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateIsPhantomExists(String isPhantom) { |
|
|
|
if (isPhantom == null) { |
|
|
|
throw exception(IS_PHANTOM_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateAbcClassExists(String abcClass) { |
|
|
|
if (abcClass.isEmpty()) { |
|
|
|
throw exception(ABC_CLASS_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateTypeExists(String type) { |
|
|
|
if (type.isEmpty()) { |
|
|
|
throw exception(TYPE_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateValidityDaysExists(Integer validityDays) { |
|
|
|
if (validityDays == null) { |
|
|
|
throw exception(VALIDITY_DAYS_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateAvailableExists(String available) { |
|
|
|
if (available == null) { |
|
|
|
throw exception(AVAIABLE_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|