package com.zfire.mall.manager.logic.socket;

import com.zfire.mall.manager.bean.socket.ReceiveAndReturnDataBean;
import com.zfire.mall.manager.bean.wallet.RebateMessageBean;
import com.zfire.mall.manager.constant.Constant;
import com.zfire.mall.manager.constant.SocketConstant;
import com.zfire.mall.manager.logic.common.CommonLogic;
import com.zfire.mall.manager.plus.entity.AdminUser;
import com.zfire.mall.manager.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component(SocketConstant.REBATE_ORDER_MSG)
public class RebateOrderProcessor implements NoticeDataProcessor {
    @Autowired
    CommonLogic commonLogic;
    @Autowired
    RedisUtil redisUtil;
    @Override
    public Object processor(String userId, ReceiveAndReturnDataBean data) {
        AdminUser adminUser = commonLogic.getAdminUser(userId);
        //如果是经销商
        RebateMessageBean rm = new RebateMessageBean();
        rm.setHasMessage(false);
        String key;
        if(adminUser.getIsCustomer()){
            key = Constant.RedisPrefix.REBATE_NOTICE + Constant.REDIS_ROLE_DEALERS + adminUser.getCustomerId();
        } else {
            key = Constant.RedisPrefix.REBATE_NOTICE + Constant.REDIS_ROLE_BUSINESS;
        }
        Object message = redisUtil.get(key);
        //获取完数据删除
        if(message != null){
            rm.setHasMessage(true);
            rm.setMessages(message.toString().split("^"));
            redisUtil.del(key);
        }

        data.setRes(rm);

        return data;
    }
}
