润德每秒查一次限制

This commit is contained in:
guoshengxiong 2025-12-02 14:51:10 +08:00
parent 89533e3482
commit f9613c9d39
3 changed files with 36 additions and 11 deletions

View File

@ -101,6 +101,13 @@ public class SafetyHatDev implements Serializable {
@Excel(name = "设备类型(1安全帽;2:安全带)", width = 15)
@ApiModelProperty(value = "设备类型(1安全帽;2:安全带)")
private java.lang.Integer type;
/**
* 获取润德安全帽数据时间
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "获取润德安全帽数据时间")
private java.util.Date rdDataTime;
/**
* 合作单位名称
*/

View File

@ -19,11 +19,16 @@ import com.zhgd.jeecg.common.system.query.QueryGenerator;
import com.zhgd.xmgl.modules.location.entity.LocationData;
import com.zhgd.xmgl.modules.project.entity.Project;
import com.zhgd.xmgl.modules.project.mapper.ProjectMapper;
import com.zhgd.xmgl.modules.safetyhat.entity.*;
import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerListyByRegionVo;
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatAlarm;
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData;
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev;
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatFence;
import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumAndRegionName;
import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumByRegionVo;
import com.zhgd.xmgl.modules.safetyhat.mapper.*;
import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatAlarmMapper;
import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDataMapper;
import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDevMapper;
import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatFenceMapper;
import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatAlarmService;
import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService;
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
@ -211,6 +216,9 @@ public class SafetyHatDataServiceImpl extends ServiceImpl<SafetyHatDataMapper, S
throw new OpenAlertException("设备编号不正确");
}
dev.setOnline(safetyHatDev.getOnline());
if (Objects.equals(dev.getOnline(), 1)) {
dev.setHeartbeatTime(new Date());
}
safetyHatDevMapper.updateById(dev);
}

View File

@ -11,6 +11,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhgd.annotation.OperLog;
import com.zhgd.jeecg.common.api.vo.Result;
@ -42,7 +43,6 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -66,7 +66,6 @@ import java.util.stream.Collectors;
@Slf4j
@RestController
@RequestMapping("xmgl/task")
@Transactional(rollbackFor = Exception.class)
public class SafetyHatTask {
public static final String SESSION_ID = "session_id";
@Autowired
@ -127,23 +126,25 @@ public class SafetyHatTask {
}
/**
* 定时2分钟获取安全帽数据
* 定时2分钟获取安全帽数据每次处理前120个
*/
@Scheduled(cron = "0 */2 * * * ?")
@SchedulerLock(name = "getHelmetData", lockAtMostFor = 1000 * 60 * 2, lockAtLeastFor = 1000 * 10)
@RequestMapping("getHelmetData")
public void getHelmetData() {
List<Project> projectList = projectService.list(Wrappers.<Project>lambdaQuery().ne(Project::getHelmetUser, "").ne(Project::getHelmetPassword, ""));
String before7Date = DateUtil.formatDateTime(DateUtil.offsetDay(new Date(), -7));
if (CollUtil.isNotEmpty(projectList)) {
log.info("定时2分钟获取安全帽数据任务开始");
for (Project project : projectList) {
List<SafetyHatDev> devList = safetyHatDevMapper.selectList(new LambdaQueryWrapper<SafetyHatDev>()
.eq(SafetyHatDev::getProjectSn, project.getProjectSn()));
.eq(SafetyHatDev::getProjectSn, project.getProjectSn())
.isNotNull(SafetyHatDev::getExtUserId)
.ge(SafetyHatDev::getHeartbeatTime, before7Date)
.orderByAsc(SafetyHatDev::getRdDataTime)
.last("limit 120")
);
for (SafetyHatDev dev : devList) {
if (StrUtil.isBlank(dev.getExtUserId())) {
log.info("定时2分钟获取安全帽数据任务安全帽外部user_id没有设置,devSn:{}", dev.getDevSn());
continue;
}
SafetyHatData lastData = safetyHatDataMapper.selectOne(new LambdaQueryWrapper<SafetyHatData>()
.eq(SafetyHatData::getDevSn, dev.getDevSn()).orderByDesc(SafetyHatData::getUploadTime).last("limit 1"));
String start;
@ -161,12 +162,21 @@ public class SafetyHatTask {
pJo.put("start", start);
pJo.put("end", end);
String json = pJo.toJSONString();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
log.info("定时2分钟获取安全帽数据任务开始devSn{},url:{},json:{}", dev.getDevSn(), url, json);
String rs = HttpRequest.post(url)
.body(json)
.timeout(20000)//超时毫秒
.execute().body();
log.info("定时2分钟获取安全帽数据任务开始rs,devSn{},rs:{}", dev.getDevSn(), rs);
safetyHatDevService.update(null, new LambdaUpdateWrapper<SafetyHatDev>()
.set(SafetyHatDev::getRdDataTime, DateUtil.now())
.eq(SafetyHatDev::getId, dev.getId())
);
JSONObject rsJo = JSON.parseObject(rs);
if (rsJo.getBoolean("status")) {
JSONArray dataJa = rsJo.getJSONArray("data");