|
@@ -1,13 +1,28 @@
|
|
|
package com.zhongshu.card.server.core.service.scene;
|
|
package com.zhongshu.card.server.core.service.scene;
|
|
|
|
|
|
|
|
|
|
+import com.github.microservice.net.ResultContent;
|
|
|
|
|
+import com.github.microservice.net.ResultMessage;
|
|
|
|
|
+import com.zhongshu.card.client.model.base.SortParam;
|
|
|
|
|
+import com.zhongshu.card.client.model.scene.RoleBindSceneParam;
|
|
|
|
|
+import com.zhongshu.card.client.model.scene.RoleSceneInfoModel;
|
|
|
|
|
+import com.zhongshu.card.server.core.dao.org.RoleDao;
|
|
|
import com.zhongshu.card.server.core.dao.scene.ProjectSceneInfoDao;
|
|
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.RoleSceneInfoDao;
|
|
|
import com.zhongshu.card.server.core.dao.scene.SceneInfoDao;
|
|
import com.zhongshu.card.server.core.dao.scene.SceneInfoDao;
|
|
|
|
|
+import com.zhongshu.card.server.core.domain.org.Role;
|
|
|
|
|
+import com.zhongshu.card.server.core.domain.scene.ProjectSceneInfo;
|
|
|
|
|
+import com.zhongshu.card.server.core.domain.scene.RoleSceneInfo;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
|
|
+import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @author TRX
|
|
* @author TRX
|
|
|
* @date 2024/11/22
|
|
* @date 2024/11/22
|
|
@@ -25,4 +40,85 @@ public class RoleSceneInfoService extends SuperService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RoleSceneInfoDao roleSceneInfoDao;
|
|
private RoleSceneInfoDao roleSceneInfoDao;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RoleDao roleDao;
|
|
|
|
|
+
|
|
|
|
|
+ public ResultContent bindScene(RoleBindSceneParam param) {
|
|
|
|
|
+ ProjectSceneInfo entity = projectSceneInfoDao.findTopById(param.getId());
|
|
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
|
|
+ }
|
|
|
|
|
+ Role role = roleDao.findTopById(param.getRoleId());
|
|
|
|
|
+ if (ObjectUtils.isEmpty(role)) {
|
|
|
|
|
+ return ResultContent.buildFail("角色不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ RoleSceneInfo roleSceneInfo = roleSceneInfoDao.findTopByProjectSceneInfoIdAndRoleId(entity.getId(), role.getId());
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(roleSceneInfo)) {
|
|
|
|
|
+ return ResultContent.buildFail(String.format("角色已存在场景:%s", entity.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ roleSceneInfo = new RoleSceneInfo();
|
|
|
|
|
+ roleSceneInfo.setSceneInfo(entity.getSceneInfo());
|
|
|
|
|
+ roleSceneInfo.setSceneInfoId(entity.getId());
|
|
|
|
|
+
|
|
|
|
|
+ roleSceneInfo.setProjectSceneInfo(entity);
|
|
|
|
|
+ roleSceneInfo.setProjectSceneInfoId(entity.getId());
|
|
|
|
|
+
|
|
|
|
|
+ roleSceneInfo.setRole(role);
|
|
|
|
|
+ roleSceneInfo.setRoleId(role.getId());
|
|
|
|
|
+
|
|
|
|
|
+ long index = roleSceneInfoDao.countByRoleId(role.getId());
|
|
|
|
|
+ roleSceneInfo.setSort(index + 1);
|
|
|
|
|
+ roleSceneInfoDao.save(roleSceneInfo);
|
|
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public ResultContent<List<RoleSceneInfoModel>> list(String roleId) {
|
|
|
|
|
+ List<RoleSceneInfoModel> models = new ArrayList<>();
|
|
|
|
|
+ List<RoleSceneInfo> list = roleSceneInfoDao.findByRoleIdOrderBySortAsc(roleId);
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(list)) {
|
|
|
|
|
+ models = list.stream().map(this::toModel).collect(Collectors.toUnmodifiableList());
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultContent.buildSuccess(models);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public ResultContent<RoleSceneInfoModel> getDetailById(String id) {
|
|
|
|
|
+ RoleSceneInfo entity = roleSceneInfoDao.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) {
|
|
|
|
|
+ RoleSceneInfo entity = roleSceneInfoDao.findTopById(id);
|
|
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 判断是否可以删除
|
|
|
|
|
+ roleSceneInfoDao.delete(entity);
|
|
|
|
|
+ // 删除关联的信息
|
|
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 数据排序
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param param
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ResultContent sort(SortParam param) {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public RoleSceneInfoModel toModel(RoleSceneInfo entity) {
|
|
|
|
|
+ RoleSceneInfoModel model = new RoleSceneInfoModel();
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
|
|
+ }
|
|
|
|
|
+ return model;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|