|
|
|
@ -13,7 +13,13 @@ import { |
|
|
|
|
RegisterEmailSignUpDto, |
|
|
|
|
sex, |
|
|
|
|
} from './dto/register.dto'; |
|
|
|
|
import { PositionCreateDTO } from './dto/position.dto'; |
|
|
|
|
import { |
|
|
|
|
PositionCreateDTO, |
|
|
|
|
PositionDeleteDTO, |
|
|
|
|
PositionListDTO, |
|
|
|
|
PositionRelationDTO, |
|
|
|
|
PositionUpdateDTO, |
|
|
|
|
} from './dto/position.dto'; |
|
|
|
|
import { ConfigService } from '@nestjs/config'; |
|
|
|
|
import { GloggerService } from '@/Gservice/GLOGGER/glogger.service'; |
|
|
|
|
import { GdatabaseService } from '@/Gservice/GDATABASE/gdatabase.service'; |
|
|
|
@ -608,14 +614,455 @@ export class StarlightService { |
|
|
|
|
const fatherid = body.fatherid, |
|
|
|
|
type = body.type.trim(), |
|
|
|
|
name = body.name.trim(), |
|
|
|
|
index = body.index.trim().toLowerCase(), |
|
|
|
|
pointer = body.pointer.trim().toLowerCase(), |
|
|
|
|
describe = body.describe.trim(), |
|
|
|
|
ico = body.ico.trim(); |
|
|
|
|
this.logger.info(userinfo); |
|
|
|
|
this.logger.info(fatherid, type, name, index, describe, ico); |
|
|
|
|
// 查重标识位
|
|
|
|
|
// 写入标识位
|
|
|
|
|
return {}; |
|
|
|
|
this.logger.info(fatherid, type, name, pointer, describe, ico); |
|
|
|
|
// ! 判断父定位是否存在
|
|
|
|
|
if (fatherid != 0) { |
|
|
|
|
try { |
|
|
|
|
const SQL = `SELECT * FROM user_position WHERE id = ? AND is_delete != 1`; |
|
|
|
|
const [rows] = await this.database.DB.execute(SQL, [fatherid]); |
|
|
|
|
this.logger.info(rows); |
|
|
|
|
if (rows.length != 1) { |
|
|
|
|
const message = '未找到父级定位!'; |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
this.logger.error(e); |
|
|
|
|
const message = '查找定位信息出现错误!'; |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// ! 查重标识
|
|
|
|
|
try { |
|
|
|
|
const SQL = `SELECT pointer FROM user_position WHERE pointer = ?`; |
|
|
|
|
const [rows, fault] = await this.database.DB.execute(SQL, [ |
|
|
|
|
pointer, |
|
|
|
|
]); |
|
|
|
|
if (rows.length > 0) { |
|
|
|
|
const message = '定位标识重复!'; |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
this.logger.error(e); |
|
|
|
|
const message = '查找定位信息标识重名出现错误!'; |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
// ! 判断同级定位是否重名
|
|
|
|
|
try { |
|
|
|
|
const SQL = `SELECT name FROM user_position WHERE fatherid = ? AND is_delete != 1`; |
|
|
|
|
const [rows, fault] = await this.database.DB.execute(SQL, [ |
|
|
|
|
fatherid, |
|
|
|
|
]); |
|
|
|
|
for (const i of rows) { |
|
|
|
|
if (i.name == name) { |
|
|
|
|
const message = '同级定位重名!'; |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
this.logger.error(e); |
|
|
|
|
const message = '查找定位信息名称重名出现错误!'; |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
// ! 写入定位
|
|
|
|
|
try { |
|
|
|
|
const createTime = new Date(); |
|
|
|
|
const SQL = `INSERT INTO user_position (pointer, name, type, position_describe, fatherid, ico, creator, createtime) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`; |
|
|
|
|
const [rows] = await this.database.DB.execute(SQL, [ |
|
|
|
|
pointer, |
|
|
|
|
name, |
|
|
|
|
type, |
|
|
|
|
describe, |
|
|
|
|
fatherid, |
|
|
|
|
ico, |
|
|
|
|
userinfo.uuid, |
|
|
|
|
createTime, |
|
|
|
|
]); |
|
|
|
|
this.logger.info(rows); |
|
|
|
|
} catch (e) { |
|
|
|
|
this.logger.error(e); |
|
|
|
|
const message = '写入定位信息出现错误!'; |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message: '创建定位成功!', |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ? ?
|
|
|
|
|
// ? 函数名称: positionAll
|
|
|
|
|
// ? 函数描述: 获取所有角色定位信息
|
|
|
|
|
// ? ?
|
|
|
|
|
public async positionAll() { |
|
|
|
|
try { |
|
|
|
|
const SQL = `SELECT * FROM user_position WHERE is_delete != 1`; |
|
|
|
|
const [rows] = await this.database.DB.execute(SQL, []); |
|
|
|
|
const creatorList = {}; |
|
|
|
|
for (const i of rows) { |
|
|
|
|
if (!creatorList[i.creator]) { |
|
|
|
|
// 获取创建角色用户信息
|
|
|
|
|
const getUserDataSQL = `SELECT nickname FROM user_info_extra WHERE uuid = ?`; |
|
|
|
|
const [rows2] = await this.database.DB.execute( |
|
|
|
|
getUserDataSQL, |
|
|
|
|
[i.creator], |
|
|
|
|
); |
|
|
|
|
creatorList[i.creator] = rows2.slice(-1)[0]; |
|
|
|
|
} |
|
|
|
|
i.creatorData = creatorList[i.creator]; |
|
|
|
|
} |
|
|
|
|
return { |
|
|
|
|
data: rows, |
|
|
|
|
}; |
|
|
|
|
} catch (e) { |
|
|
|
|
const message = '获取角色定位信息失败!'; |
|
|
|
|
this.logger.error({ |
|
|
|
|
message, |
|
|
|
|
data: e, |
|
|
|
|
}); |
|
|
|
|
return { |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
data: {}, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ? ?
|
|
|
|
|
// ? 函数名称: positionDelete
|
|
|
|
|
// ? 函数描述: 删除指定角色信息
|
|
|
|
|
// ? ?
|
|
|
|
|
public async positionDelete(body: PositionDeleteDTO) { |
|
|
|
|
const { id } = body; |
|
|
|
|
const deleteSQL = `UPDATE user_position SET is_delete = 1 WHERE id = ?;`; |
|
|
|
|
const successList = [], |
|
|
|
|
errorList = [], |
|
|
|
|
errorObj = []; |
|
|
|
|
for (const item of id) { |
|
|
|
|
try { |
|
|
|
|
const [row] = await this.database.DB.execute(deleteSQL, [item]); |
|
|
|
|
successList.push(item); |
|
|
|
|
} catch (e) { |
|
|
|
|
errorObj.push(e); |
|
|
|
|
errorList.push(item); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (errorList.length > 0) { |
|
|
|
|
this.logger.error({ |
|
|
|
|
message: '删除角色定位失败!', |
|
|
|
|
data: errorObj, |
|
|
|
|
}); |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message: '删除角色定位失败!', |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message: '删除角色定位成功!', |
|
|
|
|
success: true, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ? ?
|
|
|
|
|
// ? 函数名称: positionUpdate
|
|
|
|
|
// ? 函数描述: 更新指定定位角色信息
|
|
|
|
|
// ? ?
|
|
|
|
|
public async positionUpdate(body: PositionUpdateDTO) { |
|
|
|
|
// 去除空格,小写标识位
|
|
|
|
|
const id = body.id, |
|
|
|
|
type = body.type.trim(), |
|
|
|
|
name = body.name.trim(), |
|
|
|
|
pointer = body.pointer.trim().toLowerCase(), |
|
|
|
|
describe = body.describe.trim(), |
|
|
|
|
ico = body.ico.trim(); |
|
|
|
|
// ! 查父id
|
|
|
|
|
let fatherid: number; |
|
|
|
|
try { |
|
|
|
|
const SQL = `SELECT fatherid FROM user_position WHERE id = ? AND is_delete != 1`; |
|
|
|
|
const [rows, fault] = await this.database.DB.execute(SQL, [id]); |
|
|
|
|
if (rows.length == 0) { |
|
|
|
|
const message = '未找到该角色定位!'; |
|
|
|
|
return { |
|
|
|
|
message, |
|
|
|
|
data: {}, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} else { |
|
|
|
|
fatherid = rows[0].fatherid; |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
this.logger.error({ |
|
|
|
|
message: '查找角色父ID失败!', |
|
|
|
|
data: e, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const message = '查找角色父ID失败!'; |
|
|
|
|
return { |
|
|
|
|
message, |
|
|
|
|
data: {}, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
// ! 查重名和标识
|
|
|
|
|
try { |
|
|
|
|
const checkPointerSQL = `SELECT pointer FROM user_position WHERE pointer = ? AND id != ? AND is_delete != 1`; |
|
|
|
|
const [rows, fault] = await this.database.DB.execute( |
|
|
|
|
checkPointerSQL, |
|
|
|
|
[pointer, id], |
|
|
|
|
); |
|
|
|
|
if (rows.length != 0) { |
|
|
|
|
const message = '角色定位标识重复!'; |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
const message = '查冲角色定位标识失败!'; |
|
|
|
|
this.logger.error({ |
|
|
|
|
data: e, |
|
|
|
|
message, |
|
|
|
|
}); |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
const checkNameSQL = `SELECT name FROM user_position WHERE name=? AND fatherid = ? AND id != ? AND is_delete != 1`; |
|
|
|
|
const [rows, fault] = await this.database.DB.execute(checkNameSQL, [ |
|
|
|
|
name, |
|
|
|
|
fatherid, |
|
|
|
|
id, |
|
|
|
|
]); |
|
|
|
|
if (rows.length != 0) { |
|
|
|
|
const message = '角色名称重复!'; |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
const message = '查冲角色名称失败!'; |
|
|
|
|
this.logger.error({ |
|
|
|
|
data: e, |
|
|
|
|
message, |
|
|
|
|
}); |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
// ! 写入
|
|
|
|
|
try { |
|
|
|
|
const SQL = |
|
|
|
|
'UPDATE user_position SET name = ?, pointer = ?, type = ?, position_describe = ?, ico = ? WHERE id = ?'; |
|
|
|
|
const [rows, fault] = await this.database.DB.execute(SQL, [ |
|
|
|
|
name, |
|
|
|
|
pointer, |
|
|
|
|
type, |
|
|
|
|
describe, |
|
|
|
|
ico, |
|
|
|
|
id, |
|
|
|
|
]); |
|
|
|
|
} catch (e) { |
|
|
|
|
const message = '更新角色定位信息失败!'; |
|
|
|
|
this.logger.info({ |
|
|
|
|
message, |
|
|
|
|
data: e, |
|
|
|
|
}); |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
success: false, |
|
|
|
|
message, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
return { |
|
|
|
|
message: '修改角色定位信息成功!', |
|
|
|
|
success: true, |
|
|
|
|
data: {}, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ? ?
|
|
|
|
|
// ? 函数名称: positionDefault
|
|
|
|
|
// ? 函数描述: 设置默认角色
|
|
|
|
|
// ? ?
|
|
|
|
|
public async positionDefault(body: PositionListDTO) { |
|
|
|
|
// ! 清空默认设置
|
|
|
|
|
try { |
|
|
|
|
const clearSQL = `UPDATE user_position SET default_position = 0;`; |
|
|
|
|
const [rows, fault] = await this.database.DB.execute(clearSQL, []); |
|
|
|
|
} catch (e) { |
|
|
|
|
const message = '清空默认角色失败!'; |
|
|
|
|
this.logger.info({ |
|
|
|
|
data: e, |
|
|
|
|
message, |
|
|
|
|
}); |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
// ! 设置新的默认角色
|
|
|
|
|
const setDefaultSQL = `UPDATE user_position SET default_position = 1 WHERE id = ?;`; |
|
|
|
|
const successList = [], |
|
|
|
|
errorList = [], |
|
|
|
|
errObj = [[]]; |
|
|
|
|
for (const item of body.positionId) { |
|
|
|
|
try { |
|
|
|
|
const [rows, fault] = await this.database.DB.execute( |
|
|
|
|
setDefaultSQL, |
|
|
|
|
[item], |
|
|
|
|
); |
|
|
|
|
successList.push(item); |
|
|
|
|
} catch (e) { |
|
|
|
|
errorList.push(item); |
|
|
|
|
errObj.push(e); |
|
|
|
|
const message = '设置默认角色失败!'; |
|
|
|
|
this.logger.info({ |
|
|
|
|
data: errObj, |
|
|
|
|
message, |
|
|
|
|
}); |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
success: true, |
|
|
|
|
message: '设置默认角色成功!', |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ? ?
|
|
|
|
|
// ? 函数名称: getDefaultPosittion
|
|
|
|
|
// ? 函数描述: 获取默认角色
|
|
|
|
|
// ? ?
|
|
|
|
|
public async getDefaultPosition() { |
|
|
|
|
try { |
|
|
|
|
const SQL = `SELECT * FROM user_position WHERE default_position = 1 AND is_delete != 1`; |
|
|
|
|
const [rows, fault] = await this.database.DB.execute(SQL, []); |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
data: rows, |
|
|
|
|
message: '获取默认角色信息成功!', |
|
|
|
|
success: true, |
|
|
|
|
}; |
|
|
|
|
} catch (e) { |
|
|
|
|
const message = '获取默认角色信息失败'; |
|
|
|
|
this.logger.error({ |
|
|
|
|
data: e, |
|
|
|
|
message, |
|
|
|
|
}); |
|
|
|
|
return { |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
data: {}, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ? ?
|
|
|
|
|
// ? 函数名称: positionRelationUUID
|
|
|
|
|
// ? 函数描述: 关联用户角色定位
|
|
|
|
|
// ? ?
|
|
|
|
|
public async positionRelationUUID(body: PositionRelationDTO) { |
|
|
|
|
// ! 剔除不存在的用户
|
|
|
|
|
|
|
|
|
|
// ! 删除原有的用户角色定位关联
|
|
|
|
|
const clearSQL = `UPDATE user_position_relation SET is_delete = 1 WHERE uuid = ?`; |
|
|
|
|
for (const item of body.uuidList) { |
|
|
|
|
try { |
|
|
|
|
const [rows, fault] = await this.database.DB.execute(clearSQL, [ |
|
|
|
|
item, |
|
|
|
|
]); |
|
|
|
|
} catch (e) { |
|
|
|
|
const message = 'ERROR,重大错误,清除用户角色关联失败。'; |
|
|
|
|
this.logger.info({ |
|
|
|
|
message, |
|
|
|
|
data: e, |
|
|
|
|
}); |
|
|
|
|
return { |
|
|
|
|
data: e, |
|
|
|
|
success: false, |
|
|
|
|
message, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// ! 遍历加入新的角色定位关联
|
|
|
|
|
const createTime = new Date(); |
|
|
|
|
const insertSQL = `INSERT INTO user_position_relation (uuid, position_id, createtime) VALUES ?;`; |
|
|
|
|
for (const item of body.uuidList) { |
|
|
|
|
try { |
|
|
|
|
const insertData = body.positionId.map((i) => [ |
|
|
|
|
item, |
|
|
|
|
i, |
|
|
|
|
createTime, |
|
|
|
|
]); |
|
|
|
|
this.logger.info(insertData); |
|
|
|
|
const [rows, faault] = await this.database.DB.query(insertSQL, [ |
|
|
|
|
insertData, |
|
|
|
|
]); |
|
|
|
|
} catch (e) { |
|
|
|
|
const message = 'ERROR,重大错误,关联用户角色定位信息失败!'; |
|
|
|
|
this.logger.info({ |
|
|
|
|
data: e, |
|
|
|
|
message, |
|
|
|
|
}); |
|
|
|
|
return { |
|
|
|
|
data: e, |
|
|
|
|
message, |
|
|
|
|
success: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return { |
|
|
|
|
data: {}, |
|
|
|
|
success: true, |
|
|
|
|
message: '关联用户角色定位成功!', |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
|