|
@@ -1,12 +1,8 @@
|
|
|
package com.ruoyi.inventory.service.impl;
|
|
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
-import java.util.logging.SimpleFormatter;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.util.stream.Stream;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
@@ -14,21 +10,22 @@ import com.ruoyi.asset.domain.TbAssetInformation;
|
|
|
import com.ruoyi.asset.domain.TbLocation;
|
|
|
import com.ruoyi.asset.mapper.TbAssetInformationMapper;
|
|
|
import com.ruoyi.asset.mapper.TbLocationMapper;
|
|
|
-import com.ruoyi.common.exception.ServiceException;
|
|
|
-import com.ruoyi.inventory.domain.TagInfo;
|
|
|
import com.ruoyi.inventory.domain.TbInventoryDetail;
|
|
|
import com.ruoyi.inventory.domain.dto.TakeStockDTO;
|
|
|
import com.ruoyi.inventory.domain.dto.TbAssetInventoryDTO;
|
|
|
import com.ruoyi.inventory.mapper.TbInventoryDetailMapper;
|
|
|
import com.ruoyi.utils.IDUtil;
|
|
|
-import com.ruoyi.utils.RecursionUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.inventory.mapper.TbAssetInventoryMapper;
|
|
|
import com.ruoyi.inventory.domain.TbAssetInventory;
|
|
|
import com.ruoyi.inventory.service.ITbAssetInventoryService;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
+import static com.ruoyi.inventory.domain.enums.InventoryPlanResult.*;
|
|
|
+import static com.ruoyi.inventory.domain.enums.InventoryPlanStatus.PLAN_FINISH;
|
|
|
+import static com.ruoyi.inventory.domain.enums.InventoryResult.*;
|
|
|
+import static com.ruoyi.inventory.domain.enums.InventoryStatus.COUNTED;
|
|
|
+import static com.ruoyi.inventory.domain.enums.InventoryStatus.UNCOUNTED;
|
|
|
|
|
|
/**
|
|
|
* 资产盘点记录Service业务层处理
|
|
@@ -61,24 +58,18 @@ public class TbAssetInventoryServiceImpl implements ITbAssetInventoryService
|
|
|
public TbAssetInventory selectTbAssetInventoryById(Long id)
|
|
|
{
|
|
|
TbAssetInventory tbAssetInventory = tbAssetInventoryMapper.selectTbAssetInventoryById(id);
|
|
|
- setLocationName(tbAssetInventory);
|
|
|
-
|
|
|
- return tbAssetInventory;
|
|
|
- }
|
|
|
-
|
|
|
- private void setLocationName(TbAssetInventory tbAssetInventory) {
|
|
|
String inventoryLocation = tbAssetInventory.getInventoryLocation();
|
|
|
- String[] strLocationIds = inventoryLocation.split(",");
|
|
|
- List<TbLocation> tbLocations = locationMapper.selectTbLocationByIds(List.of(strLocationIds));
|
|
|
- String locationName = Arrays.toString(tbLocations.stream().map(TbLocation::getName).toArray());
|
|
|
+ String locationName = getLocationName(inventoryLocation);
|
|
|
tbAssetInventory.setInventoryLocationName(locationName);
|
|
|
+ return tbAssetInventory;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
- public TbAssetInventory selectTbAssetInventoryByNum(String num) {
|
|
|
+ public TbAssetInventory selectTbAssetInventoryByNumber(String num) {
|
|
|
TbAssetInventory tbAssetInventory = tbAssetInventoryMapper.selectTbAssetInventoryByNumber(num);
|
|
|
- setLocationName(tbAssetInventory);
|
|
|
+ String inventoryLocation = tbAssetInventory.getInventoryLocation();
|
|
|
+ String locationName = getLocationName(inventoryLocation);
|
|
|
+ tbAssetInventory.setInventoryLocationName(locationName);
|
|
|
return tbAssetInventory;
|
|
|
}
|
|
|
|
|
@@ -91,7 +82,31 @@ public class TbAssetInventoryServiceImpl implements ITbAssetInventoryService
|
|
|
@Override
|
|
|
public List<TbAssetInventory> selectTbAssetInventoryList(TbAssetInventory tbAssetInventory)
|
|
|
{
|
|
|
- return tbAssetInventoryMapper.selectTbAssetInventoryList(tbAssetInventory);
|
|
|
+ List<TbAssetInventory> tbAssetInventories = tbAssetInventoryMapper.selectTbAssetInventoryList(tbAssetInventory);
|
|
|
+ for (TbAssetInventory assetInventory : tbAssetInventories) {
|
|
|
+ String inventoryLocation = assetInventory.getInventoryLocation();
|
|
|
+ String locationName = getLocationName(inventoryLocation);
|
|
|
+ assetInventory.setInventoryLocationName(locationName);
|
|
|
+ }
|
|
|
+ return tbAssetInventories;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getLocationName(String locationIds) {
|
|
|
+ String[] ids = locationIds.split(",");
|
|
|
+ if (ids.length < 1) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ List<TbLocation> tbLocations = locationMapper.selectTbLocationByIds(List.of(ids));
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ for (int i = 0; i < tbLocations.size(); i++) {
|
|
|
+ if (i == tbLocations.size() - 1) {
|
|
|
+ stringBuilder.append(tbLocations.get(i).getName());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ stringBuilder.append(tbLocations.get(i).getName());
|
|
|
+ stringBuilder.append(",");
|
|
|
+ }
|
|
|
+ return stringBuilder.toString();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -114,27 +129,14 @@ public class TbAssetInventoryServiceImpl implements ITbAssetInventoryService
|
|
|
}
|
|
|
|
|
|
String inventoryLocation = tbAssetInventory.getInventoryLocation();
|
|
|
- String[] locationIds = inventoryLocation.split(",");
|
|
|
- Set<String> locationNumberSet = new HashSet<>();
|
|
|
- for (String locationId : locationIds) {
|
|
|
- List<String> locationNumberList = locationMapper.selectChildTbLocationById(Long.valueOf(locationId));
|
|
|
- locationNumberSet.addAll(locationNumberList);
|
|
|
- }
|
|
|
- List<TbAssetInformation> tbAssetInformationList = informationMapper.selectAssetInformationByLocations(locationNumberSet);
|
|
|
-
|
|
|
- List<TbInventoryDetail> tbInventoryDetails = new ArrayList<>();
|
|
|
- for (TbAssetInformation tbAssetInformation : tbAssetInformationList) {
|
|
|
- // 未盘点
|
|
|
- TbInventoryDetail uncounted = TbInventoryDetail.uncounted(orderNumber, tbAssetInformation);
|
|
|
- tbInventoryDetails.add(uncounted);
|
|
|
- }
|
|
|
+ List<TbInventoryDetail> inventoryDetails = getInventoryDetails(orderNumber, inventoryLocation);
|
|
|
|
|
|
int insertTbAssetInventory = tbAssetInventoryMapper.insertTbAssetInventory(tbAssetInventory);
|
|
|
if (insertTbAssetInventory == 0) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- for (TbInventoryDetail tbInventoryDetail : tbInventoryDetails) {
|
|
|
+ for (TbInventoryDetail tbInventoryDetail : inventoryDetails) {
|
|
|
tbInventoryDetailMapper.insertTbInventoryDetail(tbInventoryDetail);
|
|
|
}
|
|
|
|
|
@@ -234,10 +236,6 @@ public class TbAssetInventoryServiceImpl implements ITbAssetInventoryService
|
|
|
String orderNumber = tbAssetInventory.getOrderNumber();
|
|
|
|
|
|
int result = 0;
|
|
|
- // 设置盘点状态:盘点完毕
|
|
|
- tbAssetInventory.setInventoryStatus(2);
|
|
|
- // 记录已盘点epc
|
|
|
- Set<String> epcRecord = new HashSet<>();
|
|
|
|
|
|
// 根据盘点单号获取盘点资产详细
|
|
|
List<TbInventoryDetail> tbInventoryDetails = tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
|
|
@@ -246,20 +244,43 @@ public class TbAssetInventoryServiceImpl implements ITbAssetInventoryService
|
|
|
String inventoryMetadata = tbInventoryDetail.getInventoryMetadata();
|
|
|
// 将元数据转换为资产信息
|
|
|
TbAssetInformation assetInformation = JSONUtil.toBean(inventoryMetadata, TbAssetInformation.class);
|
|
|
- // 判断是否盘点到该epc
|
|
|
- boolean flag = epcSet.stream().anyMatch(epc -> epc.equals(assetInformation.getEpc()));
|
|
|
- if (flag) {
|
|
|
+ Integer assetQuantity = assetInformation.getQuantity();
|
|
|
+
|
|
|
+ // 实际盘点数量统计
|
|
|
+ int inventoryQuantity;
|
|
|
+
|
|
|
+ // 获取该资产的所有epc
|
|
|
+ Set<String> assetEpcSet = epcSet
|
|
|
+ .stream()
|
|
|
+ .filter(epc -> TbAssetInformation.encodeChildEpc2Epc(epc).equals(assetInformation.getEpc()))
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ inventoryQuantity = assetEpcSet.size();
|
|
|
+ // 删除已盘点epc
|
|
|
+ epcSet.removeAll(assetEpcSet);
|
|
|
+
|
|
|
+ if (inventoryQuantity > 0) {
|
|
|
// 设置盘点更新状态:已盘点
|
|
|
- tbInventoryDetail.setInventoryStatus(1);
|
|
|
- int update = tbInventoryDetailMapper.updateTbInventoryDetail(tbInventoryDetail);
|
|
|
- if (update > 0) {
|
|
|
- // 新增已盘点epc
|
|
|
- epcRecord.add(assetInformation.getEpc());
|
|
|
- // 删除已盘点epc
|
|
|
- epcSet.remove(assetInformation.getEpc());
|
|
|
- if (result < 1) {
|
|
|
- result = 1;
|
|
|
- }
|
|
|
+ tbInventoryDetail.setInventoryStatus(COUNTED.getCode());
|
|
|
+ // 设置盘点数量
|
|
|
+ tbInventoryDetail.setInventoryQuantity(inventoryQuantity);
|
|
|
+
|
|
|
+ if (inventoryQuantity > assetQuantity) { // 盘盈: 实际盘点数量 大于 资产账面数量
|
|
|
+ tbInventoryDetail.setInventoryResult(INVENTORY_PROFIT.getCode());
|
|
|
+ } else if (inventoryQuantity == assetQuantity) { // 正常: 实际盘点数量 等于 资产账面数量
|
|
|
+ tbInventoryDetail.setInventoryResult(INVENTORY_NORMAL.getCode());
|
|
|
+ } else { // 盘亏: 实际盘点数量 小于 资产账面数量
|
|
|
+ tbInventoryDetail.setInventoryResult(INVENTORY_SHORTAGES.getCode());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 设置盘点更新状态:未盘点
|
|
|
+ tbInventoryDetail.setInventoryStatus(UNCOUNTED.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ int update = tbInventoryDetailMapper.updateTbInventoryDetail(tbInventoryDetail);
|
|
|
+ if (update > 0) {
|
|
|
+ if (result < 1) {
|
|
|
+ result = 1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -267,71 +288,70 @@ public class TbAssetInventoryServiceImpl implements ITbAssetInventoryService
|
|
|
// 统计未盘点
|
|
|
int uncountedCount = tbInventoryDetailMapper.countUncounted(orderNumber);
|
|
|
|
|
|
- // 获取盘点位置
|
|
|
- String inventoryLocation = tbAssetInventory.getInventoryLocation();
|
|
|
- List<Long> locationIds = Arrays.stream(inventoryLocation.split(",")).map(Long::valueOf).collect(Collectors.toList());
|
|
|
- List<String> locationNumbers = locationMapper.selectChildTbLocationByIds(locationIds);
|
|
|
-
|
|
|
- // 根据盘点位置获取位置下的资产信息
|
|
|
- List<TbAssetInformation> locationAssetInformationList = informationMapper.selectAssetInformationByLocations(locationNumbers);
|
|
|
-
|
|
|
- if (!locationAssetInformationList.isEmpty()) {
|
|
|
- // 获取该位置下的全部资产epc
|
|
|
- Set<String> newEpcSet = locationAssetInformationList.stream().map(TbAssetInformation::getEpc).collect(Collectors.toSet());
|
|
|
- // 删除已盘点epc
|
|
|
- newEpcSet.removeAll(epcRecord);
|
|
|
-
|
|
|
- if (!newEpcSet.isEmpty()) {
|
|
|
- // 获取存在该位置且未盘点资产信息
|
|
|
- List<TbAssetInformation> newEpcAssetInformationList = locationAssetInformationList.stream().map(tbAssetInformation -> {
|
|
|
- for (String newEpc : newEpcSet) {
|
|
|
- if (tbAssetInformation.getEpc().equals(newEpc)) {
|
|
|
- return tbAssetInformation;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }).collect(Collectors.toList());
|
|
|
-
|
|
|
- for (TbAssetInformation tbAssetInformation : newEpcAssetInformationList) {
|
|
|
- if (tbAssetInformation == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- String newEpc = tbAssetInformation.getEpc();
|
|
|
- // 判断是否盘点到该epc
|
|
|
- boolean flag = epcSet.stream().anyMatch(epc -> epc.equals(newEpc));
|
|
|
- if (flag) {
|
|
|
- // 已盘点资产详细
|
|
|
- TbInventoryDetail counted = TbInventoryDetail.counted(orderNumber, tbAssetInformation);
|
|
|
- int inserted = tbInventoryDetailMapper.insertTbInventoryDetail(counted);
|
|
|
- if (inserted > 0) {
|
|
|
- // 新增已盘点epc
|
|
|
- epcRecord.add(newEpc);
|
|
|
- // 删除已盘点epc
|
|
|
- epcSet.remove(newEpc);
|
|
|
- if (result < 1) {
|
|
|
- result = 1;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if (uncountedCount > 0) { // 存在未盘点 盘亏
|
|
|
+ tbAssetInventory.setInventoryResult(PLAN_INVENTORY_SHORTAGES.getCode());
|
|
|
+ } else { // 不存在未盘点
|
|
|
+ // 统计盘亏
|
|
|
+ int inventoryShortagesCount = tbInventoryDetailMapper.countInventoryShortages(orderNumber);
|
|
|
+ // 是否存在盘亏
|
|
|
+ if (inventoryShortagesCount > 0) {
|
|
|
+ tbAssetInventory.setInventoryResult(PLAN_INVENTORY_SHORTAGES.getCode());
|
|
|
+ } else {
|
|
|
+ // 统计盘盈
|
|
|
+ int inventoryProfitCount = tbInventoryDetailMapper.countInventoryProfit(orderNumber);
|
|
|
+ // 是否存在盘盈
|
|
|
+ if (inventoryProfitCount > 0) {
|
|
|
+ tbAssetInventory.setInventoryResult(PLAN_INVENTORY_PROFIT.getCode());
|
|
|
+ } else {
|
|
|
+ tbAssetInventory.setInventoryResult(PLAN_INVENTORY_NORMAL.getCode());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 根据未盘点资产epc获取资产信息
|
|
|
- List<TbAssetInformation> tbAssetInformationList = informationMapper.selectTbAssetInformationByEpcList(epcSet);
|
|
|
- for (TbAssetInformation tbAssetInformation : tbAssetInformationList) {
|
|
|
- TbInventoryDetail tbInventoryDetail = TbInventoryDetail.errCounted(orderNumber, tbAssetInformation);
|
|
|
- tbInventoryDetailMapper.insertTbInventoryDetail(tbInventoryDetail);
|
|
|
+ // 意外盘点资产EPC
|
|
|
+ Set<String> unCountEpcSet = new HashSet<>();
|
|
|
+ for (String epc : epcSet) {
|
|
|
+ String unCountEpc = TbAssetInformation.encodeChildEpc2Epc(epc);
|
|
|
+ // 存入未盘点资产epc中
|
|
|
+ unCountEpcSet.add(unCountEpc);
|
|
|
}
|
|
|
|
|
|
- if (uncountedCount > 0) { // 未盘点统计大于0时 盘亏
|
|
|
- tbAssetInventory.setInventoryResult(2);
|
|
|
- } else if (epcRecord.size() > tbInventoryDetails.size()) { // 未盘点统计0,且实际已盘点数大于计划盘点数 盘盈
|
|
|
- tbAssetInventory.setInventoryResult(1);
|
|
|
- } else { // 未盘点统计0,且实际已盘点数等于计划盘点数 正常
|
|
|
- tbAssetInventory.setInventoryResult(3);
|
|
|
+ // 根据意外资产epc获取资产信息
|
|
|
+ List<TbAssetInformation> tbAssetInformationList = informationMapper.selectTbAssetInformationByEpcList(unCountEpcSet);
|
|
|
+ for (TbAssetInformation tbAssetInformation : tbAssetInformationList) { // 盘点异常
|
|
|
+ // 盘点意外的资产信息
|
|
|
+ TbInventoryDetail tbInventoryDetail = TbInventoryDetail.errCounted(orderNumber, tbAssetInformation);
|
|
|
+
|
|
|
+ Integer assetQuantity = tbAssetInformation.getQuantity();
|
|
|
+
|
|
|
+ // 实际盘点数量统计
|
|
|
+ int inventoryQuantity;
|
|
|
+
|
|
|
+ // 获取该资产的所有epc
|
|
|
+ Set<String> assetEpcSet = epcSet
|
|
|
+ .stream()
|
|
|
+ .filter(epc -> TbAssetInformation.encodeChildEpc2Epc(epc).equals(tbAssetInformation.getEpc()))
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ inventoryQuantity = assetEpcSet.size();
|
|
|
+ // 删除已盘点epc
|
|
|
+ epcSet.removeAll(assetEpcSet);
|
|
|
+
|
|
|
+ // 设置盘点数量
|
|
|
+ tbInventoryDetail.setInventoryQuantity(inventoryQuantity);
|
|
|
+ if (inventoryQuantity > assetQuantity) { // 盘盈: 实际盘点数量 大于 资产账面数量
|
|
|
+ tbInventoryDetail.setInventoryResult(INVENTORY_PROFIT.getCode());
|
|
|
+ } else if (inventoryQuantity == assetQuantity) { // 正常: 实际盘点数量 等于 资产账面数量
|
|
|
+ tbInventoryDetail.setInventoryResult(INVENTORY_NORMAL.getCode());
|
|
|
+ } else { // 盘亏: 实际盘点数量 小于 资产账面数量
|
|
|
+ tbInventoryDetail.setInventoryResult(INVENTORY_SHORTAGES.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ tbInventoryDetailMapper.insertTbInventoryDetail(tbInventoryDetail);
|
|
|
}
|
|
|
|
|
|
+ // 设置盘点状态:盘点完毕
|
|
|
+ tbAssetInventory.setInventoryStatus(PLAN_FINISH.getCode());
|
|
|
tbAssetInventoryMapper.updateTbAssetInventory(tbAssetInventory);
|
|
|
return result;
|
|
|
}
|
|
@@ -351,7 +371,43 @@ public class TbAssetInventoryServiceImpl implements ITbAssetInventoryService
|
|
|
} else {
|
|
|
tbAssetInventory.setInventoryStatus(0);
|
|
|
}
|
|
|
- return tbAssetInventoryMapper.updateTbAssetInventory(tbAssetInventory);
|
|
|
+
|
|
|
+ int update = tbAssetInventoryMapper.updateTbAssetInventory(tbAssetInventory);
|
|
|
+ if (update < 1) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderNumber = tbAssetInventory.getOrderNumber();
|
|
|
+ tbInventoryDetailMapper.deleteTbInventoryDetailByOrderNumber(orderNumber);
|
|
|
+
|
|
|
+ String inventoryLocation = tbAssetInventory.getInventoryLocation();
|
|
|
+ List<TbInventoryDetail> inventoryDetails = getInventoryDetails(orderNumber, inventoryLocation);
|
|
|
+
|
|
|
+ for (TbInventoryDetail tbInventoryDetail : inventoryDetails) {
|
|
|
+ tbInventoryDetailMapper.insertTbInventoryDetail(tbInventoryDetail);
|
|
|
+ }
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<TbInventoryDetail> getInventoryDetails(String orderNumber, String inventoryLocation) {
|
|
|
+ String[] locationIds = inventoryLocation.split(",");
|
|
|
+
|
|
|
+ Set<String> locationNumberSet = new HashSet<>();
|
|
|
+ for (String locationId : locationIds) {
|
|
|
+ List<String> locationNumberList = locationMapper.selectChildTbLocationById(Long.valueOf(locationId));
|
|
|
+ locationNumberSet.addAll(locationNumberList);
|
|
|
+ }
|
|
|
+ List<TbAssetInformation> tbAssetInformationList = informationMapper.selectAssetInformationByLocations(locationNumberSet);
|
|
|
+
|
|
|
+ List<TbInventoryDetail> tbInventoryDetails = new ArrayList<>();
|
|
|
+ for (TbAssetInformation tbAssetInformation : tbAssetInformationList) {
|
|
|
+ // 未盘点
|
|
|
+ TbInventoryDetail uncounted = TbInventoryDetail.uncounted(orderNumber, tbAssetInformation);
|
|
|
+ tbInventoryDetails.add(uncounted);
|
|
|
+ }
|
|
|
+
|
|
|
+ return tbInventoryDetails;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -402,142 +458,4 @@ public class TbAssetInventoryServiceImpl implements ITbAssetInventoryService
|
|
|
String locationName = Arrays.toString(tbLocations.stream().map(TbLocation::getName).toArray());
|
|
|
tbAssetInventoryDTO.setInventoryLocationName(locationName);
|
|
|
}
|
|
|
-
|
|
|
- // 旧手持机盘点
|
|
|
- public int addByTakeStock(List<TakeStockDTO> _dto){
|
|
|
- int result = 0;
|
|
|
- for (TakeStockDTO dto : _dto) {
|
|
|
- //解析实体
|
|
|
- List<TagInfo> list = dto.getAssetList();
|
|
|
- String location = dto.getInventoryLocation();
|
|
|
- String orderNumber = dto.getOrderNumber();
|
|
|
- //提取epc rfid
|
|
|
- ArrayList<String> epcList = new ArrayList<>();
|
|
|
- for (TagInfo tagInfo : list) {
|
|
|
- String epc = tagInfo.getEpc();
|
|
|
- // 删除字符串中前导的零
|
|
|
- epc = epc.replaceFirst("^0+", "");
|
|
|
- epcList.add(epc);
|
|
|
- }
|
|
|
- //根据位置获取包含自身及子位置,递归
|
|
|
- List<String> locations = new RecursionUtil().getNumberWithChildren(locationMapper, location);
|
|
|
- //获取所在位置内的资产
|
|
|
- // List<String> rfidList = informationMapper.selectNumberByLocations(locations);
|
|
|
- List<TbAssetInformation> informationList = informationMapper.selectAssetInformationByLocations(locations);
|
|
|
- List<String> rfidList = informationList.stream().map(TbAssetInformation::getEpc).collect(Collectors.toList());
|
|
|
-
|
|
|
- //对比盘点
|
|
|
- List<String> intersection = new ArrayList<>(rfidList);
|
|
|
- intersection.retainAll(epcList);
|
|
|
- if (intersection.size() < rfidList.size()) {
|
|
|
- //盘亏
|
|
|
- if (!orderNumber.isEmpty()) {
|
|
|
- result = takeStock(orderNumber, epcList, 2);
|
|
|
- } else {
|
|
|
- result = takeStock2(location, 2, epcList);
|
|
|
- }
|
|
|
- } else if (list.size() > intersection.size()) {
|
|
|
- //盘盈
|
|
|
- if (!orderNumber.isEmpty()) {
|
|
|
- result = takeStock(orderNumber, epcList, 1);
|
|
|
- } else {
|
|
|
- result = takeStock2(location, 1, epcList);
|
|
|
- }
|
|
|
- } else if (intersection.size() == rfidList.size()) {
|
|
|
- //正常
|
|
|
- if (!orderNumber.isEmpty()) {
|
|
|
- result = takeStock(orderNumber, epcList, 3);
|
|
|
- } else {
|
|
|
- result = takeStock2(location, 3, epcList);
|
|
|
- }
|
|
|
- } else {
|
|
|
- result = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- // 旧手持机盘点
|
|
|
- private int takeStock(String orderNumber, List<String> list, Integer result){
|
|
|
- TbAssetInventory inventory = tbAssetInventoryMapper.selectTbAssetInventoryByNumber(orderNumber);
|
|
|
- if (inventory.getRecordStatus() == 1) {
|
|
|
- //插入盘点
|
|
|
- inventory.setInventoryStatus(2);
|
|
|
- inventory.setInventoryResult(result);
|
|
|
- //插入明细
|
|
|
- setDetail(orderNumber, list);
|
|
|
- return updateTbAssetInventory(inventory);
|
|
|
- }else {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 旧手持机盘点
|
|
|
- private int takeStock2(String location, Integer result, List<String> list){
|
|
|
- TbAssetInventory inventory = new TbAssetInventory();
|
|
|
- inventory.setInventoryStatus(2);
|
|
|
- inventory.setInventoryResult(result);
|
|
|
- inventory.setRecordStatus(1);
|
|
|
- inventory.setInventoryLocation(location);
|
|
|
- inventory.setInventoryDate(new Date());
|
|
|
- SimpleDateFormat formatter = new SimpleDateFormat("yyMMdd HH:mm:ss");
|
|
|
- String format = formatter.format(new Date());
|
|
|
- inventory.setName("线下自测"+format);
|
|
|
- int i = insertTbAssetInventory(inventory);
|
|
|
- if(i < 1){
|
|
|
- throw new ServiceException("生成盘点记录失败");
|
|
|
- }
|
|
|
- String orderNumber = inventory.getOrderNumber();
|
|
|
- //插入盘点明细
|
|
|
- setDetail(orderNumber, list);
|
|
|
- return 1;
|
|
|
- }
|
|
|
-
|
|
|
- // 旧手持机盘点
|
|
|
- private void setDetail(String orderNumber, List<String> list){
|
|
|
- //该位置下的资产
|
|
|
- TbAssetInventory _inventory = tbAssetInventoryMapper.selectTbAssetInventoryByNumber(orderNumber);
|
|
|
- TbAssetInformation information = new TbAssetInformation();
|
|
|
- String location = _inventory.getInventoryLocation();
|
|
|
- information.setLocationNumber(location);
|
|
|
- List<String> childrens = new RecursionUtil().getNumberWithChildren(locationMapper, location);
|
|
|
- information.setNlist(childrens);
|
|
|
- List<TbAssetInformation> informations = informationMapper.selectTbAssetInformationList(information);
|
|
|
- if (informations == null || informations.isEmpty() ){
|
|
|
- return ;
|
|
|
- }
|
|
|
- //该位置下资产rfid list
|
|
|
- List<String> _list = informations.stream().map(TbAssetInformation::getEpc).collect(Collectors.toList());
|
|
|
-
|
|
|
- //已盘点,1
|
|
|
- List<String> green = (List<String>) CollectionUtil.intersection(_list, list);
|
|
|
- //未盘点,2
|
|
|
- List<String> red = new ArrayList<>(_list);
|
|
|
- red.removeAll(list);
|
|
|
- //异常(多余),0
|
|
|
- List<String> yellow = new ArrayList<>(list);
|
|
|
- yellow.removeAll(_list);
|
|
|
- //插入详细盘点信息
|
|
|
- TbInventoryDetail detail = new TbInventoryDetail();
|
|
|
- //已盘
|
|
|
- setInventoryDetail(green, detail, orderNumber, 1);
|
|
|
- //未盘
|
|
|
- setInventoryDetail(red, detail, orderNumber, 2);
|
|
|
- //异常
|
|
|
- setInventoryDetail(yellow, detail, orderNumber, 0);
|
|
|
- }
|
|
|
-
|
|
|
- // 旧手持机盘点
|
|
|
- private void setInventoryDetail(List<String> list, TbInventoryDetail detail, String orderNumber, Integer isUpdate){
|
|
|
- for (String epc : list) {
|
|
|
- detail.setOrderNumber(orderNumber);
|
|
|
- TbAssetInformation tbAssetInformation = informationMapper.selectTbAssetInformationByEpc(epc);
|
|
|
- if (tbAssetInformation == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- detail.setInventoryMetadata(JSONUtil.toJsonStr(tbAssetInformation));
|
|
|
- detail.setInventoryStatus(isUpdate);
|
|
|
- tbInventoryDetailMapper.insertTbInventoryDetail(detail);
|
|
|
- }
|
|
|
- }
|
|
|
}
|