|
|
@@ -0,0 +1,112 @@
|
|
|
+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.*;
|
|
|
+import com.zhongshu.card.client.type.DataState;
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
+import com.zhongshu.card.server.core.dao.scene.ProjectSceneInfoDao;
|
|
|
+import com.zhongshu.card.server.core.dao.scene.RoleSceneInfoDao;
|
|
|
+import com.zhongshu.card.server.core.dao.scene.SceneInfoDao;
|
|
|
+import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
+import com.zhongshu.card.server.core.domain.scene.ProjectSceneInfo;
|
|
|
+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;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author TRX
|
|
|
+ * @date 2024/11/22
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class ProjectSceneInfoService extends SuperService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SceneInfoDao sceneInfoDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProjectSceneInfoDao projectSceneInfoDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RoleSceneInfoDao roleSceneInfoDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrganizationDao organizationDao;
|
|
|
+
|
|
|
+ public ResultContent bindScene(ProjectBindSceneParam param) {
|
|
|
+ SceneInfo entity = sceneInfoDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ Organization organization = organizationDao.findTopByOid(param.getProjectOid());
|
|
|
+ if (ObjectUtils.isEmpty(organization)) {
|
|
|
+ return ResultContent.buildFail("项目不存在");
|
|
|
+ }
|
|
|
+ ProjectSceneInfo projectSceneInfo = projectSceneInfoDao.findTopBySceneInfoAndProjectOid(entity, param.getProjectOid());
|
|
|
+ if (ObjectUtils.isNotEmpty(projectSceneInfo)) {
|
|
|
+ return ResultContent.buildFail(String.format("项目已存在场景:%s", entity.getName()));
|
|
|
+ }
|
|
|
+ projectSceneInfo = new ProjectSceneInfo();
|
|
|
+ projectSceneInfo.setSceneInfo(entity);
|
|
|
+ projectSceneInfo.setSceneInfoId(entity.getId());
|
|
|
+ projectSceneInfo.setName(entity.getName());
|
|
|
+ projectSceneInfo.setSceneType(entity.getSceneType());
|
|
|
+ projectSceneInfo.setSceneState(entity.getState());
|
|
|
+ projectSceneInfoDao.save(projectSceneInfo);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<Page<ProjectSceneInfoModel>> page(ProjectSceneInfoSearch param, Pageable pageable) {
|
|
|
+ Page<ProjectSceneInfo> page = projectSceneInfoDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<ProjectSceneInfoModel> getDetailById(String id) {
|
|
|
+ ProjectSceneInfo entity = projectSceneInfoDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(toModel(entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent deleteById(String id) {
|
|
|
+ ProjectSceneInfo entity = projectSceneInfoDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ // 判断是否可以删除
|
|
|
+ projectSceneInfoDao.delete(entity);
|
|
|
+
|
|
|
+ // 删除关联的信息
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent changeState(String id, DataState state) {
|
|
|
+ ProjectSceneInfo entity = projectSceneInfoDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ entity.setState(state);
|
|
|
+ projectSceneInfoDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ProjectSceneInfoModel toModel(ProjectSceneInfo entity) {
|
|
|
+ ProjectSceneInfoModel model = new ProjectSceneInfoModel();
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|