|
@@ -2,27 +2,38 @@ package com.songhua.system.service.impl;
|
|
|
|
|
|
import com.songhua.common.exception.ServiceException;
|
|
import com.songhua.common.exception.ServiceException;
|
|
import com.songhua.common.utils.DateUtils;
|
|
import com.songhua.common.utils.DateUtils;
|
|
-import com.songhua.common.utils.StringUtils;
|
|
|
|
import com.songhua.system.domain.PzRawData;
|
|
import com.songhua.system.domain.PzRawData;
|
|
import com.songhua.system.domain.PzRawDataVo;
|
|
import com.songhua.system.domain.PzRawDataVo;
|
|
import com.songhua.system.domain.vo.ShhTicketRulesReqVO;
|
|
import com.songhua.system.domain.vo.ShhTicketRulesReqVO;
|
|
|
|
+import com.songhua.system.domain.vo.TicketStatisticsImpVO;
|
|
import com.songhua.system.enums.TicketRulesEnum;
|
|
import com.songhua.system.enums.TicketRulesEnum;
|
|
import com.songhua.system.mapper.PzRawDataMapper;
|
|
import com.songhua.system.mapper.PzRawDataMapper;
|
|
import com.songhua.system.service.IPzRawDataService;
|
|
import com.songhua.system.service.IPzRawDataService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
|
+import org.apache.poi.ss.util.NumberToTextConverter;
|
|
|
|
+import org.apache.poi.util.IOUtils;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
|
+import org.springframework.scheduling.annotation.EnableAsync;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
|
|
+import java.text.DateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 原始数据导入Service业务层处理
|
|
* 原始数据导入Service业务层处理
|
|
@@ -73,7 +84,6 @@ public class PzRawDataServiceImpl implements IPzRawDataService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public int insertPzRawDataVo(PzRawDataVo pzRawDataVo) {
|
|
public int insertPzRawDataVo(PzRawDataVo pzRawDataVo) {
|
|
- pzRawDataVo.setCreateTime(DateUtils.getNowDate());
|
|
|
|
return pzRawDataMapper.insertPzRawDataVo(pzRawDataVo);
|
|
return pzRawDataMapper.insertPzRawDataVo(pzRawDataVo);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -116,42 +126,151 @@ public class PzRawDataServiceImpl implements IPzRawDataService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public PzRawDataVo checkIfDataExists(String ticketName) {
|
|
|
|
- PzRawDataVo pzRawDataVo = pzRawDataMapper.checkIfDataExists(ticketName);
|
|
|
|
|
|
+ public Long checkIfDataExists(String ticketName) {
|
|
|
|
+ return pzRawDataMapper.checkIfDataExists(ticketName);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<PzRawDataVo> mapToPzRawDataVo(TicketStatisticsImpVO ticket) {
|
|
|
|
+ List<PzRawDataVo> pzRawDataVoList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ // 微信
|
|
|
|
+ pzRawDataVoList.add(createPzRawDataVo(ticket.getTicketName(), ticket.getVxNumber(), ticket.getVxMoney(), "1"));
|
|
|
|
+
|
|
|
|
+ // 支付宝
|
|
|
|
+ pzRawDataVoList.add(createPzRawDataVo(ticket.getTicketName(), ticket.getZfbNumber(), ticket.getZfbMoney(), "2"));
|
|
|
|
+
|
|
|
|
+ // 现金
|
|
|
|
+ pzRawDataVoList.add(createPzRawDataVo(ticket.getTicketName(), ticket.getXjNumber(), ticket.getXjMoney(), "3"));
|
|
|
|
+
|
|
|
|
+ // 云闪付
|
|
|
|
+ pzRawDataVoList.add(createPzRawDataVo(ticket.getTicketName(), ticket.getYsfNumber(), ticket.getYsfMoney(), "4"));
|
|
|
|
+
|
|
|
|
+ // 支付宝小程序余额支付
|
|
|
|
+ pzRawDataVoList.add(createPzRawDataVo(ticket.getTicketName(), ticket.getZfbxcxNumber(), ticket.getZfbxcxMoney(), "5"));
|
|
|
|
+
|
|
|
|
+ // 微信小程序余额支付
|
|
|
|
+ pzRawDataVoList.add(createPzRawDataVo(ticket.getTicketName(), ticket.getVxxcxNumber(), ticket.getVxxcxMoney(), "6"));
|
|
|
|
+
|
|
|
|
+ // ota余额支付
|
|
|
|
+ pzRawDataVoList.add(createPzRawDataVo(ticket.getTicketName(), ticket.getOtaNumber(), ticket.getOtaMoney(), "7"));
|
|
|
|
+
|
|
|
|
+ // 灵活代收
|
|
|
|
+ pzRawDataVoList.add(createPzRawDataVo(ticket.getTicketName(), ticket.getLhdsNumber(), ticket.getLhdsMoney(), "8"));
|
|
|
|
+
|
|
|
|
+ // 旅行社余额支付
|
|
|
|
+ pzRawDataVoList.add(createPzRawDataVo(ticket.getTicketName(), ticket.getLysNumber(), ticket.getLysMoney(), "9"));
|
|
|
|
+
|
|
|
|
+ return pzRawDataVoList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private PzRawDataVo createPzRawDataVo(String ticketName, String number, String money, String payType) {
|
|
|
|
+ PzRawDataVo pzRawDataVo = new PzRawDataVo();
|
|
|
|
+ pzRawDataVo.setTicketId(checkIfDataExists(ticketName));
|
|
|
|
+ pzRawDataVo.setNumber(Integer.parseInt(number));
|
|
|
|
+ pzRawDataVo.setMoney(new BigDecimal(money));
|
|
|
|
+ pzRawDataVo.setPayType(payType);
|
|
|
|
+ pzRawDataVo.setCreateTime(new Date()); // 假设当前时间为创建时间
|
|
return pzRawDataVo;
|
|
return pzRawDataVo;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private String getCellValue(Cell cell) {
|
|
|
|
+ String cellValue = "";
|
|
|
|
+ switch (cell.getCellType()) {
|
|
|
|
+ case _NONE: // 未知类型,用于表示初始化前的状态或缺少具体类型。仅供内部使用。
|
|
|
|
+ break;
|
|
|
|
+ case NUMERIC: // 数字类型,用于Excel日期格式化
|
|
|
|
+ if (HSSFDateUtil.isCellDateFormatted(cell)) {
|
|
|
|
+ Date d = cell.getDateCellValue();
|
|
|
|
+ DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss 'CST' yyyy", Locale.US);
|
|
|
|
+ DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
|
|
|
+ try {
|
|
|
|
+ cellValue = sdf.format(df.parse(d.toString()));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ cellValue = NumberToTextConverter.toText(cell.getNumericCellValue());
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case STRING: // 字符串类型
|
|
|
|
+ cellValue = cell.getStringCellValue();
|
|
|
|
+ break;
|
|
|
|
+ case FORMULA: // 公式类型
|
|
|
|
+ cellValue = String.valueOf(cell.getStringCellValue());
|
|
|
|
+ break;
|
|
|
|
+ case BLANK: // 空白的单元格
|
|
|
|
+ break;
|
|
|
|
+ case BOOLEAN: // 布尔类型
|
|
|
|
+ break;
|
|
|
|
+ case ERROR: // 错误类型
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ }
|
|
|
|
+ return cellValue;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * 导入用户数据
|
|
|
|
- *
|
|
|
|
- * @param userList 用户数据列表
|
|
|
|
- * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
|
|
|
|
- * @param operName 操作用户
|
|
|
|
- * @return 结果
|
|
|
|
|
|
+ * 导入
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public String importData(List<PzRawDataVo> userList, Boolean isUpdateSupport, String operName) {
|
|
|
|
- if (StringUtils.isNull(userList) || userList.size() == 0) {
|
|
|
|
- throw new ServiceException("导入用户数据不能为空!");
|
|
|
|
- }
|
|
|
|
|
|
+// @Async
|
|
|
|
+ public CompletableFuture<String> importTicket(MultipartFile file) throws IOException {
|
|
|
|
+ List<TicketStatisticsImpVO> list = new ArrayList<>();
|
|
|
|
+ int successNum = 0;
|
|
|
|
+ int failureNum = 0;
|
|
StringBuilder successMsg = new StringBuilder();
|
|
StringBuilder successMsg = new StringBuilder();
|
|
StringBuilder failureMsg = new StringBuilder();
|
|
StringBuilder failureMsg = new StringBuilder();
|
|
- for (PzRawDataVo data : userList) {
|
|
|
|
- try {
|
|
|
|
- // 检查数据是否已存在
|
|
|
|
- PzRawDataVo isExist = checkIfDataExists(data.getTicketName());
|
|
|
|
- data.setTicketId(isExist.getId());
|
|
|
|
- insertPzRawDataVo(data);
|
|
|
|
- String msg = "【成功】" + data.toString() + " 导入成功:";
|
|
|
|
- failureMsg.append(msg).append("\n");
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- String msg = "【失败】" + data.toString() + " 导入失败:" + e.getMessage();
|
|
|
|
- failureMsg.append(msg).append("\n");
|
|
|
|
|
|
+ // 获取文件输入流
|
|
|
|
+ InputStream inputStream = file.getInputStream();
|
|
|
|
+ // 读取整个excel
|
|
|
|
+ XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
|
|
|
|
+ // 获取第一个sheet页
|
|
|
|
+ XSSFSheet sheetAt = sheets.getSheetAt(0);
|
|
|
|
+ try {
|
|
|
|
+ // 从第三行开始循环获取每一行数据
|
|
|
|
+ for (int i = 2; i <= sheetAt.getPhysicalNumberOfRows(); i++) {
|
|
|
|
+ Row row = sheetAt.getRow(i);
|
|
|
|
+ list.add(new TicketStatisticsImpVO(getCellValue(row.getCell(0)), getCellValue(row.getCell(1)), getCellValue(row.getCell(2)), getCellValue(row.getCell(3)),
|
|
|
|
+ getCellValue(row.getCell(4)), getCellValue(row.getCell(5)), getCellValue(row.getCell(6)),
|
|
|
|
+ getCellValue(row.getCell(7)), getCellValue(row.getCell(8)), getCellValue(row.getCell(9)),
|
|
|
|
+ getCellValue(row.getCell(10)), getCellValue(row.getCell(11)), getCellValue(row.getCell(12)),
|
|
|
|
+ getCellValue(row.getCell(13)), getCellValue(row.getCell(14)), getCellValue(row.getCell(15)),
|
|
|
|
+ getCellValue(row.getCell(16)), getCellValue(row.getCell(17)), getCellValue(row.getCell(18))));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ failureNum++;
|
|
|
|
+ } finally {
|
|
|
|
+ IOUtils.closeQuietly(inputStream);
|
|
}
|
|
}
|
|
- return successMsg.toString();
|
|
|
|
|
|
+// 将 TicketStatisticsImpVO 映射到 PzRawDataVo 并插入数据库
|
|
|
|
+ list = list.stream().filter(item -> !item.getTicketName().contains("总计")).collect(Collectors.toList());
|
|
|
|
+ if (list.size() > 0) {
|
|
|
|
+ pzRawDataMapper.deleteByTicketName();
|
|
|
|
+ for (TicketStatisticsImpVO ticket : list) {
|
|
|
|
+ List<PzRawDataVo> pzRawDataVoList = mapToPzRawDataVo(ticket);
|
|
|
|
+ if (pzRawDataVoList == null || pzRawDataVoList.isEmpty()) {
|
|
|
|
+ throw new ServiceException("导入失败:数据映射失败。");
|
|
|
|
+ }
|
|
|
|
+ for (PzRawDataVo pzRawDataVo : pzRawDataVoList) {
|
|
|
|
+ try {
|
|
|
|
+ insertPzRawDataVo(pzRawDataVo);
|
|
|
|
+ successNum++;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ failureNum++;
|
|
|
|
+ failureMsg.append("导入失败:").append(e.getMessage()).append("\n");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ successMsg.append("导入成功:" + successNum + " 条数据,失败:" + failureNum + " 条数据。");
|
|
|
|
+ if (failureNum > 0) {
|
|
|
|
+ successMsg.append("\n").append(failureMsg);
|
|
|
|
+ }
|
|
|
|
+ return CompletableFuture.completedFuture(successMsg.toString());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void export(PzRawData pzRawData) {
|
|
public void export(PzRawData pzRawData) {
|
|
List<ShhTicketRulesReqVO> list = calculateTotalPrices(pzRawDataMapper.selectPzRawDataList(pzRawData));
|
|
List<ShhTicketRulesReqVO> list = calculateTotalPrices(pzRawDataMapper.selectPzRawDataList(pzRawData));
|