Es 工具封装

yun-zuoyi
wei.peng 5 years ago
parent 5dd3f6a38a
commit 6ffb1685d7

@ -1,176 +1,176 @@
package cn.estsh.i3plus.core.apiservice.controller.base; //package cn.estsh.i3plus.core.apiservice.controller.base;
//
import cn.estsh.i3plus.platform.common.tool.HttpClientTool; //import cn.estsh.i3plus.platform.common.tool.HttpClientTool;
import cn.estsh.i3plus.platform.plugin.opc.pojo.OpcUAParam; //import cn.estsh.i3plus.platform.plugin.opc.pojo.OpcUAParam;
import cn.estsh.i3plus.platform.plugin.opc.service.OpcUAService; //import cn.estsh.i3plus.platform.plugin.opc.service.OpcUAService;
import cn.estsh.i3plus.pojo.base.annotation.AnnoIgnoreLog; //import cn.estsh.i3plus.pojo.base.annotation.AnnoIgnoreLog;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; //import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil; //import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.impp.framework.base.controller.CoreBaseController; //import cn.estsh.impp.framework.base.controller.CoreBaseController;
import cn.estsh.impp.framework.boot.exception.ImppBusiException; //import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder; //import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ResultBean; //import cn.estsh.impp.framework.boot.util.ResultBean;
import com.alibaba.fastjson.JSON; //import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api; //import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; //import io.swagger.annotations.ApiOperation;
import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription; //import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger; //import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
import org.slf4j.Logger; //import org.slf4j.Logger;
import org.slf4j.LoggerFactory; //import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping; //import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; //import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; //import org.springframework.web.bind.annotation.RestController;
//
import java.util.HashMap; //import java.util.HashMap;
import java.util.Hashtable; //import java.util.Hashtable;
import java.util.Map; //import java.util.Map;
//
/** ///**
* @Description : // * @Description :
* @Reference : // * @Reference :
* @Author : yunhao // * @Author : yunhao
* @CreateDate : 2020-01-08 11:53 // * @CreateDate : 2020-01-08 11:53
* @Modify: // * @Modify:
**/ // **/
@RestController //@RestController
@Api(tags = "压测接口") //@Api(tags = "压测接口")
@RequestMapping("/impp/pressure-test") //@RequestMapping("/impp/pressure-test")
public class PressureTestController extends CoreBaseController { //public class PressureTestController extends CoreBaseController {
public static final Logger LOGGER = LoggerFactory.getLogger(PressureTestController.class); // public static final Logger LOGGER = LoggerFactory.getLogger(PressureTestController.class);
//
private static Map<String,OpcUAService> uaServiceMap = new Hashtable<>(); // private static Map<String,OpcUAService> uaServiceMap = new Hashtable<>();
//
public static Map<UInteger,OpcUAParam> upcSub = new Hashtable<>(); // public static Map<UInteger,OpcUAParam> upcSub = new Hashtable<>();
//
private OpcUAService getOpcUaService(OpcUAParam opcUAParam){ // private OpcUAService getOpcUaService(OpcUAParam opcUAParam){
if(!uaServiceMap.containsKey(opcUAParam.getServerUrl())){ // if(!uaServiceMap.containsKey(opcUAParam.getServerUrl())){
OpcUAService opcService = new OpcUAService(); // OpcUAService opcService = new OpcUAService();
opcService.connUaService(opcUAParam); // opcService.connUaService(opcUAParam);
uaServiceMap.put(opcUAParam.getServerUrl(),opcService); // uaServiceMap.put(opcUAParam.getServerUrl(),opcService);
} // }
return uaServiceMap.get(opcUAParam.getServerUrl()); // return uaServiceMap.get(opcUAParam.getServerUrl());
} // }
//
@GetMapping("/opc-write") // @GetMapping("/opc-write")
@ApiOperation(value = "写Opc", notes = "写Opc") // @ApiOperation(value = "写Opc", notes = "写Opc")
@AnnoIgnoreLog // @AnnoIgnoreLog
public ResultBean writeOpc(OpcUAParam opcUA){ // public ResultBean writeOpc(OpcUAParam opcUA){
try { // try {
OpcUAService opcService = new OpcUAService(); // OpcUAService opcService = new OpcUAService();
boolean editResult = opcService.editOpcParamValue(opcUA); // boolean editResult = opcService.editOpcParamValue(opcUA);
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(editResult); // return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(editResult);
}catch(ImppBusiException busExcep){ // }catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep); // return ResultBean.fail(busExcep);
}catch(Exception e){ // }catch(Exception e){
return ImppExceptionBuilder.newInstance().buildExceptionResult(e); // return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
} // }
} // }
//
@GetMapping("/opc-read") // @GetMapping("/opc-read")
@ApiOperation(value = "读Opc", notes = "读Opc") // @ApiOperation(value = "读Opc", notes = "读Opc")
@AnnoIgnoreLog // @AnnoIgnoreLog
public ResultBean readOpc(OpcUAParam opcUA){ // public ResultBean readOpc(OpcUAParam opcUA){
try { // try {
Object readResult = getOpcUaService(opcUA).getOpcParamValue(opcUA); // Object readResult = getOpcUaService(opcUA).getOpcParamValue(opcUA);
if(readResult == null){ // if(readResult == null){
return ResultBean.fail(); // return ResultBean.fail();
} // }
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(readResult); // return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(readResult);
}catch(ImppBusiException busExcep){ // }catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep); // return ResultBean.fail(busExcep);
}catch(Exception e){ // }catch(Exception e){
return ImppExceptionBuilder.newInstance().buildExceptionResult(e); // return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
} // }
} // }
//
//
@GetMapping("/opc-sub") // @GetMapping("/opc-sub")
@ApiOperation(value = "订阅Opc", notes = "订阅Opc") // @ApiOperation(value = "订阅Opc", notes = "订阅Opc")
@AnnoIgnoreLog // @AnnoIgnoreLog
public ResultBean subOpc(OpcUAParam opcUA,String callbackMethod,String callbackUrl){ // public ResultBean subOpc(OpcUAParam opcUA,String callbackMethod,String callbackUrl){
try { // try {
UaSubscription subscription = getOpcUaService(opcUA).createSubscription(opcUA, (uaMonitoredItem, integer) -> { // UaSubscription subscription = getOpcUaService(opcUA).createSubscription(opcUA, (uaMonitoredItem, integer) -> {
uaMonitoredItem.setValueConsumer((node, value) -> { // uaMonitoredItem.setValueConsumer((node, value) -> {
LOGGER.info("OPC订阅回调 {} - {} , callback {}", node.getReadValueId().getNodeId(), value.getValue(), // LOGGER.info("OPC订阅回调 {} - {} , callback {}", node.getReadValueId().getNodeId(), value.getValue(),
callbackMethod+callbackUrl); // callbackMethod+callbackUrl);
HashMap<String,String> param = new HashMap<>(); // HashMap<String,String> param = new HashMap<>();
param.put("key",node.getReadValueId().getNodeId().toString()); // param.put("key",node.getReadValueId().getNodeId().toString());
param.put("value",value.getValue().toString()); // param.put("value",value.getValue().toString());
//
HttpClientTool.doHttpUrl(CommonEnumUtil.HTTP_METHOD_TYPE.valueOf(callbackMethod), callbackUrl, param); // HttpClientTool.doHttpUrl(CommonEnumUtil.HTTP_METHOD_TYPE.valueOf(callbackMethod), callbackUrl, param);
} ); // } );
}); // });
upcSub.put(subscription.getSubscriptionId(),opcUA); // upcSub.put(subscription.getSubscriptionId(),opcUA);
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(subscription.getSubscriptionId().toString()); // return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(subscription.getSubscriptionId().toString());
}catch(ImppBusiException busExcep){ // }catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep); // return ResultBean.fail(busExcep);
}catch(Exception e){ // }catch(Exception e){
return ImppExceptionBuilder.newInstance().buildExceptionResult(e); // return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
} // }
} // }
//
@GetMapping("/remove-opc-sub") // @GetMapping("/remove-opc-sub")
@ApiOperation(value = "移除Opc订阅", notes = "移除Opc订阅") // @ApiOperation(value = "移除Opc订阅", notes = "移除Opc订阅")
@AnnoIgnoreLog // @AnnoIgnoreLog
public ResultBean removeSubOpc(OpcUAParam opcUA,String subscriptionId){ // public ResultBean removeSubOpc(OpcUAParam opcUA,String subscriptionId){
try { // try {
getOpcUaService(opcUA).deleteSubscription(opcUA,UInteger.valueOf(subscriptionId)); // getOpcUaService(opcUA).deleteSubscription(opcUA,UInteger.valueOf(subscriptionId));
upcSub.remove(UInteger.valueOf(subscriptionId)); // upcSub.remove(UInteger.valueOf(subscriptionId));
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()); // return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
}catch(ImppBusiException busExcep){ // }catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep); // return ResultBean.fail(busExcep);
}catch(Exception e){ // }catch(Exception e){
return ImppExceptionBuilder.newInstance().buildExceptionResult(e); // return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
} // }
} // }
//
@GetMapping("/remove-all-opc-sub") // @GetMapping("/remove-all-opc-sub")
@ApiOperation(value = "移除Opc订阅", notes = "移除Opc订阅") // @ApiOperation(value = "移除Opc订阅", notes = "移除Opc订阅")
@AnnoIgnoreLog // @AnnoIgnoreLog
public ResultBean removeAllSubOpc(OpcUAParam opcUA){ // public ResultBean removeAllSubOpc(OpcUAParam opcUA){
try { // try {
OpcUAService opcService = getOpcUaService(opcUA); // OpcUAService opcService = getOpcUaService(opcUA);
for (UInteger uInteger : upcSub.keySet()) { // for (UInteger uInteger : upcSub.keySet()) {
opcService.deleteSubscription(opcUA,uInteger); // opcService.deleteSubscription(opcUA,uInteger);
} // }
upcSub.clear(); // upcSub.clear();
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()); // return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
}catch(ImppBusiException busExcep){ // }catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep); // return ResultBean.fail(busExcep);
}catch(Exception e){ // }catch(Exception e){
return ImppExceptionBuilder.newInstance().buildExceptionResult(e); // return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
} // }
} // }
//
@GetMapping("/show-opc-sub-list") // @GetMapping("/show-opc-sub-list")
@ApiOperation(value = "查询Opc订阅", notes = "查询Opc订阅") // @ApiOperation(value = "查询Opc订阅", notes = "查询Opc订阅")
@AnnoIgnoreLog // @AnnoIgnoreLog
public ResultBean showSubOpcList(){ // public ResultBean showSubOpcList(){
try { // try {
HashMap resultMap = new HashMap<>(); // HashMap resultMap = new HashMap<>();
for (UInteger uInteger : upcSub.keySet()) { // for (UInteger uInteger : upcSub.keySet()) {
resultMap.put(uInteger.toString(), JSON.toJSONString(upcSub.get(uInteger))); // resultMap.put(uInteger.toString(), JSON.toJSONString(upcSub.get(uInteger)));
} // }
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultMap(resultMap); // return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultMap(resultMap);
}catch(ImppBusiException busExcep){ // }catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep); // return ResultBean.fail(busExcep);
}catch(Exception e){ // }catch(Exception e){
return ImppExceptionBuilder.newInstance().buildExceptionResult(e); // return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
} // }
} // }
//
@GetMapping("/test-callback") // @GetMapping("/test-callback")
@ApiOperation(value = "查询Opc订阅", notes = "查询Opc订阅") // @ApiOperation(value = "查询Opc订阅", notes = "查询Opc订阅")
@AnnoIgnoreLog // @AnnoIgnoreLog
public ResultBean showSubOpcList(String key,String value){ // public ResultBean showSubOpcList(String key,String value){
try { // try {
LOGGER.info("回调:{} : {}", key,value); // LOGGER.info("回调:{} : {}", key,value);
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(key+":"+value); // return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultObject(key+":"+value);
}catch(ImppBusiException busExcep){ // }catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep); // return ResultBean.fail(busExcep);
}catch(Exception e){ // }catch(Exception e){
return ImppExceptionBuilder.newInstance().buildExceptionResult(e); // return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
} // }
} // }
//
} //}

@ -29,6 +29,7 @@ import org.bson.Document;
import org.bson.conversions.Bson; import org.bson.conversions.Bson;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Primary;
import org.springframework.data.mongodb.MongoDbFactory; import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -45,6 +46,7 @@ import java.util.Map;
* @Modify: * @Modify:
**/ **/
@Service @Service
@Primary
public class SysLogMongoService implements ISysLogService { public class SysLogMongoService implements ISysLogService {
public static final Logger LOGGER = LoggerFactory.getLogger(SysLogMongoService.class); public static final Logger LOGGER = LoggerFactory.getLogger(SysLogMongoService.class);

@ -1,66 +1,64 @@
package test.cn.estsh.i3plus.core.apiservice.serviceimpl.busi; //package test.cn.estsh.i3plus.core.apiservice.serviceimpl.busi;
//
import cn.estsh.i3plus.core.api.iservice.busi.ISysLogExceptionService; //import cn.estsh.i3plus.core.api.iservice.busi.ISysLogExceptionService;
import cn.estsh.i3plus.core.api.iservice.busi.ISysLogSystemService; //import cn.estsh.i3plus.core.api.iservice.busi.ISysLogSystemService;
import cn.estsh.i3plus.core.apiservice.serviceimpl.busi.TestBase; //import cn.estsh.i3plus.core.apiservice.serviceimpl.busi.TestBase;
import cn.estsh.i3plus.pojo.base.bean.ListPager; //import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager; //import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogException; //import cn.estsh.i3plus.pojo.platform.platbean.SysLogException;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogSystem; //import cn.estsh.i3plus.pojo.platform.platbean.SysLogSystem;
import com.alibaba.fastjson.JSON; //import org.junit.Test;
import org.junit.Test; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired; //
//import javax.transaction.Transactional;
import javax.transaction.Transactional; //
import java.util.List; ///**
// * @Description :
/** // * @Reference :
* @Description : // * @Author : alwaysfrin
* @Reference : // * @CreateDate : 2019-04-09 14:38
* @Author : alwaysfrin // * @Modify:
* @CreateDate : 2019-04-09 14:38 // **/
* @Modify: //public class TestMongoDb extends TestBase {
**/ //
public class TestMongoDb extends TestBase { //
// @Autowired
// private ISysLogExceptionService sysLogExceptionService;
@Autowired //
private ISysLogExceptionService sysLogExceptionService; // @Autowired
// private ISysLogSystemService syslogSystemService;
@Autowired //
private ISysLogSystemService syslogSystemService; // /**
// * 测试 查询所有系统参数
/** // */
* // @Test
*/ // @Transactional
@Test // public void testListSysConfig() {
@Transactional // Pager pager = new Pager();
public void testListSysConfig() { // pager.setStartRow(0);
Pager pager = new Pager(); // pager.setPageSize(10);
pager.setStartRow(0); //
pager.setPageSize(10); // SysLogException sysLogException = new SysLogException();
//
SysLogException sysLogException = new SysLogException(); // ListPager logExceptionList = sysLogExceptionService.querySysLogExceptionByPager(sysLogException, pager);
// System.out.println(logExceptionList);
ListPager logExceptionList = sysLogExceptionService.querySysLogExceptionByPager(sysLogException, pager); // }
System.out.println(logExceptionList); //
} //
// @Test
// @Transactional
@Test // public void testListSysLogSystem() {
@Transactional // Pager pager = new Pager();
public void testListSysLogSystem() { // pager.setStartRow(0);
Pager pager = new Pager(); // pager.setPageSize(10);
pager.setStartRow(0); //
pager.setPageSize(10); // SysLogSystem logSystem = new SysLogSystem();
// logSystem.setLogLevel(1);
SysLogSystem logSystem = new SysLogSystem(); // logSystem.setLogModuleId(1);
logSystem.setLogLevel(1); //
logSystem.setLogModuleId(1); // System.out.println("2===============");
// ListPager logSystemList = syslogSystemService.querySysLogSystemByPager(logSystem,pager);
System.out.println("2==============="); // System.out.println(logSystemList.getObjectList().size());
ListPager logSystemList = syslogSystemService.querySysLogSystemByPager(logSystem,pager); // System.out.println("===============pager:" + pager);
System.out.println(logSystemList.getObjectList().size()); // }
System.out.println("===============pager:" + pager); //}
}
}

Loading…
Cancel
Save