更新导出协议
This commit is contained in:
@@ -351,4 +351,27 @@ public class DeviceController {
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@GetMapping({"/queryDBInfoByDriverCode/{driverCode}"})
|
||||
@Log("根据驱动编码获取db信息")
|
||||
@ApiOperation("根据驱动编码获取db信息")
|
||||
public ResponseEntity<Object> 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<Object> getAllDriverCodeList() {
|
||||
return new ResponseEntity<>(DriverTypeEnum.getList(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -269,4 +269,20 @@ public interface DeviceService {
|
||||
List<Device> 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;
|
||||
}
|
||||
|
||||
@@ -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<Map<String,Object>> 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<String,Object> 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<String, Object> 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<String,Object> 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<String, Object> 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<String,Object> getValue(JSONArray wss, int j, Integer dbInterval, int i){
|
||||
int size = wss.size();
|
||||
Map<String,Object> 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<String,Object> getValue1(JSONArray wss, int j, Integer dbInterval, int i){
|
||||
int size = wss.size();
|
||||
Map<String,Object> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user