diff --git a/common/pom.xml b/common/pom.xml
index bf993ba..82eb64a 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -10,7 +10,6 @@
common
-
17
17
@@ -45,17 +44,6 @@
orika-core
1.5.4
-
- org.mapstruct
- mapstruct
- 1.5.5.Final
-
-
- org.mapstruct
- mapstruct-processor
- 1.5.5.Final
- compile
-
org.apache.commons
commons-pool2
@@ -101,7 +89,20 @@
gson
2.10.1
-
+
+ org.mapstruct
+ mapstruct
+
+
+ org.mapstruct
+ mapstruct-processor
+ provided
+
+
+ cn.dev33
+ sa-token-spring-boot3-starter
+
+
\ No newline at end of file
diff --git a/common/src/main/java/com/jiagutech/ams/model/LoginUser.java b/common/src/main/java/com/jiagutech/ams/model/LoginUser.java
index ae7770c..a4fb58e 100644
--- a/common/src/main/java/com/jiagutech/ams/model/LoginUser.java
+++ b/common/src/main/java/com/jiagutech/ams/model/LoginUser.java
@@ -96,5 +96,7 @@ public class LoginUser implements Serializable {
private String regionPath;
+ private String regionName;
+
}
diff --git a/common/src/main/java/com/jiagutech/ams/utils/LoginUtil.java b/common/src/main/java/com/jiagutech/ams/utils/LoginUtil.java
new file mode 100644
index 0000000..7169573
--- /dev/null
+++ b/common/src/main/java/com/jiagutech/ams/utils/LoginUtil.java
@@ -0,0 +1,25 @@
+package com.jiagutech.ams.utils;
+
+import cn.dev33.satoken.stp.StpUtil;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.jiagutech.ams.constant.UserConstants;
+import com.jiagutech.ams.model.LoginUser;
+
+public class LoginUtil {
+
+
+ public static LoginUser getLoginUser() {
+ String userStr = (String) StpUtil.getSession().get(UserConstants.SYS_SESSION);
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ try {
+ return mapper.readValue(userStr, LoginUser.class);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 91416b8..1db6f2d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,6 +27,7 @@
3.1.7
1.37.0
5.2.5
+ 1.6.1
3.3.2
2.2.0
@@ -37,7 +38,7 @@
1.3.5
3.2.2
- 3.11.0
+ 3.11.0
3.1.2
1.3.0
@@ -186,7 +187,17 @@
+
+ org.mapstruct
+ mapstruct
+ ${mapstruct.version}
+
+
+ org.mapstruct
+ mapstruct-processor
+ ${mapstruct.version}
+
+
-
\ No newline at end of file
diff --git a/publish.sh b/publish.sh
new file mode 100755
index 0000000..6b2e3dd
--- /dev/null
+++ b/publish.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+echo "服务开始打包"
+export JAVA_HOME=~/Library/Java/JavaVirtualMachines/corretto-17.0.11/Contents/Home
+
+mvn -P prod clean package -Dmaven.test.skip=true
+
+echo "服务打包完成"
+
+echo "开始上传jar"
+scp ./web/target/*.jar jg-node1:/usr/local/ams-social/
+echo "上传完成"
+echo "开始启动服务"
+ssh jg-node1 "cd /usr/local/ams-social && docker-compose up -d --build "
+echo "部署完成"
\ No newline at end of file
diff --git a/social/pom.xml b/social/pom.xml
index 86abdc9..fb16e35 100644
--- a/social/pom.xml
+++ b/social/pom.xml
@@ -67,17 +67,13 @@
org.springframework.boot
spring-boot-starter-amqp
-
- org.mapstruct
- mapstruct
- 1.5.5.Final
+ org.springframework.amqp
+ spring-rabbit
- org.mapstruct
- mapstruct-processor
- 1.5.5.Final
- compile
+ org.springframework.amqp
+ spring-amqp
com.alibaba
@@ -99,6 +95,16 @@
proj4j
1.1.3
+
+ org.mapstruct
+ mapstruct
+
+
+ org.mapstruct
+ mapstruct-processor
+ provided
+
+
\ No newline at end of file
diff --git a/social/src/main/java/com/jiagutech/ams/controller/DeviceController.java b/social/src/main/java/com/jiagutech/ams/controller/DeviceController.java
index 7f3b308..367b9a5 100644
--- a/social/src/main/java/com/jiagutech/ams/controller/DeviceController.java
+++ b/social/src/main/java/com/jiagutech/ams/controller/DeviceController.java
@@ -1,6 +1,7 @@
package com.jiagutech.ams.controller;
import cn.dev33.satoken.annotation.SaCheckRole;
+import cn.dev33.satoken.annotation.SaMode;
import com.jiagutech.ams.model.common.PageRequest;
import com.jiagutech.ams.model.common.PageResult;
import com.jiagutech.ams.model.common.R;
@@ -32,7 +33,7 @@ public class DeviceController {
@Operation(summary = "获取在线设备列表")
@GetMapping("/onlineAndRound")
- @SaCheckRole("machinist")
+ @SaCheckRole(value = {"machinist", "admin"}, mode = SaMode.OR)
public R> onlineAndRound(@RequestParam(required = false, defaultValue = "0") double maxLng,
@RequestParam(required = false, defaultValue = "0") double maxLat,
@RequestParam(required = false, defaultValue = "0") double minLng,
@@ -43,8 +44,18 @@ public class DeviceController {
@Operation(summary = "设备列表")
@PostMapping("/page")
- @SaCheckRole("manager")
+ @SaCheckRole(value = {"manager", "admin"}, mode = SaMode.OR)
public R> page(@RequestBody PageRequest pageRequest) {
return R.ok(deviceService.page(pageRequest));
}
+
+
+
+ @Operation(summary = "获取所有设备列表")
+ @GetMapping("/list")
+ public R> list() {
+ return R.ok(deviceService.deviceList());
+ }
+
+
}
diff --git a/social/src/main/java/com/jiagutech/ams/listener/JobFinishListener.java b/social/src/main/java/com/jiagutech/ams/listener/JobFinishListener.java
index 2990a64..5dccc34 100644
--- a/social/src/main/java/com/jiagutech/ams/listener/JobFinishListener.java
+++ b/social/src/main/java/com/jiagutech/ams/listener/JobFinishListener.java
@@ -1,17 +1,24 @@
package com.jiagutech.ams.listener;
+import cn.hutool.core.collection.CollectionUtil;
import com.jiagutech.ams.event.JobFinishEvent;
+import com.jiagutech.ams.mapper.DeviceMapper;
import com.jiagutech.ams.mapper.JobMapper;
import com.jiagutech.ams.model.TrackItem;
+import com.jiagutech.ams.model.dto.DeviceDTO;
import com.jiagutech.ams.model.dto.JobDTO;
import com.jiagutech.ams.service.JobService;
+import com.jiagutech.ams.utils.FlightTrackerUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
+import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.time.Duration;
import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
import java.util.List;
/**
@@ -27,7 +34,9 @@ import java.util.List;
public class JobFinishListener {
private final JobService jobService;
private final JobMapper jobMapper;
+ private final DeviceMapper deviceMapper;
+ @Async
@EventListener(JobFinishEvent.class)
public void finishJob(JobFinishEvent event) {
log.info("JobFinishListener:{}", event.getJobId());
@@ -40,10 +49,38 @@ public class JobFinishListener {
Duration duration = Duration.between(instant1, instant2);
jobDTO.setDuration((int) duration.toSeconds());
List trackList = jobService.getTrackList(event.getJobId());
+ if (CollectionUtil.isNotEmpty(trackList)) {
+ jobDTO.setArea(calculateArea(trackList));
+ TrackItem trackItem = trackList.get(trackList.size() - 1);
+ jobDTO.setLat(trackItem.getLat()).setLng(trackItem.getLng());
+ DeviceDTO deviceDTO = new DeviceDTO().setId(jobDTO.getDeviceId()).setLat(trackItem.getLat()).setLng(trackItem.getLng()).setUpdateTime(trackItem.getTimestamp());
+ deviceMapper.updateById(deviceDTO);
+ }
jobMapper.updateById(jobDTO);
+
} catch (Exception e) {
throw new RuntimeException(e);
}
}
+
+ public float calculateArea(List trackList) {
+ try {
+ if (CollectionUtil.isEmpty(trackList)) {
+ return 0.0f;
+ }
+ List pointTemps = trackList.stream().map(item -> {
+ LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(item.getTimestamp()), ZoneId.systemDefault());
+ int speed = Math.round(item.getVelocity() * 5 / 18);
+ return new FlightTrackerUtils.PointTemp(localDateTime, item.getLat(), item.getLng(), speed);
+ }).toList();
+ if (CollectionUtil.isEmpty(pointTemps)) {
+ return 0.0f;
+ }
+ return (float) FlightTrackerUtils.calculateArea(pointTemps);
+ } catch (Exception e) {
+ log.error("calculate area error", e);
+ return 0.0f;
+ }
+ }
}
diff --git a/social/src/main/java/com/jiagutech/ams/mapper/JobMapper.java b/social/src/main/java/com/jiagutech/ams/mapper/JobMapper.java
index d6786fe..a9b28a4 100644
--- a/social/src/main/java/com/jiagutech/ams/mapper/JobMapper.java
+++ b/social/src/main/java/com/jiagutech/ams/mapper/JobMapper.java
@@ -17,4 +17,6 @@ public interface JobMapper extends BaseMapper {
List jobList(@Param("ew") QueryWrapper wrapper);
List jobListCountByFarmer(@Param("ew") QueryWrapper wrapper);
+
+ List inJob(@Param("ew") QueryWrapper queryWrapper);
}
diff --git a/social/src/main/java/com/jiagutech/ams/model/DeviceMapping.java b/social/src/main/java/com/jiagutech/ams/model/DeviceMapping.java
new file mode 100644
index 0000000..2ca723a
--- /dev/null
+++ b/social/src/main/java/com/jiagutech/ams/model/DeviceMapping.java
@@ -0,0 +1,17 @@
+package com.jiagutech.ams.model;
+
+import com.jiagutech.ams.model.dto.DeviceDTO;
+import com.jiagutech.ams.model.response.DeviceInfo;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+@Mapper
+public interface DeviceMapping {
+
+ DeviceMapping INSTANCE = Mappers.getMapper(DeviceMapping.class);
+
+ @Mapping(source = "id", target = "deviceId")
+ DeviceInfo convertDeviceInfo(DeviceDTO device);
+
+}
diff --git a/social/src/main/java/com/jiagutech/ams/model/UavSortie.java b/social/src/main/java/com/jiagutech/ams/model/UavSortie.java
index ef54e4a..35090e5 100644
--- a/social/src/main/java/com/jiagutech/ams/model/UavSortie.java
+++ b/social/src/main/java/com/jiagutech/ams/model/UavSortie.java
@@ -2,8 +2,10 @@ package com.jiagutech.ams.model;
import lombok.Data;
+import lombok.NoArgsConstructor;
@Data
+@NoArgsConstructor
public class UavSortie implements java.io.Serializable {
private static final long serialVersionUID = 1L;
diff --git a/social/src/main/java/com/jiagutech/ams/model/dto/DeviceDTO.java b/social/src/main/java/com/jiagutech/ams/model/dto/DeviceDTO.java
index 41a7961..397ded2 100644
--- a/social/src/main/java/com/jiagutech/ams/model/dto/DeviceDTO.java
+++ b/social/src/main/java/com/jiagutech/ams/model/dto/DeviceDTO.java
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
+import lombok.experimental.Accessors;
/**
* @ClassName DeviceDTO
@@ -14,6 +15,7 @@ import lombok.Data;
**/
@Data
@TableName("ams_device_info")
+@Accessors(chain = true)
public class DeviceDTO {
@TableId(type = IdType.AUTO)
@@ -23,5 +25,15 @@ public class DeviceDTO {
private String boxNum;
+ private String name;
+
+ private String licensePlate;
+
private Long deptId;
+
+ private Double lat;
+
+ private Double lng;
+
+ private Long updateTime;
}
diff --git a/social/src/main/java/com/jiagutech/ams/model/dto/JobDTO.java b/social/src/main/java/com/jiagutech/ams/model/dto/JobDTO.java
index 855e0ef..0afa55c 100644
--- a/social/src/main/java/com/jiagutech/ams/model/dto/JobDTO.java
+++ b/social/src/main/java/com/jiagutech/ams/model/dto/JobDTO.java
@@ -19,7 +19,7 @@ public class JobDTO {
@TableId
private Long id;
- private Long deviceId;
+ private Integer deviceId;
private Long startTime;
@@ -41,5 +41,8 @@ public class JobDTO {
private Long deptId;
+ private Double lat;
+
+ private Double lng;
}
diff --git a/social/src/main/java/com/jiagutech/ams/model/request/JobCreateRequest.java b/social/src/main/java/com/jiagutech/ams/model/request/JobCreateRequest.java
index 97e4eeb..b0cc159 100644
--- a/social/src/main/java/com/jiagutech/ams/model/request/JobCreateRequest.java
+++ b/social/src/main/java/com/jiagutech/ams/model/request/JobCreateRequest.java
@@ -38,7 +38,7 @@ public class JobCreateRequest {
* 设备ID
*/
@JsonDeserialize(using = StringToLongDeserializer.class)
- private long deviceId;
+ private int deviceId;
/**
* 作业类型
*/
diff --git a/social/src/main/java/com/jiagutech/ams/model/response/DeviceInfo.java b/social/src/main/java/com/jiagutech/ams/model/response/DeviceInfo.java
index 54c5995..562f5c9 100644
--- a/social/src/main/java/com/jiagutech/ams/model/response/DeviceInfo.java
+++ b/social/src/main/java/com/jiagutech/ams/model/response/DeviceInfo.java
@@ -15,8 +15,8 @@ import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class DeviceInfo {
- @JsonSerialize(using = ToStringSerializer.class)
- private long deviceId;
+
+ private int deviceId;
private double lat;
@@ -28,4 +28,8 @@ public class DeviceInfo {
private String boxNum;
+ private String name;
+
+ private String licensePlate;
+
}
diff --git a/social/src/main/java/com/jiagutech/ams/model/response/JobCreateResponse.java b/social/src/main/java/com/jiagutech/ams/model/response/JobCreateResponse.java
index b0cf77d..f5ff1f1 100644
--- a/social/src/main/java/com/jiagutech/ams/model/response/JobCreateResponse.java
+++ b/social/src/main/java/com/jiagutech/ams/model/response/JobCreateResponse.java
@@ -22,7 +22,7 @@ public class JobCreateResponse {
private long farmerId;
- private long deviceId;
+ private int deviceId;
private Integer status;
diff --git a/social/src/main/java/com/jiagutech/ams/model/response/JobItem.java b/social/src/main/java/com/jiagutech/ams/model/response/JobItem.java
index f11f209..affa9e1 100644
--- a/social/src/main/java/com/jiagutech/ams/model/response/JobItem.java
+++ b/social/src/main/java/com/jiagutech/ams/model/response/JobItem.java
@@ -55,13 +55,20 @@ public class JobItem {
@JsonSerialize(using = ToStringSerializer.class)
private Long deviceId;
@ExcelIgnore
- private long deptId;
+ private int deptId;
@ExcelProperty(value = "合作社")
private String deptName;
@ExcelProperty(value = "作业地区")
private String regionName;
-
+ @ExcelProperty(value = "联系人电话")
+ private String contactPhone;
+ @ExcelIgnore
private int duration;
-
+ @ExcelProperty(value = "作业设备")
+ private String deviceName;
+ @ExcelProperty(value = "车牌号")
+ private String licensePlate;
+ @ExcelProperty(value = "盒子编号")
+ private String boxNum;
}
diff --git a/social/src/main/java/com/jiagutech/ams/service/DeviceService.java b/social/src/main/java/com/jiagutech/ams/service/DeviceService.java
index 02a246f..77ce3db 100644
--- a/social/src/main/java/com/jiagutech/ams/service/DeviceService.java
+++ b/social/src/main/java/com/jiagutech/ams/service/DeviceService.java
@@ -11,4 +11,6 @@ public interface DeviceService {
List onlineAndRound(double maxLng, double maxLat, double minLng, double minLat);
PageResult page(PageRequest pageRequest);
+
+ List deviceList();
}
diff --git a/social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java b/social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java
index cf4d51e..2e8f297 100644
--- a/social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java
+++ b/social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java
@@ -1,34 +1,28 @@
package com.jiagutech.ams.service;
-import cn.dev33.satoken.annotation.SaCheckLogin;
-import cn.dev33.satoken.annotation.SaCheckRole;
-import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-import com.jiagutech.ams.constant.UserConstants;
import com.jiagutech.ams.mapper.DeviceMapper;
+import com.jiagutech.ams.model.DeviceMapping;
import com.jiagutech.ams.model.LoginUser;
import com.jiagutech.ams.model.TrackDataJG;
import com.jiagutech.ams.model.common.PageRequest;
import com.jiagutech.ams.model.common.PageResult;
import com.jiagutech.ams.model.dto.DeviceDTO;
+import com.jiagutech.ams.model.dto.RoleDTO;
import com.jiagutech.ams.model.response.DeviceInfo;
-import com.jiagutech.ams.model.response.JobItem;
+import com.jiagutech.ams.utils.LoginUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
-import java.lang.reflect.Type;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
-import java.util.stream.Collectors;
/**
* @ClassName DeviceServiceImpl
@@ -49,23 +43,20 @@ public class DeviceServiceImpl implements DeviceService {
public List onlineAndRound(double maxLng, double maxLat, double minLng, double minLat) {
Set keys = stringRedisTemplate.keys(TRACK_PREFIX_REDIS_KEY);
List deviceInfos = new ArrayList<>();
-
- DeviceInfo deviceInfo1 = new DeviceInfo().setBoxNum("0").setStatus(2).setDeviceId(321).setBoxNum("5ds3a22w").setLng(118.73929470486111).setLat(31.9823046875);
- deviceInfos.add(deviceInfo1);
if (CollectionUtils.isNotEmpty(keys)) {
List values = stringRedisTemplate.opsForValue().multiGet(keys);
if (CollectionUtils.isEmpty(values)) {
return deviceInfos;
}
- List trackDataJGS = values.stream().map(s -> JSON.parseObject(s, TrackDataJG.class)).collect(Collectors.toList());
+ List trackDataJGS = values.stream().map(s -> JSON.parseObject(s, TrackDataJG.class)).toList();
Predicate predicate = t -> t.getLat() <= maxLat && t.getLat() >= minLat
&& ((t.getLng() >= -180 && t.getLng() <= maxLng) || (t.getLng() >= minLng && t.getLng() <= 180));
- if (maxLat==0 && minLat==0 && maxLng==0 && minLng==0){
- predicate = t-> true;
+ if (maxLat == 0 && minLat == 0 && maxLng == 0 && minLng == 0) {
+ predicate = t -> true;
}
Consumer consumer = t -> deviceInfos.add(new DeviceInfo().setBoxNum(t.getDroneId()).setLng(t.getLng()).setLat(t.getLat()));
trackDataJGS.stream().filter(predicate).forEach(consumer);
- LoginUser loginUser = StpUtil.getSession().get(UserConstants.SYS_SESSION, new LoginUser());
+ LoginUser loginUser = LoginUtil.getLoginUser();
if (loginUser != null && loginUser.getDept() != null) {
long deptId = loginUser.getDept().getId();
List deviceInfos1 = deviceMapper.queryDeviceList(deptId);
@@ -90,9 +81,43 @@ public class DeviceServiceImpl implements DeviceService {
public PageResult page(PageRequest pageRequest) {
Page page = new Page(pageRequest.getPageNum(), pageRequest.getPageSize());
QueryWrapper queryWrapper = Wrappers.query();
- LoginUser loginUser = StpUtil.getSession().get(UserConstants.SYS_SESSION, new LoginUser());
+ LoginUser loginUser = LoginUtil.getLoginUser();
queryWrapper.eq("dept_id", loginUser.getDept().getId());
Page result = deviceMapper.selectPage(page, queryWrapper);
return PageResult.of((int) result.getTotal(), (int) pageRequest.getPageSize(), (int) result.getCurrent(), result.getRecords());
}
+
+ @Override
+ public List deviceList() {
+ LoginUser loginUser = LoginUtil.getLoginUser();
+ QueryWrapper queryWrapper = Wrappers.query();
+ Predicate predicate1 = r -> r.getKey().equals("manager");
+
+ boolean hasManager = loginUser.getRoles().stream().anyMatch(predicate1);
+ if (hasManager) {
+ queryWrapper.eq("dept_id", loginUser.getDept().getId());
+ }
+ List deviceDTOS = deviceMapper.selectList(queryWrapper);
+
+ Set keys = stringRedisTemplate.keys(TRACK_PREFIX_REDIS_KEY);
+ List deviceInfos = new ArrayList<>();
+ deviceDTOS.forEach(deviceDTO -> {
+ DeviceInfo deviceInfo = DeviceMapping.INSTANCE.convertDeviceInfo(deviceDTO);
+ Optional isOnline = keys.stream().filter(s -> s.contains(deviceDTO.getBoxNum())).findFirst();
+ if (isOnline.isPresent()) {
+ String s = stringRedisTemplate.opsForValue().get(isOnline.get());
+ TrackDataJG trackDataJG = JSON.parseObject(s, TrackDataJG.class);
+ deviceInfo.setStatus(1);
+ assert trackDataJG != null;
+ deviceInfo.setLng(trackDataJG.getLng());
+ deviceInfo.setLat(trackDataJG.getLat());
+ } else {
+ deviceInfo.setStatus(2);
+ }
+
+ deviceInfos.add(deviceInfo);
+ });
+
+ return deviceInfos;
+ }
}
diff --git a/social/src/main/java/com/jiagutech/ams/service/JobServiceImpl.java b/social/src/main/java/com/jiagutech/ams/service/JobServiceImpl.java
index 0beca90..5d581cd 100644
--- a/social/src/main/java/com/jiagutech/ams/service/JobServiceImpl.java
+++ b/social/src/main/java/com/jiagutech/ams/service/JobServiceImpl.java
@@ -23,6 +23,7 @@ import com.jiagutech.ams.model.response.JobItem;
import com.jiagutech.ams.model.response.JobPolyItem;
import com.jiagutech.ams.rest.TrackRestClient;
import com.jiagutech.ams.utils.ExcelUtil;
+import com.jiagutech.ams.utils.LoginUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -66,7 +67,7 @@ public class JobServiceImpl implements JobService {
@Override
public JobCreateResponse createJob(JobCreateRequest jobCreateRequest) {
- LoginUser loginUser = StpUtil.getSession().get(UserConstants.SYS_SESSION, new LoginUser());
+ LoginUser loginUser = LoginUtil.getLoginUser();
log.info("create job, loginUser: {}", loginUser);
if (CollectionUtil.isNotEmpty(inJob())) {
throw new BusinessException(BizCode.NOT_ALLOWABLE);
@@ -107,7 +108,7 @@ public class JobServiceImpl implements JobService {
public List inJob() {
QueryWrapper queryWrapper = Wrappers.query();
queryWrapper.eq("operator_id", StpUtil.getLoginIdAsLong()).eq("status", 1);
- return jobMapper.jobList(queryWrapper);
+ return jobMapper.inJob(queryWrapper);
}
@Override
@@ -154,10 +155,7 @@ public class JobServiceImpl implements JobService {
for (Locus locus : locusList) {
TrackItem trackItem = TrackMapping.INSTANCE.convertToTrackItemByLocus(locus);
Optional imageDTOOptional = trackImageDTOS.stream().filter(t -> t.getTs().equals(locus.getTimestamp())).findFirst();
- if (imageDTOOptional.isPresent()) {
- trackItem.setImageUrl(imageDTOOptional.get().getImageUrl());
-
- }
+ imageDTOOptional.ifPresent(trackImageDTO -> trackItem.setImageUrl(trackImageDTO.getImageUrl()));
trackItems.add(trackItem);
}
return trackItems;
@@ -199,10 +197,13 @@ public class JobServiceImpl implements JobService {
if (requestParam.getRegionCode() != 0l) {
queryWrapper.eq("j.region_code", requestParam.getRegionCode());
}
+ if (requestParam.getDeviceId() != 0l) {
+ queryWrapper.eq("j.device_id", requestParam.getDeviceId());
+ }
}
- LoginUser loginUser = StpUtil.getSession().get(UserConstants.SYS_SESSION, new LoginUser());
+ LoginUser loginUser = LoginUtil.getLoginUser();
Predicate predicate1 = r -> r.getKey().equals("manager");
Predicate predicate2 = r -> r.getKey().equals("gov");
Predicate predicate3 = r -> r.getKey().equals("machinist");
diff --git a/social/src/main/java/com/jiagutech/ams/service/RegionServiceImpl.java b/social/src/main/java/com/jiagutech/ams/service/RegionServiceImpl.java
index ae48cc2..9e64b77 100644
--- a/social/src/main/java/com/jiagutech/ams/service/RegionServiceImpl.java
+++ b/social/src/main/java/com/jiagutech/ams/service/RegionServiceImpl.java
@@ -10,6 +10,7 @@ import com.jiagutech.ams.model.dto.RegionDTO;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
+import com.jiagutech.ams.utils.LoginUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -33,7 +34,7 @@ public class RegionServiceImpl implements RegionService {
@Override
public List getHistoryJobRegions() {
- LoginUser currentUser = StpUtil.getSession().get(UserConstants.SYS_SESSION, new LoginUser());
+ LoginUser currentUser = LoginUtil.getLoginUser();
if (ObjectUtil.isNotNull(currentUser)) {
return regionMapper.selectHistoryJobRegions(currentUser.getDept().getId());
}
diff --git a/social/src/main/java/com/jiagutech/ams/service/SortieService.java b/social/src/main/java/com/jiagutech/ams/service/SortieService.java
index 63c70be..486ad4c 100644
--- a/social/src/main/java/com/jiagutech/ams/service/SortieService.java
+++ b/social/src/main/java/com/jiagutech/ams/service/SortieService.java
@@ -2,16 +2,23 @@ package com.jiagutech.ams.service;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.jiagutech.ams.mapper.DeviceMapper;
import com.jiagutech.ams.mapper.SortieMapper;
import com.jiagutech.ams.model.SortieMapping;
import com.jiagutech.ams.model.UavSortie;
+import com.jiagutech.ams.model.dto.DeviceDTO;
import com.jiagutech.ams.model.dto.SortieDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+
/**
* @ClassName SortieService
* @author: zhangyeguang
@@ -25,21 +32,31 @@ import org.springframework.stereotype.Component;
public class SortieService {
private final SortieMapper sortieMapper;
+ private final DeviceMapper deviceMapper;
- @RabbitListener(queues = "queue_amssortie_social")
- public void receiveMessage(String message) {
- log.info("receiveMessage: {}", message);
+ @RabbitListener(queues = "queue_ams_social_sortie")
+ public void receiveMessage(Message message) {
+ byte[] body = message.getBody();
+ String jsonString = new String(body, StandardCharsets.UTF_8);
+ log.info("receiveMessage: {}", jsonString);
try {
- UavSortie uavSortie = JSON.parseObject(message, UavSortie.class);
+ UavSortie uavSortie = JSON.parseObject(jsonString, UavSortie.class);
SortieDTO sortieDTO = SortieMapping.INSTANCE.convertToSortieDTOByUavSortie(uavSortie);
- SortieDTO hasSorties = sortieMapper.selectOne(Wrappers.lambdaQuery(SortieDTO.class).eq(SortieDTO::getVehicleId, uavSortie.getStartTime()));
+ SortieDTO hasSorties = sortieMapper.selectOne(Wrappers.lambdaQuery(SortieDTO.class).eq(SortieDTO::getVehicleId, sortieDTO.getVehicleId())
+ .eq(SortieDTO::getStartAt, sortieDTO.getStartAt()));
if (ObjectUtil.isNotEmpty(sortieDTO)) {
if (ObjectUtil.isNotEmpty(hasSorties)) {
sortieDTO.setId(hasSorties.getId());
sortieMapper.updateById(sortieDTO);
- return;
+
+ } else {
+ sortieMapper.insert(sortieDTO);
}
- sortieMapper.insert(sortieDTO);
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.lambda().eq(DeviceDTO::getBoxNum, sortieDTO.getVehicleId()).lt(DeviceDTO::getUpdateTime, sortieDTO.getEndAt());
+ DeviceDTO deviceDTO = new DeviceDTO().setUpdateTime(sortieDTO.getEndAt()).setLat(sortieDTO.getLatitude()).setLng(sortieDTO.getLongitude());
+ deviceMapper.update(deviceDTO,queryWrapper);
+
}
} catch (Exception e) {
log.error("receiveMessage error", e);
diff --git a/social/src/main/resources/mapper/DeviceMapper.xml b/social/src/main/resources/mapper/DeviceMapper.xml
index d78647b..01ecb11 100644
--- a/social/src/main/resources/mapper/DeviceMapper.xml
+++ b/social/src/main/resources/mapper/DeviceMapper.xml
@@ -4,7 +4,9 @@