|
@@ -1,18 +1,43 @@
|
|
|
package com.sckw.slope.detection.service;
|
|
package com.sckw.slope.detection.service;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
+import com.sckw.core.common.enums.NumberConstant;
|
|
|
import com.sckw.core.exception.BusinessException;
|
|
import com.sckw.core.exception.BusinessException;
|
|
|
|
|
+import com.sckw.core.model.page.PageRes;
|
|
|
|
|
+import com.sckw.core.utils.IdWorker;
|
|
|
import com.sckw.core.utils.StringUtils;
|
|
import com.sckw.core.utils.StringUtils;
|
|
|
|
|
+import com.sckw.core.model.enums.AlarmTypeEnum;
|
|
|
|
|
+import com.sckw.core.model.enums.DeviceEnum;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.slope.detection.dao.mysql.KwsDeviceMapper;
|
|
import com.sckw.slope.detection.dao.mysql.KwsDeviceMapper;
|
|
|
|
|
+import com.sckw.slope.detection.dao.mysql.KwsAlarmMapper;
|
|
|
|
|
+import com.sckw.slope.detection.dao.mysql.KwsDeviceModelMapper;
|
|
|
|
|
+import com.sckw.slope.detection.model.dos.mysql.KwsAlarm;
|
|
|
import com.sckw.slope.detection.model.dos.mysql.KwsDevice;
|
|
import com.sckw.slope.detection.model.dos.mysql.KwsDevice;
|
|
|
|
|
+import com.sckw.slope.detection.model.dos.mysql.KwsDeviceModel;
|
|
|
|
|
+import com.sckw.slope.detection.model.dos.mysql.KwsProject;
|
|
|
import com.sckw.slope.detection.model.dto.DeviceDataDTO;
|
|
import com.sckw.slope.detection.model.dto.DeviceDataDTO;
|
|
|
|
|
+import com.sckw.slope.detection.model.dto.HeaderData;
|
|
|
|
|
+import com.sckw.slope.detection.model.dto.ProjectAddDTO;
|
|
|
|
|
+import com.sckw.slope.detection.model.param.DeviceAdd;
|
|
|
|
|
+import com.sckw.slope.detection.model.param.DeviceQuery;
|
|
|
|
|
+import com.sckw.slope.detection.model.vo.ProjectVo;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
|
|
+import com.sckw.slope.detection.model.vo.DeviceVo;
|
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author lfdc
|
|
* @author lfdc
|
|
@@ -26,6 +51,15 @@ public class DeviceService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
KwsDeviceMapper deviceMapper;
|
|
KwsDeviceMapper deviceMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ KwsAlarmMapper alarmMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ KwsDeviceModelMapper deviceModelMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ CommonService commonService;
|
|
|
|
|
+
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public HttpResult dels(String ids) {
|
|
public HttpResult dels(String ids) {
|
|
|
List<Long> list = StringUtils.splitStrToList(ids, Long.class);
|
|
List<Long> list = StringUtils.splitStrToList(ids, Long.class);
|
|
@@ -43,4 +77,77 @@ public class DeviceService {
|
|
|
List<DeviceDataDTO> list = deviceMapper.selectDeviceAllNotDeviceRelation(projectId);
|
|
List<DeviceDataDTO> list = deviceMapper.selectDeviceAllNotDeviceRelation(projectId);
|
|
|
return HttpResult.ok(list);
|
|
return HttpResult.ok(list);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 项目管理分页查询
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param deviceQuery 请求分页
|
|
|
|
|
+ * @param response http流
|
|
|
|
|
+ * @return 返回值
|
|
|
|
|
+ */
|
|
|
|
|
+ public PageRes select(DeviceQuery deviceQuery, HttpResponse response) {
|
|
|
|
|
+ PageHelper.startPage(deviceQuery.getPage(), deviceQuery.getPageSize());
|
|
|
|
|
+ List<DeviceVo> list = deviceMapper.selectByDeviceParam(deviceQuery);
|
|
|
|
|
+ PageInfo<DeviceVo> pageInfo = new PageInfo<>(list);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
+ return PageRes.build(pageInfo, list);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> devicesId = list.stream().map(DeviceVo::getId).toList();
|
|
|
|
|
+ List<Map<String,Long>> alarmData = alarmMapper.selectByDevicesId(devicesId);
|
|
|
|
|
+ for (DeviceVo vo : list) {
|
|
|
|
|
+ vo.setStatusText(DeviceEnum.getName(vo.getStatus()));
|
|
|
|
|
+ if(!CollectionUtils.isEmpty(alarmData)){
|
|
|
|
|
+ for(int i=0;i<alarmData.size();i++){
|
|
|
|
|
+ Map<String,Long> map = alarmData.get(i);
|
|
|
|
|
+ if(map.get("pid").toString().equals(vo.getId().toString())){
|
|
|
|
|
+ vo.setDataErrorCount(map.get("count"));
|
|
|
|
|
+ vo.setDeviceErrorCount(map.get("count"));
|
|
|
|
|
+ }
|
|
|
|
|
+ /*if(map.get("pid").toString().equals(vo.getId().toString()) && map.get("type").toString().equals(AlarmTypeEnum.ALARM_TWO.getCode())){
|
|
|
|
|
+ vo.setDeviceErrorCount(map.get("count"));
|
|
|
|
|
+ }*/
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return PageRes.build(pageInfo, list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增设备
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param deviceAdd 请求参数
|
|
|
|
|
+ * @param request http流
|
|
|
|
|
+ * @return 返回值
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public HttpResult add(DeviceAdd deviceAdd, HttpServletRequest request) {
|
|
|
|
|
+ HeaderData headerData = commonService.getHeaderData(request);
|
|
|
|
|
+ KwsDevice device = new KwsDevice();
|
|
|
|
|
+ BeanUtils.copyProperties(deviceAdd, device);
|
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
+ device.setCreateBy(Long.parseLong(headerData.getCreateBy()));
|
|
|
|
|
+ device.setCreateTime(now);
|
|
|
|
|
+ device.setStatus(DeviceEnum.IDENTIFYING.getCode());
|
|
|
|
|
+ device.setUpdateBy(Long.parseLong(headerData.getUpdateBy()));
|
|
|
|
|
+ device.setUpdateTime(now);
|
|
|
|
|
+ device.setMountainId(headerData.getCompanyId());
|
|
|
|
|
+ deviceMapper.insert(device);
|
|
|
|
|
+ return HttpResult.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public HttpResult detail(Long id, HttpServletRequest response) {
|
|
|
|
|
+ KwsDevice device = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
|
|
|
|
|
+ .eq(KwsDevice::getId, id));
|
|
|
|
|
+ DeviceVo vo = new DeviceVo();
|
|
|
|
|
+ BeanUtils.copyProperties(device, vo);
|
|
|
|
|
+
|
|
|
|
|
+ KwsDeviceModel deviceModel = deviceModelMapper.selectOne(new LambdaQueryWrapper<KwsDeviceModel>()
|
|
|
|
|
+ .eq(KwsDeviceModel::getId, vo.getModelId()));
|
|
|
|
|
+ vo.setManufacturer(deviceModel.getManufacturer());
|
|
|
|
|
+ vo.setManufacturer_contacts(deviceModel.getManufacturerContacts());
|
|
|
|
|
+ vo.setManufacturer_phone(deviceModel.getManufacturerPhone());
|
|
|
|
|
+ return HttpResult.ok(vo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|