| | |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.IUserAssetsServices; |
| | | import com.nq.utils.KeyUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | /** |
| | | * 用户资产 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class UserAssetsServices implements IUserAssetsServices { |
| | | |
| | |
| | | |
| | | @Override |
| | | public UserAssets assetsByTypeAndUserId(String accetType, Integer userId) { |
| | | if(accetType.equals("SZHB")){ |
| | | accetType = "US"; |
| | | } |
| | | QueryWrapper<UserAssets> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("accect_type",accetType); |
| | | queryWrapper.eq("user_id",userId); |
| | |
| | | |
| | | @Override |
| | | public BigDecimal getAvailableBalance(String accetType, Integer userId) { |
| | | if(accetType.equals("SZHB")){ |
| | | accetType = "US"; |
| | | } |
| | | return assetsByTypeAndUserId(accetType,userId).getAvailableBalance(); |
| | | } |
| | | |
| | |
| | | userAssets.setAmountToBeCovered(BigDecimal.ZERO); |
| | | userAssets.setHandlingChargeWritten(BigDecimal.ZERO); |
| | | }else{ |
| | | BigDecimal amountToBeCovered = userAssets.getAmountToBeCovered().subtract(amount); |
| | | userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(amount)); |
| | | userAssets.setAmountToBeCovered(amountToBeCovered); |
| | | BigDecimal subtract = amount.subtract(userAssets.getHandlingChargeWritten()); |
| | | if(subtract.compareTo(BigDecimal.ZERO) >= 0) { |
| | | BigDecimal decimal = amount.subtract(userAssets.getAmountToBeCovered()); |
| | | decimal = decimal.subtract(userAssets.getHandlingChargeWritten()); |
| | | userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(amount.subtract(userAssets.getHandlingChargeWritten()))); |
| | | userAssets.setHandlingChargeWritten(BigDecimal.ZERO); |
| | | userAssets.setAmountToBeCovered(decimal.negate()); |
| | | }else{ |
| | | userAssets.setHandlingChargeWritten(userAssets.getHandlingChargeWritten().subtract(amount)); |
| | | } |
| | | } |
| | | }else{ |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount)); |
| | |
| | | } |
| | | |
| | | if(null != userPosition){ |
| | | userPosition.setAmountToBeCovered(userAssets.getAmountToBeCovered()); |
| | | userPosition.setAmountToBeCovered(userAssets.getAmountToBeCovered().add(userAssets.getHandlingChargeWritten())); |
| | | userPositionMapper.updateById(userPosition); |
| | | } |
| | | String after = userAssets.getAvailableBalance().toString(); |