lxw
2023-11-24 a21f9150961e555475455e2d80ea3c5dd14e59d2
ups告警实时和历史
2个文件已添加
8个文件已修改
283 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/UpspwrdevAlarmHistoryController.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/dto/UpsAlarmDTO.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/UpspwrdevAlarm.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/UpspwrdevAlarmHistory.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/SubTablePageInfoService.java 128 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/UpspwrdevAlarmHistoryService.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/UpspwrdevAlarmService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/util/SubTablePageInfoUtils.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/config/application-dev.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/UpspwrdevAlarmMapper.xml 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/UpspwrdevAlarmHistoryController.java
New file
@@ -0,0 +1,29 @@
package com.whyc.controller;
import com.whyc.dto.Response;
import com.whyc.dto.UpsAlarmDTO;
import com.whyc.service.UpspwrdevAlarmHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
@RestController
@RequestMapping("upsHisAlm")
@Api(tags = "ups历史告警")
public class UpspwrdevAlarmHistoryController {
    @Autowired
    private UpspwrdevAlarmHistoryService service;
    @PostMapping("getAlmHis")
    @ApiOperation(value = "ups历史告警数据")
    public Response getAlmHis(@RequestBody UpsAlarmDTO upsAlarmDTO) throws ParseException {
        return service.getAlmHis(upsAlarmDTO);
    }
}
src/main/java/com/whyc/dto/UpsAlarmDTO.java
@@ -13,4 +13,8 @@
    private Date almEndTime;
    private int pageNum;
    private int pageSize;
    private String recordYear;
    private int usrId;
    private int limitStart;
    private int limitEnd;
}
src/main/java/com/whyc/pojo/UpspwrdevAlarm.java
@@ -28,7 +28,7 @@
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@TableName(schema = "db_pwrdev_data_rt",value ="tb_upspwrdev_alarm")
@TableName(schema = "db_upspwrdev_alarm",value ="tb_upspwrdev_alarm")
@ApiModel(value="UpspwrdevAlarm对象", description="UPS电源实时告警表")
public class UpspwrdevAlarm implements Serializable {
@@ -70,5 +70,18 @@
    @ApiModelProperty(value = "告警状态0-实时告警  1-历史告警  2-取消的告警")
    private Integer almClearedType;
    @TableField(exist = false)
    private String devName;
    @TableField(exist = false)
    private String stationName;
    @TableField(exist = false)
    private String stationName1;
    @TableField(exist = false)
    private String stationName2;
    @TableField(exist = false)
    private String stationName3;
    @TableField(exist = false)
    private String stationName5;
}
src/main/java/com/whyc/pojo/UpspwrdevAlarmHistory.java
@@ -1,6 +1,7 @@
package com.whyc.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
@@ -46,6 +47,10 @@
    @ApiModelProperty(value = "告警等级")
    private Integer almLevel;
    @TableField(exist = false)
    @ApiModelProperty(value = "告警名称")
    private String almTypeName;
    @ApiModelProperty(value = "告警开始时间")
    private Date almStartTime;
@@ -64,5 +69,19 @@
    @ApiModelProperty(value = "告警状态0-实时告警  1-历史告警  2-取消的告警")
    private Integer almClearedType;
    @TableField(exist = false)
    private String devName;
    @TableField(exist = false)
    private String stationName;
    @TableField(exist = false)
    private String stationName1;
    @TableField(exist = false)
    private String stationName2;
    @TableField(exist = false)
    private String stationName3;
    @TableField(exist = false)
    private String stationName5;
}
src/main/java/com/whyc/service/SubTablePageInfoService.java
@@ -3,6 +3,7 @@
import com.whyc.dto.InterfaceParam;
import com.whyc.dto.ReportBattDTO;
import com.whyc.dto.StandardFeatureCurve;
import com.whyc.dto.UpsAlarmDTO;
import com.whyc.dto.paramter.AlarmPar;
import com.whyc.dto.paramter.DevAlarmPar;
import com.whyc.dto.result.AlarmRes;
@@ -3204,5 +3205,130 @@
        }
        return tableNum;
    }
    //查询ups历史告警数量
    public int getCountForUps(UpsAlarmDTO param) {
        String sql="select  count(distinct alarm.num) as number from db_upspwrdev_alarm."+param.getRecordYear()+" alarm,db_pwrdev_inf.tb_pwrdev_inf inf " +
                "  where alarm.power_device_id = inf.PowerDeviceId ";
/*        if(param.getStationName1()!=null){
            sql+=" and stationName1 like '%"+param.getStationName1()+"%'";
        }
        if(param.getStationName2()!=null){
            sql+=" and stationName2 like '%"+param.getStationName2()+"%'";
        }
        if(param.getStationName5()!=null){
            sql+=" and stationName5 like '%"+param.getStationName5()+"%'";
        }
        if(param.getStationName3()!=null){
            sql+=" and stationName3 like '%"+param.getStationName3()+"%'";
        }*/
        if(param.getPwrdevId()!=0){
            sql+=" and alarm.power_device_id="+param.getPwrdevId();
        }
        if(param.getAlmStartTime()!=null){
            sql+=" and alarm.alm_start_time  >='"+ThreadLocalUtil.format(param.getAlmStartTime(),1)+"' ";
        }
        if(param.getAlmEndTime()!=null){
            sql+=" and alarm.alm_start_time  <='"+ThreadLocalUtil.format(param.getAlmEndTime(),1)+"' ";
        }
        if(param.getAlmTypes()!=null&&param.getAlmTypes().size()>0){
            sql+=" and alm_type in ( ";
            for (int i=0;i<param.getAlmTypes().size();i++) {
                sql+=param.getAlmTypes().get(i);
                if(i!=(param.getAlmTypes().size()-1)){
                    sql+=",";
                }
            }
            sql+=")";
        }
        sql+=" and alarm.power_device_id in ( select distinct inf.PowerDeviceId from" +
                "            (select PowerDeviceId,StationId from db_pwrdev_inf.tb_pwrdev_inf ) inf," +
                "            db_user.tb_user_battgroup_baojigroup_battgroup," +
                "            db_user.tb_user_battgroup_baojigroup_usr," +
                "            db_user.tb_user_inf" +
                "            where db_user.tb_user_battgroup_baojigroup_battgroup.StationId=inf.StationId" +
                "            and" +
                "            db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id=db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id" +
                "            and db_user.tb_user_inf.uid=db_user.tb_user_battgroup_baojigroup_usr.uid" +
                "            and db_user.tb_user_inf.uid="+param.getUsrId()+" )";
        List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                LinkedList<Object> temp = new LinkedList<>();
                try {
                    while (rs.next())
                        temp.add(rs.getInt("number"));
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                return temp;
            }
        });
        int num =0;
        if(list!=null){
            num= (int) list.get(0);
        }
        return num;
    }
    //查询ups历史告警
    public List getList2(UpsAlarmDTO param){
        String sql=" SELECT   history.num,record_id,power_device_id,alm_type,alm_level,alm_start_time,alm_end_time,alm_value,alm_is_confirmed,alm_confirmed_time,alm_cleared_type,  " +
                "        inf.stationName,stationName1,stationName2,stationName3,stationName5,inf.PowerDeviceName as dev_name " +
                "        FROM db_upspwrdev_alarm."+param.getRecordYear()+" history,db_pwrdev_inf.tb_pwrdev_inf inf  " +
                " where history.power_device_id = inf.PowerDeviceId  ";
/*        if(param.getStationName1()!=null){
            if(param.getStationName1().equals("")){
                sql+=" and stationName1!='"+param.getStationName1()+"' ";
            }else{
                sql+=" and stationName1='"+param.getStationName1()+"' ";
            }
        }
        if(param.getStationName()!=null){
            if(param.getStationName().equals("")){
                sql+=" and stationName!='"+param.getStationName()+"' ";
            }else{
                sql+=" and stationName='"+param.getStationName()+"' ";
            }
        }*/
        sql+="  and alm_start_time  >='"+ThreadLocalUtil.format(param.getAlmStartTime(),1)+"' and alm_start_time  <='"+ThreadLocalUtil.format(param.getAlmEndTime(),1)+"' ";
        sql+=" and history.power_device_id in ( select distinct inf.PowerDeviceId from" +
                "            (select PowerDeviceId,StationId from db_pwrdev_inf.tb_pwrdev_inf ) inf," +
                "            db_user.tb_user_battgroup_baojigroup_battgroup," +
                "            db_user.tb_user_battgroup_baojigroup_usr," +
                "            db_user.tb_user_inf" +
                "            where db_user.tb_user_battgroup_baojigroup_battgroup.StationId=inf.StationId" +
                "            and" +
                "            db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id=db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id" +
                "            and db_user.tb_user_inf.uid=db_user.tb_user_battgroup_baojigroup_usr.uid" +
                "            and db_user.tb_user_inf.uid="+param.getUsrId()+" ) " +
                "  ORDER BY alm_start_time desc ,dev_name asc limit "+param.getLimitStart()+","+param.getLimitEnd()+" ";
        List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<UpspwrdevAlarmHistory> list=new ArrayList<>();
                while (rs.next()){
                    UpspwrdevAlarmHistory ph=new UpspwrdevAlarmHistory();
                    ph.setNum(rs.getLong("num"));
                    ph.setRecordId(rs.getLong("record_id"));
                    ph.setPowerDeviceId(rs.getLong("power_device_id"));
                    ph.setAlmType(rs.getInt("alm_type"));
                    ph.setAlmLevel(rs.getInt("alm_level"));
                    ph.setAlmStartTime(rs.getTimestamp("alm_start_time"));
                    ph.setAlmEndTime(rs.getTimestamp("alm_end_time"));
                    ph.setAlmValue(rs.getFloat("alm_value"));
                    ph.setAlmIsConfirmed(rs.getInt("alm_is_confirmed"));
                    ph.setAlmConfirmedTime(rs.getTimestamp("alm_confirmed_time"));
                    ph.setAlmClearedType(rs.getInt("alm_cleared_type"));
                    ph.setDevName(rs.getString("dev_name"));
                    ph.setStationName(rs.getString("stationName"));
                    ph.setStationName1(rs.getString("stationName1"));
                    ph.setStationName2(rs.getString("stationName2"));
                    ph.setStationName3(rs.getString("stationName3"));
                    ph.setStationName5(rs.getString("stationName5"));
                    list.add(ph);
                }
                return list;
            }
        });
        return list;
    }
}
src/main/java/com/whyc/service/UpspwrdevAlarmHistoryService.java
New file
@@ -0,0 +1,45 @@
package com.whyc.service;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.AlarmDaoFactory;
import com.whyc.dto.Response;
import com.whyc.dto.UpsAlarmDTO;
import com.whyc.pojo.PwrdevAlarmHistory;
import com.whyc.pojo.UpspwrdevAlarmHistory;
import com.whyc.util.ActionUtil;
import com.whyc.util.SubTablePageInfoUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
@Service
public class UpspwrdevAlarmHistoryService {
    @Resource
    private SubTablePageInfoUtils subTablePageInfoUtils;
    //ups历史告警数据
    public Response getAlmHis(UpsAlarmDTO upsAlarmDTO) throws ParseException {
        Integer pageNum = upsAlarmDTO.getPageNum();
        Integer pageSize = upsAlarmDTO.getPageSize();
        Date almStartTime = upsAlarmDTO.getAlmStartTime();
        Date almEndTime = upsAlarmDTO.getAlmEndTime();
        //recordId = 1 普通电源
        //param.setRecordId(1L);
        int uId = ActionUtil.getUser().getUId().intValue();
        upsAlarmDTO.setUsrId(uId);
        PageInfo<Object> pageInfo = subTablePageInfoUtils.getPageInfo(pageNum, pageSize, almStartTime, almEndTime,
                "db_upspwrdev_alarm", "tb_upspwrdev_alarm_history", upsAlarmDTO);
        List<Object> list = pageInfo.getList();
        for (Object temp : list) {
            UpspwrdevAlarmHistory p = (UpspwrdevAlarmHistory) temp;
            p.setAlmTypeName(AlarmDaoFactory.getUpsAlarmName(p.getAlmType()));
        }
        return new Response<>().setII(1, pageInfo, null, "返回结果");
    }
}
src/main/java/com/whyc/service/UpspwrdevAlarmService.java
@@ -8,6 +8,7 @@
import com.whyc.mapper.UpspwrdevAlarmMapper;
import com.whyc.pojo.PwrdevAlarm;
import com.whyc.pojo.UpspwrdevAlarm;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -20,6 +21,7 @@
    //ups告警推送实时数据
    public Response getAlmReal(UpsAlarmDTO upsAlarmDTO) {
        PageHelper.startPage(upsAlarmDTO.getPageNum(),upsAlarmDTO.getPageSize());
        upsAlarmDTO.setUsrId(ActionUtil.getUser().getUId().intValue());
        List<UpspwrdevAlarm> list=mapper.getAlmReal(upsAlarmDTO);
        for (UpspwrdevAlarm u:list) {
            u.setAlmTypeName(AlarmDaoFactory.getUpsAlarmName(u.getAlmType()));
src/main/java/com/whyc/util/SubTablePageInfoUtils.java
@@ -2,6 +2,7 @@
import com.github.pagehelper.PageInfo;
import com.whyc.dto.InterfaceParam;
import com.whyc.dto.UpsAlarmDTO;
import com.whyc.dto.paramter.AlarmPar;
import com.whyc.dto.paramter.DevAlarmPar;
import com.whyc.dto.result.AlarmRes;
@@ -134,6 +135,15 @@
                    queryCountMap.put(tableYear,currentCount);
                }
            }
            else if (pojo instanceof UpsAlarmDTO) {
                UpsAlarmDTO param = (UpsAlarmDTO) pojo;
                param.setAlmStartTime(queryTime.get(0));
                param.setAlmEndTime(queryTime.get(1));
                param.setRecordYear(tableName);
                //int currentCount = powerAlarmHistoryMapper.getCount(param);
                int currentCount = subService.getCountForUps(param);
                queryCountMap.put(tableYear, currentCount);
            }
        }
        //分页信息
@@ -204,6 +214,20 @@
                dataList.addAll(list);
            }
            else if (pojo instanceof UpsAlarmDTO) {
                UpsAlarmDTO data = (UpsAlarmDTO) pojo;
                data.setAlmStartTime(queryTime.get(0));
                data.setAlmEndTime(queryTime.get(1));
                List<Integer> limitList = tableAndLimitMap.get(key);
                data.setLimitStart(limitList.get(0));
                data.setLimitEnd(limitList.get(1));
                data.setRecordYear(recordYear);
                //List<DevalarmDataHistory> list = devAlarmDataHistoryMapper.getList2(data);
                List<UpspwrdevAlarmHistory> list =  subService.getList2(data);
                dataList.addAll(list);
            }
            else if (pojo instanceof PwrdevAlarmHistory) {
                PwrdevAlarmHistory data = (PwrdevAlarmHistory) pojo;
                if(data.getRecordId()==1) {
src/main/resources/config/application-dev.yml
@@ -62,7 +62,7 @@
    map-underscore-to-camel-case: true
    cache-enabled: false
    #mybatis日志输出
#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
pagehelper:
  helper-dialect: mysql
  reasonable: true
src/main/resources/mapper/UpspwrdevAlarmMapper.xml
@@ -4,9 +4,10 @@
    <select id="getAlmReal" resultType="UpspwrdevAlarm">
        select  * from db_upspwrdev_alarm.tb_upspwrdev_alarm
        select  alarm.*,inf.stationName,stationName1,stationName2,stationName3,stationName5,inf.PowerDeviceName
        from db_upspwrdev_alarm.tb_upspwrdev_alarm alarm,db_pwrdev_inf.tb_pwrdev_inf inf
        <where>
            1=1
            alarm.power_device_id = inf.PowerDeviceId
            <if test="pwrdevId!=0">
                and power_device_id=#{pwrdevId}
            </if>
@@ -15,6 +16,16 @@
                    #{almType}
                </foreach>
            </if>
            and power_device_id in ( select distinct inf.PowerDeviceId from
                        (select PowerDeviceId,StationId from db_pwrdev_inf.tb_pwrdev_inf ) inf,
                        db_user.tb_user_battgroup_baojigroup_battgroup,
                        db_user.tb_user_battgroup_baojigroup_usr,
                        db_user.tb_user_inf
                        where db_user.tb_user_battgroup_baojigroup_battgroup.StationId=inf.StationId
                        and
                        db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id=db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id
                        and db_user.tb_user_inf.uid=db_user.tb_user_battgroup_baojigroup_usr.uid
                        and db_user.tb_user_inf.uid=#{usrId})
        </where>
        order by alm_start_time desc
    </select>