| | |
| | | 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.BaseService; |
| | | import com.mzl.flower.service.calendar.CalendarService; |
| | | 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.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class OrderReportServiceImpl implements OrderReportService { |
| | | public class OrderReportServiceImpl extends BaseService implements OrderReportService { |
| | | |
| | | @Autowired |
| | | private CalendarService calendarService; |
| | |
| | | List<OrderReportCalendarBO> calendarBOList= calendarService.getOrderDatePage(page,dto); |
| | | |
| | | final List<OrderReportResultVO> list = calendarBOList.stream().map(calendarBO -> { |
| | | BeanUtils.copyProperties(dto,calendarBO); |
| | | if(null!=dto.getPartnerId()) calendarBO.setPartnerId(dto.getPartnerId()); |
| | | OrderReportResultVO vo2=orderReportMapper.getOrderDateReport(calendarBO); |
| | | if(null==vo2) vo2=new OrderReportResultVO(); |
| | | vo2.setOrderDate(calendarBO.getCalDate()); |
| | | |
| | | return vo2; |
| | |
| | | // 计算开始时间和结束时间 |
| | | |
| | | OrderReportCalendarBO bo=new OrderReportCalendarBO(); |
| | | BeanUtils.copyProperties(dto,bo); |
| | | if(null!=dto.getPartnerId()) bo.setPartnerId(dto.getPartnerId()); |
| | | bo.setStartDate(calculateStartTime(dto.getStartDate())); |
| | | bo.setEndDate(calculateEndTime(dto.getEndDate())); |
| | | OrderReportResultVO vo2=orderReportMapper.getOrderDateReport(bo); |
| | |
| | | @Override |
| | | public void exportSalesList(HttpServletResponse response, QueryOrderDTO dto) { |
| | | |
| | | List<OrderReportCalendarBO> calendarBOList= calendarService.getOrderDateList(dto); |
| | | final List<OrderReportResultVO> list = calendarBOList.stream().map(calendarBO -> { |
| | | if(null!=dto.getPartnerId()) calendarBO.setPartnerId(dto.getPartnerId()); |
| | | OrderReportResultVO vo2=orderReportMapper.getOrderDateReport(calendarBO); |
| | | if(null==vo2) vo2=new OrderReportResultVO(); |
| | | vo2.setOrderDate(calendarBO.getCalDate()); |
| | | |
| | | return vo2; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | String[] rowsName = new String[]{"序号","下单日期", "销售额", "花农底价", "平台区间加价", "平台加价", "平台区域加价" |
| | | , "合伙人加价", "合伙人区间加价", "会员折扣","优惠券","降级扣款","缺货扣款","补货扣款","售后扣合伙人款","售后扣花农款", |
| | | "售后扣平台款","总包干费","实际销售扎数","利润","结算状态",}; |
| | | List<Object[]> dataList = new ArrayList<>(); |
| | | int sn = 1; |
| | | for (OrderReportResultVO 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.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); |
| | | } |
| | | } |
| | | |
| | | // 计算 startDate 的前一天 17:00:00 |
| | | public static LocalDateTime calculateStartTime(LocalDate startDate) { |
| | | LocalDate previousDay = startDate.minusDays(1); |
| | | LocalTime fivePM = LocalTime.of(17, 0, 0); // 下午 17:00:00 |
| | | return LocalDateTime.of(previousDay, fivePM); |
| | | public static LocalDateTime calculateStartTime(LocalDateTime startDateTime) { |
| | | // 获取 LocalDate 部分 |
| | | LocalDateTime previousDay = startDateTime.minusDays(1).with(LocalTime.of(17, 0, 0)); |
| | | return previousDay; |
| | | } |
| | | |
| | | // 计算 endDate 当天的 17:00:00 |
| | | public static LocalDateTime calculateEndTime(LocalDate endDate) { |
| | | LocalTime fivePM = LocalTime.of(17, 0, 0); // 下午 17:00:00 |
| | | return LocalDateTime.of(endDate, fivePM); |
| | | public static LocalDateTime calculateEndTime(LocalDateTime endDateTime) { |
| | | // 将时间部分固定为 17:00:00 |
| | | LocalDateTime endOfDay = endDateTime.with(LocalTime.of(17, 0, 0)); |
| | | return endOfDay; |
| | | } |
| | | } |
| | | |