package com.ms.biz.spi.callback;

import com.alibaba.fastjson.JSON;
import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.api.dto.common.DoudianMessage;
import com.ms.biz.common.R;
import com.ms.biz.common.SPIBaseService;
import com.ms.biz.service.DoudianMsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@ExtensionService("CloudOpenMsgConsumer")
@Slf4j
public class DoudianMsgReceiveService extends SPIBaseService implements ExtensionServiceHandler<List<String>, Void> {

    @Autowired
    private DoudianMsgService doudianMsgService;

    @Override
    public BaseResponse<Void> handle(BaseRequest<List<String>> req) {
        List<String> msgList = req.getData();
        if (msgList == null || msgList.isEmpty()) {
            return R.ok();
        }
        for (String msgStr: msgList) {
            DoudianMessage msg = JSON.parseObject(msgStr, DoudianMessage.class);
        }
        // 处理成功则返回 true  code 0
        return BaseResponse.<Void>builder().success(true).code("0").build();
    }
}
