wisdomisite-java/src/main/java/com/zhgd/xmgl/task/GantryCraneTask.java

149 lines
6.1 KiB
Java
Raw Normal View History

2023-12-26 10:25:54 +08:00
package com.zhgd.xmgl.task;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhgd.jeecg.common.util.pass.HttpUtils;
import com.zhgd.xmgl.modules.bigdevice.entity.GantryCrane;
import com.zhgd.xmgl.modules.bigdevice.entity.GantryCraneCurrentData;
import com.zhgd.xmgl.modules.bigdevice.mapper.GantryCraneCurrentDataMapper;
import com.zhgd.xmgl.modules.bigdevice.mapper.GantryCraneMapper;
import com.zhgd.xmgl.task.dto.GantryCraneCurrentDataDto;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.Objects;
/**
* 龙门吊定时任务
*/
@Slf4j
@Component
public class GantryCraneTask {
@Autowired
GantryCraneCurrentDataMapper gantryCraneCurrentDataMapper;
@Autowired
GantryCraneMapper gantryCraneMapper;
/**
* 定时获取实时数据
*/
@SchedulerLock(name = "getGantryCraneTaskData", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5)
@Scheduled(cron = "0 5 * * * ?")
public void getGantryCraneTaskData() {
log.info("getGantryCraneTaskData任务执行");
HashMap<String, Object> pMap = new HashMap<>();
pMap.put("uuid", "");
pMap.put("time", "");
pMap.put("interval", "");
String rs = HttpUtils.postJson("", pMap);
String uuid = null;
GantryCrane gc = gantryCraneMapper.selectOne(new LambdaQueryWrapper<GantryCrane>()
.eq(GantryCrane::getDevSn, uuid));
if (gc == null) {
//
}
GantryCraneCurrentDataDto dto = new GantryCraneCurrentDataDto();
GantryCraneCurrentData entity = new GantryCraneCurrentData();
entity.setDevSn(uuid);
entity.setProjectSn(gc.getProjectSn());
entity.setReciveTime(new Date());
entity.setRunTime(null);
entity.setWindSpeed(String.valueOf(dto.getWind1()));
entity.setWindSpeedState(getWindSpeedState(dto.getAL1bit5()));
entity.setAngleXAxis(null);
entity.setAngleYAxis(null);
entity.setLargeCraneRange(String.valueOf(dto.getDistance7()));
entity.setLargeCraneSpeed(String.valueOf(dto.getSpeed1()));
entity.setSmallCraneRange(null);
entity.setSmallCraneSpeed(String.valueOf(dto.getSpeed1()));
entity.setSecondSmallCraneRange(null);
entity.setSecondSmallCraneSpeed(String.valueOf(dto.getSpeed2()));
entity.setSmallCraneMainHookLoad(String.valueOf(dto.getNeiweight1()));
entity.setSmallCraneMainHookHeight(String.valueOf(dto.getDistance5()));
entity.setSmallCraneAuxiliaryHookLoad(String.valueOf(dto.getDistance6()));
entity.setSmallCraneAuxiliaryHookHeight(null);
entity.setSecondSmallCraneMainHookLoad(String.valueOf(dto.getNeiweight2()));
entity.setSecondSmallCraneMainHookHeight(String.valueOf(dto.getDistance6()));
entity.setSecondSmallCraneAuxiliaryHookLoad(null);
entity.setSecondSmallCraneAuxiliaryHookHeight(null);
entity.setMainHookCurrent(null);
entity.setMainHookVoltage(null);
entity.setSecondMainHookCurrent(null);
entity.setSecondMainHookVoltage(null);
entity.setSmallCraneRangeState(null);
entity.setSecondSmallCraneRangeState(null);
entity.setLargeCraneDistanceState(null);
entity.setMainHookWeightState(null);
entity.setSecondMainHookWeightState(null);
entity.setAuxiliaryHookWeightState(null);
entity.setSecondAuxiliaryHookWeightState(null);
entity.setMainHookHeightState(null);
entity.setSecondMainHookHeightState(null);
entity.setAuxiliaryHookHeightState(null);
entity.setSecondAuxiliaryHookHeightState(null);
entity.setAngleXState(null);
entity.setAngleYState(null);
entity.setGatedState(null);
entity.setAntiWindAndNonslipState(null);
entity.setCableReelStatus(null);
entity.setLargeCarSafeStatus(null);
entity.setLargeCarRunStatus(null);
entity.setSmallCarRunStatus(null);
entity.setSecondSmallCarRunStatus(null);
entity.setMasterHookRunStatus(getMasterHookRunStatus(dto));
entity.setSecondMasterHookRunStatus(getSecondMasterHookRunStatus(dto));
entity.setSubHookRunStatus(null);
entity.setSecondSubHookRunStatus(null);
entity.setDriverName(null);
entity.setDriverIdCard(null);
entity.setTotalDay(String.valueOf(dto.getCumulativeWorkingTime()));
entity.setTotalTimes(String.valueOf(dto.getCumulativeWorkingTime()));
entity.setPowerOnDay(String.valueOf(dto.getWorkTime()));
entity.setPowerOnTimes(String.valueOf(dto.getWorkTime()));
//gantryCraneCurrentDataMapper.insert(entity);
}
private Integer getSecondMasterHookRunStatus(GantryCraneCurrentDataDto dto) {
//小车2主钩运行状态 0:停止 1:上升 2:下降 3:故障
if (Objects.equals(dto.getOP1bit6(), 0) || Objects.equals(dto.getOP1bit7(), 0)) {
return 0;
} else if (Objects.equals(dto.getOP1bit6(), 1)) {
return 1;
} else if (Objects.equals(dto.getOP1bit7(), 1)) {
return 2;
}
return null;
}
private Integer getMasterHookRunStatus(GantryCraneCurrentDataDto dto) {
//主钩运行状态 0:停止 1:上升 2:下降 3:故障
if (Objects.equals(dto.getOP1bit0(), 0) || Objects.equals(dto.getOP1bit1(), 0)) {
return 0;
} else if (Objects.equals(dto.getOP1bit0(), 1)) {
return 1;
} else if (Objects.equals(dto.getOP1bit1(), 1)) {
return 2;
}
return null;
}
private Integer getWindSpeedState(String al1bit5) {
if (StrUtil.isBlank(al1bit5)) {
return null;
}
switch (al1bit5) {
case "0":
return 0;
case "1":
return 2;
}
return null;
}
}