package ${domain};

import ${domain}.frame.auth.Token;
import ${domain}.frame.base.BaseResponse;
import ${domain}.frame.utils.MapperUtil;
import ${domain}.frame.utils.Message;
import ${domain}.module.wsys.mgr.DictItemManager;
import ${domain}.module.wsys.mgr.DictManager;
import ${domain}.module.wsys.req.DictCreateRequest;
import ${domain}.module.wsys.req.DictItemCreateRequest;
import ${domain}.module.wsys.rsp.DictCreateResponse;
import ${domain}.module.wsys.rsp.DictItemCreateResponse;
<#if project.frameValue() &gt;= 3>
import ${domain}.module.wsys.ent.Res;
import ${domain}.module.wsys.mgr.ResManager;
import ${domain}.module.wsys.mgr.RoleManager;
import ${domain}.module.wsys.mgr.RoleResManager;
import ${domain}.module.wsys.req.ResCreateRequest;
import ${domain}.module.wsys.req.ResFindRequest;
import ${domain}.module.wsys.req.RoleCreateRequest;
import ${domain}.module.wsys.req.RoleResCheckRequest;
import ${domain}.module.wsys.rsp.ResCreateResponse;
import ${domain}.module.wsys.rsp.ResFindResponse;
import ${domain}.module.wsys.rsp.RoleCreateResponse;
import ${domain}.module.wsys.rsp.RoleResCheckResponse;
</#if>
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.junit.Assert.assertTrue;

@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class DataInit {

    @Autowired
    private Token token;
    @Autowired
    private DictManager dictManager;
    @Autowired
    private DictItemManager dictItemManager;
    <#if project.frameValue() &gt;= 3>
    @Autowired
    private ResManager resManager;
    @Autowired
    private RoleManager roleManager;
    @Autowired
    private RoleResManager roleCreateRequest;
    </#if>

    /**
     * 字典数据初始化
     */
    @Test
    @Rollback(false)
    public void init() {
        //region 字典初始化
        {
            {// 终端类型
                createDict("TERMINAL_TYPE", "终端类型", new String[][]{
                        {"WEB", "游览器端"},
                        {"API", "接口端"},
                        {"PHONE", "手机端"},
                });
            }
            {// 错误日志类型
                createDict("LOG_ERR_TYPE", "日志错误类型", new String[][]{
                        {"SYS_ERR", "系统错误"},
                        {"BIZ_ERR", "业务错误"},
                });
            }
            {// 错误日志结果
                createDict("LOG_ERR_RESULT", "错误日志结果", new String[][]{
                        {"0", "待处理"},
                        {"1", "已处理"},
                        {"2", "搁置"},
                });
            }
            {// 资源类型
                createDict("RES_TYPE", "资源类型", new String[][]{
                        {"WEB", "网页"},
                        {"API", "接口"},
                });
            }
            {// 用户状态
                createDict("USER_STATUS", "用户状态", new String[][]{
                        {"正常", "正常"},
                        {"初始密码", "初始密码"},
                        {"锁定/注销", "锁定/注销"},
                });
            }
            {// 文件类型
                createDict("FILE_TYPE", "文件类型", new String[][]{
                        {"IMG", "图片"},
                });
            }
            {// 任务类型
                createDict("TASK_TYPE", "任务类型", new String[][]{
                        {"Cron", "Cron表达式"},
                        {"DelayRepeat", "间隔重复(秒)"},
                        {"FixRepeat", "绝对重复(秒)"},
                });
            }
            {// 环境
                createDict("ACTIVE", "环境", new String[][]{
                        {"dev", "开发环境"},
                        {"prod", "生产环境"},
                });
            }
<#list project.modules as module>
    <#list module.tables as table>
        <#list table.fields as field>
            <#if field.fieldType == 'Dict' && module.moduleName != 'wsys'>
            {// ${field.fieldComment?default('')}
                createDict("${field.fieldName?default('')}", "${field.fieldComment?default('')}", new String[][]{
                    <#list field.dictItems as dictItem>
                        {"${dictItem.key?default('')}", "${dictItem.value?default('')}"},
                    </#list>
                });
            }
            </#if>
        </#list>
    </#list>
</#list>
        }
        //endregion

        <#if project.frameValue() &gt;= 3>
        //region 管理员初始化
        {
            List<Res> forDev = new ArrayList<>();
            {// 初始化开发角色特有资源
                forDev.add(createRes("DEV", "开发管理菜单", "WEB", "DEV"));

                forDev.add(createRes("DEV_PROFILES", "系统配置菜单", "WEB", "DEV_PROFILES"));
                forDev.add(createRes("DEV_PROFILES_HTM", "系统配置管理页", "WEB", "/wsys/profiles.htm"));
                forDev.add(createRes("DEV_PROFILES_TEMPLATE", "系统配置模板", "WEB", "/ajax/wsys/profiles/template"));
                forDev.add(createRes("DEV_PROFILES_IMPORT", "系统配置导入", "WEB", "/ajax/wsys/profiles/imports"));
                forDev.add(createRes("DEV_PROFILES_EXPORT", "系统配置导出", "WEB", "/ajax/wsys/profiles/exports"));
                forDev.add(createRes("DEV_PROFILES_CREATE", "系统配置新增", "WEB", "/ajax/wsys/profiles/create"));
                forDev.add(createRes("DEV_PROFILES_DELETE", "系统配置删除", "WEB", "/ajax/wsys/profiles/delete"));
                forDev.add(createRes("DEV_PROFILES_UPDATE", "系统配置编辑", "WEB", "/ajax/wsys/profiles/update"));
                forDev.add(createRes("DEV_PROFILES_FIND", "系统配置查询", "WEB", "/ajax/wsys/profiles/find"));
                forDev.add(createRes("DEV_PROFILES_GET", "系统配置获取", "WEB", "/ajax/wsys/profiles/get"));

                forDev.add(createRes("DEV_RES", "资源管理菜单", "WEB", "DEV_RES"));
                forDev.add(createRes("DEV_RES_HTM", "资源管理页", "WEB", "/wsys/res.htm"));
                forDev.add(createRes("DEV_RES_TEMPLATE", "资源模板", "WEB", "/ajax/wsys/res/template"));
                forDev.add(createRes("DEV_RES_IMPORT", "资源导入", "WEB", "/ajax/wsys/res/imports"));
                forDev.add(createRes("DEV_RES_EXPORT", "资源导出", "WEB", "/ajax/wsys/res/exports"));
                forDev.add(createRes("DEV_RES_CREATE", "资源新增", "WEB", "/ajax/wsys/res/create"));
                forDev.add(createRes("DEV_RES_DELETE", "资源删除", "WEB", "/ajax/wsys/res/delete"));
                forDev.add(createRes("DEV_RES_UPDATE", "资源编辑", "WEB", "/ajax/wsys/res/update"));
                forDev.add(createRes("DEV_RES_FIND", "资源查询", "WEB", "/ajax/wsys/res/find"));
                forDev.add(createRes("DEV_RES_GET", "资源获取", "WEB", "/ajax/wsys/res/get"));

                forDev.add(createRes("DEV_TASK_SQL", "SQL任务菜单", "WEB", "DEV_TASK_SQL"));
                forDev.add(createRes("DEV_TASK_SQL_HTM", "SQL任务管理页", "WEB", "/wsys/taskSql.htm"));
                forDev.add(createRes("DEV_TASK_SQL_TEMPLATE", "SQL任务模板", "WEB", "/ajax/wsys/taskSql/template"));
                forDev.add(createRes("DEV_TASK_SQL_IMPORT", "SQL任务导入", "WEB", "/ajax/wsys/taskSql/imports"));
                forDev.add(createRes("DEV_TASK_SQL_EXPORT", "SQL任务导出", "WEB", "/ajax/wsys/taskSql/exports"));
                forDev.add(createRes("DEV_TASK_SQL_CREATE", "SQL任务新增", "WEB", "/ajax/wsys/taskSql/create"));
                forDev.add(createRes("DEV_TASK_SQL_DELETE", "SQL任务删除", "WEB", "/ajax/wsys/taskSql/delete"));
                forDev.add(createRes("DEV_TASK_SQL_UPDATE", "SQL任务编辑", "WEB", "/ajax/wsys/taskSql/update"));
                forDev.add(createRes("DEV_TASK_SQL_FIND", "SQL任务查询", "WEB", "/ajax/wsys/taskSql/find"));
                forDev.add(createRes("DEV_TASK_SQL_GET", "SQL任务获取", "WEB", "/ajax/wsys/taskSql/get"));
                forDev.add(createRes("DEV_SYSTEM_VISITOR", "应用接入管理菜单", "WEB", "WEB_SYSTEM_VISITOR"));
                forDev.add(createRes("DEV_SYSTEM_VISITOR_HTM", "应用接入管理页", "WEB", "/wsys/visitor.htm"));
                forDev.add(createRes("DEV_SYSTEM_VISITOR_TEMPLATE", "应用接入模板", "WEB", "/ajax/wsys/visitor/template"));
                forDev.add(createRes("DEV_SYSTEM_VISITOR_IMPORT", "应用接入导入", "WEB", "/ajax/wsys/visitor/imports"));
                forDev.add(createRes("DEV_SYSTEM_VISITOR_EXPORT", "应用接入导出", "WEB", "/ajax/wsys/visitor/exports"));
                forDev.add(createRes("DEV_SYSTEM_VISITOR_CREATE", "应用接入新增", "WEB", "/ajax/wsys/visitor/create"));
                forDev.add(createRes("DEV_SYSTEM_VISITOR_DELETE", "应用接入删除", "WEB", "/ajax/wsys/visitor/delete"));
                forDev.add(createRes("DEV_SYSTEM_VISITOR_UPDATE", "应用接入更新", "WEB", "/ajax/wsys/visitor/update"));
                forDev.add(createRes("DEV_SYSTEM_VISITOR_FIND", "应用接入查询", "WEB", "/ajax/wsys/visitor/find"));
                forDev.add(createRes("DEV_SYSTEM_VISITOR_GET", "应用接入获取", "WEB", "/ajax/wsys/visitor/get"));
                forDev.add(createRes("DEV_SYSTEM_VISITOR_RES_CREATE", "应用资源关系新增", "WEB", "/ajax/wsys/visitorRes/create"));
                forDev.add(createRes("DEV_SYSTEM_VISITOR_RES_DELETE", "应用资源关系删除", "WEB", "/ajax/wsys/visitorRes/delete"));

                forDev.add(createRes("OBS", "监控运行菜单", "WEB", "OBS"));
                forDev.add(createRes("OBS_SCHEDULE", "调度监控菜单", "WEB", "OBS_SCHEDULE"));
                forDev.add(createRes("OBS_SCHEDULE_HTM", "调度监控页", "WEB", "/wsys/schedule.htm"));
                forDev.add(createRes("OBS_SCHEDULE_FIND", "调度监控查询", "WEB", "/ajax/wsys/schedule/find"));
                forDev.add(createRes("OBS_SCHEDULE_START", "调度监控启动", "WEB", "/ajax/wsys/schedule/start"));
                forDev.add(createRes("OBS_SCHEDULE_STOP", "调度监控暂停", "WEB", "/ajax/wsys/schedule/stop"));

                forDev.add(createRes("OBS_LOG_ERR", "错误日志菜单", "WEB", "OBS_LOG_ERR"));
                forDev.add(createRes("OBS_LOG_ERR_HTM", "错误日志管理页", "WEB", "/wsys/logErr.htm"));
                forDev.add(createRes("OBS_LOG_ERR_DELETE", "错误日志删除", "WEB", "/ajax/wsys/logErr/delete"));
                forDev.add(createRes("OBS_LOG_ERR_UPDATE", "错误日志更新", "WEB", "/ajax/wsys/logErr/update"));
                forDev.add(createRes("OBS_LOG_ERR_FIND", "错误日志查询", "WEB", "/ajax/wsys/logErr/find"));
            }

            List<Res> forMgr = new ArrayList<>();
            {// 初始化管理资源
                forMgr.add(createRes("SYS", "系统管理菜单", "WEB", "SYS"));
                forMgr.add(createRes("SYS_INDEX_ROOT", "根页", "WEB", "/", true));
                forMgr.add(createRes("SYS_INDEX", "主页", "WEB", "/index.htm", true));
                forMgr.add(createRes("SYS_INDEX_HOME", "首页", "WEB", "/home.htm", true));

                forMgr.add(createRes("SYS_DICT", "字典管理菜单", "WEB", "SYS_DICT"));
                forMgr.add(createRes("SYS_DICT_HTM", "字典管理页", "WEB", "/wsys/dict.htm"));
                forMgr.add(createRes("SYS_DICT_TEMPLATE", "字典模板", "WEB", "/ajax/wsys/dict/template"));
                forMgr.add(createRes("SYS_DICT_IMPORT", "字典导入", "WEB", "/ajax/wsys/dict/imports"));
                forMgr.add(createRes("SYS_DICT_EXPORT", "字典导出", "WEB", "/ajax/wsys/dict/exports"));
                forMgr.add(createRes("SYS_DICT_CREATE", "字典新建", "WEB", "/ajax/wsys/dict/create"));
                forMgr.add(createRes("SYS_DICT_DELETE", "字典删除", "WEB", "/ajax/wsys/dict/delete"));
                forMgr.add(createRes("SYS_DICT_UPDATE", "字典更新", "WEB", "/ajax/wsys/dict/update"));
                forMgr.add(createRes("SYS_DICT_FIND", "字典查询", "WEB", "/ajax/wsys/dict/find"));
                forMgr.add(createRes("SYS_DICT_GET", "字典获取", "WEB", "/ajax/wsys/dict/get"));
                forMgr.add(createRes("SYS_DICT_LOAD", "字典详情", "WEB", "/ajax/wsys/dict/load", true));
                forMgr.add(createRes("SYS_DICT_ITEM_HTM", "字典项管理页", "WEB", "/wsys/dictItem.htm"));
                forMgr.add(createRes("SYS_DICT_ITEM_TEMPLATE", "字典项模板", "WEB", "/ajax/wsys/dictItem/template"));
                forMgr.add(createRes("SYS_DICT_ITEM_IMPORT", "字典项导入", "WEB", "/ajax/wsys/dictItem/imports"));
                forMgr.add(createRes("SYS_DICT_ITEM_EXPORT", "字典项导出", "WEB", "/ajax/wsys/dictItem/exports"));
                forMgr.add(createRes("SYS_DICT_ITEM_CREATE", "字典项新增", "WEB", "/ajax/wsys/dictItem/create"));
                forMgr.add(createRes("SYS_DICT_ITEM_DELETE", "字典项删除", "WEB", "/ajax/wsys/dictItem/delete"));
                forMgr.add(createRes("SYS_DICT_ITEM_UPDATE", "字典项更新", "WEB", "/ajax/wsys/dictItem/update"));
                forMgr.add(createRes("SYS_DICT_ITEM_FIND", "字典项查找", "WEB", "/ajax/wsys/dictItem/find"));
                forMgr.add(createRes("SYS_DICT_ITEM_GET", "字典项获取", "WEB", "/ajax/wsys/dictItem/get"));

                forMgr.add(createRes("SYS_USER", "用户管理菜单", "WEB", "SYS_USER"));
                forMgr.add(createRes("SYS_USER_HTM", "用户管理页", "WEB", "/wsys/user.htm"));
                forMgr.add(createRes("SYS_USER_TEMPLATE", "字用户模板", "WEB", "/ajax/wsys/user/template"));
                forMgr.add(createRes("SYS_USER_IMPORT", "用户导入", "WEB", "/ajax/wsys/user/imports"));
                forMgr.add(createRes("SYS_USER_EXPORT", "用户导出", "WEB", "/ajax/wsys/user/exports"));
                forMgr.add(createRes("SYS_USER_CREATE", "用户新增", "WEB", "/ajax/wsys/user/create"));
                forMgr.add(createRes("SYS_USER_DELETE", "用户删除", "WEB", "/ajax/wsys/user/delete"));
                forMgr.add(createRes("SYS_USER_UPDATE", "用户更新", "WEB", "/ajax/wsys/user/update"));
                forMgr.add(createRes("SYS_USER_FIND", "用户查询", "WEB", "/ajax/wsys/user/find"));
                forMgr.add(createRes("SYS_USER_GET", "用户获取", "WEB", "/ajax/wsys/user/get"));

                forMgr.add(createRes("SYS_DEPT", "机构管理菜单", "WEB", "SYS_DEPT"));
                forMgr.add(createRes("SYS_DEPT_HTM", "机构管理页", "WEB", "/wsys/dept.htm"));
                forMgr.add(createRes("SYS_DEPT_CREATE", "机构新增", "WEB", "/ajax/wsys/dept/create"));
                forMgr.add(createRes("SYS_DEPT_DELETE", "机构删除", "WEB", "/ajax/wsys/dept/delete"));
                forMgr.add(createRes("SYS_DEPT_UPDATE", "机构更新", "WEB", "/ajax/wsys/dept/update"));
                forMgr.add(createRes("SYS_DEPT_FIND", "机构查询", "WEB", "/ajax/wsys/dept/find"));
                forMgr.add(createRes("SYS_DEPT_GET", "机构获取", "WEB", "/ajax/wsys/dept/get"));
                forMgr.add(createRes("SYS_DEPT_TREE", "机构树查询", "WEB", "/ajax/wsys/dept/tree"));
                forMgr.add(createRes("SYS_DEPT_TEMPLATE", "机构模板", "WEB", "/ajax/wsys/dept/template"));
                forMgr.add(createRes("SYS_DEPT_IMPORT", "机构导入", "WEB", "/ajax/wsys/dept/imports"));
                forMgr.add(createRes("SYS_DEPT_EXPORT", "机构导出", "WEB", "/ajax/wsys/dept/exports"));

                forMgr.add(createRes("SYS_FILE", "文件管理菜单", "WEB", "SYS_FILE"));
                forMgr.add(createRes("SYS_FILE_HTM", "文件管理页", "WEB", "/wsys/file.htm"));
                forMgr.add(createRes("SYS_FILE_DELETE", "文件删除", "WEB", "/ajax/wsys/file/delete"));
                forMgr.add(createRes("SYS_FILE_FIND", "文件查询", "WEB", "/ajax/wsys/file/find"));

                forMgr.add(createRes("SYS_ROLE", "角色管理菜单", "WEB", "SYS_ROLE"));
                forMgr.add(createRes("SYS_ROLE_HTM", "角色管理页", "WEB", "/wsys/role.htm"));
                forMgr.add(createRes("SYS_ROLE_TEMPLATE", "角色模板", "WEB", "/ajax/wsys/role/template"));
                forMgr.add(createRes("SYS_ROLE_IMPORT", "角色导入", "WEB", "/ajax/wsys/role/imports"));
                forMgr.add(createRes("SYS_ROLE_EXPORT", "角色导出", "WEB", "/ajax/wsys/role/exports"));
                forMgr.add(createRes("SYS_ROLE_CREATE", "角色新增", "WEB", "/ajax/wsys/role/create"));
                forMgr.add(createRes("SYS_ROLE_DELETE", "角色删除", "WEB", "/ajax/wsys/role/delete"));
                forMgr.add(createRes("SYS_ROLE_UPDATE", "角色更新", "WEB", "/ajax/wsys/role/update"));
                forMgr.add(createRes("SYS_ROLE_FIND", "角色查询", "WEB", "/ajax/wsys/role/find"));
                forMgr.add(createRes("SYS_ROLE_GET", "角色获取", "WEB", "/ajax/wsys/role/get"));
                forMgr.add(createRes("SYS_ROLE_RESCHECK", "角色资源分配", "WEB", "/ajax/wsys/roleRes/check"));
                forMgr.add(createRes("SYS_ROLE_ROLERES", "角色资源关系查询", "WEB", "/ajax/wsys/roleRes/find"));
                forMgr.add(createRes("SYS_ROLE_RES_TREE", "资源树查询", "WEB", "/ajax/wsys/res/tree"));

                forMgr.add(createRes("SYS_TOKENS", "登录凭证管理菜单", "WEB", "SYS_TOKENS"));
                forMgr.add(createRes("SYS_TOKENS_HTM", "登录凭证管理页", "WEB", "/wsys/tokens.htm"));
                forMgr.add(createRes("SYS_TOKENS_FIND", "登录凭证查询", "WEB", "/ajax/wsys/tokens/find"));
                forMgr.add(createRes("SYS_TOKENS_EXPORT", "凭证导出", "WEB", "/ajax/wsys/tokens/exports"));
                forMgr.add(createRes("SYS_TOKENS_LOGOUT", "凭证注销", "WEB", "/ajax/wsys/tokens/logout"));

<#list project.modules as module>
                forMgr.add(createRes("${module.moduleName?upper_case}", "${module.moduleComment}菜单", "WEB", "WEB_${module.moduleName?upper_case}"));
    <#list module.tables as table>
        <#if table.html>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}", "${table.tableComment}管理菜单", "WEB", "WEB_${module.moduleName?upper_case}_${table.tableName?upper_case}"));
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_HTM", "${table.tableComment}管理页", "WEB", "/${module.moduleName}/${table.getFName()}.htm"));
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_TEMPLATE", "${table.tableComment}模板", "WEB", "/ajax/${module.moduleName}/${table.getFName()}/template"));
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_IMPORT", "${table.tableComment}导入", "WEB", "/ajax/${module.moduleName}/${table.getFName()}/imports"));
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_EXPORT", "${table.tableComment}导出", "WEB", "/ajax/${module.moduleName}/${table.getFName()}/exports"));
        </#if>
        <#if table.create>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_CREATE", "${table.tableComment}新增", "WEB", "/ajax/${module.moduleName}/${table.getFName()}/create"));
        </#if>
        <#if table.delete>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_DELETE", "${table.tableComment}删除", "WEB", "/ajax/${module.moduleName}/${table.getFName()}/delete"));
        </#if>
        <#if table.update>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_UPDATE", "${table.tableComment}更新", "WEB", "/ajax/${module.moduleName}/${table.getFName()}/update"));
        </#if>
        <#if table.find>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_FIND", "${table.tableComment}查询", "WEB", "/ajax/${module.moduleName}/${table.getFName()}/find"));
        </#if>
        <#if table.get>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_GET", "${table.tableComment}获取", "WEB", "/ajax/${module.moduleName}/${table.getFName()}/get"));
        </#if>
        <#if table.search>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_SEARCH", "${table.tableComment}搜索", "WEB", "/ajax/${module.moduleName}/${table.getFName()}/search"));
        </#if>

    </#list>
</#list>
<#if project.isNeedApi()>
                forMgr.add(createRes("SYS_USER_LOGIN", "用户登录", "API", "/api/wsys/User/login"));
                forMgr.add(createRes("SYS_DICT_FIND", "字典查询", "API", "/api/wsys/Dict/find"));
                forMgr.add(createRes("SYS_DICT_LOAD", "加载字典", "API", "/api/wsys/Dict/load"));
                forMgr.add(createRes("SYS_FILE_UPLOAD", "文件上传", "API", "/api/wsys/File/upload"));
                forMgr.add(createRes("SYS_FILE_DOWNLOAD", "文件下载", "API", "/api/wsys/File/download"));
<#list project.modules as module>
    <#list module.tables as table>
        <#if table.create>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_CREATE", "${table.tableComment}新增", "API", "/api/${module.moduleName}/${table.getFName()}/create"));
        </#if>
        <#if table.delete>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_DELETE", "${table.tableComment}删除", "API", "/api/${module.moduleName}/${table.getFName()}/delete"));
        </#if>
        <#if table.update>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_UPDATE", "${table.tableComment}更新", "API", "/api/${module.moduleName}/${table.getFName()}/update"));
        </#if>
        <#if table.find>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_FIND", "${table.tableComment}查询", "API", "/api/${module.moduleName}/${table.getFName()}/find"));
        </#if>
        <#if table.get>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_GET", "${table.tableComment}获取", "API", "/api/${module.moduleName}/${table.getFName()}/get"));
        </#if>
        <#if table.search>
                forMgr.add(createRes("${module.moduleName?upper_case}_${table.tableName?upper_case}_SEARCH", "${table.tableComment}搜索", "API", "/api/${module.moduleName}/${table.getFName()}/search"));
        </#if>
    </#list>
</#list>
</#if>
            }

            {//初始化开发角色
                Long roleId = createRole("developer", "开发", "开发");
                for (Res res : forDev) {
                    allocateRes(roleId, "developer", res.getId(), res.getResCode());
                }
                for (Res res : forMgr) {
                    allocateRes(roleId, "developer", res.getId(), res.getResCode());
                }
            }
            {//初始化管理角色
                Long roleId = createRole("management", "管理员", "管理员");
                for (Res res : forMgr) {
                    allocateRes(roleId, "management", res.getId(), res.getResCode());
                }
            }
        }
        //endregion
        </#if>
    }

    private void createDict(String name, String comment, String[][] items) {
        DictCreateRequest dictCreateRequest = new DictCreateRequest();
        dictCreateRequest.setDictName(name);
        dictCreateRequest.setDictComment(comment);
        dictCreateRequest.setVersion(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        dictCreateRequest.setValid(true);
        DictCreateResponse dictCreateResponse = dictManager.create(dictCreateRequest, token);
        printError(dictCreateResponse);
        assertTrue(!dictCreateResponse.hasError());

        for (int i = 0; i < items.length; i++) {
            String[] item = items[i];
            DictItemCreateRequest dictItemCreateRequest = new DictItemCreateRequest();
            dictItemCreateRequest.setDictName(name);
            dictItemCreateRequest.setKey(item[0]);
            dictItemCreateRequest.setValue(item[1]);
            dictItemCreateRequest.setSort(i);
            dictItemCreateRequest.setValid(true);
            DictItemCreateResponse dictItemCreateResponse = dictItemManager.create(dictItemCreateRequest, token);
            printError(dictItemCreateResponse);
            assertTrue(!dictItemCreateResponse.hasError());
        }
    }
    <#if project.frameValue() &gt;= 3>

    private Res createRes(String code, String name, String resType, String value) {
        return createRes(code,name,resType,value,false);
    }

    private Res createRes(String code, String name, String resType, String value, boolean free) {
        ResCreateRequest resCreateRequest = new ResCreateRequest();
        resCreateRequest.setResName(name);
        resCreateRequest.setResCode(code);
        resCreateRequest.setResType(resType);
        resCreateRequest.setResValue(value);
        resCreateRequest.setFree(free);
        resCreateRequest.setValid(true);
        ResCreateResponse resCreateResponse = resManager.create(resCreateRequest, token);
        printError(resCreateResponse);
        if (resCreateResponse.hasError() && resCreateResponse.getErrors().get(0).getMessage().equals(Message.INSERT_DUPLICATE)) {
            ResFindRequest resFindRequest = new ResFindRequest();
            resFindRequest.setResCode(code);
            ResFindResponse resFindResponse = resManager.find(resFindRequest, token);
            return resFindResponse.getResult().get(0);
        } else if (resCreateResponse.hasError()) {
            assertTrue(!resCreateResponse.hasError());
            return null;
        } else {
            Res res = new Res();
            res.setResCode(code);
            res.setResName(name);
            res.setResType(resType);
            res.setId(resCreateResponse.getId());
            return res;
        }
    }

    private Long createRole(String roleCode, String roleName, String roleComment) {
        RoleCreateRequest roleCreateRequest = new RoleCreateRequest();
        roleCreateRequest.setCode(roleCode);
        roleCreateRequest.setName(roleName);
        roleCreateRequest.setComment(roleComment);
        RoleCreateResponse roleCreateResponse = roleManager.create(roleCreateRequest, token);
        printError(roleCreateResponse);
        assertTrue(!roleCreateResponse.hasError());
        return roleCreateResponse.getId();
    }

    private void allocateRes(Long roleId, String roleCode, Long resId, String resCode) {
        RoleResCheckRequest roleResCheckRequest = new RoleResCheckRequest();
        roleResCheckRequest.setRoleId(roleId);
        roleResCheckRequest.setRoleCode(roleCode);
        roleResCheckRequest.setResId(resId);
        roleResCheckRequest.setResCode(resCode);
        roleResCheckRequest.setChecked(true);

        RoleResCheckResponse roleResCheckResponse = roleCreateRequest.check(roleResCheckRequest, token);
        printError(roleResCheckResponse);
        assertTrue(!roleResCheckResponse.hasError());
    }
    </#if>

    private void printError(BaseResponse response) {
        if (response.hasError()) {
            System.err.println("==========>" + MapperUtil.toJson(response));
        }
    }
}