From 4c4f5ee2cb9d76729194ca8331adf09166a2daf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=B9=8F?= Date: Wed, 6 Jul 2022 14:41:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AD=97=E5=85=B8=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/modules/base/config.ts | 2 + src/modules/dict/config.ts | 19 ++++++ src/modules/dict/controller/admin/info.ts | 26 +++++++++ src/modules/dict/controller/admin/type.ts | 16 ++++++ src/modules/dict/controller/app/info.ts | 18 ++++++ src/modules/dict/entity/info.ts | 21 +++++++ src/modules/dict/entity/type.ts | 15 +++++ src/modules/dict/init.sql | 68 ++++++++++++++++++++++ src/modules/dict/service/info.ts | 70 +++++++++++++++++++++++ src/modules/task/config.ts | 5 +- 11 files changed, 260 insertions(+), 2 deletions(-) create mode 100644 src/modules/dict/config.ts create mode 100644 src/modules/dict/controller/admin/info.ts create mode 100644 src/modules/dict/controller/admin/type.ts create mode 100644 src/modules/dict/controller/app/info.ts create mode 100644 src/modules/dict/entity/info.ts create mode 100644 src/modules/dict/entity/type.ts create mode 100644 src/modules/dict/init.sql create mode 100644 src/modules/dict/service/info.ts diff --git a/package.json b/package.json index b1c66aa..af02326 100755 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "private": true, "dependencies": { - "@cool-midway/core": "^5.0.12", + "@cool-midway/core": "^5.0.15", "@cool-midway/es": "^5.0.2", "@cool-midway/file": "^5.0.5", "@cool-midway/pay": "^5.0.0", diff --git a/src/modules/base/config.ts b/src/modules/base/config.ts index 78862f6..49b4e10 100644 --- a/src/modules/base/config.ts +++ b/src/modules/base/config.ts @@ -13,6 +13,8 @@ export default () => { description: '基础的权限管理功能,包括登录,权限校验', // 中间件 globalMiddlewares: [BaseAuthorityMiddleware, BaseLogMiddleware], + // 模块加载顺序,默认为0,值越大越优先加载 + order: 10, // jwt 生成解密token的 jwt: { // 单点登录 diff --git a/src/modules/dict/config.ts b/src/modules/dict/config.ts new file mode 100644 index 0000000..c0f21f7 --- /dev/null +++ b/src/modules/dict/config.ts @@ -0,0 +1,19 @@ +import { ModuleConfig } from '@cool-midway/core'; + +/** + * 模块配置 + */ +export default () => { + return { + // 模块名称 + name: '信息管理', + // 模块描述 + description: '信息管理模块,主要管理数据字典等', + // 中间件,只对本模块有效 + middlewares: [], + // 中间件,全局有效 + globalMiddlewares: [], + // 模块加载顺序,默认为0,值越大越优先加载 + order: 0, + } as ModuleConfig; +}; diff --git a/src/modules/dict/controller/admin/info.ts b/src/modules/dict/controller/admin/info.ts new file mode 100644 index 0000000..48b0eb7 --- /dev/null +++ b/src/modules/dict/controller/admin/info.ts @@ -0,0 +1,26 @@ +import { DictInfoEntity } from './../../entity/info'; +import { Body, Inject, Post, Provide } from '@midwayjs/decorator'; +import { CoolController, BaseController } from '@cool-midway/core'; +import { DictInfoService } from '../../service/info'; + +/** + * 字典信息 + */ +@Provide() +@CoolController({ + api: ['add', 'delete', 'update', 'info', 'list', 'page'], + entity: DictInfoEntity, + pageQueryOp: { + fieldEq: ['typeId'], + keyWordLikeFields: ['name'], + }, +}) +export class AdminDictInfoController extends BaseController { + @Inject() + dictInfoService: DictInfoService; + + @Post('/data', { summary: '获得字典数据' }) + async data(@Body('types') types: string[] = []) { + return this.ok(await this.dictInfoService.data(types)); + } +} diff --git a/src/modules/dict/controller/admin/type.ts b/src/modules/dict/controller/admin/type.ts new file mode 100644 index 0000000..04cd61a --- /dev/null +++ b/src/modules/dict/controller/admin/type.ts @@ -0,0 +1,16 @@ +import { DictTypeEntity } from './../../entity/type'; +import { Provide } from '@midwayjs/decorator'; +import { CoolController, BaseController } from '@cool-midway/core'; + +/** + * 字典类型 + */ +@Provide() +@CoolController({ + api: ['add', 'delete', 'update', 'info', 'list', 'page'], + entity: DictTypeEntity, + listQueryOp: { + keyWordLikeFields: ['name'], + }, +}) +export class AdminDictTypeController extends BaseController {} diff --git a/src/modules/dict/controller/app/info.ts b/src/modules/dict/controller/app/info.ts new file mode 100644 index 0000000..172bfc6 --- /dev/null +++ b/src/modules/dict/controller/app/info.ts @@ -0,0 +1,18 @@ +import { Body, Inject, Post, Provide } from '@midwayjs/decorator'; +import { CoolController, BaseController } from '@cool-midway/core'; +import { DictInfoService } from '../../service/info'; + +/** + * 字典信息 + */ +@Provide() +@CoolController() +export class AppDictInfoController extends BaseController { + @Inject() + dictInfoService: DictInfoService; + + @Post('/data', { summary: '获得字典数据' }) + async data(@Body('types') types: string[] = []) { + return this.ok(await this.dictInfoService.data(types)); + } +} diff --git a/src/modules/dict/entity/info.ts b/src/modules/dict/entity/info.ts new file mode 100644 index 0000000..dc99631 --- /dev/null +++ b/src/modules/dict/entity/info.ts @@ -0,0 +1,21 @@ +import { EntityModel } from '@midwayjs/orm'; +import { BaseEntity } from '@cool-midway/core'; +import { Column } from 'typeorm'; + +/** + * 字典信息 + */ +@EntityModel('dict_info') +export class DictInfoEntity extends BaseEntity { + @Column({ comment: '类型ID' }) + typeId: number; + + @Column({ comment: '名称' }) + name: string; + + @Column({ comment: '排序', default: 0 }) + orderNum: number; + + @Column({ comment: '备注', nullable: true }) + remark: string; +} diff --git a/src/modules/dict/entity/type.ts b/src/modules/dict/entity/type.ts new file mode 100644 index 0000000..61b3006 --- /dev/null +++ b/src/modules/dict/entity/type.ts @@ -0,0 +1,15 @@ +import { EntityModel } from '@midwayjs/orm'; +import { BaseEntity } from '@cool-midway/core'; +import { Column } from 'typeorm'; + +/** + * 字典类别 + */ +@EntityModel('dict_type') +export class DictTypeEntity extends BaseEntity { + @Column({ comment: '名称' }) + name: string; + + @Column({ comment: '标识' }) + key: string; +} diff --git a/src/modules/dict/init.sql b/src/modules/dict/init.sql new file mode 100644 index 0000000..d7d29ad --- /dev/null +++ b/src/modules/dict/init.sql @@ -0,0 +1,68 @@ +BEGIN; +INSERT INTO `base_sys_menu` VALUES (197, '2022-07-05 16:05:27.403000', '2022-07-05 16:15:16.025000', NULL, '字典管理', NULL, NULL, 0, 'icon-log', 3, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (198, '2022-07-05 16:08:50.307000', '2022-07-05 16:14:13.196000', 197, '字典列表', '/dict/list', NULL, 1, 'icon-menu', 1, 'modules/dict/views/list.vue', 1, 1); +INSERT INTO `base_sys_menu` VALUES (199, '2022-07-05 16:08:50.748162', '2022-07-05 16:08:50.748162', 198, '删除', NULL, 'dict:info:delete', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (200, '2022-07-05 16:08:50.800623', '2022-07-05 16:08:50.800623', 198, '修改', NULL, 'dict:info:update,dict:info:info', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (201, '2022-07-05 16:08:50.859141', '2022-07-05 16:08:50.859141', 198, '获得字典数据', NULL, 'dict:info:data', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (202, '2022-07-05 16:08:50.916874', '2022-07-05 16:08:50.916874', 198, '单个信息', NULL, 'dict:info:info', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (203, '2022-07-05 16:08:50.972783', '2022-07-05 16:08:50.972783', 198, '列表查询', NULL, 'dict:info:list', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (204, '2022-07-05 16:08:51.030928', '2022-07-05 16:08:51.030928', 198, '分页查询', NULL, 'dict:info:page', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (205, '2022-07-05 16:08:51.087883', '2022-07-05 16:08:51.087883', 198, '新增', NULL, 'dict:info:add', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (206, '2022-07-06 10:41:26.503000', '2022-07-06 10:41:37.000000', 198, '组权限', NULL, 'dict:type:list,dict:type:update,dict:type:delete,dict:type:add', 2, NULL, 0, NULL, 1, 1); +COMMIT; + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for dict_info +-- ---------------------------- +DROP TABLE IF EXISTS `dict_info`; +CREATE TABLE `dict_info` ( + `id` int NOT NULL AUTO_INCREMENT COMMENT 'ID', + `createTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间', + `updateTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间', + `typeId` int NOT NULL COMMENT '类型ID', + `name` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT '名称', + `orderNum` int NOT NULL DEFAULT '0' COMMENT '排序', + `remark` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注', + PRIMARY KEY (`id`), + KEY `IDX_5c311a4af30de1181a5d7a7cc2` (`createTime`), + KEY `IDX_10362a62adbf120821fff209d8` (`updateTime`) +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- ---------------------------- +-- Records of dict_info +-- ---------------------------- +BEGIN; +INSERT INTO `dict_info` VALUES (1, '2022-07-06 14:18:53.841000', '2022-07-06 14:19:10.954000', 1, '衣服', 2, NULL); +INSERT INTO `dict_info` VALUES (2, '2022-07-06 14:18:59.834000', '2022-07-06 14:18:59.834000', 1, '裤子', 1, NULL); +INSERT INTO `dict_info` VALUES (3, '2022-07-06 14:19:03.993000', '2022-07-06 14:19:15.251000', 1, '鞋子', 3, NULL); +INSERT INTO `dict_info` VALUES (4, '2022-07-06 14:21:47.122000', '2022-07-06 14:22:26.131000', 2, '闪酷', 2, NULL); +INSERT INTO `dict_info` VALUES (5, '2022-07-06 14:22:18.309000', '2022-07-06 14:22:18.309000', 2, 'COOL', 1, NULL); +COMMIT; + +-- ---------------------------- +-- Table structure for dict_type +-- ---------------------------- +DROP TABLE IF EXISTS `dict_type`; +CREATE TABLE `dict_type` ( + `id` int NOT NULL AUTO_INCREMENT COMMENT 'ID', + `createTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间', + `updateTime` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间', + `name` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT '名称', + `key` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT '标识', + PRIMARY KEY (`id`), + KEY `IDX_69734e5c2d29cc2139d5078f2c` (`createTime`), + KEY `IDX_6cccb2e33846cd354e8dc0e0ef` (`updateTime`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- ---------------------------- +-- Records of dict_type +-- ---------------------------- +BEGIN; +INSERT INTO `dict_type` VALUES (1, '2022-07-06 14:18:41.879000', '2022-07-06 14:18:41.879000', '类别', 'type'); +INSERT INTO `dict_type` VALUES (2, '2022-07-06 14:21:33.778000', '2022-07-06 14:21:33.778000', '品牌', 'brand'); +COMMIT; + +SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file diff --git a/src/modules/dict/service/info.ts b/src/modules/dict/service/info.ts new file mode 100644 index 0000000..0a6b7de --- /dev/null +++ b/src/modules/dict/service/info.ts @@ -0,0 +1,70 @@ +import { DictTypeEntity } from './../entity/type'; +import { DictInfoEntity } from './../entity/info'; +import { Provide } from '@midwayjs/decorator'; +import { BaseService } from '@cool-midway/core'; +import { InjectEntityModel } from '@midwayjs/orm'; +import { Repository, In } from 'typeorm'; +import * as _ from 'lodash'; + +/** + * 字典信息 + */ +@Provide() +export class DictInfoService extends BaseService { + @InjectEntityModel(DictInfoEntity) + dictInfoEntity: Repository; + + @InjectEntityModel(DictTypeEntity) + dictTypeEntity: Repository; + + /** + * 获得字典数据 + * @param types + */ + async data(types: string[]) { + const result = {}; + const find = await this.dictTypeEntity.createQueryBuilder(); + if (!_.isEmpty(types)) { + find.where('`key` in(:key)', { key: types }); + } + const typeData = await find.getMany(); + if (_.isEmpty(typeData)) { + return {}; + } + const data = await this.dictInfoEntity + .createQueryBuilder() + .where('typeId in(:typeIds)', { + typeIds: typeData.map(e => { + return e.id; + }), + }) + .orderBy('orderNum', 'ASC') + .getMany(); + for (const item of typeData) { + result[item.key] = _.filter(data, { typeId: item.id }); + } + return result; + } + + /** + * 获得字典值 + * @param infoId + * @returns + */ + async value(infoId: number) { + const info = await this.dictInfoEntity.findOne({ id: infoId }); + return info?.name; + } + + /** + * 获得字典值 + * @param infoId + * @returns + */ + async values(infoIds: number[]) { + const infos = await this.dictInfoEntity.find({ id: In(infoIds) }); + return infos.map(e => { + return e.name; + }); + } +} diff --git a/src/modules/task/config.ts b/src/modules/task/config.ts index b2ca4ff..b919075 100644 --- a/src/modules/task/config.ts +++ b/src/modules/task/config.ts @@ -1,4 +1,5 @@ import { ModuleConfig } from '@cool-midway/core'; +import { TaskMiddleware } from './middleware/task'; /** * 模块配置 @@ -10,6 +11,8 @@ export default () => { // 模块描述 description: '任务调度模块,支持分布式任务,由redis整个集群的任务', // 中间件 - middlewares: [], + middlewares: [TaskMiddleware], + // 模块加载顺序,默认为0,值越大越优先加载 + order: 0, } as ModuleConfig; };