PlatformAccountServiceImpl.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.kym.service.impl;
  2. import com.github.pagehelper.PageHelper;
  3. import com.kym.common.exception.BusinessException;
  4. import com.kym.entity.PlatformAccount;
  5. import com.kym.entity.common.PageBean;
  6. import com.kym.entity.queryParams.CommonQueryParam;
  7. import com.kym.mapper.PlatformAccountMapper;
  8. import com.kym.service.PlatformAccountService;
  9. import com.kym.service.mybatisplus.MyBaseServiceImpl;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Transactional;
  12. /**
  13. * 平台账户服务实现
  14. *
  15. * @author skyline
  16. * @since 2026-05-18
  17. */
  18. @Service
  19. public class PlatformAccountServiceImpl extends MyBaseServiceImpl<PlatformAccountMapper, PlatformAccount> implements PlatformAccountService {
  20. @Override
  21. public PlatformAccount getPlatformAccount() {
  22. var account = lambdaQuery().last("LIMIT 1").one();
  23. if (account == null) {
  24. account = new PlatformAccount();
  25. account.setTotalRevenue(0);
  26. account.setAvailableBalance(0);
  27. account.setWithdrawnFrozenAmount(0);
  28. account.setWithdrawnAmount(0);
  29. save(account);
  30. }
  31. return account;
  32. }
  33. @Override
  34. @Transactional(rollbackFor = Exception.class)
  35. public void addRevenue(int amount) {
  36. if (amount <= 0) {
  37. return;
  38. }
  39. boolean updated = lambdaUpdate()
  40. .setSql("total_revenue = total_revenue + {0}", amount)
  41. .setSql("available_balance = available_balance + {0}", amount)
  42. .eq(PlatformAccount::getId, getPlatformAccount().getId())
  43. .update();
  44. if (!updated) {
  45. throw new BusinessException("平台账户更新失败");
  46. }
  47. }
  48. @Override
  49. public PageBean<PlatformAccount> listPlatformAccounts(CommonQueryParam params) {
  50. PageHelper.startPage(params.getPageNum(), params.getPageSize());
  51. var list = lambdaQuery().list();
  52. return new PageBean<>(list);
  53. }
  54. }