wangsixiang
4 months ago
26 changed files with 1003 additions and 157 deletions
@ -0,0 +1,330 @@ |
|||
package com.zc.business.controller; |
|||
|
|||
import com.alibaba.excel.util.DateUtils; |
|||
import com.github.pagehelper.util.StringUtil; |
|||
import com.ruoyi.common.annotation.Log; |
|||
import com.ruoyi.common.core.controller.BaseController; |
|||
import com.ruoyi.common.core.domain.AjaxResult; |
|||
import com.ruoyi.common.core.page.TableDataInfo; |
|||
import com.ruoyi.common.core.redis.RedisCache; |
|||
import com.ruoyi.common.enums.BusinessType; |
|||
import com.ruoyi.common.utils.StringUtils; |
|||
import com.ruoyi.common.utils.poi.ExcelUtil; |
|||
import com.zc.business.constant.RedisKeyConstants; |
|||
import com.zc.business.domain.*; |
|||
import com.zc.business.enums.UniversalEnum; |
|||
import com.zc.business.service.IDcRoadSectionService; |
|||
import com.zc.business.service.IOnlineLogService; |
|||
import com.zc.business.service.IOnlineSumService; |
|||
import com.zc.business.service.impl.DcDeviceServiceImpl; |
|||
import com.zc.business.utils.MathUtil; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.checkerframework.checker.units.qual.A; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
import org.springframework.util.ObjectUtils; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.annotation.Resource; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.math.BigDecimal; |
|||
import java.math.RoundingMode; |
|||
import java.time.LocalDate; |
|||
import java.time.LocalDateTime; |
|||
import java.time.format.DateTimeFormatter; |
|||
import java.time.temporal.ChronoUnit; |
|||
import java.util.*; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Api(tags = "设备在线监测") |
|||
@RestController |
|||
@RequestMapping("/system/status") |
|||
public class DcDeviceOnlineController extends BaseController { |
|||
@Autowired |
|||
private DcDeviceServiceImpl dcDeviceService; |
|||
@Resource |
|||
private RedisCache redisCache; |
|||
@Resource |
|||
private IDcRoadSectionService dcRoadSectionService; |
|||
@Resource |
|||
private IOnlineSumService onlineSumService; |
|||
@Resource |
|||
private IOnlineLogService onlineLogService; |
|||
|
|||
private static final String ORDERRULE = "orderRule";//排序策略key
|
|||
|
|||
@ApiOperation("设备状态列表按时间和类型") |
|||
@GetMapping("/tablist") |
|||
public TableDataInfo getTabList(@RequestParam("type") String[] deviceTypes, |
|||
@RequestParam(required = false) String orderByField, |
|||
@RequestParam(required = false) String orderDirection, |
|||
@RequestParam(required = false) String searchValue) { |
|||
if(ObjectUtils.isEmpty(deviceTypes)) { |
|||
return getDataTable(new ArrayList<>()); |
|||
} |
|||
if(StringUtil.isEmpty(orderByField) ||"time".equals(orderByField)) { |
|||
orderByField = "online_rate"; |
|||
} |
|||
startPage(); |
|||
List<OnlineSum> sums = onlineSumService.queryByDeviceTypesOfToday(deviceTypes, orderByField, orderDirection, searchValue); |
|||
Map<String,OnlineSum> onlineSumMap = redisCache.getCacheMap(RedisKeyConstants.DEVICE_ONLINE); |
|||
String date = LocalDate.now().toString(); |
|||
for (OnlineSum sum : sums) { |
|||
String deviceId = sum.getDeviceId().toString(); |
|||
String hKey = date+":"+deviceId; |
|||
OnlineSum online = onlineSumMap.get(hKey); |
|||
if(ObjectUtils.isEmpty(online)) { |
|||
continue; |
|||
} |
|||
sum.setLastOnlineTime(onlineSumMap.get(hKey).getLastOnlineTime()); |
|||
sum.setDeviceStatus(onlineSumMap.get(hKey).getDeviceStatus()); |
|||
} |
|||
return getDataTable(sums); |
|||
} |
|||
//按时间划分设备柱状图
|
|||
@ApiOperation("设备状态柱状图按时间和类型") |
|||
@GetMapping("/list") |
|||
public AjaxResult getStatusList( |
|||
@RequestParam("startTime") String startTime, |
|||
@RequestParam("time") String endTime, |
|||
@RequestParam("type") String[] types, |
|||
@RequestParam(value = "direction",required = false) String direction) { |
|||
Map<String, Map<String, String>> maps = new HashMap<>(); |
|||
LocalDateTime start = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
|||
LocalDateTime end = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
|||
List<OnlineSum> onlineSums = onlineSumService.queryByDeviceTypeAndDate(types, start.toLocalDate(), end.toLocalDate(),direction); |
|||
Map<String,List<OnlineSum>> stringListMap = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType)); |
|||
for (String type : types) { |
|||
Map<String, String> map = new HashMap<>(); |
|||
List<OnlineSum> listOfType = stringListMap.getOrDefault(type, new ArrayList<>()); |
|||
Map<LocalDate,List<OnlineSum>> localDateListMap = listOfType.stream().collect(Collectors.groupingBy(OnlineSum::getStatisticalDate)); |
|||
for (LocalDate date = start.toLocalDate(); date.isBefore(end.toLocalDate().plusDays(1)); date=date.plusDays(1)) { |
|||
List<OnlineSum> dayList = localDateListMap.getOrDefault(date, new ArrayList<>()); |
|||
map.put(date.toString(), MathUtil.doubleTwoDecimalStr(dayList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0))+"%"); |
|||
} |
|||
maps.put(type, new TreeMap<>(map)); |
|||
} |
|||
return AjaxResult.success(maps); |
|||
} |
|||
|
|||
/** |
|||
* 查询设备在线率 |
|||
* @param deviceId |
|||
* @return |
|||
*/ |
|||
@ApiOperation("根据设备Id查询折线图数据") |
|||
@GetMapping("/deviceStatusList/{deviceId}") |
|||
public AjaxResult getDeviceStatusList(@PathVariable Long deviceId) { |
|||
LocalDate startDate = LocalDate.now().minusDays(30); |
|||
LocalDate endDate = LocalDate.now(); |
|||
List<OnlineSum> onlineSums = onlineSumService.queryByDateRangeOfDevice(deviceId, startDate, endDate); |
|||
if(onlineSums.isEmpty()) { |
|||
return AjaxResult.success(UniversalEnum.NO_DATA_AVAILABLE.getValue()); |
|||
} |
|||
Map<String, Object> map = new HashMap<>(); |
|||
for (OnlineSum onlineSum : onlineSums) { |
|||
map.put(onlineSum.getStatisticalDate().toString(), onlineSum.getOnlineRate()); |
|||
} |
|||
return AjaxResult.success(new TreeMap<>(map)); |
|||
} |
|||
|
|||
/** |
|||
* 缓存类型卡片排序规则 |
|||
* @param rule 排序规则 |
|||
* @return AjaxResult |
|||
*/ |
|||
@ApiOperation("缓存类型卡片排序规则") |
|||
@GetMapping("/rule") |
|||
public AjaxResult setRule(String rule) { |
|||
redisCache.setCacheObject(ORDERRULE, rule); |
|||
return AjaxResult.success(); |
|||
} |
|||
|
|||
/** |
|||
* 设备分类当日在线率 |
|||
*/ |
|||
@ApiOperation("设备分类当日在线率") |
|||
@GetMapping("/type") |
|||
public AjaxResult getTypeList() { |
|||
String LOST_RATE = "lostRate";//丢包率
|
|||
String SUCESS_RATE = "sucessRate";//在线率
|
|||
String FAIL_RATE = "failRate";//离线率
|
|||
String SUM_USE_STATE = "sumUseState";//在用数
|
|||
String SUM = "sum";//总数
|
|||
String RULE = "rule"; |
|||
String All_TYPE = "全部设备"; |
|||
String SORT_RULE = "排序规则"; |
|||
Map<String, Object> returnMap = new HashMap<>(); |
|||
List<OnlineSum> onlineSums = onlineSumService.queryByDateOfDeviceType(LocalDate.now()); |
|||
List<DcDevice> dcDeviceList = dcDeviceService.list(); |
|||
List<DcDevice> useDeviceList = dcDeviceList.stream().filter(device ->device.getUseState()!=null && device.getUseState()==1).collect(Collectors.toList()); |
|||
//分类总数
|
|||
Map<String, Long> totalCounts = dcDeviceList.stream() |
|||
.collect(Collectors.groupingBy(DcDevice::getRealType, Collectors.counting())); |
|||
//分类在用数
|
|||
Map<String,Long> useCounts = useDeviceList.stream() |
|||
.collect(Collectors.groupingBy(DcDevice::getRealType, Collectors.counting())); |
|||
Map<String,List<OnlineSum>> typeSumGroup = onlineSums.stream().collect(Collectors.groupingBy(OnlineSum::getDeviceType)); |
|||
DeviceType.toMap().forEach((k,v) -> { |
|||
Map<String,Object> itemMap = new HashMap<>(); |
|||
itemMap.put(SUM,totalCounts.getOrDefault(k,0L).toString());//总数
|
|||
itemMap.put(SUM_USE_STATE,useCounts.getOrDefault(k,0L).toString());//在用数
|
|||
List<OnlineSum> onlineSumsOfType = typeSumGroup.getOrDefault(k,new ArrayList<>()); |
|||
itemMap.put(LOST_RATE, MathUtil.doubleTwoDecimalStr(onlineSumsOfType.stream().mapToDouble(OnlineSum::getLossRate).average().orElse(0.0))+"%"); |
|||
itemMap.put(SUCESS_RATE,MathUtil.doubleTwoDecimalStr(onlineSumsOfType.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0))+"%"); |
|||
itemMap.put(FAIL_RATE,MathUtil.doubleTwoDecimalStr(onlineSumsOfType.stream().mapToDouble(OnlineSum::getOfflineRate).average().orElse(0.0))+"%"); |
|||
returnMap.put(v,itemMap); |
|||
}); |
|||
Map<String, Object> allMap = new HashMap<>(); |
|||
allMap.put(SUM,dcDeviceList.size()+"");//总数
|
|||
allMap.put(SUM_USE_STATE,useDeviceList.size()+"");//在用数
|
|||
allMap.put(LOST_RATE,MathUtil.doubleTwoDecimalStr(onlineSums.stream().mapToDouble(OnlineSum::getLossRate).average().orElse(0.0))+"%"); |
|||
allMap.put(SUCESS_RATE,MathUtil.doubleTwoDecimalStr(onlineSums.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0))+"%"); |
|||
allMap.put(FAIL_RATE,MathUtil.doubleTwoDecimalStr(onlineSums.stream().mapToDouble(OnlineSum::getOfflineRate).average().orElse(0.0))+"%"); |
|||
returnMap.put(All_TYPE,allMap); |
|||
Map<String, Object> sortMap = new TreeMap<>(); |
|||
String orderRule = redisCache.getCacheObject(ORDERRULE); |
|||
if (StringUtil.isNotEmpty(orderRule)) { |
|||
sortMap.put(RULE, orderRule); |
|||
} else { |
|||
sortMap.put(RULE, DeviceType.defaultSortRule()); |
|||
} |
|||
returnMap.put(SORT_RULE, sortMap); |
|||
return AjaxResult.success(returnMap); |
|||
} |
|||
|
|||
//按路段统计设备在线率
|
|||
@ApiOperation("设备状态列表按路段") |
|||
@GetMapping("/section") |
|||
public AjaxResult getSectionList() { |
|||
String LOST_RATE = "lostRate";//丢包率
|
|||
String SUCESS_RATE = "sucessRate";//在线率
|
|||
String FAIL_RATE = "failRate";//离线率
|
|||
String SUM_USE_STATE = "sumUseState";//在用数
|
|||
String SUM = "sum";//总数
|
|||
Map<String, Object> returnMap = new HashMap<>(); |
|||
List<Map<String, Object>> deviceOfRoad = dcDeviceService.selectDeviceOfRoad(); |
|||
List<DcRoadSection> dcRoadSections = dcRoadSectionService.selectDcRoadSectionList(new DcRoadSection()); |
|||
List<OnlineSum> onlineSums = onlineSumService.queryByDateOfRoad(LocalDate.now()); |
|||
Map<String,Long> totalRoadCounts = deviceOfRoad.stream() |
|||
.collect(Collectors.groupingBy(m -> m.get("roadId").toString(),Collectors.counting())); |
|||
Map<String,Long> useRoadCounts = deviceOfRoad.stream().filter(dr -> dr.get("useStata")!=null && dr.get("useStata").toString().equals("1")) |
|||
.collect(Collectors.groupingBy(m -> m.get("roadId").toString(),Collectors.counting())); |
|||
Map<Long,List<OnlineSum>> onLineSumMap = onlineSums.stream().filter(onlineSum -> onlineSum.getRoadId() != null).collect(Collectors.groupingBy(OnlineSum::getRoadId)); |
|||
for(DcRoadSection dcRoadSection : dcRoadSections) { |
|||
Map<String,Object> itemMap = new HashMap<>(); |
|||
itemMap.put(SUM,totalRoadCounts.getOrDefault(dcRoadSection.getId().toString(),0L).toString());//总数
|
|||
itemMap.put(SUM_USE_STATE,useRoadCounts.getOrDefault(dcRoadSection.getId().toString(),0L).toString());//在用数
|
|||
List<OnlineSum> onlineSumsByRoad = onLineSumMap.getOrDefault(dcRoadSection.getId(),new ArrayList<>()); |
|||
itemMap.put(LOST_RATE, MathUtil.doubleTwoDecimalStr(onlineSumsByRoad.stream().mapToDouble(OnlineSum::getLossRate).average().orElse(0.0))+"%"); |
|||
itemMap.put(SUCESS_RATE,MathUtil.doubleTwoDecimalStr(onlineSumsByRoad.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0))+"%"); |
|||
itemMap.put(FAIL_RATE,MathUtil.doubleTwoDecimalStr(onlineSumsByRoad.stream().mapToDouble(OnlineSum::getOfflineRate).average().orElse(0.0))+"%"); |
|||
returnMap.put(dcRoadSection.getSectionName(),itemMap); |
|||
} |
|||
return AjaxResult.success(returnMap); |
|||
} |
|||
|
|||
@ApiOperation("查询设备网络日志") |
|||
@GetMapping("/networkLogTable") |
|||
public TableDataInfo networkLogTable( |
|||
@RequestParam("deviceId") Long deviceId, |
|||
@RequestParam("queryDate")String queryDate) { |
|||
LocalDateTime start = LocalDateTime.parse(queryDate + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
|||
LocalDateTime end = LocalDateTime.now(); |
|||
startPage(); |
|||
List<OnlineLog> onlineLogs = onlineLogService.queryByDateAndDevice(start,end,deviceId); |
|||
return getDataTable(onlineLogs); |
|||
} |
|||
@ApiOperation("查询设备网络日志") |
|||
@GetMapping("/networkLogEcharts") |
|||
public AjaxResult networkLogEcharts( |
|||
@RequestParam("deviceId") Long deviceId, |
|||
@RequestParam("queryDate")String queryDate) { |
|||
String LOST_RATE = "lostRate";//丢包率
|
|||
String RTT_AVG = "rttAvg";//平均往返时延
|
|||
String MONITOR_TIME = "time";//监控时间
|
|||
LocalDateTime start = LocalDateTime.parse(queryDate + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
|||
LocalDateTime end = LocalDateTime.now(); |
|||
List<OnlineLog> onlineLogs = onlineLogService.queryByDateAndDevice(start,end,deviceId); |
|||
Map<String,Object> returnMap = new HashMap<>(); |
|||
List<String> xAxis = new ArrayList<>(); |
|||
List<Double> lossRate = new ArrayList<>(); |
|||
List<Double> rttAvg = new ArrayList<>(); |
|||
onlineLogs.stream().sorted(Comparator.comparing(OnlineLog::getMonitorTime)).forEach(onlineLog -> { |
|||
xAxis.add(onlineLog.getMonitorTime().format(DateTimeFormatter.ofPattern("HH:mm"))); |
|||
lossRate.add(onlineLog.getLossRate()); |
|||
rttAvg.add(onlineLog.getRttAvg()); |
|||
}); |
|||
returnMap.put(LOST_RATE,lossRate); |
|||
returnMap.put(RTT_AVG,rttAvg); |
|||
returnMap.put(MONITOR_TIME,xAxis); |
|||
return AjaxResult.success(returnMap); |
|||
} |
|||
enum DeviceType { |
|||
GUN_CAMERA("1-1","高清网络枪型固定摄像机"), |
|||
SPHERICAL_CAMERA("1-2", "高清网络球形摄像机"), |
|||
SPHERICAL_CAMERA_BRIDGE("1-3", "桥下高清网络球形摄像机"), |
|||
PANORAMIC_CAMERA_360("1-4", "360°全景摄像机"), |
|||
PANORAMIC_CAMERA_180("1-5", "180°全景摄像机"), |
|||
GANTRY_VMS("2-1", "门架式可变信息标志"), |
|||
STATION_FRONT_VMS("2-2", "站前可变信息标志"), |
|||
AWNING_VMS("2-3", "雨棚可变信息标志"), |
|||
//站前悬臂式可变信息标志2-4
|
|||
MET_DET("3", "气象检测器"), |
|||
//出口诱导灯4
|
|||
VOICE_BROADCAST("5", "路段语音广播系统"), |
|||
GUARDRAIL_COLLISION("6", "护栏碰撞预警系统"), |
|||
MMW_RADAR("7", "毫米波雷达"), |
|||
CA_EARLY("8", "合流区预警系统"), |
|||
//智慧锥桶9
|
|||
LASER_FATIGUE_AWAKENING("10", "激光疲劳唤醒"), |
|||
TRAFFIC_SURVEY_STATION("11", "一类交通量调查站"), |
|||
DRIVING_GUIDANCE("12", "智能行车诱导系统"), |
|||
DEVICE_BOX("13", "智能设备箱"), |
|||
//光纤在线监测14
|
|||
SOLAR_PANEL("15", "太阳能板"), |
|||
REMOTE_COMPUTER("16", "远端机"); |
|||
private final String value; |
|||
private final String description; |
|||
|
|||
public String getValue() { |
|||
return value; |
|||
} |
|||
|
|||
public String getDescription() { |
|||
return description; |
|||
} |
|||
|
|||
DeviceType(String value, String description) { |
|||
this.value = value; |
|||
this.description = description; |
|||
} |
|||
|
|||
/** |
|||
* map转换{value,description} |
|||
* @return 转换后的map |
|||
*/ |
|||
static Map<String,String> toMap(){ |
|||
Map<String, String> map = new HashMap<>(); |
|||
for (DeviceType deviceType : DeviceType.values()) { |
|||
map.put(deviceType.getValue(), deviceType.getDescription()); |
|||
} |
|||
return map; |
|||
} |
|||
|
|||
/** |
|||
* 默认排序规则 |
|||
* @return 排序规则 |
|||
*/ |
|||
static String defaultSortRule(){ |
|||
StringBuilder stringBuilder = new StringBuilder(); |
|||
String ALL_TYPE = "全部设备"; |
|||
stringBuilder.append(ALL_TYPE); |
|||
for (DeviceType deviceType : DeviceType.values()) { |
|||
stringBuilder.append(",").append(deviceType.getDescription()); |
|||
} |
|||
return stringBuilder.toString(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,57 @@ |
|||
package com.zc.business.enums; |
|||
|
|||
public enum NetworkQuality { |
|||
GOOD("优"), |
|||
FAIR("良"), |
|||
NORMAL("一般"), |
|||
BAD("差"); |
|||
private final String value; |
|||
public String getValue() { |
|||
return value; |
|||
} |
|||
NetworkQuality(String value) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public static String ofNetworkQuality(double offlineRate,double rttAvg) { |
|||
double score = calculateScore(offlineRate,rttAvg); |
|||
if (score <= 10 && score >= 9) { |
|||
return GOOD.getValue(); |
|||
}else if (score < 9 && score >= 7) { |
|||
return FAIR.getValue(); |
|||
}else if(score >=6 && score < 7){ |
|||
return NORMAL.getValue(); |
|||
}else { |
|||
return BAD.getValue(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 计算网络质量分(权重:丢包率0.5、平均往返时延0.5) |
|||
* @param offlineRate 丢包率 |
|||
* @param rttAvg 平均往返时延 |
|||
* @return 分数 |
|||
*/ |
|||
private static double calculateScore(double offlineRate,double rttAvg){ |
|||
double offScore ,rttScore; |
|||
if (offlineRate <= 2) { |
|||
offScore = 10; |
|||
}else if (offlineRate <= 10 && offlineRate > 2){ |
|||
offScore = 5; |
|||
}else if (offlineRate <= 15 && offlineRate > 10){ |
|||
offScore = 4; |
|||
}else { |
|||
offScore = 1; |
|||
} |
|||
if (rttAvg <= 30 && rttAvg > 0) { |
|||
rttScore = 10; |
|||
}else if (rttAvg <= 50 && rttAvg > 30){ |
|||
rttScore = 5; |
|||
}else if (rttAvg <= 100 && rttAvg > 50){ |
|||
rttScore = 4; |
|||
}else { |
|||
rttScore = 1; |
|||
} |
|||
return offScore*0.5+rttScore*0.5; |
|||
} |
|||
} |
@ -1,9 +1,18 @@ |
|||
package com.zc.business.mapper; |
|||
|
|||
import com.zc.business.domain.OnlineLog; |
|||
import org.apache.ibatis.annotations.Param; |
|||
|
|||
import java.time.LocalDateTime; |
|||
import java.util.List; |
|||
|
|||
public interface OnlineLogMapper { |
|||
int addBatch(List<OnlineLog> onlineLogs); |
|||
List<OnlineLog> queryByDate( |
|||
@Param("startTime") LocalDateTime startTime, |
|||
@Param("endTime") LocalDateTime endTime); |
|||
List<OnlineLog> queryByDateAndDevice( |
|||
@Param("startTime")LocalDateTime startTime, |
|||
@Param("endTime")LocalDateTime endTime, |
|||
@Param("deviceId")Long deviceId); |
|||
} |
|||
|
@ -0,0 +1,26 @@ |
|||
package com.zc.business.mapper; |
|||
|
|||
import com.zc.business.domain.OnlineSum; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import java.time.LocalDate; |
|||
import java.util.List; |
|||
|
|||
public interface OnlineSumMapper { |
|||
int duplicateKeyUpdate(OnlineSum onlineSum); |
|||
List<OnlineSum> queryByDateRangeOfDevice(@Param("deviceId") Long deviceId, |
|||
@Param("startDate") LocalDate startDate, |
|||
@Param("endDate") LocalDate endDate); |
|||
List<OnlineSum> queryByDeviceTypeAndDate( |
|||
@Param("types") String[] types, |
|||
@Param("startDate") LocalDate startDate, |
|||
@Param("endDate") LocalDate endDate, |
|||
@Param("direction") String direction |
|||
); |
|||
List<OnlineSum> queryByDateOfDeviceType(@Param("queryDate") LocalDate queryDate); |
|||
List<OnlineSum> queryByDateOfRoad(@Param("queryDate") LocalDate queryDate); |
|||
List<OnlineSum> queryByDeviceTypesOfToday( |
|||
@Param("types") String[] deviceTypes, |
|||
@Param("orderByField") String orderByField, |
|||
@Param("orderDirection") String orderDirection, |
|||
@Param("searchValue") String searchValue); |
|||
} |
@ -0,0 +1,27 @@ |
|||
package com.zc.business.service; |
|||
|
|||
import com.zc.business.domain.OnlineSum; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.util.List; |
|||
|
|||
public interface IOnlineSumService { |
|||
int duplicateKeyUpdate(OnlineSum onlineSum); |
|||
|
|||
List<OnlineSum> queryByDateRangeOfDevice(Long deviceId, LocalDate startDate, LocalDate endDate); |
|||
|
|||
List<OnlineSum> queryByDeviceTypeAndDate( |
|||
String[] deviceType, |
|||
LocalDate startDate, |
|||
LocalDate endDate, |
|||
String direction |
|||
); |
|||
List<OnlineSum> queryByDateOfDeviceType(LocalDate queryDate); |
|||
List<OnlineSum> queryByDateOfRoad(LocalDate queryDate); |
|||
|
|||
List<OnlineSum> queryByDeviceTypesOfToday( |
|||
String[] deviceTypes, |
|||
String orderByField, |
|||
String orderDirection, |
|||
String searchValue); |
|||
} |
@ -0,0 +1,55 @@ |
|||
package com.zc.business.service.impl; |
|||
|
|||
import com.zc.business.domain.OnlineSum; |
|||
import com.zc.business.mapper.OnlineSumMapper; |
|||
import com.zc.business.service.IOnlineSumService; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.time.LocalDate; |
|||
import java.util.List; |
|||
|
|||
@Service |
|||
public class OnlineSumServiceImpl implements IOnlineSumService { |
|||
@Resource |
|||
OnlineSumMapper onlineSumMapper; |
|||
@Override |
|||
public int duplicateKeyUpdate(OnlineSum onlineSum) { |
|||
return onlineSumMapper.duplicateKeyUpdate(onlineSum); |
|||
} |
|||
@Override |
|||
public List<OnlineSum> queryByDateRangeOfDevice( |
|||
Long deviceId, |
|||
LocalDate startDate, |
|||
LocalDate endDate) { |
|||
return onlineSumMapper.queryByDateRangeOfDevice(deviceId, startDate, endDate); |
|||
} |
|||
|
|||
@Override |
|||
public List<OnlineSum> queryByDeviceTypeAndDate( |
|||
String[] deviceType, |
|||
LocalDate startDate, |
|||
LocalDate endDate, |
|||
String direction) { |
|||
return onlineSumMapper.queryByDeviceTypeAndDate(deviceType, startDate, endDate, direction); |
|||
} |
|||
|
|||
@Override |
|||
public List<OnlineSum> queryByDateOfDeviceType(LocalDate queryDate) { |
|||
return onlineSumMapper.queryByDateOfDeviceType(queryDate); |
|||
} |
|||
|
|||
@Override |
|||
public List<OnlineSum> queryByDateOfRoad(LocalDate queryDate) { |
|||
return onlineSumMapper.queryByDateOfRoad(queryDate); |
|||
} |
|||
|
|||
@Override |
|||
public List<OnlineSum> queryByDeviceTypesOfToday(String[] deviceTypes, String orderByField, String orderDirection, String searchValue) { |
|||
return onlineSumMapper.queryByDeviceTypesOfToday( |
|||
deviceTypes, |
|||
orderByField, |
|||
orderDirection, |
|||
searchValue); |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
package com.zc.business.utils; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.math.RoundingMode; |
|||
|
|||
public class MathUtil { |
|||
|
|||
/** |
|||
* 保留两位小数 |
|||
* @param d 数字 |
|||
* @return 保留两位小数后的数字 |
|||
*/ |
|||
public static double doubleTwoDecimal(double d){ |
|||
BigDecimal originalNumber = new BigDecimal(d); |
|||
BigDecimal roundedNumber = originalNumber.setScale(2, RoundingMode.HALF_UP); |
|||
return roundedNumber.doubleValue(); |
|||
} |
|||
public static String doubleTwoDecimalStr(double d){ |
|||
BigDecimal originalNumber = new BigDecimal(d); |
|||
BigDecimal roundedNumber = originalNumber.setScale(2, RoundingMode.HALF_UP); |
|||
return roundedNumber.toString(); |
|||
} |
|||
} |
@ -0,0 +1,108 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper |
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.zc.business.mapper.OnlineSumMapper"> |
|||
|
|||
<resultMap type="com.zc.business.domain.OnlineSum" id="OnlineSum"> |
|||
<result property="id" column="id"/> |
|||
<result property="deviceId" column="device_id"/> |
|||
<result property="totalCount" column="total_count"/> |
|||
<result property="onlineRate" column="online_rate"/> |
|||
<result property="offlineRate" column="offline_rate"/> |
|||
<result property="lossRate" column="loss_rate"/> |
|||
<result property="rttAvg" column="rtt_avg"/> |
|||
<result property="networkQuality" column="network_quality"/> |
|||
<result property="statisticalDate" column="statistical_date"/> |
|||
<result property="deviceType" column="device_type"/> |
|||
<result property="roadId" column="section_id"/> |
|||
<result property="deviceIp" column="device_ip"/> |
|||
<result property="deviceName" column="device_name"/> |
|||
<result property="stakeMark" column="stake_mark"/> |
|||
<result property="direction" column="direction"/> |
|||
<result property="useState" column="use_state"/> |
|||
</resultMap> |
|||
|
|||
<insert id="duplicateKeyUpdate"> |
|||
insert into dc_online_sum |
|||
(device_id,total_count,online_rate,offline_rate,loss_rate,rtt_avg,network_quality,statistical_date) |
|||
values |
|||
(#{deviceId},#{totalCount},#{onlineRate},#{offlineRate},#{lossRate},#{rttAvg},#{networkQuality},#{statisticalDate}) |
|||
on duplicate key update |
|||
total_count= values(total_count), |
|||
online_rate = values(online_rate), |
|||
offline_rate = values(offline_rate), |
|||
loss_rate = values(loss_rate), |
|||
rtt_avg = values(rtt_avg), |
|||
network_quality = values(network_quality) |
|||
</insert> |
|||
<select id="queryByDateRangeOfDevice" resultMap="OnlineSum"> |
|||
select id,device_id,total_count,online_rate,offline_rate,loss_rate,rtt_avg,network_quality,statistical_date |
|||
from dc_online_sum |
|||
where |
|||
device_id = #{deviceId} and (statistical_date between #{startDate} and #{endDate}) |
|||
</select> |
|||
<select id="queryByDeviceTypeAndDate" resultMap="OnlineSum"> |
|||
select s.id,s.device_id,total_count,online_rate,offline_rate,loss_rate,rtt_avg,network_quality,statistical_date,COALESCE(d.child_type,d.device_type) as device_type |
|||
from dc_online_sum s join dc_device d on s.device_id = d.id |
|||
where d.use_state = 1 |
|||
AND (s.statistical_date BETWEEN #{startDate} AND #{endDate}) |
|||
AND (d.device_type in |
|||
<foreach item="typeItem" collection="types" open="(" separator="," close=")"> |
|||
#{typeItem} |
|||
</foreach> |
|||
or d.child_type in |
|||
<foreach item="typeItem" collection="types" open="(" separator="," close=")"> |
|||
#{typeItem} |
|||
</foreach> |
|||
) |
|||
<if test="direction != null and direction != ''"> |
|||
AND d.direction = #{direction} |
|||
</if> |
|||
</select> |
|||
<select id="queryByDateOfDeviceType" resultMap="OnlineSum"> |
|||
select s.id,s.device_id,total_count, |
|||
online_rate,offline_rate,loss_rate, |
|||
rtt_avg,network_quality,statistical_date,COALESCE (d.child_type, d.device_type) as device_type |
|||
from dc_online_sum s join dc_device d on s.device_id = d.id |
|||
where d.use_state = 1 and s.statistical_date = #{queryDate} |
|||
</select> |
|||
<select id="queryByDateOfRoad" resultMap="OnlineSum"> |
|||
select s.id,s.device_id,total_count,online_rate, |
|||
offline_rate,loss_rate,rtt_avg,network_quality,statistical_date, |
|||
m.section_id |
|||
from dc_online_sum s join dc_device d on s.device_id = d.id |
|||
LEFT JOIN dc_stake_mark m on m.stake_mark=d.stake_mark and m.direction = d.direction |
|||
where d.use_state = 1 and s.statistical_date = #{queryDate} |
|||
</select> |
|||
|
|||
<select id="queryByDeviceTypesOfToday" resultMap="OnlineSum"> |
|||
select d.device_ip,d.device_name,d.stake_mark,COALESCE (d.child_type, d.device_type) as device_type, |
|||
d.direction,d.use_state, |
|||
s.id,s.device_id,total_count,online_rate, |
|||
offline_rate,loss_rate,rtt_avg,network_quality,statistical_date |
|||
from dc_device d |
|||
join dc_online_sum s on s.device_id = d.id |
|||
where |
|||
s.statistical_date = CURDATE() |
|||
<if test="types.length != 0"> |
|||
and (d.device_type in |
|||
<foreach item="typeItem" collection="types" open="(" separator="," close=")"> |
|||
#{typeItem} |
|||
</foreach> |
|||
or d.child_type in |
|||
<foreach item="typeItem" collection="types" open="(" separator="," close=")"> |
|||
#{typeItem} |
|||
</foreach> |
|||
) |
|||
</if> |
|||
<if test="searchValue != null and searchValue != ''"> |
|||
and (d.device_ip like concat('%',#{searchValue},'%') |
|||
or d.stake_mark like concat('%',#{searchValue},'%')) |
|||
</if> |
|||
<if test="orderByField != null and orderDirection != null"> |
|||
order by ${orderByField} ${orderDirection} |
|||
</if> |
|||
</select> |
|||
|
|||
</mapper> |
Loading…
Reference in new issue