package com.muyu.fence.service.impl;

import java.util.List;
import org.springframework.stereotype.Service;
import com.muyu.fence.mapper.TbFenceMapper;
import com.muyu.fence.domain.TbFence;
import com.muyu.fence.service.ITbFenceService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import org.springframework.util.Assert;

/**
 * 电子围栏Service业务层处理
 *
 * @author muyu
 * @date 2024-09-18
 */
@Service
public class TbFenceServiceImpl
        extends ServiceImpl<TbFenceMapper, TbFence>
        implements ITbFenceService {

    /**
     * 精确查询电子围栏
     *
     * @param fenceId 电子围栏主键
     * @return 电子围栏
     */
    @Override
    public TbFence selectTbFenceByFenceId(Long fenceId)
    {
        LambdaQueryWrapper<TbFence> queryWrapper = new LambdaQueryWrapper<>();
        Assert.notNull(fenceId, "fenceId不可为空");
        queryWrapper.eq(TbFence::getFenceId, fenceId);
        return this.getOne(queryWrapper);
    }


    /**
     * 查询电子围栏列表
     *
     * @param tbFence 电子围栏
     * @return 电子围栏
     */
    @Override
    public List<TbFence> selectTbFenceList(TbFence tbFence)
    {
        LambdaQueryWrapper<TbFence> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(tbFence.getFenceName())){
            queryWrapper.like(TbFence::getFenceName, tbFence.getFenceName());
        }
        if (tbFence.getFenceType()!=null){
            queryWrapper.eq(TbFence::getFenceType, tbFence.getFenceType());
        }
        if (tbFence.getFenceFlag()!=null){
            queryWrapper.eq(TbFence::getFenceFlag, tbFence.getFenceFlag());
        }
        if (StringUtils.isNotEmpty(tbFence.getLongitudeAndLatitudeInformation())){
            queryWrapper.eq(TbFence::getLongitudeAndLatitudeInformation, tbFence.getLongitudeAndLatitudeInformation());
        }
        if (tbFence.getFencePriority()!=null){
            queryWrapper.eq(TbFence::getFencePriority, tbFence.getFencePriority());
        }
        return this.list(queryWrapper);
    }

    /**
    * 唯一 判断
    * @param tbFence 电子围栏
     * @return 电子围栏
    */
    @Override
    public Boolean checkIdUnique(TbFence tbFence) {
        LambdaQueryWrapper<TbFence> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TbFence::getFenceId, tbFence.getFenceId());
        return this.count(queryWrapper) > 0;
    }

}
