Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
robot-server
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
inroi
robot-server
Commits
2f5482bc
提交
2f5482bc
authored
2月 08, 2023
作者:
李炎
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增通用导出excel接口
上级
75828b81
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
185 行增加
和
6 行删除
+185
-6
.gitignore
.gitignore
+1
-0
ExportModel.java
...ain/java/com/system/framework/core/excel/ExportModel.java
+35
-0
ExcelUtil.java
.../java/com/system/framework/core/excel/util/ExcelUtil.java
+22
-0
KingDeeCommonSyncConstants.java
...java/com/system/constants/KingDeeCommonSyncConstants.java
+13
-0
KingDeeGetController.java
...main/java/com/system/controller/KingDeeGetController.java
+44
-0
KingDeeCommonGetApi.java
...src/main/java/com/system/kingdee/KingDeeCommonGetApi.java
+8
-5
IKingDeeCommonGetService.java
...ain/java/com/system/serivce/IKingDeeCommonGetService.java
+8
-0
KingDeeCommonGetServiceImpl.java
.../com/system/serivce/impl/KingDeeCommonGetServiceImpl.java
+53
-0
KingDeeDataListInVo.java
...java/com/system/transfer/kingdee/KingDeeDataListInVo.java
+1
-1
没有找到文件。
.gitignore
浏览文件 @
2f5482bc
...
...
@@ -31,3 +31,4 @@ build/
### VS Code ###
.vscode/
/robot-system/src/test
robot-framework/robot-framework-core/src/main/java/com/system/framework/core/excel/ExportModel.java
0 → 100644
浏览文件 @
2f5482bc
package
com
.
system
.
framework
.
core
.
excel
;
import
java.util.List
;
public
class
ExportModel
{
private
String
name
;
private
List
<
List
<
String
>>
head
;
private
List
<
List
<
Object
>>
dataList
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
List
<
List
<
String
>>
getHead
()
{
return
head
;
}
public
void
setHead
(
List
<
List
<
String
>>
head
)
{
this
.
head
=
head
;
}
public
List
<
List
<
Object
>>
getDataList
()
{
return
dataList
;
}
public
void
setDataList
(
List
<
List
<
Object
>>
dataList
)
{
this
.
dataList
=
dataList
;
}
}
robot-framework/robot-framework-core/src/main/java/com/system/framework/core/excel/util/ExcelUtil.java
0 → 100644
浏览文件 @
2f5482bc
package
com
.
system
.
framework
.
core
.
excel
.
util
;
import
com.alibaba.excel.EasyExcel
;
import
com.system.framework.core.excel.ExportModel
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.net.URLEncoder
;
public
class
ExcelUtil
{
public
static
void
export
(
ExportModel
exportModel
,
HttpServletResponse
response
)
throws
IOException
{
// 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
response
.
setContentType
(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
);
response
.
setCharacterEncoding
(
"utf-8"
);
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
String
fileName
=
URLEncoder
.
encode
(
exportModel
.
getName
(),
"UTF-8"
).
replaceAll
(
"\\+"
,
"%20"
);
response
.
setHeader
(
"Content-disposition"
,
"attachment;filename*=utf-8''"
+
fileName
+
".xlsx"
);
EasyExcel
.
write
(
response
.
getOutputStream
()).
autoCloseStream
(
Boolean
.
FALSE
).
head
(
exportModel
.
getHead
()).
sheet
(
exportModel
.
getName
()).
doWrite
(
exportModel
.
getDataList
());
}
}
robot-system/src/main/java/com/system/constants/KingDeeCommonSyncConstants.java
浏览文件 @
2f5482bc
...
...
@@ -105,6 +105,19 @@ public class KingDeeCommonSyncConstants {
return
key
;
}
/**
* 封装本机映射金蝶的字段
*/
public
static
Map
<
String
,
String
>
encapsulationThirdPartyFieldCn
(
List
<
Map
<
String
,
String
>>
fieldList
)
{
Map
<
String
,
String
>
key
=
new
LinkedHashMap
<>();
for
(
Map
<
String
,
String
>
map
:
fieldList
)
{
String
thirdPartyFieldName
=
map
.
get
(
"thirdPartyFieldName"
);
String
thirdPartyField
=
map
.
get
(
"thirdPartyField"
);
key
.
put
(
thirdPartyFieldName
,
thirdPartyField
);
}
return
key
;
}
public
static
void
encapsulationOnWhole
(
List
<
List
<
Object
>>
list
,
List
<
Map
<
String
,
String
>>
fieldList
,
List
<
Map
<
String
,
Object
>>
result
)
{
for
(
List
<
Object
>
objectList
:
list
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
fieldList
.
size
());
...
...
robot-system/src/main/java/com/system/controller/KingDeeGetController.java
浏览文件 @
2f5482bc
package
com
.
system
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.system.framework.core.excel.ExportModel
;
import
com.system.framework.core.excel.util.ExcelUtil
;
import
com.system.serivce.IKingDeeCommonGetService
;
import
com.system.transfer.kingdee.KingDeeDataListInVo
;
import
com.system.transfer.response.RestResponse
;
...
...
@@ -12,6 +15,11 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author Inori
*/
...
...
@@ -30,5 +38,41 @@ public class KingDeeGetController {
return
kingDeeCommonGetService
.
kingDeeDataList
(
inVo
);
}
@ApiOperation
(
"金蝶通用查询"
)
@PostMapping
(
"/kingdee/data/export"
)
public
void
kingDeeDataExport
(
@RequestBody
@Validated
KingDeeDataListInVo
inVo
,
HttpServletResponse
response
)
throws
IOException
{
try
{
ExportModel
export
=
kingDeeCommonGetService
.
export
(
inVo
);
ExcelUtil
.
export
(
export
,
response
);
}
catch
(
Exception
e
)
{
// 重置response
response
.
reset
();
response
.
setContentType
(
"application/json"
);
response
.
setCharacterEncoding
(
"utf-8"
);
Map
<
String
,
String
>
map
=
new
HashMap
<>(
2
);
map
.
put
(
"status"
,
"failure"
);
map
.
put
(
"message"
,
"下载文件失败"
+
e
.
getMessage
());
response
.
getWriter
().
println
(
JSON
.
toJSONString
(
map
));
}
}
@ApiOperation
(
"金蝶通用查询"
)
@PostMapping
(
"/kingdee/data/export/all"
)
public
void
kingDeeDataExportAll
(
@RequestBody
@Validated
KingDeeDataListInVo
inVo
,
HttpServletResponse
response
)
throws
IOException
{
inVo
.
setAll
(
true
);
try
{
ExportModel
export
=
kingDeeCommonGetService
.
export
(
inVo
);
ExcelUtil
.
export
(
export
,
response
);
}
catch
(
Exception
e
)
{
// 重置response
response
.
reset
();
response
.
setContentType
(
"application/json"
);
response
.
setCharacterEncoding
(
"utf-8"
);
Map
<
String
,
String
>
map
=
new
HashMap
<>(
2
);
map
.
put
(
"status"
,
"failure"
);
map
.
put
(
"message"
,
"下载文件失败"
+
e
.
getMessage
());
response
.
getWriter
().
println
(
JSON
.
toJSONString
(
map
));
}
}
}
robot-system/src/main/java/com/system/kingdee/KingDeeCommonGetApi.java
浏览文件 @
2f5482bc
...
...
@@ -8,10 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
/**
* @author Inori
...
...
@@ -29,6 +26,12 @@ public class KingDeeCommonGetApi {
return
encapsulationIms
(
result
,
fieldList
,
config
.
get
(
"mesEntryName"
),
Integer
.
valueOf
(
config
.
get
(
"encapsulationFormat"
)));
}
public
List
<
List
<
Object
>>
getKingDeeList
(
Map
<
String
,
String
>
config
,
String
queueId
,
List
<
Map
<
String
,
String
>>
fieldList
,
Map
<
String
,
String
>
where
)
{
Map
<
String
,
String
>
key
=
KingDeeCommonSyncConstants
.
encapsulationKingDeeField
(
fieldList
);
List
<
List
<
Object
>>
result
=
kingDeeApi
.
getKingDeeData
(
config
,
queueId
,
key
,
where
);
return
result
;
}
/**
* 封装第三方字段
*/
...
...
@@ -37,7 +40,7 @@ public class KingDeeCommonGetApi {
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
String
errorName
=
"Errors"
;
if
(!
list
.
get
(
0
).
get
(
0
).
toString
().
contains
(
errorName
))
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
fieldList
.
size
());
Map
<
String
,
Object
>
map
=
new
Linked
HashMap
<>(
fieldList
.
size
());
List
<
Map
<
String
,
Object
>>
tempList
=
new
ArrayList
<>();
if
(
encapsulationFormat
==
1
)
{
...
...
robot-system/src/main/java/com/system/serivce/IKingDeeCommonGetService.java
浏览文件 @
2f5482bc
package
com
.
system
.
serivce
;
import
com.system.framework.core.excel.ExportModel
;
import
com.system.transfer.kingdee.KingDeeDataListInVo
;
import
com.system.transfer.response.RestResponse
;
...
...
@@ -16,5 +17,12 @@ public interface IKingDeeCommonGetService {
*/
RestResponse
kingDeeDataList
(
KingDeeDataListInVo
inVo
);
/**
* 金蝶通用导出
*
* @param inVo 条件
* @return 列表
*/
ExportModel
export
(
KingDeeDataListInVo
inVo
);
}
robot-system/src/main/java/com/system/serivce/impl/KingDeeCommonGetServiceImpl.java
浏览文件 @
2f5482bc
package
com
.
system
.
serivce
.
impl
;
import
com.system.constants.KingDeeCommonGetConstants
;
import
com.system.constants.KingDeeCommonSyncConstants
;
import
com.system.framework.core.excel.ExportModel
;
import
com.system.framework.core.exception.StarBosException
;
import
com.system.kingdee.KingDeeCommonGetApi
;
import
com.system.serivce.IKingDeeCommonGetService
;
import
com.system.transfer.kingdee.KingDeeDataListInVo
;
import
com.system.transfer.response.RestResponse
;
import
com.system.transfer.temp.KingDeeCommonGetListOutVo
;
import
com.system.utils.JsonUtil
;
import
com.system.utils.KingDeeUtil
;
import
com.system.utils.ProductLogUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
javax.validation.constraints.NotBlank
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -75,6 +80,54 @@ public class KingDeeCommonGetServiceImpl implements IKingDeeCommonGetService {
return
RestResponse
.
success
(
outVo
);
}
@Override
public
ExportModel
export
(
KingDeeDataListInVo
inVo
)
{
long
start
=
System
.
currentTimeMillis
();
String
queueId
=
inVo
.
getQueueId
();
Map
<
String
,
String
>
config
=
kingDeeCommonGetConstants
.
get
(
inVo
.
getDocType
());
if
(
CollectionUtils
.
isEmpty
(
config
))
{
throw
new
StarBosException
(
"docType为: "
+
inVo
.
getDocType
()
+
" 的表单ERP-MES标识不存在"
);
}
List
<
Object
>
tempList
=
JsonUtil
.
toList
(
config
.
get
(
"kingDeeFiledDetail"
),
Object
.
class
);
List
<
Map
<
String
,
String
>>
fieldList
=
tempList
.
stream
().
map
(
m
->
JsonUtil
.
toMap
(
JsonUtil
.
toString
(
m
),
String
.
class
,
String
.
class
)).
collect
(
Collectors
.
toList
());
Map
<
String
,
String
>
where
=
new
HashMap
<>(
5
);
if
(!
CollectionUtils
.
isEmpty
(
inVo
.
getData
()))
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
inVo
.
getData
().
entrySet
())
{
where
.
put
(
entry
.
getKey
(),
String
.
valueOf
(
entry
.
getValue
()));
}
}
this
.
setWhereDefaultRule
(
inVo
.
getDocType
(),
where
);
List
<
List
<
Object
>>
response
=
kingDeeCommonGetApi
.
getKingDeeList
(
config
,
queueId
,
fieldList
,
where
);
long
costTime
=
System
.
currentTimeMillis
()
-
start
;
if
(!
CollectionUtils
.
isEmpty
(
response
))
{
String
temp
=
"false"
;
String
errorName
=
"Errors"
;
if
(
response
.
get
(
0
).
get
(
0
).
toString
().
contains
(
errorName
))
{
String
message
=
KingDeeUtil
.
getMessage
(
response
.
get
(
0
).
get
(
0
));
throw
new
StarBosException
(
String
.
valueOf
(
message
));
}
}
Map
<
String
,
String
>
key
=
KingDeeCommonSyncConstants
.
encapsulationThirdPartyFieldCn
(
fieldList
);
List
<
List
<
String
>>
head
=
key
.
keySet
().
stream
().
map
(
m
->
new
ArrayList
()
{{
add
(
m
);
}}).
collect
(
Collectors
.
toList
());
List
<
List
<
Object
>>
dataList
=
response
;
if
(!
inVo
.
getAll
())
{
dataList
=
response
.
stream
().
skip
((
inVo
.
getPageNo
()
-
1
)
*
inVo
.
getPageSize
()).
limit
(
inVo
.
getPageSize
()).
collect
(
Collectors
.
toList
());
}
ExportModel
exportModel
=
new
ExportModel
();
exportModel
.
setName
(
inVo
.
getDocType
());
exportModel
.
setHead
(
head
);
exportModel
.
setDataList
(
dataList
);
return
exportModel
;
}
/**
* 设置默认where自定义查询过滤条件
* 注:此为该项目应急用使用,建议后续扩展
...
...
robot-system/src/main/java/com/system/transfer/kingdee/KingDeeDataListInVo.java
浏览文件 @
2f5482bc
...
...
@@ -43,5 +43,5 @@ public class KingDeeDataListInVo {
*/
private
Integer
pageSize
=
10
;
private
Boolean
all
=
false
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论