|
@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.usky.dxtop.common.core.domain.model.LoginUser;
|
|
|
import com.usky.dxtop.common.core.page.CommonPage;
|
|
|
import com.usky.dxtop.common.exception.CustomException;
|
|
|
import com.usky.dxtop.common.utils.*;
|
|
@@ -20,6 +21,7 @@ import com.usky.dxtop.model.*;
|
|
|
import com.usky.dxtop.service.*;
|
|
|
import com.usky.dxtop.service.api.TopApi;
|
|
|
import com.usky.dxtop.service.config.rabbitmq.charge.ChargeConsumeConfig;
|
|
|
+import com.usky.dxtop.service.emun.AsyncResultType;
|
|
|
import com.usky.dxtop.service.emun.OrderPayType;
|
|
|
import com.usky.dxtop.service.emun.OrderSceneCode;
|
|
|
import com.usky.dxtop.service.emun.OrderStatus;
|
|
@@ -34,14 +36,16 @@ import ma.glasnost.orika.impl.DefaultMapperFactory;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
+import org.springframework.aop.framework.AopContext;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.FastByteArrayOutputStream;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
@@ -85,6 +89,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
|
|
|
@Autowired
|
|
|
private StaffService staffService;
|
|
|
+ @Autowired
|
|
|
+ private ISysAsyncTaskService sysAsyncTaskService;
|
|
|
+ @Autowired
|
|
|
+ private SysFileService sysFileService;
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
@@ -292,8 +300,22 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
this.updateById(order);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public void exportDetail(OrderRequest orderRequest,HttpServletResponse response) {
|
|
|
+ public String exportDetail(OrderRequest orderRequest) {
|
|
|
+ LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
+ SysUser user = loginUser.getUser();
|
|
|
+ Long taskId = sysAsyncTaskService.getId(user.getUserName(), AsyncResultType.FILE.name());
|
|
|
+ if (null == taskId) {
|
|
|
+ throw new CustomException("获取次数太多了请稍后获取");
|
|
|
+ }
|
|
|
+ ((OrderServiceImpl) AopContext.currentProxy()).syncOrder(taskId,orderRequest);
|
|
|
+ return String.valueOf(taskId);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ public void syncOrder(Long taskId,OrderRequest orderRequest){
|
|
|
Workbook workbook = null;
|
|
|
try {
|
|
|
ExportParams params = new ExportParams(null, "订单详情");
|
|
@@ -306,13 +328,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
},null);
|
|
|
if (null != workbook) {
|
|
|
String fileName = String.format("%s.xls", "订单详情");
|
|
|
- ExcelUtils.downLoadExcel(fileName,response,workbook);
|
|
|
+ MultipartFile multipartFile = ExcelUtils.downLoadExcel(workbook, fileName);
|
|
|
+ uploadOrderFile(multipartFile,taskId);
|
|
|
} else {
|
|
|
- throw new CustomException("表格数据为空");
|
|
|
+ sysAsyncTaskService.sendResult(taskId, false, "订单表格数据为空", AsyncResultType.TEXT);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("导出文件失败", e);
|
|
|
- throw new CustomException("导出文件失败");
|
|
|
+ sysAsyncTaskService.sendResult(taskId, false, "导出订单文件失败", AsyncResultType.TEXT);
|
|
|
} finally {
|
|
|
if (workbook != null) {
|
|
|
try {
|
|
@@ -324,6 +347,31 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void uploadOrderFile(MultipartFile multipartFile, Long taskId){
|
|
|
+ List<MultipartFile> list = new ArrayList<>();
|
|
|
+ list.add(multipartFile);
|
|
|
+ String batchNo = sysFileService.generateBatchNo();
|
|
|
+ SysFile sysFile = new SysFile();
|
|
|
+ sysFile.setBatchNo(batchNo);
|
|
|
+ sysFile.setFiles(list);
|
|
|
+ sysFile.setUploadType(SysFileServiceImpl.FILE);
|
|
|
+ sysFile.setBusinessType("订单报表导出");
|
|
|
+ sysFile.setExpriceAt(DateUtils.addDays(new Date(), 3));
|
|
|
+ List<SysFile> sysFileList = sysFileService.addFile(sysFile);
|
|
|
+ long count = sysFileList.stream().filter(sysFileDTO -> !sysFileDTO.getSuccess()).count();
|
|
|
+ if (count > 0) {
|
|
|
+ sysAsyncTaskService.sendResult(taskId, false, "上传文件失败", AsyncResultType.TEXT);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<String> idList = sysFileList.stream().map(sf -> sf.getId().toString()).collect(Collectors.toList());
|
|
|
+ boolean active = sysFileService.active(batchNo,idList);
|
|
|
+ if (active) {
|
|
|
+ sysAsyncTaskService.sendResult(taskId, true, batchNo, AsyncResultType.FILE);
|
|
|
+ } else {
|
|
|
+ sysAsyncTaskService.sendResult(taskId, false, "上传文件失败", AsyncResultType.TEXT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public OrderExport orderChangeOrderExport(Order order){
|
|
|
MapperFactory factory = new DefaultMapperFactory.Builder().build();
|
|
|
factory.classMap(Order.class, OrderExport.class)
|
|
@@ -363,8 +411,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
"sum(if(pay_type = '2', money, 0)) as wxMoney",
|
|
|
"sum(if(pay_type = '3', money, 0)) as zfbMoney")
|
|
|
.between(null != startTime && null != endTime,"create_time",startTime,endTime)
|
|
|
+ .eq("order_flag",OrderStatus.COMPLETE.getCode())
|
|
|
.groupBy("reportDate")
|
|
|
- .orderByAsc("reportDate");
|
|
|
+ .orderByDesc("reportDate");
|
|
|
IPage<Map<String, Object>> mapIPage = baseMapper.selectMapsPage(page, queryWrapper);
|
|
|
String jsonStr = JSON.toJSONString(mapIPage.getRecords());
|
|
|
List<OrderReport> orderReports = JSON.parseArray(jsonStr, OrderReport.class);
|
|
@@ -372,24 +421,36 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void reportExport(Date startTime, Date endTime, Integer type, HttpServletResponse response) {
|
|
|
+ public String reportExport(Date startTime, Date endTime, Integer type) {
|
|
|
+ LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
+ SysUser user = loginUser.getUser();
|
|
|
+ Long taskId = sysAsyncTaskService.getId(user.getUserName(), AsyncResultType.FILE.name());
|
|
|
+ if (null == taskId) {
|
|
|
+ throw new CustomException("获取次数太多了请稍后获取");
|
|
|
+ }
|
|
|
+ ((OrderServiceImpl) AopContext.currentProxy()).syncOrderBusiness(taskId,startTime,endTime,type);
|
|
|
+ return String.valueOf(taskId);
|
|
|
+ }
|
|
|
+ @Async
|
|
|
+ public void syncOrderBusiness(Long taskId,Date startTime, Date endTime, Integer type){
|
|
|
Workbook workbook = null;
|
|
|
try {
|
|
|
- ExportParams params = new ExportParams(null, "订单统计");
|
|
|
+ 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) {
|
|
|
- String fileName = String.format("%s.xls", "订单统计");
|
|
|
- ExcelUtils.downLoadExcel(fileName,response,workbook);
|
|
|
+ String fileName = String.format("%s.xls", "订单报表");
|
|
|
+ MultipartFile multipartFile = ExcelUtils.downLoadExcel(workbook, fileName);
|
|
|
+ uploadOrderBusinessFile(multipartFile,taskId);
|
|
|
} else {
|
|
|
- throw new CustomException("表格数据为空");
|
|
|
+ sysAsyncTaskService.sendResult(taskId, false, "订单表格数据为空", AsyncResultType.TEXT);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("导出文件失败", e);
|
|
|
- throw new CustomException("导出文件失败");
|
|
|
+ sysAsyncTaskService.sendResult(taskId, false, "导出订单文件失败", AsyncResultType.TEXT);
|
|
|
} finally {
|
|
|
if (workbook != null) {
|
|
|
try {
|
|
@@ -400,6 +461,33 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void uploadOrderBusinessFile(MultipartFile multipartFile, Long taskId){
|
|
|
+ List<MultipartFile> list = new ArrayList<>();
|
|
|
+ list.add(multipartFile);
|
|
|
+ String batchNo = sysFileService.generateBatchNo();
|
|
|
+ SysFile sysFile = new SysFile();
|
|
|
+ sysFile.setBatchNo(batchNo);
|
|
|
+ sysFile.setFiles(list);
|
|
|
+ sysFile.setUploadType(SysFileServiceImpl.FILE);
|
|
|
+ sysFile.setBusinessType("订单");
|
|
|
+ sysFile.setExpriceAt(DateUtils.addDays(new Date(), 3));
|
|
|
+ List<SysFile> sysFileList = sysFileService.addFile(sysFile);
|
|
|
+ long count = sysFileList.stream().filter(sysFileDTO -> !sysFileDTO.getSuccess()).count();
|
|
|
+ if (count > 0) {
|
|
|
+ sysAsyncTaskService.sendResult(taskId, false, "上传文件失败", AsyncResultType.TEXT);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<String> idList = sysFileList.stream().map(sf -> sf.getId().toString()).collect(Collectors.toList());
|
|
|
+ boolean active = sysFileService.active(batchNo,idList);
|
|
|
+ if (active) {
|
|
|
+ sysAsyncTaskService.sendResult(taskId, true, batchNo, AsyncResultType.FILE);
|
|
|
+ } else {
|
|
|
+ sysAsyncTaskService.sendResult(taskId, false, "上传文件失败", AsyncResultType.TEXT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public String callUnifiedPay(Order order) {
|