|
@@ -2,8 +2,10 @@ 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.interfaces.Func;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.fjhx.account.controller.utils.DateUtils;
|
|
|
import com.fjhx.account.entity.account.po.AccountDeptRunningWater;
|
|
|
import com.fjhx.account.entity.account.vo.AccountRequestFundsVo;
|
|
|
import com.fjhx.account.entity.account.vo.AccountRunningWaterVo;
|
|
@@ -11,6 +13,7 @@ import com.fjhx.account.mapper.account.AccountDeptRunningWaterMapper;
|
|
|
import com.fjhx.account.service.account.AccountDeptRunningWaterService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
+import com.obs.services.internal.ServiceException;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
@@ -23,6 +26,9 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.fjhx.account.entity.account.dto.AccountDeptRunningWaterDto;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -99,4 +105,87 @@ public class AccountDeptRunningWaterServiceImpl extends ServiceImpl<AccountDeptR
|
|
|
this.removeById(id);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 部门-资金流水报表
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Map<String,Object>> DeptRunningWaterReport(AccountDeptRunningWaterSelectDto dto) {
|
|
|
+ if (ObjectUtil.isEmpty(dto.getBeginTime())&&ObjectUtil.isEmpty(dto.getEndTime())) {
|
|
|
+ throw new ServiceException("查询的时间范围不能为空!");
|
|
|
+ }
|
|
|
+ //获取月份集合
|
|
|
+ List<String> months = DateUtils.getMonthBetweenDate(dto.getBeginTime(), dto.getEndTime());
|
|
|
+ //存放部门信息
|
|
|
+ List<SysDept> sysDeptList = new ArrayList<>();
|
|
|
+ //查询部门信息
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getDeptId())){
|
|
|
+ //切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ //判断是否存在子集的部门信息
|
|
|
+ sysDeptList = sysDeptService.list(Wrappers.<SysDept>lambdaQuery().like(SysDept::getAncestors,dto.getDeptId())
|
|
|
+ .orderByDesc(SysDept::getParentId));
|
|
|
+ SysDept sysDept = sysDeptService.getById(dto.getDeptId());
|
|
|
+ sysDeptList.add(sysDept);
|
|
|
+ }else {
|
|
|
+ //切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ sysDeptList = sysDeptService.list(Wrappers.<SysDept>lambdaQuery().orderByDesc(SysDept::getParentId));
|
|
|
+ }
|
|
|
+ //获取到部门ID
|
|
|
+ List<Long> deptIds = sysDeptList.stream().map(sysDept -> sysDept.getDeptId()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //查询资金流水表的信息
|
|
|
+ QueryWrapper<Object> query = Wrappers.query();
|
|
|
+ query.ge("DATE_FORMAT(ar.create_time,'%Y-%m')",dto.getBeginTime());
|
|
|
+ query.le("DATE_FORMAT(ar.create_time,'%Y-%m')",dto.getEndTime());
|
|
|
+ query.in("wd.dept_id",deptIds);
|
|
|
+ query.groupBy("wd.dept_id","time");
|
|
|
+ //切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.ACCOUNT);
|
|
|
+ List<AccountRunningWaterVo> accountRunningWaterVos = baseMapper.DeptRunningWaterReport(query);
|
|
|
+ Map<Long, List<AccountRunningWaterVo>> accountRunningWaterMap = accountRunningWaterVos.stream()
|
|
|
+ .collect(Collectors.groupingBy(AccountRunningWaterVo::getDeptId));
|
|
|
+
|
|
|
+ //存放部门费用统计的数据
|
|
|
+ List<Map<String,Object>> mapList = new ArrayList<>();
|
|
|
+ for (SysDept sysDept : sysDeptList) {
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("deptName",sysDept.getDeptName());
|
|
|
+ //获取到这个部门的费用统计报表
|
|
|
+ List<AccountRunningWaterVo> accountRunningWaterVoList = accountRunningWaterMap.get(sysDept.getDeptId());
|
|
|
+ //如果这个部门没有费用统计表的数据则将统计相关数据表设计为0
|
|
|
+ if (ObjectUtil.isEmpty(accountRunningWaterVoList)){
|
|
|
+ accountRunningWaterVoList = new ArrayList<>();
|
|
|
+ for (String month : months) {
|
|
|
+ AccountRunningWaterVo accountRunningWaterVo = new AccountRunningWaterVo();
|
|
|
+ accountRunningWaterVo.setIncomeAmount(new BigDecimal(0));
|
|
|
+ accountRunningWaterVo.setExpenditureAmount(new BigDecimal(0));
|
|
|
+ accountRunningWaterVo.setBalanceAmount(new BigDecimal(0));
|
|
|
+ accountRunningWaterVo.setTime(month);
|
|
|
+ accountRunningWaterVoList.add(accountRunningWaterVo);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ Map<String, List<AccountRunningWaterVo>> waterMap = accountRunningWaterVoList.stream()
|
|
|
+ .collect(Collectors.groupingBy(AccountRunningWaterVo::getTime));
|
|
|
+
|
|
|
+ for (String month : months) {//判断这个月份中是否有这个数据,如果没有则赋值为0
|
|
|
+ List<AccountRunningWaterVo> accountRunningWaterVos1 = waterMap.get(month);
|
|
|
+ if (ObjectUtil.isEmpty(accountRunningWaterVos1)){
|
|
|
+ AccountRunningWaterVo accountRunningWaterVo = new AccountRunningWaterVo();
|
|
|
+ accountRunningWaterVo.setIncomeAmount(new BigDecimal(0));
|
|
|
+ accountRunningWaterVo.setExpenditureAmount(new BigDecimal(0));
|
|
|
+ accountRunningWaterVo.setBalanceAmount(new BigDecimal(0));
|
|
|
+ accountRunningWaterVo.setTime(month);
|
|
|
+ accountRunningWaterVoList.add(accountRunningWaterVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("accountRunningWaterVoList",accountRunningWaterVoList);
|
|
|
+ mapList.add(map);
|
|
|
+ }
|
|
|
+ return mapList;
|
|
|
+ }
|
|
|
+
|
|
|
}
|