mirror of
https://github.com/cool-team-official/cool-admin-midway-packages.git
synced 2025-12-15 08:22:49 +00:00
修改无用代码
This commit is contained in:
parent
fc23c816b2
commit
8deaa90fd4
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cool-midway/core",
|
"name": "@cool-midway/core",
|
||||||
"version": "7.1.16",
|
"version": "7.1.17",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "index.d.ts",
|
"typings": "index.d.ts",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cool-midway/core",
|
"name": "@cool-midway/core",
|
||||||
"version": "7.1.16",
|
"version": "7.1.17",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"typings": "index.d.ts",
|
"typings": "index.d.ts",
|
||||||
|
|||||||
@ -447,7 +447,7 @@ export abstract class BaseMysqlService {
|
|||||||
}
|
}
|
||||||
// 单表字段无别名的情况下操作
|
// 单表字段无别名的情况下操作
|
||||||
if (typeof key === "string") {
|
if (typeof key === "string") {
|
||||||
if (query[key] || (query[key] == 0 && query[key] == "")) {
|
if (query[key] || (query[key] == 0 && query[key] != "")) {
|
||||||
c[key] = query[key];
|
c[key] = query[key];
|
||||||
const eq = query[key] instanceof Array ? "in" : "=";
|
const eq = query[key] instanceof Array ? "in" : "=";
|
||||||
if (eq === "in") {
|
if (eq === "in") {
|
||||||
|
|||||||
@ -509,7 +509,7 @@ export abstract class BasePgService {
|
|||||||
}
|
}
|
||||||
// 单表字段无别名的情况下操作
|
// 单表字段无别名的情况下操作
|
||||||
if (typeof key === "string") {
|
if (typeof key === "string") {
|
||||||
if (query[key] || (query[key] == 0 && query[key] == "")) {
|
if (query[key] || (query[key] == 0 && query[key] != "")) {
|
||||||
c[key] = query[key];
|
c[key] = query[key];
|
||||||
const eq = query[key] instanceof Array ? "in" : "=";
|
const eq = query[key] instanceof Array ? "in" : "=";
|
||||||
if (eq === "in") {
|
if (eq === "in") {
|
||||||
|
|||||||
@ -69,23 +69,23 @@ export abstract class BaseSqliteService {
|
|||||||
let rSql = false;
|
let rSql = false;
|
||||||
if (condition || (condition === 0 && condition !== "")) {
|
if (condition || (condition === 0 && condition !== "")) {
|
||||||
rSql = true;
|
rSql = true;
|
||||||
for(let i = 0; i < params.length; i++) {
|
for (let i = 0; i < params.length; i++) {
|
||||||
const param = params[i];
|
const param = params[i];
|
||||||
if (param instanceof Array) {
|
if (param instanceof Array) {
|
||||||
// 将这个? 替换成 $1,$2,$3
|
// 将这个? 替换成 $1,$2,$3
|
||||||
const replaceStr = [];
|
const replaceStr = [];
|
||||||
for(let j = 0; j < param.length; j++) {
|
for (let j = 0; j < param.length; j++) {
|
||||||
replaceStr.push('$' + (this.sqlParams.length + j + 1));
|
replaceStr.push("$" + (this.sqlParams.length + j + 1));
|
||||||
}
|
}
|
||||||
this.sqlParams = this.sqlParams.concat(...params);
|
this.sqlParams = this.sqlParams.concat(...params);
|
||||||
sql = sql.replace('?', replaceStr.join(','));
|
sql = sql.replace("?", replaceStr.join(","));
|
||||||
} else {
|
} else {
|
||||||
sql = sql.replace('?', '$' + (this.sqlParams.length + 1));
|
sql = sql.replace("?", "$" + (this.sqlParams.length + 1));
|
||||||
this.sqlParams.push(param);
|
this.sqlParams.push(param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (rSql ? sql : "").replace(/\$\d+/g, '?');
|
return (rSql ? sql : "").replace(/\$\d+/g, "?");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,26 +126,29 @@ export abstract class BaseSqliteService {
|
|||||||
*/
|
*/
|
||||||
async nativeQuery(sql, params?, connectionName?) {
|
async nativeQuery(sql, params?, connectionName?) {
|
||||||
if (_.isEmpty(params)) {
|
if (_.isEmpty(params)) {
|
||||||
params = this.sqlParams;
|
params = this.sqlParams;
|
||||||
}
|
}
|
||||||
let newParams = [];
|
let newParams = [];
|
||||||
// sql没处理过?的情况下
|
// sql没处理过?的情况下
|
||||||
for (const item of params) {
|
for (const item of params) {
|
||||||
// 如果是数组,将这个? 替换成 $1,$2,$3
|
// 如果是数组,将这个? 替换成 $1,$2,$3
|
||||||
if (item instanceof Array) {
|
if (item instanceof Array) {
|
||||||
const replaceStr = [];
|
const replaceStr = [];
|
||||||
for(let i = 0; i < item.length; i++) {
|
for (let i = 0; i < item.length; i++) {
|
||||||
replaceStr.push('$' + (newParams.length + i + 1));
|
replaceStr.push("$" + (newParams.length + i + 1));
|
||||||
}
|
|
||||||
newParams.push(...item)
|
|
||||||
sql = sql.replace('?', replaceStr.join(','));
|
|
||||||
} else {
|
|
||||||
sql = sql.replace('?', '$' + (newParams.length + 1));
|
|
||||||
newParams.push(item);
|
|
||||||
}
|
}
|
||||||
|
newParams.push(...item);
|
||||||
|
sql = sql.replace("?", replaceStr.join(","));
|
||||||
|
} else {
|
||||||
|
sql = sql.replace("?", "$" + (newParams.length + 1));
|
||||||
|
newParams.push(item);
|
||||||
}
|
}
|
||||||
this.sqlParams = [];
|
}
|
||||||
return await this.getOrmManager(connectionName).query(sql.replace(/\$\d+/g, '?'), newParams || []);
|
this.sqlParams = [];
|
||||||
|
return await this.getOrmManager(connectionName).query(
|
||||||
|
sql.replace(/\$\d+/g, "?"),
|
||||||
|
newParams || []
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -325,33 +328,37 @@ export abstract class BaseSqliteService {
|
|||||||
* 新增|修改
|
* 新增|修改
|
||||||
* @param param 数据
|
* @param param 数据
|
||||||
*/
|
*/
|
||||||
async addOrUpdate(param: any | any[], type: 'add' | 'update' = 'add') {
|
async addOrUpdate(param: any | any[], type: "add" | "update" = "add") {
|
||||||
if (!this.entity) throw new CoolValidateException(ERRINFO.NOENTITY);
|
if (!this.entity) throw new CoolValidateException(ERRINFO.NOENTITY);
|
||||||
delete param.createTime;
|
delete param.createTime;
|
||||||
// 判断是否是批量操作
|
// 判断是否是批量操作
|
||||||
if (param instanceof Array) {
|
if (param instanceof Array) {
|
||||||
param.forEach((item) => {
|
param.forEach((item) => {
|
||||||
item.updateTime = new Date();
|
item.updateTime = new Date();
|
||||||
item.createTime = new Date();
|
item.createTime = new Date();
|
||||||
});
|
});
|
||||||
await this.entity.save(param);
|
await this.entity.save(param);
|
||||||
} else{
|
} else {
|
||||||
const upsert = this._coolConfig.crud?.upsert || 'normal';
|
const upsert = this._coolConfig.crud?.upsert || "normal";
|
||||||
if (type == 'update') {
|
if (type == "update") {
|
||||||
if(upsert == 'save') {
|
if (upsert == "save") {
|
||||||
const info = await this.entity.findOneBy({id: param.id})
|
const info = await this.entity.findOneBy({ id: param.id });
|
||||||
param = {
|
param = {
|
||||||
...info,
|
...info,
|
||||||
...param
|
...param,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
param.updateTime = new Date();
|
param.updateTime = new Date();
|
||||||
upsert == 'normal'? await this.entity.update(param.id, param): await this.entity.save(param);
|
upsert == "normal"
|
||||||
|
? await this.entity.update(param.id, param)
|
||||||
|
: await this.entity.save(param);
|
||||||
}
|
}
|
||||||
if(type =='add'){
|
if (type == "add") {
|
||||||
param.createTime = new Date();
|
param.createTime = new Date();
|
||||||
param.updateTime = new Date();
|
param.updateTime = new Date();
|
||||||
upsert == 'normal'? await this.entity.insert(param): await this.entity.save(param);
|
upsert == "normal"
|
||||||
|
? await this.entity.insert(param)
|
||||||
|
: await this.entity.save(param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -466,14 +473,14 @@ export abstract class BaseSqliteService {
|
|||||||
for (let key of option.fieldEq) {
|
for (let key of option.fieldEq) {
|
||||||
const c = {};
|
const c = {};
|
||||||
// 如果key有包含.的情况下操作
|
// 如果key有包含.的情况下操作
|
||||||
if(typeof key === "string" && key.includes('.')){
|
if (typeof key === "string" && key.includes(".")) {
|
||||||
const keys = key.split('.');
|
const keys = key.split(".");
|
||||||
const lastKey = keys.pop();
|
const lastKey = keys.pop();
|
||||||
key = {requestParam: lastKey, column: key};
|
key = { requestParam: lastKey, column: key };
|
||||||
}
|
}
|
||||||
// 单表字段无别名的情况下操作
|
// 单表字段无别名的情况下操作
|
||||||
if (typeof key === "string") {
|
if (typeof key === "string") {
|
||||||
if (query[key] || (query[key] == 0 && query[key] == "")) {
|
if (query[key] || (query[key] == 0 && query[key] != "")) {
|
||||||
c[key] = query[key];
|
c[key] = query[key];
|
||||||
const eq = query[key] instanceof Array ? "in" : "=";
|
const eq = query[key] instanceof Array ? "in" : "=";
|
||||||
if (eq === "in") {
|
if (eq === "in") {
|
||||||
@ -481,7 +488,7 @@ export abstract class BaseSqliteService {
|
|||||||
} else {
|
} else {
|
||||||
find.andWhere(`${key} ${eq} :${key}`, c);
|
find.andWhere(`${key} ${eq} :${key}`, c);
|
||||||
}
|
}
|
||||||
// this.sqlParams.push(query[key]);
|
// this.sqlParams.push(query[key]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
@ -495,7 +502,7 @@ export abstract class BaseSqliteService {
|
|||||||
} else {
|
} else {
|
||||||
find.andWhere(`${key.column} ${eq} :${key.column}`, c);
|
find.andWhere(`${key.column} ${eq} :${key.column}`, c);
|
||||||
}
|
}
|
||||||
// this.sqlParams.push(query[key.requestParam]);
|
// this.sqlParams.push(query[key.requestParam]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -526,5 +533,4 @@ export abstract class BaseSqliteService {
|
|||||||
sqlArr.push(sqls[sqls.length - 1]);
|
sqlArr.push(sqls[sqls.length - 1]);
|
||||||
return sqlArr.join(" ");
|
return sqlArr.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user