package com.wgcloud.service; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.wgcloud.dto.SubtitleDto; import com.wgcloud.entity.HeathState; import com.wgcloud.mapper.HeathStateMapper; import com.wgcloud.util.DateUtil; import com.wgcloud.util.FormatUtil; import com.wgcloud.util.UUIDUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.ui.Model; import java.util.List; import java.util.Map; /** * @version v3.3 * @ClassName:HeathStateService.java * @author: http://www.wgstart.com * @date: 2021年1月16日 * @Description: HeathStateService.java * @Copyright: 2019-2021 wgcloud. All rights reserved. */ @Service public class HeathStateService { public PageInfo selectByParams(Map params, int currPage, int pageSize) throws Exception { PageHelper.startPage(currPage, pageSize); List list = heathStateMapper.selectByParams(params); PageInfo pageInfo = new PageInfo(list); return pageInfo; } public void save(HeathState HeathState) throws Exception { HeathState.setId(UUIDUtil.getUUID()); HeathState.setCreateTime(DateUtil.getNowTime()); heathStateMapper.save(HeathState); } public void saveRecord(List recordList) throws Exception { if (recordList.size() < 1) { return; } for (HeathState as : recordList) { as.setId(UUIDUtil.getUUID()); } heathStateMapper.insertList(recordList); } public int deleteById(String[] id) throws Exception { return heathStateMapper.deleteById(id); } public HeathState selectById(String id) throws Exception { return heathStateMapper.selectById(id); } public List selectAllByParams(Map params) throws Exception { return heathStateMapper.selectAllByParams(params); } public int deleteByDate(Map map) throws Exception { return heathStateMapper.deleteByDate(map); } /** * 设置图表的副标题,响应时间的最高、平均、最低值 * * @param model * @param heathStateList 数据列表 */ public void setSubtitle(Model model, List heathStateList) { //最高 int maxValue = 0; //最低 int minValue = 20000; //平均 Double avgValue = 0d; long sumValue = 0L; for (HeathState heathState : heathStateList) { if (null != heathState.getResTimes()) { if (heathState.getResTimes() > maxValue) { maxValue = heathState.getResTimes(); } if (heathState.getResTimes() < minValue) { minValue = heathState.getResTimes(); } sumValue += heathState.getResTimes(); } } if (heathStateList.size() > 0) { avgValue = sumValue / (double) heathStateList.size(); } else { minValue = 0; } SubtitleDto heathStateSubtitleDto = new SubtitleDto(); heathStateSubtitleDto.setAvgValue(FormatUtil.formatDouble(avgValue, 2) + ""); heathStateSubtitleDto.setMaxValue(maxValue + ""); heathStateSubtitleDto.setMinValue(minValue + ""); model.addAttribute("heathStateSubtitleDto", heathStateSubtitleDto); } @Autowired private HeathStateMapper heathStateMapper; }