Commit 0945855e authored by 赵啸非's avatar 赵啸非

添加设备版本信息

parent 535cdc5c
......@@ -14,4 +14,6 @@ public class DeviceResp implements Serializable {
private String content;
}
package com.mortals.xhx.busiz.rsp;
import lombok.Data;
import java.io.Serializable;
/**
* 产品版本信息
*/
@Data
public class ProductVersionInfo implements Serializable {
private Integer productId;
/**
* 产品编号
*/
private String productCode;
/**
* 产品名称
*/
private String productName;
/**
* 版本号
*/
private String version;
/**
* 备注信息
*/
private String remark;
/**
* 版本下载地址
*/
private String downloadUrl;
}
......@@ -12,6 +12,7 @@ import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.OrderCol;
import com.mortals.framework.service.IAuthTokenService;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.ILogService;
......@@ -48,7 +49,10 @@ import com.mortals.xhx.module.platform.model.PlatformQuery;
import com.mortals.xhx.module.platform.service.PlatformService;
import com.mortals.xhx.module.product.model.ProductEntity;
import com.mortals.xhx.module.product.model.ProductQuery;
import com.mortals.xhx.module.product.model.ProductVersionEntity;
import com.mortals.xhx.module.product.model.ProductVersionQuery;
import com.mortals.xhx.module.product.service.ProductService;
import com.mortals.xhx.module.product.service.ProductVersionService;
import com.mortals.xhx.queue.TbQueueMsgHeaders;
import com.mortals.xhx.queue.TopicPartitionInfo;
import lombok.extern.slf4j.Slf4j;
......@@ -61,6 +65,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
......@@ -87,7 +92,7 @@ public class DeviceApiController {
@Autowired
private UserService userService;
@Autowired
private IAuthTokenService authTokenService;
private ProductVersionService productVersionService;
@Autowired
private PlatformService platformService;
@Value("${queue.rabbitmq.virtual_host:}")
......@@ -175,6 +180,7 @@ public class DeviceApiController {
deviceInfo.setSiteCode(deviceEntity.getSiteCode());
deviceInfo.setSiteName(deviceEntity.getSiteName());
deviceInfo.setProductId(productEntity.getId());
deviceInfo.setProductCode(productEntity.getProductCode());
deviceInfo.setProductName(productEntity.getProductName());
deviceInfo.setEnabled(deviceEntity.getEnabled());
deviceInfo.setSource(deviceEntity.getSource());
......@@ -203,19 +209,7 @@ public class DeviceApiController {
return JSON.toJSONString(rsp);
}
private void buildHomeUrl(DeviceEntity deviceEntity, ProductEntity productEntity, ServerInfo serverInfo) {
String homeUrl = "";
if (!ObjectUtils.isEmpty(productEntity.getHomeUrl())) {
homeUrl = productEntity.getHomeUrl();
}
if (!ObjectUtils.isEmpty(deviceEntity.getHomeUrl())) {
homeUrl = deviceEntity.getHomeUrl();
}
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11091");
serverInfo.setHomeUrl(UrlBuilder.of(domain).addPath(homeUrl).toString());
}
/**
* 获取Token
......@@ -269,7 +263,6 @@ public class DeviceApiController {
List<ProductInfo> productInfoList = productService.find(new ProductEntity()).stream().map(item -> {
ProductInfo productInfo = new ProductInfo();
BeanUtils.copyProperties(item, productInfo, BeanUtil.getNullPropertyNames(item));
productInfo.setProductId(item.getId());
return productInfo;
}).collect(Collectors.toList());
......@@ -420,6 +413,51 @@ public class DeviceApiController {
return JSON.toJSONString(rsp);
}
/**
* 检查设备最新版本信息
*
* @param req
* @return
*/
@PostMapping("checkVersion")
public String checkVersion(@RequestBody DeviceReq req) {
log.info("【检查设备最新版本信息】【请求体】--> " + JSONObject.toJSONString(req));
ApiResp<DeviceResp> rsp = new ApiResp<>();
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
DeviceResp deviceResp = new DeviceResp();
try {
DeviceEntity deviceEntity = checkDeviceExist(req);
//查找版本号最大的.
ProductVersionQuery productVersionQuery = new ProductVersionQuery();
productVersionQuery.setProductId(deviceEntity.getProductId());
productVersionQuery.setOrderColList(Arrays.asList(new OrderCol("version")));
productVersionQuery.setOrderKind(OrderCol.ASCENDING);
ProductVersionEntity productVersionEntity = productVersionService.selectOne(productVersionQuery);
if (ObjectUtils.isEmpty(productVersionEntity))
throw new AppException(DEVICE_VERSION_UNEXIST, DEVICE_VERSION_UNEXIST_CONTENT);
ProductVersionInfo productVersionInfo = new ProductVersionInfo();
BeanUtils.copyProperties(productVersionEntity, productVersionInfo, BeanUtil.getNullPropertyNames(productVersionEntity));
buildDownloadUrl(productVersionEntity,productVersionInfo);
String content = EncryptUtil.myEnscrt(JSON.toJSONString(productVersionInfo), 9, DES_STR, ENCRYPT_STR);
deviceResp.setContent(content);
} catch (AppException e) {
log.error("接收数据失败", e);
rsp.setCode(e.getCode());
rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp);
} catch (Exception e) {
log.error("接收数据失败", e);
rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp);
}
log.info("响应【设备版本检查】【响应体】--> " + JSONObject.toJSONString(rsp));
return JSON.toJSONString(rsp);
}
private void saveOrUpdate(DeviceReq req, PlatformEntity platformEntity, ProductEntity productEntity, DeviceEntity deviceEntity) {
BeanUtils.copyProperties(req, deviceEntity, BeanUtil.getNullPropertyNames(req));
......@@ -762,5 +800,29 @@ public class DeviceApiController {
}
}
private void buildHomeUrl(DeviceEntity deviceEntity, ProductEntity productEntity, ServerInfo serverInfo) {
String homeUrl = "";
if (!ObjectUtils.isEmpty(productEntity.getHomeUrl())) {
homeUrl = productEntity.getHomeUrl();
}
if (!ObjectUtils.isEmpty(deviceEntity.getHomeUrl())) {
homeUrl = deviceEntity.getHomeUrl();
}
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11091");
serverInfo.setHomeUrl(UrlBuilder.of(domain).addPath(homeUrl).toString());
}
private void buildDownloadUrl(ProductVersionEntity productVersionEntity, ProductVersionInfo productVersionInfo) {
String download = "";
if (!ObjectUtils.isEmpty(productVersionEntity.getFilePath())) {
download = productVersionEntity.getFilePath();
}
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11091");
productVersionInfo.setDownloadUrl(UrlBuilder.of(domain).addPath(download).toString());
}
}
......@@ -111,6 +111,9 @@ public interface ErrorCode {
public static final int TOKEN_AUTH_FAIL = 1010;
public static final String TOKEN_AUTH_FAIL_CONTENT = "token认证失败!";
public static final int DEVICE_VERSION_UNEXIST = 1011;
public static final String DEVICE_VERSION_UNEXIST_CONTENT = "未找到设备版本信息!";
public static final int ERROR_TOKEN_EXPIRED = 9001;
public static final String ERROR_TOKEN_EXPIRED_CONTENT = "用户登录过期,请重新登录!";
......
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