package com.ydtech.modules.admin.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ydtech.constants.sys.SysDeptAccountStatus; import com.ydtech.core.page.HttpResult; import com.ydtech.core.page.PageRequest; import com.ydtech.exception.SystemException; import com.ydtech.modules.admin.dao.SysDeptAccountWithdrawMapper; import com.ydtech.modules.admin.model.SysDeptAccount; import com.ydtech.modules.admin.model.SysDeptAccountHistory; import com.ydtech.modules.admin.model.SysDeptAccountWithdraw; import com.ydtech.modules.admin.model.po.SysAmountAuditingDeptHistory; import com.ydtech.modules.admin.model.vo.SysDeptAccountWithdrawVo; import com.ydtech.modules.admin.service.SysAmountAuditingDeptHistoryService; import com.ydtech.modules.admin.service.SysDeptAccountHistoryService; import com.ydtech.modules.admin.service.SysDeptAccountService; import com.ydtech.modules.admin.service.SysDeptAccountWithdrawService; import com.ydtech.modules.base.controller.BaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.Date; @Service public class SysDeptAccountWithdrawServiceImpl extends ServiceImpl implements SysDeptAccountWithdrawService { @Autowired private SysDeptAccountWithdrawMapper sysDeptAccountWithdrawMapper; @Autowired private SysDeptAccountWithdrawService sysDeptAccountWithdrawService; @Autowired private SysDeptAccountService sysDeptAccountService; @Autowired private SysDeptAccountHistoryService sysDeptAccountHistoryService; @Autowired private SysAmountAuditingDeptHistoryService sysAmountAuditingDeptHistoryService; @Override public IPage getList(SysDeptAccountWithdrawVo sysDeptAccountWithdrawVo) { PageRequest pageRequest = new PageRequest(); pageRequest.setPageNum(sysDeptAccountWithdrawVo.getPageNo()); pageRequest.setPageSize(sysDeptAccountWithdrawVo.getPageSize()); Page page = PageRequest.buildPageRequest(pageRequest); Page iPage = sysDeptAccountWithdrawMapper.selectSysDeptAccountWithdraw(page,sysDeptAccountWithdrawVo); return iPage; } @Override @Transactional public HttpResult updateByStatus(SysDeptAccountWithdraw sysDeptAccountWithdraw) { try{ //查询账户表金额 SysDeptAccount sysDeptAccount = sysDeptAccountService.getById(sysDeptAccountWithdraw.getDeptId()); sysDeptAccountWithdraw.setVoucherId(sysDeptAccountWithdraw.getVoucherId()); sysDeptAccountWithdraw.setAuditUserid(BaseController.getUser().getId()); sysDeptAccountWithdraw.setAuditName(BaseController.getUser().getName()); BigDecimal afterAmount = BigDecimal.ZERO; // add by hxl 2024 -07-05 插入审核时间 sysDeptAccountWithdraw.setAuditingTime(new Date()); String auditingStatus=""; if (sysDeptAccountWithdraw.getStatus().equals(SysDeptAccountStatus.PASS.getCode())) { //sysDeptAccount.setManagementFee(sysDeptAccount.getManagementFee()); //sysDeptAccountService.updateById(sysDeptAccount); //已到账金额 = 原先的到账金额+ 已到账的金额 sysDeptAccount.setSumAmountAccount((sysDeptAccount.getSumAmountAccount()==null? BigDecimal.ZERO:sysDeptAccount.getSumAmountAccount()).add(sysDeptAccountWithdraw.getAmount())); //支付中的金额 = 原先的支付金额 -去提现的金额 sysDeptAccount.setSumAmountPayment((sysDeptAccount.getSumAmountPayment()==null?BigDecimal.ZERO:sysDeptAccount.getSumAmountPayment()).subtract(sysDeptAccountWithdraw.getAmount())); auditingStatus="4"; } if (sysDeptAccountWithdraw.getStatus().equals(SysDeptAccountStatus.REJECT.getCode())) { //驳回,将金额退回 //提现前的金额 BigDecimal beforeAmount = sysDeptAccount.getManagementFee()==null?BigDecimal.ZERO:sysDeptAccount.getManagementFee(); //提现后的金额 afterAmount = beforeAmount.add(sysDeptAccountWithdraw.getAmount()); sysDeptAccount.setManagementFee(afterAmount); //提现的总金额 = 原先的提现总金额 - 提现的金额 sysDeptAccount.setSumAmountWithdrawal((sysDeptAccount.getSumAmountWithdrawal()==null?BigDecimal.ZERO:sysDeptAccount.getSumAmountWithdrawal().subtract(sysDeptAccountWithdraw.getAmount()))); //支付中的金额 = 原先的支付金额 -去提现的金额 sysDeptAccount.setSumAmountPayment((sysDeptAccount.getSumAmountPayment()==null?BigDecimal.ZERO:sysDeptAccount.getSumAmountPayment()).subtract(sysDeptAccountWithdraw.getAmount())); auditingStatus="3"; } sysDeptAccountWithdrawService.updateById(sysDeptAccountWithdraw); //通过审核表id查询历史记录表 LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(SysDeptAccountHistory::getAuditingId, sysDeptAccountWithdraw.getId()); lqw.eq(SysDeptAccountHistory::getDeptId, sysDeptAccountWithdraw.getDeptId()); //插入轨迹表审核成功数据 SysDeptAccountHistory sysDeptAccountHistory = sysDeptAccountHistoryService.getBaseMapper().selectOne(lqw); //插入轨迹表 SysAmountAuditingDeptHistory sysAmountAuditingDeptHistory =new SysAmountAuditingDeptHistory(sysDeptAccountWithdraw.getId(), sysDeptAccountWithdraw.getAmount(), sysDeptAccountWithdraw.getDeptId(),new Date(),auditingStatus, "1",sysDeptAccountHistory.getId()); sysAmountAuditingDeptHistoryService.save(sysAmountAuditingDeptHistory); //跟新账户金额 sysDeptAccountService.updateById(sysDeptAccount); //插入退款记录 if("3".equals(auditingStatus)){ //将收入支出状态台改为收入 2插入历史表中历史表 sysDeptAccountHistory.setId(null); sysDeptAccountHistory.setDocumentary("2"); sysDeptAccountHistory.setProperty(5); sysDeptAccountHistory.setBusinessSegmentsType(2); sysDeptAccountHistory.setCreateTime(new Date()); sysDeptAccountHistory.setSurplusAmount(afterAmount); sysDeptAccountHistoryService.getBaseMapper().insert(sysDeptAccountHistory); } }catch(Exception e){ throw new SystemException("提现错误"); } return HttpResult.ok("审核完成",sysDeptAccountWithdraw); } }