|
@@ -542,6 +542,8 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
|
|
|
|
|
|
|
|
Long productQuantity = orderProductBos.stream().mapToLong(OrderProductBo::getOrderQuantity).sum();
|
|
Long productQuantity = orderProductBos.stream().mapToLong(OrderProductBo::getOrderQuantity).sum();
|
|
|
|
|
|
|
|
|
|
+ Boolean needAffirmOrder = remoteCustomerService.isNeedAffirmOrder(bo.getCustomerId());
|
|
|
|
|
+
|
|
|
// 应付总额 = 商品总价 + 运费
|
|
// 应付总额 = 商品总价 + 运费
|
|
|
BigDecimal payableAmount = totalAmount.add(bo.getShippingFee());
|
|
BigDecimal payableAmount = totalAmount.add(bo.getShippingFee());
|
|
|
|
|
|
|
@@ -583,6 +585,16 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
|
|
|
bo.setOrderTime(orderTimeToUse);
|
|
bo.setOrderTime(orderTimeToUse);
|
|
|
bo.setOrderType("0");
|
|
bo.setOrderType("0");
|
|
|
bo.setAssigneeType(AssigneeTypeConstants.MKT.getCode());
|
|
bo.setAssigneeType(AssigneeTypeConstants.MKT.getCode());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if ("0".equals(bo.getPayType())) {//信用支付
|
|
|
|
|
+ String orderStatus = OrderStatus.PENDING_SHIPMENT.getCode();//待发货
|
|
|
|
|
+ bo.setConfirmTime(new Date());
|
|
|
|
|
+ if (needAffirmOrder) {
|
|
|
|
|
+ orderStatus = OrderStatus.PENDING_CONFIRMATION.getCode();//待确认
|
|
|
|
|
+ }
|
|
|
|
|
+ bo.setOrderStatus(orderStatus);
|
|
|
|
|
+ }
|
|
|
// --- 步骤 C: 转换对象 ---
|
|
// --- 步骤 C: 转换对象 ---
|
|
|
orderMain = MapstructUtils.convert(bo, OrderMain.class);
|
|
orderMain = MapstructUtils.convert(bo, OrderMain.class);
|
|
|
|
|
|
|
@@ -719,6 +731,8 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
|
|
|
public Long insertOrder(PcSubmitOrderBo bo, OrderMainBo mainBo) {
|
|
public Long insertOrder(PcSubmitOrderBo bo, OrderMainBo mainBo) {
|
|
|
CustomerInfoDTO customerInfoDTO = remoteCustomerService.selectCustomerInfoById(mainBo.getCustomerId());
|
|
CustomerInfoDTO customerInfoDTO = remoteCustomerService.selectCustomerInfoById(mainBo.getCustomerId());
|
|
|
|
|
|
|
|
|
|
+ Boolean affirmFlag = remoteCustomerService.isNeedAffirmOrder(mainBo.getCustomerId());
|
|
|
|
|
+
|
|
|
RemoteCustomerContactVo remoteCustomerContactVo = remoteCustomerContactService.selectCustomerContactByCustomerIdAndUserId(mainBo.getCustomerId(), mainBo.getUserId());
|
|
RemoteCustomerContactVo remoteCustomerContactVo = remoteCustomerContactService.selectCustomerContactByCustomerIdAndUserId(mainBo.getCustomerId(), mainBo.getUserId());
|
|
|
if (ObjectUtils.isNotEmpty(remoteCustomerContactVo)) {
|
|
if (ObjectUtils.isNotEmpty(remoteCustomerContactVo)) {
|
|
|
mainBo.setContactId(remoteCustomerContactVo.getId());
|
|
mainBo.setContactId(remoteCustomerContactVo.getId());
|
|
@@ -764,13 +778,17 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
|
|
|
if (orderId != null && orderId > 0) {
|
|
if (orderId != null && orderId > 0) {
|
|
|
// 3. 初始化审批流程
|
|
// 3. 初始化审批流程
|
|
|
Boolean initOrderFlow = orderCustomerFlowService.initOrderFlow(orderId, mainBo.getContactId());
|
|
Boolean initOrderFlow = orderCustomerFlowService.initOrderFlow(orderId, mainBo.getContactId());
|
|
|
|
|
+ String orderStatus = OrderStatus.PENDING_SHIPMENT.getCode();
|
|
|
|
|
+ if (affirmFlag) {
|
|
|
|
|
+ orderStatus = OrderStatus.PENDING_CONFIRMATION.getCode();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 4. 如果流程初始化成功,更新订单状态 (注意:这里再次触发了数据库更新)
|
|
// 4. 如果流程初始化成功,更新订单状态 (注意:这里再次触发了数据库更新)
|
|
|
if (initOrderFlow) {
|
|
if (initOrderFlow) {
|
|
|
log.info("成功初始化审批流程,订单ID: {}", orderId);
|
|
log.info("成功初始化审批流程,订单ID: {}", orderId);
|
|
|
this.update(Wrappers.lambdaUpdate(OrderMain.class)
|
|
this.update(Wrappers.lambdaUpdate(OrderMain.class)
|
|
|
.eq(OrderMain::getId, orderId)
|
|
.eq(OrderMain::getId, orderId)
|
|
|
- .set(OrderMain::getOrderStatus, OrderStatus.PENDING_SHIPMENT.getCode())// 待发货
|
|
|
|
|
|
|
+ .set(OrderMain::getOrderStatus, orderStatus)// 根据当前客户设置的是否需要确认来设置订单状态
|
|
|
.set(OrderMain::getIsNeedCheck, SysPlatformYesNo.YES.getCode())
|
|
.set(OrderMain::getIsNeedCheck, SysPlatformYesNo.YES.getCode())
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -2137,4 +2155,115 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
|
|
|
proportion.setValue(value);
|
|
proportion.setValue(value);
|
|
|
return proportion;
|
|
return proportion;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R<CustomerOrderTradeDataVo> customerOrderTradeData(Long customerId) {
|
|
|
|
|
+ CustomerOrderTradeDataVo vo = new CustomerOrderTradeDataVo();
|
|
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
|
|
+
|
|
|
|
|
+ // ========== 1. 统计卡片(全部历史数据) ==========
|
|
|
|
|
+ List<OrderMain> allOrders = baseMapper.selectList(new LambdaQueryWrapper<OrderMain>()
|
|
|
|
|
+ .eq(OrderMain::getCustomerId, customerId)
|
|
|
|
|
+ .select(OrderMain::getTotalAmount, OrderMain::getProductQuantity));
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal totalAmount = BigDecimal.ZERO;
|
|
|
|
|
+ long totalQuantity = 0;
|
|
|
|
|
+ long orderCount = allOrders.size();
|
|
|
|
|
+ for (OrderMain order : allOrders) {
|
|
|
|
|
+ if (order.getTotalAmount() != null) {
|
|
|
|
|
+ totalAmount = totalAmount.add(order.getTotalAmount());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (order.getProductQuantity() != null) {
|
|
|
|
|
+ totalQuantity += order.getProductQuantity();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ vo.setTotalAmount(totalAmount);
|
|
|
|
|
+ vo.setTotalQuantity(totalQuantity);
|
|
|
|
|
+ vo.setOrderCount(orderCount);
|
|
|
|
|
+ vo.setAvgOrderAmount(orderCount > 0
|
|
|
|
|
+ ? totalAmount.divide(BigDecimal.valueOf(orderCount), 2, java.math.RoundingMode.HALF_UP)
|
|
|
|
|
+ : BigDecimal.ZERO);
|
|
|
|
|
+
|
|
|
|
|
+ // ========== 2. 采购金额月度趋势(今年12个月) ==========
|
|
|
|
|
+ DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy/MM");
|
|
|
|
|
+ List<CustomerOrderTradeDataVo.MonthTrend> amountTrend = new ArrayList<>();
|
|
|
|
|
+ for (int i = 0; i < 12; i++) {
|
|
|
|
|
+ LocalDate monthStart = LocalDate.of(today.getYear(), i + 1, 1);
|
|
|
|
|
+ LocalDate monthEnd = monthStart.plusMonths(1);
|
|
|
|
|
+
|
|
|
|
|
+ List<OrderMain> monthOrders = baseMapper.selectList(new LambdaQueryWrapper<OrderMain>()
|
|
|
|
|
+ .eq(OrderMain::getCustomerId, customerId)
|
|
|
|
|
+ .ge(OrderMain::getCreateTime, java.sql.Date.valueOf(monthStart))
|
|
|
|
|
+ .lt(OrderMain::getCreateTime, java.sql.Date.valueOf(monthEnd))
|
|
|
|
|
+ .select(OrderMain::getTotalAmount));
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal monthAmount = monthOrders.stream()
|
|
|
|
|
+ .map(OrderMain::getTotalAmount).filter(Objects::nonNull)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+
|
|
|
|
|
+ CustomerOrderTradeDataVo.MonthTrend mt = new CustomerOrderTradeDataVo.MonthTrend();
|
|
|
|
|
+ mt.setMonth(monthStart.format(monthFormatter));
|
|
|
|
|
+ mt.setAmount(monthAmount);
|
|
|
|
|
+ amountTrend.add(mt);
|
|
|
|
|
+ }
|
|
|
|
|
+ vo.setAmountTrend(amountTrend);
|
|
|
|
|
+
|
|
|
|
|
+ // ========== 3. 采购品类占比 ==========
|
|
|
|
|
+ List<OrderMain> customerOrders = baseMapper.selectList(new LambdaQueryWrapper<OrderMain>()
|
|
|
|
|
+ .eq(OrderMain::getCustomerId, customerId).eq(OrderMain::getCurrentLevel, "1")
|
|
|
|
|
+ .select(OrderMain::getId));
|
|
|
|
|
+ List<CustomerOrderTradeDataVo.CategoryProportion> categoryList = new ArrayList<>();
|
|
|
|
|
+ if (CollUtil.isNotEmpty(customerOrders)) {
|
|
|
|
|
+ Set<Long> orderIds = customerOrders.stream().map(OrderMain::getId).collect(Collectors.toSet());
|
|
|
|
|
+ List<OrderProduct> products = orderProductMapper.selectList(new LambdaQueryWrapper<OrderProduct>()
|
|
|
|
|
+ .in(OrderProduct::getOrderId, orderIds)
|
|
|
|
|
+ .select(OrderProduct::getCategoryName, OrderProduct::getOrderQuantity));
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Long> categoryMap = products.stream()
|
|
|
|
|
+ .filter(p -> p.getCategoryName() != null && p.getOrderQuantity() != null)
|
|
|
|
|
+ .collect(Collectors.groupingBy(OrderProduct::getCategoryName,
|
|
|
|
|
+ Collectors.summingLong(OrderProduct::getOrderQuantity)));
|
|
|
|
|
+
|
|
|
|
|
+ categoryList = categoryMap.entrySet().stream()
|
|
|
|
|
+ .sorted(Map.Entry.<String, Long>comparingByValue().reversed())
|
|
|
|
|
+ .map(entry -> {
|
|
|
|
|
+ CustomerOrderTradeDataVo.CategoryProportion cp = new CustomerOrderTradeDataVo.CategoryProportion();
|
|
|
|
|
+ cp.setName(entry.getKey());
|
|
|
|
|
+ cp.setValue(entry.getValue());
|
|
|
|
|
+ return cp;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ vo.setCategoryProportion(categoryList);
|
|
|
|
|
+
|
|
|
|
|
+ // ========== 4. 采购商品日变化(本月每天) ==========
|
|
|
|
|
+ LocalDate firstDayOfMonth = today.withDayOfMonth(1);
|
|
|
|
|
+ List<CustomerOrderTradeDataVo.DailyChange> dailyChange = new ArrayList<>();
|
|
|
|
|
+ for (int d = 1; d <= today.getDayOfMonth(); d++) {
|
|
|
|
|
+ LocalDate date = firstDayOfMonth.plusDays(d - 1);
|
|
|
|
|
+ Date dayStart = java.sql.Date.valueOf(date);
|
|
|
|
|
+ Date dayEnd = java.sql.Date.valueOf(date.plusDays(1));
|
|
|
|
|
+
|
|
|
|
|
+ List<OrderMain> dayOrders = baseMapper.selectList(new LambdaQueryWrapper<OrderMain>()
|
|
|
|
|
+ .eq(OrderMain::getCustomerId, customerId)
|
|
|
|
|
+ .ge(OrderMain::getCreateTime, dayStart)
|
|
|
|
|
+ .lt(OrderMain::getCreateTime, dayEnd)
|
|
|
|
|
+ .select(OrderMain::getTotalAmount, OrderMain::getProductQuantity));
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal dayAmount = dayOrders.stream()
|
|
|
|
|
+ .map(OrderMain::getTotalAmount).filter(Objects::nonNull)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ long dayQuantity = dayOrders.stream()
|
|
|
|
|
+ .map(OrderMain::getProductQuantity).filter(Objects::nonNull)
|
|
|
|
|
+ .mapToLong(Long::longValue).sum();
|
|
|
|
|
+
|
|
|
|
|
+ CustomerOrderTradeDataVo.DailyChange dc = new CustomerOrderTradeDataVo.DailyChange();
|
|
|
|
|
+ dc.setDay(String.valueOf(d));
|
|
|
|
|
+ dc.setAmount(dayAmount);
|
|
|
|
|
+ dc.setQuantity(dayQuantity);
|
|
|
|
|
+ dailyChange.add(dc);
|
|
|
|
|
+ }
|
|
|
|
|
+ vo.setDailyChange(dailyChange);
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok(vo);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|