From 88477d18b2cda7d66626f74f47d71e0e81fdb00c Mon Sep 17 00:00:00 2001 From: dqjdda <201507802@qq.com> Date: Sun, 24 Nov 2019 17:08:44 +0800 Subject: [PATCH] update --- .../mnt/repository/ServerDeployRepository.java | 6 ++++++ .../mnt/rest/DeployHistoryController.java | 17 ----------------- .../mnt/service/DeployHistoryService.java | 6 ------ .../service/dto/DeployHistoryQueryCriteria.java | 9 ++------- .../mnt/service/dto/ServerDeployDTO.java | 17 +++++++++++++++++ .../service/impl/DeployHistoryServiceImpl.java | 10 ---------- .../service/impl/ServerAccountServiceImpl.java | 8 +++++++- .../zhengjie/modules/monitor/domain/Server.java | 4 ++-- .../modules/monitor/service/dto/ServerDTO.java | 2 +- .../service/dto/ServerQueryCriteria.java | 10 +++------- .../monitor/service/impl/ServerServiceImpl.java | 2 +- 11 files changed, 39 insertions(+), 52 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/ServerDeployRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/ServerDeployRepository.java index 4681216d..a4c3a98e 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/ServerDeployRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/ServerDeployRepository.java @@ -3,10 +3,16 @@ package me.zhengjie.modules.mnt.repository; import me.zhengjie.modules.mnt.domain.ServerDeploy; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; /** * @author zhanghouying * @date 2019-08-24 */ public interface ServerDeployRepository extends JpaRepository, JpaSpecificationExecutor { + + @Modifying + @Query(value = "update mnt_server set account_id = null where account_id = ?1", nativeQuery = true) + void changeByAccount(String id); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployHistoryController.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployHistoryController.java index e43f7c7c..ad12bad7 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployHistoryController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployHistoryController.java @@ -34,23 +34,6 @@ public class DeployHistoryController { return new ResponseEntity(deployhistoryService.queryAll(criteria,pageable),HttpStatus.OK); } - @Log("新增DeployHistory") - @ApiOperation(value = "新增DeployHistory") - @PostMapping - @PreAuthorize("@el.check('deployHistory:add')") - public ResponseEntity create(@Validated @RequestBody DeployHistory resources){ - return new ResponseEntity(deployhistoryService.create(resources),HttpStatus.CREATED); - } - - @Log("修改DeployHistory") - @ApiOperation(value = "修改DeployHistory") - @PutMapping - @PreAuthorize("@el.check('deployHistory:edit')") - public ResponseEntity update(@Validated @RequestBody DeployHistory resources){ - deployhistoryService.update(resources); - return new ResponseEntity(HttpStatus.NO_CONTENT); - } - @Log("删除DeployHistory") @ApiOperation(value = "删除DeployHistory") @DeleteMapping(value = "/{id}") diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/DeployHistoryService.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/DeployHistoryService.java index b9f16b63..2dbb6d82 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/DeployHistoryService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/DeployHistoryService.java @@ -41,12 +41,6 @@ public interface DeployHistoryService { */ DeployHistoryDTO create(DeployHistory resources); - /** - * update - * @param resources - */ - void update(DeployHistory resources); - /** * delete * @param id diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployHistoryQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployHistoryQueryCriteria.java index e869e471..fefd1740 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployHistoryQueryCriteria.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployHistoryQueryCriteria.java @@ -13,11 +13,6 @@ public class DeployHistoryQueryCriteria{ /** * 精确 */ - @Query - private String deployId; - /** - * 模糊 - */ - @Query(type = Query.Type.INNER_LIKE) - private String deployDate; + @Query(blurry = "appName,ip,deployUser,deployId") + private String blurry; } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/ServerDeployDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/ServerDeployDTO.java index e17c08f1..a6752996 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/ServerDeployDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/ServerDeployDTO.java @@ -1,6 +1,10 @@ package me.zhengjie.modules.mnt.service.dto; import lombok.Data; +import me.zhengjie.modules.mnt.service.ServerAccountService; +import me.zhengjie.modules.mnt.service.ServerDeployService; +import me.zhengjie.utils.SpringContextHolder; + import java.io.Serializable; @@ -20,4 +24,17 @@ public class ServerDeployDTO implements Serializable { * 服务器账号 */ private String accountId; + + /** + * 账号名称 + */ + private String accountName; + + public String getAccountName() { + if(accountId != null){ + ServerAccountService serverAccountService = SpringContextHolder.getBean(ServerAccountService.class); + return serverAccountService.findById(accountId).getName(); + } + return accountName; + } } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployHistoryServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployHistoryServiceImpl.java index 465cba74..de36d2a5 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployHistoryServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployHistoryServiceImpl.java @@ -58,16 +58,6 @@ public class DeployHistoryServiceImpl implements DeployHistoryService { return deployhistoryMapper.toDto(deployhistoryRepository.save(resources)); } - @Override - @Transactional(rollbackFor = Exception.class) - public void update(DeployHistory resources) { - Optional optionalDeployHistory = deployhistoryRepository.findById(resources.getId()); - ValidationUtil.isNull( optionalDeployHistory,"DeployHistory","id",resources.getId()); - DeployHistory deployhistory = optionalDeployHistory.get(); - deployhistory.copy(resources); - deployhistoryRepository.save(deployhistory); - } - @Override @Transactional(rollbackFor = Exception.class) public void delete(String id) { diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/ServerAccountServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/ServerAccountServiceImpl.java index f54ad903..4c549a89 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/ServerAccountServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/ServerAccountServiceImpl.java @@ -3,6 +3,7 @@ package me.zhengjie.modules.mnt.service.impl; import cn.hutool.core.util.IdUtil; import me.zhengjie.modules.mnt.domain.ServerAccount; import me.zhengjie.modules.mnt.repository.ServerAccountRepository; +import me.zhengjie.modules.mnt.repository.ServerDeployRepository; import me.zhengjie.modules.mnt.service.ServerAccountService; import me.zhengjie.modules.mnt.service.dto.ServerAccountDTO; import me.zhengjie.modules.mnt.service.dto.ServerAccountQueryCriteria; @@ -10,6 +11,7 @@ import me.zhengjie.modules.mnt.service.mapper.ServerAccountMapper; import me.zhengjie.utils.PageUtil; import me.zhengjie.utils.QueryHelp; import me.zhengjie.utils.ValidationUtil; +import org.hibernate.mapping.IdGenerator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -30,6 +32,9 @@ public class ServerAccountServiceImpl implements ServerAccountService { @Autowired private ServerAccountRepository serverAccountRepository; + @Autowired + private ServerDeployRepository serverDeployRepository; + @Autowired private ServerAccountMapper serverAccountMapper; @@ -54,7 +59,7 @@ public class ServerAccountServiceImpl implements ServerAccountService { @Override @Transactional(rollbackFor = Exception.class) public ServerAccountDTO create(ServerAccount resources) { - resources.setId(IdUtil.simpleUUID()); + resources.setId(IdUtil.getSnowflake(0, 0).toString()); return serverAccountMapper.toDto(serverAccountRepository.save(resources)); } @@ -72,5 +77,6 @@ public class ServerAccountServiceImpl implements ServerAccountService { @Transactional(rollbackFor = Exception.class) public void delete(String id) { serverAccountRepository.deleteById(id); + serverDeployRepository.changeByAccount(id); } } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/monitor/domain/Server.java b/eladmin-system/src/main/java/me/zhengjie/modules/monitor/domain/Server.java index 0d52d972..bcfca370 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/monitor/domain/Server.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/monitor/domain/Server.java @@ -32,8 +32,8 @@ public class Server implements Serializable { /** * IP地址 */ - @Column(name = "ip",nullable = false) - private String ip; + @Column(name = "address",nullable = false) + private String address; /** * 访问端口 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/dto/ServerDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/dto/ServerDTO.java index f7494e4f..f7845a56 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/dto/ServerDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/dto/ServerDTO.java @@ -18,7 +18,7 @@ public class ServerDTO implements Serializable { private String name; // IP地址 - private String ip; + private String address; // 访问端口 private Integer port; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/dto/ServerQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/dto/ServerQueryCriteria.java index 587a3d8a..355747bf 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/dto/ServerQueryCriteria.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/dto/ServerQueryCriteria.java @@ -11,10 +11,6 @@ import me.zhengjie.annotation.Query; public class ServerQueryCriteria{ // 模糊 - @Query(type = Query.Type.INNER_LIKE) - private String name; - - // 模糊 - @Query(type = Query.Type.INNER_LIKE) - private String ip; -} + @Query(blurry = "name,address") + private String blurry; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/impl/ServerServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/impl/ServerServiceImpl.java index 765aaecf..2bc72782 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/impl/ServerServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/impl/ServerServiceImpl.java @@ -43,7 +43,7 @@ public class ServerServiceImpl implements ServerService { page.forEach(server -> { try { server.setState("1"); - String url = String.format("http://%s:%d/api/serverMonitor",server.getIp(),server.getPort()); + String url = String.format("http://%s:%d/api/serverMonitor",server.getAddress(),server.getPort()); String res = HttpUtil.get(url,1000); JSONObject obj = JSONObject.parseObject(res); server.setCpuRate(obj.getDouble("cpuRate"));