|
@@ -1,11 +1,17 @@
|
|
|
package com.bizmatics.service.impl;
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
+import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.bizmatics.common.core.bean.CommonPage;
|
|
|
+import com.bizmatics.common.core.exception.BusinessException;
|
|
|
+import com.bizmatics.common.core.util.BeanMapperUtils;
|
|
|
+import com.bizmatics.common.core.util.FileUtils;
|
|
|
import com.bizmatics.common.mvc.base.AbstractCrudService;
|
|
|
+import com.bizmatics.common.spring.util.GlobalUtils;
|
|
|
import com.bizmatics.model.Device;
|
|
|
import com.bizmatics.model.DeviceAnalogVariableList;
|
|
|
import com.bizmatics.model.DeviceList;
|
|
@@ -13,6 +19,7 @@ import com.bizmatics.model.DeviceStatus;
|
|
|
import com.bizmatics.model.system.SysUser;
|
|
|
import com.bizmatics.model.vo.CorrespondDeviceListVO;
|
|
|
import com.bizmatics.model.vo.CorrespondDeviceVO;
|
|
|
+import com.bizmatics.model.vo.DeviceAnalogVariableListOneVo;
|
|
|
import com.bizmatics.model.vo.DeviceOneVo;
|
|
|
import com.bizmatics.persistence.mapper.DeviceMapper;
|
|
|
import com.bizmatics.service.DeviceAnalogVariableListService;
|
|
@@ -20,13 +27,17 @@ import com.bizmatics.service.DeviceService;
|
|
|
import com.bizmatics.service.DeviceStatusService;
|
|
|
import com.bizmatics.service.enums.DeviceStatusCode;
|
|
|
import com.bizmatics.service.enums.DeviceType;
|
|
|
-import com.bizmatics.service.es.RtAnalogService;
|
|
|
import com.bizmatics.service.util.SecurityUtils;
|
|
|
-import com.bizmatics.service.vo.CorrespondDeviceVOT;
|
|
|
+import com.bizmatics.service.vo.DeviceAnalogVariableListExportVO;
|
|
|
import com.bizmatics.service.vo.DeviceCountVO;
|
|
|
+import com.bizmatics.service.vo.DeviceExportVO;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -78,8 +89,8 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Device> list(Integer userId,Integer siteId,Integer deviceStatus,Date startTime,Date endTime,String type) {
|
|
|
- return baseMapper.list(userId,siteId,deviceStatus,startTime,endTime,type);
|
|
|
+ public List<Device> list(Integer userId, Integer siteId, Integer deviceStatus, Date startTime, Date endTime, String type) {
|
|
|
+ return baseMapper.list(userId, siteId, deviceStatus, startTime, endTime, type);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -112,14 +123,14 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
|
|
|
List<Device> deviceList = this.list(queryWrapper);
|
|
|
List<DeviceAnalogVariableList> deviceAnalogVariableList = baseMapper.deviceAnalogVariableList(siteId);
|
|
|
|
|
|
- if (deviceList.size()>0){
|
|
|
+ if (deviceList.size() > 0) {
|
|
|
for (int i = 0; i < deviceList.size(); i++) {
|
|
|
DeviceOneVo deviceOneVoOne = new DeviceOneVo();
|
|
|
List<DeviceAnalogVariableList> deviceAnalogVariableListTwo = new ArrayList<>();
|
|
|
deviceOneVoOne.setId(deviceList.get(i).getId());
|
|
|
deviceOneVoOne.setDeviceCode(deviceList.get(i).getDeviceCode());
|
|
|
deviceOneVoOne.setDeviceName(deviceList.get(i).getDeviceName());
|
|
|
- if (deviceAnalogVariableList.size()>0){
|
|
|
+ if (deviceAnalogVariableList.size() > 0) {
|
|
|
for (int j = 0; j < deviceAnalogVariableList.size(); j++) {
|
|
|
if (deviceList.get(i).getId().equals(deviceAnalogVariableList.get(j).getCommunicationEquipment())) {
|
|
|
deviceAnalogVariableListTwo.add(deviceAnalogVariableList.get(j));
|
|
@@ -202,7 +213,7 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
|
|
|
if (deviceType != null && deviceType != 0) {
|
|
|
queryWrapper.eq(Device::getDeviceType, deviceType);
|
|
|
}
|
|
|
- if (deviceName != null && !deviceName.equals("") && !deviceName.equals(null)) {
|
|
|
+ if (null != deviceName) {
|
|
|
queryWrapper.like(Device::getDeviceName, deviceName);
|
|
|
}
|
|
|
|
|
@@ -212,14 +223,14 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void variableCloning(Integer type,String newDeviceCode,String oldDeviceCode,String deviceName){
|
|
|
+ public void variableCloning(Integer type, String newDeviceCode, String oldDeviceCode, String deviceName) {
|
|
|
SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
//查询出旧设备配置
|
|
|
LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
|
|
|
queryWrapper.eq(Device::getEnable, 1).eq(Device::getDeviceCode, oldDeviceCode);
|
|
|
List<Device> deviceList = this.list(queryWrapper);
|
|
|
|
|
|
- if (type==1){
|
|
|
+ if (type == 1) {
|
|
|
//设备表新增
|
|
|
Device device = new Device();
|
|
|
device.setEnable(1);
|
|
@@ -247,7 +258,7 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
|
|
|
LambdaQueryWrapper<DeviceAnalogVariableList> queryWrapperOne = Wrappers.lambdaQuery();
|
|
|
queryWrapperOne.eq(DeviceAnalogVariableList::getStatus, 1).eq(DeviceAnalogVariableList::getCommunicationEquipment, deviceList.get(0).getId());
|
|
|
List<DeviceAnalogVariableList> deviceAnalogVariableList = deviceAnalogVariableListService.list(queryWrapperOne);
|
|
|
- if (deviceAnalogVariableList.size()>0){
|
|
|
+ if (deviceAnalogVariableList.size() > 0) {
|
|
|
for (int i = 0; i < deviceAnalogVariableList.size(); i++) {
|
|
|
DeviceAnalogVariableList deviceAnalogVariableListOne = new DeviceAnalogVariableList();
|
|
|
deviceAnalogVariableListOne.setDeviceCode(newDeviceCode);
|
|
@@ -266,7 +277,7 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
|
|
|
deviceAnalogVariableListService.save(deviceAnalogVariableListOne);
|
|
|
}
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
LambdaQueryWrapper<DeviceAnalogVariableList> queryWrapperOneA = Wrappers.lambdaQuery();
|
|
|
queryWrapperOneA.eq(DeviceAnalogVariableList::getStatus, 1).eq(DeviceAnalogVariableList::getCommunicationEquipment, deviceList.get(0).getId());
|
|
|
List<DeviceAnalogVariableList> deviceAnalogVariableListOne = deviceAnalogVariableListService.list(queryWrapperOneA);
|
|
@@ -279,7 +290,7 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
|
|
|
queryWrapperTwoA.eq(DeviceAnalogVariableList::getStatus, 1).eq(DeviceAnalogVariableList::getCommunicationEquipment, deviceListTwo.get(0).getId());
|
|
|
List<DeviceAnalogVariableList> deviceAnalogVariableListTwo = deviceAnalogVariableListService.list(queryWrapperTwoA);
|
|
|
|
|
|
- if (deviceAnalogVariableListTwo.size()>0){
|
|
|
+ if (deviceAnalogVariableListTwo.size() > 0) {
|
|
|
for (int i = 0; i < deviceAnalogVariableListTwo.size(); i++) {
|
|
|
DeviceAnalogVariableList deviceAnalogVariableList = new DeviceAnalogVariableList();
|
|
|
deviceAnalogVariableList.setStatus(0);
|
|
@@ -288,7 +299,7 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (deviceAnalogVariableListOne.size()>0){
|
|
|
+ if (deviceAnalogVariableListOne.size() > 0) {
|
|
|
for (int i = 0; i < deviceAnalogVariableListOne.size(); i++) {
|
|
|
DeviceAnalogVariableList deviceAnalogVariableList = new DeviceAnalogVariableList();
|
|
|
deviceAnalogVariableList.setDeviceCode(newDeviceCode);
|
|
@@ -312,11 +323,57 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public List<Device> deviceListOne(Integer siteId,Integer deviceType){
|
|
|
+ public List<Device> deviceListOne(Integer siteId, Integer deviceType) {
|
|
|
LambdaQueryWrapper<Device> queryWrapperTwo = Wrappers.lambdaQuery();
|
|
|
- queryWrapperTwo.eq(Device::getEnable, 1).eq(Device::getSiteId, siteId).eq(Device::getDeviceType,deviceType);
|
|
|
+ queryWrapperTwo.eq(Device::getEnable, 1).eq(Device::getSiteId, siteId).eq(Device::getDeviceType, deviceType);
|
|
|
List<Device> deviceListTwo = this.list(queryWrapperTwo);
|
|
|
return deviceListTwo;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String deviceExport(String deviceName, Integer deviceType, Integer siteId) {
|
|
|
+ Workbook workbook = null;
|
|
|
+ File file = null;
|
|
|
+ try {
|
|
|
+ ExportParams params = new ExportParams(null, "通信设备列表");
|
|
|
+ workbook = ExcelExportUtil.exportBigExcel(params, DeviceExportVO.class,
|
|
|
+ (o, i) -> {
|
|
|
+
|
|
|
+ Page<Device> page = new Page<>(i, 30);
|
|
|
+ LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(Device::getSiteId, siteId).eq(Device::getEnable, 1);
|
|
|
+ if (deviceType != 0) {
|
|
|
+ queryWrapper.eq(Device::getDeviceType, deviceType);
|
|
|
+ }
|
|
|
+ if (null != deviceName) {
|
|
|
+ queryWrapper.like(Device::getDeviceName, deviceName);
|
|
|
+ }
|
|
|
+
|
|
|
+ page = this.page(page, queryWrapper);
|
|
|
+// this.ToCommonPage(page);
|
|
|
+ return new ArrayList<>(BeanMapperUtils.mapList(page.getRecords(), Device.class, DeviceExportVO.class));
|
|
|
+ }, null);
|
|
|
+ if (null != workbook) {
|
|
|
+ file = FileUtils.getFile(GlobalUtils.getTempBaseDir(), String.format("%s-%s.xlsx", "通信设备列表", System.currentTimeMillis() + ""));
|
|
|
+ FileUtils.createFile(file.getAbsolutePath());
|
|
|
+ FileOutputStream allListingFileOutputStream = new FileOutputStream(file);
|
|
|
+ workbook.write(allListingFileOutputStream);
|
|
|
+ } else {
|
|
|
+ throw new BusinessException("表格数据为空");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导出文件失败", e);
|
|
|
+ throw new BusinessException("导出文件失败");
|
|
|
+ } finally {
|
|
|
+ if (workbook != null) {
|
|
|
+ try {
|
|
|
+ workbook.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("===export spec=== 关闭workbook失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return file.getName();
|
|
|
+ }
|
|
|
+
|
|
|
}
|