package com.cmvr.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cmvr.common.core.domain.entity.SysGroup;
import com.cmvr.common.utils.StringUtils;
import com.cmvr.system.mapper.SysGroupMapper;
import com.cmvr.system.service.ISysGroupService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 通用分组配置Service业务层处理
 *
 * @author cmvr-iot
 */
@Service
public class SysGroupServiceImpl extends ServiceImpl<SysGroupMapper, SysGroup> implements ISysGroupService {

    /**
     * 查询通用分组配置
     *
     * @param groupId 通用分组配置主键
     * @return 通用分组配置
     */
    @Override
    public SysGroup selectSysGroupByGroupId(Long groupId) {
        return this.baseMapper.selectById(groupId);
    }

    /**
     * 查询通用分组配置列表
     *
     * @param sysGroup 通用分组配置
     * @return 通用分组配置
     */
    @Override
    public List<SysGroup> selectSysGroupList(SysGroup sysGroup) {
        LambdaQueryWrapper<SysGroup> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper
                .eq(sysGroup.getType() != null, SysGroup::getType, sysGroup.getType())
                .eq(StringUtils.isNotBlank(sysGroup.getGroupName()), SysGroup::getGroupName, sysGroup.getGroupName())
                .eq(StringUtils.isNotBlank(sysGroup.getDescription()), SysGroup::getDescription, sysGroup.getDescription());

        return this.list(queryWrapper);
    }

    /**
     * 新增通用分组配置
     *
     * @param sysGroup 通用分组配置
     * @return 结果
     */
    @Override
    public int insertSysGroup(SysGroup sysGroup) {
        return this.baseMapper.insert(sysGroup);
    }

    /**
     * 修改通用分组配置
     *
     * @param sysGroup 通用分组配置
     * @return 结果
     */
    @Override
    public int updateSysGroup(SysGroup sysGroup) {
        return this.baseMapper.updateById(sysGroup);
    }

    /**
     * 批量删除通用分组配置
     *
     * @param groupIds 需要删除的通用分组配置主键
     * @return 结果
     */
    @Override
    public int deleteSysGroupByGroupIds(Long[] groupIds) {
        return this.baseMapper.deleteBatchIds(Arrays.asList(groupIds));
    }

    /**
     * 删除通用分组配置信息
     *
     * @param groupId 通用分组配置主键
     * @return 结果
     */
    @Override
    public int deleteSysGroupByGroupId(Long groupId) {
        return this.baseMapper.deleteById(groupId);
    }
}
