Commit 08576119 authored by 赵啸非's avatar 赵啸非

添加产品升级功能

parent 46e8a47f
......@@ -22,7 +22,6 @@ public class MessageProducer implements IMessageProduceService {
private RabbitTemplate rabbitTemplate;
public void syncAccessSend(AccessLogPdu accessLogPdu) {
//log.info("accessinfo==>{}",JSON.toJSONString(accessLogPdu));
rabbitTemplate.convertAndSend(QueueKey.EXCHANGE, QueueKey.ACCESS_LOG_QUEUE, JSON.toJSONString(accessLogPdu));
}
......
......@@ -58,8 +58,7 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi
private SendTaskThreadPool sendTaskThreadPool;
@Autowired
private ICacheService cacheService;
@Value("${spring.application.name:''}")
private String appName;
@Autowired
private IMessageProduceService messageProduceService;
......@@ -196,21 +195,6 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi
deviceLogEntity.setCreateUserId(1L);
deviceLogEntity.setCreateTime(new Date());
deviceLogService.save(deviceLogEntity);
//埋点业务事件,消息上报
BizLogPdu bizLogPdu = new BizLogPdu();
bizLogPdu.initAttrValue();
bizLogPdu.setAppName(appName);
bizLogPdu.setTraceID(IdUtil.objectId());
bizLogPdu.setUserCode("system");
bizLogPdu.setDeviceCode(deviceEntity.getDeviceCode());
bizLogPdu.setEventTopic(messageType);
bizLogPdu.setEventTopicName(LogTypeEnum.下发服务.name());
bizLogPdu.setMsg(queueMsg.getData());
bizLogPdu.setLogLevel("INFO");
bizLogPdu.setLogTime(new Date());
messageProduceService.syncBizSend(bizLogPdu);
}
//获取exchange,
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
......
package com.mortals.xhx.module.device.service.impl;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.IdUtil;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.BizLogPdu;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.xhx.base.system.message.MessageProducer;
import com.mortals.xhx.common.code.LogTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.device.dao.DeviceLogDao;
import com.mortals.xhx.module.device.model.DeviceLogEntity;
import com.mortals.xhx.module.device.service.DeviceLogService;
import java.util.Date;
import java.util.List;
/**
......@@ -22,6 +29,11 @@ import java.util.List;
@Service("deviceLogService")
public class DeviceLogServiceImpl extends AbstractCRUDServiceImpl<DeviceLogDao, DeviceLogEntity, Long> implements DeviceLogService {
@Value("${spring.application.name:''}")
private String appName;
@Autowired
private MessageProducer messageProducer;
@Override
protected void findAfter(DeviceLogEntity params, PageInfo pageInfo, Context context, List<DeviceLogEntity> list) throws AppException {
......@@ -34,4 +46,21 @@ public class DeviceLogServiceImpl extends AbstractCRUDServiceImpl<DeviceLogDao,
});
}
@Override
protected void saveAfter(DeviceLogEntity entity, Context context) throws AppException {
BizLogPdu bizLogPdu = new BizLogPdu();
bizLogPdu.initAttrValue();
bizLogPdu.setAppName(appName);
bizLogPdu.setTraceID(IdUtil.objectId());
bizLogPdu.setUserCode("system");
bizLogPdu.setDeviceCode(entity.getDeviceCode());
bizLogPdu.setEventTopic(entity.getMessageHead());
bizLogPdu.setEventTopicName(LogTypeEnum.下发服务.name());
bizLogPdu.setMsg(entity.getContent());
bizLogPdu.setLogLevel("INFO");
bizLogPdu.setLogTime(new Date());
messageProducer.syncBizSend(bizLogPdu);
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.mortals.xhx.module.product.service.impl;
import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.net.url.UrlPath;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.URLUtil;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.ap.GlobalSysInfo;
......@@ -10,12 +11,15 @@ import com.mortals.framework.model.Context;
import com.mortals.framework.model.OrderCol;
import com.mortals.xhx.base.system.message.MessageService;
import com.mortals.xhx.busiz.rsp.ProductVersionInfo;
import com.mortals.xhx.common.code.LogTypeEnum;
import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders;
import com.mortals.xhx.common.model.MessageHeader;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceLogEntity;
import com.mortals.xhx.module.device.model.DeviceQuery;
import com.mortals.xhx.module.device.service.DeviceLogService;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.platform.model.PlatformEntity;
import com.mortals.xhx.module.platform.service.PlatformService;
......@@ -23,7 +27,9 @@ 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.ProductVersionService;
import com.mortals.xhx.queue.TbQueueCallback;
import com.mortals.xhx.queue.TbQueueMsgHeaders;
import com.mortals.xhx.queue.TbQueueMsgMetadata;
import com.mortals.xhx.queue.TopicPartitionInfo;
import com.sun.jndi.toolkit.url.UrlUtil;
import org.springframework.beans.BeanUtils;
......@@ -37,6 +43,7 @@ import org.springframework.util.ObjectUtils;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_HTTP_URL;
......@@ -61,6 +68,8 @@ public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, Prod
private MessageService messageService;
@Autowired
private PlatformService platformService;
@Autowired
private DeviceLogService deviceLogService;
@Override
protected void saveBefore(ProductEntity entity, Context context) throws AppException {
......@@ -124,11 +133,49 @@ public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, Prod
header.put(MessageHeader.DEVICECODE, deviceEntity.getDeviceCode());
ProductVersionInfo productVersionInfo = new ProductVersionInfo();
BeanUtils.copyProperties(productVersionEntity, productVersionInfo, BeanUtil.getNullPropertyNames(productVersionEntity));
buildDownloadUrl(productVersionEntity,productVersionInfo);
deviceService.sendDeviceMessage(deviceEntity, info, header, JSON.toJSONString(productVersionInfo), null, null);
buildDownloadUrl(productVersionEntity, productVersionInfo);
TbQueueCallback callback = new TbQueueCallback() {
@Override
public void onSuccess(TbQueueMsgMetadata metadata) {
DeviceLogEntity deviceLogEntity = new DeviceLogEntity();
deviceLogEntity.initAttrValue();
deviceLogEntity.setTraceID(metadata.getMessageId());
deviceLogEntity.setSiteId(deviceEntity.getSiteId());
deviceLogEntity.setDeviceId(deviceEntity.getId());
deviceLogEntity.setDeviceName(deviceEntity.getDeviceName());
deviceLogEntity.setDeviceCode(deviceEntity.getDeviceCode());
deviceLogEntity.setMessageHead(Constant.MESSAGETYPE_UPGREAD);
deviceLogEntity.setContent(JSON.toJSONString(productVersionInfo));
deviceLogEntity.setLogType(LogTypeEnum.下发服务.getValue());
deviceLogEntity.setCreateUserId(1L);
deviceLogEntity.setCreateTime(new Date());
deviceLogService.save(deviceLogEntity);
}
@Override
public void onFailure(Throwable t) {
DeviceLogEntity deviceLogEntity = new DeviceLogEntity();
deviceLogEntity.initAttrValue();
String traceID = IdUtil.fastSimpleUUID();
deviceLogEntity.setTraceID(traceID);
deviceLogEntity.setDeviceId(deviceEntity.getId());
deviceLogEntity.setSiteId(deviceEntity.getSiteId());
deviceLogEntity.setDeviceName(deviceEntity.getDeviceName());
deviceLogEntity.setDeviceCode(deviceEntity.getDeviceCode());
deviceLogEntity.setMessageHead(Constant.MESSAGETYPE_UPGREAD);
deviceLogEntity.setContent(JSON.toJSONString(productVersionInfo));
deviceLogEntity.setLogType(LogTypeEnum.消息异常.getValue());
deviceLogEntity.setCreateUserId(1L);
deviceLogEntity.setCreateTime(new Date());
deviceLogService.save(deviceLogEntity);
}
};
deviceService.sendDeviceMessage(deviceEntity, info, header, JSON.toJSONString(productVersionInfo), callback, null);
});
}
private void buildDownloadUrl(ProductVersionEntity productVersionEntity, ProductVersionInfo productVersionInfo) {
String download = "";
......
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