|
@@ -0,0 +1,121 @@
|
|
|
|
|
+//package seecoder.devcloud.web.service.impl.user;
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//import org.gitlab4j.api.GitLabApiException;
|
|
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+//import org.springframework.context.ApplicationContext;
|
|
|
|
|
+//import org.springframework.stereotype.Service;
|
|
|
|
|
+//import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+//import seecoder.devcloud.api.gitlab.GitlabApi;
|
|
|
|
|
+//import seecoder.devcloud.api.gitlab.model.GitlabGroup;
|
|
|
|
|
+//import seecoder.devcloud.common.exceptions.EntityNotFoundException;
|
|
|
|
|
+//import seecoder.devcloud.web.dao.user.GroupMapper;
|
|
|
|
|
+//import seecoder.devcloud.web.dao.user.UserMapper;
|
|
|
|
|
+//import seecoder.devcloud.web.enums.GroupType;
|
|
|
|
|
+//import seecoder.devcloud.web.po.user.Group;
|
|
|
|
|
+//import seecoder.devcloud.web.po.user.User;
|
|
|
|
|
+//import seecoder.devcloud.web.service.user.GroupService;
|
|
|
|
|
+//import seecoder.devcloud.web.vo.user.CustomUserDetails;
|
|
|
|
|
+//import seecoder.devcloud.web.vo.user.GroupVO;
|
|
|
|
|
+//
|
|
|
|
|
+//import java.util.ArrayList;
|
|
|
|
|
+//import java.util.List;
|
|
|
|
|
+//import java.util.UUID;
|
|
|
|
|
+//
|
|
|
|
|
+///**
|
|
|
|
|
+// * @ClassName GroupServiceImp
|
|
|
|
|
+// * @PackageName com.moekr.moocoder.logic.service.impl
|
|
|
|
|
+// * @Author sheen
|
|
|
|
|
+// * @Date 2019/1/9
|
|
|
|
|
+// * @Version 1.0
|
|
|
|
|
+// * @Description //TODO
|
|
|
|
|
+// **/
|
|
|
|
|
+//@Service
|
|
|
|
|
+//public class GroupServiceImp implements GroupService {
|
|
|
|
|
+// private final GroupMapper groupMapper;
|
|
|
|
|
+// private final UserMapper userMapper;
|
|
|
|
|
+// private final GitlabApi gitlabApi;
|
|
|
|
|
+// @Autowired
|
|
|
|
|
+// ApplicationContext applicationContext;
|
|
|
|
|
+//
|
|
|
|
|
+// @Autowired
|
|
|
|
|
+// public GroupServiceImp(GroupMapper groupMapper, UserMapper userMapper, GitlabApi gitlabApi) {
|
|
|
|
|
+// this.groupMapper = groupMapper;
|
|
|
|
|
+// this.userMapper = userMapper;
|
|
|
|
|
+// this.gitlabApi = gitlabApi;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// @Override
|
|
|
|
|
+// @Transactional
|
|
|
|
|
+// public GroupVO createGroup(String name, Integer courseId, CustomUserDetails userDetails) throws EntityNotFoundException {
|
|
|
|
|
+//
|
|
|
|
|
+// User user = userMapper.findByUsername(userDetails.getUsername());
|
|
|
|
|
+// final boolean isJoin = user.getGroup().stream()
|
|
|
|
|
+// .anyMatch(g -> g.getCourses().getId().equals(courseId));
|
|
|
|
|
+// if (isJoin) {
|
|
|
|
|
+// throw new RuntimeException("已经加入小组!");
|
|
|
|
|
+// }
|
|
|
|
|
+// //todo:判断学生是否选课
|
|
|
|
|
+// List<User> members = new ArrayList<>();
|
|
|
|
|
+// members.add(user);
|
|
|
|
|
+// GitlabGroup gitGroup;
|
|
|
|
|
+// try {
|
|
|
|
|
+// gitGroup = gitlabApi.createGroup(name);
|
|
|
|
|
+// gitlabApi.addMemberToGroup(gitGroup.getId(), user.getId());
|
|
|
|
|
+// } catch (GitLabApiException e) {
|
|
|
|
|
+// throw new RuntimeException("创建Group时发生异常[" + e.getMessage() + "]");
|
|
|
|
|
+// }
|
|
|
|
|
+// Group group = new Group();
|
|
|
|
|
+// group.setId(gitGroup.getId());
|
|
|
|
|
+// group.setMembers(members);
|
|
|
|
|
+// group.setName(name);
|
|
|
|
|
+// group.setNamespace(gitGroup.getNamespace());
|
|
|
|
|
+// group.setShareLink(UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
|
+// group.setType(GroupType.GROUP);
|
|
|
|
|
+// groupMapper.insert(group);
|
|
|
|
|
+// userMapper.save(user);
|
|
|
|
|
+// // 发出小组创建的事件
|
|
|
|
|
+// GroupVO groupVO = new GroupVO(group);
|
|
|
|
|
+// applicationContext.publishEvent(new GroupCreateEvent(this, courseId, groupVO));
|
|
|
|
|
+// return groupVO;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// @Override
|
|
|
|
|
+// @Transactional
|
|
|
|
|
+// public GroupVO addMember(String code, CustomUserDetails userDetails) throws EntityNotFoundException {
|
|
|
|
|
+// Group group = groupMapper.findGroupByShareLink(code);
|
|
|
|
|
+// if (group == null) {
|
|
|
|
|
+// throw new EntityNotFoundException("小组码错误!");
|
|
|
|
|
+// }
|
|
|
|
|
+// User user = userMapper.findByUsername(userDetails.getUsername());
|
|
|
|
|
+// final boolean haveCourse = user.getCourses().contains(group.getCourses());
|
|
|
|
|
+// if (!haveCourse) {
|
|
|
|
|
+// throw new RuntimeException("尚未加入课程!");
|
|
|
|
|
+// } else {
|
|
|
|
|
+// final boolean isJoin = user.getGroup().stream()
|
|
|
|
|
+// .anyMatch(g -> g.getCourses().getId().equals(group.getCourses().getId()));
|
|
|
|
|
+// if (isJoin) {
|
|
|
|
|
+// throw new RuntimeException("已经加入小组!");
|
|
|
|
|
+// }
|
|
|
|
|
+// group.getMembers().add(user);
|
|
|
|
|
+// try {
|
|
|
|
|
+// gitlabApi.addMemberToGroup(group.getId(), user.getId());
|
|
|
|
|
+// } catch (GitLabApiException e) {
|
|
|
|
|
+// throw new RuntimeException("将成员加入Group时发生异常[" + e.getMessage() + "]");
|
|
|
|
|
+// }
|
|
|
|
|
+// groupMapper.save(group);
|
|
|
|
|
+// userMapper.save(user);
|
|
|
|
|
+// return new GroupVO(group);
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public GroupVO getGroupsById(Integer groupId) {
|
|
|
|
|
+// Group get= groupMapper.findById(groupId).orElseGet(Group::new);
|
|
|
|
|
+//
|
|
|
|
|
+// return new GroupVO(get);
|
|
|
|
|
+// }
|
|
|
|
|
+//}
|