package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.UserCommissionRoleMapper;
import com.gxwebsoft.shop.service.UserCommissionRoleService;
import com.gxwebsoft.shop.entity.UserCommissionRole;
import com.gxwebsoft.shop.param.UserCommissionRoleParam;
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 2024-12-02 12:43:40
 */
@Service
public class UserCommissionRoleServiceImpl extends ServiceImpl<UserCommissionRoleMapper, UserCommissionRole> implements UserCommissionRoleService {

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

    @Override
    public List<UserCommissionRole> listRel(UserCommissionRoleParam param) {
        List<UserCommissionRole> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<UserCommissionRole, UserCommissionRoleParam> page = new PageParam<>();
        return page.sortRecords(list);
    }

    @Override
    public UserCommissionRole getByIdRel(Integer id) {
        UserCommissionRoleParam param = new UserCommissionRoleParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

    @Override
    public List<UserCommissionRole> listByRoleIds(List<Integer> roleIds) {
        return list(
                new LambdaQueryWrapper<UserCommissionRole>()
                        .in(UserCommissionRole::getRoleId, roleIds)
        );
    }

}
