//package com.base.step.mq;
//
//
//import com.base.orbit.mq.model.enums.MessageTypeEnums;
//import com.base.orbit.mq.topics.TopicConst;
//import com.base.orbit.utils.DateUtils;
//import com.base.step.aop.IndicationStateEnums;
//import com.base.step.aop.IndicationStepEnums;
//import com.plan.api.model.PlanIndicatorBodyDTO;
//import com.plan.api.model.PlanIndicatorStateDTO;
//import com.plan.api.model.PlanIndicatorStepDTO;
//import com.plan.api.model.StepDtoMapTool;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//
//@Service
//public class MqService {
//
//    @Resource
//    StepMqProducer stepMqProducer;
//
//    /**
//     * 执行状态反馈
//     */
//    @Async
//    public void sendIndicatorState(String taskId, IndicationStateEnums state, IndicationStepEnums[] steps) throws InterruptedException {
//
//        for (int i = 0; i < steps.length; i++) {
//            PlanIndicatorStateDTO planIndicatorStateDTO = new PlanIndicatorStateDTO();
//            //  消息头
//            planIndicatorStateDTO.setCreationTime(DateUtils.dateTimeNow());
//            planIndicatorStateDTO.setOriginator("YKSC");
//            planIndicatorStateDTO.setRecipient("JCPT");
//            planIndicatorStateDTO.setMessageType(MessageTypeEnums.TASKSTATE.toString());
//            planIndicatorStateDTO.setMessageId(planIndicatorStateDTO.getMessageType() + "_" + planIndicatorStateDTO.getOriginator() + "_" + planIndicatorStateDTO.getCreationTime());
//            //  消息体
//            String stepVal = steps[i].getType();
//            PlanIndicatorStepDTO planIndicatorStepDTO = new PlanIndicatorStepDTO();
//            planIndicatorStepDTO.setStepName(steps[i].getValue());
//            planIndicatorStepDTO.setStepVal(stepVal);
//            planIndicatorStepDTO.setStatus(state.getType());
////            planIndicatorStepDTO.setTimeStamp(DateUtils.dateTimeNow());
//            //  添加前，先判断当前任务下 是否已经存在该步骤
//            if (!StepDtoMapTool.getStepInfosByTaskId(taskId).contains(planIndicatorStepDTO)) {
//                StepDtoMapTool.stepInfo.add(planIndicatorStepDTO);
//                StepDtoMapTool.add(taskId, StepDtoMapTool.stepInfo);
//            }
//            //  设置信息包装类型
//            PlanIndicatorBodyDTO planIndicatorBodyDTO = new PlanIndicatorBodyDTO();
//            planIndicatorBodyDTO.setTaskId(taskId);
//            planIndicatorBodyDTO.setStepInfo(StepDtoMapTool.stepInfo);
//            planIndicatorStateDTO.setBody(planIndicatorBodyDTO);
//            Thread.sleep(2000l);
//            stepMqProducer.push(TopicConst.YKSC_JCPT, "data", planIndicatorStateDTO);
//            //  如果当前任务已经完成，则清除当前所有步骤
//            if (steps[i].getType().equals(IndicationStepEnums.END.getType())) {
//                StepDtoMapTool.remove(taskId);
//                StepDtoMapTool.stepInfo.clear();
//            }
//        }
//    }
//}
