You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.1 KiB
97 lines
2.1 KiB
package com.example.demo.serviceImpl;
|
|
|
|
import com.example.demo.domain.entity.Role;
|
|
import com.example.demo.domain.vo.Result;
|
|
import com.example.demo.domain.vo.RoleVo;
|
|
import com.example.demo.mapper.RefundMapper;
|
|
import com.example.demo.mapper.RoleMapper;
|
|
import com.example.demo.service.MenuService;
|
|
import com.example.demo.service.RoleService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @program: gold-java
|
|
* @ClassName RoleServiceImpl
|
|
* @description:
|
|
* @author: Double
|
|
* @create: 2025−07-15 11:30
|
|
* @Version 1.0
|
|
**/
|
|
|
|
@Service
|
|
public class RoleServiceImpl implements RoleService {
|
|
|
|
@Autowired
|
|
private RoleMapper roleMapper;
|
|
@Autowired
|
|
private MenuService menuService;
|
|
|
|
//新增角色
|
|
@Override
|
|
@Transactional
|
|
public Result addRole(RoleVo roleVo) {
|
|
//校验角色
|
|
if(roleVo.getRoleName()==null|| roleVo.getRoleName().isEmpty()){
|
|
return Result.error("角色名为空");
|
|
}
|
|
if(roleMapper.selectByRoleName(roleVo.getRoleName())!=null){
|
|
return Result.error("角色名重复");
|
|
}
|
|
if(roleVo.getPriority()==null){
|
|
return Result.error("优先级为空");
|
|
}
|
|
if(roleVo.getMenuIds()==null||roleVo.getMenuIds().isEmpty()){
|
|
return Result.error("权限为空");
|
|
}
|
|
try {
|
|
roleMapper.addRole(roleVo);
|
|
Role role = roleMapper.selectByRoleName(roleVo.getRoleName());
|
|
if(role==null){
|
|
return Result.error("角色添加失败");
|
|
}else{
|
|
roleVo.setId(role.getId());
|
|
}
|
|
menuService.addPermission(roleVo);
|
|
}catch (Exception e)
|
|
{
|
|
return Result.error("添加失败");
|
|
}
|
|
|
|
return Result.success("创建成功");
|
|
}
|
|
|
|
//查找全部角色
|
|
@Override
|
|
public List<RoleVo> selectAllRole() {
|
|
return roleMapper.selectAllRole();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|