Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ask_data_ai_admin
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
linyangyang
ask_data_ai_admin
Commits
e6672292
Commit
e6672292
authored
Jul 23, 2025
by
林洋洋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加日报数据从数据库查询
parent
bc927235
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
249 additions
and
23 deletions
+249
-23
AskHistoryCollectData.java
...c/main/java/com/ask/api/entity/AskHistoryCollectData.java
+21
-0
AskReportDict.java
...i-api/src/main/java/com/ask/api/entity/AskReportDict.java
+57
-0
AskHistoryCollectDataMapper.java
...main/java/com/ask/mapper/AskHistoryCollectDataMapper.java
+11
-0
AskReportDictMapper.java
...biz/src/main/java/com/ask/mapper/AskReportDictMapper.java
+10
-0
ExcelTools.java
...k-data-ai-biz/src/main/java/com/ask/tools/ExcelTools.java
+149
-19
ConvertUtils.java
...data-ai-biz/src/main/java/com/ask/utils/ConvertUtils.java
+1
-4
科环集团电力运营日报模板.docx
...-ai/ask-data-ai-boot/src/main/resources/科环集团电力运营日报模板.docx
+0
-0
No files found.
ask-data-ai/ask-data-ai-api/src/main/java/com/ask/api/entity/AskHistoryCollectData.java
0 → 100644
View file @
e6672292
package
com
.
ask
.
api
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
java.time.LocalDateTime
;
@Slf4j
@Data
@TableName
(
value
=
"ask_history_collect_data"
)
@Schema
(
description
=
"点位历史表"
)
public
class
AskHistoryCollectData
{
// 路径
private
String
path
;
// 值
private
Double
value
;
// 时间戳
private
LocalDateTime
datetime
;
}
ask-data-ai/ask-data-ai-api/src/main/java/com/ask/api/entity/AskReportDict.java
0 → 100644
View file @
e6672292
package
com
.
ask
.
api
.
entity
;
import
com.ask.api.handle.JsonbTypeHandler
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
@Data
@TableName
(
value
=
"ask_report_dict"
,
autoResultMap
=
true
)
@Schema
(
description
=
"报表对照表"
)
public
class
AskReportDict
{
private
Long
id
;
// 类型
private
Integer
type
;
// 计算方法
private
Integer
calculationMethod
;
// 键
private
String
key
;
@TableField
(
typeHandler
=
JsonbTypeHandler
.
class
)
private
List
<
Map
<
String
,
Object
>>
params
;
@TableField
(
exist
=
false
)
private
List
<
Params
>
paramList
;
public
void
convertParamsToParamList
()
{
if
(
this
.
params
!=
null
)
{
this
.
paramList
=
new
ArrayList
<>();
for
(
Map
<
String
,
Object
>
map
:
this
.
params
)
{
Params
param
=
new
Params
();
if
(
map
.
containsKey
(
"type"
))
{
param
.
setType
((
Integer
)
map
.
get
(
"type"
));
}
if
(
map
.
containsKey
(
"param"
))
{
param
.
setParam
((
String
)
map
.
get
(
"param"
));
}
this
.
paramList
.
add
(
param
);
}
}
}
@Data
public
static
class
Params
{
private
Integer
type
;
private
String
param
;
}
}
ask-data-ai/ask-data-ai-biz/src/main/java/com/ask/mapper/AskHistoryCollectDataMapper.java
0 → 100644
View file @
e6672292
package
com
.
ask
.
mapper
;
import
com.ask.api.entity.AskHistoryCollectData
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Mapper
;
@Mapper
public
interface
AskHistoryCollectDataMapper
extends
BaseMapper
<
AskHistoryCollectData
>
{
}
\ No newline at end of file
ask-data-ai/ask-data-ai-biz/src/main/java/com/ask/mapper/AskReportDictMapper.java
0 → 100644
View file @
e6672292
package
com
.
ask
.
mapper
;
import
com.ask.api.entity.AskReportDict
;
import
com.ask.api.entity.AskVectorStore
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
public
interface
AskReportDictMapper
extends
BaseMapper
<
AskReportDict
>
{
}
\ No newline at end of file
ask-data-ai/ask-data-ai-biz/src/main/java/com/ask/tools/ExcelTools.java
View file @
e6672292
package
com
.
ask
.
tools
;
import
cn.hutool.json.JSONObject
;
import
com.ask.api.entity.AskHistoryCollectData
;
import
com.ask.api.entity.AskReportDict
;
import
com.ask.common.core.FileTemplate
;
import
com.ask.mapper.AskHistoryCollectDataMapper
;
import
com.ask.mapper.AskReportDictMapper
;
import
com.ask.utils.ConvertUtils
;
import
com.baomidou.mybatisplus.core.toolkit.CollectionUtils
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.ai.tool.annotation.Tool
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.stereotype.Component
;
import
java.sql.Date
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
...
...
@@ -18,7 +22,10 @@ import java.time.format.DateTimeFormatterBuilder;
import
java.time.format.SignStyle
;
import
java.time.temporal.ChronoField
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.concurrent.atomic.AtomicReference
;
@Component
@Slf4j
...
...
@@ -30,6 +37,15 @@ public class ExcelTools {
@Value
(
"${file.local.base-url:http://8.152.98.45/api}"
)
private
String
baseUrl
;
@Autowired
private
AskReportDictMapper
askReportDictMapper
;
@Autowired
private
AskHistoryCollectDataMapper
askHistoryCollectDataMapper
;
@Autowired
private
FileTemplate
fileTemplate
;
private
String
formatLocalDate
(
LocalDate
date
)
{
// 创建自定义格式器:2位年份.单/双位月.单/双位日
DateTimeFormatter
formatter
=
new
DateTimeFormatterBuilder
()
...
...
@@ -52,26 +68,140 @@ public class ExcelTools {
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-M-d"
);
LocalDate
date
=
LocalDate
.
parse
(
dateStr
,
formatter
);
String
dateFileStr
=
formatLocalDate
(
date
);
// 动态生成文件名
String
fileName
=
String
.
format
(
"科环集团电力运营日报(%s).docx"
,
dateFileStr
);
LocalDateTime
startTime
=
date
.
atTime
(
0
,
0
,
0
);
LocalDateTime
endTime
=
date
.
atTime
(
23
,
59
,
59
);
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<
String
,
Object
>();
paramMap
.
put
(
"year"
,
date
.
getYear
());
paramMap
.
put
(
"month"
,
date
.
getMonthValue
());
paramMap
.
put
(
"day"
,
date
.
getDayOfMonth
());
String
bucketName
=
"report"
;
boolean
result
=
convertUtils
.
fillWordLoop
(
fileName
,
"科环集团电力运营日报模板.docx"
,
paramMap
,
bucketName
);
JSONObject
jsonObject
=
new
JSONObject
();
if
(
result
){
jsonObject
.
set
(
"success"
,
true
);
jsonObject
.
set
(
"fileName"
,
fileName
);
jsonObject
.
set
(
"filePath"
,
baseUrl
+
"/admin/sys-file/"
+
bucketName
+
"/"
+
fileName
);
}
else
{
jsonObject
.
set
(
"success"
,
false
);
jsonObject
.
set
(
"fileName"
,
""
);
jsonObject
.
set
(
"filePath"
,
""
);
// 动态生成文件名
String
fileName
=
String
.
format
(
"科环集团电力运营日报(%s).docx"
,
dateFileStr
);
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
set
(
"success"
,
true
);
jsonObject
.
set
(
"fileName"
,
fileName
);
jsonObject
.
set
(
"filePath"
,
baseUrl
+
"/admin/sys-file/"
+
bucketName
+
"/"
+
fileName
);
// 载入Word文档
if
(
fileTemplate
.
isFileExists
(
bucketName
,
fileName
))
{
return
jsonObject
.
toString
();
}
Map
<
String
,
Object
>
paramMap
=
generateReport
(
startTime
,
endTime
);
log
.
info
(
"入参{}"
,
paramMap
);
boolean
result
=
convertUtils
.
fillWordLoop
(
fileName
,
"科环集团电力运营日报模板.docx"
,
paramMap
,
bucketName
);
if
(!
result
)
{
jsonObject
.
set
(
"success"
,
false
);
jsonObject
.
set
(
"fileName"
,
""
);
jsonObject
.
set
(
"filePath"
,
""
);
}
return
jsonObject
.
toString
();
}
public
Map
<
String
,
Object
>
generateReport
(
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"year"
,
startTime
.
getYear
());
paramMap
.
put
(
"month"
,
startTime
.
getMonthValue
());
paramMap
.
put
(
"day"
,
startTime
.
getDayOfMonth
());
List
<
AskReportDict
>
askReportDicts
=
askReportDictMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
AskReportDict
.
class
).
eq
(
AskReportDict:
:
getType
,
1
)
);
for
(
AskReportDict
askReportDict
:
askReportDicts
)
{
String
key
=
askReportDict
.
getKey
();
paramMap
.
put
(
key
,
""
);
askReportDict
.
convertParamsToParamList
();
List
<
AskReportDict
.
Params
>
params
=
askReportDict
.
getParamList
();
if
(
CollectionUtils
.
isEmpty
(
params
))
{
continue
;
}
switch
(
askReportDict
.
getType
())
{
case
1
:
handleType1
(
askReportDict
.
getKey
(),
params
,
paramMap
,
startTime
,
endTime
);
break
;
case
2
:
handleType2
(
askReportDict
.
getKey
(),
params
,
paramMap
,
startTime
,
endTime
);
break
;
case
3
:
handleType3
(
askReportDict
.
getKey
(),
params
,
paramMap
,
startTime
,
endTime
);
break
;
default
:
// Handle other types if necessary
break
;
}
}
return
paramMap
;
}
private
void
handleType1
(
String
key
,
List
<
AskReportDict
.
Params
>
params
,
Map
<
String
,
Object
>
paramMap
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
AskReportDict
.
Params
param
=
params
.
get
(
0
);
if
(
param
==
null
)
{
return
;
}
Double
value
=
getLatestValue
(
param
.
getParam
(),
startTime
,
endTime
);
if
(
value
!=
null
)
{
paramMap
.
put
(
key
,
value
);
}
}
private
void
handleType2
(
String
key
,
List
<
AskReportDict
.
Params
>
params
,
Map
<
String
,
Object
>
paramMap
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
if
(
params
.
size
()
<
2
)
{
return
;
}
Double
numerator
=
getParamValue
(
params
.
get
(
0
),
startTime
,
endTime
);
Double
denominator
=
getParamValue
(
params
.
get
(
1
),
startTime
,
endTime
);
if
(
numerator
==
null
||
denominator
==
null
||
denominator
==
0
)
{
return
;
}
double
result
=
Math
.
round
(
numerator
/
denominator
*
100.0
)
/
100.0
;
// 保留两位小数
paramMap
.
put
(
key
,
result
);
}
private
void
handleType3
(
String
key
,
List
<
AskReportDict
.
Params
>
params
,
Map
<
String
,
Object
>
paramMap
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
if
(
params
.
size
()
<
2
)
{
return
;
}
Double
numerator
=
getParamValue
(
params
.
get
(
0
),
startTime
,
endTime
);
Double
denominator
=
getParamValue
(
params
.
get
(
1
),
startTime
,
endTime
);
if
(
numerator
==
null
||
denominator
==
null
||
denominator
==
0
)
{
return
;
}
double
result
=
(
numerator
/
denominator
)
*
100
;
// 计算百分比
result
=
Math
.
round
(
result
*
100.0
)
/
100.0
;
// 保留两位小数
String
percentageResult
=
String
.
format
(
"%.2f%%"
,
result
);
// 格式化为百分比字符串
paramMap
.
put
(
key
,
percentageResult
);
}
private
Double
getParamValue
(
AskReportDict
.
Params
param
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
try
{
if
(
param
.
getType
()
==
1
)
{
return
getLatestValue
(
param
.
getParam
(),
startTime
,
endTime
);
}
else
{
return
Double
.
valueOf
(
param
.
getParam
());
}
}
catch
(
Exception
e
)
{
return
null
;
}
}
private
Double
getLatestValue
(
String
path
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
AskHistoryCollectData
data
=
askHistoryCollectDataMapper
.
selectOne
(
Wrappers
.
lambdaQuery
(
AskHistoryCollectData
.
class
)
.
eq
(
AskHistoryCollectData:
:
getPath
,
path
)
.
between
(
AskHistoryCollectData:
:
getDatetime
,
startTime
,
endTime
)
.
orderByDesc
(
AskHistoryCollectData:
:
getDatetime
)
.
last
(
"limit 1"
)
);
return
data
!=
null
?
data
.
getValue
()
:
null
;
}
}
ask-data-ai/ask-data-ai-biz/src/main/java/com/ask/utils/ConvertUtils.java
View file @
e6672292
...
...
@@ -36,10 +36,7 @@ public class ConvertUtils {
* @return {@link String} 返回OSS中的文件路径
*/
private
boolean
fillWord
(
String
fileName
,
String
templatePath
,
Map
<
String
,
Object
>
paramMap
,
String
bucketName
)
{
// 载入Word文档
if
(
fileTemplate
.
isFileExists
(
bucketName
,
fileName
))
{
return
true
;
}
Resource
resource
=
resourceLoader
.
getResource
(
"classpath:"
+
templatePath
);
// OSS中的文件路径
try
(
InputStream
resourceStream
=
resource
.
getInputStream
();
...
...
ask-data-ai/ask-data-ai-boot/src/main/resources/科环集团电力运营日报模板.docx
View file @
e6672292
No preview for this file type
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