diff --git a/src/main/java/com/zmzm/finance/common/controller/ImportController.java b/src/main/java/com/zmzm/finance/common/controller/ImportController.java
index a3009e1..5a14cc5 100644
--- a/src/main/java/com/zmzm/finance/common/controller/ImportController.java
+++ b/src/main/java/com/zmzm/finance/common/controller/ImportController.java
@@ -3,8 +3,10 @@ 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.entity.PaymentToOrder;
import com.zmzm.finance.common.service.IImportService;
import com.zmzm.finance.common.service.IPaymentService;
+import com.zmzm.finance.common.service.IPaymentToOrderService;
import com.zmzm.finance.util.ExcelUtil;
import com.zmzm.finance.util.FileUtil;
import com.zmzm.finance.util.R;
@@ -20,7 +22,11 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.time.YearMonth;
+import java.time.temporal.ChronoUnit;
import java.util.*;
+import java.util.stream.Collectors;
/**
*
@@ -38,10 +44,29 @@ public class ImportController {
private IImportService importService;
@Autowired
private IPaymentService paymentService;
+ @Autowired
+ private IPaymentToOrderService paymentToOrderService;
//导入文件列表
@RequestMapping("/getImportList")
public R getImportList(@RequestBody Map params){
+ Import alreadyImport = importService.getOne(new LambdaQueryWrapper()
+ .orderByDesc(Import::getYear,Import::getMonth).last("limit 1"));
+// if(alreadyImport == null){
+// alreadyImport = new Import();
+// alreadyImport.setYear(2022);
+// alreadyImport.setMonth(12);
+// importService.save(alreadyImport);
+// }
+// YearMonth startMonth = YearMonth.of(alreadyImport.getYear(),alreadyImport.getMonth());
+// YearMonth endMonth = YearMonth.now();
+// long difference = ChronoUnit.MONTHS.between(startMonth, endMonth);
+ if(alreadyImport == null){
+ Import import1 = new Import();
+ import1.setYear(LocalDateTime.now().getYear());
+ import1.setMonth(LocalDateTime.now().getMonthValue());
+ importService.save(import1);
+ }
List importList = importService.list(new LambdaQueryWrapper()
.eq(StringUtils.isNotEmpty(params.get("year").toString()),Import::getYear,params.get("year"))
.eq(StringUtils.isNotEmpty(params.get("month").toString()),Import::getMonth,params.get("month")));
@@ -57,9 +82,15 @@ public class ImportController {
Import imp = importService.getOne(new LambdaQueryWrapper()
.eq(Import::getYear, year).eq(Import::getMonth, month));
if(imp != null){
- List oldPayments = paymentService.list(new LambdaQueryWrapper()
- .eq(Payment::getImportId,imp.getId()).eq(Payment::getType, type));
- paymentService.removeBatchByIds(oldPayments);
+ List oldPaymentIds = paymentService.list(new LambdaQueryWrapper()
+ .eq(Payment::getImportId,imp.getId()).eq(Payment::getType, type))
+ .stream().map(Payment::getId).toList();
+ if (!oldPaymentIds.isEmpty()) {
+ List ptos = paymentToOrderService.list(new LambdaQueryWrapper()
+ .in(PaymentToOrder::getPaymentId,oldPaymentIds));
+ paymentService.removeBatchByIds(oldPaymentIds);
+ paymentToOrderService.removeByIds(ptos);
+ }
}else {
imp = new Import();
imp.setYear(year);
@@ -97,9 +128,9 @@ public class ImportController {
Payment payment = new Payment();
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, ""));
+ payment.setFinanceSn(map.getOrDefault("B" + i, "").replace("\t",""));
+ payment.setTransactionSn(map.getOrDefault("C" + i, "").replace("\t",""));
+ payment.setRelationSn(map.getOrDefault("D" + i, "").replace("\t",""));
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, ""));
diff --git a/src/main/java/com/zmzm/finance/common/controller/PaymentController.java b/src/main/java/com/zmzm/finance/common/controller/PaymentController.java
index f30536d..948b62c 100644
--- a/src/main/java/com/zmzm/finance/common/controller/PaymentController.java
+++ b/src/main/java/com/zmzm/finance/common/controller/PaymentController.java
@@ -1,24 +1,26 @@
package com.zmzm.finance.common.controller;
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
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.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.zmzm.finance.common.dao.TCurriculumCatalogueMapper;
+import com.zmzm.finance.common.entity.*;
+import com.zmzm.finance.common.service.*;
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.RequestBody;
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.*;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
/**
*
@@ -35,75 +37,134 @@ public class PaymentController {
@Autowired
private IPaymentService paymentService;
@Autowired
- private IImportService importService;
+ private IPaymentToOrderService paymentToOrderService;
+ @Autowired
+ private IOrdersService ordersService;
+ @Autowired
+ private ITCustomerTaihuClassService customerTaihuClassService;
+ @Autowired
+ private ITCurriculumCatalogueService curriculumCatalogueService;
+ @Autowired
+ private ITCommodityService commodityService;
- //导入数据
- @RequestMapping("/importData")
- @Transactional
- 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()
- .eq(Import::getYear, year).eq(Import::getMonth, month));
- if(imp != null){
- List oldPayments = paymentService.list(new LambdaQueryWrapper()
- .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()) {
- //解析数据
- ExcelUtil example = new ExcelUtil();
- example.processOneSheet(fis);
- LinkedHashMap map = example.getRowContents();
- Iterator> it = map.entrySet().iterator();
- //处理数据
- int count = 0;
- List list = new ArrayList<>();
- while (it.hasNext()) {
- Map.Entry 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.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, ""));
- 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+"条");
+ //账单列表
+ @RequestMapping("/getPaymentList")
+ public R getPaymentList(@RequestBody Map params){
+ Page paymentList = paymentService.page(new Page<>(Long.parseLong(params.get("page").toString()),
+ Long.parseLong(params.get("limit").toString())),new LambdaQueryWrapper()
+ .eq(params.containsKey("type")&&StringUtils.isNotEmpty(params.get("type").toString()),
+ Payment::getType,params.get("type").toString())
+ .eq(params.containsKey("checkoff")&&StringUtils.isNotEmpty(params.get("checkoff").toString()),
+ Payment::getCheckoff,params.get("checkoff").toString())
+ .apply(params.containsKey("year")&&StringUtils.isNotEmpty(params.get("year").toString()),
+ "DATE_FORMAT(ctime, '%Y') = '"+params.get("year").toString()+"'")
+ .apply(params.containsKey("month")&&StringUtils.isNotEmpty(params.get("month").toString()),
+ "DATE_FORMAT(ctime, '%m') = '"+params.get("month").toString()+"'")
+ .orderByDesc(Payment::getCtime));
+ return R.ok().put("data",paymentList);
}
+
+ //自动对账
+ @RequestMapping("/autoCheckoff")
+ @DSTransactional
+ public R autoCheckoff(@RequestBody Map params){
+ //先同步吴门医述订单
+ ordersService.importWumenOrder();
+ //查询自动核对失败的平台流水
+ List paymentList = paymentService.list(new MPJLambdaWrapper()
+ .leftJoin(Orders.class,on->on
+ .eq(Orders::getOrderSn,Payment::getRelationSn).eq(Orders::getState,0))
+ .disableSubLogicDel()
+ .selectAll(Payment.class)
+ .selectAs(Orders::getId,"ordersId")
+ .selectAs(Orders::getOrderSn,"ordersSn")
+ .ne(Payment::getCheckoff,2)
+ .apply(params.containsKey("year")&&StringUtils.isNotEmpty(params.get("year").toString()),
+ "DATE_FORMAT(t.ctime, '%Y') = '"+params.get("year").toString()+"'")
+ .apply(params.containsKey("month")&&StringUtils.isNotEmpty(params.get("month").toString()),
+ "DATE_FORMAT(t.ctime, '%m') = '"+params.get("month").toString()+"'"));
+ List ptos = new ArrayList<>();
+ List ps = new ArrayList<>();
+ //自动绑定
+ for (Payment payment : paymentList) {
+ if (StringUtils.isNotEmpty(payment.getRelationSn())&&
+ payment.getRelationSn().equals(payment.getOrdersSn())) {
+ PaymentToOrder pto = new PaymentToOrder();
+ pto.setPaymentId(payment.getId());
+ pto.setOrderId(payment.getOrdersId());
+ ptos.add(pto);
+ payment.setCheckoff(2);
+ }else {
+ payment.setCheckoff(1);
+ }
+ ps.add(payment);
+ }
+ paymentService.updateBatchById(ps);
+ paymentToOrderService.saveBatch(ptos);
+ return R.ok();
+ }
+
+ //手动对账订单列表
+ @RequestMapping("/manualList")
+ public R manualList(@RequestBody Map params){
+ Payment payment = paymentService.getById(params.get("paymentId").toString());
+ Page ordersList = ordersService.page(new Page<>(Long.parseLong(params.get("page").toString()),
+ Long.parseLong(params.get("limit").toString())), new LambdaQueryWrapper()
+ .notExists("select 1 from payment_to_order where order_id = orders.id and state = 0")
+ .eq(Orders::getFee, payment.getFee())
+ .ge(Orders::getOrderTime, DateUtils.addDays(payment.getCtime(),-1))
+ .le(Orders::getOrderTime, DateUtils.addDays(payment.getCtime(),3))
+ .orderByAsc(Orders::getOrderTime));
+ return R.ok().put("data",ordersList);
+ }
+
+ //手动对账确认
+ @RequestMapping("/manualCheckoff")
+ public R manualCheckoff(@RequestBody PaymentToOrder pto){
+ Payment payment = paymentService.getById(pto.getPaymentId());
+ payment.setCheckoff(2);
+ paymentService.updateById(payment);
+ paymentToOrderService.save(pto);
+ return R.ok();
+ }
+
+ //获取课程消费记录
+ @RequestMapping("/courseBuyList")
+ public R courseBuyList(@RequestBody Map params) {
+ Payment payment = paymentService.getById(params.get("paymentId").toString());
+ Page