24282 4 ay önce
ebeveyn
işleme
d541811f48

+ 28 - 9
hx-account/src/main/java/com/fjhx/account/controller/account/AccountDeptRunningWaterController.java

@@ -1,17 +1,21 @@
 package com.fjhx.account.controller.account;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
-import com.fjhx.account.entity.account.vo.AccountRunningWaterVo;
-import com.fjhx.common.constant.SourceConstant;
-import org.springframework.web.bind.annotation.*;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.fjhx.account.entity.account.vo.AccountDeptRunningWaterVo;
-import com.fjhx.account.entity.account.dto.AccountDeptRunningWaterSelectDto;
 import com.fjhx.account.entity.account.dto.AccountDeptRunningWaterDto;
-import com.ruoyi.common.core.domain.BaseSelectDto;
+import com.fjhx.account.entity.account.dto.AccountDeptRunningWaterSelectDto;
+import com.fjhx.account.entity.account.dto.DeptExpenseDto;
+import com.fjhx.account.entity.account.vo.DeptExpenseVo;
 import com.fjhx.account.service.account.AccountDeptRunningWaterService;
+import com.fjhx.common.constant.SourceConstant;
+import com.fjhx.item.util.excel.util.ExcelUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 import java.util.Map;
 
@@ -30,16 +34,29 @@ import java.util.Map;
 public class AccountDeptRunningWaterController {
 
     @Autowired
+    private HttpServletResponse response;
+
+    @Autowired
     private AccountDeptRunningWaterService accountDeptRunningWaterService;
 
     /**
      * 部门-资金流水关联表分页
      */
     @PostMapping("/page")
-    public Page<AccountRunningWaterVo> page(@RequestBody AccountDeptRunningWaterSelectDto dto) {
+    public Page<DeptExpenseVo> page(@RequestBody DeptExpenseDto dto) {
         return accountDeptRunningWaterService.getPage(dto);
     }
 
+    /**
+     * 部门-资金流水关联表分页
+     */
+    @PostMapping("/export")
+    public void export(@RequestBody DeptExpenseDto dto) {
+        dto.setPageNum(1);
+        dto.setPageSize(Integer.MAX_VALUE);
+        Page<DeptExpenseVo> page = accountDeptRunningWaterService.getPage(dto);
+        ExcelUtil.export(response, page.getRecords(), DeptExpenseVo.class);
+    }
 
 
     /**
@@ -52,21 +69,23 @@ public class AccountDeptRunningWaterController {
 
     /**
      * 部门-资金流水报表
+     *
      * @param dto
      * @return
      */
     @PostMapping("/DeptRunningWaterReport")
-    public  List<Map<String,Object>> DeptRunningWaterReport(@RequestBody AccountDeptRunningWaterSelectDto dto){
+    public List<Map<String, Object>> DeptRunningWaterReport(@RequestBody DeptExpenseDto dto) {
         return accountDeptRunningWaterService.DeptRunningWaterReport(dto);
     }
 
     /**
      * 部门-资金流水统计( 部门-资金流水列表)
+     *
      * @param dto
      * @return
      */
     @PostMapping("/deptRunningWaterStatistics")
-    public  Map<String,Object> deptRunningWaterStatistics(@RequestBody AccountDeptRunningWaterSelectDto dto){
+    public Map<String, Object> deptRunningWaterStatistics(@RequestBody AccountDeptRunningWaterSelectDto dto) {
         return accountDeptRunningWaterService.deptRunningWaterStatistics(dto);
     }
 

+ 7 - 2
hx-account/src/main/java/com/fjhx/account/entity/account/dto/AccountDeptRunningWaterSelectDto.java

@@ -5,6 +5,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.math.BigDecimal;
+import java.util.Set;
 
 /**
  * 部门-资金流水关联表列表查询入参实体
@@ -31,7 +32,7 @@ public class AccountDeptRunningWaterSelectDto extends BaseSelectDto {
     private String keyword;
 
     /**
-     *是否分拆(10未分拆  20 已分拆)
+     * 是否分拆(10未分拆  20 已分拆)
      */
     private String type;
 
@@ -51,7 +52,7 @@ public class AccountDeptRunningWaterSelectDto extends BaseSelectDto {
     private Long accountManagementId;
 
     /**
-     *摘要
+     * 摘要
      */
     private String remarks;
 
@@ -65,5 +66,9 @@ public class AccountDeptRunningWaterSelectDto extends BaseSelectDto {
      */
     private BigDecimal endAmount;
 
+    /**
+     * 部门列表
+     */
+    private Set<Long> deptIds;
 
 }

+ 38 - 0
hx-account/src/main/java/com/fjhx/account/entity/account/dto/DeptExpenseDto.java

@@ -0,0 +1,38 @@
+package com.fjhx.account.entity.account.dto;
+
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Set;
+
+@Getter
+@Setter
+public class DeptExpenseDto extends BaseSelectDto {
+
+    /**
+     * 币种(字典account_currency)
+     */
+    private String currency;
+
+    /**
+     * 收支类型:10 收入,20支出
+     */
+    private Integer status;
+
+    /**
+     * 部门id
+     */
+    private Long deptId;
+
+    /**
+     * 备注
+     */
+    private String remarks;
+
+    /**
+     * 部门列表
+     */
+    private Set<Long> deptIds;
+
+}

+ 35 - 0
hx-account/src/main/java/com/fjhx/account/entity/account/vo/DeptExpenseVo.java

@@ -0,0 +1,35 @@
+package com.fjhx.account.entity.account.vo;
+
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Getter
+@Setter
+@ExcelIgnoreUnannotated
+public class DeptExpenseVo {
+
+    @ExcelProperty("部门")
+    private String deptName;
+
+    @ExcelProperty("交易时间")
+    private Date transactionTime;
+
+    @ExcelProperty("币种")
+    private String currency;
+
+    @ExcelProperty("交易金额")
+    private BigDecimal amount;
+
+    @ExcelProperty("摘要")
+    private String remarks;
+
+    private Long id;
+    private Long departmentId;
+    private Integer status;
+    private String month;
+}

+ 6 - 4
hx-account/src/main/java/com/fjhx/account/mapper/account/AccountDeptRunningWaterMapper.java

@@ -1,12 +1,13 @@
 package com.fjhx.account.mapper.account;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.fjhx.account.entity.account.po.AccountDeptRunningWater;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.fjhx.account.entity.account.vo.AccountDeptRunningWaterVo;
+import com.fjhx.account.entity.account.dto.AccountDeptRunningWaterSelectDto;
+import com.fjhx.account.entity.account.dto.DeptExpenseDto;
+import com.fjhx.account.entity.account.po.AccountDeptRunningWater;
 import com.fjhx.account.entity.account.vo.AccountRunningWaterVo;
-import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.fjhx.account.entity.account.vo.DeptExpenseVo;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -25,7 +26,7 @@ public interface AccountDeptRunningWaterMapper extends BaseMapper<AccountDeptRun
     /**
      * 部门-资金流水关联表分页
      */
-    Page<AccountRunningWaterVo> getPage(@Param("page") Page<Object> page,@Param("ew") QueryWrapper<Object> wrapper);
+    Page<DeptExpenseVo> getPage(@Param("page") Page<Object> page, @Param("dto") DeptExpenseDto dto);
 
     /**
      * 部门-资金流水统计列表
@@ -34,6 +35,7 @@ public interface AccountDeptRunningWaterMapper extends BaseMapper<AccountDeptRun
 
     /**
      * 查询部门-资金流水统计信息
+     *
      * @param query
      * @return
      */

+ 10 - 7
hx-account/src/main/java/com/fjhx/account/service/account/AccountDeptRunningWaterService.java

@@ -1,12 +1,13 @@
 package com.fjhx.account.service.account;
 
-import com.fjhx.account.entity.account.po.AccountDeptRunningWater;
-import com.fjhx.account.entity.account.vo.AccountRunningWaterVo;
-import com.ruoyi.common.core.service.BaseService;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.fjhx.account.entity.account.vo.AccountDeptRunningWaterVo;
-import com.fjhx.account.entity.account.dto.AccountDeptRunningWaterSelectDto;
 import com.fjhx.account.entity.account.dto.AccountDeptRunningWaterDto;
+import com.fjhx.account.entity.account.dto.AccountDeptRunningWaterSelectDto;
+import com.fjhx.account.entity.account.dto.DeptExpenseDto;
+import com.fjhx.account.entity.account.po.AccountDeptRunningWater;
+import com.fjhx.account.entity.account.vo.AccountDeptRunningWaterVo;
+import com.fjhx.account.entity.account.vo.DeptExpenseVo;
+import com.ruoyi.common.core.service.BaseService;
 
 import java.util.List;
 import java.util.Map;
@@ -25,7 +26,7 @@ public interface AccountDeptRunningWaterService extends BaseService<AccountDeptR
     /**
      * 部门-资金流水关联表分页
      */
-    Page<AccountRunningWaterVo> getPage(AccountDeptRunningWaterSelectDto dto);
+    Page<DeptExpenseVo> getPage(DeptExpenseDto dto);
 
     /**
      * 部门-资金流水关联表明细
@@ -49,13 +50,15 @@ public interface AccountDeptRunningWaterService extends BaseService<AccountDeptR
 
     /**
      * 部门-资金流水报表
+     *
      * @param dto
      * @return
      */
-    List<Map<String,Object>> DeptRunningWaterReport(AccountDeptRunningWaterSelectDto dto);
+    List<Map<String, Object>> DeptRunningWaterReport(DeptExpenseDto dto);
 
     /**
      * 部门-资金流水统计( 部门-资金流水列表)
+     *
      * @param dto
      * @return
      */

+ 78 - 118
hx-account/src/main/java/com/fjhx/account/service/account/impl/AccountDeptRunningWaterServiceImpl.java

@@ -1,7 +1,6 @@
 package com.fjhx.account.service.account.impl;
 
 import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -12,9 +11,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.account.controller.utils.DateUtils;
 import com.fjhx.account.entity.account.dto.AccountDeptRunningWaterDto;
 import com.fjhx.account.entity.account.dto.AccountDeptRunningWaterSelectDto;
+import com.fjhx.account.entity.account.dto.DeptExpenseDto;
 import com.fjhx.account.entity.account.po.AccountDeptRunningWater;
 import com.fjhx.account.entity.account.vo.AccountDeptRunningWaterVo;
 import com.fjhx.account.entity.account.vo.AccountRunningWaterVo;
+import com.fjhx.account.entity.account.vo.DeptExpenseVo;
 import com.fjhx.account.mapper.account.AccountDeptRunningWaterMapper;
 import com.fjhx.account.service.account.AccountDeptRunningWaterService;
 import com.fjhx.common.constant.SourceConstant;
@@ -26,9 +27,12 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 
@@ -46,49 +50,20 @@ public class AccountDeptRunningWaterServiceImpl extends ServiceImpl<AccountDeptR
     @Autowired
     private ISysDeptService sysDeptService;
 
-    @Override
-    public Page<AccountRunningWaterVo> getPage(AccountDeptRunningWaterSelectDto dto) {
-        QueryWrapper<Object> wrapper = Wrappers.query();
-        // 收支类型
-        wrapper.eq(ObjectUtil.isNotEmpty(dto.getStatus()), "arw.status", dto.getStatus());
-        // 币种
-        wrapper.eq(ObjectUtil.isNotEmpty(dto.getCurrency()), "arw.currency", dto.getCurrency());
-        wrapper.eq(ObjectUtil.isNotEmpty(dto.getType()), "adrw.type", dto.getType());
-        // 归属公司id
-        wrapper.eq(ObjectUtil.isNotEmpty(dto.getCorporationId()), "am.corporation_id", dto.getCorporationId());
-        // 摘要
-        wrapper.eq(ObjectUtil.isNotEmpty(dto.getRemarks()), "arw.remarks", dto.getRemarks());
-        // 起始金额
-        wrapper.eq(ObjectUtil.isNotEmpty(dto.getBeginAmount()), "arw.amount", dto.getBeginAmount());
-        // 结束金额
-        wrapper.eq(ObjectUtil.isNotEmpty(dto.getEndAmount()), "arw.amount", dto.getEndAmount());
-        // 开始时间
-        wrapper.eq(ObjectUtil.isNotEmpty(dto.getBeginTime()), "arw.create_time", dto.getBeginTime());
-        // 结束时间
-        wrapper.eq(ObjectUtil.isNotEmpty(dto.getEndTime()), "arw.create_time", dto.getEndTime());
-
-        // if (StringUtils.isNotEmpty(dto.getKeyword())) {
-        //     wrapper.and(wrapper1 -> wrapper1.like("arw.remarks", dto.getKeyword()).or().like("arw.name", dto.getKeyword()));
-        // }
-
-        // 交易时间倒叙排序
-        wrapper.orderByDesc("arw.transaction_time", "arw.id");
-
-        Page<AccountRunningWaterVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
-        // 切换数据源
-        DynamicDataSourceContextHolder.push(SourceConstant.BASE);
-        // 查询部门信息
-        List<SysDept> sysDeptList = sysDeptService.list();
-        Map<Long, List<SysDept>> sysDeptMap = sysDeptList.stream().collect(Collectors.groupingBy(SysDept::getDeptId));
+    private static final Set<Long> deptIds = new HashSet<Long>() {{
+        add(1508293663904624641L);
+        add(1508293745521586177L);
+        add(1508351674429861890L);
+        add(1509835006418219009L);
+        add(1545289616599367681L);
+        add(1567825087275495425L);
+        add(1663020305968291842L);
+    }};
 
-        List<AccountRunningWaterVo> records = page.getRecords();
-        for (AccountRunningWaterVo record : records) {
-            List<SysDept> sysDepts = sysDeptMap.get(record.getDeptId());
-            if (ObjectUtil.isNotEmpty(sysDepts)) {
-                record.setDeptName(sysDepts.get(0).getDeptName());
-            }
-        }
-        return page;
+    @Override
+    public Page<DeptExpenseVo> getPage(DeptExpenseDto dto) {
+        dto.setDeptIds(deptIds);
+        return baseMapper.getPage(dto.getPage(), dto);
     }
 
     @Override
@@ -103,9 +78,9 @@ public class AccountDeptRunningWaterServiceImpl extends ServiceImpl<AccountDeptR
      */
     @Override
     public void add(AccountDeptRunningWaterDto accountDeptRunningWaterDto) {
-        if (ObjectUtil.isNotEmpty(accountDeptRunningWaterDto.getId())){
+        if (ObjectUtil.isNotEmpty(accountDeptRunningWaterDto.getId())) {
             this.updateById(accountDeptRunningWaterDto);
-        }else {
+        } else {
             this.save(accountDeptRunningWaterDto);
         }
 
@@ -123,89 +98,74 @@ public class AccountDeptRunningWaterServiceImpl extends ServiceImpl<AccountDeptR
 
     /**
      * 部门-资金流水报表
+     *
      * @param dto
      * @return
      */
     @Override
-    public  List<Map<String,Object>> DeptRunningWaterReport(AccountDeptRunningWaterSelectDto dto) {
-        if (ObjectUtil.isEmpty(dto.getBeginTime())&&ObjectUtil.isEmpty(dto.getEndTime())) {
+    public List<Map<String, Object>> DeptRunningWaterReport(DeptExpenseDto dto) {
+        if (ObjectUtil.isEmpty(dto.getBeginTime()) && ObjectUtil.isEmpty(dto.getEndTime())) {
             throw new ServiceException("查询的时间范围不能为空!");
         }
+
+        dto.setDeptIds(deptIds);
+        dto.setPageNum(1);
+        dto.setPageSize(Integer.MAX_VALUE);
+        Page<DeptExpenseVo> page = baseMapper.getPage(dto.getPage(), dto);
+        List<DeptExpenseVo> records = page.getRecords();
+        if (records.isEmpty()) {
+            return Collections.emptyList();
+        }
+
         //获取月份集合
         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')", DateUtil.format(dto.getBeginTime(),"yyyy-MM"));
-        query.le("DATE_FORMAT(ar.create_time,'%Y-%m')", DateUtil.format(dto.getEndTime(),"yyyy-MM"));
-        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<Long, List<DeptExpenseVo>> map = records.stream().collect(Collectors.groupingBy(DeptExpenseVo::getDepartmentId));
+
+        List<Map<String, Object>> list = new ArrayList<>();
+        map.forEach((k, v) -> {
+            Map<String, Object> item = new HashMap<>();
+            Map<String, List<DeptExpenseVo>> collect = v.stream().collect(Collectors.groupingBy(DeptExpenseVo::getMonth));
+            item.put("deptName", v.get(0).getDeptName());
+            item.put("accountRunningWaterVoList", getList(months, collect));
+            list.add(item);
+        });
+
+        return list;
+    }
+
+    private List<Map<String, Object>> getList(List<String> months, Map<String, List<DeptExpenseVo>> collect) {
+        return months.stream().map(item -> {
+            // 收入金额
+            BigDecimal incomeAmount = BigDecimal.ZERO;
+
+            // 支出金额
+            BigDecimal expenditureAmount = BigDecimal.ZERO;
+
+            List<DeptExpenseVo> list = collect.getOrDefault(item, Collections.emptyList());
+
+            for (DeptExpenseVo deptExpenseVo : list) {
+                BigDecimal amount = deptExpenseVo.getAmount();
+                if (amount.compareTo(BigDecimal.ZERO) > 0) {
+                    incomeAmount = incomeAmount.add(amount);
+                }else {
+                    expenditureAmount = expenditureAmount.add(amount);
                 }
             }
-           map.put("accountRunningWaterVoList",accountRunningWaterVoList);
-            mapList.add(map);
-        }
-        return mapList;
+
+            Map<String, Object> map = new HashMap<>();
+            map.put("time", item);
+            map.put("incomeAmount", incomeAmount);
+            map.put("expenditureAmount", BigDecimal.ZERO.subtract(expenditureAmount));
+            map.put("balanceAmount", incomeAmount.add(expenditureAmount));
+
+            return map;
+        }).collect(Collectors.toList());
     }
 
     /**
      * 部门-资金流水统计( 部门-资金流水列表)
+     *
      * @param dto
      * @return
      */
@@ -217,7 +177,7 @@ public class AccountDeptRunningWaterServiceImpl extends ServiceImpl<AccountDeptR
         QueryWrapper<Object> query = Wrappers.query();
         query.groupBy("rwd.dept_id");
         //查询部门-资金流水统计信息
-        List<AccountRunningWaterVo> accountRunningWaterVoList =  baseMapper.deptRunningWaterStatistics(query);
+        List<AccountRunningWaterVo> accountRunningWaterVoList = baseMapper.deptRunningWaterStatistics(query);
 
         //计算收入合计数据
         BigDecimal incomeAmount = accountRunningWaterVoList.stream().map(accountRunningWaterVo ->
@@ -226,8 +186,8 @@ public class AccountDeptRunningWaterServiceImpl extends ServiceImpl<AccountDeptR
         //计算支出合计数据
         BigDecimal expenditureAmount = accountRunningWaterVoList.stream().map(accountRunningWaterVo ->
                 accountRunningWaterVo.getExpenditureAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
-        map.put("incomeAmount",incomeAmount);
-        map.put("expenditureAmount",expenditureAmount);
+        map.put("incomeAmount", incomeAmount);
+        map.put("expenditureAmount", expenditureAmount);
 
         //查询部门信息
         //切换数据源
@@ -238,11 +198,11 @@ public class AccountDeptRunningWaterServiceImpl extends ServiceImpl<AccountDeptR
         //赋值部门信息
         for (AccountRunningWaterVo accountRunningWaterVo : accountRunningWaterVoList) {
             List<SysDept> sysDepts = sysDeptMap.get(accountRunningWaterVo.getDeptId());
-            if (CollectionUtils.isNotEmpty(sysDepts)){
+            if (CollectionUtils.isNotEmpty(sysDepts)) {
                 accountRunningWaterVo.setDeptName(sysDepts.get(0).getDeptName());
             }
         }
-        map.put("accountRunningWaterVoList",accountRunningWaterVoList);
+        map.put("accountRunningWaterVoList", accountRunningWaterVoList);
         return map;
     }
 

+ 124 - 23
hx-account/src/main/resources/mapper/account/AccountDeptRunningWaterMapper.xml

@@ -1,30 +1,131 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fjhx.account.mapper.account.AccountDeptRunningWaterMapper">
-    <select id="getPage" resultType="com.fjhx.account.entity.account.vo.AccountRunningWaterVo">
+<!--    <select id="getPage" resultType="com.fjhx.account.entity.account.vo.AccountRunningWaterVo">-->
+<!--        select-->
+<!--            arw.id,-->
+<!--            arw.account_management_id,-->
+<!--            arw.status,-->
+<!--            arw.amount,-->
+<!--            arw.currency,-->
+<!--            arw.name,-->
+<!--            arw.received,-->
+<!--            arw.opening_bank,-->
+<!--            arw.account_opening,-->
+<!--            arw.transaction_time,-->
+<!--            arw.remarks,-->
+<!--            arw.create_user,-->
+<!--            arw.create_time,-->
+<!--            arw.update_user,-->
+<!--            arw.update_time,-->
+<!--            am.alias accountManagementName,-->
+<!--            adrw.type,-->
+<!--            adrw.id  accountDeptRunningWaterId-->
+<!--        from account_running_water arw-->
+<!--                 left join  account_management am on arw.account_management_id = am.id-->
+<!--                 left join account_dept_running_water adrw on arw.id = adrw.running_water_id-->
+<!--            ${ew.customSqlSegment}-->
+<!--    </select>-->
+
+    <select id="getPage" resultType="com.fjhx.account.entity.account.vo.DeptExpenseVo">
         select
-            arw.id,
-            arw.account_management_id,
-            arw.status,
-            arw.amount,
-            arw.currency,
-            arw.name,
-            arw.received,
-            arw.opening_bank,
-            arw.account_opening,
-            arw.transaction_time,
-            arw.remarks,
-            arw.create_user,
-            arw.create_time,
-            arw.update_user,
-            arw.update_time,
-            am.alias accountManagementName,
-            adrw.type,
-            adrw.id  accountDeptRunningWaterId
-        from account_running_water arw
-                 left join  account_management am on arw.account_management_id = am.id
-                 left join account_dept_running_water adrw on arw.id = adrw.running_water_id
-            ${ew.customSqlSegment}
+        t.*,
+        DATE_FORMAT(t.transaction_time, '%Y-%m') month
+        from (
+
+        SELECT
+        arfd.id id,
+        arf.department_id,
+        arf.create_time transaction_time,
+        arf.currency,
+        -arfd.amount amount,
+        arfd.remarks,
+        d.dept_name,
+        20 status
+        FROM account_request_funds arf
+        INNER JOIN account_request_funds_detail arfd ON arf.id = arfd.account_request_funds_id
+        LEFT JOIN bytesailing_base.sys_dept d on arf.department_id = d.dept_id
+        WHERE
+        arf.del_flag = 0
+        AND arfd.del_flag = 0
+        AND d.del_flag = 0
+        AND arf.STATUS = 30
+        AND arfd.contract_id IS NULL
+        AND arf.department_id IN
+        <foreach item="item" collection="dto.deptIds" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+
+        UNION ALL
+
+        SELECT
+        c.id id,
+        1508351674429861890 department_id,
+        c.create_time transaction_time,
+        'CNY' currency,
+        c.have_overall_amount amount,
+        CONCAT( '合同 【', c.contract_code, '】 总办收入' ) remarks,
+        '总经理办公室' dept_name,
+        10 STATUS
+        FROM
+        bytesailing_sale.commission c
+        WHERE c.del_flag=0
+
+        UNION ALL
+
+        SELECT
+        c.id id,
+        1545289616599367681 department_id,
+        c.create_time transaction_time,
+        'CNY' currency,
+        c.public_amount amount,
+        CONCAT( '合同 【', c.contract_code, '】 公共收入' ) remarks,
+        '行政人事部' dept_name,
+        10 STATUS
+        FROM
+        bytesailing_sale.commission c
+        WHERE c.del_flag=0
+
+        UNION ALL
+
+        SELECT
+        c.id id,
+        1508293745521586177 department_id,
+        c.create_time transaction_time,
+        'CNY' currency,
+        c.after_sales_amount amount,
+        CONCAT( '合同 【', c.contract_code, '】 售后收入' ) remarks,
+        '供应链及售后' dept_name,
+        10 STATUS
+        FROM
+        bytesailing_sale.commission c
+        WHERE c.del_flag=0
+
+        ) t
+        <where>
+            <if test="dto.remarks neq null and dto.remarks neq ''">
+                t.remarks like concat('%',#{dto.remarks},'%')
+            </if>
+            <if test="dto.keyword neq null and dto.keyword neq ''">
+                and t.remarks like concat('%',#{dto.keyword},'%')
+            </if>
+            <if test="dto.currency neq null and dto.currency neq ''">
+                and t.currency = #{dto.currency}
+            </if>
+            <if test="dto.status neq null">
+                and t.status = #{dto.status}
+            </if>
+            <if test="dto.deptId neq null">
+                and t.department_id = #{dto.deptId}
+            </if>
+            <if test="dto.beginTime neq null">
+                and t.transaction_time &gt;= #{dto.beginTime}
+            </if>
+            <if test="dto.endTime neq null">
+                and t.transaction_time &lt;= #{dto.endTime}
+            </if>
+        </where>
+        order by t.id desc
     </select>
 
     <select id="DeptRunningWaterReport" resultType="com.fjhx.account.entity.account.vo.AccountRunningWaterVo">