明树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
9d7324e3
Commit
9d7324e3
authored
Dec 01, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
99a08ce9
Pipeline
#103959
passed with stage
in 3 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
117 deletions
+65
-117
a.js
a.js
+38
-111
resourceController.js
controller/resourceController.js
+7
-4
userController.js
controller/userController.js
+0
-1
user.js
db/model/system/user.js
+0
-1
index.js
utils/index.js
+20
-0
No files found.
a.js
View file @
9d7324e3
const
_
=
require
(
'lodash'
);
let
a
=
[
{
xjlr
:
100
,
xjlc
:
200
,
sdsqjxjll
:
300
,
tzsds
:
400
,
sdshjxjll
:
500
,
year
:
"合计"
,
},
{
xjlr
:
100
,
xjlc
:
200
,
sdsqjxjll
:
300
,
tzsds
:
400
,
sdshjxjll
:
500
,
year
:
2022
,
},
{
xjlr
:
101
,
xjlc
:
201
,
sdsqjxjll
:
301
,
tzsds
:
401
,
sdshjxjll
:
501
,
year
:
2023
,
},
{
xjlr
:
1003
,
xjlc
:
2003
,
sdsqjxjll
:
3003
,
tzsds
:
4003
,
sdshjxjll
:
5003
,
year
:
"2024"
,
},
{
xjlr
:
1004
,
xjlc
:
2004
,
sdsqjxjll
:
3004
,
tzsds
:
4004
,
sdshjxjll
:
5004
,
year
:
"2025"
,
}
]
const
b
=
_
.
sortBy
(
a
,
'year'
);
console
.
log
(
b
);
function
thvc
(
a
)
{
let
xjlr
=
[],
xjlc
=
[],
sdsqjxjll
=
[],
tzsds
=
[],
sdshjxjll
=
[];
let
retArr
=
[];
for
(
let
index
=
0
;
index
<
a
.
length
;
index
++
)
{
const
element
=
a
[
index
];
xjlr
.
push
(
element
.
xjlr
);
xjlc
.
push
(
element
.
xjlc
);
sdsqjxjll
.
push
(
element
.
sdsqjxjll
);
tzsds
.
push
(
element
.
tzsds
);
sdshjxjll
.
push
(
element
.
sdshjxjll
);
// year.push(element.year);
}
return
[
xjlr
,
xjlc
,
sdsqjxjll
,
tzsds
,
sdshjxjll
];
}
console
.
log
(
thvc
(
a
));
function
cvht
(
obj
)
{
for
(
const
key
in
obj
)
{
const
element
=
obj
[
key
];
}
}
function
reverseTransform
(
transformedData
)
{
// 获取第一个字段的数组长度作为对象数量
const
field
=
Object
.
keys
(
transformedData
)[
0
];
const
itemCount
=
transformedData
[
field
].
length
;
function
flattenTreeIterative
(
forest
)
{
const
result
=
[];
const
stack
=
[...
forest
.
map
(
node
=>
({
node
,
parentId
:
null
}))];
// 遍历每个索引位置构建对象
for
(
let
i
=
0
;
i
<
itemCount
;
i
++
)
{
const
item
=
{}
;
while
(
stack
.
length
)
{
const
{
node
,
parentId
}
=
stack
.
pop
();
const
{
chilrden
,
children
,
...
rest
}
=
node
;
// 为每个字段赋值
for
(
const
key
in
transformedData
)
{
if
(
transformedData
.
hasOwnProperty
(
key
))
{
item
[
key
]
=
transformedData
[
key
][
i
];
}
}
result
.
push
({
...
rest
,
parentId
});
result
.
push
(
item
);
const
kids
=
chilrden
||
children
||
[];
for
(
let
i
=
kids
.
length
-
1
;
i
>=
0
;
i
--
)
{
stack
.
push
({
node
:
kids
[
i
],
parentId
:
node
.
id
});
}
}
return
result
;
}
// 使用示例
const
transformed
=
{
xjlr
:
[
100
,
100
,
101
,
1003
,
1004
],
xjlc
:
[
200
,
200
,
201
,
2003
,
2004
],
sdsqjxjll
:
[
300
,
300
,
301
,
3003
,
3004
],
tzsds
:
[
400
,
400
,
401
,
4003
,
4004
],
sdshjxjll
:
[
500
,
500
,
501
,
5003
,
5004
]
};
// console.log(reverseTransform(transformed));
// console.log(thvc(a));
// {
// xh: String,
// sjx: String,
// }
// {
// year: []
// }
\ No newline at end of file
// 扩展测试:包含额外字段和标准children字段
const
complexForest
=
[
{
id
:
'A'
,
name
:
'Root A'
,
chilrden
:
[
{
id
:
'A1'
,
value
:
100
},
{
id
:
'A2'
,
value
:
200
,
children
:
[{
id
:
'A2a'
}]
}
]
},
{
id
:
'B'
,
name
:
'Root B'
,
children
:
[{
id
:
'B1'
}]
}
];
console
.
log
(
flattenTreeIterative
(
complexForest
));
/* 输出:
[
{ id: 'A', name: 'Root A', parentId: null },
{ id: 'A1', value: 100, parentId: 'A' },
{ id: 'A2', value: 200, parentId: 'A' },
{ id: 'A2a', parentId: 'A2' },
{ id: 'B', name: 'Root B', parentId: null },
{ id: 'B1', parentId: 'B' }
]
*/
\ No newline at end of file
controller/resourceController.js
View file @
9d7324e3
...
...
@@ -158,7 +158,13 @@ async function listResourceInfo(req, res, next) {
}
};
/**
* 这个接口有点问题,只能处理平行数据,数据
* @param {*} req
* @param {*} res
* @param {*} next
* @returns
*/
async
function
saveAllResourceInfo
(
req
,
res
,
next
)
{
try
{
let
{
resourceId
,
data
=
[]
}
=
req
.
body
;
...
...
@@ -175,9 +181,6 @@ async function saveAllResourceInfo(req, res, next) {
if
(
!
resource
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
if
(
resource
&&
resource
.
type
==
2
)
{
data
=
utils
.
disTree
(
data
)
}
let
toCreate
=
[],
toKeep
=
[];
if
(
data
.
length
)
{
for
(
let
index
=
0
;
index
<
data
.
length
;
index
++
)
{
...
...
controller/userController.js
View file @
9d7324e3
...
...
@@ -104,7 +104,6 @@ async function createUser(req, res, next) {
const
{
salt
,
passwordHash
}
=
utils
.
saltHashPassword
(
req
.
body
.
password
);
body
.
salt
=
salt
;
body
.
password
=
passwordHash
;
const
ret
=
await
DB
.
User
.
create
(
body
);
if
(
!
(
ret
&&
ret
.
id
))
{
return
res
.
sendError
(
errorMessage
.
databaseQueryError
);
...
...
db/model/system/user.js
View file @
9d7324e3
...
...
@@ -13,7 +13,6 @@ const User = sequelize.define('User', {
mobile
:
{
type
:
DataTypes
.
STRING
(
11
),
allowNull
:
false
,
unique
:
true
,
},
password
:
{
type
:
DataTypes
.
STRING
(
200
),
...
...
utils/index.js
View file @
9d7324e3
...
...
@@ -66,6 +66,26 @@ function disTree(tree) {
return
parallel
}
// 迭代替代递归(万级以上节点)
function
flattenTreeIterative
(
forest
)
{
const
result
=
[];
const
stack
=
[...
forest
.
map
(
node
=>
({
node
,
parentId
:
null
}))];
while
(
stack
.
length
)
{
const
{
node
,
parentId
}
=
stack
.
pop
();
const
{
chilrden
,
children
,
...
rest
}
=
node
;
result
.
push
({
...
rest
,
parentId
});
const
kids
=
chilrden
||
children
||
[];
for
(
let
i
=
kids
.
length
-
1
;
i
>=
0
;
i
--
)
{
stack
.
push
({
node
:
kids
[
i
],
parentId
:
node
.
id
});
}
}
return
result
;
}
function
genTracSourceCode
({
EnterpriseCode
,
type
,
date
,
batchNum
,
logisticsNum
})
{
// 企业代码(9) MA4W271Y8 + 产品代码【种植、初加工、深加工】(6)+ 生产/出厂日期(8)) + 批次号(8)+ 物流码 + 校验码(8)
//MA4W271Y8
...
...
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