package com.fdkankan.ucenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fdkankan.ucenter.entity.SceneResourceCamera;
import com.fdkankan.ucenter.mapper.ISceneResourceCameraMapper;
import com.fdkankan.ucenter.service.ISceneResourceCameraService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fdkankan.ucenter.util.DateUserUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 场景资源和相机关联表 服务实现类
 * </p>
 *
 * @author 
 * @since 2022-07-05
 */
@Service
public class SceneResourceCameraServiceImpl extends ServiceImpl<ISceneResourceCameraMapper, SceneResourceCamera> implements ISceneResourceCameraService {


    @Override
    public void deleteByCameraIds(List<Long> cameraIds) {
        LambdaQueryWrapper<SceneResourceCamera> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(SceneResourceCamera::getCameraId,cameraIds);
        this.remove(wrapper);
    }

    @Override
    public void saveBatchByCameraIds(List<Long> cameraIds, List<Long> resourceIdList) {
        List<SceneResourceCamera> saveSceneResourceCameraList = new ArrayList<>();
        SceneResourceCamera sceneResourceCameraEntity = null;
        for (Long cameraId : cameraIds) {
            for (Long resourceId : resourceIdList) {
                sceneResourceCameraEntity = new SceneResourceCamera();
                sceneResourceCameraEntity.setSceneResourceId(resourceId);
                sceneResourceCameraEntity.setCameraId(cameraId);
                sceneResourceCameraEntity.setRecStatus("A");
                sceneResourceCameraEntity.setCreateTime(DateUserUtil.getDate(new Date()));
                sceneResourceCameraEntity.setUpdateTime(DateUserUtil.getDate(new Date()));
                saveSceneResourceCameraList.add(sceneResourceCameraEntity);
            }
        }
        if(saveSceneResourceCameraList.size() >0){
            this.saveBatch(saveSceneResourceCameraList);
        }
    }
}
