|
@@ -0,0 +1,156 @@
|
|
|
+package com.fjhx.account.service.account.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.fjhx.account.entity.account.dto.AccountRequestFundsSelectDto;
|
|
|
+import com.fjhx.account.entity.account.po.AccountPayment;
|
|
|
+import com.fjhx.account.entity.account.po.AccountRemainder;
|
|
|
+import com.fjhx.account.entity.account.vo.AccountRequestFundsVo;
|
|
|
+import com.fjhx.account.mapper.account.AccountPaymentMapper;
|
|
|
+import com.fjhx.account.service.account.AccountManagementService;
|
|
|
+import com.fjhx.account.service.account.AccountPaymentService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.account.service.account.AccountRemainderService;
|
|
|
+import com.fjhx.account.service.account.AccountRequestFundsDetailService;
|
|
|
+import com.fjhx.common.constant.SourceConstant;
|
|
|
+import com.fjhx.common.entity.corporation.po.Corporation;
|
|
|
+import com.fjhx.common.service.corporation.CorporationService;
|
|
|
+import com.fjhx.file.utils.ObsFileUtil;
|
|
|
+import com.obs.services.internal.ServiceException;
|
|
|
+import com.ruoyi.common.core.domain.BasePo;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
+import com.ruoyi.system.service.ISysDeptService;
|
|
|
+import com.ruoyi.system.utils.UserUtil;
|
|
|
+import org.checkerframework.checker.units.qual.A;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fjhx.account.entity.account.vo.AccountPaymentVo;
|
|
|
+import com.fjhx.account.entity.account.dto.AccountPaymentSelectDto;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.fjhx.account.entity.account.dto.AccountPaymentDto;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 打款表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-04-11
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class AccountPaymentServiceImpl extends ServiceImpl<AccountPaymentMapper, AccountPayment> implements AccountPaymentService {
|
|
|
+ @Autowired
|
|
|
+ private CorporationService corporationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysDeptService sysDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AccountRemainderService accountRemainderService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<AccountRequestFundsVo> getPage(AccountRequestFundsSelectDto dto) {
|
|
|
+ QueryWrapper<Object> wrapper = Wrappers.query();
|
|
|
+ wrapper.eq(ObjectUtil.isNotEmpty(dto.getType()),"arf.type",dto.getType());
|
|
|
+ wrapper.eq(ObjectUtil.isNotEmpty(dto.getStatus()),"arf.status",dto.getStatus());
|
|
|
+ wrapper.eq(ObjectUtil.isNotEmpty(dto.getPaymentStatus()),"ap.status",dto.getPaymentStatus());
|
|
|
+ wrapper.like(ObjectUtil.isNotEmpty(dto.getKeyword()),"arf.payment_remarks",dto.getKeyword());
|
|
|
+ wrapper.orderByDesc("ap.status","arf.payment_time","arf.create_time");
|
|
|
+ Page<AccountRequestFundsVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+
|
|
|
+ //切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.COMMON);
|
|
|
+ //查询公司名称信息
|
|
|
+ List<Corporation> corporationList = corporationService.list();
|
|
|
+ Map<Long, List<Corporation>> corporationMap = corporationList.stream().collect(Collectors.groupingBy(Corporation::getId));
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+
|
|
|
+
|
|
|
+ //切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ //查询部门信息
|
|
|
+ List<SysDept> sysDeptList = sysDeptService.list();
|
|
|
+ Map<Long, List<SysDept>> sysDeptMap = sysDeptList.stream().collect(Collectors.groupingBy(SysDept::getDeptId));
|
|
|
+
|
|
|
+
|
|
|
+ //赋值部门名称、归属公司名称
|
|
|
+ List<AccountRequestFundsVo> records = page.getRecords();
|
|
|
+ for (AccountRequestFundsVo record : records) {
|
|
|
+ List<SysDept> sysDepts = sysDeptMap.get(record.getDepartmentId());
|
|
|
+ if (ObjectUtil.isNotEmpty(sysDepts)){
|
|
|
+ record.setDeptName(sysDepts.get(0).getDeptName());
|
|
|
+ }
|
|
|
+ List<Corporation> corporations = corporationMap.get(record.getCorporationId());
|
|
|
+ if (ObjectUtil.isNotEmpty(corporations)){
|
|
|
+ record.setCorporationName(corporations.get(0).getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 赋值用户名称
|
|
|
+ UserUtil.assignmentNickName(records, BasePo::getCreateUser,AccountRequestFundsVo::setUserName);
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 打款表明细
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AccountPaymentVo detail(Long id) {
|
|
|
+ AccountPayment AccountPayment = baseMapper.detail(id);
|
|
|
+ AccountPaymentVo result = BeanUtil.toBean(AccountPayment, AccountPaymentVo.class);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 打款功能
|
|
|
+ * @param accountPaymentDto
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public void add(AccountPaymentDto accountPaymentDto) {
|
|
|
+ AccountRemainder accountRemainder = accountRemainderService.getOne(Wrappers.<AccountRemainder>lambdaQuery()
|
|
|
+ .eq(AccountRemainder::getAccountManagementId, accountPaymentDto.getAccountManagementId())
|
|
|
+ .eq(AccountRemainder::getCurrency, accountPaymentDto.getCurrency()));
|
|
|
+ //如果不存在这条数据则返回账户余额不足
|
|
|
+ if (ObjectUtil.isEmpty(accountRemainder)){
|
|
|
+ throw new ServiceException("账户余额不足");
|
|
|
+ }
|
|
|
+ //如果余额小于付款金额则返回账户余额不足
|
|
|
+ if (accountRemainder.getRemainder().compareTo(accountPaymentDto.getAmount()) == -1){
|
|
|
+ throw new ServiceException("账户余额不足");
|
|
|
+ }
|
|
|
+ this.save(accountPaymentDto);
|
|
|
+
|
|
|
+ //添加附件信息
|
|
|
+ ObsFileUtil.saveFile(accountPaymentDto.getFileList(),accountPaymentDto.getId());
|
|
|
+
|
|
|
+ //修改账户-余额表的中余额
|
|
|
+ accountRemainder.setRemainder( accountRemainder.getRemainder().subtract(accountPaymentDto.getAmount()));
|
|
|
+ accountRemainderService.updateById(accountRemainder);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(AccountPaymentDto accountPaymentDto) {
|
|
|
+ this.updateById(accountPaymentDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ this.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|