|
@@ -1,5 +1,7 @@
|
|
|
package com.usky.dxtop.service.impl;
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
+import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -9,10 +11,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.usky.dxtop.common.core.page.CommonPage;
|
|
|
import com.usky.dxtop.common.exception.CustomException;
|
|
|
-import com.usky.dxtop.common.utils.Arith;
|
|
|
-import com.usky.dxtop.common.utils.DateUtils;
|
|
|
-import com.usky.dxtop.common.utils.QRCodeUtil;
|
|
|
-import com.usky.dxtop.common.utils.StringUtils;
|
|
|
+import com.usky.dxtop.common.utils.*;
|
|
|
import com.usky.dxtop.common.utils.http.HttpUtils;
|
|
|
import com.usky.dxtop.common.utils.sign.Base64;
|
|
|
import com.usky.dxtop.common.utils.spring.GlobalUtils;
|
|
@@ -24,15 +23,29 @@ import com.usky.dxtop.service.OrderService;
|
|
|
import com.usky.dxtop.service.api.TopApi;
|
|
|
import com.usky.dxtop.service.emun.OrderPayType;
|
|
|
import com.usky.dxtop.service.emun.OrderStatus;
|
|
|
+import com.usky.dxtop.service.vo.OrderExport;
|
|
|
+import com.usky.dxtop.service.vo.OrderReport;
|
|
|
import com.usky.dxtop.service.vo.OrderRequest;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import ma.glasnost.orika.MapperFacade;
|
|
|
+import ma.glasnost.orika.MapperFactory;
|
|
|
+import ma.glasnost.orika.impl.DefaultMapperFactory;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.FastByteArrayOutputStream;
|
|
|
import javax.imageio.ImageIO;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
import java.util.TreeMap;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -255,6 +268,106 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String exportDetail(OrderRequest orderRequest) {
|
|
|
+ Workbook workbook = null;
|
|
|
+ File file = null;
|
|
|
+ try {
|
|
|
+ ExportParams params = new ExportParams(null, "订单详情");
|
|
|
+ workbook = ExcelExportUtil.exportBigExcel(params, OrderExport.class,
|
|
|
+ (o, i) -> {
|
|
|
+ orderRequest.setCurrent(i);
|
|
|
+ orderRequest.setSize(30);
|
|
|
+ CommonPage<Order> page = this.list(orderRequest);
|
|
|
+ return page.getRecords().stream().map(this::orderChangeOrderExport).collect(Collectors.toList());
|
|
|
+ },null);
|
|
|
+ if (null != workbook) {
|
|
|
+ file = FileUtils.getFile(GlobalUtils.getTempBaseDir(), String.format("%s-%s.xlsx", "订单详情", System.currentTimeMillis() + ""));
|
|
|
+ FileOutputStream allListingFileOutputStream = new FileOutputStream(file);
|
|
|
+ workbook.write(allListingFileOutputStream);
|
|
|
+ } else {
|
|
|
+ throw new CustomException("表格数据为空");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导出文件失败", e);
|
|
|
+ throw new CustomException("导出文件失败");
|
|
|
+ } finally {
|
|
|
+ if (workbook != null) {
|
|
|
+ try {
|
|
|
+ workbook.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("===export spec=== 关闭workbook失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return file.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ public OrderExport orderChangeOrderExport(Order order){
|
|
|
+ MapperFactory factory = new DefaultMapperFactory.Builder().build();
|
|
|
+ factory.classMap(Order.class, OrderExport.class)
|
|
|
+ .exclude("orderFlag")
|
|
|
+ .exclude("payType")
|
|
|
+ .byDefault().register();
|
|
|
+ MapperFacade mapper = factory.getMapperFacade();
|
|
|
+ OrderExport orderExport = mapper.map(order, OrderExport.class);
|
|
|
+ orderExport.setOrderFlag(OrderStatus.parse(order.getOrderFlag()).getName());
|
|
|
+ orderExport.setPayType(OrderPayType.parse(order.getPayType()).getName());
|
|
|
+ return orderExport;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonPage<OrderReport> orderReportList(Integer current,Integer size,Date startTime, Date endTime, Integer type) {
|
|
|
+ IPage<OrderReport> page = new Page<>(current, size);
|
|
|
+ switch (type){
|
|
|
+ case 1 :
|
|
|
+ page = baseMapper.getCountByDay(page, startTime, endTime);
|
|
|
+ break;
|
|
|
+ case 2 :
|
|
|
+ page = baseMapper.getCountByWeek(page, startTime, endTime);
|
|
|
+ break;
|
|
|
+ case 3 :
|
|
|
+ page = baseMapper.getCountByMonth(page, startTime, endTime);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ page = baseMapper.getCountByYear(page, startTime, endTime);
|
|
|
+ }
|
|
|
+ return new CommonPage<>(page.getRecords(),page.getTotal(),page.getCurrent(),page.getSize());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String reportExport(Date startTime, Date endTime, Integer type) {
|
|
|
+ Workbook workbook = null;
|
|
|
+ File file = null;
|
|
|
+ try {
|
|
|
+ ExportParams params = new ExportParams(null, "订单明细");
|
|
|
+ workbook = ExcelExportUtil.exportBigExcel(params, OrderReport.class,
|
|
|
+ (o, i) -> {
|
|
|
+ CommonPage<OrderReport> list = this.orderReportList(i,30,startTime,endTime,type);
|
|
|
+ return new ArrayList<>(list.getRecords());
|
|
|
+ },null);
|
|
|
+ if (null != workbook) {
|
|
|
+ file = FileUtils.getFile(GlobalUtils.getTempBaseDir(), String.format("%s-%s.xlsx", "订单明细", System.currentTimeMillis() + ""));
|
|
|
+ FileOutputStream allListingFileOutputStream = new FileOutputStream(file);
|
|
|
+ workbook.write(allListingFileOutputStream);
|
|
|
+ } else {
|
|
|
+ throw new CustomException("表格数据为空");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导出文件失败", e);
|
|
|
+ throw new CustomException("导出文件失败");
|
|
|
+ } finally {
|
|
|
+ if (workbook != null) {
|
|
|
+ try {
|
|
|
+ workbook.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("===export spec=== 关闭workbook失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return file.getName();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 充值失败后处理
|
|
|
* @param order
|