Sfoglia il codice sorgente

环境维护者返回数据结构修改

luoshi 2 anni fa
parent
commit
02f2cb17b1

+ 15 - 6
src/main/java/com/qmth/ops/api/controller/admin/EnvController.java

@@ -4,12 +4,14 @@ import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.ops.api.constants.OpsApiConstants;
 import com.qmth.ops.api.dto.CodeNameBean;
+import com.qmth.ops.api.dto.EnvVO;
 import com.qmth.ops.api.security.AdminSession;
 import com.qmth.ops.biz.domain.Env;
 import com.qmth.ops.biz.domain.EnvType;
 import com.qmth.ops.biz.domain.Role;
 import com.qmth.ops.biz.service.AppService;
 import com.qmth.ops.biz.service.EnvService;
+import com.qmth.ops.biz.service.UserService;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.annotation.Resource;
 import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @RestController
 @RequestMapping(OpsApiConstants.ADMIN_URI_PREFIX + "/env")
@@ -29,6 +32,9 @@ public class EnvController {
     @Resource
     private EnvService envService;
 
+    @Resource
+    private UserService userService;
+
     @RequestMapping("/types")
     @Aac(auth = BOOL.FALSE)
     public Object types() {
@@ -36,21 +42,24 @@ public class EnvController {
     }
 
     @PostMapping("/insert")
-    public Env insert(@RequestAttribute AdminSession adminSession, Env env) {
+    public EnvVO insert(@RequestAttribute AdminSession adminSession, Env env) {
         adminSession.validateRole(Role.ADMIN);
-        return envService.insert(env);
+        env = envService.insert(env);
+        return new EnvVO(env, userService.getById(env.getUserId()));
     }
 
     @PostMapping("/update")
-    public Env update(@RequestAttribute AdminSession adminSession, Env env) {
+    public EnvVO update(@RequestAttribute AdminSession adminSession, Env env) {
         adminSession.validateRole(Role.ADMIN);
-        return envService.update(env);
+        env = envService.update(env);
+        return new EnvVO(env, userService.getById(env.getUserId()));
     }
 
     @PostMapping("/list")
-    public List<Env> list(@RequestAttribute AdminSession adminSession, Long appId) {
+    public List<EnvVO> list(@RequestAttribute AdminSession adminSession, Long appId) {
         adminSession.validateApp(appService.getById(appId));
-        return envService.list(appId);
+        return envService.list(appId).stream().map(env -> new EnvVO(env, userService.getById(env.getUserId())))
+                .collect(Collectors.toList());
     }
 
 }

+ 66 - 0
src/main/java/com/qmth/ops/api/dto/EnvVO.java

@@ -0,0 +1,66 @@
+package com.qmth.ops.api.dto;
+
+import com.qmth.ops.biz.domain.Env;
+import com.qmth.ops.biz.domain.EnvType;
+import com.qmth.ops.biz.domain.User;
+
+public class EnvVO {
+
+    private Long id;
+
+    private String code;
+
+    private String name;
+
+    private EnvType type;
+
+    private UserVO user;
+
+    public EnvVO(Env env, User user) {
+        this.id = env.getId();
+        this.code = env.getCode();
+        this.name = env.getName();
+        this.type = env.getType();
+        this.user = new UserVO(user);
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public EnvType getType() {
+        return type;
+    }
+
+    public void setType(EnvType type) {
+        this.type = type;
+    }
+
+    public UserVO getUser() {
+        return user;
+    }
+
+    public void setUser(UserVO user) {
+        this.user = user;
+    }
+}

+ 54 - 0
src/main/java/com/qmth/ops/api/dto/UserVO.java

@@ -0,0 +1,54 @@
+package com.qmth.ops.api.dto;
+
+import com.qmth.ops.biz.domain.Role;
+import com.qmth.ops.biz.domain.User;
+
+public class UserVO {
+
+    private Long id;
+
+    private String loginName;
+
+    private String name;
+
+    private Role[] role;
+
+    public UserVO(User user) {
+        this.id = user.getId();
+        this.loginName = user.getLoginName();
+        this.name = user.getName();
+        this.role = user.getRole();
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getLoginName() {
+        return loginName;
+    }
+
+    public void setLoginName(String loginName) {
+        this.loginName = loginName;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Role[] getRole() {
+        return role;
+    }
+
+    public void setRole(Role[] role) {
+        this.role = role;
+    }
+}

+ 2 - 0
src/main/java/com/qmth/ops/biz/service/EnvService.java

@@ -29,6 +29,8 @@ public class EnvService extends ServiceImpl<EnvDao, Env> {
     public Env update(Env env) {
         envDao.update(env, new LambdaUpdateWrapper<Env>().set(env.getCode() != null, Env::getCode, env.getCode())
                 .set(env.getName() != null, Env::getName, env.getName())
+                .set(env.getType() != null, Env::getType, env.getType())
+                .set(env.getUserId() != null, Env::getUserId, env.getUserId())
                 .set(Env::getUpdateTime, System.currentTimeMillis()).eq(Env::getId, env.getId()));
         return envDao.selectById(env.getId());
     }