From cddcf22a61489ee9c2dfee169d817ccd66f95430 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期五, 03 九月 2021 02:23:43 +0800
Subject: [PATCH] 优化代码

---
 service-front/src/main/java/com/java110/front/smo/assetExport/impl/ExportRoomSMOImpl.java |   89 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 86 insertions(+), 3 deletions(-)

diff --git a/service-front/src/main/java/com/java110/front/smo/assetExport/impl/ExportRoomSMOImpl.java b/service-front/src/main/java/com/java110/front/smo/assetExport/impl/ExportRoomSMOImpl.java
old mode 100644
new mode 100755
index e05256f..7da0b73
--- a/service-front/src/main/java/com/java110/front/smo/assetExport/impl/ExportRoomSMOImpl.java
+++ b/service-front/src/main/java/com/java110/front/smo/assetExport/impl/ExportRoomSMOImpl.java
@@ -4,12 +4,12 @@
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.component.BaseComponentSMO;
 import com.java110.core.context.IPageData;
+import com.java110.dto.fee.FeeDto;
 import com.java110.entity.component.ComponentValidateResult;
 import com.java110.front.smo.assetExport.IExportRoomSMO;
 import com.java110.utils.constant.ServiceConstant;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.DateUtil;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -47,13 +47,21 @@
 
         ComponentValidateResult result = this.validateStoreStaffCommunityRelationship(pd, restTemplate);
 
+        JSONObject paramIn = JSONObject.parseObject(pd.getReqData());
+
         Assert.hasKeyAndValue(JSONObject.parseObject(pd.getReqData()), "communityId", "璇锋眰涓湭鍖呭惈灏忓尯");
+        Assert.hasKeyAndValue(paramIn, "objType", "璇锋眰涓湭鍖呭惈璐圭敤瀵硅薄");
 
         Workbook workbook = null;  //宸ヤ綔绨�
         //宸ヤ綔琛�
         workbook = new XSSFWorkbook();
-        //鑾峰彇妤间俊鎭�
-        getRooms(pd, result, workbook);
+
+        if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(paramIn.getString("objType"))) {
+            //鑾峰彇妤间俊鎭�
+            getRooms(pd, result, workbook);
+        } else {
+            getCars(pd, result, workbook);
+        }
 
 
         ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -77,6 +85,51 @@
         }
         // 淇濆瓨鏁版嵁
         return new ResponseEntity<Object>(context, headers, HttpStatus.OK);
+    }
+
+    /**
+     * 鏌ヨ杞﹁締
+     *
+     * @param pd
+     * @param result
+     * @param workbook
+     */
+    private void getCars(IPageData pd, ComponentValidateResult result, Workbook workbook) {
+        Sheet sheet = workbook.createSheet("杞︿綅璐圭敤淇℃伅");
+        Row row = sheet.createRow(0);
+        Cell cell0 = row.createCell(0);
+        cell0.setCellValue("璐圭敤鍚嶇О: 璇峰~鍐欑郴缁熶腑璐圭敤绫诲瀷锛屽鍋滆溅璐圭瓑 锛沑n寮�濮嬫椂闂�: " +
+                "鏀惰垂寮�濮嬫椂闂达紝鏍煎紡涓篩YYY-MM-DD锛沑n缁撴潫鏃堕棿: 璐圭敤缁撴潫鏃堕棿锛屾牸寮忎负YYYY-MM-DD锛� \n鏀惰垂閲戦: 鏈鏀跺彇閲戦 鍗曚綅鍏冿紱 " +
+                "\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("鏀惰垂閲戦");
+
+        //鏌ヨ妤兼爧淇℃伅
+        JSONArray cars = this.getExistsCars(pd, result);
+        if (cars == null) {
+            CellRangeAddress region = new CellRangeAddress(0, 0, 0, 4);
+            sheet.addMergedRegion(region);
+            return;
+        }
+        for (int carIndex = 0; carIndex < cars.size(); carIndex++) {
+            row = sheet.createRow(carIndex + 2);
+            row.createCell(0).setCellValue(cars.getJSONObject(carIndex).getString("carNum"));
+            row.createCell(1).setCellValue("");
+            row.createCell(2).setCellValue("");
+            row.createCell(3).setCellValue("");
+            row.createCell(4).setCellValue("");
+        }
+
+        CellRangeAddress region = new CellRangeAddress(0, 0, 0, 4);
+        sheet.addMergedRegion(region);
     }
 
 
@@ -110,6 +163,36 @@
 
     }
 
+    /**
+     * 鏌ヨ瀛樺湪鐨勬埧灞嬩俊鎭�
+     * room.queryRooms
+     *
+     * @param pd
+     * @param result
+     * @return
+     */
+    private JSONArray getExistsCars(IPageData pd, ComponentValidateResult result) {
+        String apiUrl = "";
+        ResponseEntity<String> responseEntity = null;
+        apiUrl = ServiceConstant.SERVICE_API_URL + "/api/owner.queryOwnerCars?page=1&row=10000&communityId=" + result.getCommunityId();
+        responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET);
+
+        if (responseEntity.getStatusCode() != HttpStatus.OK) { //璺宠繃 淇濆瓨鍗曞厓淇℃伅
+            return null;
+        }
+
+        JSONObject savedCarInfoResults = JSONObject.parseObject(responseEntity.getBody());
+
+
+        if (!savedCarInfoResults.containsKey("data")) {
+            return null;
+        }
+
+
+        return savedCarInfoResults.getJSONArray("data");
+
+    }
+
 
     private JSONArray getExistsUnit(IPageData pd, ComponentValidateResult result, String floorId) {
         String apiUrl = "";

--
Gitblit v1.8.0