mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2024-11-01 06:02:39 +08:00
5.x
This commit is contained in:
parent
ee67ced629
commit
14a51132ec
27
.vscode/service copy.code-snippets
vendored
27
.vscode/service copy.code-snippets
vendored
@ -1,27 +0,0 @@
|
|||||||
{
|
|
||||||
"service": {
|
|
||||||
"prefix": "service",
|
|
||||||
"body": [
|
|
||||||
"import { Provide } from '@midwayjs/decorator';",
|
|
||||||
"import { BaseService } from '@cool-midway/core';",
|
|
||||||
"import { InjectEntityModel } from '@midwayjs/orm';",
|
|
||||||
"import { Repository } from 'typeorm';",
|
|
||||||
"",
|
|
||||||
"/**",
|
|
||||||
" * 描述",
|
|
||||||
" */",
|
|
||||||
"@Provide()",
|
|
||||||
"export class XxxService extends BaseService {",
|
|
||||||
" @InjectEntityModel(实体)",
|
|
||||||
" xxxEntity: Repository<实体>;",
|
|
||||||
"",
|
|
||||||
" /**",
|
|
||||||
" * 描述",
|
|
||||||
" */",
|
|
||||||
" async xxx() {}",
|
|
||||||
"}",
|
|
||||||
""
|
|
||||||
],
|
|
||||||
"description": "cool-admin service代码片段"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
{"expireTime":1646900815600,"key":"d751713988987e9331980363e24189ce","val":"{\"a\":1,\"b\":2}"}
|
|
@ -4,14 +4,13 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cool-midway/core": "^5.0.2",
|
"@cool-midway/core": "^5.0.4",
|
||||||
"@cool-midway/es": "^5.0.0",
|
"@cool-midway/es": "^5.0.1",
|
||||||
"@cool-midway/file": "^5.0.1",
|
"@cool-midway/file": "^5.0.1",
|
||||||
"@cool-midway/pay": "^5.0.0",
|
"@cool-midway/pay": "^5.0.0",
|
||||||
"@cool-midway/rpc": "^5.0.0",
|
"@cool-midway/rpc": "^5.0.1",
|
||||||
"@cool-midway/task": "^5.0.1",
|
"@cool-midway/task": "^5.0.1",
|
||||||
"@midwayjs/bootstrap": "^3.1.1",
|
"@midwayjs/bootstrap": "^3.1.1",
|
||||||
"@midwayjs/cache": "^3.1.1",
|
|
||||||
"@midwayjs/core": "^3.1.1",
|
"@midwayjs/core": "^3.1.1",
|
||||||
"@midwayjs/decorator": "^3.0.0",
|
"@midwayjs/decorator": "^3.0.0",
|
||||||
"@midwayjs/info": "^3.1.1",
|
"@midwayjs/info": "^3.1.1",
|
||||||
@ -21,10 +20,8 @@
|
|||||||
"@midwayjs/static-file": "^3.1.1",
|
"@midwayjs/static-file": "^3.1.1",
|
||||||
"@midwayjs/validate": "^3.1.1",
|
"@midwayjs/validate": "^3.1.1",
|
||||||
"@midwayjs/view-ejs": "^3.1.1",
|
"@midwayjs/view-ejs": "^3.1.1",
|
||||||
"cache-manager-fs-hash": "^1.0.0",
|
|
||||||
"ipip-ipdb": "^0.6.0",
|
"ipip-ipdb": "^0.6.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"midway-custom-component": "D:\\src\\cool\\admin\\midway-core\\pay\\",
|
|
||||||
"mini-svg-data-uri": "^1.4.4",
|
"mini-svg-data-uri": "^1.4.4",
|
||||||
"mysql2": "^2.3.3",
|
"mysql2": "^2.3.3",
|
||||||
"svg-captcha": "^1.4.0",
|
"svg-captcha": "^1.4.0",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { CoolFileConfig, MODETYPE } from '@cool-midway/file';
|
import { CoolConfig } from '@cool-midway/core';
|
||||||
|
import { MODETYPE } from '@cool-midway/file';
|
||||||
import { MidwayConfig } from '@midwayjs/core';
|
import { MidwayConfig } from '@midwayjs/core';
|
||||||
import * as fsStore from 'cache-manager-fs-hash';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
// 修改成你自己独有的key
|
// 修改成你自己独有的key
|
||||||
@ -14,21 +14,18 @@ export default {
|
|||||||
'.html': 'ejs',
|
'.html': 'ejs',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// 缓存 可切换成其他缓存如:redis http://midwayjs.org/docs/extensions/cache
|
|
||||||
cache: {
|
|
||||||
store: fsStore,
|
|
||||||
options: {
|
|
||||||
path: 'cache',
|
|
||||||
ttl: -1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// cool配置
|
// cool配置
|
||||||
cool: {
|
cool: {
|
||||||
|
// 是否自动导入数据库
|
||||||
file: {
|
file: {
|
||||||
// 上传模式 本地上传或云存储
|
// 上传模式 本地上传或云存储
|
||||||
mode: MODETYPE.LOCAL,
|
mode: MODETYPE.CLOUD,
|
||||||
// 本地上传 文件地址前缀
|
// 本地上传 文件地址前缀
|
||||||
domain: 'http://127.0.0.1:8001',
|
domain: 'http://127.0.0.1:8001',
|
||||||
} as CoolFileConfig,
|
},
|
||||||
},
|
} as CoolConfig,
|
||||||
} as unknown as MidwayConfig;
|
} as
|
||||||
|
| MidwayConfig
|
||||||
|
| {
|
||||||
|
cache: any;
|
||||||
|
};
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { CoolConfig } from '@cool-midway/core';
|
||||||
import { MidwayConfig } from '@midwayjs/core';
|
import { MidwayConfig } from '@midwayjs/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,4 +19,8 @@ export default {
|
|||||||
// 字符集
|
// 字符集
|
||||||
charset: 'utf8mb4',
|
charset: 'utf8mb4',
|
||||||
},
|
},
|
||||||
|
cool: {
|
||||||
|
// 是否自动导入数据库
|
||||||
|
initDB: true,
|
||||||
|
} as CoolConfig,
|
||||||
} as MidwayConfig;
|
} as MidwayConfig;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { CoolConfig } from '@cool-midway/core';
|
||||||
import { MidwayConfig } from '@midwayjs/core';
|
import { MidwayConfig } from '@midwayjs/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,8 +15,12 @@ export default {
|
|||||||
// 自动建表 注意:线上部署的时候不要使用,有可能导致数据丢失
|
// 自动建表 注意:线上部署的时候不要使用,有可能导致数据丢失
|
||||||
synchronize: false,
|
synchronize: false,
|
||||||
// 打印日志
|
// 打印日志
|
||||||
logging: true,
|
logging: false,
|
||||||
// 字符集
|
// 字符集
|
||||||
charset: 'utf8mb4',
|
charset: 'utf8mb4',
|
||||||
},
|
},
|
||||||
|
cool: {
|
||||||
|
// 是否自动导入数据库
|
||||||
|
initDB: false,
|
||||||
|
} as CoolConfig,
|
||||||
} as MidwayConfig;
|
} as MidwayConfig;
|
||||||
|
@ -6,7 +6,6 @@ import { join } from 'path';
|
|||||||
import * as staticFile from '@midwayjs/static-file';
|
import * as staticFile from '@midwayjs/static-file';
|
||||||
import * as view from '@midwayjs/view-ejs';
|
import * as view from '@midwayjs/view-ejs';
|
||||||
import * as orm from '@midwayjs/orm';
|
import * as orm from '@midwayjs/orm';
|
||||||
import * as cache from '@midwayjs/cache';
|
|
||||||
import * as cool from '@cool-midway/core';
|
import * as cool from '@cool-midway/core';
|
||||||
import * as file from '@cool-midway/file';
|
import * as file from '@cool-midway/file';
|
||||||
// import * as task from '@cool-midway/task';
|
// import * as task from '@cool-midway/task';
|
||||||
@ -26,8 +25,6 @@ import * as file from '@cool-midway/file';
|
|||||||
staticFile,
|
staticFile,
|
||||||
// typeorm https://typeorm.io 打不开? https://typeorm.biunav.com/zh/
|
// typeorm https://typeorm.io 打不开? https://typeorm.biunav.com/zh/
|
||||||
orm,
|
orm,
|
||||||
// 缓存 http://midwayjs.org/docs/extensions/cache
|
|
||||||
cache,
|
|
||||||
// cool-admin 官方组件 https://www.cool-js.com
|
// cool-admin 官方组件 https://www.cool-js.com
|
||||||
cool,
|
cool,
|
||||||
// 文件上传 阿里云存储 腾讯云存储 七牛云存储
|
// 文件上传 阿里云存储 腾讯云存储 七牛云存储
|
||||||
@ -51,10 +48,5 @@ export class ContainerLifeCycle {
|
|||||||
@App()
|
@App()
|
||||||
app: koa.Application;
|
app: koa.Application;
|
||||||
|
|
||||||
async onReady() {
|
async onReady() {}
|
||||||
// add middleware
|
|
||||||
// this.app.useMiddleware([ReportMiddleware]);
|
|
||||||
// add filter
|
|
||||||
// this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,45 +17,6 @@
|
|||||||
SET NAMES utf8mb4;
|
SET NAMES utf8mb4;
|
||||||
SET FOREIGN_KEY_CHECKS = 0;
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
|
||||||
-- ----------------------------
|
|
||||||
-- Table structure for base_app_space_info
|
|
||||||
-- ----------------------------
|
|
||||||
DROP TABLE IF EXISTS `base_app_space_info`;
|
|
||||||
CREATE TABLE `base_app_space_info` (
|
|
||||||
`id` int(11) 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 '更新时间',
|
|
||||||
`url` varchar(255) NOT NULL COMMENT '地址',
|
|
||||||
`type` varchar(255) NOT NULL COMMENT '类型',
|
|
||||||
`classifyId` bigint(20) DEFAULT NULL COMMENT '分类ID',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `IDX_4aed04cbfa2ecdc01485b86e51` (`createTime`),
|
|
||||||
KEY `IDX_abd5de4a4895eb253a5cabb20f` (`updateTime`)
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
|
|
||||||
|
|
||||||
-- ----------------------------
|
|
||||||
-- Table structure for base_app_space_type
|
|
||||||
-- ----------------------------
|
|
||||||
DROP TABLE IF EXISTS `base_app_space_type`;
|
|
||||||
CREATE TABLE `base_app_space_type` (
|
|
||||||
`id` int(11) 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) NOT NULL COMMENT '类别名称',
|
|
||||||
`parentId` tinyint(4) DEFAULT NULL COMMENT '父分类ID',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `IDX_5e8376603f89fdf3e7bb05103a` (`createTime`),
|
|
||||||
KEY `IDX_500ea9e8b2c5c08c9b86a0667e` (`updateTime`)
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
|
|
||||||
|
|
||||||
-- ----------------------------
|
|
||||||
-- Records of base_app_space_type
|
|
||||||
-- ----------------------------
|
|
||||||
BEGIN;
|
|
||||||
INSERT INTO `base_app_space_type` VALUES (1, '2021-02-26 14:07:48.867045', '2021-02-26 14:07:48.867045', 'a', NULL);
|
|
||||||
INSERT INTO `base_app_space_type` VALUES (2, '2021-02-26 14:07:52.285531', '2021-02-26 14:07:52.285531', 'b', NULL);
|
|
||||||
COMMIT;
|
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Table structure for base_sys_conf
|
-- Table structure for base_sys_conf
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
@ -689,29 +650,5 @@ INSERT INTO `base_sys_user_role` VALUES (43, '2021-02-26 14:36:58.477817', '2021
|
|||||||
INSERT INTO `base_sys_user_role` VALUES (44, '2021-02-26 14:36:58.577114', '2021-02-26 14:36:58.577114', 28, 10);
|
INSERT INTO `base_sys_user_role` VALUES (44, '2021-02-26 14:36:58.577114', '2021-02-26 14:36:58.577114', 28, 10);
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
||||||
-- ----------------------------
|
|
||||||
-- Table structure for demo_app_goods
|
|
||||||
-- ----------------------------
|
|
||||||
DROP TABLE IF EXISTS `demo_app_goods`;
|
|
||||||
CREATE TABLE `demo_app_goods` (
|
|
||||||
`id` int(11) 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 '更新时间',
|
|
||||||
`title` varchar(255) NOT NULL COMMENT '标题',
|
|
||||||
`pic` varchar(255) NOT NULL COMMENT '图片',
|
|
||||||
`price` decimal(5,2) NOT NULL COMMENT '价格',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
KEY `IDX_de2b99b64158bb4030487d7475` (`createTime`),
|
|
||||||
KEY `IDX_f84cff6dc28b1a5dcc53856e66` (`updateTime`)
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
|
|
||||||
|
|
||||||
-- ----------------------------
|
|
||||||
-- Records of demo_app_goods
|
|
||||||
-- ----------------------------
|
|
||||||
BEGIN;
|
|
||||||
INSERT INTO `demo_app_goods` VALUES (1, '2021-03-02 17:22:10.687462', '2021-03-02 17:22:10.687462', 'cool-mall商城', 'https://docs.cool-js.com/mall/show05.jpeg', 20.00);
|
|
||||||
COMMIT;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SET FOREIGN_KEY_CHECKS = 1;
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
@ -15,12 +15,24 @@ export class AppDemoCacheController extends BaseController {
|
|||||||
@Inject()
|
@Inject()
|
||||||
demoCacheService: DemoCacheService;
|
demoCacheService: DemoCacheService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置缓存
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
@Post('/set')
|
@Post('/set')
|
||||||
async set() {
|
async set() {
|
||||||
this.cacheManager.set('a', 1);
|
await this.cacheManager.set('a', 1);
|
||||||
|
// 缓存10秒
|
||||||
|
await this.cacheManager.set('a', 1, {
|
||||||
|
ttl: 10,
|
||||||
|
});
|
||||||
return this.ok(await this.cacheManager.get('a'));
|
return this.ok(await this.cacheManager.get('a'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得缓存
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
@Get('/get')
|
@Get('/get')
|
||||||
async get() {
|
async get() {
|
||||||
return this.ok(await this.demoCacheService.get());
|
return this.ok(await this.demoCacheService.get());
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Inject, Post, Provide } from '@midwayjs/decorator';
|
import { Inject, Post, Provide } from '@midwayjs/decorator';
|
||||||
import { CoolController, BaseController } from '@cool-midway/core';
|
import { CoolController, BaseController } from '@cool-midway/core';
|
||||||
import { TestEsIndex } from '../../es/test';
|
import { TestEsIndex } from '../../es/test';
|
||||||
|
import { CoolElasticSearch } from '@cool-midway/es';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* elasticsearch
|
* elasticsearch
|
||||||
@ -11,11 +12,16 @@ export class AppDemoEsController extends BaseController {
|
|||||||
@Inject()
|
@Inject()
|
||||||
testEsIndex: TestEsIndex;
|
testEsIndex: TestEsIndex;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
es: CoolElasticSearch;
|
||||||
|
|
||||||
@Post('/test')
|
@Post('/test')
|
||||||
async test() {
|
async test() {
|
||||||
|
// es 客户端实例
|
||||||
|
this.es.client;
|
||||||
// 新增与修改
|
// 新增与修改
|
||||||
await this.testEsIndex.upsert({
|
await this.testEsIndex.upsert({
|
||||||
name: '啊平',
|
name: '你好啊你是谁',
|
||||||
age: 18,
|
age: 18,
|
||||||
});
|
});
|
||||||
return this.ok(await this.testEsIndex.find());
|
return this.ok(await this.testEsIndex.find());
|
||||||
|
36
src/modules/demo/controller/app/rpc.ts
Normal file
36
src/modules/demo/controller/app/rpc.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { Inject, Post, Provide } from '@midwayjs/decorator';
|
||||||
|
import { CoolController, BaseController } from '@cool-midway/core';
|
||||||
|
import { CoolRpc } from '@cool-midway/rpc';
|
||||||
|
import { DemoRpcService } from '../../service/rpc';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微服务
|
||||||
|
*/
|
||||||
|
@Provide()
|
||||||
|
@CoolController()
|
||||||
|
export class DemoRpcController extends BaseController {
|
||||||
|
@Inject()
|
||||||
|
rpc: CoolRpc;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
demoRpcService: DemoRpcService;
|
||||||
|
|
||||||
|
@Post('/call', { summary: '远程调用' })
|
||||||
|
async call() {
|
||||||
|
return this.ok(
|
||||||
|
await this.rpc.call('goods', 'demoGoodsService', 'test', { a: 1 })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('/event', { summary: '集群事件' })
|
||||||
|
async event() {
|
||||||
|
this.rpc.broadcastEvent('test', { a: 1 });
|
||||||
|
return this.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('/transaction', { summary: '分布式事务' })
|
||||||
|
async transaction() {
|
||||||
|
await this.demoRpcService.transaction({ a: 1 });
|
||||||
|
return this.ok();
|
||||||
|
}
|
||||||
|
}
|
@ -3,12 +3,20 @@ import { CoolEsIndex, ICoolEs, BaseEsIndex } from '@cool-midway/es';
|
|||||||
/**
|
/**
|
||||||
* 测试索引
|
* 测试索引
|
||||||
*/
|
*/
|
||||||
@CoolEsIndex('test')
|
@CoolEsIndex({ name: 'test', replicas: 0 })
|
||||||
export class TestEsIndex extends BaseEsIndex implements ICoolEs {
|
export class TestEsIndex extends BaseEsIndex implements ICoolEs {
|
||||||
indexInfo() {
|
indexInfo() {
|
||||||
return {
|
return {
|
||||||
|
// 需要安装ik分词器 https://github.com/medcl/elasticsearch-analysis-ik
|
||||||
name: {
|
name: {
|
||||||
type: 'text',
|
type: 'text',
|
||||||
|
analyzer: 'ik_max_word',
|
||||||
|
search_analyzer: 'ik_max_word',
|
||||||
|
fields: {
|
||||||
|
raw: {
|
||||||
|
type: 'keyword',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
age: {
|
age: {
|
||||||
type: 'long',
|
type: 'long',
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
|
||||||
import { CoolEvent, Event } from '@cool-midway/core';
|
import { CoolEvent, Event } from '@cool-midway/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接收事件
|
* 接收事件
|
||||||
*/
|
*/
|
||||||
@Provide()
|
|
||||||
@Scope(ScopeEnum.Singleton)
|
|
||||||
@CoolEvent()
|
@CoolEvent()
|
||||||
export class DemoEvent {
|
export class DemoEvent {
|
||||||
/**
|
/**
|
||||||
|
@ -1,8 +1,16 @@
|
|||||||
import { Provide } from '@midwayjs/decorator';
|
import { Inject, Provide } from '@midwayjs/decorator';
|
||||||
import { BaseService } from '@cool-midway/core';
|
import { BaseService } from '@cool-midway/core';
|
||||||
|
import { CoolRpc } from '@cool-midway/rpc';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存
|
* 缓存
|
||||||
*/
|
*/
|
||||||
@Provide()
|
@Provide()
|
||||||
export class DemoGoodsService extends BaseService {}
|
export class DemoGoodsService extends BaseService {
|
||||||
|
@Inject()
|
||||||
|
rpc: CoolRpc;
|
||||||
|
|
||||||
|
async test() {
|
||||||
|
console.log('调用');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
import { App, Provide } from '@midwayjs/decorator';
|
import { App, Inject, Provide } from '@midwayjs/decorator';
|
||||||
import { DemoGoodsEntity } from '../entity/goods';
|
import { DemoGoodsEntity } from '../entity/goods';
|
||||||
import { IMidwayApplication } from '@midwayjs/core';
|
import { IMidwayApplication } from '@midwayjs/core';
|
||||||
import { BaseRpcService, CoolRpcService } from '@cool-midway/rpc';
|
import {
|
||||||
|
BaseRpcService,
|
||||||
|
CoolRpc,
|
||||||
|
CoolRpcService,
|
||||||
|
CoolRpcTransaction,
|
||||||
|
} from '@cool-midway/rpc';
|
||||||
|
import { QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
@Provide()
|
@Provide()
|
||||||
@CoolRpcService({
|
@CoolRpcService({
|
||||||
@ -12,6 +18,33 @@ export class DemoRpcService extends BaseRpcService {
|
|||||||
@App()
|
@App()
|
||||||
app: IMidwayApplication;
|
app: IMidwayApplication;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
rpc: CoolRpc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分布式事务
|
||||||
|
* @param params 方法参数
|
||||||
|
* @param rpcTransactionId 无需调用者传参, 本次事务的ID,ID会自动注入无需调用者传参
|
||||||
|
* @param queryRunner 无需调用者传参,操作数据库,需要用queryRunner操作数据库,才能统一提交或回滚事务
|
||||||
|
*/
|
||||||
|
// 注解启用分布式事务,参数可以指定事务类型
|
||||||
|
@CoolRpcTransaction()
|
||||||
|
async transaction(params, rpcTransactionId?, queryRunner?: QueryRunner) {
|
||||||
|
console.log('获得的参数', params);
|
||||||
|
const data = {
|
||||||
|
title: '商品标题',
|
||||||
|
pic: 'https://xxx',
|
||||||
|
price: 99.0,
|
||||||
|
type: 1,
|
||||||
|
};
|
||||||
|
await queryRunner.manager.save(DemoGoodsEntity, data);
|
||||||
|
|
||||||
|
// 将事务id传给调用的远程服务方法
|
||||||
|
await this.rpc.call('goods', 'demoGoodsService', 'transaction', {
|
||||||
|
rpcTransactionId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async info(params) {
|
async info(params) {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Provide } from '@midwayjs/decorator';
|
import { Provide } from '@midwayjs/decorator';
|
||||||
import { CoolController, BaseController } from '@cool-midway/core';
|
import { CoolController, BaseController } from '@cool-midway/core';
|
||||||
import { BaseAppSpaceInfoEntity } from '../../entity/info';
|
import { SpaceInfoEntity } from '../../entity/info';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图片空间信息
|
* 图片空间信息
|
||||||
@ -8,7 +8,7 @@ import { BaseAppSpaceInfoEntity } from '../../entity/info';
|
|||||||
@Provide()
|
@Provide()
|
||||||
@CoolController({
|
@CoolController({
|
||||||
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
|
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
|
||||||
entity: BaseAppSpaceInfoEntity,
|
entity: SpaceInfoEntity,
|
||||||
pageQueryOp: {
|
pageQueryOp: {
|
||||||
fieldEq: ['type', 'classifyId'],
|
fieldEq: ['type', 'classifyId'],
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Provide } from '@midwayjs/decorator';
|
import { Provide } from '@midwayjs/decorator';
|
||||||
import { CoolController, BaseController } from '@cool-midway/core';
|
import { CoolController, BaseController } from '@cool-midway/core';
|
||||||
import { BaseAppSpaceTypeEntity } from '../../entity/type';
|
import { SpaceTypeEntity } from '../../entity/type';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 空间分类
|
* 空间分类
|
||||||
@ -8,6 +8,6 @@ import { BaseAppSpaceTypeEntity } from '../../entity/type';
|
|||||||
@Provide()
|
@Provide()
|
||||||
@CoolController({
|
@CoolController({
|
||||||
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
|
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
|
||||||
entity: BaseAppSpaceTypeEntity,
|
entity: SpaceTypeEntity,
|
||||||
})
|
})
|
||||||
export class BaseAppSpaceTypeController extends BaseController {}
|
export class BaseAppSpaceTypeController extends BaseController {}
|
||||||
|
@ -5,8 +5,8 @@ import { Column } from 'typeorm';
|
|||||||
/**
|
/**
|
||||||
* 文件空间信息
|
* 文件空间信息
|
||||||
*/
|
*/
|
||||||
@EntityModel('base_app_space_info')
|
@EntityModel('space_info')
|
||||||
export class BaseAppSpaceInfoEntity extends BaseEntity {
|
export class SpaceInfoEntity extends BaseEntity {
|
||||||
@Column({ comment: '地址' })
|
@Column({ comment: '地址' })
|
||||||
url: string;
|
url: string;
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ import { Column } from 'typeorm';
|
|||||||
/**
|
/**
|
||||||
* 图片空间信息分类
|
* 图片空间信息分类
|
||||||
*/
|
*/
|
||||||
@EntityModel('base_app_space_type')
|
@EntityModel('space_type')
|
||||||
export class BaseAppSpaceTypeEntity extends BaseEntity {
|
export class SpaceTypeEntity extends BaseEntity {
|
||||||
@Column({ comment: '类别名称' })
|
@Column({ comment: '类别名称' })
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user