package com.miaxis.newgzpt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miaxis.common.annotation.DataSource;
import com.miaxis.common.enums.DataSourceTypeEnum;
import com.miaxis.common.utils.StringUtils;
import com.miaxis.newgzpt.domain.GzptSchActivation;
import com.miaxis.newgzpt.dto.GzptSchActivationDTO;
import com.miaxis.newgzpt.mapper.GzptSchActivationMapper;
import com.miaxis.newgzpt.service.IGzptSchActivationService;
import org.springframework.stereotype.Service;

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


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


    @Resource
    private GzptSchActivationMapper mapper;


    @Override
    public void saveSchActivation(GzptSchActivation schActivation) {
        mapper.saveSchActivation(schActivation);
    }

    @Override
    public int isSchActivation(Long stuId) {
        GzptSchActivation schActivation= mapper.getSchActivation(stuId);
        if(schActivation!=null){
            if(schActivation.getIsDel()!=null && schActivation.getIsDel()==0) {
                return 1;
            } else if (schActivation.getIsDel()!=null && schActivation.getIsDel()==1) {
                return 2;
            }
            return 0;
        } else {
            return 0;
        }
    }

    @Override
    public void delSchActivationByStuId(Long stuId) {
        mapper.delSchActivationByStuId(stuId);
    }

    @Override
    public void upDelSchActivationByStuId(Long stuId,Integer state) { mapper.upDelSchActivationByStuId(stuId,state); }

    @Override
    public List<GzptSchActivation> selectSchActivationList(GzptSchActivationDTO gzptSchActivationDTO) {
        QueryWrapper<GzptSchActivation> queryWrapper = new QueryWrapper<GzptSchActivation>();
        if (!StringUtils.isEmpty(gzptSchActivationDTO.getJxmc())){;
            queryWrapper.like("JXMC",gzptSchActivationDTO.getJxmc());
        }
        if (gzptSchActivationDTO.getUserId()!=null){;
            queryWrapper.eq("USER_ID",gzptSchActivationDTO.getUserId());
        }
        if (gzptSchActivationDTO.getIsDel()!=null){;
            queryWrapper.eq("IS_DEL",gzptSchActivationDTO.getIsDel());
        }
        List<GzptSchActivation> list = this.list(queryWrapper);
        return list;
    }

}
