//package com.zcloud.controller.mq;
//
//import com.alibaba.fastjson.JSON;
//import com.zcloud.dto.TenCorpDto;
//import com.zcloud.entity.PageData;
//import com.zcloud.mapper.dsno2.mq.MqMessageLogMapper;
//import com.zcloud.service.eightwork.HotworkService;
//import com.zcloud.service.mq.LogService;
//import com.zcloud.service.mq.SendMessageService;
//import com.zcloud.util.DateUtil;
//import com.zcloud.util.MqUtil;
//import com.zcloud.util.Warden;
//import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
//import org.apache.rocketmq.spring.annotation.SelectorType;
//import org.apache.rocketmq.spring.core.RocketMQListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.util.Date;
//
///**
// * 说明：消费某个 topic 下指定 tag 的消息 对接课件DEMO
// * 作者：wangxuan
// * 官网：www.zcloudchina.com
// */
//@Component
//@RocketMQMessageListener(consumerGroup = "${mq.group.eightWork}",
//        topic = "${mq.topic.eightWork}",
//        selectorType = SelectorType.TAG)
//public class EightWorkListener implements RocketMQListener<String> {
//
//    @Resource
//    private SendMessageService sendMessageService;
//    @Resource
//    private LogService logService;
//    @Resource
//    private MqMessageLogMapper mqMessageLogMapper;
//    @Autowired
//    private HotworkService hotworkService;
//
//    @Override
//    public void onMessage(String message) {
//        TenCorpDto data = JSON.parseObject(message, TenCorpDto.class);
//        PageData log = data.getPd();
//        log.put("MESSAGE_LOG_ID", Warden.get32UUID());
//        log.put("CREATE_TIME", DateUtil.getTime());
//        log.put("PRODUCER_NAME",data.getProducer_name());
//        log.put("TYPE","1");
//        try {
//            System.out.println("消费者:" + data.toString());
//            Date limit_date = MqUtil.dateFormat(data.getTime_stamp());
//            if (limit_date.getTime() - new Date().getTime() > 1000) {
//                sendMessageService.sendDelayQueue(data);
//                log.put("DIGESTION_FLAG","0");
//            } else {
//                switch (data.getMessage()){
////                    case "confined-space":
////                        System.out.println("受限空间模块消费");
////                        confinedSpaceService.cancel(data.getData());
////                        break;
////                    case "electricity":
////                        System.out.println("临时用电模块消费");
////                        electricityService.cancel(data.getData());
////                        break;
//                    case "hot-work":
//                        System.out.println("动火模块消费");
//                        hotworkService.cancel(data.getData());
//                        break;
//                    default:
//                        System.out.println("异常模块不消费");
//                        throw new RuntimeException("未找到对应的消费者");
//                }
//                log.put("DIGESTION_FLAG","1");
//            }
//            mqMessageLogMapper.save(log);
//        } catch (Exception e) {
//            e.printStackTrace();
//            logService.saveErrorMessage(log,e.getMessage());
//            throw new RuntimeException(e);
//        }
//    }
//
//}
//
