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
f23ce0cf
Commit
f23ce0cf
authored
Sep 10, 2024
by
wangqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
采购计划导入功能开发(已测试ok)
parent
13c8d106
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
147 additions
and
33 deletions
+147
-33
Constants.java
...n/java/com/yonde/dcs/plan/common/constants/Constants.java
+1
-0
PurchasePlanExcelReadListenner.java
...cs/plan/core/listener/PurchasePlanExcelReadListenner.java
+54
-33
CommonUtils.java
...c/main/java/com/yonde/dcs/plan/core/util/CommonUtils.java
+51
-0
SearchUtil.java
...rc/main/java/com/yonde/dcs/plan/core/util/SearchUtil.java
+41
-0
No files found.
dcs-plan-common/src/main/java/com/yonde/dcs/plan/common/constants/Constants.java
View file @
f23ce0cf
...
...
@@ -407,4 +407,5 @@ public class Constants {
public
static
final
String
PURCHASE_PLAN_EXCEL_NAME
=
"\\采购计划列表.xlsx"
;
public
static
final
String
PURCHASE_PLAN_TEMP_FILE_CODE_NAME
=
"采购计划001模板"
;
}
dcs-plan-core/src/main/java/com/yonde/dcs/plan/core/listener/PurchasePlanExcelReadListenner.java
View file @
f23ce0cf
package
com
.
yonde
.
dcs
.
plan
.
core
.
listener
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.alibaba.excel.util.ListUtils
;
import
com.yonde.dcs.document.common.entity.vo.DxDocumentVO
;
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.ExtPuchasePlanExcelVO
;
import
com.yonde.dcs.plan.core.service.ExtDistributeRecordService
;
import
com.yonde.dcs.plan.core.service.ExtPuchasePlanAttributeService
;
import
com.yonde.dcs.plan.core.util.CommonUtils
;
import
com.yonde.dcs.plan.entity.po.ExtPuchasePlanAttribute
;
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.exception.DxBusinessException
;
import
com.yonde.dex.dao.service.util.ApplicationContextUtil
;
import
com.yonde.dex.dao.service.util.DxPageUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.ObjectUtils
;
import
java
.io.File
;
import
java
x.servlet.ServletContextListener
;
import
java.util.ArrayList
;
import
java.util.List
;
@Component
@Slf4j
public
class
PurchasePlanExcelReadListenner
extends
AnalysisEventListener
<
ExtPuchasePlanExcelVO
>
{
public
class
PurchasePlanExcelReadListenner
extends
AnalysisEventListener
<
ExtPuchasePlanExcelVO
>
implements
ServletContextListener
{
@Autowired
private
ExtPuchasePlanAttributeService
extPuchasePlanAttributeService
;
...
...
@@ -43,6 +45,9 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
*/
private
List
<
ExtPuchasePlanExcelVO
>
cachedDataList
=
ListUtils
.
newArrayListWithExpectedSize
(
BATCH_COUNT
);
public
PurchasePlanExcelReadListenner
()
{
this
.
extPuchasePlanAttributeService
=
ApplicationContextUtil
.
getBean
(
ExtPuchasePlanAttributeService
.
class
);
}
@Override
public
void
invoke
(
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
,
AnalysisContext
analysisContext
)
{
...
...
@@ -64,18 +69,22 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
}
for
(
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
:
cachedDataList
)
{
ExtPuchasePlanAttributeVO
extPuchasePlanAttributeVO
=
new
ExtPuchasePlanAttributeVO
();
//
讲
excel数据转换成VO对象
//
将
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
);
extPuchasePlanAttributeService
.
saveRecursion
(
extPuchasePlanAttributeVO
);
}
else
if
(
Constants
.
EXCEL_UPDATE
.
equals
(
extPuchasePlanExcelVO
.
getOperation
()))
{
//更新
//根据计划编码获取采购计划
ExtPuchasePlanAttributeVO
purPlanForDB
=
getPurchasePlanByPlanCode
(
extPuchasePlanExcelVO
.
getPlanCode
());
purPlanForDB
.
setOperator
(
OperatorType
.
MODIFY
);
extPuchasePlanAttributeService
.
saveRecursion
(
transformObject
(
purPlanForDB
,
extPuchasePlanExcelVO
));
}
else
if
(
Constants
.
EXCEL_DELETE
.
equals
(
extPuchasePlanExcelVO
.
getOperation
()))
{
//删除;
//根据计划编码获取采购计划
ExtPuchasePlanAttributeVO
purPlanForDB
=
getPurchasePlanByPlanCode
(
extPuchasePlanExcelVO
.
getPlanCode
());
purPlanForDB
.
setOperator
(
OperatorType
.
REMOVE
);
extPuchasePlanAttributeService
.
remove
(
purPlanForDB
.
getId
());
}
else
{
log
.
info
(
"sheet={} ,操作符={}无效!"
,
analysisContext
.
readSheetHolder
().
getSheetName
(),
extPuchasePlanExcelVO
.
getOperation
());
}
...
...
@@ -107,7 +116,9 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
extPuchasePlanAttributeVO
.
setContractDeliveryTime
(
extPuchasePlanExcelVO
.
getContractActualDeliveryTime
());
extPuchasePlanAttributeVO
.
setPurDesignFileManager
(
extPuchasePlanExcelVO
.
getPurDesignFileManager
());
extPuchasePlanAttributeVO
.
setPurchaseBudget
(
extPuchasePlanExcelVO
.
getPurchaseBudget
());
extPuchasePlanAttributeVO
.
setSecretCode
(
extPuchasePlanExcelVO
.
getSecretCode
());
//获取密级code
String
secretCode
=
CommonUtils
.
searchDictDataByDictCode
(
Constants
.
SECRET_CODE
,
extPuchasePlanExcelVO
.
getSecretCode
());
extPuchasePlanAttributeVO
.
setSecretCode
(
secretCode
);
extPuchasePlanAttributeVO
.
setPlanCode
(
extPuchasePlanExcelVO
.
getPlanCode
());
extPuchasePlanAttributeVO
.
setNote
(
extPuchasePlanExcelVO
.
getNote
());
//todo wq:excel中的项目代号对应项目属性中什么?
...
...
@@ -124,17 +135,18 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
if
(
cachedDataList
.
size
()
>
0
)
{
for
(
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
:
cachedDataList
)
{
StringBuffer
errString
=
new
StringBuffer
();
if
(
StringUtils
.
isEmpty
(
extPuchasePlanExcelVO
.
getPlanCode
()))
{
errString
.
append
(
"项目代号为:"
+
extPuchasePlanExcelVO
.
getProjectCode
()
+
"的计划编码不能为空"
);
if
(
Constants
.
EXCEL_ADD
.
equals
(
extPuchasePlanExcelVO
.
getOperation
())
&&
StringUtils
.
isNotEmpty
(
extPuchasePlanExcelVO
.
getPlanCode
())){
ExtPuchasePlanAttributeVO
extPuchasePlanAttributeVO
=
getPurchasePlanByPlanCode
(
extPuchasePlanExcelVO
.
getPlanCode
());
if
(!
ObjectUtils
.
isEmpty
(
extPuchasePlanAttributeVO
)){
errString
.
append
(
"新增计划编码:"
+
extPuchasePlanExcelVO
.
getPlanCode
()
+
"已存在,不能重复导入!!"
);
errorList
.
add
(
errString
);
}
}
else
if
(
Constants
.
EXCEL_UPDATE
.
equals
(
extPuchasePlanExcelVO
.
getOperation
())
&&
StringUtils
.
isEmpty
(
extPuchasePlanExcelVO
.
getPlanCode
())){
errString
.
append
(
"更新计划编码:项目代号为"
+
extPuchasePlanExcelVO
.
getProjectCode
()
+
"的计划编码不能为空"
);
errorList
.
add
(
errString
);
}
else
if
(
Constants
.
EXCEL_DELETE
.
equals
(
extPuchasePlanExcelVO
.
getOperation
())
&&
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
);
}
}
}
}
}
...
...
@@ -142,12 +154,21 @@ public class PurchasePlanExcelReadListenner extends AnalysisEventListener<ExtPuc
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();
// }
/**
* 根据计划编码查询计划
* @param planCode
* @return
*/
public
ExtPuchasePlanAttributeVO
getPurchasePlanByPlanCode
(
String
planCode
){
//根据计划编码获取数据库中采购计划数据
DxPageImpl
<
ExtPuchasePlanAttributeVO
>
dxPuchasePlanPage
=
extPuchasePlanAttributeService
.
findRecursion
(
SearchUtil
.
buildQuery
(
"planCode"
,
SearchItem
.
Operator
.
EQ
,
planCode
));
if
(!
CollectionUtils
.
isEmpty
(
dxPuchasePlanPage
.
getContent
()))
{
ExtPuchasePlanAttributeVO
extPurPlanForDB
=
DxPageUtils
.
getFirst
(
dxPuchasePlanPage
);
return
extPurPlanForDB
;
}
else
{
log
.
info
(
"根据计划编码:{},未查到相关计划"
,
planCode
);
}
return
null
;
}
}
dcs-plan-core/src/main/java/com/yonde/dcs/plan/core/util/CommonUtils.java
0 → 100644
View file @
f23ce0cf
package
com
.
yonde
.
dcs
.
plan
.
core
.
util
;
import
com.yonde.dex.dao.service.util.ApplicationContextUtil
;
import
com.yonde.dex.dict.feign.DictDataFeignService
;
import
com.yonde.dex.dict.service.vo.DictDataVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.List
;
@Slf4j
@Component
public
class
CommonUtils
{
private
static
DictDataFeignService
dictDataFeignService
;
public
CommonUtils
()
{
this
.
dictDataFeignService
=
ApplicationContextUtil
.
getBean
(
DictDataFeignService
.
class
);
}
/**
*根据字典code获取字典code和字典项的值获取key
* @param dictCode
* @param dictValue
* @return
*/
public
static
String
searchDictDataByDictCode
(
String
dictCode
,
String
dictValue
)
{
if
(!
StringUtils
.
isEmpty
(
dictValue
))
{
//字典type 项目代号 ProjectCode
List
<
DictDataVO
>
dictDatasByDictCode
=
dictDataFeignService
.
getDictDatas
(
dictCode
);
if
(
CollectionUtils
.
isEmpty
(
dictDatasByDictCode
))
{
log
.
error
(
"所查字典为空!字典code为:"
+
dictCode
);
return
""
;
}
else
{
for
(
DictDataVO
dictDataVO
:
dictDatasByDictCode
)
{
if
(
dictValue
.
equals
(
dictDataVO
.
getDictValue
()))
{
return
dictDataVO
.
getDictKey
();
}
}
log
.
error
(
"所查字典数据项为空!字典code为:"
+
dictCode
);
return
""
;
}
}
log
.
error
(
"所查字典Key为空!字典code为:"
+
dictCode
);
return
""
;
}
}
dcs-plan-core/src/main/java/com/yonde/dcs/plan/core/util/SearchUtil.java
0 → 100644
View file @
f23ce0cf
package
com
.
yonde
.
dcs
.
plan
.
core
.
util
;
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
();
}
}
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