提交 448c368e 作者: 17607474349

fix:

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