package com.vctgo.system.service.impl;

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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vctgo.common.security.utils.SecurityUtils;
import com.vctgo.system.api.domain.SysService;
import com.vctgo.system.mapper.SysServiceMapper;
import com.vctgo.system.service.ISysServiceService;
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 SysServiceServiceImpl implements ISysServiceService {

    @Autowired
    private SysServiceMapper sysServiceMapper;

    /**
     * 查询服务
     *
     * @param id 服务主键
     * @return 服务
     */
    @Override
    public SysService selectSysServiceById(Long id) {
        return sysServiceMapper.selectById(id);
    }

    /**
     * 查询服务列表-分页
     *
     * @param sysService 服务
     * @return 服务
     */
    @Override
    public IPage<SysService> selectSysServicePage(SysService sysService) {
        Page mpPage = new Page(Convert.toLong(ServletUtils.getParameterToInt(MybatisPageConstants.PAGE_NUM), 1L)
                , Convert.toLong(ServletUtils.getParameterToInt(MybatisPageConstants.PAGE_SIZE), 10L));
        return sysServiceMapper.selectSysServiceList(mpPage, sysService);
    }

    /**
     * 查询服务列表
     *
     * @param sysService 服务
     * @return 服务
     */
    @Override
    public List<SysService> selectSysServiceList(SysService sysService) {
        return sysServiceMapper.selectSysServiceList(sysService);
    }

    /**
     * 新增服务
     *
     * @param sysService 服务
     * @return 结果
     */
    @Transactional
    @Override
    public int insertSysService(SysService sysService) {
        return sysServiceMapper.insert(sysService);
    }

    /**
     * 修改服务
     *
     * @param sysService 服务
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSysService(SysService sysService) {
        return sysServiceMapper.updateById(sysService);
    }

    /**
     * 逻辑删除服务
     *
     * @param ids 需要删除的服务主键
     * @return 结果
     */
    @Transactional
    @Override
    public int logicalDeleteSysServiceByIds(Long[] ids) {
        SysService sysService = new SysService();
        sysService.setUpdateById(SecurityUtils.getUserId());
        sysService.setUpdateBy(SecurityUtils.getUsername());
        sysService.setUpdateTime(new Date());
        sysService.setIsDeleted(ConstantUtils.IS_DELETED_1);
        return sysServiceMapper.logicalDeleteSysServiceByIds(ids, sysService);
    }

    /**
     * 批量删除服务
     *
     * @param ids 需要删除的服务主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysServiceByIds(Long[] ids) {
        return sysServiceMapper.deleteSysServiceByIds(ids);
    }

    /**
     * 删除服务信息
     *
     * @param id 服务主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysServiceById(Long id) {
        return sysServiceMapper.deleteById(id);
    }
}
