package com.qmth.themis.backend.listener.service.impl;

import com.google.gson.Gson;
import com.qmth.themis.backend.listener.service.MqAdminLogicService;
import com.qmth.themis.business.constant.SystemConstant;
import com.qmth.themis.business.entity.TMRocketMessage;
import com.qmth.themis.business.service.TMRocketMessageService;
import com.qmth.themis.business.util.JacksonUtil;
import com.qmth.themis.business.util.RedisUtil;
import com.qmth.themis.business.dto.MqDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;

/** 
* @Description: mq 管理端执行逻辑 impl
* @Param:  
* @return:  
* @Author: wangliang
* @Date: 2020/8/3 
*/ 
@Service
public class MqAdminLogicServiceImpl implements MqAdminLogicService {
    private final static Logger log = LoggerFactory.getLogger(MqAdminLogicServiceImpl.class);

    @Resource
    RedisUtil redisUtil;

    @Resource
    TMRocketMessageService tmRocketMessageService;

    @Override
    @Transactional
    public void execMqMaxReconsumeTime(MqDto mqDto, String key) {
        //超过最大重试次数，保存到数据库，后续可以发短信通知系统管理人员
        Gson gson = new Gson();
        mqDto.setAck(SystemConstant.POSION_ACK_TYPE);
        TMRocketMessage tmRocketMessage = gson.fromJson(gson.toJson(mqDto), TMRocketMessage.class);
        tmRocketMessage.setBody(JacksonUtil.parseJson(tmRocketMessage.getBody()));
        tmRocketMessageService.saveOrUpdate(tmRocketMessage);
        redisUtil.delete(key, mqDto.getId());
    }

    @Override
    @Transactional
    public void execMqAdminLogic(MqDto mqDto, String key) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {

    }
}
