package com.sptg.estate.biz.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.estate.api.entity.MemberDevice;
import com.sptg.estate.biz.mapper.MemberDeviceMapper;
import com.sptg.estate.biz.service.MemberDeviceServiceInterface;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberDeviceServiceImpl extends ServiceImpl<MemberDeviceMapper, MemberDevice> implements MemberDeviceServiceInterface {
    @Override
    public ResultBean<Page<MemberDevice>> pagingQuery(MemberDevice memberDevice) {
        Wrapper<MemberDevice> wrapper = new EntityWrapper<>();
        //app会员id
        wrapper.eq("l_member_id",memberDevice.getMemberId());
        //小区id
        if (memberDevice.getResidentialId() != null){
            wrapper.eq("l_residential_id",memberDevice.getResidentialId());
        }
        return new ResultBean<>(ResultEnum.SUCCESS,this.selectPage(memberDevice.getPage(),wrapper));
    }

    @Override
    public ResultBean<Boolean> enable(MemberDevice memberDevice) {
        return new ResultBean<>(ResultEnum.SUCCESS,this.updateById(memberDevice));
    }

    @Override
    public ResultBean<Boolean> add(MemberDevice memberDevice) {
        return new ResultBean<>(ResultEnum.SUCCESS,this.insert(memberDevice));
    }

    @Override
    public List<MemberDevice> getListByMemberId(MemberDevice memberDevice) {
        Wrapper<MemberDevice> wrapper = new EntityWrapper<>();
        wrapper.eq("l_member_id",memberDevice.getMemberId());
        //小区id
        wrapper.eq(memberDevice.getResidentialId() != null,"l_residential_id",memberDevice.getResidentialId());
        //deviceIds
        if (memberDevice.getDeviceIds() !=null){
            wrapper.in("l_device_id",memberDevice.getDeviceIds());
        }
        return this.selectList(wrapper);
    }

    @Override
    public ResultBean<Boolean> addBatch(List<MemberDevice> memberDeviceList) {
        return new ResultBean<>(ResultEnum.SUCCESS,this.insertBatch(memberDeviceList));
    }

    @Override
    public ResultBean<Boolean> deleteBatch(List<Long> ids) {
        return new ResultBean<>(ResultEnum.SUCCESS,this.deleteBatchIds(ids));
    }
}
