package com.sptg.ad.biz.receiver;

import com.baomidou.mybatisplus.enums.SqlLike;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.sptg.ad.api.entity.AdContent;
import com.sptg.ad.api.entity.AdPushContent;
import com.sptg.ad.api.entity.AdPushTask;
import com.sptg.ad.biz.service.AdContentServiceInterface;
import com.sptg.ad.biz.service.AdPushContentServiceInterface;
import com.sptg.ad.biz.service.AdPushTaskServiceInterface;
import com.sptg.permissions.api.entity.Organization;
import com.sptg.permissions.api.stream.OrgDeleteReceiverInterface;
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 AdContentServiceInterface adContentServiceInterface;
    private final AdPushContentServiceInterface adPushContentServiceInterface;
    private final AdPushTaskServiceInterface adPushTaskServiceInterface;

    @StreamListener(value = OrgDeleteReceiverInterface.INPUT)
    public void input(Organization org){
        //删除广告
        Wrapper<AdContent> adContentWrapper=new EntityWrapper<>();
        adContentWrapper.like("s_org_position",org.getPosition(), SqlLike.RIGHT);
        this.adContentServiceInterface.delete(adContentWrapper);

        //删除发布广告
        Wrapper<AdPushContent> adPushContentWrapper=new EntityWrapper<>();
        adPushContentWrapper.like("s_org_position",org.getPosition(), SqlLike.RIGHT);
        this.adPushContentServiceInterface.delete(adPushContentWrapper);

        //删除发布的任务
        Wrapper<AdPushTask> adPushTaskWrapper=new EntityWrapper<>();
        adPushTaskWrapper.like("s_org_position",org.getPosition(), SqlLike.RIGHT);
        this.adPushTaskServiceInterface.delete(adPushTaskWrapper);
    }

}
