|
@@ -2,6 +2,7 @@ package cn.com.ty.lift.business.contract.service;
|
|
|
|
|
|
import cn.com.ty.lift.business.contract.dao.entity.Contracts;
|
|
import cn.com.ty.lift.business.contract.dao.entity.Contracts;
|
|
import cn.com.ty.lift.business.contract.dao.entity.Payment;
|
|
import cn.com.ty.lift.business.contract.dao.entity.Payment;
|
|
|
|
+import cn.com.ty.lift.business.contract.dao.entity.PaymentHistory;
|
|
import cn.com.ty.lift.business.contract.dao.entity.model.request.PaymentRequest;
|
|
import cn.com.ty.lift.business.contract.dao.entity.model.request.PaymentRequest;
|
|
import cn.com.ty.lift.business.contract.dao.entity.model.response.PaymentDetailResponse;
|
|
import cn.com.ty.lift.business.contract.dao.entity.model.response.PaymentDetailResponse;
|
|
import cn.com.ty.lift.business.contract.dao.entity.model.response.PaymentListResponse;
|
|
import cn.com.ty.lift.business.contract.dao.entity.model.response.PaymentListResponse;
|
|
@@ -11,6 +12,7 @@ import cn.com.ty.lift.business.framework.util.MessageUtils;
|
|
import cn.com.ty.lift.common.utils.DateUtils;
|
|
import cn.com.ty.lift.common.utils.DateUtils;
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.collection.IterUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -18,6 +20,8 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.time.LocalDateTime;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -29,6 +33,9 @@ import java.util.stream.Collectors;
|
|
@Service
|
|
@Service
|
|
public class PaymentService extends ServiceImpl<PaymentMapper, Payment> {
|
|
public class PaymentService extends ServiceImpl<PaymentMapper, Payment> {
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private PaymentHistoryService paymentHistoryService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param request 付款列表查询条件
|
|
* @param request 付款列表查询条件
|
|
* @return RestResponse 付款分页列表结果
|
|
* @return RestResponse 付款分页列表结果
|
|
@@ -99,6 +106,10 @@ public class PaymentService extends ServiceImpl<PaymentMapper, Payment> {
|
|
return saveBatch(payments);
|
|
return saveBatch(payments);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private String formatPaymentContent(Payment payment){
|
|
|
|
+ return String.format("应收:%.2f, 实收:%.2f, 开票:%.2f", payment.getPlanMoney(), payment.getWorkMoney(), payment.getAmountInvoice());
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param oldPaymentList 原有付款列表
|
|
* @param oldPaymentList 原有付款列表
|
|
* @param paymentList 修改的付款列表
|
|
* @param paymentList 修改的付款列表
|
|
@@ -109,17 +120,47 @@ public class PaymentService extends ServiceImpl<PaymentMapper, Payment> {
|
|
public RestResponse modifyPayment(Collection<Payment> oldPaymentList, List<Payment> paymentList) {
|
|
public RestResponse modifyPayment(Collection<Payment> oldPaymentList, List<Payment> paymentList) {
|
|
List<Payment> updateList = new ArrayList<>();
|
|
List<Payment> updateList = new ArrayList<>();
|
|
List<Payment> deleteList = new ArrayList<>();
|
|
List<Payment> deleteList = new ArrayList<>();
|
|
|
|
+ List<PaymentHistory> histories = new ArrayList<>();
|
|
//新增付款项
|
|
//新增付款项
|
|
List<Payment> insertList = paymentList.stream().filter(entry -> Objects.isNull(entry.getId())).collect(Collectors.toList());
|
|
List<Payment> insertList = paymentList.stream().filter(entry -> Objects.isNull(entry.getId())).collect(Collectors.toList());
|
|
|
|
+ if (IterUtil.isNotEmpty(insertList)) {
|
|
|
|
+ for (Payment payment : insertList) {
|
|
|
|
+ PaymentHistory history = new PaymentHistory();
|
|
|
|
+ history.setContractsId(payment.getContractsId());
|
|
|
|
+ history.setDescription("新增收款项");
|
|
|
|
+ history.setBeforeContent("--");
|
|
|
|
+ String afterContent = formatPaymentContent(payment);
|
|
|
|
+ history.setAfterContent(afterContent);
|
|
|
|
+ history.setOperatorId(payment.getUpdateId());
|
|
|
|
+ history.setOperateDate(LocalDateTime.now());
|
|
|
|
+ histories.add(history);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
if (CollUtil.isEmpty(oldPaymentList)) {
|
|
if (CollUtil.isEmpty(oldPaymentList)) {
|
|
updateList.addAll(paymentList);
|
|
updateList.addAll(paymentList);
|
|
} else {
|
|
} else {
|
|
//比较原有收款项
|
|
//比较原有收款项
|
|
for (Payment payment : oldPaymentList) {
|
|
for (Payment payment : oldPaymentList) {
|
|
|
|
+ PaymentHistory history = new PaymentHistory();
|
|
|
|
+ history.setContractsId(payment.getContractsId());
|
|
|
|
+ String before = formatPaymentContent(payment);
|
|
|
|
+ history.setBeforeContent(before);
|
|
|
|
+ history.setOperatorId(payment.getUpdateId());
|
|
|
|
+ history.setOperateDate(LocalDateTime.now());
|
|
Optional<Payment> newPayment = paymentList.stream().filter(entry -> payment.getId().equals(entry.getId())).findFirst();
|
|
Optional<Payment> newPayment = paymentList.stream().filter(entry -> payment.getId().equals(entry.getId())).findFirst();
|
|
if (newPayment.isPresent()) {
|
|
if (newPayment.isPresent()) {
|
|
- updateList.add(newPayment.get());
|
|
|
|
|
|
+ history.setDescription("修改收费项");
|
|
|
|
+ Payment p = newPayment.get();
|
|
|
|
+ String after = formatPaymentContent(p);
|
|
|
|
+ if (!Objects.equals(before, after)) {
|
|
|
|
+ history.setAfterContent(after);
|
|
|
|
+ histories.add(history);
|
|
|
|
+ updateList.add(p);
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
|
|
+ history.setDescription("删除付款项");
|
|
|
|
+ history.setAfterContent("--");
|
|
|
|
+ histories.add(history);
|
|
deleteList.add(payment);
|
|
deleteList.add(payment);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -142,6 +183,11 @@ public class PaymentService extends ServiceImpl<PaymentMapper, Payment> {
|
|
return RestResponse.fail(MessageUtils.get("msg.add.batch.fail"));
|
|
return RestResponse.fail(MessageUtils.get("msg.add.batch.fail"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ boolean history = paymentHistoryService.saveBatch(histories, histories.size());
|
|
|
|
+ if (!history) {
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ return RestResponse.fail("插入付款操作记录失败");
|
|
|
|
+ }
|
|
return RestResponse.success(null, MessageUtils.get("msg.modify.success"));
|
|
return RestResponse.success(null, MessageUtils.get("msg.modify.success"));
|
|
}
|
|
}
|
|
|
|
|