Browse Source

楼栋资料库下载模板

魏熙美 6 years ago
parent
commit
8596501f0d

+ 25
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/BuildingOwnerInfoController.java View File

10
 import io.swagger.annotations.ApiImplicitParam;
10
 import io.swagger.annotations.ApiImplicitParam;
11
 import io.swagger.annotations.ApiImplicitParams;
11
 import io.swagger.annotations.ApiImplicitParams;
12
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiOperation;
13
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
14
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
13
 import org.springframework.beans.factory.annotation.Autowired;
15
 import org.springframework.beans.factory.annotation.Autowired;
14
 import org.springframework.cloud.context.config.annotation.RefreshScope;
16
 import org.springframework.cloud.context.config.annotation.RefreshScope;
15
 import org.springframework.web.bind.annotation.*;
17
 import org.springframework.web.bind.annotation.*;
16
 import org.springframework.web.multipart.MultipartFile;
18
 import org.springframework.web.multipart.MultipartFile;
17
 
19
 
20
+import javax.servlet.http.HttpServletResponse;
18
 import javax.servlet.http.HttpSession;
21
 import javax.servlet.http.HttpSession;
22
+import java.io.OutputStream;
19
 import java.util.List;
23
 import java.util.List;
20
 import java.util.stream.Collectors;
24
 import java.util.stream.Collectors;
21
 
25
 
193
         ResponseBean responseBean = iBuildingOwnerInfoService.communitybuildingUpdate(parameter, userElement.getCommunityId());
197
         ResponseBean responseBean = iBuildingOwnerInfoService.communitybuildingUpdate(parameter, userElement.getCommunityId());
194
         return responseBean;
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 View File

111
      * @return
111
      * @return
112
      */
112
      */
113
     ResponseBean communitybuildingUpdate(String parameter, Integer communityId);
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 View File

25
 import com.google.common.collect.Maps;
25
 import com.google.common.collect.Maps;
26
 import org.apache.commons.collections.CollectionUtils;
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
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
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
 import org.slf4j.Logger;
34
 import org.slf4j.Logger;
34
 import org.slf4j.LoggerFactory;
35
 import org.slf4j.LoggerFactory;
35
 
36
 
39
 import org.springframework.transaction.annotation.Transactional;
40
 import org.springframework.transaction.annotation.Transactional;
40
 import org.springframework.web.multipart.MultipartFile;
41
 import org.springframework.web.multipart.MultipartFile;
41
 
42
 
43
+import java.io.IOException;
44
+import java.io.InputStream;
42
 import java.time.LocalDateTime;
45
 import java.time.LocalDateTime;
43
 import java.util.*;
46
 import java.util.*;
44
 import java.util.regex.Pattern;
47
 import java.util.regex.Pattern;
845
 
848
 
846
         return selectBuild;
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
 }

BIN
CODE/smart-community/property-api/src/main/resources/业主资料库.xlsx View File


+ 9
- 0
VUECODE/smart-property-manage/src/api/buildingOwnerInfo.js View File

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 View File

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
 const buildingOwnerInfo = {
4
 const buildingOwnerInfo = {
5
   state: {
5
   state: {
113
           reject(error)
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 View File

4
     <el-form :inline="true" :model="listQuery" class="form-listQuery">
4
     <el-form :inline="true" :model="listQuery" class="form-listQuery">
5
       <el-form-item>
5
       <el-form-item>
6
         <el-upload :on-preview="handlePreview" :on-change="handleChange" :before-upload="beforeUpload" :limit="1" :on-exceed="handleExceed" class="upload-demo" action="" multiple>
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
           <el-button slot="trigger" size="large" type="primary">选取文件并预览</el-button>
9
           <el-button slot="trigger" size="large" type="primary">选取文件并预览</el-button>
9
           <el-button style="margin-left: 10px;" size="large" type="success" @click="submitUpload">提交</el-button>
10
           <el-button style="margin-left: 10px;" size="large" type="success" @click="submitUpload">提交</el-button>
10
           <el-button style="margin-left: 10px;" size="large" type="success" @click="dialogBuildingIndex">取消</el-button>
11
           <el-button style="margin-left: 10px;" size="large" type="success" @click="dialogBuildingIndex">取消</el-button>
142
     },
143
     },
143
     dialogBuildingIndex() {
144
     dialogBuildingIndex() {
144
       this.$router.push({ name: "building-index" });
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
 };