package com.sptg.statistics.biz.receiver;

import com.sptg.permissions.api.dto.OrgDto;
import com.sptg.permissions.api.stream.OrgTransferReceiverInterface;
import com.sptg.statistics.biz.service.*;
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 StatisticsAdPushServiceInterface statisticsAdPushServiceInterface;
    private final StatisticsAdWatchServiceInterface statisticsAdWatchServiceInterface;
    private final SysDeviceLogServiceInterface sysDeviceLogServiceInterface;
    private final SysOperationServiceInterface sysOperationServiceInterface;
    private final StatisticsAdPushCountServiceInterface statisticsAdPushCountServiceInterface;
    private final StatisticsCountServiceInterface statisticsCountServiceInterface;

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

        //更新机构位置
        this.statisticsAdPushServiceInterface.updateOrgPosition(oldPosition,newPosition);
        this.statisticsAdWatchServiceInterface.updateOrgPosition(oldPosition,newPosition);
        this.sysDeviceLogServiceInterface.updateOrgPosition(oldPosition,newPosition);
        this.sysOperationServiceInterface.updateOrgPosition(oldPosition,newPosition);
        this.statisticsAdPushCountServiceInterface.updateOrgPosition(oldPosition,newPosition);
        this.statisticsCountServiceInterface.updateOrgPosition(oldPosition,newPosition);

    }

}
