Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
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
项目统一框架
amos-boot-biz
Commits
5663866c
Commit
5663866c
authored
Jan 31, 2024
by
suhuiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.报检结果接收接口开发
parent
53396c1f
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
582 additions
and
9 deletions
+582
-9
BizCustomDateSerializer.java
.../boot/module/jyjc/api/common/BizCustomDateSerializer.java
+71
-0
AttachmentData.java
...ejoin/amos/boot/module/jyjc/api/model/AttachmentData.java
+21
-0
AttachmentModel.java
...join/amos/boot/module/jyjc/api/model/AttachmentModel.java
+31
-0
JyjcInspectionResultDataModel.java
.../module/jyjc/api/model/JyjcInspectionResultDataModel.java
+85
-0
JyjcInspectionResultController.java
...e/jyjc/biz/controller/JyjcInspectionResultController.java
+12
-0
InspectionDetectionSaveToDbEvent.java
...dule/jyjc/biz/event/InspectionDetectionSaveToDbEvent.java
+27
-0
UseInfoSaveToDbEvent.java
...amos/boot/module/jyjc/biz/event/UseInfoSaveToDbEvent.java
+27
-0
InspectionDetectionSaveToDbEventListener.java
...nt/listener/InspectionDetectionSaveToDbEventListener.java
+106
-0
UseInfoSaveToDbEventListener.java
...jyjc/biz/event/listener/UseInfoSaveToDbEventListener.java
+58
-0
EventPublisher.java
.../boot/module/jyjc/biz/event/publisher/EventPublisher.java
+21
-0
JyjcInspectionResultServiceImpl.java
...yjc/biz/service/impl/JyjcInspectionResultServiceImpl.java
+123
-9
No files found.
amos-boot-system-tzs/amos-boot-module-jyjc/amos-boot-module-jyjc-api/src/main/java/com/yeejoin/amos/boot/module/jyjc/api/common/BizCustomDateSerializer.java
0 → 100644
View file @
5663866c
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jyjc
.
api
.
common
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.JsonSerializer
;
import
com.fasterxml.jackson.databind.SerializerProvider
;
import
org.apache.commons.lang3.StringUtils
;
import
org.typroject.tyboot.core.foundation.utils.DateTimeUtil
;
import
java.io.IOException
;
import
java.lang.reflect.Field
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* @JsonComponent 会覆盖JsonFormat, 这里解析字段提升JsonFormat优先级
* <p>
* ProjectName: amos-boot-biz
* PackageName: com.yeejoin.amos.boot.module.jg.biz.config
*
* @author yangyang
* @version v1.0
* @date 2023/12/18 17:35
*/
public
class
BizCustomDateSerializer
extends
JsonSerializer
<
Date
>
{
private
List
<
String
>
customFields
=
Arrays
.
asList
(
"acceptDate"
,
"expiryDate"
,
"applicationDate"
,
"noticeDate"
,
"installStartDate"
,
"handleDate"
,
"auditPassDate"
,
"applyDate"
);
public
BizCustomDateSerializer
()
{
}
@Override
public
void
serialize
(
Date
value
,
JsonGenerator
jgen
,
SerializerProvider
provider
)
throws
IOException
,
JsonProcessingException
{
try
{
Class
<?>
clazz
=
jgen
.
getCurrentValue
().
getClass
();
if
(
Objects
.
equals
(
clazz
,
HashMap
.
class
))
{
// 分页参数
if
(
customFields
.
contains
(
jgen
.
getOutputContext
().
getCurrentName
()))
{
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
DateTimeUtil
.
ISO_DATE
);
jgen
.
writeString
(
formatter
.
format
(
value
));
return
;
}
}
else
{
Field
field
=
clazz
.
getDeclaredField
(
jgen
.
getOutputContext
().
getCurrentName
());
if
(
Objects
.
equals
(
field
.
getType
(),
Date
.
class
))
{
if
(
field
.
isAnnotationPresent
(
JsonFormat
.
class
))
{
String
pattern
=
field
.
getAnnotation
(
JsonFormat
.
class
).
pattern
();
if
(
StringUtils
.
isNotBlank
(
pattern
))
{
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
pattern
);
jgen
.
writeString
(
formatter
.
format
(
value
));
return
;
}
}
}
}
jgen
.
writeString
(
defaultFormattedDate
(
value
));
}
catch
(
Exception
e
)
{
jgen
.
writeString
(
defaultFormattedDate
(
value
));
}
}
private
String
defaultFormattedDate
(
Date
value
)
{
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
DateTimeUtil
.
ISO_DATE_HOUR24_MIN_SEC
);
String
formattedDate
=
formatter
.
format
(
value
);
return
formattedDate
;
}
}
\ No newline at end of file
amos-boot-system-tzs/amos-boot-module-jyjc/amos-boot-module-jyjc-api/src/main/java/com/yeejoin/amos/boot/module/jyjc/api/model/AttachmentData.java
0 → 100644
View file @
5663866c
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jyjc
.
api
.
model
;
import
lombok.Data
;
import
java.util.List
;
/**
* @author Administrator
*/
@Data
public
class
AttachmentData
{
/**
* 附件类型
*/
public
String
attachmentType
;
/**
* 附件列表
*/
public
List
<
AttachmentModel
>
attachmentContent
;
}
amos-boot-system-tzs/amos-boot-module-jyjc/amos-boot-module-jyjc-api/src/main/java/com/yeejoin/amos/boot/module/jyjc/api/model/AttachmentModel.java
0 → 100644
View file @
5663866c
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jyjc
.
api
.
model
;
import
lombok.Data
;
/**
* @author Administrator
* 附件结构
*/
@Data
public
class
AttachmentModel
{
/**
* 附件名称
*/
String
name
;
/**
* 附件路径
*/
String
url
;
/**
* 前端标识
*/
String
uid
;
/**
* 前端附件状态
*/
String
status
;
}
amos-boot-system-tzs/amos-boot-module-jyjc/amos-boot-module-jyjc-api/src/main/java/com/yeejoin/amos/boot/module/jyjc/api/model/JyjcInspectionResultDataModel.java
0 → 100644
View file @
5663866c
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jyjc
.
api
.
model
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
com.yeejoin.amos.boot.module.jyjc.api.common.BizCustomDateSerializer
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.Date
;
import
java.util.List
;
/**
* 业务开通申请表
*
* @author system_generator
* @date 2023-12-14
*/
@Data
@ApiModel
(
value
=
"JyjcInspectionResultDataModel"
,
description
=
"检验检测结果数据接收"
)
public
class
JyjcInspectionResultDataModel
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"报检单号"
)
private
String
applicationNo
;
@ApiModelProperty
(
value
=
"监管码"
)
private
String
supervisoryCode
;
@ApiModelProperty
(
value
=
"检验结果状态(已出2、未出1)"
)
private
String
resultStatus
;
@ApiModelProperty
(
value
=
"核准证号/许可证号"
)
private
String
licenseNumber
;
@ApiModelProperty
(
value
=
"检验报告编号"
)
private
String
resultNo
;
@ApiModelProperty
(
value
=
"内部人员代码"
)
private
String
innerPersonCode
;
@ApiModelProperty
(
value
=
"检验结论"
)
private
String
inspectionConclusion
;
@ApiModelProperty
(
value
=
"检验日期"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
)
@JsonSerialize
(
using
=
BizCustomDateSerializer
.
class
)
private
Date
inspectionDate
;
@ApiModelProperty
(
value
=
"下次检验日期"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
)
@JsonSerialize
(
using
=
BizCustomDateSerializer
.
class
)
private
Date
nextInspectionDate
;
@ApiModelProperty
(
value
=
"检验开始日期"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
)
@JsonSerialize
(
using
=
BizCustomDateSerializer
.
class
)
private
Date
inspectionStartDate
;
@ApiModelProperty
(
value
=
"检验结束日期"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
)
@JsonSerialize
(
using
=
BizCustomDateSerializer
.
class
)
private
Date
inspectionEndDate
;
@ApiModelProperty
(
value
=
"检验结果汇总"
)
private
String
inspectionResultSummary
;
@ApiModelProperty
(
value
=
"不符合项"
)
private
JSONArray
nonConformance
;
@ApiModelProperty
(
value
=
"附件"
)
private
List
<
AttachmentData
>
attachments
;
@ApiModelProperty
(
value
=
"检验结果技术参数"
)
private
JSONObject
techParams
;
/**
* 校验检验系统唯一流水号,排查问题,跟踪问题使用
*/
private
String
traceId
;
}
amos-boot-system-tzs/amos-boot-module-jyjc/amos-boot-module-jyjc-biz/src/main/java/com/yeejoin/amos/boot/module/jyjc/biz/controller/JyjcInspectionResultController.java
View file @
5663866c
...
...
@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.jyjc.biz.controller;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.yeejoin.amos.boot.biz.common.controller.BaseController
;
import
com.yeejoin.amos.boot.module.jyjc.api.model.JyjcInspectionResultDataModel
;
import
com.yeejoin.amos.boot.module.jyjc.api.model.JyjcInspectionResultModel
;
import
com.yeejoin.amos.boot.module.jyjc.biz.service.impl.JyjcInspectionResultServiceImpl
;
import
io.swagger.annotations.Api
;
...
...
@@ -175,4 +176,15 @@ public class JyjcInspectionResultController extends BaseController {
return
ResponseHelper
.
buildResponse
(
jyjcInspectionResultServiceImpl
.
equipList
(
type
,
notNode
));
}
/**
* 报检结果接收
* @param resultDataModels 结果信息
* @return List<JyjcInspectionResultDataModel>
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"报检结果接收"
,
notes
=
"对外对接使用,支持单条及批量"
)
@PostMapping
(
value
=
"/receive/data"
)
public
ResponseModel
<
List
<
JyjcInspectionResultDataModel
>>
receivePushResultData
(
@RequestBody
List
<
JyjcInspectionResultDataModel
>
resultDataModels
){
return
ResponseHelper
.
buildResponse
(
jyjcInspectionResultServiceImpl
.
receivePushResultData
(
resultDataModels
));
}
}
amos-boot-system-tzs/amos-boot-module-jyjc/amos-boot-module-jyjc-biz/src/main/java/com/yeejoin/amos/boot/module/jyjc/biz/event/InspectionDetectionSaveToDbEvent.java
0 → 100644
View file @
5663866c
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jyjc
.
biz
.
event
;
import
com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionResult
;
import
lombok.Getter
;
import
org.springframework.context.ApplicationEvent
;
import
java.util.List
;
/**
* @author Administrator
*/
@Getter
public
class
InspectionDetectionSaveToDbEvent
extends
ApplicationEvent
{
private
List
<
JyjcInspectionResult
>
jyjcInspectionResultList
;
/**
* Create a new {@code ApplicationEvent}.
*
* @param source the object on which the event initially occurred or with
* which the event is associated (never {@code null})
*/
public
InspectionDetectionSaveToDbEvent
(
Object
source
,
List
<
JyjcInspectionResult
>
jyjcInspectionResultList
)
{
super
(
source
);
this
.
jyjcInspectionResultList
=
jyjcInspectionResultList
;
}
}
amos-boot-system-tzs/amos-boot-module-jyjc/amos-boot-module-jyjc-biz/src/main/java/com/yeejoin/amos/boot/module/jyjc/biz/event/UseInfoSaveToDbEvent.java
0 → 100644
View file @
5663866c
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jyjc
.
biz
.
event
;
import
com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionResult
;
import
lombok.Getter
;
import
org.springframework.context.ApplicationEvent
;
import
java.util.List
;
/**
* @author Administrator
*/
@Getter
public
class
UseInfoSaveToDbEvent
extends
ApplicationEvent
{
private
List
<
JyjcInspectionResult
>
jyjcInspectionResultList
;
/**
* Create a new {@code ApplicationEvent}.
*
* @param source the object on which the event initially occurred or with
* which the event is associated (never {@code null})
*/
public
UseInfoSaveToDbEvent
(
Object
source
,
List
<
JyjcInspectionResult
>
jyjcInspectionResultList
)
{
super
(
source
);
this
.
jyjcInspectionResultList
=
jyjcInspectionResultList
;
}
}
amos-boot-system-tzs/amos-boot-module-jyjc/amos-boot-module-jyjc-biz/src/main/java/com/yeejoin/amos/boot/module/jyjc/biz/event/listener/InspectionDetectionSaveToDbEventListener.java
0 → 100644
View file @
5663866c
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jyjc
.
biz
.
event
.
listener
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Sequence
;
import
com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionResult
;
import
com.yeejoin.amos.boot.module.jyjc.biz.event.InspectionDetectionSaveToDbEvent
;
import
com.yeejoin.amos.boot.module.jyjc.biz.service.impl.CommonserviceImpl
;
import
com.yeejoin.amos.boot.module.ymt.api.entity.InspectionDetectionInfo
;
import
com.yeejoin.amos.boot.module.ymt.api.entity.TzsUserInfo
;
import
com.yeejoin.amos.boot.module.ymt.api.mapper.InspectionDetectionInfoMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.PostConstruct
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.stream.Collectors
;
/**
* @author Administrator
*/
@Component
@Slf4j
public
class
InspectionDetectionSaveToDbEventListener
implements
ApplicationListener
<
InspectionDetectionSaveToDbEvent
>
{
@Value
(
"${inspect.info.save.thread.number:3}"
)
private
int
threadNumber
;
@Autowired
CommonserviceImpl
commonService
;
@Autowired
private
Sequence
sequence
;
@Autowired
InspectionDetectionInfoMapper
inspectionDetectionInfoMapper
;
private
BlockingQueue
<
JyjcInspectionResult
>
blockingQueue
=
new
LinkedBlockingQueue
<>();
@Override
public
void
onApplicationEvent
(
InspectionDetectionSaveToDbEvent
event
)
{
log
.
info
(
"收到检验检测信息插入或者更新消息:{}"
,
JSONObject
.
toJSONString
(
event
.
getJyjcInspectionResultList
()));
blockingQueue
.
addAll
(
event
.
getJyjcInspectionResultList
());
}
@PostConstruct
public
void
init
()
{
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
threadNumber
);
for
(
int
i
=
0
;
i
<
threadNumber
;
i
++)
{
executorService
.
execute
(()
->
{
while
(
true
)
{
try
{
JyjcInspectionResult
jyjcInspectionResult
=
blockingQueue
.
take
();
InspectionDetectionInfo
info
=
new
InspectionDetectionInfo
();
QueryWrapper
<
InspectionDetectionInfo
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
lambda
().
eq
(
InspectionDetectionInfo:
:
getInspectReportNo
,
jyjcInspectionResult
.
getResultNo
());
List
<
InspectionDetectionInfo
>
list
=
inspectionDetectionInfoMapper
.
selectList
(
wrapper
);
if
(
CollectionUtils
.
isEmpty
(
list
))
{
extracted
(
jyjcInspectionResult
,
info
);
info
.
setSequenceNbr
(
sequence
.
nextId
()
+
""
);
inspectionDetectionInfoMapper
.
insert
(
info
);
}
else
{
info
=
list
.
get
(
0
);
extracted
(
jyjcInspectionResult
,
info
);
inspectionDetectionInfoMapper
.
updateById
(
info
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
}
});
}
}
private
void
extracted
(
JyjcInspectionResult
jyjcInspectionResult
,
InspectionDetectionInfo
info
)
{
info
.
setInspectOrgName
(
jyjcInspectionResult
.
getInspectionTypeName
());
info
.
setInspectType
(
jyjcInspectionResult
.
getInspectionType
());
info
.
setRecord
(
jyjcInspectionResult
.
getEquipUnicode
());
info
.
setInspectDate
(
jyjcInspectionResult
.
getInspectionDate
());
info
.
setInspectStaff
(
getInspectUserName
(
jyjcInspectionResult
));
info
.
setInspectStaffCode
(
jyjcInspectionResult
.
getInspector
());
info
.
setInspectConclusion
(
jyjcInspectionResult
.
getInspectionConclusion
());
info
.
setProblemRemark
(
jyjcInspectionResult
.
getNonConformance
());
info
.
setNextInspectDate
(
jyjcInspectionResult
.
getNextInspectionDate
());
info
.
setSequenceCode
(
jyjcInspectionResult
.
getEquipUnicode
());
info
.
setInspectOrgCode
(
jyjcInspectionResult
.
getInspectionUnitCode
());
info
.
setInspectReportNo
(
jyjcInspectionResult
.
getResultNo
());
info
.
setRecDate
(
new
Date
());
}
private
String
getInspectUserName
(
JyjcInspectionResult
model
)
{
List
<
TzsUserInfo
>
userInfos
=
commonService
.
getUserInfosByUnitCode
(
model
.
getInspectionUnitCode
());
return
userInfos
.
stream
().
filter
(
u
->
model
.
getInspector
().
contains
(
u
.
getSequenceNbr
()
+
""
)).
map
(
TzsUserInfo:
:
getName
).
collect
(
Collectors
.
joining
(
","
));
}
}
amos-boot-system-tzs/amos-boot-module-jyjc/amos-boot-module-jyjc-biz/src/main/java/com/yeejoin/amos/boot/module/jyjc/biz/event/listener/UseInfoSaveToDbEventListener.java
0 → 100644
View file @
5663866c
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jyjc
.
biz
.
event
.
listener
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionResult
;
import
com.yeejoin.amos.boot.module.jyjc.biz.event.UseInfoSaveToDbEvent
;
import
com.yeejoin.amos.boot.module.ymt.api.mapper.UseInfoMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.LinkedBlockingQueue
;
/**
* @author Administrator
*/
@Component
@Slf4j
public
class
UseInfoSaveToDbEventListener
implements
ApplicationListener
<
UseInfoSaveToDbEvent
>
{
@Value
(
"${user.info.save.thread.number:3}"
)
private
int
threadNumber
;
@Autowired
UseInfoMapper
useInfoMapper
;
private
BlockingQueue
<
JyjcInspectionResult
>
blockingQueue
=
new
LinkedBlockingQueue
<>();
@Override
public
void
onApplicationEvent
(
UseInfoSaveToDbEvent
event
)
{
log
.
info
(
"收到更新使用信息的检验检测字段消息:{}"
,
JSONObject
.
toJSONString
(
event
.
getJyjcInspectionResultList
()));
blockingQueue
.
addAll
(
event
.
getJyjcInspectionResultList
());
}
@PostConstruct
public
void
init
()
{
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
threadNumber
);
for
(
int
i
=
0
;
i
<
threadNumber
;
i
++)
{
executorService
.
execute
(()
->
{
while
(
true
)
{
try
{
JyjcInspectionResult
jyjcInspectionResult
=
blockingQueue
.
take
();
//更新使用信息表
useInfoMapper
.
updateByRecord
(
jyjcInspectionResult
.
getEquipUnicode
(),
jyjcInspectionResult
.
getNextInspectionDate
(),
jyjcInspectionResult
.
getInspectionType
(),
jyjcInspectionResult
.
getApplicationNo
());
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
}
});
}
}
}
amos-boot-system-tzs/amos-boot-module-jyjc/amos-boot-module-jyjc-biz/src/main/java/com/yeejoin/amos/boot/module/jyjc/biz/event/publisher/EventPublisher.java
0 → 100644
View file @
5663866c
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jyjc
.
biz
.
event
.
publisher
;
import
org.springframework.context.ApplicationEvent
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Component
;
@Component
public
class
EventPublisher
{
private
ApplicationEventPublisher
publisher
;
public
EventPublisher
(
ApplicationEventPublisher
publisher
)
{
this
.
publisher
=
publisher
;
}
@Async
public
void
publish
(
ApplicationEvent
event
)
{
publisher
.
publishEvent
(
event
);
}
}
\ No newline at end of file
amos-boot-system-tzs/amos-boot-module-jyjc/amos-boot-module-jyjc-biz/src/main/java/com/yeejoin/amos/boot/module/jyjc/biz/service/impl/JyjcInspectionResultServiceImpl.java
View file @
5663866c
package
com
.
yeejoin
.
amos
.
boot
.
module
.
jyjc
.
biz
.
service
.
impl
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
...
...
@@ -15,18 +16,24 @@ import com.yeejoin.amos.boot.module.jyjc.api.common.StringUtil;
import
com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionResult
;
import
com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionResultAttachment
;
import
com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionResultParam
;
import
com.yeejoin.amos.boot.module.jyjc.api.enums.EquipCategoryEnum
;
import
com.yeejoin.amos.boot.module.jyjc.api.enums.ResultStatusEnum
;
import
com.yeejoin.amos.boot.module.jyjc.api.mapper.JyjcInspectionResultMapper
;
import
com.yeejoin.amos.boot.module.jyjc.api.model.JyjcInspectionResultDataModel
;
import
com.yeejoin.amos.boot.module.jyjc.api.model.JyjcInspectionResultModel
;
import
com.yeejoin.amos.boot.module.jyjc.api.service.IJyjcInspectionResultAttachmentService
;
import
com.yeejoin.amos.boot.module.jyjc.api.service.IJyjcInspectionResultParamService
;
import
com.yeejoin.amos.boot.module.jyjc.api.service.IJyjcInspectionResultService
;
import
com.yeejoin.amos.boot.module.jyjc.biz.event.InspectionDetectionSaveToDbEvent
;
import
com.yeejoin.amos.boot.module.jyjc.biz.event.UseInfoSaveToDbEvent
;
import
com.yeejoin.amos.boot.module.jyjc.biz.event.publisher.EventPublisher
;
import
com.yeejoin.amos.boot.module.jyjc.biz.utils.JsonUtils
;
import
com.yeejoin.amos.boot.module.ymt.api.entity.InspectionDetectionInfo
;
import
com.yeejoin.amos.boot.module.ymt.api.entity.TzBaseEnterpriseInfo
;
import
com.yeejoin.amos.boot.module.ymt.api.entity.TzsUserInfo
;
import
com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentClassifityEnum
;
import
com.yeejoin.amos.boot.module.ymt.api.mapper.*
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.core.io.Resource
;
...
...
@@ -36,9 +43,12 @@ import org.springframework.util.CollectionUtils;
import
org.springframework.util.ObjectUtils
;
import
org.typroject.tyboot.core.foundation.context.RequestContext
;
import
org.typroject.tyboot.core.foundation.utils.ValidationUtil
;
import
org.typroject.tyboot.core.rdbms.orm.entity.BaseEntity
;
import
org.typroject.tyboot.core.rdbms.service.BaseService
;
import
java.io.IOException
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -48,6 +58,7 @@ import java.util.stream.Collectors;
* @date 2023-12-14
*/
@Service
@Slf4j
public
class
JyjcInspectionResultServiceImpl
extends
BaseService
<
JyjcInspectionResultModel
,
JyjcInspectionResult
,
JyjcInspectionResultMapper
>
implements
IJyjcInspectionResultService
{
private
static
final
String
JYJC_SUBMIT_FILE_PREFIX
=
"JYJC_"
;
...
...
@@ -93,6 +104,12 @@ public class JyjcInspectionResultServiceImpl extends BaseService<JyjcInspectionR
@Autowired
CommonserviceImpl
commonService
;
@Autowired
TzsUserInfoMapper
tzsUserInfoMapper
;
@Autowired
EventPublisher
eventPublisher
;
/**
* 检验检测单位分页查询
*/
...
...
@@ -260,14 +277,7 @@ public class JyjcInspectionResultServiceImpl extends BaseService<JyjcInspectionR
}
private
void
extracted
(
JyjcInspectionResultModel
model
,
InspectionDetectionInfo
info
,
JyjcInspectionResultAttachment
jybgFile
)
{
// 回填检验机构名称
LambdaQueryWrapper
<
TzBaseEnterpriseInfo
>
wrapper
=
new
LambdaQueryWrapper
<>();
wrapper
.
eq
(
TzBaseEnterpriseInfo:
:
getUseCode
,
model
.
getInspectionUnitCode
());
List
<
TzBaseEnterpriseInfo
>
tzBaseEnterpriseInfos
=
tzBaseEnterpriseInfoMapper
.
selectList
(
wrapper
);
if
(!
CollectionUtils
.
isEmpty
(
tzBaseEnterpriseInfos
))
{
info
.
setInspectOrgName
(
tzBaseEnterpriseInfos
.
get
(
0
).
getUseUnit
());
}
info
.
setInspectOrgName
(
model
.
getInspectionUnitName
());
info
.
setInspectType
(
model
.
getInspectionType
());
info
.
setRecord
(
model
.
getEquipUnicode
());
info
.
setInspectDate
(
model
.
getInspectionDate
());
...
...
@@ -285,7 +295,7 @@ public class JyjcInspectionResultServiceImpl extends BaseService<JyjcInspectionR
private
String
getInspectUserName
(
JyjcInspectionResultModel
model
)
{
List
<
TzsUserInfo
>
userInfos
=
commonService
.
getUserInfosByUnitCode
(
model
.
getInspectionUnitCode
());
return
userInfos
.
stream
().
filter
(
u
->
model
.
getInspector
().
contains
(
u
.
getSequenceNbr
()
+
""
)).
map
(
TzsUserInfo:
:
getName
).
collect
(
Collectors
.
joining
(
","
));
return
userInfos
.
stream
().
filter
(
u
->
model
.
getInspector
().
contains
(
u
.
getSequenceNbr
()
+
""
)).
map
(
TzsUserInfo:
:
getName
).
collect
(
Collectors
.
joining
(
","
));
}
/**
...
...
@@ -362,4 +372,107 @@ public class JyjcInspectionResultServiceImpl extends BaseService<JyjcInspectionR
return
menus
;
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
List
<
JyjcInspectionResultDataModel
>
receivePushResultData
(
List
<
JyjcInspectionResultDataModel
>
resultDataModels
)
{
log
.
info
(
"收到检验检测厂商推送的结果数据:{}"
,
JSONArray
.
toJSONString
(
resultDataModels
));
// 1.组织数据
Map
<
String
,
JyjcInspectionResult
>
resultListMap
=
queryWaitUpdateResultList
(
resultDataModels
);
List
<
JyjcInspectionResultAttachment
>
resultAttachments
=
new
ArrayList
<>();
List
<
JyjcInspectionResultParam
>
resultParams
=
new
ArrayList
<>();
resultDataModels
.
forEach
(
r
->
{
// 填充主表数据
this
.
fillResultData
(
r
,
resultListMap
.
get
(
r
.
getApplicationNo
()));
// 填充附件数据
this
.
fillResultAttachmentData
(
r
,
resultListMap
.
get
(
r
.
getApplicationNo
()),
resultAttachments
);
// 填充技术参数数据
this
.
fillResultParamData
(
r
,
resultListMap
.
get
(
r
.
getApplicationNo
()),
resultParams
);
});
// 2.批量保存主表数据
this
.
updateBatchById
(
resultListMap
.
values
());
// 3.批量保存子表数据
deleteAndCreateSubTable
(
resultListMap
,
resultAttachments
,
resultParams
);
// 4.异步更新最新一次检验信息
eventPublisher
.
publish
(
new
UseInfoSaveToDbEvent
(
this
,
new
ArrayList
<>(
resultListMap
.
values
())));
// 5.异步更新设备的检验检测信息
eventPublisher
.
publish
(
new
InspectionDetectionSaveToDbEvent
(
this
,
new
ArrayList
<>(
resultListMap
.
values
())));
return
resultDataModels
;
}
private
void
deleteAndCreateSubTable
(
Map
<
String
,
JyjcInspectionResult
>
resultListMap
,
List
<
JyjcInspectionResultAttachment
>
resultAttachments
,
List
<
JyjcInspectionResultParam
>
resultParams
)
{
List
<
JyjcInspectionResult
>
resultList
=
new
ArrayList
<>(
resultListMap
.
values
());
List
<
Long
>
resultIds
=
resultList
.
stream
().
map
(
BaseEntity:
:
getSequenceNbr
).
collect
(
Collectors
.
toList
());
if
(
resultAttachments
.
size
()
>
0
){
attachmentService
.
remove
(
new
LambdaQueryWrapper
<
JyjcInspectionResultAttachment
>().
in
(
JyjcInspectionResultAttachment:
:
getResultSeq
,
resultIds
));
attachmentService
.
saveBatch
(
resultAttachments
);
}
if
(
resultParams
.
size
()
>
0
){
resultParamService
.
remove
(
new
LambdaQueryWrapper
<
JyjcInspectionResultParam
>().
in
(
JyjcInspectionResultParam:
:
getResultSeq
,
resultIds
));
resultParamService
.
saveBatch
(
resultParams
);
}
}
private
void
fillResultParamData
(
JyjcInspectionResultDataModel
r
,
JyjcInspectionResult
jyjcInspectionResult
,
List
<
JyjcInspectionResultParam
>
resultParams
)
{
JyjcInspectionResultParam
resultParam
=
new
JyjcInspectionResultParam
();
resultParam
.
setResultSeq
(
jyjcInspectionResult
.
getSequenceNbr
());
resultParam
.
setParamJson
(
JSON
.
toJSONString
(
r
.
getTechParams
()));
resultParam
.
setRecUserId
(
RequestContext
.
getExeUserId
());
resultParam
.
setRecDate
(
new
Date
());
resultParam
.
setRemark
(
"同步数据"
);
resultParam
.
setParamType
(
this
.
getTypeByEquipList
(
jyjcInspectionResult
.
getEquList
()));
resultParams
.
add
(
resultParam
);
}
private
String
getTypeByEquipList
(
String
equList
)
{
EquipCategoryEnum
categoryEnum
=
EquipCategoryEnum
.
of
(
Integer
.
parseInt
(
equList
));
assert
categoryEnum
!=
null
;
return
StrUtil
.
toCamelCase
(
categoryEnum
.
name
());
}
private
void
fillResultAttachmentData
(
JyjcInspectionResultDataModel
r
,
JyjcInspectionResult
jyjcInspectionResult
,
List
<
JyjcInspectionResultAttachment
>
resultAttachments
)
{
r
.
getAttachments
().
forEach
(
a
->
{
JyjcInspectionResultAttachment
attachment
=
new
JyjcInspectionResultAttachment
();
attachment
.
setResultSeq
(
jyjcInspectionResult
.
getSequenceNbr
());
attachment
.
setAttachmentType
(
a
.
getAttachmentType
());
attachment
.
setAttachmentUrl
(
JSON
.
toJSONString
(
a
.
getAttachmentContent
()));
attachment
.
setRecUserId
(
RequestContext
.
getExeUserId
());
attachment
.
setRecDate
(
new
Date
());
attachment
.
setRemark
(
"同步数据"
);
resultAttachments
.
add
(
attachment
);
});
}
private
void
fillResultData
(
JyjcInspectionResultDataModel
r
,
JyjcInspectionResult
jyjcInspectionResult
)
{
jyjcInspectionResult
.
setResultStatus
(
ResultStatusEnum
.
YES_RESULT
.
getCode
());
jyjcInspectionResult
.
setLicenseNumber
(
r
.
getLicenseNumber
());
jyjcInspectionResult
.
setResultNo
(
r
.
getResultNo
());
jyjcInspectionResult
.
setInnerPersonCode
(
r
.
getInnerPersonCode
());
jyjcInspectionResult
.
setInspector
(
this
.
getUserSeqByPersonCode
(
r
.
getInnerPersonCode
()));
jyjcInspectionResult
.
setInspectionConclusion
(
r
.
getInspectionConclusion
());
jyjcInspectionResult
.
setInspectionDate
(
r
.
getInspectionDate
());
jyjcInspectionResult
.
setNextInspectionDate
(
r
.
getNextInspectionDate
());
jyjcInspectionResult
.
setInspectionStartDate
(
r
.
getInspectionStartDate
());
jyjcInspectionResult
.
setInspectionEndDate
(
r
.
getInspectionEndDate
());
jyjcInspectionResult
.
setInspectionResultSummary
(
r
.
getInspectionResultSummary
());
jyjcInspectionResult
.
setNonConformance
(
JSON
.
toJSONString
(
r
.
getNonConformance
()));
jyjcInspectionResult
.
setRemark
(
"同步数据"
);
jyjcInspectionResult
.
setTraceId
(
r
.
getTraceId
());
}
private
String
getUserSeqByPersonCode
(
String
innerPersonCode
)
{
if
(
StrUtil
.
isNotEmpty
(
innerPersonCode
)){
List
<
TzsUserInfo
>
tzsUserInfos
=
tzsUserInfoMapper
.
selectList
(
new
LambdaQueryWrapper
<
TzsUserInfo
>().
in
(
TzsUserInfo:
:
getInnerPersonCode
,
Arrays
.
asList
(
innerPersonCode
.
split
(
","
))));
return
tzsUserInfos
.
stream
().
map
(
u
->
u
.
getSequenceNbr
()
+
""
).
collect
(
Collectors
.
joining
(
","
));
}
log
.
error
(
"检验人员内部编号为空"
);
return
""
;
}
private
Map
<
String
,
JyjcInspectionResult
>
queryWaitUpdateResultList
(
List
<
JyjcInspectionResultDataModel
>
resultDataModels
)
{
List
<
String
>
applicationNos
=
resultDataModels
.
stream
().
map
(
JyjcInspectionResultDataModel:
:
getApplicationNo
).
collect
(
Collectors
.
toList
());
LambdaQueryWrapper
<
JyjcInspectionResult
>
wrapper
=
new
LambdaQueryWrapper
<
JyjcInspectionResult
>().
in
(
JyjcInspectionResult:
:
getApplicationNo
,
applicationNos
);
List
<
JyjcInspectionResult
>
resultList
=
this
.
list
(
wrapper
);
return
resultList
.
stream
().
collect
(
Collectors
.
toMap
(
JyjcInspectionResult:
:
getApplicationNo
,
Function
.
identity
()));
}
}
\ 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