赵士淞
2023-04-28 377e6fd55b5e57f9d4d237597b521eb9734c9f4c
营业费用(Flowable)
6 files modified
187 ■■■■■ changed files
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/business/rabbit/BusinessExpenseRabbit.java 25 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/business/service/impl/BusinessExpenseReimbursementServiceImpl.java 10 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/business/service/impl/BusinessExpenseServiceImpl.java 65 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/capital/service/impl/CapitalAccountMoneyServiceImpl.java 55 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/capitalFlow/service/CapitalFlowExpendService.java 8 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/capitalFlow/service/impl/CapitalFlowExpendServiceImpl.java 24 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/business/rabbit/BusinessExpenseRabbit.java
@@ -2,20 +2,12 @@
import com.alibaba.fastjson.JSON;
import me.zhengjie.modules.business.service.BusinessExpenseService;
import me.zhengjie.modules.business.service.BusinessPlanService;
import me.zhengjie.modules.business.service.dto.BusinessExpenseDto;
import me.zhengjie.modules.business.service.dto.BusinessExpenseReimbursementDto;
import me.zhengjie.modules.business.service.dto.BusinessPlanDto;
import me.zhengjie.modules.capitalFlow.service.CapitalFlowExpendService;
import me.zhengjie.modules.constant.Constant;
import me.zhengjie.modules.system.domain.DictDetail;
import me.zhengjie.modules.system.repository.DictDetailRepository;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.Map;
@Component
@@ -23,29 +15,12 @@
public class BusinessExpenseRabbit {
    @Autowired
    private BusinessPlanService businessPlanService;
    @Autowired
    private DictDetailRepository dictDetailRepository;
    @Autowired
    private CapitalFlowExpendService capitalFlowExpendService;
    @Autowired
    private BusinessExpenseService businessExpenseService;
    @RabbitHandler
    public void process(Map<String, Object> message) {
        // Map 转 实体类
        BusinessExpenseDto businessExpenseDto = JSON.parseObject(JSON.toJSONString(message), BusinessExpenseDto.class);
        // 营业计划
        BusinessPlanDto businessPlanDto = businessPlanService.findById(businessExpenseDto.getBusinessPlanId());
        // 费用类型
        DictDetail dictDetail = dictDetailRepository.findByDictNameAndValue(Constant.EXPENSE_TYPE, businessExpenseDto.getExpenseType());
        // 费用金额
        BigDecimal amount = new BigDecimal(0);
        for (BusinessExpenseReimbursementDto businessExpenseReimbursementDto : businessExpenseDto.getBusinessExpenseReimbursementDtoList()) {
            amount = amount.add(businessExpenseReimbursementDto.getReimbursementAmount());
        }
        // 关联创建
        capitalFlowExpendService.flowableCreate(Constant.ACCOUNT_TYPE_QIYUAN, businessPlanDto.getBusinessContent() + " - " + dictDetail.getLabel(), amount);
        // 新增营业费用
        businessExpenseService.create(businessExpenseDto);
    }
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/business/service/impl/BusinessExpenseReimbursementServiceImpl.java
@@ -15,9 +15,9 @@
*/
package me.zhengjie.modules.business.service.impl;
import me.zhengjie.modules.business.domain.BusinessExpense;
import me.zhengjie.modules.business.domain.BusinessExpenseReimbursement;
import me.zhengjie.modules.business.service.BusinessExpenseService;
import me.zhengjie.modules.business.service.dto.BusinessExpenseDto;
import me.zhengjie.modules.business.repository.BusinessExpenseRepository;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
@@ -52,7 +52,7 @@
    private final BusinessExpenseReimbursementRepository businessExpenseReimbursementRepository;
    private final BusinessExpenseReimbursementMapper businessExpenseReimbursementMapper;
    private final BusinessExpenseService businessExpenseService;
    private final BusinessExpenseRepository businessExpenseRepository;
    @Override
    public Map<String,Object> queryAll(BusinessExpenseReimbursementQueryCriteria criteria, Pageable pageable){
@@ -65,8 +65,8 @@
                BusinessExpenseReimbursementDto businessExpenseReimbursementDto = businessExpenseReimbursementMapper.toDto(t);
                // 获取营业费用
                BusinessExpenseDto businessExpenseDto = businessExpenseService.findById(businessExpenseReimbursementDto.getBusinessExpenseId());
                businessExpenseReimbursementDto.setBusinessExpenseType(businessExpenseDto.getExpenseType());
                BusinessExpense businessExpense = businessExpenseRepository.findById(businessExpenseReimbursementDto.getBusinessExpenseId()).orElseGet(BusinessExpense::new);
                businessExpenseReimbursementDto.setBusinessExpenseType(businessExpense.getExpenseType());
                // 返回处理好的DTO
                return businessExpenseReimbursementDto;
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/business/service/impl/BusinessExpenseServiceImpl.java
@@ -18,19 +18,21 @@
import me.zhengjie.modules.business.domain.BusinessExpense;
import me.zhengjie.modules.business.domain.BusinessExpenseReimbursement;
import me.zhengjie.modules.business.repository.BusinessExpenseReimbursementRepository;
import me.zhengjie.modules.business.service.BusinessExpenseReimbursementService;
import me.zhengjie.modules.business.service.BusinessPlanService;
import me.zhengjie.modules.business.service.dto.BusinessExpenseReimbursementDto;
import me.zhengjie.modules.business.service.dto.BusinessPlanDto;
import me.zhengjie.modules.business.service.dto.*;
import me.zhengjie.modules.business.service.mapstruct.BusinessExpenseReimbursementMapper;
import me.zhengjie.modules.capitalFlow.service.CapitalFlowExpendService;
import me.zhengjie.modules.constant.Constant;
import me.zhengjie.modules.project.service.ProjectService;
import me.zhengjie.modules.project.service.dto.ProjectDto;
import me.zhengjie.modules.system.domain.DictDetail;
import me.zhengjie.modules.system.repository.DictDetailRepository;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.business.repository.BusinessExpenseRepository;
import me.zhengjie.modules.business.service.BusinessExpenseService;
import me.zhengjie.modules.business.service.dto.BusinessExpenseDto;
import me.zhengjie.modules.business.service.dto.BusinessExpenseQueryCriteria;
import me.zhengjie.modules.business.service.mapstruct.BusinessExpenseMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -64,6 +66,9 @@
    private final ProjectService projectService;
    private final BusinessExpenseReimbursementRepository businessExpenseReimbursementRepository;
    private final BusinessExpenseReimbursementMapper businessExpenseReimbursementMapper;
    private final CapitalFlowExpendService capitalFlowExpendService;
    private final DictDetailRepository dictDetailRepository;
    private final BusinessExpenseReimbursementService businessExpenseReimbursementService;
    @Override
    public Map<String,Object> queryAll(BusinessExpenseQueryCriteria criteria, Pageable pageable){
@@ -117,6 +122,8 @@
        BusinessExpense businessExpense = businessExpenseRepository.save(businessExpenseMapper.toEntity(resources));
        // 保存相关营业费用明细
        saveBusinessExpenseReimbursement(resources.getBusinessExpenseReimbursementDtoList(), businessExpense.getId());
        // 关联新增
        accountCreate(resources);
        return findById(businessExpense.getId());
    }
@@ -125,10 +132,17 @@
    public void update(BusinessExpenseDto resources) {
        BusinessExpense businessExpense = businessExpenseRepository.findById(resources.getId()).orElseGet(BusinessExpense::new);
        ValidationUtil.isNull( businessExpense.getId(),"BusinessExpense","id",resources.getId());
        // 关联删除
        accountDelete(businessExpense);
        businessExpense.copy(businessExpenseMapper.toEntity(resources));
        businessExpenseRepository.save(businessExpense);
        // 保存相关营业费用明细
        saveBusinessExpenseReimbursement(resources.getBusinessExpenseReimbursementDtoList(), businessExpense.getId());
        // 实体类 转 DTO
        BusinessExpenseDto businessExpenseDto = businessExpenseMapper.toDto(businessExpense);
        businessExpenseDto.setBusinessExpenseReimbursementDtoList(resources.getBusinessExpenseReimbursementDtoList());
        // 关联新增
        accountCreate(businessExpenseDto);
    }
    /**
@@ -153,6 +167,10 @@
    @Override
    public void deleteAll(Long[] ids) {
        for (Long id : ids) {
            BusinessExpense businessExpense = businessExpenseRepository.findById(id).orElseGet(BusinessExpense::new);
            ValidationUtil.isNull( businessExpense.getId(),"BusinessExpense","id",id);
            // 关联删除
            accountDelete(businessExpense);
            businessExpenseRepository.deleteById(id);
        }
    }
@@ -174,4 +192,43 @@
        }
        FileUtil.downloadExcel(list, response);
    }
    /**
     * 关联创建
     * @param resources
     */
    private void accountCreate(BusinessExpenseDto resources) {
        // 营业计划
        BusinessPlanDto businessPlanDto = businessPlanService.findById(resources.getBusinessPlanId());
        // 费用类型
        DictDetail dictDetail = dictDetailRepository.findByDictNameAndValue(Constant.EXPENSE_TYPE, resources.getExpenseType());
        // 费用金额
        BigDecimal amount = new BigDecimal(0);
        for (BusinessExpenseReimbursementDto businessExpenseReimbursementDto : resources.getBusinessExpenseReimbursementDtoList()) {
            amount = amount.add(businessExpenseReimbursementDto.getReimbursementAmount());
        }
        // 关联创建
        capitalFlowExpendService.flowableCreate(Constant.ACCOUNT_TYPE_QIYUAN, businessPlanDto.getBusinessContent() + " - " + dictDetail.getLabel(), amount);
    }
    /**
     * 关联删除
     * @param resources
     */
    private void accountDelete(BusinessExpense resources) {
        // 营业计划
        BusinessPlanDto businessPlanDto = businessPlanService.findById(resources.getBusinessPlanId());
        // 费用类型
        DictDetail dictDetail = dictDetailRepository.findByDictNameAndValue(Constant.EXPENSE_TYPE, resources.getExpenseType());
        // 费用金额
        BigDecimal amount = new BigDecimal(0);
        BusinessExpenseReimbursementQueryCriteria businessExpenseReimbursementQueryCriteria = new BusinessExpenseReimbursementQueryCriteria();
        businessExpenseReimbursementQueryCriteria.setBusinessExpenseId(resources.getId());
        List<BusinessExpenseReimbursementDto> businessExpenseReimbursementDtoList = businessExpenseReimbursementService.queryAll(businessExpenseReimbursementQueryCriteria);
        for (BusinessExpenseReimbursementDto businessExpenseReimbursementDto : businessExpenseReimbursementDtoList) {
            amount = amount.add(businessExpenseReimbursementDto.getReimbursementAmount());
        }
        // 关联删除
        capitalFlowExpendService.flowableDelete(Constant.ACCOUNT_TYPE_QIYUAN, businessPlanDto.getBusinessContent() + " - " + dictDetail.getLabel(), amount);
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/capital/service/impl/CapitalAccountMoneyServiceImpl.java
@@ -30,12 +30,10 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
import java.math.BigDecimal;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
/**
* @website https://eladmin.vip
@@ -148,4 +146,53 @@
            }
        }
    }
    /**
     * 关联年度资金现金流账户
     * @return
     */
    public CapitalAccountMoneyDto relevanceCapitalAccountMoney() {
        // 当前系统时间
        Calendar calendar = Calendar.getInstance();
        // 年度资金账户(现金流)检索类
        CapitalAccountMoneyQueryCriteria criteria = new CapitalAccountMoneyQueryCriteria();
        criteria.setAccountYear(DateUtil.getYear(calendar));
        // 查询年度资金账户(现金流)
        List<CapitalAccountMoneyDto> capitalAccountMoneyDtoList = capitalAccountMoneyMapper.toDto(capitalAccountMoneyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
        // 判断年度资金账户(现金流)
        if (capitalAccountMoneyDtoList.size() == 0) {
            throw new BadRequestException("没有找到对应的年度资金现金流账户!");
        } else if (capitalAccountMoneyDtoList.size() > 1) {
            throw new BadRequestException("找到多条对应的年度资金现金流账户!");
        }
        return capitalAccountMoneyDtoList.get(0);
    }
    /**
     * 关联年度资金现金流账户(增加金额)
     * @param capitalAccountMoneyDto
     * @param amount
     */
    public void relevanceCapitalAccountMoneyAdd(CapitalAccountMoneyDto capitalAccountMoneyDto, BigDecimal amount) {
        // 账户金额
        BigDecimal accountAmount = capitalAccountMoneyDto.getAccountAmount();
        accountAmount = accountAmount.add(amount);
        capitalAccountMoneyDto.setAccountAmount(accountAmount);
        // 保存
        capitalAccountMoneyRepository.save(capitalAccountMoneyMapper.toEntity(capitalAccountMoneyDto));
    }
    /**
     * 关联年度资金现金流账户(减少金额)
     * @param capitalAccountMoneyDto
     * @param amount
     */
    public void relevanceCapitalAccountMoneySubtract(CapitalAccountMoneyDto capitalAccountMoneyDto, BigDecimal amount) {
        // 账户金额
        BigDecimal accountAmount = capitalAccountMoneyDto.getAccountAmount();
        accountAmount = accountAmount.subtract(amount);
        capitalAccountMoneyDto.setAccountAmount(accountAmount);
        // 保存
        capitalAccountMoneyRepository.save(capitalAccountMoneyMapper.toEntity(capitalAccountMoneyDto));
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/capitalFlow/service/CapitalFlowExpendService.java
@@ -90,4 +90,12 @@
     * @param amount
     */
    void flowableCreate(String accountType, String title, BigDecimal amount);
    /**
     * 关联删除
     * @param accountType
     * @param title
     * @param amount
     */
    void flowableDelete(String accountType, String title, BigDecimal amount);
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/capitalFlow/service/impl/CapitalFlowExpendServiceImpl.java
@@ -16,7 +16,9 @@
package me.zhengjie.modules.capitalFlow.service.impl;
import me.zhengjie.modules.capital.service.dto.CapitalAccountCompanyDto;
import me.zhengjie.modules.capital.service.dto.CapitalAccountMoneyDto;
import me.zhengjie.modules.capital.service.impl.CapitalAccountCompanyServiceImpl;
import me.zhengjie.modules.capital.service.impl.CapitalAccountMoneyServiceImpl;
import me.zhengjie.modules.capitalFlow.domain.CapitalFlowExpend;
import me.zhengjie.modules.capitalFlow.service.dto.CapitalFlowDto;
import me.zhengjie.utils.*;
@@ -51,6 +53,7 @@
    private final CapitalFlowExpendRepository capitalFlowExpendRepository;
    private final CapitalFlowExpendMapper capitalFlowExpendMapper;
    private final CapitalFlowServiceImpl capitalFlowServiceImpl;
    private final CapitalAccountMoneyServiceImpl capitalAccountMoneyServiceImpl;
    private final CapitalAccountCompanyServiceImpl capitalAccountCompanyServiceImpl;
    @Override
@@ -141,6 +144,10 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void flowableCreate(String accountType, String title, BigDecimal amount) {
        // 关联年度资金现金流账户
        CapitalAccountMoneyDto capitalAccountMoneyDto = capitalAccountMoneyServiceImpl.relevanceCapitalAccountMoney();
        // 关联年度资金现金流账户(减少金额)
        capitalAccountMoneyServiceImpl.relevanceCapitalAccountMoneySubtract(capitalAccountMoneyDto, amount);
        // 关联年度资金公司流账户
        CapitalAccountCompanyDto capitalAccountCompanyDto = capitalAccountCompanyServiceImpl.relevanceCapitalAccountCompany(accountType);
        // 关联年度资金公司流账户(减少金额)
@@ -151,6 +158,23 @@
        relevanceCapitalFlowExpendAdd(capitalFlowDto.getId(), title, amount);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void flowableDelete(String accountType, String title, BigDecimal amount) {
        // 关联年度资金现金流账户
        CapitalAccountMoneyDto capitalAccountMoneyDto = capitalAccountMoneyServiceImpl.relevanceCapitalAccountMoney();
        // 关联年度资金现金流账户(增加金额)
        capitalAccountMoneyServiceImpl.relevanceCapitalAccountMoneyAdd(capitalAccountMoneyDto, amount);
        // 关联年度资金公司流账户
        CapitalAccountCompanyDto capitalAccountCompanyDto = capitalAccountCompanyServiceImpl.relevanceCapitalAccountCompany(accountType);
        // 关联年度资金公司流账户(增加金额)
        capitalAccountCompanyServiceImpl.relevanceCapitalAccountCompanyAdd(capitalAccountCompanyDto, amount);
        // 关联月度资金公司流账户
        CapitalFlowDto capitalFlowDto = capitalFlowServiceImpl.relevanceCapitalFlow(capitalAccountCompanyDto.getId());
        // 关联资金流水支出(减少金额)
        relevanceCapitalFlowExpendSubtract(capitalFlowDto.getId(), title, amount);
    }
    /**
     * 关联资金流水支出(增加金额)
     * @param capitalFlowId