|
@@ -2,7 +2,7 @@ package com.songhua.system.service.impl;
|
|
|
|
|
|
import com.songhua.common.exception.ServiceException;
|
|
|
import com.songhua.common.utils.DateUtils;
|
|
|
-import com.songhua.common.utils.poi.ExcelUtil;
|
|
|
+import com.songhua.common.utils.file.FileUtils;
|
|
|
import com.songhua.system.domain.PzRawData;
|
|
|
import com.songhua.system.domain.PzRawDataVo;
|
|
|
import com.songhua.system.domain.vo.ShhTicketRulesReqVO;
|
|
@@ -11,7 +11,6 @@ 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.commons.collections4.CollectionUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
@@ -24,10 +23,10 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.net.URLEncoder;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
@@ -46,6 +45,9 @@ public class PzRawDataServiceImpl implements IPzRawDataService {
|
|
|
@Autowired
|
|
|
private PzRawDataMapper pzRawDataMapper;
|
|
|
|
|
|
+ private final String reportFileUrlWin = "D:\\report\\";
|
|
|
+
|
|
|
+ private final String reportFileUrlLinux = "/u01/report/";
|
|
|
|
|
|
/**
|
|
|
* 查询原始数据导入
|
|
@@ -271,8 +273,7 @@ public class PzRawDataServiceImpl implements IPzRawDataService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void export(HttpServletResponse response, PzRawData pzRawData) throws IOException {
|
|
|
- ExcelUtil<ShhTicketRulesReqVO> util = new ExcelUtil<ShhTicketRulesReqVO>(ShhTicketRulesReqVO.class);
|
|
|
+ public Map<String, String> export(HttpServletResponse response, PzRawData pzRawData) throws IOException {
|
|
|
List<ShhTicketRulesReqVO> list = calculateTotalPrices(pzRawDataMapper.selectPzRawDataList(pzRawData));
|
|
|
// 创建
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
@@ -312,14 +313,43 @@ public class PzRawDataServiceImpl implements IPzRawDataService {
|
|
|
dataCell2.setCellValue(String.valueOf(data.getAmount()));
|
|
|
dataCell2.setCellStyle(style);
|
|
|
}
|
|
|
- try {
|
|
|
- response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
- response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(sheet + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xlsx", "UTF-8"));
|
|
|
- workbook.write(response.getOutputStream());
|
|
|
+ String fileName = "销售汇总表统计" + DateUtils.dateTimeNow() + ".xlsx";
|
|
|
+ //生成文档
|
|
|
+ String dssFileDownloadUrl = isWindows() ? reportFileUrlWin : reportFileUrlLinux;
|
|
|
+ String localFilePath = dssFileDownloadUrl + fileName;
|
|
|
+ //先把这个文件夹下的历史文件删除,再生成新的
|
|
|
+ FileUtils.deleteAll(dssFileDownloadUrl);
|
|
|
+ try (FileOutputStream fileOut = new FileOutputStream(localFilePath)) {
|
|
|
+ workbook.write(fileOut);
|
|
|
workbook.close();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("fileName", fileName);
|
|
|
+ map.put("filePath", dssFileDownloadUrl);
|
|
|
+ map.put("localFilePath", localFilePath);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断操作系统是否是 Windows
|
|
|
+ *
|
|
|
+ * @return true:操作系统是 Windows
|
|
|
+ * false:其它操作系统
|
|
|
+ */
|
|
|
+ public static boolean isWindows() {
|
|
|
+ String osName = getOsName();
|
|
|
+ return osName != null && osName.startsWith("Windows");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取操作系统名称
|
|
|
+ *
|
|
|
+ * @return os.name 属性值
|
|
|
+ */
|
|
|
+ public static String getOsName() {
|
|
|
+ return System.getProperty("os.name");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -330,26 +360,24 @@ public class PzRawDataServiceImpl implements IPzRawDataService {
|
|
|
*/
|
|
|
public List<ShhTicketRulesReqVO> calculateTotalPrices(List<PzRawDataVo> list) {
|
|
|
List<ShhTicketRulesReqVO> returnList = new ArrayList<>();
|
|
|
- Map<String, PzRawDataVo> map = new HashMap<>();
|
|
|
+ Map<String, ShhTicketRulesReqVO> map = new HashMap<>();
|
|
|
+ List<String> keyByValue = TicketRulesEnum.getAllKeys();
|
|
|
+ keyByValue.forEach(name -> {
|
|
|
+ ShhTicketRulesReqVO ticketRulesReqVO = new ShhTicketRulesReqVO();
|
|
|
+ ticketRulesReqVO.setTicketName(name);
|
|
|
+ map.put(name, ticketRulesReqVO);
|
|
|
+ });
|
|
|
list.forEach(e -> {
|
|
|
- List<String> keyByValue = TicketRulesEnum.getKeyByValues(e.getTicketId());
|
|
|
- if (!CollectionUtils.isEmpty(keyByValue)) {
|
|
|
- keyByValue.forEach(name -> {
|
|
|
- if (map.containsKey(name)) {
|
|
|
- //如果有相同的票种,则累加数量和金额
|
|
|
- PzRawDataVo pzRawDataVo = map.get(name);
|
|
|
- pzRawDataVo.setNumber(pzRawDataVo.getNumber() + e.getNumber());
|
|
|
- pzRawDataVo.setMoney(pzRawDataVo.getMoney() == null ? BigDecimal.ZERO : pzRawDataVo.getMoney().add(e.getMoney()));
|
|
|
- } else {
|
|
|
- PzRawDataVo newPzRawDataVo = new PzRawDataVo();
|
|
|
- newPzRawDataVo.setNumber(e.getNumber());
|
|
|
- newPzRawDataVo.setMoney(e.getMoney());
|
|
|
- map.put(name, newPzRawDataVo);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ keyByValue.forEach(name -> {
|
|
|
+ if(name.equals(TicketRulesEnum.getKeyByValue(e.getTicketId()))) {
|
|
|
+ //如果有相同的票种,则累加数量和金额
|
|
|
+ ShhTicketRulesReqVO ticketRulesReqVO = map.get(name);
|
|
|
+ ticketRulesReqVO.setNumberSheets(ticketRulesReqVO.getNumberSheets() + e.getNumber());
|
|
|
+ ticketRulesReqVO.setAmount(ticketRulesReqVO.getAmount() == null ? BigDecimal.ZERO : ticketRulesReqVO.getAmount().add(e.getMoney()));
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
- map.forEach((k, v) -> returnList.add(new ShhTicketRulesReqVO(k, v.getNumber(), v.getMoney())));
|
|
|
+ map.forEach((k, v) -> returnList.add(new ShhTicketRulesReqVO(k, v.getNumberSheets(), v.getAmount())));
|
|
|
return returnList;
|
|
|
}
|
|
|
|