liuguijing 1 year ago
commit 239e0c83f7

@ -12,10 +12,8 @@ import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
@ -84,4 +82,15 @@ public class NiecSensorController extends BasicController {
reportService.exportSensor(detail, response.getOutputStream());
}
@PostMapping("importCac")
@ApiOperation("导入CAC")
public Response<String> importCac(@RequestParam("file") MultipartFile file) throws Exception {
if (file != null && file.getInputStream() != null) {
reportService.importCac(file.getInputStream());
return Response.success("OK");
} else {
return Response.fail("缺少上传文件");
}
}
}

@ -0,0 +1,69 @@
package com.xydl.cac.excel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.xydl.cac.entity.NiecSensor;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
public class CacExcelListener extends AnalysisEventListener<CacLine> {
List<CacLine> list = new ArrayList<>();
int base = 16385;
int type;
LinkedHashMap<String, NiecSensor> sensorList = new LinkedHashMap<>();
@Override
public void invoke(CacLine line, AnalysisContext analysisContext) {
int row = analysisContext.readRowHolder().getRowIndex();
if (row > 1) {
if (line.getPointId().contains("遥测")) {
type = 0;
} else if (line.getPointId().contains("遥信")) {
type = 1;
} else {
processDate(line, row + 1);
}
}
}
private void processDate(CacLine line, int row) {
if (StringUtils.isNotBlank(line.getSensorCode())) {
NiecSensor sensor = sensorList.get(line.getSensorCode());
if (sensor == null) {
sensor = new NiecSensor();
sensor.setSensorCode(line.getSensorCode());
Integer pointId = Integer.parseInt(line.getPointId()) + base;
if (StringUtils.isBlank(line.getEquipmentCode())) {
throw new RuntimeException("第" + row + "行的被监测设备的唯一标识不能为空");
}
sensor.setEquipmentId(line.getEquipmentCode());
if (StringUtils.isBlank(line.getTableName())) {
throw new RuntimeException("第" + row + "行的表名不能为空");
}
sensor.setTableName(line.getTableName());
if (StringUtils.isNotBlank(line.getParentName()) && StringUtils.isNotBlank(line.getShortName())) {
sensor.setName(line.getParentName() + line.getShortName());
} else {
sensor.setName(line.getLongName());
}
sensorList.put(line.getSensorCode(), sensor);
}
if (StringUtils.isBlank(line.getField())) {
throw new RuntimeException("第" + row + "行的字段名不能为空");
}
list.add(line);
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
}

@ -0,0 +1,80 @@
package com.xydl.cac.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@Data
public class CacLine {
@ExcelProperty("pointId")
private String pointId;
@ExcelProperty("longName")
private String longName;
@ExcelProperty("siteName")
private String siteName;
@ExcelProperty("fullname")
private String fullname;
@ExcelProperty("e")
private String e;
@ExcelProperty("f")
private String f;
@ExcelProperty("g")
private String g;
@ExcelProperty("h")
private String h;
@ExcelProperty("i")
private String i;
@ExcelProperty("paramindex")
private String paramindex;
@ExcelProperty("k")
private String k;
@ExcelProperty("devid")
private String devid;
@ExcelProperty("grpNo")
private String grpNo;
@ExcelProperty("itemNo")
private String itemNo;
@ExcelProperty("o")
private String o;
@ExcelProperty("p")
private String p;
@ExcelProperty("sensorCode")
private String sensorCode;
@ExcelProperty("equipmentCode")
private String equipmentCode;
@ExcelProperty("phase")
private String phase;
@ExcelProperty("tableName")
private String tableName;
@ExcelProperty("field")
private String field;
@ExcelProperty("parentName")
private String parentName;
@ExcelProperty("shortName")
private String shortName;
@ExcelProperty("fieldDesc")
private String fieldDesc;
}

@ -2,10 +2,13 @@ package com.xydl.cac.service;
import com.xydl.cac.model.SensorDetail;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
public interface ReportService {
void exportSensor(SensorDetail<Map<String, Object>> detail, OutputStream output) throws Exception;
void importCac(InputStream input) throws Exception;
}

@ -5,12 +5,15 @@ import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.xydl.cac.entity.NiecPoint;
import com.xydl.cac.excel.CacExcelListener;
import com.xydl.cac.excel.CacLine;
import com.xydl.cac.model.SensorDetail;
import com.xydl.cac.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
@ -59,4 +62,13 @@ public class ReportServiceImpl implements ReportService {
excelWriter.finish();
}
@Override
public void importCac(InputStream input) throws Exception {
CacExcelListener listener = new CacExcelListener();
EasyExcel.read(input, CacLine.class, listener)
.sheet(0)
.doRead();
}
}

Loading…
Cancel
Save