|
|
@@ -3,11 +3,11 @@ package com.zhongshu.card.server.core.service.scene;
|
|
|
import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
import com.github.microservice.net.ResultMessage;
|
|
|
-import com.zhongshu.card.client.model.scene.SceneInfoModel;
|
|
|
-import com.zhongshu.card.client.model.scene.SceneInfoParam;
|
|
|
-import com.zhongshu.card.client.model.scene.SceneInfoSearch;
|
|
|
+import com.zhongshu.card.client.model.scene.*;
|
|
|
import com.zhongshu.card.client.type.DataState;
|
|
|
+import com.zhongshu.card.server.core.dao.scene.SceneComponentDao;
|
|
|
import com.zhongshu.card.server.core.dao.scene.SceneInfoDao;
|
|
|
+import com.zhongshu.card.server.core.domain.scene.SceneComponent;
|
|
|
import com.zhongshu.card.server.core.domain.scene.SceneInfo;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
@@ -20,6 +20,10 @@ import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* @author TRX
|
|
|
* @date 2024/11/22
|
|
|
@@ -37,6 +41,9 @@ public class SceneInfoService extends SuperService {
|
|
|
@Autowired
|
|
|
private ProjectSceneInfoService projectSceneInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SceneComponentDao sceneComponentDao;
|
|
|
+
|
|
|
public ResultContent saveInfo(SceneInfoParam param) {
|
|
|
boolean isAdd = true;
|
|
|
SceneInfo entity = null;
|
|
|
@@ -73,6 +80,7 @@ public class SceneInfoService extends SuperService {
|
|
|
if (!isAdd) {
|
|
|
projectSceneInfoService.updateAllSceneInfo(entity);
|
|
|
}
|
|
|
+ saveComponents(entity, param.getComponents());
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
@@ -81,12 +89,12 @@ public class SceneInfoService extends SuperService {
|
|
|
return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
}
|
|
|
|
|
|
- public ResultContent<SceneInfoModel> getDetailById(String id) {
|
|
|
+ public ResultContent<SceneInfoAboutComModel> getDetailById(String id) {
|
|
|
SceneInfo entity = sceneInfoDao.findTopById(id);
|
|
|
if (ObjectUtils.isEmpty(entity)) {
|
|
|
return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
}
|
|
|
- return ResultContent.buildSuccess(toModel(entity));
|
|
|
+ return ResultContent.buildSuccess(toAboutComModel(entity));
|
|
|
}
|
|
|
|
|
|
public ResultContent deleteById(String id) {
|
|
|
@@ -117,6 +125,58 @@ public class SceneInfoService extends SuperService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ //--------------------------场景组件信息 start---------------------
|
|
|
+
|
|
|
+ public ResultContent deleteComponentById(String id) {
|
|
|
+ SceneComponent entity = sceneComponentDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ // 判断是否可以删除
|
|
|
+ sceneComponentDao.delete(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent saveComponents(SceneInfo sceneInfo, List<SceneComponentParam> components) {
|
|
|
+ if (ObjectUtils.isNotEmpty(sceneInfo)) {
|
|
|
+ List<SceneComponent> oldComponents = sceneComponentDao.findBySceneInfoIdOrderBySortAsc(sceneInfo.getId());
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
+ if (ObjectUtils.isNotEmpty(oldComponents)) {
|
|
|
+ ids = oldComponents.stream().map(it -> it.getId()).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(components)) {
|
|
|
+ List<SceneComponent> componentEntitys = new ArrayList<>();
|
|
|
+ for (SceneComponentParam param : components) {
|
|
|
+ SceneComponent component = new SceneComponent();
|
|
|
+ BeanUtils.copyProperties(param, component);
|
|
|
+ componentEntitys.add(component);
|
|
|
+ if (StringUtils.isNotEmpty(param.getId()) && ids.contains(param.getId())) {
|
|
|
+ ids.remove(param.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sceneComponentDao.saveAll(componentEntitys);
|
|
|
+ }
|
|
|
+ // 删除不存在的
|
|
|
+ if (ObjectUtils.isNotEmpty(ids)) {
|
|
|
+ sceneComponentDao.deleteByIdIn(ids);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<SceneComponentModel> getSceneAllComponents(String sceneInfoId) {
|
|
|
+ List<SceneComponentModel> models = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotEmpty(sceneInfoId)) {
|
|
|
+ List<SceneComponent> components = sceneComponentDao.findBySceneInfoIdOrderBySortAsc(sceneInfoId);
|
|
|
+ if (ObjectUtils.isNotEmpty(components)) {
|
|
|
+ models = components.stream().map(this::toComponentModel).collect(Collectors.toUnmodifiableList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return models;
|
|
|
+ }
|
|
|
+
|
|
|
+ //--------------------------场景组件信息 end-----------------------
|
|
|
+
|
|
|
public SceneInfoModel toModel(SceneInfo entity) {
|
|
|
SceneInfoModel model = new SceneInfoModel();
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
@@ -125,4 +185,21 @@ public class SceneInfoService extends SuperService {
|
|
|
return model;
|
|
|
}
|
|
|
|
|
|
+ public SceneInfoAboutComModel toAboutComModel(SceneInfo entity) {
|
|
|
+ SceneInfoAboutComModel model = new SceneInfoAboutComModel();
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ model.setComponents(getSceneAllComponents(entity.getId()));
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public SceneComponentModel toComponentModel(SceneComponent entity) {
|
|
|
+ SceneComponentModel model = new SceneComponentModel();
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
}
|