|
|
|
|
@ -22,16 +22,11 @@ import com.ruoyi.asset.service.IAmsAssetLocationService;
|
|
|
|
|
import com.ruoyi.asset.service.IAmsTransferOrderService;
|
|
|
|
|
import com.ruoyi.asset.service.IAmsWarehouseService;
|
|
|
|
|
import com.ruoyi.asset.service.IAssetStatusTransitionService;
|
|
|
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
|
|
import com.ruoyi.common.core.text.Convert;
|
|
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
|
import com.ruoyi.system.service.ISysCodeRuleService;
|
|
|
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@ -66,12 +61,6 @@ public class AmsTransferOrderServiceImpl implements IAmsTransferOrderService
|
|
|
|
|
@Autowired
|
|
|
|
|
private IAmsAssetLocationService amsAssetLocationService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysDeptService sysDeptService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysUserService sysUserService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IAssetStatusTransitionService assetStatusTransitionService;
|
|
|
|
|
|
|
|
|
|
@ -92,8 +81,7 @@ public class AmsTransferOrderServiceImpl implements IAmsTransferOrderService
|
|
|
|
|
public List<AmsAsset> selectAvailableTransferAssetList(AmsAsset amsAsset, Long currentOrderId)
|
|
|
|
|
{
|
|
|
|
|
return amsTransferOrderMapper.selectAvailableTransferAssetList(amsAsset, currentOrderId,
|
|
|
|
|
AssetStatus.IN_STOCK, AssetStatus.IN_USE, TransferOrderStatus.DRAFT,
|
|
|
|
|
TransferOrderStatus.PENDING_CONFIRM);
|
|
|
|
|
AssetStatus.IN_STOCK, TransferOrderStatus.DRAFT, TransferOrderStatus.PENDING_CONFIRM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -211,7 +199,7 @@ public class AmsTransferOrderServiceImpl implements IAmsTransferOrderService
|
|
|
|
|
context.setChangeSummary("确认资产调拨");
|
|
|
|
|
context.setRemark(order.getRemark());
|
|
|
|
|
assetStatusTransitionService.confirmTransfer(item.getAssetId(), item.getNewWarehouseId(),
|
|
|
|
|
item.getNewLocationId(), item.getNewDeptId(), item.getNewUserId(), context);
|
|
|
|
|
item.getNewLocationId(), context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Date now = DateUtils.getNowDate();
|
|
|
|
|
@ -328,7 +316,7 @@ public class AmsTransferOrderServiceImpl implements IAmsTransferOrderService
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 加行锁并校验资产为可调拨状态(在库或在用),同时校验仓位和使用归属完整性。 */
|
|
|
|
|
/** 加行锁并校验资产为可调拨的在库状态,同时校验仓位和使用归属完整性。 */
|
|
|
|
|
private AmsAsset lockTransferableAsset(Long assetId)
|
|
|
|
|
{
|
|
|
|
|
if (StringUtils.isNull(assetId))
|
|
|
|
|
@ -340,7 +328,7 @@ public class AmsTransferOrderServiceImpl implements IAmsTransferOrderService
|
|
|
|
|
{
|
|
|
|
|
throw new ServiceException("调拨资产不存在或已删除");
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtils.equalsAny(asset.getAssetStatus(), AssetStatus.IN_STOCK, AssetStatus.IN_USE))
|
|
|
|
|
if (!StringUtils.equals(asset.getAssetStatus(), AssetStatus.IN_STOCK))
|
|
|
|
|
{
|
|
|
|
|
throw new ServiceException(StringUtils.format("资产【{}】当前状态不允许调拨", asset.getAssetCode()));
|
|
|
|
|
}
|
|
|
|
|
@ -348,10 +336,10 @@ public class AmsTransferOrderServiceImpl implements IAmsTransferOrderService
|
|
|
|
|
{
|
|
|
|
|
throw new ServiceException(StringUtils.format("资产【{}】缺少当前仓库或位置", asset.getAssetCode()));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.equals(AssetStatus.IN_USE, asset.getAssetStatus())
|
|
|
|
|
&& (StringUtils.isNull(asset.getUseDeptId()) || StringUtils.isNull(asset.getUseUserId())))
|
|
|
|
|
if (StringUtils.isNotNull(asset.getUseDeptId()) || StringUtils.isNotNull(asset.getUseUserId())
|
|
|
|
|
|| StringUtils.isNotEmpty(asset.getUseDeptName()) || StringUtils.isNotEmpty(asset.getUseUserName()))
|
|
|
|
|
{
|
|
|
|
|
throw new ServiceException(StringUtils.format("在用资产【{}】缺少当前使用部门或使用人", asset.getAssetCode()));
|
|
|
|
|
throw new ServiceException(StringUtils.format("在库资产【{}】仍存在使用归属,请先修正后再调拨", asset.getAssetCode()));
|
|
|
|
|
}
|
|
|
|
|
return asset;
|
|
|
|
|
}
|
|
|
|
|
@ -377,10 +365,10 @@ public class AmsTransferOrderServiceImpl implements IAmsTransferOrderService
|
|
|
|
|
item.setSpecModel(asset.getSpecModel());
|
|
|
|
|
item.setBrand(asset.getBrand());
|
|
|
|
|
item.setAssetStatus(asset.getAssetStatus());
|
|
|
|
|
item.setOldDeptId(asset.getUseDeptId());
|
|
|
|
|
item.setOldDeptName(asset.getUseDeptName());
|
|
|
|
|
item.setOldUserId(asset.getUseUserId());
|
|
|
|
|
item.setOldUserName(asset.getUseUserName());
|
|
|
|
|
item.setOldDeptId(null);
|
|
|
|
|
item.setOldDeptName(null);
|
|
|
|
|
item.setOldUserId(null);
|
|
|
|
|
item.setOldUserName(null);
|
|
|
|
|
item.setOldWarehouseId(asset.getWarehouseId());
|
|
|
|
|
item.setOldWarehouseCode(asset.getWarehouseCode());
|
|
|
|
|
item.setOldWarehouseName(asset.getWarehouseName());
|
|
|
|
|
@ -407,34 +395,17 @@ public class AmsTransferOrderServiceImpl implements IAmsTransferOrderService
|
|
|
|
|
item.setNewLocationCode(location.getLocationCode());
|
|
|
|
|
item.setNewLocationName(location.getLocationName());
|
|
|
|
|
|
|
|
|
|
if (StringUtils.equals(AssetStatus.IN_USE, asset.getAssetStatus()))
|
|
|
|
|
{
|
|
|
|
|
SysDept dept = requireNormalDept(item.getNewDeptId());
|
|
|
|
|
SysUser user = requireNormalUser(item.getNewUserId());
|
|
|
|
|
if (!Objects.equals(user.getDeptId(), dept.getDeptId()))
|
|
|
|
|
{
|
|
|
|
|
throw new ServiceException(StringUtils.format("资产【{}】的新使用人不属于所选新部门", asset.getAssetCode()));
|
|
|
|
|
}
|
|
|
|
|
item.setNewDeptName(dept.getDeptName());
|
|
|
|
|
item.setNewUserName(user.getUserName());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// 在库资产没有使用归属,前端即使伪造部门或人员也必须清空。
|
|
|
|
|
item.setNewDeptId(null);
|
|
|
|
|
item.setNewDeptName(null);
|
|
|
|
|
item.setNewUserId(null);
|
|
|
|
|
item.setNewUserName(null);
|
|
|
|
|
}
|
|
|
|
|
item.setNewDeptId(null);
|
|
|
|
|
item.setNewDeptName(null);
|
|
|
|
|
item.setNewUserId(null);
|
|
|
|
|
item.setNewUserName(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 陈旧归属校验:若草稿保存后资产台账的归属已被其他业务修改,阻断当前流转。 */
|
|
|
|
|
private void validateOldSnapshot(AmsTransferOrderItem item, AmsAsset asset)
|
|
|
|
|
{
|
|
|
|
|
if (!Objects.equals(item.getOldWarehouseId(), asset.getWarehouseId())
|
|
|
|
|
|| !Objects.equals(item.getOldLocationId(), asset.getLocationId())
|
|
|
|
|
|| !Objects.equals(item.getOldDeptId(), asset.getUseDeptId())
|
|
|
|
|
|| !Objects.equals(item.getOldUserId(), asset.getUseUserId()))
|
|
|
|
|
|| !Objects.equals(item.getOldLocationId(), asset.getLocationId()))
|
|
|
|
|
{
|
|
|
|
|
throw new ServiceException(StringUtils.format("资产【{}】当前归属已变化,请重新编辑并提交调拨单",
|
|
|
|
|
asset.getAssetCode()));
|
|
|
|
|
@ -445,9 +416,7 @@ public class AmsTransferOrderServiceImpl implements IAmsTransferOrderService
|
|
|
|
|
private void validateActualChange(AmsTransferOrderItem item, AmsAsset asset)
|
|
|
|
|
{
|
|
|
|
|
boolean changed = !Objects.equals(asset.getWarehouseId(), item.getNewWarehouseId())
|
|
|
|
|
|| !Objects.equals(asset.getLocationId(), item.getNewLocationId())
|
|
|
|
|
|| !Objects.equals(asset.getUseDeptId(), item.getNewDeptId())
|
|
|
|
|
|| !Objects.equals(asset.getUseUserId(), item.getNewUserId());
|
|
|
|
|
|| !Objects.equals(asset.getLocationId(), item.getNewLocationId());
|
|
|
|
|
if (!changed)
|
|
|
|
|
{
|
|
|
|
|
throw new ServiceException(StringUtils.format("资产【{}】的调拨前后归属不能完全相同", asset.getAssetCode()));
|
|
|
|
|
@ -482,38 +451,6 @@ public class AmsTransferOrderServiceImpl implements IAmsTransferOrderService
|
|
|
|
|
return location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SysDept requireNormalDept(Long deptId)
|
|
|
|
|
{
|
|
|
|
|
if (StringUtils.isNull(deptId))
|
|
|
|
|
{
|
|
|
|
|
throw new ServiceException("在用资产的新使用部门不能为空");
|
|
|
|
|
}
|
|
|
|
|
SysDept dept = sysDeptService.selectDeptById(deptId);
|
|
|
|
|
if (StringUtils.isNull(dept)
|
|
|
|
|
|| !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getStatus())
|
|
|
|
|
|| !StringUtils.equals(DEL_FLAG_NORMAL, dept.getDelFlag()))
|
|
|
|
|
{
|
|
|
|
|
throw new ServiceException("新使用部门不存在或已停用");
|
|
|
|
|
}
|
|
|
|
|
return dept;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SysUser requireNormalUser(Long userId)
|
|
|
|
|
{
|
|
|
|
|
if (StringUtils.isNull(userId))
|
|
|
|
|
{
|
|
|
|
|
throw new ServiceException("在用资产的新使用人不能为空");
|
|
|
|
|
}
|
|
|
|
|
SysUser user = sysUserService.selectUserById(userId);
|
|
|
|
|
if (StringUtils.isNull(user)
|
|
|
|
|
|| !StringUtils.equals(UserConstants.NORMAL, user.getStatus())
|
|
|
|
|
|| !StringUtils.equals(DEL_FLAG_NORMAL, user.getDelFlag()))
|
|
|
|
|
{
|
|
|
|
|
throw new ServiceException("新使用人不存在或已停用");
|
|
|
|
|
}
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AmsTransferOrder requireOrderForUpdate(Long orderId, String requiredStatus, String message)
|
|
|
|
|
{
|
|
|
|
|
if (StringUtils.isNull(orderId))
|
|
|
|
|
|