cloudroam
2024-10-12 021fcaca65cc87874e216630153e17455acaabce
src/main/java/com/mzl/flower/service/impl/report/OrderReportServiceImpl.java
@@ -18,10 +18,12 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
@@ -205,18 +207,33 @@
    @Override
    public Page<OrderPartnerReportResultVO> getPartnerSalePage(Page page, QueryPartnerOrderDTO dto) {
        if(null!=dto.getPaymentDateStart())
            dto.setStartDate(calculateStartTime(dto.getPaymentDateStart()));
        if(null!=dto.getPaymentDateEnd())
            dto.setEndDate(calculateEndTime(dto.getPaymentDateEnd()));
        Page<OrderPartnerReportResultVO> result=orderReportMapper.getPartnerOrderDateReportPage(page,dto);
        return result;
    }
    @Override
    public OrderPartnerReportResultVO getPartnerSaleStatis(QueryPartnerOrderDTO dto) {
        if(null!=dto.getPaymentDateStart())
            dto.setStartDate(calculateStartTime(dto.getPaymentDateStart()));
        if(null!=dto.getPaymentDateEnd())
            dto.setEndDate(calculateEndTime(dto.getPaymentDateEnd()));
        OrderPartnerReportResultVO vo2=orderReportMapper.getPartnerOrderDateReportStatis(dto);
        return vo2;
    }
    @Override
    public void exportPartnerSalesList(HttpServletResponse response, QueryPartnerOrderDTO dto) {
        if(null!=dto.getPaymentDateStart())
            dto.setStartDate(calculateStartTime(dto.getPaymentDateStart()));
        if(null!=dto.getPaymentDateEnd())
            dto.setEndDate(calculateEndTime(dto.getPaymentDateEnd()));
        List<OrderPartnerReportResultVO> list = orderReportMapper.getPartnerOrderDateReportList(dto);
@@ -259,8 +276,8 @@
            throw new ValidationException("日期不能为空");
        }
        supplierReportCalendarBO.setSupplierId(dto.getSupplierId());
        supplierReportCalendarBO.setStartDate(dto.getStartDate());
        supplierReportCalendarBO.setEndDate(dto.getEndDate());
        supplierReportCalendarBO.setStartDate(calculateStartTime(dto.getStartDate().atStartOfDay()));
        supplierReportCalendarBO.setEndDate(calculateEndTime(dto.getEndDate().atStartOfDay()));
        List<OrderSupplierReportResultVO> list = orderReportMapper.getOrderSupplierPageReport(supplierReportCalendarBO, page);
        page.setRecords(list);
        return page;
@@ -273,8 +290,8 @@
            throw new ValidationException("日期不能为空");
        }
        supplierReportCalendarBO.setSupplierId(dto.getSupplierId());
        supplierReportCalendarBO.setStartDate(dto.getStartDate());
        supplierReportCalendarBO.setEndDate(dto.getEndDate());
        supplierReportCalendarBO.setStartDate(calculateStartTime(dto.getStartDate().atStartOfDay()));
        supplierReportCalendarBO.setEndDate(calculateEndTime(dto.getEndDate().atStartOfDay()));
        OrderSupplierReportResultVO orderSupplierCountReport = orderReportMapper.getOrderSupplierCountReport(supplierReportCalendarBO);
        return orderSupplierCountReport;
    }
@@ -287,30 +304,32 @@
            throw new ValidationException("日期不能为空");
        }
        supplierReportCalendarBO.setSupplierId(dto.getSupplierId());
        supplierReportCalendarBO.setStartDate(dto.getStartDate());
        supplierReportCalendarBO.setEndDate(dto.getEndDate());
        supplierReportCalendarBO.setStartDate(calculateStartTime(dto.getStartDate().atStartOfDay()));
        supplierReportCalendarBO.setEndDate(calculateEndTime(dto.getEndDate().atStartOfDay()));
        List<OrderSupplierReportResultVO> list = orderReportMapper.getOrderSupplierReport(supplierReportCalendarBO);
        String[] rowsName = new String[]{"序号","日期", "供应商ID", "供应商","花农底价"
                , "降级扣款",  "缺货扣款(缺货+补货)","售后扣花农款","售后扣合伙人款","实际销售扎数","结算费用","订单状态"};
                , "降级扣款",  "缺货扣款(缺货+补货)","售后扣花农款","实际销售扎数","结算费用","订单状态"};
        List<Object[]> dataList = new ArrayList<>();
        int sn = 1;
        for (OrderSupplierReportResultVO o : list) {
            Object[] objs = new Object[rowsName.length];
            int a = 0;
            objs[a++] = sn; // 序号
            objs[a++] = format(o.getOrderDate(), "yyyy-MM-dd"); // 日期
            objs[a++] = o.getSupplierId(); // 供应商ID
            objs[a++] = o.getSupplierName(); // 供应商
            objs[a++] = o.getOrderSupplierPriceAmount(); // 花农底价
            objs[a++] = o.getOrderCheckFee(); //降级扣款
            objs[a++] = o.getOrderLackFeeSupplier();//缺货扣款
            objs[a++] = o.getSalesFeeSupplier(); // 售后扣花农款
            objs[a++] = o.getRealSaleNum(); // 实际销售扎数
            objs[a++] = o.getProfitFeeAmount(); // 结算费用
            objs[a++] = o.getSettleStatus(); // 订单状态
            dataList.add(objs);
            sn++;
            if(!ObjectUtils.isEmpty(o)) {
                Object[] objs = new Object[rowsName.length];
                int a = 0;
                objs[a++] = sn; // 序号
                objs[a++] = format(o.getDateinfo(), "yyyy-MM-dd"); // 日期
                objs[a++] = o.getSupplierId(); // 供应商ID
                objs[a++] = o.getSupplierName(); // 供应商
                objs[a++] = o.getOrderSupplierPriceAmount(); // 花农底价
                objs[a++] = o.getOrderCheckFee(); //降级扣款
                objs[a++] = o.getOrderLackFeeSupplier();//缺货扣款
                objs[a++] = o.getSalesFeeSupplier(); // 售后扣花农款
                objs[a++] = o.getRealSaleNum(); // 实际销售扎数
                objs[a++] = o.getProfitFeeAmount(); // 结算费用
                objs[a++] = o.getSettleStatus(); // 订单状态
                dataList.add(objs);
                sn++;
            }
        }
        ExcelExportUtil excelExportUtil = new ExcelExportUtil("花农结算报表", rowsName, dataList, response);
@@ -335,5 +354,21 @@
        LocalDateTime endOfDay = endDateTime.with(LocalTime.of(17, 0, 0));
        return endOfDay;
    }
    // 计算 startDate 前一天的 17:00:00
    public static LocalDateTime calculateStartTime(LocalDate startDate) {
        // 获取前一天的日期,并将时间设为 17:00:00
        LocalDateTime previousDay = startDate.minusDays(1).atTime(LocalTime.of(17, 0, 0));
        return previousDay;
    }
    // 计算 endDate 当天的 17:00:00
    public static LocalDateTime calculateEndTime(LocalDate endDate) {
        // 将时间部分固定为 17:00:00
        LocalDateTime endOfDay = endDate.atTime(LocalTime.of(17, 0, 0));
        return endOfDay;
    }
}