|
@@ -0,0 +1,129 @@
|
|
|
+package com.fire.admin.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fire.admin.dto.AdditionalPaymentDto;
|
|
|
+import com.fire.admin.mapper.AdditionalPaymentMapper;
|
|
|
+import com.fire.admin.service.AdditionalPaymentService;
|
|
|
+import com.fire.admin.util.AliyunOSSUtil;
|
|
|
+import com.fire.admin.util.SecurityUtil;
|
|
|
+import com.fire.admin.vo.AdditionalPaymentVo;
|
|
|
+import com.fire.common.exception.BaseException;
|
|
|
+import com.fire.common.redis.RedisAmountScript;
|
|
|
+import com.fire.dto.AdditionalPayment;
|
|
|
+import com.fire.dto.enums.Status;
|
|
|
+import com.fire.utils.date.DateUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+
|
|
|
+import static com.fire.dto.enums.RedisKey.CUSTOMER_AMOUNT;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: liuliu
|
|
|
+ * @ClassName: AdditionalPaymentServiceImpl
|
|
|
+ * @Description: TODO
|
|
|
+ * @date: 2021-06-04 15:21
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class AdditionalPaymentServiceImpl extends ServiceImpl<AdditionalPaymentMapper, AdditionalPayment> implements AdditionalPaymentService {
|
|
|
+
|
|
|
+ private AliyunOSSUtil aliyunOSSUtil;
|
|
|
+ private RedisAmountScript redisAmountScript;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public AdditionalPaymentServiceImpl(AliyunOSSUtil aliyunOSSUtil, RedisAmountScript redisAmountScript) {
|
|
|
+ this.aliyunOSSUtil = aliyunOSSUtil;
|
|
|
+ this.redisAmountScript = redisAmountScript;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: TODO 新增加款记录
|
|
|
+ * @Param: [additionalPaymentDto]
|
|
|
+ * @return: void
|
|
|
+ * @Author: liuliu
|
|
|
+ * @Date: 2021/6/4 15:28
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void insertAdditionalPaymen(AdditionalPaymentDto additionalPaymentDto) {
|
|
|
+ if (additionalPaymentDto.getType().equals("customer")) {
|
|
|
+ additionalPaymentDto.setDistinguish(2);
|
|
|
+ // TODO 客户加款
|
|
|
+ int count = this.additionalPayment(additionalPaymentDto);
|
|
|
+ if (count > 0) {
|
|
|
+ // TODO 加款成功之后,把加款的金额写入数据库
|
|
|
+ redisAmountScript.changeAmount(CUSTOMER_AMOUNT.key(), Long.getLong(additionalPaymentDto.getRelationId()), "add", additionalPaymentDto.getAmount().multiply(new BigDecimal(10000)).intValue(), 0L);
|
|
|
+ }
|
|
|
+ } else if (additionalPaymentDto.getType().equals("suppler")) {
|
|
|
+ additionalPaymentDto.setDistinguish(1);
|
|
|
+ // TODO 供应商加款
|
|
|
+ this.additionalPayment(additionalPaymentDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: TODO 客户和供应商加款共用和方法
|
|
|
+ * @Param: [additionalPaymentDto]
|
|
|
+ * @return: void
|
|
|
+ * @Author: liuliu
|
|
|
+ * @Date: 2021/6/7 16:12
|
|
|
+ */
|
|
|
+ private int additionalPayment(AdditionalPaymentDto additionalPaymentDto) {
|
|
|
+ if (ObjectUtil.isNotEmpty(additionalPaymentDto.getType()) && ObjectUtil.isNotEmpty(additionalPaymentDto.getRelationId())) {
|
|
|
+ AdditionalPayment payment = new AdditionalPayment();
|
|
|
+ BeanUtil.copyProperties(additionalPaymentDto, payment);
|
|
|
+ payment.setTime(DateUtils.strformatDatetime(LocalDateTime.now()));
|
|
|
+ payment.setPayer(SecurityUtil.getUser().getUsername());
|
|
|
+ return baseMapper.insert(payment);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // TODO 请求参数不合法抛异常
|
|
|
+ throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: TODO 分页获取客户加款信息
|
|
|
+ * @Param: [additionalPaymentDto]
|
|
|
+ * @return: com.baomidou.mybatisplus.core.metadata.IPage<com.fire.admin.vo.AdditionalPaymentVo>
|
|
|
+ * @Author: liuliu
|
|
|
+ * @Date: 2021/6/7 14:28
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<AdditionalPaymentVo> getAdditionalPaymentPage(AdditionalPaymentDto additionalPaymentDto) {
|
|
|
+
|
|
|
+ Page page = new Page();
|
|
|
+ // TODO 对前端的页码 以及每页显示的数量进行处理
|
|
|
+ if (ObjectUtil.isNotEmpty(additionalPaymentDto.getCurrent()) && ObjectUtil.isNotEmpty(additionalPaymentDto.getSize())) {
|
|
|
+ page.setSize(additionalPaymentDto.getSize());
|
|
|
+ page.setCurrent(additionalPaymentDto.getCurrent());
|
|
|
+ }
|
|
|
+
|
|
|
+ return baseMapper.selectAddiPayCustomerPageInfo(page, additionalPaymentDto);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: TODO 修改客户加款信息
|
|
|
+ * @Param: [additionalPaymentDto]
|
|
|
+ * @return: void
|
|
|
+ * @Author: liuliu
|
|
|
+ * @Date: 2021/6/7 16:48
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updAdditionPayment(AdditionalPaymentDto additionalPaymentDto) {
|
|
|
+
|
|
|
+ AdditionalPayment payment = AdditionalPayment.builder().id(additionalPaymentDto.getId()).certificate(additionalPaymentDto.getCertificate()).build();
|
|
|
+ baseMapper.updateById(payment);
|
|
|
+ }
|
|
|
+}
|