| | |
| | | package com.mzl.flower.service.impl.report; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.mzl.flower.config.exception.ValidationException; |
| | | import com.mzl.flower.dto.request.report.QueryOrderDTO; |
| | | import com.mzl.flower.dto.request.report.QueryPartnerOrderDTO; |
| | | import com.mzl.flower.dto.response.report.OrderDetailReportResultVO; |
| | | import com.mzl.flower.dto.response.report.OrderPartnerReportResultVO; |
| | | import com.mzl.flower.dto.response.report.OrderReportCalendarBO; |
| | | import com.mzl.flower.dto.response.report.OrderReportResultVO; |
| | | import com.mzl.flower.mapper.report.OrderReportMapper; |
| | |
| | | import com.mzl.flower.service.report.OrderReportService; |
| | | import com.mzl.flower.utils.ExcelExportUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | 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; |
| | | import java.util.Calendar; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | |
| | | return vo2; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | page.setRecords(list); |
| | | return page; |
| | | } |
| | | |
| | | @Override |
| | | public Page<OrderDetailReportResultVO> getOrderDetailPage(Page page, QueryOrderDTO dto) { |
| | | OrderReportCalendarBO orderReportCalendarBO = new OrderReportCalendarBO(); |
| | | if (StringUtils.isEmpty(dto.getCalDate())) { |
| | | throw new ValidationException("日期不能为空"); |
| | | } |
| | | LocalDateTime orderTime = dto.getCalDate().atStartOfDay(); |
| | | orderReportCalendarBO.setPartnerId(dto.getPartnerId()); |
| | | orderReportCalendarBO.setStartDate(calculateStartTime(orderTime)); |
| | | orderReportCalendarBO.setEndDate(calculateEndTime(orderTime)); |
| | | List<OrderDetailReportResultVO> list = orderReportMapper.getOrderDetailReport(orderReportCalendarBO, page); |
| | | page.setRecords(list); |
| | | return page; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void exportOrderDetail(HttpServletResponse response, QueryOrderDTO dto) { |
| | | |
| | | if (StringUtils.isEmpty(dto.getCalDate())) { |
| | | throw new ValidationException("日期不能为空"); |
| | | } |
| | | OrderReportCalendarBO orderReportCalendarBO = new OrderReportCalendarBO(); |
| | | LocalDateTime orderTime = dto.getCalDate().atStartOfDay(); |
| | | orderReportCalendarBO.setPartnerId(dto.getPartnerId()); |
| | | orderReportCalendarBO.setStartDate(calculateStartTime(orderTime)); |
| | | orderReportCalendarBO.setEndDate(calculateEndTime(orderTime)); |
| | | List<OrderDetailReportResultVO> odrs = orderReportMapper.getOrderDetailReport(orderReportCalendarBO, null); |
| | | String[] rowsName = new String[]{"序号","订单号", "下单用户", "收货人地址", "合伙人", "下单时间", "订单金额" |
| | | , "花农底价", "平台区间加价", "平台加价", "平台区域加价", "合伙人加价", "合伙人区间加价", "会员折扣" |
| | | , "优惠券", "降级扣款", "缺货扣款", "补货扣款", "售后扣合伙人款", "售后扣花农款", "售后扣平台款", "总包干费" |
| | | , "销售扎数", "利润", "结算状态"}; |
| | | List<Object[]> dataList = new ArrayList<>(); |
| | | int sn = 1; |
| | | for (OrderDetailReportResultVO o : odrs) { |
| | | Object[] objs = new Object[rowsName.length]; |
| | | int a = 0; |
| | | objs[a++] = sn; |
| | | objs[a++] = o.getOrderNo(); |
| | | objs[a++] = o.getCustomer(); |
| | | objs[a++] = o.getAddress(); |
| | | objs[a++] = o.getPartnerName(); |
| | | objs[a++] = o.getOrderDate(); |
| | | objs[a++] = o.getOrderTotal(); |
| | | objs[a++] = o.getOrderSupplierPriceAmount(); |
| | | objs[a++] = o.getOrderMarkupOneAmount(); |
| | | objs[a++] = o.getOrderMarkupTwoAmount(); |
| | | objs[a++] = o.getPlatformAreaFeeAmount(); |
| | | objs[a++] = o.getOrderMarkupPartnerAmount(); |
| | | objs[a++] = o.getPartnerSectionFeeAmount(); |
| | | objs[a++] = o.getOrderPriceDiscountAmount(); |
| | | objs[a++] = o.getOrderCouponAmountTotal(); |
| | | objs[a++] = o.getOrderCheckFee(); |
| | | objs[a++] = o.getOrderLackFeeSupplier(); |
| | | objs[a++] = o.getOrderReplaceFee(); |
| | | objs[a++] = o.getOrderFeePartner(); |
| | | objs[a++] = o.getOrderFeeSupplier(); |
| | | objs[a++] = o.getOrderFeePlatform(); |
| | | objs[a++] = o.getPartnerTotalFeeAmount(); |
| | | objs[a++] = o.getRealSaleNum(); |
| | | objs[a++] = o.getProfitFeeAmount(); |
| | | objs[a++] = o.getSettleStatus(); |
| | | dataList.add(objs); |
| | | |
| | | sn++; |
| | | } |
| | | ExcelExportUtil excelExportUtil = new ExcelExportUtil("订单结算明细", rowsName, dataList, response); |
| | | try { |
| | | response.addHeader("filename", URLEncoder.encode("订单结算明细.xls", "UTF-8")); |
| | | response.addHeader("Access-Control-Expose-Headers", "filename"); |
| | | excelExportUtil.export(); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public Page<OrderPartnerReportResultVO> getPartnerSalePage(Page page, QueryPartnerOrderDTO dto) { |
| | | Page<OrderPartnerReportResultVO> result=orderReportMapper.getPartnerOrderDateReportPage(page,dto); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public OrderPartnerReportResultVO getPartnerSaleStatis(QueryPartnerOrderDTO dto) { |
| | | OrderPartnerReportResultVO vo2=orderReportMapper.getPartnerOrderDateReportStatis(dto); |
| | | return vo2; |
| | | } |
| | | |
| | | @Override |
| | | public void exportPartnerSalesList(HttpServletResponse response, QueryPartnerOrderDTO dto) { |
| | | List<OrderPartnerReportResultVO> list = orderReportMapper.getPartnerOrderDateReportList(dto); |
| | | |
| | | |
| | | String[] rowsName = new String[]{"序号","下单日期", "合伙人ID", "合伙人","底价" |
| | | , "合伙人加价", "会员折扣","优惠券","售后扣合伙人款","总包干费","实际销售扎数"}; |
| | | List<Object[]> dataList = new ArrayList<>(); |
| | | int sn = 1; |
| | | for (OrderPartnerReportResultVO o : list) { |
| | | Object[] objs = new Object[rowsName.length]; |
| | | int a = 0; |
| | | objs[a++] = sn; // 序号 |
| | | objs[a++] = o.getOrderDate(); // 下单日期 |
| | | objs[a++] = o.getPartnerId(); // 合伙人ID |
| | | objs[a++] = o.getPartnerName(); // 合伙人 |
| | | objs[a++] = o.getOrderPartnerPriceAmount(); // 合伙人底价 |
| | | objs[a++] = o.getOrderMarkupPartnerAmount(); //合伙人加价 |
| | | objs[a++] = o.getOrderPriceDiscountAmount();//会员折扣 |
| | | objs[a++] = o.getOrderCouponAmountTotal(); // 优惠券 |
| | | objs[a++] = o.getOrderFeePartner(); //售后扣合伙人款 |
| | | objs[a++] = o.getPartnerTotalFeeAmount(); // 总包干费 |
| | | objs[a++] = o.getRealSaleNum(); // 实际销售扎数 |
| | | dataList.add(objs); |
| | | sn++; |
| | | } |
| | | |
| | | ExcelExportUtil excelExportUtil = new ExcelExportUtil("合伙人财务报表", rowsName, dataList, response); |
| | | try { |
| | | response.addHeader("filename", URLEncoder.encode("合伙人财务报表.xls", "UTF-8")); |
| | | response.addHeader("Access-Control-Expose-Headers", "filename"); |
| | | excelExportUtil.export(); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | // 计算 startDate 的前一天 17:00:00 |
| | | public static LocalDateTime calculateStartTime(LocalDateTime startDateTime) { |
| | | // 获取 LocalDate 部分 |