Explorar el Código

完成 数据导出

魏熙美 hace 6 años
padre
commit
063da67588

+ 25
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/TaUserLicenseOrderController.java Ver fichero

@@ -9,13 +9,17 @@ import io.swagger.annotations.Api;
9 9
 import io.swagger.annotations.ApiImplicitParam;
10 10
 import io.swagger.annotations.ApiImplicitParams;
11 11
 import io.swagger.annotations.ApiOperation;
12
+import org.apache.poi.ss.usermodel.Workbook;
12 13
 import org.springframework.beans.factory.annotation.Autowired;
13 14
 import org.springframework.web.bind.annotation.RequestMapping;
14 15
 import org.springframework.web.bind.annotation.RequestMethod;
15 16
 import org.springframework.web.bind.annotation.RequestParam;
16 17
 import org.springframework.web.bind.annotation.RestController;
17 18
 
19
+import javax.servlet.http.HttpServletRequest;
20
+import javax.servlet.http.HttpServletResponse;
18 21
 import javax.servlet.http.HttpSession;
22
+import java.io.OutputStream;
19 23
 
20 24
 /**
21 25
  * <p>
@@ -59,4 +63,25 @@ public class TaUserLicenseOrderController extends BaseController {
59 63
     }
60 64
 
61 65
 
66
+    @ApiOperation(value = "月租车导出数据", notes = "月租车导出数据")
67
+    @ApiImplicitParams({
68
+            @ApiImplicitParam(dataTypeClass = String.class, paramType = "header", name = "X-Auth-Token", value = "token")
69
+    })
70
+    @RequestMapping(value = "/user/license/export", method = RequestMethod.GET)
71
+    public void exportDate(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
72
+        UserElement userElement = getUserElement(session);
73
+        ResponseBean responseBean = iTaUserLicenseOrderService.exportDate(userElement);
74
+        Workbook workbook = (Workbook) responseBean.getData();
75
+        this.setResponseHeader(response, "月租租车.xlsx");
76
+        //响应到客户端
77
+        try {
78
+            OutputStream os = response.getOutputStream();
79
+            workbook.write(os);
80
+            os.flush();
81
+            os.close();
82
+        } catch (Exception e) {
83
+            e.printStackTrace();
84
+        }
85
+    }
86
+
62 87
 }

+ 26
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/TaUserLicenseOrderMapper.java Ver fichero

@@ -2,6 +2,11 @@ package com.community.huiju.dao;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 4
 import com.community.huiju.model.TaUserLicenseOrder;
5
+import org.apache.ibatis.annotations.Param;
6
+import org.apache.ibatis.annotations.ResultType;
7
+import org.apache.ibatis.annotations.Select;
8
+
9
+import java.util.List;
5 10
 
6 11
 /**
7 12
  * <p>
@@ -13,4 +18,25 @@ import com.community.huiju.model.TaUserLicenseOrder;
13 18
  */
14 19
 public interface TaUserLicenseOrderMapper extends BaseMapper<TaUserLicenseOrder> {
15 20
 
21
+    /**
22
+     * 分页查询
23
+     * @param communityId
24
+     * @param pageNum
25
+     * @param pageSize
26
+     * @return
27
+     */
28
+    @ResultType(TaUserLicenseOrder.class)
29
+    @Select("select * from ta_user_license_order where community_id = #{communityId} limit #{pageNum},#{pageSize}")
30
+    List<TaUserLicenseOrder> getLicensePage(@Param("communityId") Integer communityId, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);
31
+
32
+    /**
33
+     * 查询总数
34
+     * @param communityId
35
+     * @return
36
+     */
37
+    @ResultType(Integer.class)
38
+    @Select("select count(*) from ta_user_license_order where community_id = #{communityId}")
39
+    Integer getCount(@Param("communityId") Integer communityId);
40
+
41
+
16 42
 }

+ 6
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/ITaUserLicenseOrderService.java Ver fichero

@@ -26,4 +26,10 @@ public interface ITaUserLicenseOrderService extends IService<TaUserLicenseOrder>
26 26
      */
27 27
     ResponseBean getAll(Integer id, String licensePlate, String orderNumber, String paymentName, String paymentTel, Integer pageNum, Integer pageSize, UserElement userElement);
28 28
 
29
+    /**
30
+     * 导出数据
31
+     * @param userElement
32
+     * @return
33
+     */
34
+    ResponseBean exportDate(UserElement userElement);
29 35
 }

+ 98
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/TaUserLicenseOrderServiceImpl.java Ver fichero

@@ -9,9 +9,22 @@ import com.community.commom.session.UserElement;
9 9
 import com.community.huiju.model.TaUserLicenseOrder;
10 10
 import com.community.huiju.dao.TaUserLicenseOrderMapper;
11 11
 import com.community.huiju.service.ITaUserLicenseOrderService;
12
+import org.apache.commons.collections.CollectionUtils;
12 13
 import org.apache.commons.lang3.StringUtils;
14
+import org.apache.poi.ss.usermodel.Cell;
15
+import org.apache.poi.ss.usermodel.Row;
16
+import org.apache.poi.ss.usermodel.Sheet;
17
+import org.apache.poi.ss.usermodel.Workbook;
18
+import org.apache.poi.xssf.usermodel.XSSFRow;
19
+import org.apache.poi.xssf.usermodel.XSSFSheet;
20
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
21
+import org.springframework.beans.factory.annotation.Autowired;
13 22
 import org.springframework.stereotype.Service;
14 23
 
24
+import java.text.SimpleDateFormat;
25
+import java.time.format.DateTimeFormatter;
26
+import java.util.List;
27
+
15 28
 /**
16 29
  * <p>
17 30
  * 月租车缴费订单表 服务实现类
@@ -23,6 +36,9 @@ import org.springframework.stereotype.Service;
23 36
 @Service
24 37
 public class TaUserLicenseOrderServiceImpl extends ServiceImpl<TaUserLicenseOrderMapper, TaUserLicenseOrder> implements ITaUserLicenseOrderService {
25 38
 
39
+    @Autowired
40
+    private TaUserLicenseOrderMapper taUserLicenseOrderMapper;
41
+
26 42
     @Override
27 43
     public ResponseBean getAll(Integer id, String licensePlate, String orderNumber, String paymentName, String paymentTel, Integer pageNum, Integer pageSize, UserElement userElement) {
28 44
         ResponseBean responseBean = new ResponseBean();
@@ -41,4 +57,86 @@ public class TaUserLicenseOrderServiceImpl extends ServiceImpl<TaUserLicenseOrde
41 57
         responseBean.addSuccess(orderIPage);
42 58
         return responseBean;
43 59
     }
60
+
61
+    @Override
62
+    public ResponseBean exportDate(UserElement userElement) {
63
+        ResponseBean responseBean = new ResponseBean();
64
+        Integer pageNum = 0;
65
+        Integer pageSize = 10;
66
+        Integer count = 0;
67
+        count = taUserLicenseOrderMapper.getCount(userElement.getCommunityId());
68
+        List<TaUserLicenseOrder> licensePage = taUserLicenseOrderMapper.getLicensePage(userElement.getCommunityId(), pageNum * pageSize, pageSize);
69
+
70
+        Workbook workbook = new XSSFWorkbook();
71
+        Sheet sheet = workbook.createSheet();
72
+        Row row = sheet.createRow(0);
73
+        Cell cell = row.createCell(0);
74
+        cell.setCellValue("编号");
75
+        cell = row.createCell(0);
76
+        cell.setCellValue("车牌号");
77
+        cell = row.createCell(1);
78
+        cell.setCellValue("续期时长(月)");
79
+        cell = row.createCell(2);
80
+        cell.setCellValue("续期费用(元)");
81
+        cell = row.createCell(3);
82
+        cell.setCellValue("缴费订单号");
83
+        cell = row.createCell(4);
84
+        cell.setCellValue("缴费人手机号");
85
+        cell = row.createCell(5);
86
+        cell.setCellValue("缴费人姓名");
87
+        cell = row.createCell(6);
88
+        cell.setCellValue("缴费方式");
89
+        cell = row.createCell(7);
90
+        cell.setCellValue("延期后到期日");
91
+        cell = row.createCell(8);
92
+        cell.setCellValue("缴费完成时间");
93
+
94
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
95
+
96
+        int listIndex = 0;
97
+        int currentRow = 1;
98
+        if (listIndex < licensePage.size()) {
99
+            do{
100
+                TaUserLicenseOrder taUserLicenseOrder = licensePage.get(listIndex);
101
+
102
+                row = sheet.createRow(currentRow);
103
+                cell = row.createCell(0);
104
+                cell.setCellValue(taUserLicenseOrder.getId());
105
+                cell = row.createCell(1);
106
+                cell.setCellValue(taUserLicenseOrder.getLicensePlate());
107
+                cell = row.createCell(2);
108
+                cell.setCellValue(taUserLicenseOrder.getExtensionMonth());
109
+                cell = row.createCell(3);
110
+                cell.setCellValue(taUserLicenseOrder.getExtensionPrice());
111
+                cell = row.createCell(4);
112
+                cell.setCellValue(taUserLicenseOrder.getOrderNumber());
113
+                cell = row.createCell(5);
114
+                cell.setCellValue(taUserLicenseOrder.getPaymentTel());
115
+                cell = row.createCell(6);
116
+                cell.setCellValue(taUserLicenseOrder.getPaymentName());
117
+                cell = row.createCell(7);
118
+                cell.setCellValue("0".equals(taUserLicenseOrder.getPaymentType()) ? "微信支付" : "2".equals(taUserLicenseOrder.getPaymentType()) ? "支付宝" : "" );
119
+                cell = row.createCell(8);
120
+                cell.setCellValue(dateTimeFormatter.format(taUserLicenseOrder.getExpireDate()));
121
+                cell = row.createCell(9);
122
+                cell.setCellValue(taUserLicenseOrder.getUpdateDate() == null ? "" : dateTimeFormatter.format(taUserLicenseOrder.getUpdateDate()));
123
+
124
+                listIndex ++;
125
+                currentRow ++;
126
+
127
+                if (listIndex == licensePage.size()) {
128
+                    listIndex = 0;
129
+                    pageNum ++;
130
+                    licensePage = taUserLicenseOrderMapper.getLicensePage(userElement.getCommunityId(), pageNum * pageSize, pageSize);
131
+                }
132
+                if (licensePage.isEmpty()) {
133
+                    break;
134
+                }
135
+
136
+            }while (pageNum <= count);
137
+        }
138
+
139
+        responseBean.addSuccess(workbook);
140
+        return responseBean;
141
+    }
44 142
 }

+ 9
- 0
VUECODE/smart-property-manage/src/api/license.js Ver fichero

@@ -16,3 +16,12 @@ export function getLicenseAll(data) {
16 16
     }
17 17
   })
18 18
 }
19
+
20
+// 导出月租车数据
21
+export function exportLicenseData() {
22
+  return request({
23
+    url: '/user/license/export',
24
+    method: 'get',
25
+    responseType: 'blob'
26
+  })
27
+}

+ 10
- 1
VUECODE/smart-property-manage/src/store/modules/license.js Ver fichero

@@ -1,4 +1,4 @@
1
-import { getLicenseAll } from '@/api/license'
1
+import { getLicenseAll, exportLicenseData } from '@/api/license'
2 2
 
3 3
 const license = {
4 4
   state: {
@@ -16,6 +16,15 @@ const license = {
16 16
           reject(error)
17 17
         })
18 18
       })
19
+    },
20
+    ExportLicenseData({ commit }) { // 导出月租车数据
21
+      return new Promise((resolve, reject) => {
22
+        exportLicenseData().then(response => {
23
+          resolve(response)
24
+        }).catch(error => {
25
+          reject(error)
26
+        })
27
+      })
19 28
     }
20 29
   }
21 30
 }

+ 31
- 2
VUECODE/smart-property-manage/src/views/bill/license/index.vue Ver fichero

@@ -21,14 +21,14 @@
21 21
         <el-button type="primary" @click="query">查询</el-button>
22 22
       </el-form-item>
23 23
     </el-form>
24
-    <div>
24
+    <div style="display: flex; margin-left: 20px;">
25 25
       <el-button type="primary" @click="exportLicense">导出数据</el-button>
26 26
     </div>
27 27
     <el-table
28 28
       v-loading="loading"
29 29
       :data="list"
30 30
       border
31
-      style="width: 100%">
31
+      style="width: 100%; margin-top: 20px;">
32 32
       <el-table-column
33 33
         prop="id"
34 34
         label="编号"
@@ -122,6 +122,17 @@ export default {
122 122
     this.getData()
123 123
   },
124 124
   methods: {
125
+    handleSizeChange(val) {
126
+      console.log(`每页 ${val} 条`)
127
+      this.listQuery.pageSize = val
128
+      this.listQuery.pageNum = 1
129
+      this.getData()
130
+    },
131
+    handleCurrentChange(val) {
132
+      console.log(`当前页: ${val}`)
133
+      this.listQuery.pageNum = val
134
+      this.getData()
135
+    },
125 136
     formatDate(val) {
126 137
       if (val === null || val === '') {
127 138
         return ''
@@ -203,6 +214,24 @@ export default {
203 214
           break
204 215
       }
205 216
       return str
217
+    },
218
+    exportLicense() {
219
+      this.$store.dispatch('ExportLicenseData').then((res) => {
220
+        this.download(res)
221
+      })
222
+    },
223
+    download(data) { // 下载文件
224
+      if (!data) {
225
+        return
226
+      }
227
+      let url = window.URL.createObjectURL(new Blob([data]))
228
+      let link = document.createElement('a')
229
+      link.style.display = 'none'
230
+      link.href = url
231
+      link.setAttribute('download', '月租车订单.xlsx')
232
+
233
+      document.body.appendChild(link)
234
+      link.click()
206 235
     }
207 236
   }
208 237
 }