package com.cpop.oam.framework.strategy.cloud;

import com.cpop.api.tencent.wxWork.handler.WebHookSendHandler;
import com.cpop.core.base.exception.ServiceException;
import com.cpop.core.utils.SpringUtils;
import com.cpop.oam.business.bo.CloudUnionCallbackBo;
import com.cpop.oam.business.entity.DataImport;
import com.cpop.oam.business.service.DataImportService;
import com.cpop.oam.framework.constant.WebHookKeyConstant;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.ArrayList;

/**
 * @author DB
 * @version 1.0.0
 * @since 2024-01-16 11:44
 */
@Component
public class CloudDataImportCallbackStrategy implements CloudCallbackStrategy {

    /**
     * 回调策略
     */
    @Override
    public void callback(CloudUnionCallbackBo callback) {
        DataImportService dataImportService = SpringUtils.getBean(DataImportService.class);
        DataImport dataImport = dataImportService.getById(callback.getMainId());
        //数据导入异常通知
        try {
            SpringUtils.getBean(WebHookSendHandler.class)
                    .webHookSendText(WebHookKeyConstant.PRODUCT_BOT,
                            new ArrayList<>(),
                            "==========有一条校区数据导入失败==========\n" +
                                    "导入id:" + dataImport.getId() + "\n" +
                                    "校区id:" + dataImport.getStoreId() + "\n",
                            true);
        } catch (IOException ex) {
            throw new ServiceException("发送消息通知失败!");
        }
    }
}
