|
|
@@ -1,27 +1,31 @@
|
|
|
package com.xunmei.system.service.impl;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
-import com.alibaba.fastjson2.JSONReader;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xunmei.common.core.util.BeanHelper;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
+import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
+import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
+import com.xunmei.system.domain.SysServer;
|
|
|
+import com.xunmei.system.dto.server.SysServerEditDto;
|
|
|
+import com.xunmei.system.dto.server.SysServerPageDto;
|
|
|
+import com.xunmei.system.mapper.SysServerMapper;
|
|
|
+import com.xunmei.system.service.ISysServerService;
|
|
|
import com.xunmei.system.vo.server.CheckListVo;
|
|
|
+import com.xunmei.system.vo.server.SysServerPageVo;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
-import com.xunmei.system.mapper.SysServerMapper;
|
|
|
-import com.xunmei.system.domain.SysServer;
|
|
|
-import com.xunmei.system.service.ISysServerService;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 服务器维护Service业务层处理
|
|
|
@@ -36,19 +40,10 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|
|
private SysServerMapper sysServerMapper;
|
|
|
|
|
|
@Override
|
|
|
- public TableDataInfo<SysServer> selectPage(SysServer sysServer) {
|
|
|
- //未删除
|
|
|
- Page<SysServer> page;
|
|
|
- //分页
|
|
|
- if (sysServer.getPageNum() != null && sysServer.getPageSize() != null) {
|
|
|
- page = new Page<>(sysServer.getPageNum(), sysServer.getPageSize());
|
|
|
- } else {
|
|
|
- page = new Page<>();
|
|
|
- }
|
|
|
- //查询条件
|
|
|
- QueryWrapper<SysServer> query = new QueryWrapper<>(sysServer);
|
|
|
+ public TableDataInfo<SysServerPageVo> selectPage(SysServerPageDto req) {
|
|
|
+
|
|
|
//获取数据
|
|
|
- page = sysServerMapper.selectPage(page, query);
|
|
|
+ Page<SysServerPageVo> page = sysServerMapper.selectPageData(req.getPageRequest(), req);
|
|
|
//抓换为TableDataInfo适配前端
|
|
|
return TableDataInfo.build(page);
|
|
|
|
|
|
@@ -60,7 +55,7 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|
|
SysServer server = this.selectSysServerById(sysServer.getId());
|
|
|
StringBuffer baseUrl = new StringBuffer("http://");
|
|
|
baseUrl.append(server.getServerIp()).append(":")
|
|
|
- .append(server.getServerPort());
|
|
|
+ .append(server.getServerPort());
|
|
|
String rootUrl = baseUrl.toString();
|
|
|
|
|
|
String getServices = "/result/list?size=10000¤t=1";
|
|
|
@@ -105,28 +100,30 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
|
|
|
return sysServerMapper.selectList(new QueryWrapper<>(sysServer));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 新增服务器维护
|
|
|
- *
|
|
|
- * @param sysServer 服务器维护
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
@Override
|
|
|
- public int insertSysServer(SysServer sysServer) {
|
|
|
- sysServer.setCreateTime(DateUtils.getNowDate());
|
|
|
- return sysServerMapper.insert(sysServer);
|
|
|
+ public boolean checkIpRepeat(String ip, Long id) {
|
|
|
+ final Long count = lambdaQuery().eq(SysServer::getServerIp, ip).ne(id != null, SysServer::getId, id).count();
|
|
|
+ return count == 0;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 修改服务器维护
|
|
|
- *
|
|
|
- * @param sysServer 服务器维护
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
@Override
|
|
|
- public int updateSysServer(SysServer sysServer) {
|
|
|
- sysServer.setUpdateTime(DateUtils.getNowDate());
|
|
|
- return sysServerMapper.updateById(sysServer);
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int editSysServer(SysServerEditDto req) {
|
|
|
+ if (!checkIpRepeat(req.getServerIp(), req.getId())) {
|
|
|
+ throw new RuntimeException("ip重复");
|
|
|
+ }
|
|
|
+ if (req.getId() == null) {
|
|
|
+ final SysServer sysServer = BeanHelper.copyProperties(req, SysServer.class);
|
|
|
+ sysServer.setCreateTime(DateUtils.getNowDate());
|
|
|
+ sysServer.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ sysServer.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getUsername());
|
|
|
+ sysServer.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getUsername());
|
|
|
+ return sysServerMapper.insertSysServer(sysServer);
|
|
|
+ }
|
|
|
+ final SysServer server = getById(req.getId());
|
|
|
+ BeanUtils.copyProperties(req, server);
|
|
|
+ server.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ return sysServerMapper.updateById(server);
|
|
|
}
|
|
|
|
|
|
/**
|