导入平台流水
This commit is contained in:
@@ -1,7 +1,21 @@
|
||||
package com.zmzm.finance.common.controller;
|
||||
|
||||
import com.zmzm.finance.common.entity.Payment;
|
||||
import com.zmzm.finance.common.service.IPaymentService;
|
||||
import com.zmzm.finance.util.ExcelUtil;
|
||||
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;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -15,4 +29,50 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RequestMapping("/common/payment")
|
||||
public class PaymentController {
|
||||
|
||||
@Autowired
|
||||
private IPaymentService paymentService;
|
||||
|
||||
//导入数据
|
||||
@RequestMapping("/importData")
|
||||
@Transactional
|
||||
public R importData(@RequestParam("file") MultipartFile file) {
|
||||
int num = 0;
|
||||
try (InputStream fis = file.getInputStream()) {
|
||||
//解析数据
|
||||
ExcelUtil example = new ExcelUtil();
|
||||
example.processOneSheet(fis);
|
||||
LinkedHashMap<String, String> map = example.getRowContents();
|
||||
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
|
||||
//处理数据
|
||||
int count = 0;
|
||||
List<Payment> list = new ArrayList<>();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, String> entry = it.next();
|
||||
String pos = entry.getKey();
|
||||
String rowNo = pos.replaceAll("[a-zA-Z]", "");
|
||||
count = Integer.parseInt(rowNo);
|
||||
System.out.println(pos + ";" + entry.getValue());
|
||||
}
|
||||
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.setFinanceSn(map.getOrDefault("B" + i, ""));
|
||||
payment.setTransactionSn(map.getOrDefault("C" + i, ""));
|
||||
payment.setRelationSn(map.getOrDefault("D" + i, ""));
|
||||
payment.setFee(new BigDecimal(map.get("E" + i)));
|
||||
payment.setCtime(DateUtils.parseDate(map.get("F"+i), new String[]{"yyyy-MM-dd HH:mm:ss"}));
|
||||
payment.setPaymentName(map.getOrDefault("G" + i, ""));
|
||||
payment.setPaymentType(map.getOrDefault("H" + i, ""));
|
||||
payment.setRemark(map.getOrDefault("I" + i, ""));
|
||||
list.add(payment);
|
||||
num++;
|
||||
}
|
||||
paymentService.saveBatch(list);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return R.error("金额、时间不能为空"+e.getMessage());
|
||||
}
|
||||
return R.ok("导入成功"+num+"条");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -71,7 +70,7 @@ public class Payment implements Serializable {
|
||||
/**
|
||||
* 收款时间
|
||||
*/
|
||||
private LocalDateTime ctime;
|
||||
private Date ctime;
|
||||
|
||||
/**
|
||||
* 状态0初始1删除
|
||||
|
||||
Reference in New Issue
Block a user