mirror of https://github.com/elunez/eladmin
update
parent
40852235b2
commit
88477d18b2
|
@ -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<ServerDeploy, String>, JpaSpecificationExecutor {
|
||||
|
||||
@Modifying
|
||||
@Query(value = "update mnt_server set account_id = null where account_id = ?1", nativeQuery = true)
|
||||
void changeByAccount(String id);
|
||||
}
|
||||
|
|
|
@ -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}")
|
||||
|
|
|
@ -41,12 +41,6 @@ public interface DeployHistoryService {
|
|||
*/
|
||||
DeployHistoryDTO create(DeployHistory resources);
|
||||
|
||||
/**
|
||||
* update
|
||||
* @param resources
|
||||
*/
|
||||
void update(DeployHistory resources);
|
||||
|
||||
/**
|
||||
* delete
|
||||
* @param id
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<DeployHistory> 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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* 访问端口
|
||||
|
|
|
@ -18,7 +18,7 @@ public class ServerDTO implements Serializable {
|
|||
private String name;
|
||||
|
||||
// IP地址
|
||||
private String ip;
|
||||
private String address;
|
||||
|
||||
// 访问端口
|
||||
private Integer port;
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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"));
|
||||
|
|
Loading…
Reference in New Issue