All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rexsheng.springboot.faster.system.role.application.RoleServiceImpl Maven / Gradle / Ivy

The newest version!
package com.github.rexsheng.springboot.faster.system.role.application;

import com.github.rexsheng.springboot.faster.common.constant.CommonConstant;
import com.github.rexsheng.springboot.faster.common.domain.PagedList;
import com.github.rexsheng.springboot.faster.system.post.application.dto.ValidateRoleCodeRequest;
import com.github.rexsheng.springboot.faster.system.role.application.dto.*;
import com.github.rexsheng.springboot.faster.system.role.domain.SysRole;
import com.github.rexsheng.springboot.faster.system.role.domain.gateway.QueryRoleDO;
import com.github.rexsheng.springboot.faster.system.role.domain.gateway.RoleGateway;
import jakarta.annotation.Resource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;
import java.util.stream.Collectors;

@Service
@ConditionalOnClass(SqlSessionFactoryBean.class)
public class RoleServiceImpl implements RoleService{

    @Resource
    private RoleGateway roleGateway;

    @Override
    public void add(AddRoleRequest request) {
        roleGateway.insertRole(request.toRole());
    }

    @Override
    public List queryList(QueryRoleRequest request) {
        QueryRoleDO query=new QueryRoleDO();
        query.setKeyword(request.getKeyword());
        query.setStatus(CommonConstant.STATUS_RUNNING);
        List dataList=roleGateway.queryRoles(query);
        return dataList.stream().map(RoleDetailResponse::of).collect(Collectors.toList());
    }

    @Override
    public PagedList pagedList(QueryRoleRequest request) {
        QueryRoleDO query=new QueryRoleDO();
        query.setKeyword(request.getKeyword());
        query.setPageIndex(request.getPageIndex());
        query.setPageSize(request.getPageSize());
        PagedList dataList=roleGateway.paginateRoles(query);
        return PagedList.of(dataList, RoleDetailResponse::of);
    }

    @Override
    public RoleDetailResponse get(Integer id) {
        SysRole data= roleGateway.getRole(id);
        Assert.notNull(data,"角色不存在");
        return RoleDetailResponse.of(data);
    }

    @Override
    public void update(UpdateRoleRequest request) {
        SysRole data=request.toRole();
        roleGateway.updateRoleById(data);
    }

    @Override
    public void updateStatus(List request) {
        List dataList=request.stream().map(UpdateRoleRequest::toRole).collect(Collectors.toList());
        roleGateway.updateRoleStatus(dataList);
    }

    @Override
    public void delete(List ids) {
        roleGateway.deleteRoles(SysRole.of(ids,true));
    }

    @Override
    public Boolean validCode(ValidateRoleCodeRequest request) {
        SysRole role=request.toRole();
        QueryRoleDO query=new QueryRoleDO();
        query.setRoleId(role.getRoleId());
        query.setRoleCode(role.getRoleCode());
        return roleGateway.queryCodeCount(query)==0L;
    }

    @Override
    public void changeAuth(ChangeRoleAuthRequest request) {
        SysRole role =request.toRole();
        roleGateway.changeAuth(role);
    }

    @Override
    public List getAuths(Integer id) {
        SysRole role =SysRole.of(id);
        return roleGateway.getAuths(role).stream().map(a->a.getMenuId()).collect(Collectors.toList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy