import {
|
Provide,
|
Body,
|
ALL,
|
Inject,
|
Post,
|
Get,
|
Query,
|
} from '@midwayjs/decorator';
|
import { Context } from 'egg';
|
import { CoolController, BaseController } from '@cool-midway/core';
|
import { LoginDTO } from '../../dto/login';
|
import * as fs from 'fs';
|
import { BaseSysLoginService } from '../../service/sys/login';
|
import { BaseSysParamService } from '../../service/sys/param';
|
import { DataService } from '../../service/dataapi/dataapi';
|
import { CommEntity } from '../../entity/app/commentity';
|
import { CreateEntityUtil } from '../../utils/createEntity';
|
|
/**
|
* 不需要登录的后台接口
|
*/
|
@Provide()
|
@CoolController({
|
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
|
entity: CommEntity
|
})
|
export class BaseOpenController extends BaseController {
|
@Inject()
|
baseSysLoginService: BaseSysLoginService;
|
|
@Inject()
|
baseSysParamService: BaseSysParamService;
|
|
@Inject()
|
dataService: DataService;
|
|
@Inject()
|
createEntityUtil: CreateEntityUtil;
|
|
@Inject()
|
ctx: Context;
|
|
@Inject('cool:eps:open')
|
eps;
|
|
/**
|
* 实体信息与路径
|
* @returns
|
*/
|
@Get('/eps', { summary: '实体信息与路径' })
|
public async getEps() {
|
return this.ok(this.eps);
|
}
|
|
/**
|
* 根据配置参数key获得网页内容(富文本)
|
*/
|
@Get('/html', { summary: '获得网页内容的参数值' })
|
async htmlByKey(@Query() key: string) {
|
this.ctx.body = await this.baseSysParamService.htmlByKey(key);
|
}
|
|
/**
|
* 登录
|
* @param login
|
*/
|
@Post('/login', { summary: '登录' })
|
async login(@Body(ALL) login: LoginDTO) {
|
return this.ok(await this.baseSysLoginService.login(login));
|
}
|
|
/**
|
* 获得验证码
|
*/
|
@Get('/captcha', { summary: '验证码' })
|
async captcha(
|
@Query() type: string,
|
@Query() width: number,
|
@Query() height: number
|
) {
|
return this.ok(await this.baseSysLoginService.captcha(type, width, height));
|
}
|
|
/**
|
* 刷新token
|
*/
|
@Get('/refreshToken', { summary: '刷新token' })
|
async refreshToken(@Query() refreshToken: string) {
|
return this.ok(await this.baseSysLoginService.refreshToken(refreshToken));
|
}
|
|
|
/**
|
* 获得数据
|
*/
|
@Get('/getdata', { summary: '数据接口' })
|
async getData(@Query(ALL) params: any) {
|
console.log(params);
|
return this.ok(await this.dataService.getData(params));
|
}
|
|
/**
|
* 获得数据
|
*/
|
@Post('/postdata', { summary: '数据接口' })
|
async postData(@Query(ALL) params: any) {
|
return this.ok(await this.dataService.getData(params));
|
}
|
|
@Get('/createEntity', {})
|
async createEntity() {
|
console.log('生成综合实体类任务开始执行');
|
|
let tables = await this.dataService.getDataByNative({ "bid": "getTableNeedCreate", "pageindex": "1", "pagesize": "300" })
|
let columns = await this.dataService.getDataByNative({ "bid": "getColumns", "pageindex": "1", "pagesize": "300" }) //bid_obj_[0], query?.pageindex || null , query?.pagesize || null, query
|
console.log(`${tables.length} and columnlength ${columns.length}`)
|
let tabs = {};
|
tables.forEach(element => {
|
tabs[element.name] = element;
|
});
|
columns.forEach(element => {
|
let tbname = element.table_name;
|
if (!tabs[tbname]) {
|
tabs[tbname] = {}
|
}
|
if (!tabs[tbname].tbcolumn) {
|
tabs[tbname].tbcolumn = [];
|
}
|
tabs[tbname].tbcolumn.push(element)
|
});
|
Object.keys(tabs).forEach(key => {
|
this.createEntityUtil.createEntity(tabs[key])
|
this.createEntityUtil.createService(tabs[key])
|
this.createEntityUtil.createController(tabs[key])
|
})
|
}
|
|
}
|