瀏覽代碼

费用报销导出修改

Min 1 年之前
父節點
當前提交
9d4dfccbce

+ 3 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ExcelExportService.java

@@ -4,6 +4,7 @@ import com.management.platform.entity.WxCorpInfo;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.HttpRespMsg;
 
 
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 public interface ExcelExportService {
 public interface ExcelExportService {
     public void testRead(String jobId);
     public void testRead(String jobId);
@@ -11,4 +12,6 @@ public interface ExcelExportService {
     public HttpRespMsg exportGeneralExcelByTitleAndList2(WxCorpInfo wxCorpInfo, String title, List<List<String>> list, String downloadPath) throws Exception;
     public HttpRespMsg exportGeneralExcelByTitleAndList2(WxCorpInfo wxCorpInfo, String title, List<List<String>> list, String downloadPath) throws Exception;
     public HttpRespMsg exportMultiSheetGeneralExcelByTitleAndList(WxCorpInfo wxCorpInfo,String title, List<List<String>>[] multiSheetList, String downloadPath,String[] sheetsName) throws Exception;
     public HttpRespMsg exportMultiSheetGeneralExcelByTitleAndList(WxCorpInfo wxCorpInfo,String title, List<List<String>>[] multiSheetList, String downloadPath,String[] sheetsName) throws Exception;
     void testAdd(String jobId);
     void testAdd(String jobId);
+
+    HttpRespMsg exportGeneralExcelForExpense(WxCorpInfo wxCorpInfo, String fileName, List<List<String>> allList, List<Map> mapList, String path) throws Exception;
 }
 }

+ 49 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ExcelExportServiceImpl.java

@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileOutputStream;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 @Service
 @Service
 public class ExcelExportServiceImpl implements ExcelExportService {
 public class ExcelExportServiceImpl implements ExcelExportService {
@@ -107,6 +108,54 @@ public class ExcelExportServiceImpl implements ExcelExportService {
         return httpRespMsg;
         return httpRespMsg;
     }
     }
 
 
+    public HttpRespMsg exportGeneralExcelForExpense(WxCorpInfo wxCorpInfo, String title, List<List<String>> list, List<Map> mapList, String downloadPath) throws Exception {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        if (title.contains("/")) {
+            //文件名不能含有路径,得替换掉
+            title = title.replace("/", "@");
+        }
+        if (title.contains("\\")) {
+            //文件名不能含有路径,得替换掉
+            title = title.replace("\\", "@");
+        }
+        String resp = ExcelUtil.exportGeneralExcelForExpense(title, list,mapList, downloadPath);
+        String fileUrlSuffix = title + ".xlsx";
+        if(wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1){
+            String mediaId = wxCorpInfoService.getTranslationMediaId(fileUrlSuffix);
+            String jobId = wxCorpInfoService.syncTranslation(wxCorpInfo.getCorpid(),mediaId,fileUrlSuffix, null);
+            int i = 0;
+            String syncTranslationResult = null;
+            /**
+             * 异步上传转译文件的任务完成时会触发回调,在WeiXinCorpController中的commonDevCallbackPost实现了对回调的处理,存储到corpwxJobResult表中
+             * 此处轮询查询本地数据库,检测到有任务的回调数据时继续执行查询操作
+             */
+            while (i < 10) {
+                Thread.sleep(300);
+                CorpwxJobResult corpwxJobResult = corpwxJobCenter.get(jobId);
+                if (corpwxJobResult != null) {
+                    if (corpwxJobResult.getErrCode() == 0) {
+                        syncTranslationResult = wxCorpInfoService.getSyncTranslationResult(jobId);
+                        corpwxJobCenter.remove(jobId);
+                    } else {
+                        httpRespMsg.setError(corpwxJobResult.getErrMsg());
+                        return httpRespMsg;
+                    }
+                    break;
+                }
+                i++;
+            }
+            if (syncTranslationResult != null) {
+                httpRespMsg.data = syncTranslationResult;
+            } else {
+                //httpRespMsg.setError("处理超时...");
+                httpRespMsg.setError(MessageUtils.message("request.outTime"));
+            }
+        }else {
+            httpRespMsg.data = resp;
+        }
+        return httpRespMsg;
+    }
+
     public HttpRespMsg exportGeneralExcelByTitleAndList2(WxCorpInfo wxCorpInfo, String title, List<List<String>> list, String downloadPath) throws Exception {
     public HttpRespMsg exportGeneralExcelByTitleAndList2(WxCorpInfo wxCorpInfo, String title, List<List<String>> list, String downloadPath) throws Exception {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         String resp = ExcelUtil.exportGeneralExcelByTitleAndList2(title, list, downloadPath);
         String resp = ExcelUtil.exportGeneralExcelByTitleAndList2(title, list, downloadPath);

+ 69 - 45
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ExpenseSheetServiceImpl.java

@@ -740,57 +740,78 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
             queryWrapper.between("create_date", startDate, endDate);
             queryWrapper.between("create_date", startDate, endDate);
         }
         }
         List<ExpenseSheet> records = expenseSheetMapper.selectList(queryWrapper);
         List<ExpenseSheet> records = expenseSheetMapper.selectList(queryWrapper);
+        List<Integer> ids = records.stream().map(ExpenseSheet::getId).distinct().collect(Collectors.toList());
+        ids.add(-1);
+        List<ExpenseItem> expenseItemList = expenseItemMapper.selectList(new QueryWrapper<ExpenseItem>().in("expense_id", ids));
+        List<Integer> projectIds = expenseItemList.stream().map(ExpenseItem::getProjectId).distinct().collect(Collectors.toList());
+        projectIds.add(-1);
+        List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().in("id", projectIds));
         List<List<String>> allList=new ArrayList<>();
         List<List<String>> allList=new ArrayList<>();
         List<String> titleList=new ArrayList<>();
         List<String> titleList=new ArrayList<>();
-//        titleList.add("票据编号");
-//        titleList.add("金额(元)");
-//        titleList.add("报销人");
-//        titleList.add("填报日期");
-//        titleList.add("发票张数");
-//        titleList.add("票据类型");
-//        titleList.add("备注");
-//        titleList.add("状态");
-        titleList.add(MessageUtils.message("Reimbursement.No"));
-        titleList.add(MessageUtils.message("Reimbursement.amount"));
-        titleList.add(MessageUtils.message("excel.reiPer"));
-        titleList.add(MessageUtils.message("excel.fillDate"));
-        titleList.add(MessageUtils.message("Reimbursement.numberOfInvoices"));
-        titleList.add(MessageUtils.message("Reimbursement.billType"));
-        titleList.add(MessageUtils.message("excel.remark"));
-        titleList.add(MessageUtils.message("leave.status"));
+        titleList.add("报销人");
+        titleList.add("填报时间");
+        titleList.add("发票张数");
+        titleList.add("费用类型");
+        titleList.add("总费用");
+        titleList.add("备注");
+        titleList.add("状态");
+        titleList.add("项目名称");
+        titleList.add("费用日期");
+        titleList.add("发票种类");
+        titleList.add("费用类型");
+        titleList.add("费用金额");
+        titleList.add("发票号");
+
         allList.add(titleList);
         allList.add(titleList);
         BigDecimal sumAmount = new BigDecimal(0);
         BigDecimal sumAmount = new BigDecimal(0);
+        List<Map> mapList=new ArrayList<>();
         for (ExpenseSheet record : records) {
         for (ExpenseSheet record : records) {
-            List<String> item=new ArrayList<>();
-            item.add(record.getCode());
-            item.add(record.getTotalAmount()==null?"0":record.getTotalAmount()+"");
-            if (wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
-                item.add("$userName=" + record.getOwnerName() +"$");
-            }else {
-                item.add(record.getOwnerName());
-            }
-            item.add(record.getCreateDate()==null?"":record.getCreateDate()+"");
-            item.add(record.getTicketNum()==null?"0":record.getTicketNum()+"");
-            Optional<ExpenseMainType> first = mainTypes.stream().filter(ms -> ms.getId().equals(record.getType())).findFirst();
-            item.add(first.isPresent()?first.get().getName():"");
-            item.add(record.getRemark()==null?"":record.getRemark());
-            switch (record.getStatus()){
-                case 0:
-                    item.add("审核通过");
-                    break;
-                case 1:
-                    item.add("待审核");
-                    break;
-                case 2:
-                    item.add("驳回");
-                    break;
-                case 3:
-                    item.add("已撤回");
-                    break;
-                default:
+            Map map=new HashMap();
+            List<ExpenseItem> expenseItems = expenseItemList.stream().filter(el -> el.getExpenseId().equals(record.getId())).collect(Collectors.toList());
+            map.put("size",expenseItems.size());
+            mapList.add(map);
+            for (ExpenseItem expenseItem : expenseItems) {
+                List<String> item=new ArrayList<>();
+                if (wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
+                    item.add("$userName=" + record.getOwnerName() +"$");
+                }else {
+                    item.add(record.getOwnerName());
+                }
+                item.add(record.getCreateDate()==null?"":record.getCreateDate()+"");
+                item.add(record.getTicketNum()==null?"0":record.getTicketNum()+"");
+                Optional<ExpenseMainType> first = mainTypes.stream().filter(ms -> ms.getId().equals(record.getType())).findFirst();
+                item.add(first.isPresent()?first.get().getName():"");
+                item.add(record.getTotalAmount()==null?"0":record.getTotalAmount()+"");
+                item.add(record.getRemark()==null?"":record.getRemark());
+                switch (record.getStatus()){
+                    case 0:
+                        item.add("审核通过");
+                        break;
+                    case 1:
+                        item.add("待审核");
+                        break;
+                    case 2:
+                        item.add("驳回");
+                        break;
+                    case 3:
+                        item.add("已撤回");
+                        break;
+                    default:
+                        item.add("");
+                }
+                Optional<Project> optional = projectList.stream().filter(p -> expenseItem.getProjectId() != null && p.getId().equals(expenseItem.getProjectId())).findFirst();
+                if(optional.isPresent()){
+                    item.add(optional.get().getProjectName());
+                }else {
                     item.add("");
                     item.add("");
+                }
+                item.add(expenseItem.getHappenDate());
+                item.add(expenseItem.getInvoiceType()!=null&&expenseItem.getInvoiceType()==0?"增值税专用发票":"增值税普通发票");
+                item.add(expenseItem.getExpenseType());
+                item.add(String.valueOf(expenseItem.getAmount()==null?"0":expenseItem.getAmount()));
+                item.add(expenseItem.getInvoiceNo()==null?"":expenseItem.getInvoiceNo());
+                allList.add(item);
             }
             }
-            allList.add(item);
             if (record.getTotalAmount() == null) record.setTotalAmount(0.0);
             if (record.getTotalAmount() == null) record.setTotalAmount(0.0);
             sumAmount = sumAmount.add(BigDecimal.valueOf(record.getTotalAmount()));
             sumAmount = sumAmount.add(BigDecimal.valueOf(record.getTotalAmount()));
         }
         }
@@ -798,6 +819,9 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
         List<String> sumRow = new ArrayList<String>();
         List<String> sumRow = new ArrayList<String>();
         //sumRow.add("合计");
         //sumRow.add("合计");
         sumRow.add(MessageUtils.message("entry.total"));
         sumRow.add(MessageUtils.message("entry.total"));
+        sumRow.add("");
+        sumRow.add("");
+        sumRow.add("");
         sumRow.add(sumAmount.setScale(2,BigDecimal.ROUND_UP)+"");
         sumRow.add(sumAmount.setScale(2,BigDecimal.ROUND_UP)+"");
         for (int i = 0; i < titleList.size() - 2; i++) {
         for (int i = 0; i < titleList.size() - 2; i++) {
             sumRow.add("");
             sumRow.add("");
@@ -808,7 +832,7 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
         //String fileName = "费用报销单据列表"+System.currentTimeMillis();
         //String fileName = "费用报销单据列表"+System.currentTimeMillis();
         String fileName = MessageUtils.message("fileName.expense")+System.currentTimeMillis();
         String fileName = MessageUtils.message("fileName.expense")+System.currentTimeMillis();
         try {
         try {
-            return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,fileName , allList, path);
+            return excelExportService.exportGeneralExcelForExpense(wxCorpInfo,fileName , allList,mapList, path);
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();
         }
         }

+ 170 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/ExcelUtil.java

@@ -1,6 +1,7 @@
 package com.management.platform.util;
 package com.management.platform.util;
 
 
 import com.management.platform.entity.CorpwxJobResult;
 import com.management.platform.entity.CorpwxJobResult;
+import com.management.platform.entity.ExpenseSheet;
 import com.management.platform.entity.WxCorpInfo;
 import com.management.platform.entity.WxCorpInfo;
 import com.management.platform.mapper.CorpwxJobResultMapper;
 import com.management.platform.mapper.CorpwxJobResultMapper;
 import com.management.platform.service.CorpwxJobResultService;
 import com.management.platform.service.CorpwxJobResultService;
@@ -19,6 +20,7 @@ import javax.annotation.PostConstruct;
 import java.io.File;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileOutputStream;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 @Component
 @Component
 public class ExcelUtil {
 public class ExcelUtil {
@@ -583,6 +585,174 @@ public class ExcelUtil {
         return "/upload/"+fileName;
         return "/upload/"+fileName;
     }
     }
 
 
+    public static String exportGeneralExcelForExpense(String title, List<List<String>> list, List<Map> mapList, String downloadPath) {
+        String result="系统提示:Excel文件导出成功!";
+        String fileName= title+".xlsx";
+        try {
+//            response.reset();
+//            response.setHeader("Content-disposition",
+//                "attachment;filename="+ URLEncoder.encode(fileName, "UTF-8"));
+//            //设置文件头编码格式
+//            response.setContentType("APPLICATION/OCTET-STREAM;charset=UTF-8");//设置类型
+//            response.setHeader("Cache-Control","no-cache");//设置头
+//            response.setDateHeader("Expires", 0);//设置日期头
+            // 创建工作簿, 换成XSSSF 来支持万以上的数据
+            SXSSFWorkbook workBook = new SXSSFWorkbook();
+//            HSSFWorkbook workBook = new HSSFWorkbook();
+            // 创建工作类
+            Sheet sheet = workBook.createSheet();
+            //设置首行冻结
+            sheet.createFreezePane(0, 1);
+            sheet.setDefaultColumnWidth(16);
+            //设置字体样式
+            Font headFont = workBook.createFont();
+            headFont.setBold(true);
+            headFont.setFontHeightInPoints((short) 10);
+            headFont.setFontName("黑体");
+
+            Font titleFont = workBook.createFont();
+            titleFont.setBold(true);
+            titleFont.setFontHeightInPoints((short) 10);
+            titleFont.setFontName("黑体");
+
+            Font font = workBook.createFont();
+            font.setFontHeightInPoints((short) 10);
+            font.setFontName("宋体");
+
+            //设置单元格样式
+            XSSFCellStyle  headStyle = (XSSFCellStyle) workBook.createCellStyle();
+            headStyle.setFont(headFont);
+            headStyle.setAlignment(HorizontalAlignment.CENTER);
+            headStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
+            headStyle.setWrapText(true);
+            headStyle.setBorderBottom(BorderStyle.THIN); //下边框
+            headStyle.setBorderLeft(BorderStyle.THIN);//左边框
+            headStyle.setBorderTop(BorderStyle.THIN);//上边框
+            headStyle.setBorderRight(BorderStyle.THIN);//右边框
+
+            String color = "c0c0c0";    //此处得到的color为16进制的字符串
+            //转为RGB码
+            int r = Integer.parseInt((color.substring(0,2)),16);   //转为16进制
+            int g = Integer.parseInt((color.substring(2,4)),16);
+            int b = Integer.parseInt((color.substring(4,6)),16);
+
+            //自定义cell颜色
+//            HSSFPalette palette = workBook.getCustomPalette();
+            //这里的9是索引
+//            palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
+
+            //设置自定义颜色
+            XSSFColor xssfColor = new XSSFColor();
+            byte[] colorRgb = { (short)9, (byte) r, (byte) g, (byte) b };
+            xssfColor.setRGB(colorRgb);
+
+            headStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
+            headStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);// 填充模式(和背景颜色成对使用)
+            /*headStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex());*/ //设置自带的颜色
+
+            CellStyle titleStyle = workBook.createCellStyle();
+            titleStyle.setFont(titleFont);
+            titleStyle.setAlignment(HorizontalAlignment.CENTER);
+            titleStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
+            titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);  //填充单元格
+            titleStyle.setFillForegroundColor((short)9);    //填色
+            titleStyle.setWrapText(true);
+            titleStyle.setBorderBottom(BorderStyle.THIN); //下边框
+            titleStyle.setBorderLeft(BorderStyle.THIN);//左边框
+            titleStyle.setBorderTop(BorderStyle.THIN);//上边框
+            titleStyle.setBorderRight(BorderStyle.THIN);//右边框
+
+            CellStyle cellStyle = workBook.createCellStyle();
+            cellStyle.setFont(font);
+            cellStyle.setAlignment(HorizontalAlignment.CENTER);
+            cellStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
+            cellStyle.setWrapText(true);
+            cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
+            cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
+            cellStyle.setBorderTop(BorderStyle.THIN);//上边框
+            cellStyle.setBorderRight(BorderStyle.THIN);//右边框
+
+            if(list.size() > 0) {
+                //标题(如果需要在EXCEL内容最上面加标题,请打开下面的注释,修改start)
+                /*
+                HSSFRow titleRow = sheet.createRow(0);
+                titleRow.setHeightInPoints(30);
+                HSSFCell titleCell = titleRow.createCell(0);
+                titleCell.setCellStyle(headStyle);
+                titleCell.setCellValue(title);
+                //合并单元格
+                CellRangeAddress cellRangeAddress = new CellRangeAddress(0,0,0, list.get(0).size() - 1);
+                //加入合并单元格对象
+                sheet.addMergedRegion(cellRangeAddress);
+                //使用RegionUtil类为合并后的单元格添加边框
+			    RegionUtil.setBorderBottom(BorderStyle.THIN, cellRangeAddress, sheet); // 下边框
+                RegionUtil.setBorderLeft(BorderStyle.THIN, cellRangeAddress, sheet); // 左边框
+                RegionUtil.setBorderRight(BorderStyle.THIN, cellRangeAddress, sheet); // 有边框
+                RegionUtil.setBorderTop(BorderStyle.THIN, cellRangeAddress, sheet); // 上边框
+                */
+                int nextStartIndex=1;
+                int nextEndIndex=0;
+                for (int i = 0; i < mapList.size(); i++) {
+                    nextEndIndex+=Integer.valueOf(String.valueOf(mapList.get(i).get("size")));
+                    if(nextEndIndex>nextStartIndex){
+                        CellRangeAddress cellRangeAddress  = new CellRangeAddress(nextStartIndex, nextEndIndex, 0,0);
+                        CellRangeAddress cellRangeAddress1 = new CellRangeAddress(nextStartIndex, nextEndIndex, 1,1);
+                        CellRangeAddress cellRangeAddress2 = new CellRangeAddress(nextStartIndex, nextEndIndex, 2,2);
+                        CellRangeAddress cellRangeAddress3 = new CellRangeAddress(nextStartIndex, nextEndIndex, 3,3);
+                        CellRangeAddress cellRangeAddress4 = new CellRangeAddress(nextStartIndex, nextEndIndex, 4,4);
+                        CellRangeAddress cellRangeAddress5 = new CellRangeAddress(nextStartIndex, nextEndIndex, 5,5);
+                        CellRangeAddress cellRangeAddress6 = new CellRangeAddress(nextStartIndex, nextEndIndex, 6,6);
+                        sheet.addMergedRegion(cellRangeAddress);
+                        sheet.addMergedRegion(cellRangeAddress1);
+                        sheet.addMergedRegion(cellRangeAddress2);
+                        sheet.addMergedRegion(cellRangeAddress3);
+                        sheet.addMergedRegion(cellRangeAddress4);
+                        sheet.addMergedRegion(cellRangeAddress5);
+                        sheet.addMergedRegion(cellRangeAddress6);
+                    }
+                    nextStartIndex+=Integer.valueOf(String.valueOf(mapList.get(i).get("size")));
+                }
+                int start = 0;
+                for(List<String> rowList : list) {
+                    Row row = sheet.createRow(start);
+                    row.setHeightInPoints(24);
+
+                    for(int i = 0; i < rowList.size(); i++) {
+                        Cell cell = row.createCell(i);
+                        if(start == 0) {
+                            cell.setCellStyle(headStyle);
+                        }else {
+                            cell.setCellStyle(cellStyle);
+                        }
+                        cell.setCellValue(rowList.get(i));
+                    }
+                    start++;
+                }
+            }
+            //用于非传统ajax;
+//            String headStr = "attachment; filename=\"" + fileName + "\"";
+//            response.setContentType("APPLICATION/OCTET-STREAM");//返回格式为流
+//            response.setHeader("Content-Disposition", headStr);
+//            //普通下载不需要以上三行,注掉即可
+//            OutputStream os = response.getOutputStream();//在线下载
+            File dir = null;
+            dir = new File(downloadPath);
+            // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
+            if (!dir.exists()) {
+                dir.mkdirs();
+            }
+            FileOutputStream os = new FileOutputStream(downloadPath+fileName);//保存到本地
+            workBook.write(os);
+            os.flush();
+            os.close();
+        }catch(Exception e) {
+            System.out.println(result);
+            e.printStackTrace();
+        }
+        return "/upload/"+fileName;
+//        return "";
+    }
+
     public static boolean isRowEmpty(Row row){
     public static boolean isRowEmpty(Row row){
         for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) {
         for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) {
             Cell cell = row.getCell(i);
             Cell cell = row.getCell(i);