提交 448c368e 作者: 17607474349

fix:

1、标签、信标同步
上级 aebdedb8
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.location;
import cn.hutool.core.util.StrUtil;
import com.yiring.app.domain.visitor.Car;
import com.yiring.auth.domain.user.User;
import com.yiring.common.annotation.FieldMapping;
......@@ -131,6 +132,15 @@ public class LocationTag extends BasicEntity implements Serializable {
public String text() {
return this.text;
}
public static Type getByCode(String text) {
for (Type type : values()) {
if (StrUtil.equals(type.text(), text)) {
return type;
}
}
throw new RuntimeException("Type获取未知风险");
}
}
@Override
......
......@@ -34,8 +34,8 @@ public class LocationTagExportExcel implements Serializable {
@ExcelColumn(title = "编号")
String code;
@ExcelColumn(title = "标签类型")
LocationTag.Type type;
@ExcelColumn(title = "标签型号")
String type;
@ExcelColumn(title = "状态")
Boolean silent;
......@@ -53,7 +53,7 @@ public class LocationTagExportExcel implements Serializable {
return LocationTagExportExcel
.builder()
.code(locationTag.getCode())
.type(locationTag.getType())
.type(locationTag.getType().text())
.silent(locationTag.getSilent())
.imei(locationTag.getImei())
.volt(locationTag.getVolt())
......
......@@ -30,7 +30,7 @@ public class LocationTagImportExcel implements Serializable {
String code;
// 标签型号
@ExcelColumn(title = "标签类型")
@ExcelColumn(title = "标签型号")
String type;
// 设备编码
......@@ -40,9 +40,9 @@ public class LocationTagImportExcel implements Serializable {
public static LocationTag transform(LocationTagImportExcel locationTagImportExcel) {
return LocationTag
.builder()
.code(locationTagImportExcel.code)
.type(LocationTag.Type.valueOf(locationTagImportExcel.type))
.imei(StrUtil.isEmpty(locationTagImportExcel.imei) ? null : locationTagImportExcel.imei)
.code(locationTagImportExcel.getCode())
.type(LocationTag.Type.getByCode(locationTagImportExcel.getType()))
.imei(StrUtil.isEmpty(locationTagImportExcel.getImei()) ? null : locationTagImportExcel.imei)
.createTime(LocalDateTime.now())
.build();
}
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.param.location.beacon;
import cn.hutool.core.util.ObjectUtil;
import com.yiring.app.domain.location.LocationBeacon;
import com.yiring.app.util.GeoUtils;
import io.swagger.annotations.ApiModel;
......@@ -58,7 +59,7 @@ public class LocationBeaconAddParam implements Serializable {
String voltUnit;
public static LocationBeacon transform(LocationBeaconAddParam locationBeaconAddParam) {
return LocationBeacon
LocationBeacon locationBeacon = LocationBeacon
.builder()
.linkId(locationBeaconAddParam.getId())
.areaId(locationBeaconAddParam.getAreaId())
......@@ -66,16 +67,23 @@ public class LocationBeaconAddParam implements Serializable {
.x(locationBeaconAddParam.getX())
.y(locationBeaconAddParam.getY())
.z(locationBeaconAddParam.getZ())
.point(
.time(locationBeaconAddParam.getTime())
.volt(locationBeaconAddParam.getVolt())
.voltUnit(locationBeaconAddParam.getVoltUnit())
.build();
if (
ObjectUtil.isNotEmpty(locationBeaconAddParam.getX()) &&
ObjectUtil.isNotEmpty(locationBeaconAddParam.getY()) &&
ObjectUtil.isNotEmpty(locationBeaconAddParam.getY())
) {
locationBeacon.setPoint(
GeoUtils.xyzToPoint(
locationBeaconAddParam.getX().doubleValue(),
locationBeaconAddParam.getY().doubleValue(),
locationBeaconAddParam.getZ().doubleValue()
)
)
.time(locationBeaconAddParam.getTime())
.volt(locationBeaconAddParam.getVolt())
.voltUnit(locationBeaconAddParam.getVoltUnit())
.build();
);
}
return locationBeacon;
}
}
......@@ -2,6 +2,7 @@
package com.yiring.app.service.location.beacon.impl;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
......@@ -65,8 +66,8 @@ public class LocationBeaconServiceImpl implements LocationBeaconService {
public void saveLocationBeacon() {
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("deviceType", "BTI");
hashMap.put("pageSize", 100);
hashMap.put("pageNum", 0);
hashMap.put("pageSize", 10000);
hashMap.put("pageNum", 1);
hashMap.put("orgId", 100);
hashMap.put("deviceId", "");
JSONObject jsonObject = locationTagBeaconClient.page(JSONUtil.toJsonStr(hashMap), ZyUtil.manageLogin());
......@@ -94,6 +95,7 @@ public class LocationBeaconServiceImpl implements LocationBeaconService {
} else {
LocationBeacon locationBeacon = locationBeaconOptional.get();
modifyLocationBeacon(locationBeacon, locationBeaconAddParam);
locationBeaconRepository.save(locationBeacon);
}
});
}
......@@ -217,6 +219,11 @@ public class LocationBeaconServiceImpl implements LocationBeaconService {
locationBeacon.setTime(locationBeaconAddParam.getTime());
locationBeacon.setVolt(locationBeaconAddParam.getVolt());
locationBeacon.setVoltUnit(locationBeaconAddParam.getVoltUnit());
if (
ObjectUtil.isNotEmpty(locationBeaconAddParam.getX()) &&
ObjectUtil.isNotEmpty(locationBeaconAddParam.getY()) &&
ObjectUtil.isNotEmpty(locationBeaconAddParam.getY())
) {
locationBeacon.setPoint(
GeoUtils.xyzToPoint(
locationBeaconAddParam.getX().doubleValue(),
......@@ -225,4 +232,5 @@ public class LocationBeaconServiceImpl implements LocationBeaconService {
)
);
}
}
}
......@@ -72,4 +72,10 @@ public interface LocationTagService {
* @return Result<LocationTagVo>
*/
Result<LocationTagVo> info(LocationTagFindParam param);
/**
* 同步标签
* @return Result<String>
*/
Result<String> sync();
}
......@@ -25,6 +25,7 @@ import com.yiring.app.service.location.tag.LocationTagService;
import com.yiring.app.util.zy.ZyUtil;
import com.yiring.app.vo.location.tag.LocationTagIndexVo;
import com.yiring.app.vo.location.tag.LocationTagVo;
import com.yiring.app.vo.location.tag.ZyLocationTagVo;
import com.yiring.app.vo.user.UserVo;
import com.yiring.app.vo.visitor.CarVo;
import com.yiring.auth.domain.user.User;
......@@ -100,7 +101,7 @@ public class LocationTagServiceImpl implements LocationTagService {
page.put("pageSize", 1);
page.put("tagId", locationTag.getCode());
JSONObject result = locationTagClient.tagPage(JSONUtil.toJsonStr(page), ZyUtil.manageLogin());
if (!ObjectUtil.equals(jsonObject.get("code"), 200)) {
if (!ObjectUtil.equals(result.get("code"), 200)) {
throw new RuntimeException(StrUtil.toString(jsonObject.get("msg")));
}
JSONObject data = JSONUtil.parseObj(result.get("data"));
......@@ -230,8 +231,8 @@ public class LocationTagServiceImpl implements LocationTagService {
page.put("pageSize", 1);
page.put("tagId", locationTag.getCode());
JSONObject result = locationTagClient.tagPage(JSONUtil.toJsonStr(page), ZyUtil.manageLogin());
if (!ObjectUtil.equals(jsonObject.get("code"), 200)) {
throw new RuntimeException(StrUtil.toString(jsonObject.get("msg")));
if (!ObjectUtil.equals(result.get("code"), 200)) {
throw new RuntimeException(StrUtil.toString(result.get("msg")));
}
JSONObject data = JSONUtil.parseObj(result.get("data"));
JSONArray records = JSONUtil.parseArray(data.get("records"));
......@@ -333,6 +334,53 @@ public class LocationTagServiceImpl implements LocationTagService {
return Result.ok(locationTagVo);
}
@Override
public Result<String> sync() {
HashMap<String, Object> page = new HashMap<>();
page.put("orgId", FACTORY_ID);
page.put("pageNum", 1);
page.put("pageSize", 1000);
JSONObject result = locationTagClient.tagPage(JSONUtil.toJsonStr(page), ZyUtil.manageLogin());
if (!ObjectUtil.equals(result.get("code"), 200)) {
throw new RuntimeException(StrUtil.toString(result.get("msg")));
}
JSONObject data = JSONUtil.parseObj(result.get("data"));
JSONArray records = JSONUtil.parseArray(data.get("records"));
List<ZyLocationTagVo> zyLocationTagVos = JSONUtil.toList(JSONUtil.toJsonStr(records), ZyLocationTagVo.class);
List<LocationTag> locationTags = locationTagRepository.findAll();
Map<String, List<LocationTag>> resultMap = locationTags
.stream()
.collect(Collectors.groupingBy(LocationTag::getCode));
zyLocationTagVos.forEach(zyLocationTagVo -> {
if (resultMap.get(zyLocationTagVo.getTagId()) == null) {
LocationTag locationTag = LocationTag
.builder()
.code(zyLocationTagVo.getTagId())
.linkId(zyLocationTagVo.getId())
.time(zyLocationTagVo.getRaiseTime())
.silent(zyLocationTagVo.getSilent())
.used(zyLocationTagVo.getUsed())
.volt(zyLocationTagVo.getVolt())
.voltUnit(zyLocationTagVo.getVoltUnit())
.type(LocationTag.Type.getByCode(zyLocationTagVo.getTagCategory()))
.build();
locationTagRepository.save(locationTag);
return;
}
LocationTag locationTag = resultMap.get(zyLocationTagVo.getTagId()).get(0);
locationTag.setLinkId(zyLocationTagVo.getId());
locationTag.setTime(zyLocationTagVo.getRaiseTime());
locationTag.setSilent(zyLocationTagVo.getSilent());
locationTag.setUsed(zyLocationTagVo.getUsed());
locationTag.setVolt(zyLocationTagVo.getVolt());
locationTag.setVoltUnit(zyLocationTagVo.getVoltUnit());
locationTagRepository.save(locationTag);
});
return Result.ok();
}
private boolean hasLocationTagInfoByCode(String code) {
LocationTag locationTag = LocationTag.builder().code(code).build();
return locationTagRepository.count(Example.of(locationTag)) > 0;
......
......@@ -84,4 +84,10 @@ public class LocationTagController {
public Result<LocationTagVo> info(@Valid LocationTagFindParam param) {
return locationTagService.info(param);
}
@ApiOperation("同步数据")
@PostMapping("sync")
public Result<String> sync() {
return locationTagService.sync();
}
}
......@@ -101,23 +101,23 @@ zy-config:
queue-name: tenant_msg_${zy-config.open.client-secret}_${zy-config.open.client-id}_mock
# 开放接口信息配置
open:
api: http://${zy-config.host}:789/positionApi
client-id: sc21080400
api: https://nl.yz-cloud.com/positionApi
client-id: sc22030527
grant-type: client_credentials
client-secret: 12A14FDC
tenant: sc21080400
client-secret: C18422B9
tenant: sc22030527
# 代理接口信息配置
proxy:
api: https://nl.yz-cloud.com
tenant: ts00000006
tenant: sc22030527
# 应用平台账户信息
client:
username: test1234
password: 123456
username: client
password: client@yiring.com
# 管理后台账户信息
manage:
username: test123
password: test123
username: manage
password: manage@yiring.com
feign:
httpclient:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论