package com.miaxis.newgzpt.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miaxis.common.annotation.DataSource;
import com.miaxis.common.enums.DataSourceTypeEnum;
import com.miaxis.newgzpt.domain.GzptVideoVip;
import com.miaxis.newgzpt.dto.GzptVideoVipDTO;
import com.miaxis.newgzpt.mapper.GzptVideoVipMapper;
import com.miaxis.newgzpt.service.IGzptVideoVipService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;


/**
 * <p>
 * 视频VIP表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-01-27
 */
@Service
@DataSource(value = DataSourceTypeEnum.NEWGZPT)
public class GzptVideoVipServiceImpl extends ServiceImpl<GzptVideoVipMapper, GzptVideoVip> implements IGzptVideoVipService {


    @Resource
    private GzptVideoVipMapper mapper;

    @Override
    public void saveGzptVideoVip(GzptVideoVip gzptVideoVip) {
        mapper.saveGzptVideoVip(gzptVideoVip);
    }


    @Override
    public void updateGzptVideoVipByUserId(GzptVideoVip gzptVideoVip) {
        mapper.updateGzptVideoVipByUserId(gzptVideoVip);
    }

    @Override
    public GzptVideoVip getGzptVideoVipByUserId(GzptVideoVipDTO gzptVideoVipDTO) {
        GzptVideoVip vv =  mapper.getGzptVideoVipByUserId(gzptVideoVipDTO);
        Date now = new Date();
        if(vv!=null) {
            if(vv.getSubject2()!=null) {
                if(vv.getSubject2().compareTo(now)<0){
                    vv.setSubject2(null);
                }
            }
            if(vv.getSubject3()!=null) {
                if(vv.getSubject3().compareTo(now)<0){
                    vv.setSubject3(null);
                }
            }
            return vv;
        } else {
            GzptVideoVip v2 = new GzptVideoVip();
            return v2;
        }
    }

    @Override
    public GzptVideoVip getGzptVideoVipByUserIdForLocal(GzptVideoVipDTO gzptVideoVipDTO) {
        return mapper.getGzptVideoVipByUserId(gzptVideoVipDTO);
    }

    @Override
    public int removeByUserId(Long userId) {
      return mapper.removeByUserId(userId);
    }

}
