|
@@ -23,15 +23,19 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
async saveAudits(pid, accountList, transaction = null) {
|
|
|
+ // 判断是否已存在该用户,存在则不插入
|
|
|
+ const pauditList = await this.getAllDataByCondition({ where: { pid } });
|
|
|
const pushData = [];
|
|
|
- for (const a of accountList) {
|
|
|
- const data = {
|
|
|
- pid,
|
|
|
- groupid: a.account_group,
|
|
|
- uid: a.id,
|
|
|
- create_time: new Date(),
|
|
|
- };
|
|
|
- pushData.push(data);
|
|
|
+ for (const a of this._.uniqBy(accountList, 'id')) {
|
|
|
+ if (this._.findIndex(pauditList, { uid: a.id }) === -1) {
|
|
|
+ const data = {
|
|
|
+ pid,
|
|
|
+ groupid: a.account_group,
|
|
|
+ uid: a.id,
|
|
|
+ create_time: new Date(),
|
|
|
+ };
|
|
|
+ pushData.push(data);
|
|
|
+ }
|
|
|
}
|
|
|
if (pushData.length > 0) {
|
|
|
return transaction ? await transaction.insert(this.tableName, pushData) : await this.db.insert(this.tableName, pushData);
|