Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dcs-plan
Project
Project
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
INET-TWO
server
dcs-plan
Commits
f43aabd6
Commit
f43aabd6
authored
Sep 09, 2024
by
wangqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
采购计划导入导出功能开发(暂时还未开发完成,临时提交代码)
parent
2eb5a9b2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
340 additions
and
15 deletions
+340
-15
SearchUtil.java
...main/java/com/yonde/dcs/plan/common/utils/SearchUtil.java
+41
-0
ExtPuchasePlanExcelVO.java
...a/com/yonde/dcs/plan/common/vo/ExtPuchasePlanExcelVO.java
+3
-4
ExtPuchasePlanAttributeController.java
...an/core/controller/ExtPuchasePlanAttributeController.java
+31
-0
PurchasePlanExcelReadListenner.java
...cs/plan/core/listener/PurchasePlanExcelReadListenner.java
+153
-0
ExtPuchasePlanAttributeService.java
...dcs/plan/core/service/ExtPuchasePlanAttributeService.java
+8
-1
ExtPuchasePlanAttributeServiceImpl.java
...core/service/impl/ExtPuchasePlanAttributeServiceImpl.java
+104
-10
No files found.
dcs-plan-common/src/main/java/com/yonde/dcs/plan/common/utils/SearchUtil.java
0 → 100644
View file @
f43aabd6
package
com
.
yonde
.
dcs
.
plan
.
common
.
utils
;
import
com.yonde.dex.basedata.data.search.SearchItem
;
import
com.yonde.dex.basedata.data.search.SearchQueryBuilder
;
import
com.yonde.dex.basedata.data.search.SearchQueryCondition
;
public
class
SearchUtil
{
/**
* 构建查询条件
*
* @param key
* @param value
* @return
*/
public
static
SearchQueryCondition
buildQuery
(
String
key
,
SearchItem
.
Operator
operator
,
Object
value
)
{
return
SearchQueryBuilder
.
openBuild
()
.
openFilterBuilder
()
.
setItem
(
key
,
operator
,
value
)
.
builder
().
build
();
}
/**
* 构建带扩展属性的查询条件
*
* @param key
* @param value
* @param openAttr
* @return
*/
public
static
SearchQueryCondition
buildQueryWithOpenAttr
(
String
key
,
SearchItem
.
Operator
operator
,
Object
value
,
String
openAttr
)
{
return
SearchQueryBuilder
.
openBuild
()
.
setPropName
(
openAttr
)
.
openFilterBuilder
()
.
setItem
(
key
,
operator
,
value
)
.
builder
().
build
();
}
}
dcs-plan-common/src/main/java/com/yonde/dcs/plan/common/vo/ExtPuchasePlanExcelVO.java
View file @
f43aabd6
...
@@ -89,7 +89,7 @@ public class ExtPuchasePlanExcelVO {
...
@@ -89,7 +89,7 @@ public class ExtPuchasePlanExcelVO {
/**
/**
* 计划编码
* 计划编码
*/
*/
@ExcelProperty
(
value
=
{
"采购计划"
,
"计划编码*"
},
index
=
0
)
@ExcelProperty
(
value
=
{
"采购计划"
,
"计划编码*"
},
index
=
9
)
@ColumnWidth
(
20
)
@ColumnWidth
(
20
)
private
String
planCode
;
private
String
planCode
;
...
@@ -97,7 +97,7 @@ public class ExtPuchasePlanExcelVO {
...
@@ -97,7 +97,7 @@ public class ExtPuchasePlanExcelVO {
/**
/**
* 备注
* 备注
*/
*/
@ExcelProperty
(
value
=
{
"采购计划"
,
"备注*"
},
index
=
9
)
@ExcelProperty
(
value
=
{
"采购计划"
,
"备注*"
},
index
=
10
)
@ColumnWidth
(
20
)
@ColumnWidth
(
20
)
private
String
note
;
private
String
note
;
...
@@ -111,9 +111,8 @@ public class ExtPuchasePlanExcelVO {
...
@@ -111,9 +111,8 @@ public class ExtPuchasePlanExcelVO {
}
}
EasyExcel
.
write
(
EasyExcel
.
write
(
"F:\\yangyi\\项目\\清华核研院\\核研院设计文档及原型\\采购计划导入模板.xlsx"
,
ExtPuchasePlanExcelVO
.
class
)
"F:\\yangyi\\项目\\清华核研院\\核研院设计文档及原型\\采购计划导入模板
333
.xlsx"
,
ExtPuchasePlanExcelVO
.
class
)
.
sheet
(
"采购计划"
).
doWrite
(
list
);
.
sheet
(
"采购计划"
).
doWrite
(
list
);
}
}
}
}
...
...
dcs-plan-core/src/main/java/com/yonde/dcs/plan/core/controller/ExtPuchasePlanAttributeController.java
View file @
f43aabd6
...
@@ -3,6 +3,8 @@ package com.yonde.dcs.plan.core.controller;
...
@@ -3,6 +3,8 @@ package com.yonde.dcs.plan.core.controller;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
import
com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO
;
import
com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
...
@@ -13,8 +15,11 @@ import com.yonde.dcs.plan.core.service.ExtPuchasePlanAttributeService;
...
@@ -13,8 +15,11 @@ import com.yonde.dcs.plan.core.service.ExtPuchasePlanAttributeService;
import
com.yonde.dex.basedata.entity.api.ApiResult
;
import
com.yonde.dex.basedata.entity.api.ApiResult
;
import
com.yonde.dcs.plan.core.controller.shadow.ExtPuchasePlanAttributeControllerShadow
;
import
com.yonde.dcs.plan.core.controller.shadow.ExtPuchasePlanAttributeControllerShadow
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
com.yonde.dex.basedata.auth.annos.BasePermission
;
import
com.yonde.dex.basedata.auth.annos.BasePermission
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.multipart.MultipartFile
;
/**
/**
* @description: ExtPuchasePlanAttribute-Controller
* @description: ExtPuchasePlanAttribute-Controller
...
@@ -30,6 +35,32 @@ import org.springframework.stereotype.Controller;
...
@@ -30,6 +35,32 @@ import org.springframework.stereotype.Controller;
public
class
ExtPuchasePlanAttributeController
<
V
extends
ExtPuchasePlanAttributeVO
,
S
extends
ExtPuchasePlanAttributeService
<
V
>>
extends
ExtPuchasePlanAttributeControllerShadow
<
V
,
S
>
{
public
class
ExtPuchasePlanAttributeController
<
V
extends
ExtPuchasePlanAttributeVO
,
S
extends
ExtPuchasePlanAttributeService
<
V
>>
extends
ExtPuchasePlanAttributeControllerShadow
<
V
,
S
>
{
@Autowired
private
ExtPuchasePlanAttributeService
extPuchasePlanAttributeService
;
/**
* 导入采购计划
*
* @param uploadFile
* @return
* @throws IOException
*/
@ApiOperation
(
"导入采购计划"
)
@PostMapping
(
value
=
"/insertPurchasePlan"
)
public
ApiResult
insertPlan
(
@RequestParam
(
"file"
)
MultipartFile
uploadFile
)
throws
IOException
{
return
ApiResult
.
ok
(
extPuchasePlanAttributeService
.
ExportPurchasePlan
(
uploadFile
.
getInputStream
()),
"采购计划导入成功"
);
}
/**
* 导出计划
* @param response
* @param ids
* @throws IOException
*/
@ApiOperation
(
value
=
"导出采购计划计划"
,
notes
=
"导出计划"
,
httpMethod
=
"GET"
)
@GetMapping
(
value
=
"/exportPurchasePlan"
)
public
ApiResult
exportPlan
(
HttpServletResponse
response
,
@RequestParam
(
"ids"
)
List
<
Long
>
ids
)
throws
IOException
{
return
ApiResult
.
ok
(
extPuchasePlanAttributeService
.
exportPurchasePlanFile
(
response
,
ids
),
"采购计划导出成功"
);
}
}
}
dcs-plan-core/src/main/java/com/yonde/dcs/plan/core/listener/PurchasePlanExcelListenner.java
→
dcs-plan-core/src/main/java/com/yonde/dcs/plan/core/listener/PurchasePlanExcel
Read
Listenner.java
View file @
f43aabd6
package
com
.
yonde
.
dcs
.
plan
.
core
.
listener
;
package
com
.
yonde
.
dcs
.
plan
.
core
.
listener
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.alibaba.excel.util.ListUtils
;
import
com.alibaba.excel.util.ListUtils
;
import
com.yonde.dcs.plan.common.constants.Constants
;
import
com.yonde.dcs.plan.common.constants.Constants
;
import
com.yonde.dcs.plan.common.utils.SearchUtil
;
import
com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO
;
import
com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO
;
import
com.yonde.dcs.plan.common.vo.ExtPuchasePlanExcelVO
;
import
com.yonde.dcs.plan.common.vo.ExtPuchasePlanExcelVO
;
import
com.yonde.dcs.plan.core.service.ExtDistributeRecordService
;
import
com.yonde.dcs.plan.core.service.ExtDistributeRecordService
;
import
com.yonde.dcs.plan.core.service.ExtPuchasePlanAttributeService
;
import
com.yonde.dcs.plan.core.service.ExtPuchasePlanAttributeService
;
import
com.yonde.dex.basedata.data.search.SearchItem
;
import
com.yonde.dex.basedata.data.search.SearchItems
;
import
com.yonde.dex.basedata.data.search.SearchQueryCondition
;
import
com.yonde.dex.basedata.entity.data.DxPageImpl
;
import
com.yonde.dex.basedata.entity.data.OperatorType
;
import
com.yonde.dex.basedata.entity.data.OperatorType
;
import
com.yonde.dex.basedata.exception.DxBusinessException
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
@Component
@Component
@Slf4j
@Slf4j
public
class
PurchasePlanExcelListenner
extends
AnalysisEventListener
<
ExtPuchasePlanExcelVO
>
{
public
class
PurchasePlanExcel
Read
Listenner
extends
AnalysisEventListener
<
ExtPuchasePlanExcelVO
>
{
@Autowired
@Autowired
private
ExtPuchasePlanAttributeService
extPuchasePlanAttributeService
;
private
ExtPuchasePlanAttributeService
extPuchasePlanAttributeService
;
...
@@ -36,21 +46,9 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase
...
@@ -36,21 +46,9 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase
@Override
@Override
public
void
invoke
(
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
,
AnalysisContext
analysisContext
)
{
public
void
invoke
(
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
,
AnalysisContext
analysisContext
)
{
ExtPuchasePlanAttributeVO
extPuchasePlanAttributeVO
=
new
ExtPuchasePlanAttributeVO
();
log
.
info
(
"解析到一条数据:{}"
,
extPuchasePlanExcelVO
);
log
.
info
(
"解析到一条数据:{}"
,
extPuchasePlanExcelVO
);
//todo 需要处理采购计划数据到数据库
cachedDataList
.
add
(
extPuchasePlanExcelVO
);
//根据excle中操作符执行 新增、更新、删除
if
(
Constants
.
EXCEL_ADD
.
equals
(
extPuchasePlanExcelVO
.
getOperation
())){
extPuchasePlanAttributeVO
.
setOperator
(
OperatorType
.
ADD
);
extPuchasePlanAttributeService
.
saveRecursion
(
transformObject
(
extPuchasePlanAttributeVO
,
extPuchasePlanExcelVO
));
}
else
if
(
Constants
.
EXCEL_UPDATE
.
equals
(
extPuchasePlanExcelVO
.
getOperation
())){
extPuchasePlanAttributeVO
.
setOperator
(
OperatorType
.
MODIFY
);
}
else
if
(
Constants
.
EXCEL_DELETE
.
equals
(
extPuchasePlanExcelVO
.
getOperation
())){
extPuchasePlanAttributeVO
.
setOperator
(
OperatorType
.
REMOVE
);
}
else
{
log
.
info
(
"sheet={} ,操作符={}无效!"
,
analysisContext
.
readSheetHolder
().
getSheetName
(),
extPuchasePlanExcelVO
.
getOperation
());
}
}
}
...
@@ -58,10 +56,34 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase
...
@@ -58,10 +56,34 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase
public
void
doAfterAllAnalysed
(
AnalysisContext
analysisContext
)
{
public
void
doAfterAllAnalysed
(
AnalysisContext
analysisContext
)
{
// 收尾工作,处理剩下的缓存数据。。。
// 收尾工作,处理剩下的缓存数据。。。
log
.
info
(
"sheet={} 所有数据解析完成!"
,
analysisContext
.
readSheetHolder
().
getSheetName
());
log
.
info
(
"sheet={} 所有数据解析完成!"
,
analysisContext
.
readSheetHolder
().
getSheetName
());
//校验表格中的数据是否合法
List
<
StringBuffer
>
errList
=
checkPurchasePlanExcelData
();
if
(
errList
.
size
()
>
0
)
{
throw
new
DxBusinessException
(
"-1"
,
"导入采购计划数据有误!!"
+
errList
.
toString
());
}
for
(
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
:
cachedDataList
)
{
ExtPuchasePlanAttributeVO
extPuchasePlanAttributeVO
=
new
ExtPuchasePlanAttributeVO
();
//讲excel数据转换成VO对象
transformObject
(
extPuchasePlanAttributeVO
,
extPuchasePlanExcelVO
);
//根据excle中操作符执行 新增、更新、删除
if
(
Constants
.
EXCEL_ADD
.
equals
(
extPuchasePlanExcelVO
.
getOperation
()))
{
extPuchasePlanAttributeVO
.
setOperator
(
OperatorType
.
ADD
);
extPuchasePlanAttributeService
.
saveRecursion
(
transformObject
(
extPuchasePlanAttributeVO
,
extPuchasePlanExcelVO
));
}
else
if
(
Constants
.
EXCEL_UPDATE
.
equals
(
extPuchasePlanExcelVO
.
getOperation
()))
{
extPuchasePlanAttributeVO
.
setOperator
(
OperatorType
.
MODIFY
);
}
else
if
(
Constants
.
EXCEL_DELETE
.
equals
(
extPuchasePlanExcelVO
.
getOperation
()))
{
extPuchasePlanAttributeVO
.
setOperator
(
OperatorType
.
REMOVE
);
}
else
{
log
.
info
(
"sheet={} ,操作符={}无效!"
,
analysisContext
.
readSheetHolder
().
getSheetName
(),
extPuchasePlanExcelVO
.
getOperation
());
}
}
}
}
/**
/**
*
* @param exception
* @param exception
* @param context
* @param context
* @throws Exception
* @throws Exception
...
@@ -74,10 +96,11 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase
...
@@ -74,10 +96,11 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase
/**
/**
* 将excel中的数据转换成VO对象
* 将excel中的数据转换成VO对象
*
* @param extPuchasePlanAttributeVO
* @param extPuchasePlanAttributeVO
* @param extPuchasePlanExcelVO
* @param extPuchasePlanExcelVO
*/
*/
public
ExtPuchasePlanAttributeVO
transformObject
(
ExtPuchasePlanAttributeVO
extPuchasePlanAttributeVO
,
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
)
{
public
ExtPuchasePlanAttributeVO
transformObject
(
ExtPuchasePlanAttributeVO
extPuchasePlanAttributeVO
,
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
)
{
extPuchasePlanAttributeVO
.
setOutsourceProjectName
(
extPuchasePlanExcelVO
.
getOutsourceProjectName
());
extPuchasePlanAttributeVO
.
setOutsourceProjectName
(
extPuchasePlanExcelVO
.
getOutsourceProjectName
());
extPuchasePlanAttributeVO
.
setPurDesignFileSubmitTime
(
extPuchasePlanExcelVO
.
getPurDesignFileSubmitTime
());
extPuchasePlanAttributeVO
.
setPurDesignFileSubmitTime
(
extPuchasePlanExcelVO
.
getPurDesignFileSubmitTime
());
extPuchasePlanAttributeVO
.
setContractSigningTime
(
extPuchasePlanExcelVO
.
getContractActualSigningTime
());
extPuchasePlanAttributeVO
.
setContractSigningTime
(
extPuchasePlanExcelVO
.
getContractActualSigningTime
());
...
@@ -93,12 +116,38 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase
...
@@ -93,12 +116,38 @@ public class PurchasePlanExcelListenner extends AnalysisEventListener<ExtPuchase
/**
/**
* 检查采购计划数据的合法性
* 检查采购计划数据的合法性
*
@param extPuchasePlanExcelVO
*
* @return
* @return
*/
*/
public
StringBuffer
checkPurchasePlanExcelData
(
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
){
public
List
<
StringBuffer
>
checkPurchasePlanExcelData
()
{
List
<
StringBuffer
>
errorList
=
new
ArrayList
<>();
if
(
cachedDataList
.
size
()
>
0
)
{
for
(
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
:
cachedDataList
)
{
StringBuffer
errString
=
new
StringBuffer
();
if
(
StringUtils
.
isEmpty
(
extPuchasePlanExcelVO
.
getPlanCode
()))
{
errString
.
append
(
"项目代号为:"
+
extPuchasePlanExcelVO
.
getProjectCode
()
+
"的计划编码不能为空"
);
errorList
.
add
(
errString
);
}
else
{
if
(
Constants
.
EXCEL_ADD
.
equals
(
extPuchasePlanExcelVO
.
getOperation
())){
DxPageImpl
dxPage
=
extPuchasePlanAttributeService
.
findRecursion
(
SearchUtil
.
buildQuery
(
"planCode"
,
SearchItem
.
Operator
.
EQ
,
extPuchasePlanExcelVO
.
getPlanCode
()));
if
(
dxPage
.
getTotalElements
()
>
0
){
errString
.
append
(
"计划编码:"
+
extPuchasePlanExcelVO
.
getPlanCode
()
+
"已存在,不能重复导入!!"
);
errorList
.
add
(
errString
);
}
}
}
}
}
return
null
;
return
errorList
;
}
}
// public static void main(String[] args) {
// File file = new File("F:\\yangyi\\项目\\清华核研院\\核研院设计文档及原型\\采购计划导入模板333.xlsx");
// EasyExcel.read("F:\\yangyi\\项目\\清华核研院\\核研院设计文档及原型\\采购计划导入模板333.xlsx", ExtPuchasePlanExcelVO.class,
// new PurchasePlanExcelReadListenner())
// .sheet()
// .doRead();
// }
}
}
dcs-plan-core/src/main/java/com/yonde/dcs/plan/core/service/ExtPuchasePlanAttributeService.java
View file @
f43aabd6
...
@@ -3,7 +3,11 @@ package com.yonde.dcs.plan.core.service;
...
@@ -3,7 +3,11 @@ package com.yonde.dcs.plan.core.service;
import
com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO
;
import
com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO
;
import
com.yonde.dcs.plan.core.service.shadow.ExtPuchasePlanAttributeServiceShadow
;
import
com.yonde.dcs.plan.core.service.shadow.ExtPuchasePlanAttributeServiceShadow
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.List
;
/**
/**
* @description: ExtPuchasePlanAttribute-service
* @description: ExtPuchasePlanAttribute-service
...
@@ -14,5 +18,8 @@ import java.io.File;
...
@@ -14,5 +18,8 @@ import java.io.File;
public
interface
ExtPuchasePlanAttributeService
<
V
extends
ExtPuchasePlanAttributeVO
>
extends
ExtPuchasePlanAttributeServiceShadow
<
V
>
{
public
interface
ExtPuchasePlanAttributeService
<
V
extends
ExtPuchasePlanAttributeVO
>
extends
ExtPuchasePlanAttributeServiceShadow
<
V
>
{
public
String
ExportPurchasePlan
(
File
file
);
public
String
ExportPurchasePlan
(
InputStream
inputStream
);
public
String
exportPurchasePlanFile
(
HttpServletResponse
response
,
List
<
String
>
planCodeList
)
throws
IOException
;
}
}
dcs-plan-core/src/main/java/com/yonde/dcs/plan/core/service/impl/ExtPuchasePlanAttributeServiceImpl.java
View file @
f43aabd6
package
com
.
yonde
.
dcs
.
plan
.
core
.
service
.
impl
;
package
com
.
yonde
.
dcs
.
plan
.
core
.
service
.
impl
;
import
cn.hutool.core.io.FileUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy
;
import
com.yonde.dcs.plan.common.vo.ExtPuchasePlanExcelVO
;
import
com.yonde.dcs.plan.core.listener.PurchasePlanExcelReadListenner
;
import
com.yonde.dcs.plan.core.util.FileUtils
;
import
com.yonde.dex.basedata.data.search.SearchItem
;
import
com.yonde.dex.basedata.data.search.SearchItems
;
import
com.yonde.dex.basedata.data.search.SearchQueryCondition
;
import
com.yonde.dex.basedata.entity.api.ApiResult
;
import
com.yonde.dex.basedata.entity.api.CustomMultipartFile
;
import
com.yonde.dex.basedata.entity.data.DxPageImpl
;
import
com.yonde.dex.basedata.exception.DxBusinessException
;
import
com.yonde.dex.dfs.feign.FileManagerFeignService
;
import
com.yonde.dex.dfs.feign.RepoFileFeignService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
java.io.File
;
import
java.io.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO
;
import
com.yonde.dcs.plan.common.vo.ExtPuchasePlanAttributeVO
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -13,28 +31,104 @@ import org.springframework.web.bind.annotation.*;
...
@@ -13,28 +31,104 @@ import org.springframework.web.bind.annotation.*;
import
com.yonde.dcs.plan.core.service.ExtPuchasePlanAttributeService
;
import
com.yonde.dcs.plan.core.service.ExtPuchasePlanAttributeService
;
import
com.yonde.dcs.plan.core.repository.ExtPuchasePlanAttributeRepository
;
import
com.yonde.dcs.plan.core.repository.ExtPuchasePlanAttributeRepository
;
import
com.yonde.dcs.plan.entity.po.ExtPuchasePlanAttribute
;
import
com.yonde.dcs.plan.entity.po.ExtPuchasePlanAttribute
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
/**
/**
* @description: ExtPuchasePlanAttribute-ServiceImpl
* @description: ExtPuchasePlanAttribute-ServiceImpl
* @author: dexadmin
* @author: dexadmin
* @version: V
* @version: V
* @date: 2024-8-29 17:14:49
* @date: 2024-8-29 17:14:49
**/
**/
@Slf4j
@Slf4j
@Service
(
ExtPuchasePlanAttributeServiceImpl
.
BEAN_NAME
)
@Service
(
ExtPuchasePlanAttributeServiceImpl
.
BEAN_NAME
)
public
class
ExtPuchasePlanAttributeServiceImpl
<
V
extends
ExtPuchasePlanAttributeVO
>
implements
ExtPuchasePlanAttributeService
<
V
>{
public
class
ExtPuchasePlanAttributeServiceImpl
<
V
extends
ExtPuchasePlanAttributeVO
>
implements
ExtPuchasePlanAttributeService
<
V
>
{
public
static
final
String
BEAN_NAME
=
"extPuchasePlanAttributeServiceImpl"
;
public
static
final
String
BEAN_NAME
=
"extPuchasePlanAttributeServiceImpl"
;
@Autowired
@Autowired
ExtPuchasePlanAttributeRepository
<
ExtPuchasePlanAttribute
>
extPuchasePlanAttributeRepository
;
private
ExtPuchasePlanAttributeRepository
<
ExtPuchasePlanAttribute
>
extPuchasePlanAttributeRepository
;
@Autowired
private
RepoFileFeignService
repoFileFeignService
;
@Autowired
private
FileManagerFeignService
fileManagerFeignService
;
@Override
public
String
ExportPurchasePlan
(
InputStream
inputStream
)
{
EasyExcel
.
read
(
inputStream
,
ExtPuchasePlanExcelVO
.
class
,
new
PurchasePlanExcelReadListenner
())
.
sheet
()
.
doRead
();
return
ApiResult
.
SUCCESS
;
}
@Override
@Override
public
String
ExportPurchasePlan
(
File
file
)
{
public
String
exportPurchasePlanFile
(
HttpServletResponse
response
,
List
<
String
>
Ids
)
throws
IOException
{
InputStream
inputStream
=
null
;
CustomMultipartFile
multipartFile
=
null
;
SearchQueryCondition
condition
=
SearchQueryCondition
.
builder
()
.
searchItems
(
SearchItems
.
builder
()
.
item
(
new
SearchItem
(
"id"
,
SearchItem
.
Operator
.
IN
,
Ids
,
null
))
.
build
())
.
build
();
//根据批量计划编码获取计划集合
DxPageImpl
<
V
>
purchasePlanPage
=
this
.
findRecursion
(
condition
);
if
(
CollectionUtils
.
isNotEmpty
(
purchasePlanPage
.
getContent
()))
{
List
<
V
>
content
=
purchasePlanPage
.
getContent
();
//数据转换,将PO转换成EXCEL-VO;
List
<
ExtPuchasePlanExcelVO
>
extPuchasePlanExcelVOList
=
transformationObject
(
content
);
try
{
multipartFile
=
fileManagerFeignService
.
feignDownloadIO
(
1626790903997L
);
}
catch
(
IOException
e
)
{
log
.
info
(
"[接口单] >>> 文件服务下载为文件:{}--失败!"
,
1626790903997L
);
throw
new
DxBusinessException
(
"500"
,
"文件服务下载文件失败:"
+
1626790903997L
);
}
try
{
inputStream
=
new
ByteArrayInputStream
(
multipartFile
.
getBytes
());
}
catch
(
IOException
e
)
{
log
.
info
(
"[接口单] >>> 文件服务下载的文件:{}--转换为输入流失败!"
,
1626790903997L
);
throw
new
DxBusinessException
(
"500"
,
"文件服务下载的文件转换为输入流失败:"
+
1626790903997L
);
}
File
file
=
new
File
(
ExtPuchasePlanAttributeServiceImpl
.
class
.
getResource
(
""
).
getPath
());
String
filePath
=
file
.
getAbsolutePath
()+
"采购计划列表.xlsx"
;
FileUtils
.
inputToFile
(
inputStream
,
filePath
);
//向表格中写入数据
EasyExcel
.
write
(
filePath
,
ExtPuchasePlanExcelVO
.
class
)
.
registerWriteHandler
(
new
LongestMatchColumnWidthStyleStrategy
())
.
sheet
(
"采购计划列表"
).
doWrite
(
extPuchasePlanExcelVOList
);
//导出数据
FileUtils
.
exportFile
(
response
,
new
FileInputStream
(
filePath
),
"application/vnd.ms-excel;charset=utf-8"
,
"采购计划.xlsx"
);
FileUtil
.
del
(
filePath
);
}
else
{
log
.
info
(
"根据计划ids:"
+
Ids
.
toString
()
+
"未查到相关数据"
);
}
return
ApiResult
.
SUCCESS
;
}
return
null
;
public
List
<
ExtPuchasePlanExcelVO
>
transformationObject
(
List
<
V
>
content
)
{
List
<
ExtPuchasePlanExcelVO
>
extPuchasePlanExcelVOList
=
new
ArrayList
<>();
for
(
V
extPuchasePlanAttribute
:
content
)
{
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
=
new
ExtPuchasePlanExcelVO
();
extPuchasePlanExcelVO
.
setOutsourceProjectName
(
extPuchasePlanAttribute
.
getOutsourceProjectName
());
extPuchasePlanExcelVO
.
setPurDesignFileSubmitTime
(
extPuchasePlanAttribute
.
getPurDesignFileSubmitTime
());
extPuchasePlanExcelVO
.
setContractActualSigningTime
(
extPuchasePlanAttribute
.
getContractActualSigningTime
());
extPuchasePlanExcelVO
.
setContractActualDeliveryTime
(
extPuchasePlanAttribute
.
getContractActualDeliveryTime
());
extPuchasePlanExcelVO
.
setPurDesignFileManager
(
extPuchasePlanAttribute
.
getPurDesignFileManager
());
extPuchasePlanExcelVO
.
setPurchaseBudget
(
extPuchasePlanAttribute
.
getPurchaseBudget
());
extPuchasePlanExcelVO
.
setSecretCode
(
extPuchasePlanAttribute
.
getSecretCode
());
extPuchasePlanExcelVO
.
setPlanCode
(
extPuchasePlanAttribute
.
getPlanCode
());
extPuchasePlanExcelVO
.
setNote
(
extPuchasePlanAttribute
.
getNote
());
extPuchasePlanExcelVOList
.
add
(
extPuchasePlanExcelVO
);
}
return
extPuchasePlanExcelVOList
;
}
}
}
}
...
...
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