Browse Source

fix: 添加通过 id 增加成员的方法

刘一也 3 years ago
parent
commit
abd18ea963

+ 11 - 0
web/src/main/java/cn/seecoder/web/controller/project/ProjectController.java

@@ -73,6 +73,17 @@ public class ProjectController {
         return Response.buildSuccess();
     }
 
+    @ApiOperation(value = "给项目添加成员", httpMethod = "POST")
+    @PostMapping("/members/add")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "projectId", dataType = "int", paramType = "query"),
+            @ApiImplicitParam(name = "phone", dataType = "int", paramType = "query")
+    })
+    public Response addMember(@RequestParam("projectId") Integer projectId,@RequestParam("userId") Integer userId) throws ServiceException {
+        projectService.addMember(projectId, userId);
+        return Response.buildSuccess();
+    }
+
     @ApiOperation(value = "生成项目关联邀请码", httpMethod = "POST")
     @PostMapping("/relate/code")
     @ApiImplicitParams({

+ 22 - 0
web/src/main/java/cn/seecoder/web/service/impl/project/ProjectServiceImpl.java

@@ -135,6 +135,28 @@ public class ProjectServiceImpl implements ProjectService {
         }catch (Exception e){}
     }
 
+    @Override
+    public void addMember(Integer projectId, Integer userId) throws ServiceException {
+//        Integer userId = userMapper.selectIdByPhone(phone);
+        if(userId == null){
+            throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "该手机号不存在对应用户");
+        }
+        try {
+            seecoderGitlabApi.addAuthorization(projectId, userId, AccessLevelForm.MASTER);
+        } catch (Exception e) {
+            throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "添加项目权限失败", e);
+        }
+        //ANA 日志需要打出加入的成员信息
+        try{
+            JSONObject object = new JSONObject();
+            object.put("project_id",projectId);
+            object.put("user_id",userId);
+
+            String data = JSONObject.toJSONString(object);
+            LogTrackingUtil.log(data, OpType.ADD_MEMBER);
+        }catch (Exception e){}
+    }
+
     @Override
     public List<UserVO> getProjectMembers(Integer projectId) throws ServiceException {
         List<Integer> userIds;

+ 2 - 0
web/src/main/java/cn/seecoder/web/service/project/ProjectService.java

@@ -30,6 +30,8 @@ public interface ProjectService {
 
     void addMember(Integer projectId, String phone) throws ServiceException;
 
+    void addMember(Integer projectId, Integer userId) throws ServiceException;
+
     List<UserVO> getProjectMembers(Integer projectId) throws ServiceException;
 
     /**