mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2026-01-08 04:38:12 +00:00
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { Inject, Provide } from '@midwayjs/decorator';
|
|
import { BaseService, Cache, CoolTransaction } from 'midwayjs-cool-core';
|
|
import { InjectEntityModel } from '@midwayjs/orm';
|
|
import { Repository, QueryRunner } from 'typeorm';
|
|
import { DemoAppGoodsEntity } from '../entity/goods';
|
|
import { ICoolCache } from 'midwayjs-cool-core';
|
|
|
|
/**
|
|
* 商品
|
|
*/
|
|
@Provide()
|
|
export class DemoGoodsService extends BaseService {
|
|
@InjectEntityModel(DemoAppGoodsEntity)
|
|
demoAppGoodsEntity: Repository<DemoAppGoodsEntity>;
|
|
|
|
@Inject('cool:cache')
|
|
coolCache: ICoolCache;
|
|
|
|
/**
|
|
* 返回所有数据
|
|
*/
|
|
@Cache(5)
|
|
async all() {
|
|
return this.demoAppGoodsEntity.find();
|
|
}
|
|
|
|
/**
|
|
* 事务
|
|
* @param params
|
|
* @param queryRunner
|
|
*/
|
|
@CoolTransaction({ isolation: 'SERIALIZABLE' })
|
|
async testTransaction(params: any, queryRunner?: QueryRunner) {
|
|
await queryRunner.manager.insert<DemoAppGoodsEntity>(DemoAppGoodsEntity, {
|
|
title: '这是个商品',
|
|
pic: '商品图',
|
|
price: 99.0,
|
|
type: 1,
|
|
});
|
|
}
|
|
}
|