润德安全帽bug修复
This commit is contained in:
parent
89e37cb627
commit
2902ea6a45
@ -5,10 +5,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
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.WorkerNumByRegionVo;
|
||||
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -105,4 +105,13 @@ public interface ISafetyHatDataService extends IService<SafetyHatData> {
|
||||
Page<WorkerInfo> getWorkerListByRegion(Map<String, Object> param);
|
||||
|
||||
Page<WorkerInfo> getWorkerListByRegion1(Map<String, Object> param);
|
||||
|
||||
/**
|
||||
* 保存替换某设备某天安全帽数据
|
||||
*
|
||||
* @param date
|
||||
* @param dev
|
||||
* @param datas
|
||||
*/
|
||||
void saveReplaceSafetyHatDataByDate(Date date, SafetyHatDev dev, List<SafetyHatData> datas);
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@ -31,6 +32,7 @@ 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.safetyhat.service.ISafetyHatDevService;
|
||||
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
||||
import com.zhgd.xmgl.modules.worker.mapper.WorkerInfoMapper;
|
||||
import com.zhgd.xmgl.util.*;
|
||||
@ -38,6 +40,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -58,6 +61,9 @@ public class SafetyHatDataServiceImpl extends ServiceImpl<SafetyHatDataMapper, S
|
||||
public static final String STATUS = "status";
|
||||
@Resource
|
||||
SafetyHatFenceServiceImpl safetyHatFenceService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
ISafetyHatDevService safetyHatDevService;
|
||||
@Autowired
|
||||
private SafetyHatDataMapper safetyHatDataMapper;
|
||||
@Autowired
|
||||
@ -147,7 +153,7 @@ public class SafetyHatDataServiceImpl extends ServiceImpl<SafetyHatDataMapper, S
|
||||
boolean isInFence = false;
|
||||
boolean inFence = false;
|
||||
// for (SafetyHatFence fence : fenceList) {
|
||||
//判断是否在围栏范围内
|
||||
//判断是否在围栏范围内
|
||||
if (Objects.equals(fence.getRangeType(), 1)) {
|
||||
isInFence = RegionUtil.isInCircle(safetyHatData.getLongitude(), safetyHatData.getLatitude(), fence.getLongitude(), fence.getLatitude(), fence.getAreaRadius());
|
||||
} else if (Objects.equals(fence.getRangeType(), 2)) {
|
||||
@ -207,7 +213,6 @@ public class SafetyHatDataServiceImpl extends ServiceImpl<SafetyHatDataMapper, S
|
||||
return baseMapper.getNewestList1(paramMap);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateStatus(SafetyHatDev safetyHatDev) {
|
||||
SafetyHatDev dev = safetyHatDevMapper.selectOne(new LambdaQueryWrapper<SafetyHatDev>()
|
||||
@ -312,7 +317,7 @@ public class SafetyHatDataServiceImpl extends ServiceImpl<SafetyHatDataMapper, S
|
||||
.eq(SafetyHatData::getProjectSn, projectSn)
|
||||
.ge(SafetyHatData::getUploadTime, DateUtil.formatDate(DateUtil.offsetDay(new Date(), -6))));
|
||||
List<SafetyHatDev> devList = safetyHatDevMapper.selectList(new LambdaQueryWrapper<SafetyHatDev>()
|
||||
.eq(SafetyHatDev::getProjectSn, projectSn));
|
||||
.eq(SafetyHatDev::getProjectSn, projectSn));
|
||||
List<SafetyHatFence> regions = safetyHatFenceService.queryList(new MapBuilder<String, Object>()
|
||||
.put("projectSn", projectSn)
|
||||
.build());
|
||||
@ -398,7 +403,7 @@ public class SafetyHatDataServiceImpl extends ServiceImpl<SafetyHatDataMapper, S
|
||||
for (WorkerInfo workerInfo : collect) {
|
||||
workerInfo.setInserviceType(workerSet.contains(workerInfo.getId()) ? 1 : 2);
|
||||
}
|
||||
collect.sort((a,b) -> a.getInserviceType().compareTo(b.getInserviceType()));
|
||||
collect.sort((a, b) -> a.getInserviceType().compareTo(b.getInserviceType()));
|
||||
Page<WorkerInfo> page = PageUtil.getPage(param);
|
||||
int fromIndex = (int) (page.getSize() * (page.getCurrent() - 1));
|
||||
int toIndex = (int) (fromIndex + page.getSize());
|
||||
@ -437,6 +442,24 @@ public class SafetyHatDataServiceImpl extends ServiceImpl<SafetyHatDataMapper, S
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveReplaceSafetyHatDataByDate(Date date, SafetyHatDev dev, List<SafetyHatData> datas) {
|
||||
this.remove(new LambdaQueryWrapper<SafetyHatData>()
|
||||
.eq(SafetyHatData::getDevSn, dev.getDevSn())
|
||||
.eq(SafetyHatData::getIsPlatformData, 1)
|
||||
.ge(SafetyHatData::getUploadTime, DateUtil.formatDateTime(DateUtil.beginOfDay(date)))
|
||||
.le(SafetyHatData::getUploadTime, DateUtil.formatDateTime(date))
|
||||
);
|
||||
safetyHatDevService.update(null, new LambdaUpdateWrapper<SafetyHatDev>()
|
||||
.set(SafetyHatDev::getRdDataTime, DateUtil.now())
|
||||
.eq(SafetyHatDev::getId, dev.getId())
|
||||
);
|
||||
if (CollUtil.isNotEmpty(datas)) {
|
||||
this.saveBatch(datas);
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Long> getWorkerNumInFence(SafetyHatFence fence, List<SafetyHatData> datas) {
|
||||
Set<Long> inWorkerSet = new HashSet<>();
|
||||
for (SafetyHatData d : datas) {
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.zhgd.xmgl.task;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
@ -11,7 +13,6 @@ 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;
|
||||
@ -133,7 +134,8 @@ public class SafetyHatTask {
|
||||
@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));
|
||||
Date now = new Date();
|
||||
String before7Date = DateUtil.formatDateTime(DateUtil.offsetDay(now, -7));
|
||||
if (CollUtil.isNotEmpty(projectList)) {
|
||||
log.info("定时5分钟获取安全帽数据任务开始");
|
||||
for (Project project : projectList) {
|
||||
@ -145,70 +147,80 @@ public class SafetyHatTask {
|
||||
.last("limit 120")
|
||||
);
|
||||
for (SafetyHatDev dev : devList) {
|
||||
SafetyHatData lastData = safetyHatDataMapper.selectOne(new LambdaQueryWrapper<SafetyHatData>()
|
||||
.eq(SafetyHatData::getDevSn, dev.getDevSn()).orderByDesc(SafetyHatData::getUploadTime).last("limit 1"));
|
||||
String start;
|
||||
if (lastData != null) {
|
||||
start = lastData.getUploadTime().getTime() / 1000L + "";
|
||||
} else {
|
||||
start = DateUtil.offsetHour(new Date(), -12).getTime() / 1000L + "";
|
||||
}
|
||||
//轨迹回放
|
||||
String url = "https://caps.runde.pro/api/index.php?ctl=location&act=get_user_path_web";
|
||||
JSONObject pJo = new JSONObject();
|
||||
pJo.put("admin_id", project.getHelmetUser());
|
||||
pJo.put("user_id", dev.getExtUserId());
|
||||
String end = System.currentTimeMillis() / 1000L + "";
|
||||
pJo.put("start", start);
|
||||
pJo.put("end", end);
|
||||
String json = pJo.toJSONString();
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} 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");
|
||||
if (CollUtil.isEmpty(dataJa)) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < dataJa.size(); i++) {
|
||||
JSONObject dataJo = dataJa.getJSONObject(i);
|
||||
Double xPoint = dataJo.getDouble("x_point");
|
||||
Double yPoint = dataJo.getDouble("y_point");
|
||||
Long time = dataJo.getLong("time");
|
||||
SafetyHatData data = new SafetyHatData();
|
||||
data.setWorkerInfoId(dev.getWorkerInfoId());
|
||||
data.setDevSn(dev.getDevSn());
|
||||
data.setLatitude(xPoint);
|
||||
data.setLongitude(yPoint);
|
||||
data.setUploadTime(new Date(time * 1000L));
|
||||
data.setProjectSn(dev.getProjectSn());
|
||||
data.setIsPlatformData(1);
|
||||
data.setType(dev.getType());
|
||||
data.setWorkerInfoName(dev.getWorkerInfoName());
|
||||
safetyHatDataService.add(data);
|
||||
}
|
||||
} else {
|
||||
log.error("定时2分钟获取安全帽数据任务失败:devSn:{}", dev.getDevSn());
|
||||
}
|
||||
JSONObject rsJo = getHttpSafeHatDatasByDate(now, dev.getDevSn(), project.getHelmetUser(), dev.getExtUserId());
|
||||
List<SafetyHatData> datas = getSafeHatDatas(rsJo, dev);
|
||||
safetyHatDataService.saveReplaceSafetyHatDataByDate(now, dev, datas);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<SafetyHatData> getSafeHatDatas(JSONObject rsJo, SafetyHatDev dev) {
|
||||
List<SafetyHatData> safetyHatDataList = Lists.newArrayList();
|
||||
if (rsJo.getBoolean("status")) {
|
||||
JSONArray dataJa = rsJo.getJSONArray("data");
|
||||
if (CollUtil.isEmpty(dataJa)) {
|
||||
return safetyHatDataList;
|
||||
}
|
||||
for (int i = 0; i < dataJa.size(); i++) {
|
||||
JSONObject dataJo = dataJa.getJSONObject(i);
|
||||
Double xPoint = dataJo.getDouble("x_point");
|
||||
Double yPoint = dataJo.getDouble("y_point");
|
||||
Long time = dataJo.getLong("time");
|
||||
SafetyHatData data = new SafetyHatData();
|
||||
data.setWorkerInfoId(dev.getWorkerInfoId());
|
||||
data.setDevSn(dev.getDevSn());
|
||||
data.setLatitude(xPoint);
|
||||
data.setLongitude(yPoint);
|
||||
data.setUploadTime(new Date(time * 1000L));
|
||||
data.setProjectSn(dev.getProjectSn());
|
||||
data.setIsPlatformData(1);
|
||||
data.setType(dev.getType());
|
||||
data.setWorkerInfoName(dev.getWorkerInfoName());
|
||||
safetyHatDataList.add(data);
|
||||
}
|
||||
} else {
|
||||
log.error("定时5分钟获取安全帽数据任务失败:devSn:{}", dev.getDevSn());
|
||||
}
|
||||
return safetyHatDataList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某天某设备的安全帽数据
|
||||
*
|
||||
* @param date
|
||||
* @param devSn
|
||||
* @param helmetUser
|
||||
* @param extUserId
|
||||
* @return
|
||||
*/
|
||||
private JSONObject getHttpSafeHatDatasByDate(Date date, String devSn, String helmetUser, String extUserId) {
|
||||
DateTime yB = DateUtil.beginOfDay(date);
|
||||
String start = yB.getTime() / 1000L + "";
|
||||
String end = System.currentTimeMillis() / 1000L + "";
|
||||
//轨迹回放
|
||||
String url = "https://caps.runde.pro/api/index.php?ctl=location&act=get_user_path_web";
|
||||
JSONObject pJo = new JSONObject();
|
||||
pJo.put("admin_id", helmetUser);
|
||||
pJo.put("user_id", extUserId);
|
||||
pJo.put("start", start);
|
||||
pJo.put("end", end);
|
||||
String json = pJo.toJSONString();
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
log.info("定时5分钟获取安全帽数据任务开始,devSn:{},url:{},json:{}", devSn, url, json);
|
||||
String rs = HttpRequest.post(url)
|
||||
.body(json)
|
||||
.timeout(20000)//超时,毫秒
|
||||
.execute().body();
|
||||
log.info("定时5分钟获取安全帽数据任务结束rs,devSn:{},rs:{}", devSn, rs);
|
||||
JSONObject rsJo = JSON.parseObject(rs);
|
||||
return rsJo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时设置昨天的轨迹到数据库
|
||||
*/
|
||||
@ -226,7 +238,6 @@ public class SafetyHatTask {
|
||||
.isNotNull(SafetyHatDev::getExtUserId)
|
||||
.ge(SafetyHatDev::getHeartbeatTime, before7Date)
|
||||
.orderByAsc(SafetyHatDev::getRdDataTime)
|
||||
.last("limit 120")
|
||||
);
|
||||
for (SafetyHatDev dev : devList) {
|
||||
DateTime yB = DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -1));
|
||||
@ -234,7 +245,7 @@ public class SafetyHatTask {
|
||||
String start = yB.getTime() / 1000L + "";
|
||||
String end = yE.getTime() / 1000L + "";
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user