package com.sptg.statistics.biz.receiver;

import com.baomidou.mybatisplus.enums.SqlLike;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.sptg.permissions.api.entity.Organization;
import com.sptg.permissions.api.stream.OrgDeleteReceiverInterface;
import com.sptg.statistics.api.entity.*;
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: OrgDeleteConsume
 * description: 机构删除消费者
 *
 *                  
 *            
 */
@Component
@Slf4j
@RequiredArgsConstructor
@EnableBinding(value = { OrgDeleteReceiverInterface.class})
public class OrgDeleteReceiver {

    private final StatisticsAdPushServiceInterface statisticsAdPushServiceInterface;
    private final StatisticsAdPushCountServiceInterface statisticsAdPushCountServiceInterface;
    private final StatisticsAdWatchServiceInterface statisticsAdWatchServiceInterface;
    private final AppMemberLoginRecordsServiceInterface appMemberLoginRecordsServiceInterface;
    private final StatisticsCountServiceInterface statisticsCountServiceInterface;
    private final SysDeviceLogServiceInterface sysDeviceLogServiceInterface;
    private final SysOperationServiceInterface sysOperationServiceInterface;

    @StreamListener(value = OrgDeleteReceiverInterface.INPUT)
    public void input(Organization org){
        //删除广告投放
        Wrapper<StatisticsAdPush> adPushWrapper=new EntityWrapper<>();
        adPushWrapper.like("s_org_position",org.getPosition(),SqlLike.RIGHT);
        this.statisticsAdPushServiceInterface.delete(adPushWrapper);
        //删除广告发布条数记录
        Wrapper<StatisticsAdPushCount> adPushCountWrapper=new EntityWrapper<>();
        adPushCountWrapper.like("s_org_position",org.getPosition(),SqlLike.RIGHT);
        this.statisticsAdPushCountServiceInterface.delete(adPushCountWrapper);
        //删除广告观看记录
        Wrapper<StatisticsAdWatch> adWatchWrapper=new EntityWrapper<>();
        adWatchWrapper.like("s_org_position",org.getPosition(),SqlLike.RIGHT);
        this.statisticsAdWatchServiceInterface.delete(adWatchWrapper);
        //删除app会员登录记录
        Wrapper<AppMemberLoginRecords> appMemberLoginRecordsWrapper=new EntityWrapper<>();
        appMemberLoginRecordsWrapper.like("s_org_position",org.getPosition(),SqlLike.RIGHT);
        this.appMemberLoginRecordsServiceInterface.delete(appMemberLoginRecordsWrapper);
        //删除统计累计数量记录
        Wrapper<StatisticsCount> statisticsCountWrapper=new EntityWrapper<>();
        statisticsCountWrapper.like("s_org_position",org.getPosition(),SqlLike.RIGHT);
        this.statisticsCountServiceInterface.delete(statisticsCountWrapper);
        //删除设备日志
        Wrapper<SysDeviceLog> sysDeviceLogWrapper=new EntityWrapper<>();
        sysDeviceLogWrapper.like("s_org_position",org.getPosition(),SqlLike.RIGHT);
        this.sysDeviceLogServiceInterface.delete(sysDeviceLogWrapper);
        //删除系统操作日志
        Wrapper<SysOperationLog> sysOperationLogWrapper=new EntityWrapper<>();
        sysOperationLogWrapper.like("s_org_position",org.getPosition(),SqlLike.RIGHT);
        this.sysOperationServiceInterface.delete(sysOperationLogWrapper);
    }

}
