|
|
@@ -0,0 +1,186 @@
|
|
|
+package com.zhongshu.card.server.core.service.org;
|
|
|
+
|
|
|
+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.org.userGroup.*;
|
|
|
+import com.zhongshu.card.client.type.DataState;
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationUserDao;
|
|
|
+import com.zhongshu.card.server.core.dao.org.UserGroupDao;
|
|
|
+import com.zhongshu.card.server.core.dao.org.UserGroupToUserDao;
|
|
|
+import com.zhongshu.card.server.core.domain.org.*;
|
|
|
+import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
|
|
|
+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;
|
|
|
+import org.springframework.util.Assert;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 权限时间段管理
|
|
|
+ *
|
|
|
+ * @author TRX
|
|
|
+ * @date 2024/12/19
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class UserGroupService extends SuperService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserGroupDao userGroupDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserGroupToUserDao userGroupToUserDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrganizationDao organizationDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserAccountServiceImpl userAccountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrganizationUserDao organizationUserDao;
|
|
|
+
|
|
|
+ public ResultContent saveInfo(UserGroupParam param) {
|
|
|
+ Assert.hasText(param.getProjectOid(), "projectOid不能为空");
|
|
|
+
|
|
|
+ UserGroup entity = null;
|
|
|
+ if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
+ entity = userGroupDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ initUpdateEntity(entity);
|
|
|
+ } else {
|
|
|
+ entity = new UserGroup();
|
|
|
+ initEntityNoCheckOid(entity);
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+ userGroupDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<Page<UserGroupModel>> page(UserGroupSearch param, Pageable pageable) {
|
|
|
+ String projectOid = param.getProjectOid();
|
|
|
+ Organization organization = organizationDao.findTopByOid(projectOid);
|
|
|
+ if (ObjectUtils.isEmpty(organization)) {
|
|
|
+ return ResultContent.buildFail("projectOid不存在");
|
|
|
+ }
|
|
|
+ Page<UserGroup> page = userGroupDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent deleteInfo(String id) {
|
|
|
+ UserGroup entity = userGroupDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ userGroupDao.delete(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<UserGroupModel> getDetailInfo(String id) {
|
|
|
+ UserGroup entity = userGroupDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(toModel(entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent changeState(String id, DataState state) {
|
|
|
+ UserGroup entity = userGroupDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ entity.setState(state);
|
|
|
+ userGroupDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ //-----------------------------分组关联的用户信息 start--------------------
|
|
|
+
|
|
|
+ public ResultContent groupBindUser(UserGroupToUserAddParam param) {
|
|
|
+ UserGroup userGroup = userGroupDao.findTopById(param.getGroupId());
|
|
|
+ if (ObjectUtils.isEmpty(userGroup)) {
|
|
|
+ return ResultContent.buildFail("分组不存在");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isEmpty(param.getOrgUserId())) {
|
|
|
+ return ResultContent.buildFail("用户信息为空");
|
|
|
+ }
|
|
|
+ List<OrganizationUser> list = organizationUserDao.findByIdIn(param.getOrgUserId());
|
|
|
+ if (ObjectUtils.isNotEmpty(list)) {
|
|
|
+ List<UserGroupToUser> saveList = new ArrayList<>();
|
|
|
+ for (OrganizationUser organizationUser : list) {
|
|
|
+ UserGroupToUser userGroupToUser = userGroupToUserDao.findTopByUserGroupAndOrganizationUser(userGroup, organizationUser);
|
|
|
+ if (ObjectUtils.isEmpty(userGroupToUser)) {
|
|
|
+ userGroupToUser = new UserGroupToUser();
|
|
|
+ userGroupToUser.setUserGroup(userGroup);
|
|
|
+ userGroupToUser.setOrganizationUser(organizationUser);
|
|
|
+
|
|
|
+ userGroupToUser.setProjectOid(userGroup.getProjectOid());
|
|
|
+ userGroupToUser.setOrgDataId(organizationUser.getId());
|
|
|
+ UserAccount userAccount = organizationUser.getUser();
|
|
|
+ userGroupToUser.setUserName(userAccount.getName());
|
|
|
+ userGroupToUser.setUserId(userAccount.getUserId());
|
|
|
+
|
|
|
+ initEntity(userGroupToUser);
|
|
|
+ saveList.add(userGroupToUser);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(saveList)) {
|
|
|
+ userGroupToUserDao.saveAll(saveList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent deleteGroupUserInfo(String id) {
|
|
|
+ UserGroupToUser entity = userGroupToUserDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ userGroupToUserDao.delete(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<Page<UserGroupToUserModel>> pageGroupUsers(UserGroupToUserSearch param, Pageable pageable) {
|
|
|
+ String projectOid = param.getProjectOid();
|
|
|
+ Organization organization = organizationDao.findTopByOid(projectOid);
|
|
|
+ if (ObjectUtils.isEmpty(organization)) {
|
|
|
+ return ResultContent.buildFail("projectOid不存在");
|
|
|
+ }
|
|
|
+ Page<UserGroupToUser> page = userGroupToUserDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toUserModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ //-----------------------------分组关联的用户信息 end----------------------
|
|
|
+
|
|
|
+ private UserGroupModel toModel(UserGroup entity) {
|
|
|
+ UserGroupModel model = new UserGroupModel();
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public UserGroupToUserModel toUserModel(UserGroupToUser entity) {
|
|
|
+ UserGroupToUserModel model = null;
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ model = new UserGroupToUserModel();
|
|
|
+ model.setId(entity.getId());
|
|
|
+
|
|
|
+ model.setUser(userAccountService.toOrgUserModel(entity.getOrganizationUser()));
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|