diff --git a/src/main/java/com/bellmann/common/enums/RemoteOperateMsgEnum.java b/src/main/java/com/bellmann/common/enums/RemoteOperateMsgEnum.java index 968a3e1..c023f2b 100644 --- a/src/main/java/com/bellmann/common/enums/RemoteOperateMsgEnum.java +++ b/src/main/java/com/bellmann/common/enums/RemoteOperateMsgEnum.java @@ -46,7 +46,24 @@ public enum RemoteOperateMsgEnum implements IBaseEnum { IPV6_INFO_QUERY("Ipv6InfoQuery","Ipv6InfoQuery"), GET_LAND_HCP_INFO("GETLANDHCPINFO","GETLANDHCPINFO"), WBAND("wband","查询上网业务"), - BASIC_COMMON_QUERY("basicCommonQuery","basicCommonQuery") + BASIC_COMMON_QUERY("basicCommonQuery","basicCommonQuery"), + + PON112_NET_FAILED("1-1", "Pon112NetFailed"), + + PON112_NET_UNSTABLE("1-2", "Pon112NetUnstable"), + + PON112_NET_SLOW("1-3", "Pon112NetSlow"), + PON112_WIFI_FAILED("1-4", "Pon112WifiFailed"), + PON112_BUSY_TONE("2-1", "Pon112BusyTone"), + PON112_NO_TONE("2-2", "Pon112NoTone"), + PON112_CALL_OUT("2-3", "Pon112CallOut"), + PON112_CALL_IN("2-4", "Pon112CallIn"), + PON112_SINGLE_LINE("2-5", "Pon112SingleLine"), + PON112_VOICE_UNSTABLE("2-6", "Pon112VoiceUnstable"), + PON112_FAX("2-7", "Pon112Fax"), + PON112_ALG_SIP("2-8", "Pon112AlgSip"), + PON112_IPTV_UNABLE("3-1", "Pon112IPTVUnable"), + PON112_IPTV_UNSTABLE("3-2", "Pon112IPTVUnstable"), ; @Getter private String value; diff --git a/src/main/java/com/bellmann/common/result/ResultCode.java b/src/main/java/com/bellmann/common/result/ResultCode.java index c13b444..c718338 100644 --- a/src/main/java/com/bellmann/common/result/ResultCode.java +++ b/src/main/java/com/bellmann/common/result/ResultCode.java @@ -137,7 +137,9 @@ public enum ResultCode implements IResultCode, Serializable { MUST_NOT_CONTAIN_KEY_SORTING_PASSWORDS("F0043","不得包含键盘排序密码"), FAILED_TO_CHANGE_THE_PASSWORD("F0044","修改密码失败"), FAILED_TO_READ_DEVICE_SEQUENCE_FILE("F0045","读取设备序列号文件失败"), - PLEASE_UPLOAD_THE_TXT_FILE_TYPE("F0046","请上传txt文件类型" ); + PLEASE_UPLOAD_THE_TXT_FILE_TYPE("F0046","请上传txt文件类型" ), + THE_INTERFACE_CONNECTION_TIMED_OUT("F0047","接口连接超时,请检查设备是否在线") + ; @Override public String getCode() { diff --git a/src/main/java/com/bellmann/common/util/CommonUtils.java b/src/main/java/com/bellmann/common/util/CommonUtils.java index 458c220..e077ddf 100644 --- a/src/main/java/com/bellmann/common/util/CommonUtils.java +++ b/src/main/java/com/bellmann/common/util/CommonUtils.java @@ -82,4 +82,10 @@ public class CommonUtils { return str; } + + public static boolean isNeedlanOrEpon(String key) { + return key.equalsIgnoreCase("1-1") || key.equalsIgnoreCase("1-2") + || key.equalsIgnoreCase("1-3") || key.equalsIgnoreCase("1-4") + || key.equalsIgnoreCase("3-1") || key.equalsIgnoreCase("3-2"); + } } diff --git a/src/main/java/com/bellmann/controller/FaultController.java b/src/main/java/com/bellmann/controller/FaultController.java index 0393ded..15c349a 100644 --- a/src/main/java/com/bellmann/controller/FaultController.java +++ b/src/main/java/com/bellmann/controller/FaultController.java @@ -3,15 +3,13 @@ package com.bellmann.controller; import com.bellmann.common.result.Result; import com.bellmann.model.query.FaultQuery; import com.bellmann.model.vo.FaultBasicInfoVO; +import com.bellmann.model.vo.FaultDiagnosisResult; import com.bellmann.model.vo.FaultQueryVO; import com.bellmann.service.FaultService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -36,4 +34,11 @@ public class FaultController { FaultBasicInfoVO faultBasicInfoVO = faultService.basicInfoQuery(query); return Result.success(faultBasicInfoVO); } + + @Operation(summary = "基本信息诊断") + @GetMapping("/basic_info/diagnosis") + public Result basicInfoDiagnosis(@RequestParam Long devId,@RequestParam String remote){ + FaultDiagnosisResult result = faultService.basicInfoDiagnosis(devId,remote); + return Result.success(result); + } } diff --git a/src/main/java/com/bellmann/manger/impl/DataDictManager.java b/src/main/java/com/bellmann/manger/impl/DataDictManager.java new file mode 100644 index 0000000..abe9f7c --- /dev/null +++ b/src/main/java/com/bellmann/manger/impl/DataDictManager.java @@ -0,0 +1,5 @@ +package com.bellmann.manger.impl; + +public interface DataDictManager { + String AddEponOrLan(Long devId); +} diff --git a/src/main/java/com/bellmann/manger/impl/DataDictManagerImpl.java b/src/main/java/com/bellmann/manger/impl/DataDictManagerImpl.java new file mode 100644 index 0000000..254aae5 --- /dev/null +++ b/src/main/java/com/bellmann/manger/impl/DataDictManagerImpl.java @@ -0,0 +1,24 @@ +package com.bellmann.manger.impl; + +import com.bellmann.mapper.DataDictMapper; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class DataDictManagerImpl implements DataDictManager{ + private final DataDictMapper dataDictMapper; + + @Override + public String AddEponOrLan(Long devId) { + String result = dataDictMapper.AddEponOrLan(devId); + if (result.equalsIgnoreCase("EPON")) { + return "Epon"; + } else if (result.equalsIgnoreCase("LAN")) { + return "Lan"; + } else if (result.equalsIgnoreCase("GPON")) { + return "Gpon"; + } + return "Epon"; + } +} diff --git a/src/main/java/com/bellmann/mapper/DataDictMapper.java b/src/main/java/com/bellmann/mapper/DataDictMapper.java index 56a58bb..8ceaeb6 100644 --- a/src/main/java/com/bellmann/mapper/DataDictMapper.java +++ b/src/main/java/com/bellmann/mapper/DataDictMapper.java @@ -3,7 +3,9 @@ package com.bellmann.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.bellmann.model.entity.DataDict; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; @Mapper public interface DataDictMapper extends BaseMapper { + String AddEponOrLan(@Param("devId") Long devId); } diff --git a/src/main/java/com/bellmann/model/vo/FaultDiagnosisResult.java b/src/main/java/com/bellmann/model/vo/FaultDiagnosisResult.java new file mode 100644 index 0000000..f9b956e --- /dev/null +++ b/src/main/java/com/bellmann/model/vo/FaultDiagnosisResult.java @@ -0,0 +1,17 @@ +package com.bellmann.model.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.util.Date; + +@Data +public class FaultDiagnosisResult { + + private String errorDesc; + + private String testResult; + + @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss") + private Date endTime; +} diff --git a/src/main/java/com/bellmann/service/FaultService.java b/src/main/java/com/bellmann/service/FaultService.java index 26a4e3b..122210e 100644 --- a/src/main/java/com/bellmann/service/FaultService.java +++ b/src/main/java/com/bellmann/service/FaultService.java @@ -2,6 +2,7 @@ package com.bellmann.service; import com.bellmann.model.query.FaultQuery; import com.bellmann.model.vo.FaultBasicInfoVO; +import com.bellmann.model.vo.FaultDiagnosisResult; import com.bellmann.model.vo.FaultQueryVO; import java.util.List; @@ -10,4 +11,6 @@ public interface FaultService { List queryList(FaultQuery query); FaultBasicInfoVO basicInfoQuery(FaultQuery query); + + FaultDiagnosisResult basicInfoDiagnosis(Long devId, String remote); } diff --git a/src/main/java/com/bellmann/service/impl/FaultServiceImpl.java b/src/main/java/com/bellmann/service/impl/FaultServiceImpl.java index f87f4dc..96247a6 100644 --- a/src/main/java/com/bellmann/service/impl/FaultServiceImpl.java +++ b/src/main/java/com/bellmann/service/impl/FaultServiceImpl.java @@ -1,23 +1,42 @@ package com.bellmann.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.bellmann.common.base.IBaseEnum; -import com.bellmann.common.enums.CustomTypeEnum; -import com.bellmann.common.enums.DevAccessTypeEnum; -import com.bellmann.common.enums.DevStatusEnum; +import com.bellmann.common.constant.SystemConstants; +import com.bellmann.common.enums.*; +import com.bellmann.common.exception.BusinessException; +import com.bellmann.common.result.ResultCode; +import com.bellmann.common.util.CommonUtils; import com.bellmann.manger.CustomerManager; +import com.bellmann.manger.impl.DataDictManager; import com.bellmann.mapper.DeviceStaticMapper; import com.bellmann.mapper.DeviceTypeVerDetailMapper; +import com.bellmann.mapper.OperateResult2Mapper; +import com.bellmann.mapper.OperateResultArgsMapper; +import com.bellmann.model.dto.OperationTask; import com.bellmann.model.entity.Customer; import com.bellmann.model.entity.DeviceTypeVerDetail; +import com.bellmann.model.entity.OperateResult2; +import com.bellmann.model.entity.OperateResultArgs; import com.bellmann.model.query.FaultQuery; import com.bellmann.model.vo.FaultBasicInfoVO; +import com.bellmann.model.vo.FaultDiagnosisResult; import com.bellmann.model.vo.FaultQueryVO; +import com.bellmann.security.util.SecurityUtils; import com.bellmann.service.FaultService; +import com.zznode.itms.api.OAMManager; +import com.zznode.itms.api.Utils; +import com.zznode.itms.idl.device.DOperTask2DetailStruct; +import com.zznode.itms.idl.device.DOperTask2DetailStructHolder; +import com.zznode.itms.idl.device.DOperTask2Struct; +import com.zznode.itms.idl.device.DOperTaskArgsStruct; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.Date; import java.util.List; +import java.util.concurrent.TimeUnit; @Service @RequiredArgsConstructor @@ -29,6 +48,12 @@ public class FaultServiceImpl implements FaultService { private final DeviceTypeVerDetailMapper deviceTypeVerDetailMapper; + private final DataDictManager dataDictManager; + + private final OperateResult2Mapper operateResult2Mapper; + + private final OperateResultArgsMapper operateResultArgsMapper; + @Override public List queryList(FaultQuery query) { return deviceStaticMapper.faultQueryList(query.getLabel(), query.getValue()); @@ -59,4 +84,108 @@ public class FaultServiceImpl implements FaultService { } return faultBasicInfoQuery; } + + @Override + public FaultDiagnosisResult basicInfoDiagnosis(Long devId, String remote) { + if (devId==null || devId==0L || remote==null){ + throw new BusinessException(ResultCode.PARAM_IS_NULL); + } + String operateName = ""; + String addEponOrLan = dataDictManager.AddEponOrLan(devId); + boolean flag = CommonUtils.isNeedlanOrEpon(remote); + if (flag){ + operateName = IBaseEnum.getLabelByValue(remote, RemoteOperateMsgEnum.class) + addEponOrLan; + }else { + operateName = IBaseEnum.getLabelByValue(remote, RemoteOperateMsgEnum.class); + } + OperationTask operationTask = new OperationTask(); + operationTask.setDeviceId(devId); + operationTask.setOperationName(operateName); + operationTask.setOperationTaskDescription(operateName); + operationTask.setCreateUser(SecurityUtils.getUsername()); + long taskId = getDiagnosisResult(operationTask); + boolean isSuccess = taskIsSuccess(taskId); + FaultDiagnosisResult result = new FaultDiagnosisResult(); + OperateResult2 operateResult2 = operateResult2Mapper.selectOne( + new QueryWrapper() + .eq("oper_task_id", taskId) + ); + if (isSuccess){ + List list = operateResultArgsMapper.selectList(new LambdaQueryWrapper() + .eq(OperateResultArgs::getOperTaskId, taskId) + ); + result.setErrorDesc(operateResult2.getErrorDesc()); + if (!list.isEmpty()){ + result.setEndTime(list.get(0).getRecTime()); + result.setTestResult(list.get(0).getArgsValue()); + } + return result; + }else { + result.setErrorDesc(ResultCode.THE_INTERFACE_CONNECTION_TIMED_OUT.getMsg()); + result.setEndTime(operateResult2.getOperEndTime()); + return result; + } + + } + public long getDiagnosisResult(OperationTask operationTask) { + DOperTask2DetailStruct detailStruct = new DOperTask2DetailStruct(); + DOperTask2Struct operTaskStruct = new DOperTask2Struct(); + operTaskStruct.devId = operationTask.getDeviceId() == 0 ? Utils.LONG_NULL + : operationTask.getDeviceId(); + operTaskStruct.operName = operationTask.getOperationName() == null ? "" + : operationTask.getOperationName(); + operTaskStruct.operTaskCreateTime = (new Date()).getTime(); + operTaskStruct.operTaskDesc = operationTask.getOperationTaskDescription(); + operTaskStruct.operTaskId = operationTask.getOperationTaskId() == 0 ? Utils.LONG_NULL + : operationTask.getOperationTaskId(); + operTaskStruct.userName = operationTask.getCreateUser() == null ? "" + : operationTask.getCreateUser(); + detailStruct.operTask = operTaskStruct; + + DOperTaskArgsStruct[] argsStruct = new DOperTaskArgsStruct[1]; + argsStruct[0] = new DOperTaskArgsStruct(); + argsStruct[0].argsName = ""; + argsStruct[0].argsValue = ""; + argsStruct[0].operTaskId = operTaskStruct.operTaskId; + detailStruct.operTaskArgsList = argsStruct; + + DOperTask2DetailStructHolder detailStructHolder = new DOperTask2DetailStructHolder( + detailStruct); + int result = OAMManager.sendDeviceOper2Task(detailStructHolder); + if (result != 0) { + throw new BusinessException(ResultCode.OAM_INTERFACE_ERROR); + } + return detailStructHolder.value.operTask.operTaskId; + } + + private boolean taskIsSuccess(Long taskId) { + int attempt = 0; + while (attempt < 10) { + OperateResult2 operateResult2 = operateResult2Mapper.selectOne( + new QueryWrapper() + .eq("oper_task_id", taskId) + ); + if (operateResult2 == null) { + throw new BusinessException(ResultCode.TASK_NOT_FOUND); + } + String state = operateResult2.getResultState(); + if (OperateTaskStateEnum.NOT_EXECUTED.getValue().equals(state)) { + throw new BusinessException(ResultCode.TASK_NOT_EXE); + } else if (OperateTaskStateEnum.EXECUTION_FAILED.getValue().equals(state)) { + return true; + } else if (OperateTaskStateEnum.THE_DEVICE_IS_NOT_ONLINE.getValue().equals(state)) { + return true; + } else if (OperateTaskStateEnum.THE_EXECUTION_WAS_SUCCESSFUL.getValue().equals(state)) { + return true; + } + try { + TimeUnit.MILLISECONDS.sleep(SystemConstants.TASK_TIME_OUT_CONST4); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + attempt++; + } + + return false; + } } diff --git a/src/main/resources/mapper/DataDictMapper.xml b/src/main/resources/mapper/DataDictMapper.xml new file mode 100644 index 0000000..33611a1 --- /dev/null +++ b/src/main/resources/mapper/DataDictMapper.xml @@ -0,0 +1,18 @@ + + + + + +