package com.sptg.ad.biz.receiver;

import com.sptg.ad.api.entity.AdType;
import com.sptg.ad.biz.service.AdContentServiceInterface;
import com.sptg.ad.biz.service.AdPushContentServiceInterface;
import com.sptg.ad.biz.service.AdPushTaskServiceInterface;
import com.sptg.ad.biz.service.AdTypeServiceInterface;
import com.sptg.permissions.api.dto.OrgDto;
import com.sptg.permissions.api.stream.OrgTransferReceiverInterface;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.stereotype.Component;

/**
 * title: OrgTransferReceiver
 * description:
 *
 *                  
 *            
 */
@Component
@Slf4j
@RequiredArgsConstructor
@EnableBinding(value = { OrgTransferReceiverInterface.class})
public class OrgTransferReceiver {

    private final AdContentServiceInterface adContentServiceInterface;
    private final AdPushContentServiceInterface adPushContentServiceInterface;
    private final AdPushTaskServiceInterface adPushTaskServiceInterface;

    @StreamListener(value = OrgTransferReceiverInterface.INPUT)
    public void input(OrgDto dto){
        if (null == dto){
            return;
        }
        //  旧的机构位置
        String oldPosition = dto.getOrgPosition();
        //  新的机构位置
        String newPosition = dto.getPosition();

        //更新机构位置
        this.adContentServiceInterface.updateOrgPosition(oldPosition,newPosition);
        this.adPushContentServiceInterface.updateOrgPosition(oldPosition,newPosition);
        this.adPushTaskServiceInterface.updateOrgPosition(oldPosition,newPosition);
    }

}

