|
@@ -4,11 +4,12 @@ import com.usky.dao.impl.BaseDaoImpl;
|
|
|
import com.usky.entity.mqtt.TbDeviceAlarmsDTO;
|
|
|
import com.usky.entity.mqtt.TbDeviceDTO;
|
|
|
import com.usky.entity.mqtt.TbDeviceInfoDTO;
|
|
|
-import com.usky.entity.mqtt.vo.TbDeviceVO;
|
|
|
+import com.usky.entity.mqtt.vo.TbDeviceAlarmsVO;
|
|
|
import com.usky.entity.mqtt.vo.TbDeviceVOTop;
|
|
|
-import com.usky.utils.BeanHelp;
|
|
|
-import com.usky.utils.RedisUtil;
|
|
|
+import com.usky.utils.*;
|
|
|
import net.sf.json.JSONObject;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.hibernate.query.Query;
|
|
|
import org.hibernate.transform.Transformers;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -35,7 +36,7 @@ public class TopServcieImpl extends BaseDaoImpl implements TopServcie {
|
|
|
//离线数量
|
|
|
long unOline = alarmsDTOList.stream().filter(s -> "1".equals(s.getSerial())).count();
|
|
|
//故障数量
|
|
|
- long malfunction = alarmsDTOList.stream().filter(s -> "32".equals(s.getSerial())).count();
|
|
|
+ long malfunction = alarmsDTOList.stream().filter(s -> !"1".equals(s.getSerial())).collect(Collectors.groupingBy(TbDeviceAlarmsDTO::getDevId)).size();
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
//设备总数
|
|
|
result.put("deviceTotalNum", list.size());
|
|
@@ -49,12 +50,18 @@ public class TopServcieImpl extends BaseDaoImpl implements TopServcie {
|
|
|
//查询七天告警数据
|
|
|
List<TbDeviceAlarmsDTO> list = getSession().createSQLQuery("SELECT id,dev_id as devId,register_id AS registerId,device_name AS deviceName,device_type AS deviceType,devcie_model AS devcieModel,property,serial,`value`,`status`,create_time AS createTime ,time_stamp AS `timeStamp` FROM tb_device_alarms WHERE date_sub(curdate(), interval 7 day) < date(create_time) order by id ASC")
|
|
|
.setResultTransformer(Transformers.aliasToBean(TbDeviceAlarmsDTO.class)).list();
|
|
|
- //根据时间分组
|
|
|
- // Map<String, List<TbDeviceAlarmsDTO>> collect = list.stream().collect(Collectors.groupingBy(TbDeviceAlarmsDTO::getCreateTime));
|
|
|
- // Map<LocalDate, List> modelMap = modelVOList.stream().collect(Collectors.groupingBy(Model::getGroupTime,
|
|
|
|
|
|
- // LinkedHashMap::new, Collectors.toList()));
|
|
|
- Map<String, List<TbDeviceAlarmsDTO>> collect = list.stream().collect(Collectors.groupingBy(TbDeviceAlarmsDTO::getCreateTime, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ List<TbDeviceAlarmsDTO> objects = new ArrayList<>();
|
|
|
+ for (TbDeviceAlarmsDTO deviceAlarmsDTO : list) {
|
|
|
+ String createTime = deviceAlarmsDTO.getCreateTime();
|
|
|
+ String time = createTime.substring(0, createTime.indexOf(" "));
|
|
|
+ deviceAlarmsDTO.setCreateTime(time);
|
|
|
+ objects.add(deviceAlarmsDTO);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, List<TbDeviceAlarmsDTO>> collect = objects.stream().collect(Collectors.groupingBy(TbDeviceAlarmsDTO::getCreateTime, LinkedHashMap::new, Collectors.toList()));
|
|
|
+
|
|
|
|
|
|
List<Object> resultList = new ArrayList<>();
|
|
|
Set<String> strings = collect.keySet();
|
|
@@ -79,7 +86,7 @@ public class TopServcieImpl extends BaseDaoImpl implements TopServcie {
|
|
|
List<TbDeviceDTO> list = getSession().createQuery("from TbDeviceDTO t where t.del=0").list();
|
|
|
List<TbDeviceVOTop> tbDeviceVOS = BeanHelp.copyWithCollection(list, TbDeviceVOTop.class);
|
|
|
for (TbDeviceVOTop tbDeviceVOTop : tbDeviceVOS) {
|
|
|
- Object o = redisUtil.get(tbDeviceVOTop.getDevId());
|
|
|
+ Object o = redisUtil.get(tbDeviceVOTop.getDevId());
|
|
|
JSONObject jsonObject = JSONObject.fromObject(o);
|
|
|
tbDeviceVOTop.setData(jsonObject);
|
|
|
tbDeviceVOTop.setUserName("吉超薄");
|
|
@@ -113,5 +120,71 @@ public class TopServcieImpl extends BaseDaoImpl implements TopServcie {
|
|
|
List<TbDeviceInfoDTO> list = getSession().createSQLQuery(sb.toString()).setResultTransformer(Transformers.aliasToBean(TbDeviceInfoDTO.class)).list();
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<TbDeviceAlarmsVO> listHistryAlarms(String devId, Integer pageSize, Integer pageNo, String status, String serial) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append("from TbDeviceAlarmsDTO t where 1 =1 ");
|
|
|
+ if (StringUtils.isNotBlank(devId)) {
|
|
|
+ sb.append(" and t.devId= '" + devId + "' ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(status)) {
|
|
|
+ sb.append(" and t.status= " + status + " ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(serial)) {
|
|
|
+ sb.append(" and t.serial= '" + serial + "' ");
|
|
|
+ }
|
|
|
+ Query query = getSession().createQuery(sb.toString());
|
|
|
+
|
|
|
+
|
|
|
+ Page<TbDeviceAlarmsVO> result = new Page<>(query.list().size(), pageSize);
|
|
|
+ query.setFirstResult((pageNo - 1) * pageSize);
|
|
|
+ query.setMaxResults(pageSize);
|
|
|
+ List<TbDeviceAlarmsVO> tbDeviceAlarmsVOS = BeanHelp.copyWithCollection(query.list(), TbDeviceAlarmsVO.class);
|
|
|
+ result.setPageList(tbDeviceAlarmsVOS);
|
|
|
+ result.setPageNo(pageNo);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> listHistryAlarmsTj() {
|
|
|
+ List<TbDeviceAlarmsDTO> list = getSession().createQuery("from TbDeviceAlarmsDTO ").list();
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ //历史告警总数
|
|
|
+ result.put("total", list.size());
|
|
|
+ //未处理告警
|
|
|
+ long count = list.stream().filter(s -> s.getStatus() == 0).count();
|
|
|
+ //离线告警数
|
|
|
+ long offline = list.stream().filter(s -> "1".equals(s.getSerial())).count();
|
|
|
+ // 号1离线2异动32故障 3液位告警 4 电量告警
|
|
|
+ long YD = list.stream().filter(s -> "32".equals(s.getSerial())).count();
|
|
|
+ long YW = list.stream().filter(s -> "3".equals(s.getSerial())).count();
|
|
|
+ long DL = list.stream().filter(s -> "4".equals(s.getSerial())).count();
|
|
|
+ //未处理数
|
|
|
+ result.put("untreated", count);
|
|
|
+ result.put("offline", offline);
|
|
|
+ result.put("YD", YD);
|
|
|
+ result.put("YW", YW);
|
|
|
+ result.put("DL", DL);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<?> updateAlarm(Integer id) {
|
|
|
+ List<TbDeviceAlarmsDTO> list = getSession().createQuery("from TbDeviceAlarmsDTO t where t.status=0 and t.id=" + id + "").list();
|
|
|
+ if (ListUtil.isBlank(list)) {
|
|
|
+ return Result.error("告警不存在!");
|
|
|
+ }
|
|
|
+ TbDeviceAlarmsDTO o = list.get(0);
|
|
|
+ o.setStatus(1);
|
|
|
+ getSession().update(o);
|
|
|
+ return Result.OK("操作成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String time = "2018/12/8 12:45";
|
|
|
+ String substring = time.substring(0, time.indexOf(" "));
|
|
|
+ System.out.println("substring = " + substring);
|
|
|
+ }
|
|
|
}
|
|
|
|