|
@@ -1,6 +1,7 @@
|
|
|
package com.fire.admin.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -19,6 +20,7 @@ import com.fire.dto.CustomerInfo;
|
|
|
import com.fire.dto.enums.Status;
|
|
|
import com.fire.utils.date.DateUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.regexp.RE;
|
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.messaging.support.MessageBuilder;
|
|
@@ -27,6 +29,10 @@ import redis.clients.jedis.JedisCluster;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import static com.fire.common.constants.RocketTags.SUPPLIER_TAG;
|
|
|
import static com.fire.common.constants.RocketTopic.UPDATE_TOPIC;
|
|
@@ -201,13 +207,14 @@ public class AdditionalPaymentServiceImpl extends ServiceImpl<AdditionalPaymentM
|
|
|
@Override
|
|
|
public String cancelAdditionalPayment(AdditionalPaymentDto additionalPaymentDto) {
|
|
|
|
|
|
+ log.info("撤销参数为:【{}】", JSONUtil.parseObj(additionalPaymentDto));
|
|
|
AdditionalPayment payment = this.formatAdditionalPaymentDto(additionalPaymentDto);
|
|
|
// TODO 客户的撤销
|
|
|
if (ObjectUtil.isNotEmpty(additionalPaymentDto.getRelationId()) && additionalPaymentDto.getType().equals("customer")) {
|
|
|
payment.setUndo(1);
|
|
|
-
|
|
|
- AdditionalPayment additionalPayment = getAdditionalPaymentOne(additionalPaymentDto.getDistinguish(), additionalPaymentDto.getRelationId());
|
|
|
- if (!additionalPayment.getId().equals(payment.getId())) {
|
|
|
+ // TODO 获取该客户时间倒叙的第一条记录
|
|
|
+ AdditionalPayment additionalPayment = getAdditionalPaymentOne(additionalPaymentDto.getDistinguish(), additionalPaymentDto.getRelationId(), additionalPaymentDto.getId());
|
|
|
+ if (additionalPayment.getId().equals(payment.getId())) {
|
|
|
// TODO 获取客户授信金额
|
|
|
CustomerInfo customerInfo = customerService.getcustomerOne(Long.parseLong(payment.getRelationId()));
|
|
|
|
|
@@ -225,7 +232,7 @@ public class AdditionalPaymentServiceImpl extends ServiceImpl<AdditionalPaymentM
|
|
|
}
|
|
|
} else {
|
|
|
log.info("撤销失败,撤销不能撤销当前客户最近一次的加款记录。如果非要撤销请先加款一次再撤销本次记录");
|
|
|
- throw new BaseException("577", "客户账户撤销失败,不能撤销最近一次的记录");
|
|
|
+ throw new BaseException("577", "撤销失败");
|
|
|
}
|
|
|
|
|
|
} else if (ObjectUtil.isNotEmpty(additionalPaymentDto.getRelationId()) && additionalPaymentDto.getType().equals("supplier")) {
|
|
@@ -259,14 +266,41 @@ public class AdditionalPaymentServiceImpl extends ServiceImpl<AdditionalPaymentM
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private AdditionalPayment getAdditionalPaymentOne(Integer distinguish, String relationId) {
|
|
|
+ /**
|
|
|
+ * @descible: TODO 获取最近的一条记录条数
|
|
|
+ * @param: distinguish :1-供应商 2-客户
|
|
|
+ * @param: relationId : 客户或者供应商id
|
|
|
+ * @return: com.fire.dto.AdditionalPayment
|
|
|
+ * @author: liuliu
|
|
|
+ * @date: 2021-06-29 18:40
|
|
|
+ */
|
|
|
+ private AdditionalPayment getAdditionalPaymentOne(Integer distinguish, String relationId, Long id) {
|
|
|
+ // TODO 获取可以该客户或者供应商可以撤销的所有记录条数
|
|
|
LambdaQueryWrapper<AdditionalPayment> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.select(AdditionalPayment::getId, AdditionalPayment::getAmount)
|
|
|
- .eq(AdditionalPayment::getDistinguish, distinguish)
|
|
|
+ wrapper.eq(AdditionalPayment::getDistinguish, distinguish)
|
|
|
.eq(AdditionalPayment::getRelationId, relationId)
|
|
|
- .orderByDesc(AdditionalPayment::getTime);
|
|
|
- return baseMapper.selectList(wrapper).get(0);
|
|
|
+ .eq(AdditionalPayment::getUndo, 0);
|
|
|
+ Integer integer = baseMapper.selectCount(wrapper);
|
|
|
+ // TODO 记录条数大于1的情况下才可以执行撤销操作
|
|
|
+ if (integer > 1) {
|
|
|
+ String time = DateUtils.strformatDatetime(LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0).plusDays(-180));
|
|
|
+ List<AdditionalPayment> payments = baseMapper.selectAdditionalPaymentOne(distinguish, relationId, time);
|
|
|
+ // TODO 移除第一条记录
|
|
|
+ boolean flat = payments.remove(payments.get(0));
|
|
|
+ if(flat && !payments.isEmpty()){
|
|
|
+ // TODO 过滤接口传过来的账户id记录
|
|
|
+ List<AdditionalPayment> collect = payments.stream().filter(pay -> pay.getId().equals(id)).collect(Collectors.toList());
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
+ return collect.get(0);
|
|
|
+ }else {
|
|
|
+ throw new BaseException("577","账户撤销失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.info("只有一条账户记录的情况下不能撤销");
|
|
|
+ throw new BaseException("577", "撤销失败");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
}
|