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 | 176 ++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 109 insertions(+), 67 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 84e2139..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,15 +4,15 @@
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.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -47,19 +47,27 @@
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 HSSFWorkbook();
- //鑾峰彇妤间俊鎭�
- getRooms(pd, result, workbook);
+ workbook = new XSSFWorkbook();
+
+ if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(paramIn.getString("objType"))) {
+ //鑾峰彇妤间俊鎭�
+ getRooms(pd, result, workbook);
+ } else {
+ getCars(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=" + DateUtil.getyyyyMMddhhmmssDateString() + ".xls");
+ headers.add("Content-Disposition", "attachment;filename=feeImport_" + DateUtil.getyyyyMMddhhmmssDateString() + ".xlsx");
headers.add("Pargam", "no-cache");
headers.add("Cache-Control", "no-cache");
//headers.add("Content-Disposition", "attachment; filename=" + outParam.getString("fileName"));
@@ -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 = "";
@@ -127,27 +210,6 @@
return savedFloorInfoResults;
}
- private JSONArray getExistsFloor(IPageData pd, ComponentValidateResult result) {
- String apiUrl = "";
- ResponseEntity<String> responseEntity = null;
- apiUrl = ServiceConstant.SERVICE_API_URL + "/api/floor.queryFloors?page=1&row=100&communityId=" + result.getCommunityId();
-
- responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET);
-
- if (responseEntity.getStatusCode() != HttpStatus.OK) { //璺宠繃 淇濆瓨鍗曞厓淇℃伅
- return null;
- }
-
- JSONObject savedFloorInfoResult = JSONObject.parseObject(responseEntity.getBody());
-
- if (!savedFloorInfoResult.containsKey("apiFloorDataVoList")) {
- return null;
- }
-
- return savedFloorInfoResult.getJSONArray("apiFloorDataVoList");
-
- }
-
/**
* 鑾峰彇 鎴垮眿淇℃伅
@@ -156,8 +218,17 @@
* @param workbook
*/
private void getRooms(IPageData pd, ComponentValidateResult componentValidateResult, Workbook workbook) {
- Sheet sheet = workbook.createSheet("鎴垮眿淇℃伅");
+ 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("鎴垮眿缂栫爜");
@@ -169,52 +240,23 @@
//鏌ヨ妤兼爧淇℃伅
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 + 1);
- row.createCell(0).setCellValue(rooms.getJSONObject(roomIndex).getString("roomNum"));
- row.createCell(1).setCellValue(rooms.getJSONObject(roomIndex).getString("floorNum"));
- row.createCell(2).setCellValue(rooms.getJSONObject(roomIndex).getString("unitNum"));
+ 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("");
row.createCell(4).setCellValue("");
row.createCell(5).setCellValue("");
row.createCell(6).setCellValue("");
}
- }
-
- /**
- * 鑾峰彇灏忓尯
- *
- * @param workbook
- */
- private void getFloors(IPageData pd, ComponentValidateResult componentValidateResult, Workbook workbook) {
- Sheet sheet = workbook.createSheet("妤兼爧鍗曞厓");
- Row row = sheet.createRow(0);
- row.createCell(0).setCellValue("妤兼爧鍙�");
- row.createCell(1).setCellValue("鍗曞厓缂栧彿");
- row.createCell(2).setCellValue("鎬诲眰鏁�");
- row.createCell(3).setCellValue("鏄惁鏈夌數姊�");
-
- //鏌ヨ妤兼爧淇℃伅
- JSONArray floors = this.getExistsFloor(pd, componentValidateResult);
-
- if (floors == null) {
- return;
- }
- for (int floorIndex = 0; floorIndex < floors.size(); floorIndex++) {
- JSONArray units = this.getExistsUnit(pd, componentValidateResult, floors.getJSONObject(floorIndex).getString("floorId"));
- for (int unitIndex = 0; unitIndex < units.size(); unitIndex++) {
- row = sheet.createRow(floorIndex + 1);
- row.createCell(0).setCellValue(floors.getJSONObject(floorIndex).getString("floorNum"));
- row.createCell(1).setCellValue(units.getJSONObject(unitIndex).getString("unitNum"));
- row.createCell(2).setCellValue(units.getJSONObject(unitIndex).getString("layerCount"));
- row.createCell(3).setCellValue("1010".equals(units.getJSONObject(unitIndex).getString("lift")) ? "鏈�" : "鏃�");
- }
- }
-
-
+ CellRangeAddress region = new CellRangeAddress(0, 0, 0, 6);
+ sheet.addMergedRegion(region);
}
public RestTemplate getRestTemplate() {
--
Gitblit v1.8.0