lrf hace 8 meses
padre
commit
978bc04fca

+ 5 - 3
src/controller/home.controller.ts

@@ -26,13 +26,15 @@ export class HomeController {
   testService: TestsService;
   @Get('/')
   async home(@Query() query: object): Promise<any> {
+    await this.dataDealService.initUserMenus();
+    await this.dataDealService.initRoleMenus();
     // await this.oneService.addTags();
     // await this.oneService.addImportDataTags();
     // await this.twoService.addTags();
     // await this.twoService.addImportDataTags();
-    await this.oneService.dataToUse();
-    await this.twoService.dataToUse();
-    await this.threeService.dataToUse();
+    // await this.oneService.dataToUse();
+    // await this.twoService.dataToUse();
+    // await this.threeService.dataToUse();
     // const data = await this.qichachaService.searchByName('长春市福瑞科技');
     // await this.threeService.import2021Company();
     // await this.threeService.import2024Company();

+ 66 - 0
src/controller/system/userMenus.controller.ts

@@ -0,0 +1,66 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/core';
+import { ApiQuery, ApiResponse, ApiTags } from '@midwayjs/swagger';
+import { BaseController } from '../../frame/BaseController';
+import { UserMenusService } from '../../service/system/userMenus.service';
+import { Validate } from '@midwayjs/validate';
+import { omit, pick } from 'lodash';
+import { ServiceError, ErrorCode } from '../../error/service.error';
+import { CVO_menus, FVO_menus, QVO_menus, UVAO_menus } from '../../interface/system/menus.interface';
+
+const namePrefix = '用户目录';
+@ApiTags(['用户目录'])
+@Controller('/userMenus', { tagName: namePrefix })
+export class UserMenusController implements BaseController {
+  controllerCode = 'system_userMenus';
+  @Inject()
+  service: UserMenusService;
+  
+  @Get('/')
+  @ApiTags('列表查询')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_menus })
+  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, order: { order_num: 'ASC' } });
+    return result;
+  }
+
+  @Get('/:id')
+  @ApiTags('单查询')
+  @ApiResponse({ type: FVO_menus })
+  async fetch(@Param('id') id: number) {
+    const data = await this.service.fetch({ id });
+    const result = new FVO_menus(data);
+    return result;
+  }
+
+  @Post('/', { routerName: `创建${namePrefix}` })
+  @ApiTags('创建数据')
+  @Validate()
+  @ApiResponse({ type: CVO_menus })
+  async create(@Body() data: object) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_menus(dbData);
+    return result;
+  }
+
+  @Post('/:id', { routerName: `修改${namePrefix}` })
+  @ApiTags('修改数据')
+  @Validate()
+  @ApiResponse({ type: UVAO_menus })
+  async update(@Param('id') id: number, @Body() data: object) {
+    if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
+    const result = await this.service.update({ id }, data);
+    return result;
+  }
+
+  @Del('/:id', { routerName: `删除${namePrefix}` })
+  @ApiTags('删除数据')
+  @Validate()
+  async delete(@Param('id') id: number) {
+    if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
+    const result = await this.service.delete({ id });
+    return result;
+  }
+}

+ 2 - 2
src/entity/system/user.entity.ts

@@ -10,8 +10,8 @@ export class User extends BaseModel {
   nick_name: string;
   @Column({ type: 'character varying', comment: '账号', unique: true })
   account: string;
-  @Column({ type: 'character varying', nullable: true, comment: '所属产业' })
-  industry: string;
+  @Column({ type: 'jsonb', nullable: true, comment: '所属产业' })
+  industry: Array<any>;
   @Column({
     type: 'character varying',
     select: false,

+ 38 - 0
src/entity/system/userMenus.entity.ts

@@ -0,0 +1,38 @@
+import { Column, Entity } from 'typeorm';
+import { BaseModel } from '../../frame/BaseModel';
+
+// interface config {
+//   comment: '中文';
+//   code: '页面功能编码';
+//   controller_code: '接口函数名路径';
+// }
+// 菜单表
+@Entity('userMenus')
+export class UserMenus extends BaseModel {
+  @Column({ type: 'character varying', comment: '目录名称' })
+  name: string;
+  @Column({ type: 'character varying', comment: '路由名称 英文' })
+  route_name: string;
+  @Column({ type: 'character varying', comment: '国际化编码' })
+  i18n_code: string;
+  @Column({ type: 'integer', nullable: true, comment: '父级目录' })
+  parent_id: number;
+  @Column({ type: 'integer', nullable: true, comment: '显示顺序' })
+  order_num: number;
+  @Column({ type: 'character varying', nullable: true, comment: '路由地址' })
+  path: string;
+  @Column({ type: 'character varying', nullable: true, comment: '组件地址' })
+  component: string;
+  @Column({ type: 'character varying', comment: '目录类型 0:目录;1:目录;2:子页面' })
+  type: string;
+  @Column({ type: 'character varying', nullable: true, comment: '图标' })
+  icon: string;
+  @Column({ type: 'jsonb', nullable: true, comment: '功能列表 不在功能列表中的功能不能使用', default: [] })
+  config: Array<any>;
+  @Column({ type: 'character varying', comment: '是否为默认目录 默认:0,非默认:1; 默认不能删除', default: '1' })
+  is_default: string;
+  @Column({ type: 'text', nullable: true, comment: '备注' })
+  remark: string;
+  @Column({ type: 'character varying', comment: '是否启用', default: '0' })
+  is_use: string;
+}

+ 207 - 2
src/service/initData/dataDeal.service.ts

@@ -1,8 +1,8 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { Repository } from 'typeorm';
+import { In, Repository } from 'typeorm';
 import { Menus } from '../../entity/system/menus.entity';
-import { get, isNull, isUndefined } from 'lodash';
+import { get, isNull, isUndefined, omit } from 'lodash';
 import { User } from '../../entity/system/user.entity';
 import { Admin } from '../../entity/system/admin.entity';
 import { Achievement } from '../../entity/platform/achievement.entity';
@@ -17,6 +17,8 @@ import { Project } from '../../entity/platform/project.entity';
 import { Sector } from '../../entity/platform/sector.entity';
 import { Supply } from '../../entity/platform/supply.entity';
 import { Support } from '../../entity/platform/support.entity';
+import { UserMenus } from '../../entity/system/userMenus.entity';
+import { Role } from '../../entity/system/role.entity';
 
 @Provide()
 export class DataDealService {
@@ -51,6 +53,209 @@ export class DataDealService {
   @InjectEntityModel(Support)
   Support: Repository<Support>;
 
+  @InjectEntityModel(UserMenus)
+  UserMenus: Repository<UserMenus>;
+
+  @InjectEntityModel(Role)
+  Role: Repository<Role>;
+
+  /**初始化用户目录,先去数据库把表清空,顺便重置下id索引 */
+  async initUserMenus() {
+    console.log(' in initUserMenus ');
+    await this.UserMenus.query('TRUNCATE TABLE "public"."userMenus" RESTART IDENTITY RESTRICT;');
+    const datas = [
+      {
+        order_num: 0,
+        name: '基础信息',
+        route_name: 'center_base',
+        i18n_code: 'menus.center_base',
+        path: '/center/base',
+        component: '/center/base/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 1,
+        name: '认证信息',
+        route_name: 'center_role',
+        i18n_code: 'menus.center_role',
+        path: '/center/role',
+        component: '/center/role/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 2,
+        name: '消息通知',
+        route_name: 'center_notice',
+        i18n_code: 'menus.center_notice',
+        path: '/center/notice',
+        component: '/center/notice/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 3,
+        name: '行业动态',
+        route_name: 'center_news2',
+        i18n_code: 'menus.center_news2',
+        path: '/center/news2',
+        component: '/center/news2/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 4,
+        name: '需求管理',
+        route_name: 'center_demand',
+        i18n_code: 'menus.center_demand',
+        path: '/center/demand',
+        component: '/center/demand/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 5,
+        name: '供给管理',
+        route_name: 'center_supply',
+        i18n_code: 'menus.center_supply',
+        path: '/center/supply',
+        component: '/center/supply/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 6,
+        name: '成果管理',
+        route_name: 'center_achievement',
+        i18n_code: 'menus.center_achievement',
+        path: '/center/achievement',
+        component: '/center/achievement/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 7,
+        name: '项目管理',
+        route_name: 'center_project',
+        i18n_code: 'menus.center_project',
+        path: '/center/project',
+        component: '/center/project/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 8,
+        name: '中试管理',
+        route_name: 'center_footplate',
+        i18n_code: 'menus.center_footplate',
+        path: '/center/footplate',
+        component: '/center/footplate/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 9,
+        name: '赛事管理',
+        route_name: 'center_match',
+        i18n_code: 'menus.center_match',
+        path: '/center/match',
+        component: '/center/match/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 10,
+        name: '报名管理',
+        route_name: 'center_sign',
+        i18n_code: 'menus.center_sign',
+        path: '/center/sign',
+        component: '/center/sign/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 11,
+        name: '产研行研',
+        route_name: 'center_journal',
+        i18n_code: 'menus.center_journal',
+        path: '/center/journal',
+        component: '/center/journal/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 998,
+        name: '收藏管理',
+        route_name: 'center_collection',
+        i18n_code: 'menus.center_collection',
+        path: '/center/collection',
+        component: '/center/collection/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+      {
+        order_num: 999,
+        name: '修改密码',
+        route_name: 'center_password',
+        i18n_code: 'menus.center_password',
+        path: '/center/password',
+        component: '/center/password/index',
+        type: '1',
+        config: [],
+        is_default: '0',
+        is_use: '0',
+      },
+    ];
+    await this.UserMenus.insert(datas);
+  }
+
+  async initRoleMenus() {
+    /**
+     * 初始化角色的菜单
+     * 共有: 基础信息,认证信息,行业动态,
+     */
+    const common = ['center_base', 'center_role', 'center_notice', 'center_collection', 'center_password', 'center_sign'];
+    // 只用通用菜单的角色
+    const justCommonRole = ['User', 'Association', 'Investment', 'State'];
+    await this.Role.update({ code: In(justCommonRole) }, { menu: common });
+    // 第一类菜单
+    const menus1 = [...common, 'center_news2', 'center_demand', 'center_supply', 'center_achievement', 'center_project', 'center_footplate'];
+    // 第一类菜单用户: 用户,科研机构,孵化器,企业,高校
+    const roleUseMenus1 = ['Expert', 'Unit', 'Incubator', 'Company', 'GX'];
+    await this.Role.update({ code: In(roleUseMenus1) }, { menu: menus1 });
+    // 创业大赛用户: 需要去掉报名管理,加入赛事管理
+    const MatchRole = common.filter(f => f != 'center_sign');
+    MatchRole.push('center_match');
+    await this.Role.update({ code: In(['Competition']) }, { menu: MatchRole });
+  }
+
   count = 0;
 
   isNoValue(val) {

+ 17 - 0
src/service/system/userMenus.service.ts

@@ -0,0 +1,17 @@
+import { Provide } from "@midwayjs/core";
+import { BaseServiceV2 } from "../../frame/BaseServiceV2";
+import { UserMenus } from "../../entity/system/userMenus.entity";
+import { InjectEntityModel } from "@midwayjs/typeorm";
+import { Repository } from "typeorm";
+
+
+/**
+ * 角色用户菜单,不存在层级,只需要到时候查出来分配给的菜单就行
+ */
+@Provide()
+export class UserMenusService extends BaseServiceV2 {
+  @InjectEntityModel(UserMenus)
+  model: Repository<UserMenus>;
+  
+}
+