|
@@ -0,0 +1,216 @@
|
|
|
+package com.persagy.labsl.service.impl
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil
|
|
|
+import cn.hutool.core.collection.CollUtil
|
|
|
+import cn.hutool.core.util.StrUtil
|
|
|
+import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
|
|
|
+import com.persagy.labsl.Opts
|
|
|
+import com.persagy.labsl.domain.*
|
|
|
+import com.persagy.labsl.mapper.GraphMapper
|
|
|
+import com.persagy.labsl.models.entities.tpt.Graph
|
|
|
+import com.persagy.labsl.service.*
|
|
|
+import com.persagy.service.models.enums.SResponseType
|
|
|
+import com.persagy.service.models.responses.SCreateResponse
|
|
|
+import lombok.extern.slf4j.Slf4j
|
|
|
+import org.springframework.beans.factory.annotation.Autowired
|
|
|
+import org.springframework.stereotype.Service
|
|
|
+import org.springframework.transaction.annotation.Transactional
|
|
|
+import java.util.*
|
|
|
+import kotlin.collections.ArrayList
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+open class GraphServiceImpl : ServiceImpl<GraphMapper?, GraphEntity?>(), GraphService{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ lateinit var nodeService: NodeService
|
|
|
+ @Autowired
|
|
|
+ lateinit var markerService: MarkerService
|
|
|
+ @Autowired
|
|
|
+ lateinit var relationService: RelationService
|
|
|
+ @Autowired
|
|
|
+ lateinit var anchorService: AnchorService
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建图
|
|
|
+ *
|
|
|
+ * @param graph 图对象
|
|
|
+ * @return 图形对象列表
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ override fun saveLogic(graph: Graph): SCreateResponse<Graph> {
|
|
|
+ val sCreateResponse = SCreateResponse<Graph>()
|
|
|
+ /** 未发布 */
|
|
|
+ if (graph.id.isNullOrEmpty()) {
|
|
|
+ /** id赋值 */
|
|
|
+ graph.id = UUID.randomUUID().toString().replace("-", "")
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 图 id 为空赋值*/
|
|
|
+ if (graph.graphId.isNullOrEmpty()){
|
|
|
+ graph.graphId = UUID.randomUUID().toString().replace("-", "")
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 项目 id 赋值 */
|
|
|
+ graph.projectId = Opts.projectId!!
|
|
|
+
|
|
|
+ /** 清除以前的版本 */
|
|
|
+ delOldData(graph)
|
|
|
+ /** 版本号 */
|
|
|
+ if (graph.version.isNullOrEmpty()) {
|
|
|
+ graph.version = "2.0.1"
|
|
|
+ } else {
|
|
|
+ val listVersion = graph.version!!.split(".")
|
|
|
+ val num = listVersion[2].toInt() + 1
|
|
|
+ graph.version = listVersion[0] + "." + listVersion[1] + "." + num
|
|
|
+ }
|
|
|
+ /** 图标记设置为 1 草稿箱 */
|
|
|
+ graph.state = 1
|
|
|
+ /** 插入图形数据 */
|
|
|
+ val graphEntity = BeanUtil.copyProperties(graph, GraphEntity::class.java)
|
|
|
+ save(graphEntity)
|
|
|
+ /** 列表不能为空 */
|
|
|
+ saveElements(graph)
|
|
|
+ /** 返回标志 */
|
|
|
+ sCreateResponse.result = SResponseType.success
|
|
|
+ /** 返回对象列表 */
|
|
|
+ sCreateResponse.entityList = arrayListOf(graph)
|
|
|
+ /** 返回对象 */
|
|
|
+ return sCreateResponse
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun saveElements(graph: Graph) {
|
|
|
+ if (null==graph.elements){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ val nodesList = graph.elements!!.nodes
|
|
|
+ /** 列表不能为空 */
|
|
|
+ if (!nodesList.isNullOrEmpty()) {
|
|
|
+ val addNodesList = ArrayList<NodeEntity>()
|
|
|
+ val addAnchorsList = ArrayList<AnchorEntity>()
|
|
|
+ /** 遍历列表 */
|
|
|
+ for (nodes in nodesList) {
|
|
|
+ /** 图 id 赋值给子节点*/
|
|
|
+ nodes.graphId = graph.graphId
|
|
|
+ /** 图形 id */
|
|
|
+ nodes.id = graph.id
|
|
|
+ nodes.state = 1
|
|
|
+ /** 子节点 id */
|
|
|
+ if (nodes.nodeId.isNullOrEmpty()) {
|
|
|
+ /** id 赋值 */
|
|
|
+ nodes.nodeId = UUID.randomUUID().toString().replace("-", "")
|
|
|
+ }
|
|
|
+ addNodesList.add(BeanUtil.copyProperties(nodes,NodeEntity::class.java))
|
|
|
+ val anchorList = nodes.anchorList
|
|
|
+ /** 列表不能为空 */
|
|
|
+ if (anchorList.isNullOrEmpty()) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ /** 遍历列表 */
|
|
|
+ for (anchor in anchorList) {
|
|
|
+ /** 图 id 赋值 */
|
|
|
+ anchor.graphId = graph.graphId
|
|
|
+ /** 图编码 */
|
|
|
+ anchor.id = graph.id
|
|
|
+ /** 节点 id 赋值 */
|
|
|
+ anchor.nodeId = nodes.nodeId
|
|
|
+ anchor.state = 1
|
|
|
+ if (anchor.anchorId.isNullOrEmpty()) {
|
|
|
+ /** id赋值 */
|
|
|
+ anchor.anchorId = UUID.randomUUID().toString().replace("-", "")
|
|
|
+ }
|
|
|
+ addAnchorsList.add(BeanUtil.copyProperties(anchor,AnchorEntity::class.java))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(addNodesList)){
|
|
|
+ nodeService.saveBatch(CollUtil.newArrayList(addNodesList))
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(addAnchorsList)){
|
|
|
+ anchorService.saveBatch(CollUtil.newArrayList(addAnchorsList))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ val markersList = graph.elements!!.markers
|
|
|
+ /** 列表不为空 */
|
|
|
+ if (!markersList.isNullOrEmpty()) {
|
|
|
+ val addMarkerList = ArrayList<MarkerEntity>()
|
|
|
+ /** 遍历列表 */
|
|
|
+ for (markers in markersList) {
|
|
|
+ /** 图 id */
|
|
|
+ markers.graphId = graph.graphId
|
|
|
+ /** 标识 id */
|
|
|
+ markers.id = graph.id
|
|
|
+ /** 草稿箱标志 */
|
|
|
+ markers.state = 1
|
|
|
+ /** id 为空赋值 */
|
|
|
+ if (markers.markerId.isNullOrEmpty()) {
|
|
|
+ /** id赋值 */
|
|
|
+ markers.markerId = UUID.randomUUID().toString().replace("-", "")
|
|
|
+ }
|
|
|
+ addMarkerList.add(BeanUtil.copyProperties(markers,MarkerEntity::class.java))
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(addMarkerList)){
|
|
|
+ markerService.saveBatch(CollUtil.newArrayList(addMarkerList))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ val relationsList = graph.elements!!.relations
|
|
|
+ /** 列表不为空 */
|
|
|
+ if (!relationsList.isNullOrEmpty()) {
|
|
|
+ val addRelationList = ArrayList<RelationEntity>()
|
|
|
+ /** 遍历列表 */
|
|
|
+ for (relations in relationsList) {
|
|
|
+ /** 图 id */
|
|
|
+ relations.graphId = graph.graphId
|
|
|
+ /** 草稿箱标志 */
|
|
|
+ relations.state = 1
|
|
|
+ /** 图编码 */
|
|
|
+ relations.id = graph.id
|
|
|
+ /** 管线 id 为空 赋值 */
|
|
|
+ if (relations.relationId.isNullOrEmpty()) {
|
|
|
+ /** id 赋值 */
|
|
|
+ relations.relationId = UUID.randomUUID().toString().replace("-", "")
|
|
|
+ }
|
|
|
+ addRelationList.add(BeanUtil.copyProperties(relations,RelationEntity::class.java))
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(addRelationList)){
|
|
|
+ relationService.saveBatch(CollUtil.newArrayList(addRelationList))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清除草稿箱以前数据
|
|
|
+ *
|
|
|
+ * @param graph 图对象
|
|
|
+ */
|
|
|
+ private fun delOldData(graph: Graph) {
|
|
|
+ val graphWrapper= KtQueryWrapper(GraphEntity())
|
|
|
+ val nodeWrapper=KtQueryWrapper(NodeEntity())
|
|
|
+ val markerWrapper=KtQueryWrapper(MarkerEntity())
|
|
|
+ val relationWrapper=KtQueryWrapper(RelationEntity())
|
|
|
+ val anchorWrapper=KtQueryWrapper(AnchorEntity())
|
|
|
+ graphWrapper.eq(StrUtil.isNotBlank(graph.projectId),GraphEntity::projectId,graph.projectId!!)
|
|
|
+ graphWrapper.eq(StrUtil.isNotBlank(graph.id),GraphEntity::id,graph.id!!)
|
|
|
+ graphWrapper.eq(StrUtil.isNotBlank(graph.graphId),GraphEntity::graphId,graph.graphId)
|
|
|
+ remove(graphWrapper)
|
|
|
+ nodeWrapper.eq(StrUtil.isNotBlank(graph.id),NodeEntity::id,graph.id!!)
|
|
|
+ nodeWrapper.eq(StrUtil.isNotBlank(graph.graphId),NodeEntity::graphId,graph.graphId)
|
|
|
+ nodeService.remove(nodeWrapper)
|
|
|
+ markerWrapper.eq(StrUtil.isNotBlank(graph.id),MarkerEntity::id,graph.id!!)
|
|
|
+ markerWrapper.eq(StrUtil.isNotBlank(graph.graphId),MarkerEntity::graphId,graph.graphId)
|
|
|
+ markerService.remove(markerWrapper)
|
|
|
+ relationWrapper.eq(StrUtil.isNotBlank(graph.id),RelationEntity::id,graph.id!!)
|
|
|
+ relationWrapper.eq(StrUtil.isNotBlank(graph.graphId),RelationEntity::graphId,graph.graphId)
|
|
|
+ relationService.remove(relationWrapper)
|
|
|
+ anchorWrapper.eq(StrUtil.isNotBlank(graph.id),AnchorEntity::id,graph.id!!)
|
|
|
+ anchorWrapper.eq(StrUtil.isNotBlank(graph.graphId),AnchorEntity::graphId,graph.graphId)
|
|
|
+ anchorService.remove(anchorWrapper)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|