|
@@ -3,10 +3,14 @@ package com.sd.business.service.order.impl;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.tenant.entity.dict.po.DictCommonData;
|
|
|
+import com.fjhx.tenant.service.dict.DictCommonDataService;
|
|
|
import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.sd.business.entity.board.bo.TurnoverRateSalesShipmentStatisticsBo;
|
|
|
import com.sd.business.entity.board.dto.TurnoverRateBoardSelectDto;
|
|
|
import com.sd.business.entity.board.vo.TurnoverRateStatisticsVo;
|
|
|
+import com.sd.business.entity.bom.po.Bom;
|
|
|
import com.sd.business.entity.bom.po.BomClassify;
|
|
|
import com.sd.business.entity.bom.po.BomSpec;
|
|
|
import com.sd.business.entity.department.constant.DepartmentConstant;
|
|
@@ -30,6 +34,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static java.util.Comparator.comparing;
|
|
@@ -54,6 +59,9 @@ public class OrderSalesShipmentStatisticsServiceImpl extends ServiceImpl<OrderSa
|
|
|
@Autowired
|
|
|
private InventoryBackupService inventoryBackupService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DictCommonDataService dictCommonDataService;
|
|
|
+
|
|
|
@Override
|
|
|
public List<OrderSalesShipmentStatisticsVo> getSalesShipmentStatisticsByDate(OrderSalesShipmentStatisticsDto dto) {
|
|
|
IWrapper<OrderSalesShipmentStatistics> wrapper = getWrapper();
|
|
@@ -72,25 +80,49 @@ public class OrderSalesShipmentStatisticsServiceImpl extends ServiceImpl<OrderSa
|
|
|
@Override
|
|
|
public List<TurnoverRateStatisticsVo> getTurnoverRateStatisticsList(TurnoverRateBoardSelectDto dto) {
|
|
|
Date date = new Date();
|
|
|
- Date beginDate = DateUtil.beginOfDay(DateUtil.offsetDay(date, -dto.getDays() - 1));
|
|
|
- Date endDate = DateUtil.beginOfDay(DateUtil.offsetDay(date, -1));
|
|
|
- OrderSalesShipmentStatisticsDto statisticsDto = new OrderSalesShipmentStatisticsDto();
|
|
|
- statisticsDto.setBomClassify(dto.getBomClassify());
|
|
|
- statisticsDto.setBeginDate(beginDate);
|
|
|
- statisticsDto.setEndDate(endDate);
|
|
|
- List<OrderSalesShipmentStatisticsVo> statisticsVoList = this.getSalesShipmentStatisticsByDate(statisticsDto);
|
|
|
+ String ninetyDaysDate = DateUtil.format(DateUtil.offsetDay(date, -91), "yyyy-MM-dd");
|
|
|
+ String sixtyDaysDate = DateUtil.format(DateUtil.offsetDay(date, -61), "yyyy-MM-dd");
|
|
|
+ String thirtyDaysDate = DateUtil.format(DateUtil.offsetDay(date, -31), "yyyy-MM-dd");
|
|
|
+ String endDate = DateUtil.format(DateUtil.offsetDay(date, -1), "yyyy-MM-dd");
|
|
|
+
|
|
|
+ IWrapper<OrderSalesShipmentStatistics> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc("osss", OrderSalesShipmentStatistics::getId);
|
|
|
+ wrapper.between("osss", OrderSalesShipmentStatistics::getTotalDate, ninetyDaysDate, endDate);
|
|
|
+ if (Objects.equals(dto.getBomClassify(), 1)) {
|
|
|
+ wrapper.eq("bc", BomClassify::getCode, "201.G");
|
|
|
+ } else if (Objects.equals(dto.getBomClassify(), 2)){
|
|
|
+ wrapper.eq("bc", BomClassify::getCode,"202.G");
|
|
|
+ } else if (Objects.equals(dto.getBomClassify(), 3)) {
|
|
|
+ wrapper.eq("bc", BomClassify::getCode,"203.G");
|
|
|
+ }
|
|
|
+ wrapper.ne("bs", BomSpec::getCode, "1010000007");
|
|
|
+ wrapper.eq("b", Bom::getChromatophore, dto.getChromatophore());
|
|
|
+ wrapper.like("bs", BomSpec::getWidth, dto.getWidth());
|
|
|
+ wrapper.like("bs", BomSpec::getHeight, dto.getHeight());
|
|
|
+ wrapper.groupBy("osss.bom_spec_id");
|
|
|
+ List<TurnoverRateSalesShipmentStatisticsBo> statisticsVoList = this.baseMapper.getTurnoverRateSalesShipmentStatisticsList(wrapper);
|
|
|
if (ObjectUtil.isEmpty(statisticsVoList)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
- List<Long> bomSpecIds = statisticsVoList.stream().map(OrderSalesShipmentStatistics::getBomSpecId).collect(Collectors.toList());
|
|
|
+ List<Long> bomSpecIds = statisticsVoList.stream().map(TurnoverRateSalesShipmentStatisticsBo::getBomSpecId).collect(Collectors.toList());
|
|
|
|
|
|
- // 期初库存数据
|
|
|
- Map<Long, InventoryBackup> beginBackupMap = inventoryBackupService.mapKEntity(InventoryBackup::getBomSpecId, q -> q
|
|
|
- .eq(InventoryBackup::getBackupDate, beginDate)
|
|
|
+ Map<String, String> bomChromatophoreMap = dictCommonDataService.list(q -> q.eq(DictCommonData::getDictCode, "bom_chromatophore"))
|
|
|
+ .stream().collect(Collectors.toMap(DictCommonData::getDictKey, DictCommonData::getDictValue));
|
|
|
+
|
|
|
+ // 查询前90、60、30天的所有库存数据
|
|
|
+ List<InventoryBackup> inventoryBackupList = inventoryBackupService.list(q -> q
|
|
|
+ .in(InventoryBackup::getBackupDate, ninetyDaysDate, sixtyDaysDate, thirtyDaysDate)
|
|
|
.eq(InventoryBackup::getDepartmentId, DepartmentConstant.SD_SPORTS)
|
|
|
.eq(InventoryBackup::getWarehouseId, WarehouseConstant.SEMI_FINISHED_PRODUCT)
|
|
|
.in(InventoryBackup::getBomSpecId, bomSpecIds));
|
|
|
|
|
|
+ // 期初库存数据
|
|
|
+ Map<String, Map<Long, InventoryBackup>> beginBackupMap = inventoryBackupList.stream()
|
|
|
+ .collect(
|
|
|
+ Collectors.groupingBy(
|
|
|
+ item -> DateUtil.format(item.getBackupDate(), "yyyy-MM-dd"),
|
|
|
+ Collectors.toMap(InventoryBackup::getBomSpecId, Function.identity())));
|
|
|
+
|
|
|
// 期末库存数据
|
|
|
Map<Long, InventoryBackup> endBackupMap = inventoryBackupService.mapKEntity(InventoryBackup::getBomSpecId, q -> q
|
|
|
.eq(InventoryBackup::getBackupDate, endDate)
|
|
@@ -99,18 +131,37 @@ public class OrderSalesShipmentStatisticsServiceImpl extends ServiceImpl<OrderSa
|
|
|
.in(InventoryBackup::getBomSpecId, bomSpecIds));
|
|
|
|
|
|
List<TurnoverRateStatisticsVo> list = statisticsVoList.stream().map(item -> {
|
|
|
+ Long bomSpecId = item.getBomSpecId();
|
|
|
// 计算周转率
|
|
|
// 时间段库存周转天数 = 时间段天数 * (1 / 2) * (期初库存数量+期末库存数量) / 时间段销售量;
|
|
|
// 库存周转率 = 时间段天数 / 库存周转天数。
|
|
|
// 获取期初和期末数据
|
|
|
- InventoryBackup beginBackup = beginBackupMap.get(item.getBomSpecId());
|
|
|
- InventoryBackup endBackup = endBackupMap.get(item.getBomSpecId());
|
|
|
- BigDecimal beginQuantity;
|
|
|
+ InventoryBackup beginBackupNinetyDays = beginBackupMap.getOrDefault(ninetyDaysDate, Collections.emptyMap()).get(bomSpecId);
|
|
|
+ InventoryBackup beginBackupSixtyDays = beginBackupMap.getOrDefault(sixtyDaysDate, Collections.emptyMap()).get(bomSpecId);
|
|
|
+ InventoryBackup beginBackupThirtyDays = beginBackupMap.getOrDefault(thirtyDaysDate, Collections.emptyMap()).get(bomSpecId);
|
|
|
+ InventoryBackup endBackup = endBackupMap.get(bomSpecId);
|
|
|
+ // 计算bom近90、60、30天的期初库存数量
|
|
|
+ BigDecimal beginQuantityNinetyDays;
|
|
|
+ BigDecimal beginQuantitySixtyDays;
|
|
|
+ BigDecimal beginQuantityThirtyDays;
|
|
|
BigDecimal endQuantity;
|
|
|
- if (beginBackup == null) {
|
|
|
- beginQuantity = BigDecimal.ZERO;
|
|
|
+ if (beginBackupNinetyDays == null) {
|
|
|
+ beginQuantityNinetyDays = BigDecimal.ZERO;
|
|
|
} else {
|
|
|
- beginQuantity = beginBackup.getQuantity().add(beginBackup.getLockQuantity() == null ? BigDecimal.ZERO : beginBackup.getLockQuantity());
|
|
|
+ beginQuantityNinetyDays = beginBackupNinetyDays.getQuantity()
|
|
|
+ .add(beginBackupNinetyDays.getLockQuantity() == null ? BigDecimal.ZERO : beginBackupNinetyDays.getLockQuantity());
|
|
|
+ }
|
|
|
+ if (beginBackupSixtyDays == null) {
|
|
|
+ beginQuantitySixtyDays = BigDecimal.ZERO;
|
|
|
+ } else {
|
|
|
+ beginQuantitySixtyDays = beginBackupSixtyDays.getQuantity()
|
|
|
+ .add(beginBackupSixtyDays.getLockQuantity() == null ? BigDecimal.ZERO : beginBackupSixtyDays.getLockQuantity());
|
|
|
+ }
|
|
|
+ if (beginBackupThirtyDays == null) {
|
|
|
+ beginQuantityThirtyDays = BigDecimal.ZERO;
|
|
|
+ } else {
|
|
|
+ beginQuantityThirtyDays = beginBackupThirtyDays.getQuantity()
|
|
|
+ .add(beginBackupThirtyDays.getLockQuantity() == null ? BigDecimal.ZERO : beginBackupThirtyDays.getLockQuantity());
|
|
|
}
|
|
|
if (endBackup == null) {
|
|
|
endQuantity = BigDecimal.ZERO;
|
|
@@ -118,28 +169,61 @@ public class OrderSalesShipmentStatisticsServiceImpl extends ServiceImpl<OrderSa
|
|
|
endQuantity = endBackup.getQuantity().add(endBackup.getLockQuantity() == null ? BigDecimal.ZERO : endBackup.getLockQuantity());
|
|
|
}
|
|
|
// 时间段天数
|
|
|
- BigDecimal days = new BigDecimal(dto.getDays());
|
|
|
- BigDecimal turnoverRate;
|
|
|
- if (ObjectUtil.equals(item.getQuantity(), BigDecimal.ZERO)
|
|
|
- || ObjectUtil.equals(beginQuantity.add(endQuantity), BigDecimal.ZERO)) {
|
|
|
- turnoverRate = BigDecimal.ZERO;
|
|
|
+ BigDecimal days;
|
|
|
+ BigDecimal turnoverRateNinetyDays;
|
|
|
+ BigDecimal turnoverRateSixtyDays;
|
|
|
+ BigDecimal turnoverRateThirtyDays;
|
|
|
+ if (ObjectUtil.equals(item.getNinetyDaysSalesQuantity(), BigDecimal.ZERO)
|
|
|
+ || ObjectUtil.equals(beginQuantityNinetyDays.add(endQuantity), BigDecimal.ZERO)) {
|
|
|
+ turnoverRateNinetyDays = BigDecimal.ZERO;
|
|
|
} else {
|
|
|
- turnoverRate = days
|
|
|
+ days = new BigDecimal(90);
|
|
|
+ turnoverRateNinetyDays = days
|
|
|
.divide(days.multiply(new BigDecimal("0.5"))
|
|
|
- .multiply(beginQuantity.add(endQuantity))
|
|
|
- .divide(item.getQuantity(), 4, RoundingMode.HALF_UP),
|
|
|
+ .multiply(beginQuantityNinetyDays.add(endQuantity))
|
|
|
+ .divide(item.getNinetyDaysSalesQuantity(), 4, RoundingMode.HALF_UP),
|
|
|
4, RoundingMode.HALF_UP);
|
|
|
}
|
|
|
- if (ObjectUtil.equals(endQuantity, BigDecimal.ZERO) && ObjectUtil.equals(turnoverRate, BigDecimal.ZERO)) {
|
|
|
+ if (ObjectUtil.equals(item.getSixtyDaysSalesQuantity(), BigDecimal.ZERO)
|
|
|
+ || ObjectUtil.equals(beginQuantitySixtyDays.add(endQuantity), BigDecimal.ZERO)) {
|
|
|
+ turnoverRateSixtyDays = BigDecimal.ZERO;
|
|
|
+ } else {
|
|
|
+ days = new BigDecimal(60);
|
|
|
+ turnoverRateSixtyDays = days
|
|
|
+ .divide(days.multiply(new BigDecimal("0.5"))
|
|
|
+ .multiply(beginQuantitySixtyDays.add(endQuantity))
|
|
|
+ .divide(item.getSixtyDaysSalesQuantity(), 4, RoundingMode.HALF_UP),
|
|
|
+ 4, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.equals(item.getThirtyDaysSalesQuantity(), BigDecimal.ZERO)
|
|
|
+ || ObjectUtil.equals(beginQuantityThirtyDays.add(endQuantity), BigDecimal.ZERO)) {
|
|
|
+ turnoverRateThirtyDays = BigDecimal.ZERO;
|
|
|
+ } else {
|
|
|
+ days = new BigDecimal(30);
|
|
|
+ turnoverRateThirtyDays = days
|
|
|
+ .divide(days.multiply(new BigDecimal("0.5"))
|
|
|
+ .multiply(beginQuantityThirtyDays.add(endQuantity))
|
|
|
+ .divide(item.getThirtyDaysSalesQuantity(), 4, RoundingMode.HALF_UP),
|
|
|
+ 4, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.equals(endQuantity, BigDecimal.ZERO)) {
|
|
|
return null;
|
|
|
}
|
|
|
TurnoverRateStatisticsVo vo = new TurnoverRateStatisticsVo();
|
|
|
vo.setBomSpecCode(item.getBomSpecCode());
|
|
|
vo.setBomSpecName(item.getBomSpecName());
|
|
|
- vo.setTurnoverRate(turnoverRate);
|
|
|
+ vo.setWidth(item.getWidth());
|
|
|
+ vo.setHeight(item.getHeight());
|
|
|
+ vo.setChromatophore(bomChromatophoreMap.get(item.getChromatophore()));
|
|
|
+ vo.setSalesQuantityThirtyDays(item.getThirtyDaysSalesQuantity());
|
|
|
+ vo.setSalesQuantitySixtyDays(item.getSixtyDaysSalesQuantity());
|
|
|
+ vo.setSalesQuantityNinetyDays(item.getNinetyDaysSalesQuantity());
|
|
|
+ vo.setTurnoverRateNinetyDays(turnoverRateNinetyDays);
|
|
|
+ vo.setTurnoverRateSixtyDays(turnoverRateSixtyDays);
|
|
|
+ vo.setTurnoverRateThirtyDays(turnoverRateThirtyDays);
|
|
|
vo.setQuantity(endQuantity);
|
|
|
return vo;
|
|
|
- }).filter(Objects::nonNull).sorted(comparing(TurnoverRateStatisticsVo::getTurnoverRate)).collect(Collectors.toList());
|
|
|
+ }).filter(Objects::nonNull).sorted(comparing(TurnoverRateStatisticsVo::getTurnoverRateNinetyDays)).collect(Collectors.toList());
|
|
|
return list;
|
|
|
}
|
|
|
|
|
@@ -159,7 +243,9 @@ public class OrderSalesShipmentStatisticsServiceImpl extends ServiceImpl<OrderSa
|
|
|
if (list.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
- Map<Long, OrderSalesShipmentStatistics> statisticsMap = this.mapKEntity(OrderSalesShipmentStatistics::getBomSpecId, q -> q.eq(OrderSalesShipmentStatistics::getTotalDate, formatDate));
|
|
|
+ Map<Long, OrderSalesShipmentStatistics> statisticsMap = this.mapKEntity(
|
|
|
+ OrderSalesShipmentStatistics::getBomSpecId,
|
|
|
+ q -> q.eq(OrderSalesShipmentStatistics::getTotalDate, formatDate));
|
|
|
|
|
|
List<Long> orderIds = list.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getOrderId, orderIds));
|