This commit is contained in:
啊平 2022-03-21 09:44:27 +08:00
parent ee67ced629
commit 14a51132ec
19 changed files with 144 additions and 139 deletions

View File

@ -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代码片段"
}
}

View File

@ -1 +0,0 @@
{"expireTime":1646900815600,"key":"d751713988987e9331980363e24189ce","val":"{\"a\":1,\"b\":2}"}

View File

@ -4,14 +4,13 @@
"description": "",
"private": true,
"dependencies": {
"@cool-midway/core": "^5.0.2",
"@cool-midway/es": "^5.0.0",
"@cool-midway/core": "^5.0.4",
"@cool-midway/es": "^5.0.1",
"@cool-midway/file": "^5.0.1",
"@cool-midway/pay": "^5.0.0",
"@cool-midway/rpc": "^5.0.0",
"@cool-midway/rpc": "^5.0.1",
"@cool-midway/task": "^5.0.1",
"@midwayjs/bootstrap": "^3.1.1",
"@midwayjs/cache": "^3.1.1",
"@midwayjs/core": "^3.1.1",
"@midwayjs/decorator": "^3.0.0",
"@midwayjs/info": "^3.1.1",
@ -21,10 +20,8 @@
"@midwayjs/static-file": "^3.1.1",
"@midwayjs/validate": "^3.1.1",
"@midwayjs/view-ejs": "^3.1.1",
"cache-manager-fs-hash": "^1.0.0",
"ipip-ipdb": "^0.6.0",
"jsonwebtoken": "^8.5.1",
"midway-custom-component": "D:\\src\\cool\\admin\\midway-core\\pay\\",
"mini-svg-data-uri": "^1.4.4",
"mysql2": "^2.3.3",
"svg-captcha": "^1.4.0",

View File

@ -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 * as fsStore from 'cache-manager-fs-hash';
export default {
// 修改成你自己独有的key
@ -14,21 +14,18 @@ export default {
'.html': 'ejs',
},
},
// 缓存 可切换成其他缓存如redis http://midwayjs.org/docs/extensions/cache
cache: {
store: fsStore,
options: {
path: 'cache',
ttl: -1,
},
},
// cool配置
cool: {
// 是否自动导入数据库
file: {
// 上传模式 本地上传或云存储
mode: MODETYPE.LOCAL,
mode: MODETYPE.CLOUD,
// 本地上传 文件地址前缀
domain: 'http://127.0.0.1:8001',
} as CoolFileConfig,
},
} as unknown as MidwayConfig;
},
} as CoolConfig,
} as
| MidwayConfig
| {
cache: any;
};

View File

@ -1,3 +1,4 @@
import { CoolConfig } from '@cool-midway/core';
import { MidwayConfig } from '@midwayjs/core';
/**
@ -18,4 +19,8 @@ export default {
// 字符集
charset: 'utf8mb4',
},
cool: {
// 是否自动导入数据库
initDB: true,
} as CoolConfig,
} as MidwayConfig;

View File

@ -1,3 +1,4 @@
import { CoolConfig } from '@cool-midway/core';
import { MidwayConfig } from '@midwayjs/core';
/**
@ -14,8 +15,12 @@ export default {
// 自动建表 注意:线上部署的时候不要使用,有可能导致数据丢失
synchronize: false,
// 打印日志
logging: true,
logging: false,
// 字符集
charset: 'utf8mb4',
},
cool: {
// 是否自动导入数据库
initDB: false,
} as CoolConfig,
} as MidwayConfig;

View File

@ -6,7 +6,6 @@ import { join } from 'path';
import * as staticFile from '@midwayjs/static-file';
import * as view from '@midwayjs/view-ejs';
import * as orm from '@midwayjs/orm';
import * as cache from '@midwayjs/cache';
import * as cool from '@cool-midway/core';
import * as file from '@cool-midway/file';
// import * as task from '@cool-midway/task';
@ -26,8 +25,6 @@ import * as file from '@cool-midway/file';
staticFile,
// typeorm https://typeorm.io 打不开? https://typeorm.biunav.com/zh/
orm,
// 缓存 http://midwayjs.org/docs/extensions/cache
cache,
// cool-admin 官方组件 https://www.cool-js.com
cool,
// 文件上传 阿里云存储 腾讯云存储 七牛云存储
@ -51,10 +48,5 @@ export class ContainerLifeCycle {
@App()
app: koa.Application;
async onReady() {
// add middleware
// this.app.useMiddleware([ReportMiddleware]);
// add filter
// this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
}
async onReady() {}
}

View File

@ -17,45 +17,6 @@
SET NAMES utf8mb4;
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
-- ----------------------------
@ -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);
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;

View File

@ -15,12 +15,24 @@ export class AppDemoCacheController extends BaseController {
@Inject()
demoCacheService: DemoCacheService;
/**
*
* @returns
*/
@Post('/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'));
}
/**
*
* @returns
*/
@Get('/get')
async get() {
return this.ok(await this.demoCacheService.get());

View File

@ -1,6 +1,7 @@
import { Inject, Post, Provide } from '@midwayjs/decorator';
import { CoolController, BaseController } from '@cool-midway/core';
import { TestEsIndex } from '../../es/test';
import { CoolElasticSearch } from '@cool-midway/es';
/**
* elasticsearch
@ -11,11 +12,16 @@ export class AppDemoEsController extends BaseController {
@Inject()
testEsIndex: TestEsIndex;
@Inject()
es: CoolElasticSearch;
@Post('/test')
async test() {
// es 客户端实例
this.es.client;
// 新增与修改
await this.testEsIndex.upsert({
name: '啊平',
name: '你好啊你是谁',
age: 18,
});
return this.ok(await this.testEsIndex.find());

View 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();
}
}

View File

@ -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 {
indexInfo() {
return {
// 需要安装ik分词器 https://github.com/medcl/elasticsearch-analysis-ik
name: {
type: 'text',
analyzer: 'ik_max_word',
search_analyzer: 'ik_max_word',
fields: {
raw: {
type: 'keyword',
},
},
},
age: {
type: 'long',

View File

@ -1,11 +1,8 @@
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
import { CoolEvent, Event } from '@cool-midway/core';
/**
*
*/
@Provide()
@Scope(ScopeEnum.Singleton)
@CoolEvent()
export class DemoEvent {
/**

View File

@ -1,8 +1,16 @@
import { Provide } from '@midwayjs/decorator';
import { Inject, Provide } from '@midwayjs/decorator';
import { BaseService } from '@cool-midway/core';
import { CoolRpc } from '@cool-midway/rpc';
/**
*
*/
@Provide()
export class DemoGoodsService extends BaseService {}
export class DemoGoodsService extends BaseService {
@Inject()
rpc: CoolRpc;
async test() {
console.log('调用');
}
}

View File

@ -1,7 +1,13 @@
import { App, Provide } from '@midwayjs/decorator';
import { App, Inject, Provide } from '@midwayjs/decorator';
import { DemoGoodsEntity } from '../entity/goods';
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()
@CoolRpcService({
@ -12,6 +18,33 @@ export class DemoRpcService extends BaseRpcService {
@App()
app: IMidwayApplication;
@Inject()
rpc: CoolRpc;
/**
*
* @param params
* @param rpcTransactionId IDID会自动注入无需调用者传参
* @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) {
return params;
}

View File

@ -1,6 +1,6 @@
import { Provide } from '@midwayjs/decorator';
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()
@CoolController({
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
entity: BaseAppSpaceInfoEntity,
entity: SpaceInfoEntity,
pageQueryOp: {
fieldEq: ['type', 'classifyId'],
},

View File

@ -1,6 +1,6 @@
import { Provide } from '@midwayjs/decorator';
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()
@CoolController({
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
entity: BaseAppSpaceTypeEntity,
entity: SpaceTypeEntity,
})
export class BaseAppSpaceTypeController extends BaseController {}

View File

@ -5,8 +5,8 @@ import { Column } from 'typeorm';
/**
*
*/
@EntityModel('base_app_space_info')
export class BaseAppSpaceInfoEntity extends BaseEntity {
@EntityModel('space_info')
export class SpaceInfoEntity extends BaseEntity {
@Column({ comment: '地址' })
url: string;

View File

@ -5,8 +5,8 @@ import { Column } from 'typeorm';
/**
*
*/
@EntityModel('base_app_space_type')
export class BaseAppSpaceTypeEntity extends BaseEntity {
@EntityModel('space_type')
export class SpaceTypeEntity extends BaseEntity {
@Column({ comment: '类别名称' })
name: string;