|
@@ -1,24 +1,39 @@
|
1
|
1
|
package com.community.huiju.service.impl;
|
2
|
2
|
|
3
|
3
|
import com.alibaba.fastjson.JSONObject;
|
|
4
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
4
|
5
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
5
|
6
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
7
|
+import com.community.commom.constant.Constant;
|
6
|
8
|
import com.community.commom.mode.ResponseBean;
|
7
|
9
|
import com.community.commom.session.UserElement;
|
8
|
|
-import com.community.huiju.dao.BillInvoiceMapper;
|
9
|
|
-import com.community.huiju.dao.BillStatementMapper;
|
10
|
|
-import com.community.huiju.model.Bill;
|
11
|
|
-import com.community.huiju.dao.BillMapper;
|
12
|
|
-import com.community.huiju.model.TpTransaction;
|
|
10
|
+import com.community.commom.utils.PayPriceUtils;
|
|
11
|
+import com.community.huiju.dao.*;
|
|
12
|
+import com.community.huiju.exception.WisdomException;
|
|
13
|
+import com.community.huiju.model.*;
|
|
14
|
+import com.community.huiju.service.IBillInvoiceService;
|
13
|
15
|
import com.community.huiju.service.IBillService;
|
|
16
|
+import com.google.common.collect.Lists;
|
14
|
17
|
import com.google.common.collect.Maps;
|
|
18
|
+import lombok.Data;
|
|
19
|
+import lombok.extern.slf4j.Slf4j;
|
15
|
20
|
import org.apache.commons.lang3.StringUtils;
|
|
21
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
22
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
23
|
+import org.apache.poi.ss.usermodel.Row;
|
|
24
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
25
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
26
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
16
|
27
|
import org.springframework.beans.factory.annotation.Autowired;
|
17
|
28
|
import org.springframework.stereotype.Service;
|
18
|
29
|
import org.springframework.transaction.annotation.Transactional;
|
|
30
|
+import org.springframework.web.multipart.MultipartFile;
|
19
|
31
|
|
|
32
|
+import java.io.IOException;
|
|
33
|
+import java.util.Date;
|
20
|
34
|
import java.util.List;
|
21
|
35
|
import java.util.Map;
|
|
36
|
+import java.util.stream.Collectors;
|
22
|
37
|
|
23
|
38
|
/**
|
24
|
39
|
* <p>
|
|
@@ -29,6 +44,7 @@ import java.util.Map;
|
29
|
44
|
* @since 2019-02-13
|
30
|
45
|
*/
|
31
|
46
|
@Service
|
|
47
|
+@Slf4j
|
32
|
48
|
public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements IBillService {
|
33
|
49
|
|
34
|
50
|
/** 缴费项表 **/
|
|
@@ -39,10 +55,19 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements IB
|
39
|
55
|
@Autowired
|
40
|
56
|
private BillInvoiceMapper billInvoiceMapper;
|
41
|
57
|
|
|
58
|
+ private IBillInvoiceService iBillInvoiceService;
|
|
59
|
+
|
42
|
60
|
/** 账单流水表 **/
|
43
|
61
|
@Autowired
|
44
|
62
|
private BillStatementMapper billStatementMapper;
|
45
|
63
|
|
|
64
|
+ @Autowired
|
|
65
|
+ private TpBuildingOwnerInfoMapper tpBuildingOwnerInfoMapper;
|
|
66
|
+
|
|
67
|
+ @Autowired
|
|
68
|
+ private TaUserMapper taUserMapper;
|
|
69
|
+
|
|
70
|
+
|
46
|
71
|
@Override
|
47
|
72
|
@Transactional(rollbackFor = Exception.class)
|
48
|
73
|
public ResponseBean updateBillNameAndBillExplainAndEndDate(UserElement userElement, String parameter) {
|
|
@@ -100,4 +125,217 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements IB
|
100
|
125
|
responseBean.addSuccess(map);
|
101
|
126
|
return responseBean;
|
102
|
127
|
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+ @Override
|
|
131
|
+ public ResponseBean getExcelData(MultipartFile file, String billExplain) {
|
|
132
|
+ ResponseBean responseBean = new ResponseBean();
|
|
133
|
+ if (file == null) {
|
|
134
|
+ responseBean.addError("对象不能为空");
|
|
135
|
+ return responseBean;
|
|
136
|
+ }
|
|
137
|
+
|
|
138
|
+ responseBean = getExcelData(file, responseBean);
|
|
139
|
+ List<TempBill> tempBills = (List<TempBill>) responseBean.getData();
|
|
140
|
+ tempBills.forEach(e -> {
|
|
141
|
+ e.setBillExplain(billExplain);
|
|
142
|
+ });
|
|
143
|
+
|
|
144
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
145
|
+ map.put("list", tempBills);
|
|
146
|
+ map.put("total", tempBills.size());
|
|
147
|
+ responseBean.addSuccess(map);
|
|
148
|
+
|
|
149
|
+ return responseBean;
|
|
150
|
+ }
|
|
151
|
+
|
|
152
|
+ @Override
|
|
153
|
+ public ResponseBean getExcelData(MultipartFile file, String billExplain, String billName, Date endDate, String billStatus, UserElement userElement) {
|
|
154
|
+ ResponseBean responseBean = new ResponseBean();
|
|
155
|
+ responseBean = getExcelData(file, responseBean);
|
|
156
|
+ List<TempBill> tempBills = (List<TempBill>) responseBean.getData();
|
|
157
|
+
|
|
158
|
+ Double sumDouble = tempBills.stream().mapToDouble(TempBill::getMoney).sum();
|
|
159
|
+
|
|
160
|
+ // 存入缴费项表
|
|
161
|
+ Bill bill = new Bill();
|
|
162
|
+ bill.setBillName(billName);
|
|
163
|
+ bill.setBillExplain(billExplain);
|
|
164
|
+ bill.setEndDate(endDate);
|
|
165
|
+ bill.setPayedNum(PayPriceUtils.yuanConversionPoints(Double.valueOf(sumDouble)));
|
|
166
|
+ bill.setPayTotalNum(tempBills.size());
|
|
167
|
+ bill.setPayedNum(0);
|
|
168
|
+ bill.setUnpayedNum(tempBills.size());
|
|
169
|
+ bill.setBillStatus(billStatus);
|
|
170
|
+ bill.setCreateUser(userElement.getId());
|
|
171
|
+ bill.setCreateDate(new Date());
|
|
172
|
+
|
|
173
|
+ int rows = billMapper.insert(bill);
|
|
174
|
+ if (rows > 0) {
|
|
175
|
+ List<BillInvoice> billInvoices = tempBills.stream().map(e -> {
|
|
176
|
+ BillInvoice billInvoice = new BillInvoice();
|
|
177
|
+ billInvoice.setCommunityId(userElement.getCommunityId());
|
|
178
|
+ billInvoice.setBillId(bill.getId());
|
|
179
|
+
|
|
180
|
+ // 楼栋资料库
|
|
181
|
+ QueryWrapper<TpBuildingOwnerInfo> queryWrapper = new QueryWrapper<>();
|
|
182
|
+ queryWrapper.eq("phase", e.getPhase());
|
|
183
|
+ queryWrapper.eq("building", e.getBuilding());
|
|
184
|
+ queryWrapper.eq("unit", e.getUnit());
|
|
185
|
+ queryWrapper.eq("room_no", e.getRoomNo());
|
|
186
|
+ queryWrapper.eq("community_id", userElement.getCommunityId());
|
|
187
|
+ TpBuildingOwnerInfo buildingOwnerInfo = tpBuildingOwnerInfoMapper.selectOne(queryWrapper);
|
|
188
|
+
|
|
189
|
+ // 查询app用户id
|
|
190
|
+ QueryWrapper<TaUser> userQueryWrapper = new QueryWrapper<>();
|
|
191
|
+ userQueryWrapper.eq("community_id", userElement.getCommunityId());
|
|
192
|
+ userQueryWrapper.eq("login_name", buildingOwnerInfo.getOwnerTel());
|
|
193
|
+ TaUser taUser = taUserMapper.selectOne(userQueryWrapper);
|
|
194
|
+
|
|
195
|
+ billInvoice.setBuildingOwnerInfoId(buildingOwnerInfo.getId());
|
|
196
|
+ billInvoice.setTaUserId(taUser.getId());
|
|
197
|
+ billInvoice.setBillInvoiceExplain(bill.getBillExplain());
|
|
198
|
+ billInvoice.setPayPrice(e.getMoney());
|
|
199
|
+ billInvoice.setBillStatus("0");
|
|
200
|
+ billInvoice.setCreateUser(userElement.getId());
|
|
201
|
+ billInvoice.setCreateDate(new Date());
|
|
202
|
+ billInvoice.setStatus(1);
|
|
203
|
+ return billInvoice;
|
|
204
|
+ }).collect(Collectors.toList());
|
|
205
|
+
|
|
206
|
+ iBillInvoiceService.saveBatch(billInvoices);
|
|
207
|
+ responseBean.addSuccess("操作成功!");
|
|
208
|
+ } else {
|
|
209
|
+ responseBean.addError("操作失败!");
|
|
210
|
+ }
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+ return responseBean;
|
|
214
|
+ }
|
|
215
|
+
|
|
216
|
+ private ResponseBean getExcelData(MultipartFile file, ResponseBean responseBean) {
|
|
217
|
+ ResponseBean responseBean1 = new ResponseBean();
|
|
218
|
+ //获取文件的名字
|
|
219
|
+ String originalFilename = file.getOriginalFilename();
|
|
220
|
+ Workbook workbook = null;
|
|
221
|
+ try {
|
|
222
|
+ if (originalFilename.endsWith(Constant.SUFFIX_2003)) {
|
|
223
|
+ workbook = new HSSFWorkbook(file.getInputStream());
|
|
224
|
+ } else if (originalFilename.endsWith(Constant.SUFFIX_2007)) {
|
|
225
|
+ workbook = new XSSFWorkbook(file.getInputStream());
|
|
226
|
+ }
|
|
227
|
+ } catch (Exception e) {
|
|
228
|
+ log.info(originalFilename);
|
|
229
|
+ e.printStackTrace();
|
|
230
|
+ responseBean.addError("格式错误");
|
|
231
|
+ return responseBean;
|
|
232
|
+ }
|
|
233
|
+
|
|
234
|
+ // 获取 Sheet 第一页
|
|
235
|
+ Sheet sheetAt = workbook.getSheetAt(0);
|
|
236
|
+ int lastRowNum = sheetAt.getLastRowNum();
|
|
237
|
+
|
|
238
|
+ // 数据
|
|
239
|
+ List<TempBill> tempBills = Lists.newArrayList();
|
|
240
|
+
|
|
241
|
+ // 从第7行开始读取
|
|
242
|
+ for (int i= 6; i<= lastRowNum; i++) {
|
|
243
|
+ Row row = sheetAt.getRow(i);
|
|
244
|
+ Cell cell = getCell(row.getCell(0));
|
|
245
|
+ if (null == cell) {
|
|
246
|
+ throw new WisdomException("第" + i + "行 期/区 不能为空");
|
|
247
|
+ }
|
|
248
|
+ String phase = cell.getStringCellValue().trim();
|
|
249
|
+ cell = getCell(row.getCell(1));
|
|
250
|
+ if (null == cell) {
|
|
251
|
+ throw new WisdomException("第" + i + "行 楼栋 不能为空");
|
|
252
|
+ }
|
|
253
|
+ String building = cell.getStringCellValue().trim();
|
|
254
|
+ cell = getCell(row.getCell(2));
|
|
255
|
+ if (null == cell) {
|
|
256
|
+ throw new WisdomException("第" + i + "行 单元 不能为空");
|
|
257
|
+ }
|
|
258
|
+ String unit = cell.getStringCellValue().trim();
|
|
259
|
+ cell = getCell(row.getCell(3));
|
|
260
|
+ if (null == cell) {
|
|
261
|
+ throw new WisdomException("第" + i + "行 楼层 不能为空");
|
|
262
|
+ }
|
|
263
|
+ String level = cell.getStringCellValue().trim();
|
|
264
|
+ cell = getCell(row.getCell(4));
|
|
265
|
+ if (null == cell) {
|
|
266
|
+ throw new WisdomException("第" + i + "行 房号 不能为空");
|
|
267
|
+ }
|
|
268
|
+ String roomNo = cell.getStringCellValue().trim();
|
|
269
|
+ cell = getCell(row.getCell(5));
|
|
270
|
+ if (null == cell) {
|
|
271
|
+ throw new WisdomException("第" + i + "行 业主姓名 不能为空");
|
|
272
|
+ }
|
|
273
|
+ String ownerName = cell.getStringCellValue().trim();
|
|
274
|
+ cell = getCell(row.getCell(6));
|
|
275
|
+ if (null == cell) {
|
|
276
|
+ throw new WisdomException("第" + i + "行 金额 不能为空");
|
|
277
|
+ }
|
|
278
|
+ String money = cell.getStringCellValue().trim();
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+ TempBill temp = new TempBill();
|
|
282
|
+ temp.setPhase(phase);
|
|
283
|
+ temp.setBuilding(building);
|
|
284
|
+ temp.setLevel(level);
|
|
285
|
+ temp.setUnit(unit);
|
|
286
|
+ temp.setRoomNo(roomNo);
|
|
287
|
+ temp.setOwnerName(ownerName);
|
|
288
|
+
|
|
289
|
+ if (StringUtils.isNotBlank(money)) {
|
|
290
|
+ String[] split = money.split(".");
|
|
291
|
+ // 判断是否包含 . ,包含表示 0.00 的格式, 并且最后一位不等于 "."
|
|
292
|
+ if (money.endsWith(".") && !split[1].equals(".")) {
|
|
293
|
+ temp.setMoney(PayPriceUtils.yuanConversionPoints(Double.valueOf(money)));
|
|
294
|
+ }else if (!money.endsWith(".")){
|
|
295
|
+ temp.setMoney(PayPriceUtils.yuanConversionPoints(Integer.valueOf(money)));
|
|
296
|
+ } else {
|
|
297
|
+ throw new WisdomException("第" + i + "行 金额 格式不合法");
|
|
298
|
+ }
|
|
299
|
+ }
|
|
300
|
+
|
|
301
|
+ tempBills.add(temp);
|
|
302
|
+ }
|
|
303
|
+
|
|
304
|
+ responseBean.addSuccess(tempBills);
|
|
305
|
+ return responseBean;
|
|
306
|
+ }
|
|
307
|
+
|
|
308
|
+ private Cell getCell(Cell ce){
|
|
309
|
+ Cell cell = ce;
|
|
310
|
+ if (null == cell) {
|
|
311
|
+ return null;
|
|
312
|
+ }
|
|
313
|
+ //把数字当成String来读,避免出现1读成1.0的情况
|
|
314
|
+ if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
|
|
315
|
+ cell.setCellType(Cell.CELL_TYPE_STRING);
|
|
316
|
+ }
|
|
317
|
+
|
|
318
|
+ return cell;
|
|
319
|
+ }
|
|
320
|
+
|
|
321
|
+ @Data
|
|
322
|
+ private class TempBill {
|
|
323
|
+ // 期 / 区
|
|
324
|
+ private String phase;
|
|
325
|
+ // 栋
|
|
326
|
+ private String building;
|
|
327
|
+ // 单元
|
|
328
|
+ private String unit;
|
|
329
|
+ // 楼层
|
|
330
|
+ private String level;
|
|
331
|
+ // 户号
|
|
332
|
+ private String roomNo;
|
|
333
|
+ // 业主姓名
|
|
334
|
+ private String ownerName;
|
|
335
|
+ // 金额
|
|
336
|
+ private Integer money;
|
|
337
|
+
|
|
338
|
+ // 收费说明
|
|
339
|
+ private String billExplain;
|
|
340
|
+ }
|
103
|
341
|
}
|