package com.usky.iot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.common.security.utils.SecurityUtils;
import com.usky.iot.domain.VcDevice;
import com.usky.iot.domain.VcDeviceGroup;
import com.usky.iot.mapper.VcDeviceGroupMapper;
import com.usky.iot.service.VcDeviceGroupService;
import com.usky.common.mybatis.core.AbstractCrudService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author han
 * @since 2024-10-23
 */
@Service
public class VcDeviceGroupServiceImpl extends AbstractCrudService<VcDeviceGroupMapper, VcDeviceGroup> implements VcDeviceGroupService {

    @Override
    public void vcDeviceGroupAdd(String groupName){
        VcDeviceGroup vcDeviceGroup = new VcDeviceGroup();
        vcDeviceGroup.setGroupName(groupName);
        vcDeviceGroup.setCreateBy(SecurityUtils.getUsername());
        vcDeviceGroup.setCreateTime(LocalDateTime.now());
        vcDeviceGroup.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId());
        vcDeviceGroup.setTenantId(SecurityUtils.getTenantId());
        this.save(vcDeviceGroup);
    }

    @Override
    public void vcDeviceGroupUpdate(String groupName,Integer id){
        VcDeviceGroup vcDeviceGroup = this.getById(id);
        vcDeviceGroup.setUpdateBy(SecurityUtils.getUsername());
        vcDeviceGroup.setUpdateTime(LocalDateTime.now());
        vcDeviceGroup.setGroupName(groupName);
        this.updateById(vcDeviceGroup);
    }

    @Override
    public List<VcDeviceGroup> vcDeviceGroupList(String groupName){
        LambdaQueryWrapper<VcDeviceGroup> lambdaQuery = Wrappers.lambdaQuery();
//        lambdaQuery.eq(VcDeviceGroup::getTenantId,SecurityUtils.getTenantId());
        List<VcDeviceGroup> list = this.list(lambdaQuery);
        return list;
    }
}
