SysDeptAccountWithdrawServiceImpl.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package com.ydtech.modules.admin.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.ydtech.constants.sys.SysDeptAccountStatus;
  7. import com.ydtech.core.page.HttpResult;
  8. import com.ydtech.core.page.PageRequest;
  9. import com.ydtech.exception.SystemException;
  10. import com.ydtech.modules.admin.dao.SysDeptAccountWithdrawMapper;
  11. import com.ydtech.modules.admin.model.SysDeptAccount;
  12. import com.ydtech.modules.admin.model.SysDeptAccountHistory;
  13. import com.ydtech.modules.admin.model.SysDeptAccountWithdraw;
  14. import com.ydtech.modules.admin.model.po.SysAmountAuditingDeptHistory;
  15. import com.ydtech.modules.admin.model.vo.SysDeptAccountWithdrawVo;
  16. import com.ydtech.modules.admin.service.SysAmountAuditingDeptHistoryService;
  17. import com.ydtech.modules.admin.service.SysDeptAccountHistoryService;
  18. import com.ydtech.modules.admin.service.SysDeptAccountService;
  19. import com.ydtech.modules.admin.service.SysDeptAccountWithdrawService;
  20. import com.ydtech.modules.base.controller.BaseController;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.transaction.annotation.Transactional;
  24. import java.math.BigDecimal;
  25. import java.util.Date;
  26. @Service
  27. public class SysDeptAccountWithdrawServiceImpl extends ServiceImpl<SysDeptAccountWithdrawMapper, SysDeptAccountWithdraw> implements SysDeptAccountWithdrawService {
  28. @Autowired
  29. private SysDeptAccountWithdrawMapper sysDeptAccountWithdrawMapper;
  30. @Autowired
  31. private SysDeptAccountWithdrawService sysDeptAccountWithdrawService;
  32. @Autowired
  33. private SysDeptAccountService sysDeptAccountService;
  34. @Autowired
  35. private SysDeptAccountHistoryService sysDeptAccountHistoryService;
  36. @Autowired
  37. private SysAmountAuditingDeptHistoryService sysAmountAuditingDeptHistoryService;
  38. @Override
  39. public IPage<SysDeptAccountWithdraw> getList(SysDeptAccountWithdrawVo sysDeptAccountWithdrawVo) {
  40. PageRequest pageRequest = new PageRequest();
  41. pageRequest.setPageNum(sysDeptAccountWithdrawVo.getPageNo());
  42. pageRequest.setPageSize(sysDeptAccountWithdrawVo.getPageSize());
  43. Page page = PageRequest.buildPageRequest(pageRequest);
  44. Page<SysDeptAccountWithdraw> iPage = sysDeptAccountWithdrawMapper.selectSysDeptAccountWithdraw(page,sysDeptAccountWithdrawVo);
  45. return iPage;
  46. }
  47. @Override
  48. @Transactional
  49. public HttpResult updateByStatus(SysDeptAccountWithdraw sysDeptAccountWithdraw) {
  50. try{
  51. //查询账户表金额
  52. SysDeptAccount sysDeptAccount = sysDeptAccountService.getById(sysDeptAccountWithdraw.getDeptId());
  53. sysDeptAccountWithdraw.setVoucherId(sysDeptAccountWithdraw.getVoucherId());
  54. sysDeptAccountWithdraw.setAuditUserid(BaseController.getUser().getId());
  55. sysDeptAccountWithdraw.setAuditName(BaseController.getUser().getName());
  56. BigDecimal afterAmount = BigDecimal.ZERO;
  57. // add by hxl 2024 -07-05 插入审核时间
  58. sysDeptAccountWithdraw.setAuditingTime(new Date());
  59. String auditingStatus="";
  60. if (sysDeptAccountWithdraw.getStatus().equals(SysDeptAccountStatus.PASS.getCode())) {
  61. //sysDeptAccount.setManagementFee(sysDeptAccount.getManagementFee());
  62. //sysDeptAccountService.updateById(sysDeptAccount);
  63. //已到账金额 = 原先的到账金额+ 已到账的金额
  64. sysDeptAccount.setSumAmountAccount((sysDeptAccount.getSumAmountAccount()==null? BigDecimal.ZERO:sysDeptAccount.getSumAmountAccount()).add(sysDeptAccountWithdraw.getAmount()));
  65. //支付中的金额 = 原先的支付金额 -去提现的金额
  66. sysDeptAccount.setSumAmountPayment((sysDeptAccount.getSumAmountPayment()==null?BigDecimal.ZERO:sysDeptAccount.getSumAmountPayment()).subtract(sysDeptAccountWithdraw.getAmount()));
  67. auditingStatus="4";
  68. }
  69. if (sysDeptAccountWithdraw.getStatus().equals(SysDeptAccountStatus.REJECT.getCode())) {
  70. //驳回,将金额退回
  71. //提现前的金额
  72. BigDecimal beforeAmount = sysDeptAccount.getManagementFee()==null?BigDecimal.ZERO:sysDeptAccount.getManagementFee();
  73. //提现后的金额
  74. afterAmount = beforeAmount.add(sysDeptAccountWithdraw.getAmount());
  75. sysDeptAccount.setManagementFee(afterAmount);
  76. //提现的总金额 = 原先的提现总金额 - 提现的金额
  77. sysDeptAccount.setSumAmountWithdrawal((sysDeptAccount.getSumAmountWithdrawal()==null?BigDecimal.ZERO:sysDeptAccount.getSumAmountWithdrawal().subtract(sysDeptAccountWithdraw.getAmount())));
  78. //支付中的金额 = 原先的支付金额 -去提现的金额
  79. sysDeptAccount.setSumAmountPayment((sysDeptAccount.getSumAmountPayment()==null?BigDecimal.ZERO:sysDeptAccount.getSumAmountPayment()).subtract(sysDeptAccountWithdraw.getAmount()));
  80. auditingStatus="3";
  81. }
  82. sysDeptAccountWithdrawService.updateById(sysDeptAccountWithdraw);
  83. //通过审核表id查询历史记录表
  84. LambdaQueryWrapper<SysDeptAccountHistory> lqw = new LambdaQueryWrapper<>();
  85. lqw.eq(SysDeptAccountHistory::getAuditingId, sysDeptAccountWithdraw.getId());
  86. lqw.eq(SysDeptAccountHistory::getDeptId, sysDeptAccountWithdraw.getDeptId());
  87. //插入轨迹表审核成功数据
  88. SysDeptAccountHistory sysDeptAccountHistory = sysDeptAccountHistoryService.getBaseMapper().selectOne(lqw);
  89. //插入轨迹表
  90. SysAmountAuditingDeptHistory sysAmountAuditingDeptHistory =new SysAmountAuditingDeptHistory(sysDeptAccountWithdraw.getId(), sysDeptAccountWithdraw.getAmount(), sysDeptAccountWithdraw.getDeptId(),new Date(),auditingStatus, "1",sysDeptAccountHistory.getId());
  91. sysAmountAuditingDeptHistoryService.save(sysAmountAuditingDeptHistory);
  92. //跟新账户金额
  93. sysDeptAccountService.updateById(sysDeptAccount);
  94. //插入退款记录
  95. if("3".equals(auditingStatus)){
  96. //将收入支出状态台改为收入 2插入历史表中历史表
  97. sysDeptAccountHistory.setId(null);
  98. sysDeptAccountHistory.setDocumentary("2");
  99. sysDeptAccountHistory.setProperty(5);
  100. sysDeptAccountHistory.setBusinessSegmentsType(2);
  101. sysDeptAccountHistory.setCreateTime(new Date());
  102. sysDeptAccountHistory.setSurplusAmount(afterAmount);
  103. sysDeptAccountHistoryService.getBaseMapper().insert(sysDeptAccountHistory);
  104. }
  105. }catch(Exception e){
  106. throw new SystemException("提现错误");
  107. }
  108. return HttpResult.ok("审核完成",sysDeptAccountWithdraw);
  109. }
  110. }