针对华亿的部署过程中,着重调试分析mqtt连接问题,收发消息的问题

dev
kale 2023-04-04 12:03:55 +08:00
parent 57d741b898
commit 5458043bf4
41 changed files with 369 additions and 262 deletions

View File

@ -6,24 +6,29 @@
*/
package com.lp;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.DispatcherServlet;
import com.lp.authority.AuthorityIntercept;
import com.lp.authority.WechatAuthorityIntercept;
import com.lp.util.LogUtil4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.DispatcherServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Dispatcher extends DispatcherServlet {
private static final long serialVersionUID = 1L;
protected final static Logger LOGGER = LoggerFactory.getLogger(Dispatcher.class);
@Override
protected void doDispatch(HttpServletRequest req, HttpServletResponse response) throws Exception {
// 微信公众号授权拦截
int statusCode = WechatAuthorityIntercept.AutjorityIntercept(req, response) ;
LogUtil4j.debugLogger.debug("---------------++++++++++++++++++++statusCode is {}", statusCode);
if(statusCode == 0 ){
super.doDispatch(req, response);
}else if(statusCode == 1){

View File

@ -11,10 +11,7 @@ import com.lp.cache.CacheName;
import com.lp.cache.ProCacheUtil;
import com.lp.cfg.ProConfig;
import com.lp.common.Code;
import com.lp.util.CommonUtil;
import com.lp.util.LogUtil;
import com.lp.util.ObjectUtil;
import com.lp.util.ResultMapUtils;
import com.lp.util.*;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -44,11 +41,15 @@ public class AuthorityIntercept {
String requestMethod = req.getMethod();
// key -- GET请求不包含KEY WEB请求的时候全部包含Session
String userKey = req.getHeader(ResultMapUtils.USER_KEY);
LogUtil4j.debugLogger.debug("----------------+++++++++++++++++++AutjorityIntercept is called with ({})------({})------({})------({})"
, requestUri, requestUrl, requestMethod, userKey);
try {
if (requestUrl.contains("/login") || requestUrl.contains("/register") || requestUrl.contains("/password") ||
requestUrl.contains("/validate/code") || requestUrl.contains("/security_code") || requestUrl.contains("/upload")
|| requestUrl.contains("/mail") || requestUrl.contains("/bind") || requestUrl.contains("/live") ||
requestUrl.contains("/mqtt") || requestUrl.contains("/baidu") || requestUrl.contains("/vp") ||requestUrl.contains("/noauth") || requestUrl.endsWith("/") ) {
requestUrl.contains("/mqtt") || requestUrl.contains("/baidu") || requestUrl.contains("/vp") ||requestUrl.contains("/noauth")
|| requestUrl.endsWith("/") || requestUrl.contains("/yinzy")) {
return true;
} else {
if (ObjectUtil.isNotEmpty(userKey) || requestMethod.equals("PUT") || requestMethod.equals("POST")
@ -57,7 +58,7 @@ public class AuthorityIntercept {
if (ObjectUtil.isNotEmpty(ProCacheUtil.getCache(CacheName.USERINFO, userKey,new Object()) )) {
return true ;
} else {
LOGGER.debug("AutjorityIntercept with {}{} is called with user {}{}", requestUrl, requestMethod, userKey, ProCacheUtil.getCache(CacheName.USERINFO, userKey,new Object()));
LogUtil4j.debugLogger.debug("AutjorityIntercept with {}{} is called with user {}{}", requestUrl, requestMethod, userKey, ProCacheUtil.getCache(CacheName.USERINFO, userKey,new Object()));
JSONObject resultData = new JSONObject();
resultData.put("status", Code.ResponseCode.SystemCode.NO_AUTHORIZATION);
resultData.put("statusMsg", "NO ACCESS");

View File

@ -6,18 +6,21 @@
*/
package com.lp.authority;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.lp.bo.UserInfoBO;
import com.lp.cfg.ProConfig;
import com.lp.util.LogUtil;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class WechatAuthorityIntercept {
protected final static Logger LOGGER = LoggerFactory.getLogger(WechatAuthorityIntercept.class);
/**
*
*
@ -25,6 +28,9 @@ public class WechatAuthorityIntercept {
* @return boolean
*/
public static boolean isWeixin(HttpServletRequest request) {
LogUtil4j.debugLogger.debug("-------------+++++++++++++++isWeixin is called with request {} "
, ((HttpServletRequest) request).getHeader("user-agent"));
if (((HttpServletRequest) request).getHeader("user-agent") == null) {
return false;
}
@ -48,18 +54,23 @@ public class WechatAuthorityIntercept {
String requestUrl = req.getRequestURL().toString();
String queryString = req.getQueryString();
// 是否需要微信授权信息
Boolean is_auth = false ;
Boolean is_auth = false;
if(ObjectUtil.isNotEmpty(queryString)){
requestUrl+= '?'+queryString.replace("&", "*") ;
}
LogUtil4j.debugLogger.debug("----------------------++++++++++++++++++++++++AutjorityIntercept is called with {}---{}###"
, requestUrl, queryString);
try{
if ((isWeixin(req))
&& !requestUrl.toString().contains(ProConfig.WEIXIN.MP_OAUTH2_REDIRECT_URI) ) {
UserInfoBO userInfo = (UserInfoBO) req.getSession().getAttribute("user");
Object openid = req.getSession().getAttribute("open_id") ;
LogUtil4j.debugLogger.debug("----------------------++++++++++++++++++++++++AutjorityIntercept get wx with {}---{}###"
, userInfo, openid);
if ( ObjectUtil.isEmpty(userInfo) ) {
if(requestUrl.contains("login") || requestUrl.contains("login_sms")
|| requestUrl.contains("validate/code") || requestUrl.contains("/security_code") ){
@ -96,6 +107,8 @@ public class WechatAuthorityIntercept {
/**
* 2.
*/
LogUtil4j.debugLogger.debug("----------------------++++++++++++++++++++++++AutjorityIntercept will redirect to {} ###"
, authorization_url);
response.sendRedirect(authorization_url);
return 1 ;
}
@ -103,7 +116,7 @@ public class WechatAuthorityIntercept {
return 0 ;
}else{
if( requestUrl.toString().contains(ProConfig.WEIXIN.MP_OAUTH2_REDIRECT_URI)
|| requestUrl.toString().contains("/service/weixin/mp/msg") ){
|| requestUrl.toString().contains("/service/weixin/mp/msg") || requestUrl.toString().contains("/yinzy")){
return 0 ;
}
}

View File

@ -1,32 +1,22 @@
package com.lp.cache;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import com.lp.bo.*;
import com.lp.cfg.ProConfig;
import com.lp.dao.BaseDao;
import com.lp.ezuiz.EzuizService;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import com.lp.util.ResultMapUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
import com.lp.bean.IotLpmInfo;
import com.lp.bo.IotNodeInfoBO;
import com.lp.bo.IotSceneInfoBO;
import com.lp.bo.IotSensorInfoBO;
import com.lp.bo.IotTriggerInfoBO;
import com.lp.bo.IotVideoInfoBO;
import com.lp.bo.ProDictionaryInfoBO;
import com.lp.bo.SysConfigInfoBO;
import com.lp.bo.UserAccountInfoBO;
import com.lp.bo.UserInfoBO;
import com.lp.cfg.ProConfig;
import com.lp.dao.BaseDao;
import com.lp.ezuiz.EzuizService;
import com.lp.util.ObjectUtil;
import com.lp.util.ResultMapUtils;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
@ -258,6 +248,8 @@ public class ProCache extends ResultMapUtils {
if( ObjectUtil.isNotEmpty(iotSensorInfoList) ){
for(IotSensorInfoBO obj: iotSensorInfoList){
ProCacheUtil.addCache(CacheName.SENSORINFO, obj.getId()+"", obj);
LogUtil4j.debugLogger.debug("add cache {}---{}", CacheName.SENSORINFO_NSP
, obj.getNode_id()+"-"+obj.getSensor_device_id()+"-"+obj.getPort_id());
ProCacheUtil.addCache(CacheName.SENSORINFO_NSP,
obj.getNode_id()+"-"+obj.getSensor_device_id()+"-"+obj.getPort_id(), obj);
}

View File

@ -1,18 +1,5 @@
package com.lp.controller;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.servlet.ModelAndView;
import com.lp.bo.UserInfoBO;
import com.lp.cache.CacheName;
import com.lp.cache.ProCacheUtil;
@ -20,6 +7,17 @@ import com.lp.service.BaseService;
import com.lp.util.ExcelUtil;
import com.lp.util.ObjectUtil;
import com.lp.util.ResultMapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -47,6 +45,7 @@ public class BaseController extends ResultMapUtils {
* @return
*/
protected UserInfoBO getUserInfoBySession(HttpServletRequest req) {
LOGGER.info("getUserInfoBySession");
return (UserInfoBO) req.getSession().getAttribute("user");
}

View File

@ -133,7 +133,7 @@ public class FileInfoController extends BaseController {
}
// 转存文件
String icoFileName = ProConfig.LOCAL_FILE_PATH + "/sensor_icos/" + code + suffix_name;
LOGGER.debug("{} call upload from {} to {} "
LogUtil4j.debugLogger.debug("{} call upload from {} to {} "
, RequestURL.FileInfo.FILE_SENSOR_ICO, file.getOriginalFilename(), icoFileName);
// file.transferTo(new File(rootPath+"/image/oss/iot/"+ code + suffix_name ));
file.transferTo(new File(icoFileName));

View File

@ -362,7 +362,7 @@ public class UserController extends BaseController {
public ModelAndView userLogin(HttpServletRequest req, HttpServletResponse resp,
@RequestBody UserInfoBO user) {
Map<String, Object> resultMap = getResultMap();
LOGGER.debug("aaaa{}", user);
LogUtil4j.debugLogger.debug("login request with name: ({})", user.getName());
try {
if(CommonUtil.isBlank(user.getName()) || CommonUtil.isBlank(user.getPassword())){
putStatusCode(resultMap, Code.ResponseCode.UserInfo.USERNAME_OR_PASSWORD_ERROR);
@ -390,7 +390,7 @@ public class UserController extends BaseController {
} catch (Exception e) {
super.exception(e, resultMap);
}
LOGGER.debug("bbbb{}", resultMap);
LogUtil4j.debugLogger.debug("login response with name: ({})---{}", user.getName(), resultMap);
return getModelAndView(resp, resultMap);
}

View File

@ -7,6 +7,7 @@ import com.lp.cfg.ProConfig;
import com.lp.common.Code;
import com.lp.service.base.FileInfoService;
import com.lp.util.LogUtil;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import com.lp.util.ResultMapUtils;
import me.chanjar.weixin.common.api.WxConsts;
@ -68,7 +69,7 @@ public class WxMpController extends BaseController {
@RequestParam(value = "nonce", required = false) String nonce,
@RequestParam(value = "echostr", required = false) String echostr, HttpServletRequest req,
HttpServletResponse response) throws IOException {
LOGGER.debug("get echostr with {}", echostr);
LogUtil4j.debugLogger.debug("get echostr with {}", echostr);
PrintWriter out = response.getWriter();
out.write(echostr);
out.flush();
@ -121,6 +122,7 @@ public class WxMpController extends BaseController {
*/
@RequestMapping(method = RequestMethod.GET, value = "weixin/mp/menu/create")
public void menuCreate(HttpServletRequest req, HttpServletResponse response) throws IOException, WxErrorException {
LogUtil4j.debugLogger.debug("------------------+++++++++++++++++ menuCreate");
PrintWriter out = response.getWriter();
response.setCharacterEncoding("UTF-8");
createMenu(out);
@ -142,6 +144,7 @@ public class WxMpController extends BaseController {
public String authCallback(HttpServletRequest req, HttpServletResponse response,
@RequestParam(required = false) String state, @RequestParam(required = false) String code)
throws IOException, WxErrorException {
LogUtil4j.debugLogger.debug("------------------+++++++++++++++++ authCallback called with {}---{}", state, code);
if (!StringUtils.isEmpty(code)) {
// 通过code换取网页授权access_token
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(code);
@ -149,9 +152,10 @@ public class WxMpController extends BaseController {
String openid = wxMpOAuth2AccessToken.getOpenId();
// 设置到session中
req.getSession().setAttribute("open_id", openid);
LogUtil4j.debugLogger.debug("------------------+++++++++++++++++ authCallback get openid {}", openid);
if(state.contains("cbind")){
WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, "zh_CN");
LogUtil4j.debugLogger.debug("------------------+++++++++++++++++ authCallback get wxMpUser {}", wxMpUser);
// 联系人信息绑定
UserInfoBO userx = new UserInfoBO() ;
userx.setWx_open_id(openid);
@ -171,8 +175,8 @@ public class WxMpController extends BaseController {
if( ObjectUtil.isEmpty(user) ){
// 获取用户更多的信息snap_userinfo 授权
WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, "zh_CN");
WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, "zh_CN");
LogUtil4j.debugLogger.debug("------------------+++++++++++++++++ authCallback get wxMpUser {}", wxMpUser);
if( state.contains("bind") ){
// 账户绑定,将微信或者url
if(wxMpUser.getHeadImgUrl().length() < 180){

View File

@ -7,6 +7,7 @@ import com.lp.common.Code;
import com.lp.common.Constants;
import com.lp.common.RequestURLIOT;
import com.lp.controller.BaseController;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import com.lp.util.QRCodeUtil;
import com.lp.util.ResultMapUtils;
@ -60,7 +61,7 @@ public class ContactUserInfoController extends BaseController {
obj.setUser_id(user.getId());
resultMap = service.insert("ContactUserInfo.insert", obj) ;
if(isOk(resultMap)){
LOGGER.debug("{} save is called with {}", RequestURLIOT.ContactUserInfo.CONTACT_USER_INFO, obj);
LogUtil4j.debugLogger.debug("{} save is called with {}", RequestURLIOT.ContactUserInfo.CONTACT_USER_INFO, obj);
// 增加二维码,提供微信公众号绑定 [ 增加新的文件储存隔离系统 ]
QRCodeUtil.encode(ProConfig.LOCAL_DOMAIN +"/service/wiot/cbind?id="+obj.getId() ,null,
ProConfig.LOCAL_FILE_PATH+"/"+Constants.FileRealPath.QRCODE+"/"+ (int) (obj.getId()/100+1)*100

View File

@ -10,10 +10,7 @@ import com.lp.common.Constants;
import com.lp.common.RequestURLIOT;
import com.lp.controller.BaseController;
import com.lp.service.IotHistorySensorDataService;
import com.lp.util.DateUtils;
import com.lp.util.ObjectUtil;
import com.lp.util.PageBean;
import com.lp.util.ResultMapUtils;
import com.lp.util.*;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.springframework.beans.factory.annotation.Autowired;
@ -75,7 +72,7 @@ public class IotHistorySensorInfoController extends BaseController {
}
PageBean data = (PageBean) getData(resultMap);
List<IotHistorySensorDataBO> data1 = (List<IotHistorySensorDataBO>) data.getData();
LOGGER.debug("/page/sensor/history selectPage return: {}", resultMap);
LogUtil4j.debugLogger.debug("/page/sensor/history selectPage return: {}", resultMap);
return getModelAndView(response, resultMap);
}
@ -286,7 +283,7 @@ public class IotHistorySensorInfoController extends BaseController {
} catch (Exception e) {
exception(e,resultMap, id);
}
LOGGER.debug("{} selectOne return {}", RequestURLIOT.SensorHistoryInfo.SENSOR_HISTORY_INFO, resultMap);
LogUtil4j.debugLogger.debug("{} selectOne return {}", RequestURLIOT.SensorHistoryInfo.SENSOR_HISTORY_INFO, resultMap);
return getModelAndView(response, resultMap);
}

View File

@ -19,6 +19,7 @@ import com.lp.common.CodeIot;
import com.lp.common.RequestURLIOT;
import com.lp.controller.BaseController;
import com.lp.service.IotNodeInfoService;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import com.lp.util.ResultMapUtils;
import com.lp.util.iot.ProtocolUtil;
@ -55,8 +56,10 @@ public class IotNodeInfoController extends BaseController {
Map<String, Object> resultMap = getResultMap();
try {
UserInfoBO user = getUserInfoByUserKey(userKey);
obj.setUser_id(user.getId());
resultMap = service.selectPageList("IotNodeInfo.selectPage",getPageBean(paged,pageSize), obj);
// if(user.getType() != Code.UserType.SUPER ){
obj.setUser_id(user.getId());
// }
resultMap = service.selectPageList("IotNodeInfo.selectPage",getPageBean(paged,pageSize), obj);
} catch (Exception e) {
exception(e,resultMap, obj);
}
@ -300,6 +303,7 @@ public class IotNodeInfoController extends BaseController {
ProCacheUtil.addCache(CacheName.NODEINFO_DEVICECODE, obj.getDevice_code(), obj);
}else{
ProCacheUtil.addCache(CacheName.NODEINFO_DEVICECODE, obj.getDevice_code(), obj);
LogUtil4j.debugLogger.debug("ProCacheUtil.removeCache NodeInfoDeviceCode with {}", obj.getDevice_code());
ProCacheUtil.removeCache(CacheName.NODEINFO_DEVICECODE, pre.getDevice_code());
}
@ -346,7 +350,6 @@ public class IotNodeInfoController extends BaseController {
try {
UserInfoBO user = getUserInfoByUserKey(userKey);
obj.setUser_id(user.getId());
resultMap = service.selectList("IotNodeInfo.selectNodeSensorList", obj);
} catch (Exception e) {
@ -369,7 +372,7 @@ public class IotNodeInfoController extends BaseController {
try {
UserInfoBO user = getUserInfoByUserKey(userKey);
obj.setUser_id(user.getId());
LOGGER.debug("selectNodeSensorListPages is called with {}", obj);
LogUtil4j.debugLogger.debug("selectNodeSensorListPages is called with {}", obj);
resultMap = service.selectPageList("IotNodeInfo.selectNodeSensorList",getPageBean(paged,pageSize), obj);
} catch (Exception e) {
exception(e,resultMap, obj);
@ -417,6 +420,7 @@ public class IotNodeInfoController extends BaseController {
// obj 获取缓存
obj = ProCacheUtil.getCache(CacheName.NODEINFO, obj.getId().toString());
ProCacheUtil.removeCache(CacheName.NODEINFO, obj.getId().toString());
LogUtil4j.debugLogger.debug("ProCacheUtil.removeCache NodeInfoDeviceCode with {}", obj.getDevice_code());
ProCacheUtil.removeCache(CacheName.NODEINFO_DEVICECODE, obj.getDevice_code());
}
}
@ -466,6 +470,15 @@ public class IotNodeInfoController extends BaseController {
}
return getModelAndView(response, resultMap);
}
@RequestMapping(method = RequestMethod.GET, value = "/yinzy/getcacheinfo")
public String getCacheInfo(HttpServletResponse response,
@PathVariable String deviceCode ) {
IotNodeInfoBO nodeInfo = ProCacheUtil.getCache(CacheName.NODEINFO_DEVICECODE, deviceCode );
if(ObjectUtil.isEmpty(nodeInfo)){
return null;
}
else return nodeInfo.toString();
}
}

View File

@ -17,6 +17,7 @@ import com.lp.common.Constants;
import com.lp.common.RequestURLIOT;
import com.lp.controller.BaseController;
import com.lp.service.IotSceneInfoService;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import com.lp.util.PageBean;
import com.lp.util.ResultMapUtils;
@ -47,8 +48,10 @@ public class IotSceneInfoController extends BaseController {
Map<String, Object> resultMap = getResultMap();
try {
UserInfoBO user = getUserInfoByUserKey(userKey);
obj.setUser_id(user.getId());
resultMap = service.selectPageList("IotSceneInfo.select",getPageBean(paged,pageSize), obj);
// if(user.getType() != Code.UserType.SUPER ){
obj.setUser_id(user.getId());
// }
resultMap = service.selectPageList("IotSceneInfo.select",getPageBean(paged,pageSize), obj);
} catch (Exception e) {
exception(e,resultMap, obj);
}
@ -99,7 +102,7 @@ public class IotSceneInfoController extends BaseController {
UserInfoBO user = getUserInfoByUserKey(userKey);
obj.setUser_id(user.getId());
resultMap = service.selectPageList("IotSceneInfo.selectSceneInfo",getPageBean(paged,pageSize), obj);
LOGGER.debug("{} call selectSelfPage with {} ret: {}"
LogUtil4j.debugLogger.debug("{} call selectSelfPage with {} ret: {}"
, RequestURLIOT.SceneInfo.SELF_SCENE_INFO_PAGE ,obj
, ((PageBean)getData(resultMap)).getData());
} catch (Exception e) {

View File

@ -1,34 +1,26 @@
package com.lp.controller.iot;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.lp.bo.IotNodeInfoBO;
import com.lp.bo.IotSensorDeviceInfoBO;
import com.lp.bo.IotSensorInfoBO;
import com.lp.bo.IotTriggerInfoBO;
import com.lp.bo.UserInfoBO;
import com.lp.cache.CacheName;
import com.lp.cache.ProCacheUtil;
import com.lp.common.Constants;
import com.lp.common.Code;
import com.lp.common.CodeIot;
import com.lp.common.RequestURLIOT;
import com.lp.controller.BaseController;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import com.lp.util.ResultMapUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Controller
@ -107,6 +99,8 @@ public class IotSensorDeviceInfoController extends BaseController {
service.insert("IotSensorInfo.insert", sensor) ;
ProCacheUtil.addCache(CacheName.SENSORINFO, sensor.getId().toString(), sensor);
LogUtil4j.debugLogger.debug("add cache {}---{}", CacheName.SENSORINFO_NSP
, sensor.getNode_id()+"-"+sensor.getSensor_device_id()+"-"+sensor.getPort_id());
ProCacheUtil.addCache(CacheName.SENSORINFO_NSP, sensor.getNode_id()+"-"+
sensor.getSensor_device_id()+"-"+sensor.getPort_id(), sensor);

View File

@ -6,21 +6,6 @@
*/
package com.lp.controller.iot;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.lp.bo.IotNodeInfoBO;
import com.lp.bo.IotSensorInfoBO;
import com.lp.bo.UserInfoBO;
@ -33,9 +18,19 @@ import com.lp.common.RequestURLIOT;
import com.lp.controller.BaseController;
import com.lp.mqtt.MqttService;
import com.lp.service.IotSensorInfoService;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import com.lp.util.ResultMapUtils;
import com.lp.util.iot.ProtocolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Controller
@ -98,6 +93,9 @@ public class IotSensorInfoController extends BaseController {
resultMap = service.insert("IotSensorInfo.insert", obj) ;
if(isOk(resultMap)){
ProCacheUtil.addCache(CacheName.SENSORINFO, obj.getId().toString(), obj);
LogUtil4j.debugLogger.debug("add cache {}---{}", CacheName.SENSORINFO_NSP
, obj.getNode_id()+"-"+obj.getSensor_device_id()+"-"+obj.getPort_id());
ProCacheUtil.addCache(CacheName.SENSORINFO_NSP, obj.getNode_id()+"-"+obj.getSensor_device_id()+"-"+obj.getPort_id(), obj);
// 这边获取到网关的缓存信息,如果是modbus设备则更新下发的缓存
@ -375,6 +373,8 @@ public class IotSensorInfoController extends BaseController {
resultMap = service.update("IotSensorInfo.update", obj) ;
if(isOk(resultMap)){
ProCacheUtil.addCache(CacheName.SENSORINFO, obj.getId().toString(), obj);
LogUtil4j.debugLogger.debug("add cache {}---{}", CacheName.SENSORINFO_NSP
, obj.getNode_id()+"-"+obj.getSensor_device_id()+"-"+obj.getPort_id());
ProCacheUtil.addCache(CacheName.SENSORINFO_NSP, obj.getNode_id()+"-"+obj.getSensor_device_id()+"-"+obj.getPort_id(), obj);
// 这边获取到网关的缓存信息,如果是modbus设备则更新下发的缓存

View File

@ -1,11 +1,16 @@
package com.lp.controller.iot;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.lp.bo.ContactUserInfoBO;
import com.lp.bo.IotVideoInfoBO;
import com.lp.bo.UserInfoBO;
import com.lp.controller.BaseController;
import com.lp.util.BrowserJudge;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@ -13,21 +18,17 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.lp.bo.ContactUserInfoBO;
import com.lp.bo.IotVideoInfoBO;
import com.lp.bo.UserInfoBO;
import com.lp.controller.BaseController;
import com.lp.util.BrowserJudge;
import com.lp.util.ObjectUtil;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
@Controller
public class IotWechatViewController extends BaseController {
protected final static Logger LOGGER = LoggerFactory.getLogger(IotWechatViewController.class);
private final static String VIEW_PATH = "/wechat/iot/" ;
@Resource(name = "wxMpService")
@ -56,6 +57,7 @@ public class IotWechatViewController extends BaseController {
public String wechatPage(HttpServletRequest req, HttpServletResponse resp,
@PathVariable String viewName) {
setModelWeb(req,viewName);
LogUtil4j.debugLogger.debug("------------------++++++++++++++++++ get view {}", viewName);
return VIEW_PATH + viewName;
}

View File

@ -1,24 +1,8 @@
package com.lp.cronservice;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.lp.bean.TableSystem;
import com.lp.bo.BussinessTriggerBO;
import com.lp.bo.IotNodeInfoBO;
import com.lp.bo.IotSceneInfoBO;
import com.lp.bo.IotSensorInfoBO;
import com.lp.bo.IotTriggerInfoBO;
import com.lp.bo.*;
import com.lp.cache.CacheName;
import com.lp.cache.EhcacheUtil;
import com.lp.cache.ProCacheUtil;
@ -26,13 +10,17 @@ import com.lp.common.CodeIot;
import com.lp.dao.BaseDao;
import com.lp.mqtt.MessageCallback;
import com.lp.mqtt.MqttService;
import com.lp.util.DateUtils;
import com.lp.util.LogUtil;
import com.lp.util.ObjectUtil;
import com.lp.util.PropertiesUtil;
import com.lp.util.*;
import com.lp.util.iot.IotTrigger;
import net.sf.ehcache.Cache;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* @鸿
@ -265,16 +253,22 @@ public class CronServiceThread {
private TaskExecutor taskExecutor ;
public void connect() {
if(MqttService.autoReconn == true){
return;
}
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(false);
options.setUserName(MqttService.userName);
options.setPassword(MqttService.passWord.toCharArray());
// 设置超时时间
options.setConnectionTimeout(20);
// 设置会话心跳时间
options.setKeepAliveInterval(30);
options.setPassword(MqttService.passWord.toCharArray());
if(StringUtils.isNumeric(MqttService.timeout)){
options.setConnectionTimeout(Integer.parseInt(MqttService.timeout));
}
// 设置会话心跳时间
if(StringUtils.isNumeric(MqttService.keepalive)){
options.setKeepAliveInterval(Integer.parseInt(MqttService.keepalive));
}
// 重连
options.setAutomaticReconnect(false);
options.setAutomaticReconnect(MqttService.autoReconn);
// 清楚缓存
options.setCleanSession(MqttService.cleanSession);
try {
@ -294,8 +288,11 @@ public class CronServiceThread {
public class SysHealthCheck implements Runnable {
@Override
public void run() {
LogUtil4j.debugLogger.debug("SysHealthCheck");
if(ObjectUtil.isNotEmpty(MqttService.client) ){
LogUtil4j.debugLogger.debug("SysHealthCheck mqtt client {}---{}", MqttService.client.getClientId(), MqttService.client.getDebug().toString());
if( ! MqttService.client.isConnected() ){
LogUtil4j.debugLogger.debug("SysHealthCheck mqtt client {} is disconnected", MqttService.client.getClientId());
connect();
}
}
@ -317,8 +314,10 @@ public class CronServiceThread {
obj = ProCacheUtil.getCache(CacheName.NODEINFO, obj.getId().toString() ) ;
if( DateUtils.getMinusFromCurrent( obj.getMtime() , obj.getFrequency()+ 30 ) > 0 ){
// 设备离线
// ProCacheUtil.addCache(CacheName.NODEINFO_DEVICECODE, obj.getDevice_code(), obj);
obj.setIot_node_status(CodeIot.DEVICE_STATUS.OFFLINE);
baseDao.update("IotNodeInfo.updateNodeStatusById", obj);
LogUtil4j.debugLogger.debug("DeviceStatusMaintain will offline {}", obj.getDevice_code());
}
}catch(Exception e){
log.error("error info"+ e.getMessage()+",param=" + JSON.toJSONString(obj) );

View File

@ -7,10 +7,7 @@ import com.lp.cache.CacheName;
import com.lp.cache.ProCacheUtil;
import com.lp.common.Constants.CodeType;
import com.lp.dao.BaseDao;
import com.lp.util.LogUtil;
import com.lp.util.ObjectUtil;
import com.lp.util.PageBean;
import com.lp.util.ResultMapUtils;
import com.lp.util.*;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
@ -60,7 +57,7 @@ public class BaseDaoImpl extends ResultMapUtils implements BaseDao {
@Override
public <T> List<T> selectList(String statement, Object obj, PageBean pageBean) {
LOGGER.debug("selectList is called");
LogUtil4j.debugLogger.debug("selectList is called");
List<T> o = null ;
try {
pageBean.setPageParam4Mysql(obj);
@ -188,7 +185,7 @@ public class BaseDaoImpl extends ResultMapUtils implements BaseDao {
}
String code_value =null ;
try{
LOGGER.debug("dictionaryValue with {}---{}", valueSdata, value);
LogUtil4j.debugLogger.debug("dictionaryValue with {}---{}", valueSdata, value);
code_value = ObjectUtil.dictionaryValue( Double.parseDouble(String.valueOf(valueSdata)), value);
annotationedFieldMap.put(f.getField().getName(), code_value);
}catch(NumberFormatException e){

View File

@ -6,15 +6,19 @@
*/
package com.lp.mqtt;
import com.lp.util.LogUtil4j;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.task.TaskExecutor;
public class MessageCallback implements MqttCallbackExtended {
private TaskExecutor taskExecutor ;
protected final static Logger LOGGER = LoggerFactory.getLogger(MessageCallback.class);
public MessageCallback(TaskExecutor taskExecutor2) {
super();
@ -23,11 +27,13 @@ public class MessageCallback implements MqttCallbackExtended {
@Override
public void connectionLost(Throwable arg0) {
LogUtil4j.debugLogger.debug("connectionLost {}", arg0.getLocalizedMessage());
// TODO 连接断开,可以做重连,目前重连失败,还没有设置
}
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
LogUtil4j.debugLogger.debug("deliveryComplete {}", token.getTopics());
// TODO delivery 传送OK
}
@ -39,6 +45,7 @@ public class MessageCallback implements MqttCallbackExtended {
taskExecutor.execute(new MessageHandler(message.getPayload() ,
new String(message.getPayload()), topic));
}catch(Exception e){
LOGGER.error("messageArrived error: ", e);
e.printStackTrace();
}
}
@ -46,6 +53,7 @@ public class MessageCallback implements MqttCallbackExtended {
@Override
public void connectComplete(boolean arg0, String arg1) {
// 连接成功后,重新订阅自己的主题
LogUtil4j.debugLogger.debug("connectComplete with ({})({})", arg0, arg1);
MqttService.subscribe();
}
}

View File

@ -7,7 +7,9 @@
package com.lp.mqtt;
import com.lp.util.LogUtil;
import com.lp.util.LogUtil4j;
import com.lp.util.PropertiesUtil;
import org.apache.commons.lang.StringUtils;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
@ -40,7 +42,10 @@ public class MqttService {
public static final String passWord = PropertiesUtil.getProperty("mqtt.config" ,"mqtt.password");
public static final Boolean cleanSession = "true".equalsIgnoreCase(PropertiesUtil.getProperty("mqtt.config" ,"mqtt.cleanSession")) ;
public static final Boolean autoReconn = "true".equalsIgnoreCase(PropertiesUtil.getProperty("mqtt.config" ,"mqtt.autoReconnect")) ;
public static final String keepalive = PropertiesUtil.getProperty("mqtt.config" ,"mqtt.keepalive") ;
public static final String timeout = PropertiesUtil.getProperty("mqtt.config" ,"mqtt.timeout") ;
public static Logger LOGGER = (Logger) LoggerFactory.getLogger(MqttService.class);
public static MqttClient client;
@ -68,12 +73,16 @@ public class MqttService {
options.setCleanSession(false);
options.setUserName(userName);
options.setPassword(passWord.toCharArray());
// 设置超时时间
options.setConnectionTimeout(20);
// 设置会话心跳时间
options.setKeepAliveInterval(30);
// 设置超时时间
if(StringUtils.isNumeric(timeout)){
options.setConnectionTimeout(Integer.parseInt(timeout));
}
// 设置会话心跳时间
if(StringUtils.isNumeric(keepalive)){
options.setKeepAliveInterval(Integer.parseInt(keepalive));
}
// 重连
options.setAutomaticReconnect(false);
options.setAutomaticReconnect(autoReconn);
// 清楚缓存
options.setCleanSession(cleanSession);
try {
@ -93,7 +102,7 @@ public class MqttService {
Qos[i] =1 ;
}
client.subscribe(topic1, Qos);
LOGGER.debug("subscribe with {}", topic1);
LogUtil4j.debugLogger.debug("subscribe with {}", topic1);
}catch (Exception e) {
LOGGER.error("subscribe error", e);
}
@ -111,7 +120,7 @@ public class MqttService {
try {
client.publish(topic, mess);
} catch (Exception e) {
LogUtil.errorLog(e);
LOGGER.error("pubMessage", e);
}
}
@ -128,7 +137,7 @@ public class MqttService {
try {
client.publish(topic, mess);
} catch (Exception e) {
LogUtil.errorLog(e);
LOGGER.error("pubMessage", e);
}
}
}

View File

@ -10,6 +10,7 @@ import com.lp.common.CodeIot;
import com.lp.mqtt.MqttService;
import com.lp.service.impl.IotNodeInfoServerImpl;
import com.lp.service.impl.IotSensorInfoServiceImpl;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import com.lp.util.SpringApplicationContext;
import org.slf4j.Logger;
@ -26,7 +27,7 @@ public class ProtocalMing implements Iprotocal {
@Override
public void analysisData(String topic, byte[] data, String msg) {
LOGGER.debug("analysisData get {}---{}---{}", topic, data, msg);
// 这边可以保证主题都是 /dev/coo/device_id
msg =msg.replaceAll("\r|\n", "");
@ -38,7 +39,7 @@ public class ProtocalMing implements Iprotocal {
List<SimpleProtocolMqtt> tmpList = JSON.parseArray(msg, SimpleProtocolMqtt.class);
// 对象转换
for(SimpleProtocolMqtt dt : tmpList ){
LOGGER.debug("analysisData msg from json {}", dt.toString());
LogUtil4j.debugLogger.debug("analysisData msg from json {}", dt.toString());
IotSensorInfoBO tp = new IotSensorInfoBO();
tp.setSensor_device_id(dt.getSid());
tp.setPort_id(dt.getPid());
@ -51,13 +52,13 @@ public class ProtocalMing implements Iprotocal {
String[] tmp = topic.split("/");
String deviceCode = tmp[tmp.length -1];
LogUtil4j.debugLogger.debug("analysisData get msg from topic:{}---device:{}", topic, deviceCode);
IotNodeInfoBO nodeInfo = ProCacheUtil.getCache(CacheName.NODEINFO_DEVICECODE, deviceCode );
LOGGER.debug("get nodeInfo with {}---{}", deviceCode, nodeInfo.toString());
if(ObjectUtil.isEmpty(nodeInfo)){
return ;
}
LogUtil4j.debugLogger.debug("get nodeInfo with {}---{}({})", deviceCode, nodeInfo.getName(), nodeInfo.getIot_node_status());
if(nodeInfo.getIot_node_status() != CodeIot.DEVICE_STATUS.ONLINE){
IotNodeInfoBO nodB = new IotNodeInfoBO() ;
nodB.setDevice_code(deviceCode);
@ -65,7 +66,7 @@ public class ProtocalMing implements Iprotocal {
IotNodeInfoServerImpl nodeTmp = SpringApplicationContext.getBeanType("iotNodeInfoServerImpl") ;
nodeTmp.updateNodeStatus(nodB);
}
LOGGER.debug("get IotSensorInfoBO list {}", list.toString());
LogUtil4j.debugLogger.debug("get IotSensorInfoBO list ({}){}", list.size(), list.isEmpty() ? null : list.get(0).getSensor_device_id());
for(IotSensorInfoBO sensorInfo : list){
sensorInfo.setDevice_code(deviceCode);
sensorInfo.setRequest_sdata(sensorInfo.getSdata());
@ -75,7 +76,8 @@ public class ProtocalMing implements Iprotocal {
if(ObjectUtil.isEmpty(sensorInfo.getMtime())){
sensorInfo.setMtime(new Date());
}
LOGGER.debug("get IotSensorInfoBO from list {}", sensorInfo.toString());
LogUtil4j.debugLogger.debug("get IotSensorInfoBO from list ({}---{}---{})"
, sensorInfo.getDevice_code(), sensorInfo.getRequest_sdata(), sensorInfo.getPort_id());
// 传感器处理
IotSensorInfoServiceImpl app = (IotSensorInfoServiceImpl) SpringApplicationContext.getBean("iotSensorInfoServiceImpl") ;
app.updateRealTimeData(sensorInfo) ;
@ -88,10 +90,12 @@ public class ProtocalMing implements Iprotocal {
if(ObjectUtil.isNotEmpty(iotNodeInfo)){
String scene_id = ProCacheUtil.getCache(CacheName.SCENE_IPDATE_FLAG , "scene_" + iotNodeInfo.getScene_id() );
if(ObjectUtil.isNotEmpty(scene_id)){
LogUtil4j.debugLogger.debug("will send msg to /scene/update/{}", iotNodeInfo.getScene_id());
MqttService.pubMessage( "1", "/scene/update/"+ iotNodeInfo.getScene_id() );
}
String node_id = ProCacheUtil.getCache(CacheName.SCENE_IPDATE_FLAG , "node_" + iotNodeInfo.getId() );
if(ObjectUtil.isNotEmpty(node_id)){
LogUtil4j.debugLogger.debug("will send msg to /node/update/{}", iotNodeInfo.getId());
MqttService.pubMessage( "1", "/node/update/"+ iotNodeInfo.getId() );
}
}
@ -100,25 +104,28 @@ public class ProtocalMing implements Iprotocal {
@Override
public void handbert(String topic) {
// TODO Auto-generated method stub
LogUtil4j.debugLogger.debug("handbert");
}
@Override
public void loginProtocal(Object obj) {
// TODO Auto-generated method stub
IotNodeInfoServerImpl tmp = SpringApplicationContext.getBeanType("iotNodeInfoServerImpl") ;
tmp.updateNodeStatus(((IotNodeInfoBO) obj));
LogUtil4j.debugLogger.debug("loginProtocal");
IotNodeInfoServerImpl tmp = SpringApplicationContext.getBeanType("iotNodeInfoServerImpl") ;
tmp.updateNodeStatus(((IotNodeInfoBO) obj));
}
@Override
public void logout(Object obj) {
// TODO Auto-generated method stub
IotNodeInfoServerImpl tmp = SpringApplicationContext.getBeanType("iotNodeInfoServerImpl") ;
tmp.updateNodeStatus(((IotNodeInfoBO) obj));
LogUtil4j.debugLogger.debug("logout");
IotNodeInfoServerImpl tmp = SpringApplicationContext.getBeanType("iotNodeInfoServerImpl") ;
tmp.updateNodeStatus(((IotNodeInfoBO) obj));
}
@Override
public Integer execServerControll(IotSensorInfoBO sensor, IotNodeInfoBO node) {
LogUtil4j.debugLogger.debug("execServerControll");
if(node.getIot_node_status() == CodeIot.DEVICE_STATUS.ONLINE+0){
MqttService.pubMessage("{\"sensor_device_id\":\""+ sensor.getSensor_device_id()
+"\",\"port_id\":"+sensor.getPort_id()+",\"sdata\":"+sensor.getRequest_sdata() +"}",
@ -131,6 +138,7 @@ public class ProtocalMing implements Iprotocal {
@Override
public Integer execServerParamWrite(IotSensorInfoBO sensor, IotNodeInfoBO node) {
LogUtil4j.debugLogger.debug("execServerParamWrite");
if(node.getIot_node_status() == CodeIot.DEVICE_STATUS.ONLINE+0){
MqttService.pubMessage("{\"sensor_device_id\":\""+ sensor.getSensor_device_id()
+"\",\"port_id\":"+sensor.getPort_id()+",\"sdata\":"+sensor.getRequest_sdata() +"}",
@ -143,6 +151,7 @@ public class ProtocalMing implements Iprotocal {
@Override
public Integer execServerParamRead(IotSensorInfoBO sensorInfo, IotNodeInfoBO node) {
LogUtil4j.debugLogger.debug("execServerParamRead");
if(node.getIot_node_status() == CodeIot.DEVICE_STATUS.ONLINE+0){
MqttService.pubMessage("{\"sensor_device_id\":\""+ sensorInfo.getSensor_device_id()
+"\",\"port_id\":"+sensorInfo.getPort_id() +"}",

View File

@ -10,6 +10,7 @@ import com.lp.common.CodeIot;
import com.lp.mqtt.MqttService;
import com.lp.service.impl.IotNodeInfoServerImpl;
import com.lp.service.impl.IotSensorInfoServiceImpl;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import com.lp.util.SpringApplicationContext;
import org.slf4j.Logger;
@ -26,7 +27,7 @@ public class ProtocalXinaoV1 implements Iprotocal {
@Override
public void analysisData(String topic, byte[] data, String msg) {
LOGGER.debug("analysisData get {}---{}---{}", topic, data, msg);
LogUtil4j.debugLogger.debug("analysisData get {}---{}---{}", topic, data, msg);
// 这边可以保证主题都是 /dev/coo/device_id
msg =msg.replaceAll("\r|\n", "");
@ -38,7 +39,7 @@ public class ProtocalXinaoV1 implements Iprotocal {
List<SimpleProtocolMqtt> tmpList = JSON.parseArray(msg, SimpleProtocolMqtt.class);
// 对象转换
for(SimpleProtocolMqtt dt : tmpList ){
LOGGER.debug("analysisData msg from json {}", dt.toString());
LogUtil4j.debugLogger.debug("analysisData msg from json {}", dt.toString());
IotSensorInfoBO tp = new IotSensorInfoBO();
tp.setSensor_device_id(dt.getSid());
tp.setPort_id(dt.getPid());
@ -53,7 +54,7 @@ public class ProtocalXinaoV1 implements Iprotocal {
String deviceCode = tmp[tmp.length -1];
IotNodeInfoBO nodeInfo = ProCacheUtil.getCache(CacheName.NODEINFO_DEVICECODE, deviceCode );
LOGGER.debug("get nodeInfo with {}---{}", deviceCode, nodeInfo.toString());
LogUtil4j.debugLogger.debug("get nodeInfo with {}---{}", deviceCode, nodeInfo.toString());
if(ObjectUtil.isEmpty(nodeInfo)){
return ;
}
@ -65,7 +66,7 @@ public class ProtocalXinaoV1 implements Iprotocal {
IotNodeInfoServerImpl nodeTmp = SpringApplicationContext.getBeanType("iotNodeInfoServerImpl") ;
nodeTmp.updateNodeStatus(nodB);
}
LOGGER.debug("get IotSensorInfoBO list {}", list.toString());
LogUtil4j.debugLogger.debug("get IotSensorInfoBO list {}", list.toString());
for(IotSensorInfoBO sensorInfo : list){
sensorInfo.setDevice_code(deviceCode);
sensorInfo.setRequest_sdata(sensorInfo.getSdata());
@ -75,7 +76,7 @@ public class ProtocalXinaoV1 implements Iprotocal {
if(ObjectUtil.isEmpty(sensorInfo.getMtime())){
sensorInfo.setMtime(new Date());
}
LOGGER.debug("get IotSensorInfoBO from list {}", sensorInfo.toString());
LogUtil4j.debugLogger.debug("get IotSensorInfoBO from list {}", sensorInfo.toString());
// 传感器处理
IotSensorInfoServiceImpl app = (IotSensorInfoServiceImpl) SpringApplicationContext.getBean("iotSensorInfoServiceImpl") ;
app.updateRealTimeData(sensorInfo) ;

View File

@ -7,6 +7,7 @@ import com.lp.cache.CacheName;
import com.lp.cache.ProCacheUtil;
import com.lp.common.Code;
import com.lp.service.IotHistorySensorDataService;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -23,7 +24,7 @@ public class IotHistorySensorDataServiceImpl extends BaseServiceImpl implements
@Override
public Map<String, Object> getHistorySensorData(IotHistorySensorDataBO obj) {
LOGGER.debug("getHistorySensorData is called with IotHistorySensorDataBO({})", obj);
LogUtil4j.debugLogger.debug("getHistorySensorData is called with IotHistorySensorDataBO({})", obj);
Map<String, Object> resultMap = getResultMap();
try{
List<IotSensorInfoBO> list = new ArrayList<>();
@ -45,7 +46,7 @@ public class IotHistorySensorDataServiceImpl extends BaseServiceImpl implements
}
}
resultMap.put("totalPage", max);
LOGGER.debug("getHistorySensorData is called get res: ({}) items, with ids: ({})", list.size(), obj.getIds());
LogUtil4j.debugLogger.debug("getHistorySensorData is called get res: ({}) items, with ids: ({})", list.size(), obj.getIds());
putData(resultMap, list);
}else{
putStatusCode(resultMap, Code.ResponseCode.SystemCode.PARAM_ERROR) ;

View File

@ -1,14 +1,5 @@
package com.lp.service.impl;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import com.lp.bo.IotImportNodeInfoBO;
import com.lp.bo.IotNodeInfoBO;
import com.lp.bo.IotSensorInfoBO;
@ -21,10 +12,11 @@ import com.lp.common.CodeIot;
import com.lp.common.Constants;
import com.lp.mqtt.MqttService;
import com.lp.service.IotNodeInfoService;
import com.lp.util.ExcelUtil;
import com.lp.util.LogUtil;
import com.lp.util.ObjectUtil;
import com.lp.util.QRCodeUtil;
import com.lp.util.*;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.*;
@Service
public class IotNodeInfoServerImpl extends BaseServiceImpl implements IotNodeInfoService {
@ -155,6 +147,8 @@ public class IotNodeInfoServerImpl extends BaseServiceImpl implements IotNodeInf
int re = dao.insert("IotSensorInfo.insert", sensor) ;
if(re>0){
ProCacheUtil.addCache(CacheName.SENSORINFO, sensor.getId().toString(), sensor);
LogUtil4j.debugLogger.debug("add cache {}---{}", CacheName.SENSORINFO_NSP
, sensor.getNode_id()+"-"+sensor.getSensor_device_id()+"-"+sensor.getPort_id());
ProCacheUtil.addCache(CacheName.SENSORINFO_NSP, sensor.getNode_id()+"-"+
sensor.getSensor_device_id()+"-"+sensor.getPort_id(), sensor);
}

View File

@ -11,6 +11,7 @@ import com.lp.common.CodeIot;
import com.lp.service.IotSensorInfoService;
import com.lp.util.Calculator;
import com.lp.util.DateUtils;
import com.lp.util.LogUtil4j;
import com.lp.util.ObjectUtil;
import com.lp.util.iot.IotTrigger;
import org.slf4j.Logger;
@ -25,32 +26,35 @@ import java.util.Map;
public class IotSensorInfoServiceImpl extends BaseServiceImpl implements IotSensorInfoService {
protected final static Logger LOGGER = LoggerFactory.getLogger(IotSensorInfoServiceImpl.class);
public static void main(String[] args) {
}
@Override
public Map<String, Object> updateRealTimeData(IotSensorInfoBO obj) {
LOGGER.debug("updateRealTimeData is called with {}", obj);
LogUtil4j.debugLogger.debug("updateRealTimeData is called with ({}---{}---{})"
, obj.getDevice_code() + "-" + obj.getSensor_device_id(), obj.getPort_id(), obj.getRequest_sdata());
Map<String, Object> resultMap = getResultMap();
try{
// 通过网关缓存 deviceCode -> nodeInfo -> id (or nodeId)
IotNodeInfoBO iotNodeInfo = ProCacheUtil.getCache(CacheName.NODEINFO_DEVICECODE, obj.getDevice_code());
if(ObjectUtil.isEmpty(iotNodeInfo)){
LOGGER.warn("updateRealTimeData is called with {} no IotNodeInfoBO", obj);
LogUtil4j.debugLogger.warn("updateRealTimeData is called with {} no IotNodeInfoBO", obj.getDevice_code());
// 这个设备已经离线了;返回错误,让用户重新登录;
putStatusCode(resultMap, CodeIot.DEVICE_STATUS.OFFLINE);
// 服务端发送重新登录的命令
return resultMap;
}
if( ObjectUtil.isEmpty(iotNodeInfo.getIot_node_status()) || iotNodeInfo.getIot_node_status() != 16 ){
IotNodeInfoBO tmpnode = dao.selectOne("IotNodeInfo.selectOne", iotNodeInfo);
if( ObjectUtil.isEmpty(iotNodeInfo.getIot_node_status()) || iotNodeInfo.getIot_node_status() != 16
|| ObjectUtil.isEmpty(tmpnode.getIot_node_status()) || tmpnode.getIot_node_status() != CodeIot.DEVICE_STATUS.ONLINE){
// 缓存在线
iotNodeInfo.setIot_node_status(CodeIot.DEVICE_STATUS.ONLINE);
iotNodeInfo.setMtime(new Date());
LogUtil4j.debugLogger.warn("iotNodeInfo({}) is offline, will online", iotNodeInfo.getDevice_code());
// 如果设备不在线,则让设备在线
dao.update("IotNodeInfo.updateNodeStatus", iotNodeInfo);
}
@ -58,17 +62,18 @@ public class IotSensorInfoServiceImpl extends BaseServiceImpl implements IotSens
// 网关没有项目信息
IotSceneInfoBO sceneBo = ProCacheUtil.getCache(CacheName.SCENEINFO, iotNodeInfo.getScene_id().toString() );
if(ObjectUtil.isEmpty(sceneBo)){
LOGGER.warn("updateRealTimeData is called with {} no IotSceneInfoBO", obj);
LogUtil4j.debugLogger.warn("updateRealTimeData is called with {} no IotSceneInfoBO", obj);
return resultMap;
}
obj.setNode_name(iotNodeInfo.getName());
obj.setNode_id( iotNodeInfo.getId() );
LogUtil4j.debugLogger.debug("get sensorinfo with key: {}", obj.getNode_id()+"-"+obj.getSensor_device_id()+"-"+obj.getPort_id());
// 获取传感器缓存信息
IotSensorInfoBO sensorInfo = ProCacheUtil.getCache(CacheName.SENSORINFO_NSP, obj.getNode_id()+"-"+obj.getSensor_device_id()+"-"+obj.getPort_id(), obj);
if( ObjectUtil.isEmpty(sensorInfo) ){
LOGGER.warn("updateRealTimeData is called with {} no IotSensorInfoBO", obj);
LOGGER.warn("updateRealTimeData is called with {} no IotSensorInfoBO", obj.getNode_id()+"-"+obj.getSensor_device_id()+"-"+obj.getPort_id());
// 不存在的数据
return resultMap;
}
@ -76,7 +81,7 @@ public class IotSensorInfoServiceImpl extends BaseServiceImpl implements IotSens
// 这边判断如果是经纬度的传感器信息,则需要更新网关信息的经纬度数据
if( sensorInfo.getIot_sensor_type()!=null && sensorInfo.getIot_sensor_type() == CodeIot.SENSOR_TYPE.POSITION +0 ){
iotNodeInfo.setLonLat( obj.getStr_sdata() );
iotNodeInfo.setLonLat( obj.getStr_sdata());
dao.update("IotNodeInfo.update", iotNodeInfo) ;
}
@ -96,7 +101,7 @@ public class IotSensorInfoServiceImpl extends BaseServiceImpl implements IotSens
obj.setSdata(ft);
obj.setRequest_sdata(obj.getSdata());
}
LOGGER.debug("updateRealTimeData is called with {} with {}", obj, sensorInfo);
// LogUtil4j.debugLogger.debug("updateRealTimeData is called with {} with {}", obj.getDevice_code(), sensorInfo.getSensor_device_id());
//*** 20190405 如果是配置数据,则直接更新数据库,并更新缓存,数据不进入历史表里面
if( sensorInfo.getData_type() == 1 ){
@ -108,7 +113,7 @@ public class IotSensorInfoServiceImpl extends BaseServiceImpl implements IotSens
return resultMap ;
}
}
// 上传一些无用的传感器信息
if( ObjectUtil.isEmpty(sensorInfo)){
LOGGER.warn("updateRealTimeData is called with {} unuserfull IotSensorInfoBO", obj);
@ -126,6 +131,8 @@ public class IotSensorInfoServiceImpl extends BaseServiceImpl implements IotSens
// 设置传感器id
obj.setId(sensorInfo.getId());
Integer num = dao.update("IotSensorInfo.updateRealTimeData_byid", obj);
LogUtil4j.debugLogger.debug("IotSensorInfo.updateRealTimeData_byid is call with {}---{}---{}({})"
, obj.getSensor_device_id(), obj.getPort_id(), obj.getSdata(), num);
if(num > 0 ){
// 传感器数据更新成功
IotSensorInfoBO sensor = ProCacheUtil.getCache(CacheName.SENSORINFO, sensorInfo.getId().toString() );
@ -137,7 +144,7 @@ public class IotSensorInfoServiceImpl extends BaseServiceImpl implements IotSens
iotSensorHistory.setSensor_id(sensor.getId());
iotSensorHistory.setSdata(obj.getStr_sdata());
iotSensorHistory.setAtime(obj.getMtime());
LOGGER.debug("updateRealTimeData is called with {} insert IotHistorySensorData with {}", obj, iotSensorHistory);
LogUtil4j.debugLogger.debug("updateRealTimeData is called with {} insert IotHistorySensorData with {}", obj, iotSensorHistory);
dao.insert("IotHistorySensorData.insert", iotSensorHistory);
}
sensor.setStr_sdata( obj.getStr_sdata() );
@ -145,16 +152,19 @@ public class IotSensorInfoServiceImpl extends BaseServiceImpl implements IotSens
else{
// 正常行 sdata
if(sensor.getSdata() == null ){
LogUtil4j.debugLogger.debug("IotSensorInfoBO{} without sdata", sensor.getDevice_code() + "-" + sensor.getSensor_device_id());
sensor.setSdata(-11111f);
}
if( sensorDataStratety(obj.getSdata() ,sensor.getSdata() ,sensor) ){
LogUtil4j.debugLogger.debug("sensor({}) check change with ({}), ({})"
, sensor.getSensor_device_id(), obj.getSdata() ,sensor.getSdata());
if( sensorDataStratety(sensor.getSdata(), obj.getSdata(), sensor) ){
// 添加历史数据。目前只添加变化的历史数据
IotHistorySensorData iotSensorHistory = new IotHistorySensorData();
iotSensorHistory.setSensor_id(sensor.getId());
iotSensorHistory.setSdata(obj.getSdata().toString());
iotSensorHistory.setAtime(obj.getMtime());
LOGGER.debug("updateRealTimeData is called with {} insert IotHistorySensorData with {}", obj, iotSensorHistory);
dao.insert("IotHistorySensorData.insert", iotSensorHistory);
num = dao.insert("IotHistorySensorData.insert", iotSensorHistory);
LogUtil4j.debugLogger.debug("IotHistorySensorData.insert with ({})", iotSensorHistory);
}
sensor.setSdata(obj.getSdata());
sensor.setRequest_sdata(obj.getRequest_sdata());
@ -171,6 +181,7 @@ public class IotSensorInfoServiceImpl extends BaseServiceImpl implements IotSens
}
private Boolean sensorDataStratety(Object oldvalue , Object newValue ,IotSensorInfoBO sensor ){
if( ObjectUtil.isEmpty(sensor.getStoreTime() ) ){
sensor.setStoreTime(new Date());
}
@ -228,6 +239,10 @@ public class IotSensorInfoServiceImpl extends BaseServiceImpl implements IotSens
if(flag){
sensor.setStoreTime(new Date());
}
LogUtil4j.debugLogger.debug("called with {} ret: {}"
, sensor.getSensor_device_id() + "-" + sensor.getPort_id() + "-" + sensor.getStore_strage()
+ "-" + sensor.getStoreTime() + ":" + oldvalue + "-" + newValue, flag);
return flag ;
}

View File

@ -1,22 +1,22 @@
package com.lp.util;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.List;
public class LogUtil{
public static Logger otherLogger =Logger.getLogger("other");
private final static Log LOGGER = LogFactory.getLog(LogUtil.class);
private static RuntimeMXBean runtimeMXBean=ManagementFactory.getRuntimeMXBean();
@ -103,7 +103,7 @@ public class LogUtil{
sb.append(msg);
LOGGER.info(sb.toString());
}
//获取当前进程号
private static String getPid(){
return runtimeMXBean.getName().split("@")[0];

View File

@ -139,7 +139,7 @@ public class QRCodeUtil {
}
public static void encode(String content, String imgPath, String destPath, boolean needCompress,String fileName) throws Exception {
LOGGER.debug("{} encode is called with {}---{}---{}---{}"
LogUtil4j.debugLogger.debug("{} encode is called with {}---{}---{}---{}"
, QRCodeUtil.class, content, imgPath, destPath, fileName);
BufferedImage image = QRCodeUtil.createImage(content, imgPath, needCompress);
mkdirs(destPath);

View File

@ -39,6 +39,8 @@ public class IotTrigger {
// trigger 不能为空
if( iotSensorInfoBo!=null && ObjectUtil.isNotEmpty(iotSensorInfoBo.getTriggerList()) && ObjectUtil.isNotEmpty(obj.getSdata()) ){
List<IotTriggerInfoBO> triggerList = iotSensorInfoBo.getTriggerList();
LogUtil4j.debugLogger.debug("will trigger with sensor:({}---{}) with ({})triggers"
, obj.getDevice_code(), sensorDevicePort, triggerList.size());
for( IotTriggerInfoBO trigger : triggerList ){
Boolean trigger_flag = false;
String message ="" ;
@ -523,6 +525,8 @@ public class IotTrigger {
}
}
}
LogUtil4j.debugLogger.debug("sensor:({}---{}) trigger with ({})"
, obj.getDevice_code(), sensorDevicePort, exception_flag);
}catch(Exception e){
LogUtil.errorLog(e);
return -1 ;
@ -885,7 +889,7 @@ public class IotTrigger {
return "" ;
}
LOGGER.debug("sendWechat is called with IotSensorInfoBO({})---IotTriggerInfoBO({})---BussinessTriggerBO({})---BaseDao({})---flag({})"
LogUtil4j.debugLogger.debug("sendWechat is called with IotSensorInfoBO({})---IotTriggerInfoBO({})---BussinessTriggerBO({})---BaseDao({})---flag({})"
, param, trigger, message, dao, flag);
// 将string 转json
ContactorBO contactor = JSON.parseObject(trigger.getAction_params(), ContactorBO.class);
@ -942,7 +946,7 @@ public class IotTrigger {
// wxTemplate.setTemplateId(ProConfig.WEIXIN.NOTICE_2);
try {
String ret = wxMpserver.templateSend(wxTemplate);
LOGGER.debug("wxMpserver.templateSend is called {} res: ({})", wxTemplate, ret);
LogUtil4j.debugLogger.debug("wxMpserver.templateSend is called {} res: ({})", wxTemplate, ret);
} catch (Exception e) {
LOGGER.error("wxMpserver.templateSend", e);
e.printStackTrace();

View File

@ -4,9 +4,19 @@ jdbc.maxActive=200
jdbc.maxWait=500
jdbc.defaultAutoCommit=true
jdbc.url=jdbc:mysql://192.168.3.5:35007/easyiot?characterEncoding=utf8&serverTimezone=Asia/Shanghai
#\u6D4B\u8BD5 1
#jdbc.url=jdbc:mysql://192.168.3.5:35007/easyiot?characterEncoding=utf8&serverTimezone=Asia/Shanghai
#\u6D4B\u8BD5 2
#jdbc.url=jdbc:mysql://192.168.1.222:3306/easyiot?characterEncoding=utf8&serverTimezone=Asia/Shanghai
jdbc.username=easyiot
jdbc.password=easyiot
# \u6D4B\u8BD5 1
#jdbc.password=easyiot
#\u6D4B\u8BD5 2
#jdbc.password=nnSf2aySKrt7xe6z
#\u8FDE\u63A5\u521D\u59CB\u503C\uFF0C\u8FDE\u63A5\u6C60\u542F\u52A8\u65F6\u521B\u5EFA\u7684\u8FDE\u63A5\u6570\u91CF\u7684\u521D\u59CB\u503C \u9ED8\u8BA4\u503C\u662F0
jdbc.initialSize=10

View File

@ -1,6 +1,10 @@
mqtt.clientId=iot_platform_hy
mqtt.username=yinzy
mqtt.password=yzy123456
mqtt.cleanSession=true
mqtt.cleanSession=false
mqtt.autoReconnect=true
mqtt.keepalive=3600
mqtt.timeout=30
mqtt.serverURI1=tcp://192.168.3.5:35883
mqtt.clientId=iot_platform_1
mqtt.simpleURI=wss://iot.hy-ec.cn/mqtt
mqtt.service.topic=/dev/coo/+,/edge/+,/sys/update/+

View File

@ -2,19 +2,23 @@
#mp \u516C\u4F17\u53F7\u914D\u7F6E
#weixin.mp.appid=wxcda55f09127119f9
weixin.mp.appid=wxff7e4d874e52241a
weixin.mp.secret=acb909da964498dc9b1b76c1031aaca9
#weixin.mp.appid=wxff7e4d874e52241a
#weixin.mp.appid=wx00b6998a595762a0
#weixin.mp.secret=f126999b83b902b697aaee8c7128839c
#weixin.mp.secret=acb909da964498dc9b1b76c1031aaca9
#weixin.mp.secret=c6700a2962dae167ef4dac3b9494357e
weixin.mp.token=iotadmin
#weixin.mp.aesKey=71AJPXUTBFje7YctbndixEoNrUfQxyHH56EWoRlY8Cd
weixin.mp.aesKey=7MhltzJjl4J7E9YbY5lk3azXBx4LmuZX9Cl7lkLyaH5
#weixin.mp.aesKey=7MhltzJjl4J7E9YbY5lk3azXBx4LmuZX9Cl7lkLyaH5
#weixin.mp.aesKey=o0EXvGbPWG4F24WiibiiUw0Sn7su3FrOfOjNg9i3JFL
#mch \u5546\u6237 \u4FE1\u606F
weixin.mp.mch.id=1523933151
weixin.mp.mch.key=
#\u8BF7\u6C42URL
local.domain=http://iotadmin.segsvip.com
#local.domain=https://iotadmin.segsvip.com
#local.domain=https://iot.hy-ec.cn
#
# local.domain=http://127.0.0.1:8080/lpro
@ -26,8 +30,8 @@ weixin.mp.oauth2.redirect_uri=/service/oauth2/authorize/weixin/mp
#----------------------\u5FAE\u4FE1\u6D88\u606F\u6A21\u677F\u53F7----------------------------
weixin.msg.tpl.NOTICE_1=2xuSdxuFrfJidejIEYSVA7nXDC0PYU2bwow0Gm90pnU
weixin.msg.tpl.NOTICE_2=2xuSdxuFrfJidejIEYSVA7nXDC0PYU2bwow0Gm90pnU
weixin.msg.tpl.NOTICE_3=hjtAb8aVxzsC6c-ZpuZ47F3AC-2txpUxHOrUdewsCPU
weixin.msg.tpl.NOTICE_2=hjtAb8aVxzsC6c-ZpuZ47F3AC-2txpUxHOrUdewsCPU
weixin.msg.tpl.NOTICE_3=JyO2orI0NMHU2wVfNnHP0jeiaR1XXLJXDJ3snNpwa9U
weixin.msg.tpl.NOTICE_4=
weixin.msg.tpl.NOTICE_5=
weixin.msg.tpl.NOTICE_6=

View File

@ -25,7 +25,7 @@ log4j.appender.Threshold=DEBUG
#JDBC config
log4j.logger.com.mybatis=DEBUG
log4j.logger.com.mybatis=OFF
log4j.logger.com.mybatis.common.jdbc.SimpleDataSource=OFF
log4j.logger.com.mybatis.common.jdbc.ScriptRunner=OFF
log4j.logger.com.mybatis.sqlmap.engine.impl.SqlMapClientDelegate=OFF
@ -56,15 +56,34 @@ log4j.appender.LOG_FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOG_FILE.layout.ConversionPattern=%d %p [%t] %C.%M(%F:%L) - %m%n
# SQL\u65E5\u5FD7
log4j.logger.sql=DEBUG,sql
log4j.appender.sql=org.apache.log4j.DailyRollingFileAppender
log4j.appender.sql.File=/data/lpro/logs/sql.log
log4j.appender.sql.DatePattern='_'yyyy-MM-dd'.log'
log4j.appender.sql.layout=org.apache.log4j.PatternLayout
log4j.appender.sql.layout.ConversionPattern=%d %p [%c %L %l] - %m%n
log4j.additivity.sql=false
#\u5176\u4ED6\u884C\u4E3A\u7684\u65E5\u5FD7\u6587\u4EF6\uFF0C\u5982\u652F\u4ED8\u8BB0\u5F55\u7B49
log4j.logger.other=INFO,other
log4j.logger.other=DEBUG,other
log4j.appender.other=org.apache.log4j.DailyRollingFileAppender
log4j.appender.other.File=/data/lpro/logs/other.log
log4j.appender.other.DatePattern='_'yyyy-MM-dd'.log'
log4j.appender.other.layout=org.apache.log4j.PatternLayout
log4j.appender.other.layout.ConversionPattern=%d %p [%c %L %l] - %m%n
log4j.additivity.other=true
log4j.appender.other.layout.ConversionPattern=%d %p %C.%M(%F:%L) - %m%n
log4j.additivity.other=false
#\u5176\u4ED6\u884C\u4E3A\u7684\u65E5\u5FD7\u6587\u4EF6\uFF0C\u5982\u652F\u4ED8\u8BB0\u5F55\u7B49
log4j.logger.debug=DEBUG, debug
log4j.appender.debug=org.apache.log4j.DailyRollingFileAppender
log4j.appender.debug.File=/data/lpro/logs/debug.log
log4j.appender.debug.DatePattern='_'yyyy-MM-dd'.log'
log4j.appender.debug.layout=org.apache.log4j.PatternLayout
log4j.appender.debug.layout.ConversionPattern=%d %p %C.%M(%F:%L) - %m%n
log4j.additivity.debug=false

View File

@ -11,6 +11,9 @@
var base_domain="http://"+window.location.host+"<%=basePath%>";
var userKey= "${user.user_key}";
var websocket_url = 'ws://' + window.location.host + '<%=ProConfig.PROJECT_NAME%>/service/websocket';
var mqttUserName = '<%=ProConfig.MQTT.USERNAME%>'
var mqttPassword = '<%=ProConfig.MQTT.PASSWORD%>'
var mqttUrl = '<%=ProConfig.MQTT.MQTTSIMPLEURI%>';
var videoUrl = "<%=ProConfig.VIDEO_DOMAIN%>";
var status_code = {
'OK' : <%=Code.ResponseCode.SystemCode.OK%> ,

View File

@ -281,7 +281,7 @@
username: '<%=ProConfig.MQTT.USERNAME%>',
password: '<%=ProConfig.MQTT.PASSWORD%>',
}
client = mqtt.connect('ws://221.195.106.155:35884/mqtt', options) ;
client = mqtt.connect('<%=ProConfig.MQTT.MQTTSIMPLEURI%>', options) ;
// client = mqtt.connect('ws://'+document.domain+':8083/mqtt', options) ;
client.on('reconnect', function(error) {
$("#init-table").tableAdaptor( $(".curr").html() );

View File

@ -373,9 +373,13 @@ function searchDeviceInfo(dataParam){
if(isOK(data)){
var dataObj = data.data ;
for(var i=0; i <dataObj.length;i++){
$(".sceneList-info").append($("#template0").html().format( dataObj[i].name ,
$(".sceneList-info").append($("#template0").html().format(
dataObj[i].name,
nodeStatusInfo(dataObj[i].iot_node_status ,dataObj[i].iot_node_status) ,
dataObj[i].device_code, getSensorListHtml( dataObj[i].iotSensorList, dataParam.scene_id ,dataObj[i].iot_node_status ) ,dataObj[i].id ) );
dataObj[i].device_code,
getSensorListHtml( dataObj[i].iotSensorList, dataParam.scene_id ,dataObj[i].iot_node_status ) ,
dataObj[i].id
) );
}
}
});
@ -386,7 +390,7 @@ function getSensorListHtml(dataT,sid , node_status){
var src1 = 'src="<%=sensorImg%>/on.png"';
var src2 = 'src="<%=sensorImg%>/off.png"';
// console.log(dataT);
console.log("monitor getSensorListHtml with %s, %o", sid, dataT);
console.log("monitor getSensorListHtml with %s, %o, %s", sid, dataT, node_status);
for(var i=0;i<dataT.length;i++){
// 传感器logo数据
var sensorLogo = dataT[i].measure_unit_type ;
@ -483,9 +487,9 @@ function getMoreSwitch(data,dataType,sensor_id){
function nodeStatusInfo(code,value){
if(code == 16){
return "<span class='blue-span'>"+value+"</span>" ;
return "<span class='blue-span'>"+'在线'+"</span>" ;
}else{
return "<span class='red-span'>"+value+"</span>" ;
return "<span class='red-span'>"+'离线'+"</span>" ;
}
}
@ -550,8 +554,9 @@ function mqttInit(){
password: '<%=ProConfig.MQTT.PASSWORD%>',
}
// client = mqtt.connect('ws://'+document.domain+':35883', options) ;
client = mqtt.connect('ws://221.195.106.155:35884/mqtt', options) ;
client = mqtt.connect('<%=ProConfig.MQTT.MQTTSIMPLEURI%>', options) ;
client.on('reconnect', function(error) {
console.log('mqtt reconnect')
reflash( $(".dashboard-menu li.active").attr("sid"));
})
client.on('error', function(error) {

View File

@ -199,7 +199,7 @@
username: '<%=ProConfig.MQTT.USERNAME%>',
password: '<%=ProConfig.MQTT.PASSWORD%>',
}
client = mqtt.connect('ws://221.195.106.155:35884/mqtt', options) ;
client = mqtt.connect('<%=ProConfig.MQTT.MQTTSIMPLEURI%>', options) ;
// client = mqtt.connect('ws://'+document.domain+':8083/mqtt', options) ;
client.on('reconnect', function(error) {
for(var i=1;i< paged;i++){
@ -255,11 +255,14 @@
if(isOK(data)){
var dataObj = data.data.data ;
for(var i=0; i <dataObj.length;i++){
$(".container").append($("#template0").html().format(dataObj[i].name ,dataObj[i].data.iot_node_status
,disvalue(dataObj[i].device_code,10)
,getSensorListHtml(dataObj[i].iotSensorList,sid ,dataObj[i].iot_node_status )
, getDeviceState(dataObj[i].iot_node_status),
dataObj[i].id ) );
$(".container").append($("#template0").html().format(
dataObj[i].name
,dataObj[i].data.iot_node_status
,disvalue(dataObj[i].device_code,10)
,getSensorListHtml(dataObj[i].iotSensorList,sid ,dataObj[i].iot_node_status )
, getDeviceState(dataObj[i].iot_node_status),
dataObj[i].id
) );
}
if(data.data.totalPage > data.data.paged){
@ -391,7 +394,7 @@
var src1 = 'src="<%=sensorImg%>/on.png"';
<%--var src2 = 'src="<%=basePath%>/image/oss/iot/off.png"';--%>
var src2 = 'src="<%=sensorImg%>/off.png"';
console.log("device getSensorListHtml with %s, %o", sid, dataT);
console.log("device getSensorListHtml with %s, %o, %s", sid, dataT, node_status);
for(var i=0;i<dataT.length;i++){
if( dataT[i].data_type ==2){
continue ;

View File

@ -10,8 +10,8 @@ var baseurl= window.location.href.split("/page")[0] ;
var ucode= localStorage.getItem("ucode");
var mqttUserName = 'yinzy' ;
var mqttPassword = 'yzy123456' ;
// var mqttUserName = 'yinzy' ;
// var mqttPassword = 'yzy123456' ;
// config end -----------------------------------------------------------------

View File

@ -115,7 +115,7 @@
username: mqttUserName ,
password: mqttPassword ,
}
client = mqtt.connect('ws://221.195.106.155:35884/mqtt', options) ;
client = mqtt.connect(mqttUrl, options) ;
// client = mqtt.connect('ws://'+document.domain+':8083/mqtt', options) ;
client.on('reconnect', function(error) {
console.log("reconnect");

View File

@ -449,7 +449,7 @@
password: mqttPassword ,
protocol: 'ws',
}
client = mqtt.connect('ws://221.195.106.155:35884/mqtt', options) ;
client = mqtt.connect(mqttUrl, options) ;
// client = mqtt.connect('ws://'+document.domain+':8083/mqtt', options) ;
client.on('reconnect', function(error) {
console.log("reconnect " + error);

View File

@ -193,7 +193,7 @@
password: mqttPassword ,
}
// client = mqtt.connect('ws://'+document.domain+':8083/mqtt', options) ;
client = mqtt.connect('ws://221.195.106.155:35884/mqtt', options) ;
client = mqtt.connect(mqttUrl, options) ;
client.on('reconnect', function(error) {
console.log("reconnect");
})

View File

@ -13,9 +13,7 @@
</style>
</head>
<body>
nihao hello
nihao hello
</body>
<script type="text/javascript">

View File

@ -30,7 +30,7 @@
password: '<%=ProConfig.MQTT.PASSWORD%>',
}
var client = mqtt.connect('ws://192.168.3.5:35884/mqtt', options)
var client = mqtt.connect('<%=ProConfig.MQTT.MQTTSIMPLEURI%>', options)
client.on('reconnect', function(error) {
console.log('正在重连:', error)