Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zjxcxServer
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
node_server
zjxcxServer
Commits
1f834465
Commit
1f834465
authored
Feb 06, 2023
by
lixinming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
69e71289
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
121 additions
and
467 deletions
+121
-467
serverConfig.xml
serverConfig.xml
+8
-1
task.ts
src/biz/fuHuqQi/task.ts
+34
-3
enum.ts
src/config/enum.ts
+4
-3
serverConfig.ts
src/config/serverConfig.ts
+11
-2
enterprise.ts
src/data/enterprise/enterprise.ts
+11
-1
financing.ts
src/data/enterprise/financing.ts
+14
-2
task.ts
src/data/fuHuaQi/task.ts
+8
-2
dbConnect.ts
src/db/dbConnect.ts
+7
-5
dbInit.ts
src/db/dbInit.ts
+2
-0
tableInit.ts
src/db/tableInit.ts
+10
-0
main.ts
src/main.ts
+9
-0
tools.ts
src/util/tools.ts
+3
-448
No files found.
serverConfig.xml
View file @
1f834465
<config>
<config>
<port>
30001
</port>
<port>
30001
</port>
<mongodb>
mongodb://192.168.12.79:27017/adminDB?w=1
&
wtimeoutMS=30000
</mongodb>
<mongodb>
<path>
127.0.0.1
</path>
<port>
27017
</port>
<w>
1
</w>
<dataBase>
baseDB
</dataBase>
<wtimeoutMS>
30000
</wtimeoutMS>
</mongodb>
</config>
</config>
\ No newline at end of file
src/biz/fuHuqQi/task.ts
View file @
1f834465
...
@@ -5,8 +5,11 @@
...
@@ -5,8 +5,11 @@
*
*
*/
*/
import
{
TASKTYPEENUM
}
from
"../../config/enum"
;
import
{
findEnterpriseListByTaskId
}
from
"../../data/enterprise/enterprise"
;
import
{
findFinancingListByTaskId
}
from
"../../data/enterprise/financing"
;
import
{
findFuHuaQiTaskByKeyAndUscc
}
from
"../../data/fuHuaQi/task"
;
import
{
findFuHuaQiTaskByKeyAndUscc
}
from
"../../data/fuHuaQi/task"
;
import
{
getTaskId
}
from
"../../util/tools"
;
/**
/**
...
@@ -15,12 +18,40 @@ import { findFuHuaQiTaskByKeyAndUscc } from "../../data/fuHuaQi/task";
...
@@ -15,12 +18,40 @@ import { findFuHuaQiTaskByKeyAndUscc } from "../../data/fuHuaQi/task";
* @returns
* @returns
*/
*/
export
async
function
fuHuaQiTaskList
(
uscc
:
string
)
{
export
async
function
fuHuaQiTaskList
(
uscc
:
string
)
{
/**
* 返回格式 [{type:, }]
*/
let
result
=
[];
let
result
=
[];
const
timeKey
=
`
${
new
Date
().
getFullYear
()}${
new
Date
().
getMonth
()
+
1
}
`
;
const
timeKey
=
`
${
new
Date
().
getFullYear
()}${
new
Date
().
getMonth
()
+
1
}
`
;
let
taskList
=
await
findFuHuaQiTaskByKeyAndUscc
(
uscc
,
timeKey
);
let
taskMap
=
await
findFuHuaQiTaskByKeyAndUscc
(
uscc
,
timeKey
);
if
(
!
taskList
.
length
)
{
let
taskTypeMapConf
=
{};
for
(
let
key
in
TASKTYPEENUM
)
{
let
k
:
any
=
key
;
if
(
isNaN
(
k
))
taskTypeMapConf
[
TASKTYPEENUM
[
key
]]
=
key
;
}
const
TaskId
=
getTaskId
(
uscc
);
for
(
let
typeStr
in
taskTypeMapConf
)
{
let
typeKey
=
parseInt
(
typeStr
);
let
onceObj
=
{
key
:
typeStr
,
enterpriseList
:[]};
if
(
!
taskMap
[
typeStr
])
{
//没有提交任务
if
(
TASKTYPEENUM
.
孵化器月度填报
==
typeKey
)
{
// enterpriseList.push();
continue
;
}
let
dataList
=
[];
if
(
TASKTYPEENUM
.
新注册或迁入企业登记
==
typeKey
)
dataList
=
await
findEnterpriseListByTaskId
(
TaskId
);
if
(
TASKTYPEENUM
.
融资企业填报
==
typeKey
)
dataList
=
await
findFinancingListByTaskId
(
TaskId
);
dataList
.
forEach
(
info
=>
{
onceObj
.
enterpriseList
.
push
(
info
.
name
);
});
}
result
.
push
(
onceObj
);
}
}
return
result
;
return
result
;
}
}
src/config/enum.ts
View file @
1f834465
export
enum
ERRORENUM
{
export
enum
TASKTYPEENUM
{
未找到数据
,
孵化器月度填报
=
1
,
参数错误
,
融资企业填报
,
新注册或迁入企业登记
}
}
src/config/serverConfig.ts
View file @
1f834465
...
@@ -18,8 +18,13 @@ export async function initConfig() {
...
@@ -18,8 +18,13 @@ export async function initConfig() {
let
{
port
,
mongodb
}
=
configInfo
.
config
;
let
{
port
,
mongodb
}
=
configInfo
.
config
;
systemConfig
.
port
=
parseInt
(
port
[
0
]);
systemConfig
.
port
=
parseInt
(
port
[
0
]);
systemConfig
.
mongodbStr
=
mongodb
[
0
]
const
MongoPath
=
mongodb
[
0
].
path
[
0
];
const
MongoPort
=
mongodb
[
0
].
port
[
0
];
const
MongoW
=
mongodb
[
0
].
w
[
0
];
const
MongoDataBase
=
mongodb
[
0
].
dataBase
[
0
];
const
MongoWtimeoutMS
=
mongodb
[
0
].
wtimeoutMS
[
0
];
systemConfig
.
mongodbStr
=
analysisMongoConnectStr
(
MongoPath
,
MongoPort
,
MongoDataBase
,
MongoW
,
MongoWtimeoutMS
);
}
}
console
.
log
(
"config init success"
);
console
.
log
(
"config init success"
);
...
@@ -28,6 +33,10 @@ export async function initConfig() {
...
@@ -28,6 +33,10 @@ export async function initConfig() {
throw
new
BizError
(
"服务器配置解析错误 请检查根目录下 serverConfig.xml 文件是否正确"
);
throw
new
BizError
(
"服务器配置解析错误 请检查根目录下 serverConfig.xml 文件是否正确"
);
}
}
}
}
function
analysisMongoConnectStr
(
path
,
port
,
dataBase
,
w
,
timeOutMs
)
{
return
`mongodb://
${
path
}
:
${
port
}
/
${
dataBase
}
?w=
${
w
}
&wtimeoutMS=
${
timeOutMs
}
`
}
export
function
getEnum
()
{
export
function
getEnum
()
{
...
...
src/data/enterprise/enterprise.ts
View file @
1f834465
...
@@ -3,7 +3,7 @@ import { baseDB } from '../../db/dbInit';
...
@@ -3,7 +3,7 @@ import { baseDB } from '../../db/dbInit';
const
enterpriseSchema
=
new
Schema
({
const
enterpriseSchema
=
new
Schema
({
name
:
{
type
:
String
,
index
:
true
},
//企业名称
name
:
{
type
:
String
,
index
:
true
},
//企业名称
id
:{
type
:
String
,
index
:
true
},
//唯一标识
taskId
:{
type
:
String
,
index
:
true
},
//任务id
uscc
:{
type
:
String
,
index
:
true
},
//统一信用代码
uscc
:{
type
:
String
,
index
:
true
},
//统一信用代码
logonTime
:
Number
,
//注册时间
logonTime
:
Number
,
//注册时间
logonAdd
:
String
,
//注册地址
logonAdd
:
String
,
//注册地址
...
@@ -22,3 +22,12 @@ var enterpriseModel;
...
@@ -22,3 +22,12 @@ var enterpriseModel;
export
function
initModel
(){
export
function
initModel
(){
enterpriseModel
=
baseDB
.
model
(
'enterprise'
,
enterpriseSchema
);
enterpriseModel
=
baseDB
.
model
(
'enterprise'
,
enterpriseSchema
);
}
}
/**
* 通过taskId 获取此次任务提交的企业列表
* @param taskId
* @returns
*/
export
async
function
findEnterpriseListByTaskId
(
taskId
:
string
)
{
return
await
enterpriseModel
.
findOne
({
taskId
}).
exec
();
}
\ No newline at end of file
src/data/enterprise/financing.ts
View file @
1f834465
...
@@ -2,8 +2,9 @@ import {Schema} from 'mongoose';
...
@@ -2,8 +2,9 @@ import {Schema} from 'mongoose';
import
{
baseDB
}
from
'../../db/dbInit'
;
import
{
baseDB
}
from
'../../db/dbInit'
;
const
financingSchema
=
new
Schema
({
const
financingSchema
=
new
Schema
({
uscc
:{
type
:
String
,
key
:
true
},
//统一信用代码
uscc
:{
type
:
String
,
index
:
true
},
//统一信用代码
id
:{
type
:
String
,
key
:
true
},
//唯一标识
name
:
String
,
//企业名称
taskId
:{
type
:
String
,
index
:
true
},
//任务id
createTime
:
Number
,
//入库时间
createTime
:
Number
,
//入库时间
financingTime
:
Number
,
//获得融资时间
financingTime
:
Number
,
//获得融资时间
financingAmount
:
Number
,
//融资金额(万元)
financingAmount
:
Number
,
//融资金额(万元)
...
@@ -12,9 +13,19 @@ const financingSchema = new Schema({
...
@@ -12,9 +13,19 @@ const financingSchema = new Schema({
fuHuaQiInvestment
:{
type
:
Boolean
,
default
:
false
},
//孵化器是否投资
fuHuaQiInvestment
:{
type
:
Boolean
,
default
:
false
},
//孵化器是否投资
fuHuaQiInvestmentAmount
:
Number
,
//孵化器投资金额(万元)
fuHuaQiInvestmentAmount
:
Number
,
//孵化器投资金额(万元)
fuHuaQiInvestmentStyle
:
Number
,
//孵化器投资方式
fuHuaQiInvestmentStyle
:
Number
,
//孵化器投资方式
draftLock
:{
type
:
Boolean
,
default
:
false
},
//草稿锁,true为提交之后,false为草稿
});
});
var
financingModel
;
var
financingModel
;
export
function
initModel
(){
export
function
initModel
(){
financingModel
=
baseDB
.
model
(
'financing'
,
financingSchema
);
financingModel
=
baseDB
.
model
(
'financing'
,
financingSchema
);
}
}
/**
* 通过taskId 获取此次任务提交的融资列表
* @param taskId
* @returns
*/
export
async
function
findFinancingListByTaskId
(
taskId
:
string
)
{
return
await
financingModel
.
findOne
({
taskId
}).
exec
();
}
\ No newline at end of file
src/data/fuHuaQi/task.ts
View file @
1f834465
...
@@ -4,6 +4,7 @@ import { baseDB } from '../../db/dbInit';
...
@@ -4,6 +4,7 @@ import { baseDB } from '../../db/dbInit';
const
fuHuaQiTaskSchema
=
new
Schema
({
const
fuHuaQiTaskSchema
=
new
Schema
({
key
:{
type
:
String
,
index
:
true
},
//任务标识 格式为:YYYYMM
key
:{
type
:
String
,
index
:
true
},
//任务标识 格式为:YYYYMM
type
:
{
type
:
Number
,
index
:
true
},
//任务类型
type
:
{
type
:
Number
,
index
:
true
},
//任务类型
taskId
:
String
,
//任务id
fuHuaQiUscc
:
String
,
//任务所属孵化器id
fuHuaQiUscc
:
String
,
//任务所属孵化器id
createTime
:
Number
,
//提交时间
createTime
:
Number
,
//提交时间
relevanceId
:
String
,
//任务关联的表 financing 或 enterprise 的id
relevanceId
:
String
,
//任务关联的表 financing 或 enterprise 的id
...
@@ -16,6 +17,10 @@ export function initModel(){
...
@@ -16,6 +17,10 @@ export function initModel(){
}
}
export
async
function
findFuHuaQiTaskByKeyAndUscc
(
uscc
:
string
,
key
:
string
)
{
export
async
function
findFuHuaQiTaskByKeyAndUscc
(
uscc
:
string
,
key
:
string
)
{
let
result
=
await
fuHuaQiTaskModel
.
find
({
uscc
,
key
}).
exec
();
let
findList
=
await
fuHuaQiTaskModel
.
find
({
uscc
,
key
}).
exec
()
||
[];
return
result
;
let
taskMap
=
{};
findList
.
forEach
(
item
=>
{
taskMap
[
item
.
key
]
=
item
;
});
return
taskMap
;
}
}
\ No newline at end of file
src/db/dbConnect.ts
View file @
1f834465
...
@@ -6,14 +6,16 @@ let defaultOptions = {
...
@@ -6,14 +6,16 @@ let defaultOptions = {
// reconnectTries:1000,
// reconnectTries:1000,
// reconnectInterval:3000,
// reconnectInterval:3000,
keepAlive
:
1
,
keepAlive
:
1
,
connectTimeoutMS
:
3000
0
,
connectTimeoutMS
:
3000
,
useCreateIndex
:
true
,
useCreateIndex
:
true
,
useUnifiedTopology
:
true
useUnifiedTopology
:
true
};
};
export
async
function
createDbConnect
(
connectUrl
:
string
,
options
?:
object
)
{
export
async
function
createDbConnect
(
connectUrl
:
string
,
options
?:
object
)
{
if
(
!
connectUrl
)
throw
new
Error
(
`wrong connect url
${
connectUrl
}
`
);
if
(
!
options
)
options
=
defaultOptions
;
if
(
!
options
)
options
=
defaultOptions
;
return
await
mongoose
.
createConnection
(
connectUrl
,
options
).
catch
(
return
await
mongoose
.
createConnection
(
connectUrl
,
options
).
catch
((
err
)
=>
{
throw
err
});
(
err
)
=>
{
throw
err
});
}
}
src/db/dbInit.ts
View file @
1f834465
...
@@ -8,11 +8,13 @@ var baseDB;
...
@@ -8,11 +8,13 @@ var baseDB;
export
async
function
initDB
()
{
export
async
function
initDB
()
{
//如果配置了mongoServerConstVal 才会连接mongo
//如果配置了mongoServerConstVal 才会连接mongo
if
(
systemConfig
.
mongodbStr
)
{
if
(
systemConfig
.
mongodbStr
)
{
console
.
log
(
systemConfig
.
mongodbStr
)
baseDB
=
await
createDbConnect
(
systemConfig
.
mongodbStr
).
catch
(
err
=>
{
baseDB
=
await
createDbConnect
(
systemConfig
.
mongodbStr
).
catch
(
err
=>
{
throw
err
throw
err
});
});
await
initTable
();
await
initTable
();
console
.
log
(
'init mongodb success'
);
}
else
{
}
else
{
throw
new
BizError
(
"xml中未配置mongo连接字符串 无法连接到mongodb"
);
throw
new
BizError
(
"xml中未配置mongo连接字符串 无法连接到mongodb"
);
}
}
...
...
src/db/tableInit.ts
View file @
1f834465
import
*
as
taskinModel
from
"../data/fuHuaQi/task"
;
import
*
as
fuhuaqiinModel
from
"../data/fuHuaQi/fuhuaqi"
;
import
*
as
enterpriseinModel
from
"../data/enterprise/enterprise"
;
import
*
as
financinginModel
from
"../data/enterprise/financing"
;
export
async
function
initTable
()
{
export
async
function
initTable
()
{
taskinModel
.
initModel
();
fuhuaqiinModel
.
initModel
();
enterpriseinModel
.
initModel
();
financinginModel
.
initModel
();
}
}
\ No newline at end of file
src/main.ts
View file @
1f834465
import
{
fuHuaQiTaskList
}
from
"./biz/fuHuqQi/task"
;
import
{
initConfig
,
systemConfig
}
from
"./config/serverConfig"
;
import
{
initConfig
,
systemConfig
}
from
"./config/serverConfig"
;
import
{
initDB
}
from
"./db/dbInit"
;
import
{
httpServer
}
from
"./net/http_server"
;
import
{
httpServer
}
from
"./net/http_server"
;
async
function
lanuch
()
{
async
function
lanuch
()
{
await
initConfig
();
//初始化配置解析
await
initConfig
();
//初始化配置解析
await
initDB
();
httpServer
.
createServer
(
systemConfig
.
port
);
httpServer
.
createServer
(
systemConfig
.
port
);
console
.
log
(
'This indicates that the server is started successfully.'
);
console
.
log
(
'This indicates that the server is started successfully.'
);
await
t
();
}
async
function
t
()
{
await
fuHuaQiTaskList
(
'111'
);
}
}
lanuch
();
lanuch
();
\ No newline at end of file
src/util/tools.ts
View file @
1f834465
export
function
getTaskId
(
uscc
:
string
)
{
export
function
limitEnteNameString
(
name
,
number
?)
{
return
`
${
uscc
}${
new
Date
().
getFullYear
()}${
new
Date
().
getMonth
()
+
1
}
`
number
=
number
?
number
:
13
;
if
(
name
.
length
>
number
)
return
`
${
name
.
substring
(
0
,
number
-
2
)}
...`
;
return
name
;
}
const
moneyStrConfig
=
{
"万亿"
:
13
,
"萬億"
:
13
,
"千亿"
:
12
,
"千億"
:
12
,
"百亿"
:
11
,
"佰億"
:
11
,
"十亿"
:
10
,
"拾億"
:
10
,
"亿"
:
9
,
"億"
:
9
,
"千万"
:
8
,
"千萬"
:
8
,
"百万"
:
7
,
"佰萬"
:
7
,
"十万"
:
6
,
"拾萬"
:
6
,
"万"
:
5
,
"萬"
:
5
,
"千"
:
4
,
"百"
:
3
,
"十"
:
2
,
"美元"
:
1
,
"人名币"
:
1
,
"元"
:
1
,
};
// 汇率
let
dollarRate
=
6.4731
;
//解析金额
export
function
analysisMoneyStr
(
mnyStr
:
string
)
{
let
zeroNum
=
1
;
let
moneyNumber
=
0
;
for
(
let
key
in
moneyStrConfig
)
{
let
checkNum
=
mnyStr
.
indexOf
(
key
);
if
(
checkNum
>
-
1
)
{
zeroNum
=
moneyStrConfig
[
key
];
moneyNumber
=
parseFloat
(
mnyStr
.
slice
(
0
,
checkNum
));
break
;
}
}
if
(
mnyStr
.
replace
(
/
[^
0-9
]
/ig
,
""
)
==
""
)
return
0
;
if
(
zeroNum
>
1
)
{
let
count
=
1
;
for
(
let
i
=
1
;
i
<
zeroNum
;
i
++
)
{
count
=
count
*
10
;
}
zeroNum
=
count
;
}
let
money
=
parseInt
(
`
${
zeroNum
*
moneyNumber
}
`
);
if
(
mnyStr
.
indexOf
(
'美元'
))
money
=
parseInt
(
`
${
money
*
dollarRate
}
`
);
return
money
;
}
//缩略金额
export
function
simplifyMoney
(
mny
:
number
,
str
:
string
)
{
let
num
=
moneyStrConfig
[
str
];
let
count
=
1
;
for
(
let
i
=
1
;
i
<
num
;
i
++
)
{
count
=
count
*
10
;
}
return
mny
/
count
;
}
//分离 带单位的数据
function
separateDataAndUint
(
str
)
{
if
(
!
str
)
return
{
data
:
0
,
unit
:
""
};
let
data
=
str
.
replace
(
/
[\u
4E00-
\u
9FA5a-zA-Z
]
+/
,
""
);
let
unit
=
str
.
replace
(
/^
(
-
)?\d
+
(\.\d
+
)?
/
,
""
);
return
{
data
,
unit
};
}
//object key替换 带单位
export
function
objKeyReplace
(
object
,
keyInfo
=
{},
isString
=
true
)
{
if
(
isString
)
{
//校验字符
for
(
let
key
in
object
)
{
if
(
!
object
[
key
])
object
[
key
]
=
''
;
}
}
else
{
//校验数字
for
(
let
key
in
object
)
{
if
(
!
object
[
key
])
object
[
key
]
=
'0'
;
}
}
let
unitMap
=
{};
let
dataMap
=
{};
for
(
let
key
in
object
)
{
let
newKey
=
keyInfo
[
key
]
||
key
;
let
{
data
,
unit
}
=
separateDataAndUint
(
`
${
object
[
key
]}
`
||
""
);
unitMap
[
newKey
]
=
unit
;
dataMap
[
newKey
]
=
parseFloat
(
data
);
}
return
{
dataMap
,
unitMap
};
}
//返回特定key和value的obj
export
function
objKeyAndValue
(
dataMap
,
...
keyList
)
{
let
result
=
{};
for
(
let
key
in
dataMap
)
{
if
(
keyList
.
indexOf
(
key
)
>
-
1
)
result
[
key
]
=
dataMap
[
key
];
}
return
result
;
}
//获取键值数据 percent =>为数字的时候 保留几位小数
export
function
getKeyValue
(
title
,
dataMap
,
unit
,
total
,
percent
)
{
let
data
=
{
title
,
subTitle
:
title
,
total
:
0
,
list
:
[]
};
let
count
=
0
;
for
(
let
key
in
dataMap
)
{
let
value
=
parseFloat
(
dataMap
[
key
]);
count
+=
value
;
if
(
total
)
data
.
total
+=
value
;
}
for
(
let
key
in
dataMap
)
{
let
thisUnit
=
""
;
if
(
unit
)
{
if
(
typeof
unit
==
"string"
)
thisUnit
=
unit
;
else
thisUnit
=
unit
[
key
];
}
let
value
=
parseFloat
(
dataMap
[
key
]);
if
(
percent
)
{
thisUnit
=
'%'
;
value
=
getDecimalForN
(
value
/
count
,
percent
);
}
let
onceInfo
:
any
=
{
key
,
value
,
unit
:
thisUnit
};
data
.
list
.
push
(
onceInfo
);
}
return
data
;
}
export
function
getKeyStringValue
(
title
,
dataMap
)
{
let
data
=
{
title
,
subTitle
:
title
,
total
:
0
,
list
:
[]
};
for
(
let
key
in
dataMap
)
{
if
(
dataMap
[
key
])
{
data
.
list
.
push
({
key
,
value
:
dataMap
[
key
]
});
}
else
{
data
.
list
.
push
({
key
,
value
:
""
});
}
}
return
data
;
}
function
getChartMin
(
num
)
{
if
(
num
>
0
)
return
0
;
return
Math
.
floor
(
num
);
}
export
function
getChartData
(
title
,
dataMap
,
unit
,
percent
)
{
unit
=
unit
||
""
;
let
data
=
{
title
,
yMaxValue
:
0
,
yMinValue
:
new
Date
().
valueOf
(),
yStepValue
:
0
,
unit
:
percent
?
"%"
:
unit
,
data
:
{
title
:
title
,
total
:
0
,
list
:
[
]
}
}
let
count
=
0
;
for
(
let
key
in
dataMap
)
{
let
value
=
parseFloat
(
dataMap
[
key
]
||
0
);
data
.
yMaxValue
=
Math
.
max
(
data
.
yMaxValue
,
value
);
data
.
yMinValue
=
Math
.
min
(
data
.
yMinValue
,
value
);
count
+=
1
;
data
.
data
.
total
+=
value
;
}
for
(
let
key
in
dataMap
)
{
let
value
=
parseFloat
(
dataMap
[
key
]);
let
thisUnit
=
unit
;
if
(
percent
)
{
thisUnit
=
'%'
;
value
=
getDecimalForN
(
value
/
count
,
percent
);
}
let
onceInfo
=
{
key
,
unit
:
thisUnit
,
value
};
data
.
data
.
list
.
push
(
onceInfo
)
}
data
.
yMinValue
=
getChartMin
(
data
.
yMinValue
);
data
.
yStepValue
=
getChartStepNumber
(
Math
.
ceil
((
data
.
yMaxValue
-
data
.
yMinValue
)
/
count
));
let
maxVal
=
Math
.
ceil
(
data
.
yMaxValue
);
data
.
yMaxValue
=
maxVal
+
(
data
.
yStepValue
-
(
maxVal
%
data
.
yStepValue
));
return
data
;
}
export
function
getListData
(
title
,
dataList
,
titleList
,
titleValueObj
)
{
let
data
=
{
title
,
subTitle
:
title
,
total
:
dataList
.
length
,
titleList
,
valueList
:[]
};
dataList
.
forEach
(
info
=>
{
let
onceList
=
[];
titleList
.
forEach
(
titleName
=>
{
onceList
.
push
(
info
[
titleValueObj
[
titleName
]
]);
});
data
.
valueList
.
push
(
onceList
);
});
return
data
;
}
//多个y轴的条柱状图 dataMap => {"name":{"key1":1111,"key2":232, "key3":dsfs, ... }, ... }
export
function
getMoreYChartData
(
title
,
dataMap
,
percent
,
unit
)
{
let
data
=
{
title
,
dataList
:
[]
};
for
(
let
subDataName
in
dataMap
)
{
let
onceData
=
{
title
:
subDataName
,
yMaxValue
:
0
,
yMinValue
:
new
Date
().
valueOf
(),
yStepValue
:
0
,
unit
:
""
,
total
:
0
,
list
:
[
]
};
let
thisDataInfo
=
dataMap
[
subDataName
];
let
thisCount
=
0
;
for
(
let
key
in
thisDataInfo
)
{
let
value
=
parseFloat
(
thisDataInfo
[
key
]);
onceData
.
yMaxValue
=
Math
.
max
(
onceData
.
yMaxValue
,
value
);
onceData
.
yMinValue
=
Math
.
min
(
onceData
.
yMinValue
,
value
);
onceData
.
total
+=
value
;
thisCount
+=
1
;
}
onceData
.
yStepValue
=
getChartStepNumber
(
Math
.
ceil
(
(
onceData
.
yMaxValue
-
onceData
.
yMinValue
)
/
thisCount
)
);
let
thisUnit
;
if
(
percent
)
{
thisUnit
=
"%"
;
onceData
.
yMaxValue
=
100
;
onceData
.
yStepValue
=
Math
.
ceil
(
(
100
-
onceData
.
yMinValue
)
/
onceData
.
total
)
;
}
else
if
(
typeof
unit
==
'object'
)
{
thisUnit
=
unit
[
subDataName
]
||
""
;
}
else
thisUnit
=
unit
||
""
;
for
(
let
key
in
thisDataInfo
)
{
let
value
;
if
(
percent
)
value
=
getDecimalForN
(
value
/
onceData
.
total
,
percent
);
else
value
=
parseFloat
(
thisDataInfo
[
key
]);
let
onceInfo
=
{
key
,
unit
:
thisUnit
,
value
};
onceData
.
list
.
push
(
onceInfo
)
}
onceData
.
total
=
getDecimalForN
(
onceData
.
total
,
1
);
let
maxVal
=
Math
.
ceil
(
onceData
.
yMaxValue
);
onceData
.
yMinValue
=
getChartMin
(
onceData
.
yMinValue
);
onceData
.
yMaxValue
=
maxVal
+
(
onceData
.
yStepValue
-
(
maxVal
%
onceData
.
yStepValue
));
data
.
dataList
.
push
(
onceData
);
}
return
data
;
}
//一个y轴的多个数据的柱状图
export
function
getSingleYAndMoreData
(
title
,
dataMap
,
percent
,
unit
)
{
let
data
=
{
title
,
dataList
:[],
yMaxValue
:
0
,
yMinValue
:
new
Date
().
valueOf
(),
yStepValue
:
0
,
unit
:
""
,
total
:
0
};
let
maxCount
=
0
;
for
(
let
subDataName
in
dataMap
)
{
let
onceData
=
{
title
:
subDataName
,
list
:[]
};
let
thisDataCount
=
0
;
let
analysisMap
=
objKeyReplace
(
dataMap
[
subDataName
])
let
thisData
=
analysisMap
.
dataMap
;
let
thisMax
=
0
;
for
(
let
key
in
thisData
)
{
let
value
=
parseFloat
(
dataMap
[
key
]);
thisDataCount
+=
value
;
thisMax
+=
1
;
}
maxCount
=
Math
.
max
(
maxCount
,
thisMax
);
let
thisUnit
;
if
(
percent
)
thisUnit
=
"%"
;
else
if
(
typeof
unit
==
'object'
)
{
thisUnit
=
unit
[
subDataName
]
||
""
;
}
else
thisUnit
=
unit
||
""
;
for
(
let
key
in
thisData
)
{
let
value
;
if
(
percent
)
value
=
getDecimalForN
(
value
/
thisDataCount
,
percent
);
else
value
=
parseFloat
(
thisData
[
key
]);
data
.
yMaxValue
=
Math
.
max
(
data
.
yMaxValue
,
value
);
data
.
yMinValue
=
Math
.
min
(
data
.
yMinValue
,
value
);
data
.
total
+=
value
;
let
onceInfo
=
{
key
,
unit
:
thisUnit
,
value
};
onceData
.
list
.
push
(
onceInfo
)
}
data
.
dataList
.
push
(
onceData
);
}
data
.
yMinValue
=
getChartMin
(
data
.
yMinValue
);
data
.
yMaxValue
=
Math
.
ceil
(
data
.
yMaxValue
);
data
.
yStepValue
=
getChartStepNumber
(
Math
.
ceil
((
data
.
yMaxValue
-
data
.
yMinValue
)
/
maxCount
));
return
data
;
}
function
getChartStepNumber
(
number
)
{
let
lenth
=
`
${
number
}
`
.
length
;
let
count
=
1
;
for
(
let
i
=
1
;
i
<
lenth
;
i
++
)
{
count
=
count
*
10
;
}
return
number
+
(
count
-
(
number
%
count
)
);
}
//字符模板
export
function
getStringMoreData
(
title
,
valueList
)
{
let
result
=
{
title
,
data
:{}
};
valueList
.
forEach
(
(
info
,
index
)
=>
{
let
key
=
index
+
1
result
.
data
[
`
${
key
}
`
]
=
info
;
});
return
result
;
}
//撒点图 cutApartXAndY:[分割的x坐标,分割的y坐标]
export
function
getDropMoreData
(
dataList
,
title
,
subTitle
,
cutApartXAndY
?)
{
let
data
:
any
=
{
title
,
subTitle
,
dataList
:[],
xMax
:
0
,
xMin
:
new
Date
().
valueOf
(),
yMax
:
0
,
yMin
:
new
Date
().
valueOf
()
};
dataList
.
forEach
(
info
=>
{
let
{
x
,
y
}
=
info
;
let
thisDropXInfo
=
separateDataAndUint
(
`
${
x
}
`
);
let
thisDropX
=
parseFloat
(
thisDropXInfo
.
data
);
let
thisDropYInfo
=
separateDataAndUint
(
`
${
y
}
`
);
let
thisDropY
=
parseFloat
(
thisDropYInfo
.
data
);
data
.
xMax
=
Math
.
max
(
thisDropX
,
data
.
xMax
);
data
.
xMin
=
Math
.
min
(
thisDropX
,
data
.
xMin
);
data
.
yMax
=
Math
.
max
(
thisDropY
,
data
.
yMax
);
data
.
yMin
=
Math
.
min
(
thisDropY
,
data
.
yMin
);
let
value
=
[
thisDropX
,
thisDropY
];
let
type
=
1
;
if
(
cutApartXAndY
)
{
let
cutX
=
cutApartXAndY
[
0
];
let
cutY
=
cutApartXAndY
[
1
];
if
(
thisDropX
<
cutX
&&
thisDropY
>
cutY
)
type
=
1
;
else
if
(
thisDropX
>
cutX
&&
thisDropY
>
cutY
)
type
=
2
;
else
if
(
thisDropX
<
cutX
&&
thisDropY
<
cutY
)
type
=
3
;
else
type
=
4
;
}
data
.
dataList
.
push
({
value
,
name
:
info
.
name
||
""
,
type
});
});
if
(
cutApartXAndY
)
{
data
.
cutApartX
=
cutApartXAndY
[
0
];
data
.
cutApartY
=
cutApartXAndY
[
1
];
}
let
count
=
dataList
.
length
;
let
xAvg
=
Math
.
ceil
((
data
.
xMax
-
data
.
xMin
)
/
count
);
data
.
xMax
=
Math
.
floor
(
data
.
xMax
+
xAvg
);
data
.
xMin
=
Math
.
floor
(
data
.
xMin
-
xAvg
);
let
yAvg
=
Math
.
ceil
((
data
.
yMax
-
data
.
yMin
)
/
count
);
data
.
yMax
=
Math
.
floor
(
data
.
yMax
+
yAvg
);
data
.
yMin
=
Math
.
floor
(
data
.
yMin
-
yAvg
);
return
data
;
}
//按需取保留小数长度 tenNumber保留小数位 1位就填1
export
function
getDecimalForN
(
number
,
n
)
{
let
ten
=
1
;
for
(
let
i
=
0
;
i
<
n
;
i
++
)
{
ten
=
ten
*
10
;
}
return
Math
.
ceil
(
number
*
ten
)
/
ten
}
//生日获取时间段
export
function
getAgeByBirthday
(
birthday
:
string
)
{
let
b
=
new
Date
(
birthday
).
valueOf
();
let
d
=
new
Date
().
valueOf
();
let
onceYear
=
365
*
24
*
3600
*
1000
;
let
age
=
Math
.
floor
(
(
d
-
b
)
/
onceYear
);
if
(
age
>=
21
&&
age
<=
30
)
return
"21-30"
;
else
if
(
age
>=
31
&&
age
<=
40
)
return
"35-45"
;
else
if
(
age
>=
41
&&
age
<=
50
)
return
"46-55"
;
else
if
(
age
>
50
)
return
"50岁以上"
;
else
return
'其他'
;
}
export
function
analysisAddOrRMData
(
str
)
{
str
=
`
${
str
}
`
;
let
checkStr
=
str
.
replace
(
/增加/
,
""
);
let
result
=
checkStr
.
replace
(
/减少/
,
"-"
);
return
result
;
}
export
function
changeDataName
(
str
)
{
let
result
=
str
.
replace
(
/
[
()""“”
/
()-
]
/
,
"_"
);
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
result
=
result
.
replace
(
/
[
()""“”
/
()-
]
/
,
"_"
);
}
return
result
;
}
//数据保留两位小数
export
function
getDataMapDecimalForN
(
dataMap
,
number
?)
{
let
tenCount
=
number
?
number
:
2
;
let
result
=
{};
for
(
let
key
in
dataMap
)
{
let
value
=
dataMap
[
key
];
if
(
typeof
value
==
'string'
)
{
let
{
data
}
=
separateDataAndUint
(
value
);
value
=
parseFloat
(
data
);
}
result
[
key
]
=
getDecimalForN
(
value
,
tenCount
);
}
return
result
;
}
}
\ 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