BAOLH
2026-11-10 4d730af0447c686133130d0116a0fa3dd82c2dca
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/capitalFlow/service/impl/CapitalFlowServiceImpl.java
@@ -15,13 +15,15 @@
*/
package me.zhengjie.modules.capitalFlow.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.capital.service.CapitalAccountCompanyService;
import me.zhengjie.modules.capital.service.dto.CapitalAccountCompanyDto;
import me.zhengjie.modules.capitalFlow.domain.CapitalFlow;
import me.zhengjie.modules.capitalFlow.domain.CapitalFlowExpend;
import me.zhengjie.modules.capitalFlow.domain.CapitalFlowIncome;
import me.zhengjie.modules.capitalFlow.repository.CapitalFlowExpendRepository;
import me.zhengjie.modules.capitalFlow.repository.CapitalFlowIncomeRepository;
import me.zhengjie.modules.system.service.dto.SysCompanyDto;
import me.zhengjie.modules.system.service.impl.SysCompanyServiceImpl;
import me.zhengjie.modules.quartz.service.impl.CapitalServiceImpl;
import me.zhengjie.utils.*;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.capitalFlow.repository.CapitalFlowRepository;
@@ -34,12 +36,10 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.function.Function;
/**
@@ -49,14 +49,16 @@
* @date 2023-02-13
**/
@Service
@Transactional
@RequiredArgsConstructor
public class CapitalFlowServiceImpl implements CapitalFlowService {
    private final CapitalFlowRepository capitalFlowRepository;
    private final CapitalFlowMapper capitalFlowMapper;
    private final SysCompanyServiceImpl sysCompanyServiceImpl;
    private final CapitalFlowExpendRepository capitalFlowExpendRepository;
    private final CapitalFlowIncomeRepository capitalFlowIncomeRepository;
    private final CapitalServiceImpl capitalService;
    private final CapitalAccountCompanyService capitalAccountCompanyService;
    @Override
    public Map<String,Object> queryAll(CapitalFlowQueryCriteria criteria, Pageable pageable){
@@ -72,8 +74,8 @@
            public CapitalFlowDto apply(CapitalFlow t) {
                // 将实体类转换成DTO
                CapitalFlowDto capitalFlowDto = capitalFlowMapper.toDto(t);
                // 公司名称
                capitalFlowDto.setCompanyName(companyName(t));
                // 年度账户名称
                capitalFlowDto.setAccountCompanyName(accountCompanyName(t));
                // 流水支出
                capitalFlowDto.setCapitalFlowExpends(capitalFlowExpendRepository.findByFlowId(t.getId()));
                // 流水支出金额
@@ -97,7 +99,7 @@
            // 资金流水
            CapitalFlowDto capitalFlowDto = capitalFlowDtoList.get(i);
            // DTO赋值
            capitalFlowDto.setCompanyName(companyName(capitalFlowMapper.toEntity(capitalFlowDto)));
            capitalFlowDto.setAccountCompanyName(accountCompanyName(capitalFlowMapper.toEntity(capitalFlowDto)));
        }
        return capitalFlowDtoList;
    }
@@ -128,6 +130,16 @@
    @Override
    public void deleteAll(Long[] ids) {
        for (Long id : ids) {
            // 查询流水支出表
            List<CapitalFlowExpend> capitalFlowExpends = capitalFlowExpendRepository.findByFlowId(id);
            for(int i = 0; i < capitalFlowExpends.size(); i++){
                capitalFlowExpendRepository.deleteByFlowId(capitalFlowExpends.get(i).getFlowId());
            }
            // 查询流水收入表
            List<CapitalFlowIncome> capitalFlowIncomes = capitalFlowIncomeRepository.findByFlowId(id);
            for(int i = 0; i < capitalFlowIncomes.size(); i++){
                capitalFlowIncomeRepository.deleteByFlowId(capitalFlowIncomes.get(i).getFlowId());
            }
            capitalFlowRepository.deleteById(id);
        }
    }
@@ -136,10 +148,10 @@
    public void download(List<CapitalFlowDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (CapitalFlowDto capitalFlow : all) {
            String companyName = companyName(capitalFlowMapper.toEntity(capitalFlow));
            String accountCompanyName = accountCompanyName(capitalFlowMapper.toEntity(capitalFlow));
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("流水年月", capitalFlow.getFlowYearMonth());
            map.put("所属公司", companyName);
            map.put("所属年度账户", accountCompanyName);
            map.put("备注", capitalFlow.getRemarks());
            map.put("创建者", capitalFlow.getCreateBy());
            map.put("创建时间", capitalFlow.getCreateTime());
@@ -151,13 +163,54 @@
    }
    /**
     * 公司名称
     * 流水生成
     * @param resources /
     */
    @Override
    public void generate(CapitalFlow resources) {
//        // 日历类
//        Calendar cal = Calendar.getInstance();
//        cal.add(Calendar.MONTH, -1);
//        if(resources.getFlowYearMonth().compareTo(cal.getTime()) > 0){
//            throw new BadRequestException("只能更新上个月的流水记录");
//        }
        // 格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        // 目标年月
        String targetYearMonth = sdf.format(resources.getFlowYearMonth().getTime());
        capitalService.getCapitalInfo(resources.getAccountCompanyId(), targetYearMonth);
    }
    /**
     * 年度账户名称
     * @param resources
     * @return
     */
    private String companyName(CapitalFlow resources) {
    private String accountCompanyName(CapitalFlow resources) {
        // 查询公司数据
        SysCompanyDto sysCompanyDto = sysCompanyServiceImpl.findById(resources.getCompanyId());
        return sysCompanyDto.getLabel();
        CapitalAccountCompanyDto capitalAccountCompanyDto = capitalAccountCompanyService.findById(resources.getAccountCompanyId());
        return capitalAccountCompanyDto.getAccountName();
    }
    /**
     * 关联月度资金公司流账户
     * @return
     */
    public CapitalFlowDto relevanceCapitalFlow(Long accountCompanyId) {
        // 当前系统时间
        Calendar calendar = Calendar.getInstance();
        // 资金流水检索类
        CapitalFlowQueryCriteria criteria = new CapitalFlowQueryCriteria();
        criteria.setAccountCompanyId(accountCompanyId);
        criteria.setFlowYearMonth(DateUtil.getYearMonth(calendar));
        // 查询资金流水
        List<CapitalFlowDto> capitalFlowDtoList = capitalFlowMapper.toDto(capitalFlowRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));;
        // 判断资金流水
        if (capitalFlowDtoList.size() == 0) {
            throw new BadRequestException("没有找到对应的月度资金公司流账户!");
        } else if (capitalFlowDtoList.size() > 1) {
            throw new BadRequestException("找到多条对应的月度资金公司流账户!");
        }
        return capitalFlowDtoList.get(0);
    }
}