import BaseController from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { SysParamValue } from "../../entity/sys/core/sysParamValue";
|
import { IsNull, Not, In } from "typeorm";
|
import { SysParamValue2 } from "../../entity/sys/core/sysParamValue2";
|
|
export default class ParamContrller extends BaseController {
|
//#region getConfig
|
/**
|
* 获得参数值集合
|
*/
|
@Post()
|
public async getConfig() {
|
let { ctx } = this;
|
let body = ctx.body;
|
let userInfo = await ctx.helper.userInfo();
|
let type_Id = body.type_Id;
|
if (!type_Id) type_Id = 585;
|
|
var keys = body.keys;
|
if (!Array.isArray(body.keys)) {
|
keys = body.keys.split(",");
|
}
|
var valueList: Array<SysParamValue> = [];
|
for (var key of keys) {
|
var valueInfo = await this.dbRead.findOne(SysParamValue, {
|
select: ["params_Id", "type_Id", "value01", "value02", "value03", "value04"],
|
where: {
|
type_Id: type_Id,
|
userProduct_Id: userInfo.userProduct_Id,
|
value02: key
|
}
|
});
|
|
//获得默认规则
|
if (!valueInfo) {
|
valueInfo = await this.dbRead.findOne(SysParamValue, {
|
where: {
|
type_Id: type_Id,
|
userProduct_Id: userInfo.userProduct_Id,
|
value02: key
|
}
|
});
|
}
|
if (valueInfo) {
|
valueList.push(valueInfo);
|
}
|
}
|
|
this.info.result = true;
|
this.info.data = valueList;
|
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region getValueList
|
/**
|
* 获得参数值集合
|
*/
|
@Post()
|
public async getValueList() {
|
let { ctx } = this;
|
let body = ctx.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
var valueList = await this.dbRead.find(SysParamValue, {
|
where: {
|
type_Id: body.type_Id,
|
userProduct_Id: userInfo.userProduct_Id
|
}
|
});
|
|
//获得默认规则
|
if (valueList.length === 0) {
|
valueList = await this.dbRead.find(SysParamValue, {
|
where: [
|
{
|
type_Id: body.type_Id,
|
userProduct_Id: IsNull()
|
},
|
{
|
type_Id: body.type_Id,
|
userProduct_Id: 0
|
}
|
]
|
});
|
}
|
|
this.info.result = true;
|
this.info.data = valueList;
|
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region saveParams
|
/**
|
* 保存参数值
|
*/
|
@Post()
|
public async saveParams() {
|
let { ctx } = this;
|
let body = ctx.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
try {
|
var params_Ids = "0";
|
for (let valueInfo of body.valueList) {
|
var valInfo = await this.dbRead.findOne(SysParamValue, {
|
where: {
|
type_Id: valueInfo.type_Id || body.type_Id,
|
userProduct_Id: userInfo.userProduct_Id,
|
value02: valueInfo.value02
|
}
|
});
|
|
//更新自有参数值
|
if (valInfo) {
|
var _valInfo: any = {};
|
_valInfo.value01 = valueInfo.value01;
|
_valInfo.value02 = valueInfo.value02;
|
_valInfo.value03 = valueInfo.value03;
|
_valInfo.value04 = valueInfo.value04;
|
_valInfo.value05 = valueInfo.value05;
|
_valInfo.enable = 1;
|
await this.dbWrite.update(SysParamValue, valInfo.params_Id, _valInfo);
|
params_Ids += "," + valInfo.params_Id;
|
} else {
|
var paramInfo = new SysParamValue2();
|
paramInfo.type_Id = body.type_Id;
|
paramInfo.value01 = valueInfo.value01;
|
paramInfo.value02 = valueInfo.value02;
|
paramInfo.value03 = valueInfo.value03;
|
paramInfo.value04 = valueInfo.value04;
|
paramInfo.value05 = valueInfo.value05;
|
paramInfo.enable = 1;
|
|
paramInfo.platCorpName = userInfo.platCorpName;
|
paramInfo.platUserCode = userInfo.platUserCode;
|
paramInfo.platUserName = userInfo.platUserName;
|
paramInfo.platUser_Id = userInfo.platUser_Id;
|
paramInfo.userProductAlias = userInfo.userProductAlias;
|
paramInfo.userProductCode = userInfo.userProductCode;
|
paramInfo.userProduct_Id = userInfo.userProduct_Id;
|
await this.dbWrite.insert(SysParamValue2, paramInfo);
|
|
valInfo = await this.dbWrite.findOne(SysParamValue, {
|
where: {
|
type_Id: valueInfo.type_Id || body.type_Id,
|
userProduct_Id: userInfo.userProduct_Id,
|
value02: valueInfo.value02
|
}
|
});
|
if (valInfo) {
|
params_Ids += "," + valInfo.params_Id;
|
}
|
}
|
}
|
|
// 585=为系统参数
|
if (body.type_Id != 585) {
|
//删除不存在的数据
|
await this.dbWrite.delete(SysParamValue, {
|
type_Id: body.type_Id,
|
userProduct_Id: userInfo.userProduct_Id,
|
params_Id: Not(In(params_Ids.split(",")))
|
});
|
}
|
|
this.info.result = true;
|
this.info.msg = "保存成功";
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "保存失败," + ex.message;
|
}
|
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|