Browse Source

#开停机统计

zhongwei
yang_shj 3 months ago
parent
commit
9f81205f60
  1. 43
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/StartStopDurationEntity.java
  2. 4
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java
  3. 32
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/vo/StartStopDurationRecordVo.java
  4. 14
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/StartStopDurationMapper.java
  5. 12
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/StartStopScheduledTask.java
  6. 12
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/StartStopDurationService.java
  7. 223
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/StartStopDurationServiceImpl.java
  8. 9
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/startstop/StratStopService.java
  9. 24
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/startstop/impl/StartStopServiceImpl.java
  10. 8
      hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/StartStopDurationMapper.xml
  11. 3
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/FrameRecordServiceImpl.java
  12. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/UserDeptConfigServiceImpl.java
  13. 3
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/VideoRecordServiceImpl.java

43
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/StartStopDurationEntity.java

@ -0,0 +1,43 @@
package com.hnac.hzims.equipment.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.tenant.mp.TenantEntity;
import java.util.Date;
/**
* @author ysj
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("hzims_em_start_stop_duration")
@ApiModel(value = "设备开停机时长", description = "单日开停机记录")
public class StartStopDurationEntity extends TenantEntity {
@ApiModelProperty(value = "站点编码")
private String stationId;
@ApiModelProperty(value = "站点名称")
private String stationName;
@ApiModelProperty(value = "设备编号")
private String deviceCode;
@ApiModelProperty(value = "设备名称")
private String deviceName;
@ApiModelProperty(value = "日期")
private String strDay;
@ApiModelProperty(value = "开机时长")
private Double startDuration;
@ApiModelProperty(value = "停机时长")
private Double stopDuration;
}

4
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java

@ -67,7 +67,7 @@ public interface HomePageConstant {
*/
List<String> SIGNAGES = Arrays.asList(
// 泵站、水电站
HomePageConstant.JOINT_RELAY, HomePageConstant.SWITCH_ON_OFF, HomePageConstant.ELECTRICITY_CONSUMPTION,
HomePageConstant.START_STOP_STATUS,HomePageConstant.JOINT_RELAY, HomePageConstant.SWITCH_ON_OFF, HomePageConstant.ELECTRICITY_CONSUMPTION,
HomePageConstant.ACTIVE_POWER, HomePageConstant.REACTIVE_POWER, HomePageConstant.POWER_FACTOR, HomePageConstant.VOLTAGE, HomePageConstant.CURRENT,
HomePageConstant.HYDROPOWER_GENERATE_POWER, HomePageConstant.HYDROPOWER_POWERFACTOR, HomePageConstant.HYDROPOWER_FREQUENCY, HomePageConstant.HYDROPOWER_GUIDEOPEN,
HomePageConstant.HYDROPOWER_VOLTAGE, HomePageConstant.HYDROPOWER_CURRENT, HomePageConstant.UNIT_SPEED, HomePageConstant.ACTIVE_POWER_GIVEN, HomePageConstant.REACTIVE_POWER_GIVEN,
@ -152,8 +152,10 @@ public interface HomePageConstant {
// 水利-泵组实时属性名称
String JOINT_RELAY = "joint_relay"; // 开机状态
String START_STOP_STATUS = "power_on"; // 开关机状态
String SWITCH_ON_OFF = "switch_on_off"; // 开机状态
String OFF = "1.0"; // 开机
String OFF_COMPLEX = "1"; // 开机
String ON = "0"; // 关机
String ELECTRICITY_CONSUMPTION = "electricity_consumption"; // 用电量

32
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/vo/StartStopDurationRecordVo.java

@ -0,0 +1,32 @@
package com.hnac.hzims.operational.station.vo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.NullSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* @author ysj
*/
@Data
@EqualsAndHashCode
@ApiModel("开停机数据对象")
public class StartStopDurationRecordVo {
@ApiModelProperty(value = "时间")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String ts;
@ApiModelProperty(value = "值")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String val;
@ApiModelProperty(value = "质量")
@JsonSerialize(nullsUsing = NullSerializer.class)
private String q;
}

14
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/StartStopDurationMapper.java

@ -0,0 +1,14 @@
package com.hnac.hzims.scheduled.mapper.equipment;
import com.hnac.hzims.equipment.entity.StartStopDurationEntity;
import org.apache.ibatis.annotations.Param;
import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper;
/**
* @author ysj
*/
public interface StartStopDurationMapper extends UserDataScopeBaseMapper<StartStopDurationEntity> {
void deleteThisDayStartStopRecord(@Param(value = "strDay") String strDay);
}

12
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/StartStopScheduledTask.java

@ -1,12 +1,13 @@
package com.hnac.hzims.scheduled.scheduled;
import com.hnac.hzims.scheduled.service.startstop.StratStopService;
import com.hnac.hzims.scheduled.service.equipment.StartStopDurationService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
@ -23,14 +24,15 @@ import static com.hnac.hzims.operational.main.constant.ScheduledConstant.THIS_DA
public class StartStopScheduledTask {
@Autowired
private StratStopService service;
private StartStopDurationService service;
/**
* 单日开停机记录
*/
@XxlJob(THIS_DAY_START_STOP_RECORD)
//@Scheduled(cron = "0/40 * * * * ? ")
public ReturnT<String> thisDayStartStopRecord(String param) {
//@XxlJob(THIS_DAY_START_STOP_RECORD)
@Scheduled(cron = "0/40 * * * * ? ")
public ReturnT<String> thisDayStartStopRecord() {
String param = "";
if (Func.isBlank(param)) {
param = DateUtil.format(new Date(), "yyyy-MM");
}

12
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/StartStopDurationService.java

@ -0,0 +1,12 @@
package com.hnac.hzims.scheduled.service.equipment;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hnac.hzims.equipment.entity.StartStopDurationEntity;
/**
* @author ysj
*/
public interface StartStopDurationService extends IService<StartStopDurationEntity> {
void thisDayStartStopRecord(String param);
}

223
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/StartStopDurationServiceImpl.java

@ -0,0 +1,223 @@
package com.hnac.hzims.scheduled.service.equipment.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.hnac.hzims.equipment.entity.StartStopDurationEntity;
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo;
import com.hnac.hzims.operational.main.constant.HomePageConstant;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.vo.StartStopDurationRecordVo;
import com.hnac.hzims.scheduled.mapper.equipment.StartStopDurationMapper;
import com.hnac.hzims.scheduled.service.equipment.StartStopDurationService;
import com.hnac.hzims.scheduled.service.operation.station.StationService;
import com.hnac.hzinfo.datasearch.PointData;
import com.hnac.hzinfo.datasearch.history.IHistoryDataSearchClient;
import com.hnac.hzinfo.datasearch.history.OriginalDataQuery;
import com.hnac.hzinfo.sdk.core.response.HzPage;
import com.hnac.hzinfo.sdk.core.response.Result;
import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient;
import com.hnac.hzinfo.sdk.v5.device.source.dto.HisDeviceSourceDataDTO;
import com.hnac.hzinfo.sdk.v5.device.source.dto.HisFacSourceDataDTO;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* @author ysj
*/
@RequiredArgsConstructor
@Service
@Slf4j
@DS("equipment")
public class StartStopDurationServiceImpl extends ServiceImpl<StartStopDurationMapper, StartStopDurationEntity> implements StartStopDurationService {
private final StationService stationService;
private final DeviceDataClient deviceDataClient;
private final RedisTemplate redisTemplate;
@Value("${hzims.equipment.emInfo.emInfoList}")
public String device_cache_cofig_final;
private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(256), new ThreadFactoryBuilder().setNameFormat("device-start-stop-duration-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy());
/**
* 单日开停机记录
* @param param
*/
@Override
public void thisDayStartStopRecord(String param) {
// 查询水电站点
List<StationEntity> stations = stationService.list(Wrappers.<StationEntity>lambdaQuery().
eq(StationEntity::getType, HomePageConstant.HYDROPOWER)
);
// 查询设备信息
List<EminfoAndEmParamVo> eminfos = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference<List<EminfoAndEmParamVo>>() {});
// 查询时间
Calendar calendar = Calendar.getInstance();
Date end = calendar.getTime();
calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY));
calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE));
calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND));
Date start = calendar.getTime();
// 删除当日计算开关机记录
this.baseMapper.deleteThisDayStartStopRecord(DateUtil.format(start,DateUtil.PATTERN_DATETIME));
// 遍历站点记录当日开停机时间
stations.forEach(station->{
if(CollectionUtil.isEmpty(eminfos)){
return;
}
List<EminfoAndEmParamVo> devices = eminfos.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList());
if(CollectionUtil.isEmpty(devices)){
return;
}
// 遍历设备
devices.forEach(device->{
// 设备开关机状态监测点
Map<String,String> point = device.getPoint();
if(MapUtils.isEmpty(point)){
return;
}
// 监测点
String realId = point.get(HomePageConstant.START_STOP_STATUS);
if(StringUtil.isBlank(realId)){
return;
}
// 查询时间范围开关机监测点历史数据
HisDeviceSourceDataDTO source = new HisDeviceSourceDataDTO();
source.setProjectId(station.getCode());
source.setDeviceCode(device.getEmCode());
source.setAttrSignages(Collections.singletonList(HomePageConstant.START_STOP_STATUS));
source.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), DateUtil.format(start,DateUtil.PATTERN_DATETIME)), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME)));
source.setFinishTime(LocalDateTime.parse(DateUtil.format(new Date(), DateUtil.format(end,DateUtil.PATTERN_DATETIME)), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME)));
source.setIsPage(false);
source.setCurrent(1);
source.setPageSize(100000);
Result<List<Map<String, Object>>> sources = deviceDataClient.hisDeviceSourceData(source);
if(!sources.isSuccess() || CollectionUtil.isEmpty(sources.getData())){
return;
}
// 相邻数据处理
List<StartStopDurationRecordVo> adjacents = this.adjacents(sources.getData());
// 开机时长
long runTimes = this.runTimes(adjacents,start,end);
StartStopDurationEntity duration = new StartStopDurationEntity();
duration.setTenantId(station.getTenantId());
duration.setCreateDept(station.getRefDept());
duration.setCreateUser(station.getCreateUser());
duration.setUpdateUser(station.getUpdateUser());
duration.setStationId(station.getCode());
duration.setStationName(station.getName());
duration.setDeviceCode(device.getEmCode());
duration.setDeviceName(device.getName());
duration.setStartDuration(BigDecimal.valueOf(runTimes / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue());
duration.setStopDuration(BigDecimal.valueOf((end.getTime() - start.getTime() - runTimes) / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue());
duration.setStrDay(DateUtil.format(start,DateUtil.PATTERN_DATETIME));
this.save(duration);
});
});
}
/**
* 过滤相邻开关机状态相同数据
* @param sources
* @return
*/
private List<StartStopDurationRecordVo> adjacents(List<Map<String, Object>> sources) {
Map<String, Object> map = sources.get(0);
if (MapUtils.isEmpty(map) || !map.containsKey(HomePageConstant.START_STOP_STATUS) || ObjectUtil.isEmpty(map.get(HomePageConstant.START_STOP_STATUS))) {
return new ArrayList<>();
}
List<StartStopDurationRecordVo> records = JSONObject.parseArray(JSONObject.toJSONString(map.get(HomePageConstant.START_STOP_STATUS)),StartStopDurationRecordVo.class);
if(CollectionUtil.isEmpty(records)){
return new ArrayList<>();
}
// 遍历数据
List<StartStopDurationRecordVo> result = new ArrayList<>();
for(int i = 0; i< records.size() ; i++){
// 第一个数据保存下来
if(i == 0){
result.add(records.get(i));
continue;
}
// 遍历数据状态
String value = records.get(i).getVal();
if(StringUtil.isBlank(value)){
continue;
}
// 上一条数据状态
String up_value = records.get(i-1).getVal();
if(value.equals(up_value)){
continue;
}
result.add(records.get(i));
}
return result;
}
/**
* 获取运行时长
* @param result
* @return
*/
private long runTimes(List<StartStopDurationRecordVo> result,Date startDate,Date endDate) {
if(result.size() == 1){
// 一直开机
if(HomePageConstant.OFF_COMPLEX.equals(result.get(0).getVal()) || HomePageConstant.OFF.equals(result.get(0).getVal())){
return endDate.getTime() - startDate.getTime();
}
// 一直关机
return 0;
}
long time=0;
// 遍历累计开机时长
for(int i = 0; i< result.size() ; i++){
// 记录为开机状态 就计算到下次关机的时间差
if(HomePageConstant.ON.equals(result.get(i).getVal())){
continue;
}
Date endTime,startTime = DateUtil.parse(result.get(i).getTs(), "yyyy-MM-dd HH:mm:ss.sss");
// 遍历至最后一条数据,累计至当前时间
if(i == result.size() - 1){
endTime = endDate;
}
else {
endTime = DateUtil.parse(result.get(i+1).getTs(), "yyyy-MM-dd HH:mm:ss.sss");
}
time += endTime.getTime() - startTime.getTime();
}
return time;
}
}

9
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/startstop/StratStopService.java

@ -1,9 +0,0 @@
package com.hnac.hzims.scheduled.service.startstop;
/**
* @author ysj
*/
public interface StratStopService {
void thisDayStartStopRecord(String param);
}

24
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/startstop/impl/StartStopServiceImpl.java

@ -1,24 +0,0 @@
package com.hnac.hzims.scheduled.service.startstop.impl;
import com.hnac.hzims.scheduled.service.startstop.StratStopService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author ysj
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class StartStopServiceImpl implements StratStopService {
/**
* 单日开停机记录
* @param param
*/
@Override
public void thisDayStartStopRecord(String param) {
}
}

8
hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/StartStopDurationMapper.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hnac.hzims.scheduled.mapper.equipment.StartStopDurationMapper">
<delete id="deleteThisDayStartStopRecord">
delete from hzims_em_start_stop_duration where STR_DAY = #{strDay}
</delete>
</mapper>

3
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/FrameRecordServiceImpl.java

@ -11,6 +11,7 @@ import com.hnac.hzims.operational.station.service.FrameRecordService;
import com.hnac.hzims.operational.station.service.VideoRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.stereotype.Service;
/**
@ -26,7 +27,7 @@ public class FrameRecordServiceImpl extends ServiceImpl<FrameRecordMapper, Frame
// 根据用户,站点查询历史配置记录
FrameRecordEntity frameRecord = this.getOne(Wrappers.<FrameRecordEntity>lambdaQuery()
.eq(FrameRecordEntity::getStationId,entity.getStationId())
.eq(FrameRecordEntity::getCreateUser,entity.getCreateUser())
.eq(FrameRecordEntity::getCreateUser, AuthUtil.getUserId())
);
if(ObjectUtils.isEmpty(frameRecord)){
return this.save(entity);

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/UserDeptConfigServiceImpl.java

@ -70,7 +70,7 @@ public class UserDeptConfigServiceImpl extends ServiceImpl<UserDeptConfigMapper,
// 检查记录是否保存
UserDeptConfigEntity userDeptConfig = this.getOne(Wrappers.<UserDeptConfigEntity>lambdaQuery()
.eq(UserDeptConfigEntity::getStationId,entity.getStationId())
.eq(UserDeptConfigEntity::getCreateUser,entity.getCreateUser())
.eq(UserDeptConfigEntity::getCreateUser,AuthUtil.getUserId())
);
if(ObjectUtils.isEmpty(userDeptConfig)){
return this.save(entity);

3
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/VideoRecordServiceImpl.java

@ -8,6 +8,7 @@ import com.hnac.hzims.operational.station.mapper.VideoRecordMapper;
import com.hnac.hzims.operational.station.service.VideoRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.stereotype.Service;
/**
@ -28,7 +29,7 @@ public class VideoRecordServiceImpl extends ServiceImpl<VideoRecordMapper, Video
// 根据用户,站点查询历史配置记录
VideoRecordEntity videoRecord = this.getOne(Wrappers.<VideoRecordEntity>lambdaQuery()
.eq(VideoRecordEntity::getStationId,entity.getStationId())
.eq(VideoRecordEntity::getCreateUser,entity.getCreateUser())
.eq(VideoRecordEntity::getCreateUser,AuthUtil.getUserId())
);
if(ObjectUtils.isEmpty(videoRecord)){
return this.save(entity);

Loading…
Cancel
Save