|
@@ -5,20 +5,21 @@ import com.songhua.common.utils.DateUtils;
|
|
|
import com.songhua.common.utils.StringUtils;
|
|
|
import com.songhua.system.domain.PzRawData;
|
|
|
import com.songhua.system.domain.PzRawDataVo;
|
|
|
+import com.songhua.system.domain.vo.ShhTicketRulesReqVO;
|
|
|
+import com.songhua.system.enums.TicketRulesEnum;
|
|
|
import com.songhua.system.mapper.PzRawDataMapper;
|
|
|
import com.songhua.system.service.IPzRawDataService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 原始数据导入Service业务层处理
|
|
@@ -26,6 +27,7 @@ import java.util.List;
|
|
|
* @author ruoyi
|
|
|
* @date 2024-11-04
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class PzRawDataServiceImpl implements IPzRawDataService {
|
|
|
@Autowired
|
|
@@ -149,11 +151,11 @@ public class PzRawDataServiceImpl implements IPzRawDataService {
|
|
|
|
|
|
@Override
|
|
|
public void export(PzRawData pzRawData) {
|
|
|
- List<PzRawDataVo> list = pzRawDataMapper.selectPzRawDataList(pzRawData);
|
|
|
+ List<ShhTicketRulesReqVO> list = calculateTotalPrice(pzRawDataMapper.selectPzRawDataList(pzRawData));
|
|
|
// 创建
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
Sheet sheet = workbook.createSheet("票务数据");
|
|
|
-
|
|
|
+ sheet.setColumnWidth(0, 20 * 260);//设置单元格宽度 ,X代表第几列
|
|
|
Row headerRow = sheet.createRow(0);
|
|
|
CellStyle style = workbook.createCellStyle(); // 创建单元格样式
|
|
|
style.setAlignment(HorizontalAlignment.CENTER); // 设置水平居中对齐
|
|
@@ -170,7 +172,6 @@ public class PzRawDataServiceImpl implements IPzRawDataService {
|
|
|
|
|
|
// 创建子标题行
|
|
|
Row subHeaderRow = sheet.createRow(1);
|
|
|
- style.setAlignment(HorizontalAlignment.CENTER); // 设置水平居中对齐
|
|
|
Cell sonCell1 = subHeaderRow.createCell(1);
|
|
|
sonCell1.setCellValue("张数");
|
|
|
sonCell1.setCellStyle(style);
|
|
@@ -179,16 +180,16 @@ public class PzRawDataServiceImpl implements IPzRawDataService {
|
|
|
sonCell2.setCellStyle(style);
|
|
|
// 填充数据
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
- PzRawDataVo data = list.get(i);
|
|
|
+ ShhTicketRulesReqVO data = list.get(i);
|
|
|
Row dataRow = sheet.createRow(i + 2); // 从第三行开始填充数据
|
|
|
- dataRow.createCell(0).setCellValue(data.getTicketName()); // 假设有这个方法
|
|
|
- dataRow.createCell(1).setCellValue(data.getNumber()); // 假设有这个方法
|
|
|
- dataRow.createCell(2).setCellValue(data.getMoney()); // 假设有这个方法
|
|
|
+ dataRow.createCell(0).setCellValue(data.getTicketName());
|
|
|
+ dataRow.createCell(1).setCellValue(data.getNumberSheets());
|
|
|
+ dataRow.createCell(2).setCellValue(String.valueOf(data.getAmount()));
|
|
|
}
|
|
|
// 写入
|
|
|
try (FileOutputStream fileOut = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\出票数据" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xlsx")) {
|
|
|
workbook.write(fileOut);
|
|
|
- System.out.println("Excel 文件已成功导出!");
|
|
|
+ log.info("Excel 文件已成功导出!");
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
@@ -199,7 +200,29 @@ public class PzRawDataServiceImpl implements IPzRawDataService {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 统计导出计算总价公式
|
|
|
+ * @param list
|
|
|
+ * @return
|
|
|
+ * */
|
|
|
+ public List<ShhTicketRulesReqVO> calculateTotalPrice(List<PzRawDataVo> list) {
|
|
|
+ List<ShhTicketRulesReqVO> returnList = new ArrayList<>();
|
|
|
+ Map<String, PzRawDataVo> map = new HashMap<>();
|
|
|
+ list.forEach(e -> {
|
|
|
+ String name = TicketRulesEnum.getKeyByValue(e.getTicketId());
|
|
|
+ if (map.containsKey(name)) {
|
|
|
+ //如果有相同的票种,则累加数量和金额
|
|
|
+ PzRawDataVo pzRawDataVo = map.get(name);
|
|
|
+ pzRawDataVo.setNumber(pzRawDataVo.getNumber() + e.getNumber());
|
|
|
+ pzRawDataVo.setMoney(pzRawDataVo.getMoney().add(e.getMoney()));
|
|
|
+ } else {
|
|
|
+ map.put(TicketRulesEnum.getKeyByValue(e.getTicketId()), e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ map.forEach((k, v) -> returnList.add(new ShhTicketRulesReqVO(k, v.getNumber(), v.getMoney())));
|
|
|
+ return returnList;
|
|
|
}
|
|
|
|
|
|
|