|
|
@@ -0,0 +1,252 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package org.springblade.salesPart.statistics.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.salesPart.dto.StayDoOrder;
|
|
|
+import org.springblade.salesPart.entity.PjOrder;
|
|
|
+import org.springblade.salesPart.entity.PjOrderItems;
|
|
|
+import org.springblade.salesPart.entity.PjShip;
|
|
|
+import org.springblade.salesPart.order.service.IOrderItemsService;
|
|
|
+import org.springblade.salesPart.order.service.IOrderService;
|
|
|
+import org.springblade.salesPart.ship.service.IShipService;
|
|
|
+import org.springblade.salesPart.statistics.service.IStatisticsService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 首页统计 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2023-04-21
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class StatisticsServiceImpl implements IStatisticsService {
|
|
|
+
|
|
|
+ private final IOrderService orderService;
|
|
|
+
|
|
|
+ private final IOrderItemsService orderItemsService;
|
|
|
+
|
|
|
+ private final IShipService shipService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<Map<String, Object>> amountStatistics() {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ BigDecimal dealAmountD = new BigDecimal("0.00");
|
|
|
+ BigDecimal dealAmountM = new BigDecimal("0.00");
|
|
|
+ BigDecimal salesNumD = new BigDecimal("0.00");
|
|
|
+ BigDecimal salesNumM = new BigDecimal("0.00");
|
|
|
+ BigDecimal stlAmountD = new BigDecimal("0.00");
|
|
|
+ BigDecimal stlAmountM = new BigDecimal("0.00");
|
|
|
+ BigDecimal profitD = new BigDecimal("0.00");
|
|
|
+ BigDecimal profitM = new BigDecimal("0.00");
|
|
|
+ List<PjOrder> pjOrderListD = orderService.list(new LambdaQueryWrapper<PjOrder>()
|
|
|
+ .eq(PjOrder::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrder::getIsDeleted, 0)
|
|
|
+ .eq(PjOrder::getBsType, "XS")
|
|
|
+ .apply("status = '已发货' and busines_date = CURDATE()"));
|
|
|
+ if (pjOrderListD.size() > 0) {
|
|
|
+ List<Long> orderIdsD = pjOrderListD.stream().map(PjOrder::getId).collect(Collectors.toList());
|
|
|
+ if (orderIdsD.size() > 0) {
|
|
|
+ List<PjOrderItems> pjOrderItemsListD = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .in(PjOrderItems::getPid, orderIdsD));
|
|
|
+ if (pjOrderItemsListD.size() > 0) {
|
|
|
+ salesNumD = pjOrderItemsListD.stream().map(PjOrderItems::getSendNum).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dealAmountD = pjOrderListD.stream().map(PjOrder::getTotalMoney).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ stlAmountD = pjOrderListD.stream().filter(e -> ObjectUtils.isNotNull(e.getOldTrxId())).map(PjOrder::getTotalMoney).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ profitD = pjOrderListD.stream().map(PjOrder::getGrossProfit).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ List<PjOrder> pjOrderListM = orderService.list(new LambdaQueryWrapper<PjOrder>()
|
|
|
+ .eq(PjOrder::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrder::getIsDeleted, 0)
|
|
|
+ .eq(PjOrder::getBsType, "XS")
|
|
|
+ .apply("status = '已发货' and DATE_FORMAT(busines_date, '%Y-%m') = DATE_FORMAT(CURRENT_DATE(), '%Y-%m')"));
|
|
|
+ if (pjOrderListM.size() > 0) {
|
|
|
+ List<Long> orderIdsM = pjOrderListD.stream().map(PjOrder::getId).collect(Collectors.toList());
|
|
|
+ if (orderIdsM.size() > 0) {
|
|
|
+ List<PjOrderItems> pjOrderItemsListM = orderItemsService.list(new LambdaQueryWrapper<PjOrderItems>()
|
|
|
+ .eq(PjOrderItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrderItems::getIsDeleted, 0)
|
|
|
+ .in(PjOrderItems::getPid, orderIdsM));
|
|
|
+ if (pjOrderItemsListM.size() > 0) {
|
|
|
+ salesNumM = pjOrderItemsListM.stream().map(PjOrderItems::getSendNum).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dealAmountM = pjOrderListM.stream().map(PjOrder::getTotalMoney).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ stlAmountM = pjOrderListM.stream().filter(e -> ObjectUtils.isNotNull(e.getOldTrxId())).map(PjOrder::getTotalMoney).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ profitM = pjOrderListM.stream().map(PjOrder::getGrossProfit).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ map.put("dealAmountD", dealAmountD);
|
|
|
+ map.put("dealAmountM", dealAmountM);
|
|
|
+ map.put("salesNumD", salesNumD);
|
|
|
+ map.put("salesNumM", salesNumM);
|
|
|
+ map.put("stlAmountD", stlAmountD);
|
|
|
+ map.put("stlAmountM", stlAmountM);
|
|
|
+ map.put("profitD", profitD);
|
|
|
+ map.put("profitM", profitM);
|
|
|
+ return R.data(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<List<StayDoOrder>> stayDoOrder(StayDoOrder quer) {
|
|
|
+ if (quer.getDateList() == null) {
|
|
|
+ quer.setDateList(new ArrayList<>());
|
|
|
+ }
|
|
|
+ List<StayDoOrder> stayDoOrderList = new ArrayList<>();
|
|
|
+ List<PjOrder> pjOrderList = orderService.list(new LambdaQueryWrapper<PjOrder>()
|
|
|
+ .eq(PjOrder::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrder::getIsDeleted, 0)
|
|
|
+ .eq(PjOrder::getBsType, "XS")
|
|
|
+ .apply("find_in_set(status,'录入,待确认')")
|
|
|
+ .gt(quer.getDateList().size() > 0, PjOrder::getBusinesDate, quer.getDateList().get(0))
|
|
|
+ .lt(quer.getDateList().size() > 0, PjOrder::getBusinesDate, quer.getDateList().get(1)));
|
|
|
+ for (PjOrder item : pjOrderList) {
|
|
|
+ StayDoOrder stayDoOrder = new StayDoOrder();
|
|
|
+ stayDoOrder.setOrderNo(item.getOrdNo());
|
|
|
+ stayDoOrder.setId(item.getId());
|
|
|
+ stayDoOrder.setCorpName(item.getCustomerName());
|
|
|
+ stayDoOrder.setDate(item.getBusinesDate());
|
|
|
+ stayDoOrder.setStatus(item.getStatus());
|
|
|
+ stayDoOrder.setType(item.getBsType());
|
|
|
+ if (1 == item.getActualPaymentStatus()) {
|
|
|
+ stayDoOrder.setPayStatus("待收款");
|
|
|
+ } else if (2 == item.getActualPaymentStatus()) {
|
|
|
+ stayDoOrder.setPayStatus("已收款");
|
|
|
+ } else if (3 == item.getActualPaymentStatus()) {
|
|
|
+ stayDoOrder.setPayStatus("尾款");
|
|
|
+ } else {
|
|
|
+ stayDoOrder.setPayStatus("已退款");
|
|
|
+ }
|
|
|
+ stayDoOrder.setSalesman(item.getSalerName());
|
|
|
+ stayDoOrderList.add(stayDoOrder);
|
|
|
+ }
|
|
|
+ List<PjShip> pjShipListRW = shipService.list(new LambdaQueryWrapper<PjShip>()
|
|
|
+ .eq(PjShip::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjShip::getIsDeleted, 0)
|
|
|
+ .eq(PjShip::getBizTypeName, "FHRW")
|
|
|
+ .eq(PjShip::getStatusName, "待处理")
|
|
|
+ .gt(quer.getDateList().size() > 0, PjShip::getBusinesDate, quer.getDateList().get(0))
|
|
|
+ .lt(quer.getDateList().size() > 0, PjShip::getBusinesDate, quer.getDateList().get(1)));
|
|
|
+ List<PjShip> pjShipListGD = shipService.list(new LambdaQueryWrapper<PjShip>()
|
|
|
+ .eq(PjShip::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjShip::getIsDeleted, 0)
|
|
|
+ .eq(PjShip::getBizTypeName, "FHGD")
|
|
|
+ .eq(PjShip::getStatusName, "待出库")
|
|
|
+ .gt(quer.getDateList().size() > 0, PjShip::getBusinesDate, quer.getDateList().get(0))
|
|
|
+ .lt(quer.getDateList().size() > 0, PjShip::getBusinesDate, quer.getDateList().get(1)));
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ if (pjShipListRW.size() > 0) {
|
|
|
+ List<Long> pjShipListId = pjShipListRW.stream().map(PjShip::getOrdId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ if (pjShipListId.size() > 0) {
|
|
|
+ ids.addAll(pjShipListId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (pjShipListGD.size() > 0) {
|
|
|
+ List<Long> pjShipListId = pjShipListGD.stream().map(PjShip::getOrdId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ if (pjShipListId.size() > 0) {
|
|
|
+ ids.addAll(pjShipListId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<PjOrder> orderList = new ArrayList<>();
|
|
|
+ if (ids.size() > 0) {
|
|
|
+ orderList = orderService.list(new LambdaQueryWrapper<PjOrder>()
|
|
|
+ .eq(PjOrder::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjOrder::getIsDeleted, 0)
|
|
|
+ .in(PjOrder::getId, ids));
|
|
|
+ }
|
|
|
+ for (PjShip item : pjShipListRW) {
|
|
|
+ StayDoOrder stayDoOrder = new StayDoOrder();
|
|
|
+ stayDoOrder.setOrderNo(item.getOrdNo());
|
|
|
+ stayDoOrder.setId(item.getId());
|
|
|
+ stayDoOrder.setCorpName(item.getCustomerName());
|
|
|
+ stayDoOrder.setDate(item.getBusinesDate());
|
|
|
+ stayDoOrder.setStatus(item.getStatusName());
|
|
|
+ stayDoOrder.setType(item.getBizTypeName());
|
|
|
+ if (orderList.size() > 0) {
|
|
|
+ PjOrder pjOrder = orderList.stream().filter(e -> e.getId().equals(item.getOrdId())).findFirst().orElse(null);
|
|
|
+ if (pjOrder != null) {
|
|
|
+ if (1 == pjOrder.getActualPaymentStatus()) {
|
|
|
+ stayDoOrder.setPayStatus("待收款");
|
|
|
+ } else if (2 == pjOrder.getActualPaymentStatus()) {
|
|
|
+ stayDoOrder.setPayStatus("已收款");
|
|
|
+ } else if (3 == pjOrder.getActualPaymentStatus()) {
|
|
|
+ stayDoOrder.setPayStatus("尾款");
|
|
|
+ } else {
|
|
|
+ stayDoOrder.setPayStatus("已退款");
|
|
|
+ }
|
|
|
+ stayDoOrder.setSalesman(pjOrder.getSalerName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stayDoOrderList.add(stayDoOrder);
|
|
|
+ }
|
|
|
+ for (PjShip item : pjShipListGD) {
|
|
|
+ StayDoOrder stayDoOrder = new StayDoOrder();
|
|
|
+ stayDoOrder.setOrderNo(item.getOrdNo());
|
|
|
+ stayDoOrder.setId(item.getId());
|
|
|
+ stayDoOrder.setCorpName(item.getCustomerName());
|
|
|
+ stayDoOrder.setDate(item.getBusinesDate());
|
|
|
+ stayDoOrder.setStatus(item.getStatusName());
|
|
|
+ stayDoOrder.setType(item.getBizTypeName());
|
|
|
+ if (orderList.size() > 0) {
|
|
|
+ PjOrder pjOrder = orderList.stream().filter(e -> e.getId().equals(item.getOrdId())).findFirst().orElse(null);
|
|
|
+ if (pjOrder != null) {
|
|
|
+ if (1 == pjOrder.getActualPaymentStatus()) {
|
|
|
+ stayDoOrder.setPayStatus("待收款");
|
|
|
+ } else if (2 == pjOrder.getActualPaymentStatus()) {
|
|
|
+ stayDoOrder.setPayStatus("已收款");
|
|
|
+ } else if (3 == pjOrder.getActualPaymentStatus()) {
|
|
|
+ stayDoOrder.setPayStatus("尾款");
|
|
|
+ } else {
|
|
|
+ stayDoOrder.setPayStatus("已退款");
|
|
|
+ }
|
|
|
+ stayDoOrder.setSalesman(pjOrder.getSalerName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stayDoOrderList.add(stayDoOrder);
|
|
|
+ }
|
|
|
+ if (1 == quer.getSort()) {
|
|
|
+ Collections.sort(stayDoOrderList, new Comparator<StayDoOrder>() {
|
|
|
+ @Override
|
|
|
+ public int compare(StayDoOrder o1, StayDoOrder o2) {
|
|
|
+ // 从小到大
|
|
|
+ return o1.getDate().compareTo(o2.getDate());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ Collections.sort(stayDoOrderList, new Comparator<StayDoOrder>() {
|
|
|
+ @Override
|
|
|
+ public int compare(StayDoOrder o1, StayDoOrder o2) {
|
|
|
+ // 从大到小
|
|
|
+ return o2.getDate().compareTo(o1.getDate());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return R.data(stayDoOrderList);
|
|
|
+ }
|
|
|
+}
|