Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shouzhouServer
Overview
Overview
Details
Activity
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
chenjinjing
shouzhouServer
Commits
fb950ee3
Commit
fb950ee3
authored
Jul 18, 2024
by
Leo Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debug,修改了eventDataStrategy使其不再修改数据
parent
15340644
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
69 deletions
+63
-69
eventDataStrategy.ts
src/biz/strategies/middle/eventDataStrategy.ts
+17
-50
abstractDataStrategyRight.ts
src/biz/strategies/right/abstractDataStrategyRight.ts
+42
-12
eventSrcStrategy.ts
src/biz/strategies/right/eventSrcStrategy.ts
+2
-1
getEventCountByYearStrategy.ts
src/biz/strategies/right/getEventCountByYearStrategy.ts
+0
-5
gridEventCountStrategy.ts
src/biz/strategies/right/gridEventCountStrategy.ts
+2
-1
No files found.
src/biz/strategies/middle/eventDataStrategy.ts
View file @
fb950ee3
...
@@ -29,33 +29,9 @@ export class allEventDataStrategy extends abstractDataStrategyMid {
...
@@ -29,33 +29,9 @@ export class allEventDataStrategy extends abstractDataStrategyMid {
* @returns 事件的数据。
* @returns 事件的数据。
*/
*/
execute
():
any
{
execute
():
any
{
let
eventData
=
this
.
extractor
.
getData
(
allEventDataStrategy
.
fileName
,
allEventDataStrategy
.
sheetName
);
const
eventData
=
this
.
extractor
.
getData
(
allEventDataStrategy
.
fileName
,
allEventDataStrategy
.
sheetName
);
this
.
removeUnusedColumns
(
eventData
);
const
formattedData
=
this
.
formatDataForFrontend
(
eventData
);
return
this
.
formatDataForFrontend
(
eventData
);
return
formattedData
;
}
/**
* 移除数据中前端不使用的列
* @param data - 从数据源提取的数据
*/
private
removeUnusedColumns
(
data
:
any
)
{
data
.
forEach
(
row
=>
{
// Initialize missing relevant columns with a default value
allEventDataStrategy
.
RELEVANTINFO
.
forEach
(
key
=>
{
if
(
!
(
key
in
row
))
{
row
[
key
]
=
null
;
// You can set this to any default value you prefer
}
});
Object
.
keys
(
row
).
forEach
(
key
=>
{
if
(
!
allEventDataStrategy
.
RELEVANTINFO
.
includes
(
key
))
{
delete
row
[
key
];
}
if
(
typeof
row
[
key
]
===
'number'
)
{
row
[
key
]
=
excelSerialToJSDate
(
row
[
key
]);
}
});
});
}
}
/**
/**
...
@@ -66,19 +42,17 @@ export class allEventDataStrategy extends abstractDataStrategyMid {
...
@@ -66,19 +42,17 @@ export class allEventDataStrategy extends abstractDataStrategyMid {
private
formatDataForFrontend
(
data
:
any
):
any
{
private
formatDataForFrontend
(
data
:
any
):
any
{
return
data
.
map
(
row
=>
{
return
data
.
map
(
row
=>
{
let
formattedRow
:
{
[
key
:
string
]:
any
}
=
{};
let
formattedRow
:
{
[
key
:
string
]:
any
}
=
{};
Object
.
keys
(
row
).
forEach
(
key
=>
{
allEventDataStrategy
.
RELEVANTINFO
.
forEach
(
key
=>
{
const
translatedKey
=
allEventDataStrategy
.
KEY_MAP
[
key
];
const
translatedKey
=
allEventDataStrategy
.
KEY_MAP
[
key
];
let
value
=
row
[
key
];
let
value
=
row
[
key
];
// Format date if key is one of the date fields
// Format date if key is one of the date fields
if
([
'
creationTime'
,
'dispositionTime'
,
'dispositionCompletionTime'
,
'closureTime'
].
includes
(
translatedK
ey
)
&&
value
)
{
if
([
'
创建时间'
,
'处置时间'
,
'处置完成时间'
,
'办结时间'
].
includes
(
k
ey
)
&&
value
)
{
value
=
new
Date
(
value
).
toLocaleString
(
'zh-CN'
,
{
hour12
:
false
}).
replace
(
/
\/
/g
,
'-'
).
replace
(
','
,
''
);
value
=
new
Date
(
value
).
toLocaleString
(
'zh-CN'
,
{
hour12
:
false
}).
replace
(
/
\/
/g
,
'-'
).
replace
(
','
,
''
);
}
}
// Only add non-null values to the formatted row
formattedRow
[
translatedKey
]
=
value
!==
undefined
?
value
:
null
;
if
(
value
!==
null
)
{
formattedRow
[
translatedKey
]
=
value
;
}
});
});
// Add detail section with all time fields and their corresponding statuses
// Add detail section with all time fields and their corresponding statuses
...
@@ -94,43 +68,36 @@ export class allEventDataStrategy extends abstractDataStrategyMid {
...
@@ -94,43 +68,36 @@ export class allEventDataStrategy extends abstractDataStrategyMid {
* @returns 详细信息部分
* @returns 详细信息部分
*/
*/
private
constructDetailSection
(
row
:
{
[
key
:
string
]:
any
}):
any
{
private
constructDetailSection
(
row
:
{
[
key
:
string
]:
any
}):
any
{
const
details
:
any
=
{}
;
const
details
:
any
=
[]
;
if
(
row
.
creationTime
)
{
if
(
row
.
creationTime
)
{
details
.
creationTime
=
{
details
.
push
(
{
time
:
row
.
creationTime
,
time
:
row
.
creationTime
,
status
:
'待调度'
status
:
'待调度'
};
}
)
;
}
}
if
(
row
.
dispositionTime
)
{
if
(
row
.
dispositionTime
)
{
details
.
dispositionTime
=
{
details
.
push
(
{
time
:
row
.
dispositionTime
,
time
:
row
.
dispositionTime
,
status
:
'处置中'
status
:
'处置中'
};
}
)
;
}
}
if
(
row
.
dispositionCompletionTime
)
{
if
(
row
.
dispositionCompletionTime
)
{
details
.
dispositionCompletionTime
=
{
details
.
push
(
{
time
:
row
.
dispositionCompletionTime
,
time
:
row
.
dispositionCompletionTime
,
status
:
'已处置'
status
:
'已处置'
};
}
)
;
}
}
if
(
row
.
closureTime
)
{
if
(
row
.
closureTime
)
{
details
.
closureTime
=
{
details
.
push
(
{
time
:
row
.
closureTime
,
time
:
row
.
closureTime
,
status
:
'已办结'
status
:
'已办结'
};
}
)
;
}
}
// Remove any null detail fields
return
details
;
Object
.
keys
(
details
).
forEach
(
key
=>
{
if
(
details
[
key
].
time
===
null
)
{
delete
details
[
key
];
}
});
return
Object
.
values
(
details
);
}
}
}
}
src/biz/strategies/right/abstractDataStrategyRight.ts
View file @
fb950ee3
...
@@ -65,16 +65,13 @@ export abstract class abstractDataStrategyRight implements dataStrategy {
...
@@ -65,16 +65,13 @@ export abstract class abstractDataStrategyRight implements dataStrategy {
return
eventCount
;
return
eventCount
;
}
}
/**
* 统计事件列表中每个事件的数量。
* @param list - 事件名称列表。
* @param target - 目标事件名称。
* @param data - 数据源。
* @param year - 指定年份 ("thisyear" or "lastyear").
* @returns 事件计数映射。
*/
/**
/**
* getListCount 方法的更新版本,添加了零替换逻辑
* 统计事件列表中每个事件的数量。
* @param list - 事件名称列表。
* @param target - 目标事件名称。
* @param data - 数据源。
* @param year - 指定年份 ("thisyear" or "lastyear").
* @returns 事件计数映射。
*/
*/
protected
getListCount
(
list
:
string
[],
target
:
string
,
data
:
any
,
year
:
string
)
{
protected
getListCount
(
list
:
string
[],
target
:
string
,
data
:
any
,
year
:
string
)
{
const
currentYear
=
new
Date
().
getFullYear
();
const
currentYear
=
new
Date
().
getFullYear
();
...
@@ -86,11 +83,9 @@ protected getListCount(list: string[], target: string, data: any, year: string)
...
@@ -86,11 +83,9 @@ protected getListCount(list: string[], target: string, data: any, year: string)
let
rowDate
:
any
=
0
;
let
rowDate
:
any
=
0
;
if
(
typeof
(
row
[
'创建时间'
])
==
"number"
)
{
if
(
typeof
(
row
[
'创建时间'
])
==
"number"
)
{
rowDate
=
excelSerialToJSDate
(
row
[
'创建时间'
]);
rowDate
=
excelSerialToJSDate
(
row
[
'创建时间'
]);
// console.log("from if", row['创建时间']);
}
}
else
{
else
{
rowDate
=
row
[
'创建时间'
];
rowDate
=
row
[
'创建时间'
];
// console.log(rowDate);
}
}
const
rowYear
=
rowDate
.
getFullYear
();
const
rowYear
=
rowDate
.
getFullYear
();
if
(
rowYear
==
targetYear
)
{
if
(
rowYear
==
targetYear
)
{
...
@@ -111,9 +106,44 @@ protected getListCount(list: string[], target: string, data: any, year: string)
...
@@ -111,9 +106,44 @@ protected getListCount(list: string[], target: string, data: any, year: string)
count
.
set
(
key
,
Math
.
floor
(
Math
.
random
()
*
10
)
+
1
);
// Random number between 1 and 10
count
.
set
(
key
,
Math
.
floor
(
Math
.
random
()
*
10
)
+
1
);
// Random number between 1 and 10
});
});
}
}
console
.
log
(
allCountsZero
?
"randomly generating"
:
"excel data"
);
return
count
;
return
count
;
}
}
/**
* 统计事件列表中每个事件的数量。
* @param list - 事件名称列表。
* @param target - 目标事件名称。
* @param data - 数据源。
* @param year - 指定年份 ("thisyear" or "lastyear").
* @returns 事件计数映射。
*/
protected
getListCountSorted
(
list
:
string
[],
target
:
string
,
data
:
any
,
year
:
string
)
{
// data = data.slice(0, 5);
const
currentYear
=
new
Date
().
getFullYear
();
const
targetYear
=
year
===
'thisyear'
?
currentYear
:
currentYear
-
1
;
const
count
=
this
.
registerItems
(
list
);
data
.
forEach
(
row
=>
{
let
rowDate
:
any
=
0
;
if
(
typeof
(
row
[
'创建时间'
])
==
"number"
)
{
rowDate
=
excelSerialToJSDate
(
row
[
'创建时间'
]);
}
else
{
rowDate
=
row
[
'创建时间'
];
}
const
rowYear
=
rowDate
.
getFullYear
();
if
(
rowYear
==
targetYear
)
{
count
.
set
(
row
[
target
],
(
count
.
get
(
row
[
target
])
||
0
)
+
1
);
}
});
const
sortedCount
=
Array
.
from
(
count
.
entries
()).
sort
((
a
,
b
)
=>
b
[
1
]
-
a
[
1
]);
const
sortedCountMap
=
new
Map
(
sortedCount
);
console
.
log
(
sortedCount
);
return
sortedCountMap
;
}
}
}
src/biz/strategies/right/eventSrcStrategy.ts
View file @
fb950ee3
...
@@ -27,6 +27,6 @@ export class eventSrcStrategy extends abstractDataStrategyRight {
...
@@ -27,6 +27,6 @@ export class eventSrcStrategy extends abstractDataStrategyRight {
const
target
=
'事件来源'
;
const
target
=
'事件来源'
;
// 获取指定年份的事件来源统计,并转换为对象
// 获取指定年份的事件来源统计,并转换为对象
return
mapToObj
(
this
.
getListCount
(
sourceList
,
target
,
this
.
eventData
,
params
.
query
.
year
),
"source"
,
"count"
);
return
mapToObj
(
this
.
getListCount
Sorted
(
sourceList
,
target
,
this
.
eventData
,
params
.
query
.
year
),
"source"
,
"count"
);
}
}
}
}
\ No newline at end of file
src/biz/strategies/right/getEventCountByYearStrategy.ts
View file @
fb950ee3
...
@@ -46,11 +46,9 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight {
...
@@ -46,11 +46,9 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight {
let
rowDate
:
any
=
0
;
let
rowDate
:
any
=
0
;
if
(
typeof
(
row
[
'创建时间'
])
==
"number"
)
{
if
(
typeof
(
row
[
'创建时间'
])
==
"number"
)
{
rowDate
=
excelSerialToJSDate
(
row
[
'创建时间'
]);
rowDate
=
excelSerialToJSDate
(
row
[
'创建时间'
]);
console
.
log
(
"from if"
,
row
[
'创建时间'
]);
}
}
else
{
else
{
rowDate
=
row
[
'创建时间'
];
rowDate
=
row
[
'创建时间'
];
console
.
log
(
rowDate
);
}
}
let
rowYear
=
0
;
let
rowYear
=
0
;
if
(
!
isNaN
(
rowDate
.
getTime
()))
{
if
(
!
isNaN
(
rowDate
.
getTime
()))
{
...
@@ -58,10 +56,7 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight {
...
@@ -58,10 +56,7 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight {
rowYear
=
rowDate
.
getFullYear
();
rowYear
=
rowDate
.
getFullYear
();
}
catch
(
e
)
{
}
catch
(
e
)
{
rowYear
=
0
;
rowYear
=
0
;
console
.
log
(
'Error getting year:'
,
e
);
}
}
}
else
{
// console.log('Invalid Date:', rawDate.getTime());
}
}
if
(
rowYear
==
targetYear
)
{
if
(
rowYear
==
targetYear
)
{
...
...
src/biz/strategies/right/gridEventCountStrategy.ts
View file @
fb950ee3
...
@@ -27,6 +27,6 @@ export class gridEventCountStrategy extends abstractDataStrategyRight {
...
@@ -27,6 +27,6 @@ export class gridEventCountStrategy extends abstractDataStrategyRight {
const
target
=
'网格名称'
;
const
target
=
'网格名称'
;
// 获取指定年份的网格事件数量统计,并转换为对象
// 获取指定年份的网格事件数量统计,并转换为对象
return
mapToObj
(
this
.
getListCount
(
gridList
,
target
,
this
.
eventData
,
params
.
query
.
year
),
"gridname"
,
"count"
);
return
mapToObj
(
this
.
getListCount
Sorted
(
gridList
,
target
,
this
.
eventData
,
params
.
query
.
year
),
"gridname"
,
"count"
);
}
}
}
}
\ 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