2021与蓝度共同重构项目,服务端
liuhaonan
2022-10-25 dda268997ca8f8a364f7c19b45d7a43a50a98efe
ximon-admin/src/main/java/com/sandu/ximon/admin/service/RemoteUpdateService.java
@@ -1,7 +1,10 @@
package com.sandu.ximon.admin.service;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.dto.RemoteFileDto;
import com.sandu.ximon.admin.dto.RemoteUpdateTypeDto;
import com.sandu.ximon.admin.manager.iot.frame.A5Frame;
@@ -11,12 +14,19 @@
import com.sandu.ximon.admin.manager.iot.rrpc.enums.RemoteUpdateTypeEnum;
import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService;
import com.sandu.ximon.admin.manager.iot.rrpc.util.FileProcessingUtils;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
import com.sandu.ximon.admin.utils.StringUtil;
import com.sandu.ximon.dao.bo.RemoteUpdateFileBo;
import com.sandu.ximon.dao.domain.Admin;
import com.sandu.ximon.dao.domain.Client;
import com.sandu.ximon.dao.domain.RemoteUpdateFile;
import com.sandu.ximon.dao.mapper.RemoteUpdateFileMapper;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
@@ -25,6 +35,8 @@
 */
@Service
public class RemoteUpdateService extends BaseServiceImpl<RemoteUpdateFileMapper, RemoteUpdateFile> {
    private RemoteUpdateFileMapper remoteUpdateFileMapper;
    /**
     * 添加文件更新内容
     *
@@ -39,6 +51,8 @@
        RemoteUpdateFile remoteUpdateFile = new RemoteUpdateFile();
        remoteUpdateFile.setAliAddress(aliAddress);
        remoteUpdateFile.setFileType(fileType);
        remoteUpdateFile.setUploadUserId(SecurityUtils.getUserId());
        remoteUpdateFile.setUploadUserType(SecurityUtils.getClientId() == null ? 0 : 1);
        remoteUpdateFile.setSoftwareVersion(new BigDecimal(softwareVersion).setScale(2, BigDecimal.ROUND_DOWN));
        remoteUpdateFile.setHardwareVersion(new BigDecimal(hardwareVersion).setScale(2, BigDecimal.ROUND_DOWN));
        remoteUpdateFile.setFilename(filename);
@@ -47,12 +61,63 @@
    }
    /**
     * 修改固件升级文件名称
     *
     * @param remoteFileId
     * @param remoteFileName
     * @return
     */
    public String updateRemoteFileName(String remoteFileId, String remoteFileName) {
        if (remoteFileId == null || StringUtil.strIsNullOrEmpty(remoteFileName)) {
            throw new BusinessException("参数错误!");
        }
        RemoteUpdateFile remoteUpdateFile = getById(remoteFileId);
        if (remoteUpdateFile == null) {
            throw new BusinessException("固件升级文件不存在!");
        }
        remoteUpdateFile.setFilename(remoteFileName);
        boolean update = updateById(remoteUpdateFile);
        if (!update) {
            throw new BusinessException("修改固件升级文件名失败!");
        }
        return "修改固件升级文件名成功!";
    }
    /**
     * 固件升级文件
     *
     * @return
     */
    public List<RemoteUpdateFile> getRemoteFileList() {
        return list();
    public List<RemoteUpdateFileBo> getRemoteFileList() {
        List<RemoteUpdateFile> list = list();
        List<Admin> adminList = SpringContextHolder.getBean(AdminService.class).list();
        List<Client> clientList = SpringContextHolder.getBean(ClientService.class).list();
        List<RemoteUpdateFileBo> remoteUpdateFileBoList = new ArrayList<>();
        RemoteUpdateFileBo remoteUpdateFileBo;
        for (RemoteUpdateFile bean : list) {
            remoteUpdateFileBo = new RemoteUpdateFileBo();
            BeanUtil.copyProperties(bean, remoteUpdateFileBo);
            if (bean.getUploadUserType() == 0) {
                for (Admin admin : adminList) {
                    if (bean.getUploadUserId().equals(admin.getId())) {
                        remoteUpdateFileBo.setUploadName(admin.getNickName());
                    }
                }
            } else if (bean.getUploadUserType() == 1) {
                for (Client client : clientList) {
                    if (bean.getUploadUserId().equals(client.getId())) {
                        remoteUpdateFileBo.setUploadName(client.getClientName());
                    }
                }
            } else {
                remoteUpdateFileBo.setUploadName("未知用户!");
            }
            remoteUpdateFileBoList.add(remoteUpdateFileBo);
        }
        return remoteUpdateFileBoList;
    }
@@ -78,6 +143,7 @@
        A5Frame a5Frame = new A5Frame(orderType, remoteStartUpdateReqInnerFrame);
        System.out.println(a5Frame + "      a5Frame");
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(mac, "固件升级-启动远程升级", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
        RemoteStartUpdateReportInnerFrame remoteStartUpdateReportInnerFrame
@@ -118,29 +184,30 @@
     * @param filePath 文件路径地址
     */
    public RemoteFileDto UpdateFileInfo(String orderType, String mac, String filePath) {
        try {
            RemoteFileDto remoteFileDto = FileProcessingUtils.read(filePath);
            RemoteSendFileReqInnerFrame remoteSendFileReqInnerFrame
                    = new RemoteSendFileReqInnerFrame(remoteFileDto.getListSize(), remoteFileDto.getList().size(), 512, remoteFileDto.getFileHexStr());
            A5Frame a5Frame = new A5Frame(orderType, remoteSendFileReqInnerFrame);
            System.out.println(a5Frame + "      a5Frame");
            CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame);
            System.out.println(commonFrame + "            -----commonFrame");
            RemoteUpdateFileInfoReportInnerFrame remoteUpdateFileInfoReportInnerFrame
                    = new RemoteUpdateFileInfoReportInnerFrame().transformFrame(commonFrame.getPayload());
            //确认OK
            if (remoteUpdateFileInfoReportInnerFrame != null && remoteUpdateFileInfoReportInnerFrame.isFlag()) {
                return remoteFileDto;
            } else {
                return null;
            }
        } catch (IOException e) {
            e.printStackTrace();
        RemoteFileDto remoteFileDto = FileProcessingUtils.read(filePath);
        if (remoteFileDto == null) {
            throw new BusinessException("文件不存在");
        }
        return null;
        RemoteSendFileReqInnerFrame remoteSendFileReqInnerFrame
                = new RemoteSendFileReqInnerFrame(remoteFileDto.getListSize(), remoteFileDto.getList().size(), 512, remoteFileDto.getFileHexStr());
        A5Frame a5Frame = new A5Frame(orderType, remoteSendFileReqInnerFrame);
        System.out.println(a5Frame + "      a5Frame");
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(mac, "固件升级-升级文件信息", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
        RemoteUpdateFileInfoReportInnerFrame remoteUpdateFileInfoReportInnerFrame
                = new RemoteUpdateFileInfoReportInnerFrame().transformFrame(commonFrame.getPayload());
        //确认OK
        if (remoteUpdateFileInfoReportInnerFrame != null && remoteUpdateFileInfoReportInnerFrame.isFlag()) {
            return remoteFileDto;
        } else {
            return null;
        }
    }
    /**
@@ -156,10 +223,13 @@
        CommonFrame commonFrame = null;
        try {
            commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame);
            System.out.println(commonFrame + "            -----commonFrame");
        } catch (Exception e) {
            System.out.println("发送数据超时或失败");
        }
        StoreOperationRecordsUtils.storeInnerFrameData(mac, "固件升级-升级包数据", a5Frame, commonFrame);
        //FE  B2  0004  0056  01  00  AE2C4474
    }
@@ -171,6 +241,8 @@
        A5Frame a5Frame = new A5Frame(orderType, remoteSearchLoseDataReqInnerFrame);
        System.out.println(a5Frame + "      a5Frame");
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(mac, "固件升级-查询漏包帧", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
        RemoteSearchLoseDataReportInnerFrame remoteSearchLoseDataReportInnerFrame = new RemoteSearchLoseDataReportInnerFrame().transformFrame(commonFrame.getPayload());
@@ -196,6 +268,8 @@
        A5Frame a5Frame = new A5Frame(orderType, remoteFinishUpdateReqInnerFrame);
        System.out.println(a5Frame + "      a5Frame");
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(mac, "固件升级-升级结束", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
        RemoteFinishUpdateReportInnerFrame remoteFinishUpdateReportInnerFrame = new RemoteFinishUpdateReportInnerFrame().transformFrame(commonFrame.getPayload());
@@ -212,6 +286,8 @@
        A5Frame a5Frame = new A5Frame(orderType, remoteSearchUpdateResultReqInnerFrame);
        System.out.println(a5Frame + "      a5Frame");
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(mac, "固件升级-升级结果查询", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
        RemoteSearchUpdateResultReportInnerFrame innerFrame = new RemoteSearchUpdateResultReportInnerFrame().transformFrame(commonFrame.getPayload());
@@ -227,6 +303,8 @@
        A5Frame a5Frame = new A5Frame(orderType, remoteStopUpdateReqInnerFrame);
        System.out.println(a5Frame + "      a5Frame");
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(mac, "固件升级-紧急中断", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
        RemoteStopUpdateReportInnerFrame innerFrame = new RemoteStopUpdateReportInnerFrame().transformFrame(commonFrame.getPayload());