whyclxw
2024-06-15 2325edf52ba3e999e276dbb2347c887d4d981f9e
再用电池模块推送告警
1个文件已修改
3个文件已添加
99 ■■■■■ 已修改文件
src/main/java/com/whyc/mapper/BattAlarmMapper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/BattAlarm.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BattAlarmService.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/webSocket/BattSocket.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/BattAlarmMapper.java
New file
@@ -0,0 +1,7 @@
package com.whyc.mapper;
import com.whyc.pojo.BattAlarm;
public interface BattAlarmMapper extends CustomMapper<BattAlarm>{
}
src/main/java/com/whyc/pojo/BattAlarm.java
New file
@@ -0,0 +1,48 @@
package com.whyc.pojo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@ApiModel(value="电池告警", description="")
@TableName(schema = "db_alarm",value = "batt_alarm")
public class BattAlarm {
    @TableField("num")
    @ApiModelProperty("主键编号")
    private Integer num;
    @TableField("binf_id")
    @ApiModelProperty("电池组id")
    private String binfId;
    @TableField("alm_start_time")
    @ApiModelProperty("告警开始时间")
    private Date almStartTime;
    @TableField("mon_num")
    @ApiModelProperty("告警单体编号")
    private Integer monNum;
    @TableField("alm_id")
    @ApiModelProperty("告警类型")
    private Integer almId;
    @TableField("alm_level")
    @ApiModelProperty("告警等级")
    private Integer almLevel;
    @TableField("alm_value")
    @ApiModelProperty("告警值")
    private Float almValue;
}
src/main/java/com/whyc/service/BattAlarmService.java
New file
@@ -0,0 +1,28 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whyc.dto.Response;
import com.whyc.mapper.BattAlarmMapper;
import com.whyc.pojo.BattAlarm;
import com.whyc.pojo.RtData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class BattAlarmService {
    @Autowired(required = false)
    private BattAlarmMapper mapper;
    /*
     在用电池组实时推送告警信息
     **/
    public Response getResBattAlm(int binfId) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("binf_id",binfId);
        List<BattAlarm> list=mapper.selectList(wrapper);
        return new Response().setII(1,list!=null,list,"在用电池组实时推送告警信息");
    }
}
src/main/java/com/whyc/webSocket/BattSocket.java
@@ -5,6 +5,7 @@
import com.whyc.factory.ThreadPoolExecutorFactory;
import com.whyc.pojo.RtState;
import com.whyc.pojo.StationInf;
import com.whyc.service.BattAlarmService;
import com.whyc.service.BattInfService;
import com.whyc.service.RtDataService;
import com.whyc.service.RtStateService;
@@ -50,6 +51,8 @@
    private static RtDataService rtDataService;
    private static BattAlarmService battAlarmService;
    @Autowired
    public void setRtStateService(RtStateService rtStateService) {
@@ -60,6 +63,12 @@
    public void setRtDataService(RtDataService rtDataService) {
        BattSocket.rtDataService = rtDataService;
    }
    @Autowired
    public void setBattAlarmService(BattAlarmService battAlarmService) {
        BattSocket.battAlarmService = battAlarmService;
    }
    @OnOpen
    public void onOpen(Session session) {
        this.session = session;
@@ -75,7 +84,7 @@
                    Map<String, Object> res = new HashMap<>();
                    while (!currentThread().isInterrupted()) {
                        ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor();
                        CountDownLatch latch = new CountDownLatch(2);
                        CountDownLatch latch = new CountDownLatch(3);
                        poolExecutor.execute(() -> {
                            Response resRtState = rtStateService.getResRtState(binfId);
                            res.put("resRtState", resRtState);
@@ -86,6 +95,11 @@
                            res.put("resRtData", resRtData);
                            latch.countDown();
                        });
                        poolExecutor.execute(() -> {
                            Response resBattAlm = battAlarmService.getResBattAlm(binfId);
                            res.put("resBattAlm", resBattAlm);
                            latch.countDown();
                        });
                        latch.await(10, TimeUnit.MINUTES);
                        session.getBasicRemote().sendObject(new Response().set(1, res));
                        sleep(executeTime);