package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.busi.bu3;

import cn.estsh.i3plus.ext.mes.api.busi.bu3.ISxProdDataPushNotifyService;
import cn.estsh.i3plus.ext.mes.api.busi.bu3.ISxProdDataPushNotifyStrategyService;
import cn.estsh.i3plus.ext.mes.pojo.model.bu3.SxPushDataNotifyParamModel;
import cn.estsh.i3plus.pojo.model.platform.PushDataNotifyModel;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wangjie
 * @version 1.0
 * @date 2021/1/13 9:28
 **/
@Slf4j
@Service
public class SxProdDataPushNotifyService implements ISxProdDataPushNotifyService {

    @Override
    public List<PushDataNotifyModel> execProdDataPushNotify(PushDataNotifyModel data) {
        return new SxProdDataPushNotifyWatchService(getStrategyClass(data.getPushParam())).exec(data);
    }

    private ISxProdDataPushNotifyStrategyService getStrategyClass(String pushParam) {
        try {
            return (ISxProdDataPushNotifyStrategyService) SpringContextsUtil.getBean(JSONObject.parseObject(pushParam, SxPushDataNotifyParamModel.class).getStrategyClass());
        } catch (Exception e) {
            return null;
        }
    }

}
