|
|
|
@ -2,10 +2,7 @@ package com.xydl.cac.controller;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.util.StringUtils;
|
|
|
|
|
import com.xydl.cac.adapter.BusiAdapter;
|
|
|
|
|
import com.xydl.cac.entity.I2syncConfig;
|
|
|
|
|
import com.xydl.cac.entity.I2syncField;
|
|
|
|
|
import com.xydl.cac.entity.I2syncRecord;
|
|
|
|
|
import com.xydl.cac.entity.ModevType;
|
|
|
|
|
import com.xydl.cac.entity.*;
|
|
|
|
|
import com.xydl.cac.exception.BusinessException;
|
|
|
|
|
import com.xydl.cac.model.Response;
|
|
|
|
|
import com.xydl.cac.model.i2sync.Attr;
|
|
|
|
@ -13,7 +10,9 @@ import com.xydl.cac.model.i2sync.Datanode;
|
|
|
|
|
import com.xydl.cac.model.i2sync.Monitordata;
|
|
|
|
|
import com.xydl.cac.model.i2sync.Request;
|
|
|
|
|
import com.xydl.cac.service.I2syncService;
|
|
|
|
|
import com.xydl.cac.service.ModevTypePointService;
|
|
|
|
|
import com.xydl.cac.service.ModevTypeService;
|
|
|
|
|
import com.xydl.cac.transform.I2DataTransformer;
|
|
|
|
|
import com.xydl.cac.util.DateUtil;
|
|
|
|
|
import com.xydl.cac.util.JSONUtil;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
@ -37,7 +36,11 @@ public class I2syncController extends BasicController {
|
|
|
|
|
@Resource
|
|
|
|
|
ModevTypeService modevTypeService;
|
|
|
|
|
@Resource
|
|
|
|
|
ModevTypePointService modevTypePointService;
|
|
|
|
|
@Resource
|
|
|
|
|
BusiAdapter busiAdapter;
|
|
|
|
|
@Resource
|
|
|
|
|
I2DataTransformer dataTransformer;
|
|
|
|
|
|
|
|
|
|
@GetMapping("status")
|
|
|
|
|
@ApiOperation("查询状态")
|
|
|
|
@ -107,37 +110,33 @@ public class I2syncController extends BasicController {
|
|
|
|
|
@ApiOperation("预览xml结构")
|
|
|
|
|
public Response<String> prewXml(Integer modevtypeId) throws Exception {
|
|
|
|
|
ModevType modevType = modevTypeService.detail(modevtypeId);
|
|
|
|
|
List<ModevTypePoint> points = modevTypePointService.listAll(modevtypeId);
|
|
|
|
|
List<I2syncField> fieldList = service.listFieldConfig(modevType.getTablename());
|
|
|
|
|
List<Attr> attrs = new ArrayList<>();
|
|
|
|
|
Attr attr = new Attr();
|
|
|
|
|
attr.setName("Phase");
|
|
|
|
|
attr.setValue("A相");
|
|
|
|
|
attr.setAlarm("FALSE");
|
|
|
|
|
attrs.add(attr);
|
|
|
|
|
for (I2syncField field : fieldList) {
|
|
|
|
|
attr = new Attr();
|
|
|
|
|
attr.setName(field.getDestFieldName());
|
|
|
|
|
attr.setValue("100.0");
|
|
|
|
|
attr.setAlarm("FALSE");
|
|
|
|
|
attrs.add(attr);
|
|
|
|
|
NSensor sensor = NSensor.builder()
|
|
|
|
|
.id(12)
|
|
|
|
|
.typeId(modevtypeId)
|
|
|
|
|
.sensorCode("HNHFT001Q1W000104")
|
|
|
|
|
.equipmentId("HNHFT001Q1W000104")
|
|
|
|
|
.phase("ABC相")
|
|
|
|
|
.build();
|
|
|
|
|
I2syncRecord record = I2syncRecord.builder()
|
|
|
|
|
.build();
|
|
|
|
|
I2syncConfig config = I2syncConfig.builder()
|
|
|
|
|
.typeCode(modevType.getTypeCode())
|
|
|
|
|
.build();
|
|
|
|
|
List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
map.put("acquisitionTime", DateUtil.format(new Date()));
|
|
|
|
|
for (ModevTypePoint point : points) {
|
|
|
|
|
map.put(point.getField(), 1.25);
|
|
|
|
|
}
|
|
|
|
|
Datanode node = new Datanode();
|
|
|
|
|
node.setSensorid("HNHFT001Q1W000104");
|
|
|
|
|
node.setType(modevType.getTypeCode());
|
|
|
|
|
node.setEquipmentid("HNHFT001Q1W000104");
|
|
|
|
|
node.setTimestamp(DateUtil.format(new Date()));
|
|
|
|
|
node.setAttr(attrs);
|
|
|
|
|
List<Datanode> nodeList = new ArrayList<>();
|
|
|
|
|
nodeList.add(node);
|
|
|
|
|
Monitordata monitordata = new Monitordata();
|
|
|
|
|
monitordata.setCacid("HNHFT001Q1W000104");
|
|
|
|
|
monitordata.setDatanodenum(1);
|
|
|
|
|
monitordata.setDatanode(nodeList);
|
|
|
|
|
Request request = new Request();
|
|
|
|
|
request.setMonitordata(monitordata);
|
|
|
|
|
dataList.add(map);
|
|
|
|
|
|
|
|
|
|
Request request = dataTransformer.transform(sensor, record, config, fieldList, dataList);
|
|
|
|
|
|
|
|
|
|
String xml = JSONUtil.object2Xml(request);
|
|
|
|
|
Response<String> resp = Response.success(xml);
|
|
|
|
|
if (StringUtils.isBlank(node.getType())) {
|
|
|
|
|
if (StringUtils.isBlank(modevType.getTypeCode())) {
|
|
|
|
|
resp.setWarnMsg("该类型还未配置对应的类型编码将导致type为空");
|
|
|
|
|
}
|
|
|
|
|
return resp;
|
|
|
|
|