weiximei 6 years ago
parent
commit
64715c0553

+ 24
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/BillController.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;
13
 import org.springframework.beans.factory.annotation.Autowired;
14
 import org.springframework.beans.factory.annotation.Autowired;
14
 import org.springframework.cloud.context.config.annotation.RefreshScope;
15
 import org.springframework.cloud.context.config.annotation.RefreshScope;
15
 import org.springframework.web.bind.annotation.*;
16
 import org.springframework.web.bind.annotation.*;
16
 import org.springframework.web.multipart.MultipartFile;
17
 import org.springframework.web.multipart.MultipartFile;
17
 
18
 
19
+import javax.servlet.http.HttpServletResponse;
18
 import javax.servlet.http.HttpSession;
20
 import javax.servlet.http.HttpSession;
21
+import java.io.OutputStream;
19
 import java.text.ParseException;
22
 import java.text.ParseException;
20
 import java.text.SimpleDateFormat;
23
 import java.text.SimpleDateFormat;
21
 import java.util.Date;
24
 import java.util.Date;
138
         return responseBean;
141
         return responseBean;
139
     }
142
     }
140
 
143
 
144
+    @ApiOperation(value = "下载Excel模板", notes = "下载Excel模板")
145
+    @ApiImplicitParams({
146
+            @ApiImplicitParam(dataTypeClass = String.class, paramType = "body", name = "parameter", value = "billExplain收费组说明"),
147
+//            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token")
148
+    })
149
+    @RequestMapping(value = "/bill/downloadExcel", method = RequestMethod.POST)
150
+    public void exportExcel(HttpServletResponse response, HttpSession session, @RequestBody String parameter) {
151
+        ResponseBean responseBean = new ResponseBean();
152
+//        UserElement userElement = getUserElement(session);
153
+        HSSFWorkbook workbook = (HSSFWorkbook) iBillService.downloadExcel(parameter).getData();
154
+        this.setResponseHeader(response, "缴费单模板.xls");
155
+        //响应到客户端
156
+        try {
157
+            OutputStream os = response.getOutputStream();
158
+            workbook.write(os);
159
+            os.flush();
160
+            os.close();
161
+        } catch (Exception e) {
162
+            e.printStackTrace();
163
+        }
164
+    }
141
 
165
 
142
 }
166
 }

+ 7
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IBillService.java View File

78
 	 * @return
78
 	 * @return
79
 	 */
79
 	 */
80
     ResponseBean deleteBillBeach(UserElement userElement, List<Integer> ids);
80
     ResponseBean deleteBillBeach(UserElement userElement, List<Integer> ids);
81
+
82
+	/**
83
+	 * 下载 excel 模板
84
+	 * @param parameter
85
+	 * @return
86
+	 */
87
+	ResponseBean downloadExcel(String parameter);
81
 }
88
 }

+ 79
- 1
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/BillServiceImpl.java View File

20
 import lombok.Data;
20
 import lombok.Data;
21
 import lombok.extern.slf4j.Slf4j;
21
 import lombok.extern.slf4j.Slf4j;
22
 import org.apache.commons.lang3.StringUtils;
22
 import org.apache.commons.lang3.StringUtils;
23
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
23
+import org.apache.poi.hssf.usermodel.*;
24
 import org.apache.poi.ss.usermodel.Cell;
24
 import org.apache.poi.ss.usermodel.Cell;
25
 import org.apache.poi.ss.usermodel.Row;
25
 import org.apache.poi.ss.usermodel.Row;
26
 import org.apache.poi.ss.usermodel.Sheet;
26
 import org.apache.poi.ss.usermodel.Sheet;
31
 import org.springframework.transaction.annotation.Transactional;
31
 import org.springframework.transaction.annotation.Transactional;
32
 import org.springframework.web.multipart.MultipartFile;
32
 import org.springframework.web.multipart.MultipartFile;
33
 
33
 
34
+import java.io.FileInputStream;
35
+import java.io.FileNotFoundException;
34
 import java.io.IOException;
36
 import java.io.IOException;
37
+import java.io.InputStream;
35
 import java.text.ParseException;
38
 import java.text.ParseException;
36
 import java.text.SimpleDateFormat;
39
 import java.text.SimpleDateFormat;
37
 import java.util.Date;
40
 import java.util.Date;
463
         // 收费说明
466
         // 收费说明
464
         private String billExplain;
467
         private String billExplain;
465
     }
468
     }
469
+
470
+    @Override
471
+    public ResponseBean downloadExcel(String parameter) {
472
+        ResponseBean responseBean = new ResponseBean();
473
+
474
+        InputStream inputStream = null;
475
+        HSSFWorkbook workbook = null;
476
+        try {
477
+            inputStream = new FileInputStream("缴费单模板.xls");
478
+            workbook = new HSSFWorkbook(inputStream);
479
+        } catch (FileNotFoundException e) {
480
+            e.printStackTrace();
481
+        } catch (IOException e) {
482
+            e.printStackTrace();
483
+        }
484
+
485
+       
486
+        HSSFSheet sheet = workbook.createSheet("缴费单");
487
+        // 创建行
488
+        HSSFRow row = sheet.createRow(0);
489
+        // 创建列
490
+        HSSFCell cell = row.createCell(0);
491
+        cell.setCellValue("1.第1行到第4行为模板说明。第5行为列头。第6行为示例。第7行及以后行中的金额部分为需要您填写的区域。请不要删除任何列、说明以及示例等。");
492
+        row = sheet.createRow(1);
493
+        cell = row.createCell(0);
494
+        cell.setCellValue("2.下表中 栋/单元/楼层/房号/业主姓名为系统生成,自行增加、修改无效,只能修改金额!!!如果没有内容或缺失内容,请先登录物业系统,在 社区管理——业主/楼盘——楼盘库中添加楼盘信息,在社区管理——业主/楼盘——业主资料库中添加业主信息,完成后再重新下载账单模板。");
495
+        row = sheet.createRow(2);
496
+        cell = row.createCell(0);
497
+        cell.setCellValue("3.无需缴费的户可以直接在户所在行最左侧行号上点击右键删除行。");
498
+        row = sheet.createRow(3);
499
+        cell = row.createCell(0);
500
+        cell.setCellValue("4.需要缴费的户,在金额列中填写金额,默认单位为人民币元,请输入大于0的数字,小数点请用英文小数点,更不能使用句号。最多保留小数点后两位。若是复制粘贴的金额,请在粘贴后检查金额是否正确,系统暂时无法退费,请仔细核对账单");
501
+        row = sheet.createRow(4);
502
+        cell = row.createCell(0);
503
+        cell.setCellValue("期/区");
504
+        cell = row.createCell(1);
505
+        cell.setCellValue("栋");
506
+        cell = row.createCell(2);
507
+        cell.setCellValue("单元");
508
+        cell = row.createCell(3);
509
+        cell.setCellValue("楼层");
510
+        cell = row.createCell(4);
511
+        cell.setCellValue("房号");
512
+        cell = row.createCell(5);
513
+        cell.setCellValue("业主姓名");
514
+        cell = row.createCell(6);
515
+        cell.setCellValue("金额(元)");
516
+
517
+        String [] [] data = new String[][] {{"1区","0", "0", "0", "0", "示例忽删", "12.34", "<-示例"}};
518
+        int crrentRow = 5;
519
+        // 行数
520
+        for (int i = 0; i < data.length; i++) {
521
+            row = sheet.createRow(i + crrentRow);
522
+            for (int t = 0; t < data[i].length; t++) {
523
+                cell = row.createCell(t);
524
+                cell.setCellValue(data[i][t]);
525
+            }
526
+        }
527
+
528
+        responseBean.addSuccess(workbook);
529
+        return responseBean;
530
+    }
531
+
532
+    private void setExcelData(String [][] data, HSSFSheet sheet, HSSFRow row, HSSFCell cell){
533
+        int crrentRow = 5;
534
+        // 行数
535
+        for (int i = 0; i < data.length; i++) {
536
+            row = sheet.createRow(i + crrentRow);
537
+            for (int t = 0; t < data[i].length; t++) {
538
+                cell = row.createCell(t);
539
+                cell.setCellValue(data[i][t]);
540
+            }
541
+        }
542
+    }
543
+
466
 }
544
 }