2021与蓝度共同重构项目,服务端
liuhaonan
2022-10-25 d495f9b8cdc83663e4189bc3cc72ac9543ff5555
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
package com.sandu.ximon.admin.service;
 
import com.github.pagehelper.PageHelper;
import com.sandu.common.domain.CommonPage;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.manager.iot.frame.A5Frame;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightErrorCodeReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightOperationReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.A5LightCleanErrorCodeInnerFrame;
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.LightErrorEnum;
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.LightReportErrorBo;
import com.sandu.ximon.dao.domain.LightReportError;
import com.sandu.ximon.dao.mapper.LightReportErrorMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @author chenjiantian
 * @date 2021/12/17 17:47
 */
@Slf4j
@Service
public class LightReportErrorService extends BaseServiceImpl<LightReportErrorMapper, LightReportError> {
 
    public void saveReportError(String deviceName, A5LightErrorCodeReportInnerFrame codeRespInnerFrame) {
        LightReportError lightReportError = new LightReportError();
        lightReportError.setDeviceCode(deviceName);
        lightReportError.setErrorCode(codeRespInnerFrame.getErrorCode());
        lightReportError.setLightAddress(codeRespInnerFrame.getDestinationAddress());
        save(lightReportError);
    }
 
    public List<LightReportErrorBo> listReportError(int pageNo, int pageSize, String keyword, Integer error_code) {
        PageHelper.startPage(pageNo, pageSize);
        List<LightReportErrorBo> lightReportErrorBos;
        //为null的话是超管
        if (SecurityUtils.getClientId() == null) {
            lightReportErrorBos = baseMapper.listReportError(keyword, error_code, null);
        } else {
            lightReportErrorBos = baseMapper.listReportError(keyword, error_code, SecurityUtils.getUserId());
        }
 
        for (LightReportErrorBo lightReportErrorBo : lightReportErrorBos) {
            Integer errorCode = lightReportErrorBo.getErrorCode();
            StringBuilder sb = new StringBuilder();
            LightErrorEnum[] values = LightErrorEnum.values();
            for (LightErrorEnum value : values) {
                if ((value.getCode() & errorCode) > 0) {
                    sb.append(value.getMessage() + ";");
                }
            }
            lightReportErrorBo.setErrorMsg(sb.toString());
        }
        return lightReportErrorBos;
    }
 
    /**
     * 查询故常数据
     *
     * @return
     */
    public CommonPage queryErrorCode(BaseConditionVO baseConditionVO) {
        List<LightReportErrorBo> lightReportErrorBos = baseMapper.listError(SecurityUtils.getClientId());
        lightReportErrorBos = lightReportErrorBos.stream().filter(bean -> bean.getErrorCode() != 0).collect(Collectors.toList());
        CommonPage commonPage = ListPagingUtils.pages(lightReportErrorBos, baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
 
        for (LightReportErrorBo lightReportErrorBo : (List<LightReportErrorBo>) commonPage.getList()) {
            Integer errorCode = lightReportErrorBo.getErrorCode();
            StringBuilder sb = new StringBuilder();
            LightErrorEnum[] values = LightErrorEnum.values();
            for (LightErrorEnum 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) {
        A5LightCleanErrorCodeInnerFrame a5LightCleanErrorCodeInnerFram = new A5LightCleanErrorCodeInnerFrame(address);
 
        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_LIGHT_DATA.getCode(), a5LightCleanErrorCodeInnerFram);
        System.out.println(a5Frame + "            -----a5Frame");
 
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(deviceName, "单灯帧-单灯故障清除", a5Frame, commonFrame);
 
        System.out.println(commonFrame + "            -----commonFrame");
        A5LightOperationReportInnerFrame operationReportInnerFrame = new A5LightOperationReportInnerFrame().transformFrame(commonFrame.getPayload());
        if (operationReportInnerFrame.isValidate()) {
            log.error("清除故障码成功,code:" + deviceName + ",灯头地址:" + address);
        }
    }
}