package com.yuchen.saas.park.service.service.security.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuchen.saas.park.api.dto.security.SaasParkSecurityDeviceQryDto;
import com.yuchen.saas.park.api.entity.security.SaasParkSecurityDevice;
import com.yuchen.saas.park.service.mapper.security.SaasParkSecurityDeviceMapper;
import com.yuchen.saas.park.service.service.security.ISaasParkSecurityDeviceService;
import org.nest.springwrap.core.mp.base.BaseServiceImpl;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 智慧安防设备表 服务实现类
 * </p>
 *
 * @author 洪铭铭
 * @since 2024-09-19
 */
@Service
public class SaasParkSecurityDeviceServiceImpl extends BaseServiceImpl<SaasParkSecurityDeviceMapper, SaasParkSecurityDevice> implements ISaasParkSecurityDeviceService {

    public List<SaasParkSecurityDevice> getAll() {

        LambdaQueryWrapper<SaasParkSecurityDevice> qw = new LambdaQueryWrapper<>();
        List<SaasParkSecurityDevice> saasParkSecurityDeviceList = baseMapper.selectList(qw);

        return saasParkSecurityDeviceList;
    }

    public Page<SaasParkSecurityDevice> selectPage(SaasParkSecurityDeviceQryDto qryDto) {
        Page<SaasParkSecurityDevice> page = new Page<>(qryDto.getCurrent(), qryDto.getSize());
        LambdaQueryWrapper<SaasParkSecurityDevice> qw = new LambdaQueryWrapper<>();
//        if (!AuthUtil.isAdministrator()) {
//            qw.eq(SaasParkSecurityDevice::getCustomerManageId, AuthUtil.getUser().getCustomerManageId());
//        } else {
//            // 超管
//            qw.eq(Func.isNotEmpty(qryDto.getCustomerManageId()), SaasParkSecurityDevice::getCustomerManageId, qryDto.getCustomerManageId());
//        }
        qw.eq(Func.isNotEmpty(qryDto.getParkId()), SaasParkSecurityDevice::getParkId, qryDto.getParkId());
        qw.eq(Func.isNotEmpty(qryDto.getDeviceName()), SaasParkSecurityDevice::getDeviceName, qryDto.getDeviceName());
        qw.eq(Func.isNotEmpty(qryDto.getProductKey()), SaasParkSecurityDevice::getProductKey, qryDto.getProductKey());
        qw.eq(Func.isNotEmpty(qryDto.getDeviceDesc()), SaasParkSecurityDevice::getDeviceDesc, qryDto.getDeviceDesc());
        qw.eq(Func.isNotEmpty(qryDto.getDeviceType()), SaasParkSecurityDevice::getDeviceType, qryDto.getDeviceType());
        qw.eq(Func.isNotEmpty(qryDto.getDeviceStatus()), SaasParkSecurityDevice::getDeviceStatus, qryDto.getDeviceStatus());
        qw.eq(Func.isNotEmpty(qryDto.getDeviceLocation()), SaasParkSecurityDevice::getDeviceLocation, qryDto.getDeviceLocation());
        qw.eq(Func.isNotEmpty(qryDto.getLatitude()), SaasParkSecurityDevice::getLatitude, qryDto.getLatitude());
        qw.eq(Func.isNotEmpty(qryDto.getLongitude()), SaasParkSecurityDevice::getLongitude, qryDto.getLongitude());
        qw.eq(Func.isNotEmpty(qryDto.getLastConnectTime()), SaasParkSecurityDevice::getLastConnectTime, qryDto.getLastConnectTime());
        qw.eq(Func.isNotEmpty(qryDto.getLastDisconnectTime()), SaasParkSecurityDevice::getLastDisconnectTime, qryDto.getLastDisconnectTime());
        return this.page(page, qw);
    }

}
