Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
info-publish-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
info-publish-platform
Commits
eb4ec341
Commit
eb4ec341
authored
Dec 05, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改同步逻辑
parent
303d0f20
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
3 deletions
+79
-3
info-publish-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java
...als/xhx/module/device/service/impl/DeviceServiceImpl.java
+79
-3
No files found.
info-publish-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java
View file @
eb4ec341
...
...
@@ -16,12 +16,16 @@ import com.mortals.xhx.module.device.model.*;
import
com.mortals.xhx.module.device.service.DeviceFileService
;
import
com.mortals.xhx.module.device.service.DeviceService
;
import
com.mortals.xhx.module.device.service.DeviceWorkmanService
;
import
com.mortals.xhx.module.workman.model.WorkmanEntity
;
import
com.mortals.xhx.module.workman.service.WorkmanService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
...
...
@@ -48,6 +52,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
private
DeviceFileService
deviceFileService
;
@Autowired
private
DeviceWorkmanService
deviceWorkmanService
;
@Autowired
private
WorkmanService
workmanService
;
@Override
protected
String
getExtKey
(
DeviceEntity
data
)
{
...
...
@@ -69,7 +75,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
@Override
public
Rest
<
DeviceEntity
>
deviceInfoByCode
(
String
deviceCode
,
Context
context
)
{
DeviceEntity
deviceEntity
=
this
.
selectOne
(
new
DeviceQuery
().
deviceCode
(
deviceCode
),
context
);
if
(
ObjectUtils
.
isEmpty
(
deviceEntity
)){
if
(
ObjectUtils
.
isEmpty
(
deviceEntity
))
{
throw
new
AppException
(
"设备编码未找到相应设备!code:"
+
deviceCode
);
}
List
<
DeviceWorkmanEntity
>
deviceWorkmanEntityList
=
deviceWorkmanService
.
find
(
new
DeviceWorkmanQuery
().
deviceId
(
deviceEntity
.
getId
()));
...
...
@@ -128,22 +134,92 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
@Override
protected
void
saveAfter
(
DeviceEntity
entity
,
Context
context
)
throws
AppException
{
super
.
saveAfter
(
entity
,
context
);
if
(!
ObjectUtils
.
isEmpty
(
entity
.
getDeviceWorkmanEntityList
()))
{
saveDeviceWorkman
(
entity
,
context
);
}
if
(!
ObjectUtils
.
isEmpty
(
entity
.
getDeviceFileEntityList
()))
{
saveDeviceFile
(
entity
,
context
);
}
}
@Override
protected
void
updateAfter
(
DeviceEntity
entity
,
Context
context
)
throws
AppException
{
if
(!
ObjectUtils
.
isEmpty
(
entity
.
getDeviceWorkmanEntityList
()))
{
//先删除 再添加
List
<
Long
>
deviceIdList
=
entity
.
getDeviceWorkmanEntityList
().
stream
().
map
(
i
->
i
.
getDeviceId
()).
collect
(
Collectors
.
toList
());
if
(!
ObjectUtils
.
isEmpty
(
deviceIdList
))
{
DeviceWorkmanQuery
deviceWorkmanQuery
=
new
DeviceWorkmanQuery
();
deviceWorkmanQuery
.
setDeviceIdList
(
deviceIdList
);
Long
[]
deviceIds
=
deviceWorkmanService
.
find
(
deviceWorkmanQuery
).
stream
().
map
(
DeviceWorkmanEntity:
:
getId
).
toArray
(
Long
[]::
new
);
deviceWorkmanService
.
remove
(
deviceIds
,
context
);
}
saveDeviceWorkman
(
entity
,
context
);
}
if
(!
ObjectUtils
.
isEmpty
(
entity
.
getDeviceFileEntityList
()))
{
List
<
Long
>
deviceIdList
=
entity
.
getDeviceFileEntityList
().
stream
().
map
(
i
->
i
.
getDeviceId
()).
collect
(
Collectors
.
toList
());
if
(!
ObjectUtils
.
isEmpty
(
deviceIdList
))
{
DeviceFileQuery
deviceFileQuery
=
new
DeviceFileQuery
();
deviceFileQuery
.
setDeviceIdList
(
deviceIdList
);
Long
[]
deviceIds
=
deviceFileService
.
find
(
deviceFileQuery
).
stream
().
map
(
DeviceFileEntity:
:
getId
).
toArray
(
Long
[]::
new
);
deviceFileService
.
remove
(
deviceIds
,
context
);
}
saveDeviceFile
(
entity
,
context
);
}
}
private
void
saveDeviceFile
(
DeviceEntity
entity
,
Context
context
)
{
List
<
DeviceFileEntity
>
deviceFileEntities
=
entity
.
getDeviceFileEntityList
().
stream
().
map
(
item
->
{
Long
deviceId
=
item
.
getDeviceId
();
DeviceEntity
deviceEntity
=
this
.
get
(
deviceId
,
context
);
item
.
setDeviceId
(
deviceEntity
.
getId
());
item
.
setDeviceCode
(
deviceEntity
.
getDeviceCode
());
item
.
setDeviceName
(
deviceEntity
.
getDeviceName
());
item
.
setCreateUserId
(
this
.
getContextUserId
(
context
));
item
.
setCreateTime
(
new
Date
());
return
item
;
}).
collect
(
Collectors
.
toList
());
if
(!
ObjectUtils
.
isEmpty
(
deviceFileEntities
))
{
deviceFileService
.
save
(
deviceFileEntities
);
}
}
private
void
saveDeviceWorkman
(
DeviceEntity
entity
,
Context
context
)
{
List
<
DeviceWorkmanEntity
>
deviceWorkmanEntityList
=
entity
.
getDeviceWorkmanEntityList
().
stream
().
map
(
item
->
{
DeviceWorkmanEntity
deviceWorkmanEntity
=
new
DeviceWorkmanEntity
();
Long
workmanId
=
item
.
getWorkmanId
();
WorkmanEntity
workmanEntity
=
workmanService
.
get
(
workmanId
);
BeanUtils
.
copyProperties
(
workmanEntity
,
deviceWorkmanEntity
);
Long
deviceId
=
item
.
getDeviceId
();
DeviceEntity
deviceEntity
=
this
.
get
(
deviceId
);
deviceWorkmanEntity
.
setDeviceId
(
deviceId
);
deviceWorkmanEntity
.
setDeviceName
(
deviceEntity
.
getDeviceName
());
deviceWorkmanEntity
.
setDeviceCode
(
deviceEntity
.
getDeviceCode
());
deviceWorkmanEntity
.
setCreateUserId
(
this
.
getContextUserId
(
context
));
deviceWorkmanEntity
.
setCreateTime
(
new
Date
());
return
deviceWorkmanEntity
;
}).
collect
(
Collectors
.
toList
());
if
(!
ObjectUtils
.
isEmpty
(
deviceWorkmanEntityList
))
{
deviceWorkmanService
.
save
(
deviceWorkmanEntityList
);
}
}
@Override
protected
void
removeAfter
(
Long
[]
ids
,
Context
context
,
int
result
)
throws
AppException
{
super
.
removeAfter
(
ids
,
context
,
result
);
DeviceWorkmanQuery
deviceWorkmanQuery
=
new
DeviceWorkmanQuery
();
deviceWorkmanQuery
.
setDeviceIdList
(
Arrays
.
asList
(
ids
));
Long
[]
deviceIds
=
deviceWorkmanService
.
find
(
deviceWorkmanQuery
).
stream
().
map
(
DeviceWorkmanEntity:
:
getId
).
toArray
(
Long
[]::
new
);
deviceWorkmanService
.
remove
(
deviceIds
,
context
);
DeviceFileQuery
deviceFileQuery
=
new
DeviceFileQuery
();
deviceFileQuery
.
setDeviceIdList
((
Arrays
.
asList
(
ids
)));
deviceIds
=
deviceFileService
.
find
(
deviceFileQuery
).
stream
().
map
(
DeviceFileEntity:
:
getId
).
toArray
(
Long
[]::
new
);
deviceFileService
.
remove
(
deviceIds
,
context
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment