润德每秒查一次限制
This commit is contained in:
parent
89533e3482
commit
f9613c9d39
@ -101,6 +101,13 @@ public class SafetyHatDev implements Serializable {
|
|||||||
@Excel(name = "设备类型(1:安全帽;2:安全带)", width = 15)
|
@Excel(name = "设备类型(1:安全帽;2:安全带)", width = 15)
|
||||||
@ApiModelProperty(value = "设备类型(1:安全帽;2:安全带)")
|
@ApiModelProperty(value = "设备类型(1:安全帽;2:安全带)")
|
||||||
private java.lang.Integer type;
|
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;
|
||||||
/**
|
/**
|
||||||
* 合作单位名称
|
* 合作单位名称
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -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.location.entity.LocationData;
|
||||||
import com.zhgd.xmgl.modules.project.entity.Project;
|
import com.zhgd.xmgl.modules.project.entity.Project;
|
||||||
import com.zhgd.xmgl.modules.project.mapper.ProjectMapper;
|
import com.zhgd.xmgl.modules.project.mapper.ProjectMapper;
|
||||||
import com.zhgd.xmgl.modules.safetyhat.entity.*;
|
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatAlarm;
|
||||||
import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerListyByRegionVo;
|
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.WorkerNumAndRegionName;
|
||||||
import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumByRegionVo;
|
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.ISafetyHatAlarmService;
|
||||||
import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService;
|
import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService;
|
||||||
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
||||||
@ -211,6 +216,9 @@ public class SafetyHatDataServiceImpl extends ServiceImpl<SafetyHatDataMapper, S
|
|||||||
throw new OpenAlertException("设备编号不正确");
|
throw new OpenAlertException("设备编号不正确");
|
||||||
}
|
}
|
||||||
dev.setOnline(safetyHatDev.getOnline());
|
dev.setOnline(safetyHatDev.getOnline());
|
||||||
|
if (Objects.equals(dev.getOnline(), 1)) {
|
||||||
|
dev.setHeartbeatTime(new Date());
|
||||||
|
}
|
||||||
safetyHatDevMapper.updateById(dev);
|
safetyHatDevMapper.updateById(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
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.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.zhgd.annotation.OperLog;
|
import com.zhgd.annotation.OperLog;
|
||||||
import com.zhgd.jeecg.common.api.vo.Result;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
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.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -66,7 +66,6 @@ import java.util.stream.Collectors;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("xmgl/task")
|
@RequestMapping("xmgl/task")
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public class SafetyHatTask {
|
public class SafetyHatTask {
|
||||||
public static final String SESSION_ID = "session_id";
|
public static final String SESSION_ID = "session_id";
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -127,23 +126,25 @@ public class SafetyHatTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时2分钟获取安全帽数据
|
* 定时2分钟获取安全帽数据(每次处理前120个)
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "0 */2 * * * ?")
|
@Scheduled(cron = "0 */2 * * * ?")
|
||||||
@SchedulerLock(name = "getHelmetData", lockAtMostFor = 1000 * 60 * 2, lockAtLeastFor = 1000 * 10)
|
@SchedulerLock(name = "getHelmetData", lockAtMostFor = 1000 * 60 * 2, lockAtLeastFor = 1000 * 10)
|
||||||
@RequestMapping("getHelmetData")
|
@RequestMapping("getHelmetData")
|
||||||
public void getHelmetData() {
|
public void getHelmetData() {
|
||||||
List<Project> projectList = projectService.list(Wrappers.<Project>lambdaQuery().ne(Project::getHelmetUser, "").ne(Project::getHelmetPassword, ""));
|
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)) {
|
if (CollUtil.isNotEmpty(projectList)) {
|
||||||
log.info("定时2分钟获取安全帽数据任务开始");
|
log.info("定时2分钟获取安全帽数据任务开始");
|
||||||
for (Project project : projectList) {
|
for (Project project : projectList) {
|
||||||
List<SafetyHatDev> devList = safetyHatDevMapper.selectList(new LambdaQueryWrapper<SafetyHatDev>()
|
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) {
|
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>()
|
SafetyHatData lastData = safetyHatDataMapper.selectOne(new LambdaQueryWrapper<SafetyHatData>()
|
||||||
.eq(SafetyHatData::getDevSn, dev.getDevSn()).orderByDesc(SafetyHatData::getUploadTime).last("limit 1"));
|
.eq(SafetyHatData::getDevSn, dev.getDevSn()).orderByDesc(SafetyHatData::getUploadTime).last("limit 1"));
|
||||||
String start;
|
String start;
|
||||||
@ -161,12 +162,21 @@ public class SafetyHatTask {
|
|||||||
pJo.put("start", start);
|
pJo.put("start", start);
|
||||||
pJo.put("end", end);
|
pJo.put("end", end);
|
||||||
String json = pJo.toJSONString();
|
String json = pJo.toJSONString();
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
log.info("定时2分钟获取安全帽数据任务开始,devSn:{},url:{},json:{}", dev.getDevSn(), url, json);
|
log.info("定时2分钟获取安全帽数据任务开始,devSn:{},url:{},json:{}", dev.getDevSn(), url, json);
|
||||||
String rs = HttpRequest.post(url)
|
String rs = HttpRequest.post(url)
|
||||||
.body(json)
|
.body(json)
|
||||||
.timeout(20000)//超时,毫秒
|
.timeout(20000)//超时,毫秒
|
||||||
.execute().body();
|
.execute().body();
|
||||||
log.info("定时2分钟获取安全帽数据任务开始rs,devSn:{},rs:{}", dev.getDevSn(), rs);
|
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);
|
JSONObject rsJo = JSON.parseObject(rs);
|
||||||
if (rsJo.getBoolean("status")) {
|
if (rsJo.getBoolean("status")) {
|
||||||
JSONArray dataJa = rsJo.getJSONArray("data");
|
JSONArray dataJa = rsJo.getJSONArray("data");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user