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

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
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.SignviewDao;
import io.renren.modules.admin.entity.SignviewEntity;
import io.renren.modules.admin.service.SignviewService;

@Service("signviewService")
public class SignviewServiceImpl extends ServiceImpl<SignviewDao, SignviewEntity> implements SignviewService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Long meetingId = Long.valueOf(params.get("meetingId").toString());
        String key = params.containsKey("key") ? (String) params.get("key") : "";
        int status = params.containsKey("status") ? (int) params.get("status") : -1;

        boolean statusOn = false;
        if (status == 0 || status == 1) {
            statusOn = true;
        }

        IPage<SignviewEntity> page = this.page(new Query<SignviewEntity>().getPage(params),
                new QueryWrapper<SignviewEntity>().eq("meeting_id", meetingId).eq(statusOn, "status", status)
                        .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 SignviewEntity getByAid(Long aid) {
        return this.getOne(new QueryWrapper<SignviewEntity>().eq("aid", aid));
    }

    @Override
    public List<SignviewEntity> listSignAll(Long meetingId) {
        return this.list(new QueryWrapper<SignviewEntity>().eq("meeting_id", meetingId).eq("status", 1));
    }

    @Override
    public Integer getSignTotal(Long meetingId, Integer feeType) {
        return this.count(new QueryWrapper<SignviewEntity>().eq("meeting_id", meetingId).eq("status", 1).eq(feeType!=0,"fee_type", feeType));
    }

}