|
|
@@ -250,6 +250,7 @@ public class StatisticsApiServiceImpl implements StatisticsApiService {
|
|
|
fileOutputStream(request, response, workbook, fileName);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// 使用synchronized,防止list在多线程的情况下顺序变乱
|
|
|
private synchronized void getData(SXSSFWorkbook workbook, List<InventoryVO> data, String sheetName) {
|
|
|
// 由于数据格式的问题,直接转换成List<List<String>>
|
|
|
@@ -319,4 +320,167 @@ public class StatisticsApiServiceImpl implements StatisticsApiService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void exportBaseData(HttpServletResponse response, HttpServletRequest request, String startTime, String endTime) {
|
|
|
+ String fileName = "导出数据";
|
|
|
+ SXSSFWorkbook workbook = new SXSSFWorkbook(20000);
|
|
|
+ // ------------------------ 第一个sheet---------------------------------------------
|
|
|
+ List<CabinetStatisticsVO> cabinetStatisticsVOList = getCabinetStatistics(startTime, endTime);
|
|
|
+ // 数据承载
|
|
|
+ ArrayList<List<String>> lists = new ArrayList<>();
|
|
|
+ // 构造第一行
|
|
|
+ List<String> one = new ArrayList<>();
|
|
|
+ one.add("物资柜");
|
|
|
+ one.add("开关次数");
|
|
|
+ one.add("异常总数");
|
|
|
+ one.add("错放数");
|
|
|
+ one.add("超时未关");
|
|
|
+ lists.add(one);
|
|
|
+ // 构造其他行
|
|
|
+ for (CabinetStatisticsVO vo : cabinetStatisticsVOList) {
|
|
|
+ List<String> other = new ArrayList<>();
|
|
|
+ other.add(vo.getCabinetName());
|
|
|
+ other.add(vo.getOpenCount() == null ? "0" : String.valueOf(vo.getOpenCount()));
|
|
|
+ other.add(String.valueOf(vo.getMisplaceCount() + vo.getOpenTimeoutCount()));
|
|
|
+ other.add(String.valueOf(vo.getMisplaceCount()));
|
|
|
+ other.add(String.valueOf(vo.getOpenTimeoutCount()));
|
|
|
+ lists.add(other);
|
|
|
+ }
|
|
|
+ SXSSFSheet sheet = workbook.createSheet("物资柜统计");
|
|
|
+ for (int i = 0; i < lists.size(); i++) {
|
|
|
+ sheet.setColumnWidth(i, 5000);
|
|
|
+ SXSSFRow row = sheet.createRow(i);
|
|
|
+ for (int j = 0; j < lists.get(i).size(); j++) {
|
|
|
+ row.createCell(j).setCellValue(lists.get(i).get(j));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // ------------------------ 第二个sheet---------------------------------------------
|
|
|
+ List<MaterialsStatusStatisticsVO> materialsStatusStatistics = getMaterialsStatusStatistics(startTime, endTime);
|
|
|
+ List<MaterialsChangeStatisticsVO> materialsChangeStatistics = getMaterialsChangeStatistics(startTime, endTime);
|
|
|
+ ArrayList<ExportMaterialsStatusStatisticsVO> exportMaterialsStatusStatisticsVOS = new ArrayList<>();
|
|
|
+ for (MaterialsStatusStatisticsVO materialsStatusStatistic : materialsStatusStatistics) {
|
|
|
+ ExportMaterialsStatusStatisticsVO vo = new ExportMaterialsStatusStatisticsVO();
|
|
|
+ vo.setMaterialsTypeId(materialsStatusStatistic.getMaterialsTypeId());
|
|
|
+ vo.setMaterialsTypeName(materialsStatusStatistic.getMaterialsTypeName());
|
|
|
+ vo.setAllCount(materialsStatusStatistic.getAllCount());
|
|
|
+ vo.setWillExpireCount(materialsStatusStatistic.getWillExpireCount());
|
|
|
+ vo.setExpiredCount(materialsStatusStatistic.getExpiredCount());
|
|
|
+ vo.setBadCount(materialsStatusStatistic.getBadCount());
|
|
|
+ vo.setAllChangeCount(0);
|
|
|
+ vo.setExpireChangeCount(0);
|
|
|
+ vo.setBadChangeCount(0);
|
|
|
+ for (MaterialsChangeStatisticsVO materialsChangeStatistic : materialsChangeStatistics) {
|
|
|
+ if (materialsChangeStatistic.getMaterialsTypeId().equals(materialsStatusStatistic.getMaterialsTypeId())) {
|
|
|
+ vo.setAllChangeCount(materialsChangeStatistic.getAllCount());
|
|
|
+ vo.setExpireChangeCount(materialsChangeStatistic.getExpireCount());
|
|
|
+ vo.setBadChangeCount(materialsChangeStatistic.getBadCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ exportMaterialsStatusStatisticsVOS.add(vo);
|
|
|
+ }
|
|
|
+ // 数据承载
|
|
|
+ ArrayList<List<String>> lists1 = new ArrayList<>();
|
|
|
+ // 构造第一行
|
|
|
+ List<String> one1 = new ArrayList<>();
|
|
|
+ one1.add("物资");
|
|
|
+ one1.add("即将过期");
|
|
|
+ one1.add("已过期");
|
|
|
+ one1.add("损坏数");
|
|
|
+ one1.add("正常更换次数");
|
|
|
+ one1.add("过期更换次数");
|
|
|
+ one1.add("损坏更换次数");
|
|
|
+ lists1.add(one1);
|
|
|
+ // 构造其他行
|
|
|
+ for (ExportMaterialsStatusStatisticsVO vo : exportMaterialsStatusStatisticsVOS) {
|
|
|
+ List<String> other = new ArrayList<>();
|
|
|
+ other.add(vo.getMaterialsTypeName());
|
|
|
+ other.add(String.valueOf(vo.getWillExpireCount()));
|
|
|
+ other.add(String.valueOf(vo.getExpiredCount()));
|
|
|
+ other.add(String.valueOf(vo.getBadCount()));
|
|
|
+ other.add(String.valueOf(vo.getAllChangeCount()));
|
|
|
+ other.add(String.valueOf(vo.getExpireChangeCount()));
|
|
|
+ other.add(String.valueOf(vo.getBadChangeCount()));
|
|
|
+ lists1.add(other);
|
|
|
+ }
|
|
|
+ SXSSFSheet sheet1 = workbook.createSheet("物资统计");
|
|
|
+ for (int i = 0; i < lists1.size(); i++) {
|
|
|
+ sheet1.setColumnWidth(i, 5000);
|
|
|
+ SXSSFRow row = sheet1.createRow(i);
|
|
|
+ for (int j = 0; j < lists1.get(i).size(); j++) {
|
|
|
+ row.createCell(j).setCellValue(lists1.get(i).get(j));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fileOutputStream(request, response, workbook, fileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportClaimAndReturn(HttpServletResponse response, HttpServletRequest request, String startTime, String endTime) {
|
|
|
+ String fileName = "导出数据";
|
|
|
+ SXSSFWorkbook workbook = new SXSSFWorkbook(20000);
|
|
|
+ // ------------------------ 第一个sheet---------------------------------------------
|
|
|
+ List<MaterialsLoanStatisticsVO> materialsLoanStatistics = getMaterialsLoanStatistics(startTime, endTime);
|
|
|
+ // 数据承载
|
|
|
+ ArrayList<List<String>> lists = new ArrayList<>();
|
|
|
+ // 构造第一行
|
|
|
+ List<String> one = new ArrayList<>();
|
|
|
+ one.add("物资");
|
|
|
+ one.add("借出平均时长(小时)");
|
|
|
+ one.add("领取次数");
|
|
|
+ one.add("正常归还次数");
|
|
|
+ one.add("超时归还次数");
|
|
|
+ lists.add(one);
|
|
|
+ // 构造其他行
|
|
|
+ for (MaterialsLoanStatisticsVO vo : materialsLoanStatistics) {
|
|
|
+ List<String> other = new ArrayList<>();
|
|
|
+ other.add(vo.getMaterialsTypeName());
|
|
|
+ double seconds = vo.getAverageTime();
|
|
|
+ // 计算小时数,并保留两位小数
|
|
|
+ double hours = seconds / 3600.0;
|
|
|
+ other.add(String.format("%.2f", hours));
|
|
|
+ other.add(String.valueOf(vo.getAllCount()));
|
|
|
+ other.add(String.valueOf(vo.getReturnCount()));
|
|
|
+ other.add(String.valueOf(vo.getTimeoutCount()));
|
|
|
+ lists.add(other);
|
|
|
+ }
|
|
|
+ SXSSFSheet sheet = workbook.createSheet("物资领取归还");
|
|
|
+ for (int i = 0; i < lists.size(); i++) {
|
|
|
+ sheet.setColumnWidth(i, 5000);
|
|
|
+ SXSSFRow row = sheet.createRow(i);
|
|
|
+ for (int j = 0; j < lists.get(i).size(); j++) {
|
|
|
+ row.createCell(j).setCellValue(lists.get(i).get(j));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // ------------------------ 第二个sheet---------------------------------------------
|
|
|
+ List<DayLoanStatisticsVO> dayLoanStatistics = getDayLoanStatistics(startTime, endTime);
|
|
|
+ // 数据承载
|
|
|
+ ArrayList<List<String>> lists1 = new ArrayList<>();
|
|
|
+ // 构造第一行
|
|
|
+ List<String> one1 = new ArrayList<>();
|
|
|
+ one1.add("日期");
|
|
|
+ one1.add("累计领取次数");
|
|
|
+ one1.add("累计正常归还次数");
|
|
|
+ one1.add("累计超时归还次数");
|
|
|
+ lists1.add(one1);
|
|
|
+ // 构造其他行
|
|
|
+ for (DayLoanStatisticsVO vo : dayLoanStatistics) {
|
|
|
+ List<String> other = new ArrayList<>();
|
|
|
+ other.add(vo.getDay());
|
|
|
+ other.add(String.valueOf(vo.getAllCount()));
|
|
|
+ other.add(String.valueOf(vo.getReturnCount()));
|
|
|
+ other.add(String.valueOf(vo.getTimeoutCount()));
|
|
|
+ lists1.add(other);
|
|
|
+ }
|
|
|
+ SXSSFSheet sheet1 = workbook.createSheet("每日领取归还");
|
|
|
+ for (int i = 0; i < lists1.size(); i++) {
|
|
|
+ sheet1.setColumnWidth(i, 5000);
|
|
|
+ SXSSFRow row = sheet1.createRow(i);
|
|
|
+ for (int j = 0; j < lists1.get(i).size(); j++) {
|
|
|
+ row.createCell(j).setCellValue(lists1.get(i).get(j));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fileOutputStream(request, response, workbook, fileName);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|