修改导入数据
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package com.zmzm.finance.common.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zmzm.finance.common.entity.Import;
|
||||
import com.zmzm.finance.common.entity.Payment;
|
||||
import com.zmzm.finance.common.service.IImportService;
|
||||
import com.zmzm.finance.common.service.IPaymentService;
|
||||
import com.zmzm.finance.util.ExcelUtil;
|
||||
import com.zmzm.finance.util.FileUtil;
|
||||
import com.zmzm.finance.util.R;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -31,11 +34,38 @@ public class PaymentController {
|
||||
|
||||
@Autowired
|
||||
private IPaymentService paymentService;
|
||||
@Autowired
|
||||
private IImportService importService;
|
||||
|
||||
//导入数据
|
||||
@RequestMapping("/importData")
|
||||
@Transactional
|
||||
public R importData(@RequestParam("file") MultipartFile file) {
|
||||
public R importData(@RequestParam("file") MultipartFile file,@RequestParam("type") int type,
|
||||
@RequestParam("year") int year,@RequestParam("month") int month) {
|
||||
//删除之前上的的数据
|
||||
Import imp = importService.getOne(new LambdaQueryWrapper<Import>()
|
||||
.eq(Import::getYear, year).eq(Import::getMonth, month));
|
||||
if(imp != null){
|
||||
List<Payment> oldPayments = paymentService.list(new LambdaQueryWrapper<Payment>()
|
||||
.eq(Payment::getImportId,imp.getId()).eq(Payment::getType, type));
|
||||
paymentService.removeBatchByIds(oldPayments);
|
||||
}else {
|
||||
imp = new Import();
|
||||
imp.setYear(year);
|
||||
imp.setMonth(month);
|
||||
}
|
||||
//上传文件
|
||||
FileUtil fileUtil = new FileUtil();
|
||||
String url = fileUtil.uploadFile(file);
|
||||
if(0==type){
|
||||
imp.setWechatFile(url);
|
||||
}else if(1==type){
|
||||
imp.setAlipayFile(url);
|
||||
}else if(2==type){
|
||||
imp.setBankFile(url);
|
||||
}
|
||||
importService.saveOrUpdate(imp);
|
||||
//导入新数据
|
||||
int num = 0;
|
||||
try (InputStream fis = file.getInputStream()) {
|
||||
//解析数据
|
||||
@@ -55,7 +85,8 @@ public class PaymentController {
|
||||
}
|
||||
for (int i=2;i<=count;i++){
|
||||
Payment payment = new Payment();
|
||||
payment.setType(map.containsKey("A"+i)?Byte.valueOf(map.get("A"+i)):0);
|
||||
payment.setImportId(imp.getId());
|
||||
payment.setType(map.containsKey("A"+i)?Integer.valueOf(map.get("A"+i)):0);
|
||||
payment.setFinanceSn(map.getOrDefault("B" + i, ""));
|
||||
payment.setTransactionSn(map.getOrDefault("C" + i, ""));
|
||||
payment.setRelationSn(map.getOrDefault("D" + i, ""));
|
||||
@@ -71,7 +102,7 @@ public class PaymentController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return R.error("金额、时间不能为空"+e.getMessage());
|
||||
return R.error(e.getMessage());
|
||||
}
|
||||
return R.ok("导入成功"+num+"条");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user