package com.docus.server.collect.basic.mq.impl;

import com.docus.core.util.json.JSON;
import com.docus.log.annotation.TrackGroup;
import com.docus.log.context.TrackHelper;
import com.docus.server.collect.basic.mq.IBasicMqCollectService;
import com.docus.server.collect.web.process.VisitorProcessor;
import com.docus.server.collect.web.service.CollectService;
import com.docus.server.record.common.pojo.dto.TBasicDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 每家mq 都不一样，这部分无法预先写好写入，需要根据每家独立编写。
 */
@Slf4j
@Service("basicJmsMqCollectServiceImpl")
public class BasicJmsMqCollectServiceImpl implements IBasicMqCollectService {
    @Resource
    private CollectService collectService;

    @Override
    @TrackGroup(
        group = "JMS_MQ_PASSIVE_INSERT_BASIC", retryKey = "basic",
        beanNames = {"mqBasicConverter", "mqBasicResultImpl"},
        processor = VisitorProcessor.class)
    public void addTBasic(String message) {
        log.info("新增基础数据：{}", message);
        collectService.insertOrUpdateBasic(getValue());
    }

    @Override
    @TrackGroup(
        group = "JMS_MQ_PASSIVE_UPDATE_BASIC", retryKey = "basic",
        beanNames = {"mqBasicConverter", "mqBasicResultImpl"},
        processor = VisitorProcessor.class)
    public void updateTBasic(String message) {
        log.info("修改基础数据：{}", message);
        collectService.insertOrUpdateBasic(getValue());
    }

    public TBasicDTO getValue() {
        return JSON.fromJSON((String) TrackHelper.getValue("jsonStr"), TBasicDTO.class);
    }
}
