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.AttendersviewDao;
import io.renren.modules.admin.entity.AttendersviewEntity;
import io.renren.modules.admin.service.AttendersviewService;


@Service("attendersviewService")
public class AttendersviewServiceImpl extends ServiceImpl<AttendersviewDao, AttendersviewEntity> implements AttendersviewService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Long meetingId = Long.valueOf((String) params.get("meetingId"));
        String key = params.containsKey("key") ? (String) params.get("key") : null;
        IPage<AttendersviewEntity> page = this.page(new Query<AttendersviewEntity>().getPage(params),
                new QueryWrapper<AttendersviewEntity>().eq("meeting_id", meetingId)
                        .like(StringUtils.isNotBlank(key), "truename", key).or()
                        .like(StringUtils.isNotBlank(key), "phone", key).or()
                        .like(StringUtils.isNotBlank(key), "organization", key));

        return new PageUtils(page);
    }

    @Override
    public List<AttendersviewEntity> listall(Long mid) {
        return this.list(new QueryWrapper<AttendersviewEntity>().eq("meeting_id", mid));
    }

    @Override
    public List<AttendersviewEntity> listall(Long mid, String... columns) {
        return this.list(new QueryWrapper<AttendersviewEntity>().eq("meeting_id", mid).select(columns));
    }

    @Override
    public AttendersviewEntity getBySymbolAndMid(String symbol, Long meetingId) {
        AttendersviewEntity attenders = this.getOne(new QueryWrapper<AttendersviewEntity>().eq("symbol", symbol).eq("meeting_id",meetingId));
        return attenders;
    }
}