|
@@ -1,15 +1,17 @@
|
|
import {IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
|
|
import {IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
|
|
import {AcsUserInfo} from "@core-models/AcsUserInfo";
|
|
import {AcsUserInfo} from "@core-models/AcsUserInfo";
|
|
-import {Op, Sequelize} from "sequelize";
|
|
|
|
|
|
+import {QueryTypes} from "sequelize";
|
|
import {Resp} from "@util/Resp";
|
|
import {Resp} from "@util/Resp";
|
|
import DataCURD from "@core/DataCURD";
|
|
import DataCURD from "@core/DataCURD";
|
|
import {AcsUserDomain} from "@core-models/AcsUserDomain";
|
|
import {AcsUserDomain} from "@core-models/AcsUserDomain";
|
|
import {AcsUserRole} from "@core-models/AcsUserRole";
|
|
import {AcsUserRole} from "@core-models/AcsUserRole";
|
|
|
|
+import {AcsDomain} from "@core-models/AcsDomain";
|
|
|
|
+
|
|
interface IData {
|
|
interface IData {
|
|
/**
|
|
/**
|
|
* 部门id
|
|
* 部门id
|
|
*/
|
|
*/
|
|
- domain_id?: number;
|
|
|
|
|
|
+ domain_ids?: number[];
|
|
/**
|
|
/**
|
|
* 邮箱号
|
|
* 邮箱号
|
|
*/
|
|
*/
|
|
@@ -39,16 +41,15 @@ interface IData {
|
|
*/
|
|
*/
|
|
pass?: string;
|
|
pass?: string;
|
|
/**
|
|
/**
|
|
- * 角色id
|
|
|
|
|
|
+ * 职位id
|
|
*/
|
|
*/
|
|
- role_id?: string;
|
|
|
|
|
|
+ role_ids?: string[];
|
|
/**
|
|
/**
|
|
* 状态,0=锁定,1=正常
|
|
* 状态,0=锁定,1=正常
|
|
*/
|
|
*/
|
|
status?: number;
|
|
status?: number;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
function get_where(json: IRequest, _params: IMethodParams, _cached_data: ICachedData): Promise<any> {
|
|
function get_where(json: IRequest, _params: IMethodParams, _cached_data: ICachedData): Promise<any> {
|
|
return new Promise<any>(async (resolve, reject) => {
|
|
return new Promise<any>(async (resolve, reject) => {
|
|
try {
|
|
try {
|
|
@@ -67,10 +68,10 @@ function modify(json: IRequest, params: IMethodParams, cached_data: ICachedData)
|
|
let data = <IData>json.data;
|
|
let data = <IData>json.data;
|
|
let staff = await AcsUserInfo.findOne({where:{id: data.id}, transaction: t});
|
|
let staff = await AcsUserInfo.findOne({where:{id: data.id}, transaction: t});
|
|
if (!staff) throw Resp.gen_err(Resp.ResourceNotFound);
|
|
if (!staff) throw Resp.gen_err(Resp.ResourceNotFound);
|
|
- data.name? staff.name = data.name : null;
|
|
|
|
- data.memo? staff.memo = data.memo: null;
|
|
|
|
- data.email? staff.email = data.email: null;
|
|
|
|
- data.pass? staff.pass =data.pass: null;
|
|
|
|
|
|
+ // data.name? staff.name = data.name : null;
|
|
|
|
+ // data.memo? staff.memo = data.memo: null;
|
|
|
|
+ // data.email? staff.email = data.email: null;
|
|
|
|
+ // data.pass? staff.pass =data.pass: null;
|
|
|
|
|
|
|
|
|
|
let ext_info: any = {
|
|
let ext_info: any = {
|
|
@@ -78,20 +79,32 @@ function modify(json: IRequest, params: IMethodParams, cached_data: ICachedData)
|
|
level: data.level,
|
|
level: data.level,
|
|
}
|
|
}
|
|
ext_info = DataCURD.filter_null(ext_info);
|
|
ext_info = DataCURD.filter_null(ext_info);
|
|
- staff.ext_info = {
|
|
|
|
|
|
+ ext_info = {
|
|
...staff.ext_info,
|
|
...staff.ext_info,
|
|
...ext_info
|
|
...ext_info
|
|
}
|
|
}
|
|
- if (data.role_id) {
|
|
|
|
- await AcsUserRole.upsert({
|
|
|
|
- user_id: data.id,
|
|
|
|
- role_id: data.role_id
|
|
|
|
- }, {transaction: t, returning: false})
|
|
|
|
|
|
+ await AcsUserInfo.update({...staff, ...data, ext_info: ext_info}, {where: {id: data.id}, transaction: t, returning: false});
|
|
|
|
+ if (data.role_ids) {
|
|
|
|
+ await AcsUserRole.destroy({where: {user_id: data.id}, transaction: t});
|
|
|
|
+ for (let role_id of data.role_ids) {
|
|
|
|
+ await AcsUserRole.create({
|
|
|
|
+ user_id: data.id,
|
|
|
|
+ role_id: role_id
|
|
|
|
+ }, {transaction: t, returning: false})
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- await staff.save({transaction: t});
|
|
|
|
- if (data.domain_id !== undefined) {
|
|
|
|
- await AcsUserDomain.update({domain_id: data.domain_id}, {where: {user_id: data.id}, transaction: t, returning: []});
|
|
|
|
|
|
+ //await staff.save({transaction: t});
|
|
|
|
+ if (data.domain_ids !== undefined) {
|
|
|
|
+ await AcsUserDomain.sequelize!.query(`
|
|
|
|
+ delete from ${AcsUserDomain.tableName} where user_id = :user_id and domain_id in (select id from ${AcsDomain.tableName} where category='org')
|
|
|
|
+ `, {type: QueryTypes.DELETE, transaction: t});
|
|
|
|
+ for (let domain_id of data.domain_ids) {
|
|
|
|
+ await AcsUserDomain.create({user_id: data.id, domain_id: domain_id}, {
|
|
|
|
+ transaction: t,
|
|
|
|
+ returning: false
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
await t.commit();
|
|
await t.commit();
|
|
@@ -127,10 +140,6 @@ const v1_0: IApiProcessor = {
|
|
"type": "string",
|
|
"type": "string",
|
|
"title": "备注"
|
|
"title": "备注"
|
|
},
|
|
},
|
|
- "domain_id": {
|
|
|
|
- "type": "integer",
|
|
|
|
- "title": "部门id"
|
|
|
|
- },
|
|
|
|
"status": {
|
|
"status": {
|
|
"type": "integer",
|
|
"type": "integer",
|
|
"title": "状态",
|
|
"title": "状态",
|
|
@@ -150,9 +159,19 @@ const v1_0: IApiProcessor = {
|
|
"type": "integer",
|
|
"type": "integer",
|
|
"title": "级别"
|
|
"title": "级别"
|
|
},
|
|
},
|
|
- "role_id": {
|
|
|
|
- "type": "string",
|
|
|
|
- "title": "角色id"
|
|
|
|
|
|
+ "domain_ids": {
|
|
|
|
+ "type": "array",
|
|
|
|
+ "items": {
|
|
|
|
+ "type": "integer"
|
|
|
|
+ },
|
|
|
|
+ "title": "部门id"
|
|
|
|
+ },
|
|
|
|
+ "role_ids": {
|
|
|
|
+ "type": "array",
|
|
|
|
+ "items": {
|
|
|
|
+ "type": "string"
|
|
|
|
+ },
|
|
|
|
+ "title": "职位id"
|
|
}
|
|
}
|
|
},
|
|
},
|
|
"x-apifox-orders": [
|
|
"x-apifox-orders": [
|
|
@@ -160,12 +179,12 @@ const v1_0: IApiProcessor = {
|
|
"name",
|
|
"name",
|
|
"email",
|
|
"email",
|
|
"memo",
|
|
"memo",
|
|
- "domain_id",
|
|
|
|
|
|
+ "role_ids",
|
|
|
|
+ "domain_ids",
|
|
"status",
|
|
"status",
|
|
"pass",
|
|
"pass",
|
|
"full_range",
|
|
"full_range",
|
|
- "level",
|
|
|
|
- "role_id"
|
|
|
|
|
|
+ "level"
|
|
],
|
|
],
|
|
"required": [
|
|
"required": [
|
|
"id"
|
|
"id"
|
|
@@ -188,7 +207,7 @@ const v1_0: IApiProcessor = {
|
|
},
|
|
},
|
|
{
|
|
{
|
|
"required": [
|
|
"required": [
|
|
- "domain_id"
|
|
|
|
|
|
+ "domain_ids"
|
|
]
|
|
]
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -213,7 +232,7 @@ const v1_0: IApiProcessor = {
|
|
},
|
|
},
|
|
{
|
|
{
|
|
"required": [
|
|
"required": [
|
|
- "role_id"
|
|
|
|
|
|
+ "role_ids"
|
|
]
|
|
]
|
|
}
|
|
}
|
|
],
|
|
],
|