2021与蓝度共同重构项目,服务端
liuhaonan
2022-07-28 74f08756ac954a567d4b4d299052f23f3874fadb
优化
已添加3个文件
已修改1个文件
157 ■■■■■ 文件已修改
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/ErrorMsgController.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/dto/ErrorMsgDto.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/ErrorMsgService.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightReportErrorService.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/ErrorMsgController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,31 @@
package com.sandu.ximon.admin.controller;
import com.sandu.common.domain.ResponseVO;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.security.annotation.AnonymousAccess;
import com.sandu.common.util.ResponseUtil;
import com.sandu.ximon.admin.service.ErrorMsgService;
import com.sandu.ximon.admin.utils.RedisUtils;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author LiuHaoNan
 * @date 2022/7/27
 */
@RestController
@AllArgsConstructor
@RequestMapping("/v1/errorMsg")
public class ErrorMsgController {
    private final ErrorMsgService errorMsgService;
    @AnonymousAccess
    @GetMapping("/listMsg")
    public ResponseVO<Object> list(BaseConditionVO conditionVO){
      return ResponseUtil.success(errorMsgService.listMsg(conditionVO));
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/dto/ErrorMsgDto.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,41 @@
package com.sandu.ximon.admin.dto;
import lombok.Data;
import java.time.LocalDateTime;
/**
 * @author LiuHaoNan
 * @date 2022/7/27
 * æ•…障列表
 */
@Data
public class ErrorMsgDto {
    /**
     * è®¾å¤‡ç 
     */
    private String Mac;
    /**
     * æ•…障码
     */
    private Integer ErrorCode;
    /**
     * æ•…障描述
     */
    private String ErrorDesc;
    /**
     * æ•…障时间
     */
    private LocalDateTime ErrorTime;
    /**
     * è®¾å¤‡ç±»åž‹   0:单灯  1:充电桩 2:大气
     */
    private Integer DeviceType;
    private String DeviceJson;
}
ximon-admin/src/main/java/com/sandu/ximon/admin/service/ErrorMsgService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,60 @@
package com.sandu.ximon.admin.service;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.ximon.admin.dto.ErrorMsgDto;
import com.sandu.ximon.dao.bo.LightReportErrorBo;
import com.sandu.ximon.dao.domain.Light;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
 * @author LiuHaoNan
 * @date 2022/7/25
 * è®¾å¤‡é”™è¯¯ä¿¡æ¯
 */
@Service
@AllArgsConstructor
public class ErrorMsgService {
    private final LightReportErrorService lightReportErrorService;
    private final C3mReportErrorService c3mReportErrorService;
    private final LightService lightService;
    public List<ErrorMsgDto> listMsg(BaseConditionVO baseConditionVO) {
        List<ErrorMsgDto> errorMsgDtos = new ArrayList<>();
        //单灯故障数据
        List<LightReportErrorBo> lightReportErrors = lightReportErrorService.queryErrorCode(baseConditionVO);
        if (!lightReportErrors.isEmpty()) {
            for (LightReportErrorBo lightReportError : lightReportErrors) {
                ErrorMsgDto errorMsgDto = new ErrorMsgDto();
                errorMsgDto.setMac(lightReportError.getDeviceCode());
                errorMsgDto.setErrorCode(lightReportError.getErrorCode());
                errorMsgDto.setErrorDesc(lightReportError.getErrorMsg());
                errorMsgDto.setErrorTime(lightReportError.getCreateTime());
                errorMsgDto.setDeviceType(0);
                Light one = lightService.getOne(Wrappers.lambdaQuery(Light.class).eq(Light::getDeviceCode, lightReportError.getDeviceCode()));
                if (one != null) {
                    errorMsgDto.setDeviceJson(JSON.toJSONString(one));
                }
                errorMsgDtos.add(errorMsgDto);
            }
        }
        //充电桩故障数据
        //对errorMsgDtos按创建时间倒叙
        errorMsgDtos.sort((a, b) -> b.getErrorTime().compareTo(a.getErrorTime()));
        //手动分页  baseConditionVO.getPageNo() å½“前页 baseConditionVO.getPageSize() æ¯é¡µæ¡æ•°
        return errorMsgDtos.subList((baseConditionVO.getPageNo() - 1) * baseConditionVO.getPageSize(), baseConditionVO.getPageNo() * baseConditionVO.getPageSize());
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightReportErrorService.java
@@ -1,6 +1,7 @@
package com.sandu.ximon.admin.service;
import com.github.pagehelper.PageHelper;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightErrorCodeReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.rrpc.enums.LightErrorEnum;
@@ -49,4 +50,28 @@
        }
        return lightReportErrorBos;
    }
    /**
     * æŸ¥è¯¢æ•…常数据
     *
     * @return
     */
    public List<LightReportErrorBo> queryErrorCode(BaseConditionVO baseConditionVO) {
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
        List<LightReportErrorBo> lightReportErrorBos = baseMapper.listError(SecurityUtils.getClientId());
        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;
    }
}