import BaseController from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { SysExportInfo } from "../../entity/sys/import/sysExportInfo";
|
import { SysExportColumnInfo } from "../../entity/sys/import/sysExportColumnInfo";
|
import { SysImportInfo } from "../../entity/sys/import/sysImportInfo";
|
|
/**
|
* 通用导入模块
|
*/
|
export default class ImportController extends BaseController {
|
//#region GetExportInfo
|
/// <summary>
|
/// 获得导出字段信息
|
/// </summary>
|
/// <param name="this.body">请求参数</param>
|
@Post()
|
public async getExportInfo() {
|
try {
|
var dataInfo = await this.dbRead.findOne(SysExportInfo, this.body.exportInfo_Id);
|
if (dataInfo != null) {
|
this.info.data = dataInfo;
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
this.info.msg = "获取数据失败";
|
}
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "获取数据失败," + ex.message;
|
}
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region GetExportColList
|
/// <summary>
|
/// 获得导出字段信息
|
/// </summary>
|
/// <param name="this.body">请求参数</param>
|
@Post()
|
public async getExportColList() {
|
try {
|
var dataInfo = await this.dbRead.find(SysExportColumnInfo, {
|
where: {
|
exportInfo_Id: this.body.exportInfo_Id,
|
enable: 1
|
},
|
order: {
|
orderNo: "DESC",
|
exportInfo_Id: "ASC"
|
}
|
});
|
if (dataInfo != null) {
|
this.info.data = dataInfo;
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
this.info.msg = "获取数据失败";
|
}
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "获取数据失败," + ex.message;
|
}
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region GetImportInfo
|
/// <summary>
|
/// 获得导出字段信息
|
/// </summary>
|
/// <param name="this.body">请求参数</param>
|
@Post()
|
public async getImportInfo() {
|
try {
|
var dataInfo = await this.dbRead.findOne(SysImportInfo, this.body.importInfo_Id);
|
if (dataInfo != null) {
|
this.info.data = dataInfo;
|
this.info.result = true;
|
} else {
|
this.info.result = false;
|
this.info.msg = "获取数据失败";
|
}
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "获取数据失败," + ex.message;
|
}
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region startImport
|
@Post()
|
public async startImport() {
|
setTimeout(async () => {
|
await this.importWork();
|
}, 0);
|
|
this.info.result = true;
|
this.info.statusCode = 0;
|
this.ctx.body = this.info;
|
}
|
|
/**
|
* 批量导入业务处理
|
*/
|
private async importWork() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let redis = ctx.app.redis.clients.get("common"); // 将消息放入redis缓存
|
let fileUrl = body.fileUrl;
|
redis.expire(body.uploadKey, 5 * 60);
|
if (!body.uploadKey) {
|
redis.rpush(body.uploadKey, "上传key不存在");
|
redis.expire(body.uploadKey, 5 * 60);
|
return;
|
}
|
if (!fileUrl) {
|
redis.rpush(body.uploadKey, "上传文件不存在");
|
redis.expire(body.uploadKey, 5 * 60);
|
return;
|
}
|
|
await this.ctx.service.sys.importCommon.start();
|
await redis.rpush(this.body.uploadKey, "执行完成");
|
await redis.rpush(this.body.uploadKey, "-1");
|
redis.expire(this.body.uploadKey, 5 * 60);
|
}
|
//#endregion
|
}
|