赵士淞
2023-04-25 010d1800aad7a37f02c101756f34b873a60c7f9f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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);
    }
}