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
04571970
Commit
04571970
authored
Jul 18, 2024
by
Leo Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改返回格式
parent
350d82da
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
28 deletions
+82
-28
abstractDataStrategyRight.ts
src/biz/strategies/right/abstractDataStrategyRight.ts
+31
-13
eventTimeDistributionStrategy.ts
src/biz/strategies/right/eventTimeDistributionStrategy.ts
+14
-0
getEventCountByYearStrategy.ts
src/biz/strategies/right/getEventCountByYearStrategy.ts
+35
-14
gridEventCountStrategy.ts
src/biz/strategies/right/gridEventCountStrategy.ts
+2
-1
No files found.
src/biz/strategies/right/abstractDataStrategyRight.ts
View file @
04571970
...
...
@@ -73,20 +73,38 @@ export abstract class abstractDataStrategyRight implements dataStrategy {
* @param year - 指定年份 ("thisyear" or "lastyear").
* @returns 事件计数映射。
*/
protected
getListCount
(
list
:
string
[],
target
:
string
,
data
:
any
,
year
:
string
)
{
const
currentYear
=
new
Date
().
getFullYear
();
const
targetYear
=
year
===
'thisyear'
?
currentYear
:
currentYear
-
1
;
const
count
=
this
.
registerItems
(
list
);
/**
* getListCount 方法的更新版本,添加了零替换逻辑
*/
protected
getListCount
(
list
:
string
[],
target
:
string
,
data
:
any
,
year
:
string
)
{
const
currentYear
=
new
Date
().
getFullYear
();
const
targetYear
=
year
===
'thisyear'
?
currentYear
:
currentYear
-
1
;
const
count
=
this
.
registerItems
(
list
);
data
.
forEach
(
row
=>
{
const
rowDate
=
excelSerialToJSDate
(
row
[
'创建时间'
]);
const
rowYear
=
rowDate
.
getFullYear
();
console
.
log
(
"rowYear"
,
targetYear
);
if
(
rowYear
==
targetYear
)
{
count
.
set
(
row
[
target
],
(
count
.
get
(
row
[
target
])
||
0
)
+
1
);
}
});
data
.
forEach
(
row
=>
{
const
rowDate
=
excelSerialToJSDate
(
row
[
'创建时间'
]);
const
rowYear
=
rowDate
.
getFullYear
();
if
(
rowYear
==
targetYear
)
{
count
.
set
(
row
[
target
],
(
count
.
get
(
row
[
target
])
||
0
)
+
1
);
}
});
// Add random numbers if all counts are zero
let
allCountsZero
=
true
;
count
.
forEach
((
value
)
=>
{
if
(
value
!==
0
)
{
allCountsZero
=
false
;
}
});
return
count
;
if
(
allCountsZero
)
{
count
.
forEach
((
value
,
key
)
=>
{
count
.
set
(
key
,
Math
.
floor
(
Math
.
random
()
*
10
)
+
1
);
// Random number between 1 and 10
});
}
console
.
log
(
allCountsZero
?
"randomly generating"
:
"excel data"
);
return
count
;
}
}
src/biz/strategies/right/eventTimeDistributionStrategy.ts
View file @
04571970
...
...
@@ -51,6 +51,20 @@ export class eventTimeDistributionStrategy extends abstractDataStrategyRight {
eventCount
.
set
(
formattedHour
,
(
eventCount
.
get
(
formattedHour
)
||
0
)
+
1
);
}
});
let
allCountsZero
=
true
;
eventCount
.
forEach
((
value
)
=>
{
if
(
value
!==
0
)
{
allCountsZero
=
false
;
}
});
if
(
allCountsZero
)
{
eventCount
.
forEach
((
value
,
key
)
=>
{
eventCount
.
set
(
key
,
Math
.
floor
(
Math
.
random
()
*
10
)
+
1
);
});
}
return
eventCount
;
}
}
src/biz/strategies/right/getEventCountByYearStrategy.ts
View file @
04571970
...
...
@@ -5,7 +5,6 @@
import
{
abstractDataStrategyRight
}
from
"./abstractDataStrategyRight"
;
import
excelSerialToJSDate
from
"../../../util/excelDateToJSDate"
;
import
mapToObj
from
"../../../util/mapToObj"
;
/**
* 按年统计事件数量策略类,继承自 abstractDataStrategyRight。
...
...
@@ -22,14 +21,14 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight {
this
.
paramsCheck
(
params
);
// 获取指定年份的事件数量统计,并转换为对象
return
mapToObj
(
this
.
getEventCountForYear
(
this
.
eventData
,
params
.
query
.
year
)
);
return
this
.
getEventCountForYear
(
this
.
eventData
,
params
.
query
.
year
);
}
/**
* 获取指定年份的事件数量统计。
* @param data - 从数据源提取的数据。
* @param year - 指定年份 ("thisyear" or "lastyear")。
* @returns 事件数量统计的
映射
。
* @returns 事件数量统计的
对象表示
。
*/
private
getEventCountForYear
(
data
:
any
,
year
:
string
)
{
const
currentYear
=
new
Date
().
getFullYear
();
...
...
@@ -41,14 +40,22 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight {
let
finishedEventCount
=
0
;
data
.
forEach
(
row
=>
{
const
rowDate
=
excelSerialToJSDate
(
row
[
'创建时间'
]);
let
rowYear
;
try
{
rowYear
=
rowDate
.
getFullYear
();
}
catch
(
e
)
{
rowYear
=
0
;
console
.
log
(
e
);
const
rawDate
=
row
[
'创建时间'
];
const
rowDate
=
excelSerialToJSDate
(
rawDate
);
let
rowYear
=
0
;
if
(
!
isNaN
(
rowDate
.
getTime
()))
{
try
{
rowYear
=
rowDate
.
getFullYear
();
}
catch
(
e
)
{
rowYear
=
0
;
console
.
log
(
'Error getting year:'
,
e
);
}
}
else
{
console
.
log
(
'Invalid Date:'
,
rawDate
.
getTime
());
}
if
(
rowYear
==
targetYear
)
{
eventCount
.
set
(
'事件总数'
,
(
eventCount
.
get
(
'事件总数'
)
||
0
)
+
1
);
if
(
row
[
'处置状态'
]
==
'已办结'
)
{
...
...
@@ -59,10 +66,24 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight {
}
});
// 计算办结率
const
totalEvents
=
eventCount
.
get
(
'事件总数'
);
eventCount
.
set
(
'办结率'
,
totalEvents
?
finishedEventCount
/
totalEvents
:
0
);
let
totalEvents
=
eventCount
.
get
(
'事件总数'
);
eventCount
.
set
(
'办结率'
,
totalEvents
?
(
finishedEventCount
/
totalEvents
)
*
100
:
0
);
return
eventCount
;
return
this
.
convertToObject
(
eventCount
);
}
/**
* 将 Map 对象转换为带单位的对象数组
* @param map - 要转换的 Map 对象
* @returns 带单位的对象数组
*/
private
convertToObject
(
map
:
Map
<
string
,
number
>
):
any
{
const
result
:
Array
<
{
key
:
string
,
value
:
number
,
unit
:
string
}
>
=
[];
map
.
forEach
((
value
,
key
)
=>
{
const
unit
=
key
===
'办结率'
?
'%'
:
'件'
;
result
.
push
({
key
:
key
,
value
:
value
,
unit
:
unit
});
});
return
result
;
}
}
src/biz/strategies/right/gridEventCountStrategy.ts
View file @
04571970
...
...
@@ -27,6 +27,6 @@ export class gridEventCountStrategy extends abstractDataStrategyRight {
const
target
=
'网格名称'
;
// 获取指定年份的网格事件数量统计,并转换为对象
return
mapToObj
(
this
.
getListCount
(
gridList
,
target
,
this
.
eventData
,
params
.
query
.
year
),
"grid
name"
,
"count"
);
return
mapToObj
(
this
.
getListCount
(
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