|
@@ -7,6 +7,8 @@ import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -54,7 +56,10 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
|
import java.time.Instant;
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
@@ -1155,6 +1160,61 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void gatewayExport(GatewayDeviceInfoRequestVO gatewayDeviceInfoRequestVO){
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 1. 查询数据库中的设备信息
|
|
|
|
|
+ LambdaQueryWrapper<DmpDeviceInfo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
+ queryWrapper.eq(DmpDeviceInfo::getCategoryType,3)
|
|
|
|
|
+ .eq(DmpDeviceInfo::getDeleteFlag, 0)
|
|
|
|
|
+ .eq(StringUtils.isNotBlank(gatewayDeviceInfoRequestVO.getGatewayUuid()), DmpDeviceInfo::getGatewayUuid, gatewayDeviceInfoRequestVO.getGatewayUuid())
|
|
|
|
|
+ .eq(StringUtils.isNotBlank(gatewayDeviceInfoRequestVO.getProductCode()), DmpDeviceInfo::getProductCode, gatewayDeviceInfoRequestVO.getProductCode())
|
|
|
|
|
+ .eq(DmpDeviceInfo::getTenantId, SecurityUtils.getTenantId())
|
|
|
|
|
+ .orderByDesc(DmpDeviceInfo::getId);
|
|
|
|
|
+ List<DmpDeviceInfo> gatewayDeviceList = this.list(queryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 定义服务器本地保存路径(建议配置在application.yml中,这里简化写死)
|
|
|
|
|
+ // 注意:要确保该目录存在,否则会报错;Windows路径用\\,Linux/Mac用/
|
|
|
|
|
+ String localPath = gatewayDeviceInfoRequestVO.getFilePath()+ "/" + gatewayDeviceInfoRequestVO.getProductCode() + ".cfg";
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 调用exportToLocalFile导出到本地
|
|
|
|
|
+ File file = FileUtil.file(localPath);
|
|
|
|
|
+ exportDeviceToTxt(gatewayDeviceList, FileUtil.getOutputStream(file));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException("导出网关设备配置信息失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 导出设备信息到TXT文件
|
|
|
|
|
+ * @param deviceList 设备列表
|
|
|
|
|
+ * @param outputStream 输出流(用于下载)
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void exportDeviceToTxt(List<DmpDeviceInfo> deviceList, OutputStream outputStream) {
|
|
|
|
|
+ // 1. 构建TXT内容(自定义格式,按行写入)
|
|
|
|
|
+ StringBuilder content = new StringBuilder();
|
|
|
|
|
+ // 写入表头
|
|
|
|
|
+ content.append("{");
|
|
|
|
|
+ // 写入数据行
|
|
|
|
|
+ for (DmpDeviceInfo device : deviceList) {
|
|
|
|
|
+ content.append("\n\t\"").append(device.getImsiCode()).append("\":")
|
|
|
|
|
+ .append("{").append("\"").append("deviceid").append("\"").append(":").append("\"").append(device.getDeviceId()).append("\"").append(",")
|
|
|
|
|
+ .append("\"").append("deviceUuid").append("\"").append(":").append("\"").append(device.getDeviceUuid()).append("\"").append(",")
|
|
|
|
|
+ .append("\"").append("productCode").append("\"").append(":").append("\"").append(device.getProductCode()).append("\"")
|
|
|
|
|
+ .append("}").append(",");
|
|
|
|
|
+ }
|
|
|
|
|
+ content.delete(content.length()-1, content.length());
|
|
|
|
|
+ content.append("\n}");
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 将内容写入输出流(UTF-8编码避免乱码)
|
|
|
|
|
+ try {
|
|
|
|
|
+ outputStream.write(content.toString().getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
+ outputStream.flush();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException("导出TXT文件失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void exportExcel(Workbook workbook, HttpServletResponse response) {
|
|
public void exportExcel(Workbook workbook, HttpServletResponse response) {
|
|
|
// 定义一个流,用作流式输出
|
|
// 定义一个流,用作流式输出
|
|
|
ServletOutputStream outputStream = null;
|
|
ServletOutputStream outputStream = null;
|