package com.nasc.custom.service.impl;

import com.nasc.common.utils.SecurityUtils;
import com.nasc.common.utils.StringUtils;
import com.nasc.custom.domain.NascVncDesktop;
import com.nasc.custom.mapper.NascVncDesktopMapper;
import com.nasc.custom.service.INascVncDesktopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Yujianq
 * @Date: 2024/6/4 16:36
 * @Description: 远程桌面数据
 * @return:
 */
@Service
public class NascVncDesktopServiceImpl implements INascVncDesktopService {

    @Autowired
    private NascVncDesktopMapper vncDesktopMapper;

    @Override
    public List<NascVncDesktop> selectVncDesktopList(NascVncDesktop vncDesktop) {
        return vncDesktopMapper.selectVncDesktopList(vncDesktop);
    }

    @Override
    public Long checkVncDesktopDuplicates(NascVncDesktop vncDesktop) {
        return vncDesktopMapper.checkVncDesktopDuplicates(vncDesktop);
    }

    @Override
    public int insertVncDesktop(NascVncDesktop vncDesktop) {
        if (!StringUtils.isEmpty(vncDesktop.getPassword())) {
            vncDesktop.setPassword(SecurityUtils.encryptPassword(vncDesktop.getPassword()));
        }
        return vncDesktopMapper.insertVncDesktop(vncDesktop);
    }

    @Override
    public int updateVncDesktop(NascVncDesktop vncDesktop) {
        if (!StringUtils.isEmpty(vncDesktop.getPassword())) {
            vncDesktop.setPassword(SecurityUtils.encryptPassword(vncDesktop.getPassword()));
        }
        return vncDesktopMapper.updateVncDesktop(vncDesktop);
    }

    @Override
    public int deleteVncDesktopByIds(Long[] ids) {
        return vncDesktopMapper.deleteVncDesktopByIds(ids);
    }

    @Override
    public NascVncDesktop getVncDesktopInfo(Long id) {
        NascVncDesktop vncDesktop = vncDesktopMapper.getVncDesktopInfo(id);
        vncDesktop.setPassword(null);
        return vncDesktop;
    }

}
