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

添加产品升级功能

parent 46e8a47f
...@@ -22,7 +22,6 @@ public class MessageProducer implements IMessageProduceService { ...@@ -22,7 +22,6 @@ public class MessageProducer implements IMessageProduceService {
private RabbitTemplate rabbitTemplate; private RabbitTemplate rabbitTemplate;
public void syncAccessSend(AccessLogPdu accessLogPdu) { public void syncAccessSend(AccessLogPdu accessLogPdu) {
//log.info("accessinfo==>{}",JSON.toJSONString(accessLogPdu));
rabbitTemplate.convertAndSend(QueueKey.EXCHANGE, QueueKey.ACCESS_LOG_QUEUE, JSON.toJSONString(accessLogPdu)); rabbitTemplate.convertAndSend(QueueKey.EXCHANGE, QueueKey.ACCESS_LOG_QUEUE, JSON.toJSONString(accessLogPdu));
} }
......
...@@ -58,8 +58,7 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi ...@@ -58,8 +58,7 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi
private SendTaskThreadPool sendTaskThreadPool; private SendTaskThreadPool sendTaskThreadPool;
@Autowired @Autowired
private ICacheService cacheService; private ICacheService cacheService;
@Value("${spring.application.name:''}")
private String appName;
@Autowired @Autowired
private IMessageProduceService messageProduceService; private IMessageProduceService messageProduceService;
...@@ -196,21 +195,6 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi ...@@ -196,21 +195,6 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi
deviceLogEntity.setCreateUserId(1L); deviceLogEntity.setCreateUserId(1L);
deviceLogEntity.setCreateTime(new Date()); deviceLogEntity.setCreateTime(new Date());
deviceLogService.save(deviceLogEntity); 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, //获取exchange,
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId()); PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
......
package com.mortals.xhx.module.device.service.impl; package com.mortals.xhx.module.device.service.impl;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.IdUtil;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.BizLogPdu;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo; 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 org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.device.dao.DeviceLogDao; import com.mortals.xhx.module.device.dao.DeviceLogDao;
import com.mortals.xhx.module.device.model.DeviceLogEntity; import com.mortals.xhx.module.device.model.DeviceLogEntity;
import com.mortals.xhx.module.device.service.DeviceLogService; import com.mortals.xhx.module.device.service.DeviceLogService;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -22,6 +29,11 @@ import java.util.List; ...@@ -22,6 +29,11 @@ import java.util.List;
@Service("deviceLogService") @Service("deviceLogService")
public class DeviceLogServiceImpl extends AbstractCRUDServiceImpl<DeviceLogDao, DeviceLogEntity, Long> implements DeviceLogService { public class DeviceLogServiceImpl extends AbstractCRUDServiceImpl<DeviceLogDao, DeviceLogEntity, Long> implements DeviceLogService {
@Value("${spring.application.name:''}")
private String appName;
@Autowired
private MessageProducer messageProducer;
@Override @Override
protected void findAfter(DeviceLogEntity params, PageInfo pageInfo, Context context, List<DeviceLogEntity> list) throws AppException { protected void findAfter(DeviceLogEntity params, PageInfo pageInfo, Context context, List<DeviceLogEntity> list) throws AppException {
...@@ -34,4 +46,21 @@ public class DeviceLogServiceImpl extends AbstractCRUDServiceImpl<DeviceLogDao, ...@@ -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; ...@@ -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.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.URLUtil; import cn.hutool.core.util.URLUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.mortals.framework.ap.GlobalSysInfo; import com.mortals.framework.ap.GlobalSysInfo;
...@@ -10,12 +11,15 @@ import com.mortals.framework.model.Context; ...@@ -10,12 +11,15 @@ import com.mortals.framework.model.Context;
import com.mortals.framework.model.OrderCol; import com.mortals.framework.model.OrderCol;
import com.mortals.xhx.base.system.message.MessageService; import com.mortals.xhx.base.system.message.MessageService;
import com.mortals.xhx.busiz.rsp.ProductVersionInfo; 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.key.Constant;
import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders; import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders;
import com.mortals.xhx.common.model.MessageHeader; import com.mortals.xhx.common.model.MessageHeader;
import com.mortals.xhx.common.utils.BeanUtil; import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.device.model.DeviceEntity; 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.model.DeviceQuery;
import com.mortals.xhx.module.device.service.DeviceLogService;
import com.mortals.xhx.module.device.service.DeviceService; import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.platform.model.PlatformEntity; import com.mortals.xhx.module.platform.model.PlatformEntity;
import com.mortals.xhx.module.platform.service.PlatformService; import com.mortals.xhx.module.platform.service.PlatformService;
...@@ -23,7 +27,9 @@ import com.mortals.xhx.module.product.model.ProductQuery; ...@@ -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.ProductVersionEntity;
import com.mortals.xhx.module.product.model.ProductVersionQuery; import com.mortals.xhx.module.product.model.ProductVersionQuery;
import com.mortals.xhx.module.product.service.ProductVersionService; 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.TbQueueMsgHeaders;
import com.mortals.xhx.queue.TbQueueMsgMetadata;
import com.mortals.xhx.queue.TopicPartitionInfo; import com.mortals.xhx.queue.TopicPartitionInfo;
import com.sun.jndi.toolkit.url.UrlUtil; import com.sun.jndi.toolkit.url.UrlUtil;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
...@@ -37,6 +43,7 @@ import org.springframework.util.ObjectUtils; ...@@ -37,6 +43,7 @@ import org.springframework.util.ObjectUtils;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_HTTP_URL; import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_HTTP_URL;
...@@ -61,6 +68,8 @@ public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, Prod ...@@ -61,6 +68,8 @@ public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, Prod
private MessageService messageService; private MessageService messageService;
@Autowired @Autowired
private PlatformService platformService; private PlatformService platformService;
@Autowired
private DeviceLogService deviceLogService;
@Override @Override
protected void saveBefore(ProductEntity entity, Context context) throws AppException { protected void saveBefore(ProductEntity entity, Context context) throws AppException {
...@@ -124,11 +133,49 @@ public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, Prod ...@@ -124,11 +133,49 @@ public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, Prod
header.put(MessageHeader.DEVICECODE, deviceEntity.getDeviceCode()); header.put(MessageHeader.DEVICECODE, deviceEntity.getDeviceCode());
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);
deviceService.sendDeviceMessage(deviceEntity, info, header, JSON.toJSONString(productVersionInfo), null, null); 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) { private void buildDownloadUrl(ProductVersionEntity productVersionEntity, ProductVersionInfo productVersionInfo) {
String download = ""; 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