Commit 64515fa9 authored by 赵啸非's avatar 赵啸非

修改站点请求地址

parent 0ece7525
...@@ -4,8 +4,6 @@ NODE_ENV = production ...@@ -4,8 +4,6 @@ NODE_ENV = production
# 地址 # 地址
VUE_APP_BASE_API = /basics_api/m VUE_APP_BASE_API = /basics_api/m
# websocket地址
VUE_APP_WEBSOCKET_API =192.168.2.144:18222/m
# 门户登录地址 # 门户登录地址
VUE_APP_PORTAL_URL = /portal_home VUE_APP_PORTAL_URL = /portal_home
......
...@@ -36,7 +36,6 @@ instance.interceptors.request.use( ...@@ -36,7 +36,6 @@ instance.interceptors.request.use(
// console.log("sessionStorage",window.sessionStorage) // console.log("sessionStorage",window.sessionStorage)
config.headers.Authorization = window.sessionStorage.getItem("token") || ""; config.headers.Authorization = window.sessionStorage.getItem("token") || "";
//console.log("request config and session",config,window.sessionStorage); //console.log("request config and session",config,window.sessionStorage);
console.log(config);
return config; return config;
}, },
(err) => { (err) => {
......
...@@ -229,6 +229,9 @@ export default { ...@@ -229,6 +229,9 @@ export default {
let newFormData = {}; let newFormData = {};
// this.form = this.encode(data, this.form); // this.form = this.encode(data, this.form);
this.search.forEach((item) => { this.search.forEach((item) => {
console.log("item",this.form[item.name])
//复选框 //复选框
if (item.type === "checkbox") { if (item.type === "checkbox") {
if (this.form[item.name] == undefined) { if (this.form[item.name] == undefined) {
...@@ -272,6 +275,8 @@ export default { ...@@ -272,6 +275,8 @@ export default {
}, },
onSubmit() { onSubmit() {
let { path, query } = this.$route; let { path, query } = this.$route;
let data = this.decode(this.form); let data = this.decode(this.form);
this.$router.push({ this.$router.push({
path: path, path: path,
......
...@@ -67,10 +67,10 @@ ...@@ -67,10 +67,10 @@
<slot name="table-head-left2"></slot> <slot name="table-head-left2"></slot>
</el-row> </el-row>
</div> </div>
<el-row>
<slot name="table-head-row2-left"></slot>
</el-row>
</div> </div>
<el-row>
<slot name="table-head-row2-left"></slot>
</el-row>
<div class="table-head-right"> <div class="table-head-right">
<div class="extend flex flex-pack-justify"> <div class="extend flex flex-pack-justify">
......
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
>批量重启</el-button >批量重启</el-button
> >
<el-tag <el-tag
slot="table-head-row2-left" slot="table-body-head"
size="mini" size="mini"
class="cursord" class="cursord"
@click="changeStat(null)" @click="changeStat(null)"
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
> >
<el-tag <el-tag
slot="table-head-row2-left" slot="table-body-head"
size="mini" size="mini"
style="margin: 5px" style="margin: 5px"
type="success" type="success"
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
> >
<el-tag <el-tag
slot="table-head-row2-left" slot="table-body-head"
size="mini" size="mini"
style="margin: 5px" style="margin: 5px"
type="danger" type="danger"
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
> >
<el-tag <el-tag
slot="table-head-row2-left" slot="table-body-head"
size="mini" size="mini"
style="margin: 5px" style="margin: 5px"
type="danger" type="danger"
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
> >
<el-tag <el-tag
slot="table-head-row2-left" slot="table-body-head"
size="mini" size="mini"
style="margin: 5px" style="margin: 5px"
type="danger" type="danger"
......
...@@ -210,7 +210,6 @@ ...@@ -210,7 +210,6 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.mortals.xhx</groupId> <groupId>com.mortals.xhx</groupId>
<artifactId>common-lib</artifactId> <artifactId>common-lib</artifactId>
...@@ -252,6 +251,11 @@ ...@@ -252,6 +251,11 @@
<groupId>io.jsonwebtoken</groupId> <groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId> <artifactId>jjwt</artifactId>
</dependency> </dependency>
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>5.6.0</version>
</dependency>
<dependency> <dependency>
<groupId>p6spy</groupId> <groupId>p6spy</groupId>
<artifactId>p6spy</artifactId> <artifactId>p6spy</artifactId>
......
package com.mortals.xhx.base.framework.aspect; package com.mortals.xhx.base.framework.aspect;
import cn.hutool.core.net.Ipv4Util;
import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.util.ContentCachingRequestWrapper; import org.springframework.web.util.ContentCachingRequestWrapper;
...@@ -22,7 +17,9 @@ import org.springframework.web.util.ContentCachingRequestWrapper; ...@@ -22,7 +17,9 @@ import org.springframework.web.util.ContentCachingRequestWrapper;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* 打印每个请求的入参、出参等信息 * 打印每个请求的入参、出参等信息
...@@ -69,12 +66,13 @@ public class WebLogAspect { ...@@ -69,12 +66,13 @@ public class WebLogAspect {
if (map != null&&result!=null) { if (map != null&&result!=null) {
String startTime = map.getOrDefault("startTime", String.valueOf(System.currentTimeMillis())); String startTime = map.getOrDefault("startTime", String.valueOf(System.currentTimeMillis()));
long takeTime = (System.currentTimeMillis() - Long.parseLong(startTime)); long takeTime = (System.currentTimeMillis() - Long.parseLong(startTime));
String req = map.getOrDefault("req", "");
if (result instanceof String) { if (result instanceof String) {
log.info(" \n 请求路径:{} 耗时:{}ms 客户端IP:{} \n 请求报文:{} \n 响应报文:{} " log.info(" \n 请求路径:{} 耗时:{}ms 客户端IP:{} \n 请求报文:{} \n 响应报文:{}\n cookies:{} "
, request.getRequestURI(), takeTime,ServletUtil.getClientIP(request), map.getOrDefault("req", ""), result); , request.getRequestURI(), takeTime,ServletUtil.getClientIP(request), req, result);
} else { } else {
log.info(" \n 请求路径:{} 耗时:{}ms 客户端IP:{}\n 请求报文:{} \n 响应报文:{}" log.info(" \n 请求路径:{} 耗时:{}ms 客户端IP:{}\n 请求报文:{} \n 响应报文:{}\n cookies:{}"
, request.getRequestURI(), takeTime,ServletUtil.getClientIP(request), map.getOrDefault("req", ""), JSON.toJSONString(result)); , request.getRequestURI(), takeTime,ServletUtil.getClientIP(request), req, JSON.toJSONString(result));
} }
} }
...@@ -97,11 +95,15 @@ public class WebLogAspect { ...@@ -97,11 +95,15 @@ public class WebLogAspect {
requestInfo.put("remoteAddr", remoteAddr); requestInfo.put("remoteAddr", remoteAddr);
if (req instanceof ContentCachingRequestWrapper) { if (req instanceof ContentCachingRequestWrapper) {
ContentCachingRequestWrapper wrapper = (ContentCachingRequestWrapper) req; ContentCachingRequestWrapper wrapper = (ContentCachingRequestWrapper) req;
String bodyStr = new String(wrapper.getContentAsByteArray(), StandardCharsets.UTF_8); String bodyStr = new String(wrapper.getContentAsByteArray(), StandardCharsets.UTF_8);
if (bodyStr.startsWith("{")) { if (bodyStr.startsWith("{")) {
JSONObject jsonObject = JSON.parseObject(bodyStr); JSONObject jsonObject = JSON.parseObject(bodyStr);
requestInfo.put("requestBody", jsonObject); requestInfo.put("requestBody", jsonObject);
} }
String cookieStr = Arrays.asList(wrapper.getCookies()).stream().map(item -> JSON.toJSONString(item)).collect(Collectors.joining("|"));
requestInfo.put("cookieStr", cookieStr);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("解析请求失败", e); log.error("解析请求失败", e);
......
...@@ -27,6 +27,7 @@ import org.springframework.util.ObjectUtils; ...@@ -27,6 +27,7 @@ import org.springframework.util.ObjectUtils;
import java.util.Date; import java.util.Date;
import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_PHP_IN_HTTP_URL;
import static com.mortals.xhx.common.model.MessageHeader.DEVICECODE; import static com.mortals.xhx.common.model.MessageHeader.DEVICECODE;
import static com.mortals.xhx.common.model.MessageHeader.MESSAGETYPE; import static com.mortals.xhx.common.model.MessageHeader.MESSAGETYPE;
...@@ -97,11 +98,13 @@ public class DirectDynamicListener implements MessageListener { ...@@ -97,11 +98,13 @@ public class DirectDynamicListener implements MessageListener {
} }
//获取exchange, //获取exchange,
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId()); PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
String phpInUrl=GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_IN_HTTP_URL, "http://172.15.28.116:8090");
if (!Constant.MESSAGETYPE_HEARTBEAT.equalsIgnoreCase(messageType) if (!Constant.MESSAGETYPE_HEARTBEAT.equalsIgnoreCase(messageType)
&& !ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(platformEntity)
&& platformEntity.getSendSwitch() == YesNoEnum.YES.getValue()) { && platformEntity.getSendSwitch() == YesNoEnum.YES.getValue()) {
if (platformEntity.getSendMsgType() == SendMsgTypeEnum.http.getValue() && !ObjectUtils.isEmpty(platformEntity.getSendUrl())) { if (platformEntity.getSendMsgType() == SendMsgTypeEnum.http.getValue()) {
SendTask sendTask = new SendTask(platformEntity.getSendUrl(), queueMsg.getData()); SendTask sendTask = new SendTask(phpInUrl, queueMsg.getData());
sendTaskThreadPool.execute(sendTask); sendTaskThreadPool.execute(sendTask);
} }
} }
......
package com.mortals.xhx.busiz.web; package com.mortals.xhx.busiz.web;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.net.URLDecoder; import cn.hutool.core.net.URLDecoder;
import cn.hutool.core.net.url.UrlBuilder; import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil; import cn.hutool.core.util.URLUtil;
import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.extra.servlet.ServletUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
...@@ -183,9 +185,9 @@ public class DeviceApiController { ...@@ -183,9 +185,9 @@ public class DeviceApiController {
//判断设备是否设置了url 如果设置了,则用设备的 否则用产品的 //判断设备是否设置了url 如果设置了,则用设备的 否则用产品的
buildHomeUrl(deviceEntity, productEntity, serverInfo); buildHomeUrl(deviceEntity, productEntity, serverInfo);
//对外 //对外
// serverInfo.setServerUrl(platformEntity.getSendUrl()); serverInfo.setServerUrl(platformEntity.getSendUrl());
String phpUrl=GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://10.12.185.213:8090"); //String phpUrl=GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://10.12.185.213:8090");
serverInfo.setServerUrl(phpUrl); //serverInfo.setServerUrl(phpUrl);
registerResp.setServiceInfo(serverInfo); registerResp.setServiceInfo(serverInfo);
DeviceInfo deviceInfo = new DeviceInfo(); DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setSiteId(deviceEntity.getSiteId()); deviceInfo.setSiteId(deviceEntity.getSiteId());
...@@ -206,7 +208,7 @@ public class DeviceApiController { ...@@ -206,7 +208,7 @@ public class DeviceApiController {
deviceEntity.setDeviceVersion(req.getDeviceVersion() == null ? "" : req.getDeviceVersion()); deviceEntity.setDeviceVersion(req.getDeviceVersion() == null ? "" : req.getDeviceVersion());
deviceService.getDeviceDao().update(deviceEntity); deviceService.getDeviceDao().update(deviceEntity);
rsp.setData(deviceResp); rsp.setData(deviceResp);
SendThirdPartyTask sendThirdPartyTask = new SendThirdPartyTask(deviceEntity, productEntity, platformEntity,deviceService); SendThirdPartyTask sendThirdPartyTask = new SendThirdPartyTask(deviceEntity, productEntity, platformEntity, deviceService);
sendTaskThreadPool.execute(sendThirdPartyTask); sendTaskThreadPool.execute(sendThirdPartyTask);
} catch (AppException e) { } catch (AppException e) {
log.error("接收数据失败", e); log.error("接收数据失败", e);
...@@ -219,7 +221,7 @@ public class DeviceApiController { ...@@ -219,7 +221,7 @@ public class DeviceApiController {
rsp.setMsg(e.getMessage()); rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp); return JSON.toJSONString(rsp);
} }
log.info("响应【设备注册】【响应体】--> " + JSONObject.toJSONString(rsp)); //log.info("响应【设备注册】【响应体】--> " + JSONObject.toJSONString(rsp));
return JSON.toJSONString(rsp); return JSON.toJSONString(rsp);
} }
...@@ -410,9 +412,9 @@ public class DeviceApiController { ...@@ -410,9 +412,9 @@ public class DeviceApiController {
ServerInfo serverInfo = new ServerInfo(); ServerInfo serverInfo = new ServerInfo();
buildHomeUrl(deviceEntity, productEntity, serverInfo); buildHomeUrl(deviceEntity, productEntity, serverInfo);
//serverInfo.setServerUrl(platformEntity.getSendUrl()); serverInfo.setServerUrl(platformEntity.getSendUrl());
String phpUrl=GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://10.12.185.213:8090"); //String phpUrl=GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://10.12.185.213:8090");
serverInfo.setServerUrl(phpUrl); //serverInfo.setServerUrl(phpUrl);
registerResp.setServiceInfo(serverInfo); registerResp.setServiceInfo(serverInfo);
DeviceInfo deviceInfo = new DeviceInfo(); DeviceInfo deviceInfo = new DeviceInfo();
...@@ -439,7 +441,7 @@ public class DeviceApiController { ...@@ -439,7 +441,7 @@ public class DeviceApiController {
rsp.setMsg(e.getMessage()); rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp); return JSON.toJSONString(rsp);
} }
log.info("响应【设备前端新增或更新】【响应体】--> " + JSONObject.toJSONString(rsp)); //log.info("响应【设备前端新增或更新】【响应体】--> " + JSONObject.toJSONString(rsp));
return JSON.toJSONString(rsp); return JSON.toJSONString(rsp);
} }
...@@ -470,7 +472,6 @@ public class DeviceApiController { ...@@ -470,7 +472,6 @@ public class DeviceApiController {
throw new AppException(DEVICE_VERSION_UNEXIST, DEVICE_VERSION_UNEXIST_CONTENT); throw new AppException(DEVICE_VERSION_UNEXIST, DEVICE_VERSION_UNEXIST_CONTENT);
} }
ProductVersionInfo productVersionInfo = new ProductVersionInfo(); ProductVersionInfo productVersionInfo = new ProductVersionInfo();
BeanUtils.copyProperties(productVersionEntity, productVersionInfo, BeanUtil.getNullPropertyNames(productVersionEntity)); BeanUtils.copyProperties(productVersionEntity, productVersionInfo, BeanUtil.getNullPropertyNames(productVersionEntity));
buildDownloadUrl(productVersionEntity, productVersionInfo); buildDownloadUrl(productVersionEntity, productVersionInfo);
...@@ -576,11 +577,11 @@ public class DeviceApiController { ...@@ -576,11 +577,11 @@ public class DeviceApiController {
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue()); rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
try { try {
ProductEntity productEntity = productService.selectOne(new ProductQuery().productCode(deviceMsgReq.getProductCode())); ProductEntity productEntity = productService.selectOne(new ProductQuery().productCode(deviceMsgReq.getProductCode()));
if(!ObjectUtils.isEmpty(productEntity)){ if (!ObjectUtils.isEmpty(productEntity)) {
List<DeviceEntity> deviceEntities = deviceService.find(new DeviceQuery().productId(productEntity.getId()).siteId(deviceMsgReq.getSiteid())); List<DeviceEntity> deviceEntities = deviceService.find(new DeviceQuery().productId(productEntity.getId()).siteId(deviceMsgReq.getSiteid()));
List<DeviceMsgReq> list = deviceEntities.stream().map(item -> { List<DeviceMsgReq> list = deviceEntities.stream().map(item -> {
DeviceMsgReq msgReq = new DeviceMsgReq(); DeviceMsgReq msgReq = new DeviceMsgReq();
BeanUtils.copyProperties(deviceMsgReq,msgReq,BeanUtil.getNullPropertyNames(deviceMsgReq)); BeanUtils.copyProperties(deviceMsgReq, msgReq, BeanUtil.getNullPropertyNames(deviceMsgReq));
msgReq.setDeviceCode(item.getDeviceCode()); msgReq.setDeviceCode(item.getDeviceCode());
return msgReq; return msgReq;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
...@@ -913,11 +914,20 @@ public class DeviceApiController { ...@@ -913,11 +914,20 @@ public class DeviceApiController {
private void buildDownloadUrl(ProductVersionEntity productVersionEntity, ProductVersionInfo productVersionInfo) { private void buildDownloadUrl(ProductVersionEntity productVersionEntity, ProductVersionInfo productVersionInfo) {
String download = ""; String download = "";
if (!ObjectUtils.isEmpty(productVersionEntity.getFilePath())) { if (!ObjectUtils.isEmpty(productVersionEntity.getFilePath())) {
download = productVersionEntity.getFilePath(); String fileType = FileUtil.extName(productVersionEntity.getFilePath());
if ("zip".equals(fileType)) {
String mainName = FileUtil.mainName(productVersionEntity.getFilePath());
String replace = StrUtil.replace(productVersionEntity.getFilePath(), FileUtil.getName(productVersionEntity.getFilePath()), "");
download = replace + mainName + "/";
log.info("download:" + download);
} else {
download = productVersionEntity.getFilePath();
log.info("download:" + download);
}
} }
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11091"); String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11091");
//String temp = domain + "/" + download; //String temp = domain + "/" + download;
productVersionInfo.setDownloadUrl(UrlBuilder.of(domain).addPath(download).build()); productVersionInfo.setDownloadUrl(UrlBuilder.of(domain).addPath(download).build());
//productVersionInfo.setDownloadUrl(temp); //productVersionInfo.setDownloadUrl(temp);
log.info("downurl:" + productVersionInfo.getDownloadUrl()); log.info("downurl:" + productVersionInfo.getDownloadUrl());
} }
...@@ -930,16 +940,27 @@ public class DeviceApiController { ...@@ -930,16 +940,27 @@ public class DeviceApiController {
System.out.println(urlBuilder.build()); System.out.println(urlBuilder.build());
String str="http://10.12.185.213:11078/homeDeviceUrl%2Fdsj%2F1920x1080"; String str = "http://10.12.185.213:11078/homeDeviceUrl%2Fdsj%2F1920x1080/";
System.out.println(str); System.out.println(str);
String decode = URLDecoder.decode(str, Charset.defaultCharset()); String decode = URLDecoder.decode(str, Charset.defaultCharset());
System.out.println(decode); System.out.println(decode);
str = "/file/uploadfile/1675836231156.zip";
System.out.println(FileUtil.getPrefix(str));
System.out.println(FileUtil.mainName(str));
System.out.println(FileUtil.getName(str));
String replace = StrUtil.replace(str, FileUtil.getName(str), "");
System.out.println(replace);
//FileUtil.getName()
//URL url = URLUtil.url(domain); //URL url = URLUtil.url(domain);
// System.out.println(StrUtil.removeAllLineBreaks(domain)); // System.out.println(StrUtil.removeAllLineBreaks(domain));
/* String content="OTFENjJBODBBRjFFNDNERDVGMDVGNkY3RTg1MEVDNDIxQUNFNTRCRDhDQTM2QjNGM0MwNEUyNERGOTg3NzVCNjRDRkU1MDg0NjU0QjU1ODgzRTg2OUM4MUJGRTE3ODQzRjJFQkMwNjdEMTRCRTdCQ0RDRENBNDFEQkJEMzQyRThGMzUzOTQ3MjVFRjE5RDUzOTlBMTAxQkM0MzZDRTY4M0Y0Mzg5ODZGM0Y3NUZGMTNEMEQyRDMwMzYzREE4OTBCNEVFM0EwQ0IzNjk3RkNDNTY5NDhENEVGNkE4RUU1QzE5QTg3QzAzMTM4MUE5REQ3RjRCQkQ3RjZDQjhDQUM1RkFENTZCNDZGMjhGQ0Q0MkY3MzI5MUM0MDk5QkUxNDkzRTcwRTQ5NzY1OTZDOURENzJBMzQyQjNENjQ2Q0EyNTkwMDk0QkNENTEyNzNBMzM3NkMwNUJDM0VBQTU3OThDNjk5RDQ0ODMyRTE3RTI1NzdGMDBGN0FENzlDMkYwRkVFMDQwNzIzQzM1NDdGREUxMzQzNjlDMzUzNEU0MkNDRkIwMTY3ODUxRTk1ODQ4RT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FCQkQzQUQ1MzdDOUQ0QTEzRTAwQzYxRUY0QjAwRTkzQUJCNjc5NUJCNDEyNzA5MjVCNEI5NzdCNzg4NzVCNERBMDNDRkM5NDc5NjRGNDI4RUYwRTdCN0EzNEQ1MjgwRTczM0I2N0M4MjQwQjQ4NDdEQzgzOUQ2RURDMDZENDg2OTMyNjgxNzJBRkVERERBRjI2RjY4MzI3RTQ1QzExQzU5NDEzQjc0Q0FDMDM0NDMwRUU4MEQ5RUYyQThBMTYyRjM5RTZDNjc2MjIxNUU3QUU1NTlFREFCODc3M0M4N0JFNDI2MkE2RjkxQUY4NjYwQ0Y0MjNBNjM1MjFDMUQ5RjNCRUJEMkQ0MDdCNzNBRTYwRENGNDY2NDY4Mjk5MDc4NkEyRUU5MkQ3Mjc3N0YyREVFOEY1NzNBQzFBMjI2MjA3RTNEQjYzMzc5MjI2ODUwQ0Y5MjU3QjIzNDEzQTQ5OEYxMEQ2MjI1OTc0QjUyQUU1QzcyQjg1Qjg0Qjg1QUJFNkExRjlEMTYzMUEyRTNCMUQ4MDg4QzMxNzQyREQyRUU5NzA3QzRGMzY0RDlCNzIwRkVFM0Q5QTU5NjAyQUNBQzVCMjBGREQ2Q0ZCQUUzOUZCM0U2MTQyOQ==";
......
package com.mortals.xhx.busiz.web; package com.mortals.xhx.busiz.web;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.ILogService; import com.mortals.framework.service.ILogService;
import com.mortals.framework.service.impl.FileLogServiceImpl; import com.mortals.framework.service.impl.FileLogServiceImpl;
import com.mortals.xhx.base.system.message.impl.MessageProducer;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.busiz.req.TestReq; import com.mortals.xhx.busiz.req.TestReq;
import com.mortals.xhx.busiz.rsp.ApiResp; import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.DeviceResp; import com.mortals.xhx.busiz.rsp.DeviceResp;
import com.mortals.xhx.common.code.ApiRespCodeEnum; import com.mortals.xhx.common.code.ApiRespCodeEnum;
import com.mortals.xhx.common.utils.SendTaskThreadPool; import com.mortals.xhx.common.utils.ImgUtils;
import com.mortals.xhx.feign.site.ISiteFeign; import com.mortals.xhx.common.utils.Tess4J;
import com.mortals.xhx.module.device.service.DeviceLogService;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.firm.service.FirmService;
import com.mortals.xhx.module.platform.service.PlatformService;
import com.mortals.xhx.module.product.service.ProductService;
import com.mortals.xhx.module.product.service.ProductVersionService;
import com.mortals.xhx.module.site.service.SiteService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
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.io.File;
/** /**
* 设备 * 设备
* *
...@@ -38,47 +32,6 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -38,47 +32,6 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j @Slf4j
@RequestMapping("/test") @RequestMapping("/test")
public class TestSendMsgController { public class TestSendMsgController {
@Autowired
private DeviceService deviceService;
@Autowired
private ProductService productService;
@Autowired
private UserService userService;
@Autowired
private ProductVersionService productVersionService;
@Autowired
private PlatformService platformService;
@Value("${spring..rabbitmq.virtual_host:}")
private String virtualHost;
@Value("${spring..rabbitmq.password:}")
private String password;
@Value("${spring..rabbitmq.host:}")
private String host;
@Value("${spring..rabbitmq.port:0}")
private int port;
@Value("${spring..rabbitmq.username:}")
private String username;
@Value("${spring..rabbitmq.queue-properties.x-message-ttl:86400000}")
private String messageTtl;
@Value("${token.secret}")
private String secret;
@Autowired
private SendTaskThreadPool sendTaskThreadPool;
@Autowired
private ISiteFeign siteFeign;
@Value("${platform.type:cloud}")
private String platFormType;//版本,默认云服务版本
@Autowired
private SiteService siteService;
@Autowired
private FirmService firmService;
@Autowired
private DeviceLogService deviceLogService;
@Autowired
private ICacheService cacheService;
@Autowired
private MessageProducer messageProducer;
@Autowired @Autowired
protected ILogService logService = FileLogServiceImpl.getInstance(); protected ILogService logService = FileLogServiceImpl.getInstance();
...@@ -100,5 +53,35 @@ public class TestSendMsgController { ...@@ -100,5 +53,35 @@ public class TestSendMsgController {
} }
public static void main(String[] args) {
String resp = HttpUtil.get("http://59.225.206.13:8331/oauth-pro/admin-pro/sys/randomImage/1675827431800?_t=1675827431");
JSONObject jsonObject = JSON.parseObject(resp);
// log.info("resp:{}",resp);
log.info("result:{}", jsonObject.get("result"));
String OriginalImg = "F:\\pics\\2.jpg";
String ocrResult = "F:\\pics\\2-1.jpg";
Base64.decodeToFile(StrUtil.replace(jsonObject.get("result").toString(),"data:image/jpg;base64,",""), new File(OriginalImg));
ImgUtils.removeBackground(OriginalImg, ocrResult);
String code = Tess4J.executeTess4J(ocrResult);
log.info(code);
/*
//原始验证码地址
//识别样本输出地址
String ocrResult = "F:\\pics\\2.jpg";
//测试登录
//获取并识别验证码
ImgUtils.removeBackground(OriginalImg, ocrResult);
*/
}
} }
...@@ -88,6 +88,8 @@ public final class Constant { ...@@ -88,6 +88,8 @@ public final class Constant {
*/ */
public final static String PARAM_SERVER_PHP_HTTP_URL = "server_php_http_url"; public final static String PARAM_SERVER_PHP_HTTP_URL = "server_php_http_url";
public final static String PARAM_SERVER_PHP_IN_HTTP_URL = "server_php_in_http_url";
/** /**
* 短信平台url * 短信平台url
*/ */
......
package com.mortals.xhx.common.utils;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class ImgUtils {
public static void removeBackground(String imgUrl, String resUrl){
//定义一个临界阈值
int threshold = 300;
try{
BufferedImage img = ImageIO.read(new File(imgUrl));
int width = img.getWidth();
int height = img.getHeight();
for(int i = 1;i < width;i++){
for (int x = 0; x < width; x++){
for (int y = 0; y < height; y++){
Color color = new Color(img.getRGB(x, y));
System.out.println("red:"+color.getRed()+" | green:"+color.getGreen()+" | blue:"+color.getBlue());
int num = color.getRed()+color.getGreen()+color.getBlue();
if(num >= threshold){
img.setRGB(x, y, Color.WHITE.getRGB());
}
}
}
}
for(int i = 1;i<width;i++){
Color color1 = new Color(img.getRGB(i, 1));
int num1 = color1.getRed()+color1.getGreen()+color1.getBlue();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
Color color = new Color(img.getRGB(x, y));
int num = color.getRed()+color.getGreen()+color.getBlue();
if(num==num1){
img.setRGB(x, y, Color.BLACK.getRGB());
}else{
img.setRGB(x, y, Color.WHITE.getRGB());
}
}
}
}
File file = new File(resUrl);
if (!file.exists())
{
File dir = file.getParentFile();
if (!dir.exists())
{
dir.mkdirs();
}
try
{
file.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
}
}
ImageIO.write(img, "jpg", file);
}catch (Exception e){
e.printStackTrace();
}
}
public static void removeBackground(BufferedImage img, String resUrl){
//定义一个临界阈值
int threshold = 300;
try{
// BufferedImage img = ImageIO.read(new File(imgUrl));
int width = img.getWidth();
int height = img.getHeight();
for(int i = 1;i < width;i++){
for (int x = 0; x < width; x++){
for (int y = 0; y < height; y++){
Color color = new Color(img.getRGB(x, y));
System.out.println("red:"+color.getRed()+" | green:"+color.getGreen()+" | blue:"+color.getBlue());
int num = color.getRed()+color.getGreen()+color.getBlue();
if(num >= threshold){
img.setRGB(x, y, Color.WHITE.getRGB());
}
}
}
}
for(int i = 1;i<width;i++){
Color color1 = new Color(img.getRGB(i, 1));
int num1 = color1.getRed()+color1.getGreen()+color1.getBlue();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
Color color = new Color(img.getRGB(x, y));
int num = color.getRed()+color.getGreen()+color.getBlue();
if(num==num1){
img.setRGB(x, y, Color.BLACK.getRGB());
}else{
img.setRGB(x, y, Color.WHITE.getRGB());
}
}
}
}
File file = new File(resUrl);
if (!file.exists())
{
File dir = file.getParentFile();
if (!dir.exists())
{
dir.mkdirs();
}
try
{
file.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
}
}
ImageIO.write(img, "jpg", file);
}catch (Exception e){
e.printStackTrace();
}
}
public static void cuttingImg(String imgUrl){
try{
File newfile=new File(imgUrl);
BufferedImage bufferedimage=ImageIO.read(newfile);
int width = bufferedimage.getWidth();
int height = bufferedimage.getHeight();
if (width > 52) {
bufferedimage=ImgUtils.cropImage(bufferedimage,(int) ((width - 52) / 2),0,(int) (width - (width-52) / 2),(int) (height));
if (height > 16) {
bufferedimage=ImgUtils.cropImage(bufferedimage,0,(int) ((height - 16) / 2),52,(int) (height - (height - 16) / 2));
}
}else{
if (height > 16) {
bufferedimage=ImgUtils.cropImage(bufferedimage,0,(int) ((height - 16) / 2),(int) (width),(int) (height - (height - 16) / 2));
}
}
ImageIO.write(bufferedimage, "jpg", new File(imgUrl));
}catch (IOException e){
e.printStackTrace();
}
}
public static BufferedImage cropImage(BufferedImage bufferedImage, int startX, int startY, int endX, int endY) {
int width = bufferedImage.getWidth();
int height = bufferedImage.getHeight();
if (startX == -1) {
startX = 0;
}
if (startY == -1) {
startY = 0;
}
if (endX == -1) {
endX = width - 1;
}
if (endY == -1) {
endY = height - 1;
}
BufferedImage result = new BufferedImage(endX - startX, endY - startY, 4);
for (int x = startX; x < endX; ++x) {
for (int y = startY; y < endY; ++y) {
int rgb = bufferedImage.getRGB(x, y);
result.setRGB(x - startX, y - startY, rgb);
}
}
return result;
}
}
\ No newline at end of file
...@@ -3,9 +3,7 @@ package com.mortals.xhx.daemon.applicationservice; ...@@ -3,9 +3,7 @@ package com.mortals.xhx.daemon.applicationservice;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.mortals.framework.ap.GlobalSysInfo; import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.model.BizLogPdu;
import com.mortals.framework.service.ICacheService; import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IMessageProduceService;
import com.mortals.framework.springcloud.service.IApplicationStartedService; import com.mortals.framework.springcloud.service.IApplicationStartedService;
import com.mortals.xhx.common.code.*; import com.mortals.xhx.common.code.*;
import com.mortals.xhx.common.key.Constant; import com.mortals.xhx.common.key.Constant;
...@@ -27,8 +25,6 @@ import com.mortals.xhx.queue.TopicPartitionInfo; ...@@ -27,8 +25,6 @@ import com.mortals.xhx.queue.TopicPartitionInfo;
import com.mortals.xhx.utils.IotThreadFactory; import com.mortals.xhx.utils.IotThreadFactory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.*; import java.util.*;
...@@ -37,7 +33,9 @@ import java.util.concurrent.Executors; ...@@ -37,7 +33,9 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.mortals.xhx.common.model.MessageHeader.*; import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_PHP_IN_HTTP_URL;
import static com.mortals.xhx.common.model.MessageHeader.DEVICECODE;
import static com.mortals.xhx.common.model.MessageHeader.MESSAGETYPE;
//@Component //@Component
...@@ -198,13 +196,14 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi ...@@ -198,13 +196,14 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi
} }
//获取exchange, //获取exchange,
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId()); PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
String phpInUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_IN_HTTP_URL, "http://172.15.28.116:8090");
if (!Constant.MESSAGETYPE_HEARTBEAT.equalsIgnoreCase(messageType) if (!Constant.MESSAGETYPE_HEARTBEAT.equalsIgnoreCase(messageType)
&& !ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(platformEntity)
&& platformEntity.getSendSwitch() == YesNoEnum.YES.getValue()) { && platformEntity.getSendSwitch() == YesNoEnum.YES.getValue()) {
if (platformEntity.getSendMsgType() == SendMsgTypeEnum.http.getValue() && !ObjectUtils.isEmpty(platformEntity.getSendUrl())) { if (platformEntity.getSendMsgType() == SendMsgTypeEnum.http.getValue()) {
//http方式 //http方式
//通过线程池进行发送消息 //通过线程池进行发送消息
SendTask sendTask = new SendTask(platformEntity.getSendUrl(), queueMsg.getData()); SendTask sendTask = new SendTask(phpInUrl, queueMsg.getData());
sendTaskThreadPool.execute(sendTask); sendTaskThreadPool.execute(sendTask);
} }
} }
......
...@@ -12,7 +12,6 @@ import com.mortals.xhx.module.site.model.SiteQuery; ...@@ -12,7 +12,6 @@ import com.mortals.xhx.module.site.model.SiteQuery;
import com.mortals.xhx.module.site.service.SiteService; import com.mortals.xhx.module.site.service.SiteService;
import com.mortals.xhx.module.sitestat.model.SitestatEntity; import com.mortals.xhx.module.sitestat.model.SitestatEntity;
import com.mortals.xhx.module.sitestat.service.SitestatService; import com.mortals.xhx.module.sitestat.service.SitestatService;
import lombok.extern.apachecommons.CommonsLog;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
......
package com.mortals.xhx.module.device.service.impl; package com.mortals.xhx.module.device.service.impl;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.PatternPool;
import cn.hutool.core.net.url.UrlBuilder; import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.net.url.UrlPath; import cn.hutool.core.net.url.UrlPath;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
...@@ -57,6 +57,7 @@ import java.util.*; ...@@ -57,6 +57,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.mortals.xhx.common.key.Constant.MESSAGETYPE_NOTIFY_RESTART_APP; import static com.mortals.xhx.common.key.Constant.MESSAGETYPE_NOTIFY_RESTART_APP;
import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_PHP_IN_HTTP_URL;
import static java.math.BigDecimal.ROUND_HALF_DOWN; import static java.math.BigDecimal.ROUND_HALF_DOWN;
import static java.util.stream.Collectors.counting; import static java.util.stream.Collectors.counting;
...@@ -226,33 +227,33 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D ...@@ -226,33 +227,33 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
@Override @Override
public void restartApp(DeviceEntity deviceEntity, Context context) { public void restartApp(DeviceEntity deviceEntity, Context context) {
if(ObjectUtils.isEmpty(deviceEntity.getIdList())){ if (ObjectUtils.isEmpty(deviceEntity.getIdList())) {
throw new AppException("请选择需要重启应用的设备!"); throw new AppException("请选择需要重启应用的设备!");
} }
List<DeviceEntity> deviceEntities = this.find(deviceEntity, context); List<DeviceEntity> deviceEntities = this.find(deviceEntity, context);
for (DeviceEntity device : deviceEntities) { for (DeviceEntity device : deviceEntities) {
if (!ObjectUtils.isEmpty(device)) { if (!ObjectUtils.isEmpty(device)) {
TbQueueMsgHeaders header = new DefaultTbQueueMsgHeaders(); TbQueueMsgHeaders header = new DefaultTbQueueMsgHeaders();
header.put(MessageHeader.MESSAGETYPE, MESSAGETYPE_NOTIFY_RESTART_APP); header.put(MessageHeader.MESSAGETYPE, MESSAGETYPE_NOTIFY_RESTART_APP);
header.put(MessageHeader.DEVICECODE, deviceEntity.getDeviceCode()); header.put(MessageHeader.DEVICECODE, device.getDeviceCode());
header.put(MessageHeader.TIMESTAMP, DateUtils.getCurrStrDateTime()); header.put(MessageHeader.TIMESTAMP, DateUtils.getCurrStrDateTime());
TbQueueMsg queueMsg = new DefaultTbQueueMsg(IdUtil.fastUUID(), "W10=", header); TbQueueMsg queueMsg = new DefaultTbQueueMsg(IdUtil.fastUUID(), "W10=", header);
messageProducer.sendMsg(QueueKey.DEFAULT_EXCHANGE, Constant.DOWN_TOPIC + deviceEntity.getDeviceCode(),JSON.toJSONString(queueMsg)); messageProducer.sendMsg(QueueKey.DEFAULT_EXCHANGE, Constant.DOWN_TOPIC + device.getDeviceCode(), JSON.toJSONString(queueMsg));
DeviceLogEntity deviceLogEntity = new DeviceLogEntity(); DeviceLogEntity deviceLogEntity = new DeviceLogEntity();
deviceLogEntity.initAttrValue(); deviceLogEntity.initAttrValue();
deviceLogEntity.setTraceID(IdUtil.fastSimpleUUID()); deviceLogEntity.setTraceID(IdUtil.fastSimpleUUID());
deviceLogEntity.setSiteId(deviceEntity.getSiteId()); deviceLogEntity.setSiteId(device.getSiteId());
deviceLogEntity.setDeviceId(deviceEntity.getId()); deviceLogEntity.setDeviceId(device.getId());
deviceLogEntity.setDeviceName(deviceEntity.getDeviceName()); deviceLogEntity.setDeviceName(device.getDeviceName());
deviceLogEntity.setDeviceCode(deviceEntity.getDeviceCode()); deviceLogEntity.setDeviceCode(device.getDeviceCode());
deviceLogEntity.setMessageHead(MESSAGETYPE_NOTIFY_RESTART_APP); deviceLogEntity.setMessageHead(MESSAGETYPE_NOTIFY_RESTART_APP);
deviceLogEntity.setContent("W10="); deviceLogEntity.setContent("W10=");
deviceLogEntity.setLogType(LogTypeEnum.下发服务.getValue()); deviceLogEntity.setLogType(LogTypeEnum.下发服务.getValue());
deviceLogEntity.setCreateUserId(1L); deviceLogEntity.setCreateUserId(1L);
deviceLogEntity.setCreateTime(new Date()); deviceLogEntity.setCreateTime(new Date());
deviceLogService.save(deviceLogEntity,null); deviceLogService.save(deviceLogEntity, null);
} else { } else {
log.info("未找到设备,deviceCode:{}", device.getDeviceCode()); log.info("未找到设备,deviceCode:{}", device.getDeviceCode());
} }
...@@ -336,19 +337,11 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D ...@@ -336,19 +337,11 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
BeanUtils.copyProperties(entity, deviceReq, BeanUtil.getNullPropertyNames(entity)); BeanUtils.copyProperties(entity, deviceReq, BeanUtil.getNullPropertyNames(entity));
deviceReq.setDeviceStatus(update.getValue()); deviceReq.setDeviceStatus(update.getValue());
deviceReq.setProductCode(productEntity.getProductCode()); deviceReq.setProductCode(productEntity.getProductCode());
if (!ObjectUtils.isEmpty(platformEntity.getSendUrl()) //http://192.168.0.98:8090/inter/device/deviceIn
//&& platformEntity.getSendSwitch() == SendSwitchEnum.启用.getValue() String phpInUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_IN_HTTP_URL, "http://172.15.28.116:8090");
&& entity.getSwitchSend()) { ApiResp<String> resp = messageService.sendThirdParty(UrlBuilder.of(phpInUrl).addPath(thirdPartyPath).build(), deviceReq);
//http://192.168.0.98:8090/inter/device/deviceIn log.info("sendThirtyis resp ==>{}", JSON.toJSONString(resp));
if (PatternPool.URL_HTTP.matcher(platformEntity.getSendUrl()).find()) {
ApiResp<String> resp = messageService.sendThirdParty(UrlBuilder.of(platformEntity.getSendUrl()).addPath(thirdPartyPath).build(), deviceReq);
log.info("sendThirtyis resp ==>{}", JSON.toJSONString(resp));
} else {
throw new AppException("http send url 不合法!" + platformEntity.getSendUrl());
}
} else {
log.info("sendThirtyis null ==>{}", JSON.toJSONString(platformEntity));
}
} }
@Override @Override
...@@ -707,7 +700,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D ...@@ -707,7 +700,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
protected void updateBefore(DeviceEntity entity, Context context) throws AppException { protected void updateBefore(DeviceEntity entity, Context context) throws AppException {
super.updateBefore(entity, context); super.updateBefore(entity, context);
ProductEntity productEntity = productService.get(entity.getProductId(), context); ProductEntity productEntity = productService.get(entity.getProductId(), context);
entity.setProductCode(productEntity==null?"":productEntity.getProductCode()); entity.setProductCode(productEntity == null ? "" : productEntity.getProductCode());
updateDeviceHomeUrl(entity); updateDeviceHomeUrl(entity);
} }
......
...@@ -23,7 +23,6 @@ public class PlatformServiceImpl extends AbstractCRUDCacheServiceImpl<PlatformDa ...@@ -23,7 +23,6 @@ public class PlatformServiceImpl extends AbstractCRUDCacheServiceImpl<PlatformDa
protected void validData(PlatformEntity entity, Context context) throws AppException { protected void validData(PlatformEntity entity, Context context) throws AppException {
if(!ObjectUtils.isEmpty(entity.getSendUrl())){ if(!ObjectUtils.isEmpty(entity.getSendUrl())){
if (!PatternPool.URL_HTTP.matcher(entity.getSendUrl()).find()) { if (!PatternPool.URL_HTTP.matcher(entity.getSendUrl()).find()) {
throw new AppException("URL不合法"); throw new AppException("URL不合法");
} }
......
package com.mortals.xhx.module.product.service.impl; package com.mortals.xhx.module.product.service.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ZipUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DateUtils; import com.mortals.framework.util.DateUtils;
import com.mortals.xhx.base.system.message.impl.MessageProducer; import com.mortals.xhx.base.system.message.impl.MessageProducer;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.common.code.LogTypeEnum; import com.mortals.xhx.common.code.LogTypeEnum;
import com.mortals.xhx.common.key.Constant; import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.key.QueueKey; import com.mortals.xhx.common.key.QueueKey;
...@@ -25,10 +29,16 @@ import com.mortals.xhx.module.product.service.ProductVersionService; ...@@ -25,10 +29,16 @@ import com.mortals.xhx.module.product.service.ProductVersionService;
import com.mortals.xhx.queue.DefaultTbQueueMsg; import com.mortals.xhx.queue.DefaultTbQueueMsg;
import com.mortals.xhx.queue.TbQueueMsg; import com.mortals.xhx.queue.TbQueueMsg;
import com.mortals.xhx.queue.TbQueueMsgHeaders; import com.mortals.xhx.queue.TbQueueMsgHeaders;
import com.mortals.xhx.utils.EncodeUtil;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.io.File;
import java.nio.charset.Charset;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -42,6 +52,7 @@ import static com.mortals.xhx.common.key.Constant.MESSAGETYPE_UPGREAD; ...@@ -42,6 +52,7 @@ import static com.mortals.xhx.common.key.Constant.MESSAGETYPE_UPGREAD;
* @date 2022-08-22 * @date 2022-08-22
*/ */
@Service("productVersionService") @Service("productVersionService")
@Slf4j
public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVersionDao, ProductVersionEntity, Long> implements ProductVersionService { public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVersionDao, ProductVersionEntity, Long> implements ProductVersionService {
@Autowired @Autowired
...@@ -52,6 +63,12 @@ public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVe ...@@ -52,6 +63,12 @@ public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVe
private MessageProducer messageProducer; private MessageProducer messageProducer;
@Autowired @Autowired
private DeviceLogService deviceLogService; private DeviceLogService deviceLogService;
@Autowired
private UploadService uploadService;
@Value("${upload.path}")
@Getter
private String filePathGlob;
@Override @Override
...@@ -93,7 +110,7 @@ public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVe ...@@ -93,7 +110,7 @@ public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVe
TbQueueMsgHeaders header = new DefaultTbQueueMsgHeaders(); TbQueueMsgHeaders header = new DefaultTbQueueMsgHeaders();
header.put(MessageHeader.MESSAGETYPE, MESSAGETYPE_UPGREAD); header.put(MessageHeader.MESSAGETYPE, MESSAGETYPE_UPGREAD);
header.put(MessageHeader.DEVICECODE, deviceEntity.getDeviceCode()); header.put(MessageHeader.DEVICECODE, deviceEntity.getDeviceCode());
header.put(MessageHeader.TIMESTAMP, DateUtils.getCurrStrDateTime()); header.put(MessageHeader.TIMESTAMP, DateUtils.getCurrStrDateTime());
TbQueueMsg queueMsg = new DefaultTbQueueMsg(IdUtil.fastUUID(), "W10=", header); TbQueueMsg queueMsg = new DefaultTbQueueMsg(IdUtil.fastUUID(), "W10=", header);
messageProducer.sendMsg(QueueKey.DEFAULT_EXCHANGE, Constant.DOWN_TOPIC + deviceEntity.getDeviceCode(), JSON.toJSONString(queueMsg)); messageProducer.sendMsg(QueueKey.DEFAULT_EXCHANGE, Constant.DOWN_TOPIC + deviceEntity.getDeviceCode(), JSON.toJSONString(queueMsg));
...@@ -109,7 +126,7 @@ public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVe ...@@ -109,7 +126,7 @@ public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVe
deviceLogEntity.setLogType(LogTypeEnum.下发服务.getValue()); deviceLogEntity.setLogType(LogTypeEnum.下发服务.getValue());
deviceLogEntity.setCreateUserId(1L); deviceLogEntity.setCreateUserId(1L);
deviceLogEntity.setCreateTime(new Date()); deviceLogEntity.setCreateTime(new Date());
deviceLogService.save(deviceLogEntity,null); deviceLogService.save(deviceLogEntity, null);
} }
} }
} }
...@@ -117,6 +134,26 @@ public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVe ...@@ -117,6 +134,26 @@ public class ProductVersionServiceImpl extends AbstractCRUDServiceImpl<ProductVe
@Override @Override
public void appPublish(ProductVersionEntity productVersionEntity, Context context) { public void appPublish(ProductVersionEntity productVersionEntity, Context context) {
String filePath = productVersionEntity.getFilePath();
String targetFilePath = uploadService.getFilePath(productVersionEntity.getFilePath());
String mainName = FileUtil.mainName(targetFilePath);
String type = FileUtil.extName(filePath);
if ("zip".equals(type)) {
String disPath = filePath + "/file/fileupload/" + mainName;
String replace = StrUtil.replace(productVersionEntity.getFilePath(), FileUtil.getName(productVersionEntity.getFilePath()), "");
disPath = filePathGlob+"/"+replace+mainName+"/";
if(!FileUtil.isDirectory(new File(disPath))){
FileUtil.mkdir(disPath);
}
String fileEncode = "UTF-8";
try {
fileEncode = EncodeUtil.getEncode(targetFilePath, true);
} catch (Exception e) {
log.error("异常", e);
}
log.info("unzip disPath:{}",disPath);
ZipUtil.unzip(targetFilePath, disPath, Charset.forName(fileEncode));
}
pushUpgradMsg(productVersionEntity, context); pushUpgradMsg(productVersionEntity, context);
} }
} }
\ No newline at end of file
...@@ -46,7 +46,9 @@ public class ProductController extends BaseCRUDJsonBodyMappingController<Product ...@@ -46,7 +46,9 @@ public class ProductController extends BaseCRUDJsonBodyMappingController<Product
@Override @Override
protected void init(Map<String, Object> model, Context context) { protected void init(Map<String, Object> model, Context context) {
//获取所有产品皮肤 分组显示 //获取所有产品皮肤 分组显示
Rest<RespData<List<SkinBasePdu>>> resp = skinBaseFeign.list(new SkinBasePdu()); SkinBasePdu skinBasePdu = new SkinBasePdu();
skinBasePdu.setSize(-1);
Rest<RespData<List<SkinBasePdu>>> resp = skinBaseFeign.list(skinBasePdu);
if (resp.getCode() == YesNoEnum.YES.getValue()) { if (resp.getCode() == YesNoEnum.YES.getValue()) {
Map<String, Map<String, String>> skinProductCodeMap = resp.getData().getData().stream().collect(Collectors.groupingBy(x -> x.getProductCode(), Collectors.toMap(a -> a.getImageResolution() == null ? "" : a.getImageResolution()+"", b -> b.getImageResolutionValue() == null ? "" : b.getImageResolutionValue(), (o, n) -> n))); Map<String, Map<String, String>> skinProductCodeMap = resp.getData().getData().stream().collect(Collectors.groupingBy(x -> x.getProductCode(), Collectors.toMap(a -> a.getImageResolution() == null ? "" : a.getImageResolution()+"", b -> b.getImageResolutionValue() == null ? "" : b.getImageResolutionValue(), (o, n) -> n)));
this.addDict(model, "skinProductCodeMap", skinProductCodeMap); this.addDict(model, "skinProductCodeMap", skinProductCodeMap);
......
...@@ -14,5 +14,9 @@ ...@@ -14,5 +14,9 @@
"portal": { "portal": {
"baseUrl": "http://192.168.0.98:11072/zwfw", "baseUrl": "http://192.168.0.98:11072/zwfw",
"baseLogin": "http://192.168.0.98:11078/base" "baseLogin": "http://192.168.0.98:11078/base"
},
"yibin": {
"baseUrl": "http://10.12.185.213:11078/m"
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment