|
@@ -0,0 +1,199 @@
|
|
|
+package com.usky.park.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.usky.common.core.bean.CommonPage;
|
|
|
+import com.usky.park.domain.DmpDevice;
|
|
|
+import com.usky.park.domain.DataRealTime;
|
|
|
+import com.usky.park.mapper.DmpDeviceMapper;
|
|
|
+import com.usky.park.service.DataRealTimeService;
|
|
|
+import com.usky.park.service.DmpDeviceService;
|
|
|
+import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import com.usky.park.service.vo.DmpDeviceVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 设备信息表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author zyj
|
|
|
+ * @since 2023-03-30
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class DmpDeviceServiceImpl extends AbstractCrudService<DmpDeviceMapper, DmpDevice> implements DmpDeviceService {
|
|
|
+ @Autowired
|
|
|
+ private DataRealTimeService dataRealTimeService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonPage<DmpDeviceVO> dmpDeviceList(String deviceName,String installAddress,String deviceType,String deviceStatus,String doorStatus,String startDate,String endDate,Integer pageNum,Integer pageSize){
|
|
|
+
|
|
|
+ LambdaQueryWrapper<DmpDevice> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.select(DmpDevice::getDeviceId,DmpDevice::getDeviceName,DmpDevice::getDeviceType,DmpDevice::getInstallAddress,DmpDevice::getCreatedTime)
|
|
|
+ .eq(DmpDevice::getDeviceType,deviceType)
|
|
|
+ .like(StringUtils.isNotBlank(deviceName),DmpDevice::getDeviceName,deviceName)
|
|
|
+ .like(StringUtils.isNotBlank(installAddress),DmpDevice::getInstallAddress,installAddress)
|
|
|
+ .between(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate),DmpDevice::getCreatedTime,startDate,endDate)
|
|
|
+ .orderByDesc(DmpDevice::getId);
|
|
|
+ List<DmpDevice> pagelist = this.list(queryWrapper);
|
|
|
+ List<DmpDeviceVO> list = new ArrayList<>();
|
|
|
+ if(pagelist.size()>0){
|
|
|
+ List<String> deviceIdList = new ArrayList<>();
|
|
|
+ for(int i=0;i<pagelist.size();i++){
|
|
|
+ deviceIdList.add(pagelist.get(i).getDeviceId());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<DataRealTime> list1 = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<DataRealTime> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper1.select(DataRealTime::getDeviceId,DataRealTime::getAttributeName,DataRealTime::getAttributeData)
|
|
|
+ .eq(DataRealTime::getAttributeName,"device_status")
|
|
|
+ .in(DataRealTime::getDeviceId,deviceIdList);
|
|
|
+ list1 = dataRealTimeService.list(queryWrapper1);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ List<DataRealTime> list2 = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<DataRealTime> queryWrapper2 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper2.select(DataRealTime::getDeviceId,DataRealTime::getAttributeName,DataRealTime::getAttributeData)
|
|
|
+ .eq(DataRealTime::getAttributeName,"door_status")
|
|
|
+ .in(DataRealTime::getDeviceId,deviceIdList);
|
|
|
+ list2 = dataRealTimeService.list(queryWrapper2);
|
|
|
+
|
|
|
+
|
|
|
+ List<DmpDeviceVO> list3 = new ArrayList<>();
|
|
|
+ for(int i=0;i<pagelist.size();i++){
|
|
|
+
|
|
|
+ DmpDeviceVO dmpDeviceVO = new DmpDeviceVO();
|
|
|
+ dmpDeviceVO.setDeviceId(pagelist.get(i).getDeviceId());
|
|
|
+ dmpDeviceVO.setDeviceName(pagelist.get(i).getDeviceName());
|
|
|
+ dmpDeviceVO.setInstallAddress(pagelist.get(i).getInstallAddress());
|
|
|
+ dmpDeviceVO.setCreatedTime((pagelist.get(i).getCreatedTime()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+
|
|
|
+
|
|
|
+ if(list1.size()>0){
|
|
|
+ for(int j=0;j<list1.size();j++){
|
|
|
+ if(pagelist.get(i).getDeviceId().equals(list1.get(j).getDeviceId())){
|
|
|
+ dmpDeviceVO.setDeviceStatus(list1.get(j).getAttributeData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(list2.size()>0){
|
|
|
+ for(int j=0;j<list2.size();j++){
|
|
|
+ if(pagelist.get(i).getDeviceId().equals(list2.get(j).getDeviceId())){
|
|
|
+ dmpDeviceVO.setDoorStatus(list2.get(j).getAttributeData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list3.add(dmpDeviceVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(deviceStatus.length()>0){
|
|
|
+ list = list3.stream().filter(e -> deviceStatus.equals(e.getDeviceStatus())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(doorStatus.length()>0){
|
|
|
+ list = list3.stream().filter(e -> doorStatus.equals(e.getDoorStatus())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ if((deviceStatus.length()==0 )&&(doorStatus.length()==0)){
|
|
|
+ list = list3;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ int total=0;
|
|
|
+ if(list.size()>0){
|
|
|
+ total = list.size();
|
|
|
+ }
|
|
|
+ int current = 0;
|
|
|
+ if (pageNum != null && pageSize > 0) {
|
|
|
+ current = (pageNum - 1) * pageSize;
|
|
|
+ }
|
|
|
+ List<DmpDeviceVO> list4 = list.stream().skip(current).limit(pageSize).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new CommonPage<>(list4,total,pageNum,pageSize);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonPage<Object> deviceCurrentDataList(String deviceName,String installAddress,Integer deviceType,Integer switchStatus,Integer pageNum,Integer pageSize){
|
|
|
+ List<Object> list = new ArrayList<>();
|
|
|
+
|
|
|
+ List<DmpDevice> devList = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<DmpDevice> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.select(DmpDevice::getDeviceId,DmpDevice::getDeviceName,DmpDevice::getInstallAddress)
|
|
|
+ .like(StringUtils.isNotBlank(deviceName),DmpDevice::getDeviceName,deviceName)
|
|
|
+ .like(StringUtils.isNotBlank(installAddress),DmpDevice::getInstallAddress,installAddress)
|
|
|
+ .eq(DmpDevice::getDeviceType,deviceType);
|
|
|
+ devList = this.list(queryWrapper);
|
|
|
+ if(devList.size()>0){
|
|
|
+ for(int i=0;i<devList.size();i++){
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("deviceId",devList.get(i).getDeviceId());
|
|
|
+ map.put("deviceName",devList.get(i).getDeviceName());
|
|
|
+ map.put("installAddress",devList.get(i).getInstallAddress());
|
|
|
+ map.put("latestTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+
|
|
|
+ List<DataRealTime> dataRealList = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<DataRealTime> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper1.select(DataRealTime::getAttributeName,DataRealTime::getAttributeData,DataRealTime::getDataTime)
|
|
|
+ .eq(DataRealTime::getDeviceId,devList.get(i).getDeviceId());
|
|
|
+ dataRealList = dataRealTimeService.list(queryWrapper1);
|
|
|
+ if(dataRealList.size()>0){
|
|
|
+ Boolean found = true;
|
|
|
+ for(int j=0;j<dataRealList.size();j++){
|
|
|
+ map.put(dataRealList.get(j).getAttributeName(),dataRealList.get(j).getAttributeData());
|
|
|
+ map.put(dataRealList.get(j).getAttributeName()+"Time",dataRealList.get(j).getDataTime());
|
|
|
+ if((deviceType == 510) && (switchStatus != null)){
|
|
|
+ if((("switch_status").equals(dataRealList.get(j).getAttributeName())) && (switchStatus != Integer.valueOf(dataRealList.get(j).getAttributeData()))){
|
|
|
+ found = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(deviceType == 510){
|
|
|
+ if(found){
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Object> objectList = new ArrayList<>();
|
|
|
+ int total = 0;
|
|
|
+ if(list.size() > 0){
|
|
|
+ total = list.size();
|
|
|
+ }
|
|
|
+ int current = 0;
|
|
|
+ if(pageNum != 0 && pageSize > 0){
|
|
|
+ current = (pageNum - 1)*pageSize;
|
|
|
+ }
|
|
|
+
|
|
|
+ objectList = list.stream().skip(current).limit(pageSize).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ return new CommonPage<>(objectList,total,pageNum,pageSize);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|