package com.dxhy.erp.rabbitmq;

import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.constant.RabbitMqConstant;
import com.dxhy.erp.entity.alltax.TaxesSaleRequestInfo;
import com.dxhy.erp.service.AllTaxesSaleService;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * @author user
 */
@Component
@Slf4j
public class ErpReceiver {
    @Autowired
    private AllTaxesSaleService allTaxesSaleService;

    /**
     * 导出消费者
     *
     * @param message
     *            导出数据
     */
    @RabbitHandler
    @RabbitListener(queues = RabbitMqConstant.TO_SALE_COUNT_ITEM)
    public void handleMessage(String message) {
        try {
            log.debug("销项汇总项目分类接收的消息为" + message);
            JSONObject jsonObject = JSONObject.parseObject(message);
            TaxesSaleRequestInfo req = JSONObject.toJavaObject(jsonObject, TaxesSaleRequestInfo.class);
            allTaxesSaleService.countByItem(req.getParam());
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
        }
    }

}
