| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- package com.ydtech.modules.admin.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- 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.SysDeptAccountMapper;
- import com.ydtech.modules.admin.model.SysDept;
- 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.dto.SysDeptAccountDto;
- import com.ydtech.modules.admin.model.po.SysAmountAuditingDeptHistory;
- import com.ydtech.modules.admin.model.vo.SysDeptAccountByUserVo;
- import com.ydtech.modules.admin.model.vo.SysDeptAccountVO;
- import com.ydtech.modules.admin.service.*;
- import com.ydtech.modules.base.controller.BaseController;
- import com.ydtech.modules.order.entity.BasePageResult;
- import com.ydtech.modules.protocol.utils.AssertionUtils;
- import com.ydtech.utils.idgen.IdGenerate;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.math.BigInteger;
- import java.time.LocalDateTime;
- import java.util.Date;
- import java.util.List;
- @Service
- public class SysDeptAccountServiceImpl extends ServiceImpl<SysDeptAccountMapper, SysDeptAccount> implements SysDeptAccountService {
- @Autowired
- private SysDeptAccountService sysDeptAccountService;
- @Autowired
- private SysDeptAccountHistoryService sysDeptAccountHistoryService;
- @Autowired
- private SysDeptAccountMapper sysDeptAccountMapper;
- @Autowired
- private SysDeptAccountWithdrawService sysDeptAccountWithdrawService;
- @Autowired
- private SysDeptService sysDeptService;
- @Autowired
- private SysUserInfoService sysUserInfoService;
- @Autowired
- private SysAmountAuditingDeptHistoryService sysAmountAuditingDeptHistoryService;
- @Override
- public BasePageResult<SysDeptAccount> queryByVo(SysDeptAccountVO sysDeptAccountVO) {
- Page<SysDeptAccount> page = new Page<>(sysDeptAccountVO.getPageNum(), sysDeptAccountVO.getPageSize());
- QueryWrapper<SysDeptAccount> wrapper = new QueryWrapper<>();
- Page<SysDeptAccount> sysUserAccountHistoryPage = page(page, wrapper);
- return new BasePageResult<>(sysDeptAccountVO.getPageNum(), page.getSize(), sysUserAccountHistoryPage.getTotal(), page.getPages(),
- sysUserAccountHistoryPage.getRecords());
- }
- public IPage<SysDeptAccountDto> getDept(SysDeptAccountDto sysDeptAccountDto) {
- PageRequest pageRequest = new PageRequest();
- pageRequest.setPageNum(sysDeptAccountDto.getPageNum());
- pageRequest.setPageSize(sysDeptAccountDto.getPageSize());
- Page page = PageRequest.buildPageRequest(pageRequest);
- Page<SysDeptAccountDto> deptList = sysDeptAccountMapper.getDept(page,sysDeptAccountDto);
- return deptList;
- }
- public List<SysDeptAccountByUserVo> getDeptAccountByUser() {
- List<SysDeptAccountByUserVo> deptAccountByUserList = sysDeptAccountMapper.getDeptAccountByUser(BaseController.getUser().getId());
- return deptAccountByUserList;
- }
- @Transactional
- public HttpResult withdrawDeptAccount(SysDeptAccount sysDeptAccount) {
- SysDeptAccount deptAccount = sysDeptAccountMapper.selectById(sysDeptAccount.getDeptId());
- //根据deptId查询提现人员相关信息
- LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(SysDept::getId, sysDeptAccount.getDeptId());
- SysDept sysDept = sysDeptService.getOne(queryWrapper);
- if (sysDeptAccount.getAmount().compareTo(deptAccount.getManagementFee()) > 0) {
- throw new SystemException("提现金额大于机构账户金额");
- }
- if (sysDeptAccount.getAmount().equals(new BigDecimal(BigInteger.ZERO))) {
- throw new SystemException("提现金额不能为0");
- }
- BigDecimal accountAmount = deptAccount.getManagementFee().subtract(sysDeptAccount.getAmount());
- // 减去提现金额
- deptAccount.setManagementFee(accountAmount);
- //计算两个金额
- //支付中总金额 = 原先的支付金额 + 提现的金额
- deptAccount.setSumAmountPayment((deptAccount.getSumAmountPayment()==null?BigDecimal.ZERO:deptAccount.getSumAmountPayment()).add(sysDeptAccount.getAmount()));
- //提现的总金额 = 原先的提现总金额 + 提现的金额
- deptAccount.setSumAmountWithdrawal((deptAccount.getSumAmountWithdrawal()==null?BigDecimal.ZERO:deptAccount.getSumAmountWithdrawal().add(sysDeptAccount.getAmount())));
- sysDeptAccountService.updateById(deptAccount);
- // 生成提现审核数据
- SysDeptAccountWithdraw sysDeptAccountWithdraw = new SysDeptAccountWithdraw();
- sysDeptAccountWithdraw.setId(IdGenerate.nextId());
- sysDeptAccountWithdraw.setDeptId(deptAccount.getDeptId());
- sysDeptAccountWithdraw.setName(sysDept.getName());
- sysDeptAccountWithdraw.setAmount(sysDeptAccount.getAmount());
- sysDeptAccountWithdraw.setStatus(SysDeptAccountStatus.WAIT.getCode()); //待审核
- sysDeptAccountWithdraw.setRemark("");
- sysDeptAccountWithdraw.setWithdrawName(BaseController.getUser().getName());
- sysDeptAccountWithdraw.setWithdrawUserid(BaseController.getUser().getId());
- sysDeptAccountWithdraw.setCreateTime(LocalDateTime.now());
- sysDeptAccountWithdrawService.save(sysDeptAccountWithdraw);
- //插入机构历史表
- // 机构历史明细生成提现明细
- SysDeptAccountHistory sysDeptAccountHistory = new SysDeptAccountHistory();
- sysDeptAccountHistory.setId(IdGenerate.nextId());
- sysDeptAccountHistory.setDeptId(sysDeptAccount.getDeptId());
- sysDeptAccountHistory.setAmount(sysDeptAccountWithdraw.getAmount());
- sysDeptAccountHistory.setSurplusAmount(accountAmount);
- sysDeptAccountHistory.setSuborder(sysDeptAccountWithdraw.getId());
- sysDeptAccountHistory.setDocumentary("1");
- sysDeptAccountHistory.setProperty(6);
- sysDeptAccountHistory.setBusinessSegmentsType(1);
- sysDeptAccountHistory.setFromBankCard(null);
- sysDeptAccountHistory.setToBankCard(null);
- sysDeptAccountHistory.setUserId(BaseController.getUser().getId());
- sysDeptAccountHistory.setCreateTime(new Date());
- // add by hxl 2024 -07-05 插入审核表Id
- sysDeptAccountHistory.setAuditingId(sysDeptAccountWithdraw.getId());
- sysDeptAccountHistory.setRemark("从" + sysDeptAccountWithdraw.getName() + "机构账户中提现" + sysDeptAccountWithdraw.getAmount() + "元");
- sysDeptAccountHistoryService.save(sysDeptAccountHistory);
- // 提现审核插入轨迹表 待审核数据 和审核处理中的数据
- Date date = new Date();
- SysAmountAuditingDeptHistory sysAmountAuditingDeptHistory =new SysAmountAuditingDeptHistory(sysDeptAccountWithdraw.getId(), sysDeptAccountWithdraw.getAmount(), deptAccount.getDeptId(),date,"1", "1",sysDeptAccountHistory.getId());
- SysAmountAuditingDeptHistory sysAmountAuditingDeptHistoryTwo =new SysAmountAuditingDeptHistory(sysDeptAccountWithdraw.getId(), sysDeptAccountWithdraw.getAmount(), deptAccount.getDeptId(),date, "2", "1",sysDeptAccountHistory.getId());
- sysAmountAuditingDeptHistoryService.save(sysAmountAuditingDeptHistory);
- sysAmountAuditingDeptHistoryService.save(sysAmountAuditingDeptHistoryTwo);
- return HttpResult.ok("", sysDeptAccount);
- }
- @Override
- @Transactional
- public boolean inert(SysDeptAccountVO sysDeptAccountVO) {
- SysDeptAccount sysDeptAccount = new SysDeptAccount();
- BeanUtils.copyProperties(sysDeptAccountVO, sysDeptAccount);
- return super.save(sysDeptAccount);
- }
- @Override
- public void deleteSysUserBank(Long id) {
- boolean b = removeById(id);
- AssertionUtils.isSucceed(b, "删除失败");
- }
- @Override
- @Transactional
- public void uodate(SysDeptAccountVO sysDeptAccountVO) {
- SysDeptAccount sysDeptAccount = new SysDeptAccount();
- BeanUtils.copyProperties(sysDeptAccountVO, sysDeptAccount);
- super.updateById(sysDeptAccount);
- }
- }
|