package io.renren.modules.admin.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.admin.dao.SignInfoDao;
import io.renren.modules.admin.entity.SignInfoEntity;
import io.renren.modules.admin.service.SignInfoService;

@Service("signInfoService")
public class SignInfoServiceImpl extends ServiceImpl<SignInfoDao, SignInfoEntity> implements SignInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Long meetingId = Long.valueOf(params.get("meetingId").toString());
        String key = params.containsKey("key") ? params.get("key").toString() : null;
        String badge = params.containsKey("badge") ? params.get("badge").toString() : null;
        String isPay = params.containsKey("isPay") ? params.get("isPay").toString() : null;
        String isServer = params.containsKey("isServer") ? params.get("isServer").toString() : null;
        // Integer isPay2 = params.containsKey("isPay") ? Integer.valueOf(params.get("isPay").toString()) : null;
 
        QueryWrapper<SignInfoEntity> thatqWrapper = new QueryWrapper<SignInfoEntity>();
        thatqWrapper.eq("meeting_id", meetingId);
        if (StringUtils.isNotBlank(badge)) {
            thatqWrapper.eq("badge", Integer.valueOf(badge));
        }
        if (StringUtils.isNotBlank(isPay)) {
            thatqWrapper.eq("is_pay", Integer.valueOf(isPay));
        }
        if (StringUtils.isNotBlank(isServer)) {
            Integer isServerVal = Integer.valueOf(isServer);
            if (isServerVal == 0) {
                thatqWrapper.isNull("servername");
            } else {
                thatqWrapper.isNotNull("servername");
            }
        }

        if (StringUtils.isNotBlank(key)) {
            thatqWrapper.like("truename", key).or().like("servername", key);
        }
        IPage<SignInfoEntity> page = this.page(
                new Query<SignInfoEntity>().getPage(params),
                thatqWrapper
        );

        return new PageUtils(page);
    }

    public List<SignInfoEntity> getList(Map<String, Object> params) {
        Long meetingId = Long.valueOf(params.get("meetingId").toString());
        String key = params.containsKey("key") ? params.get("key").toString() : null;
        String badge = params.containsKey("badge") ? params.get("badge").toString() : null;
        String isPay = params.containsKey("isPay") ? params.get("isPay").toString() : null;
        String isServer = params.containsKey("isServer") ? params.get("isServer").toString() : null;
 
        QueryWrapper<SignInfoEntity> thatqWrapper = new QueryWrapper<SignInfoEntity>();
        thatqWrapper.eq("meeting_id", meetingId);
        if (StringUtils.isNotBlank(badge)) {
            thatqWrapper.eq("badge", Integer.valueOf(badge));
        }
        if (StringUtils.isNotBlank(isPay)) {
            thatqWrapper.eq("is_pay", Integer.valueOf(isPay));
        }
        if (StringUtils.isNotBlank(isServer)) {
            Integer isServerVal = Integer.valueOf(isServer);
            if (isServerVal == 0) {
                thatqWrapper.isNull("servername");
            } else {
                thatqWrapper.isNotNull("servername");
            }
        }

        if (StringUtils.isNotBlank(key)) {
            thatqWrapper.like("truename", key).or().like("servername", key);
        }

        List<SignInfoEntity> list = this.list(thatqWrapper);

        return list;
    }
}