package com.sooka.sponest.monitor.camera.service.impl;

import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.DictUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.sooka.sponest.monitor.camera.domain.CentermonitorTCamerachannel;
import com.sooka.sponest.monitor.camera.mapper.CentermonitorTCamerachannelMapper;
import com.sooka.sponest.monitor.camera.service.ICentermonitorTCamerachannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 摄像头通道Service业务层处理
 *
 * @author ruoyi
 * @date 2022-06-10
 */
@Service
public class CentermonitorTCamerachannelServiceImpl implements ICentermonitorTCamerachannelService
{
    @Autowired
    private CentermonitorTCamerachannelMapper centermonitorTCamerachannelMapper;

    /**
     * 查询摄像头通道
     *
     * @param id 摄像头通道主键
     * @return 摄像头通道
     */
    @Override
    public CentermonitorTCamerachannel selectCentermonitorTCamerachannelById(String id)
    {
        return centermonitorTCamerachannelMapper.selectCentermonitorTCamerachannelById(id);
    }

    /**
     * 校验通道编码IP唯一
     *
     * @param centermonitorTCamerachannel 摄像头
     * @return 结果
     */
    @Override
    public String checkChannelUnique(CentermonitorTCamerachannel centermonitorTCamerachannel){

        String Id = StringUtils.isNull(centermonitorTCamerachannel.getId()) ? String.valueOf(-1L) : centermonitorTCamerachannel.getId();
        CentermonitorTCamerachannel info = centermonitorTCamerachannelMapper.checkChannelUnique(centermonitorTCamerachannel.getChannelCode());
        if (StringUtils.isNotNull(info) && !info.getId().equals(Id))
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 查询摄像头通道列表
     *
     * @param centermonitorTCamerachannel 摄像头通道
     * @return 摄像头通道
     */
    @Override
    public List<CentermonitorTCamerachannel> selectCentermonitorTCamerachannelList(CentermonitorTCamerachannel centermonitorTCamerachannel)
    {
        return centermonitorTCamerachannelMapper.selectCentermonitorTCamerachannelList(centermonitorTCamerachannel);
    }

    /**
     * 新增摄像头通道
     *
     * @param centermonitorTCamerachannel 摄像头通道
     * @return 结果
     */
    @Override
    public int insertCentermonitorTCamerachannel(CentermonitorTCamerachannel centermonitorTCamerachannel)
    {

        int row = centermonitorTCamerachannelMapper.insertCentermonitorTCamerachannel(centermonitorTCamerachannel);
        if (row > 0)
        {
            DictUtils.setDictCache(centermonitorTCamerachannel.getChannelCode(), null);
        }
        return row;
    }

    /**
     * 修改摄像头通道
     *
     * @param centermonitorTCamerachannel 摄像头通道
     * @return 结果
     */
    @Override
    public int updateCentermonitorTCamerachannel(CentermonitorTCamerachannel centermonitorTCamerachannel)
    {
        centermonitorTCamerachannel.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getUserId());
        centermonitorTCamerachannel.setUpdateTime(DateUtils.getNowDate());
        return centermonitorTCamerachannelMapper.updateCentermonitorTCamerachannel(centermonitorTCamerachannel);
    }

    /**
     * 批量删除摄像头通道
     *
     * @param ids 需要删除的摄像头通道主键
     * @return 结果
     */
    @Override
    public int deleteCentermonitorTCamerachannelByIds(String[] ids)
    {
        return centermonitorTCamerachannelMapper.deleteCentermonitorTCamerachannelByIds(ids);
    }

    /**
     * 删除摄像头通道信息
     *
     * @param id 摄像头通道主键
     * @return 结果
     */
    @Override
    public int deleteCentermonitorTCamerachannelById(String id)
    {
        return centermonitorTCamerachannelMapper.deleteCentermonitorTCamerachannelById(id);
    }
}
