aa51513
2021-05-15 d06fbb7626ca5c9e4e7a91ac06a6f2ae186c0f27
service-front/src/main/java/com/java110/front/smo/assetExport/impl/ExportFeeManualCollectionSMOImpl.java
@@ -10,10 +10,12 @@
import com.java110.front.smo.assetExport.IExportFeeManualCollectionSMO;
import com.java110.utils.constant.ServiceConstant;
import com.java110.utils.util.Assert;
import com.java110.utils.util.Base64Convert;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.Money2ChineseUtil;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -139,10 +141,12 @@
     * @param workbook
     */
    private void getRoomOweFees(IPageData pd, ComponentValidateResult result, Workbook workbook) {
        Sheet sheet = workbook.createSheet("催缴单");
        Drawing patriarch = sheet.createDrawingPatriarch();
        String apiUrl = "";
        ResponseEntity<String> responseEntity = null;
        apiUrl = ServiceConstant.SERVICE_API_URL + "/api/feeApi/listAllRoomOweFees?communityId=" + result.getCommunityId();
        JSONObject reqJson = JSONObject.parseObject(pd.getReqData());
        apiUrl = ServiceConstant.SERVICE_API_URL + "/api/feeApi/listAllRoomOweFees" + mapToUrlParam(reqJson);
        responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET);
        if (responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息
@@ -163,24 +167,47 @@
            return;
        }
        Sheet sheet = workbook.createSheet("催缴单");
        //查询催缴单二维码
        JSONObject feePrint = null;
        apiUrl = ServiceConstant.SERVICE_API_URL + "/api/feePrintSpec/queryFeePrintSpec?page=1&row=1&specCd=1010&communityId=" + result.getCommunityId();
        responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET);
        if (responseEntity.getStatusCode() == HttpStatus.OK) {
            JSONObject feePrintResults = JSONObject.parseObject(responseEntity.getBody(), Feature.OrderedField);
            if (feePrintResults.containsKey("data")) {
                JSONArray feePrints = feePrintResults.getJSONArray("data");
                if (feePrints != null && feePrints.size() > 0) {
                    feePrint = feePrints.getJSONObject(0);
                }
            }
        }
        int line = 0;
        double totalPageHeight = 0;
        for (int roomIndex = 0; roomIndex < rooms.size(); roomIndex++) {
            Map info = generatorRoomOweFee(sheet, workbook, rooms.getJSONObject(roomIndex), line, totalPageHeight);
            Map<String, Object> info = generatorRoomOweFee(sheet, workbook, rooms.getJSONObject(roomIndex), line, totalPageHeight, patriarch, feePrint);
            line = Integer.parseInt(info.get("line").toString()) + 1;
            totalPageHeight = Double.parseDouble(info.get("totalPageHeight").toString());
        }
    }
    private Map<String, Object> generatorRoomOweFee(Sheet sheet, Workbook workbook, JSONObject room, int line, double totalPageHeight) {
    private Map<String, Object> generatorRoomOweFee(Sheet sheet, Workbook workbook, JSONObject room, int line, double totalPageHeight, Drawing patriarch, JSONObject feePrint) {
        JSONArray fees = room.getJSONArray("fees");
        String[] feePrintRemarks = null;
        if (feePrint != null) {
            feePrintRemarks = feePrint.getString("content").toLowerCase().replace("</br>", "").split("\n");
        }
        int defaultRowHeight = 280;
        //计算当前单子的高度
        int titleHeight = defaultRowHeight * 3;
        int subTitleHeight = defaultRowHeight * 3;
        int totalHeight = titleHeight + subTitleHeight + defaultRowHeight * 5 + fees.size() * defaultRowHeight;
        double A4_lengthways_pageSize = defaultRowHeight * 54;//15120
        int subTitleHeight = defaultRowHeight * 5;
        int totalHeight = titleHeight + subTitleHeight + defaultRowHeight * 3 + fees.size() * defaultRowHeight;
        //备注,加上打印配置内容
        if (feePrintRemarks != null && feePrintRemarks.length > 0) {
            totalHeight += (feePrintRemarks.length * defaultRowHeight);
        }
        double A4_lengthways_pageSize = defaultRowHeight * 57;//15960
        //当前页 已经占用的高度
        double curPageHeight = totalPageHeight % A4_lengthways_pageSize;
@@ -188,7 +215,7 @@
        double freePageHeight = A4_lengthways_pageSize - curPageHeight;
        if (freePageHeight < totalHeight && curPageHeight != 0) {
            line += Math.ceil(freePageHeight / defaultRowHeight);
            totalPageHeight += Math.ceil(freePageHeight / defaultRowHeight);
            totalPageHeight += freePageHeight;
        }
        totalPageHeight += totalHeight;
@@ -214,11 +241,12 @@
        // 标题
        Row row = sheet.createRow(0 + line);
        Cell cell0 = row.createCell(0);
        cell0.setCellValue("缴费通知单totalHeight:"+totalHeight+"-totalPageHeight:"+totalPageHeight+"-curPageHeight:"+curPageHeight+"-freePageHeight:"+freePageHeight+"-line:"+line);
        //cell0.setCellValue("缴费通知单totalHeight:" + totalHeight + "-totalPageHeight:" + totalPageHeight + "-curPageHeight:" + curPageHeight + "-freePageHeight:" + freePageHeight + "-line:" + line);
        cell0.setCellValue("缴费通知单");
        //标题设置字体
        Font font = workbook.createFont();
        font.setFontName("黑体");
        font.setFontHeightInPoints((short) 12);
        font.setFontHeightInPoints((short) 26);
        CellStyle titleCellStyle = workbook.createCellStyle();
        titleCellStyle.setFont(font);
        titleCellStyle.setAlignment(HorizontalAlignment.CENTER);
@@ -230,34 +258,54 @@
        sheet.addMergedRegion(region);
        //第一行
        //子标题
        if (feePrint != null) {
            XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) 0, 1 + line, (short) 1, 1 + line + 1);
            anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);//设置图片随单元移动调整大小
            try {
                String qrImg = feePrint.getString("qrImg").replace("data:image/webp;base64,", "")
                        .replace("data:image/png;base64,", "")
                        .replace("data:image/jpeg;base64,", "");
                patriarch.createPicture(anchor, workbook.addPicture(Base64Convert.base64ToByte(qrImg), XSSFWorkbook.PICTURE_TYPE_JPEG));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        CellStyle subTitleCellStyle = workbook.createCellStyle();
        subTitleCellStyle.setAlignment(HorizontalAlignment.CENTER);
        subTitleCellStyle.setVerticalAlignment(VerticalAlignment.BOTTOM);
        row = sheet.createRow(1 + line);
        row.createCell(0).setCellValue("收费二维码");
        row.createCell(1).setCellValue("房号:" + room.getString("floorNum")
        Cell cell1 = row.createCell(1);
        cell1.setCellValue("房号:" + room.getString("floorNum")
                + "-" + room.getString("unitNum")
                + "-" + room.getString("roomNum"));
        cell1.setCellStyle(subTitleCellStyle);
        row.createCell(2).setCellValue("");
        row.createCell(3).setCellValue("");
        row.createCell(4).setCellValue("");
        row.createCell(5).setCellValue(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B));
        row.setHeight((short) (subTitleHeight));
        Cell cell5 = row.createCell(5);
        cell5.setCellValue(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B));
        cell5.setCellStyle(subTitleCellStyle);
        CellStyle rowCellStyle = workbook.createCellStyle();
        rowCellStyle.setVerticalAlignment(VerticalAlignment.BOTTOM);
        row.setRowStyle(rowCellStyle);
        //设置表头之上
        region = new CellRangeAddress(1 + line, 1 + line, 1, 2);
        region = new CellRangeAddress(1 + line, 1 + line, 1, 3);
        sheet.addMergedRegion(region);
        row.setHeight((short) (titleHeight));
        region = new CellRangeAddress(1 + line, 1 + line, 5, 6);
        sheet.addMergedRegion(region);
        //子标题高度
        row.setHeight((short) (subTitleHeight));
        row = sheet.createRow(2 + line);
        cell0 = row.createCell(0);
        cell0.setCellValue("收费名称");
        cell0.setCellStyle(cellStyle);
        Cell cell1 = row.createCell(1);
        cell1 = row.createCell(1);
        cell1.setCellValue("收费标准");
        cell1.setCellStyle(cellStyle);
        Cell cell2 = row.createCell(2);
@@ -269,7 +317,7 @@
        Cell cell4 = row.createCell(4);
        cell4.setCellValue("应缴金额(元)");
        cell4.setCellStyle(cellStyle);
        Cell cell5 = row.createCell(5);
        cell5 = row.createCell(5);
        cell5.setCellValue("违约金(元)");
        cell5.setCellStyle(cellStyle);
        Cell cell6 = row.createCell(6);
@@ -342,16 +390,18 @@
        region = new CellRangeAddress(line + fees.size() + 3, line + fees.size() + 3, 1, 3);
        sheet.addMergedRegion(region);
        row = sheet.createRow(line + fees.size() + 4);
        row.createCell(0).setCellValue("1、请收到通知单5日内到物业处或微信支付");
        if (feePrintRemarks != null && feePrintRemarks.length > 0) {
            for (int remarkIndex = 0; remarkIndex < feePrintRemarks.length; remarkIndex++) {
                row = sheet.createRow(line + fees.size() + 4 + remarkIndex);
                row.createCell(0).setCellValue(feePrintRemarks[remarkIndex]);
                row.setHeight((short) (defaultRowHeight));
            }
        }
        row = sheet.createRow(line + fees.size() + 4 + feePrintRemarks.length);
        row.createCell(0).setCellValue("");
        row.setHeight((short) (defaultRowHeight));
        row = sheet.createRow(line + fees.size() + 5);
        row.createCell(0).setCellValue("2、逾期未缴,将按规定收取违约金,会给您照成不必要的损失");
        row.setHeight((short) (defaultRowHeight));
        Map info = new HashMap();
        info.put("line", line + fees.size() + 6);
        info.put("line", line + fees.size() + 4 + feePrintRemarks.length);
        info.put("totalPageHeight", totalPageHeight);
        return info;
    }