|
@@ -2,6 +2,7 @@ package com.community.huiju.service.impl;
|
2
|
2
|
|
3
|
3
|
import com.alibaba.fastjson.JSONObject;
|
4
|
4
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
5
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
6
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
6
|
7
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
7
|
8
|
import com.community.commom.constant.Constant;
|
|
@@ -163,11 +164,36 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements IB
|
163
|
164
|
public ResponseBean getExcelData(Integer billId, MultipartFile file, String billExplain, String billName, Date endDate, String billStatus, UserElement userElement) {
|
164
|
165
|
ResponseBean responseBean = new ResponseBean();
|
165
|
166
|
|
|
167
|
+ List<BillInvoice> records = null;
|
|
168
|
+ if (billId != null) {
|
|
169
|
+ // 查询出这个收费单, 存在的缴费单数据
|
|
170
|
+ QueryWrapper<BillInvoice> billInvoiceQueryWrapper = new QueryWrapper<>();
|
|
171
|
+ billInvoiceQueryWrapper.eq("bill_id", billId);
|
|
172
|
+ billInvoiceQueryWrapper.eq("community_id", userElement.getCommunityId());
|
|
173
|
+ records = billInvoiceMapper.selectList(billInvoiceQueryWrapper);
|
|
174
|
+ }
|
|
175
|
+
|
|
176
|
+ // 如果没有携带 excel 文件, 并且这个收费组里面也没有收费单, 那么就提示 发送账单失败,需要先上传账单excel
|
|
177
|
+ if (null == file && "0".equals(billStatus) && (null == records ||records.size() == 0)) {
|
|
178
|
+ responseBean.addError("发送账单失败,需要先上传账单excel");
|
|
179
|
+ return responseBean;
|
|
180
|
+ }
|
|
181
|
+
|
166
|
182
|
responseBean = getExcelData(file, responseBean);
|
167
|
183
|
List<TempBill> tempBills = (List<TempBill>) responseBean.getData();
|
168
|
184
|
|
169
|
|
- Double sumDouble = tempBills.stream().mapToDouble(TempBill::getMoney).sum() * 100;
|
|
185
|
+ Double sumDouble = 0.0;
|
170
|
186
|
String strSumDouble = sumDouble + "";
|
|
187
|
+ // 如果 List 有数据, 表示携带了文件上传, 那么就从excel文件里面读取金额
|
|
188
|
+ if (tempBills.size() > 0) {
|
|
189
|
+ sumDouble = tempBills.stream().mapToDouble(TempBill::getMoney).sum() * 100;
|
|
190
|
+ strSumDouble = sumDouble + "";
|
|
191
|
+ }
|
|
192
|
+ // 如果 List 没有数据, records 有数据, 就表示用户做的修改操作 并且没有上传文件, 那么这里的金额应该从数据库读取
|
|
193
|
+ if (tempBills.size() == 0 && records != null) {
|
|
194
|
+ sumDouble = records.stream().mapToDouble(BillInvoice::getPayPrice).sum();
|
|
195
|
+ strSumDouble = sumDouble + "";
|
|
196
|
+ }
|
171
|
197
|
|
172
|
198
|
// 存入缴费项表
|
173
|
199
|
Bill bill = new Bill();
|
|
@@ -178,22 +204,27 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements IB
|
178
|
204
|
strSumDouble = strSumDouble.substring(0, strSumDouble.lastIndexOf("."));
|
179
|
205
|
bill.setPayPrice(strSumDouble);
|
180
|
206
|
}
|
181
|
|
- bill.setPayTotalNum(tempBills.size());
|
|
207
|
+
|
182
|
208
|
bill.setPayedNum(0);
|
183
|
|
- bill.setUnpayedNum(tempBills.size());
|
184
|
209
|
bill.setBillStatus(billStatus);
|
185
|
210
|
bill.setCreateUser(userElement.getId());
|
186
|
211
|
bill.setCreateDate(new Date());
|
187
|
212
|
bill.setCommunityId(userElement.getCommunityId());
|
188
|
|
- bill.setPayTotalNum(tempBills.size());
|
189
|
|
- bill.setUnpayedNum(tempBills.size());
|
|
213
|
+ Integer payTotalNum = tempBills.size() != 0 ? tempBills.size() : records != null ? records.size() : 0;
|
|
214
|
+ Integer unpayedNum = tempBills.size() != 0 ? tempBills.size() : records != null ? records.size() : 0;
|
|
215
|
+ bill.setPayTotalNum(payTotalNum);
|
|
216
|
+ bill.setUnpayedNum(unpayedNum);
|
190
|
217
|
|
191
|
|
- if (billId != null) {
|
|
218
|
+ if (file != null) {
|
192
|
219
|
// 删除掉旧数据
|
193
|
|
- QueryWrapper<BillInvoice> billInvoiceQueryWrapper = new QueryWrapper<>();
|
194
|
|
- billInvoiceQueryWrapper.eq("bill_id", billId);
|
195
|
|
- billInvoiceMapper.delete(billInvoiceQueryWrapper);
|
|
220
|
+ QueryWrapper<BillInvoice> billInvoiceQuery = new QueryWrapper<>();
|
|
221
|
+ billInvoiceQuery.eq("bill_id", billId);
|
|
222
|
+ billInvoiceMapper.delete(billInvoiceQuery);
|
|
223
|
+ }
|
196
|
224
|
|
|
225
|
+ if (billId != null) {
|
|
226
|
+ bill.setCreateUser(null);
|
|
227
|
+ bill.setCreateDate(null);
|
197
|
228
|
// 设置主键, 表示修改
|
198
|
229
|
bill.setId(billId);
|
199
|
230
|
}
|
|
@@ -238,17 +269,20 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements IB
|
238
|
269
|
}).collect(Collectors.toList());
|
239
|
270
|
|
240
|
271
|
iBillInvoiceService.saveBatch(billInvoices);
|
241
|
|
- responseBean.addSuccess("操作成功!");
|
242
|
|
- } else {
|
243
|
|
- responseBean.addError("操作失败!");
|
244
|
272
|
}
|
245
|
|
-
|
246
|
|
-
|
|
273
|
+ responseBean.addSuccess("操作成功!");
|
247
|
274
|
return responseBean;
|
248
|
275
|
}
|
249
|
276
|
|
250
|
277
|
private ResponseBean getExcelData(MultipartFile file, ResponseBean responseBean) {
|
251
|
|
- ResponseBean responseBean1 = new ResponseBean();
|
|
278
|
+
|
|
279
|
+ // 数据
|
|
280
|
+ List<TempBill> tempBills = Lists.newArrayList();
|
|
281
|
+ if (null == file) {
|
|
282
|
+ responseBean.addSuccess(tempBills);
|
|
283
|
+ return responseBean;
|
|
284
|
+ }
|
|
285
|
+
|
252
|
286
|
//获取文件的名字
|
253
|
287
|
String originalFilename = file.getOriginalFilename();
|
254
|
288
|
Workbook workbook = null;
|
|
@@ -269,9 +303,6 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements IB
|
269
|
303
|
Sheet sheetAt = workbook.getSheetAt(0);
|
270
|
304
|
int lastRowNum = sheetAt.getLastRowNum();
|
271
|
305
|
|
272
|
|
- // 数据
|
273
|
|
- List<TempBill> tempBills = Lists.newArrayList();
|
274
|
|
-
|
275
|
306
|
// 从第7行开始读取
|
276
|
307
|
for (int i= 6; i<= lastRowNum; i++) {
|
277
|
308
|
Row row = sheetAt.getRow(i);
|
|
@@ -322,7 +353,7 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements IB
|
322
|
353
|
|
323
|
354
|
|
324
|
355
|
if (StringUtils.isNotBlank(money)) {
|
325
|
|
- Double moneyDouble = Double.valueOf(money) * 100;
|
|
356
|
+ Double moneyDouble = Double.valueOf(money); // * 100
|
326
|
357
|
money = moneyDouble + "";
|
327
|
358
|
money = money.substring(0, money.lastIndexOf("."));
|
328
|
359
|
temp.setMoney(Integer.valueOf(money));
|