diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java index dfdb6209..c973d9cb 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java @@ -351,4 +351,27 @@ public class DeviceController { return new ResponseEntity<>(HttpStatus.CREATED); } + @GetMapping({"/queryDBInfoByDriverCode/{driverCode}"}) + @Log("根据驱动编码获取db信息") + @ApiOperation("根据驱动编码获取db信息") + public ResponseEntity queryDBInfoByDriverCode(@PathVariable String driverCode) { + return new ResponseEntity(deviceService.queryDBInfoByDriverCode(driverCode), HttpStatus.OK); + } + + @Log("导出设备db") + @ApiOperation("导出设备") + @PostMapping(value = "/downloadProtocolConfig") + //@PreAuthorize("@el.check('device:list')") + public void downloadProtocolConfig(HttpServletResponse response, @RequestBody JSONObject whereJson) throws IOException { + deviceService.downloadProtocolConfig(whereJson, response); + } + + @GetMapping("/getAllDriverCodeList") + @Log("协议配置下拉选设备驱动") + @ApiOperation("协议配置下拉选设备驱动") + //@PreAuthorize("@el.check('routePlan:list')") + public ResponseEntity getAllDriverCodeList() { + return new ResponseEntity<>(DriverTypeEnum.getList(), HttpStatus.OK); + } + } diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java index 138e782d..ac201f58 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java @@ -269,4 +269,20 @@ public interface DeviceService { List findCacheDevice(); void updateBarcode(JSONObject json) throws Exception; + + /** + * 根据驱动编码获取db信息 + * + * @param driver_code + */ + JSONObject queryDBInfoByDriverCode(String driver_code); + + /** + * 导出数据 + * + * @param whereJson 待导出的数据 + * @param response / + * @throws IOException / + */ + void downloadProtocolConfig(JSONObject whereJson, HttpServletResponse response) throws IOException; } diff --git a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java index 757dcadb..79402867 100644 --- a/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java +++ b/wcs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java @@ -13,6 +13,7 @@ import com.alibaba.fastjson.JSONObject; import io.swagger.models.auth.In; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.map.ListOrderedMap; import org.nl.acs.config.server.AcsConfigService; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; @@ -1591,4 +1592,226 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial } + + @Override + public JSONObject queryDBInfoByDriverCode(String driver_code) { + //处理设备扩展属性 + JSONObject result = new JSONObject(); + //根据设备驱动定义获取OPC读写数据 + DeviceDriverDefination deviceDriverDefination = deviceDriverDefinationAppService.getDeviceDriverDefination(driver_code); + if (deviceDriverDefination instanceof OpcDeviceDriverDefination) { + OpcDeviceDriverDefination opcDeviceDriverDefination = (OpcDeviceDriverDefination) deviceDriverDefination; + //处理DB读和写属性 + result.put("rs", opcDeviceDriverDefination.getReadableItemDtos()); + result.put("ws", opcDeviceDriverDefination.getWriteableItemDtos()); + } + return result; + } + + @Override + public void downloadProtocolConfig(JSONObject param, HttpServletResponse response) throws IOException { + JSONObject form = param.getJSONObject("form"); + String type = form.getString("type"); + Integer device_code = Integer.parseInt(form.getString("device_code")); + int db_interval = Integer.parseInt(form.getString("db_interval")); + JSONArray rss = param.getJSONArray("rs"); + JSONArray wss = param.getJSONArray("ws"); + int numberSize = Integer.parseInt(form.getString("device_number")); + List> list = new LinkedList<>(); + + if (type.equals("db")){ + for (int i = 0; i < numberSize; i++) { + int dbInterval = db_interval * i; + Integer deviceCode = device_code + i; + for (int j = 0; j <= rss.size(); j++) { + Map map = new ListOrderedMap<>(); + if (j == rss.size()){ + map.put("设备编码",""); + map.put("读取地址",""); + map.put("读取意义",""); + map.put("",""); + map.put("写入地址",""); + map.put("写入意义",""); + list.add(map); + continue; + } + if (i == 0 && j ==0){ + map.put("设备编码",""); + }else { + map.put("设备编码",deviceCode); + } + JSONObject rs = rss.getJSONObject(j); + String db = rs.getString("db"); + String name = rs.getString("name"); + if (i > 0){ + if (name.equals("心跳")){ + continue; + } + } + String[] dbs = db.split("\\."); + String startDB = dbs[0]; + String endDB = dbs[1]; + String endDBFirst = endDB.substring(0, 1); + Integer endDBEnd =Integer.parseInt(endDB.substring(1, endDB.length())) ; + endDBEnd = endDBEnd + dbInterval; + db = startDB + "." + endDBFirst + endDBEnd; + map.put("读取地址",db); + map.put("读取意义",name); + Map value = getValue(wss, j, dbInterval,i); + map.putAll(value); + list.add(map); + System.out.println(map); + } + } + }else if (type.equals("v")){ + for (int i = 0; i < numberSize; i++) { + int dbInterval = db_interval * i; + Integer deviceCode = device_code + i; + for (int j = 0; j <= rss.size(); j++) { + Map map = new ListOrderedMap<>(); + if (j == rss.size()){ + map.put("设备编码",""); + map.put("读取地址",""); + map.put("读取意义",""); + map.put("",""); + map.put("写入地址",""); + map.put("写入意义",""); + list.add(map); + continue; + } + if (i == 0 && j ==0){ + map.put("设备编码",""); + }else { + map.put("设备编码",deviceCode); + } + JSONObject rs = rss.getJSONObject(j); + String db = rs.getString("db"); + String name = rs.getString("name"); + if (i > 0){ + if (name.equals("心跳")){ + continue; + } + } + //String[] dbs = db.split("\\."); + String startDB = db.substring(0,2); + String endDB = db.substring(2,db.length()); + Integer endDBEnd =Integer.parseInt(endDB) ; + endDBEnd = endDBEnd + dbInterval; + db = startDB + endDBEnd + ""; + map.put("读取地址",db); + map.put("读取意义",name); + Map value = getValue1(wss, j, dbInterval,i); + map.putAll(value); + list.add(map); + System.out.println(map); + } + } + } + + response.setContentType("application/octet-stream"); + FileUtil.downloadExcel(list, response); + } + + public Map getValue(JSONArray wss, int j, Integer dbInterval, int i){ + int size = wss.size(); + Map map = new ListOrderedMap<>(); + if (i == 0 && j == 0){ + map.put("",""); + map.put("写入地址",""); + map.put("写入意义",""); + return map; + } + if (i == 0 && j > 0){ + if (j - 1 < size){ + JSONObject ws = wss.getJSONObject(j - 1); + String db = ws.getString("db"); + String name = ws.getString("name"); + String[] dbs = db.split("\\."); + String startDB = dbs[0]; + String endDB = dbs[1]; + String endDBFirst = endDB.substring(0, 1); + Integer endDBEnd =Integer.parseInt(endDB.substring(1, endDB.length())) ; + endDBEnd = endDBEnd + dbInterval; + db = startDB + "." + endDBFirst + endDBEnd; + map.put("",""); + map.put("写入地址",db); + map.put("写入意义",name); + return map; + } + } + if ( i > 0){ + j = j -1; + } + if (j < size){ + JSONObject ws = wss.getJSONObject(j); + String db = ws.getString("db"); + String name = ws.getString("name"); + String[] dbs = db.split("\\."); + String startDB = dbs[0]; + String endDB = dbs[1]; + String endDBFirst = endDB.substring(0, 1); + Integer endDBEnd =Integer.parseInt(endDB.substring(1, endDB.length())) ; + endDBEnd = endDBEnd + dbInterval; + db = startDB + "." + endDBFirst + endDBEnd; + map.put("",""); + map.put("写入地址",db); + map.put("写入意义",name); + return map; + } else { + map.put("",""); + map.put("写入地址",""); + map.put("写入意义",""); + return map; + } + } + + public Map getValue1(JSONArray wss, int j, Integer dbInterval, int i){ + int size = wss.size(); + Map map = new ListOrderedMap<>(); + if (i == 0 && j == 0){ + map.put("",""); + map.put("写入地址",""); + map.put("写入意义",""); + return map; + } + if (i == 0 && j > 0){ + if (j - 1 < size){ + JSONObject ws = wss.getJSONObject(j - 1); + String db = ws.getString("db"); + String name = ws.getString("name"); + //String[] dbs = db.split("\\."); + String startDB = db.substring(0, 2); + String endDB = db.substring(2,db.length()); + Integer endDBEnd =Integer.parseInt(endDB) ; + endDBEnd = endDBEnd + dbInterval; + db = startDB + endDBEnd + ""; + map.put("",""); + map.put("写入地址",db); + map.put("写入意义",name); + return map; + } + } + if ( i > 0){ + j = j -1; + } + if (j < size){ + JSONObject ws = wss.getJSONObject(j); + String db = ws.getString("db"); + String name = ws.getString("name"); + String startDB = db.substring(0, 2); + String endDB = db.substring(2,db.length()); + Integer endDBEnd =Integer.parseInt(endDB) ; + endDBEnd = endDBEnd + dbInterval; + db = startDB + endDBEnd + ""; + map.put("",""); + map.put("写入地址",db); + map.put("写入意义",name); + return map; + } else { + map.put("",""); + map.put("写入地址",""); + map.put("写入意义",""); + return map; + } + } } diff --git a/wcs/qd/src/api/acs/device/driverConfig.js b/wcs/qd/src/api/acs/device/driverConfig.js index c470ee10..79b2b5d0 100644 --- a/wcs/qd/src/api/acs/device/driverConfig.js +++ b/wcs/qd/src/api/acs/device/driverConfig.js @@ -64,3 +64,26 @@ export function testwrite(dbItems, opc_id) { }) } +export function queryDBInfoByDriverCode(driverCode) { + return request({ + url: 'api/device/queryDBInfoByDriverCode/' + driverCode, + method: 'get' + }) +} + +export function downloadProtocolConfig(data) { + return request({ + url: 'api/device/downloadProtocolConfig', + method: 'post', + data, + responseType: 'blob' + }) +} + +export function getAllDriverCodeList() { + return request({ + url: 'api/device/getAllDriverCodeList', + method: 'get' + }) +} + diff --git a/wcs/qd/src/views/acs/protocolConfig/config.vue b/wcs/qd/src/views/acs/protocolConfig/config.vue new file mode 100644 index 00000000..23c2721c --- /dev/null +++ b/wcs/qd/src/views/acs/protocolConfig/config.vue @@ -0,0 +1,237 @@ + + + + + diff --git a/wcs/qd/src/views/acs/protocolConfig/index.vue b/wcs/qd/src/views/acs/protocolConfig/index.vue new file mode 100644 index 00000000..54e69b5b --- /dev/null +++ b/wcs/qd/src/views/acs/protocolConfig/index.vue @@ -0,0 +1,142 @@ + + + + + + +