Ver código fonte

后端调整地图

lipenghui 2 meses atrás
pai
commit
ec462c8f0f

+ 7 - 0
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/NumberUtils.java

@@ -22,6 +22,13 @@ public class NumberUtils {
         return StrUtil.isNotEmpty(str) ? Integer.valueOf(str) : null;
     }
 
+    public static int hexToDecimal(String hex) {
+        // 去除可能的前缀和空格
+        hex = hex.trim().replaceFirst("0x", "").replaceFirst("#", "");
+        // 使用Integer.parseInt转换
+        return Integer.parseInt(hex, 16);
+    }
+
     public static boolean isAllNumber(List<String> values) {
         if (CollUtil.isEmpty(values)) {
             return false;

+ 9 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/IotDeviceController.java

@@ -49,6 +49,7 @@ import java.io.IOException;
 import java.sql.Timestamp;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@@ -435,6 +436,14 @@ public class IotDeviceController {
                         BeanUtils.toBean(list, IotDeviceRespVO.class));
     }
 
+    @GetMapping("/map")
+    @Operation(summary = "查询地图设备")
+    public CommonResult<List<IotDeviceDO>> getMap(){
+        List<IotDeviceDO> mapDevice = iotDeviceService.getMapDevice();
+        List<IotDeviceDO> collect = mapDevice.stream().filter(e -> Objects.nonNull(e.getLng()) && Objects.nonNull(e.getLat())).collect(Collectors.toList());
+        return CommonResult.success(collect);
+    }
+
     @PermitAll
     @GetMapping("/init")
     public void init() {

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDeviceRespVO.java

@@ -185,4 +185,10 @@ public class IotDeviceRespVO {
 
     @Schema(description = "车辆id")
     private Long carId;
+
+    @Schema(description = "经度")
+    private Double lng;
+    @Schema(description = "纬度")
+    private Double lat;
+    private String location;
 }

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/IotDeviceDO.java

@@ -154,4 +154,8 @@ public class IotDeviceDO extends BaseDO {
     private Long yfDeviceId ;
 
     private Long carId;
+
+    private Double lng;
+    private Double lat;
+    private String location;
 }

+ 5 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/IotDeviceMapper.java

@@ -89,6 +89,11 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
                 .eqIfPresent(IotDeviceDO::getBomSyncStatus, reqVO.getBomSyncStatus()));
     }
 
+    default List<IotDeviceDO> selectDataCollect() {
+        return selectList(new LambdaQueryWrapperX<IotDeviceDO>()
+                .isNotNull(IotDeviceDO::getYfDeviceId).or()
+                .isNotNull(IotDeviceDO::getCarId));
+    }
     default List<IotDeviceDO> selectSimpleList(IotDevicePageReqVO reqVO, Collection<Long> deptIds) {
         return selectList(new LambdaQueryWrapperX<IotDeviceDO>()
                 .likeIfPresent(IotDeviceDO::getDeviceCode, reqVO.getDeviceCode())

+ 78 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/MapLngLatJob.java

@@ -0,0 +1,78 @@
+package cn.iocoder.yudao.module.pms.job;
+
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
+import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
+import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
+import cn.iocoder.yudao.module.pms.ThingsModelDTO;
+import cn.iocoder.yudao.module.pms.controller.admin.TableDataInfo;
+import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
+import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
+import com.alibaba.fastjson.JSON;
+import com.xingyuv.captcha.util.StringUtils;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import javax.annotation.Resource;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+
+@Component
+public class MapLngLatJob implements JobHandler {
+    @Resource
+    private IotDeviceMapper iotDeviceMapper;
+    @Resource
+    private RestTemplate restTemplate;
+
+    @Override
+    @TenantJob
+    public String execute(String param) throws Exception {
+        List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectDataCollect();
+        iotDeviceDOS.forEach(deviceDO -> {
+            if (Objects.nonNull(deviceDO.getYfDeviceId())) {
+                TableDataInfo tableDataInfo = restTemplate.getForObject("http://1.94.244.160:86/prod-api/iot/device/listThingsModel?deviceId="+deviceDO.getYfDeviceId()+"&pageNum=1&pageSize=200", TableDataInfo.class);
+                if (Objects.isNull(tableDataInfo)) {
+                    return;
+                }
+                List<ThingsModelDTO> rows = JSON.parseArray(JSON.toJSONString(tableDataInfo.getRows()), ThingsModelDTO.class);
+                String lac = "";
+                ThingsModelDTO lacDTO = rows.stream().filter(e -> "lac".equals(e.getIdentifier())).findFirst().orElse(null);
+                if (Objects.nonNull(lacDTO)) {
+                    lac = lacDTO.getValue();
+                }
+                String cellId = "";
+                ThingsModelDTO cellDTO = rows.stream().filter(e -> "cell_id".equals(e.getIdentifier())).findFirst().orElse(null);
+                if (Objects.nonNull(cellDTO)) {
+                    cellId = cellDTO.getValue();
+                }
+                String mcc = "";
+                ThingsModelDTO mccDTO = rows.stream().filter(e -> "mcc_mnc".equals(e.getIdentifier())).findFirst().orElse(null);
+                if (Objects.nonNull(mccDTO)) {
+                    mcc = mccDTO.getValue();
+                }
+                if (StringUtils.isNotBlank(cellId)&&StringUtils.isNotBlank(mcc)&&StringUtils.isNotBlank(lac)) {
+                    int lacTen = NumberUtils.hexToDecimal(lac);
+                    int cellTen = NumberUtils.hexToDecimal(cellId);
+                    String result = restTemplate.getForObject("http://api.cellocation.com:84/cell/?coord=wgs84&output=csv&mcc=" + StringUtils.substring(mcc, 0, 3) + "&mnc=" + StringUtils.substring(mcc, 3) +
+                            "&lac=" + lacTen + "&ci=" + cellTen, String.class);
+                    if (StringUtils.isNotBlank(result)) {
+                        List<String> list = Arrays.asList(result.split(","));
+                        String lat = list.get(1);
+                        String lng = list.get(2);
+                        String location = list.get(4);
+                        deviceDO.setLat(Double.parseDouble(lat));
+                        deviceDO.setLng(Double.parseDouble(lng));
+                        deviceDO.setLocation(location);
+                        iotDeviceMapper.updateById(deviceDO);
+                    }
+                }
+            }
+        });
+        return "";
+    }
+
+    public static void main(String[] args) {
+        String abc = "46011";
+        System.out.println(StringUtils.substring(abc, 3));
+    }
+}

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceService.java

@@ -21,6 +21,7 @@ import java.util.Map;
  * @author 芋道源码
  */
 public interface IotDeviceService {
+    List<IotDeviceDO> getMapDevice();
     List<ThingsModelDTO> getTdParams(IotDeviceDO iotDeviceDO);
     /**
      * 创建设备台账

+ 5 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceServiceImpl.java

@@ -79,6 +79,11 @@ public class IotDeviceServiceImpl implements IotDeviceService {
     @Resource
     private RestTemplate restTemplate;
 
+    @Override
+    public List<IotDeviceDO> getMapDevice() {
+        return iotDeviceMapper.selectDataCollect();
+    }
+
     @Override
     public List<ThingsModelDTO> getTdParams(IotDeviceDO iotDeviceDO) {
         TableDataInfo tableDataInfo = restTemplate.getForObject("http://1.94.244.160:86/prod-api/iot/device/listThingsModel?deviceId="+iotDeviceDO.getYfDeviceId()+"&pageNum=1&pageSize=200", TableDataInfo.class);