|
|
@@ -0,0 +1,129 @@
|
|
|
+package org.springblade.salesPart.duoduo.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tenant.annotation.TenantIgnore;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.DateUtil;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.salesPart.cnauto.AppTenant;
|
|
|
+import org.springblade.salesPart.cnauto.CnAutoMall;
|
|
|
+import org.springblade.salesPart.duoduo.mapper.AppTenantMapper;
|
|
|
+import org.springblade.salesPart.duoduo.service.IAppTenantService;
|
|
|
+import org.springblade.salesPart.funding.entity.PjpfBalanceReset;
|
|
|
+import org.springblade.salesPart.funding.entity.PjpfFunding;
|
|
|
+import org.springblade.salesPart.funding.entity.PjpfFundingItem;
|
|
|
+import org.springblade.salesPart.funding.mapper.PjpfBalanceResetMapper;
|
|
|
+import org.springblade.salesPart.funding.mapper.PjpfFundingItemMapper;
|
|
|
+import org.springblade.salesPart.funding.mapper.PjpfFundingMapper;
|
|
|
+import org.springblade.salesPart.funding.service.IPjpfBalanceResetService;
|
|
|
+import org.springblade.system.entity.Tenant;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Rain
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class AppTenantServiceImpl extends ServiceImpl<AppTenantMapper, AppTenant> implements IAppTenantService {
|
|
|
+
|
|
|
+
|
|
|
+ private final PjpfBalanceResetMapper pjpfBalanceResetMapper;
|
|
|
+
|
|
|
+ private final ISysClient sysClient;
|
|
|
+
|
|
|
+ private final AppTenantMapper appTenantMapper;
|
|
|
+
|
|
|
+ private final PjpfFundingMapper pjpfFundingMapper;
|
|
|
+
|
|
|
+ private final PjpfFundingItemMapper pjpfFundingItemMapper;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @TenantIgnore
|
|
|
+ public R<String> customerRechargeMsg(CnAutoMall cnAutoMallVo) {
|
|
|
+ AppTenant appTenant = appTenantMapper.selectOne(new LambdaQueryWrapper<AppTenant>()
|
|
|
+ .eq(AppTenant::getAppId, cnAutoMallVo.getAppId()).eq(AppTenant::getIsDelete, 0)
|
|
|
+ .orderByDesc(AppTenant::getCreateDate).last(" limit 1"));
|
|
|
+ if (ObjectUtils.isEmpty(appTenant)) {
|
|
|
+ return R.fail("appId不存在, 请联系相关人员添加");
|
|
|
+ }
|
|
|
+ R<Tenant> tenant = sysClient.getTenant(appTenant.getTenantId());
|
|
|
+ if (!tenant.isSuccess() || ObjectUtil.isEmpty(tenant.getData())) {
|
|
|
+ return R.fail("该客户未在轮胎商城注册,请联系相关人员");
|
|
|
+ }
|
|
|
+ if (BigDecimal.ZERO.compareTo(cnAutoMallVo.getAmount()) >= 0) {
|
|
|
+ return R.fail("充值金额不能小于等于0");
|
|
|
+ }
|
|
|
+ Date nowDate = DateUtil.now();
|
|
|
+ PjpfBalanceReset pjpfBalanceReset = new PjpfBalanceReset();
|
|
|
+ pjpfBalanceReset.setDate(nowDate);
|
|
|
+ pjpfBalanceReset.setSysNo("CZ" + DateUtil.format(pjpfBalanceReset.getDate(), DateUtil.PATTERN_DATETIME));
|
|
|
+ pjpfBalanceReset.setAmount(cnAutoMallVo.getAmount());
|
|
|
+ pjpfBalanceReset.setBusinessDate(cnAutoMallVo.getBusinessDate());
|
|
|
+ pjpfBalanceReset.setTenantId(appTenant.getTenantId());
|
|
|
+ pjpfBalanceReset.setCreateUser(1721359277215502338L);
|
|
|
+ pjpfBalanceReset.setUpdateUser(1721359277215502338L);
|
|
|
+ pjpfBalanceReset.setCreateTime(nowDate);
|
|
|
+ pjpfBalanceReset.setUpdateTime(nowDate);
|
|
|
+ pjpfBalanceReset.setConfirmingPersonDate(nowDate);
|
|
|
+ pjpfBalanceReset.setConfirmingPersonId(1721359277215502338L);
|
|
|
+ pjpfBalanceReset.setConfirmingPersonName("系统自动确认");
|
|
|
+ pjpfBalanceReset.setStatus(1);
|
|
|
+ int insertCount = pjpfBalanceResetMapper.insert(pjpfBalanceReset);
|
|
|
+ if (insertCount <= 0) {
|
|
|
+ return R.fail("充值预付款失败,请联系相关人员");
|
|
|
+ }
|
|
|
+ PjpfFunding funding = pjpfFundingMapper.selectOne(new LambdaQueryWrapper<PjpfFunding>()
|
|
|
+ .eq(PjpfFunding::getTenantId, appTenant.getTenantId()).eq(PjpfFunding::getIsDeleted, 0)
|
|
|
+ .orderByDesc(PjpfFunding::getCreateTime).last(" limit 1"));
|
|
|
+ if (ObjectUtils.isEmpty(funding)) {
|
|
|
+ throw new NullPointerException("该客户没有融资账户,请联系相关人员排查");
|
|
|
+ }
|
|
|
+ PjpfFundingItem fundingItem = new PjpfFundingItem();
|
|
|
+ fundingItem.setPid(funding.getId());
|
|
|
+ fundingItem.setTenantId(appTenant.getTenantId());
|
|
|
+ fundingItem.setCreateTime(new Date());
|
|
|
+ fundingItem.setCreateUser(1721359277215502338L);
|
|
|
+ fundingItem.setCreateUserName("系统充值");
|
|
|
+ fundingItem.setCreateDept(1123598813738675201L);
|
|
|
+ fundingItem.setCreateDeptName("接口充值");
|
|
|
+ fundingItem.setType("充值");
|
|
|
+ fundingItem.setSrcId(pjpfBalanceReset.getId());
|
|
|
+ fundingItem.setSrcNo(pjpfBalanceReset.getSysNo());
|
|
|
+ fundingItem.setAmount(pjpfBalanceReset.getAmount());
|
|
|
+ pjpfFundingItemMapper.insert(fundingItem);
|
|
|
+ if (funding.getBondAmount().compareTo(funding.getPaidAlreadyBondAmount()) > 0) {
|
|
|
+ BigDecimal amountSub = funding.getBondAmount().subtract(funding.getPaidAlreadyBondAmount());
|
|
|
+ if (pjpfBalanceReset.getAmount().compareTo(amountSub) > 0) {
|
|
|
+ BigDecimal amount = pjpfBalanceReset.getAmount().subtract(amountSub);
|
|
|
+ funding.setPaidAlreadyBondAmount(funding.getBondAmount());
|
|
|
+ funding.setAvailableAmount(funding.getAvailableAmount().add(amount));
|
|
|
+ } else if (pjpfBalanceReset.getAmount().compareTo(amountSub) == 0) {
|
|
|
+ funding.setPaidAlreadyBondAmount(funding.getBondAmount());
|
|
|
+ } else if (pjpfBalanceReset.getAmount().compareTo(amountSub) < 0) {
|
|
|
+ BigDecimal amount = amountSub.subtract(pjpfBalanceReset.getAmount());
|
|
|
+ funding.setPaidAlreadyBondAmount(funding.getPaidAlreadyBondAmount().add(amount));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ funding.setAvailableAmount(funding.getAvailableAmount().add(pjpfBalanceReset.getAmount()));
|
|
|
+ }
|
|
|
+ funding.setUpdateTime(nowDate);
|
|
|
+ funding.setUpdateUser(1721359277215502338L);
|
|
|
+ funding.setUpdateUserName("系统充值");
|
|
|
+ pjpfFundingMapper.updateById(funding);
|
|
|
+ return R.success("充值成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|