Skip to content

Commit

Permalink
5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
apgzs committed Mar 21, 2022
1 parent ee67ced commit 14a5113
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 139 deletions.
27 changes: 0 additions & 27 deletions .vscode/service copy.code-snippets

This file was deleted.

1 change: 0 additions & 1 deletion cache/diskstore-9ff8bf81170e3d10f423be0ea3babea7.json

This file was deleted.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
25 changes: 11 additions & 14 deletions src/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
};
5 changes: 5 additions & 0 deletions src/config/config.local.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CoolConfig } from '@cool-midway/core';
import { MidwayConfig } from '@midwayjs/core';

/**
Expand All @@ -18,4 +19,8 @@ export default {
// 字符集
charset: 'utf8mb4',
},
cool: {
// 是否自动导入数据库
initDB: true,
} as CoolConfig,
} as MidwayConfig;
7 changes: 6 additions & 1 deletion src/config/config.prod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CoolConfig } from '@cool-midway/core';
import { MidwayConfig } from '@midwayjs/core';

/**
Expand All @@ -14,8 +15,12 @@ export default {
// 自动建表 注意:线上部署的时候不要使用,有可能导致数据丢失
synchronize: false,
// 打印日志
logging: true,
logging: false,
// 字符集
charset: 'utf8mb4',
},
cool: {
// 是否自动导入数据库
initDB: false,
} as CoolConfig,
} as MidwayConfig;
10 changes: 1 addition & 9 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
// 文件上传 阿里云存储 腾讯云存储 七牛云存储
Expand All @@ -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() {}
}
63 changes: 0 additions & 63 deletions src/modules/base/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
-- ----------------------------
Expand Down Expand Up @@ -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;
14 changes: 13 additions & 1 deletion src/modules/demo/controller/app/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 7 additions & 1 deletion src/modules/demo/controller/app/es.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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());
Expand Down
36 changes: 36 additions & 0 deletions src/modules/demo/controller/app/rpc.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
10 changes: 9 additions & 1 deletion src/modules/demo/es/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 0 additions & 3 deletions src/modules/demo/event/demo.ts
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down
12 changes: 10 additions & 2 deletions src/modules/demo/service/goods.ts
Original file line number Diff line number Diff line change
@@ -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('调用');
}
}
Loading

0 comments on commit 14a5113

Please sign in to comment.