From 38b7741d060048ebfd7be48cbc5980eeaeba287b Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期三, 16 六月 2021 19:10:12 +0800
Subject: [PATCH] 加入抄表动态单价功能

---
 service-front/src/main/java/com/java110/front/smo/assetExport/impl/ExportMeterWaterSMOImpl.java |   97 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 96 insertions(+), 1 deletions(-)

diff --git a/service-front/src/main/java/com/java110/front/smo/assetExport/impl/ExportMeterWaterSMOImpl.java b/service-front/src/main/java/com/java110/front/smo/assetExport/impl/ExportMeterWaterSMOImpl.java
old mode 100644
new mode 100755
index 6aa367e..0ca118f
--- a/service-front/src/main/java/com/java110/front/smo/assetExport/impl/ExportMeterWaterSMOImpl.java
+++ b/service-front/src/main/java/com/java110/front/smo/assetExport/impl/ExportMeterWaterSMOImpl.java
@@ -59,7 +59,7 @@
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         MultiValueMap headers = new HttpHeaders();
         headers.add("content-type", "application/octet-stream;charset=UTF-8");
-        headers.add("Content-Disposition", "attachment;filename=feeImport_" + DateUtil.getyyyyMMddhhmmssDateString() + ".xlsx");
+        headers.add("Content-Disposition", "attachment;filename=meteWaterImport_" + DateUtil.getyyyyMMddhhmmssDateString() + ".xlsx");
         headers.add("Pargam", "no-cache");
         headers.add("Cache-Control", "no-cache");
         //headers.add("Content-Disposition", "attachment; filename=" + outParam.getString("fileName"));
@@ -163,6 +163,101 @@
         sheet.addMergedRegion(region);
     }
 
+
+    @Override
+    public ResponseEntity<Object> exportExcelData2(IPageData pd) throws Exception {
+
+        ComponentValidateResult result = this.validateStoreStaffCommunityRelationship(pd, restTemplate);
+
+        Assert.hasKeyAndValue(JSONObject.parseObject(pd.getReqData()), "communityId", "璇锋眰涓湭鍖呭惈灏忓尯");
+        Assert.hasKeyAndValue(JSONObject.parseObject(pd.getReqData()), "meterType", "璇锋眰涓湭鍖呭惈璐圭敤椤圭洰");
+
+        Workbook workbook = null;  //宸ヤ綔绨�
+        //宸ヤ綔琛�
+        workbook = new XSSFWorkbook();
+        //鑾峰彇妤间俊鎭�
+        getMeterWater2(pd, result, workbook);
+
+
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        MultiValueMap headers = new HttpHeaders();
+        headers.add("content-type", "application/octet-stream;charset=UTF-8");
+        headers.add("Content-Disposition", "attachment;filename=meteWaterImport2_" + DateUtil.getyyyyMMddhhmmssDateString() + ".xlsx");
+        headers.add("Pargam", "no-cache");
+        headers.add("Cache-Control", "no-cache");
+        //headers.add("Content-Disposition", "attachment; filename=" + outParam.getString("fileName"));
+        headers.add("Accept-Ranges", "bytes");
+        byte[] context = null;
+        try {
+            workbook.write(os);
+            context = os.toByteArray();
+            os.close();
+            workbook.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+            // 淇濆瓨鏁版嵁
+            return new ResponseEntity<Object>("瀵煎嚭澶辫触", HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+        // 淇濆瓨鏁版嵁
+        return new ResponseEntity<Object>(context, headers, HttpStatus.OK);
+    }
+
+    /**
+     * 鑾峰彇 鎴垮眿淇℃伅
+     *
+     * @param componentValidateResult
+     * @param workbook
+     */
+    private void getMeterWater2(IPageData pd, ComponentValidateResult componentValidateResult, Workbook workbook) {
+        JSONObject reqJson = JSONObject.parseObject(pd.getReqData());
+        Sheet sheet = workbook.createSheet("鎴垮眿璐圭敤淇℃伅");
+        Row row = sheet.createRow(0);
+        Cell cell0 = row.createCell(0);
+        cell0.setCellValue("涓婃湡搴︽暟: 璇峰~鍐欎笂鏈熻〃璇绘暟 锛沑n涓婃湡璇昏〃鏃堕棿: " +
+                "鏍煎紡涓篩YYY-MM-DD锛� \n鏈湡搴︽暟: 鏈琛ㄨ鏁帮紱\n鏈湡璇昏〃鏃堕棿: 鏍煎紡涓篩YYY-MM-DD锛� " +
+                "\n娉ㄦ剰锛氭墍鏈夊崟鍏冩牸寮忎负鏂囨湰");
+        CellStyle cs = workbook.createCellStyle();
+        cs.setWrapText(true);  //鍏抽敭
+        cell0.setCellStyle(cs);
+        row.setHeight((short) (200 * 10));
+        row = sheet.createRow(1);
+        row.createCell(0).setCellValue("妤兼爧缂栧彿");
+        row.createCell(1).setCellValue("鍗曞厓缂栧彿");
+        row.createCell(2).setCellValue("鎴垮眿缂栫爜");
+        row.createCell(3).setCellValue("璐圭敤绫诲瀷");
+        row.createCell(4).setCellValue("鍗曚环");
+        row.createCell(5).setCellValue("涓婃湡搴︽暟");
+        row.createCell(6).setCellValue("涓婃湡璇昏〃鏃堕棿");
+        row.createCell(7).setCellValue("鏈湡搴︽暟");
+        row.createCell(8).setCellValue("鏈湡璇昏〃鏃堕棿");
+        row.createCell(9).setCellValue("澶囨敞");
+
+        //鏌ヨ妤兼爧淇℃伅
+        JSONArray rooms = this.getExistsRoom(pd, componentValidateResult);
+        if (rooms == null) {
+            CellRangeAddress region = new CellRangeAddress(0, 0, 0, 6);
+            sheet.addMergedRegion(region);
+            return;
+        }
+
+        for (int roomIndex = 0; roomIndex < rooms.size(); roomIndex++) {
+            row = sheet.createRow(roomIndex + 2);
+            row.createCell(0).setCellValue(rooms.getJSONObject(roomIndex).getString("floorNum"));
+            row.createCell(1).setCellValue(rooms.getJSONObject(roomIndex).getString("unitNum"));
+            row.createCell(2).setCellValue(rooms.getJSONObject(roomIndex).getString("roomNum"));
+            row.createCell(3).setCellValue(reqJson.getString("feeName"));
+            row.createCell(4).setCellValue(rooms.getJSONObject(roomIndex).getString("price"));
+            row.createCell(5).setCellValue(rooms.getJSONObject(roomIndex).getString("preDegrees"));
+            row.createCell(6).setCellValue(rooms.getJSONObject(roomIndex).getString("preReadingTime"));
+            row.createCell(7).setCellValue("");
+            row.createCell(8).setCellValue("");
+            row.createCell(9).setCellValue("");
+        }
+
+        CellRangeAddress region = new CellRangeAddress(0, 0, 0, 6);
+        sheet.addMergedRegion(region);
+    }
+
     public RestTemplate getRestTemplate() {
         return restTemplate;
     }

--
Gitblit v1.8.0