|
@@ -7,10 +7,15 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.ruoyi.asset.domain.TbAssetInformation;
|
|
import com.ruoyi.asset.domain.TbAssetInformation;
|
|
|
|
+import com.ruoyi.asset.domain.TbLocation;
|
|
import com.ruoyi.asset.mapper.TbAssetInformationMapper;
|
|
import com.ruoyi.asset.mapper.TbAssetInformationMapper;
|
|
import com.ruoyi.asset.mapper.TbLocationMapper;
|
|
import com.ruoyi.asset.mapper.TbLocationMapper;
|
|
import com.ruoyi.inventory.domain.TbAssetInventory;
|
|
import com.ruoyi.inventory.domain.TbAssetInventory;
|
|
import com.ruoyi.inventory.domain.TbInventoryCompare;
|
|
import com.ruoyi.inventory.domain.TbInventoryCompare;
|
|
|
|
+import com.ruoyi.inventory.domain.enums.InventoryPlanResult;
|
|
|
|
+import com.ruoyi.inventory.domain.enums.InventoryPlanStatus;
|
|
|
|
+import com.ruoyi.inventory.domain.enums.InventoryResult;
|
|
|
|
+import com.ruoyi.inventory.domain.enums.InventoryStatus;
|
|
import com.ruoyi.inventory.mapper.TbAssetInventoryMapper;
|
|
import com.ruoyi.inventory.mapper.TbAssetInventoryMapper;
|
|
import com.ruoyi.utils.RecursionUtil;
|
|
import com.ruoyi.utils.RecursionUtil;
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
@@ -96,7 +101,86 @@ public class TbInventoryDetailServiceImpl implements ITbInventoryDetailService
|
|
@Override
|
|
@Override
|
|
public int updateTbInventoryDetail(TbInventoryDetail tbInventoryDetail)
|
|
public int updateTbInventoryDetail(TbInventoryDetail tbInventoryDetail)
|
|
{
|
|
{
|
|
- return tbInventoryDetailMapper.updateTbInventoryDetail(tbInventoryDetail);
|
|
|
|
|
|
+ // 获取盘点计划单号
|
|
|
|
+ String orderNumber = tbInventoryDetail.getOrderNumber();
|
|
|
|
+ // 根据单号获取盘点计划
|
|
|
|
+ TbAssetInventory tbAssetInventory = tbAssetInventoryMapper.selectTbAssetInventoryByNumber(orderNumber);
|
|
|
|
+
|
|
|
|
+ TbAssetInformation assetInformation = JSONUtil.toBean(tbInventoryDetail.getInventoryMetadata(), TbAssetInformation.class);
|
|
|
|
+ // 获取账面数量
|
|
|
|
+ Integer quantity = assetInformation.getQuantity();
|
|
|
|
+ // 获取盘点数量
|
|
|
|
+ Integer inventoryQuantity = tbInventoryDetail.getInventoryQuantity();
|
|
|
|
+
|
|
|
|
+ // 盘点数量为null
|
|
|
|
+ if (inventoryQuantity == null) {
|
|
|
|
+ tbInventoryDetail.setInventoryResult(null);
|
|
|
|
+ } else {
|
|
|
|
+ if (quantity > inventoryQuantity) { // 账面大于盘点 盘亏
|
|
|
|
+ tbInventoryDetail.setInventoryResult(InventoryResult.INVENTORY_SHORTAGES.getCode());
|
|
|
|
+ }
|
|
|
|
+ if (quantity.equals(inventoryQuantity)) { // 账面等于盘点 正常
|
|
|
|
+ tbInventoryDetail.setInventoryResult(InventoryResult.INVENTORY_NORMAL.getCode());
|
|
|
|
+ }
|
|
|
|
+ if (inventoryQuantity > quantity ) { // 盘点大于账面 盘盈
|
|
|
|
+ tbInventoryDetail.setInventoryResult(InventoryResult.INVENTORY_PROFIT.getCode());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int updated = tbInventoryDetailMapper.updateTbInventoryDetail(tbInventoryDetail);
|
|
|
|
+ if (updated < 1) {
|
|
|
|
+ throw new RuntimeException("操作失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 查看盘点计划是否已执行
|
|
|
|
+ Integer inventoryStatus = tbAssetInventory.getInventoryStatus();
|
|
|
|
+ if (inventoryStatus.equals(InventoryPlanStatus.PLAN_FINISH.getCode())) {
|
|
|
|
+ // 根据计划单号获取盘点详细
|
|
|
|
+ List<TbInventoryDetail> tbInventoryDetails = tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
|
|
|
|
+
|
|
|
|
+ // 获取盘点计划中的盘点详细
|
|
|
|
+ List<TbInventoryDetail> inventoryDetailList = tbInventoryDetails.stream()
|
|
|
|
+ .filter(item -> !InventoryStatus.ERROR.getCode().equals(item.getInventoryStatus()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ // 获取盘点详细中未盘
|
|
|
|
+ List<TbInventoryDetail> uncountedInventoryDetailList = inventoryDetailList.stream()
|
|
|
|
+ .filter(item -> InventoryStatus.UNCOUNTED.getCode().equals(item.getInventoryStatus()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ // 获取盘点详细中盘亏
|
|
|
|
+ List<TbInventoryDetail> shortagesInventoryDetailList = inventoryDetailList.stream()
|
|
|
|
+ .filter(item -> InventoryResult.INVENTORY_SHORTAGES.getCode().equals(item.getInventoryResult()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ // 获取盘点详细中盘盈
|
|
|
|
+ List<TbInventoryDetail> normalInventoryDetailList = inventoryDetailList.stream()
|
|
|
|
+ .filter(item -> InventoryResult.INVENTORY_PROFIT.getCode().equals(item.getInventoryResult()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ // 未盘数量
|
|
|
|
+ int uncounted = uncountedInventoryDetailList.size();
|
|
|
|
+ // 盘亏数量
|
|
|
|
+ int shortages = shortagesInventoryDetailList.size();
|
|
|
|
+ // 盘盈数量
|
|
|
|
+ int normal = normalInventoryDetailList.size();
|
|
|
|
+ if (uncounted > 0 || shortages > 0) { // 存在盘亏 或者 存在未盘
|
|
|
|
+ tbAssetInventory.setInventoryResult(InventoryPlanResult.PLAN_INVENTORY_SHORTAGES.getCode());
|
|
|
|
+ } else {
|
|
|
|
+ if (normal > 0) { // 不存在盘亏,存在盘盈
|
|
|
|
+ tbAssetInventory.setInventoryResult(InventoryPlanResult.PLAN_INVENTORY_PROFIT.getCode());
|
|
|
|
+ } else { // 不存在盘亏盘盈
|
|
|
|
+ tbAssetInventory.setInventoryResult(InventoryPlanResult.PLAN_INVENTORY_NORMAL.getCode());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int flag = tbAssetInventoryMapper.updateTbAssetInventory(tbAssetInventory);
|
|
|
|
+ if (flag < 1) {
|
|
|
|
+ throw new RuntimeException("操作失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 1;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|