Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
usedCarAuction
/
aus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b2f6a2e6
authored
Apr 14, 2026
by
杨卫
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'refs/heads/v1.4.0_yw' into v1.4.0
2 parents
4f2f311d
ca6aca3a
Show whitespace changes
Inline
Side-by-side
Showing
60 changed files
with
4599 additions
and
123 deletions
aus-admin/src/main/java/com/glsx/usedcar/delegate/AdminSaveDelegate.java
aus-admin/src/main/java/com/glsx/usedcar/export/InspectorExportBean.java
aus-admin/src/main/java/com/glsx/usedcar/web/rest/RopApiController.java
aus-admin/src/main/java/com/glsx/usedcar/web/rest/event/EventTrackingController.java
aus-admin/src/main/java/com/glsx/usedcar/web/rest/inspect/InspectionNodeController.java
aus-admin/src/main/java/com/glsx/usedcar/web/rest/inspect/InspectionRecordController.java
aus-admin/src/main/java/com/glsx/usedcar/web/rest/inspect/InspectionTemplateController.java
aus-admin/src/main/java/com/glsx/usedcar/web/rest/inspect/InspectionWorkOrderController.java
aus-core/src/main/java/com/glsx/usedcar/consts/common/CommonConsts.java
aus-core/src/main/java/com/glsx/usedcar/consts/common/SymbolConsts.java
aus-core/src/main/java/com/glsx/usedcar/consts/inspect/InspectConstants.java
aus-core/src/main/java/com/glsx/usedcar/consts/inspect/JpaQueryConstants.java
aus-core/src/main/java/com/glsx/usedcar/converts/InspectionOpLogConverter.java
aus-core/src/main/java/com/glsx/usedcar/enums/event/BusinessTypeEnum.java
aus-core/src/main/java/com/glsx/usedcar/enums/event/EventSourceEnum.java
aus-core/src/main/java/com/glsx/usedcar/enums/event/ParamTypeEnum.java
aus-core/src/main/java/com/glsx/usedcar/enums/inspect/InspectionWorkOrderOperationTypeEnum.java
aus-core/src/main/java/com/glsx/usedcar/module/event/dao/EventTrackingBusinessKeyRepository.java
aus-core/src/main/java/com/glsx/usedcar/module/event/dao/EventTrackingParamRepository.java
aus-core/src/main/java/com/glsx/usedcar/module/event/dao/EventTrackingRepository.java
aus-core/src/main/java/com/glsx/usedcar/module/event/dao/EventTypeConfigRepository.java
aus-core/src/main/java/com/glsx/usedcar/module/event/entity/EventTracking.java
aus-core/src/main/java/com/glsx/usedcar/module/event/entity/EventTrackingBusinessKey.java
aus-core/src/main/java/com/glsx/usedcar/module/event/entity/EventTrackingParam.java
aus-core/src/main/java/com/glsx/usedcar/module/event/entity/EventTypeConfig.java
aus-core/src/main/java/com/glsx/usedcar/module/event/service/EventTrackingService.java
aus-core/src/main/java/com/glsx/usedcar/module/event/vo/EventTrackingBatchSaveVO.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/dao/InspectionOpLogItemRepository.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/dao/InspectionOpLogRepository.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/dao/InspectionWorkOrderOpLogRepository.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/dao/TemplateTagRelationRepository.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/dao/TemplateTagRepository.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/delegate/InspectionSaveDelegate.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/entity/InspectionOpLog.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/entity/InspectionOpLogItem.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/entity/InspectionTemplate.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/entity/TemplateTag.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/entity/TemplateTagRelation.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/service/InspectionEditLogService.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/service/InspectionNodeService.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/service/InspectionRecordService.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/service/InspectionTemplateService.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/service/InspectionWorkOrderService.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/service/InspectorService.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/CompleteInspectionRespVO.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectionBatchSaveVO.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectionLeafNodeDataVO.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectionResultSnapshotVO.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectionSaveVO.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectionTemplateDetailRespVO.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectionTemplateRespVO.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectorPageRespVO.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectorRespVO.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/OpLogItemVO.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/TemplateTagVO.java
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/WorkOrderOpLogRespVO.java
aus-core/src/main/java/com/glsx/usedcar/util/AdCodeToProvinceUtil.java
aus-framework/src/main/java/org/summerframework/core/enums/ErrorCodeEnum.java
aus-inspector/src/main/java/com/glsx/usedcar/controller/InspectionRecordController.java
aus-inspector/src/main/java/com/glsx/usedcar/delegate/InspectorSaveDelegate.java
aus-admin/src/main/java/com/glsx/usedcar/delegate/AdminSaveDelegate.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
delegate
;
import
com.glsx.usedcar.enums.inspect.InspectionPlatTypeEnum
;
import
com.glsx.usedcar.enums.inspect.InspectionWorkOrderAuditStatusEnum
;
import
com.glsx.usedcar.enums.inspect.InspectionWorkOrderStatusEnum
;
import
com.glsx.usedcar.module.inspect.delegate.InspectionSaveDelegate
;
import
com.glsx.usedcar.module.inspect.dto.InspectionResultDTO
;
import
com.glsx.usedcar.module.inspect.entity.InspectionRecord
;
import
com.glsx.usedcar.module.inspect.entity.InspectionWorkOrder
;
import
com.glsx.usedcar.module.inspect.service.InspectionEditLogService
;
import
com.glsx.usedcar.module.inspect.service.InspectionRecordService
;
import
com.glsx.usedcar.module.inspect.service.InspectionWorkOrderService
;
import
com.glsx.usedcar.module.inspect.vo.CompleteInspectionRespVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionNodeVO
;
import
com.glsx.usedcar.module.security.entity.User
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
java.time.LocalDateTime
;
import
java.util.*
;
/**
* PC 后台管理端保存策略实现
*
* @author yangwei
* @since 2026/4/8
*/
@Slf4j
@RequiredArgsConstructor
public
class
AdminSaveDelegate
implements
InspectionSaveDelegate
{
private
final
User
user
;
private
final
InspectionEditLogService
inspectionEditLogService
;
private
final
InspectionWorkOrderService
inspectionWorkOrderService
;
private
final
InspectionRecordService
inspectionRecordService
;
/** 旧数据快照,用于保存后的 diff 对比 */
private
Map
<
Long
,
InspectionEditLogService
.
SnapshotEntry
>
oldSnapshot
;
private
final
Set
<
Long
>
operationNodeIds
=
new
HashSet
<>();
/** 旧评分记录快照,用于保存后的评分 diff 对比 */
private
InspectionRecord
oldRecord
;
/** 工单对象,用于 afterSave 写入工单操作日志 */
private
InspectionWorkOrder
workOrder
;
@Override
public
void
operationNodeIds
(
Set
<
Long
>
nodeIds
)
{
operationNodeIds
.
addAll
(
Optional
.
ofNullable
(
nodeIds
).
orElse
(
new
HashSet
<>()));
}
@Override
public
void
validatePermission
(
InspectionWorkOrder
workOrder
)
{
// PC 端:管理员可编辑状态:待检测(1)、检测中(2)、已完成(3), 已取消(4)不可编辑, 审批已通过不允许编辑
Integer
status
=
workOrder
.
getStatus
();
if
(!
isEditableStatus
(
status
)
||
InspectionWorkOrderAuditStatusEnum
.
PASS
.
getCode
().
equals
(
workOrder
.
getAuditStatus
()))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
CURR_WORK_ORDER_STATUS_ERROR_SAVE
);
}
// 缓存工单引用,afterSave 中使用
this
.
workOrder
=
workOrder
;
}
@Override
public
InspectionPlatTypeEnum
getPlatType
()
{
return
InspectionPlatTypeEnum
.
BACKEND
;
}
/**
* PC 端可编辑状态:待检测(1)、检测中(2)、已完成(3)
* 已取消(4)不可编辑
*/
private
boolean
isEditableStatus
(
Integer
status
)
{
if
(
status
==
null
)
{
return
false
;
}
return
InspectionWorkOrderStatusEnum
.
beableInspection
(
status
)
||
InspectionWorkOrderStatusEnum
.
COMPLETED
.
getCode
().
equals
(
status
);
}
@Override
public
String
getOperatorName
()
{
return
user
.
getUserName
();
}
@Override
public
Long
getOperatorId
()
{
return
(
long
)
user
.
getUserId
();
}
@Override
public
void
beforeSave
(
Long
recordId
,
List
<
InspectionNodeVO
>
allNodes
)
{
// 快照旧数据,用于保存后的 diff 对比生成操作日志
this
.
oldSnapshot
=
inspectionEditLogService
.
snapshotResults
(
recordId
,
operationNodeIds
);
log
.
info
(
"【PC端】快照旧数据完成,recordId={}, snapshotSize={}"
,
recordId
,
oldSnapshot
.
size
());
}
@Override
public
void
afterSave
(
Long
recordId
,
Long
taskId
,
Long
locationModule
,
List
<
InspectionNodeVO
>
allNodes
,
List
<
InspectionResultDTO
>
savedResults
)
{
// 1. 对比新旧数据,生成并保存操作日志
if
(
oldSnapshot
!=
null
&&
workOrder
!=
null
)
{
inspectionEditLogService
.
diffAndSaveLog
(
recordId
,
taskId
,
workOrder
,
oldSnapshot
,
savedResults
,
allNodes
,
operationNodeIds
,
locationModule
,
getPlatType
(),
(
long
)
user
.
getUserId
(),
user
.
getUserName
()
);
log
.
info
(
"【PC端】操作日志记录完成,recordId={}"
,
recordId
);
}
// 2. 保存后自动检查是否满足完成条件
if
(
workOrder
!=
null
)
{
boolean
autoCompleted
=
inspectionRecordService
.
tryAutoComplete
(
taskId
,
recordId
,
workOrder
,
getPlatType
(),
allNodes
,
getOperatorId
(),
getOperatorName
());
if
(
autoCompleted
)
{
log
.
info
(
"【PC端】保存后自动完成检测,taskId={}"
,
taskId
);
}
}
}
@Override
public
void
beforeScoreSave
(
Long
taskId
)
{
// 快照旧评分数据,用于保存后 diff 对比
this
.
oldRecord
=
inspectionRecordService
.
findRecordByTaskId
(
taskId
);
log
.
info
(
"【PC端】快照旧评分数据完成,taskId={}"
,
taskId
);
}
@Override
public
void
afterScoreSave
(
InspectionRecord
record
,
Long
taskId
,
InspectionWorkOrder
workOrder
)
{
inspectionEditLogService
.
saveScoreEditLog
(
record
.
getId
(),
taskId
,
workOrder
,
oldRecord
,
record
,
getPlatType
(),
getOperatorId
(),
getOperatorName
()
);
log
.
info
(
"【PC端】评分修改日志记录完成,recordId={}"
,
record
.
getId
());
}
@Override
public
CompleteInspectionRespVO
checkAndComplete
(
InspectionRecord
record
,
InspectionWorkOrder
workOrder
,
List
<
InspectionNodeVO
>
allNodes
)
{
// PC端:一级节点检查 + 评分检查 + 自动完成
inspectionRecordService
.
tryAutoComplete
(
workOrder
.
getId
(),
record
.
getId
(),
workOrder
,
getPlatType
(),
allNodes
,
getOperatorId
(),
getOperatorName
());
// PC端不向前端返回未完成节点信息
return
null
;
}
}
aus-admin/src/main/java/com/glsx/usedcar/export/InspectorExportBean.java
View file @
b2f6a2e
...
@@ -2,6 +2,7 @@ package com.glsx.usedcar.export;
...
@@ -2,6 +2,7 @@ package com.glsx.usedcar.export;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
com.alibaba.excel.annotation.write.style.ColumnWidth
;
import
com.alibaba.excel.annotation.write.style.ColumnWidth
;
import
com.glsx.usedcar.consts.common.SymbolConsts
;
import
com.glsx.usedcar.module.inspect.vo.InspectorPageRespVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectorPageRespVO
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.*
;
import
lombok.*
;
...
@@ -82,7 +83,7 @@ public class InspectorExportBean implements Serializable {
...
@@ -82,7 +83,7 @@ public class InspectorExportBean implements Serializable {
this
.
name
=
vo
.
getName
();
this
.
name
=
vo
.
getName
();
this
.
phone
=
vo
.
getPhone
();
this
.
phone
=
vo
.
getPhone
();
this
.
status
=
vo
.
getStatus
()
==
1
?
"启用"
:
"禁用"
;
this
.
status
=
vo
.
getStatus
()
==
1
?
"启用"
:
"禁用"
;
this
.
regionName
=
vo
.
getRegionName
();
this
.
regionName
=
vo
.
get
ProvinceName
()
+
SymbolConsts
.
HYPHEN
+
vo
.
get
RegionName
();
this
.
dispatchedCount
=
vo
.
getDispatchedCount
();
this
.
dispatchedCount
=
vo
.
getDispatchedCount
();
this
.
inProgressCount
=
vo
.
getInProgressCount
();
this
.
inProgressCount
=
vo
.
getInProgressCount
();
this
.
completedCount
=
vo
.
getCompletedCount
();
this
.
completedCount
=
vo
.
getCompletedCount
();
...
...
aus-admin/src/main/java/com/glsx/usedcar/web/rest/RopApiController.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
web
.
rest
;
import
com.alibaba.fastjson2.JSON
;
import
com.glsx.usedcar.gsc.GscApiInvoker
;
import
com.glsx.usedcar.gsc.vo.CarTypeListRespVO
;
import
com.glsx.usedcar.gsc.vo.GscApiResponse
;
import
com.glsx.usedcar.resp.BaseResp
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* rop api
* @author yangwei
* @version 1.0
* @since 2026/03/24 11:05
*/
@Slf4j
@RestController
@RequestMapping
(
"/rest/ropApi"
)
@RequiredArgsConstructor
@Tag
(
name
=
"rop-api调用前端控制器"
,
description
=
"各类rop-api调用处理"
)
public
class
RopApiController
{
private
final
GscApiInvoker
gscApiInvoker
;
@Operation
(
summary
=
"根据车系ID查询车型列表"
,
description
=
"根据车系ID查询车型列表"
)
@GetMapping
(
"getCarTypeList"
)
public
BaseResp
<
CarTypeListRespVO
>
getCarTypeList
(
@RequestParam
(
value
=
"csId"
,
required
=
false
)
String
csId
)
{
String
jsonResult
=
gscApiInvoker
.
getCarTypeList
(
csId
);
if
(
jsonResult
==
null
)
{
return
BaseResp
.
fail
(
"获取车型列表失败"
);
}
try
{
GscApiResponse
<
CarTypeListRespVO
>
response
=
JSON
.
parseObject
(
jsonResult
,
new
com
.
alibaba
.
fastjson2
.
TypeReference
<
GscApiResponse
<
CarTypeListRespVO
>>()
{});
if
(
"0"
.
equals
(
response
.
getCode
()))
{
return
BaseResp
.
success
(
response
.
getData
());
}
else
{
return
BaseResp
.
fail
(
response
.
getCode
(),
response
.
getMessage
());
}
}
catch
(
Exception
e
)
{
log
.
error
(
"解析车型列表响应失败: {}"
,
e
.
getMessage
());
return
BaseResp
.
fail
(
"解析响应数据失败"
);
}
}
@Operation
(
summary
=
"查询车品牌全称"
,
description
=
"查询车品牌全称"
)
@GetMapping
(
"getCarBrandComplete"
)
public
String
getCarBrandComplete
()
{
return
gscApiInvoker
.
getCarBrandComplete
();
}
}
aus-admin/src/main/java/com/glsx/usedcar/web/rest/event/EventTrackingController.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
web
.
rest
.
event
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.usedcar.enums.event.EventSourceEnum
;
import
com.glsx.usedcar.module.event.service.EventTrackingService
;
import
com.glsx.usedcar.module.event.vo.EventTrackingBatchSaveVO
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.validation.Valid
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.glsx.usedcar.module.security.entity.User
;
import
com.glsx.usedcar.resp.BaseResp
;
import
org.summerframework.core.exception.BusinessCodeException
;
/**
* 埋点事件控制器
*
* @author yangwei
* @version 1.0
* @since 2026/04/07 21:12
*/
@Slf4j
@RestController
@RequestMapping
(
"/rest/eventTracking"
)
@RequiredArgsConstructor
@Tag
(
name
=
"埋点事件控制器"
,
description
=
"埋点事件控制器"
)
public
class
EventTrackingController
{
private
final
EventTrackingService
eventTrackingService
;
/**
* 批量保存埋点事件
*
* @param vo 请求体(包含事件列表、业务主键、扩展参数)
* @param authentication 当前登录用户
* @return 操作结果
*/
@PostMapping
(
"/batchSave"
)
@Operation
(
summary
=
"批量保存埋点事件"
,
description
=
"前端批量上报用户行为埋点事件,支持同时携带业务主键和扩展参数"
)
public
BaseResp
<
Void
>
batchSave
(
@Valid
@RequestBody
EventTrackingBatchSaveVO
vo
,
Authentication
authentication
)
{
log
.
info
(
"【接口请求】批量保存埋点事件,操作人={},事件数量={}"
,
getUserName
(
authentication
),
vo
.
getEvents
()
==
null
?
0
:
vo
.
getEvents
().
size
());
try
{
User
user
=
(
User
)
authentication
.
getPrincipal
();
eventTrackingService
.
batchSave
(
vo
,
String
.
valueOf
(
user
.
getUserId
()),
user
.
getUserName
(),
EventSourceEnum
.
ADMIN
.
getSource
());
return
BaseResp
.
success
();
}
catch
(
BusinessCodeException
be
)
{
log
.
error
(
"【接口响应】批量保存埋点事件失败!操作人={},业务异常!"
,
getUserName
(
authentication
),
be
);
return
BaseResp
.
fail
(
StrUtil
.
toString
(
be
.
getCode
()),
be
.
getMessage
());
}
catch
(
Exception
e
)
{
log
.
error
(
"【接口响应】批量保存埋点事件失败!操作人={},系统异常!"
,
getUserName
(
authentication
),
e
);
return
BaseResp
.
fail
(
"系统异常: "
+
e
.
getMessage
());
}
}
private
String
getUserName
(
Authentication
authentication
)
{
try
{
return
authentication
!=
null
?
((
User
)
authentication
.
getPrincipal
()).
getUserName
()
:
"未知用户"
;
}
catch
(
Exception
e
)
{
return
"未知用户"
;
}
}
}
aus-admin/src/main/java/com/glsx/usedcar/web/rest/inspect/InspectionNodeController.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
web
.
rest
.
inspect
;
import
cn.hutool.core.util.StrUtil
;
import
com.glsx.usedcar.module.inspect.service.InspectionNodeService
;
import
com.glsx.usedcar.module.inspect.vo.InspectionNodeVO
;
import
com.glsx.usedcar.resp.BaseResp
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.Parameter
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.*
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
java.util.List
;
/**
* 检测节点前端控制器
* @author yangwei
* @version 1.0
* @since 2026/03/12 10:19
*/
@Slf4j
@RestController
@RequestMapping
(
"/rest/inspectionNode"
)
@RequiredArgsConstructor
@Tag
(
name
=
"检测节点前端控制器"
,
description
=
"检测节点的增删改查操作"
)
public
class
InspectionNodeController
{
private
final
InspectionNodeService
inspectionNodeService
;
/**
* 根据根节点 ID 查询下级节点列表
*
* @param rootNodeId 根节点 ID,评分评级模块输入 -1
* @param taskId 检测工单 ID
* @return 下级节点列表,同级按 sortOrder 升序
*/
@GetMapping
(
"/{rootNodeId}/children"
)
@Operation
(
summary
=
"查询下级节点"
,
description
=
"根据根节点 ID 查询该节点下的所有子节点,返回结果按 sortOrder 升序排列"
)
public
BaseResp
<
List
<
InspectionNodeVO
>>
listChildNodes
(
@PathVariable
(
"rootNodeId"
)
@Parameter
(
description
=
"根节点 ID,评分评级模块输入 -1"
,
required
=
true
)
Long
rootNodeId
,
@RequestParam
(
"taskId"
)
@Parameter
(
description
=
"检测工单ID"
)
Long
taskId
)
{
try
{
List
<
InspectionNodeVO
>
childNodes
=
inspectionNodeService
.
listChildNodesByParentId
(
rootNodeId
,
taskId
);
return
BaseResp
.
success
(
childNodes
);
}
catch
(
BusinessCodeException
be
)
{
log
.
error
(
"【接口响应】查询下级节点失败!业务异常!"
,
be
);
return
BaseResp
.
fail
(
StrUtil
.
toString
(
be
.
getCode
()),
be
.
getMessage
());
}
catch
(
Exception
e
)
{
log
.
error
(
"【接口响应】查询下级节点失败!系统异常!"
,
e
);
return
BaseResp
.
fail
(
"系统异常: "
+
e
.
getMessage
());
}
}
}
aus-admin/src/main/java/com/glsx/usedcar/web/rest/inspect/InspectionRecordController.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
web
.
rest
.
inspect
;
import
cn.hutool.core.util.StrUtil
;
import
com.glsx.usedcar.delegate.AdminSaveDelegate
;
import
com.glsx.usedcar.module.inspect.entity.InspectionOpLog
;
import
com.glsx.usedcar.module.inspect.service.InspectionEditLogService
;
import
com.glsx.usedcar.module.inspect.service.InspectionRecordService
;
import
com.glsx.usedcar.module.inspect.service.InspectionWorkOrderService
;
import
com.glsx.usedcar.module.inspect.vo.CompleteInspectionVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionBatchSaveVO
;
import
com.glsx.usedcar.module.security.entity.User
;
import
com.glsx.usedcar.resp.BaseResp
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.validation.Valid
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.web.bind.annotation.*
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.exception.BusinessCodeException
;
/**
* PC 端检测记录编辑接口
*
* @author yangwei
* @since 2026/4/8
*/
@Slf4j
@Tag
(
name
=
"检测记录编辑接口"
,
description
=
"PC端检测报告编辑操作"
)
@RestController
@RequiredArgsConstructor
@RequestMapping
(
"/rest/inspect/record"
)
public
class
InspectionRecordController
{
private
final
InspectionRecordService
inspectionRecordService
;
private
final
InspectionEditLogService
inspectionEditLogService
;
private
final
InspectionWorkOrderService
inspectionWorkOrderService
;
@PostMapping
(
"/save"
)
@Operation
(
summary
=
"保存检测数据(按一级模块)"
,
description
=
"PC端按一级模块保存检测数据"
)
public
BaseResp
<
Long
>
saveInspection
(
@RequestBody
@Valid
InspectionBatchSaveVO
req
,
Authentication
authentication
)
{
User
user
=
getUser
(
authentication
);
log
.
info
(
"【PC端】保存检测数据,taskId={}, module={}, moduleCount={}, 操作人={}"
,
req
.
getTaskId
(),
req
.
getLocationModule
(),
req
.
getModules
().
size
(),
user
.
getUserName
());
try
{
req
.
setNextFlag
(
true
);
AdminSaveDelegate
delegate
=
new
AdminSaveDelegate
(
user
,
inspectionEditLogService
,
inspectionWorkOrderService
,
inspectionRecordService
);
Long
recordId
=
inspectionRecordService
.
saveInspectionWithDelegate
(
req
,
delegate
);
log
.
info
(
"【PC端】保存检测数据成功,recordId={}"
,
recordId
);
return
BaseResp
.
success
(
recordId
,
"保存成功"
);
}
catch
(
BusinessCodeException
be
)
{
log
.
error
(
"【PC端】保存检测数据失败!业务异常!"
,
be
);
return
BaseResp
.
fail
(
StrUtil
.
toString
(
be
.
getCode
()),
be
.
getMessage
());
}
catch
(
Exception
e
)
{
log
.
error
(
"【PC端】保存检测数据失败!系统异常!"
,
e
);
return
BaseResp
.
fail
(
"系统异常: "
+
e
.
getMessage
());
}
}
@PostMapping
(
"/saveScore"
)
@Operation
(
summary
=
"保存评分数据"
,
description
=
"PC端保存检测评分(保存后自动检查是否满足完成条件)"
)
public
BaseResp
<
Long
>
saveScore
(
@RequestBody
@Valid
CompleteInspectionVO
req
,
Authentication
authentication
)
{
User
user
=
getUser
(
authentication
);
log
.
info
(
"【PC端】保存评分,taskId={}, 操作人={}"
,
req
.
getTaskId
(),
user
.
getUserName
());
try
{
AdminSaveDelegate
delegate
=
new
AdminSaveDelegate
(
user
,
inspectionEditLogService
,
inspectionWorkOrderService
,
inspectionRecordService
);
inspectionRecordService
.
saveScoreWithDelegate
(
req
,
delegate
);
Long
recordId
=
inspectionRecordService
.
findRecordIdByTaskId
(
req
.
getTaskId
());
log
.
info
(
"【PC端】保存评分成功,recordId={}"
,
recordId
);
return
BaseResp
.
success
(
recordId
,
"保存成功"
);
}
catch
(
BusinessCodeException
be
)
{
log
.
error
(
"【PC端】保存评分失败!业务异常!"
,
be
);
return
BaseResp
.
fail
(
StrUtil
.
toString
(
be
.
getCode
()),
be
.
getMessage
());
}
catch
(
Exception
e
)
{
log
.
error
(
"【PC端】保存评分失败!系统异常!"
,
e
);
return
BaseResp
.
fail
(
"系统异常: "
+
e
.
getMessage
());
}
}
@GetMapping
(
"/{recordId}/editLogs"
)
@Operation
(
summary
=
"查询操作日志"
,
description
=
"分页查询检测记录的编辑操作日志"
)
public
BaseResp
<
Page
<
InspectionOpLog
>>
editLogs
(
@PathVariable
Long
recordId
,
@RequestParam
(
defaultValue
=
"0"
)
int
page
,
@RequestParam
(
defaultValue
=
"20"
)
int
size
)
{
log
.
info
(
"【PC端】查询操作日志,recordId={}"
,
recordId
);
Pageable
pageable
=
PageRequest
.
of
(
page
,
size
);
return
BaseResp
.
success
(
inspectionEditLogService
.
queryLogs
(
recordId
,
pageable
));
}
private
User
getUser
(
Authentication
authentication
)
{
if
(
authentication
==
null
||
authentication
.
getPrincipal
()
==
null
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
LOGIN_ERROR
);
}
return
(
User
)
authentication
.
getPrincipal
();
}
}
aus-admin/src/main/java/com/glsx/usedcar/web/rest/inspect/InspectionTemplateController.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
web
.
rest
.
inspect
;
import
cn.hutool.core.util.StrUtil
;
import
com.glsx.usedcar.module.inspect.entity.InspectionTemplate
;
import
com.glsx.usedcar.module.inspect.service.InspectionNodeService
;
import
com.glsx.usedcar.module.inspect.service.InspectionTemplateService
;
import
com.glsx.usedcar.module.inspect.vo.InspectionRootNodeVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionTemplateDefaultValueReqVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionTemplateDetailRespVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionTemplateRespVO
;
import
com.glsx.usedcar.module.security.entity.User
;
import
com.glsx.usedcar.resp.BaseResp
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.Parameter
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.validation.Valid
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.domain.Page
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.web.bind.annotation.*
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
org.summerframework.orm.paging.Pagination
;
import
java.util.List
;
import
java.util.Map
;
/**
* 检测报告模版前端控制器
* @author yangwei
* @version 1.0
* @since 2026/04/07 19:47
*/
@Slf4j
@RestController
@RequestMapping
(
"/rest/inspectionTemplate"
)
@RequiredArgsConstructor
@Tag
(
name
=
"检测报告模版前端控制器"
,
description
=
"检测报告模版的增删改查操作"
)
public
class
InspectionTemplateController
{
private
final
InspectionNodeService
inspectionNodeService
;
private
final
InspectionTemplateService
inspectionTemplateService
;
/**
* 分页查询检测模版列表
* <p>
* 支持通过 data.keyword 模糊匹配模版名称、模版编码
*/
@Operation
(
summary
=
"分页查询检测模版"
,
description
=
"返回模版基本信息(编码、名称、类型、状态、版本、描述等),支持 data.keyword 模糊查询"
)
@PostMapping
(
"/page"
)
public
Page
<
InspectionTemplateRespVO
>
pageList
(
@RequestBody
Pagination
<
InspectionTemplate
>
pagination
,
Authentication
authentication
)
{
log
.
info
(
"【接口请求】分页查询检测模版,操作人={},页码={},条数={}"
,
getUserName
(
authentication
),
pagination
.
getOffset
(),
pagination
.
getLimit
());
try
{
return
inspectionTemplateService
.
pageList
(
pagination
);
}
catch
(
Exception
e
)
{
log
.
error
(
"【接口响应】分页查询检测模版失败!操作人={},系统异常!"
,
getUserName
(
authentication
),
e
);
return
null
;
}
}
/**
* 查询检测模版详情(含节点配置树)
*/
@Operation
(
summary
=
"检测模版详情"
,
description
=
"返回模版基本信息及完整节点配置树(不填充检测数据)"
)
@GetMapping
(
"/detail/{id}"
)
public
BaseResp
<
InspectionTemplateDetailRespVO
>
detail
(
@Parameter
(
description
=
"模版ID"
,
required
=
true
)
@PathVariable
(
"id"
)
Long
id
,
Authentication
authentication
)
{
log
.
info
(
"【接口请求】查询检测模版详情,操作人={},模版ID={}"
,
getUserName
(
authentication
),
id
);
try
{
InspectionTemplateDetailRespVO
result
=
inspectionTemplateService
.
detail
(
id
);
return
BaseResp
.
success
(
result
);
}
catch
(
BusinessCodeException
be
)
{
log
.
error
(
"【接口响应】查询检测模版详情失败!操作人={},业务异常!"
,
getUserName
(
authentication
),
be
);
return
BaseResp
.
fail
(
StrUtil
.
toString
(
be
.
getCode
()),
be
.
getMessage
());
}
catch
(
Exception
e
)
{
log
.
error
(
"【接口响应】查询检测模版详情失败!操作人={},系统异常!"
,
getUserName
(
authentication
),
e
);
return
BaseResp
.
fail
(
"系统异常: "
+
e
.
getMessage
());
}
}
/**
* 安全获取操作人姓名(避免空指针)
*/
private
String
getUserName
(
Authentication
authentication
)
{
try
{
return
authentication
!=
null
?
((
User
)
authentication
.
getPrincipal
()).
getUserName
()
:
"未知用户"
;
}
catch
(
Exception
e
)
{
return
"未知用户"
;
}
}
/**
* 查询检测模版根节点列表
*
* @param taskId 检测工单Id
* @return 根节点列表
*/
@GetMapping
(
"/{taskId}/rootNodes"
)
@Operation
(
summary
=
"查询检测模版根节点"
,
description
=
"根据模版ID查询该模版下的所有根节点(parentId=0),按sortOrder升序排列"
)
public
BaseResp
<
List
<
InspectionRootNodeVO
>>
listRootNodes
(
@PathVariable
@Parameter
(
description
=
"检测工单ID"
,
required
=
true
)
Long
taskId
)
{
log
.
info
(
"【接口请求】查询检测模版根节点,taskId={}"
,
taskId
);
try
{
return
BaseResp
.
success
(
inspectionNodeService
.
listRootNodes
(
taskId
));
}
catch
(
BusinessCodeException
be
)
{
log
.
error
(
"【接口响应】查询检测模版根节点失败!taskId={},业务异常!"
,
taskId
,
be
);
return
BaseResp
.
fail
(
StrUtil
.
toString
(
be
.
getCode
()),
be
.
getMessage
());
}
catch
(
Exception
e
)
{
log
.
error
(
"【接口响应】查询检测模版根节点失败!taskId={},系统异常!"
,
taskId
,
e
);
return
BaseResp
.
fail
(
"系统异常: "
+
e
.
getMessage
());
}
}
@PostMapping
(
"/default"
)
@Operation
(
summary
=
"获取模版默认值"
,
description
=
"获取模版默认值"
)
public
BaseResp
<
Map
<
String
,
String
>>
getTemplateDefaultValue
(
@RequestBody
@Valid
@Parameter
(
description
=
"请求参数"
,
required
=
true
)
InspectionTemplateDefaultValueReqVO
reqVO
)
{
log
.
info
(
"【接口请求】获取模版默认值"
);
try
{
return
BaseResp
.
success
(
inspectionTemplateService
.
getTemplateDefaultValue
(
reqVO
));
}
catch
(
BusinessCodeException
be
)
{
log
.
error
(
"【接口响应】获取模版默认值失败!业务异常!"
,
be
);
return
BaseResp
.
fail
(
StrUtil
.
toString
(
be
.
getCode
()),
be
.
getMessage
());
}
catch
(
Exception
e
)
{
log
.
error
(
"【接口响应】获取模版默认值失败!系统异常!"
,
e
);
return
BaseResp
.
fail
(
"系统异常: "
+
e
.
getMessage
());
}
}
}
aus-admin/src/main/java/com/glsx/usedcar/web/rest/inspect/InspectionWorkOrderController.java
View file @
b2f6a2e
...
@@ -17,6 +17,8 @@ import jakarta.validation.Valid;
...
@@ -17,6 +17,8 @@ import jakarta.validation.Valid;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -206,4 +208,19 @@ public class InspectionWorkOrderController {
...
@@ -206,4 +208,19 @@ public class InspectionWorkOrderController {
return
BaseResp
.
fail
(
"系统异常: "
+
e
.
getMessage
());
return
BaseResp
.
fail
(
"系统异常: "
+
e
.
getMessage
());
}
}
}
}
@Operation
(
summary
=
"查询工单操作日志"
,
description
=
"分页查询检测工单操作日志,操作类型为11(修改检测项信息)和12(修改检测评分)时会关联查询具体修改内容"
)
@PostMapping
(
"/opLog/{workOrderId}/page"
)
public
BaseResp
<
Page
<
WorkOrderOpLogRespVO
>>
queryWorkOrderOpLogPage
(
@PathVariable
(
"workOrderId"
)
Long
workOrderId
,
@RequestBody
Pagination
<
InspectionWorkOrder
>
pagination
)
{
log
.
info
(
"查询工单操作日志,workOrderId={}"
,
workOrderId
);
try
{
Page
<
WorkOrderOpLogRespVO
>
result
=
inspectionWorkOrderService
.
queryWorkOrderOpLogPage
(
workOrderId
,
pagination
.
getPageRequest
());
return
BaseResp
.
success
(
result
);
}
catch
(
Exception
e
)
{
log
.
error
(
"查询工单操作日志失败!系统异常!"
,
e
);
return
BaseResp
.
fail
(
"系统异常: "
+
e
.
getMessage
());
}
}
}
}
aus-core/src/main/java/com/glsx/usedcar/consts/common/CommonConsts.java
View file @
b2f6a2e
...
@@ -14,4 +14,7 @@ public interface CommonConsts {
...
@@ -14,4 +14,7 @@ public interface CommonConsts {
/** 1 */
/** 1 */
String
ONE
=
"1"
;
String
ONE
=
"1"
;
Integer
ZERO_INT
=
0
;
Integer
ONE_INT
=
1
;
}
}
aus-core/src/main/java/com/glsx/usedcar/consts/common/SymbolConsts.java
View file @
b2f6a2e
...
@@ -20,4 +20,7 @@ public interface SymbolConsts {
...
@@ -20,4 +20,7 @@ public interface SymbolConsts {
/** " " */
/** " " */
String
BLANK
=
" "
;
String
BLANK
=
" "
;
/** "#" */
String
SHARP
=
"#"
;
}
}
aus-core/src/main/java/com/glsx/usedcar/consts/inspect/InspectConstants.java
View file @
b2f6a2e
...
@@ -83,4 +83,27 @@ public interface InspectConstants {
...
@@ -83,4 +83,27 @@ public interface InspectConstants {
// // ==================== simple-lock key ====================
// // ==================== simple-lock key ====================
/** 检测锁,使用工单id加锁 */
/** 检测锁,使用工单id加锁 */
String
INSPECTION_LOCK_KEY
=
"simpleLock:inspection:{0}"
;
String
INSPECTION_LOCK_KEY
=
"simpleLock:inspection:{0}"
;
// ==================== 检测评分 ====================
/** "外观评分" */
String
SCORE_EXTERIOR
=
"外观评分"
;
/** 外观评分依据 */
String
SCORE_EXTERIOR_BASE
=
"外观评分依据"
;
/** "综合评分" */
String
SCORE_OVERALL
=
"综合评分"
;
/** 综合评分依据 */
String
SCORE_OVERALL_BASE
=
"综合评价"
;
/** "内饰评分" */
String
SCORE_INTERIOR
=
"内饰评级"
;
/** 内饰评分依据 */
String
SCORE_INTERIOR_BASE
=
"内饰评级依据"
;
/** "骨架评分" */
String
SCORE_SKELETON
=
"骨架评级"
;
/** 骨架评分依据 */
String
SCORE_SKELETON_BASE
=
"骨架评级依据"
;
}
}
aus-core/src/main/java/com/glsx/usedcar/consts/inspect/JpaQueryConstants.java
View file @
b2f6a2e
...
@@ -8,6 +8,8 @@ package com.glsx.usedcar.consts.inspect;
...
@@ -8,6 +8,8 @@ package com.glsx.usedcar.consts.inspect;
*/
*/
public
interface
JpaQueryConstants
{
public
interface
JpaQueryConstants
{
String
KEYWORD
=
"keyword"
;
/**
/**
* 检测师
* 检测师
...
...
aus-core/src/main/java/com/glsx/usedcar/converts/InspectionOpLogConverter.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
converts
;
import
com.glsx.usedcar.module.inspect.entity.InspectionOpLogItem
;
import
com.glsx.usedcar.module.inspect.vo.OpLogItemVO
;
import
org.mapstruct.Mapper
;
import
java.util.List
;
/**
* 检测项编辑日志转换器
* @author yangwei
* @version 1.0
* @since 2026/04/09 18:09
*/
@Mapper
(
componentModel
=
"spring"
)
public
interface
InspectionOpLogConverter
{
/**
* 单个实体转换为VO
*
* @param item 检测操作日志明细实体
* @return 操作日志明细VO
*/
OpLogItemVO
toOpLogItemVO
(
InspectionOpLogItem
item
);
/**
* 多个实体转换为VO列表
*
* @param items 检测操作日志明细实体列表
* @return 操作日志明细VO列表
*/
List
<
OpLogItemVO
>
toOpLogItemVOList
(
List
<
InspectionOpLogItem
>
items
);
}
aus-core/src/main/java/com/glsx/usedcar/enums/event/BusinessTypeEnum.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
enums
.
event
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
/**
* 埋点时间业务类型枚举
* @author yangwei
* @version 1.0
* @since 2026/04/07 21:27
*/
@Getter
@AllArgsConstructor
public
enum
BusinessTypeEnum
{
INSPECTION_MANAGEMENT
(
"INSPECTION_MANAGEMENT"
,
"检测管理"
),
REPORT
(
"REPORT"
,
"报表"
),
VEHICLE
(
"VEHICLE"
,
"车辆"
),
WORK_ORDER
(
"WORK_ORDER"
,
"工单"
);
private
final
String
value
;
private
final
String
desc
;
}
aus-core/src/main/java/com/glsx/usedcar/enums/event/EventSourceEnum.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
enums
.
event
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
/**
* 事件来源,admin、api、inspector
* @author yangwei
* @version 1.0
* @since 2026/04/07 21:32
*/
@Getter
@AllArgsConstructor
public
enum
EventSourceEnum
{
// 事件来源,admin、api、inspector
ADMIN
(
"admin"
),
API
(
"api"
),
INSPECTOR
(
"inspector"
);
private
final
String
source
;
}
aus-core/src/main/java/com/glsx/usedcar/enums/event/ParamTypeEnum.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
enums
.
event
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
/**
* 埋点事件参数类型
* @author yangwei
* @version 1.0
* @since 2026/04/07 21:24
*/
@Getter
@AllArgsConstructor
public
enum
ParamTypeEnum
{
// 参数类型: STRING, NUMBER, BOOLEAN, ARRAY, OBJECT
STRING
(
"STRING"
),
NUMBER
(
"NUMBER"
),
BOOLEAN
(
"BOOLEAN"
),
ARRAY
(
"ARRAY"
),
OBJECT
(
"OBJECT"
);
private
final
String
value
;
}
aus-core/src/main/java/com/glsx/usedcar/enums/inspect/InspectionWorkOrderOperationTypeEnum.java
View file @
b2f6a2e
...
@@ -16,7 +16,10 @@ public enum InspectionWorkOrderOperationTypeEnum {
...
@@ -16,7 +16,10 @@ public enum InspectionWorkOrderOperationTypeEnum {
COMPLETE_ORDER
(
7
,
"完成工单"
),
COMPLETE_ORDER
(
7
,
"完成工单"
),
CANCEL_ORDER
(
8
,
"取消工单"
),
CANCEL_ORDER
(
8
,
"取消工单"
),
UPDATE_ORDER_INFO
(
9
,
"修改工单信息"
),
UPDATE_ORDER_INFO
(
9
,
"修改工单信息"
),
REDISPATCH_ORDER
(
10
,
"重新派单"
);
REDISPATCH_ORDER
(
10
,
"重新派单"
),
UPDATE_INSPECTION_ITEM
(
11
,
"修改检测项信息"
),
UPDATE_INSPECTION_SCORE
(
12
,
"修改检测评分"
),
;
private
final
Integer
code
;
private
final
Integer
code
;
private
final
String
desc
;
private
final
String
desc
;
...
...
aus-core/src/main/java/com/glsx/usedcar/module/event/dao/EventTrackingBusinessKeyRepository.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
event
.
dao
;
import
com.glsx.usedcar.module.event.entity.EventTrackingBusinessKey
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.stereotype.Repository
;
import
org.summerframework.orm.BaseRepository
;
import
java.util.List
;
import
java.util.Optional
;
/**
* 埋点事件业务主键表数据访问层
*
* @author yangwei
* @since 2026/4/7
*/
@Repository
public
interface
EventTrackingBusinessKeyRepository
extends
BaseRepository
<
EventTrackingBusinessKey
,
Long
>,
JpaSpecificationExecutor
<
EventTrackingBusinessKey
>
{
/**
* 根据事件ID和删除标识查询业务主键列表
*
* @param eventId 事件ID
* @param deleteFlag 删除标识
* @return 业务主键列表
*/
List
<
EventTrackingBusinessKey
>
findByEventIdAndDeleteFlag
(
Long
eventId
,
String
deleteFlag
);
/**
* 根据业务类型和业务主键及删除标识查询列表
*
* @param businessType 业务类型
* @param businessKey 业务主键
* @param deleteFlag 删除标识
* @return 业务主键列表
*/
List
<
EventTrackingBusinessKey
>
findByBusinessTypeAndBusinessKeyAndDeleteFlag
(
String
businessType
,
String
businessKey
,
String
deleteFlag
);
/**
* 根据事件ID、业务类型、业务主键及删除标识查询
*
* @param eventId 事件ID
* @param businessType 业务类型
* @param businessKey 业务主键
* @param deleteFlag 删除标识
* @return 业务主键信息
*/
Optional
<
EventTrackingBusinessKey
>
findByEventIdAndBusinessTypeAndBusinessKeyAndDeleteFlag
(
Long
eventId
,
String
businessType
,
String
businessKey
,
String
deleteFlag
);
/**
* 根据事件ID列表和删除标识查询业务主键列表
*
* @param eventIds 事件ID列表
* @param deleteFlag 删除标识
* @return 业务主键列表
*/
List
<
EventTrackingBusinessKey
>
findByEventIdInAndDeleteFlag
(
List
<
Long
>
eventIds
,
String
deleteFlag
);
}
aus-core/src/main/java/com/glsx/usedcar/module/event/dao/EventTrackingParamRepository.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
event
.
dao
;
import
com.glsx.usedcar.module.event.entity.EventTrackingParam
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.stereotype.Repository
;
import
org.summerframework.orm.BaseRepository
;
import
java.util.List
;
import
java.util.Optional
;
/**
* 埋点事件参数表数据访问层
*
* @author yangwei
* @since 2026/4/7
*/
@Repository
public
interface
EventTrackingParamRepository
extends
BaseRepository
<
EventTrackingParam
,
Long
>,
JpaSpecificationExecutor
<
EventTrackingParam
>
{
/**
* 根据事件ID和删除标识查询参数列表
*
* @param eventId 事件ID
* @param deleteFlag 删除标识
* @return 参数列表
*/
List
<
EventTrackingParam
>
findByEventIdAndDeleteFlag
(
Long
eventId
,
String
deleteFlag
);
/**
* 根据事件ID、参数键和删除标识查询参数
*
* @param eventId 事件ID
* @param paramKey 参数键
* @param deleteFlag 删除标识
* @return 参数信息
*/
Optional
<
EventTrackingParam
>
findByEventIdAndParamKeyAndDeleteFlag
(
Long
eventId
,
String
paramKey
,
String
deleteFlag
);
/**
* 根据事件ID列表和删除标识查询参数列表
*
* @param eventIds 事件ID列表
* @param deleteFlag 删除标识
* @return 参数列表
*/
List
<
EventTrackingParam
>
findByEventIdInAndDeleteFlag
(
List
<
Long
>
eventIds
,
String
deleteFlag
);
/**
* 根据参数键和删除标识查询参数列表
*
* @param paramKey 参数键
* @param deleteFlag 删除标识
* @return 参数列表
*/
List
<
EventTrackingParam
>
findByParamKeyAndDeleteFlag
(
String
paramKey
,
String
deleteFlag
);
}
aus-core/src/main/java/com/glsx/usedcar/module/event/dao/EventTrackingRepository.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
event
.
dao
;
import
com.glsx.usedcar.module.event.entity.EventTracking
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.stereotype.Repository
;
import
org.summerframework.orm.BaseRepository
;
import
java.time.LocalDateTime
;
import
java.util.List
;
/**
* 埋点事件主表数据访问层
*
* @author yangwei
* @since 2026/4/7
*/
@Repository
public
interface
EventTrackingRepository
extends
BaseRepository
<
EventTracking
,
Long
>,
JpaSpecificationExecutor
<
EventTracking
>
{
/**
* 根据事件代码和删除标识查询列表
*
* @param eventCode 事件代码
* @param deleteFlag 删除标识
* @return 事件列表
*/
List
<
EventTracking
>
findByEventCodeAndDeleteFlag
(
String
eventCode
,
String
deleteFlag
);
/**
* 根据账户ID和删除标识查询列表
*
* @param accountId 账户ID
* @param deleteFlag 删除标识
* @return 事件列表
*/
List
<
EventTracking
>
findByAccountIdAndDeleteFlag
(
String
accountId
,
String
deleteFlag
);
/**
* 根据账户ID、事件代码和删除标识查询列表
*
* @param accountId 账户ID
* @param eventCode 事件代码
* @param deleteFlag 删除标识
* @return 事件列表
*/
List
<
EventTracking
>
findByAccountIdAndEventCodeAndDeleteFlag
(
String
accountId
,
String
eventCode
,
String
deleteFlag
);
/**
* 根据事件时间范围和删除标识查询列表
*
* @param startTime 开始时间
* @param endTime 结束时间
* @param deleteFlag 删除标识
* @return 事件列表
*/
List
<
EventTracking
>
findByEventTimeBetweenAndDeleteFlag
(
LocalDateTime
startTime
,
LocalDateTime
endTime
,
String
deleteFlag
);
}
aus-core/src/main/java/com/glsx/usedcar/module/event/dao/EventTypeConfigRepository.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
event
.
dao
;
import
com.glsx.usedcar.module.event.entity.EventTypeConfig
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.stereotype.Repository
;
import
org.summerframework.orm.BaseRepository
;
import
java.util.List
;
import
java.util.Optional
;
/**
* 事件类型配置表数据访问层
*
* @author yangwei
* @since 2026/4/7
*/
@Repository
public
interface
EventTypeConfigRepository
extends
BaseRepository
<
EventTypeConfig
,
Long
>,
JpaSpecificationExecutor
<
EventTypeConfig
>
{
/**
* 根据事件名称和删除标识查询
*
* @param eventName 事件名称
* @param deleteFlag 删除标识
* @return 事件类型配置
*/
Optional
<
EventTypeConfig
>
findByEventNameAndDeleteFlag
(
String
eventName
,
String
deleteFlag
);
/**
* 根据事件代码和删除标识查询
*
* @param eventCode 事件代码
* @param deleteFlag 删除标识
* @return 事件类型配置
*/
Optional
<
EventTypeConfig
>
findByEventCodeAndDeleteFlag
(
String
eventCode
,
String
deleteFlag
);
/**
* 根据事件类型和删除标识查询列表
*
* @param eventType 事件类型
* @param deleteFlag 删除标识
* @return 事件类型配置列表
*/
List
<
EventTypeConfig
>
findByEventTypeAndDeleteFlag
(
String
eventType
,
String
deleteFlag
);
/**
* 根据所属模块和删除标识查询列表
*
* @param module 所属模块
* @param deleteFlag 删除标识
* @return 事件类型配置列表
*/
List
<
EventTypeConfig
>
findByModuleAndDeleteFlag
(
String
module
,
String
deleteFlag
);
/**
* 根据启用状态和删除标识查询列表
*
* @param isActive 是否启用
* @param deleteFlag 删除标识
* @return 事件类型配置列表
*/
List
<
EventTypeConfig
>
findByIsActiveAndDeleteFlag
(
Integer
isActive
,
String
deleteFlag
);
}
aus-core/src/main/java/com/glsx/usedcar/module/event/entity/EventTracking.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
event
.
entity
;
import
jakarta.persistence.*
;
import
lombok.*
;
import
org.hibernate.annotations.DynamicInsert
;
import
org.hibernate.annotations.DynamicUpdate
;
import
org.springframework.data.jpa.domain.support.AuditingEntityListener
;
import
org.summerframework.orm.entity.AuditingEntity
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
static
jakarta
.
persistence
.
GenerationType
.
IDENTITY
;
/**
* 埋点事件主表(EventTracking)实体类
*
* @author yangwei
* @since 2026/4/7
*/
@Entity
@Getter
@Setter
@Builder
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
@AllArgsConstructor
@Table
(
name
=
"event_tracking"
)
@EntityListeners
(
AuditingEntityListener
.
class
)
public
class
EventTracking
extends
AuditingEntity
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
2325290238446386363L
;
/**
* 主键ID
*/
@Id
@GeneratedValue
(
strategy
=
IDENTITY
)
@Column
(
name
=
"EVENT_ID"
,
unique
=
true
,
nullable
=
false
)
private
Long
eventId
;
/**
* 事件代码
*/
@Column
(
name
=
"EVENT_CODE"
,
nullable
=
false
,
length
=
128
)
private
String
eventCode
;
/**
* 事件来源,admin、api、inspector
* @see com.glsx.usedcar.enums.event.EventSourceEnum
*/
@Column
(
name
=
"SOURCE"
,
nullable
=
false
,
length
=
128
)
private
String
source
;
/**
* 操作人账户ID
*/
@Column
(
name
=
"ACCOUNT_ID"
,
nullable
=
false
,
length
=
64
)
private
String
accountId
;
/**
* 操作人账户名称
*/
@Column
(
name
=
"ACCOUNT_NAME"
,
nullable
=
false
,
length
=
64
)
private
String
accountName
;
/**
* 操作人工号
*/
@Column
(
name
=
"OPERATOR_ID"
,
length
=
64
)
private
String
operatorId
;
/**
* 时长(秒),用于页面停留事件
*/
@Column
(
name
=
"DURATION"
)
private
Integer
duration
;
/**
* 事件时间
*/
@Column
(
name
=
"EVENT_TIME"
,
nullable
=
false
)
private
LocalDateTime
eventTime
;
/**
* 删除标识 N:未删除 D:已删除
*/
@Builder
.
Default
@Column
(
name
=
"DELETE_FLAG"
,
nullable
=
false
,
length
=
1
)
private
String
deleteFlag
=
"N"
;
/**
* 备注
*/
@Column
(
name
=
"REMARK"
,
length
=
256
)
private
String
remark
;
}
aus-core/src/main/java/com/glsx/usedcar/module/event/entity/EventTrackingBusinessKey.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
event
.
entity
;
import
jakarta.persistence.*
;
import
lombok.*
;
import
org.hibernate.annotations.DynamicInsert
;
import
org.hibernate.annotations.DynamicUpdate
;
import
org.springframework.data.jpa.domain.support.AuditingEntityListener
;
import
org.summerframework.orm.entity.AuditingEntity
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
static
jakarta
.
persistence
.
GenerationType
.
IDENTITY
;
/**
* 埋点事件业务主键表(EventTrackingBusinessKey)实体类
*
* @author yangwei
* @since 2026/4/7
*/
@Entity
@Getter
@Setter
@Builder
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
@AllArgsConstructor
@Table
(
name
=
"event_tracking_business_key"
)
@EntityListeners
(
AuditingEntityListener
.
class
)
public
class
EventTrackingBusinessKey
extends
AuditingEntity
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
-
5710355237303945508L
;
/**
* 主键ID
*/
@Id
@GeneratedValue
(
strategy
=
IDENTITY
)
@Column
(
name
=
"BIZ_ID"
,
unique
=
true
,
nullable
=
false
)
private
Long
bizId
;
/**
* 关联 event_tracking.event_id
*/
@Column
(
name
=
"EVENT_ID"
,
nullable
=
false
)
private
Long
eventId
;
/**
* 业务类型: REPORT-报告, VEHICLE-车辆, WORK_ORDER-工单...
*/
@Column
(
name
=
"BUSINESS_TYPE"
,
nullable
=
false
,
length
=
64
)
private
String
businessType
;
/**
* 业务主键
*/
@Column
(
name
=
"BUSINESS_KEY"
,
nullable
=
false
,
length
=
128
)
private
String
businessKey
;
/**
* 删除标识 N:未删除 D:已删除
*/
@Builder
.
Default
@Column
(
name
=
"DELETE_FLAG"
,
nullable
=
false
,
length
=
1
)
private
String
deleteFlag
=
"N"
;
/**
* 备注
*/
@Column
(
name
=
"REMARK"
,
length
=
256
)
private
String
remark
;
}
aus-core/src/main/java/com/glsx/usedcar/module/event/entity/EventTrackingParam.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
event
.
entity
;
import
jakarta.persistence.*
;
import
lombok.*
;
import
org.hibernate.annotations.DynamicInsert
;
import
org.hibernate.annotations.DynamicUpdate
;
import
org.springframework.data.jpa.domain.support.AuditingEntityListener
;
import
org.summerframework.orm.entity.AuditingEntity
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
static
jakarta
.
persistence
.
GenerationType
.
IDENTITY
;
/**
* 埋点事件参数表(EventTrackingParam)实体类
*
* @author yangwei
* @since 2026/4/7
*/
@Entity
@Getter
@Setter
@Builder
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
@AllArgsConstructor
@Table
(
name
=
"event_tracking_param"
)
@EntityListeners
(
AuditingEntityListener
.
class
)
public
class
EventTrackingParam
extends
AuditingEntity
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
-
928261531995021747L
;
/**
* 主键ID
*/
@Id
@GeneratedValue
(
strategy
=
IDENTITY
)
@Column
(
name
=
"PARAM_ID"
,
unique
=
true
,
nullable
=
false
)
private
Long
paramId
;
/**
* 关联 event_tracking.event_id
*/
@Column
(
name
=
"EVENT_ID"
,
nullable
=
false
)
private
Long
eventId
;
/**
* 参数键
*/
@Column
(
name
=
"PARAM_KEY"
,
nullable
=
false
,
length
=
100
)
private
String
paramKey
;
/**
* 参数值
*/
@Column
(
name
=
"PARAM_VALUE"
,
columnDefinition
=
"TEXT"
)
private
String
paramValue
;
/**
* 参数类型: STRING, NUMBER, BOOLEAN, ARRAY, OBJECT
*/
@Builder
.
Default
@Column
(
name
=
"PARAM_TYPE"
,
length
=
32
)
private
String
paramType
=
"STRING"
;
/**
* 删除标识 N:未删除 D:已删除
*/
@Builder
.
Default
@Column
(
name
=
"DELETE_FLAG"
,
nullable
=
false
,
length
=
1
)
private
String
deleteFlag
=
"N"
;
/**
* 备注
*/
@Column
(
name
=
"REMARK"
,
length
=
256
)
private
String
remark
;
}
aus-core/src/main/java/com/glsx/usedcar/module/event/entity/EventTypeConfig.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
event
.
entity
;
import
jakarta.persistence.*
;
import
lombok.*
;
import
org.hibernate.annotations.DynamicInsert
;
import
org.hibernate.annotations.DynamicUpdate
;
import
org.springframework.data.jpa.domain.support.AuditingEntityListener
;
import
org.summerframework.orm.entity.AuditingEntity
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
static
jakarta
.
persistence
.
GenerationType
.
IDENTITY
;
/**
* 事件类型配置表(EventTypeConfig)实体类
*
* @author yangwei
* @since 2026/4/7
*/
@Entity
@Getter
@Setter
@Builder
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
@AllArgsConstructor
@Table
(
name
=
"event_type_config"
)
@EntityListeners
(
AuditingEntityListener
.
class
)
public
class
EventTypeConfig
extends
AuditingEntity
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
2192070012796048699L
;
/**
* 主键ID
*/
@Id
@GeneratedValue
(
strategy
=
IDENTITY
)
@Column
(
name
=
"ID"
,
unique
=
true
,
nullable
=
false
)
private
Long
id
;
/**
* 事件类型: CLICK-点击事件, PAGE_VIEW-页面浏览, PAGE_DURATION-页面停留时长
*/
@Column
(
name
=
"EVENT_TYPE"
,
nullable
=
false
,
length
=
32
)
private
String
eventType
;
/**
* 事件代码
*/
@Column
(
name
=
"EVENT_CODE"
,
nullable
=
false
,
length
=
128
)
private
String
eventCode
;
/**
* 事件名称
*/
@Column
(
name
=
"EVENT_NAME"
,
nullable
=
false
,
length
=
128
)
private
String
eventName
;
/**
* 事件描述
*/
@Column
(
name
=
"EVENT_DESC"
,
length
=
512
)
private
String
eventDesc
;
/**
* 所属模块
*/
@Column
(
name
=
"MODULE"
,
length
=
64
)
private
String
module
;
/**
* 是否启用 1:启用 0:禁用
*/
@Builder
.
Default
@Column
(
name
=
"IS_ACTIVE"
,
nullable
=
false
)
private
Integer
isActive
=
1
;
/**
* 删除标识 N:未删除 D:已删除
*/
@Builder
.
Default
@Column
(
name
=
"DELETE_FLAG"
,
nullable
=
false
,
length
=
1
)
private
String
deleteFlag
=
"N"
;
/**
* 备注
*/
@Column
(
name
=
"REMARK"
,
length
=
256
)
private
String
remark
;
}
aus-core/src/main/java/com/glsx/usedcar/module/event/service/EventTrackingService.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
event
.
service
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.glsx.usedcar.consts.common.CommonConsts
;
import
com.glsx.usedcar.enums.common.DeleteFlag
;
import
com.glsx.usedcar.enums.event.EventSourceEnum
;
import
com.glsx.usedcar.enums.event.ParamTypeEnum
;
import
com.glsx.usedcar.module.event.dao.EventTrackingBusinessKeyRepository
;
import
com.glsx.usedcar.module.event.dao.EventTrackingParamRepository
;
import
com.glsx.usedcar.module.event.dao.EventTrackingRepository
;
import
com.glsx.usedcar.module.event.dao.EventTypeConfigRepository
;
import
com.glsx.usedcar.module.event.entity.EventTracking
;
import
com.glsx.usedcar.module.event.entity.EventTrackingBusinessKey
;
import
com.glsx.usedcar.module.event.entity.EventTrackingParam
;
import
com.glsx.usedcar.module.event.entity.EventTypeConfig
;
import
com.glsx.usedcar.module.event.vo.EventTrackingBatchSaveVO
;
import
com.glsx.usedcar.module.event.vo.EventTrackingBatchSaveVO.BusinessKeyVO
;
import
com.glsx.usedcar.module.event.vo.EventTrackingBatchSaveVO.EventTrackingItemVO
;
import
com.glsx.usedcar.module.event.vo.EventTrackingBatchSaveVO.ParamVO
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
* 埋点事件服务
*
* @author yangwei
* @version 1.0
* @since 2026/04/07
*/
@Slf4j
@Service
@RequiredArgsConstructor
public
class
EventTrackingService
{
private
final
EventTrackingRepository
eventTrackingRepository
;
private
final
EventTypeConfigRepository
eventTypeConfigRepository
;
private
final
EventTrackingParamRepository
eventTrackingParamRepository
;
private
final
EventTrackingBusinessKeyRepository
eventTrackingBusinessKeyRepository
;
/**
* 批量保存埋点事件
* <p>
* 流程:
* 1. 校验 eventCode 在 event_type_config 中存在且启用
* 2. 批量插入 event_tracking 主表
* 3. 批量插入 event_tracking_business_key(若有)
* 4. 批量插入 event_tracking_param(若有)
*
* @param vo 批量请求体
* @param accountId 操作人账户ID
* @param accountName 操作人账户名称
* @param source 来源标识(admin / api / inspector)
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
batchSave
(
EventTrackingBatchSaveVO
vo
,
String
accountId
,
String
accountName
,
String
source
)
{
List
<
EventTrackingItemVO
>
items
=
vo
.
getEvents
();
// 1. 收集所有 eventCode,批量查 event_type_config 做合法性校验
Set
<
String
>
eventCodes
=
items
.
stream
()
.
map
(
EventTrackingItemVO:
:
getEventCode
)
.
collect
(
Collectors
.
toSet
());
List
<
EventTypeConfig
>
configs
=
eventTypeConfigRepository
.
findByIsActiveAndDeleteFlag
(
CommonConsts
.
ONE_INT
,
DeleteFlag
.
NOT_DELETED
.
getCode
());
Map
<
String
,
EventTypeConfig
>
configMap
=
configs
.
stream
()
.
collect
(
Collectors
.
toMap
(
EventTypeConfig:
:
getEventCode
,
Function
.
identity
(),
(
pre
,
next
)
->
pre
));
// 校验所有 eventCode 均在配置中
for
(
String
code
:
eventCodes
)
{
if
(!
configMap
.
containsKey
(
code
))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
EVENT_CODE_NOT_CONFIG
,
code
);
}
}
// 2. 批量插入 event_tracking 主表
LocalDateTime
now
=
LocalDateTime
.
now
();
List
<
EventTracking
>
trackings
=
items
.
stream
()
.
map
(
item
->
EventTracking
.
builder
()
.
eventCode
(
item
.
getEventCode
())
.
accountId
(
accountId
)
.
accountName
(
accountName
)
.
source
(
StrUtil
.
blankToDefault
(
source
,
EventSourceEnum
.
ADMIN
.
getSource
()))
.
eventTime
(
item
.
getEventTime
()
!=
null
?
item
.
getEventTime
()
:
now
)
.
duration
(
item
.
getDuration
())
.
remark
(
item
.
getRemark
())
.
build
())
.
collect
(
Collectors
.
toList
());
List
<
EventTracking
>
savedTrackings
=
eventTrackingRepository
.
saveAll
(
trackings
);
log
.
info
(
"【埋点】批量保存事件主表成功,数量={}"
,
savedTrackings
.
size
());
// 3. 批量插入业务主键 & 参数(按索引对应)
List
<
EventTrackingBusinessKey
>
bizKeys
=
new
ArrayList
<>();
List
<
EventTrackingParam
>
params
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
items
.
size
();
i
++)
{
EventTrackingItemVO
item
=
items
.
get
(
i
);
Long
eventId
=
savedTrackings
.
get
(
i
).
getEventId
();
// 业务主键
if
(
CollUtil
.
isNotEmpty
(
item
.
getBusinessKeys
()))
{
for
(
BusinessKeyVO
bk
:
item
.
getBusinessKeys
())
{
bizKeys
.
add
(
EventTrackingBusinessKey
.
builder
()
.
eventId
(
eventId
)
.
businessType
(
bk
.
getBusinessType
())
.
businessKey
(
bk
.
getBusinessKey
())
.
build
());
}
}
// 扩展参数
if
(
CollUtil
.
isNotEmpty
(
item
.
getParams
()))
{
for
(
ParamVO
p
:
item
.
getParams
())
{
params
.
add
(
EventTrackingParam
.
builder
()
.
eventId
(
eventId
)
.
paramKey
(
p
.
getParamKey
())
.
paramValue
(
p
.
getParamValue
())
.
paramType
(
StrUtil
.
blankToDefault
(
p
.
getParamType
(),
ParamTypeEnum
.
STRING
.
getValue
()))
.
build
());
}
}
}
if
(
CollUtil
.
isNotEmpty
(
bizKeys
))
{
eventTrackingBusinessKeyRepository
.
saveAll
(
bizKeys
);
log
.
info
(
"【埋点】批量保存业务主键成功,数量={}"
,
bizKeys
.
size
());
}
if
(
CollUtil
.
isNotEmpty
(
params
))
{
eventTrackingParamRepository
.
saveAll
(
params
);
log
.
info
(
"【埋点】批量保存参数成功,数量={}"
,
params
.
size
());
}
}
}
aus-core/src/main/java/com/glsx/usedcar/module/event/vo/EventTrackingBatchSaveVO.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
event
.
vo
;
import
com.glsx.usedcar.enums.event.BusinessTypeEnum
;
import
com.glsx.usedcar.enums.event.ParamTypeEnum
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
jakarta.validation.Valid
;
import
jakarta.validation.constraints.NotBlank
;
import
jakarta.validation.constraints.NotEmpty
;
import
jakarta.validation.constraints.NotNull
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
java.util.List
;
/**
* 埋点事件批量保存请求 VO
*
* @author yangwei
* @version 1.0
* @since 2026/04/07
*/
@Data
@Schema
(
description
=
"埋点事件批量保存请求 VO"
)
public
class
EventTrackingBatchSaveVO
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
-
6490522758631650481L
;
/**
* 事件列表,至少包含一条
*/
@Valid
@NotEmpty
(
message
=
"事件列表不能为空"
)
@Schema
(
description
=
"事件列表"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
)
private
List
<
EventTrackingItemVO
>
events
;
// ----------------------------------------------------------------
// 单条事件 VO
// ----------------------------------------------------------------
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema
(
description
=
"单条埋点事件"
)
public
static
class
EventTrackingItemVO
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
-
3543221761509804738L
;
/**
* 事件代码,需在 event_type_config 中已配置且启用
*/
@NotBlank
(
message
=
"事件代码不能为空"
)
@Schema
(
description
=
"事件代码"
,
example
=
"REPORT_DETAIL_VIEW"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
)
private
String
eventCode
;
/**
* 事件时间(前端传入,格式 yyyy-MM-dd HH:mm:ss)
* 为空时取服务器当前时间
*/
@Schema
(
description
=
"事件时间,为空则取服务器时间"
)
private
LocalDateTime
eventTime
;
/**
* 时长(秒),仅页面停留类事件需传
*/
@Schema
(
description
=
"时长(秒),页面停留事件使用"
)
private
Integer
duration
;
/**
* 备注
*/
@Schema
(
description
=
"备注"
)
private
String
remark
;
/**
* 业务主键列表(可选)
*/
@Valid
@Schema
(
description
=
"业务主键列表"
)
private
List
<
BusinessKeyVO
>
businessKeys
;
/**
* 扩展参数列表(可选)
*/
@Valid
@Schema
(
description
=
"扩展参数列表"
)
private
List
<
ParamVO
>
params
;
}
// ----------------------------------------------------------------
// 业务主键 VO
// ----------------------------------------------------------------
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema
(
description
=
"业务主键"
)
public
static
class
BusinessKeyVO
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
3401073440486276291L
;
/**
* 业务类型,如 REPORT、VEHICLE、WORK_ORDER
* @see com.glsx.usedcar.enums.event.BusinessTypeEnum
*/
@NotBlank
(
message
=
"业务类型不能为空"
)
@Schema
(
description
=
"业务类型,如 REPORT、VEHICLE、WORK_ORDER"
,
example
=
"REPORT"
)
@Builder
.
Default
private
String
businessType
=
BusinessTypeEnum
.
INSPECTION_MANAGEMENT
.
getValue
();
/**
* 业务主键值
*/
@NotBlank
(
message
=
"业务主键不能为空"
)
@Schema
(
description
=
"业务主键"
,
example
=
"123456"
)
private
String
businessKey
;
}
// ----------------------------------------------------------------
// 扩展参数 VO
// ----------------------------------------------------------------
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema
(
description
=
"扩展参数"
)
public
static
class
ParamVO
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
2621909004110488768L
;
/**
* 参数键
*/
@NotBlank
(
message
=
"参数键不能为空"
)
@Schema
(
description
=
"参数键"
,
example
=
"page_name"
)
private
String
paramKey
;
/**
* 参数值
*/
@Schema
(
description
=
"参数值"
)
private
String
paramValue
;
/**
* 参数类型: STRING, NUMBER, BOOLEAN, ARRAY, OBJECT
*/
@Schema
(
description
=
"参数类型:STRING, NUMBER, BOOLEAN, ARRAY, OBJECT"
,
example
=
"STRING"
)
@Builder
.
Default
private
String
paramType
=
ParamTypeEnum
.
STRING
.
getValue
();
}
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/dao/InspectionOpLogItemRepository.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
dao
;
import
com.glsx.usedcar.module.inspect.entity.InspectionOpLogItem
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.stereotype.Repository
;
import
org.summerframework.orm.BaseRepository
;
import
java.util.List
;
/**
* 检测报告操作日志明细表数据访问层
*
* @author yangwei
* @since 2026/4/7
*/
@Repository
public
interface
InspectionOpLogItemRepository
extends
BaseRepository
<
InspectionOpLogItem
,
Long
>,
JpaSpecificationExecutor
<
InspectionOpLogItem
>
{
/**
* 根据日志ID和删除标识查询明细列表
*
* @param logId 日志ID
* @param deleteFlag 删除标识
* @return 明细列表
*/
List
<
InspectionOpLogItem
>
findByLogIdAndDeleteFlag
(
Long
logId
,
String
deleteFlag
);
/**
* 根据日志ID列表和删除标识查询明细列表
*
* @param logIds 日志ID列表
* @param deleteFlag 删除标识
* @return 明细列表
*/
List
<
InspectionOpLogItem
>
findByLogIdInAndDeleteFlag
(
List
<
Long
>
logIds
,
String
deleteFlag
);
/**
* 根据日志ID、一级模块名和删除标识查询明细列表
*
* @param logId 日志ID
* @param moduleName 一级模块名称
* @param deleteFlag 删除标识
* @return 明细列表
*/
List
<
InspectionOpLogItem
>
findByLogIdAndModuleNameAndDeleteFlag
(
Long
logId
,
String
moduleName
,
String
deleteFlag
);
/**
* 根据字段标识和删除标识查询明细列表
*
* @param fieldKey 字段标识
* @param deleteFlag 删除标识
* @return 明细列表
*/
List
<
InspectionOpLogItem
>
findByFieldKeyAndDeleteFlag
(
String
fieldKey
,
String
deleteFlag
);
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/dao/InspectionOpLogRepository.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
dao
;
import
com.glsx.usedcar.module.inspect.entity.InspectionOpLog
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.stereotype.Repository
;
import
org.summerframework.orm.BaseRepository
;
import
java.util.List
;
/**
* 检测报告操作日志主表数据访问层
*
* @author yangwei
* @since 2026/4/7
*/
@Repository
public
interface
InspectionOpLogRepository
extends
BaseRepository
<
InspectionOpLog
,
Long
>,
JpaSpecificationExecutor
<
InspectionOpLog
>
{
/**
* 根据检测记录ID和删除标识查询操作日志列表
*
* @param recordId 检测记录ID
* @param deleteFlag 删除标识
* @return 操作日志列表
*/
List
<
InspectionOpLog
>
findByRecordIdAndDeleteFlag
(
Long
recordId
,
String
deleteFlag
);
/**
* 根据任务ID和删除标识查询操作日志列表
*
* @param taskId 任务ID
* @param deleteFlag 删除标识
* @return 操作日志列表
*/
List
<
InspectionOpLog
>
findByTaskIdAndDeleteFlag
(
Long
taskId
,
String
deleteFlag
);
/**
* 根据检测记录ID和删除标识分页查询操作日志,按创建时间倒序
*
* @param recordId 检测记录ID
* @param deleteFlag 删除标识
* @param pageable 分页参数
* @return 操作日志分页结果
*/
Page
<
InspectionOpLog
>
findByRecordIdAndDeleteFlagOrderByCreateTimeDesc
(
Long
recordId
,
String
deleteFlag
,
Pageable
pageable
);
/**
* 根据工单操作日志ID列表和删除标识查询操作日志列表
*
* @param woOpIds 工单操作日志ID列表
* @param deleteFlag 删除标识
* @return 操作日志列表
*/
List
<
InspectionOpLog
>
findByWoOpIdInAndDeleteFlag
(
List
<
Long
>
woOpIds
,
String
deleteFlag
);
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/dao/InspectionWorkOrderOpLogRepository.java
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
dao
;
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
dao
;
import
com.glsx.usedcar.module.inspect.entity.InspectionWorkOrderOpLog
;
import
com.glsx.usedcar.module.inspect.entity.InspectionWorkOrderOpLog
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.stereotype.Repository
;
import
org.summerframework.orm.BaseRepository
;
import
org.summerframework.orm.BaseRepository
;
...
@@ -57,4 +59,14 @@ public interface InspectionWorkOrderOpLogRepository extends BaseRepository<Inspe
...
@@ -57,4 +59,14 @@ public interface InspectionWorkOrderOpLogRepository extends BaseRepository<Inspe
* @return 操作日志列表
* @return 操作日志列表
*/
*/
List
<
InspectionWorkOrderOpLog
>
findByOriginalStatusAndTargetStatusAndDeleteFlag
(
Integer
originalStatus
,
Integer
targetStatus
,
String
deleteFlag
);
List
<
InspectionWorkOrderOpLog
>
findByOriginalStatusAndTargetStatusAndDeleteFlag
(
Integer
originalStatus
,
Integer
targetStatus
,
String
deleteFlag
);
/**
* 根据工单主键ID和删除标识分页查询操作日志,按ID倒序
*
* @param workOrderInnerId 关联检测工单主键ID
* @param deleteFlag 删除标识(N:未删除 D:已删除)
* @param pageable 分页参数
* @return 操作日志分页结果
*/
Page
<
InspectionWorkOrderOpLog
>
findByWorkOrderInnerIdAndDeleteFlagOrderByIdDesc
(
Long
workOrderInnerId
,
String
deleteFlag
,
Pageable
pageable
);
}
}
\ No newline at end of file
\ No newline at end of file
aus-core/src/main/java/com/glsx/usedcar/module/inspect/dao/TemplateTagRelationRepository.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
dao
;
import
com.glsx.usedcar.module.inspect.entity.TemplateTagRelation
;
import
com.glsx.usedcar.module.inspect.entity.TemplateTagRelation.TemplateTagRelationId
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.query.Param
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
/**
* 模版标签关联数据访问层
*
* @author yangwei
* @since 2026/4/7
*/
@Repository
public
interface
TemplateTagRelationRepository
extends
JpaRepository
<
TemplateTagRelation
,
TemplateTagRelationId
>
{
/**
* 根据模版ID查询标签关联列表
*
* @param templateId 模版ID
* @return 关联列表
*/
List
<
TemplateTagRelation
>
findByIdTemplateId
(
Long
templateId
);
/**
* 根据标签ID查询模版关联列表
*
* @param tagId 标签ID
* @return 关联列表
*/
List
<
TemplateTagRelation
>
findByIdTagId
(
Long
tagId
);
/**
* 根据模版ID删除所有关联
*
* @param templateId 模版ID
*/
@Modifying
@Query
(
"DELETE FROM TemplateTagRelation t WHERE t.id.templateId = :templateId"
)
void
deleteByTemplateId
(
@Param
(
"templateId"
)
Long
templateId
);
/**
* 根据模版ID和标签ID查询是否存在
*
* @param templateId 模版ID
* @param tagId 标签ID
* @return 是否存在
*/
boolean
existsByIdTemplateIdAndIdTagId
(
Long
templateId
,
Long
tagId
);
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/dao/TemplateTagRepository.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
dao
;
import
com.glsx.usedcar.module.inspect.entity.TemplateTag
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.query.Param
;
import
org.springframework.stereotype.Repository
;
import
org.summerframework.orm.BaseRepository
;
import
java.util.List
;
import
java.util.Optional
;
/**
* 模版标签数据访问层
*
* @author yangwei
* @since 2026/4/7
*/
@Repository
public
interface
TemplateTagRepository
extends
BaseRepository
<
TemplateTag
,
Long
>,
JpaSpecificationExecutor
<
TemplateTag
>
{
/**
* 根据标签编码和删除标识查询
*
* @param tagCode 标签编码
* @param deleteFlag 删除标识
* @return 标签信息
*/
Optional
<
TemplateTag
>
findByTagCodeAndDeleteFlag
(
String
tagCode
,
String
deleteFlag
);
/**
* 根据标签名称和删除标识查询
*
* @param tagName 标签名称
* @param deleteFlag 删除标识
* @return 标签列表
*/
List
<
TemplateTag
>
findByTagNameAndDeleteFlag
(
String
tagName
,
String
deleteFlag
);
/**
* 根据状态和删除标识查询列表
*
* @param status 状态
* @param deleteFlag 删除标识
* @return 标签列表
*/
List
<
TemplateTag
>
findByStatusAndDeleteFlag
(
Integer
status
,
String
deleteFlag
);
/**
* 根据标签类型和删除标识查询列表
*
* @param tagType 标签类型
* @param deleteFlag 删除标识
* @return 标签列表
*/
List
<
TemplateTag
>
findByTagTypeAndDeleteFlag
(
String
tagType
,
String
deleteFlag
);
/**
* 批量查询多个模版的标签,一次 JOIN 查询避免 N+1
* 返回结果包含 templateId 用于分组
*
* @param templateIds 模版ID列表
* @return [templateId, TemplateTag] 投影列表
*/
@Query
(
"SELECT r.id.templateId, t FROM TemplateTag t "
+
"JOIN TemplateTagRelation r ON r.id.tagId = t.tagId "
+
"WHERE r.id.templateId IN :templateIds "
+
"AND t.deleteFlag = 'N' "
+
"ORDER BY t.sortOrder ASC"
)
List
<
Object
[]>
findTagsByTemplateIds
(
@Param
(
"templateIds"
)
List
<
Long
>
templateIds
);
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/delegate/InspectionSaveDelegate.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
delegate
;
import
com.glsx.usedcar.enums.inspect.InspectionPlatTypeEnum
;
import
com.glsx.usedcar.module.inspect.entity.InspectionRecord
;
import
com.glsx.usedcar.module.inspect.entity.InspectionWorkOrder
;
import
com.glsx.usedcar.module.inspect.vo.CompleteInspectionRespVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionNodeVO
;
import
java.util.List
;
import
java.util.Set
;
/**
* 检测保存策略委托接口
* <p>
* 将检测保存流程中与调用端相关的差异化行为(权限校验、日志记录、后置操作)
* 抽象为策略接口,H5 端和 PC 端各自提供实现,核心保存逻辑保持不变。
*
* @author yangwei
* @since 2026/4/8
*/
public
interface
InspectionSaveDelegate
{
default
void
operationNodeIds
(
Set
<
Long
>
nodeIds
){};
/**
* 校验调用方对该工单的操作权限(含状态检查)
*
* @param workOrder 检测工单
*/
void
validatePermission
(
InspectionWorkOrder
workOrder
);
/**
* 获取平台类型,不同平台保存的委托策略不同
*
* @return 平台类型
*/
InspectionPlatTypeEnum
getPlatType
();
/**
* 获取操作人名称(用于日志)
*
* @return 操作人名称
*/
String
getOperatorName
();
/**
* 获取操作人ID
*
* @return 操作人ID
*/
Long
getOperatorId
();
/**
* 保存前钩子:可用于快照旧数据(默认空实现)
*
* @param recordId 检测记录 ID
* @param allNodes 所有节点配置
*/
default
void
beforeSave
(
Long
recordId
,
List
<
InspectionNodeVO
>
allNodes
)
{}
/**
* 保存后钩子:可用于写操作日志(默认空实现)
*
* @param recordId 检测记录 ID
* @param taskId 检测工单 ID
* @param locationModule 当前一级模块节点 ID
* @param allNodes 所有节点配置
* @param savedResults 本次保存的检测结果 DTO(新数据,用于对比生成操作日志)
*/
default
void
afterSave
(
Long
recordId
,
Long
taskId
,
Long
locationModule
,
List
<
InspectionNodeVO
>
allNodes
,
List
<
com
.
glsx
.
usedcar
.
module
.
inspect
.
dto
.
InspectionResultDTO
>
savedResults
)
{}
/**
* 评分保存前钩子:可用于快照旧评分数据(默认空实现)
*
* @param taskId 检测工单 ID
*/
default
void
beforeScoreSave
(
Long
taskId
)
{}
/**
* 评分保存后钩子:可用于写评分修改日志(默认空实现)
*
* @param record 保存后的检测记录
* @param taskId 检测工单 ID
* @param workOrder 检测工单
*/
default
void
afterScoreSave
(
InspectionRecord
record
,
Long
taskId
,
InspectionWorkOrder
workOrder
)
{}
/**
* 保存评分后的完成检查与处理
* <p>
* H5 端默认实现:深度检查节点树,找到第一个未完成节点即返回;全部完成则执行完成操作。
* PC 端覆盖为:一级节点检查 + 评分检查 + 自动完成({@code tryAutoComplete})。
*
* @param record 检测记录
* @param workOrder 检测工单
* @param allNodes 所有节点配置
* @return 未完成的根节点信息;全部完成(或不检查)返回 null
*/
default
CompleteInspectionRespVO
checkAndComplete
(
InspectionRecord
record
,
InspectionWorkOrder
workOrder
,
List
<
InspectionNodeVO
>
allNodes
)
{
return
null
;
}
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/entity/InspectionOpLog.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
entity
;
import
jakarta.persistence.*
;
import
lombok.*
;
import
org.hibernate.annotations.DynamicInsert
;
import
org.hibernate.annotations.DynamicUpdate
;
import
org.springframework.data.jpa.domain.support.AuditingEntityListener
;
import
org.summerframework.orm.entity.AuditingEntity
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
static
jakarta
.
persistence
.
GenerationType
.
IDENTITY
;
/**
* 检测报告操作日志主表(InspectionOpLog)实体类
*
* @author yangwei
* @since 2026/4/7
*/
@Entity
@Getter
@Setter
@Builder
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
@AllArgsConstructor
@Table
(
name
=
"inspection_op_log"
)
@EntityListeners
(
AuditingEntityListener
.
class
)
public
class
InspectionOpLog
extends
AuditingEntity
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
-
6338051270559818393L
;
/**
* 主键
*/
@Id
@GeneratedValue
(
strategy
=
IDENTITY
)
@Column
(
name
=
"LOG_ID"
,
unique
=
true
,
nullable
=
false
)
private
Long
logId
;
/**
* 关联 inspection_record.id
*/
@Column
(
name
=
"RECORD_ID"
,
nullable
=
false
)
private
Long
recordId
;
/**
* 工单操作日志id,关联 inspection_work_order_op_log.id
*/
@Column
(
name
=
"WO_OP_ID"
,
nullable
=
false
)
private
Long
woOpId
;
/**
* 冗余任务 ID
*/
@Column
(
name
=
"TASK_ID"
,
nullable
=
false
)
private
Long
taskId
;
/**
* 删除标识 N:未删除 D:已删除
*/
@Builder
.
Default
@Column
(
name
=
"DELETE_FLAG"
,
nullable
=
false
,
length
=
1
)
private
String
deleteFlag
=
"N"
;
/**
* 备注
*/
@Column
(
name
=
"REMARK"
,
length
=
256
)
private
String
remark
;
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/entity/InspectionOpLogItem.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
entity
;
import
jakarta.persistence.*
;
import
lombok.*
;
import
org.hibernate.annotations.DynamicInsert
;
import
org.hibernate.annotations.DynamicUpdate
;
import
org.springframework.data.jpa.domain.support.AuditingEntityListener
;
import
org.summerframework.orm.entity.AuditingEntity
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
static
jakarta
.
persistence
.
GenerationType
.
IDENTITY
;
/**
* 检测报告操作日志明细表(InspectionOpLogItem)实体类
*
* @author yangwei
* @since 2026/4/7
*/
@Entity
@Getter
@Setter
@Builder
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
@AllArgsConstructor
@Table
(
name
=
"inspection_op_log_item"
)
@EntityListeners
(
AuditingEntityListener
.
class
)
public
class
InspectionOpLogItem
extends
AuditingEntity
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
7336807504388140418L
;
/**
* 主键
*/
@Id
@GeneratedValue
(
strategy
=
IDENTITY
)
@Column
(
name
=
"LOG_ITEM_ID"
,
unique
=
true
,
nullable
=
false
)
private
Long
logItemId
;
/**
* 关联 inspection_op_log.id
*/
@Column
(
name
=
"LOG_ID"
,
nullable
=
false
)
private
Long
logId
;
/**
* 一级模块名称(快照),用于筛选
*/
@Column
(
name
=
"MODULE_NAME"
,
nullable
=
false
,
length
=
100
)
private
String
moduleName
;
/**
* 二级模块名称(快照),用于前端分组
*/
@Column
(
name
=
"SUB_MODULE_NAME"
,
length
=
100
)
private
String
subModuleName
;
/**
* 三级模块名称(快照)
*/
@Column
(
name
=
"TRI_MODULE_NAME"
,
nullable
=
false
,
length
=
100
)
private
String
triModuleName
;
/**
* 完整路径快照,如:外观骨架检测-车头检查-前风挡
*/
@Column
(
name
=
"FIELD_LABEL"
,
nullable
=
false
,
length
=
500
)
private
String
fieldLabel
;
/**
* 字段标识(node_id 或字段英文名)
*/
@Column
(
name
=
"FIELD_KEY"
,
length
=
100
)
private
String
fieldKey
;
/**
* 交互类型快照
*/
@Column
(
name
=
"INTERACTION_TYPE"
,
length
=
32
)
private
String
interactionType
;
/**
* 修改前内容(格式化文本)
*/
@Column
(
name
=
"BEFORE_VALUE"
,
columnDefinition
=
"TEXT"
)
private
String
beforeValue
;
/**
* 修改后内容(格式化文本)
*/
@Column
(
name
=
"AFTER_VALUE"
,
columnDefinition
=
"TEXT"
)
private
String
afterValue
;
/**
* 同一批次内展示顺序
*/
@Builder
.
Default
@Column
(
name
=
"SORT_SEQ"
,
nullable
=
false
)
private
Integer
sortSeq
=
0
;
/**
* 删除标识 N:未删除 D:已删除
*/
@Builder
.
Default
@Column
(
name
=
"DELETE_FLAG"
,
nullable
=
false
,
length
=
1
)
private
String
deleteFlag
=
"N"
;
/**
* 备注
*/
@Column
(
name
=
"REMARK"
,
length
=
256
)
private
String
remark
;
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/entity/InspectionTemplate.java
View file @
b2f6a2e
...
@@ -9,6 +9,8 @@ import org.summerframework.orm.entity.AuditingEntity;
...
@@ -9,6 +9,8 @@ import org.summerframework.orm.entity.AuditingEntity;
import
java.io.Serial
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
jakarta
.
persistence
.
GenerationType
.
IDENTITY
;
import
static
jakarta
.
persistence
.
GenerationType
.
IDENTITY
;
...
@@ -91,4 +93,11 @@ public class InspectionTemplate extends AuditingEntity implements Serializable {
...
@@ -91,4 +93,11 @@ public class InspectionTemplate extends AuditingEntity implements Serializable {
@Builder
.
Default
@Builder
.
Default
@Column
(
name
=
"DELETED_FLAG"
,
nullable
=
false
,
length
=
1
)
@Column
(
name
=
"DELETED_FLAG"
,
nullable
=
false
,
length
=
1
)
private
String
deletedFlag
=
"N"
;
private
String
deletedFlag
=
"N"
;
/**
* 模版标签关系
*/
@ManyToMany
(
targetEntity
=
TemplateTag
.
class
,
cascade
=
{
CascadeType
.
MERGE
,
CascadeType
.
PERSIST
},
fetch
=
FetchType
.
LAZY
)
@JoinTable
(
name
=
"template_tag_relation"
,
joinColumns
=
{
@JoinColumn
(
name
=
"TEMPLATE_ID"
,
nullable
=
false
)},
inverseJoinColumns
=
{
@JoinColumn
(
name
=
"TAG_ID"
,
nullable
=
false
)})
private
List
<
TemplateTag
>
templateTags
=
new
ArrayList
<>();
}
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/entity/TemplateTag.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
entity
;
import
com.glsx.usedcar.module.account.entity.Account
;
import
jakarta.persistence.*
;
import
lombok.*
;
import
org.hibernate.annotations.DynamicInsert
;
import
org.hibernate.annotations.DynamicUpdate
;
import
org.springframework.data.jpa.domain.support.AuditingEntityListener
;
import
org.summerframework.orm.entity.AuditingEntity
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.util.HashSet
;
import
java.util.Set
;
import
static
jakarta
.
persistence
.
GenerationType
.
IDENTITY
;
/**
* 模版标签(TemplateTag)实体类
*
* @author yangwei
* @since 2026/4/7
*/
@Entity
@Getter
@Setter
@Builder
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
@AllArgsConstructor
@Table
(
name
=
"template_tag"
)
@EntityListeners
(
AuditingEntityListener
.
class
)
public
class
TemplateTag
extends
AuditingEntity
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
-
6266796218047003775L
;
/**
* 主键ID
*/
@Id
@GeneratedValue
(
strategy
=
IDENTITY
)
@Column
(
name
=
"TAG_ID"
,
unique
=
true
,
nullable
=
false
)
private
Long
tagId
;
/**
* 标签编码
*/
@Column
(
name
=
"TAG_CODE"
,
nullable
=
false
,
length
=
64
)
private
String
tagCode
;
/**
* 标签名称
*/
@Column
(
name
=
"TAG_NAME"
,
nullable
=
false
,
length
=
128
)
private
String
tagName
;
/**
* 标签类型
*/
@Column
(
name
=
"TAG_TYPE"
,
length
=
32
)
private
String
tagType
;
/**
* 标签描述
*/
@Column
(
name
=
"DESCRIPTION"
,
length
=
512
)
private
String
description
;
/**
* 排序顺序
*/
@Builder
.
Default
@Column
(
name
=
"SORT_ORDER"
)
private
Integer
sortOrder
=
0
;
/**
* 状态 1:启用 0:禁用
*/
@Builder
.
Default
@Column
(
name
=
"STATUS"
,
nullable
=
false
)
private
Integer
status
=
1
;
/**
* 删除标识 N:未删除 D:已删除
*/
@Builder
.
Default
@Column
(
name
=
"DELETE_FLAG"
,
nullable
=
false
,
length
=
1
)
private
String
deleteFlag
=
"N"
;
/**
* 备注
*/
@Column
(
name
=
"REMARK"
,
length
=
512
)
private
String
remark
;
@ManyToMany
(
fetch
=
FetchType
.
LAZY
,
targetEntity
=
InspectionTemplate
.
class
,
mappedBy
=
"templateTags"
,
cascade
=
{})
private
Set
<
InspectionTemplate
>
inspectionTemplates
=
new
HashSet
<>(
0
);
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/entity/TemplateTagRelation.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
entity
;
import
jakarta.persistence.*
;
import
lombok.*
;
import
java.io.Serial
;
import
java.io.Serializable
;
/**
* 模版标签关联(TemplateTagRelation)实体类
*
* @author yangwei
* @since 2026/4/7
*/
@Entity
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table
(
name
=
"template_tag_relation"
)
public
class
TemplateTagRelation
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
-
3725492187687731721L
;
/**
* 联合主键
*/
@EmbeddedId
private
TemplateTagRelationId
id
;
/**
* 联合主键类
*/
@Embeddable
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
public
static
class
TemplateTagRelationId
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
1L
;
/**
* 模版ID
*/
@Column
(
name
=
"TEMPLATE_ID"
,
nullable
=
false
)
private
Long
templateId
;
/**
* 标签ID
*/
@Column
(
name
=
"TAG_ID"
,
nullable
=
false
)
private
Long
tagId
;
}
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/service/InspectionEditLogService.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
service
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.lang.func.LambdaUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson2.JSON
;
import
com.glsx.usedcar.consts.common.SymbolConsts
;
import
com.glsx.usedcar.consts.inspect.InspectConstants
;
import
com.glsx.usedcar.enums.common.DeleteFlag
;
import
com.glsx.usedcar.enums.inspect.InspectionPlatTypeEnum
;
import
com.glsx.usedcar.enums.inspect.InspectionWorkOrderOperationTypeEnum
;
import
com.glsx.usedcar.module.inspect.dao.InspectionOpLogItemRepository
;
import
com.glsx.usedcar.module.inspect.dao.InspectionOpLogRepository
;
import
com.glsx.usedcar.module.inspect.dao.InspectionResultRepository
;
import
com.glsx.usedcar.module.inspect.dao.InspectionWorkOrderOpLogRepository
;
import
com.glsx.usedcar.module.inspect.dto.InspectionResultDTO
;
import
com.glsx.usedcar.module.inspect.entity.*
;
import
com.glsx.usedcar.module.inspect.vo.InspectionNodeVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionResultSnapshotVO
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
* 检测编辑操作日志服务
* <p>
* 提供检测结果快照、新旧差异比对并落库的能力,供 PC 端委托实现调用。
* 所有数据库操作均使用批量方式,避免 N+1 查询。
* 日志以"一次保存一条工单操作日志(InspectionWorkOrderOpLog)+ 一条主记录(InspectionOpLog)
* + 多条明细(InspectionOpLogItem)"的形式写入。
* 每条明细对应一个发生变化的叶子节点,beforeValue/afterValue 为 InspectionResultSnapshotVO 的 JSON 序列化结果。
*
* @author yangwei
* @since 2026/4/8
*/
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
)
public
class
InspectionEditLogService
{
private
final
InspectionOpLogRepository
inspectionOpLogRepository
;
private
final
InspectionOpLogItemRepository
inspectionOpLogItemRepository
;
private
final
InspectionResultRepository
inspectionResultRepository
;
private
final
InspectionWorkOrderOpLogRepository
inspectionWorkOrderOpLogRepository
;
// -------------------------------------------------------------------------
// 内部 DTO:快照条目
// -------------------------------------------------------------------------
/**
* 单个节点的检测结果快照
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public
static
class
SnapshotEntry
{
/** 检测结果状态(1-正常,2-故障,3-无此结构) */
private
Integer
resultStatus
;
/** 备注 */
private
String
remark
;
/** 值列表(保留所有值,含无 valueKey 的,同时保留 interactionType 和 valueSeq) */
private
List
<
InspectionResultSnapshotVO
.
ValueItem
>
values
;
}
// -------------------------------------------------------------------------
// 公开方法
// -------------------------------------------------------------------------
/**
* 对指定检测记录进行快照,一次性批量加载所有结果及其值,避免 N+1。
*
* @param recordId 检测记录 ID
* @return nodeId -> SnapshotEntry 的快照映射
*/
public
Map
<
Long
,
SnapshotEntry
>
snapshotResults
(
Long
recordId
,
Set
<
Long
>
operationNodeIds
)
{
List
<
InspectionResult
>
results
=
inspectionResultRepository
.
findByRecordIdWithValues
(
recordId
,
DeleteFlag
.
NOT_DELETED
.
getCode
());
results
=
results
.
stream
().
filter
(
result
->
operationNodeIds
.
contains
(
result
.
getNodeId
())).
toList
();
return
buildSnapshotFromResults
(
results
);
}
/**
* 比对新旧快照差异,并将差异批量保存为操作日志(工单操作日志 + 主表 + 明细表)。
* <p>
* 性能说明:
* <ul>
* <li>新快照直接由 DTO 参数传入,避免在同一事务内重复查询导致缓存问题</li>
* <li>通过 Map 内存匹配完成差异计算</li>
* <li>使用 saveAll 批量写入日志</li>
* </ul>
* <p>
* 明细粒度:以叶子节点为单位,每个发生变化的叶子节点生成一条 InspectionOpLogItem,
* beforeValue/afterValue 存储 InspectionResultSnapshotVO 的 JSON 字符串。
*
* @param recordId 检测记录 ID
* @param taskId 工单 ID
* @param workOrder 工单对象(用于创建工单操作日志)
* @param oldSnapshot 保存前的快照(由 {@link #snapshotResults} 生成)
* @param newResults 保存后的检测结果 DTO(新数据,由调用方传入)
* @param allNodes 本次操作所用的全部节点配置
* @param locationModule 当前操作所在的一级模块节点 ID
* @param operatorId 操作人 ID
* @param operatorName 操作人姓名
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
void
diffAndSaveLog
(
Long
recordId
,
Long
taskId
,
InspectionWorkOrder
workOrder
,
Map
<
Long
,
SnapshotEntry
>
oldSnapshot
,
List
<
InspectionResultDTO
>
newResults
,
List
<
InspectionNodeVO
>
allNodes
,
Set
<
Long
>
operationNodeIds
,
Long
locationModule
,
InspectionPlatTypeEnum
platType
,
Long
operatorId
,
String
operatorName
)
{
if
(
CollUtil
.
isEmpty
(
allNodes
))
{
return
;
}
if
(
oldSnapshot
==
null
)
{
oldSnapshot
=
Collections
.
emptyMap
();
}
// 1. 从传入的新结果 DTO 构建快照(避免在同一事务内查询导致缓存问题)
Map
<
Long
,
SnapshotEntry
>
newSnapshot
=
buildSnapshotFromDTOs
(
newResults
);
// 2. 构建 nodeId -> InspectionNodeVO 映射
Map
<
Long
,
InspectionNodeVO
>
nodeMap
=
allNodes
.
stream
()
.
collect
(
Collectors
.
toMap
(
InspectionNodeVO:
:
getId
,
Function
.
identity
(),
(
origin
,
next
)
->
origin
));
// 3. 获取 locationModule 对应的一级模块名称
String
moduleName
=
Optional
.
ofNullable
(
locationModule
)
.
map
(
nodeMap:
:
get
)
.
map
(
InspectionNodeVO:
:
getNodeName
)
.
orElse
(
StrUtil
.
EMPTY
);
// 4. 只对比本次操作范围内的叶子节点
// operationNodeIds 包含了本次需要对比的所有叶子节点 ID(由调用方传入)
if
(
CollUtil
.
isEmpty
(
operationNodeIds
))
{
log
.
info
(
"无操作节点,跳过日志记录,recordId={}"
,
recordId
);
return
;
}
// 5. 遍历范围内所有叶子节点进行对比(包括可能被删除的节点)
List
<
InspectionOpLogItem
>
items
=
new
ArrayList
<>();
int
sortSeq
=
0
;
for
(
Long
nodeId
:
operationNodeIds
)
{
InspectionNodeVO
nodeVO
=
nodeMap
.
get
(
nodeId
);
if
(
nodeVO
==
null
||
nodeVO
.
getNodeType
()
!=
InspectConstants
.
NODE_TYPE_LEAF
)
{
continue
;
}
SnapshotEntry
oldEntry
=
oldSnapshot
.
get
(
nodeId
);
SnapshotEntry
newEntry
=
newSnapshot
.
get
(
nodeId
);
// 整体对比:无差异则跳过
if
(!
isSnapshotChanged
(
oldEntry
,
newEntry
))
{
continue
;
}
// 解析层级名称
String
[]
levelNames
=
getNodeLevelNames
(
nodeVO
,
nodeMap
,
locationModule
,
moduleName
,
nodeVO
.
getNodeName
());
String
subModuleName
=
levelNames
[
0
];
String
triModuleName
=
levelNames
[
1
];
String
fieldLabel
=
moduleName
+
(
StrUtil
.
isNotBlank
(
subModuleName
)
?
SymbolConsts
.
HYPHEN
+
subModuleName
:
StrUtil
.
EMPTY
)
+
(
StrUtil
.
isNotBlank
(
triModuleName
)
?
SymbolConsts
.
HYPHEN
+
triModuleName
:
StrUtil
.
EMPTY
);
// 序列化为 JSON
String
beforeValue
=
oldEntry
!=
null
?
JSON
.
toJSONString
(
toSnapshotVO
(
oldEntry
))
:
null
;
String
afterValue
=
newEntry
!=
null
?
JSON
.
toJSONString
(
toSnapshotVO
(
newEntry
))
:
null
;
InspectionOpLogItem
item
=
new
InspectionOpLogItem
();
item
.
setModuleName
(
StrUtil
.
nullToEmpty
(
moduleName
));
item
.
setSubModuleName
(
Optional
.
ofNullable
(
subModuleName
).
filter
(
StrUtil:
:
isNotBlank
).
orElse
(
null
));
item
.
setTriModuleName
(
StrUtil
.
nullToEmpty
(
triModuleName
));
item
.
setFieldLabel
(
StrUtil
.
nullToEmpty
(
fieldLabel
));
item
.
setFieldKey
(
nodeId
.
toString
());
item
.
setBeforeValue
(
beforeValue
);
item
.
setAfterValue
(
afterValue
);
item
.
setSortSeq
(
sortSeq
++);
items
.
add
(
item
);
}
// 5. 无差异则跳过
if
(
CollUtil
.
isEmpty
(
items
))
{
log
.
info
(
"无节点变更,跳过日志记录,recordId={}"
,
recordId
);
return
;
}
// 6. 创建工单操作日志(InspectionWorkOrderOpLog)
InspectionWorkOrderOpLog
woOpLog
=
InspectionWorkOrderOpLog
.
builder
()
.
workOrderInnerId
(
workOrder
.
getId
())
.
woId
(
workOrder
.
getWoId
())
.
operatorId
(
operatorId
)
.
operatorName
(
operatorName
)
.
plateType
(
ObjectUtil
.
isNull
(
platType
)
?
InspectionPlatTypeEnum
.
BACKEND
.
getCode
()
:
platType
.
getCode
())
.
operationType
(
InspectionWorkOrderOperationTypeEnum
.
UPDATE_INSPECTION_ITEM
.
getCode
())
.
originalStatus
(
workOrder
.
getStatus
())
.
targetStatus
(
workOrder
.
getStatus
())
.
operationContent
(
"编辑检测项数据"
)
.
description
(
String
.
format
(
"操作人[%s]编辑检测项数据,共%d项变更"
,
operatorName
,
items
.
size
()))
.
operationTime
(
LocalDateTime
.
now
())
.
build
();
InspectionWorkOrderOpLog
savedWoOpLog
=
inspectionWorkOrderOpLogRepository
.
save
(
woOpLog
);
// 7. 创建检测操作日志主记录(InspectionOpLog)
InspectionOpLog
opLog
=
new
InspectionOpLog
();
opLog
.
setRecordId
(
recordId
);
opLog
.
setTaskId
(
taskId
);
opLog
.
setWoOpId
(
savedWoOpLog
.
getId
());
opLog
.
setRemark
(
"编辑检测项数据"
);
InspectionOpLog
savedLog
=
inspectionOpLogRepository
.
save
(
opLog
);
// 8. 设置 logId 并批量保存明细
items
.
forEach
(
item
->
item
.
setLogId
(
savedLog
.
getLogId
()));
inspectionOpLogItemRepository
.
saveAll
(
items
);
log
.
info
(
"操作日志记录完成,recordId={}, logId={}, woOpLogId={}, itemCount={}"
,
recordId
,
savedLog
.
getLogId
(),
savedWoOpLog
.
getId
(),
items
.
size
());
}
/**
* 分页查询指定检测记录的操作日志主记录,按创建时间倒序返回。
*
* @param recordId 检测记录 ID
* @param pageable 分页参数
* @return 操作日志主记录分页结果
*/
public
Page
<
InspectionOpLog
>
queryLogs
(
Long
recordId
,
Pageable
pageable
)
{
return
inspectionOpLogRepository
.
findByRecordIdAndDeleteFlagOrderByCreateTimeDesc
(
recordId
,
DeleteFlag
.
NOT_DELETED
.
getCode
(),
pageable
);
}
// -------------------------------------------------------------------------
// 私有辅助方法
// -------------------------------------------------------------------------
/**
* 从 InspectionResult 列表构建 nodeId -> SnapshotEntry 映射
*/
private
Map
<
Long
,
SnapshotEntry
>
buildSnapshotFromResults
(
List
<
InspectionResult
>
results
)
{
Map
<
Long
,
SnapshotEntry
>
snapshot
=
new
HashMap
<>(
results
.
size
());
for
(
InspectionResult
result
:
results
)
{
List
<
InspectionResultSnapshotVO
.
ValueItem
>
valueItems
=
new
ArrayList
<>();
if
(
CollUtil
.
isNotEmpty
(
result
.
getInspectionValues
()))
{
for
(
InspectionValue
value
:
result
.
getInspectionValues
())
{
valueItems
.
add
(
InspectionResultSnapshotVO
.
ValueItem
.
builder
()
.
valueKey
(
value
.
getValueKey
())
.
valueText
(
value
.
getValueText
())
.
interactionType
(
value
.
getInteractionType
())
.
valueSeq
(
value
.
getValueSeq
())
.
build
());
}
}
snapshot
.
put
(
result
.
getNodeId
(),
new
SnapshotEntry
(
result
.
getResultStatus
(),
result
.
getRemark
(),
valueItems
));
}
return
snapshot
;
}
/**
* 从 InspectionResultDTO 列表构建 nodeId -> SnapshotEntry 映射
*/
private
Map
<
Long
,
SnapshotEntry
>
buildSnapshotFromDTOs
(
List
<
InspectionResultDTO
>
results
)
{
Map
<
Long
,
SnapshotEntry
>
snapshot
=
new
HashMap
<>(
results
.
size
());
for
(
InspectionResultDTO
result
:
results
)
{
List
<
InspectionResultSnapshotVO
.
ValueItem
>
valueItems
=
new
ArrayList
<>();
if
(
CollUtil
.
isNotEmpty
(
result
.
getValues
()))
{
for
(
InspectionResultDTO
.
ValueItem
value
:
result
.
getValues
())
{
valueItems
.
add
(
InspectionResultSnapshotVO
.
ValueItem
.
builder
()
.
valueKey
(
value
.
getValueKey
())
.
valueText
(
value
.
getValueText
())
.
interactionType
(
value
.
getInteractionType
())
.
valueSeq
(
value
.
getValueSeq
())
.
build
());
}
}
snapshot
.
put
(
result
.
getNodeId
(),
new
SnapshotEntry
(
result
.
getResultStatus
(),
result
.
getRemark
(),
valueItems
));
}
return
snapshot
;
}
/**
* 将 SnapshotEntry 转换为 InspectionResultSnapshotVO
*/
private
InspectionResultSnapshotVO
toSnapshotVO
(
SnapshotEntry
entry
)
{
if
(
entry
==
null
)
{
return
null
;
}
return
InspectionResultSnapshotVO
.
builder
()
.
resultStatus
(
entry
.
getResultStatus
())
.
remark
(
entry
.
getRemark
())
.
values
(
entry
.
getValues
())
.
build
();
}
/**
* 整体对比两个快照条目是否有差异(节点级,非字段级)
*/
private
boolean
isSnapshotChanged
(
SnapshotEntry
oldEntry
,
SnapshotEntry
newEntry
)
{
if
(
oldEntry
==
null
&&
newEntry
==
null
)
{
return
false
;
}
if
(
oldEntry
==
null
||
newEntry
==
null
)
{
return
true
;
}
if
(!
Objects
.
equals
(
oldEntry
.
getResultStatus
(),
newEntry
.
getResultStatus
()))
{
return
true
;
}
if
(!
Objects
.
equals
(
StrUtil
.
nullToEmpty
(
oldEntry
.
getRemark
()),
StrUtil
.
nullToEmpty
(
newEntry
.
getRemark
())))
{
return
true
;
}
List
<
InspectionResultSnapshotVO
.
ValueItem
>
oldValueList
=
oldEntry
.
getValues
()
!=
null
?
oldEntry
.
getValues
()
:
Collections
.
emptyList
();
List
<
InspectionResultSnapshotVO
.
ValueItem
>
newValueList
=
newEntry
.
getValues
()
!=
null
?
newEntry
.
getValues
()
:
Collections
.
emptyList
();
Map
<
String
,
String
>
oldValues
=
oldValueList
.
stream
().
collect
(
Collectors
.
toMap
(
v
->
v
.
getValueKey
()
+
SymbolConsts
.
SHARP
+
v
.
getValueSeq
(),
v
->
StrUtil
.
nullToEmpty
(
v
.
getValueText
()),
(
pre
,
next
)
->
pre
));
Map
<
String
,
String
>
newValues
=
newValueList
.
stream
().
collect
(
Collectors
.
toMap
(
v
->
v
.
getValueKey
()
+
SymbolConsts
.
SHARP
+
v
.
getValueSeq
(),
v
->
StrUtil
.
nullToEmpty
(
v
.
getValueText
()),
(
pre
,
next
)
->
pre
));
return
!
oldValues
.
equals
(
newValues
);
}
/**
* 根据叶子节点的 parentId 链路解析各级模块名称。
* <p>
* 层级规则(相对于 locationModule 下):
* <ul>
* <li>levelNames[0] = subModuleName:叶子节点所在的二级模块名称</li>
* <li>levelNames[1] = triModuleName:叶子节点自身名称(或三级路径名称)</li>
* </ul>
*
* @param nodeVO 叶子节点 VO
* @param nodeMap 全量节点映射
* @param locationModule 一级模块节点 ID
* @param moduleName 一级模块名称(已解析)
* @param nodeName 当前节点名称(兜底)
* @return [subModuleName, triModuleName]
*/
private
String
[]
getNodeLevelNames
(
InspectionNodeVO
nodeVO
,
Map
<
Long
,
InspectionNodeVO
>
nodeMap
,
Long
locationModule
,
String
moduleName
,
String
nodeName
)
{
if
(
nodeVO
==
null
)
{
return
new
String
[]{
moduleName
,
nodeName
};
}
// 从叶子节点向上追溯祖先链(不包含 locationModule 本身),收集路径
List
<
String
>
path
=
new
ArrayList
<>();
Long
current
=
nodeVO
.
getParentId
();
while
(
current
!=
null
&&
!
current
.
equals
(
locationModule
))
{
InspectionNodeVO
parent
=
nodeMap
.
get
(
current
);
if
(
parent
==
null
)
{
break
;
}
// 头插,保持从上到下的顺序
path
.
add
(
0
,
parent
.
getNodeName
());
current
=
parent
.
getParentId
();
}
// path 现在是从 locationModule 直接子节点到叶子节点父节点的名称列表
// path[0] = 二级模块名,path.last = 叶子父节点名
String
subModuleName
=
path
.
isEmpty
()
?
StrUtil
.
EMPTY
:
path
.
get
(
0
);
// triModuleName 取叶子节点自身名称
String
triModuleName
=
nodeName
;
return
new
String
[]{
subModuleName
,
triModuleName
};
}
// -------------------------------------------------------------------------
// 评分日志保存(固定8项评分字段)
// -------------------------------------------------------------------------
/**
* 保存评分修改日志(固定8项评分字段)
* <p>
* 对比新旧评分数据,如有变更则记录到操作日志表
*
* @param recordId 检测记录ID
* @param taskId 工单ID
* @param workOrder 工单对象
* @param oldRecord 保存前的检测记录(包含旧评分)
* @param newRecord 保存后的检测记录(包含新评分)
* @param platType 平台类型
* @param operatorId 操作人ID
* @param operatorName 操作人姓名
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
void
saveScoreEditLog
(
Long
recordId
,
Long
taskId
,
InspectionWorkOrder
workOrder
,
InspectionRecord
oldRecord
,
InspectionRecord
newRecord
,
InspectionPlatTypeEnum
platType
,
Long
operatorId
,
String
operatorName
)
{
// 1. 构建评分字段对比列表
List
<
InspectionOpLogItem
>
items
=
new
ArrayList
<>();
int
sortSeq
=
0
;
// 外观评分
addScoreItemIfChanged
(
items
,
InspectConstants
.
SCORE_EXTERIOR
,
LambdaUtil
.
getFieldName
(
InspectionRecord:
:
getExteriorScore
),
oldRecord
!=
null
?
oldRecord
.
getExteriorScore
()
:
null
,
newRecord
.
getExteriorScore
(),
sortSeq
++);
// 外观评分依据
addScoreItemIfChanged
(
items
,
InspectConstants
.
SCORE_EXTERIOR_BASE
,
LambdaUtil
.
getFieldName
(
InspectionRecord:
:
getExteriorComment
),
oldRecord
!=
null
?
oldRecord
.
getExteriorComment
()
:
null
,
newRecord
.
getExteriorComment
(),
sortSeq
++);
// 骨架评级
addScoreItemIfChanged
(
items
,
InspectConstants
.
SCORE_SKELETON
,
LambdaUtil
.
getFieldName
(
InspectionRecord:
:
getSkeletonLevel
),
oldRecord
!=
null
?
oldRecord
.
getSkeletonLevel
()
:
null
,
newRecord
.
getSkeletonLevel
(),
sortSeq
++);
// 骨架评级依据
addScoreItemIfChanged
(
items
,
InspectConstants
.
SCORE_SKELETON_BASE
,
LambdaUtil
.
getFieldName
(
InspectionRecord:
:
getSkeletonComment
),
oldRecord
!=
null
?
oldRecord
.
getSkeletonComment
()
:
null
,
newRecord
.
getSkeletonComment
(),
sortSeq
++);
// 内饰评级
addScoreItemIfChanged
(
items
,
InspectConstants
.
SCORE_INTERIOR
,
LambdaUtil
.
getFieldName
(
InspectionRecord:
:
getInteriorLevel
),
oldRecord
!=
null
?
oldRecord
.
getInteriorLevel
()
:
null
,
newRecord
.
getInteriorLevel
(),
sortSeq
++);
// 内饰评级依据
addScoreItemIfChanged
(
items
,
InspectConstants
.
SCORE_INTERIOR_BASE
,
LambdaUtil
.
getFieldName
(
InspectionRecord:
:
getInteriorComment
),
oldRecord
!=
null
?
oldRecord
.
getInteriorComment
()
:
null
,
newRecord
.
getInteriorComment
(),
sortSeq
++);
// 综合评分
addScoreItemIfChanged
(
items
,
InspectConstants
.
SCORE_OVERALL
,
LambdaUtil
.
getFieldName
(
InspectionRecord:
:
getOverallScore
),
oldRecord
!=
null
?
oldRecord
.
getOverallScore
()
:
null
,
newRecord
.
getOverallScore
(),
sortSeq
++);
// 综合评价
addScoreItemIfChanged
(
items
,
InspectConstants
.
SCORE_OVERALL_BASE
,
LambdaUtil
.
getFieldName
(
InspectionRecord:
:
getOverallComment
),
oldRecord
!=
null
?
oldRecord
.
getOverallComment
()
:
null
,
newRecord
.
getOverallComment
(),
sortSeq
++);
// 2. 无变更则跳过
if
(
CollUtil
.
isEmpty
(
items
))
{
log
.
info
(
"评分无变更,跳过日志记录,recordId={}"
,
recordId
);
return
;
}
// 3. 创建工单操作日志(InspectionWorkOrderOpLog)
InspectionWorkOrderOpLog
woOpLog
=
new
InspectionWorkOrderOpLog
();
woOpLog
.
setWorkOrderInnerId
(
workOrder
.
getId
());
woOpLog
.
setWoId
(
workOrder
.
getWoId
());
woOpLog
.
setOperatorId
(
operatorId
);
woOpLog
.
setOperatorName
(
operatorName
);
woOpLog
.
setPlateType
(
platType
.
getCode
());
woOpLog
.
setOperationType
(
InspectionWorkOrderOperationTypeEnum
.
UPDATE_INSPECTION_SCORE
.
getCode
());
woOpLog
.
setOriginalStatus
(
workOrder
.
getStatus
());
woOpLog
.
setTargetStatus
(
workOrder
.
getStatus
());
woOpLog
.
setOperationContent
(
"编辑检测评分"
);
woOpLog
.
setOperationTime
(
LocalDateTime
.
now
());
woOpLog
.
setDescription
(
String
.
format
(
"操作人[%s]修改检测评分,共%d项变更"
,
operatorName
,
items
.
size
()));
woOpLog
.
setDeleteFlag
(
DeleteFlag
.
NOT_DELETED
.
getCode
());
InspectionWorkOrderOpLog
savedWoOpLog
=
inspectionWorkOrderOpLogRepository
.
save
(
woOpLog
);
// 4. 创建主日志记录(InspectionOpLog)
InspectionOpLog
opLog
=
new
InspectionOpLog
();
opLog
.
setRecordId
(
recordId
);
opLog
.
setWoOpId
(
savedWoOpLog
.
getId
());
opLog
.
setTaskId
(
taskId
);
opLog
.
setDeleteFlag
(
DeleteFlag
.
NOT_DELETED
.
getCode
());
InspectionOpLog
savedOpLog
=
inspectionOpLogRepository
.
save
(
opLog
);
// 5. 设置日志ID并批量保存明细
Long
logId
=
savedOpLog
.
getLogId
();
items
.
forEach
(
item
->
item
.
setLogId
(
logId
));
inspectionOpLogItemRepository
.
saveAll
(
items
);
log
.
info
(
"评分修改日志保存完成,recordId={}, woOpLogId={}, logId={}, itemCount={}"
,
recordId
,
savedWoOpLog
.
getId
(),
logId
,
items
.
size
());
}
/**
* 添加评分变更项(如果值有变化)
*/
private
void
addScoreItemIfChanged
(
List
<
InspectionOpLogItem
>
items
,
String
fieldLabel
,
String
fieldKey
,
Object
oldValue
,
Object
newValue
,
int
sortSeq
)
{
String
oldStr
=
oldValue
!=
null
?
oldValue
.
toString
()
:
null
;
String
newStr
=
newValue
!=
null
?
newValue
.
toString
()
:
null
;
if
(!
ObjectUtil
.
equal
(
oldStr
,
newStr
))
{
InspectionOpLogItem
item
=
new
InspectionOpLogItem
();
item
.
setModuleName
(
"检测评分"
);
item
.
setSubModuleName
(
StrUtil
.
EMPTY
);
item
.
setTriModuleName
(
fieldLabel
);
item
.
setFieldLabel
(
fieldLabel
);
item
.
setFieldKey
(
fieldKey
);
item
.
setBeforeValue
(
oldStr
);
item
.
setAfterValue
(
newStr
);
item
.
setSortSeq
(
sortSeq
);
item
.
setDeleteFlag
(
DeleteFlag
.
NOT_DELETED
.
getCode
());
items
.
add
(
item
);
}
}
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/service/InspectionNodeService.java
View file @
b2f6a2e
...
@@ -233,7 +233,7 @@ public class InspectionNodeService {
...
@@ -233,7 +233,7 @@ public class InspectionNodeService {
* @param all 所有节点
* @param all 所有节点
* @return 子节点列表,按 sortOrder 升序
* @return 子节点列表,按 sortOrder 升序
*/
*/
public
List
<
InspectionNodeVO
>
getChildNodes
(
Long
rootNodeId
,
List
<
InspectionNodeVO
>
all
)
{
public
static
List
<
InspectionNodeVO
>
getChildNodes
(
Long
rootNodeId
,
List
<
InspectionNodeVO
>
all
)
{
return
all
.
stream
()
return
all
.
stream
()
.
filter
(
node
->
ObjectUtil
.
isNotNull
(
node
.
getParentId
())
&&
node
.
getParentId
().
equals
(
rootNodeId
))
.
filter
(
node
->
ObjectUtil
.
isNotNull
(
node
.
getParentId
())
&&
node
.
getParentId
().
equals
(
rootNodeId
))
.
peek
(
node
->
node
.
setChildrenNodes
(
getChildNodes
(
node
.
getId
(),
all
)))
.
peek
(
node
->
node
.
setChildrenNodes
(
getChildNodes
(
node
.
getId
(),
all
)))
...
...
aus-core/src/main/java/com/glsx/usedcar/module/inspect/service/InspectionRecordService.java
View file @
b2f6a2e
...
@@ -14,7 +14,9 @@ import com.glsx.usedcar.converts.InspectorConverter;
...
@@ -14,7 +14,9 @@ import com.glsx.usedcar.converts.InspectorConverter;
import
com.glsx.usedcar.enums.common.DeleteFlag
;
import
com.glsx.usedcar.enums.common.DeleteFlag
;
import
com.glsx.usedcar.enums.common.WebhooksBusinessType
;
import
com.glsx.usedcar.enums.common.WebhooksBusinessType
;
import
com.glsx.usedcar.enums.inspect.InspectionBaseInfoFieldEnum
;
import
com.glsx.usedcar.enums.inspect.InspectionBaseInfoFieldEnum
;
import
com.glsx.usedcar.enums.inspect.InspectionPlatTypeEnum
;
import
com.glsx.usedcar.enums.inspect.InspectionWorkOrderStatusEnum
;
import
com.glsx.usedcar.enums.inspect.InspectionWorkOrderStatusEnum
;
import
com.glsx.usedcar.factories.inspect.InspectionValueStrategyRouter
;
import
com.glsx.usedcar.handler.WebHookHandler
;
import
com.glsx.usedcar.handler.WebHookHandler
;
import
com.glsx.usedcar.module.business.entity.NoticeTemplate
;
import
com.glsx.usedcar.module.business.entity.NoticeTemplate
;
import
com.glsx.usedcar.module.business.service.NoticeField
;
import
com.glsx.usedcar.module.business.service.NoticeField
;
...
@@ -23,25 +25,31 @@ import com.glsx.usedcar.module.inspect.dao.InspectionResultRepository;
...
@@ -23,25 +25,31 @@ import com.glsx.usedcar.module.inspect.dao.InspectionResultRepository;
import
com.glsx.usedcar.module.inspect.dao.InspectionValueRepository
;
import
com.glsx.usedcar.module.inspect.dao.InspectionValueRepository
;
import
com.glsx.usedcar.module.inspect.dao.InspectionWorkOrderRepository
;
import
com.glsx.usedcar.module.inspect.dao.InspectionWorkOrderRepository
;
import
com.glsx.usedcar.module.inspect.dto.AccidentBurnWadeDTO
;
import
com.glsx.usedcar.module.inspect.dto.AccidentBurnWadeDTO
;
import
com.glsx.usedcar.module.inspect.dto.InspectionResultDTO
;
import
com.glsx.usedcar.module.inspect.dto.InspectionTemplateDTO
;
import
com.glsx.usedcar.module.inspect.dto.InspectionTemplateDTO
;
import
com.glsx.usedcar.module.inspect.entity.*
;
import
com.glsx.usedcar.module.inspect.entity.*
;
import
com.glsx.usedcar.factories.inspect.InspectionValueStrategyRouter
;
import
com.glsx.usedcar.module.inspect.service.strategy.TemplateValueStrategy
;
import
com.glsx.usedcar.module.inspect.service.strategy.TemplateValueStrategy
;
import
com.glsx.usedcar.module.inspect.vo.*
;
import
com.glsx.usedcar.module.inspect.vo.*
;
import
com.glsx.usedcar.module.vehicle.entity.Vehicle
;
import
com.glsx.usedcar.module.vehicle.entity.Vehicle
;
import
com.glsx.usedcar.util.RedisCacheUtil
;
import
com.glsx.usedcar.util.RedisCacheUtil
;
import
com.glsx.usedcar.module.inspect.delegate.InspectionSaveDelegate
;
import
com.glsx.usedcar.validators.inspector.NodeValidationManager
;
import
com.glsx.usedcar.validators.inspector.NodeValidationManager
;
import
com.google.common.collect.Lists
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.checkerframework.checker.nullness.qual.Nullable
;
import
org.jspecify.annotations.NonNull
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
org.summerframework.core.util.StringUtils
;
import
org.summerframework.core.util.StringUtils
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
java.util.stream.Stream
;
...
@@ -71,6 +79,7 @@ public class InspectionRecordService {
...
@@ -71,6 +79,7 @@ public class InspectionRecordService {
private
final
InspectionWorkOrderService
inspectionWorkOrderService
;
private
final
InspectionWorkOrderService
inspectionWorkOrderService
;
private
final
InspectionValueStrategyRouter
inspectionValueStrategyRouter
;
private
final
InspectionValueStrategyRouter
inspectionValueStrategyRouter
;
private
final
InspectionWorkOrderRepository
inspectionWorkOrderRepository
;
private
final
InspectionWorkOrderRepository
inspectionWorkOrderRepository
;
private
final
InspectionEditLogService
inspectionEditLogService
;
/**
/**
* <pre>
* <pre>
...
@@ -92,6 +101,7 @@ public class InspectionRecordService {
...
@@ -92,6 +101,7 @@ public class InspectionRecordService {
* @param inspector 当前登录的检测师
* @param inspector 当前登录的检测师
* @return 检测记录 ID
* @return 检测记录 ID
*/
*/
@Deprecated
(
forRemoval
=
true
,
since
=
"2026.03大版本"
)
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
Long
saveInspection
(
InspectionSaveVO
req
,
Inspector
inspector
)
{
public
Long
saveInspection
(
InspectionSaveVO
req
,
Inspector
inspector
)
{
Long
taskId
=
req
.
getTaskId
();
Long
taskId
=
req
.
getTaskId
();
...
@@ -121,7 +131,8 @@ public class InspectionRecordService {
...
@@ -121,7 +131,8 @@ public class InspectionRecordService {
// 1. 查询或创建检测记录
// 1. 查询或创建检测记录
InspectionRecord
record
=
inspectionRecordRepository
.
findByTaskIdAndDeletedFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
InspectionRecord
record
=
inspectionRecordRepository
.
findByTaskIdAndDeletedFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElseGet
(()
->
createRecord
(
req
,
inspectionWorkOrder
.
getTemplateId
(),
inspectionWorkOrder
.
getTemplateVersion
()));
.
orElseGet
(()
->
createRecord
(
req
,
inspectionWorkOrder
.
getTemplateId
(),
inspectionWorkOrder
.
getTemplateVersion
(),
InspectionPlatTypeEnum
.
INSPECTOR
,
inspector
.
getId
(),
inspector
.
getName
()));
Long
recordId
=
record
.
getId
();
Long
recordId
=
record
.
getId
();
// 2. 获取所有节点配置,构建 nodeId -> InspectionNodeVO 映射
// 2. 获取所有节点配置,构建 nodeId -> InspectionNodeVO 映射
...
@@ -197,14 +208,34 @@ public class InspectionRecordService {
...
@@ -197,14 +208,34 @@ public class InspectionRecordService {
}
}
/**
/**
* 创建检测记录
* 创建检测记录
(InspectionSaveVO)
*
*
* @param req 请求参数
* @param req 请求参数
* @param platTypeEnum 平台类型
* @param operatorId 操作人ID
* @param operatorName 操作人名称
* @return InspectionRecord
* @return InspectionRecord
*/
*/
private
InspectionRecord
createRecord
(
InspectionSaveVO
req
,
Long
templateId
,
String
templateVersion
)
{
private
InspectionRecord
createRecord
(
InspectionSaveVO
req
,
Long
templateId
,
String
templateVersion
,
Long
taskId
=
req
.
getTaskId
();
InspectionPlatTypeEnum
platTypeEnum
,
Long
operatorId
,
String
operatorName
)
{
return
createRecord
(
req
.
getTaskId
(),
req
.
getLocationModule
(),
templateId
,
templateVersion
,
platTypeEnum
,
operatorId
,
operatorName
);
}
/**
* 创建检测记录(核心逻辑)
*
* @param taskId 任务 ID
* @param locationModule 一级模块 ID
* @param templateId 模板 ID
* @param templateVersion 模板版本
* @param platTypeEnum 平台类型
* @param operatorId 操作人ID
* @param operatorName 操作人名称
* @return InspectionRecord
*/
private
InspectionRecord
createRecord
(
Long
taskId
,
Long
locationModule
,
Long
templateId
,
String
templateVersion
,
InspectionPlatTypeEnum
platTypeEnum
,
Long
operatorId
,
String
operatorName
)
{
InspectionTemplateDTO
inspectionTemplateDTO
=
inspectionTemplateService
.
getTemplateByIdAndVersion
(
templateId
,
templateVersion
);
InspectionTemplateDTO
inspectionTemplateDTO
=
inspectionTemplateService
.
getTemplateByIdAndVersion
(
templateId
,
templateVersion
);
String
templateCode
=
Optional
.
ofNullable
(
inspectionTemplateDTO
)
String
templateCode
=
Optional
.
ofNullable
(
inspectionTemplateDTO
)
.
map
(
InspectionTemplateDTO:
:
getTemplateCode
)
.
map
(
InspectionTemplateDTO:
:
getTemplateCode
)
...
@@ -217,13 +248,13 @@ public class InspectionRecordService {
...
@@ -217,13 +248,13 @@ public class InspectionRecordService {
.
templateCode
(
templateCode
)
.
templateCode
(
templateCode
)
.
progress
(
0
)
.
progress
(
0
)
.
completedModules
(
0
)
.
completedModules
(
0
)
.
locationModule
(
req
.
getLocationModule
()
)
.
locationModule
(
locationModule
)
.
startTime
(
LocalDateTime
.
now
())
.
startTime
(
LocalDateTime
.
now
())
.
build
();
.
build
();
InspectionRecord
save
=
inspectionRecordRepository
.
save
(
record
);
InspectionRecord
save
=
inspectionRecordRepository
.
save
(
record
);
// 开始检测
// 开始检测
inspectionWorkOrderService
.
startInspection
(
req
.
getTaskId
()
);
inspectionWorkOrderService
.
startInspection
(
taskId
,
platTypeEnum
,
operatorId
,
operatorName
);
return
save
;
return
save
;
}
}
...
@@ -402,6 +433,251 @@ public class InspectionRecordService {
...
@@ -402,6 +433,251 @@ public class InspectionRecordService {
}
}
}
}
// =========================================================================
// 批量持久化相关(内部数据类 + 核心方法)
// =========================================================================
/**
* 单个模块的校验后数据(内存态,尚未持久化)
*/
private
record
ModulePersistData
(
Long
locationSubModule
,
List
<
InspectionLeafNodeVO
>
leafNodes
,
List
<
InspectionNodeVO
>
locationLeafNodes
,
String
completedFlag
)
{}
/**
* 批量持久化所有模块的检测结果和值(统一全删再插)
* <p>
* 将原来逐模块调用的 persistResults 合并为一次批量操作:
* 1 次查询旧数据 + 1 次删除旧值 + 1 次删除旧结果 + 1 次插入新结果 + 1 次插入新值 = 共 5 次 DB IO
* (若存在不在本次批量中的其他二级模块,判断一级完成状态时额外 +1 次查询,共 6 次)
*
* @param recordId 检测记录 ID
* @param locationModule 一级模块 ID
* @param modulePersistDataList 所有模块的待持久化数据(已完成过滤/校验/补齐)
* @param nodeConfigMap nodeId -> InspectionNodeVO
* @param parentChildMap parentId -> 子节点列表
* @return 保存后的检测结果 DTO 列表(用于操作日志对比,避免返回 JPA 实体)
*/
private
List
<
InspectionResultDTO
>
persistResultsBatch
(
Long
recordId
,
Long
locationModule
,
List
<
ModulePersistData
>
modulePersistDataList
,
Map
<
Long
,
InspectionNodeVO
>
nodeConfigMap
,
Map
<
Long
,
List
<
InspectionNodeVO
>>
parentChildMap
)
{
if
(
CollUtil
.
isEmpty
(
modulePersistDataList
))
{
return
Collections
.
emptyList
();
}
// 1. 收集所有涉及的 nodeId(所有模块的叶子节点 + 二级模块节点 + 一级模块节点)
Set
<
Long
>
allInvolvedNodeIds
=
new
HashSet
<>();
if
(
locationModule
!=
null
)
{
allInvolvedNodeIds
.
add
(
locationModule
);
}
for
(
ModulePersistData
data
:
modulePersistDataList
)
{
if
(
data
.
locationSubModule
()
!=
null
)
{
allInvolvedNodeIds
.
add
(
data
.
locationSubModule
());
}
// 使用 locationLeafNodes(当前模块下全量叶子配置)确保能清除旧数据
data
.
locationLeafNodes
().
forEach
(
n
->
allInvolvedNodeIds
.
add
(
n
.
getId
()));
// 同时包含本次实际提交的叶子节点
data
.
leafNodes
().
forEach
(
l
->
allInvolvedNodeIds
.
add
(
l
.
getNodeId
()));
}
allInvolvedNodeIds
.
remove
(
null
);
if
(
allInvolvedNodeIds
.
isEmpty
())
{
return
Collections
.
emptyList
();
}
// 2. 【1次查询】查询所有涉及节点的旧 InspectionResult
List
<
InspectionResult
>
oldResults
=
inspectionResultRepository
.
findByRecordIdAndNodeIdIn
(
recordId
,
new
ArrayList
<>(
allInvolvedNodeIds
));
// 3. 【1次删除】批量删除旧 InspectionValue
// 4. 【1次删除】批量删除旧 InspectionResult
if
(
CollUtil
.
isNotEmpty
(
oldResults
))
{
List
<
Long
>
oldResultIds
=
oldResults
.
stream
().
map
(
InspectionResult:
:
getId
).
toList
();
inspectionValueRepository
.
deleteByResultIdIn
(
oldResultIds
);
inspectionResultRepository
.
deleteAll
(
oldResults
);
}
// 5. 在内存中构建所有新 InspectionResult
List
<
InspectionResult
>
allNewResults
=
new
ArrayList
<>();
// 追踪每个二级模块的完成状态,用于在内存中计算一级模块 completedFlag
Map
<
Long
,
String
>
subModuleCompletedFlags
=
new
HashMap
<>();
for
(
ModulePersistData
data
:
modulePersistDataList
)
{
Long
locationSubModule
=
data
.
locationSubModule
();
String
completedFlag
=
data
.
completedFlag
();
// 5a. 二级模块节点
if
(
locationSubModule
!=
null
)
{
allNewResults
.
add
(
InspectionResult
.
builder
()
.
recordId
(
recordId
)
.
nodeId
(
locationSubModule
)
.
nodeName
(
Optional
.
ofNullable
(
nodeConfigMap
.
get
(
locationSubModule
))
.
map
(
InspectionNodeVO:
:
getNodeName
).
orElse
(
null
))
.
completedFlag
(
completedFlag
)
.
build
());
subModuleCompletedFlags
.
put
(
locationSubModule
,
completedFlag
);
}
// 5b. 叶子节点
for
(
InspectionLeafNodeVO
leafNode
:
data
.
leafNodes
())
{
InspectionNodeVO
cfg
=
nodeConfigMap
.
get
(
leafNode
.
getNodeId
());
if
(
cfg
==
null
)
{
continue
;
}
allNewResults
.
add
(
InspectionResult
.
builder
()
.
recordId
(
recordId
)
.
nodeId
(
leafNode
.
getNodeId
())
.
nodeName
(
cfg
.
getNodeName
())
.
resultStatus
(
ObjectUtil
.
defaultIfNull
(
leafNode
.
getResultStatus
(),
1
))
.
remark
(
leafNode
.
getRemark
())
.
completedFlag
(
completedFlag
)
.
build
());
}
}
// 5c. 计算一级模块的 completedFlag(内存计算,不发起额外 DB IO,仅当存在未覆盖的二级模块时查一次库)
if
(
locationModule
!=
null
)
{
String
moduleCompletedFlag
=
calculateModuleCompletedFlag
(
recordId
,
locationModule
,
subModuleCompletedFlags
,
parentChildMap
,
modulePersistDataList
);
allNewResults
.
add
(
InspectionResult
.
builder
()
.
recordId
(
recordId
)
.
nodeId
(
locationModule
)
.
nodeName
(
Optional
.
ofNullable
(
nodeConfigMap
.
get
(
locationModule
))
.
map
(
InspectionNodeVO:
:
getNodeName
).
orElse
(
null
))
.
completedFlag
(
moduleCompletedFlag
)
.
build
());
}
// 6. 【1次插入】批量插入所有新 InspectionResult
List
<
InspectionResult
>
savedResults
=
inspectionResultRepository
.
saveAll
(
allNewResults
);
// 7. 构建 nodeId -> resultId 映射
Map
<
Long
,
Long
>
nodeIdToResultId
=
savedResults
.
stream
()
.
collect
(
Collectors
.
toMap
(
InspectionResult:
:
getNodeId
,
InspectionResult:
:
getId
,
(
pre
,
next
)
->
pre
));
// 8. 在内存中收集所有 InspectionValue
List
<
InspectionValue
>
allNewValues
=
new
ArrayList
<>();
for
(
ModulePersistData
data
:
modulePersistDataList
)
{
for
(
InspectionLeafNodeVO
leafNode
:
data
.
leafNodes
())
{
if
(
CollUtil
.
isEmpty
(
leafNode
.
getData
()))
{
continue
;
}
Long
resultId
=
nodeIdToResultId
.
get
(
leafNode
.
getNodeId
());
if
(
resultId
==
null
)
{
continue
;
}
for
(
InspectionLeafNodeDataVO
valData
:
leafNode
.
getData
())
{
allNewValues
.
add
(
InspectionValue
.
builder
()
.
resultId
(
resultId
)
.
valueKey
(
valData
.
getValueKey
())
.
valueText
(
valData
.
getValueText
())
.
interactionType
(
valData
.
getInteractionType
())
.
valueSeq
(
ObjectUtil
.
defaultIfNull
(
valData
.
getValueSeq
(),
1
))
.
remark
(
valData
.
getRemark
())
.
build
());
}
}
}
// 9. 【1次插入】批量插入所有新 InspectionValue
List
<
InspectionValue
>
savedValues
=
Collections
.
emptyList
();
if
(
CollUtil
.
isNotEmpty
(
allNewValues
))
{
savedValues
=
inspectionValueRepository
.
saveAll
(
allNewValues
);
}
// 10. 构建 resultId -> InspectionValue 列表的映射
Map
<
Long
,
List
<
InspectionValue
>>
resultIdToValues
=
savedValues
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
InspectionValue:
:
getResultId
));
// 11. 转换为 DTO 返回(避免返回 JPA 实体,防止事务中意外修改数据库)
return
savedResults
.
stream
()
.
map
(
result
->
{
List
<
InspectionValue
>
values
=
resultIdToValues
.
getOrDefault
(
result
.
getId
(),
Collections
.
emptyList
());
return
InspectionResultDTO
.
builder
()
.
nodeId
(
result
.
getNodeId
())
.
resultStatus
(
result
.
getResultStatus
())
.
remark
(
result
.
getRemark
())
.
values
(
values
.
stream
()
.
map
(
v
->
InspectionResultDTO
.
ValueItem
.
builder
()
.
valueKey
(
v
.
getValueKey
())
.
valueText
(
v
.
getValueText
())
.
interactionType
(
v
.
getInteractionType
())
.
valueSeq
(
v
.
getValueSeq
())
.
remark
(
v
.
getRemark
())
.
build
())
.
collect
(
Collectors
.
toList
()))
.
build
();
})
.
collect
(
Collectors
.
toList
());
}
/**
* 在内存中计算一级模块的 completedFlag
* <p>
* 本次批量保存中已覆盖的二级模块直接从内存读取,未覆盖的其他二级模块才查一次库。
* 最多只有 1 次额外的 DB IO(而非原来的 2N 次)。
*
* @param recordId 检测记录 ID
* @param locationModule 一级模块 ID
* @param batchSubModuleFlags 本次批量中各二级模块的完成标记(subModuleId -> completedFlag)
* @param parentChildMap parentId -> 子节点列表
* @param modulePersistDataList 本次批量的持久化数据列表(用于无二级模块时直接取 completedFlag)
* @return 一级模块的 completedFlag
*/
private
String
calculateModuleCompletedFlag
(
Long
recordId
,
Long
locationModule
,
Map
<
Long
,
String
>
batchSubModuleFlags
,
Map
<
Long
,
List
<
InspectionNodeVO
>>
parentChildMap
,
List
<
ModulePersistData
>
modulePersistDataList
)
{
// 获取一级模块下所有二级模块 ID
List
<
Long
>
subModuleIds
=
CollUtil
.
emptyIfNull
(
parentChildMap
.
get
(
locationModule
))
.
stream
()
.
filter
(
n
->
Objects
.
equals
(
n
.
getNodeType
(),
InspectConstants
.
NODE_TYPE_GROUP
))
.
map
(
InspectionNodeVO:
:
getId
)
.
toList
();
if
(
CollUtil
.
isEmpty
(
subModuleIds
))
{
// 没有二级模块(叶子直挂一级下):直接使用批次中的 completedFlag
// 与原 persistResults 逻辑一致:completedFlag 由 nextFlag 决定
boolean
allCompleted
=
modulePersistDataList
.
stream
()
.
allMatch
(
data
->
InspectConstants
.
COMPLETED_FLAG_YES
.
equals
(
data
.
completedFlag
()));
return
allCompleted
?
InspectConstants
.
COMPLETED_FLAG_YES
:
InspectConstants
.
COMPLETED_FLAG_NO
;
}
// 有二级模块:区分本次批量已覆盖的和未覆盖的
List
<
Long
>
otherSubModuleIds
=
subModuleIds
.
stream
()
.
filter
(
id
->
!
batchSubModuleFlags
.
containsKey
(
id
))
.
toList
();
// 本次批量中的二级模块若有未完成的,一级模块直接未完成
boolean
batchAllCompleted
=
batchSubModuleFlags
.
values
().
stream
()
.
allMatch
(
InspectConstants
.
COMPLETED_FLAG_YES
::
equals
);
if
(!
batchAllCompleted
)
{
return
InspectConstants
.
COMPLETED_FLAG_NO
;
}
// 不在本次批量中的其他二级模块:查一次库(而不是 2N 次)
if
(
CollUtil
.
isNotEmpty
(
otherSubModuleIds
))
{
List
<
InspectionResult
>
otherResults
=
inspectionResultRepository
.
findByRecordIdAndNodeIdIn
(
recordId
,
otherSubModuleIds
);
Map
<
Long
,
InspectionResult
>
otherResultMap
=
otherResults
.
stream
()
.
collect
(
Collectors
.
toMap
(
InspectionResult:
:
getNodeId
,
Function
.
identity
(),
(
pre
,
next
)
->
pre
));
for
(
Long
subId
:
otherSubModuleIds
)
{
InspectionResult
result
=
otherResultMap
.
get
(
subId
);
if
(
result
==
null
||
!
InspectConstants
.
COMPLETED_FLAG_YES
.
equals
(
result
.
getCompletedFlag
()))
{
return
InspectConstants
.
COMPLETED_FLAG_NO
;
}
}
}
return
InspectConstants
.
COMPLETED_FLAG_YES
;
}
/**
/**
* <pre>
* <pre>
* 检测师完成检测
* 检测师完成检测
...
@@ -415,6 +691,7 @@ public class InspectionRecordService {
...
@@ -415,6 +691,7 @@ public class InspectionRecordService {
* @param inspector 当前登录的检测师
* @param inspector 当前登录的检测师
* @return 第一个未完成的根节点 id,全部完成返回 null
* @return 第一个未完成的根节点 id,全部完成返回 null
*/
*/
@Deprecated
(
forRemoval
=
true
,
since
=
"2026.03大版本"
)
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
CompleteInspectionRespVO
completeInspection
(
CompleteInspectionVO
req
,
Inspector
inspector
)
{
public
CompleteInspectionRespVO
completeInspection
(
CompleteInspectionVO
req
,
Inspector
inspector
)
{
Long
taskId
=
req
.
getTaskId
();
Long
taskId
=
req
.
getTaskId
();
...
@@ -429,90 +706,583 @@ public class InspectionRecordService {
...
@@ -429,90 +706,583 @@ public class InspectionRecordService {
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
BUSINESS_BUSY
);
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
BUSINESS_BUSY
);
}
}
InspectionWorkOrder
inspectionWorkOrder
=
inspectionWorkOrderRepository
.
findByIdAndDeleteFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
InspectionWorkOrder
inspectionWorkOrder
=
inspectionWorkOrderRepository
.
findByIdAndDeleteFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXISTS
,
taskId
,
"检测工单"
));
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXISTS
,
taskId
,
"检测工单"
));
if
(!
InspectionWorkOrderStatusEnum
.
beableInspection
(
inspectionWorkOrder
.
getStatus
()))
{
if
(!
InspectionWorkOrderStatusEnum
.
beableInspection
(
inspectionWorkOrder
.
getStatus
()))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
NOT_ABLE_INSPECT
);
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
NOT_ABLE_INSPECT
);
}
}
InspectionTemplateDTO
inspectionTemplateDTO
=
inspectionTemplateService
.
getTemplateByIdAndVersion
(
inspectionWorkOrder
.
getTemplateId
(),
inspectionWorkOrder
.
getTemplateVersion
());
// 校验检测师
if
(!
inspector
.
getId
().
equals
(
Optional
.
ofNullable
(
inspectionWorkOrder
.
getInspector
()).
map
(
Inspector:
:
getId
).
orElse
(
null
)))
{
if
(!
inspector
.
getId
().
equals
(
Optional
.
ofNullable
(
inspectionWorkOrder
.
getInspector
()).
map
(
Inspector:
:
getId
).
orElse
(
null
)))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
NOT_CURR_WORK_INSPECTOR
);
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
NOT_CURR_WORK_INSPECTOR
);
}
}
// 1. 查询检测记录,不存在则新建
InspectionTemplateDTO
inspectionTemplateDTO
=
inspectionTemplateService
InspectionRecord
record
;
.
getTemplateByIdAndVersion
(
inspectionWorkOrder
.
getTemplateId
(),
inspectionWorkOrder
.
getTemplateVersion
());
Optional
<
InspectionRecord
>
inspectionRecordOptional
=
inspectionRecordRepository
.
findByTaskIdAndDeletedFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
());
if
(
inspectionRecordOptional
.
isPresent
())
{
// 1. 保存或更新检测记录
record
=
inspectionRecordOptional
.
get
();
InspectionRecord
record
=
saveOrUpdateRecord
(
req
,
inspectionTemplateDTO
,
taskId
,
// 修改评分评级
InspectionPlatTypeEnum
.
INSPECTOR
,
inspector
.
getId
(),
inspector
.
getName
());
record
.
setExteriorScore
(
req
.
getExteriorScore
());
record
.
setExteriorComment
(
req
.
getExteriorComment
());
// 2. 获取节点树并查找第一个未完成节点
record
.
setSkeletonLevel
(
req
.
getSkeletonLevel
());
List
<
InspectionNodeVO
>
allNodes
=
inspectionNodeService
.
inspectionNodesByTaskId
(
taskId
);
record
.
setSkeletonComment
(
req
.
getSkeletonComment
());
List
<
InspectionNodeVO
>
rootNodes
=
allNodes
.
stream
()
record
.
setInteriorLevel
(
req
.
getInteriorLevel
());
.
filter
(
n
->
n
.
getNodeType
()
!=
null
&&
n
.
getNodeType
()
==
InspectConstants
.
NODE_TYPE_MODULE
)
record
.
setInteriorComment
(
req
.
getInteriorComment
());
.
sorted
(
Comparator
.
comparingInt
(
n
->
Optional
.
ofNullable
(
n
.
getSortOrder
()).
orElse
(
0
)))
record
.
setOverallScore
(
req
.
getOverallScore
());
.
toList
();
record
.
setOverallComment
(
req
.
getOverallComment
());
if
(
CollUtil
.
isEmpty
(
rootNodes
))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXISTS
,
"检测模板节点配置"
);
}
Map
<
Long
,
List
<
InspectionNodeVO
>>
parentChildMap
=
buildParentChildMap
(
allNodes
);
List
<
Long
>
allNodeIds
=
allNodes
.
stream
().
map
(
InspectionNodeVO:
:
getId
).
toList
();
Map
<
Long
,
InspectionResult
>
resultMap
=
CollUtil
.
isEmpty
(
allNodeIds
)
?
Map
.
of
()
:
inspectionResultRepository
.
findByRecordIdAndNodeIdIn
(
record
.
getId
(),
allNodeIds
)
.
stream
().
collect
(
Collectors
.
toMap
(
InspectionResult:
:
getNodeId
,
r
->
r
,
(
a
,
b
)
->
a
));
CompleteInspectionRespVO
uncompletedResp
=
findFirstUncompletedNode
(
rootNodes
,
parentChildMap
,
resultMap
);
if
(
uncompletedResp
!=
null
)
{
return
uncompletedResp
;
}
// 3. 所有节点已完成,更新完成时间并发送通知
LocalDateTime
completeTime
=
LocalDateTime
.
now
();
record
.
setCompleteTime
(
completeTime
);
inspectionRecordRepository
.
save
(
record
);
inspectionRecordRepository
.
save
(
record
);
}
else
{
InspectionRecord
recordSave
=
inspectorConverter
.
completeInspectionVo2InspectionRecord
(
req
);
recordSave
.
setStartTime
(
LocalDateTime
.
now
());
recordSave
.
setTemplateId
(
inspectionTemplateDTO
.
getId
());
recordSave
.
setTemplateVersion
(
inspectionTemplateDTO
.
getVersion
());
recordSave
.
setTemplateCode
(
inspectionTemplateDTO
.
getTemplateCode
());
record
=
inspectionRecordRepository
.
save
(
recordSave
);
inspectionWorkOrderService
.
startInspection
(
taskId
);
sendCompleteNotice
(
record
,
allNodes
,
taskId
,
completeTime
);
inspectionWorkOrderService
.
completeInspection
(
taskId
,
InspectionPlatTypeEnum
.
INSPECTOR
,
inspector
.
getId
(),
inspector
.
getName
());
log
.
info
(
"检测师完成检测成功,recordId: {}"
,
record
.
getId
());
return
CompleteInspectionRespVO
.
builder
().
build
();
}
finally
{
if
(
isLockSuccess
)
{
redisCacheUtil
.
deleteCacheIfMatch
(
lockKey
,
lockValue
);
}
}
}
}
/**
* 使用策略委托保存检测数据(按二级模块单次保存,兼容旧调用)
* <p>
* 将 {@link InspectionSaveVO} 包装为 {@link InspectionBatchSaveVO} 后委托给批量方法处理。
*
* @param req 保存请求(H5单模块入参)
* @param delegate 策略委托(H5检测师/PC质检员等各自实现)
* @return 检测记录 ID
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
Long
saveInspectionWithDelegate
(
InspectionSaveVO
req
,
InspectionSaveDelegate
delegate
)
{
InspectionBatchSaveVO
batchReq
=
new
InspectionBatchSaveVO
();
batchReq
.
setTaskId
(
req
.
getTaskId
());
batchReq
.
setLocationModule
(
req
.
getLocationModule
());
batchReq
.
setNextFlag
(
req
.
getNextFlag
());
InspectionBatchSaveVO
.
ModuleSaveItem
item
=
new
InspectionBatchSaveVO
.
ModuleSaveItem
();
item
.
setLocationSubModule
(
req
.
getLocationSubModule
());
item
.
setLeafNodes
(
req
.
getLeafNodes
());
batchReq
.
setModules
(
List
.
of
(
item
));
// 2. 获取所有根节点配置(一级模块,nodeType=1)
return
saveInspectionWithDelegate
(
batchReq
,
delegate
);
}
/**
* 使用策略委托批量保存检测数据(按一级模块,支持多个二级模块)
* <p>
* 核心保存逻辑:
* <ul>
* <li>分布式锁保证幂等</li>
* <li>权限校验委托给 {@link InspectionSaveDelegate#validatePermission}</li>
* <li>节点配置只查询一次,所有二级模块共用</li>
* <li>遍历所有 ModuleSaveItem,每个二级模块独立执行过滤/校验(纯内存操作),统一批量持久化</li>
* <li>所有模块在同一事务内处理</li>
* <li>保存前调用 {@link InspectionSaveDelegate#beforeSave}</li>
* <li>保存后调用 {@link InspectionSaveDelegate#afterSave}</li>
* </ul>
*
* @param req 批量保存请求
* @param delegate 策略委托(H5检测师/PC质检员等各自实现)
* @return 检测记录 ID
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
Long
saveInspectionWithDelegate
(
InspectionBatchSaveVO
req
,
InspectionSaveDelegate
delegate
)
{
Long
taskId
=
req
.
getTaskId
();
String
lockKey
=
StringUtils
.
templateFormat
(
InspectConstants
.
INSPECTION_LOCK_KEY
,
taskId
);
String
lockValue
=
UUID
.
randomUUID
().
toString
();
boolean
isLockSuccess
=
false
;
try
{
isLockSuccess
=
redisCacheUtil
.
setCacheIfAbsent
(
lockKey
,
lockValue
,
30
,
TimeUnit
.
SECONDS
);
if
(!
isLockSuccess
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
BUSINESS_BUSY
);
}
InspectionWorkOrder
inspectionWorkOrder
=
inspectionWorkOrderRepository
.
findByIdAndDeleteFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXISTS
,
taskId
,
"检测工单"
));
// ★ 使用策略校验权限(替代原来的状态检查 + 检测师ID匹配)
delegate
.
validatePermission
(
inspectionWorkOrder
);
boolean
nextFlag
=
BooleanUtil
.
isTrue
(
req
.
getNextFlag
());
Long
locationModule
=
req
.
getLocationModule
();
log
.
info
(
"保存检测数据,taskId: {}, locationModule: {}, nextFlag: {}, moduleCount: {}, 操作人: {}"
,
taskId
,
locationModule
,
nextFlag
,
CollUtil
.
size
(
req
.
getModules
()),
delegate
.
getOperatorName
());
// 1. 查询或创建检测记录(只做一次)
Long
templateId
=
inspectionWorkOrder
.
getTemplateId
();
String
templateVersion
=
inspectionWorkOrder
.
getTemplateVersion
();
InspectionRecord
record
=
inspectionRecordRepository
.
findByTaskIdAndDeletedFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElseGet
(()
->
createRecord
(
taskId
,
locationModule
,
templateId
,
templateVersion
,
delegate
.
getPlatType
(),
delegate
.
getOperatorId
(),
delegate
.
getOperatorName
()));
Long
recordId
=
record
.
getId
();
// 2. 获取所有节点配置,构建映射(只查询一次,所有模块共用)
List
<
InspectionNodeVO
>
allNodes
=
inspectionNodeService
.
inspectionNodesByTaskId
(
taskId
);
List
<
InspectionNodeVO
>
allNodes
=
inspectionNodeService
.
inspectionNodesByTaskId
(
taskId
);
Map
<
Long
,
InspectionNodeVO
>
nodeConfigMap
=
allNodes
.
stream
()
.
collect
(
Collectors
.
toMap
(
InspectionNodeVO:
:
getId
,
Function
.
identity
(),
(
pre
,
next
)
->
pre
));
Map
<
Long
,
List
<
InspectionNodeVO
>>
parentChildMap
=
allNodes
.
stream
()
.
filter
(
n
->
n
.
getParentId
()
!=
null
)
.
collect
(
Collectors
.
groupingBy
(
InspectionNodeVO:
:
getParentId
));
// 收集本次操作涉及的所有叶子节点 ID(用于操作日志对比)
Set
<
Long
>
operationNodeIds
=
new
HashSet
<>();
operationNodeIds
.
add
(
req
.
getLocationModule
());
operationNodeIds
.
addAll
(
req
.
getModules
().
stream
().
flatMap
(
single
->
{
Long
locationSubModule
=
single
.
getLocationSubModule
();
Stream
<
Long
>
leafStream
=
Optional
.
ofNullable
(
parentChildMap
.
get
(
ObjectUtil
.
isNull
(
locationSubModule
)
?
req
.
getLocationModule
()
:
locationSubModule
))
.
orElseGet
(
ArrayList:
:
new
)
.
stream
().
map
(
InspectionNodeVO:
:
getId
);
return
Stream
.
concat
(
Stream
.
of
(
locationSubModule
).
filter
(
Objects:
:
nonNull
),
leafStream
);
}).
collect
(
Collectors
.
toSet
()));
delegate
.
operationNodeIds
(
operationNodeIds
);
// ★ 保存前钩子(用于快照旧数据等)
delegate
.
beforeSave
(
recordId
,
allNodes
);
// 3. 遍历所有模块,每个模块独立执行过滤、校验(纯内存操作),收集待持久化数据
List
<
ModulePersistData
>
modulePersistDataList
=
new
ArrayList
<>();
for
(
InspectionBatchSaveVO
.
ModuleSaveItem
moduleItem
:
CollUtil
.
emptyIfNull
(
req
.
getModules
()))
{
Long
locationSubModule
=
moduleItem
.
getLocationSubModule
();
Long
targetLocationId
=
locationSubModule
!=
null
?
locationSubModule
:
locationModule
;
// 3a. 过滤叶子节点:只保留有实际数据或无此结构的
List
<
InspectionLeafNodeVO
>
leafNodes
=
CollUtil
.
emptyIfNull
(
moduleItem
.
getLeafNodes
()).
stream
()
.
filter
(
leafNode
->
(
CollUtil
.
isNotEmpty
(
leafNode
.
getData
())
&&
leafNode
.
getData
().
stream
().
anyMatch
(
v
->
StrUtil
.
isNotBlank
(
v
.
getValueText
())))
||
(
leafNode
.
getResultStatus
()
==
InspectConstants
.
RESULT_STATUS_NO_STRUCTURE
)
)
.
toList
();
// 3b. 校验叶子节点配置合法性(必须存在且为叶子节点)
for
(
InspectionLeafNodeVO
leafNode
:
leafNodes
)
{
Long
nodeId
=
leafNode
.
getNodeId
();
InspectionNodeVO
config
=
nodeConfigMap
.
get
(
nodeId
);
if
(
config
==
null
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
NODE_NOT_EXISTS
,
nodeId
,
leafNode
.
getNodeName
());
}
if
(!
Objects
.
equals
(
config
.
getNodeType
(),
InspectConstants
.
NODE_TYPE_LEAF
))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
NODE_NOT_LEAF
,
nodeId
,
config
.
getNodeName
());
}
}
// 3c. 收集当前模块下所有叶子节点配置(用于必填校验和补齐逻辑)
List
<
InspectionNodeVO
>
locationLeafNodes
=
new
ArrayList
<>();
if
(
targetLocationId
!=
null
)
{
collectLeafNodesUnder
(
targetLocationId
,
parentChildMap
,
locationLeafNodes
);
}
// 3d. 下一步 / 保存 处理
boolean
moduleNextFlag
=
nextFlag
;
if
(
moduleNextFlag
)
{
leafNodes
=
fillDefaultForFaultNodes
(
leafNodes
,
locationLeafNodes
);
validateAndCheckComplete
(
leafNodes
,
locationLeafNodes
,
nodeConfigMap
);
}
else
{
if
(
isAllRequiredFilled
(
leafNodes
,
locationLeafNodes
))
{
moduleNextFlag
=
true
;
leafNodes
=
fillDefaultForFaultNodes
(
leafNodes
,
locationLeafNodes
);
validateAndCheckComplete
(
leafNodes
,
locationLeafNodes
,
nodeConfigMap
);
}
else
{
if
(
CollUtil
.
isNotEmpty
(
leafNodes
))
{
nodeValidationManager
.
validateAll
(
leafNodes
,
nodeConfigMap
);
}
}
}
// 3e. 收集当前模块数据(不做 DB IO,统一批量处理)
String
completedFlag
=
moduleNextFlag
?
CommonConsts
.
ONE
:
CommonConsts
.
ZERO
;
modulePersistDataList
.
add
(
new
ModulePersistData
(
locationSubModule
,
leafNodes
,
locationLeafNodes
,
completedFlag
));
}
// 4. 统一批量持久化所有模块数据(一次全量批处理,替代原来的 N 次 persistResults)
List
<
InspectionResultDTO
>
savedResults
=
persistResultsBatch
(
recordId
,
locationModule
,
modulePersistDataList
,
nodeConfigMap
,
parentChildMap
);
// 5. 更新检测记录的位置信息(记录本次操作的一级模块)
record
.
setLocationModule
(
locationModule
);
inspectionRecordRepository
.
save
(
record
);
// ★ 保存后钩子(用于写操作日志等)暂时不记录补全的变更
delegate
.
afterSave
(
recordId
,
taskId
,
locationModule
,
allNodes
,
savedResults
);
log
.
info
(
"批量保存检测数据成功,recordId: {}"
,
recordId
);
return
recordId
;
}
finally
{
if
(
isLockSuccess
)
{
redisCacheUtil
.
deleteCacheIfMatch
(
lockKey
,
lockValue
);
}
}
}
/**
* 深度检查节点完成状态,返回第一个未完成的根节点信息
* (供 H5 端 {@code InspectorSaveDelegate.checkAndComplete} 调用)
*
* @param recordId 检测记录 ID
* @param allNodes 所有节点配置
* @return 未完成的根节点信息,全部完成返回 null
*/
public
CompleteInspectionRespVO
findFirstUncompletedNodeForComplete
(
Long
recordId
,
List
<
InspectionNodeVO
>
allNodes
)
{
List
<
InspectionNodeVO
>
rootNodes
=
allNodes
.
stream
()
List
<
InspectionNodeVO
>
rootNodes
=
allNodes
.
stream
()
.
filter
(
n
->
n
.
getNodeType
()
!=
null
&&
n
.
getNodeType
()
==
1
)
.
filter
(
n
->
n
.
getNodeType
()
!=
null
&&
n
.
getNodeType
()
==
InspectConstants
.
NODE_TYPE_MODULE
)
.
sorted
(
Comparator
.
comparingInt
(
n
->
Optional
.
ofNullable
(
n
.
getSortOrder
()).
orElse
(
0
)))
.
sorted
(
Comparator
.
comparingInt
(
n
->
Optional
.
ofNullable
(
n
.
getSortOrder
()).
orElse
(
0
)))
.
toList
();
.
toList
();
if
(
CollUtil
.
isEmpty
(
rootNodes
))
{
if
(
CollUtil
.
isEmpty
(
rootNodes
))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXISTS
,
"检测模板节点配置"
);
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXISTS
,
"检测模板节点配置"
);
}
}
// 查询根节点的检测结果
Map
<
Long
,
List
<
InspectionNodeVO
>>
parentChildMap
=
buildParentChildMap
(
allNodes
);
List
<
Long
>
allNodeIds
=
allNodes
.
stream
().
map
(
InspectionNodeVO:
:
getId
).
toList
();
Map
<
Long
,
InspectionResult
>
resultMap
=
CollUtil
.
isEmpty
(
allNodeIds
)
?
Map
.
of
()
:
inspectionResultRepository
.
findByRecordIdAndNodeIdIn
(
recordId
,
allNodeIds
)
.
stream
().
collect
(
Collectors
.
toMap
(
InspectionResult:
:
getNodeId
,
r
->
r
,
(
a
,
b
)
->
a
));
return
findFirstUncompletedNode
(
rootNodes
,
parentChildMap
,
resultMap
);
}
/**
* 保存评分并检查完成状态(统一入口,H5 和 PC 共用)
* <p>
* 核心流程:
* <ol>
* <li>分布式锁</li>
* <li>查询工单 + 校验权限</li>
* <li>{@link #saveOrUpdateRecord} 保存评分字段</li>
* <li>{@link InspectionSaveDelegate#checkAndComplete} 执行各端差异化的完成检查</li>
* </ol>
*
* @param req 评分/完成 VO
* @param delegate 策略委托
* @return 未完成的根节点信息;全部完成返回空 VO(rootNodeId 为 null)
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
CompleteInspectionRespVO
saveScoreWithDelegate
(
CompleteInspectionVO
req
,
InspectionSaveDelegate
delegate
)
{
Long
taskId
=
req
.
getTaskId
();
log
.
info
(
"保存评分,taskId: {}, 操作人: {}"
,
taskId
,
delegate
.
getOperatorName
());
String
lockKey
=
StringUtils
.
templateFormat
(
InspectConstants
.
INSPECTION_LOCK_KEY
,
taskId
);
String
lockValue
=
UUID
.
randomUUID
().
toString
();
boolean
isLockSuccess
=
false
;
try
{
isLockSuccess
=
redisCacheUtil
.
setCacheIfAbsent
(
lockKey
,
lockValue
,
30
,
TimeUnit
.
SECONDS
);
if
(!
isLockSuccess
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
BUSINESS_BUSY
);
}
InspectionWorkOrder
workOrder
=
inspectionWorkOrderRepository
.
findByIdAndDeleteFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXISTS
,
taskId
,
"检测工单"
));
delegate
.
validatePermission
(
workOrder
);
InspectionTemplateDTO
templateDTO
=
inspectionTemplateService
.
getTemplateByIdAndVersion
(
workOrder
.
getTemplateId
(),
workOrder
.
getTemplateVersion
());
// 0. 评分保存前钩子(PC端:快照旧评分数据)
delegate
.
beforeScoreSave
(
taskId
);
// 1. 保存或更新检测记录(含评分字段)
InspectionRecord
record
=
saveOrUpdateRecord
(
req
,
templateDTO
,
taskId
,
delegate
.
getPlatType
(),
delegate
.
getOperatorId
(),
delegate
.
getOperatorName
());
// 2. 评分保存后钩子(PC端:记录评分修改日志)
delegate
.
afterScoreSave
(
record
,
taskId
,
workOrder
);
// 3. 获取节点树
List
<
InspectionNodeVO
>
allNodes
=
inspectionNodeService
.
inspectionNodesByTaskId
(
taskId
);
// 4. delegate 执行各端差异化的完成检查与处理
CompleteInspectionRespVO
uncompletedResp
=
delegate
.
checkAndComplete
(
record
,
workOrder
,
allNodes
);
if
(
uncompletedResp
!=
null
)
{
return
uncompletedResp
;
}
log
.
info
(
"保存评分成功,recordId: {}"
,
record
.
getId
());
return
CompleteInspectionRespVO
.
builder
().
build
();
}
finally
{
if
(
isLockSuccess
)
{
redisCacheUtil
.
deleteCacheIfMatch
(
lockKey
,
lockValue
);
}
}
}
/**
* PC端保存后自动检查完成状态:
* <ul>
* <li>工单状态允许流转(待检测或检测中)</li>
* <li>所有一级节点 completedFlag 为 "1"</li>
* <li>评分字段都已填写</li>
* </ul>
* 三个条件同时满足则自动完成工单并发送企微通知。
*
* @param taskId 检测工单 ID
* @param recordId 检测记录 ID
* @param workOrder 检测工单(已从 DB 加载)
* @param allNodes 所有节点配置
* @return true=已自动完成,false=条件不满足
*/
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
boolean
tryAutoComplete
(
Long
taskId
,
Long
recordId
,
InspectionWorkOrder
workOrder
,
InspectionPlatTypeEnum
platTypeEnum
,
List
<
InspectionNodeVO
>
allNodes
,
Long
operatorId
,
String
operatorName
)
{
// 1. 检查工单状态
if
(!
InspectionWorkOrderStatusEnum
.
beableInspection
(
workOrder
.
getStatus
()))
{
log
.
info
(
"PC端自动完成检查:工单状态不允许流转,status={}, taskId={}"
,
workOrder
.
getStatus
(),
taskId
);
return
false
;
}
// 2. 检查评分是否已填
InspectionRecord
record
=
inspectionRecordRepository
.
findById
(
recordId
).
orElse
(
null
);
if
(
record
==
null
||
!
isScoreComplete
(
record
))
{
log
.
info
(
"PC端自动完成检查:评分未填写完整,recordId={}"
,
recordId
);
return
false
;
}
// 3. 检查所有一级节点是否完成
List
<
InspectionNodeVO
>
rootNodes
=
allNodes
.
stream
()
.
filter
(
n
->
n
.
getNodeType
()
!=
null
&&
n
.
getNodeType
()
==
InspectConstants
.
NODE_TYPE_MODULE
)
.
toList
();
if
(
CollUtil
.
isEmpty
(
rootNodes
))
{
log
.
info
(
"PC端自动完成检查:无一级节点,recordId={}"
,
recordId
);
return
false
;
}
List
<
Long
>
rootNodeIds
=
rootNodes
.
stream
().
map
(
InspectionNodeVO:
:
getId
).
toList
();
List
<
Long
>
rootNodeIds
=
rootNodes
.
stream
().
map
(
InspectionNodeVO:
:
getId
).
toList
();
List
<
InspectionResult
>
rootResults
=
inspectionResultRepository
.
findByRecordIdAndNodeIdIn
(
record
.
getId
()
,
rootNodeIds
);
List
<
InspectionResult
>
rootResults
=
inspectionResultRepository
.
findByRecordIdAndNodeIdIn
(
recordId
,
rootNodeIds
);
Map
<
Long
,
InspectionResult
>
r
esultMap
=
rootResults
.
stream
()
Map
<
Long
,
InspectionResult
>
rootR
esultMap
=
rootResults
.
stream
()
.
collect
(
Collectors
.
toMap
(
InspectionResult:
:
getNodeId
,
r
->
r
,
(
a
,
b
)
->
a
));
.
collect
(
Collectors
.
toMap
(
InspectionResult:
:
getNodeId
,
r
->
r
,
(
a
,
b
)
->
a
));
// 查找第一个未完成的根节点
Long
firstUncompletedNodeId
=
null
;
String
firstUncompletedNodeName
=
null
;
for
(
InspectionNodeVO
rootNode
:
rootNodes
)
{
for
(
InspectionNodeVO
rootNode
:
rootNodes
)
{
InspectionResult
result
=
resultMap
.
get
(
rootNode
.
getId
());
InspectionResult
rootResult
=
rootResultMap
.
get
(
rootNode
.
getId
());
if
(
rootResult
==
null
||
!
CommonConsts
.
ONE
.
equals
(
rootResult
.
getCompletedFlag
()))
{
log
.
info
(
"PC端自动完成检查:存在未完成的一级节点,nodeId={}, nodeName={}"
,
rootNode
.
getId
(),
rootNode
.
getNodeName
());
return
false
;
}
}
// 4. 条件全部满足,自动完成
LocalDateTime
completeTime
=
LocalDateTime
.
now
();
record
.
setCompleteTime
(
completeTime
);
inspectionRecordRepository
.
save
(
record
);
inspectionWorkOrderService
.
completeInspection
(
taskId
,
platTypeEnum
,
operatorId
,
operatorName
);
sendCompleteNotice
(
record
,
allNodes
,
taskId
,
completeTime
);
log
.
info
(
"PC端保存后自动完成检测,taskId={}, recordId={}"
,
taskId
,
recordId
);
return
true
;
}
/**
* 检查评分字段是否都已填写
*/
private
boolean
isScoreComplete
(
InspectionRecord
record
)
{
return
record
.
getExteriorScore
()
!=
null
&&
StrUtil
.
isNotBlank
(
record
.
getExteriorComment
())
&&
StrUtil
.
isNotBlank
(
record
.
getSkeletonLevel
())
&&
StrUtil
.
isNotBlank
(
record
.
getSkeletonComment
())
&&
StrUtil
.
isNotBlank
(
record
.
getInteriorLevel
())
&&
StrUtil
.
isNotBlank
(
record
.
getInteriorComment
())
&&
record
.
getOverallScore
()
!=
null
&&
StrUtil
.
isNotBlank
(
record
.
getOverallComment
());
}
/**
* 保存或更新检测记录
* 记录存在则更新评分评级;不存在则新建并启动检测工单
*
* @param req 请求参数
* @param templateDTO 模板DTO
* @param taskId 任务ID
* @param platTypeEnum 平台类型
* @param operatorId 操作人ID
* @param operatorName 操作人名称
*/
private
InspectionRecord
saveOrUpdateRecord
(
CompleteInspectionVO
req
,
InspectionTemplateDTO
templateDTO
,
Long
taskId
,
InspectionPlatTypeEnum
platTypeEnum
,
Long
operatorId
,
String
operatorName
)
{
return
inspectionRecordRepository
.
findByTaskIdAndDeletedFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
map
(
existing
->
{
existing
.
setExteriorScore
(
req
.
getExteriorScore
());
existing
.
setExteriorComment
(
req
.
getExteriorComment
());
existing
.
setSkeletonLevel
(
req
.
getSkeletonLevel
());
existing
.
setSkeletonComment
(
req
.
getSkeletonComment
());
existing
.
setInteriorLevel
(
req
.
getInteriorLevel
());
existing
.
setInteriorComment
(
req
.
getInteriorComment
());
existing
.
setOverallScore
(
req
.
getOverallScore
());
existing
.
setOverallComment
(
req
.
getOverallComment
());
return
inspectionRecordRepository
.
save
(
existing
);
})
.
orElseGet
(()
->
{
InspectionRecord
record
=
inspectorConverter
.
completeInspectionVo2InspectionRecord
(
req
);
record
.
setStartTime
(
LocalDateTime
.
now
());
record
.
setTemplateId
(
templateDTO
.
getId
());
record
.
setTemplateVersion
(
templateDTO
.
getVersion
());
record
.
setTemplateCode
(
templateDTO
.
getTemplateCode
());
InspectionRecord
saved
=
inspectionRecordRepository
.
save
(
record
);
inspectionWorkOrderService
.
startInspection
(
taskId
,
platTypeEnum
,
operatorId
,
operatorName
);
return
saved
;
});
}
/**
* 构建 parentId -> 子节点列表 映射,子节点列表按 sortOrder 升序排列
*/
private
Map
<
Long
,
List
<
InspectionNodeVO
>>
buildParentChildMap
(
List
<
InspectionNodeVO
>
allNodes
)
{
Map
<
Long
,
List
<
InspectionNodeVO
>>
map
=
allNodes
.
stream
()
.
filter
(
n
->
n
.
getParentId
()
!=
null
)
.
collect
(
Collectors
.
groupingBy
(
InspectionNodeVO:
:
getParentId
));
map
.
values
().
forEach
(
list
->
list
.
sort
(
Comparator
.
comparingInt
(
n
->
Optional
.
ofNullable
(
n
.
getSortOrder
()).
orElse
(
0
))));
return
map
;
}
/**
* 按层级下钻,找第一个未完成节点(以 nodeType 判断层级)
* <ul>
* <li>一级(nodeType=1)→ 子节点是三级(nodeType=3)→ lv2=null,直接找未完成的三级</li>
* <li>一级(nodeType=1)→ 子节点是二级(nodeType=2)→ 再找其下未完成的三级</li>
* </ul>
*
* @return 有未完成节点时返回 VO,全部完成返回 null
*/
private
CompleteInspectionRespVO
findFirstUncompletedNode
(
List
<
InspectionNodeVO
>
rootNodes
,
Map
<
Long
,
List
<
InspectionNodeVO
>>
parentChildMap
,
Map
<
Long
,
InspectionResult
>
resultMap
)
{
for
(
InspectionNodeVO
rootNode
:
rootNodes
)
{
InspectionResult
rootResult
=
resultMap
.
get
(
rootNode
.
getId
());
if
(
rootResult
!=
null
&&
CommonConsts
.
ONE
.
equals
(
rootResult
.
getCompletedFlag
()))
{
continue
;
// 一级已完成,跳过
}
log
.
info
(
"存在未完成的一级节点,nodeId: {}, nodeName: {}"
,
rootNode
.
getId
(),
rootNode
.
getNodeName
());
List
<
InspectionNodeVO
>
children
=
parentChildMap
.
getOrDefault
(
rootNode
.
getId
(),
List
.
of
());
if
(
CollUtil
.
isEmpty
(
children
))
{
// 无子节点
return
buildUncompletedResp
(
rootNode
,
null
,
null
);
}
int
childNodeType
=
Optional
.
ofNullable
(
children
.
get
(
0
).
getNodeType
()).
orElse
(
InspectConstants
.
NODE_TYPE_LEAF
);
if
(
childNodeType
==
InspectConstants
.
NODE_TYPE_LEAF
)
{
// 一级直挂三级(无二级)
InspectionNodeVO
lv3
=
findFirstUncompleted
(
children
,
resultMap
);
return
buildUncompletedResp
(
rootNode
,
null
,
lv3
);
}
else
{
// 标准三层:一级 → 二级 → 三级
for
(
InspectionNodeVO
secondNode
:
children
)
{
InspectionResult
secondResult
=
resultMap
.
get
(
secondNode
.
getId
());
if
(
secondResult
!=
null
&&
CommonConsts
.
ONE
.
equals
(
secondResult
.
getCompletedFlag
()))
{
continue
;
// 二级已完成,跳过
}
log
.
info
(
"存在未完成的二级节点,nodeId: {}, nodeName: {}"
,
secondNode
.
getId
(),
secondNode
.
getNodeName
());
List
<
InspectionNodeVO
>
thirdNodes
=
parentChildMap
.
getOrDefault
(
secondNode
.
getId
(),
List
.
of
());
InspectionNodeVO
lv3
=
findFirstUncompleted
(
thirdNodes
,
resultMap
);
return
buildUncompletedResp
(
rootNode
,
secondNode
,
lv3
);
}
}
}
return
null
;
}
/**
* 从节点列表中找第一个未完成的节点(result 为 null 或 completedFlag != '1')
*/
private
InspectionNodeVO
findFirstUncompleted
(
List
<
InspectionNodeVO
>
nodes
,
Map
<
Long
,
InspectionResult
>
resultMap
)
{
for
(
InspectionNodeVO
node
:
nodes
)
{
InspectionResult
result
=
resultMap
.
get
(
node
.
getId
());
if
(
result
==
null
||
!
CommonConsts
.
ONE
.
equals
(
result
.
getCompletedFlag
()))
{
if
(
result
==
null
||
!
CommonConsts
.
ONE
.
equals
(
result
.
getCompletedFlag
()))
{
firstUncompletedNodeId
=
rootNode
.
getId
();
log
.
info
(
"存在未完成的节点,nodeId: {}, nodeName: {}"
,
node
.
getId
(),
node
.
getNodeName
());
firstUncompletedNodeName
=
rootNode
.
getNodeName
();
return
node
;
log
.
info
(
"存在未完成的根节点,nodeId: {}, nodeName: {}"
,
rootNode
.
getId
(),
firstUncompletedNodeName
);
break
;
}
}
}
}
return
null
;
}
// 如果存在未完成的根节点,直接返回
/**
if
(
firstUncompletedNodeId
!=
null
)
{
* 构建未完成节点响应 VO,lv2/lv3 为 null 时对应字段也为 null
*/
private
CompleteInspectionRespVO
buildUncompletedResp
(
InspectionNodeVO
lv1
,
InspectionNodeVO
lv2
,
InspectionNodeVO
lv3
)
{
return
CompleteInspectionRespVO
.
builder
()
return
CompleteInspectionRespVO
.
builder
()
.
firstUncompletedNodeId
(
firstUncompletedNodeId
)
.
firstUncompletedLv1NodeId
(
lv1
!=
null
?
lv1
.
getId
()
:
null
)
.
firstUncompletedNodeName
(
firstUncompletedNodeName
)
.
firstUncompletedLv1NodeName
(
lv1
!=
null
?
lv1
.
getNodeName
()
:
null
)
.
firstUncompletedLv2NodeId
(
lv2
!=
null
?
lv2
.
getId
()
:
null
)
.
firstUncompletedLv2NodeName
(
lv2
!=
null
?
lv2
.
getNodeName
()
:
null
)
.
firstUncompletedLv3NodeId
(
lv3
!=
null
?
lv3
.
getId
()
:
null
)
.
firstUncompletedLv3NodeName
(
lv3
!=
null
?
lv3
.
getNodeName
()
:
null
)
.
build
();
.
build
();
}
}
// 3. 所有根节点都已完成,更新评分、进度、完成时间
/**
LocalDateTime
completeTime
=
LocalDateTime
.
now
();
* 保存检测记录(供 delegate 显式持久化用)
record
.
setCompleteTime
(
completeTime
);
*
* @param record 检测记录实体
*/
public
void
saveRecord
(
InspectionRecord
record
)
{
inspectionRecordRepository
.
save
(
record
);
inspectionRecordRepository
.
save
(
record
);
}
/**
* 根据任务 ID 查询检测记录 ID
*
* @param taskId 检测工单 ID
* @return 检测记录 ID,不存在返回 null
*/
public
Long
findRecordIdByTaskId
(
Long
taskId
)
{
return
inspectionRecordRepository
.
findByTaskIdAndDeletedFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
map
(
InspectionRecord:
:
getId
)
.
orElse
(
null
);
}
// 4. 发送通知消息、查询检测结果
/**
Optional
<
InspectionWorkOrder
>
inspectionWorkOrderOptional
=
inspectionWorkOrderRepository
.
findByIdAndDeleteFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
());
* 根据任务 ID 查询检测记录
List
<
InspectionResult
>
results
=
inspectionResultRepository
.
findByRecordIdWithValues
(
record
.
getId
(),
DeleteFlag
.
NOT_DELETED
.
getCode
());
*
* @param taskId 检测工单 ID
* @return 检测记录,不存在返回 null
*/
public
InspectionRecord
findRecordByTaskId
(
Long
taskId
)
{
return
inspectionRecordRepository
.
findByTaskIdAndDeletedFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElse
(
null
);
}
/**
* 发送检测完成通知消息
*/
public
void
sendCompleteNotice
(
@NonNull
InspectionRecord
record
,
List
<
InspectionNodeVO
>
allNodes
,
Long
taskId
,
LocalDateTime
completeTime
)
{
Optional
<
InspectionWorkOrder
>
workOrderOpt
=
inspectionWorkOrderRepository
.
findByIdAndDeleteFlag
(
taskId
,
DeleteFlag
.
NOT_DELETED
.
getCode
());
List
<
InspectionResult
>
results
=
inspectionResultRepository
.
findByRecordIdWithValues
(
record
.
getId
(),
DeleteFlag
.
NOT_DELETED
.
getCode
());
Map
<
Long
,
InspectionResult
>
resultAllMap
=
results
.
stream
()
Map
<
Long
,
InspectionResult
>
resultAllMap
=
results
.
stream
()
.
collect
(
Collectors
.
toMap
(
InspectionResult:
:
getNodeId
,
r
->
r
,
(
a
,
b
)
->
a
));
.
collect
(
Collectors
.
toMap
(
InspectionResult:
:
getNodeId
,
r
->
r
,
(
a
,
b
)
->
a
));
Map
<
String
,
String
>
inspectorValue
=
extractBaseInfoFromResults
(
record
,
allNodes
,
resultAllMap
);
Map
<
String
,
String
>
inspectorValue
=
extractBaseInfoFromResults
(
record
,
allNodes
,
resultAllMap
);
...
@@ -520,16 +1290,13 @@ public class InspectionRecordService {
...
@@ -520,16 +1290,13 @@ public class InspectionRecordService {
.
map
(
value
->
Stream
.
of
(
.
map
(
value
->
Stream
.
of
(
value
.
get
(
InspectionBaseInfoFieldEnum
.
LICENSE_PLATE
.
getCode
()),
value
.
get
(
InspectionBaseInfoFieldEnum
.
LICENSE_PLATE
.
getCode
()),
value
.
get
(
InspectionBaseInfoFieldEnum
.
CAR_SERIES_NAME
.
getCode
()),
value
.
get
(
InspectionBaseInfoFieldEnum
.
CAR_SERIES_NAME
.
getCode
()),
value
.
get
(
InspectionBaseInfoFieldEnum
.
CAR_TYPE_NAME
.
getCode
())
value
.
get
(
InspectionBaseInfoFieldEnum
.
CAR_TYPE_NAME
.
getCode
()))
)
.
filter
(
StrUtil:
:
isNotBlank
)
.
filter
(
StrUtil:
:
isNotBlank
)
.
collect
(
Collectors
.
joining
(
SymbolConsts
.
BLANK
)))
.
collect
(
Collectors
.
joining
(
SymbolConsts
.
BLANK
)))
.
filter
(
StrUtil:
:
isNotBlank
)
.
filter
(
StrUtil:
:
isNotBlank
)
.
or
(()
->
{
.
or
(()
->
{
log
.
info
(
"未查询到检测项中的车辆信息,使用车辆基本信息!"
);
log
.
info
(
"未查询到检测项中的车辆信息,使用车辆基本信息!"
);
return
inspectionWorkOrderOptional
return
workOrderOpt
.
map
(
InspectionWorkOrder:
:
getVehicle
).
map
(
Vehicle:
:
toVehicleName
);
.
map
(
InspectionWorkOrder:
:
getVehicle
)
.
map
(
Vehicle:
:
toVehicleName
);
}).
orElse
(
StrUtil
.
EMPTY
);
}).
orElse
(
StrUtil
.
EMPTY
);
webHookHandler
.
sendNoticeMessage
(
webHookHandler
.
sendNoticeMessage
(
...
@@ -541,7 +1308,7 @@ public class InspectionRecordService {
...
@@ -541,7 +1308,7 @@ public class InspectionRecordService {
NoticeField
.
EXTERNAL_SCORE
,
record
.
getExteriorScore
(),
NoticeField
.
EXTERNAL_SCORE
,
record
.
getExteriorScore
(),
NoticeField
.
FRAME_RATING
,
record
.
getSkeletonLevel
(),
NoticeField
.
FRAME_RATING
,
record
.
getSkeletonLevel
(),
NoticeField
.
INTERIOR_RATING
,
record
.
getInteriorLevel
(),
NoticeField
.
INTERIOR_RATING
,
record
.
getInteriorLevel
(),
NoticeField
.
DETECT_NAME
,
inspectionWorkOrderOptional
NoticeField
.
DETECT_NAME
,
workOrderOpt
.
map
(
InspectionWorkOrder:
:
getInspector
)
.
map
(
InspectionWorkOrder:
:
getInspector
)
.
map
(
Inspector:
:
getName
)
.
map
(
Inspector:
:
getName
)
.
orElse
(
StrUtil
.
EMPTY
),
.
orElse
(
StrUtil
.
EMPTY
),
...
@@ -549,18 +1316,6 @@ public class InspectionRecordService {
...
@@ -549,18 +1316,6 @@ public class InspectionRecordService {
NoticeField
.
CLICK_HANDLER
,
Optional
.
ofNullable
(
inspectorConfig
.
getInspectionAuditUrl
())
NoticeField
.
CLICK_HANDLER
,
Optional
.
ofNullable
(
inspectorConfig
.
getInspectionAuditUrl
())
.
filter
(
StrUtil:
:
isNotBlank
).
orElse
(
StrUtil
.
EMPTY
)
.
filter
(
StrUtil:
:
isNotBlank
).
orElse
(
StrUtil
.
EMPTY
)
));
));
inspectionWorkOrderService
.
completeInspection
(
taskId
);
log
.
info
(
"检测师完成检测成功,recordId: {}"
,
record
.
getId
());
return
CompleteInspectionRespVO
.
builder
()
.
firstUncompletedNodeId
(
null
)
.
build
();
}
finally
{
if
(
isLockSuccess
)
{
redisCacheUtil
.
deleteCacheIfMatch
(
lockKey
,
lockValue
);
}
}
}
}
/**
/**
...
@@ -654,7 +1409,7 @@ public class InspectionRecordService {
...
@@ -654,7 +1409,7 @@ public class InspectionRecordService {
for
(
InspectionNodeVO
node
:
locationLeafNodes
)
{
for
(
InspectionNodeVO
node
:
locationLeafNodes
)
{
if
(
Objects
.
equals
(
node
.
getRequired
(),
1
)
&&
!
filledNodeIds
.
contains
(
node
.
getId
()))
{
if
(
Objects
.
equals
(
node
.
getRequired
(),
1
)
&&
!
filledNodeIds
.
contains
(
node
.
getId
()))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
PARAM_ERROR
,
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
PARAM_ERROR
,
"【"
+
node
.
getNodeName
()
+
"】"
,
"为必填项,请填写后再进行
下一步
"
);
"【"
+
node
.
getNodeName
()
+
"】"
,
"为必填项,请填写后再进行
操作
"
);
}
}
}
}
}
}
...
...
aus-core/src/main/java/com/glsx/usedcar/module/inspect/service/InspectionTemplateService.java
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
service
;
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
service
;
import
cn.hutool.core.lang.func.LambdaUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.glsx.usedcar.consts.common.SymbolConsts
;
import
com.glsx.usedcar.consts.inspect.InspectConstants
;
import
com.glsx.usedcar.consts.inspect.JpaQueryConstants
;
import
com.glsx.usedcar.converts.InspectionTemplateConverter
;
import
com.glsx.usedcar.converts.InspectionTemplateConverter
;
import
com.glsx.usedcar.converts.InspectorConverter
;
import
com.glsx.usedcar.enums.common.DeleteFlag
;
import
com.glsx.usedcar.enums.common.DeleteFlag
;
import
com.glsx.usedcar.module.inspect.dao.InspectionNodeRepository
;
import
com.glsx.usedcar.module.inspect.dao.InspectionTemplateHistoryRepository
;
import
com.glsx.usedcar.module.inspect.dao.InspectionTemplateHistoryRepository
;
import
com.glsx.usedcar.module.inspect.dao.InspectionTemplateRepository
;
import
com.glsx.usedcar.module.inspect.dao.InspectionTemplateRepository
;
import
com.glsx.usedcar.module.inspect.dao.InspectionWorkOrderRepository
;
import
com.glsx.usedcar.module.inspect.dao.InspectionWorkOrderRepository
;
import
com.glsx.usedcar.module.inspect.dao.TemplateTagRepository
;
import
com.glsx.usedcar.module.inspect.dto.InspectionTemplateDTO
;
import
com.glsx.usedcar.module.inspect.dto.InspectionTemplateDTO
;
import
com.glsx.usedcar.module.inspect.entity.InspectionNode
;
import
com.glsx.usedcar.module.inspect.entity.InspectionTemplate
;
import
com.glsx.usedcar.module.inspect.entity.InspectionTemplate_
;
import
com.glsx.usedcar.module.inspect.entity.InspectionWorkOrder
;
import
com.glsx.usedcar.module.inspect.entity.InspectionWorkOrder
;
import
com.glsx.usedcar.module.inspect.entity.TemplateTag
;
import
com.glsx.usedcar.factories.inspect.InspectionValueStrategyRouter
;
import
com.glsx.usedcar.factories.inspect.InspectionValueStrategyRouter
;
import
com.glsx.usedcar.module.inspect.service.strategy.TemplateValueStrategy
;
import
com.glsx.usedcar.module.inspect.service.strategy.TemplateValueStrategy
;
import
com.glsx.usedcar.module.inspect.vo.InspectionNodeVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionTemplateDefaultValueReqVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionTemplateDefaultValueReqVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionTemplateDetailRespVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionTemplateRespVO
;
import
com.glsx.usedcar.module.inspect.vo.TemplateTagVO
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageImpl
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
java.util.HashMap
;
import
org.summerframework.orm.paging.Pagination
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
/**
* 检测模版服务
* 检测模版服务
...
@@ -35,6 +54,9 @@ import java.util.Optional;
...
@@ -35,6 +54,9 @@ import java.util.Optional;
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
)
public
class
InspectionTemplateService
{
public
class
InspectionTemplateService
{
private
final
InspectorConverter
inspectorConverter
;
private
final
TemplateTagRepository
templateTagRepository
;
private
final
InspectionNodeRepository
inspectionNodeRepository
;
private
final
InspectionValueStrategyRouter
defaultValueStrategyRouter
;
private
final
InspectionValueStrategyRouter
defaultValueStrategyRouter
;
private
final
InspectionTemplateConverter
inspectionTemplateConverter
;
private
final
InspectionTemplateConverter
inspectionTemplateConverter
;
private
final
InspectionTemplateRepository
inspectionTemplateRepository
;
private
final
InspectionTemplateRepository
inspectionTemplateRepository
;
...
@@ -115,4 +137,112 @@ public class InspectionTemplateService {
...
@@ -115,4 +137,112 @@ public class InspectionTemplateService {
return
defaultValueMap
;
return
defaultValueMap
;
}
}
/**
* 分页查询检测模版列表(返回基本信息)
*
* @param pagination 分页参数,支持关键词模糊查询(模版名称、模版编码)
* @return 模版基本信息分页结果
*/
public
Page
<
InspectionTemplateRespVO
>
pageList
(
Pagination
<
InspectionTemplate
>
pagination
)
{
Object
keyword
=
pagination
.
getFilterValueOrElseNull
(
JpaQueryConstants
.
KEYWORD
);
if
(
keyword
instanceof
String
kw
&&
StrUtil
.
isNotBlank
(
kw
))
{
pagination
.
removeFilter
(
JpaQueryConstants
.
KEYWORD
);
String
like
=
SymbolConsts
.
PERCENT
+
kw
.
trim
()
+
SymbolConsts
.
PERCENT
;
pagination
.
addCondition
((
root
,
query
,
cb
)
->
cb
.
or
(
cb
.
like
(
root
.
get
(
InspectionTemplate_
.
templateName
),
like
),
cb
.
like
(
root
.
get
(
InspectionTemplate_
.
templateCode
),
like
)
));
}
pagination
.
addCondition
((
root
,
query
,
cb
)
->
cb
.
equal
(
root
.
get
(
InspectionTemplate_
.
deletedFlag
),
DeleteFlag
.
NOT_DELETED
.
getCode
()));
pagination
.
setSort
(
LambdaUtil
.
getFieldName
(
InspectionTemplate:
:
getTemplateCode
));
pagination
.
setOrder
(
"asc"
);
// 第1条 SQL:分页查模版
Page
<
InspectionTemplate
>
page
=
inspectionTemplateRepository
.
findAll
(
pagination
,
pagination
.
getPageRequest
());
List
<
InspectionTemplate
>
templates
=
page
.
getContent
();
if
(
templates
.
isEmpty
())
{
return
new
PageImpl
<>(
List
.
of
(),
page
.
getPageable
(),
page
.
getTotalElements
());
}
// 第2条 SQL:批量查所有模版的标签,避免 N+1
List
<
Long
>
templateIds
=
templates
.
stream
().
map
(
InspectionTemplate:
:
getId
).
collect
(
Collectors
.
toList
());
List
<
Object
[]>
tagRows
=
templateTagRepository
.
findTagsByTemplateIds
(
templateIds
);
// 内存分组:templateId -> List<TemplateTagVO>
Map
<
Long
,
List
<
TemplateTagVO
>>
tagMap
=
tagRows
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
row
->
(
Long
)
row
[
0
],
Collectors
.
mapping
(
row
->
{
TemplateTag
tag
=
(
TemplateTag
)
row
[
1
];
return
TemplateTagVO
.
builder
()
.
tagId
(
tag
.
getTagId
())
.
tagCode
(
tag
.
getTagCode
())
.
tagName
(
tag
.
getTagName
())
.
tagType
(
tag
.
getTagType
())
.
sortOrder
(
tag
.
getSortOrder
())
.
build
();
},
Collectors
.
toList
())
));
List
<
InspectionTemplateRespVO
>
content
=
templates
.
stream
()
.
map
(
t
->
InspectionTemplateRespVO
.
builder
()
.
id
(
t
.
getId
())
.
templateCode
(
t
.
getTemplateCode
())
.
templateName
(
t
.
getTemplateName
())
.
templateType
(
t
.
getTemplateType
())
.
status
(
t
.
getStatus
())
.
version
(
t
.
getVersion
())
.
description
(
t
.
getDescription
())
.
createTime
(
t
.
getCreateTime
())
.
updateTime
(
t
.
getUpdateTime
())
.
templateTags
(
tagMap
.
getOrDefault
(
t
.
getId
(),
List
.
of
()))
.
build
())
.
collect
(
Collectors
.
toList
());
return
new
PageImpl
<>(
content
,
page
.
getPageable
(),
page
.
getTotalElements
());
}
/**
* 查询检测模版详情(基本信息 + 节点配置树)
*
* @param id 模版ID
* @return 模版详情(含节点树,不填充检测数据)
*/
public
InspectionTemplateDetailRespVO
detail
(
Long
id
)
{
InspectionTemplate
template
=
inspectionTemplateRepository
.
findByIdAndDeletedFlag
(
id
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
String
.
format
(
"检测模版不存在,ID: %s"
,
id
)));
List
<
InspectionNode
>
nodes
=
inspectionNodeRepository
.
findByTemplateIdAndDeletedFlagOrderBySortOrderAsc
(
id
,
DeleteFlag
.
NOT_DELETED
.
getCode
());
List
<
InspectionNodeVO
>
allNodes
=
inspectorConverter
.
inspectionNodesMapRespVO
(
nodes
);
// 构建树形结构:先取根节点(parentId == 0),再递归挂载子节点
List
<
InspectionNodeVO
>
rootNodes
=
allNodes
.
stream
()
.
filter
(
node
->
ObjectUtil
.
isNotNull
(
node
.
getParentId
())
&&
node
.
getParentId
()
==
0L
)
.
peek
(
node
->
node
.
setChildrenNodes
(
InspectionNodeService
.
getChildNodes
(
node
.
getId
(),
allNodes
)))
.
sorted
(
Comparator
.
comparingInt
(
InspectionNodeVO:
:
getSortOrder
))
.
toList
();
return
InspectionTemplateDetailRespVO
.
builder
()
.
id
(
template
.
getId
())
.
templateCode
(
template
.
getTemplateCode
())
.
templateName
(
template
.
getTemplateName
())
.
templateType
(
template
.
getTemplateType
())
.
status
(
template
.
getStatus
())
.
version
(
template
.
getVersion
())
.
description
(
template
.
getDescription
())
.
configJson
(
template
.
getConfigJson
())
.
createTime
(
template
.
getCreateTime
())
.
updateTime
(
template
.
getUpdateTime
())
.
nodes
(
rootNodes
)
.
build
();
}
}
}
\ No newline at end of file
\ No newline at end of file
aus-core/src/main/java/com/glsx/usedcar/module/inspect/service/InspectionWorkOrderService.java
View file @
b2f6a2e
...
@@ -21,6 +21,8 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -21,6 +21,8 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.MessageSource
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageImpl
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -33,6 +35,7 @@ import java.time.LocalDateTime;
...
@@ -33,6 +35,7 @@ import java.time.LocalDateTime;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
/**
/**
* 检测工单服务(集成操作日志)
* 检测工单服务(集成操作日志)
...
@@ -60,6 +63,9 @@ public class InspectionWorkOrderService {
...
@@ -60,6 +63,9 @@ public class InspectionWorkOrderService {
private
final
InspectionTemplateRepository
inspectionTemplateRepository
;
private
final
InspectionTemplateRepository
inspectionTemplateRepository
;
private
final
InspectionRecordRepository
inspectionRecordRepository
;
private
final
InspectionRecordRepository
inspectionRecordRepository
;
private
final
InspectorConfig
inspectorConfig
;
private
final
InspectorConfig
inspectorConfig
;
private
final
InspectionOpLogRepository
inspectionOpLogRepository
;
private
final
InspectionOpLogItemRepository
inspectionOpLogItemRepository
;
private
final
InspectionOpLogConverter
inspectionOpLogConverter
;
/**
/**
* 保存检测工单操作日志
* 保存检测工单操作日志
...
@@ -442,10 +448,10 @@ public class InspectionWorkOrderService {
...
@@ -442,10 +448,10 @@ public class InspectionWorkOrderService {
InspectionReportRespVO
inspectionReportRespVO
=
inspectionReportConverter
.
inspectionReportMapRespVO
(
report
);
InspectionReportRespVO
inspectionReportRespVO
=
inspectionReportConverter
.
inspectionReportMapRespVO
(
report
);
InspectionWORespVO
inspectionWORespVO
=
inspectionWorkOrderConverter
.
inspectorMapRespVO
(
wo
);
InspectionWORespVO
inspectionWORespVO
=
inspectionWorkOrderConverter
.
inspectorMapRespVO
(
wo
);
List
<
InspectionWorkOrderOpLog
>
logList
=
inspectionWorkOrderOpLogRepository
.
findByWorkOrderInnerIdAndDeleteFlagOrderByIdDesc
(
wo
.
getId
(),
DeleteFlag
.
NOT_DELETED
.
getCode
());
List
<
InspectionWorkOrderOpLog
>
logList
=
inspectionWorkOrderOpLogRepository
.
findByWorkOrderInnerIdAndDeleteFlagOrderByIdDesc
(
wo
.
getId
(),
DeleteFlag
.
NOT_DELETED
.
getCode
());
List
<
InspectionWOOpLogRespVo
>
inspectionWOOpLogRespVos
=
inspectionWorkOrderOpLogConverter
.
inspectionWorkOrderOpLogMapRespVO
(
logList
);
//
List<InspectionWOOpLogRespVo> inspectionWOOpLogRespVos = inspectionWorkOrderOpLogConverter.inspectionWorkOrderOpLogMapRespVO(logList);
InspectionWODetailRespVO
result
=
new
InspectionWODetailRespVO
();
InspectionWODetailRespVO
result
=
new
InspectionWODetailRespVO
();
result
.
setInspectionWORespVO
(
inspectionWORespVO
);
result
.
setInspectionWORespVO
(
inspectionWORespVO
);
result
.
setLogList
(
inspectionWOOpLogRespVos
);
//
result.setLogList(inspectionWOOpLogRespVos);
if
(
wo
.
getStatus
().
equals
(
InspectionWorkOrderStatusEnum
.
COMPLETED
.
getCode
())
&&
wo
.
getAuditStatus
().
equals
(
InspectionWorkOrderAuditStatusEnum
.
WAIT_AUDIT
.
getCode
()))
{
if
(
wo
.
getStatus
().
equals
(
InspectionWorkOrderStatusEnum
.
COMPLETED
.
getCode
())
&&
wo
.
getAuditStatus
().
equals
(
InspectionWorkOrderAuditStatusEnum
.
WAIT_AUDIT
.
getCode
()))
{
inspectionReportRespVO
=
new
InspectionReportRespVO
();
inspectionReportRespVO
=
new
InspectionReportRespVO
();
// 拼接一个默认报告
// 拼接一个默认报告
...
@@ -600,9 +606,12 @@ public class InspectionWorkOrderService {
...
@@ -600,9 +606,12 @@ public class InspectionWorkOrderService {
* 开始检测(修改状态+记录开始时间+保存日志)
* 开始检测(修改状态+记录开始时间+保存日志)
*
*
* @param id 工单主键ID
* @param id 工单主键ID
* @param platTypeEnum 平台类型
* @param operatorId 操作人ID
* @param operatorName 操作人名称
*/
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
startInspection
(
Long
id
)
{
public
void
startInspection
(
Long
id
,
InspectionPlatTypeEnum
platTypeEnum
,
Long
operatorId
,
String
operatorName
)
{
// 1. 基础参数校验
// 1. 基础参数校验
if
(
id
==
null
)
{
if
(
id
==
null
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
PARAM_ERROR
,
"工单ID不能为空"
);
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
PARAM_ERROR
,
"工单ID不能为空"
);
...
@@ -618,10 +627,6 @@ public class InspectionWorkOrderService {
...
@@ -618,10 +627,6 @@ public class InspectionWorkOrderService {
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
PARAM_ERROR
,
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
PARAM_ERROR
,
String
.
format
(
"工单状态为[%s],仅已待检测状态可开始检测,工单ID:"
,
workOrder
.
getStatus
()),
id
);
String
.
format
(
"工单状态为[%s],仅已待检测状态可开始检测,工单ID:"
,
workOrder
.
getStatus
()),
id
);
}
}
Inspector
inspector
=
workOrder
.
getInspector
();
String
opName
=
inspector
.
getName
();
Long
opId
=
inspector
.
getId
();
InspectionPlatTypeEnum
platTypeEnum
=
InspectionPlatTypeEnum
.
INSPECTOR
;
// 3. 保存原始状态(用于日志)
// 3. 保存原始状态(用于日志)
Integer
originalStatus
=
workOrder
.
getStatus
();
Integer
originalStatus
=
workOrder
.
getStatus
();
...
@@ -630,48 +635,45 @@ public class InspectionWorkOrderService {
...
@@ -630,48 +635,45 @@ public class InspectionWorkOrderService {
// 4. 修改工单状态+开始检测时间
// 4. 修改工单状态+开始检测时间
LocalDateTime
now
=
LocalDateTime
.
now
();
LocalDateTime
now
=
LocalDateTime
.
now
();
workOrder
.
setStatus
(
targetStatus
);
workOrder
.
setStatus
(
targetStatus
);
// workOrder.setInspectionTime(now);
workOrder
.
setUpdateBy
(
operatorName
);
workOrder
.
setUpdateBy
(
opName
);
workOrder
.
setUpdateTime
(
now
);
workOrder
.
setUpdateTime
(
now
);
inspectionWorkOrderRepository
.
save
(
workOrder
);
inspectionWorkOrderRepository
.
save
(
workOrder
);
// 5. 保存操作日志
// 5. 保存操作日志
String
operationContent
=
"开始检测"
;
String
operationContent
=
"开始检测"
;
String
description
=
String
.
format
(
"开始检测 操作人[%s]启动工单检测,开始时间:%s"
,
opName
,
now
.
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)));
String
description
=
String
.
format
(
"开始检测 操作人[%s]启动工单检测,开始时间:%s"
,
op
erator
Name
,
now
.
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)));
saveWorkOrderOpLog
(
workOrder
,
saveWorkOrderOpLog
(
workOrder
,
InspectionWorkOrderOperationTypeEnum
.
START_INSPECTION
.
getCode
(),
InspectionWorkOrderOperationTypeEnum
.
START_INSPECTION
.
getCode
(),
originalStatus
,
originalStatus
,
targetStatus
,
targetStatus
,
operationContent
,
operationContent
,
description
,
description
,
Long
.
valueOf
(
opId
),
Long
.
valueOf
(
op
erator
Id
),
opName
,
op
erator
Name
,
platTypeEnum
.
getCode
());
platTypeEnum
.
getCode
());
log
.
info
(
"检测工单开始检测成功: ID={}, 唯一ID={}, 操作人={}"
,
workOrder
.
getId
(),
workOrder
.
getWoId
(),
opName
);
log
.
info
(
"检测工单开始检测成功: ID={}, 唯一ID={}, 操作人={}"
,
workOrder
.
getId
(),
workOrder
.
getWoId
(),
op
erator
Name
);
}
}
/**
/**
* 完成检测(修改状态+记录结束时间+保存日志)
* 完成检测(修改状态+记录结束时间+保存日志)
*
*
* @param id 工单主键ID
* @param id 工单主键ID
* @param platTypeEnum 平台类型
* @param operatorId 操作人ID
* @param operatorName 操作人名称
*/
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
completeInspection
(
Long
id
)
{
public
void
completeInspection
(
Long
id
,
InspectionPlatTypeEnum
platTypeEnum
,
Long
operatorId
,
String
operatorName
)
{
// 1. 基础参数校验
// 1. 基础参数校验
if
(
id
==
null
)
{
if
(
id
==
null
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
PARAM_ERROR
,
"工单ID不能为空"
);
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
PARAM_ERROR
,
"工单ID不能为空"
);
}
}
InspectionPlatTypeEnum
platTypeEnum
=
InspectionPlatTypeEnum
.
INSPECTOR
;
// 2. 查询工单并校验(未删除+状态合法)
// 2. 查询工单并校验(未删除+状态合法)
InspectionWorkOrder
workOrder
=
inspectionWorkOrderRepository
.
findByIdAndDeleteFlag
(
id
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
InspectionWorkOrder
workOrder
=
inspectionWorkOrderRepository
.
findByIdAndDeleteFlag
(
id
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXIST
,
"检测工单不存在,工单ID:"
+
id
));
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXIST
,
"检测工单不存在,工单ID:"
+
id
));
Inspector
inspector
=
workOrder
.
getInspector
();
String
opName
=
inspector
.
getName
();
Long
opId
=
inspector
.
getId
();
// 仅「检测中」状态可完成检测
// 仅「检测中」状态可完成检测
Integer
inProgressStatus
=
InspectionWorkOrderStatusEnum
.
IN_PROGRESS
.
getCode
();
Integer
inProgressStatus
=
InspectionWorkOrderStatusEnum
.
IN_PROGRESS
.
getCode
();
if
(!
Objects
.
equals
(
workOrder
.
getStatus
(),
inProgressStatus
))
{
if
(!
Objects
.
equals
(
workOrder
.
getStatus
(),
inProgressStatus
))
{
...
@@ -686,26 +688,25 @@ public class InspectionWorkOrderService {
...
@@ -686,26 +688,25 @@ public class InspectionWorkOrderService {
// 4. 修改工单状态+结束检测时间
// 4. 修改工单状态+结束检测时间
LocalDateTime
now
=
LocalDateTime
.
now
();
LocalDateTime
now
=
LocalDateTime
.
now
();
workOrder
.
setStatus
(
targetStatus
);
workOrder
.
setStatus
(
targetStatus
);
// workOrder.setInspectionCompletedTime(now);
workOrder
.
setAuditStatus
(
InspectionWorkOrderAuditStatusEnum
.
WAIT_AUDIT
.
getCode
());
workOrder
.
setAuditStatus
(
InspectionWorkOrderAuditStatusEnum
.
WAIT_AUDIT
.
getCode
());
workOrder
.
setUpdateBy
(
opName
);
workOrder
.
setUpdateBy
(
op
erator
Name
);
workOrder
.
setUpdateTime
(
now
);
workOrder
.
setUpdateTime
(
now
);
inspectionWorkOrderRepository
.
save
(
workOrder
);
inspectionWorkOrderRepository
.
save
(
workOrder
);
// 5. 保存操作日志
// 5. 保存操作日志
String
operationContent
=
"完成检测"
;
String
operationContent
=
"完成检测"
;
String
description
=
String
.
format
(
"操作人[%s]完成工单检测,结束时间:%s"
,
opName
,
now
.
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)));
String
description
=
String
.
format
(
"操作人[%s]完成工单检测,结束时间:%s"
,
op
erator
Name
,
now
.
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)));
saveWorkOrderOpLog
(
workOrder
,
saveWorkOrderOpLog
(
workOrder
,
InspectionWorkOrderOperationTypeEnum
.
COMPLETE_ORDER
.
getCode
(),
InspectionWorkOrderOperationTypeEnum
.
COMPLETE_ORDER
.
getCode
(),
originalStatus
,
originalStatus
,
targetStatus
,
targetStatus
,
operationContent
,
operationContent
,
description
,
description
,
Long
.
valueOf
(
opId
),
Long
.
valueOf
(
op
erator
Id
),
opName
,
op
erator
Name
,
platTypeEnum
.
getCode
());
platTypeEnum
.
getCode
());
log
.
info
(
"检测工单完成检测成功: ID={}, 唯一ID={}, 操作人={}"
,
workOrder
.
getId
(),
workOrder
.
getWoId
(),
opName
);
log
.
info
(
"检测工单完成检测成功: ID={}, 唯一ID={}, 操作人={}"
,
workOrder
.
getId
(),
workOrder
.
getWoId
(),
op
erator
Name
);
}
}
/**
/**
...
@@ -779,4 +780,109 @@ public class InspectionWorkOrderService {
...
@@ -779,4 +780,109 @@ public class InspectionWorkOrderService {
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"检测记录不存在,ID:"
+
id
));
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"检测记录不存在,ID:"
+
id
));
return
String
.
format
(
inspectorConfig
.
getInspectionRecordH5Url
(),
inspectionRecord
.
getId
());
return
String
.
format
(
inspectorConfig
.
getInspectionRecordH5Url
(),
inspectionRecord
.
getId
());
}
}
/**
* 查询工单操作日志(分页)
* 操作类型为11(修改检测项信息)和12(修改检测评分)时会关联查询具体修改内容
*
* @param workOrderId 工单主键ID
* @param pageable 分页参数
* @return 工单操作日志分页结果
*/
public
Page
<
WorkOrderOpLogRespVO
>
queryWorkOrderOpLogPage
(
Long
workOrderId
,
Pageable
pageable
)
{
// 1. 分页查询工单操作日志
Page
<
InspectionWorkOrderOpLog
>
opLogPage
=
inspectionWorkOrderOpLogRepository
.
findByWorkOrderInnerIdAndDeleteFlagOrderByIdDesc
(
workOrderId
,
DeleteFlag
.
NOT_DELETED
.
getCode
(),
pageable
);
// 2. 获取需要查询详细修改内容的日志ID列表(操作类型为11或12)
List
<
InspectionWorkOrderOpLog
>
logs
=
opLogPage
.
getContent
();
List
<
Long
>
needDetailLogIds
=
logs
.
stream
()
.
filter
(
log
->
{
Integer
opType
=
log
.
getOperationType
();
return
InspectionWorkOrderOperationTypeEnum
.
UPDATE_INSPECTION_ITEM
.
getCode
().
equals
(
opType
)
||
InspectionWorkOrderOperationTypeEnum
.
UPDATE_INSPECTION_SCORE
.
getCode
().
equals
(
opType
);
})
.
map
(
InspectionWorkOrderOpLog:
:
getId
)
.
collect
(
Collectors
.
toList
());
// 3. 批量查询详细修改内容
Map
<
Long
,
List
<
OpLogItemVO
>>
detailMap
=
buildDetailMap
(
needDetailLogIds
);
// 4. 组装返回结果
List
<
WorkOrderOpLogRespVO
>
respList
=
logs
.
stream
().
map
(
log
->
buildWorkOrderOpLogRespVO
(
log
,
detailMap
)).
collect
(
Collectors
.
toList
());
// 5. 构建分页返回结果
return
new
PageImpl
<>(
respList
,
pageable
,
opLogPage
.
getTotalElements
());
}
/**
* 构建详细修改内容映射
*/
private
Map
<
Long
,
List
<
OpLogItemVO
>>
buildDetailMap
(
List
<
Long
>
needDetailLogIds
)
{
Map
<
Long
,
List
<
OpLogItemVO
>>
detailMap
=
new
HashMap
<>();
if
(
needDetailLogIds
.
isEmpty
())
{
return
detailMap
;
}
// 根据 woOpId 查询 inspection_op_log
List
<
InspectionOpLog
>
opLogs
=
inspectionOpLogRepository
.
findByWoOpIdInAndDeleteFlag
(
needDetailLogIds
,
DeleteFlag
.
NOT_DELETED
.
getCode
());
List
<
Long
>
logIds
=
opLogs
.
stream
()
.
map
(
InspectionOpLog:
:
getLogId
)
.
collect
(
Collectors
.
toList
());
if
(
logIds
.
isEmpty
())
{
return
detailMap
;
}
List
<
InspectionOpLogItem
>
items
=
inspectionOpLogItemRepository
.
findByLogIdInAndDeleteFlag
(
logIds
,
DeleteFlag
.
NOT_DELETED
.
getCode
());
Map
<
Long
,
Long
>
logIdToWoOpIdMap
=
opLogs
.
stream
()
.
collect
(
Collectors
.
toMap
(
InspectionOpLog:
:
getLogId
,
InspectionOpLog:
:
getWoOpId
));
for
(
InspectionOpLogItem
item
:
items
)
{
Long
woOpId
=
logIdToWoOpIdMap
.
get
(
item
.
getLogId
());
if
(
woOpId
!=
null
)
{
OpLogItemVO
itemVO
=
inspectionOpLogConverter
.
toOpLogItemVO
(
item
);
detailMap
.
computeIfAbsent
(
woOpId
,
k
->
new
ArrayList
<>()).
add
(
itemVO
);
}
}
return
detailMap
;
}
/**
* 构建 WorkOrderOpLogRespVO
*/
private
WorkOrderOpLogRespVO
buildWorkOrderOpLogRespVO
(
InspectionWorkOrderOpLog
log
,
Map
<
Long
,
List
<
OpLogItemVO
>>
detailMap
)
{
WorkOrderOpLogRespVO
vo
=
new
WorkOrderOpLogRespVO
();
vo
.
setId
(
log
.
getId
());
vo
.
setWorkOrderInnerId
(
log
.
getWorkOrderInnerId
());
vo
.
setWoId
(
log
.
getWoId
());
vo
.
setOperatorId
(
log
.
getOperatorId
());
vo
.
setOperatorName
(
log
.
getOperatorName
());
vo
.
setPlateType
(
log
.
getPlateType
());
vo
.
setOperationType
(
log
.
getOperationType
());
vo
.
setOperationTypeDesc
(
getOperationTypeDesc
(
log
.
getOperationType
()));
vo
.
setOriginalStatus
(
log
.
getOriginalStatus
());
vo
.
setTargetStatus
(
log
.
getTargetStatus
());
vo
.
setOperationContent
(
log
.
getOperationContent
());
vo
.
setOperationTime
(
log
.
getOperationTime
());
vo
.
setDescription
(
log
.
getDescription
());
vo
.
setDetailItems
(
detailMap
.
get
(
log
.
getId
()));
return
vo
;
}
/**
* 获取操作类型描述
*/
private
String
getOperationTypeDesc
(
Integer
operationType
)
{
if
(
operationType
==
null
)
{
return
""
;
}
for
(
InspectionWorkOrderOperationTypeEnum
e
:
InspectionWorkOrderOperationTypeEnum
.
values
())
{
if
(
e
.
getCode
().
equals
(
operationType
))
{
return
e
.
getDesc
();
}
}
return
""
;
}
}
}
\ No newline at end of file
\ No newline at end of file
aus-core/src/main/java/com/glsx/usedcar/module/inspect/service/InspectorService.java
View file @
b2f6a2e
...
@@ -12,6 +12,7 @@ import com.glsx.usedcar.module.inspect.dao.*;
...
@@ -12,6 +12,7 @@ import com.glsx.usedcar.module.inspect.dao.*;
import
com.glsx.usedcar.module.inspect.domain.InspectorWorkOrderStatsProjection
;
import
com.glsx.usedcar.module.inspect.domain.InspectorWorkOrderStatsProjection
;
import
com.glsx.usedcar.module.inspect.entity.*
;
import
com.glsx.usedcar.module.inspect.entity.*
;
import
com.glsx.usedcar.module.inspect.vo.*
;
import
com.glsx.usedcar.module.inspect.vo.*
;
import
com.glsx.usedcar.util.AdCodeToProvinceUtil
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -225,6 +226,8 @@ public class InspectorService {
...
@@ -225,6 +226,8 @@ public class InspectorService {
// 转换为VO
// 转换为VO
InspectorRespVO
accountVO
=
BeanUtil
.
copyProperties
(
inspector
,
InspectorRespVO
.
class
);
InspectorRespVO
accountVO
=
BeanUtil
.
copyProperties
(
inspector
,
InspectorRespVO
.
class
);
accountVO
.
setProvinceName
(
AdCodeToProvinceUtil
.
getProvinceByAdCode
(
inspector
.
getRegion
()));
// 填充统计信息
// 填充统计信息
InspectorSimpleSummaryRespVO
summary
=
simpleInspectorSummaryInfo
(
accountVO
.
getId
());
InspectorSimpleSummaryRespVO
summary
=
simpleInspectorSummaryInfo
(
accountVO
.
getId
());
...
@@ -319,6 +322,7 @@ public class InspectorService {
...
@@ -319,6 +322,7 @@ public class InspectorService {
.
findFirst
();
.
findFirst
();
vo
.
setCompletedCount
(
completedSummary
.
map
(
InspectorWorkOrderStatsProjection:
:
getWorkOrderNum
).
orElse
(
0L
));
vo
.
setCompletedCount
(
completedSummary
.
map
(
InspectorWorkOrderStatsProjection:
:
getWorkOrderNum
).
orElse
(
0L
));
vo
.
setAvgInspectCost
(
completedSummary
.
map
(
InspectorWorkOrderStatsProjection:
:
getAvgInspectTime
).
orElse
(
0
));
vo
.
setAvgInspectCost
(
completedSummary
.
map
(
InspectorWorkOrderStatsProjection:
:
getAvgInspectTime
).
orElse
(
0
));
vo
.
setProvinceName
(
AdCodeToProvinceUtil
.
getProvinceByAdCode
(
vo
.
getRegion
()));
}
}
return
result
;
return
result
;
}
}
...
...
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/CompleteInspectionRespVO.java
View file @
b2f6a2e
...
@@ -25,9 +25,21 @@ public class CompleteInspectionRespVO implements Serializable {
...
@@ -25,9 +25,21 @@ public class CompleteInspectionRespVO implements Serializable {
@Serial
@Serial
private
static
final
long
serialVersionUID
=
340028291116019642L
;
private
static
final
long
serialVersionUID
=
340028291116019642L
;
@Schema
(
description
=
"第一个未完成的一级
检测项id
"
)
@Schema
(
description
=
"第一个未完成的一级
节点ID
"
)
private
Long
firstUncompletedNodeId
;
private
Long
firstUncompleted
Lv1
NodeId
;
@Schema
(
description
=
"第一个未完成的一级检测项名称"
)
@Schema
(
description
=
"第一个未完成的一级节点名称"
)
private
String
firstUncompletedNodeName
;
private
String
firstUncompletedLv1NodeName
;
@Schema
(
description
=
"第一个未完成的二级节点ID(一级下有二级时填充)"
)
private
Long
firstUncompletedLv2NodeId
;
@Schema
(
description
=
"第一个未完成的二级节点名称(一级下有二级时填充)"
)
private
String
firstUncompletedLv2NodeName
;
@Schema
(
description
=
"第一个未完成的三级节点ID(二级下有三级时填充)"
)
private
Long
firstUncompletedLv3NodeId
;
@Schema
(
description
=
"第一个未完成的三级节点名称(二级下有三级时填充)"
)
private
String
firstUncompletedLv3NodeName
;
}
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectionBatchSaveVO.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
vo
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
jakarta.validation.Valid
;
import
jakarta.validation.constraints.NotNull
;
import
lombok.Data
;
import
java.util.List
;
/**
* 按一级模块批量保存检测数据的请求 VO
* <p>
* PC端:一次传入一级模块下所有二级模块的数据
* H5端:Controller 手动将单次请求包装为单元素列表
*
* @author yangwei
* @since 2026/4/8
*/
@Data
@Schema
(
description
=
"按一级模块批量保存检测数据请求 VO"
)
public
class
InspectionBatchSaveVO
{
/**
* 任务 ID
*/
@NotNull
(
message
=
"任务ID不能为空"
)
@Schema
(
description
=
"任务 ID"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
)
private
Long
taskId
;
/**
* 一级模块 ID
*/
@NotNull
(
message
=
"一级模块ID不能为空"
)
@Schema
(
description
=
"一级模块 ID"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
)
private
Long
locationModule
;
/**
* 是否下一步(true=下一步,false=保存)
*/
@Schema
(
description
=
"是否是下一步,true-是,false-否,下一步会保存并校验,保存不会做必填校验,默认为true"
)
private
Boolean
nextFlag
=
true
;
/**
* 模块数据列表,每个元素对应一个二级模块(或直接挂在一级下的叶子)
*/
@Valid
@NotNull
(
message
=
"模块数据不能为空"
)
@Schema
(
description
=
"模块数据列表,每个元素对应一个二级模块"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
)
private
List
<
ModuleSaveItem
>
modules
;
/**
* 单个模块(二级模块)的保存数据
*/
@Data
@Schema
(
description
=
"单个模块(二级模块)的保存数据"
)
public
static
class
ModuleSaveItem
{
/**
* 二级模块 ID(可为 null,表示叶子直接挂在一级模块下)
*/
@Schema
(
description
=
"二级模块 ID(可为null,表示叶子直接挂在一级模块下)"
)
private
Long
locationSubModule
;
/**
* 该模块下的叶子节点数据列表
*/
@Valid
@Schema
(
description
=
"该模块下的叶子节点数据列表"
)
private
List
<
InspectionLeafNodeVO
>
leafNodes
;
}
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectionLeafNodeDataVO.java
View file @
b2f6a2e
...
@@ -2,6 +2,7 @@ package com.glsx.usedcar.module.inspect.vo;
...
@@ -2,6 +2,7 @@ package com.glsx.usedcar.module.inspect.vo;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
jakarta.validation.constraints.NotBlank
;
import
jakarta.validation.constraints.NotBlank
;
import
jakarta.validation.constraints.NotNull
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -36,6 +37,8 @@ public class InspectionLeafNodeDataVO implements Serializable {
...
@@ -36,6 +37,8 @@ public class InspectionLeafNodeDataVO implements Serializable {
private
String
interactionType
;
private
String
interactionType
;
@Schema
(
description
=
"值序号,同一结果多条值时递"
)
@Schema
(
description
=
"值序号,同一结果多条值时递"
)
@NotNull
(
message
=
"值序号 不能为空"
)
@Builder
.
Default
private
Integer
valueSeq
=
1
;
private
Integer
valueSeq
=
1
;
@Schema
(
description
=
"备注内容"
)
@Schema
(
description
=
"备注内容"
)
...
...
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectionResultSnapshotVO.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
vo
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
/**
* 检测结果快照 VO(用于操作日志的 beforeValue / afterValue JSON 序列化)
* <p>
* 封装一个叶子节点的完整检测数据:结果状态 + 备注 + 所有值
*
* @author yangwei
* @since 2026/4/9
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
InspectionResultSnapshotVO
{
/** 检测结果状态:1-正常,2-故障,3-无此结构 */
private
Integer
resultStatus
;
/** 备注 */
private
String
remark
;
/** 值列表 */
private
List
<
ValueItem
>
values
;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
static
class
ValueItem
{
/** 值的 key */
private
String
valueKey
;
/** 值的内容 */
private
String
valueText
;
/** 交互类型 */
private
String
interactionType
;
/** 值序号 */
private
Integer
valueSeq
;
}
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectionSaveVO.java
View file @
b2f6a2e
...
@@ -2,7 +2,6 @@ package com.glsx.usedcar.module.inspect.vo;
...
@@ -2,7 +2,6 @@ package com.glsx.usedcar.module.inspect.vo;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
jakarta.validation.Valid
;
import
jakarta.validation.Valid
;
import
jakarta.validation.constraints.NotEmpty
;
import
jakarta.validation.constraints.NotNull
;
import
jakarta.validation.constraints.NotNull
;
import
lombok.Data
;
import
lombok.Data
;
...
...
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectionTemplateDetailRespVO.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
vo
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
java.util.List
;
/**
* 检测模版详情响应 VO(含节点树)
*
* @author yangwei
* @version 1.0
* @since 2026/04/07
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema
(
description
=
"检测模版详情响应 VO(含节点树)"
)
public
class
InspectionTemplateDetailRespVO
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
1L
;
/**
* 模版ID
*/
@Schema
(
description
=
"模版ID"
)
private
Long
id
;
/**
* 模版编码
*/
@Schema
(
description
=
"模版编码"
)
private
String
templateCode
;
/**
* 模版名称
*/
@Schema
(
description
=
"模版名称"
)
private
String
templateName
;
/**
* 模版类型:1-燃油车,2-新能源车
*/
@Schema
(
description
=
"模版类型:1-燃油车,2-新能源车"
)
private
Integer
templateType
;
/**
* 状态:0-草稿,1-已发布,2-已禁用
*/
@Schema
(
description
=
"状态:0-草稿,1-已发布,2-已禁用"
)
private
Integer
status
;
/**
* 当前版本号
*/
@Schema
(
description
=
"当前版本号"
)
private
String
version
;
/**
* 模版描述
*/
@Schema
(
description
=
"模版描述"
)
private
String
description
;
/**
* 模版扩展配置(JSON格式文本)
*/
@Schema
(
description
=
"模版扩展配置(JSON格式文本)"
)
private
String
configJson
;
/**
* 创建时间
*/
@Schema
(
description
=
"创建时间"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
LocalDateTime
createTime
;
/**
* 更新时间
*/
@Schema
(
description
=
"更新时间"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
LocalDateTime
updateTime
;
/**
* 模版节点树(根节点列表,每个根节点含子节点)
*/
@Schema
(
description
=
"模版节点树(根节点列表,每个根节点含子节点)"
)
private
List
<
InspectionNodeVO
>
nodes
;
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectionTemplateRespVO.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
vo
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
java.util.List
;
/**
* 检测模版列表查询响应 VO
*
* @author yangwei
* @version 1.0
* @since 2026/04/07
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema
(
description
=
"检测模版列表查询响应 VO"
)
public
class
InspectionTemplateRespVO
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
1L
;
/**
* 模版ID
*/
@Schema
(
description
=
"模版ID"
)
private
Long
id
;
/**
* 模版编码
*/
@Schema
(
description
=
"模版编码"
)
private
String
templateCode
;
/**
* 模版名称
*/
@Schema
(
description
=
"模版名称"
)
private
String
templateName
;
/**
* 模版类型:1-燃油车,2-新能源车
*/
@Schema
(
description
=
"模版类型:1-燃油车,2-新能源车"
)
private
Integer
templateType
;
/**
* 状态:0-草稿,1-已发布,2-已禁用
*/
@Schema
(
description
=
"状态:0-草稿,1-已发布,2-已禁用"
)
private
Integer
status
;
/**
* 当前版本号
*/
@Schema
(
description
=
"当前版本号"
)
private
String
version
;
/**
* 模版描述
*/
@Schema
(
description
=
"模版描述"
)
private
String
description
;
/**
* 创建时间
*/
@Schema
(
description
=
"创建时间"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
LocalDateTime
createTime
;
/**
* 更新时间
*/
@Schema
(
description
=
"更新时间"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
LocalDateTime
updateTime
;
/**
* 模版标签列表
*/
@Schema
(
description
=
"模版标签列表"
)
private
List
<
TemplateTagVO
>
templateTags
;
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectorPageRespVO.java
View file @
b2f6a2e
...
@@ -68,6 +68,13 @@ public class InspectorPageRespVO implements Serializable {
...
@@ -68,6 +68,13 @@ public class InspectorPageRespVO implements Serializable {
)
)
private
String
regionName
;
private
String
regionName
;
@Schema
(
description
=
"省或直辖市"
,
example
=
"北京"
)
private
String
provinceName
;
/**
/**
* 创建时间
* 创建时间
*/
*/
...
...
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/InspectorRespVO.java
View file @
b2f6a2e
...
@@ -71,6 +71,13 @@ public class InspectorRespVO implements Serializable {
...
@@ -71,6 +71,13 @@ public class InspectorRespVO implements Serializable {
)
)
private
String
regionName
;
private
String
regionName
;
// 省
@Schema
(
description
=
"省或直辖市"
,
example
=
"北京"
)
private
String
provinceName
;
/**
/**
* 创建时间
* 创建时间
*/
*/
...
...
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/OpLogItemVO.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
vo
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
/**
* 操作日志明细项VO
*
* @author yangwei
* @since 2026/4/9
*/
@Data
@Schema
(
description
=
"操作日志明细项"
)
public
class
OpLogItemVO
{
@Schema
(
description
=
"明细ID"
)
private
Long
logItemId
;
@Schema
(
description
=
"一级模块名称"
)
private
String
moduleName
;
@Schema
(
description
=
"二级模块名称"
)
private
String
subModuleName
;
@Schema
(
description
=
"三级模块名称"
)
private
String
triModuleName
;
@Schema
(
description
=
"字段标签(完整路径)"
)
private
String
fieldLabel
;
@Schema
(
description
=
"字段标识"
)
private
String
fieldKey
;
@Schema
(
description
=
"修改前值"
)
private
String
beforeValue
;
@Schema
(
description
=
"修改后值"
)
private
String
afterValue
;
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/TemplateTagVO.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
vo
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serial
;
import
java.io.Serializable
;
/**
* 模版标签响应 VO
*
* @author yangwei
* @version 1.0
* @since 2026/04/07
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema
(
description
=
"模版标签响应 VO"
)
public
class
TemplateTagVO
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
1L
;
/**
* 标签ID
*/
@Schema
(
description
=
"标签ID"
)
private
Long
tagId
;
/**
* 标签编码
*/
@Schema
(
description
=
"标签编码"
)
private
String
tagCode
;
/**
* 标签名称
*/
@Schema
(
description
=
"标签名称"
)
private
String
tagName
;
/**
* 标签类型
*/
@Schema
(
description
=
"标签类型"
)
private
String
tagType
;
/**
* 排序顺序
*/
@Schema
(
description
=
"排序顺序"
)
private
Integer
sortOrder
;
}
aus-core/src/main/java/com/glsx/usedcar/module/inspect/vo/WorkOrderOpLogRespVO.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
module
.
inspect
.
vo
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
java.time.LocalDateTime
;
import
java.util.List
;
/**
* 工单操作日志查询响应VO
*
* @author yangwei
* @since 2026/4/9
*/
@Data
@Schema
(
description
=
"工单操作日志查询响应"
)
public
class
WorkOrderOpLogRespVO
{
@Schema
(
description
=
"日志ID"
)
private
Long
id
;
@Schema
(
description
=
"工单主键ID"
)
private
Long
workOrderInnerId
;
@Schema
(
description
=
"工单唯一ID"
)
private
String
woId
;
@Schema
(
description
=
"操作人ID"
)
private
Long
operatorId
;
@Schema
(
description
=
"操作人姓名"
)
private
String
operatorName
;
@Schema
(
description
=
"平台标识:0 检测师 1 后台"
)
private
Integer
plateType
;
@Schema
(
description
=
"操作类型"
)
private
Integer
operationType
;
@Schema
(
description
=
"操作类型描述"
)
private
String
operationTypeDesc
;
@Schema
(
description
=
"操作前状态"
)
private
Integer
originalStatus
;
@Schema
(
description
=
"操作后状态"
)
private
Integer
targetStatus
;
@Schema
(
description
=
"操作内容描述"
)
private
String
operationContent
;
@Schema
(
description
=
"操作时间"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
LocalDateTime
operationTime
;
@Schema
(
description
=
"操作描述"
)
private
String
description
;
@Schema
(
description
=
"详细修改内容(操作类型为11或12时有值)"
)
private
List
<
OpLogItemVO
>
detailItems
;
}
aus-core/src/main/java/com/glsx/usedcar/util/AdCodeToProvinceUtil.java
View file @
b2f6a2e
...
@@ -52,7 +52,9 @@ public class AdCodeToProvinceUtil {
...
@@ -52,7 +52,9 @@ public class AdCodeToProvinceUtil {
adcodeMap
.
put
(
"62"
,
"甘肃省"
);
adcodeMap
.
put
(
"62"
,
"甘肃省"
);
adcodeMap
.
put
(
"63"
,
"青海省"
);
adcodeMap
.
put
(
"63"
,
"青海省"
);
adcodeMap
.
put
(
"64"
,
"宁夏回族自治区"
);
adcodeMap
.
put
(
"64"
,
"宁夏回族自治区"
);
adcodeMap
.
put
(
"65"
,
"新疆维吾尔自治区"
);
adcodeMap
.
put
(
"71"
,
"台湾省"
);
adcodeMap
.
put
(
"81"
,
"香港特别行政区"
);
adcodeMap
.
put
(
"82"
,
"澳门特别行政区"
);
ADCODE_PROVINCE_MAP
=
Collections
.
unmodifiableMap
(
adcodeMap
);
ADCODE_PROVINCE_MAP
=
Collections
.
unmodifiableMap
(
adcodeMap
);
}
}
...
...
aus-framework/src/main/java/org/summerframework/core/enums/ErrorCodeEnum.java
View file @
b2f6a2e
...
@@ -47,8 +47,9 @@ public enum ErrorCodeEnum {
...
@@ -47,8 +47,9 @@ public enum ErrorCodeEnum {
NOT_ABLE_INSPECT
(
1001104
,
"当前工单无法提交检测"
),
NOT_ABLE_INSPECT
(
1001104
,
"当前工单无法提交检测"
),
NODE_CHECK_RULE_ERROR
(
1001105
,
"【{0}】校验规则解析异常"
),
NODE_CHECK_RULE_ERROR
(
1001105
,
"【{0}】校验规则解析异常"
),
NOT_CURR_WORK_INSPECTOR
(
1001106
,
"您不是当前工单的检测师,无法提交!"
)
NOT_CURR_WORK_INSPECTOR
(
1001106
,
"您不是当前工单的检测师,无法提交!"
),
CURR_WORK_ORDER_STATUS_ERROR_SAVE
(
1001107
,
"当前工单状态无法保存"
),
EVENT_CODE_NOT_CONFIG
(
1001108
,
"事件代码 [{0}] 未在 event_type_config 中配置或未启用"
),
;
;
private
final
Integer
code
;
private
final
Integer
code
;
private
final
String
message
;
private
final
String
message
;
...
...
aus-inspector/src/main/java/com/glsx/usedcar/controller/InspectionRecordController.java
View file @
b2f6a2e
...
@@ -2,11 +2,14 @@ package com.glsx.usedcar.controller;
...
@@ -2,11 +2,14 @@ package com.glsx.usedcar.controller;
import
com.glsx.usedcar.annotation.RequireLogin
;
import
com.glsx.usedcar.annotation.RequireLogin
;
import
com.glsx.usedcar.context.InspectorContext
;
import
com.glsx.usedcar.context.InspectorContext
;
import
com.glsx.usedcar.delegate.InspectorSaveDelegate
;
import
com.glsx.usedcar.module.inspect.entity.Inspector
;
import
com.glsx.usedcar.module.inspect.entity.Inspector
;
import
com.glsx.usedcar.module.inspect.service.InspectionRecordService
;
import
com.glsx.usedcar.module.inspect.service.InspectionRecordService
;
import
com.glsx.usedcar.module.inspect.service.InspectionWorkOrderService
;
import
com.glsx.usedcar.module.inspect.vo.CompleteInspectionRespVO
;
import
com.glsx.usedcar.module.inspect.vo.CompleteInspectionRespVO
;
import
com.glsx.usedcar.module.inspect.vo.CompleteInspectionVO
;
import
com.glsx.usedcar.module.inspect.vo.CompleteInspectionVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionDetailRespVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionDetailRespVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionBatchSaveVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionSaveVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionSaveVO
;
import
com.glsx.usedcar.resp.BaseResp
;
import
com.glsx.usedcar.resp.BaseResp
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.Operation
;
...
@@ -18,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -18,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
/**
/**
...
@@ -35,20 +39,28 @@ import java.util.Optional;
...
@@ -35,20 +39,28 @@ import java.util.Optional;
public
class
InspectionRecordController
{
public
class
InspectionRecordController
{
private
final
InspectionRecordService
inspectionRecordService
;
private
final
InspectionRecordService
inspectionRecordService
;
private
final
InspectionWorkOrderService
inspectionWorkOrderService
;
/**
* 保存检测工单(分步保存同一级的所有根节点)
*
* @param req 保存请求
* @return 检测记录 ID
*/
@PostMapping
(
"/save"
)
@PostMapping
(
"/save"
)
@Operation
(
summary
=
"保存/下一步"
,
description
=
"分步保存同一级的所有叶子节点数据,包括检测记录主表和检测值明细"
)
@Operation
(
summary
=
"保存/下一步"
,
description
=
"分步保存同一级的所有叶子节点数据,包括检测记录主表和检测值明细"
)
public
BaseResp
<
Long
>
saveInspection
(
@RequestBody
@Valid
InspectionSaveVO
req
)
{
public
BaseResp
<
Long
>
saveInspection
(
@RequestBody
@Valid
InspectionSaveVO
req
)
{
Inspector
inspector
=
Optional
.
ofNullable
(
InspectorContext
.
getInspector
())
Inspector
inspector
=
Optional
.
ofNullable
(
InspectorContext
.
getInspector
())
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
LOGIN_ERROR
));
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
LOGIN_ERROR
));
Long
recordId
=
inspectionRecordService
.
saveInspection
(
req
,
inspector
);
InspectorSaveDelegate
delegate
=
new
InspectorSaveDelegate
(
inspector
,
inspectionRecordService
,
inspectionWorkOrderService
);
// 将单次请求包装为批量格式,以适配 Service 层新接口
InspectionBatchSaveVO
batchReq
=
new
InspectionBatchSaveVO
();
batchReq
.
setTaskId
(
req
.
getTaskId
());
batchReq
.
setLocationModule
(
req
.
getLocationModule
());
batchReq
.
setNextFlag
(
req
.
getNextFlag
());
InspectionBatchSaveVO
.
ModuleSaveItem
item
=
new
InspectionBatchSaveVO
.
ModuleSaveItem
();
item
.
setLocationSubModule
(
req
.
getLocationSubModule
());
item
.
setLeafNodes
(
req
.
getLeafNodes
());
batchReq
.
setModules
(
List
.
of
(
item
));
Long
recordId
=
inspectionRecordService
.
saveInspectionWithDelegate
(
batchReq
,
delegate
);
return
BaseResp
.
success
(
recordId
,
"保存成功"
);
return
BaseResp
.
success
(
recordId
,
"保存成功"
);
}
}
...
@@ -57,7 +69,8 @@ public class InspectionRecordController {
...
@@ -57,7 +69,8 @@ public class InspectionRecordController {
public
BaseResp
<
CompleteInspectionRespVO
>
completeInspection
(
@RequestBody
@Valid
CompleteInspectionVO
req
)
{
public
BaseResp
<
CompleteInspectionRespVO
>
completeInspection
(
@RequestBody
@Valid
CompleteInspectionVO
req
)
{
Inspector
inspector
=
Optional
.
ofNullable
(
InspectorContext
.
getInspector
())
Inspector
inspector
=
Optional
.
ofNullable
(
InspectorContext
.
getInspector
())
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
LOGIN_ERROR
));
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
LOGIN_ERROR
));
return
BaseResp
.
success
(
inspectionRecordService
.
completeInspection
(
req
,
inspector
),
"完成检测"
);
InspectorSaveDelegate
delegate
=
new
InspectorSaveDelegate
(
inspector
,
inspectionRecordService
,
inspectionWorkOrderService
);
return
BaseResp
.
success
(
inspectionRecordService
.
saveScoreWithDelegate
(
req
,
delegate
),
"完成检测"
);
}
}
/**
/**
...
...
aus-inspector/src/main/java/com/glsx/usedcar/delegate/InspectorSaveDelegate.java
0 → 100644
View file @
b2f6a2e
package
com
.
glsx
.
usedcar
.
delegate
;
import
com.glsx.usedcar.enums.inspect.InspectionPlatTypeEnum
;
import
com.glsx.usedcar.enums.inspect.InspectionWorkOrderStatusEnum
;
import
com.glsx.usedcar.module.inspect.delegate.InspectionSaveDelegate
;
import
com.glsx.usedcar.module.inspect.entity.Inspector
;
import
com.glsx.usedcar.module.inspect.entity.InspectionRecord
;
import
com.glsx.usedcar.module.inspect.entity.InspectionWorkOrder
;
import
com.glsx.usedcar.module.inspect.service.InspectionRecordService
;
import
com.glsx.usedcar.module.inspect.service.InspectionWorkOrderService
;
import
com.glsx.usedcar.module.inspect.vo.CompleteInspectionRespVO
;
import
com.glsx.usedcar.module.inspect.vo.InspectionNodeVO
;
import
lombok.RequiredArgsConstructor
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.Optional
;
/**
* H5 端检测师保存策略实现
*
* @author yangwei
* @since 2026/4/8
*/
@RequiredArgsConstructor
public
class
InspectorSaveDelegate
implements
InspectionSaveDelegate
{
private
final
Inspector
inspector
;
private
final
InspectionRecordService
inspectionRecordService
;
private
final
InspectionWorkOrderService
inspectionWorkOrderService
;
@Override
public
void
validatePermission
(
InspectionWorkOrder
workOrder
)
{
// 1. 检查工单状态是否允许检测(待检测或检测中)
if
(!
InspectionWorkOrderStatusEnum
.
beableInspection
(
workOrder
.
getStatus
()))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
NOT_ABLE_INSPECT
);
}
// 2. 检查当前检测师是否是工单分配的检测师
if
(!
inspector
.
getId
().
equals
(
Optional
.
ofNullable
(
workOrder
.
getInspector
()).
map
(
Inspector:
:
getId
).
orElse
(
null
)))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
NOT_CURR_WORK_INSPECTOR
);
}
}
@Override
public
InspectionPlatTypeEnum
getPlatType
()
{
return
InspectionPlatTypeEnum
.
INSPECTOR
;
}
@Override
public
String
getOperatorName
()
{
return
inspector
.
getName
();
}
@Override
public
Long
getOperatorId
()
{
return
inspector
.
getId
();
}
@Override
public
CompleteInspectionRespVO
checkAndComplete
(
InspectionRecord
record
,
InspectionWorkOrder
workOrder
,
List
<
InspectionNodeVO
>
allNodes
)
{
// H5端:深度检查节点树,找第一个未完成节点
CompleteInspectionRespVO
uncompleted
=
inspectionRecordService
.
findFirstUncompletedNodeForComplete
(
record
.
getId
(),
allNodes
);
if
(
uncompleted
!=
null
)
{
return
uncompleted
;
}
// 所有节点已完成,更新完成时间并触发完成操作
LocalDateTime
completeTime
=
LocalDateTime
.
now
();
record
.
setCompleteTime
(
completeTime
);
// record 是 managed 实体,事务提交时自动持久化;此处显式保存以确保 completeTime 可被后续逻辑读取
inspectionRecordService
.
saveRecord
(
record
);
inspectionRecordService
.
sendCompleteNotice
(
record
,
allNodes
,
workOrder
.
getId
(),
completeTime
);
inspectionWorkOrderService
.
completeInspection
(
workOrder
.
getId
(),
getPlatType
(),
getOperatorId
(),
getOperatorName
());
return
null
;
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment