2021与蓝度共同重构项目,服务端
Van333
2022-12-29 727a69f859060093e685582fa10e5de82dcc138a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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);
        }
    }
}