明树Git Lab

Commit 9d7324e3 authored by zfp1's avatar zfp1

update

parent 99a08ce9
Pipeline #103959 passed with stage
in 3 seconds
const _ = require('lodash'); function flattenTreeIterative(forest) {
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;
const result = []; const result = [];
const stack = [...forest.map(node => ({ node, parentId: null }))];
// 遍历每个索引位置构建对象 while (stack.length) {
for (let i = 0; i < itemCount; i++) { const { node, parentId } = stack.pop();
const item = {}; const { chilrden, children, ...rest } = node;
// 为每个字段赋值 result.push({ ...rest, parentId });
for (const key in transformedData) {
if (transformedData.hasOwnProperty(key)) {
item[key] = transformedData[key][i];
}
}
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; return result;
} }
// 使用示例 // 扩展测试:包含额外字段和标准children字段
const transformed = { const complexForest = [
xjlr: [100, 100, 101, 1003, 1004], {
xjlc: [200, 200, 201, 2003, 2004], id: 'A',
sdsqjxjll: [300, 300, 301, 3003, 3004], name: 'Root A',
tzsds: [400, 400, 401, 4003, 4004], chilrden: [
sdshjxjll: [500, 500, 501, 5003, 5004] { id: 'A1', value: 100 },
}; { id: 'A2', value: 200, children: [{ id: 'A2a' }] }
]
// console.log(reverseTransform(transformed)); },
{
// console.log(thvc(a)); id: 'B',
name: 'Root B',
children: [{ id: 'B1' }]
// { }
// xh: String, ];
// sjx: String,
console.log(flattenTreeIterative(complexForest));
// } /* 输出:
// { [
// year: [] { id: 'A', name: 'Root A', parentId: null },
// } { id: 'A1', value: 100, parentId: 'A' },
\ No newline at end of file { 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
...@@ -158,7 +158,13 @@ async function listResourceInfo(req, res, next) { ...@@ -158,7 +158,13 @@ async function listResourceInfo(req, res, next) {
} }
}; };
/**
* 这个接口有点问题,只能处理平行数据,数据
* @param {*} req
* @param {*} res
* @param {*} next
* @returns
*/
async function saveAllResourceInfo(req, res, next) { async function saveAllResourceInfo(req, res, next) {
try { try {
let { resourceId, data = [] } = req.body; let { resourceId, data = [] } = req.body;
...@@ -175,9 +181,6 @@ async function saveAllResourceInfo(req, res, next) { ...@@ -175,9 +181,6 @@ async function saveAllResourceInfo(req, res, next) {
if (!resource) { if (!resource) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
if (resource && resource.type == 2) {
data = utils.disTree(data)
}
let toCreate = [], toKeep = []; let toCreate = [], toKeep = [];
if (data.length) { if (data.length) {
for (let index = 0; index < data.length; index++) { for (let index = 0; index < data.length; index++) {
......
...@@ -104,7 +104,6 @@ async function createUser(req, res, next) { ...@@ -104,7 +104,6 @@ async function createUser(req, res, next) {
const { salt, passwordHash } = utils.saltHashPassword(req.body.password); const { salt, passwordHash } = utils.saltHashPassword(req.body.password);
body.salt = salt; body.salt = salt;
body.password = passwordHash; body.password = passwordHash;
const ret = await DB.User.create(body); const ret = await DB.User.create(body);
if (!(ret && ret.id)) { if (!(ret && ret.id)) {
return res.sendError(errorMessage.databaseQueryError); return res.sendError(errorMessage.databaseQueryError);
......
...@@ -13,7 +13,6 @@ const User = sequelize.define('User', { ...@@ -13,7 +13,6 @@ const User = sequelize.define('User', {
mobile: { mobile: {
type: DataTypes.STRING(11), type: DataTypes.STRING(11),
allowNull: false, allowNull: false,
unique: true,
}, },
password: { password: {
type: DataTypes.STRING(200), type: DataTypes.STRING(200),
......
...@@ -66,6 +66,26 @@ function disTree(tree) { ...@@ -66,6 +66,26 @@ function disTree(tree) {
return parallel 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}) { function genTracSourceCode({EnterpriseCode, type, date, batchNum, logisticsNum}) {
// 企业代码(9) MA4W271Y8 + 产品代码【种植、初加工、深加工】(6)+ 生产/出厂日期(8)) + 批次号(8)+ 物流码 + 校验码(8) // 企业代码(9) MA4W271Y8 + 产品代码【种植、初加工、深加工】(6)+ 生产/出厂日期(8)) + 批次号(8)+ 物流码 + 校验码(8)
//MA4W271Y8 //MA4W271Y8
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment