魏熙美 6 лет назад
Родитель
Сommit
8596501f0d

+ 25
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/BuildingOwnerInfoController.java Просмотреть файл

@@ -10,12 +10,16 @@ import io.swagger.annotations.Api;
10 10
 import io.swagger.annotations.ApiImplicitParam;
11 11
 import io.swagger.annotations.ApiImplicitParams;
12 12
 import io.swagger.annotations.ApiOperation;
13
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
14
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
13 15
 import org.springframework.beans.factory.annotation.Autowired;
14 16
 import org.springframework.cloud.context.config.annotation.RefreshScope;
15 17
 import org.springframework.web.bind.annotation.*;
16 18
 import org.springframework.web.multipart.MultipartFile;
17 19
 
20
+import javax.servlet.http.HttpServletResponse;
18 21
 import javax.servlet.http.HttpSession;
22
+import java.io.OutputStream;
19 23
 import java.util.List;
20 24
 import java.util.stream.Collectors;
21 25
 
@@ -193,4 +197,25 @@ public class BuildingOwnerInfoController extends BaseController {
193 197
         ResponseBean responseBean = iBuildingOwnerInfoService.communitybuildingUpdate(parameter, userElement.getCommunityId());
194 198
         return responseBean;
195 199
     }
200
+
201
+    @ApiOperation(value = "下载Excel模板(小区楼栋信息)", notes = "下载Excel模板(小区楼栋信息)")
202
+    @ApiImplicitParams({
203
+//            @ApiImplicitParam(dataTypeClass = String.class, paramType = "body", name = "parameter", value = "billExplain收费组说明"),
204
+            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token")
205
+    })
206
+    @RequestMapping(value = "/building/downloadExcel", method = RequestMethod.GET)
207
+    public void exportExcel(HttpServletResponse response, HttpSession session) {
208
+        UserElement userElement = getUserElement(session);
209
+        XSSFWorkbook workbook = (XSSFWorkbook) iBuildingOwnerInfoService.downloadExcel(userElement).getData();
210
+        this.setResponseHeader(response, "业主资料库.xlsx");
211
+        //响应到客户端
212
+        try {
213
+            OutputStream os = response.getOutputStream();
214
+            workbook.write(os);
215
+            os.flush();
216
+            os.close();
217
+        } catch (Exception e) {
218
+            e.printStackTrace();
219
+        }
220
+    }
196 221
 }

+ 7
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IBuildingOwnerInfoService.java Просмотреть файл

@@ -111,4 +111,11 @@ public interface IBuildingOwnerInfoService extends IService<TpBuildingOwnerInfo>
111 111
      * @return
112 112
      */
113 113
     ResponseBean communitybuildingUpdate(String parameter, Integer communityId);
114
+
115
+    /**
116
+     * 下载Excel模板(小区楼栋信息)
117
+     * @param userElement
118
+     * @return
119
+     */
120
+    ResponseBean downloadExcel(UserElement userElement);
114 121
 }

+ 90
- 4
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/BuildingOwnerInfoServiceImpl.java Просмотреть файл

@@ -25,11 +25,12 @@ import com.google.common.collect.Lists;
25 25
 import com.google.common.collect.Maps;
26 26
 import org.apache.commons.collections.CollectionUtils;
27 27
 
28
+import org.apache.poi.hssf.usermodel.HSSFCell;
29
+import org.apache.poi.hssf.usermodel.HSSFRow;
30
+import org.apache.poi.hssf.usermodel.HSSFSheet;
28 31
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
29
-import org.apache.poi.ss.usermodel.Row;
30
-import org.apache.poi.ss.usermodel.Sheet;
31
-import org.apache.poi.ss.usermodel.Workbook;
32
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
32
+import org.apache.poi.ss.usermodel.*;
33
+import org.apache.poi.xssf.usermodel.*;
33 34
 import org.slf4j.Logger;
34 35
 import org.slf4j.LoggerFactory;
35 36
 
@@ -39,6 +40,8 @@ import org.springframework.stereotype.Service;
39 40
 import org.springframework.transaction.annotation.Transactional;
40 41
 import org.springframework.web.multipart.MultipartFile;
41 42
 
43
+import java.io.IOException;
44
+import java.io.InputStream;
42 45
 import java.time.LocalDateTime;
43 46
 import java.util.*;
44 47
 import java.util.regex.Pattern;
@@ -845,4 +848,87 @@ public class BuildingOwnerInfoServiceImpl extends ServiceImpl<TpBuildingOwnerInf
845 848
 
846 849
         return selectBuild;
847 850
     }
851
+
852
+    @Override
853
+    public ResponseBean downloadExcel(UserElement userElement) {
854
+        ResponseBean responseBean = new ResponseBean();
855
+
856
+        InputStream inputStream = null;
857
+        inputStream = this.getClass().getResourceAsStream("/业主资料库.xlsx");
858
+
859
+        XSSFWorkbook workbook = null;
860
+        try {
861
+            workbook = new XSSFWorkbook(inputStream);
862
+        } catch (IOException e) {
863
+            e.printStackTrace();
864
+        }
865
+
866
+        XSSFSheet sheet = workbook.getSheetAt(0);
867
+        // 创建行
868
+        XSSFRow row = null;
869
+        // 创建列
870
+        XSSFCell cell = null;
871
+
872
+        Integer pageNum = 1;
873
+        Integer pageSize = 10;
874
+        Page<TpBuildingOwnerInfo> page = new Page(pageNum,pageSize);
875
+        // 分页查询
876
+        QueryWrapper<TpBuildingOwnerInfo> buildingOwnerInfoQueryWrapper = new QueryWrapper<>();
877
+        buildingOwnerInfoQueryWrapper.eq("community_id", userElement.getCommunityId());
878
+        IPage<TpBuildingOwnerInfo> infoIPage = tpBuildingOwnerInfoMapper.selectPage(page, buildingOwnerInfoQueryWrapper);
879
+        List<TpBuildingOwnerInfo> records = infoIPage.getRecords();
880
+        // 总页数
881
+        Long pages = infoIPage.getPages();
882
+
883
+
884
+        // 行数 默认从 第 5 行开始
885
+        int currentRow = 5;
886
+        // 记录坐标
887
+        int index = 0;
888
+
889
+        // 样式
890
+        XSSFCellStyle cellStyle = workbook.createCellStyle();
891
+        cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN); //下边框
892
+        cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);//左边框
893
+        cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);//上边框
894
+        cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);//右边框
895
+        cellStyle.setAlignment(HorizontalAlignment.LEFT);
896
+
897
+        if (records.size() > 0) {
898
+            do {
899
+                TpBuildingOwnerInfo buildingOwnerInfo = records.get(index);
900
+                row = sheet.createRow(currentRow);
901
+                String address = buildingOwnerInfo.getPhaseName() +
902
+                        buildingOwnerInfo.getBuildingName() +
903
+                        buildingOwnerInfo.getUnitName() +
904
+                        buildingOwnerInfo.getLevelName() +
905
+                        buildingOwnerInfo.getName();
906
+
907
+                cell = row.createCell(0);
908
+                cell.setCellValue(address);
909
+                cell.setCellStyle(cellStyle);
910
+                cell = row.createCell(1);
911
+                cell.setCellValue(buildingOwnerInfo.getId());
912
+                cell.setCellStyle(cellStyle);
913
+                cell = row.createCell(2);
914
+                cell.setCellStyle(cellStyle);
915
+                cell = row.createCell(3);
916
+                cell.setCellStyle(cellStyle);
917
+                cell = row.createCell(4);
918
+                cell.setCellStyle(cellStyle);
919
+
920
+                currentRow ++;
921
+                index ++;
922
+                if (index == records.size()) {
923
+                    index = 0;
924
+                    page = new Page(infoIPage.getCurrent() + 1,pageSize);
925
+                    infoIPage = tpBuildingOwnerInfoMapper.selectPage(page, buildingOwnerInfoQueryWrapper);
926
+                    records = infoIPage.getRecords();
927
+                }
928
+            } while (infoIPage.getCurrent() <= pages);
929
+        }
930
+
931
+        responseBean.addSuccess(workbook);
932
+        return responseBean;
933
+    }
848 934
 }

Двоичные данные
CODE/smart-community/property-api/src/main/resources/业主资料库.xlsx Просмотреть файл


+ 9
- 0
VUECODE/smart-property-manage/src/api/buildingOwnerInfo.js Просмотреть файл

@@ -164,3 +164,12 @@ export function communityBuildingAdd(data) {
164 164
     }
165 165
   })
166 166
 }
167
+
168
+// 下载excel模板
169
+export function buildingDownloadExcel() {
170
+  return request({
171
+    url: '/building/downloadExcel',
172
+    method: 'get',
173
+    responseType: 'blob'
174
+  })
175
+}

+ 10
- 1
VUECODE/smart-property-manage/src/store/modules/buildingOwnerInfo.js Просмотреть файл

@@ -1,5 +1,5 @@
1 1
 
2
-import { buildingAddress, buildingList, deleteBuilding, addBuilding, updateBuilding, getByIdBuildingId, userPassCertification, updataPassCertification, communityBuildinglist, buildingHouse,communityBuildingAdd } from '@/api/buildingOwnerInfo'
2
+import { buildingAddress, buildingList, deleteBuilding, addBuilding, updateBuilding, getByIdBuildingId, userPassCertification, updataPassCertification, communityBuildinglist, buildingHouse, communityBuildingAdd, buildingDownloadExcel } from '@/api/buildingOwnerInfo'
3 3
 
4 4
 const buildingOwnerInfo = {
5 5
   state: {
@@ -113,6 +113,15 @@ const buildingOwnerInfo = {
113 113
           reject(error)
114 114
         })
115 115
       })
116
+    },
117
+    BuildingDownloadExcel({ commit }) { // 下载模板
118
+      return new Promise((resolve, reject) => {
119
+        buildingDownloadExcel().then(response => {
120
+          resolve(response)
121
+        }).catch(error => {
122
+          reject(error)
123
+        })
124
+      })
116 125
     }
117 126
   }
118 127
 }

+ 15
- 1
VUECODE/smart-property-manage/src/views/building/batch/batchImport.vue Просмотреть файл

@@ -4,7 +4,8 @@
4 4
     <el-form :inline="true" :model="listQuery" class="form-listQuery">
5 5
       <el-form-item>
6 6
         <el-upload :on-preview="handlePreview" :on-change="handleChange" :before-upload="beforeUpload" :limit="1" :on-exceed="handleExceed" class="upload-demo" action="" multiple>
7
-          <a href="http://jingcheng-h5temp.oss-cn-shanghai.aliyuncs.com/%E6%A5%BC%E6%A0%8B%E5%BA%93%E6%A8%A1%E6%9D%BF.xlsx?Expires=1548327771"><el-button style="margin-left: 10px;" size="large" type="primary">下载模板</el-button></a>
7
+          <!-- <a href="http://jingcheng-h5temp.oss-cn-shanghai.aliyuncs.com/%E6%A5%BC%E6%A0%8B%E5%BA%93%E6%A8%A1%E6%9D%BF.xlsx?Expires=1548327771"></a> -->
8
+          <el-button style="margin-left: 10px;" size="large" type="primary" @click="exportExcel">下载模板-小区</el-button>
8 9
           <el-button slot="trigger" size="large" type="primary">选取文件并预览</el-button>
9 10
           <el-button style="margin-left: 10px;" size="large" type="success" @click="submitUpload">提交</el-button>
10 11
           <el-button style="margin-left: 10px;" size="large" type="success" @click="dialogBuildingIndex">取消</el-button>
@@ -142,6 +143,19 @@ export default {
142 143
     },
143 144
     dialogBuildingIndex() {
144 145
       this.$router.push({ name: "building-index" });
146
+    },
147
+    exportExcel() {
148
+      this.$store.dispatch('BuildingDownloadExcel').then(res => {
149
+        const url = window.URL.createObjectURL(new Blob([res]))
150
+        const link = document.createElement('a')
151
+        link.style.display = 'none'
152
+        link.href = url
153
+        link.setAttribute('download', '业主资料库.xlsx')
154
+        document.body.appendChild(link)
155
+        link.click()
156
+      }).catch(() => {
157
+        console.log('error BuildingDownloadExcel')
158
+      })
145 159
     }
146 160
   }
147 161
 };