import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { SysCodeRegular } from "../../entity/sys/core/sysCodeRegular";
|
import { SysCodeRegularUser } from "../../entity/sys/core/sysCodeRegularUser";
|
|
/**
|
* 编码规则
|
*/
|
export default class CodeRegularController extends BaseController {
|
//#region saveCommon
|
/**
|
* saveCommon
|
*/
|
@Post()
|
public async saveCommon() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
var regularInfo = await this.dbRead.findOne(SysCodeRegular, {
|
code_Id: body.code_Id
|
});
|
|
if (!regularInfo) {
|
this.info.result = false;
|
this.info.msg = "当前不存在!";
|
return this.info;
|
}
|
|
var regularUserInfo = await this.dbRead.findOne(SysCodeRegularUser, {
|
where: {
|
userProduct_Id: userInfo.userProduct_Id,
|
code_Id: body.code_Id
|
}
|
});
|
if (regularUserInfo == null) {
|
regularUserInfo = new SysCodeRegularUser();
|
regularUserInfo.platCorpName = userInfo.platCorpName;
|
regularUserInfo.platUser_Id = userInfo.platUser_Id;
|
regularUserInfo.platUserCode = userInfo.platUserCode;
|
regularUserInfo.platUserName = userInfo.platUserName;
|
regularUserInfo.userProductCode = userInfo.userProductCode;
|
regularUserInfo.userProduct_Id = userInfo.userProduct_Id;
|
regularUserInfo.userProductAlias = userInfo.userProductAlias;
|
|
regularUserInfo.code_Id = body.code_Id;
|
regularUserInfo.prefix = body.prefix;
|
regularUserInfo.charLength = body.charLength;
|
regularUserInfo.prefix = body.prefix;
|
regularUserInfo.isCustom = body.isCustom;
|
regularUserInfo.jsonData = body.jsonData;
|
regularUserInfo.codeRegular = body.codeRegular;
|
|
await this.dbWrite.insert(SysCodeRegularUser, regularUserInfo);
|
this.info.result = true;
|
this.info.msg = regularInfo.menuName + "新增编码成功!";
|
} else {
|
let _regularInfo: any = {};
|
_regularInfo.code_Id = body.code_Id;
|
_regularInfo.prefix = body.prefix;
|
_regularInfo.charLength = body.charLength;
|
_regularInfo.prefix = body.prefix;
|
_regularInfo.isCustom = body.isCustom;
|
_regularInfo.jsonData = body.jsonData;
|
_regularInfo.codeRegular = body.codeRegular;
|
|
await this.dbWrite.update(SysCodeRegularUser, regularUserInfo.codeUser_Id, _regularInfo);
|
this.info.result = true;
|
this.info.msg = regularInfo.menuName + "保存编码成功!";
|
}
|
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region getTreeData
|
/**
|
* 获得tree类型数据
|
*/
|
@Post()
|
public async getTreeData() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
var regularInfo = await this.dbWrite.findOne(SysCodeRegularUser, {
|
where: {
|
userProduct_Id: userInfo.userProduct_Id,
|
code_Id: body.code_Id
|
}
|
});
|
|
//获得默认规则
|
if (regularInfo == null) {
|
var defaultInfo = await this.dbRead.findOne(SysCodeRegular, {
|
code_Id: body.code_Id
|
});
|
if (defaultInfo) {
|
this.info.code = defaultInfo.code;
|
}
|
}
|
|
this.info.result = true;
|
this.info.data = regularInfo;
|
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region reset
|
/**
|
* 还原为默认规则
|
*/
|
@Post()
|
public async reset() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
var regularInfo = await this.dbRead.findOne(SysCodeRegular, {
|
code_Id: body.code_Id
|
});
|
|
if (!regularInfo) {
|
this.info.result = false;
|
this.info.msg = "当前不存在!";
|
return this.info;
|
}
|
|
var regularUserInfo = await this.dbRead.findOne(SysCodeRegularUser, {
|
userProduct_Id: userInfo.userProduct_Id,
|
code_Id: body.code_Id
|
});
|
if (!regularUserInfo) {
|
this.info.result = false;
|
this.info.msg = "不存在自定义设置!";
|
} else {
|
await this.dbWrite.delete(SysCodeRegularUser, {
|
userProduct_Id: userInfo.userProduct_Id,
|
code_Id: regularUserInfo.code_Id
|
});
|
this.info.result = true;
|
this.info.msg = regularInfo.menuName + "重置成功!";
|
}
|
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|