|
|
@@ -0,0 +1,160 @@
|
|
|
+package com.ydtech.modules.fnc.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alipay.api.domain.TakeAwayScopeInfo;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ydtech.constants.enums.dict.InsOrderStatusAllEnum;
|
|
|
+import com.ydtech.modules.admin.model.SysUser;
|
|
|
+import com.ydtech.modules.admin.model.dto.OrdersDataExcel;
|
|
|
+import com.ydtech.modules.admin.model.report.company.OrdersDataDto;
|
|
|
+import com.ydtech.modules.base.controller.BaseController;
|
|
|
+import com.ydtech.modules.console.dto.BigOrderUploadDto;
|
|
|
+import com.ydtech.modules.fnc.dao.ImportAsyncMapper;
|
|
|
+import com.ydtech.modules.fnc.dao.InsExcelTaskAsyncMapper;
|
|
|
+import com.ydtech.modules.fnc.dto.InsExcelTaskDto;
|
|
|
+import com.ydtech.modules.fnc.entity.ImportResult;
|
|
|
+import com.ydtech.modules.fnc.entity.InsExcelTaskEntity;
|
|
|
+import com.ydtech.modules.fnc.service.InsExcelTaskAsyncService;
|
|
|
+import com.ydtech.modules.inv.model.dto.InsImportResult;
|
|
|
+import com.ydtech.modules.inv.utils.EasyExcelUtils;
|
|
|
+import com.ydtech.modules.inv.utils.excel.CustomMultiFieldMergeStrategy;
|
|
|
+import com.ydtech.modules.order.dao.InsAreaCompanyMapper;
|
|
|
+import com.ydtech.modules.order.entity.BasePageResult;
|
|
|
+import com.ydtech.utils.SnowFlakeUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class InsExcelTaskAsyncServiceImpl extends ServiceImpl<InsExcelTaskAsyncMapper, InsExcelTaskEntity> implements InsExcelTaskAsyncService {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsAreaCompanyMapper insAreaCompanyMapper;
|
|
|
+ @Value("${upload.file.path}")
|
|
|
+ private String uploadFilePath;
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${upload.file.path}")
|
|
|
+ private String uploadPath;
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Override
|
|
|
+ public void importasync(List<OrdersDataExcel> resultSubOrder, HashMap<String, String> dateMapByType) {
|
|
|
+ InsExcelTaskEntity insExcelTaskEntity = new InsExcelTaskEntity();
|
|
|
+ String taskId = String.valueOf(new SnowFlakeUtil().nextId());
|
|
|
+ insExcelTaskEntity.setId(taskId);
|
|
|
+ insExcelTaskEntity.setStatus("ready");
|
|
|
+ insExcelTaskEntity.setUserId(dateMapByType.get("userId"));
|
|
|
+ insExcelTaskEntity.setCreateTime(LocalDateTime.now());
|
|
|
+ insExcelTaskEntity.setCreatedAt(LocalDateTime.now());
|
|
|
+ insExcelTaskEntity.setType("1");
|
|
|
+ baseMapper.insert(insExcelTaskEntity);
|
|
|
+
|
|
|
+ if (!resultSubOrder.isEmpty()) {
|
|
|
+ OrdersDataDto ordersDataDto = new OrdersDataDto();
|
|
|
+ ordersDataDto.setBeginDate(dateMapByType.get("startDate"));
|
|
|
+ ordersDataDto.setEndDate(dateMapByType.get("endDate"));
|
|
|
+ for (OrdersDataExcel record : resultSubOrder) {
|
|
|
+ String licenseno = record.getLicenseno(); //车牌号
|
|
|
+ String frameno = record.getFrameno(); //车牌号
|
|
|
+ ordersDataDto.setLicenseno(licenseno);
|
|
|
+ ordersDataDto.setFrameno(frameno);
|
|
|
+ OrdersDataDto dto = insAreaCompanyMapper.getSumBigOrderCount(ordersDataDto);
|
|
|
+ String orderNumber = dto.getOrderNumber();
|
|
|
+ BigDecimal num1 = new BigDecimal(orderNumber);
|
|
|
+ BigDecimal num2 = new BigDecimal(record.getOrderNumber());
|
|
|
+ BigDecimal result = num1.divide(num2, 2, RoundingMode.HALF_UP);
|
|
|
+ record.setCloseRate(result.toString());
|
|
|
+ record.setNamesimple(dto.getNamesimple());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String uploadPath = this.uploadFilePath + "/excel/" + taskId + "/";
|
|
|
+ File folder = new File(uploadPath);
|
|
|
+ // 路劲不存在创建目录
|
|
|
+ if (!folder.isDirectory()) {
|
|
|
+ folder.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ String fileName = EasyExcelUtils.downExcel(uploadPath, "控制台大订单导出", OrdersDataExcel.class, resultSubOrder);
|
|
|
+ InsExcelTaskEntity insExcelTaskEntity1 = new InsExcelTaskEntity();
|
|
|
+ insExcelTaskEntity1.setId(taskId);
|
|
|
+ insExcelTaskEntity1.setCompletedAt(LocalDateTime.now());
|
|
|
+ insExcelTaskEntity1.setStatus("complete");
|
|
|
+ if (!CollectionUtils.isEmpty(resultSubOrder)) {
|
|
|
+ insExcelTaskEntity1.setUploadUrl("/upload/excel/" + taskId + "/" + fileName);
|
|
|
+ }
|
|
|
+ baseMapper.updateById(insExcelTaskEntity1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Async
|
|
|
+ public void importasyncBigOrder(List<BigOrderUploadDto> list,String userId) {
|
|
|
+ InsExcelTaskEntity insExcelTaskEntity = new InsExcelTaskEntity();
|
|
|
+ String taskId = String.valueOf(new SnowFlakeUtil().nextId());
|
|
|
+ insExcelTaskEntity.setId(taskId);
|
|
|
+ insExcelTaskEntity.setStatus("ready");
|
|
|
+ insExcelTaskEntity.setUserId(userId);
|
|
|
+ insExcelTaskEntity.setCreateTime(LocalDateTime.now());
|
|
|
+ insExcelTaskEntity.setCreatedAt(LocalDateTime.now());
|
|
|
+ insExcelTaskEntity.setType("0");
|
|
|
+ baseMapper.insert(insExcelTaskEntity);
|
|
|
+
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
+ for (BigOrderUploadDto bigOrderUploadDto : list) {
|
|
|
+ String orderStatus = "";
|
|
|
+ if (InsOrderStatusAllEnum.matchKey(bigOrderUploadDto.getOrderStatus()) != null) {
|
|
|
+ orderStatus = InsOrderStatusAllEnum.matchKey(bigOrderUploadDto.getOrderStatus()).getDesc();
|
|
|
+ }
|
|
|
+ String subOrderStatus = "";
|
|
|
+ if (InsOrderStatusAllEnum.matchKey(bigOrderUploadDto.getSubOrderStatus()) != null) {
|
|
|
+ subOrderStatus = InsOrderStatusAllEnum.matchKey(bigOrderUploadDto.getSubOrderStatus()).getDesc();
|
|
|
+ }
|
|
|
+ bigOrderUploadDto.setOrderStatus(orderStatus);
|
|
|
+ bigOrderUploadDto.setSubOrderStatus(subOrderStatus);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String uploadPath = this.uploadFilePath + "/excel/" + taskId + "/";
|
|
|
+
|
|
|
+ File folder = new File(uploadPath);
|
|
|
+ // 路劲不存在创建目录
|
|
|
+ if (!folder.isDirectory()) {
|
|
|
+ folder.mkdirs();
|
|
|
+ }
|
|
|
+ String fileName = EasyExcelUtils.downExcel(uploadPath, "控制台大订单明细导出", BigOrderUploadDto.class, list);
|
|
|
+ InsExcelTaskEntity insExcelTaskEntity1 = new InsExcelTaskEntity();
|
|
|
+ insExcelTaskEntity1.setId(taskId);
|
|
|
+ insExcelTaskEntity1.setCompletedAt(LocalDateTime.now());
|
|
|
+ insExcelTaskEntity1.setStatus("complete");
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
+ insExcelTaskEntity1.setUploadUrl("/upload/excel/" + taskId + "/" + fileName);
|
|
|
+ }
|
|
|
+ baseMapper.updateById(insExcelTaskEntity1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BasePageResult<InsExcelTaskEntity> queryPage(InsExcelTaskDto insExcelTaskDto) {
|
|
|
+ Page<InsExcelTaskEntity> page = new Page<>(insExcelTaskDto.getPageNum(), insExcelTaskDto.getPageSize());
|
|
|
+ Page<InsExcelTaskEntity> resultPage = baseMapper.queryPage(insExcelTaskDto, page);
|
|
|
+ return new BasePageResult<>(insExcelTaskDto.getPageNum(), page.getSize(), resultPage.getTotal(), page.getPages(),
|
|
|
+ resultPage.getRecords());
|
|
|
+ }
|
|
|
+}
|