/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package org.springblade.jfpt.equipment.service.impl;
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springblade.core.tool.node.ForestNodeMerger;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.jfpt.alarm.vo.AlarmVO;
|
import org.springblade.jfpt.equipment.entity.Equipment;
|
import org.springblade.jfpt.equipment.mapper.EquipmentMapper;
|
import org.springblade.jfpt.equipment.service.IEquipmentService;
|
import org.springblade.jfpt.equipment.vo.EquipmentVO;
|
import org.springblade.jfpt.equipment.vo.EquipmentVOS;
|
import org.springblade.system.cache.SysCache;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 服务实现类
|
*
|
* @author BladeX
|
* @since 2020-07-01
|
*/
|
@Service
|
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment> implements IEquipmentService {
|
private static final String PARENT_ID = "parentId";
|
|
//时间差
|
private long TIME_DIFFERENCE = 24*3600*1000;
|
|
@Override
|
public IPage<EquipmentVO> selectEquipmentPage(IPage<EquipmentVO> page, EquipmentVO equipment,List childList) {
|
return page.setRecords(baseMapper.selectEquipmentPage(page,equipment,childList));
|
}
|
|
@Override
|
public IPage<EquipmentVO> selectPage(IPage<EquipmentVO> page, EquipmentVO equipment,String pid) {
|
|
return page.setRecords(baseMapper.selectEquipmentPage(page,equipment,null));
|
}
|
|
|
@Override
|
public IPage<EquipmentVO> selectDeptPages(IPage<EquipmentVO> page, EquipmentVO equipment,String pid) {
|
|
List deptIdList;
|
if (!pid.equals("")){
|
deptIdList = SysCache.getDeptChildIds(Long.valueOf(pid));
|
}else{
|
deptIdList = SysCache.getDeptChildIds(null);
|
}
|
return page.setRecords(baseMapper.selectDeptPages(page,equipment,deptIdList));
|
}
|
|
|
|
@Override
|
public List<EquipmentVOS> tree() {
|
return ForestNodeMerger.merge(baseMapper.tree());
|
}
|
|
@Override
|
public List<EquipmentVO> listAll() {
|
return baseMapper.listAll();
|
}
|
|
@Override
|
public void updateOne(Equipment equipment) {
|
baseMapper.updateOne(equipment);
|
}
|
|
@Override
|
public void s(Equipment equipment) {
|
baseMapper.s(equipment);
|
}
|
|
@Override
|
public void updataType(String arr) {
|
baseMapper.updataType(arr);
|
}
|
|
@Override
|
public void updataTypeC(String arr) {
|
baseMapper.updataTypeC(arr);
|
}
|
|
@Override
|
public List<EquipmentVOS> lazyList(Long parentId, Map<String, Object> param) {
|
// 判断点击搜索但是没有查询条件的情况
|
if (Func.isEmpty(param.get(PARENT_ID)) && param.size() == 1) {
|
parentId = 0L;
|
}
|
// 判断点击搜索带有查询条件的情况
|
if (Func.isEmpty(param.get(PARENT_ID)) && param.size() > 1 && Func.toLong(parentId) == 0L) {
|
parentId = null;
|
}
|
return baseMapper.lazyList(parentId, param);
|
}
|
|
@Override
|
public EquipmentVOS selectInfo(Equipment equipment) {
|
return baseMapper.selectInfo(equipment);
|
}
|
|
@Override
|
public List<Map<String, Object>> selectInfos(String deviceNumber) {
|
return baseMapper.selectInfos(deviceNumber);
|
}
|
|
@Override
|
public List<EquipmentVOS> selectList(String deviceType) {
|
return baseMapper.selectList(deviceType);
|
}
|
|
@Override
|
public void updateChannel(String heartbeat, String deviceNumber) {
|
baseMapper.updateChannel(heartbeat, deviceNumber);
|
}
|
|
/**
|
* 查询在线设备总数
|
* @param status 状态码 0:本日 1:本周 2:本月
|
* @return
|
*/
|
@Override
|
public Integer selectEquipmentCount(Integer status) {
|
//先查询所有的设备
|
List<EquipmentVO> equipmentVOS = baseMapper.listAll();
|
long time = new Date().getTime();
|
int equipmentCount = 0;
|
long hearbeat = 0;
|
//遍历集合数据,对比心跳时间,得出在线的设备数量
|
if (status==0 && equipmentVOS.size()>0){
|
for (EquipmentVO e:equipmentVOS) {
|
try {
|
if(null!=e.getHeartbeat()) {
|
hearbeat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(e.getHeartbeat()).getTime();
|
}
|
} catch (ParseException parseException) {
|
parseException.printStackTrace();
|
}
|
//对比心跳时间
|
if (time-hearbeat<TIME_DIFFERENCE){
|
equipmentCount+=1;
|
}
|
}
|
}
|
//返回数据
|
return equipmentCount;
|
}
|
|
@Override
|
public void updateexpireTime(String expireTime, String deviceNumber) {
|
baseMapper.updateexpireTime(expireTime,deviceNumber);
|
}
|
|
@Override
|
public void updateExstate(String state, String reason, String deviceNumber) {
|
baseMapper.updateExstate(state, reason, deviceNumber);
|
}
|
}
|