package com.xzx.gc.order.service; import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import com.xzx.gc.common.constant.Constants; import com.xzx.gc.common.utils.BusinessUtil; import com.xzx.gc.entity.PartnerAccount; import com.xzx.gc.entity.PartnerAccountLog; import com.xzx.gc.order.mapper.PartnerAccountLogMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; @Service @Transactional @Slf4j public class PartnerAccountLogService { @Autowired private PartnerAccountLogMapper partnerAccountLogMapper; @Autowired private PartnerAccountService partnerAccountService; @Autowired private BusinessUtil businessUtil; public void add(PartnerAccountLog partnerAccountLog){ String now=DateUtil.now(); partnerAccountLog.setCreateTime(now); partnerAccountLog.setDelFlag(Constants.DEL_NOT_FLAG); partnerAccountLog.setUpdateTime(now); //未审核 partnerAccountLog.setApproverStatus("1"); PartnerAccount byAccount=partnerAccountLog.getPartnerAccount(); if(byAccount==null) { String accountId = partnerAccountLog.getAccountId(); if (StrUtil.isBlank(accountId)) { PartnerAccount byPartnerId = partnerAccountService.findByPartnerId(partnerAccountLog.getPartnerId()); if (byPartnerId != null) { partnerAccountLog.setAccountId(byPartnerId.getAccount()); } } if (StrUtil.isBlank(partnerAccountLog.getAccountId())) return; byAccount = partnerAccountService.findByAccount(partnerAccountLog.getAccountId()); } if(StrUtil.isNotBlank(partnerAccountLog.getMoney())) { partnerAccountLog.setAccountMoney(businessUtil.changeMoney(byAccount.getHbb())); BigDecimal add = NumberUtil.add(Convert.toBigDecimal(partnerAccountLog.getAccountMoney()), Convert.toBigDecimal(partnerAccountLog.getMoney())); partnerAccountLog.setHbb(businessUtil.changeMoney(add)); } if(StrUtil.isNotBlank(partnerAccountLog.getManageLimit())) { partnerAccountLog.setOldLimit(businessUtil.changeMoney(byAccount.getOverdraftLimit())); BigDecimal add = NumberUtil.add(Convert.toBigDecimal(partnerAccountLog.getOldLimit()), Convert.toBigDecimal(partnerAccountLog.getManageLimit())); partnerAccountLog.setNewLimit(businessUtil.changeMoney(add)); } if(StrUtil.isNotBlank(partnerAccountLog.getManageLimitFix())) { partnerAccountLog.setOldLimitFix(businessUtil.changeMoney(byAccount.getFixedLimit())); BigDecimal add = NumberUtil.add(Convert.toBigDecimal(partnerAccountLog.getOldLimitFix()), Convert.toBigDecimal(partnerAccountLog.getManageLimitFix())); partnerAccountLog.setNewLimitFix(businessUtil.changeMoney(add)); } partnerAccountLogMapper.insertSelective(partnerAccountLog); } /** * 根据类型和流水号查询 * @param type * @param flowNo * @return */ public PartnerAccountLog findByTypeAndFlow(String type,String flowNo){ PartnerAccountLog partnerAccount=new PartnerAccountLog(); partnerAccount.setType(type); partnerAccount.setFlowNo(flowNo); partnerAccount.setDelFlag(Constants.DEL_NOT_FLAG); PartnerAccountLog partnerAccount1 = partnerAccountLogMapper.selectOne(partnerAccount); return partnerAccount1; } }