package com.cyksj.service.order.post;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
import com.cyksj.mapper.OrderDonMapper;
import com.cyksj.mapper.UserMapper;
import com.cyksj.mapper.order.OrderDonPostMapper;
import com.cyksj.model.entity.OrderDon;
import com.cyksj.model.entity.User;
import com.cyksj.redis.RedisService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author chan
 * @className AbstractPostDataService
 * @description 数据回传抽象类
 * @date 2020/11/23 3:33 下午
 */
@Slf4j
public abstract class AbstractPostDataService {

    protected static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();

    @Autowired
    protected OrderDonMapper orderDonMapper;

    @Autowired
    protected UserMapper userMapper;

    @Autowired
    protected RedisService redisService;

    @Autowired
    protected OrderDonPostMapper orderPostMapper;

    /**
     * @description  回传数据方法
     * @author chan
     * @date 2020-11-23 3:56 下午
     * @param
     * @return
     */
    public abstract void postData(Long orderId, String callBack, String evenType) throws Exception;


    public void delCorpCustomerAcquistionClickIdByOrderId(Long orderId){
        if(orderId != null && orderId != 0 ){
            OrderDon orderDon = orderDonMapper.selectById(orderId);
            if (orderDon  == null) {
                log.error("删除 用户获客助手 广告平台 clickId error:{}", orderId + "订单不存在.");
                return;
            }

            if (orderDon.getUserId() != null && orderDon.getUserId() != 0) {
                User user = userMapper.selectById(orderDon.getUserId());
                if (user != null) {
                    redisService.del(String.format(RedisService.key.CORP_CUSTOMER_ACQUISTION_UNIONID_CLICKID.getName(),user.getUnionid()));
                    log.info("删除用户获客助手广告平台 userId:{}",user.getId());
                }
            }
        }
    }

}
