package yem.base.common.module.version.mq;


import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.mq.MessageAcker;
import kd.bos.mq.MessageConsumer;
import yem.base.common.utils.AttachmentUtil;

import java.util.Map;

/**
 * mq消费者类
 *
 * @author longh
 * @description 用于变更生效时附件面板数据同步
 * @date 2023年12月8日
 */
public class AttachmentSendConsumer implements MessageConsumer {
    Log log = LogFactory.getLog(AttachmentSendConsumer.class);

    @Override
    public void onMessage(Object msg, String messageId, boolean resend, MessageAcker acker) {
        log.info("自定义AttachmentSendConsumer开始消费");
        try {
            Map<String, DynamicObject> objMap = (Map<String, DynamicObject>) msg;
            if (objMap != null) {
                DynamicObject fromObj = objMap.get("from");
                DynamicObject toObj = objMap.get("to");
                AttachmentUtil.uploadAttachmentPanel(fromObj, toObj);
            }
            acker.ack(messageId);
        } catch (Exception e) {
            acker.discard(messageId);// 废弃
            log.error(e);
        }

    }

}
