[server] server app relation accomplished
This commit is contained in:
@@ -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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -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<List> getAllServerInfo() {
|
||||
public R<List> serverGetAll() {
|
||||
|
||||
return R.ok(coreServerService.getServerInfoList());
|
||||
return R.ok(coreServerService.serverGetAll());
|
||||
}
|
||||
|
||||
@GetMapping("/allIncludeDelete")
|
||||
public R<List> getAllServerInfoIncludeDelete() {
|
||||
public R<List> 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<String> 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<List<AppInfoVO>> getAllAppInfo(
|
||||
// get
|
||||
@GetMapping("/appGetAll")
|
||||
public R<List<AppInfoVO>> 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<AppInfoVO> 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<String> 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
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,17 +8,21 @@ import java.util.List;
|
||||
|
||||
public interface CoreServerService {
|
||||
|
||||
List<ServerInfoPO> getServerInfoSingle(String serverName, String ipv4, String serverLocation);
|
||||
List<ServerInfoPO> serverGetSingle(String serverName, String ipv4, String serverLocation);
|
||||
|
||||
List<ServerInfoVO> getServerInfoList();
|
||||
List<ServerInfoVO> serverGetAll();
|
||||
|
||||
List<ServerInfoVO> getServerInfoListIncludeDelete();
|
||||
List<ServerInfoVO> 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<AppInfoVO> getAllAppInfo(Long serverId);
|
||||
List<AppInfoVO> appGetAll(Long serverId);
|
||||
|
||||
AppInfoVO appCreate(Long serverId, AppInfoVO appInfoVO);
|
||||
|
||||
boolean appDelete(Long serverId, Long appId);
|
||||
}
|
||||
|
||||
@@ -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<ServerInfoPO> getServerInfoSingle(String serverName, String ipv4, String serverLocation) {
|
||||
public List<ServerInfoPO> 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<ServerInfoVO> getServerInfoList() {
|
||||
public List<ServerInfoVO> serverGetAll() {
|
||||
|
||||
List<ServerInfoPO> serverInfoPOWithOutDelete = serverInfoService.list();
|
||||
|
||||
@@ -61,7 +64,7 @@ public class CoreServerServiceImpl implements CoreServerService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServerInfoVO> getServerInfoListIncludeDelete() {
|
||||
public List<ServerInfoVO> 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<AppInfoVO> getAllAppInfo(Long serverId) {
|
||||
public List<AppInfoVO> appGetAll(Long serverId) {
|
||||
|
||||
// serverInfo --- server_app_relation --- appInfo
|
||||
|
||||
List<ServerAppRelationPO> serverAppRelationPOList = new LambdaQueryChainWrapper<ServerAppRelationPO>(serverAppRelationService.getBaseMapper()).eq(ServerAppRelationPO::getServerId, serverId).list();
|
||||
|
||||
Assert.notEmpty(serverAppRelationPOList,"No server find");
|
||||
|
||||
// query the app info with specific server id
|
||||
List<AppInfoPO> 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<ServerInfoVO> covertServerPOtoVO(List<ServerInfoPO> serverInfoPOList) {
|
||||
|
||||
if (null == serverInfoPOList || serverInfoPOList.size() == 0) {
|
||||
|
||||
Reference in New Issue
Block a user