lrf 7 месяцев назад
Родитель
Сommit
03337871a7

+ 7 - 1
src/controller/home.controller.ts

@@ -8,6 +8,7 @@ import { DataDealService } from '../service/initData/dataDeal.service';
 import { TestsService } from '../service/tests.service';
 import { ESService } from '../service/elasticsearch/es.service';
 import { Opera } from '../frame/dbOpera';
+import { InitSystemDataService } from '../service/initData/initSystemData.service';
 @Controller('/')
 export class HomeController {
   @Inject()
@@ -26,12 +27,17 @@ export class HomeController {
   testService: TestsService;
   @Inject()
   esService: ESService;
+  @Inject()
+  initSystemDataService: InitSystemDataService;
 
   Opera = Opera;
 
   @Get('/')
   async home(@Query() query: object): Promise<any> {
-    await this.dataDealService.correctImportData()
+    // await this.initSystemDataService.initSystemMenus();
+    // await this.initSystemDataService.initRoleData();
+    // await this.initSystemDataService.initRoleMenus();
+    // await this.dataDealService.correctImportData();
     // await this.esService.initES()
     // await this.dataDealService.initUserMenus();
     // await this.dataDealService.initRoleMenus();

+ 1 - 1
src/controller/system/dept.controller.ts

@@ -21,7 +21,7 @@ export class DeptController implements BaseController {
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others = pick(query, ['skip', 'limit']);
-    const result = await this.service.query(qobj, others);
+    const result = await this.service.query(qobj, others, { order: { order_num: 'DESC' } });
     return result;
   }
   @Get('/')

+ 2 - 2
src/controller/system/menus.controller.ts

@@ -16,11 +16,11 @@ export class MenusController implements BaseController {
   @Get('/')
   @ApiTags('列表查询')
   @ApiResponse({ type: QVO_menus })
-  async index() {
+  async index(@Query() query: object) {
     // const qobj = omit(query, ['skip', 'limit']);
     // const others = pick(query, ['skip', 'limit']);
     // const qbr = this.service.queryBuilder(qobj);
-    const result = await this.service.queryMenu();
+    const result = await this.service.queryMenu(query);
     return result;
   }
 

+ 11 - 0
src/controller/token.controller.ts

@@ -5,6 +5,7 @@ import get = require('lodash/get');
 import { RoleService } from '../service/system/role.service';
 import { Controller, Get, Inject, MidwayWebRouterService, Post } from '@midwayjs/core';
 import { ErrorCode, ServiceError } from '../error/service.error';
+import { LoginService } from '../service/login.service';
 @ApiTags(['工具'])
 @Controller('/token')
 export class TokenController {
@@ -13,6 +14,9 @@ export class TokenController {
 
   @Inject()
   roleService: RoleService;
+  @Inject()
+  loginService: LoginService;
+
   @Inject()
   webRouterService: MidwayWebRouterService;
 
@@ -25,6 +29,13 @@ export class TokenController {
     const token = get(this.ctx, 'request.header.token');
     if (!token) throw new ServiceError(ErrorCode.NOT_LOGIN);
     const result: any = await this.jwtService.decode(token);
+    // 根据角色,重新获取昵称,实时更新
+    const role = get(result, 'role');
+    const id = get(result, 'id');
+    const userInfo = await this.loginService.tokenViewGetUserInfo(role, id);
+    if (userInfo) {
+      result.nick_name = get(userInfo, 'nick_name', result.nick_name);
+    }
     const userMenusResult = await this.roleService.getUserMenus();
     const menus = get(userMenusResult, 'menus');
     const role_code = get(userMenusResult, 'role_code');

+ 3 - 3
src/entity/system/menus.entity.ts

@@ -9,11 +9,11 @@ import { BaseModel } from '../../frame/BaseModel';
 // 菜单表
 @Entity('menus')
 export class Menus extends BaseModel {
-  @Column({ type: 'character varying', comment: '目录名称' })
+  @Column({ type: 'character varying', nullable: true, comment: '目录名称' })
   name: string;
-  @Column({ type: 'character varying', comment: '路由名称 英文' })
+  @Column({ type: 'character varying', nullable: true, comment: '路由名称 英文' })
   route_name: string;
-  @Column({ type: 'character varying', comment: '国际化编码' })
+  @Column({ type: 'character varying', nullable: true, comment: '国际化编码' })
   i18n_code: string;
   @Column({ type: 'integer', nullable: true, comment: '父级目录' })
   parent_id: number;

+ 1 - 1
src/entity/users/company.entity.ts

@@ -14,7 +14,7 @@ export class Company extends BaseModel {
   name: string;
   @Column({ type: 'jsonb', nullable: true, comment: 'logo', default: [] })
   logo: Array<any>;
-  @Column({ type: 'character varying', nullable: true, comment: '企业统一信用代码名称' })
+  @Column({ type: 'character varying', nullable: true, comment: '企业统一信用代码' })
   code: string;
   @Column({ type: 'character varying', nullable: true, comment: '企业类型' })
   pattern: string;

+ 1 - 1
src/entity/users/state.entity.ts

@@ -19,6 +19,6 @@ export class State extends BaseModel {
   brief: string;
   @Column({ type: 'character varying', nullable: true, comment: '是否公开' })
   is_show: string;
-  @Column({ type: 'character varying', nullable: true, comment: '状态' })
+  @Column({ type: 'character varying', nullable: true, comment: '状态', default: '0' })
   status: string;
 }

+ 1 - 1
src/entity/users/unit.entity.ts

@@ -17,6 +17,6 @@ export class Unit extends BaseModel {
   address: string;
   @Column({ type: 'character varying', nullable: true, comment: '是否公开' })
   is_show: string;
-  @Column({ type: 'character varying', nullable: true, comment: '状态' })
+  @Column({ type: 'character varying', nullable: true, comment: '状态', default: '0' })
   status: string;
 }

+ 21 - 2
src/frame/BaseServiceV2.ts

@@ -234,8 +234,15 @@ export abstract class BaseServiceV2 {
           break;
         case this.Opera.Equal:
         default:
-          str = `"${key}" = :${valueStr}`;
-          params = { [`${valueStr}`]: value };
+          const isString = this.columnIsString(key);
+          if (isString) {
+            // 字符串默认使用模糊查询
+            str = `"${key}" Like :${valueStr}`;
+            params = { [`${valueStr}`]: `%${value}%` };
+          } else {
+            str = `"${key}" = :${valueStr}`;
+            params = { [`${valueStr}`]: value };
+          }
           break;
       }
       if (!str) continue;
@@ -425,4 +432,16 @@ export abstract class BaseServiceV2 {
     const has = columns.find(f => get(f, 'propertyName') === columnName);
     return !isUndefined(has);
   }
+  /**
+   * 检查字段是否是字符串字段
+   * @param {string} columnName 字段名
+   */
+  private columnIsString(columnName: string) {
+    const columns = this.model.metadata.columns;
+    const colSetting = columns.find(f => get(f, 'propertyName') === columnName);
+    if (!colSetting) return false;
+    const type = get(colSetting, 'type');
+    if (!type) return false;
+    return type === 'character varying' || type === 'text';
+  }
 }

+ 799 - 0
src/service/initData/initSystemData.service.ts

@@ -0,0 +1,799 @@
+import { Provide } from '@midwayjs/core';
+import { InjectDataSource, InjectEntityModel } from '@midwayjs/typeorm';
+import { DataSource, Repository } from 'typeorm';
+import { Menus } from '../../entity/system/menus.entity';
+import { cloneDeep, flattenDeep, get } from 'lodash';
+import { Role } from '../../entity/system/role.entity';
+import { UserMenus } from '../../entity/system/userMenus.entity';
+
+@Provide()
+export class InitSystemDataService {
+  @InjectEntityModel(Menus)
+  Menus: Repository<Menus>;
+  @InjectEntityModel(Role)
+  Role: Repository<Role>;
+  @InjectEntityModel(UserMenus)
+  UserMenus: Repository<UserMenus>;
+  @InjectDataSource('default')
+  defaultDataSource: DataSource;
+  /**初始化角色的菜单(不包含管理员) */
+  async initRoleMenus() {
+    const builder = this.Role.createQueryBuilder().update(Role);
+    /**共有: 基础信息,认证信息,行业动态 */
+    const common = ['center_basic', 'center_attestation', 'center_notice', 'center_collection', 'center_password', 'center_sign'];
+    // 只用通用菜单的角色
+    const justCommonRole = ['User', 'Association', 'Investment', 'State'];
+    await builder.set({ menu: common }).where('code IN (:...value)', { value: justCommonRole }).execute();
+    // 第一类菜单
+    const menus1 = [...common, 'center_news2', 'center_demand', 'center_supply', 'center_achievement', 'center_project', 'center_footplate', 'center_service'];
+    // 第一类菜单用户: 用户,科研机构,孵化基地,企业,高校
+    const roleUseMenus1 = ['Expert', 'Unit', 'Incubator', 'Company', 'YX'];
+    await builder.set({ menu: menus1 }).where('code IN (:...value)', { value: roleUseMenus1 }).execute();
+    // 创业大赛用户: 需要去掉报名管理,加入赛事管理
+    const MatchRole = common.filter(f => f != 'center_sign');
+    MatchRole.push('center_match');
+    await builder
+      .set({ menu: MatchRole })
+      .where('code IN (:...value)', { value: ['Competition'] })
+      .execute();
+  }
+
+  /**初始化角色数据 */
+  async initRoleData() {
+    await this.clearTable(get(this.Role, 'metadata.givenTableName'));
+    let datas: any = [
+      {
+        code: 'Admin',
+        name: '管理员',
+        menu: ['home'],
+        is_use: '0',
+        is_default: '0',
+        is_admin_role: '1',
+      },
+      {
+        code: 'User',
+        name: '普通用户',
+        is_use: '0',
+        is_default: '0',
+        is_admin_role: '0',
+      },
+      {
+        code: 'Expert',
+        name: '专家',
+        is_use: '0',
+        is_default: '0',
+        is_admin_role: '0',
+      },
+      {
+        code: 'Company',
+        name: '企业',
+        is_use: '0',
+        is_default: '0',
+        is_admin_role: '0',
+      },
+      {
+        code: 'Unit',
+        name: '科研机构',
+        is_use: '0',
+        is_default: '0',
+        is_admin_role: '0',
+      },
+      {
+        code: 'Incubator',
+        name: '孵化基地',
+        is_use: '0',
+        is_default: '0',
+        is_admin_role: '0',
+      },
+      {
+        code: 'Competition',
+        name: '创业大赛',
+        is_use: '0',
+        is_default: '0',
+        is_admin_role: '0',
+      },
+
+      {
+        code: 'Association',
+        name: '商协会',
+        is_use: '0',
+        is_default: '0',
+        is_admin_role: '0',
+      },
+      {
+        code: 'School',
+        name: '院校',
+        is_use: '0',
+        is_default: '0',
+        is_admin_role: '0',
+      },
+      {
+        code: 'State',
+        name: '政府部门',
+        is_use: '0',
+        is_default: '0',
+        is_admin_role: '0',
+      },
+      {
+        code: 'Investment',
+        name: '投资人',
+        is_use: '0',
+        is_default: '0',
+        is_admin_role: '0',
+      },
+    ];
+    for (let i = 0; i < datas.length; i++) {
+      const e = datas[i];
+      e.id = i + 1;
+    }
+    await this.Role.insert(datas);
+  }
+  /**初始化用户目录 */
+  async initUserMenus() {
+    await this.clearTable(get(this.UserMenus, 'metadata.givenTableName'));
+    const datas = [
+      {
+        order_num: 0,
+        name: '基础信息',
+        route_name: 'center_basic',
+        i18n_code: 'menus.center_basic',
+        path: '/center/basic',
+        component: '/center/basic',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'User',
+      },
+      {
+        order_num: 1,
+        name: '认证入驻',
+        route_name: 'center_attestation',
+        i18n_code: 'menus.center_attestation',
+        path: '/center/attestation',
+        component: '/center/attestation',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'Finished',
+      },
+      {
+        order_num: 2,
+        name: '通知管理',
+        route_name: 'center_notice',
+        i18n_code: 'menus.center_notice',
+        path: '/center/notice',
+        component: '/center/notice',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'Notebook',
+      },
+      {
+        order_num: 3,
+        name: '行业动态',
+        route_name: 'center_news2',
+        i18n_code: 'menus.center_news2',
+        path: '/center/news2',
+        component: '/center/news2',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'Message',
+      },
+      {
+        order_num: 4,
+        name: '需求管理',
+        route_name: 'center_demand',
+        i18n_code: 'menus.center_demand',
+        path: '/center/demand',
+        component: '/center/demand',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'DataBoard',
+      },
+      {
+        order_num: 5,
+        name: '供给管理',
+        route_name: 'center_supply',
+        i18n_code: 'menus.center_supply',
+        path: '/center/supply',
+        component: '/center/supply',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'Notification',
+      },
+      {
+        order_num: 6,
+        name: '成果管理',
+        route_name: 'center_achievement',
+        i18n_code: 'menus.center_achievement',
+        path: '/center/achievement',
+        component: '/center/achievement',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'Medal',
+      },
+      {
+        order_num: 7,
+        name: '项目管理',
+        route_name: 'center_project',
+        i18n_code: 'menus.center_project',
+        path: '/center/project',
+        component: '/center/project',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'Trophy',
+      },
+      {
+        order_num: 8,
+        name: '中试管理',
+        route_name: 'center_footplate',
+        i18n_code: 'menus.center_footplate',
+        path: '/center/footplate',
+        component: '/center/footplate',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'TakeawayBox',
+      },
+      {
+        order_num: 9,
+        name: '服务管理',
+        route_name: 'center_service',
+        i18n_code: 'menus.center_service',
+        path: '/center/service',
+        component: '/center/service',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'TakeawayBox',
+      },
+      {
+        order_num: 10,
+        name: '赛事管理',
+        route_name: 'center_match',
+        i18n_code: 'menus.center_match',
+        path: '/center/match',
+        component: '/center/match',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'CollectionTag',
+      },
+      {
+        order_num: 11,
+        name: '活动管理',
+        route_name: 'center_sign',
+        i18n_code: 'menus.center_sign',
+        path: '/center/sign',
+        component: '/center/sign',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'Suitcase',
+      },
+      {
+        order_num: 12,
+        name: '产研行研',
+        route_name: 'center_journal',
+        i18n_code: 'menus.center_journal',
+        path: '/center/journal',
+        component: '/center/journal',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'Reading',
+      },
+      {
+        order_num: 13,
+        name: '企业选择',
+        route_name: 'center_company',
+        i18n_code: 'menus.center_company',
+        path: '/center/company',
+        component: '/center/company',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'SwitchFilled',
+      },
+      {
+        order_num: 998,
+        name: '我的收藏',
+        route_name: 'center_collection',
+        i18n_code: 'menus.center_collection',
+        path: '/center/collection',
+        component: '/center/collection',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'Collection',
+      },
+      {
+        order_num: 999,
+        name: '修改密码',
+        route_name: 'center_password',
+        i18n_code: 'menus.center_password',
+        path: '/center/password',
+        component: '/center/password',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+        icon: 'Lock',
+      },
+    ];
+    await this.UserMenus.insert(datas);
+  }
+  /**初始化后台目录 */
+  async initSystemMenus() {
+    await this.clearTable(get(this.Menus, 'metadata.givenTableName'));
+    let datas: any = [
+      {
+        name: '首页',
+        path: '/',
+        type: '1',
+        is_default: '0',
+        is_use: '0',
+        route_name: 'home',
+      },
+      {
+        name: '系统管理',
+        path: '/system/index',
+        type: '1',
+        is_default: '0',
+        is_use: '0',
+        route_name: 'system',
+        children: [
+          {
+            name: '管理员目录',
+            component: 'admin-menus',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'system_admin_menus',
+          },
+          {
+            name: '用户目录',
+            component: 'user-menus',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'system_user_menus',
+          },
+          {
+            name: '字典管理',
+            component: 'dict',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'system_dict',
+          },
+          {
+            name: '地区管理',
+            component: 'region',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'system_region',
+          },
+        ],
+      },
+      {
+        name: '平台设置',
+        path: '/platform/index',
+        type: '1',
+        is_default: '0',
+        is_use: '0',
+        route_name: 'platform',
+        children: [
+          {
+            name: '基础设置',
+            component: 'basic',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'platform_basic',
+          },
+          {
+            name: '部门管理',
+            component: 'dept',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'platform_dept',
+          },
+          {
+            name: '角色管理',
+            component: 'role',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'platform_role',
+          },
+          {
+            name: '标签管理',
+            component: 'tags',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'platform_tags',
+          },
+          {
+            name: '产业管理',
+            component: 'sector',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'platform_sector',
+          },
+          {
+            name: '合作伙伴',
+            component: 'friend',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'platform_friend',
+          },
+          {
+            name: '导入数据',
+            component: 'import',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'platform_import',
+          },
+        ],
+      },
+      {
+        name: '信息管理',
+        path: '/information/index',
+        type: '1',
+        is_default: '0',
+        is_use: '0',
+        route_name: 'information',
+        children: [
+          {
+            name: '平台数据',
+            component: 'platform',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'information_platform',
+            children: [
+              {
+                name: '供方信息',
+                component: 'supply',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_platform_supply',
+              },
+              {
+                name: '需求信息',
+                component: 'demand',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_platform_demand',
+              },
+              {
+                name: '技术成果',
+                component: 'achievement',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_platform_achievement',
+              },
+              {
+                name: '双创活动',
+                component: 'match',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_platform_match',
+              },
+              {
+                name: '项目信息',
+                component: 'project',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_platform_project',
+              },
+              {
+                name: '中试信息',
+                component: 'footplate',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_platform_footplate',
+              },
+              {
+                name: '服务支撑',
+                component: 'support',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_platform_support',
+              },
+            ],
+          },
+          {
+            name: '角色数据',
+            component: 'role',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'information_role',
+            children: [
+              {
+                name: '创业大赛',
+                component: 'competition',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_role_competition',
+              },
+              {
+                name: '投资人',
+                component: 'investment',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_role_investment',
+              },
+              {
+                name: '商协会',
+                component: 'association',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_role_association',
+              },
+              {
+                name: '政府部门',
+                component: 'state',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_role_state',
+              },
+              {
+                name: '院校',
+                component: 'school',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_role_school',
+              },
+              {
+                name: '企业',
+                component: 'company',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_role_company',
+              },
+              {
+                name: '专家',
+                component: 'expert',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_role_expert',
+              },
+              {
+                name: '科研机构',
+                component: 'unit',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_role_unit',
+              },
+              {
+                name: '孵化基地',
+                component: 'incubator',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_role_incubator',
+              },
+            ],
+          },
+          {
+            name: '平台新闻',
+            component: 'news',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'information_news',
+            children: [
+              {
+                name: '政策信息',
+                component: 'policy',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_news_policy',
+              },
+              {
+                name: '新闻通知',
+                component: 'news',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_news_news',
+              },
+              {
+                name: '行业动态',
+                component: 'trends',
+                type: '2',
+                is_default: '0',
+                is_use: '0',
+                route_name: 'information_news_trends',
+              },
+            ],
+          },
+          {
+            name: '信息库',
+            component: 'info',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'information_info',
+            children: [
+              {
+                name: '专家库',
+                component: 'expert',
+                type: '2',
+                is_default: '0',
+                is_use: '1',
+                route_name: 'information_info_expert',
+              },
+              {
+                name: '企业库',
+                component: 'company',
+                type: '2',
+                is_default: '0',
+                is_use: '1',
+                route_name: 'information_info_company',
+              },
+              {
+                name: '项目库',
+                component: 'project',
+                type: '2',
+                is_default: '0',
+                is_use: '1',
+                route_name: 'information_info_project',
+              },
+              {
+                name: '供需库',
+                component: 'sd',
+                type: '2',
+                is_default: '0',
+                is_use: '1',
+                route_name: 'information_info_sd',
+              },
+            ],
+          },
+        ],
+      },
+      {
+        name: '行研产研',
+        path: '/journal/index',
+        type: '1',
+        is_default: '0',
+        is_use: '0',
+        route_name: 'journal',
+      },
+      {
+        name: '用户管理',
+        path: '/user/index',
+        type: '1',
+        is_default: '0',
+        is_use: '0',
+        route_name: 'user',
+        children: [
+          {
+            name: '管理员用户',
+            component: 'admin',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'user_admin',
+          },
+          {
+            name: '平台用户',
+            component: 'user',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'user_user',
+          },
+        ],
+      },
+      {
+        name: '数据看板',
+        path: '/board/index',
+        type: '1',
+        is_default: '0',
+        is_use: '0',
+        route_name: 'board',
+      },
+      {
+        name: '站内消息',
+        order_num: 998,
+        path: '/message/index',
+        type: '1',
+        is_default: '0',
+        is_use: '0',
+        route_name: 'message',
+      },
+      {
+        name: '日志管理',
+        order_num: 999,
+        path: '/log/index',
+        type: '1',
+        is_default: '0',
+        is_use: '0',
+        route_name: 'log',
+      },
+    ];
+    // 声明每个数据id.降维并带上父级id
+    // 递归处理
+    let id = 1;
+    const deepDeal = (list, parent_id?) => {
+      const result = [];
+      for (let i = 0; i < list.length; i++) {
+        const d = list[i];
+        // 补充id和order_num和parent_id
+        d.id = cloneDeep(id);
+        id = id + 1;
+        if (!get(d, 'order_num')) d.order_num = i + 1;
+        if (parent_id) {
+          // 有上级id,则一定是子页面
+          d.parent_id = parent_id;
+          d.type = '2';
+        }
+        let children = get(d, 'children');
+        const cd = cloneDeep(d);
+        delete cd.children;
+        result.push(cd);
+        if (!children) continue;
+        children = deepDeal(children, d.id);
+        result.push(...children);
+      }
+      return result;
+    };
+    const odDatas = deepDeal(datas);
+    await this.Menus.insert(odDatas);
+  }
+
+  /**
+   * 清空表与id序列
+   * @param tableName 表名 小驼峰
+   */
+  private async clearTable(tableName: string) {
+    await this.defaultDataSource.query(`TRUNCATE TABLE "public"."${tableName}" RESTART IDENTITY RESTRICT;`);
+    await this.defaultDataSource.query(`SELECT setval('"${tableName}_id_seq"', (SELECT max(id) FROM "${tableName}"));`);
+  }
+}

+ 9 - 0
src/service/login.service.ts

@@ -32,6 +32,15 @@ export class LoginService {
   @InjectEntityModel(User)
   userModel: Repository<User>;
 
+  async tokenViewGetUserInfo(role: Array<string>, id: number) {
+    const hasAdminRole = role.find(f => f === LoginType.Admin);
+    let model;
+    if (hasAdminRole) model = this.adminModel;
+    else model = this.userModel;
+    const user = await model.createQueryBuilder().where('id = :id', { id }).getOne();
+    return user;
+  }
+
   async onePointLogin(loginVo) {
     const { id, role } = loginVo;
     const rediskey = `${this.loginSign}:${role}:${id}`;

+ 2 - 1
src/service/system/dept.service.ts

@@ -13,7 +13,7 @@ export class DeptService extends BaseServiceV2 {
   model: Repository<Dept>;
   async queryAll() {
     // const data = await this.model.find({ order: { order_num: 'DESC' } });
-    const { data } = await this.query(null, { order: { order_num: 'DESC' } });
+    const { data } = await this.query(null, { order: { order_num: 'ASC' } });
     let treeData = data.filter(f => !f.parent_id);
     treeData = this.treeData(data, treeData);
     return treeData;
@@ -24,6 +24,7 @@ export class DeptService extends BaseServiceV2 {
     builder.where(`parent_id = :value`, { value: id });
     if (isNumber(get(query, 'skip'))) builder.skip(get(query, 'skip'));
     if (isNumber(get(query, 'limit'))) builder.take(get(query, 'limit'));
+    builder.orderBy({ order_num: 'ASC' });
     const result = await builder.getMany();
     const total = await builder.getCount();
     const ids = result.map(i => i.parent_id);

+ 3 - 3
src/service/users/association.service.ts

@@ -5,9 +5,9 @@ import { Association } from '../../entity/users/association.entity';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 @Provide()
 export class AssociationService extends BaseServiceV2 {
-  getQueryColumnsOpera(): object {
-    return {};
-  }
   @InjectEntityModel(Association)
   model: Repository<Association>;
+  getQueryColumnsOpera(): {} {
+    return { name: this.Opera.Like, person: this.Opera.Like, address: this.Opera.Like };
+  }
 }

+ 3 - 0
src/service/users/investment.service.ts

@@ -7,4 +7,7 @@ import { BaseServiceV2 } from '../../frame/BaseServiceV2';
 export class InvestmentService extends BaseServiceV2 {
   @InjectEntityModel(Investment)
   model: Repository<Investment>;
+  getQueryColumnsOpera(): {} {
+    return { name: this.Opera.Like };
+  }
 }