|
@@ -3,31 +3,31 @@ package com.css.simulation.resource.home.service;
|
|
|
import api.common.pojo.common.PageVO;
|
|
|
import api.common.pojo.common.ResponseBodyVO;
|
|
|
import api.common.pojo.po.home.SystemServerPO;
|
|
|
-import api.common.pojo.vo.home.AccessVO;
|
|
|
-import api.common.pojo.vo.home.HardwareVO;
|
|
|
-import api.common.pojo.vo.home.ServiceVO;
|
|
|
-import api.common.pojo.vo.home.SystemServerVO;
|
|
|
+import api.common.pojo.vo.home.*;
|
|
|
import api.common.util.ObjectUtil;
|
|
|
import api.common.util.TimeUtil;
|
|
|
+import com.css.simulation.resource.common.utils.AuthUtil;
|
|
|
+import com.css.simulation.resource.common.utils.PageUtil;
|
|
|
import com.css.simulation.resource.feign.OauthClientService;
|
|
|
import com.css.simulation.resource.log.mapper.LogMapper;
|
|
|
-import com.css.simulation.resource.home.mapper.SystemServerMapper;
|
|
|
+import com.css.simulation.resource.home.mapper.HomePageMapper;
|
|
|
import com.css.simulation.resource.system.mapper.UserMapper;
|
|
|
-import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class HomePageService {
|
|
|
|
|
|
@Resource
|
|
|
- SystemServerMapper systemServerMapper;
|
|
|
+ HomePageMapper homePageMapper;
|
|
|
|
|
|
@Autowired
|
|
|
UserMapper userMapper;
|
|
@@ -40,16 +40,11 @@ public class HomePageService {
|
|
|
|
|
|
|
|
|
public ResponseBodyVO<HardwareVO> selectHardware() {
|
|
|
-
|
|
|
-
|
|
|
- List<SystemServerPO> systemServerPOList = systemServerMapper.selectAll();
|
|
|
-
|
|
|
-
|
|
|
+ List<SystemServerPO> systemServerPOList = homePageMapper.selectAll();
|
|
|
long memorySum = systemServerPOList.stream().mapToLong(SystemServerPO::getMemoryTotal).sum(); // 内存之和
|
|
|
long diskSum = systemServerPOList.stream().mapToLong(SystemServerPO::getDiskTotal).sum(); // 磁盘之和
|
|
|
long cpuSum = systemServerPOList.stream().mapToLong(SystemServerPO::getDiskTotal).sum(); // cpu线程数 之和
|
|
|
long gpuSum = systemServerPOList.stream().mapToLong(SystemServerPO::getDiskTotal).sum(); // 显存之和
|
|
|
-
|
|
|
HardwareVO build = HardwareVO.builder()
|
|
|
.serverNumber(systemServerPOList.size())
|
|
|
.memoryUsage((int) systemServerPOList.stream().mapToDouble(po -> po.getMemoryUsage() * po.getMemoryTotal() / memorySum).sum() + "%")
|
|
@@ -57,58 +52,26 @@ public class HomePageService {
|
|
|
.cpuUsage((int) systemServerPOList.stream().mapToDouble(po -> po.getCpuUsage() * po.getCpuTotal() / cpuSum).sum() + "%")
|
|
|
.gpuUsage((int) systemServerPOList.stream().mapToDouble(po -> po.getGpuUsage() * po.getGpuTotal() / gpuSum).sum() + "%")
|
|
|
.build();
|
|
|
-
|
|
|
return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, build);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
public ResponseBodyVO<ServiceVO> selectService() {
|
|
|
-
|
|
|
- List<SystemServerPO> systemServerPOList = systemServerMapper.selectAll();
|
|
|
+ List<SystemServerPO> systemServerPOList = homePageMapper.selectAll();
|
|
|
long count = systemServerPOList.stream().filter(system -> "gpu".equals(system.getServerType())).count();
|
|
|
-
|
|
|
ServiceVO build = ServiceVO.builder()
|
|
|
.userNumber(userMapper.selectCount())
|
|
|
.onlineNumber(oauthClientService.online().getInfo())
|
|
|
.simulationNodeNumber((int) count)
|
|
|
- .simulationLicenseNumber(systemServerMapper.selectSumOfTaskNumber())
|
|
|
+ .simulationLicenseNumber(homePageMapper.selectSumOfTaskNumber())
|
|
|
.dynamicsLicenseNumber(1) // 待定
|
|
|
.build();
|
|
|
-
|
|
|
return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, build);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public ResponseBodyVO<List<AccessVO>> selectAccess() {
|
|
|
- List<AccessVO> list = new ArrayList<>();
|
|
|
- String dateBegin = TimeUtil.getMinusDaysStr(6);
|
|
|
- List<AccessVO> listVo = logMapper.getAccessCount(dateBegin);
|
|
|
- boolean notNull = ObjectUtil.isNotNull(listVo);
|
|
|
- for (int i = 6; i >= 0; i--) {
|
|
|
- String date = TimeUtil.getMinusDaysStr(i);
|
|
|
- if(notNull){
|
|
|
- List<AccessVO> collect = listVo.stream().filter(v -> date.equals(v.getToDate())).collect(Collectors.toList());
|
|
|
- if(ObjectUtil.isNotNull(collect)){
|
|
|
- AccessVO vo = collect.get(0);
|
|
|
- list.add(vo);
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- AccessVO vo = new AccessVO();
|
|
|
- vo.setToDate(date);
|
|
|
- vo.setNum(0);
|
|
|
- list.add(vo);
|
|
|
- }
|
|
|
- return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, list);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public ResponseBodyVO<PageInfo<SystemServerVO>> selectServer(PageVO pageVO) {
|
|
|
-
|
|
|
- PageHelper.startPage(pageVO.getCurrentPage(), pageVO.getPageSize());
|
|
|
- List<SystemServerPO> systemServerPOList = systemServerMapper.selectAll();
|
|
|
+ PageUtil.setPageInfo(pageVO);
|
|
|
+ List<SystemServerPO> systemServerPOList = homePageMapper.selectAll();
|
|
|
List<SystemServerVO> systemServerVOList = new ArrayList<>();
|
|
|
systemServerPOList.forEach(po -> {
|
|
|
SystemServerVO vo = SystemServerVO.builder()
|
|
@@ -125,8 +88,56 @@ public class HomePageService {
|
|
|
.build();
|
|
|
systemServerVOList.add(vo);
|
|
|
});
|
|
|
-
|
|
|
return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, new PageInfo<>(systemServerVOList));
|
|
|
}
|
|
|
|
|
|
+ public List<LineChartVO> selectAccess() {
|
|
|
+ String dateBegin = TimeUtil.getMinusDaysStr(6);
|
|
|
+ List<LineChartVO> listVo = logMapper.getAccessCount(dateBegin);
|
|
|
+ List<LineChartVO> list = makeLineChartDate(listVo, 6);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<LineChartVO> selectRunTaskChart() {
|
|
|
+ Map<String,String> param = new HashMap();
|
|
|
+ param.put("dateBegin",TimeUtil.getMinusDaysStr(6));
|
|
|
+ param.put("createUserId", AuthUtil.getCurrentUserId());
|
|
|
+ List<LineChartVO> listVo = homePageMapper.selectRunTaskChart(param);
|
|
|
+ List<LineChartVO> list = makeLineChartDate(listVo, 6);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<LineChartVO> selectRunProjectChart() {
|
|
|
+ Map<String,String> param = new HashMap();
|
|
|
+ param.put("dateBegin",TimeUtil.getMinusDaysStr(6));
|
|
|
+ param.put("createUserId", AuthUtil.getCurrentUserId());
|
|
|
+ List<LineChartVO> listVo = homePageMapper.selectRunProjectChart(param);
|
|
|
+ List<LineChartVO> list = makeLineChartDate(listVo, 6);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建图标基础数据
|
|
|
+ */
|
|
|
+ private List<LineChartVO> makeLineChartDate(List<LineChartVO> listVo, int j) {
|
|
|
+ List<LineChartVO> list = new ArrayList<>();
|
|
|
+ boolean notNull = ObjectUtil.isNotNull(listVo);
|
|
|
+ for (int i = j; i >= 0; i--) {
|
|
|
+ String date = TimeUtil.getMinusDaysStr(i);
|
|
|
+ if(notNull){
|
|
|
+ List<LineChartVO> collect = listVo.stream().filter(v -> date.equals(v.getToDate())).collect(Collectors.toList());
|
|
|
+ if(ObjectUtil.isNotNull(collect)){
|
|
|
+ LineChartVO vo = collect.get(0);
|
|
|
+ list.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //创建新数据
|
|
|
+ LineChartVO vo = new LineChartVO();
|
|
|
+ vo.setToDate(date);
|
|
|
+ vo.setNum(0);
|
|
|
+ list.add(vo);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|