2024-03-30 18:46:27 +08:00
|
|
|
|
package com.zhgd.xmgl.task;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
|
import com.gexin.fastjson.JSON;
|
|
|
|
|
|
import com.gexin.fastjson.JSONArray;
|
|
|
|
|
|
import com.gexin.fastjson.JSONObject;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.mechanicalequipmentposition.entity.MechanicalEquipmentPositionData;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.mechanicalequipmentposition.entity.MechanicalEquipmentPositionDev;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.mechanicalequipmentposition.mapper.MechanicalEquipmentPositionDataMapper;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.mechanicalequipmentposition.mapper.MechanicalEquipmentPositionDevMapper;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.mechanicalequipmentposition.service.impl.MechanicalEquipmentPositionDataServiceImpl;
|
|
|
|
|
|
import com.zhgd.xmgl.util.CoordinateTransformUtil;
|
|
|
|
|
|
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 org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @program: wisdomSite
|
|
|
|
|
|
* @description: 机械指挥官的机械设备定位定时任务
|
|
|
|
|
|
* @author: Mr.Peng
|
|
|
|
|
|
* @create: 2021-07-07 19:17
|
|
|
|
|
|
**/
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping("xmgl/task")
|
|
|
|
|
|
public class MechanicalEquipmentPositionTask {
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private MechanicalEquipmentPositionDevMapper mechanicalEquipmentPositionDevMapper;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private MechanicalEquipmentPositionDataMapper mechanicalEquipmentPositionDataMapper;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private MechanicalEquipmentPositionDataServiceImpl mechanicalEquipmentPositionDataService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 定时2分钟查询机械设备定位-实时数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Scheduled(cron = "0 0/2 * * * ?")
|
|
|
|
|
|
@SchedulerLock(name = "msgPushTask", lockAtMostFor = 1000 * 60 * 2, lockAtLeastFor = 1000 * 60)
|
|
|
|
|
|
@RequestMapping("getMechanicalEquipmentPositionDataMapperData")
|
|
|
|
|
|
public void getMechanicalEquipmentPositionDataMapperData() {
|
|
|
|
|
|
log.info("定时2分钟查询机械设备定位-实时数据任务开始");
|
|
|
|
|
|
List<MechanicalEquipmentPositionDev> devList = mechanicalEquipmentPositionDevMapper.selectList(null);
|
|
|
|
|
|
for (MechanicalEquipmentPositionDev dev : devList) {
|
|
|
|
|
|
String devSn = dev.getDevSn();
|
|
|
|
|
|
MechanicalEquipmentPositionData lastData = mechanicalEquipmentPositionDataMapper.selectOne(new LambdaQueryWrapper<MechanicalEquipmentPositionData>()
|
|
|
|
|
|
.eq(MechanicalEquipmentPositionData::getDevSn, devSn)
|
|
|
|
|
|
.orderByDesc(MechanicalEquipmentPositionData::getUploadTime)
|
|
|
|
|
|
.last("limit 1"));
|
|
|
|
|
|
String machineUuid = dev.getMachineUuid();
|
|
|
|
|
|
if (StrUtil.isBlank(machineUuid)) {
|
|
|
|
|
|
log.info("机械唯一标识machineUuid未配置,projectSn:{},devSn:{}", dev.getProjectSn(), dev.getDevSn());
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
String startTs;
|
|
|
|
|
|
if (lastData != null) {
|
|
|
|
|
|
startTs = lastData.getUpdateTime().getTime() / 1000 + "";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
startTs = DateUtil.offsetHour(DateUtil.date(), -11).getTime() / 1000 + "";
|
|
|
|
|
|
}
|
2024-07-05 19:07:36 +08:00
|
|
|
|
String endTs = System.currentTimeMillis() / 1000 + "";
|
2024-03-30 18:46:27 +08:00
|
|
|
|
String url = "https://open-api.zhgcloud.com/api/v3/machine/location-info?app_key=819fa8fb-b0e5-4cc2-8cd9-ed17f695ebe3&app_secret=caaea46bac06ffce795b314e743f6715&tenant_key=W6FFFRFC&" +
|
|
|
|
|
|
"machine_uuid=" + machineUuid + "&start_ts=" + startTs + "&end_ts=" + endTs;
|
|
|
|
|
|
log.info("定时2分钟查询机械设备定位-实时数据,devSn:{},url:{}", devSn, url);
|
|
|
|
|
|
String rs = HttpUtil.get(url);
|
|
|
|
|
|
log.info("定时2分钟查询机械设备定位-实时数据:{}", rs);
|
|
|
|
|
|
JSONObject rsJo = JSON.parseObject(rs);
|
|
|
|
|
|
if (Objects.equals(rsJo.getInteger("status"), 0)) {
|
|
|
|
|
|
JSONObject xCmdrResultJo = rsJo.getJSONObject("XCmdrResult");
|
|
|
|
|
|
JSONObject dlJo = xCmdrResultJo.getJSONObject("data_list");
|
|
|
|
|
|
JSONArray liJa = dlJo.getJSONArray("location_info");
|
|
|
|
|
|
for (int i = 0; i < liJa.size(); i++) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
JSONObject liJo = liJa.getJSONObject(i);
|
|
|
|
|
|
Long time = liJo.getLong("time");
|
|
|
|
|
|
Double speed = liJo.getDouble("speed");
|
|
|
|
|
|
String direction = liJo.getString("direction");
|
|
|
|
|
|
Double longitude = liJo.getDouble("longitude");
|
|
|
|
|
|
Double latitude = liJo.getDouble("latitude");
|
|
|
|
|
|
String address = liJo.getString("address");
|
|
|
|
|
|
Double mileage = liJo.getDouble("mileage");
|
|
|
|
|
|
|
|
|
|
|
|
MechanicalEquipmentPositionData data = new MechanicalEquipmentPositionData();
|
|
|
|
|
|
data.setDevSn(devSn);
|
|
|
|
|
|
double[] pointArr = CoordinateTransformUtil.transformWGS84ToGCJ02(longitude, latitude);
|
|
|
|
|
|
data.setLatitude(pointArr[1]);
|
|
|
|
|
|
data.setLongitude(pointArr[0]);
|
|
|
|
|
|
data.setSpeed(speed);
|
|
|
|
|
|
data.setWorkStatus(null);
|
|
|
|
|
|
data.setEquipmentPower(100D);
|
|
|
|
|
|
data.setEquipmentVoltage(12D);
|
|
|
|
|
|
data.setProjectSn(dev.getProjectSn());
|
|
|
|
|
|
data.setUploadTime(new Date(time * 1000L));
|
|
|
|
|
|
data.setAddress(address);
|
|
|
|
|
|
data.setDirection(direction);
|
|
|
|
|
|
data.setMileage(mileage);
|
|
|
|
|
|
mechanicalEquipmentPositionDataService.add(data);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("e:", e);
|
|
|
|
|
|
log.error("定时2分钟查询机械设备定位-实时数据出现异常:{}", e.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
log.error("定时2分钟查询机械设备定位-实时数据失败:{}", rsJo.getString("message"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|