SysDeptAccountServiceImpl.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package com.ydtech.modules.admin.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.ydtech.constants.sys.SysDeptAccountStatus;
  8. import com.ydtech.core.page.HttpResult;
  9. import com.ydtech.core.page.PageRequest;
  10. import com.ydtech.exception.SystemException;
  11. import com.ydtech.modules.admin.dao.SysDeptAccountMapper;
  12. import com.ydtech.modules.admin.model.SysDept;
  13. import com.ydtech.modules.admin.model.SysDeptAccount;
  14. import com.ydtech.modules.admin.model.SysDeptAccountHistory;
  15. import com.ydtech.modules.admin.model.SysDeptAccountWithdraw;
  16. import com.ydtech.modules.admin.model.dto.SysDeptAccountDto;
  17. import com.ydtech.modules.admin.model.po.SysAmountAuditingDeptHistory;
  18. import com.ydtech.modules.admin.model.vo.SysDeptAccountByUserVo;
  19. import com.ydtech.modules.admin.model.vo.SysDeptAccountVO;
  20. import com.ydtech.modules.admin.service.*;
  21. import com.ydtech.modules.base.controller.BaseController;
  22. import com.ydtech.modules.order.entity.BasePageResult;
  23. import com.ydtech.modules.protocol.utils.AssertionUtils;
  24. import com.ydtech.utils.idgen.IdGenerate;
  25. import org.springframework.beans.BeanUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import java.math.BigDecimal;
  30. import java.math.BigInteger;
  31. import java.time.LocalDateTime;
  32. import java.util.Date;
  33. import java.util.List;
  34. @Service
  35. public class SysDeptAccountServiceImpl extends ServiceImpl<SysDeptAccountMapper, SysDeptAccount> implements SysDeptAccountService {
  36. @Autowired
  37. private SysDeptAccountService sysDeptAccountService;
  38. @Autowired
  39. private SysDeptAccountHistoryService sysDeptAccountHistoryService;
  40. @Autowired
  41. private SysDeptAccountMapper sysDeptAccountMapper;
  42. @Autowired
  43. private SysDeptAccountWithdrawService sysDeptAccountWithdrawService;
  44. @Autowired
  45. private SysDeptService sysDeptService;
  46. @Autowired
  47. private SysUserInfoService sysUserInfoService;
  48. @Autowired
  49. private SysAmountAuditingDeptHistoryService sysAmountAuditingDeptHistoryService;
  50. @Override
  51. public BasePageResult<SysDeptAccount> queryByVo(SysDeptAccountVO sysDeptAccountVO) {
  52. Page<SysDeptAccount> page = new Page<>(sysDeptAccountVO.getPageNum(), sysDeptAccountVO.getPageSize());
  53. QueryWrapper<SysDeptAccount> wrapper = new QueryWrapper<>();
  54. Page<SysDeptAccount> sysUserAccountHistoryPage = page(page, wrapper);
  55. return new BasePageResult<>(sysDeptAccountVO.getPageNum(), page.getSize(), sysUserAccountHistoryPage.getTotal(), page.getPages(),
  56. sysUserAccountHistoryPage.getRecords());
  57. }
  58. public IPage<SysDeptAccountDto> getDept(SysDeptAccountDto sysDeptAccountDto) {
  59. PageRequest pageRequest = new PageRequest();
  60. pageRequest.setPageNum(sysDeptAccountDto.getPageNum());
  61. pageRequest.setPageSize(sysDeptAccountDto.getPageSize());
  62. Page page = PageRequest.buildPageRequest(pageRequest);
  63. Page<SysDeptAccountDto> deptList = sysDeptAccountMapper.getDept(page,sysDeptAccountDto);
  64. return deptList;
  65. }
  66. public List<SysDeptAccountByUserVo> getDeptAccountByUser() {
  67. List<SysDeptAccountByUserVo> deptAccountByUserList = sysDeptAccountMapper.getDeptAccountByUser(BaseController.getUser().getId());
  68. return deptAccountByUserList;
  69. }
  70. @Transactional
  71. public HttpResult withdrawDeptAccount(SysDeptAccount sysDeptAccount) {
  72. SysDeptAccount deptAccount = sysDeptAccountMapper.selectById(sysDeptAccount.getDeptId());
  73. //根据deptId查询提现人员相关信息
  74. LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
  75. queryWrapper.eq(SysDept::getId, sysDeptAccount.getDeptId());
  76. SysDept sysDept = sysDeptService.getOne(queryWrapper);
  77. if (sysDeptAccount.getAmount().compareTo(deptAccount.getManagementFee()) > 0) {
  78. throw new SystemException("提现金额大于机构账户金额");
  79. }
  80. if (sysDeptAccount.getAmount().equals(new BigDecimal(BigInteger.ZERO))) {
  81. throw new SystemException("提现金额不能为0");
  82. }
  83. BigDecimal accountAmount = deptAccount.getManagementFee().subtract(sysDeptAccount.getAmount());
  84. // 减去提现金额
  85. deptAccount.setManagementFee(accountAmount);
  86. //计算两个金额
  87. //支付中总金额 = 原先的支付金额 + 提现的金额
  88. deptAccount.setSumAmountPayment((deptAccount.getSumAmountPayment()==null?BigDecimal.ZERO:deptAccount.getSumAmountPayment()).add(sysDeptAccount.getAmount()));
  89. //提现的总金额 = 原先的提现总金额 + 提现的金额
  90. deptAccount.setSumAmountWithdrawal((deptAccount.getSumAmountWithdrawal()==null?BigDecimal.ZERO:deptAccount.getSumAmountWithdrawal().add(sysDeptAccount.getAmount())));
  91. sysDeptAccountService.updateById(deptAccount);
  92. // 生成提现审核数据
  93. SysDeptAccountWithdraw sysDeptAccountWithdraw = new SysDeptAccountWithdraw();
  94. sysDeptAccountWithdraw.setId(IdGenerate.nextId());
  95. sysDeptAccountWithdraw.setDeptId(deptAccount.getDeptId());
  96. sysDeptAccountWithdraw.setName(sysDept.getName());
  97. sysDeptAccountWithdraw.setAmount(sysDeptAccount.getAmount());
  98. sysDeptAccountWithdraw.setStatus(SysDeptAccountStatus.WAIT.getCode()); //待审核
  99. sysDeptAccountWithdraw.setRemark("");
  100. sysDeptAccountWithdraw.setWithdrawName(BaseController.getUser().getName());
  101. sysDeptAccountWithdraw.setWithdrawUserid(BaseController.getUser().getId());
  102. sysDeptAccountWithdraw.setCreateTime(LocalDateTime.now());
  103. sysDeptAccountWithdrawService.save(sysDeptAccountWithdraw);
  104. //插入机构历史表
  105. // 机构历史明细生成提现明细
  106. SysDeptAccountHistory sysDeptAccountHistory = new SysDeptAccountHistory();
  107. sysDeptAccountHistory.setId(IdGenerate.nextId());
  108. sysDeptAccountHistory.setDeptId(sysDeptAccount.getDeptId());
  109. sysDeptAccountHistory.setAmount(sysDeptAccountWithdraw.getAmount());
  110. sysDeptAccountHistory.setSurplusAmount(accountAmount);
  111. sysDeptAccountHistory.setSuborder(sysDeptAccountWithdraw.getId());
  112. sysDeptAccountHistory.setDocumentary("1");
  113. sysDeptAccountHistory.setProperty(6);
  114. sysDeptAccountHistory.setBusinessSegmentsType(1);
  115. sysDeptAccountHistory.setFromBankCard(null);
  116. sysDeptAccountHistory.setToBankCard(null);
  117. sysDeptAccountHistory.setUserId(BaseController.getUser().getId());
  118. sysDeptAccountHistory.setCreateTime(new Date());
  119. // add by hxl 2024 -07-05 插入审核表Id
  120. sysDeptAccountHistory.setAuditingId(sysDeptAccountWithdraw.getId());
  121. sysDeptAccountHistory.setRemark("从" + sysDeptAccountWithdraw.getName() + "机构账户中提现" + sysDeptAccountWithdraw.getAmount() + "元");
  122. sysDeptAccountHistoryService.save(sysDeptAccountHistory);
  123. // 提现审核插入轨迹表 待审核数据 和审核处理中的数据
  124. Date date = new Date();
  125. SysAmountAuditingDeptHistory sysAmountAuditingDeptHistory =new SysAmountAuditingDeptHistory(sysDeptAccountWithdraw.getId(), sysDeptAccountWithdraw.getAmount(), deptAccount.getDeptId(),date,"1", "1",sysDeptAccountHistory.getId());
  126. SysAmountAuditingDeptHistory sysAmountAuditingDeptHistoryTwo =new SysAmountAuditingDeptHistory(sysDeptAccountWithdraw.getId(), sysDeptAccountWithdraw.getAmount(), deptAccount.getDeptId(),date, "2", "1",sysDeptAccountHistory.getId());
  127. sysAmountAuditingDeptHistoryService.save(sysAmountAuditingDeptHistory);
  128. sysAmountAuditingDeptHistoryService.save(sysAmountAuditingDeptHistoryTwo);
  129. return HttpResult.ok("", sysDeptAccount);
  130. }
  131. @Override
  132. @Transactional
  133. public boolean inert(SysDeptAccountVO sysDeptAccountVO) {
  134. SysDeptAccount sysDeptAccount = new SysDeptAccount();
  135. BeanUtils.copyProperties(sysDeptAccountVO, sysDeptAccount);
  136. return super.save(sysDeptAccount);
  137. }
  138. @Override
  139. public void deleteSysUserBank(Long id) {
  140. boolean b = removeById(id);
  141. AssertionUtils.isSucceed(b, "删除失败");
  142. }
  143. @Override
  144. @Transactional
  145. public void uodate(SysDeptAccountVO sysDeptAccountVO) {
  146. SysDeptAccount sysDeptAccount = new SysDeptAccount();
  147. BeanUtils.copyProperties(sysDeptAccountVO, sysDeptAccount);
  148. super.updateById(sysDeptAccount);
  149. }
  150. }