赵士淞
2023-04-25 010d1800aad7a37f02c101756f34b873a60c7f9f
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/business/rabbit/BusinessExpenseRabbit.java
@@ -2,12 +2,20 @@
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
@@ -15,13 +23,30 @@
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);
    }
}