|
@@ -11,6 +11,7 @@ import com.sd.business.entity.bom.po.BomClassify;
|
|
|
import com.sd.business.entity.bom.po.BomSpec;
|
|
|
import com.sd.business.entity.department.constant.DepartmentConstant;
|
|
|
import com.sd.business.entity.inventory.po.InventoryBackup;
|
|
|
+import com.sd.business.entity.order.dto.OrderSalesShipmentStatisticsDto;
|
|
|
import com.sd.business.entity.order.enums.OrderClassifyEnum;
|
|
|
import com.sd.business.entity.order.enums.OrderStatusEnum;
|
|
|
import com.sd.business.entity.order.po.OrderInfo;
|
|
@@ -54,13 +55,13 @@ public class OrderSalesShipmentStatisticsServiceImpl extends ServiceImpl<OrderSa
|
|
|
private InventoryBackupService inventoryBackupService;
|
|
|
|
|
|
@Override
|
|
|
- public List<OrderSalesShipmentStatisticsVo> getSalesShipmentStatisticsByDate(TurnoverRateBoardSelectDto dto) {
|
|
|
+ public List<OrderSalesShipmentStatisticsVo> getSalesShipmentStatisticsByDate(OrderSalesShipmentStatisticsDto dto) {
|
|
|
IWrapper<OrderSalesShipmentStatistics> wrapper = getWrapper();
|
|
|
wrapper.orderByDesc("osss", OrderSalesShipmentStatistics::getId);
|
|
|
wrapper.between("osss", OrderSalesShipmentStatistics::getTotalDate, dto.getBeginDate(), dto.getEndDate());
|
|
|
- if ("1".equals(dto.getBomClassify())) {
|
|
|
+ if (Objects.equals(dto.getBomClassify(), 1)) {
|
|
|
wrapper.in("bc", BomClassify::getCode, Arrays.asList("201.G","203.G"));
|
|
|
- } else {
|
|
|
+ } else if (Objects.equals(dto.getBomClassify(), 2)){
|
|
|
wrapper.eq("bc", BomClassify::getCode,"202.G");
|
|
|
}
|
|
|
wrapper.ne("bs", BomSpec::getCode, "1010000007");
|
|
@@ -70,13 +71,14 @@ public class OrderSalesShipmentStatisticsServiceImpl extends ServiceImpl<OrderSa
|
|
|
|
|
|
@Override
|
|
|
public List<TurnoverRateStatisticsVo> getTurnoverRateStatisticsList(TurnoverRateBoardSelectDto dto) {
|
|
|
- // 查询90天的周转率
|
|
|
Date date = new Date();
|
|
|
- Date beginDate = DateUtil.beginOfDay(DateUtil.offsetDay(date, -90));
|
|
|
+ Date beginDate = DateUtil.beginOfDay(DateUtil.offsetDay(date, -dto.getDays() - 1));
|
|
|
Date endDate = DateUtil.beginOfDay(DateUtil.offsetDay(date, -1));
|
|
|
- dto.setBeginDate(beginDate);
|
|
|
- dto.setEndDate(endDate);
|
|
|
- List<OrderSalesShipmentStatisticsVo> statisticsVoList = this.getSalesShipmentStatisticsByDate(dto);
|
|
|
+ OrderSalesShipmentStatisticsDto statisticsDto = new OrderSalesShipmentStatisticsDto();
|
|
|
+ statisticsDto.setBomClassify(dto.getBomClassify());
|
|
|
+ statisticsDto.setBeginDate(beginDate);
|
|
|
+ statisticsDto.setEndDate(endDate);
|
|
|
+ List<OrderSalesShipmentStatisticsVo> statisticsVoList = this.getSalesShipmentStatisticsByDate(statisticsDto);
|
|
|
if (ObjectUtil.isEmpty(statisticsVoList)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
@@ -115,7 +117,8 @@ public class OrderSalesShipmentStatisticsServiceImpl extends ServiceImpl<OrderSa
|
|
|
} else {
|
|
|
endQuantity = endBackup.getQuantity().add(endBackup.getLockQuantity() == null ? BigDecimal.ZERO : endBackup.getLockQuantity());
|
|
|
}
|
|
|
- BigDecimal days = new BigDecimal(90);
|
|
|
+ // 时间段天数
|
|
|
+ BigDecimal days = new BigDecimal(dto.getDays());
|
|
|
BigDecimal turnoverRate;
|
|
|
if (ObjectUtil.equals(item.getQuantity(), BigDecimal.ZERO)
|
|
|
|| ObjectUtil.equals(beginQuantity.add(endQuantity), BigDecimal.ZERO)) {
|
|
@@ -136,9 +139,7 @@ public class OrderSalesShipmentStatisticsServiceImpl extends ServiceImpl<OrderSa
|
|
|
vo.setTurnoverRate(turnoverRate);
|
|
|
vo.setQuantity(endQuantity);
|
|
|
return vo;
|
|
|
- }).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
- // 按照周转率升序
|
|
|
- list.sort(comparing(TurnoverRateStatisticsVo::getTurnoverRate));
|
|
|
+ }).filter(Objects::nonNull).sorted(comparing(TurnoverRateStatisticsVo::getTurnoverRate)).collect(Collectors.toList());
|
|
|
return list;
|
|
|
}
|
|
|
|
|
@@ -166,4 +167,73 @@ public class OrderSalesShipmentStatisticsServiceImpl extends ServiceImpl<OrderSa
|
|
|
}).collect(Collectors.toList());
|
|
|
this.saveBatch(statisticsDtoList);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<Long, BigDecimal> getTurnoverRateMapByBomSpecIds(List<Long> bomSpecIds) {
|
|
|
+ Map<Long, BigDecimal> map = new HashMap<>();
|
|
|
+ // 查询90天的周转率
|
|
|
+ Date date = new Date();
|
|
|
+ Date beginDate = DateUtil.beginOfDay(DateUtil.offsetDay(date, -91));
|
|
|
+ Date endDate = DateUtil.beginOfDay(DateUtil.offsetDay(date, -1));
|
|
|
+ OrderSalesShipmentStatisticsDto statisticsDto = new OrderSalesShipmentStatisticsDto();
|
|
|
+ statisticsDto.setBeginDate(beginDate);
|
|
|
+ statisticsDto.setEndDate(endDate);
|
|
|
+ statisticsDto.setBomSpecIds(bomSpecIds);
|
|
|
+ List<OrderSalesShipmentStatisticsVo> statisticsVoList = this.getSalesShipmentStatisticsByDate(statisticsDto);
|
|
|
+ if (ObjectUtil.isEmpty(statisticsVoList)) {
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ // 期初库存数据
|
|
|
+ Map<Long, InventoryBackup> beginBackupMap = inventoryBackupService.mapKEntity(InventoryBackup::getBomSpecId, q -> q
|
|
|
+ .eq(InventoryBackup::getBackupDate, beginDate)
|
|
|
+ .eq(InventoryBackup::getDepartmentId, DepartmentConstant.SD_SPORTS)
|
|
|
+ .eq(InventoryBackup::getWarehouseId, WarehouseConstant.SEMI_FINISHED_PRODUCT)
|
|
|
+ .in(InventoryBackup::getBomSpecId, bomSpecIds));
|
|
|
+
|
|
|
+ // 期末库存数据
|
|
|
+ Map<Long, InventoryBackup> endBackupMap = inventoryBackupService.mapKEntity(InventoryBackup::getBomSpecId, q -> q
|
|
|
+ .eq(InventoryBackup::getBackupDate, endDate)
|
|
|
+ .eq(InventoryBackup::getDepartmentId, DepartmentConstant.SD_SPORTS)
|
|
|
+ .eq(InventoryBackup::getWarehouseId, WarehouseConstant.SEMI_FINISHED_PRODUCT)
|
|
|
+ .in(InventoryBackup::getBomSpecId, bomSpecIds));
|
|
|
+
|
|
|
+ for (OrderSalesShipmentStatisticsVo item : statisticsVoList) {
|
|
|
+ // 计算周转率
|
|
|
+ // 时间段库存周转天数 = 时间段天数 * (1 / 2) * (期初库存数量+期末库存数量) / 时间段销售量;
|
|
|
+ // 库存周转率 = 时间段天数 / 库存周转天数。
|
|
|
+ // 获取期初和期末数据
|
|
|
+ InventoryBackup beginBackup = beginBackupMap.get(item.getBomSpecId());
|
|
|
+ InventoryBackup endBackup = endBackupMap.get(item.getBomSpecId());
|
|
|
+ BigDecimal beginQuantity;
|
|
|
+ BigDecimal endQuantity;
|
|
|
+ if (beginBackup == null) {
|
|
|
+ beginQuantity = BigDecimal.ZERO;
|
|
|
+ } else {
|
|
|
+ beginQuantity = beginBackup.getQuantity().add(beginBackup.getLockQuantity() == null ? BigDecimal.ZERO : beginBackup.getLockQuantity());
|
|
|
+ }
|
|
|
+ if (endBackup == null) {
|
|
|
+ endQuantity = BigDecimal.ZERO;
|
|
|
+ } else {
|
|
|
+ endQuantity = endBackup.getQuantity().add(endBackup.getLockQuantity() == null ? BigDecimal.ZERO : endBackup.getLockQuantity());
|
|
|
+ }
|
|
|
+ // 时间段天数
|
|
|
+ BigDecimal days = new BigDecimal(90);
|
|
|
+ BigDecimal turnoverRate;
|
|
|
+ if (ObjectUtil.equals(item.getQuantity(), BigDecimal.ZERO)
|
|
|
+ || ObjectUtil.equals(beginQuantity.add(endQuantity), BigDecimal.ZERO)) {
|
|
|
+ turnoverRate = BigDecimal.ZERO;
|
|
|
+ } else {
|
|
|
+ turnoverRate = days
|
|
|
+ .divide(days.multiply(new BigDecimal("0.5"))
|
|
|
+ .multiply(beginQuantity.add(endQuantity))
|
|
|
+ .divide(item.getQuantity(), 4, RoundingMode.HALF_UP),
|
|
|
+ 4, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.equals(endQuantity, BigDecimal.ZERO) && ObjectUtil.equals(turnoverRate, BigDecimal.ZERO)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ map.put(item.getBomSpecId(), turnoverRate);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
}
|