mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2025-12-10 16:12:50 +00:00
兼容pg
This commit is contained in:
parent
7200ef1efa
commit
7706dc90de
@ -2,7 +2,10 @@ import { Index, PrimaryGeneratedColumn, Column } from 'typeorm';
|
|||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import { CoolBaseEntity } from '@cool-midway/core';
|
import { CoolBaseEntity } from '@cool-midway/core';
|
||||||
|
|
||||||
const transformer = {
|
/**
|
||||||
|
* 时间转换器
|
||||||
|
*/
|
||||||
|
export const transformerTime = {
|
||||||
to(value) {
|
to(value) {
|
||||||
return value
|
return value
|
||||||
? moment(value).format('YYYY-MM-DD HH:mm:ss')
|
? moment(value).format('YYYY-MM-DD HH:mm:ss')
|
||||||
@ -13,6 +16,23 @@ const transformer = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Json转换器
|
||||||
|
*/
|
||||||
|
export const transformerJson = {
|
||||||
|
to: value => value,
|
||||||
|
from: value => {
|
||||||
|
// 确保从数据库返回的是对象
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
try {
|
||||||
|
return JSON.parse(value);
|
||||||
|
} catch (e) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* 实体基类
|
* 实体基类
|
||||||
*/
|
*/
|
||||||
@ -27,7 +47,7 @@ export abstract class BaseEntity extends CoolBaseEntity {
|
|||||||
@Column({
|
@Column({
|
||||||
comment: '创建时间',
|
comment: '创建时间',
|
||||||
type: 'varchar',
|
type: 'varchar',
|
||||||
transformer,
|
transformer: transformerTime,
|
||||||
})
|
})
|
||||||
createTime: Date;
|
createTime: Date;
|
||||||
|
|
||||||
@ -35,7 +55,7 @@ export abstract class BaseEntity extends CoolBaseEntity {
|
|||||||
@Column({
|
@Column({
|
||||||
comment: '更新时间',
|
comment: '更新时间',
|
||||||
type: 'varchar',
|
type: 'varchar',
|
||||||
transformer,
|
transformer: transformerTime,
|
||||||
})
|
})
|
||||||
updateTime: Date;
|
updateTime: Date;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { BaseEntity } from '../base';
|
import { BaseEntity, transformerJson } from '../base';
|
||||||
import { Column, Index, Entity } from 'typeorm';
|
import { Column, Index, Entity } from 'typeorm';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,6 +18,11 @@ export class BaseSysLogEntity extends BaseEntity {
|
|||||||
@Column({ comment: 'ip', nullable: true })
|
@Column({ comment: 'ip', nullable: true })
|
||||||
ip: string;
|
ip: string;
|
||||||
|
|
||||||
@Column({ comment: '参数', nullable: true, type: 'json' })
|
@Column({
|
||||||
|
comment: '参数',
|
||||||
|
nullable: true,
|
||||||
|
type: 'json',
|
||||||
|
transformer: transformerJson,
|
||||||
|
})
|
||||||
params: string;
|
params: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { BaseEntity } from '../base';
|
import { BaseEntity, transformerJson } from '../base';
|
||||||
import { Column, Index, Entity } from 'typeorm';
|
import { Column, Index, Entity } from 'typeorm';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,9 +23,9 @@ export class BaseSysRoleEntity extends BaseEntity {
|
|||||||
@Column({ comment: '数据权限是否关联上下级', default: false })
|
@Column({ comment: '数据权限是否关联上下级', default: false })
|
||||||
relevance: boolean;
|
relevance: boolean;
|
||||||
|
|
||||||
@Column({ comment: '菜单权限', type: 'json' })
|
@Column({ comment: '菜单权限', type: 'json', transformer: transformerJson })
|
||||||
menuIdList: number[];
|
menuIdList: number[];
|
||||||
|
|
||||||
@Column({ comment: '部门权限', type: 'json' })
|
@Column({ comment: '部门权限', type: 'json', transformer: transformerJson })
|
||||||
departmentIdList: number[];
|
departmentIdList: number[];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { BaseEntity } from '../../base/entity/base';
|
import { BaseEntity, transformerJson } from '../../base/entity/base';
|
||||||
import { Column, Entity, Index } from 'typeorm';
|
import { Column, Entity, Index } from 'typeorm';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,7 +30,12 @@ export class DemoGoodsEntity extends BaseEntity {
|
|||||||
@Column({ comment: '状态', dict: ['禁用', '启用'], default: 1 })
|
@Column({ comment: '状态', dict: ['禁用', '启用'], default: 1 })
|
||||||
status: number;
|
status: number;
|
||||||
|
|
||||||
@Column({ comment: '示例图', nullable: true, type: 'json' })
|
@Column({
|
||||||
|
comment: '示例图',
|
||||||
|
nullable: true,
|
||||||
|
type: 'json',
|
||||||
|
transformer: transformerJson,
|
||||||
|
})
|
||||||
exampleImages: string[];
|
exampleImages: string[];
|
||||||
|
|
||||||
@Column({ comment: '库存', default: 0 })
|
@Column({ comment: '库存', default: 0 })
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { BaseEntity } from '../../base/entity/base';
|
import { BaseEntity, transformerJson } from '../../base/entity/base';
|
||||||
import { Column, Entity, Index } from 'typeorm';
|
import { Column, Entity, Index } from 'typeorm';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,21 +34,31 @@ export class PluginInfoEntity extends BaseEntity {
|
|||||||
@Column({ comment: '状态 0-禁用 1-启用', default: 0 })
|
@Column({ comment: '状态 0-禁用 1-启用', default: 0 })
|
||||||
status: number;
|
status: number;
|
||||||
|
|
||||||
@Column({ comment: '内容', type: 'json' })
|
@Column({ comment: '内容', type: 'json', transformer: transformerJson })
|
||||||
content: {
|
content: {
|
||||||
type: 'comm' | 'module';
|
type: 'comm' | 'module';
|
||||||
data: string;
|
data: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@Column({ comment: 'ts内容', type: 'json' })
|
@Column({ comment: 'ts内容', type: 'json', transformer: transformerJson })
|
||||||
tsContent: {
|
tsContent: {
|
||||||
type: 'ts';
|
type: 'ts';
|
||||||
data: string;
|
data: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@Column({ comment: '插件的plugin.json', type: 'json', nullable: true })
|
@Column({
|
||||||
|
comment: '插件的plugin.json',
|
||||||
|
type: 'json',
|
||||||
|
transformer: transformerJson,
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
pluginJson: any;
|
pluginJson: any;
|
||||||
|
|
||||||
@Column({ comment: '配置', type: 'json', nullable: true })
|
@Column({
|
||||||
|
comment: '配置',
|
||||||
|
type: 'json',
|
||||||
|
transformer: transformerJson,
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
config: any;
|
config: any;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { BaseEntity } from '../../base/entity/base';
|
import { BaseEntity, transformerJson } from '../../base/entity/base';
|
||||||
import { Entity, Column, Index } from 'typeorm';
|
import { Entity, Column, Index } from 'typeorm';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -6,7 +6,7 @@ import { Entity, Column, Index } from 'typeorm';
|
|||||||
*/
|
*/
|
||||||
@Entity('recycle_data')
|
@Entity('recycle_data')
|
||||||
export class RecycleDataEntity extends BaseEntity {
|
export class RecycleDataEntity extends BaseEntity {
|
||||||
@Column({ comment: '表', type: 'json' })
|
@Column({ comment: '表', type: 'json', transformer: transformerJson })
|
||||||
entityInfo: {
|
entityInfo: {
|
||||||
// 数据源名称
|
// 数据源名称
|
||||||
dataSourceName: string;
|
dataSourceName: string;
|
||||||
@ -18,13 +18,22 @@ export class RecycleDataEntity extends BaseEntity {
|
|||||||
@Column({ comment: '操作人', nullable: true })
|
@Column({ comment: '操作人', nullable: true })
|
||||||
userId: number;
|
userId: number;
|
||||||
|
|
||||||
@Column({ comment: '被删除的数据', type: 'json' })
|
@Column({
|
||||||
|
comment: '被删除的数据',
|
||||||
|
type: 'json',
|
||||||
|
transformer: transformerJson,
|
||||||
|
})
|
||||||
data: object[];
|
data: object[];
|
||||||
|
|
||||||
@Column({ comment: '请求的接口', nullable: true })
|
@Column({ comment: '请求的接口', nullable: true })
|
||||||
url: string;
|
url: string;
|
||||||
|
|
||||||
@Column({ comment: '请求参数', nullable: true, type: 'json' })
|
@Column({
|
||||||
|
comment: '请求参数',
|
||||||
|
nullable: true,
|
||||||
|
type: 'json',
|
||||||
|
transformer: transformerJson,
|
||||||
|
})
|
||||||
params: string;
|
params: string;
|
||||||
|
|
||||||
@Column({ comment: '删除数据条数', default: 1 })
|
@Column({ comment: '删除数据条数', default: 1 })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user