package com.gxwebsoft.common.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.system.mapper.UserGroupMapper;
import com.gxwebsoft.common.system.service.UserGroupService;
import com.gxwebsoft.common.system.entity.UserGroup;
import com.gxwebsoft.common.system.param.UserGroupParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户分组管理表Service实现
 *
 * @author 科技小王子
 * @since 2023-10-28 15:16:39
 */
@Service
public class UserGroupServiceImpl extends ServiceImpl<UserGroupMapper, UserGroup> implements UserGroupService {

    @Override
    public PageResult<UserGroup> pageRel(UserGroupParam param) {
        PageParam<UserGroup, UserGroupParam> page = new PageParam<>(param);
        //page.setDefaultOrder("create_time desc");
        List<UserGroup> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<UserGroup> listRel(UserGroupParam param) {
        List<UserGroup> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<UserGroup, UserGroupParam> page = new PageParam<>();
        //page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public UserGroup getByIdRel(Integer groupId) {
        UserGroupParam param = new UserGroupParam();
        param.setGroupId(groupId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
