package com.vctgo.system.service.impl;

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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vctgo.common.security.utils.SecurityUtils;
import com.vctgo.system.domain.SysReServiceTenant;
import com.vctgo.system.mapper.SysReServiceTenantMapper;
import com.vctgo.system.service.ISysReServiceTenantService;
import com.vctgo.system.util.ConstantUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vctgo.common.core.text.Convert;
import com.vctgo.common.core.utils.ServletUtils;
import com.vctgo.common.mybatisplus.constant.MybatisPageConstants;
import org.springframework.transaction.annotation.Transactional;

/**
 * 服务与租户关联Service业务层处理
 *
 * @author caesar
 * @date 2023-10-08
 */
@Slf4j
@Service
public class SysReServiceTenantServiceImpl extends ServiceImpl<SysReServiceTenantMapper, SysReServiceTenant> implements ISysReServiceTenantService {

    @Autowired
    private SysReServiceTenantMapper sysReServiceTenantMapper;

    /**
     * 查询服务与租户关联
     *
     * @param id 服务与租户关联主键
     * @return 服务与租户关联
     */
    @Override
    public SysReServiceTenant selectSysReServiceTenantById(Long id) {
        return sysReServiceTenantMapper.selectById(id);
    }

    /**
     * 查询服务与租户关联列表-分页
     *
     * @param sysReServiceTenant 服务与租户关联
     * @return 服务与租户关联
     */
    @Override
    public IPage<SysReServiceTenant> selectSysReServiceTenantPage(SysReServiceTenant sysReServiceTenant) {
        Page mpPage = new Page(Convert.toLong(ServletUtils.getParameterToInt(MybatisPageConstants.PAGE_NUM), 1L)
                , Convert.toLong(ServletUtils.getParameterToInt(MybatisPageConstants.PAGE_SIZE), 10L));
        return sysReServiceTenantMapper.selectSysReServiceTenantList(mpPage, sysReServiceTenant);
    }

    /**
     * 查询服务与租户关联列表
     *
     * @param sysReServiceTenant 服务与租户关联
     * @return 服务与租户关联
     */
    @Override
    public List<SysReServiceTenant> selectSysReServiceTenantList(SysReServiceTenant sysReServiceTenant) {
        return sysReServiceTenantMapper.selectSysReServiceTenantList(sysReServiceTenant);
    }

    /**
     * 新增服务与租户关联
     *
     * @param sysReServiceTenant 服务与租户关联
     * @return 结果
     */
    @Transactional
    @Override
    public int insertSysReServiceTenant(SysReServiceTenant sysReServiceTenant) {
        return sysReServiceTenantMapper.insert(sysReServiceTenant);
    }

    /**
     * 修改服务与租户关联
     *
     * @param sysReServiceTenant 服务与租户关联
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSysReServiceTenant(SysReServiceTenant sysReServiceTenant) {
        return sysReServiceTenantMapper.updateById(sysReServiceTenant);
    }

    /**
     * 逻辑删除服务与租户关联
     *
     * @param ids 需要删除的服务与租户关联主键
     * @return 结果
     */
    @Transactional
    @Override
    public int logicalDeleteSysReServiceTenantByIds(Long[] ids) {
        SysReServiceTenant sysReServiceTenant = new SysReServiceTenant();
        sysReServiceTenant.setUpdateById(SecurityUtils.getUserId());
        sysReServiceTenant.setUpdateBy(SecurityUtils.getUsername());
        sysReServiceTenant.setUpdateTime(new Date());
        sysReServiceTenant.setIsDeleted(ConstantUtils.IS_DELETED_1);
        return sysReServiceTenantMapper.logicalDeleteSysReServiceTenantByIds(ids, sysReServiceTenant);
    }

    /**
     * 批量删除服务与租户关联
     *
     * @param ids 需要删除的服务与租户关联主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysReServiceTenantByIds(Long[] ids) {
        return sysReServiceTenantMapper.deleteSysReServiceTenantByIds(ids);
    }

    /**
     * 删除服务与租户关联信息
     *
     * @param id 服务与租户关联主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysReServiceTenantById(Long id) {
        return sysReServiceTenantMapper.deleteById(id);
    }

    @Override
    public List<SysReServiceTenant> selectSysReServiceTenantListByTenantId(String tenantId) {
        return sysReServiceTenantMapper.selectSysReServiceTenantListByTenantId(tenantId);
    }
}
