|
@@ -1,120 +1,117 @@
|
|
|
package com.songhua.system.service.impl;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
import com.songhua.common.exception.ServiceException;
|
|
|
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 org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
import com.songhua.system.mapper.PzRawDataMapper;
|
|
|
-import com.songhua.system.domain.PzRawData;
|
|
|
import com.songhua.system.service.IPzRawDataService;
|
|
|
+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;
|
|
|
|
|
|
/**
|
|
|
* 原始数据导入Service业务层处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author ruoyi
|
|
|
* @date 2024-11-04
|
|
|
*/
|
|
|
@Service
|
|
|
-public class PzRawDataServiceImpl implements IPzRawDataService
|
|
|
-{
|
|
|
+public class PzRawDataServiceImpl implements IPzRawDataService {
|
|
|
@Autowired
|
|
|
private PzRawDataMapper pzRawDataMapper;
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 查询原始数据导入
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 原始数据导入主键
|
|
|
* @return 原始数据导入
|
|
|
*/
|
|
|
@Override
|
|
|
- public PzRawData selectPzRawDataById(Long id)
|
|
|
- {
|
|
|
+ public PzRawData selectPzRawDataById(Long id) {
|
|
|
return pzRawDataMapper.selectPzRawDataById(id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询原始数据导入列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param pzRawData 原始数据导入
|
|
|
* @return 原始数据导入
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<PzRawDataVo> selectPzRawDataList(PzRawData pzRawData)
|
|
|
- {
|
|
|
+ public List<PzRawDataVo> selectPzRawDataList(PzRawData pzRawData) {
|
|
|
return pzRawDataMapper.selectPzRawDataList(pzRawData);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增原始数据导入
|
|
|
- *
|
|
|
+ *
|
|
|
* @param pzRawData 原始数据导入
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertPzRawData(PzRawData pzRawData)
|
|
|
- {
|
|
|
+ public int insertPzRawData(PzRawData pzRawData) {
|
|
|
pzRawData.setCreateTime(DateUtils.getNowDate());
|
|
|
return pzRawDataMapper.insertPzRawData(pzRawData);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int insertPzRawDataVo(PzRawDataVo pzRawDataVo)
|
|
|
- {
|
|
|
+ public int insertPzRawDataVo(PzRawDataVo pzRawDataVo) {
|
|
|
pzRawDataVo.setCreateTime(DateUtils.getNowDate());
|
|
|
return pzRawDataMapper.insertPzRawDataVo(pzRawDataVo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改原始数据导入
|
|
|
- *
|
|
|
+ *
|
|
|
* @param pzRawData 原始数据导入
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updatePzRawData(PzRawData pzRawData)
|
|
|
- {
|
|
|
+ public int updatePzRawData(PzRawData pzRawData) {
|
|
|
return pzRawDataMapper.updatePzRawData(pzRawData);
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
- public int updatePzRawDataVo(PzRawDataVo pzRawDataVo)
|
|
|
- {
|
|
|
+ public int updatePzRawDataVo(PzRawDataVo pzRawDataVo) {
|
|
|
return pzRawDataMapper.updatePzRawDataVo(pzRawDataVo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量删除原始数据导入
|
|
|
- *
|
|
|
+ *
|
|
|
* @param ids 需要删除的原始数据导入主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deletePzRawDataByIds(Long[] ids)
|
|
|
- {
|
|
|
+ public int deletePzRawDataByIds(Long[] ids) {
|
|
|
return pzRawDataMapper.deletePzRawDataByIds(ids);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除原始数据导入信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 原始数据导入主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deletePzRawDataById(Long id)
|
|
|
- {
|
|
|
+ public int deletePzRawDataById(Long id) {
|
|
|
return pzRawDataMapper.deletePzRawDataById(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public PzRawDataVo checkIfDataExists(String ticketName)
|
|
|
- {
|
|
|
+ public PzRawDataVo checkIfDataExists(String ticketName) {
|
|
|
PzRawDataVo pzRawDataVo = pzRawDataMapper.checkIfDataExists(ticketName);
|
|
|
return pzRawDataVo;
|
|
|
}
|
|
@@ -140,7 +137,7 @@ public class PzRawDataServiceImpl implements IPzRawDataService
|
|
|
PzRawDataVo isExist = checkIfDataExists(data.getTicketName());
|
|
|
data.setTicketId(isExist.getId());
|
|
|
insertPzRawDataVo(data);
|
|
|
- String msg = "【成功】" + data.toString() + " 导入成功:" ;
|
|
|
+ String msg = "【成功】" + data.toString() + " 导入成功:";
|
|
|
failureMsg.append(msg).append("\n");
|
|
|
} catch (Exception e) {
|
|
|
String msg = "【失败】" + data.toString() + " 导入失败:" + e.getMessage();
|
|
@@ -150,5 +147,60 @@ public class PzRawDataServiceImpl implements IPzRawDataService
|
|
|
return successMsg.toString();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void export(PzRawData pzRawData) {
|
|
|
+ List<PzRawDataVo> list = pzRawDataMapper.selectPzRawDataList(pzRawData);
|
|
|
+ // 创建
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ Sheet sheet = workbook.createSheet("票务数据");
|
|
|
+
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
+ CellStyle style = workbook.createCellStyle(); // 创建单元格样式
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER); // 设置水平居中对齐
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER); // 设置垂直居中
|
|
|
+ Cell cell1 = headerRow.createCell(0);
|
|
|
+ cell1.setCellValue("票种名");
|
|
|
+ cell1.setCellStyle(style);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
|
|
|
+
|
|
|
+ Cell cell2 = headerRow.createCell(1);
|
|
|
+ cell2.setCellValue("总计");
|
|
|
+ cell2.setCellStyle(style);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 1, 2));
|
|
|
+
|
|
|
+ // 创建子标题行
|
|
|
+ Row subHeaderRow = sheet.createRow(1);
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER); // 设置水平居中对齐
|
|
|
+ Cell sonCell1 = subHeaderRow.createCell(1);
|
|
|
+ sonCell1.setCellValue("张数");
|
|
|
+ sonCell1.setCellStyle(style);
|
|
|
+ Cell sonCell2 = subHeaderRow.createCell(2);
|
|
|
+ sonCell2.setCellValue("金额");
|
|
|
+ sonCell2.setCellStyle(style);
|
|
|
+ // 填充数据
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ PzRawDataVo 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()); // 假设有这个方法
|
|
|
+ }
|
|
|
+ // 写入
|
|
|
+ try (FileOutputStream fileOut = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\出票数据" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xlsx")) {
|
|
|
+ workbook.write(fileOut);
|
|
|
+ System.out.println("Excel 文件已成功导出!");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ //关闭
|
|
|
+ workbook.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|