package com.sandu.ximon.admin.service;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.github.pagehelper.PageHelper;
|
import com.sandu.common.domain.CommonPage;
|
import com.sandu.common.object.BaseConditionVO;
|
import com.sandu.common.service.BaseService;
|
import com.sandu.common.service.impl.BaseServiceImpl;
|
import com.sandu.ximon.admin.manager.iot.frame.A5Frame;
|
import com.sandu.ximon.admin.manager.iot.frame.A7Frame;
|
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightOperationReportInnerFrame;
|
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A7PlcErrorCodeReportInnerFrame;
|
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A7PlcOperationReportInnerFrame;
|
import com.sandu.ximon.admin.manager.iot.frame.inner.request.A5LightCleanErrorCodeInnerFrame;
|
import com.sandu.ximon.admin.manager.iot.frame.inner.request.A7PlcCleanErrorCodeInnerFrame;
|
import com.sandu.ximon.admin.manager.iot.rrpc.dto.CommonFrame;
|
import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5OrderEnum;
|
import com.sandu.ximon.admin.manager.iot.rrpc.enums.A7OrderEnum;
|
import com.sandu.ximon.admin.manager.iot.rrpc.enums.PlcErrorEnum;
|
import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService;
|
import com.sandu.ximon.admin.security.SecurityUtils;
|
import com.sandu.ximon.admin.utils.ListPagingUtils;
|
import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
|
import com.sandu.ximon.dao.bo.PlcReportErrorBo;
|
import com.sandu.ximon.dao.bo.PlcReportErrorBo;
|
import com.sandu.ximon.dao.domain.PlcReportError;
|
import com.sandu.ximon.dao.mapper.PlcReportErrorMapper;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* plc单灯故障数据列表(PlcReportError)表服务接口
|
*
|
* @author van
|
* @since 2022-12-17 14:42:19
|
*/
|
@Slf4j
|
@Service
|
public class PlcReportErrorService extends BaseServiceImpl<PlcReportErrorMapper,PlcReportError> {
|
|
|
public void saveReportError(String deviceName, A7PlcErrorCodeReportInnerFrame codeRespInnerFrame) {
|
PlcReportError plcReportError = new PlcReportError();
|
plcReportError.setPlcDeviceCode(deviceName);
|
plcReportError.setErrorCode(codeRespInnerFrame.getErrorCode());
|
plcReportError.setPlcAddress(codeRespInnerFrame.getDestinationAddress());
|
save(plcReportError);
|
}
|
|
public List<PlcReportErrorBo> listReportError(int pageNo, int pageSize, String keyword, Long error_code) {
|
PageHelper.startPage(pageNo, pageSize);
|
List<PlcReportErrorBo> plcReportErrorBos;
|
//为null的话是超管
|
if (SecurityUtils.getClientId() == null) {
|
plcReportErrorBos = baseMapper.listReportError(keyword, error_code, null);
|
} else {
|
plcReportErrorBos = baseMapper.listReportError(keyword, error_code, SecurityUtils.getUserId());
|
}
|
|
for (PlcReportErrorBo lightReportErrorBo : plcReportErrorBos) {
|
Long errorCode = lightReportErrorBo.getErrorCode();
|
StringBuilder sb = new StringBuilder();
|
PlcErrorEnum[] values = PlcErrorEnum.values();
|
for (PlcErrorEnum value : values) {
|
if ((value.getCode() & errorCode) > 0) {
|
sb.append(value.getMessage() + ";");
|
}
|
}
|
lightReportErrorBo.setErrorMsg(sb.toString());
|
}
|
return plcReportErrorBos;
|
}
|
|
/**
|
* 查询故常数据
|
*
|
* @return
|
*/
|
public CommonPage queryErrorCode(BaseConditionVO baseConditionVO) {
|
List<PlcReportErrorBo> plcReportErrorBos = baseMapper.listError(SecurityUtils.getClientId());
|
plcReportErrorBos = plcReportErrorBos.stream().filter(bean -> bean.getErrorCode() != 0).collect(Collectors.toList());
|
CommonPage commonPage = ListPagingUtils.pages(plcReportErrorBos, baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
|
|
for (PlcReportErrorBo lightReportErrorBo : (List<PlcReportErrorBo>) commonPage.getList()) {
|
Long errorCode = lightReportErrorBo.getErrorCode();
|
StringBuilder sb = new StringBuilder();
|
PlcErrorEnum[] values = PlcErrorEnum.values();
|
for (PlcErrorEnum value : values) {
|
if ((value.getCode() & errorCode) > 0) {
|
sb.append(value.getMessage());
|
}
|
}
|
lightReportErrorBo.setErrorMsg(sb.toString());
|
}
|
return commonPage;
|
}
|
|
/**
|
* 清除故障码
|
*
|
* @param deviceName
|
* @param address
|
*/
|
public void cleanErrorCode(String deviceName, String address) {
|
A7PlcCleanErrorCodeInnerFrame a7PlcCleanErrorCodeInnerFrame = new A7PlcCleanErrorCodeInnerFrame(address);
|
|
A7Frame a7Frame = new A7Frame(A7OrderEnum.REQUEST_PLC_DATA.getCode(), a7PlcCleanErrorCodeInnerFrame);
|
System.out.println(a7Frame + " -----a7Frame");
|
|
CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, a7Frame);
|
StoreOperationRecordsUtils.storeInnerFrameData(deviceName, "PLC帧-故障清除", a7Frame, commonFrame);
|
|
System.out.println(commonFrame + " -----commonFrame");
|
A7PlcOperationReportInnerFrame operationReportInnerFrame = new A7PlcOperationReportInnerFrame().transformFrame(commonFrame.getPayload());
|
if (operationReportInnerFrame.isValidate()) {
|
log.error("清除故障码成功,code:" + deviceName + ",灯头地址:" + address);
|
}
|
}
|
}
|