Browse Source

初始化固定角色

master
WendyYang 1 year ago
parent
commit
55a61d2fa2
1 changed files with 26 additions and 0 deletions
  1. +26
    -0
      pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java

+ 26
- 0
pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java View File

@@ -8,12 +8,17 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ningdatech.pmapi.AppTests;
import com.ningdatech.pmapi.sys.model.entity.Menu;
import com.ningdatech.pmapi.sys.model.entity.Role;
import com.ningdatech.pmapi.sys.model.entity.RoleMenu;
import com.ningdatech.pmapi.user.entity.enumeration.RoleEnum;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

/**
* <p>
@@ -27,6 +32,27 @@ class IMenuServiceTest extends AppTests {

@Autowired
private IMenuService menuService;
@Autowired
private IRoleService roleService;

/**
* 初始化固定角色
*/
@Test
public void roleService() {
roleService.remove(null);
AtomicLong integer = new AtomicLong(0);
Arrays.stream(RoleEnum.values()).map(w -> {
Role role = new Role();
role.setId(integer.incrementAndGet());
role.setCode(w.name());
role.setName(w.getDesc());
role.setDescribe(w.getDesc());
role.setFixed(true);
role.setCreateOn(LocalDateTime.now());
return role;
}).forEach(roleService::save);
}

@Test
public void test() throws SQLException {


Loading…
Cancel
Save