明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jt_backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengfanpei
jt_backend
Commits
436b3d6b
Commit
436b3d6b
authored
Nov 26, 2025
by
zhangqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add saveAllResourceInfo
parent
87c890bf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
1 deletion
+105
-1
resourceController.js
controller/resourceController.js
+102
-1
resourceRouter.js
router/resourceRouter.js
+3
-0
No files found.
controller/resourceController.js
View file @
436b3d6b
...
@@ -170,6 +170,105 @@ async function listResourceInfo(req, res, next) {
...
@@ -170,6 +170,105 @@ async function listResourceInfo(req, res, next) {
}
}
};
};
async
function
saveAllResourceInfo
(
req
,
res
,
next
)
{
try
{
const
{
resourceId
,
data
=
[]
}
=
req
.
body
;
if
(
!
resourceId
||
!
Array
.
isArray
(
data
))
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
const
resource
=
await
DB
.
Resources
.
findOne
({
where
:
{
id
:
resourceId
},
raw
:
true
});
if
(
!
resource
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
if
(
resource
.
type
===
1
)
{
const
existingRecords
=
await
DB
.
ResourcesInfo
.
findAll
({
where
:
{
del
:
0
,
resourceId
:
resourceId
},
// ← 关键修复!
raw
:
true
});
console
.
log
(
"existingRecords"
,
existingRecords
);
const
existMap
=
new
Map
();
existingRecords
.
forEach
(
r
=>
existMap
.
set
(
r
.
id
,
r
));
const
toCreate
=
[];
const
toUpdate
=
[];
const
incomingIds
=
new
Set
();
for
(
const
item
of
data
)
{
if
(
item
.
resourceId
!=
resourceId
)
{
// ← 正确写法
console
.
log
(
item
.
value
,
"不属于当前资源,跳过"
);
continue
;
}
console
.
log
(
"每条aaa记录"
,
item
);
const
record
=
{
...
item
,
resourceId
:
Number
(
resourceId
),
del
:
0
};
if
(
item
.
id
!=
null
&&
existMap
.
has
(
item
.
id
))
{
toUpdate
.
push
(
record
);
incomingIds
.
add
(
item
.
id
);
}
else
{
toCreate
.
push
(
record
);
}
}
const
toDeleteIds
=
existingRecords
.
filter
(
r
=>
!
incomingIds
.
has
(
r
.
id
))
.
map
(
r
=>
r
.
id
);
console
.
log
(
'本次新增:'
,
toCreate
.
length
);
console
.
log
(
'本次更新:'
,
toUpdate
.
length
);
console
.
log
(
'本次软删:'
,
toDeleteIds
);
if
(
toCreate
.
length
>
0
)
{
await
DB
.
ResourcesInfo
.
bulkCreate
(
toCreate
);
}
if
(
toUpdate
.
length
>
0
)
{
for
(
const
item
of
toUpdate
)
{
await
DB
.
ResourcesInfo
.
update
(
item
,
{
where
:
{
id
:
item
.
id
}
});
}
}
if
(
toDeleteIds
.
length
>
0
)
{
await
DB
.
ResourcesInfo
.
update
(
{
del
:
1
},
{
where
:
{
id
:
toDeleteIds
}
}
);
}
const
ret
=
await
DB
.
ResourcesInfo
.
findAll
({
where
:
{
del
:
0
,
resourceId
:
resourceId
},
raw
:
true
});
return
res
.
sendData
(
ret
);
}
return
res
.
sendData
([]);
}
catch
(
error
)
{
console
.
error
(
'saveAllResourceInfo error:'
,
error
);
next
(
error
);
}
}
module
.
exports
=
{
module
.
exports
=
{
createResource
,
createResource
,
updateResource
,
updateResource
,
...
@@ -179,5 +278,7 @@ module.exports = {
...
@@ -179,5 +278,7 @@ module.exports = {
createResourceInfo
,
createResourceInfo
,
updateResourceInfo
,
updateResourceInfo
,
deleteResourceInfo
,
deleteResourceInfo
,
listResourceInfo
listResourceInfo
,
saveAllResourceInfo
}
}
\ No newline at end of file
router/resourceRouter.js
View file @
436b3d6b
...
@@ -22,4 +22,7 @@ router.post('/deleteResourceInfo', resourceController.deleteResourceInfo);
...
@@ -22,4 +22,7 @@ router.post('/deleteResourceInfo', resourceController.deleteResourceInfo);
router
.
post
(
'/updateResourceInfo'
,
resourceController
.
updateResourceInfo
);
router
.
post
(
'/updateResourceInfo'
,
resourceController
.
updateResourceInfo
);
router
.
post
(
'/listResourceInfo'
,
resourceController
.
listResourceInfo
);
router
.
post
(
'/listResourceInfo'
,
resourceController
.
listResourceInfo
);
router
.
post
(
'/saveAllResourceInfo'
,
resourceController
.
saveAllResourceInfo
);
module
.
exports
=
router
;
module
.
exports
=
router
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment