diff --git a/server/src/main/java/io/wdd/server/beans/po/AppInfoPO.java b/server/src/main/java/io/wdd/server/beans/po/AppInfoPO.java index a6e4726..23eb835 100644 --- a/server/src/main/java/io/wdd/server/beans/po/AppInfoPO.java +++ b/server/src/main/java/io/wdd/server/beans/po/AppInfoPO.java @@ -1,11 +1,12 @@ package io.wdd.server.beans.po; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.*; + import java.io.Serializable; +import java.time.LocalDateTime; import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; /** @@ -44,12 +45,13 @@ public class AppInfoPO implements Serializable { /** * */ - private Date createTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @TableField(fill = FieldFill.INSERT) + private LocalDateTime createTime; - /** - * - */ - private Date updateTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @TableField(fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; /** * diff --git a/server/src/main/java/io/wdd/server/controller/ServerController.java b/server/src/main/java/io/wdd/server/controller/ServerController.java index f705a77..0e6fd66 100644 --- a/server/src/main/java/io/wdd/server/controller/ServerController.java +++ b/server/src/main/java/io/wdd/server/controller/ServerController.java @@ -6,6 +6,7 @@ import io.wdd.wddcommon.utils.R; import io.wdd.server.beans.po.ServerInfoPO; import io.wdd.server.beans.vo.ServerInfoVO; import io.wdd.server.coreService.CoreServerService; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.lang.Nullable; import org.springframework.validation.annotation.Validated; @@ -21,52 +22,52 @@ public class ServerController { CoreServerService coreServerService; @GetMapping("/all") - public R getAllServerInfo() { + public R serverGetAll() { - return R.ok(coreServerService.getServerInfoList()); + return R.ok(coreServerService.serverGetAll()); } @GetMapping("/allIncludeDelete") - public R getAllServerInfoIncludeDelete() { + public R serverGetAllIncludeDelete() { - return R.ok(coreServerService.getServerInfoListIncludeDelete()); + return R.ok(coreServerService.serverGetAllIncludeDelete()); } @PostMapping("/single") - public R getSingleServerInfo( + public R serverGetSingle( @RequestParam(value = "serverIPv4") @Nullable String ipv4, @RequestParam(value = "serverName") @Nullable String serverName, @RequestParam(value = "serverLocation") @Nullable String serverLocation ) { - return R.ok(coreServerService.getServerInfoSingle(serverName, ipv4, serverLocation)); + return R.ok(coreServerService.serverGetSingle(serverName, ipv4, serverLocation)); } - @PostMapping("/newServer") - public R createServerInfo(@RequestBody @Validated ServerInfoVO serverInfoVO) { + @PostMapping("/serverCreate") + public R serverCreate(@RequestBody @Validated ServerInfoVO serverInfoVO) { - if (coreServerService.createServerInfo(serverInfoVO)) { + if (coreServerService.serverCreate(serverInfoVO)) { return R.ok("Create Server Success !"); } return R.failed("Create Server Failed !"); } - @PostMapping("/updateServerInfo") - public R updateServerInfo(@RequestBody ServerInfoPO serverInfoPO) { + @PostMapping("/serverUpdate") + public R serverUpdate(@RequestBody ServerInfoPO serverInfoPO) { - if (coreServerService.updateServerInfo(serverInfoPO)) { + if (coreServerService.serverUpdate(serverInfoPO)) { return R.ok("Server info update successfully !"); } return R.failed("Server info update failed !"); } - @PostMapping("/deleteServer") - public R deleteServer( + @PostMapping("/serverDelete") + public R serverDelete( @RequestParam(value = "serverId") @Nullable Long serverId, @RequestParam(value = "serverName") @Nullable String serverName) { - if (coreServerService.deleteServer(serverId, serverName)) { + if (coreServerService.serverDelete(serverId, serverName)) { R.ok("Delete Server Successfully !"); } @@ -75,17 +76,55 @@ public class ServerController { /* - * Associated with appInfo - * server 1______n app - * */ + * Associated with appInfo + * server 1______n app + * */ - @GetMapping("/getAllApp") - public R> getAllAppInfo( + // get + @GetMapping("/appGetAll") + public R> appGetAll( @RequestParam(value = "serverId", required = true) Long serverId - ){ + ) { - return R.ok(coreServerService.getAllAppInfo(serverId)); + return R.ok(coreServerService.appGetAll(serverId)); } + // create + @PostMapping("/appCreate") + public R appCreate( + @RequestParam(value = "serverId", required = true) Long serverId, + @RequestBody @Validated AppInfoVO appInfoVO + ) { + + AppInfoVO newAppForServer = coreServerService.appCreate(serverId, appInfoVO); + + if (ObjectUtils.isNotEmpty(newAppForServer)) { + return R.ok(newAppForServer); + } + + System.out.println("create new app failed !"); + + return R.failed(null); + } + + // delete + @PostMapping("/appDelete") + public R appDelete( + @RequestParam(value = "serverId", required = true) Long serverId, + @RequestParam(value = "appId", required = true) Long appId + ) { + + if (coreServerService.appDelete(serverId, appId)) { + return R.ok("delete app successfully!"); + } + + return R.failed("delete app unsuccessful"); + + } + + // modify -- just modify the appInfo is ok + + + } diff --git a/server/src/main/java/io/wdd/server/coreService/CoreServerService.java b/server/src/main/java/io/wdd/server/coreService/CoreServerService.java index 9b9b592..5a01aba 100644 --- a/server/src/main/java/io/wdd/server/coreService/CoreServerService.java +++ b/server/src/main/java/io/wdd/server/coreService/CoreServerService.java @@ -8,17 +8,21 @@ import java.util.List; public interface CoreServerService { - List getServerInfoSingle(String serverName, String ipv4, String serverLocation); + List serverGetSingle(String serverName, String ipv4, String serverLocation); - List getServerInfoList(); + List serverGetAll(); - List getServerInfoListIncludeDelete(); + List serverGetAllIncludeDelete(); - boolean createServerInfo(ServerInfoVO serverInfoVO); + boolean serverCreate(ServerInfoVO serverInfoVO); - boolean updateServerInfo(ServerInfoPO serverInfoPO); + boolean serverUpdate(ServerInfoPO serverInfoPO); - boolean deleteServer(Long serverId, String serverName); + boolean serverDelete(Long serverId, String serverName); - List getAllAppInfo(Long serverId); + List appGetAll(Long serverId); + + AppInfoVO appCreate(Long serverId, AppInfoVO appInfoVO); + + boolean appDelete(Long serverId, Long appId); } diff --git a/server/src/main/java/io/wdd/server/coreService/impl/CoreServerServiceImpl.java b/server/src/main/java/io/wdd/server/coreService/impl/CoreServerServiceImpl.java index 6e9d3a7..fa0d3fd 100644 --- a/server/src/main/java/io/wdd/server/coreService/impl/CoreServerServiceImpl.java +++ b/server/src/main/java/io/wdd/server/coreService/impl/CoreServerServiceImpl.java @@ -18,10 +18,13 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; import javax.annotation.Resource; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @@ -40,7 +43,7 @@ public class CoreServerServiceImpl implements CoreServerService { @Override - public List getServerInfoSingle(String serverName, String ipv4, String serverLocation) { + public List serverGetSingle(String serverName, String ipv4, String serverLocation) { // ignore if deleted ! return new LambdaQueryChainWrapper<>(serverInfoService.getBaseMapper()) @@ -52,7 +55,7 @@ public class CoreServerServiceImpl implements CoreServerService { } @Override - public List getServerInfoList() { + public List serverGetAll() { List serverInfoPOWithOutDelete = serverInfoService.list(); @@ -61,7 +64,7 @@ public class CoreServerServiceImpl implements CoreServerService { } @Override - public List getServerInfoListIncludeDelete() { + public List serverGetAllIncludeDelete() { // todo how to solve the problem? // this.covertServerPOtoVO(serverInfoService.getAll()); @@ -70,7 +73,7 @@ public class CoreServerServiceImpl implements CoreServerService { } @Override - public boolean createServerInfo(ServerInfoVO serverInfoVO) { + public boolean serverCreate(ServerInfoVO serverInfoVO) { ServerInfoPO serverInfoPO = new ServerInfoPO(); BeanUtils.copyProperties(serverInfoVO, serverInfoPO); @@ -79,7 +82,7 @@ public class CoreServerServiceImpl implements CoreServerService { } @Override - public boolean updateServerInfo(ServerInfoPO serverInfoPO) { + public boolean serverUpdate(ServerInfoPO serverInfoPO) { if (serverInfoPO.getServerId() == null) { return false; @@ -91,7 +94,7 @@ public class CoreServerServiceImpl implements CoreServerService { } @Override - public boolean deleteServer(Long serverId, String serverName) { + public boolean serverDelete(Long serverId, String serverName) { if (serverId == null && StringUtils.isBlank(serverName)) { return false; @@ -107,24 +110,58 @@ public class CoreServerServiceImpl implements CoreServerService { } @Override - public List getAllAppInfo(Long serverId) { + public List appGetAll(Long serverId) { // serverInfo --- server_app_relation --- appInfo List serverAppRelationPOList = new LambdaQueryChainWrapper(serverAppRelationService.getBaseMapper()).eq(ServerAppRelationPO::getServerId, serverId).list(); + Assert.notEmpty(serverAppRelationPOList,"No server find"); // query the app info with specific server id List appInfoPOList = appInfoService.listByIds(serverAppRelationPOList.stream().map( - serverAppRelationPO -> { - return serverAppRelationPO.getAppId(); - } + serverAppRelationPO -> serverAppRelationPO.getAppId() ).collect(Collectors.toList())); return EntityUtils.cvToTarget(appInfoPOList,AppInfoVO.class); } + @Override + @Transactional + public AppInfoVO appCreate(Long serverId, AppInfoVO appInfoVO) { + + Assert.notNull(serverInfoService.getById(serverId),"server not find, can't create a app"); + + // 1- save appInfo itself + AppInfoPO appInfoPO = EntityUtils.cvToTarget(appInfoVO, AppInfoPO.class); + appInfoService.save(appInfoPO); + + // 2. create the relation + ServerAppRelationPO relationPO = new ServerAppRelationPO(); + relationPO.setServerId(serverId); + relationPO.setAppId(appInfoPO.getAppId()); + serverAppRelationService.save(relationPO); + + + return EntityUtils.cvToTarget(appInfoPO, AppInfoVO.class); + } + + @Override + @Transactional + public boolean appDelete(Long serverId, Long appId) { + + Assert.notNull(serverInfoService.getById(serverId),"server not find, can't delete a app"); + Assert.notNull(appInfoService.getById(appId),"app not find, can't delete a app"); + + // 1. delete the relation + serverAppRelationService.removeById(serverId); + // 2. delete the app + appInfoService.removeById(appId); + + return true; + } + private List covertServerPOtoVO(List serverInfoPOList) { if (null == serverInfoPOList || serverInfoPOList.size() == 0) {