业务:资产管理功能

文章目录

一、项目背景

1.1概述

本设计文档旨在定义一个页面,用于展示和管理资产信息。该页面将整合多种资产类型的信息,包括 FAU(风扇板)、BPB(基带板)、MCB(主控板)、PSU(电源板)、EIB(环境监控板)、RRU(远程射频单元) 和 BBU。通过一个集中化的界面,用户能够高效地查看、管理和分析这些资产的数据。

1.2编写目的

  1. 资产信息整合:提供一个集中的平台,将各种资产(FAU、BPB、MCB、PSU、EIB、RRU 和 BBU)的信息整合在一个页面上,以便于用户能够快速访问和管理这些资产的详细数据。
  2. 用户友好的界面:设计一个直观且用户友好的界面,使用户能够轻松地查看资产状态、规格、位置等信息。通过清晰的布局和导航,提高用户的操作效率和体验。
  3. 定时数据更新:确保资产信息能够定时更新,反映最新的状态和数据。这包括资产的运行状况、维护记录、故障警告等,帮助用户及时做出决策。
  4. 增强数据可视化:通过图表、表格和其他可视化组件,提供资产信息的直观展示,使用户能够快速理解和分析数据,支持数据驱动的决策。
  5. 支持资产管理功能:实现资产的查询基本操作功能,同时支持按条件过滤,支持资产的全面管理和维护。
  6. 提升效率与准确性:通过自动化的数据更新和管理流程,减少人工操作的错误,提高资产管理的效率和准确性。

二、注意点说明

注意点1:功能除了增删改查,还支持手动自动同步更新按钮、导出资产信息excel功能
注意点2:资产统计分:硬件资产、光模块资产。
注意点3:有手动同步按钮和自动同步逻辑,硬件资产自动同步每天1:20:00自动同步,光模块资产自动同步每天1:30:00自动同步。
注意点4:由于需要并行执行命令查询入库,为了用户体验性,采用CountDownLatch监控多线程并行结束时刻,再接口返回处理结果。

三、页面效果


四、代码

AssetManagementController

java 复制代码
package com.hero.lte.ems.monitor.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hero.lte.ems.common.tools.CustomStringUtils;
import com.hero.lte.ems.common.tools.LocaleUtil;
import com.hero.lte.ems.db.orm.mybatis.Page;
import com.hero.lte.ems.mid.service.IBusinessNeService;
import com.hero.lte.ems.mml.entity.MMLRequest;
import com.hero.lte.ems.mml.entity.MMLResponse;
import com.hero.lte.ems.mml.service.IMMLSenderService;
import com.hero.lte.ems.monitor.constants.AssetConst;
import com.hero.lte.ems.monitor.entity.HwinfoAssetManagement;
import com.hero.lte.ems.monitor.entity.SfpAssetManagement;
import com.hero.lte.ems.monitor.service.HwinfoAssetManagementService;
import com.hero.lte.ems.monitor.service.SfpAssetManagementService;
import com.hero.lte.ems.monitor.util.ConstantUtils;
import com.hero.lte.ems.sysconf.model.SysInfo;
import com.hero.lte.ems.topo.entity.Equipment;
import com.hero.lte.ems.topo.service.IEquipmentService;
import com.hero.lte.ems.topo.utils.StringUtils;
import com.hero.lte.ems.vm.newapi.model.VersionQueryClientResp;
import com.hero.lte.ems.vm.newapi.service.IVersionNewQueryService;
import io.swagger.annotations.Api;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MediaType;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


/**
 * @author l22898
 */
@Api(value = "MonitorTaskController",tags={"资产管理"})
@RestController
@RequestMapping("/lte/ems/sys/assetManagement/")
@EnableScheduling
public class AssetManagementController {

    private static final Logger logger = LoggerFactory.getLogger(AssetManagementController.class);
    @Resource
    private IEquipmentService equipmentService;
    @Autowired
    private HwinfoAssetManagementService hwinfoAssetManagementService;
    @Autowired
    private SfpAssetManagementService sfpAssetManagementService;
    @Autowired
    private IBusinessNeService businessNeService;
    @Resource
    private IMMLSenderService mmlSender;
    @Autowired
    private SysInfo sysInfo;
    @Resource
    private IVersionNewQueryService versionNewQueryService;

    private final ExecutorService executorObserveInfo = Executors.newFixedThreadPool(ConstantUtils.threadNum());

    /**
     * 查询硬件资产信息列表
     * @param page page
     * @return 结果
     */
    @ResponseBody
    @RequestMapping(value = "queryHwinfoAssetManagementList", method = RequestMethod.GET)
    public Page<HwinfoAssetManagement> queryHwinfoAssetManagementList(HwinfoAssetManagement hwinfoAssetManagement, Page<HwinfoAssetManagement> page){
        page.setParam(hwinfoAssetManagement);
        return hwinfoAssetManagementService.queryHwinfoAssetManagementList(page);
    }

    /**
     * 点击"资产信息反构"按钮,触发立即执行更新数据
     */
    @ResponseBody
    @RequestMapping(value = "syncHwinfoAssetManagementStore", method = RequestMethod.GET)
    public void syncHwinfoAssetManagementStore(){
        hwinfoAssetManagementStore();
    }

     /*
     * 导出硬件资产信息数据
     */
    @ResponseBody
    @RequestMapping(value = "exportHwinfoAssetManagementList", method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON,produces = MediaType.APPLICATION_JSON)
    public void exportHwinfoAssetManagementList(@RequestBody HwinfoAssetManagement hwinfoAssetManagement, HttpServletResponse response){
        List<HwinfoAssetManagement> list = hwinfoAssetManagementService.queryHwinfoAssetManagementList(hwinfoAssetManagement);
        Locale local = LocaleUtil.getLocale(sysInfo.getLocale());
        Boolean isChinese = "zh".equalsIgnoreCase(local.getLanguage());
        String[] headers=new String[]{AssetConst.en_nodeId, AssetConst.en_deviceName,AssetConst.en_assetType,
                AssetConst.en_localtion,AssetConst.en_presentState,AssetConst.en_sn,AssetConst.en_vid,AssetConst.en_version};
        if(isChinese){
            headers=new String[]{AssetConst.zh_nodeId, AssetConst.zh_deviceName,AssetConst.zh_assetType,
                    AssetConst.zh_localtion,AssetConst.zh_presentState,AssetConst.zh_sn,AssetConst.zh_vid,AssetConst.zh_version};
        }
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet(isChinese ? AssetConst.zh_hwinfoAssetList :AssetConst.en_hwinfoAssetList);
        XSSFRow row = sheet.createRow(0);//行
        XSSFCell cell  = null;

        // 创建单元格样式
        XSSFCellStyle style = wb.createCellStyle();
        XSSFFont font = wb.createFont();
        font.setBold(true); // 设置字体加粗
        style.setFont(font);

        //逐个设置标题样式
        for (int i = 0; i < headers.length; i++) {
            cell = row.createCell(i);
            cell.setCellValue(headers[i]);
            cell.setCellStyle(style);

        }
        int n = 1;
        for (HwinfoAssetManagement item : list) {
            //循环写入值
            XSSFRow rowN = sheet.createRow(n);//行
            for (int i = 0; i < headers.length; i++) {
                cell = rowN.createCell(i);
                cell.setCellValue(switchValue(i,item, isChinese));
            }
            n++;
        }
        sheet.setColumnWidth(1, 4000);
        sheet.setColumnWidth(2, 4000);
        sheet.setColumnWidth(3, 8000);
        sheet.setColumnWidth(4, 4000);
        sheet.setColumnWidth(5, 4000);
        sheet.setColumnWidth(6, 4000);
        sheet.setColumnWidth(7, 4000);
        String fileName = isChinese ? AssetConst.zh_hwinfo_file_name :AssetConst.en_hwinfo_file_name;
        String sysPath =  System.getProperty("eam.conf")+File.separator+"excel";
        String excelPath =sysPath+File.separator+fileName;
        File dir = new File(sysPath);
        if(!dir.exists()  && !dir.isDirectory()){
            dir.mkdir();
        }

        //生成文件并返回前端
        try{
            FileOutputStream fileOut = new FileOutputStream(excelPath);
            wb.write(fileOut);
            fileOut.flush();
            fileOut.close();
            File file = new File(excelPath);
            InputStream ins = new FileInputStream(file);
            BufferedInputStream bins = new BufferedInputStream(ins);// 放到缓冲流里面
            OutputStream outs = response.getOutputStream();// 获取文件输出IO流
            BufferedOutputStream bouts = new BufferedOutputStream(outs);
            response.setContentType("application/x-download");// 设置response内容的类型
            response.setHeader(
                    "Content-disposition",
                    "attachment;filename="
                            + URLEncoder.encode(System.currentTimeMillis()/1000+"_"+fileName, "UTF-8"));// 设置头部信息
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            //开始向网络传输文件流
            while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
                bouts.write(buffer, 0, bytesRead);
            }
            bouts.flush();// 这里一定要调用flush()方法
            ins.close();
            bins.close();
            outs.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    @Scheduled(cron = "0 20 1 * * ?")
    public void hwinfoAssetManagementStore() {
        try {
            hwinfoAssetManagementService.truncateHwinfoAssetManagement();
            List<Equipment> list = equipmentService.queryAllEquipment(null);
            //过滤掉不在线的设备,不在线的设备不能发送mml
            List<Equipment> equipments = list.stream().filter(equipment -> {
                return businessNeService.qryNodeLinkStatus(equipment.getId()) == 1;
            }).collect(Collectors.toList());
            CountDownLatch countDownLatch = new CountDownLatch(equipments.size());
            for (Equipment equipment : equipments) {
                executorObserveInfo.execute(new Runnable() {
                    @Override
                    public void run() {
                        List<HwinfoAssetManagement> assetList = new ArrayList<>();
                        queryFanInfo(equipment, assetList);
                        queryBpbInfo(equipment, assetList);
                        queryMcbInfo(equipment, assetList);
                        queryPsuInfo(equipment, assetList);
                        queryEibInfo(equipment, assetList);
                        queryRruInfo(equipment, assetList);
                        if (assetList.size() > 0) {
                            hwinfoAssetManagementService.batchInsertHwinfoAssetManagement(assetList);
                        }
                        countDownLatch.countDown();
                    }
                });
            }

            boolean flag = countDownLatch.await(5, TimeUnit.MINUTES);
            logger.info("hwinfoAssetManagementStore CountDownLatch await result:{}", flag);
        } catch (Exception e) {
            logger.error("hwinfoAssetManagementStore an exception occurred when trying to await countDownLatch", e);
        }
    }

    /**
     * MML查询风扇FAN信息
     * MML结果长这样:data=[{"MessageContent":"[0-0-0] Present State:  Present"}], neid=null]
     * @param equipment 设备
     */
    public void queryFanInfo(Equipment equipment, List<HwinfoAssetManagement> assetList) {
        logger.info("-queryFanInfo-equipmentId:{},assetList:{}", equipment.getId(), assetList);
        String presentValue = "";
        String location = "";
        String presentStateCmd = "SHW CU;" ;
        Map<Integer, MMLResponse> presentStateResult = sendMMLCmd(presentStateCmd, equipment.getId());
        MMLResponse presentStateResponse = presentStateResult.get(equipment.getId());
        List<JSONObject> presentStateDatas = presentStateResponse.getData();
        if(presentStateDatas != null && !presentStateDatas.isEmpty()) {
            for (JSONObject jsonObject : presentStateDatas) {
                presentValue = (String) jsonObject.get("Present");
                String shNum = (String) jsonObject.get("ShNum");
                String chNum = (String) jsonObject.get("ChNum");
                String slNum = (String) jsonObject.get("SlNum");
                location = "cabinet=" + shNum + ",frame=" + chNum + ",slot=" + slNum;
            }
        }

        if (presentValue.equals("Present")) {
            String shNum = "";
            String chNum = "";
            String slNum = "";
            String key = "";
            String value = "";

            String cmdCell = "DSP HwInfo:HwType = FAN" ;
            Map<Integer, MMLResponse> stringMMLResponseMapCmdCell = sendMMLCmd(cmdCell, equipment.getId());
            logger.info("-queryFanInfo-mml command={},neId={},result={}", cmdCell, equipment.getId(),stringMMLResponseMapCmdCell.toString());
            MMLResponse responseserCell = stringMMLResponseMapCmdCell.get(equipment.getId());
            List<JSONObject> datasCell = responseserCell.getData();
            if(datasCell != null && !datasCell.isEmpty()){
                for (JSONObject json : datasCell) {
                    if (json.containsKey("MessageContent") && json.getString("MessageContent") != null) {
                        String messageContent = json.getString("MessageContent");
                        if (messageContent.contains("[") && messageContent.contains("]")) {
                            Pattern pattern = Pattern.compile("\\[(\\d)+-(\\d)+-(\\d)+\\]\\s*(.+?): \\s*(.+)\\s*(?:\\n|$)");
                            Matcher matcher = pattern.matcher(messageContent);
                            HwinfoAssetManagement hwinfoAssetManagement = new HwinfoAssetManagement();
                            while (matcher.find()) {
                                shNum = matcher.group(1);
                                chNum = matcher.group(2);
                                slNum = matcher.group(3);
                                key = matcher.group(4);
                                value = matcher.group(5);
                                location = "cabinet=" + shNum + ",frame=" + chNum + ",slot=" + slNum;
                                if (org.springframework.util.StringUtils.isEmpty(value)) {
                                    continue;
                                }
                                if (CustomStringUtils.containsInvalidCharacters(value)) {
                                    continue;
                                }
                                switch (key) {
                                    case "SN":
                                        hwinfoAssetManagement.setSn(value);
                                        break;
                                    case "VID":
                                        hwinfoAssetManagement.setVid(value);
                                        break;
                                    default:
                                        logger.error("-queryFanInfo no match key:{}", key);
                                        break;
                                }
                            }
                            hwinfoAssetManagement.setPresentState("1");
                            hwinfoAssetManagement.setNodeId(equipment.getId());
                            hwinfoAssetManagement.setNodeName(equipment.getName());
                            hwinfoAssetManagement.setAssetType("FAN");
                            hwinfoAssetManagement.setLocaltion(location);
                            assetList.add(hwinfoAssetManagement);
                        }
                    }
                }
            }else{
                logger.info("-queryFanInfo mml command={},neId={},没有data数据", cmdCell, equipment);
            }
        } else {
            HwinfoAssetManagement hwinfoAssetManagement = new HwinfoAssetManagement();
            hwinfoAssetManagement.setPresentState("0");
            hwinfoAssetManagement.setNodeId(equipment.getId());
            hwinfoAssetManagement.setNodeName(equipment.getName());
            hwinfoAssetManagement.setAssetType("FAN");
            hwinfoAssetManagement.setLocaltion(location);
            assetList.add(hwinfoAssetManagement);
        }
        logger.info("-queryFanInfo-end!-assetList:{}", assetList);
    }

    /**
     * 查询BPB单板信息
     * @param equipment equipment
     * @param assetList assetList
     */
    private void queryBpbInfo(Equipment equipment, List<HwinfoAssetManagement> assetList){
        logger.info("-queryBpbInfo-equipment:{},assetList:{}", equipment, assetList);
        String shNum = "";
        String chNum = "";
        String slNum = "";
        String revisonVer="";
        String serial ="";
        String location = "";
        String presentValue = "";

        //生成查询BPB mml指令
        String mmlbbunamecmd="SHW BPB;";
        Map<Integer, MMLResponse> result = sendMMLCmd(mmlbbunamecmd, equipment.getId());
        logger.info("mml command={},neId={},result={}", mmlbbunamecmd, equipment.getId(),result.toString());
        MMLResponse response = result.get(equipment.getId());
        List<JSONObject> datas = response.getData();
        if(datas != null && !datas.isEmpty()){
            for (JSONObject jsonObject : datas) {
                presentValue = jsonObject.get("Present").toString();
                shNum = (String) jsonObject.get("ShNum");
                chNum = (String) jsonObject.get("ChNum");
                slNum = (String) jsonObject.get("SlNum");
                location = "cabinet=" + shNum + ",frame=" + chNum + ",slot=" + slNum;
                if (presentValue.equals("Present")) {
                    Integer slotNo = Integer.parseInt(jsonObject.get("SlNum").toString());
                    //生成查询BPB series mml指令
                    String mmlbpbserisecmd="DSP LBPElableInfo : " + "slotNo = " + slotNo+";";
                    Map<Integer, MMLResponse> bpbseresult = sendMMLCmd(mmlbpbserisecmd, equipment.getId());
                    logger.info("mml command={},neId={},result={}", bpbseresult, equipment.getId(),bpbseresult.toString());
                    MMLResponse bpbseriseresultresponse = bpbseresult.get(equipment.getId());
                    List<JSONObject> bpbserisedatas = bpbseriseresultresponse.getData();
                    if(bpbserisedatas !=null && !bpbserisedatas.isEmpty()){
                        Optional<JSONObject> bpbseriseData = bpbserisedatas.stream().findFirst();
                        if(bpbseriseData.isPresent()){
                            JSONObject jsonObjectbpb = bpbseriseData.get();
                            serial = StringUtils.extractedString(jsonObjectbpb.toString(), "boardSerial:", "boardProductDate");
                            if (StringUtils.isGarbage(serial)) serial = "";
                        }
                    }else{
                        serial = "";
                        logger.info("mml command={},neId={},没有data数据", bpbseresult, equipment.getId());
                    }
                    // 底软版本号
                    String mmlbpbRevisioncmd="SHW"+" "+"eSWM"+";";
                    Map<Integer, MMLResponse> bpbRevisionResult = sendMMLCmd(mmlbpbRevisioncmd, equipment.getId());
                    logger.info("mml mmlbpbRevisioncmd command={},neId={},result={}", mmlbpbRevisioncmd, equipment.getId(),bpbRevisionResult.toString());
                    MMLResponse bpbRevisionResponse = bpbRevisionResult.get(equipment.getId());
                    List<JSONObject> bpbRevisionDatas = bpbRevisionResponse.getData();
                    if(bpbRevisionDatas !=null && !bpbRevisionDatas.isEmpty()){
                        Optional<JSONObject> bpbRevisionData = bpbRevisionDatas.stream().findFirst();
                        if(bpbRevisionData.isPresent()){
                            JSONObject jsonObj = bpbRevisionData.get();
                            JSONObject eSWMJsonObject = JSONObject.parseObject(jsonObj.get("MessageContent").toString());
                            // BoardList
                            JSONArray boardList = (JSONArray) eSWMJsonObject.get("BoardList");
                            String slNumCopy = slNum;
                            Optional<String> optional = boardList.stream()
                                    .filter(filterItem -> slNumCopy.equals(((JSONObject) filterItem).getString("slNum")))
                                    .flatMap(flatItem -> {
                                        JSONArray swList = ((JSONObject) flatItem).getJSONArray("SwList");
                                        return swList.stream()
                                                .filter(sw -> "1".equals(((JSONObject) sw).get("swtype").toString()))
                                                .map(sw -> ((JSONObject) sw).get("swver").toString());
                                    })
                                    .findFirst();

                            if (optional.isPresent()) {
                                revisonVer =optional.get();
                            } else {
                                revisonVer = "";
                            }
                        }
                    }else{
                        logger.info("mml bpbRevisionDatas command={},neId={},没有data数据", mmlbbunamecmd, equipment.getId());
                    }
                    HwinfoAssetManagement hwinfoAssetManagement = new HwinfoAssetManagement();
                    hwinfoAssetManagement.setPresentState("1");
                    hwinfoAssetManagement.setNodeId(equipment.getId());
                    hwinfoAssetManagement.setNodeName(equipment.getName());
                    hwinfoAssetManagement.setAssetType("BPB");
                    hwinfoAssetManagement.setLocaltion(location);
                    hwinfoAssetManagement.setSn(serial);
                    hwinfoAssetManagement.setVid("11500000082765");
                    hwinfoAssetManagement.setVersion(revisonVer);
                    assetList.add(hwinfoAssetManagement);
                } else {
                    HwinfoAssetManagement hwinfoAssetManagement = new HwinfoAssetManagement();
                    hwinfoAssetManagement.setPresentState("0");
                    hwinfoAssetManagement.setNodeId(equipment.getId());
                    hwinfoAssetManagement.setNodeName(equipment.getName());
                    hwinfoAssetManagement.setAssetType("BPB");
                    hwinfoAssetManagement.setLocaltion(location);
                    assetList.add(hwinfoAssetManagement);
                }
            }
        }else{
            logger.info("mml command={},neId={},没有data数据", mmlbbunamecmd, equipment.getId());
        }
        logger.info("-queryBpbInfo-end!-assetList:{}", assetList);
    }

    /**
     * MML查询单板MCB信息
     * MML结果长这样:data=[{"MessageContent":"[0-0-7] SN: W150SA0036\n[0-0-7] VID: 11500000082766"}], neid=null]
     * @param equipment 设备
     */
    public void queryMcbInfo(Equipment equipment, List<HwinfoAssetManagement> assetList) {
        logger.info("-queryMcbInfo-equipment:{},assetList:{}", equipment, assetList);
        String presentValue = "";
        String location = "";
        String shNum = "";
        String chNum = "";
        String slNum = "";
        String presentStateCmd = "SHW MCB;" ;
        Map<Integer, MMLResponse> presentStateResult = sendMMLCmd(presentStateCmd, equipment.getId());
        MMLResponse presentStateResponse = presentStateResult.get(equipment.getId());
        List<JSONObject> presentStateDatas = presentStateResponse.getData();
        if(presentStateDatas != null && !presentStateDatas.isEmpty()) {
            for (JSONObject jsonObject : presentStateDatas) {
                presentValue = (String) jsonObject.get("Present");
                shNum = (String) jsonObject.get("ShNum");
                chNum = (String) jsonObject.get("ChNum");
                slNum = (String) jsonObject.get("SlNum");
                location = "cabinet=" + shNum + ",frame=" + chNum + ",slot=" + slNum;
                if (presentValue.equals("Present")) {
                    HwinfoAssetManagement hwinfoAssetManagement = new HwinfoAssetManagement();
                    String key = "";
                    String value = "";
                    List<Integer> neIds = null;
                    String cmdCell = "DSP HwInfo:HwType = MCB" ;
                    Map<Integer, MMLResponse> stringMMLResponseMapCmdCell = sendMMLCmd(cmdCell, equipment.getId());
                    logger.info("-queryMcbInfo-mml command={},neId={},result={}", cmdCell, equipment.getId(),stringMMLResponseMapCmdCell.toString());
                    MMLResponse responseserCell = stringMMLResponseMapCmdCell.get(equipment.getId());
                    List<JSONObject> datasCell = responseserCell.getData();
                    if(datasCell != null && !datasCell.isEmpty()){
                        for (JSONObject json : datasCell) {
                            if (json.containsKey("MessageContent") && json.getString("MessageContent") != null) {
                                String messageContent = json.getString("MessageContent");
                                if (messageContent.contains("[") && messageContent.contains("]")) {
                                    neIds = new ArrayList<>();
                                    neIds.add(equipment.getId());
                                    Pattern pattern = Pattern.compile("\\[(\\d)+-(\\d)+-(\\d)+\\]\\s*(.+?): \\s*(.+)\\s*(?:\\n|$)");
                                    Matcher matcher = pattern.matcher(messageContent);

                                    while (matcher.find()) {
                                        String mcbSlNum = matcher.group(3);
                                        if (mcbSlNum != null && mcbSlNum.equals(slNum)) {
                                            key = matcher.group(4);
                                            value = matcher.group(5);
                                            if (org.springframework.util.StringUtils.isEmpty(value)) {
                                                continue;
                                            }
                                            if (CustomStringUtils.containsInvalidCharacters(value)) {
                                                continue;
                                            }
                                            switch (key) {
                                                case "SN":
                                                    hwinfoAssetManagement.setSn(value);
                                                    break;
                                                case "VID":
                                                    hwinfoAssetManagement.setVid(value);
                                                    break;
                                                default:
                                                    logger.error("-queryMcbInfo no match key:{}", key);
                                                    break;
                                            }
                                        }
                                    }
                                    List<VersionQueryClientResp> newResponseList = versionNewQueryService.queryRunVerByNeId(neIds);
                                    for (VersionQueryClientResp item : newResponseList) {
                                        if (item.getSlotId().equals(slNum) && (item.getAppVersion().contains("BBU") || item.getAppVersion().contains("OBBU"))) {
                                            hwinfoAssetManagement.setVersion(item.getAppVersion());
                                        }
                                    }
                                    hwinfoAssetManagement.setPresentState("1");
                                    hwinfoAssetManagement.setNodeId(equipment.getId());
                                    hwinfoAssetManagement.setNodeName(equipment.getName());
                                    hwinfoAssetManagement.setAssetType("MCB");
                                    hwinfoAssetManagement.setLocaltion(location);
                                    assetList.add(hwinfoAssetManagement);
                                }
                            }
                        }
                    }else{
                        logger.info("-queryMcbInfo mml command={},neId={},没有data数据", cmdCell, equipment);
                    }
                } else {
                    HwinfoAssetManagement hwinfoAssetManagement = new HwinfoAssetManagement();
                    hwinfoAssetManagement.setPresentState("0");
                    hwinfoAssetManagement.setNodeId(equipment.getId());
                    hwinfoAssetManagement.setNodeName(equipment.getName());
                    hwinfoAssetManagement.setAssetType("MCB");
                    hwinfoAssetManagement.setLocaltion(location);
                    assetList.add(hwinfoAssetManagement);
                }
            }
        }
        logger.info("-queryMcbInfo-end!-assetList:{}", assetList);
    }

    /**
     * MML查询电源PSU信息
     * MML结果长这样:data=[{"MessageContent":"[PSU-1] Present State: Present\n[PSU-0] Present State: Present\n"}], neid=null]
     * @param equipment 设备
     */
    public void queryPsuInfo(Equipment equipment, List<HwinfoAssetManagement> assetList) {
        logger.info("-queryPsuInfo-equipmentId:{},assetList:{}", equipment.getId(), assetList);
        String presentValue = "";
        String location = "";
        String shNum = "";
        String chNum = "";
        String slNum = "";
        String presentStateCmd = "SHW BBUPM;" ;
        Map<Integer, MMLResponse> presentStateResult = sendMMLCmd(presentStateCmd, equipment.getId());
        MMLResponse presentStateResponse = presentStateResult.get(equipment.getId());
        List<JSONObject> presentStateDatas = presentStateResponse.getData();
        if(presentStateDatas != null && !presentStateDatas.isEmpty()) {
            for (JSONObject presentStateJson : presentStateDatas) {
                presentValue = (String) presentStateJson.get("Present");
                shNum = (String) presentStateJson.get("ShNum");
                chNum = (String) presentStateJson.get("ChNum");
                slNum = (String) presentStateJson.get("SlNum");
                location = "cabinet=" + shNum + ",frame=" + chNum + ",slot=" + slNum;
                if (presentValue.equals("Present")) {
                    HwinfoAssetManagement hwinfoAssetManagement = new HwinfoAssetManagement();
                    Pattern pattern = null;
                    Matcher matcher = null;
                    //注意3801和5801返回数据格式不统一,3801:"[PSU-1] Present State: Present\n[PSU-0] Present State: Present\n",而5801:"[0-0-10] Present State: Present\n[0-0-10] Version: psu3_230728\n[0-0-10] SN: \n[0-0-10] VID: \u0010@\n"
                    String type = "3800";
                    String key = "";
                    String value = "";

                    String cmdCell = "DSP HwInfo:HwType = PSU" ;
                    Map<Integer, MMLResponse> stringMMLResponseMapCmdCell = sendMMLCmd(cmdCell, equipment.getId());
                    logger.info("-queryPsuInfo-mml command={},neId={},result={}", cmdCell, equipment.getId(),stringMMLResponseMapCmdCell.toString());
                    MMLResponse responseserCell = stringMMLResponseMapCmdCell.get(equipment.getId());
                    List<JSONObject> datasCell = responseserCell.getData();

                    if(datasCell != null && !datasCell.isEmpty()){
                        for (JSONObject json : datasCell) {
                            if (json.containsKey("MessageContent") && json.getString("MessageContent") != null) {
                                String messageContent = json.getString("MessageContent");
                                if (messageContent.contains("[") && messageContent.contains("]")) {
                                    if (messageContent.contains("PSU")) {
                                        pattern = Pattern.compile("\\[PSU-(\\d)+\\]\\s*(.+?): \\s*(.+)\\s*\\n");
                                        type = "3801";
                                    } else {
                                        pattern = Pattern.compile("\\[(\\d)+-(\\d)+-(\\d+)\\]\\s*(.+?):\\s*(.*?)\\s*(?=$|\\[\\d+-\\d+-\\d+])");
                                        type = "5801";
                                    }
                                    matcher = pattern.matcher(messageContent);

                                    while (matcher.find()) {
                                        String psuSlNum = matcher.group(3);
                                        if (psuSlNum != null && psuSlNum.equals(slNum)) {
                                            if (type.equals("3801")) {
                                                key = matcher.group(2);
                                                value = matcher.group(3);
                                            } else if (type.equals("5801")){
                                                key = matcher.group(4);
                                                value = matcher.group(5);
                                            }
                                            if (org.springframework.util.StringUtils.isEmpty(value)) {
                                                continue;
                                            }
                                            if (CustomStringUtils.containsInvalidCharacters(value)) {
                                                continue;
                                            }
                                            switch (key) {
                                                case "SN":
                                                    hwinfoAssetManagement.setSn(value);
                                                    break;
                                                case "VID":
                                                    hwinfoAssetManagement.setVid(value);
                                                    break;
                                                case "Version":
                                                    hwinfoAssetManagement.setVersion(value);
                                                    break;
                                                default:
                                                    logger.error("-queryPsuInfo no match key:{}", key);
                                                    break;
                                            }
                                        }
                                    }
                                    hwinfoAssetManagement.setPresentState("1");
                                    hwinfoAssetManagement.setNodeId(equipment.getId());
                                    hwinfoAssetManagement.setNodeName(equipment.getName());
                                    hwinfoAssetManagement.setAssetType("PSU");
                                    hwinfoAssetManagement.setLocaltion(location);
                                    assetList.add(hwinfoAssetManagement);
                                }
                            }
                        }
                    } else {
                        logger.info("-queryPsuInfo mml command={},neId={},没有data数据", cmdCell, equipment);
                    }
                } else {
                    HwinfoAssetManagement hwinfoAssetManagement = new HwinfoAssetManagement();
                    hwinfoAssetManagement.setPresentState("0");
                    hwinfoAssetManagement.setNodeId(equipment.getId());
                    hwinfoAssetManagement.setNodeName(equipment.getName());
                    hwinfoAssetManagement.setAssetType("PSU");
                    hwinfoAssetManagement.setLocaltion(location);
                    assetList.add(hwinfoAssetManagement);
                }
            }
        }


        logger.info("-queryPsuInfo-end!-assetList:{}", assetList);
    }

    /**
     * MML查询环境监控Eib信息
     * MML结果长这样:data=[{"MessageContent":"[0-0-11] Present State: Present\n[0-0-11] Version: eib_240221"}], neid=null]
     * @param equipment 设备
     */
    public void queryEibInfo(Equipment equipment, List<HwinfoAssetManagement> assetList) {
        logger.info("-queryEibInfo-equipment:{},assetList:{}", equipment, assetList);
        String presentValue = "";
        String location = "";
        String shNum = "";
        String chNum = "";
        String slNum = "";
        String presentStateCmd = "SHW EIB;" ;
        Map<Integer, MMLResponse> presentStateResult = sendMMLCmd(presentStateCmd, equipment.getId());
        MMLResponse presentStateResponse = presentStateResult.get(equipment.getId());
        List<JSONObject> presentStateDatas = presentStateResponse.getData();
        if(presentStateDatas != null && !presentStateDatas.isEmpty()) {
            for (JSONObject jsonObject : presentStateDatas) {
                presentValue = (String) jsonObject.get("Present");
                shNum = (String) jsonObject.get("ShNum");
                chNum = (String) jsonObject.get("ChNum");
                slNum = (String) jsonObject.get("SlNum");
                location = "cabinet=" + shNum + ",frame=" + chNum + ",slot=" + slNum;
            }
        }
        if (presentValue.equals("Present")) {
            HwinfoAssetManagement hwinfoAssetManagement = new HwinfoAssetManagement();

            String key = "";
            String value = "";
            String cmdCell = "DSP HwInfo: HwType=\"EIB\"";
            Map<Integer, MMLResponse> stringMMLResponseMapCmdCell = sendMMLCmd(cmdCell, equipment.getId());
            logger.info("-queryEibInfo-mml command={},neId={},result={}", cmdCell, equipment.getId(),stringMMLResponseMapCmdCell.toString());
            MMLResponse responseserCell = stringMMLResponseMapCmdCell.get(equipment.getId());
            List<JSONObject> datasCell = responseserCell.getData();
            if(datasCell != null && !datasCell.isEmpty()){
                for (JSONObject json : datasCell) {
                    if (json.containsKey("MessageContent") && json.getString("MessageContent") != null) {
                        String messageContent = json.getString("MessageContent");
                        if (messageContent.contains("[") && messageContent.contains("]")) {
                            Pattern pattern = Pattern.compile("\\[(\\d)+-(\\d)+-(\\d)+\\]\\s*(.+?): \\s*(.+)\\s*(?:\\n|$)");
                            Matcher matcher = pattern.matcher(messageContent);

                            while (matcher.find()) {
                                slNum = matcher.group(3);
                                if (slNum != null) {
                                    key = matcher.group(4);
                                    value = matcher.group(5);
                                    if (org.springframework.util.StringUtils.isEmpty(value)) {
                                        continue;
                                    }
                                    if (CustomStringUtils.containsInvalidCharacters(value)) {
                                        continue;
                                    }
                                    switch (key) {
                                        case "SN":
                                            hwinfoAssetManagement.setSn(value);
                                            break;
                                        case "VID":
                                            hwinfoAssetManagement.setVid(value);
                                            break;
                                        case "Version":
                                            hwinfoAssetManagement.setVersion(value);
                                            break;
                                        default:
                                            logger.error("-queryEibInfo no match key:{}", key);
                                            break;
                                    }
                                }
                            }
                            hwinfoAssetManagement.setPresentState("1");
                            hwinfoAssetManagement.setNodeId(equipment.getId());
                            hwinfoAssetManagement.setNodeName(equipment.getName());
                            hwinfoAssetManagement.setAssetType("EIB");
                            hwinfoAssetManagement.setLocaltion(location);
                            assetList.add(hwinfoAssetManagement);
                        }
                    }
                }
            }else{
                logger.info("-queryEibInfo mml command={},neId={},没有data数据", cmdCell, equipment.getId());
            }
        } else {
            if (!org.springframework.util.StringUtils.isEmpty(location)) {
                HwinfoAssetManagement hwinfoAssetManagement = new HwinfoAssetManagement();
                hwinfoAssetManagement.setPresentState("0");
                hwinfoAssetManagement.setNodeId(equipment.getId());
                hwinfoAssetManagement.setNodeName(equipment.getName());
                hwinfoAssetManagement.setAssetType("EIB");
                hwinfoAssetManagement.setLocaltion(location);
                assetList.add(hwinfoAssetManagement);
            }
        }

        logger.info("-queryEibInfo-end!-assetList:{}", assetList);
    }

    /**
     * 查询RRU信息
     * @param equipment equipment
     * @param assetList assetList
     */
    private void queryRruInfo(Equipment equipment, List<HwinfoAssetManagement> assetList){
        logger.info("-queryRruInfo-equipment:{},assetList:{}", equipment, assetList);
        HwinfoAssetManagement hwinfoAssetManagement = null;
        String shNum = "";
        String chNum = "";
        String slNum = "";
        String key = "";
        String value = "";
        String location = "";
        String presentValue = "";
        //生成查询所有rru mml指令
        String mmlcmd="SHW RRU;";
        Map<Integer, MMLResponse> result = sendMMLCmd(mmlcmd, equipment.getId());
        logger.info("mml command={},neId={},result={}", mmlcmd, equipment.getId(),result.toString());
        MMLResponse response = result.get(equipment.getId());
        List<JSONObject> datas = response.getData();
        if(datas != null && !datas.isEmpty()){
            for (JSONObject jsonObject : datas) {
                hwinfoAssetManagement = new HwinfoAssetManagement();
                presentValue = jsonObject.get("present").toString();
                chNum = jsonObject.getString("chNum");
                shNum = jsonObject.getString("shNum");
                slNum = jsonObject.getString("slNum");
                location = "cabinet=" + shNum + ",frame=" + chNum + ",slot=" + slNum;
                if (presentValue.equals("Present")) {
                    //查询序列号 出厂日期
                    String cmd = "DSP HwInfo : ne= " + equipment.getId() + " , HwType = \"RRU\"";
                    Map<Integer, MMLResponse> stringMMLResponseMap = sendMMLCmd(cmd, equipment.getId());
                    logger.info("mml command={},neId={},result={}", cmd, equipment.getId(),stringMMLResponseMap.toString());
                    MMLResponse responseserCell = stringMMLResponseMap.get(equipment.getId());
                    List<JSONObject> datasCell = responseserCell.getData();
                    if(datasCell != null && !datasCell.isEmpty()){
                        for (JSONObject json : datasCell) {
                            if (json.containsKey("MessageContent") && json.getString("MessageContent") != null) {
                                String messageContent = json.getString("MessageContent");
                                if (!messageContent.contains("Error, none RRU info")) {
                                    Pattern pattern = Pattern.compile("\\[RRU-(\\d+)\\]\\s*(.+?):\\s*(.*?)\\s*(?=$|\\[RRU-\\d+\\])");
                                    Matcher matcher = pattern.matcher(messageContent);
                                    while (matcher.find()) {
                                        String rruChNum = matcher.group(1);
                                        if (rruChNum != null && rruChNum.equals(chNum)) {
                                            key = matcher.group(2);
                                            value = matcher.group(3);
                                            if (org.springframework.util.StringUtils.isEmpty(value)) {
                                                continue;
                                            }
                                            if (CustomStringUtils.containsInvalidCharacters(value)) {
                                                continue;
                                            }
                                            switch (key) {
                                                case "SN":
                                                    hwinfoAssetManagement.setSn(value);
                                                    break;
                                                case "Version":
                                                    hwinfoAssetManagement.setVersion(value);
                                                    break;
                                                case "VID":
                                                    hwinfoAssetManagement.setVid(value);
                                                    break;
                                                default:
                                                    logger.error(" no match key:{}", key);
                                                    break;
                                            }
                                        }
                                    }
                                    hwinfoAssetManagement.setPresentState("1");
                                    hwinfoAssetManagement.setNodeId(equipment.getId());
                                    hwinfoAssetManagement.setNodeName(equipment.getName());
                                    hwinfoAssetManagement.setAssetType("RRU");
                                    hwinfoAssetManagement.setLocaltion(location);
                                    assetList.add(hwinfoAssetManagement);
                                }
                            }
                        }
                    }
                } else {
                    hwinfoAssetManagement = new HwinfoAssetManagement();
                    hwinfoAssetManagement.setPresentState("0");
                    hwinfoAssetManagement.setNodeId(equipment.getId());
                    hwinfoAssetManagement.setNodeName(equipment.getName());
                    hwinfoAssetManagement.setAssetType("RRU");
                    hwinfoAssetManagement.setLocaltion(location);
                    assetList.add(hwinfoAssetManagement);
                }
            }
        }
        logger.info("-queryRruInfo-end!-assetList:{}", assetList);
    }

    //生成查询全部rru或者bbu指令
    private Map<Integer, MMLResponse> sendMMLCmd(String mmlcmd,Integer equipmentId){
        Map<Integer, MMLResponse> result = new HashMap<>();
        MMLRequest request = new MMLRequest(equipmentId, mmlcmd);
        request.setCmdType(1);  //1是设备
        //发送mml cmd
        MMLResponse mmlResponse = mmlSender.sendMMLCommand(request);
        if("0".equalsIgnoreCase(mmlResponse.getErrorCode())||"OK".equalsIgnoreCase(mmlResponse.getResult())){
            result.put(equipmentId,mmlResponse);
        }else{
            //調用失敗 模拟的数据
            if(mmlcmd.contains("QRY")&&mmlcmd.contains("Cell")){
                JSONObject jsonObject=new JSONObject();
                jsonObject.put("CellId","CellIdDefault");
                List<JSONObject> objects = new ArrayList<JSONObject>();
                objects.add(jsonObject);
                mmlResponse.setData(objects);
            }
            if(mmlcmd.contains("QRY")&&mmlcmd.contains("RRU")){
                JSONObject jsonObject=new JSONObject();
                jsonObject.put("rruName","rruNameDefault1");
                jsonObject.put("chNum",199999);
                jsonObject.put("shNum",199999);
                jsonObject.put("slNum",199999);
                JSONObject jsonObject2=new JSONObject();
                jsonObject2.put("rruName","rruNameDefault2");
                jsonObject2.put("chNum",299999);
                jsonObject2.put("shNum",299999);
                jsonObject2.put("slNum",299999);
                List<JSONObject> objects = new ArrayList<JSONObject>();
                objects.add(jsonObject);
                objects.add(jsonObject2);
                mmlResponse.setData(objects);
            }
            if(mmlcmd.contains("SHW")&&mmlcmd.contains("RRU")){
                ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS);
                String format = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(now);
                if(mmlcmd.contains("199999")){
                    JSONObject jsonObject=new JSONObject();
                    jsonObject.put("elabel","11111111111111");
                    jsonObject.put("boardManu",format);
                    List<JSONObject> objects = new ArrayList<JSONObject>();
                    objects.add(jsonObject);
                    mmlResponse.setData(objects);
                }
                if(mmlcmd.contains("299999")){
                    JSONObject jsonObject2=new JSONObject();
                    jsonObject2.put("elabel","2222222222");
                    jsonObject2.put("boardManu",format);
                    List<JSONObject> objects = new ArrayList<JSONObject>();
                    objects.add(jsonObject2);
                    mmlResponse.setData(objects);
                }
            }

            if(mmlcmd.contains("QRY")&&mmlcmd.contains("EnodebCfg")){
                JSONObject jsonObject=new JSONObject();
                jsonObject.put("EnodebName","bbuNameDefault");
                jsonObject.put("EnodebId","bbuIdDefault");
                List<JSONObject> objects = new ArrayList<JSONObject>();
                objects.add(jsonObject);
                mmlResponse.setData(objects);
            }
            if(mmlcmd.contains("DSP")&&mmlcmd.contains("LICDEVNO")){
                JSONObject jsonObject=new JSONObject();
                jsonObject.put("devNo","devNoDefault");
                List<JSONObject> objects = new ArrayList<JSONObject>();
                objects.add(jsonObject);
                mmlResponse.setData(objects);
            }
            result.put(equipmentId,mmlResponse);
        }
        return result;
    }

    private String switchValue(int order ,HwinfoAssetManagement hwinfoAssetManagement, Boolean isChinese){
        String value=null;
        switch(order){
            case 0:
                value = hwinfoAssetManagement.getNodeId().toString();
                break;
            case 1:
                if (!org.springframework.util.StringUtils.isEmpty(hwinfoAssetManagement.getNodeName())) {
                    value = hwinfoAssetManagement.getNodeName();
                }
                break;
            case 2:
                if (!org.springframework.util.StringUtils.isEmpty(hwinfoAssetManagement.getAssetType())) {
                    value = hwinfoAssetManagement.getAssetType();
                }
                break;
            case 3:
                if (!org.springframework.util.StringUtils.isEmpty(hwinfoAssetManagement.getLocaltion())) {
                    value = hwinfoAssetManagement.getLocaltion();
                }
                break;
            case 4:
                if (!org.springframework.util.StringUtils.isEmpty(hwinfoAssetManagement.getPresentState())) {
                    String presentState = hwinfoAssetManagement.getPresentState();
                    if (isChinese) {
                        value = presentState.equals("1") ? AssetConst.zh_present : AssetConst.zh_notPresent;
                    } else {
                        value = presentState.equals("1") ? AssetConst.en_present : AssetConst.en_notPresent;
                    }
                }
                break;
            case 5:
                if (!org.springframework.util.StringUtils.isEmpty(hwinfoAssetManagement.getSn())) {
                    value = hwinfoAssetManagement.getSn();
                }
                break;
            case 6:
                if (!org.springframework.util.StringUtils.isEmpty(hwinfoAssetManagement.getVid())) {
                    value = hwinfoAssetManagement.getVid();
                }
                break;
            case 7:
                if (!org.springframework.util.StringUtils.isEmpty(hwinfoAssetManagement.getVersion())) {
                    value = hwinfoAssetManagement.getVersion();
                }
                break;
            default:
                value ="";
                break;

        }
        return value;
    }

    /**
     * 查询光模块资产信息列表
     * @param page page
     * @return 结果
     */
    @ResponseBody
    @RequestMapping(value = "querySfpAssetManagementList", method = RequestMethod.GET)
    public Page<SfpAssetManagement> querySfpAssetManagementList(SfpAssetManagement hwinfoAssetManagement, Page<SfpAssetManagement> page){
        page.setParam(hwinfoAssetManagement);
        return sfpAssetManagementService.querySfpAssetManagementList(page);
    }

    @Scheduled(cron = "0 30 1 * * ?")
    public void sfpAssetManagementStore() {
        try {
            sfpAssetManagementService.truncateSfpAssetManagement();
            List<Equipment> list = equipmentService.queryAllEquipment(null);
            //过滤掉不在线的设备,不在线的设备不能发送mml
            List<Equipment> equipments = list.stream().filter(equipment -> {
                return businessNeService.qryNodeLinkStatus(equipment.getId()) == 1;
            }).collect(Collectors.toList());
            CountDownLatch countDownLatch = new CountDownLatch(equipments.size());
            for (Equipment equipment : equipments) {
                executorObserveInfo.execute(new Runnable() {
                    @Override
                    public void run() {
                        List<SfpAssetManagement> assetList = new ArrayList<>();
                        queryBasebandControlBoardSfpInfo(equipment, assetList);
                        queryMainControlBoardSfpInfo(equipment, assetList);
                        queryRruSfpInfoOfRru(equipment, assetList);
                        if (assetList.size() > 0) {
                            sfpAssetManagementService.batchInsertSfpAssetManagement(assetList);
                        }
                        countDownLatch.countDown();
                    }
                });
            }

            boolean flag = countDownLatch.await(5, TimeUnit.MINUTES);
            logger.info("sfpAssetManagementStore CountDownLatch await result:{}", flag);
        } catch (Exception e) {
            logger.error("sfpAssetManagementStore an exception occurred when trying to await countDownLatch", e);
        }
    }

    /**
     * 点击"资产信息反构"按钮,触发立即执行更新数据
     */
    @ResponseBody
    @RequestMapping(value = "syncSfpAssetManagementStore", method = RequestMethod.GET)
    public void syncSfpAssetManagementStore(){
        sfpAssetManagementStore();
    }

    /*
     * 导出光模块资产信息数据
     */
    @ResponseBody
    @RequestMapping(value = "exportSfpAssetManagementList", method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON,produces = MediaType.APPLICATION_JSON)
    public void exportSfpAssetManagementList(@RequestBody SfpAssetManagement sfpAssetManagement, HttpServletResponse response){
        List<SfpAssetManagement> list = sfpAssetManagementService.querySfpAssetManagementList(sfpAssetManagement);
        Locale local = LocaleUtil.getLocale(sysInfo.getLocale());
        Boolean isChinese = "zh".equalsIgnoreCase(local.getLanguage());
        String[] headers=new String[]{AssetConst.en_nodeId, AssetConst.en_deviceName,AssetConst.en_assetType,
                AssetConst.en_localtion,AssetConst.en_sn,AssetConst.en_vid,AssetConst.en_version};
        if(isChinese){
            headers=new String[]{AssetConst.zh_nodeId, AssetConst.zh_deviceName,AssetConst.zh_assetType,
                    AssetConst.zh_localtion,AssetConst.zh_sn,AssetConst.zh_vid,AssetConst.zh_version};
        }
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet(isChinese ? AssetConst.zh_sfpAssetList :AssetConst.en_sfpAssetList);
        XSSFRow row = sheet.createRow(0);//行
        XSSFCell cell  = null;

        // 创建单元格样式
        XSSFCellStyle style = wb.createCellStyle();
        XSSFFont font = wb.createFont();
        font.setBold(true); // 设置字体加粗
        style.setFont(font);

        //逐个设置标题样式
        for (int i = 0; i < headers.length; i++) {
            cell = row.createCell(i);
            cell.setCellValue(headers[i]);
            cell.setCellStyle(style);

        }
        int n = 1;
        for (SfpAssetManagement item : list) {
            //循环写入值
            XSSFRow rowN = sheet.createRow(n);//行
            for (int i = 0; i < headers.length; i++) {
                cell = rowN.createCell(i);
                cell.setCellValue(switchValue(i,item));
            }
            n++;
        }
        sheet.setColumnWidth(1, 4000);
        sheet.setColumnWidth(2, 4000);
        sheet.setColumnWidth(3, 9000);
        sheet.setColumnWidth(4, 4000);
        sheet.setColumnWidth(5, 4000);
        sheet.setColumnWidth(6, 4000);
        String fileName = isChinese ? AssetConst.zh_sfp_file_name :AssetConst.en_sfp_file_name;
        String sysPath =  System.getProperty("eam.conf")+File.separator+"excel";
        String excelPath =sysPath+File.separator+fileName;
        File dir = new File(sysPath);
        if(!dir.exists()  && !dir.isDirectory()){
            dir.mkdir();
        }

        //生成文件并返回前端
        try{
            FileOutputStream fileOut = new FileOutputStream(excelPath);
            wb.write(fileOut);
            fileOut.flush();
            fileOut.close();
            File file = new File(excelPath);
            InputStream ins = new FileInputStream(file);
            BufferedInputStream bins = new BufferedInputStream(ins);// 放到缓冲流里面
            OutputStream outs = response.getOutputStream();// 获取文件输出IO流
            BufferedOutputStream bouts = new BufferedOutputStream(outs);
            response.setContentType("application/x-download");// 设置response内容的类型
            response.setHeader(
                    "Content-disposition",
                    "attachment;filename="
                            + URLEncoder.encode(System.currentTimeMillis()/1000+"_"+fileName, "UTF-8"));// 设置头部信息
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            //开始向网络传输文件流
            while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
                bouts.write(buffer, 0, bytesRead);
            }
            bouts.flush();// 这里一定要调用flush()方法
            ins.close();
            bins.close();
            outs.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    private String switchValue(int order ,SfpAssetManagement sfpAssetManagement){
        String value=null;
        switch(order){
            case 0:
                value = sfpAssetManagement.getNodeId().toString();
                break;
            case 1:
                if (!org.springframework.util.StringUtils.isEmpty(sfpAssetManagement.getNodeName())) {
                    value = sfpAssetManagement.getNodeName();
                }
                break;
            case 2:
                if (!org.springframework.util.StringUtils.isEmpty(sfpAssetManagement.getAssetType())) {
                    value = sfpAssetManagement.getAssetType();
                }
                break;
            case 3:
                if (!org.springframework.util.StringUtils.isEmpty(sfpAssetManagement.getLocaltion())) {
                    value = sfpAssetManagement.getLocaltion();
                }
                break;
            case 4:
                if (!org.springframework.util.StringUtils.isEmpty(sfpAssetManagement.getSn())) {
                    value = sfpAssetManagement.getSn();
                }
                break;
            case 5:
                if (!org.springframework.util.StringUtils.isEmpty(sfpAssetManagement.getVid())) {
                    value = sfpAssetManagement.getVid();
                }
                break;
            case 6:
                if (!org.springframework.util.StringUtils.isEmpty(sfpAssetManagement.getVersion())) {
                    value = sfpAssetManagement.getVersion();
                }
                break;
            default:
                value ="";
                break;

        }
        return value;
    }

    /**
     * MML查询基带板的光模块SFP信息
     * MML结果长这样:data=[{"MessageContent":"SFP0 p_sfp_detect is:0x0\r\nSFP0 p_sfp_rx_los is:0x0\r\nSFP0 p_sfp_tx_fault_stat is:0x0\r\nSFP0 vendor is:Hisense\r\nSFP0 SN Number is:H8478J00216\r\n"}], neid=null]
     * MML结果长这样:data=[{"MessageContent":"SFP0 p_sfp_detect is:0x0\r\nSFP0 p_sfp_rx_los is:0x0\r\nSFP0 p_sfp_tx_fault_stat is:0x0\r\nNo device!!!\r\n"}], neid=null]
     */
    public void queryBasebandControlBoardSfpInfo(Equipment equipment, List<SfpAssetManagement> assetList) {
        logger.info("-queryBasebandControlBoardSfpInfo-equipment:{},assetList:{}", equipment, assetList);
        String shNum = "";
        String chNum = "";
        String slNum = "";
        String location = "";
        String key = "";
        String value = "";
        String cmdCell = "QRY BPB ;";
        Map<Integer, MMLResponse> stringMMLResponseMapCmdCell = sendMMLCmd(cmdCell, equipment.getId());
        logger.info("-queryBasebandControlBoardSfpInfo-mml command={},neId={},result={}", cmdCell, equipment.getId(),stringMMLResponseMapCmdCell.toString());
        MMLResponse responseserCell = stringMMLResponseMapCmdCell.get(equipment.getId());
        List<JSONObject> datasCell = responseserCell.getData();
        if(datasCell != null && !datasCell.isEmpty()){
            for (JSONObject jsonObject : datasCell) {
                chNum = jsonObject.getString("ChNum");
                shNum = jsonObject.getString("ShNum");
                slNum = jsonObject.getString("SlNum");
                logger.info("-queryBasebandControlBoardSfpInfo-slotNo={}", slNum);
                for (int i = 1; i < 4; i++) {
                    SfpAssetManagement sfpAssetManagement = null;
                    String basebandControlBoardCmd1 = "DSP BPBSFPInfo: slotNo=\"" + slNum + "\",fiberNo=\"" + i + "\";";
                    Map<Integer, MMLResponse> basebandControlBoardCmd1Map = sendMMLCmd(basebandControlBoardCmd1, equipment.getId());
                    logger.info("-queryBasebandControlBoardSfpInfo-mml command={},neId={},result={}", basebandControlBoardCmd1, equipment.getId(), basebandControlBoardCmd1Map.toString());
                    MMLResponse basebandControlBoardCmd1Response = basebandControlBoardCmd1Map.get(equipment.getId());
                    List<JSONObject> basebandControlBoardCmd1Datas = basebandControlBoardCmd1Response.getData();
                    if(basebandControlBoardCmd1Datas == null || basebandControlBoardCmd1Datas.isEmpty()) {
                        basebandControlBoardCmd1 = "DSP SFPInfo: slotNo=\"" + slNum + "\",fiberNo=\"" + i + "\";";
                        basebandControlBoardCmd1Map = sendMMLCmd(basebandControlBoardCmd1, equipment.getId());
                        basebandControlBoardCmd1Response = basebandControlBoardCmd1Map.get(equipment.getId());
                        basebandControlBoardCmd1Datas = basebandControlBoardCmd1Response.getData();
                    }

                    if(basebandControlBoardCmd1Datas != null && !basebandControlBoardCmd1Datas.isEmpty()){
                        for (JSONObject json : basebandControlBoardCmd1Datas) {
                            if (json.containsKey("MessageContent") && json.getString("MessageContent") != null) {
                                String messageContent = json.getString("MessageContent");
                                if (!messageContent.contains("No device") && !messageContent.contains("is disable,pls check board")) {
                                    Pattern pattern = Pattern.compile("SFP(\\d+)\\s+(.+?)\\s+is:(.+?)\\r\\n");
                                    Matcher matcher = pattern.matcher(messageContent);
                                    String currentSfpIndex = null;
                                    while (matcher.find()) {
                                        String sfpIndex = matcher.group(1);
                                        if (sfpIndex != null) {
                                            if (!sfpIndex.equals(currentSfpIndex)) {
                                                if (sfpAssetManagement != null) {
                                                    sfpAssetManagement.setNodeId(equipment.getId());
                                                    sfpAssetManagement.setNodeName(equipment.getName());
                                                    sfpAssetManagement.setAssetType("SFP");
                                                    sfpAssetManagement.setLocaltion(location);
                                                    assetList.add(sfpAssetManagement);
                                                }
                                                sfpAssetManagement = new SfpAssetManagement();
                                            }
                                            key = matcher.group(2);
                                            value = matcher.group(3);
                                            location = "cabinet=" + shNum + ",frame=" + chNum + ",slot=" + slNum + ",sfp=" + sfpIndex;
                                            if (org.springframework.util.StringUtils.isEmpty(value)) {
                                                continue;
                                            }
                                            if (CustomStringUtils.containsInvalidCharacters(value)) {
                                                continue;
                                            }
                                            switch (key) {
                                                case "SN Number":
                                                    sfpAssetManagement.setSn(value);
                                                    break;
                                                case "vendor":
                                                    sfpAssetManagement.setVid(value);
                                                    break;
                                                default:
                                                    logger.error("-queryMainControlBoardSfpInfo no match key:{}", key);
                                                    break;
                                            }
                                            currentSfpIndex = sfpIndex;
                                        }

                                    }
                                    sfpAssetManagement.setNodeId(equipment.getId());
                                    sfpAssetManagement.setNodeName(equipment.getName());
                                    sfpAssetManagement.setAssetType("SFP");
                                    sfpAssetManagement.setLocaltion(location);
                                    assetList.add(sfpAssetManagement);
                                }
                            }
                        }
                    }
                }
            }
        }else{
            logger.info("-queryBasebandControlBoardSfpInfo mml command={},neId={},没有data数据", cmdCell, equipment);
        }
        logger.info("-queryBasebandControlBoardSfpInfo-end!-assetList:{}", assetList);
    }

    /**
     * MML查询主控板的光模块SFP信息
     * MML结果长这样:data=[{"MessageContent":"[SFP-0] State: 1\n[SFP-0] SN: S9173888841\n[SFP-0] VID: Hisense\n[SFP-0] Version: V1.0nse\n[SFP-0] Type: LTD1302-BH+\n"}], neid=null]
     */
    public void queryMainControlBoardSfpInfo(Equipment equipment, List<SfpAssetManagement> assetList) {
        logger.info("-queryMainControlBoardSfpInfo-equipment:{},assetList:{}", equipment, assetList);
        String shNum = "";
        String chNum = "";
        String slNum = "";
        String location = "";
        String key = "";
        String value = "";
        Pattern pattern = null;
        Matcher matcher = null;
        String mcbCmd = "DSP HwInfo:HwType = MCB";
        Map<Integer, MMLResponse> qryMcbMMLResponseMap = sendMMLCmd(mcbCmd, equipment.getId());
        logger.info("-qryMcbMMLResponseMap-mml command={},neId={},result={}", mcbCmd, equipment.getId(),qryMcbMMLResponseMap.toString());
        MMLResponse qryMcbMMLResponse = qryMcbMMLResponseMap.get(equipment.getId());
        List<JSONObject> qryMcbDatas = qryMcbMMLResponse.getData();
        logger.info("qryMcbDatas:{}", qryMcbDatas);
        if(qryMcbDatas != null && !qryMcbDatas.isEmpty()) {
            for (JSONObject jsonObject : qryMcbDatas) {
                SfpAssetManagement sfpAssetManagement = null;
                if (jsonObject.containsKey("MessageContent") && jsonObject.getString("MessageContent") != null) {
                    String mcbMessageContent = jsonObject.getString("MessageContent");
                    if (mcbMessageContent.contains("[") && mcbMessageContent.contains("]")) {
                        pattern = Pattern.compile("\\[(\\d)+-(\\d)+-(\\d)+\\]\\s*(.+?): \\s*(.+)\\s*(?:\\n|$)");
                        matcher = pattern.matcher(mcbMessageContent);
                        while (matcher.find()) {
                            slNum = matcher.group(3);
                            if (slNum != null) {
                                shNum = matcher.group(1);
                                chNum = matcher.group(2);
                            }
                        }
                        String cmdCell = "DSP HwInfo:HwType = MCBSFP" ;
                        Map<Integer, MMLResponse> stringMMLResponseMapCmdCell = sendMMLCmd(cmdCell, equipment.getId());
                        logger.info("-stringMMLResponseMapCmdCell-mml command={},neId={},result={}", cmdCell, equipment.getId(),stringMMLResponseMapCmdCell.toString());
                        MMLResponse responseserCell = stringMMLResponseMapCmdCell.get(equipment.getId());
                        List<JSONObject> datasCell = responseserCell.getData();
                        if (datasCell == null || datasCell.isEmpty()) {
                            cmdCell = "DSP HwInfo:HwType = SFP" ;
                            stringMMLResponseMapCmdCell = sendMMLCmd(cmdCell, equipment.getId());
                            responseserCell = stringMMLResponseMapCmdCell.get(equipment.getId());
                            datasCell = responseserCell.getData();
                        }

                        if(datasCell != null && !datasCell.isEmpty()){
                            for (JSONObject json : datasCell) {
                                if (json.containsKey("MessageContent") && json.getString("MessageContent") != null) {
                                    String messageContent = json.getString("MessageContent");
                                    if (messageContent.contains("[") && messageContent.contains("]")) {
                                        pattern = Pattern.compile("\\[SFP-(\\d+)]\\s*(.+?): \\s*(.+)\\s*\\n");
                                        matcher = pattern.matcher(messageContent);
                                        String currentSfpIndex = null;
                                        while (matcher.find()) {
                                            String sfpIndex = matcher.group(1);
                                            if (sfpIndex != null) {
                                                if (!sfpIndex.equals(currentSfpIndex)) {
                                                    if (sfpAssetManagement != null) {
                                                        sfpAssetManagement.setNodeId(equipment.getId());
                                                        sfpAssetManagement.setNodeName(equipment.getName());
                                                        sfpAssetManagement.setAssetType("SFP");
                                                        sfpAssetManagement.setLocaltion(location);
                                                        assetList.add(sfpAssetManagement);
                                                    }
                                                    sfpAssetManagement = new SfpAssetManagement();
                                                }
                                                key = matcher.group(2);
                                                value = matcher.group(3);
                                                location = "cabinet=" + shNum + ",frame=" + chNum + ",slot=" + slNum + ",sfp=" + sfpIndex;
                                                if (org.springframework.util.StringUtils.isEmpty(value)) {
                                                    continue;
                                                }
                                                if (CustomStringUtils.containsInvalidCharacters(value)) {
                                                    continue;
                                                }
                                                switch (key) {
                                                    case "SN":
                                                        sfpAssetManagement.setSn(value);
                                                        break;
                                                    case "VID":
                                                        sfpAssetManagement.setVid(value);
                                                        break;
                                                    default:
                                                        logger.error("-queryMainControlBoardSfpInfo no match key:{}", key);
                                                        break;
                                                }
                                                currentSfpIndex = sfpIndex;
                                            }
                                        }
                                        sfpAssetManagement.setNodeId(equipment.getId());
                                        sfpAssetManagement.setNodeName(equipment.getName());
                                        sfpAssetManagement.setAssetType("SFP");
                                        sfpAssetManagement.setLocaltion(location);
                                        assetList.add(sfpAssetManagement);
                                    }
                                }
                            }
                        }else{
                            logger.info("-queryMainControlBoardSfpInfo mml command={},neId={},没有data数据", cmdCell, equipment);
                        }
                    }
                }
            }
        }
        logger.info("-queryMainControlBoardSfpInfo-end!-assetList:{}", assetList);
    }

    /**
     * MML查询RRU的光模块RRUSFP信息
     * MML结果长这样:String messageContent = "[RRU-61] Unsupport get SFP hw info!";
     * MML结果长这样:String messageContent = "[RRU-61][SFP-1] Present State: Present\n[RRU-61][SFP-1] SN: H8477J00489     \n[RRU-61][SFP-1] VID: Hisense         \n";
     * MML结果长这样:String messageContent = "[RRU-61][SFP-0] Present State: Present\n[RRU-61][SFP-0] SN: H8477J00480     \n[RRU-61][SFP-0] VID: Hisense0         \n[RRU-61][SFP-1] Present State: Present\n[RRU-61][SFP-1] SN: H8477J00489     \n[RRU-61][SFP-1] VID: Hisense         \n";
     */
    public void queryRruSfpInfoOfRru(Equipment equipment, List<SfpAssetManagement> assetList) {
        logger.info("-queryRruSfpInfoOfRru-equipment:{},assetList:{}", equipment, assetList);
        String shNum = "";
        String chNum = "";
        String slNum = "";
        String location = "";
        String key = "";
        String value = "";
        String mcbCmd = "QRY RRU;";
        Map<Integer, MMLResponse> qryRruMMLResponseMap = sendMMLCmd(mcbCmd, equipment.getId());
        logger.info("-queryBasebandControlBoardSfpInfo-mml command={},neId={},result={}", mcbCmd, equipment.getId(),qryRruMMLResponseMap.toString());
        MMLResponse qryRruMMLResponse = qryRruMMLResponseMap.get(equipment.getId());
        List<JSONObject> qrRruDatas = qryRruMMLResponse.getData();

        String cmdCell = "DSP HwInfo: HwType=\"RRUSFP\"";
        Map<Integer, MMLResponse> stringMMLResponseMapCmdCell = sendMMLCmd(cmdCell, equipment.getId());
        logger.info("-queryRruSfpInfoOfRru-mml command={},neId={},result={}", cmdCell, equipment.getId(),stringMMLResponseMapCmdCell.toString());
        MMLResponse responseserCell = stringMMLResponseMapCmdCell.get(equipment.getId());
        List<JSONObject> datasCell = responseserCell.getData();
        if(qrRruDatas != null && !qrRruDatas.isEmpty()) {
            for (JSONObject jsonObject : qrRruDatas) {
                SfpAssetManagement sfpAssetManagement = new SfpAssetManagement();
                chNum = jsonObject.getString("chNum");
                shNum = jsonObject.getString("shNum");
                slNum = jsonObject.getString("slNum");

                if(datasCell != null && !datasCell.isEmpty()){
                    for (JSONObject json : datasCell) {
                        if (json.containsKey("MessageContent") && json.getString("MessageContent") != null) {
                            String messageContent = json.getString("MessageContent");
                            if (!messageContent.contains("Unsupport get SFP hw info") && !messageContent.contains("Error, none RRU info")) {
                                Pattern pattern = Pattern.compile("\\[RRU-(\\d+)\\]\\[SFP-(\\d+)\\]\\s*(.+?):\\s*(.*?)\\s*(?=$|\\[RRU-\\d+\\])");
                                Matcher matcher = pattern.matcher(messageContent);
                                boolean containRruSfp = false;
                                while (matcher.find()) {
                                    String rruChNum = matcher.group(1);
                                    String sfpIndex = matcher.group(2);
                                    if (sfpIndex != null && rruChNum.equals(chNum)) {
                                        containRruSfp = true;
                                        key = matcher.group(3);
                                        value = matcher.group(4);
                                        location = "cabinet=" + shNum + ",frame=" + chNum + ",slot=" + slNum + ",sfp=" + sfpIndex;
                                        if (org.springframework.util.StringUtils.isEmpty(value)) {
                                            continue;
                                        }
                                        if (CustomStringUtils.containsInvalidCharacters(value)) {
                                            continue;
                                        }
                                        switch (key) {
                                            case "SN":
                                                sfpAssetManagement.setSn(value);
                                                break;
                                            case "VID":
                                                sfpAssetManagement.setVid(value);
                                                break;
                                            default:
                                                logger.error("-queryRruSfpInfoOfRru no match key:{}", key);
                                                break;
                                        }
                                    }
                                }
                                if (containRruSfp) {
                                    sfpAssetManagement.setNodeId(equipment.getId());
                                    sfpAssetManagement.setNodeName(equipment.getName());
                                    sfpAssetManagement.setAssetType("SFP");
                                    sfpAssetManagement.setLocaltion(location);
                                    assetList.add(sfpAssetManagement);
                                }
                            }
                        }
                    }
                }else{
                    logger.info("-queryRruSfpInfoOfRru mml command={},neId={},没有data数据", cmdCell, equipment);
                }
            }
        }
        logger.info("-queryRruSfpInfoOfRru-end!-assetList:{}", assetList);
    }

    /**
     * 资产数量统计
     */
    @ResponseBody
    @RequestMapping(value = "assetQuantityStatistics", method = RequestMethod.GET)
    public Map<String, Integer> assetQuantityStatistics(){
        int hwinfoAssetCount = hwinfoAssetManagementService.hwinfoAssetQuantityStatistic();
        int sfpAssetCount = sfpAssetManagementService.sfpAssetQuantityStatistic();
        Map<String, Integer> map = new HashMap<>();
        map.put("hwinfoAssetCount", hwinfoAssetCount);
        map.put("sfpAssetCount", sfpAssetCount);
        return map;
    }

    /**
     * 硬件资产类型统计
     */
    @ResponseBody
    @RequestMapping(value = "hwinfoAssetTypeStatistic", method = RequestMethod.GET)
    public List<Map<String, Object>> hwinfoAssetTypeStatistic(){
        return hwinfoAssetManagementService.hwinfoAssetTypeStatistic();
    }

    /**
     * 光模块资产类型统计
     */
    @ResponseBody
    @RequestMapping(value = "sfpAssetTypeStatistic", method = RequestMethod.GET)
    public List<Map<String, Object>> sfpAssetTypeStatistic(){
        return sfpAssetManagementService.sfpAssetTypeStatistic();
    }
}

HwinfoAssetManagement

java 复制代码
package com.hero.lte.ems.monitor.entity;

/**
 * 硬件资产管理
 */
public class HwinfoAssetManagement {

    private Integer id;
    //网元id
    private Integer nodeId;
    //起始网元id号
    private Integer nodeIdBegin;
    //结束网元id号
    private Integer nodeIdEnd;
    //网元名称
    private String nodeName;
    //资产类型
    private String assetType;
    //资产位置
    private String localtion;
    //SN硬件编码
    private String sn;
    //VID厂商编码
    private String vid;
    //单板版本号
    private String version;
    //模糊搜索
    private String keyword;

    private String presentState;

    public String getPresentState() {
        return presentState;
    }

    public void setPresentState(String presentState) {
        this.presentState = presentState;
    }

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    public Integer getNodeIdBegin() {
        return nodeIdBegin;
    }

    public void setNodeIdBegin(Integer nodeIdBegin) {
        this.nodeIdBegin = nodeIdBegin;
    }

    public Integer getNodeIdEnd() {
        return nodeIdEnd;
    }

    public void setNodeIdEnd(Integer nodeIdEnd) {
        this.nodeIdEnd = nodeIdEnd;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getNodeId() {
        return nodeId;
    }

    public void setNodeId(Integer nodeId) {
        this.nodeId = nodeId;
    }

    public String getNodeName() {
        return nodeName;
    }

    public void setNodeName(String nodeName) {
        this.nodeName = nodeName;
    }

    public String getAssetType() {
        return assetType;
    }

    public void setAssetType(String assetType) {
        this.assetType = assetType;
    }

    public String getLocaltion() {
        return localtion;
    }

    public void setLocaltion(String localtion) {
        this.localtion = localtion;
    }

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public String getVid() {
        return vid;
    }

    public void setVid(String vid) {
        this.vid = vid;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    @Override
    public String toString() {
        return "HwinfoAssetManagement{" +
                "id=" + id +
                ", nodeId=" + nodeId +
                ", nodeIdBegin=" + nodeIdBegin +
                ", nodeIdEnd=" + nodeIdEnd +
                ", nodeName='" + nodeName + '\'' +
                ", assetType='" + assetType + '\'' +
                ", localtion='" + localtion + '\'' +
                ", sn='" + sn + '\'' +
                ", vid='" + vid + '\'' +
                ", version='" + version + '\'' +
                ", keyword='" + keyword + '\'' +
                '}';
    }
}

HwinfoAssetManagementService

java 复制代码
package com.hero.lte.ems.monitor.service;

import com.hero.lte.ems.db.orm.mybatis.Page;
import com.hero.lte.ems.monitor.entity.HwinfoAssetManagement;

import java.util.List;
import java.util.Map;

public interface HwinfoAssetManagementService {

    Page<HwinfoAssetManagement> queryHwinfoAssetManagementList(Page<HwinfoAssetManagement> pager);
    List<HwinfoAssetManagement> queryHwinfoAssetManagementList(HwinfoAssetManagement hwinfoAssetManagement);

    int batchInsertHwinfoAssetManagement(List<HwinfoAssetManagement> list);

    int truncateHwinfoAssetManagement();

    int hwinfoAssetQuantityStatistic();

    List<Map<String,Object>> hwinfoAssetTypeStatistic();
}

HwinfoAssetManagementServiceImpl

java 复制代码
package com.hero.lte.ems.monitor.service.impl;

import com.hero.lte.ems.db.orm.mybatis.Page;
import com.hero.lte.ems.monitor.dao.HwinfoAssetManagementMapper;
import com.hero.lte.ems.monitor.entity.HwinfoAssetManagement;
import com.hero.lte.ems.monitor.service.HwinfoAssetManagementService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * @author l22898
 */
@Service
public class HwinfoAssetManagementServiceImpl implements HwinfoAssetManagementService {

    private static final Logger logger = LoggerFactory.getLogger(HwinfoAssetManagementServiceImpl.class);

    @Resource
    private HwinfoAssetManagementMapper hwinfoAssetManagementMapper;


    @Override
    public Page<HwinfoAssetManagement> queryHwinfoAssetManagementList(Page<HwinfoAssetManagement> pager) {
        HwinfoAssetManagement param = pager.getParam();
        if (!StringUtils.isEmpty(param) && isNumberDashNumber(param.getKeyword())) {
            if (param.getKeyword().contains("-")) {
                String[] split = param.getKeyword().split("-");
                param.setNodeIdBegin(Integer.valueOf(split[0]));
                param.setNodeIdEnd(Integer.valueOf(split[1]));
            }
        }
        hwinfoAssetManagementMapper.queryHwinfoAssetManagementList(pager, param);
        return pager;
    }

    @Override
    public List<HwinfoAssetManagement> queryHwinfoAssetManagementList(HwinfoAssetManagement hwinfoAssetManagement) {
        if (hwinfoAssetManagement.getKeyword().contains("-") && isNumberDashNumber(hwinfoAssetManagement.getKeyword())) {
            String[] split = hwinfoAssetManagement.getKeyword().split("-");
            hwinfoAssetManagement.setNodeIdBegin(Integer.valueOf(split[0]));
            hwinfoAssetManagement.setNodeIdEnd(Integer.valueOf(split[1]));
        }
        return hwinfoAssetManagementMapper.queryHwinfoAssetManagementList(hwinfoAssetManagement);
    }

    public static boolean isNumberDashNumber(String str) {
        // 正则表达式判断格式是否为 "数字-数字"
        String regex = "^\\d+-\\d+$";
        return Pattern.matches(regex, str);
    }

    public static boolean isInteger(String str) {
        try {
            Integer.parseInt(str);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    @Override
    public int batchInsertHwinfoAssetManagement(List<HwinfoAssetManagement> list) {
        return hwinfoAssetManagementMapper.batchInsertHwinfoAssetManagement(list);
    }

    @Override
    public int truncateHwinfoAssetManagement() {
        return hwinfoAssetManagementMapper.truncateHwinfoAssetManagement();
    }

    @Override
    public int hwinfoAssetQuantityStatistic() {
        return hwinfoAssetManagementMapper.hwinfoAssetQuantityStatistic();
    }

    @Override
    public List<Map<String, Object>> hwinfoAssetTypeStatistic() {
        return hwinfoAssetManagementMapper.hwinfoAssetTypeStatistic();
    }
}

HwinfoAssetManagementMapper

java 复制代码
package com.hero.lte.ems.monitor.dao;

import com.hero.lte.ems.db.orm.mybatis.Page;
import com.hero.lte.ems.monitor.entity.HwinfoAssetManagement;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

public interface HwinfoAssetManagementMapper {

    List<HwinfoAssetManagement> queryHwinfoAssetManagementList(@Param("page") Page pager, @Param("hwinfoAssetManagement") HwinfoAssetManagement hwinfoAssetManagement);
    List<HwinfoAssetManagement> queryHwinfoAssetManagementList(@Param("hwinfoAssetManagement") HwinfoAssetManagement hwinfoAssetManagement);

    int batchInsertHwinfoAssetManagement(@Param("list") List<HwinfoAssetManagement> list);

    int truncateHwinfoAssetManagement();
    int hwinfoAssetQuantityStatistic();
    List<Map<String,Object>> hwinfoAssetTypeStatistic();
}

HwinfoAssetManagementMapper.xml

java 复制代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hero.lte.ems.monitor.dao.HwinfoAssetManagementMapper">
    <resultMap id="BaseResultMap" type="com.hero.lte.ems.monitor.entity.HwinfoAssetManagement">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="node_id" property="nodeId" jdbcType="INTEGER"/>
        <result column="node_name" property="nodeName" jdbcType="VARCHAR"/>
        <result column="asset_type" property="assetType" jdbcType="VARCHAR"/>
        <result column="localtion" property="localtion" jdbcType="VARCHAR"/>
        <result column="sn" property="sn" jdbcType="VARCHAR"/>
        <result column="vid" property="vid" jdbcType="VARCHAR"/>
        <result column="version" property="version" jdbcType="VARCHAR"/>
        <result column="present_state" property="presentState" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,node_id,node_name,asset_type,localtion,sn,vid,version,present_state
    </sql>


    <select id="queryHwinfoAssetManagementList" resultMap="BaseResultMap">
        <choose>
            <when test="hwinfoAssetManagement.nodeIdBegin != null and hwinfoAssetManagement.nodeIdBegin !=0 and hwinfoAssetManagement.nodeIdEnd != null and hwinfoAssetManagement.nodeIdEnd !=0">
                select
                <include refid="Base_Column_List"/>
                from hwinfo_asset_management
                where node_id between #{hwinfoAssetManagement.nodeIdBegin} and #{hwinfoAssetManagement.nodeIdEnd} or node_name like CONCAT('%',#{hwinfoAssetManagement.keyword},'%')
                order by node_id asc
            </when>
            <otherwise>
                select
                <include refid="Base_Column_List"/>
                from hwinfo_asset_management
                <if test="hwinfoAssetManagement.keyword != null and hwinfoAssetManagement.keyword !=''" >
                    where asset_type like CONCAT('%',#{hwinfoAssetManagement.keyword},'%') or node_name like CONCAT('%',#{hwinfoAssetManagement.keyword},'%') or node_id like CONCAT('%',#{hwinfoAssetManagement.keyword},'%')
                </if>
                order by node_id asc
            </otherwise>
        </choose>
    </select>

    <insert id="batchInsertHwinfoAssetManagement">
        insert into hwinfo_asset_management ( node_id,node_name,asset_type,localtion,sn,vid,version,present_state ) values
        <foreach collection='list' item='item' index='index ' separator=', '>
            (#{item.nodeId}, #{item.nodeName}, #{item.assetType}, #{item.localtion}, #{item.sn}, #{item.vid}, #{item.version}, #{item.presentState} )
        </foreach>
    </insert>


    <delete id="truncateHwinfoAssetManagement">
        TRUNCATE TABLE hwinfo_asset_management
    </delete>

    <select id="hwinfoAssetQuantityStatistic" resultType="integer">
        SELECT COUNT(0) FROM  hwinfo_asset_management;
    </select>

    <select id="hwinfoAssetTypeStatistic" resultType="map">
        SELECT asset_type as assetType,COUNT(asset_type) as count FROM  hwinfo_asset_management GROUP BY asset_type;
    </select>
</mapper>

SfpAssetManagement

java 复制代码
package com.hero.lte.ems.monitor.entity;

/**
 * 光模块资产管理
 */
public class SfpAssetManagement {

    private Integer id;
    //网元id
    private Integer nodeId;
    //起始网元id号
    private Integer nodeIdBegin;
    //结束网元id号
    private Integer nodeIdEnd;
    //网元名称
    private String nodeName;
    //资产类型
    private String assetType;
    //资产位置
    private String localtion;
    //SN硬件编码
    private String sn;
    //VID厂商编码
    private String vid;
    //单板版本号
    private String version;
    //模糊搜索
    private String keyword;

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    public Integer getNodeIdBegin() {
        return nodeIdBegin;
    }

    public void setNodeIdBegin(Integer nodeIdBegin) {
        this.nodeIdBegin = nodeIdBegin;
    }

    public Integer getNodeIdEnd() {
        return nodeIdEnd;
    }

    public void setNodeIdEnd(Integer nodeIdEnd) {
        this.nodeIdEnd = nodeIdEnd;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getNodeId() {
        return nodeId;
    }

    public void setNodeId(Integer nodeId) {
        this.nodeId = nodeId;
    }

    public String getNodeName() {
        return nodeName;
    }

    public void setNodeName(String nodeName) {
        this.nodeName = nodeName;
    }

    public String getAssetType() {
        return assetType;
    }

    public void setAssetType(String assetType) {
        this.assetType = assetType;
    }

    public String getLocaltion() {
        return localtion;
    }

    public void setLocaltion(String localtion) {
        this.localtion = localtion;
    }

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public String getVid() {
        return vid;
    }

    public void setVid(String vid) {
        this.vid = vid;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    @Override
    public String toString() {
        return "SfpAssetManagement{" +
                "id=" + id +
                ", nodeId=" + nodeId +
                ", nodeIdBegin=" + nodeIdBegin +
                ", nodeIdEnd=" + nodeIdEnd +
                ", nodeName='" + nodeName + '\'' +
                ", assetType='" + assetType + '\'' +
                ", localtion='" + localtion + '\'' +
                ", sn='" + sn + '\'' +
                ", vid='" + vid + '\'' +
                ", version='" + version + '\'' +
                ", keyword='" + keyword + '\'' +
                '}';
    }
}

SfpAssetManagementService

java 复制代码
package com.hero.lte.ems.monitor.service;

import com.hero.lte.ems.db.orm.mybatis.Page;
import com.hero.lte.ems.monitor.entity.SfpAssetManagement;

import java.util.List;
import java.util.Map;

public interface SfpAssetManagementService {

    Page<SfpAssetManagement> querySfpAssetManagementList(Page<SfpAssetManagement> pager);
    List<SfpAssetManagement> querySfpAssetManagementList(SfpAssetManagement sfpAssetManagement);

    int batchInsertSfpAssetManagement(List<SfpAssetManagement> list);

    int truncateSfpAssetManagement();

    int sfpAssetQuantityStatistic();

    List<Map<String,Object>> sfpAssetTypeStatistic();
}

SfpAssetManagementServiceImpl

java 复制代码
package com.hero.lte.ems.monitor.service.impl;

import com.hero.lte.ems.db.orm.mybatis.Page;
import com.hero.lte.ems.monitor.dao.SfpAssetManagementMapper;
import com.hero.lte.ems.monitor.entity.SfpAssetManagement;
import com.hero.lte.ems.monitor.service.SfpAssetManagementService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * @author l22898
 */
@Service
public class SfpAssetManagementServiceImpl implements SfpAssetManagementService {

    private static final Logger logger = LoggerFactory.getLogger(SfpAssetManagementServiceImpl.class);

    @Resource
    private SfpAssetManagementMapper sfpAssetManagementMapper;


    @Override
    public Page<SfpAssetManagement> querySfpAssetManagementList(Page<SfpAssetManagement> pager) {
        SfpAssetManagement param = pager.getParam();
        if (!StringUtils.isEmpty(param) && isNumberDashNumber(param.getKeyword())) {
            if (param.getKeyword().contains("-")) {
                String[] split = param.getKeyword().split("-");
                param.setNodeIdBegin(Integer.valueOf(split[0]));
                param.setNodeIdEnd(Integer.valueOf(split[1]));
            }
        }
        sfpAssetManagementMapper.querySfpAssetManagementList(pager, param);
        return pager;
    }

    @Override
    public List<SfpAssetManagement> querySfpAssetManagementList(SfpAssetManagement sfpAssetManagement) {
        if (sfpAssetManagement.getKeyword().contains("-") && isNumberDashNumber(sfpAssetManagement.getKeyword())) {
            String[] split = sfpAssetManagement.getKeyword().split("-");
            sfpAssetManagement.setNodeIdBegin(Integer.valueOf(split[0]));
            sfpAssetManagement.setNodeIdEnd(Integer.valueOf(split[1]));
        }
        return sfpAssetManagementMapper.querySfpAssetManagementList(sfpAssetManagement);
    }

    public static boolean isNumberDashNumber(String str) {
        // 正则表达式判断格式是否为 "数字-数字"
        String regex = "^\\d+-\\d+$";
        return Pattern.matches(regex, str);
    }

    public static boolean isInteger(String str) {
        try {
            Integer.parseInt(str);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    @Override
    public int batchInsertSfpAssetManagement(List<SfpAssetManagement> list) {
        return sfpAssetManagementMapper.batchInsertSfpAssetManagement(list);
    }

    @Override
    public int truncateSfpAssetManagement() {
        return sfpAssetManagementMapper.truncateSfpAssetManagement();
    }

    @Override
    public int sfpAssetQuantityStatistic() {
        return sfpAssetManagementMapper.sfpAssetQuantityStatistic();
    }

    @Override
    public List<Map<String,Object>> sfpAssetTypeStatistic() {
        return sfpAssetManagementMapper.sfpAssetTypeStatistic();
    }
}

SfpAssetManagementMapper

java 复制代码
package com.hero.lte.ems.monitor.dao;

import com.hero.lte.ems.db.orm.mybatis.Page;
import com.hero.lte.ems.monitor.entity.SfpAssetManagement;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

public interface SfpAssetManagementMapper {

    List<SfpAssetManagement> querySfpAssetManagementList(@Param("page") Page pager, @Param("sfpAssetManagement") SfpAssetManagement sfpAssetManagement);
    List<SfpAssetManagement> querySfpAssetManagementList(@Param("sfpAssetManagement") SfpAssetManagement sfpAssetManagement);

    int batchInsertSfpAssetManagement(@Param("list") List<SfpAssetManagement> list);

    int truncateSfpAssetManagement();
    int sfpAssetQuantityStatistic();
    List<Map<String,Object>> sfpAssetTypeStatistic();
}

SfpAssetManagementMapper.xml

java 复制代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hero.lte.ems.monitor.dao.SfpAssetManagementMapper">
    <resultMap id="BaseResultMap" type="com.hero.lte.ems.monitor.entity.SfpAssetManagement">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="node_id" property="nodeId" jdbcType="INTEGER"/>
        <result column="node_name" property="nodeName" jdbcType="VARCHAR"/>
        <result column="asset_type" property="assetType" jdbcType="VARCHAR"/>
        <result column="localtion" property="localtion" jdbcType="VARCHAR"/>
        <result column="sn" property="sn" jdbcType="VARCHAR"/>
        <result column="vid" property="vid" jdbcType="VARCHAR"/>
        <result column="version" property="version" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,node_id,node_name,asset_type,localtion,sn,vid,version
    </sql>


    <select id="querySfpAssetManagementList" resultMap="BaseResultMap">
        <choose>
            <when test="sfpAssetManagement.nodeIdBegin != null and sfpAssetManagement.nodeIdBegin !=0 and sfpAssetManagement.nodeIdEnd != null and sfpAssetManagement.nodeIdEnd !=0">
                select
                <include refid="Base_Column_List"/>
                from sfp_asset_management
                where node_id between #{sfpAssetManagement.nodeIdBegin} and #{sfpAssetManagement.nodeIdEnd} or node_name like CONCAT('%',#{sfpAssetManagement.keyword},'%')
                order by node_id asc
            </when>
            <otherwise>
                select
                <include refid="Base_Column_List"/>
                from sfp_asset_management
                <if test="sfpAssetManagement.keyword != null and sfpAssetManagement.keyword !=''" >
                    where asset_type like CONCAT('%',#{sfpAssetManagement.keyword},'%') or node_name like CONCAT('%',#{sfpAssetManagement.keyword},'%') or node_id like CONCAT('%',#{sfpAssetManagement.keyword},'%')
                </if>
                order by node_id asc
            </otherwise>
        </choose>
    </select>

    <insert id="batchInsertSfpAssetManagement">
        insert into sfp_asset_management ( node_id,node_name,asset_type,localtion,sn,vid,version ) values
        <foreach collection='list' item='item' index='index ' separator=', '>
            (#{item.nodeId}, #{item.nodeName}, #{item.assetType}, #{item.localtion}, #{item.sn}, #{item.vid}, #{item.version} )
        </foreach>
    </insert>


    <delete id="truncateSfpAssetManagement">
        TRUNCATE TABLE sfp_asset_management
    </delete>

    <select id="sfpAssetQuantityStatistic" resultType="integer">
        SELECT COUNT(0) FROM  sfp_asset_management;
    </select>

    <select id="sfpAssetTypeStatistic" resultType="map">
        SELECT asset_type as assetType,COUNT(asset_type) as count FROM  sfp_asset_management GROUP BY asset_type;
    </select>
</mapper>

建表sql

java 复制代码
DROP TABLE IF EXISTS `hwinfo_asset_management`;
CREATE TABLE `hwinfo_asset_management`  (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `node_id` int(11) NULL DEFAULT NULL COMMENT '网元id',
    `node_name` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '网元名称',
    `asset_type` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '资产类型',
    `localtion` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '资产位置',
    `sn` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'SN硬件编码',
    `vid` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'VID厂商编码',
    `version` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '单板版本号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '硬件资产管理表' ROW_FORMAT = Compact;

DROP TABLE IF EXISTS `sfp_asset_management`;
CREATE TABLE `sfp_asset_management`  (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `node_id` int(11) NULL DEFAULT NULL COMMENT '网元id',
    `node_name` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '网元名称',
    `asset_type` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '资产类型',
    `localtion` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '资产位置',
    `sn` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'SN硬件编码',
    `vid` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'VID厂商编码',
    `version` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '单板版本号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '光模块资产管理表' ROW_FORMAT = Compact;
相关推荐
白总Server5 分钟前
Golang dig框架与GraphQL的完美结合
java·大数据·前端·javascript·后端·go·graphql
lightgis21 分钟前
个人支出智能分析系统
java
春生野草25 分钟前
MyBatis中关于缓存的理解
java·缓存·mybatis
oioihoii1 小时前
C++11 Generalized(non-trivial) Unions:从入门到精通
java·开发语言·c++
颯沓如流星1 小时前
装饰模式(Decorator Pattern)重构java邮件发奖系统实战
java·重构·装饰器模式
惜鸟1 小时前
springboot 项目的包结构设计(一)
java·spring boot
程序员岳焱1 小时前
Stream 流式编程在实际项目中的落地:从业务场景到代码优化
java·后端·程序员
l0sgAi1 小时前
EasyExcel读取多层嵌套表头数据
java·程序员
酷爱码1 小时前
Maven 配置中绕过 HTTP 阻断机制的完整解决方案
java·http·maven
快乐肚皮2 小时前
堆排序详解:从理论到实践
java·算法·排序算法·堆排序