package me.zhengjie.modules.business.rabbit;
|
|
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
|
@RabbitListener(queues = "business.businessExpenseApply")
|
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);
|
}
|
}
|