package com.huimv.management.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huimv.management.dao.CameraInfoDao;
import com.huimv.management.entity.CameraInfoEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
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 com.huimv.common.utils.PageUtils;
import com.huimv.common.utils.Query;

import com.huimv.management.dao.CameraBrandDao;
import com.huimv.management.entity.CameraBrandEntity;
import com.huimv.management.service.CameraBrandService;

/**
 * 
 *
 * @author yinhao
 * @version ${version}
 * @date 2021-07-08 17:02:38
 */
@Service("cameraBrandService")
public class CameraBrandServiceImpl extends ServiceImpl<CameraBrandDao, CameraBrandEntity> implements CameraBrandService {

    @Autowired
    private CameraInfoDao cameraInfoDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<CameraBrandEntity> wrapper = new QueryWrapper<>();

        String keyword = (String)params.get("keyword");
        wrapper.like(StringUtils.isNotBlank(keyword),"brand_name",keyword);


        IPage<CameraBrandEntity> page = this.page(
                new Query<CameraBrandEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public boolean delete(Integer[] ids) {
        LambdaQueryWrapper<CameraInfoEntity> wrapper = Wrappers.lambdaQuery();
        for (Integer id : ids) {
            wrapper.eq(CameraInfoEntity::getCameraBrandId,id);
            if ( cameraInfoDao.selectCount(wrapper) > 0){
                return false;
            }
            wrapper.clear();
        }

        return true;
    }
}