Browse Source

完善功能

master
zhangyeguang 3 months ago
parent
commit
05d1e0f2f0
  1. 27
      common/pom.xml
  2. 2
      common/src/main/java/com/jiagutech/ams/model/LoginUser.java
  3. 25
      common/src/main/java/com/jiagutech/ams/utils/LoginUtil.java
  4. 15
      pom.xml
  5. 14
      publish.sh
  6. 22
      social/pom.xml
  7. 15
      social/src/main/java/com/jiagutech/ams/controller/DeviceController.java
  8. 37
      social/src/main/java/com/jiagutech/ams/listener/JobFinishListener.java
  9. 2
      social/src/main/java/com/jiagutech/ams/mapper/JobMapper.java
  10. 17
      social/src/main/java/com/jiagutech/ams/model/DeviceMapping.java
  11. 2
      social/src/main/java/com/jiagutech/ams/model/UavSortie.java
  12. 12
      social/src/main/java/com/jiagutech/ams/model/dto/DeviceDTO.java
  13. 5
      social/src/main/java/com/jiagutech/ams/model/dto/JobDTO.java
  14. 2
      social/src/main/java/com/jiagutech/ams/model/request/JobCreateRequest.java
  15. 8
      social/src/main/java/com/jiagutech/ams/model/response/DeviceInfo.java
  16. 2
      social/src/main/java/com/jiagutech/ams/model/response/JobCreateResponse.java
  17. 13
      social/src/main/java/com/jiagutech/ams/model/response/JobItem.java
  18. 2
      social/src/main/java/com/jiagutech/ams/service/DeviceService.java
  19. 59
      social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java
  20. 15
      social/src/main/java/com/jiagutech/ams/service/JobServiceImpl.java
  21. 3
      social/src/main/java/com/jiagutech/ams/service/RegionServiceImpl.java
  22. 31
      social/src/main/java/com/jiagutech/ams/service/SortieService.java
  23. 4
      social/src/main/resources/mapper/DeviceMapper.xml
  24. 40
      social/src/main/resources/mapper/JobMapper.xml
  25. 14
      system/pom.xml
  26. 3
      system/src/main/java/com/jiagutech/ams/controller/UserController.java
  27. 2
      system/src/main/java/com/jiagutech/ams/model/request/UserRequest.java
  28. 3
      system/src/main/java/com/jiagutech/ams/service/DeptServcieImpl.java
  29. 16
      system/src/main/java/com/jiagutech/ams/service/UserServiceImpl.java
  30. 3
      system/src/main/resources/mapper/UserMapper.xml
  31. 11
      web/pom.xml
  32. 2
      web/src/main/java/com/jiagutech/ams/SocialApplication.java
  33. 13
      web/src/main/java/com/jiagutech/ams/common/RabbitConfig.java
  34. 3
      web/src/main/java/com/jiagutech/ams/config/SaPermissionImpl.java
  35. 2
      web/src/main/resources/application-dev.yml
  36. 28
      web/src/main/resources/application-prod.yml
  37. 2
      web/src/main/resources/application.yml

27
common/pom.xml

@ -10,7 +10,6 @@
</parent>
<artifactId>common</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
@ -45,17 +44,6 @@
<artifactId>orika-core</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.5.Final</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.5.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
@ -101,7 +89,20 @@
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot3-starter</artifactId>
</dependency>
</dependencies>
</project>

2
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;
}

25
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);
}
}
}

15
pom.xml

@ -27,6 +27,7 @@
<spring-boot.version>3.1.7</spring-boot.version>
<satoken.version>1.37.0</satoken.version>
<poi.version>5.2.5</poi.version>
<mapstruct.version>1.6.1</mapstruct.version>
<easyexcel.version>3.3.2</easyexcel.version>
<springdoc.version>2.2.0</springdoc.version>
@ -37,7 +38,7 @@
<mapstruct-plus.version>1.3.5</mapstruct-plus.version>
<!-- 插件版本 -->
<maven-jar-plugin.version>3.2.2</maven-jar-plugin.version>
<maven-compiler-plugin.verison>3.11.0</maven-compiler-plugin.verison>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
<flatten-maven-plugin.version>1.3.0</flatten-maven-plugin.version>
</properties>
@ -186,7 +187,17 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

14
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 "部署完成"

22
social/pom.xml

@ -67,17 +67,13 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.5.Final</version>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.5.Final</version>
<scope>compile</scope>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
@ -99,6 +95,16 @@
<artifactId>proj4j</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

15
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<List<DeviceInfo>> 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<PageResult<DeviceDTO>> page(@RequestBody PageRequest<Void> pageRequest) {
return R.ok(deviceService.page(pageRequest));
}
@Operation(summary = "获取所有设备列表")
@GetMapping("/list")
public R<List<DeviceInfo>> list() {
return R.ok(deviceService.deviceList());
}
}

37
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<TrackItem> 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<TrackItem> trackList) {
try {
if (CollectionUtil.isEmpty(trackList)) {
return 0.0f;
}
List<FlightTrackerUtils.PointTemp> 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;
}
}
}

2
social/src/main/java/com/jiagutech/ams/mapper/JobMapper.java

@ -17,4 +17,6 @@ public interface JobMapper extends BaseMapper<JobDTO> {
List<JobItem> jobList(@Param("ew") QueryWrapper wrapper);
List<JobItem> jobListCountByFarmer(@Param("ew") QueryWrapper wrapper);
List<JobItem> inJob(@Param("ew") QueryWrapper<JobItem> queryWrapper);
}

17
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);
}

2
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;

12
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;
}

5
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;
}

2
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;
/**
* 作业类型
*/

8
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;
}

2
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;

13
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;
}

2
social/src/main/java/com/jiagutech/ams/service/DeviceService.java

@ -11,4 +11,6 @@ public interface DeviceService {
List<DeviceInfo> onlineAndRound(double maxLng, double maxLat, double minLng, double minLat);
PageResult<DeviceDTO> page(PageRequest<Void> pageRequest);
List<DeviceInfo> deviceList();
}

59
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<DeviceInfo> onlineAndRound(double maxLng, double maxLat, double minLng, double minLat) {
Set<String> keys = stringRedisTemplate.keys(TRACK_PREFIX_REDIS_KEY);
List<DeviceInfo> 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<String> values = stringRedisTemplate.opsForValue().multiGet(keys);
if (CollectionUtils.isEmpty(values)) {
return deviceInfos;
}
List<TrackDataJG> trackDataJGS = values.stream().map(s -> JSON.parseObject(s, TrackDataJG.class)).collect(Collectors.toList());
List<TrackDataJG> trackDataJGS = values.stream().map(s -> JSON.parseObject(s, TrackDataJG.class)).toList();
Predicate<TrackDataJG> 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<TrackDataJG> 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<DeviceInfo> deviceInfos1 = deviceMapper.queryDeviceList(deptId);
@ -90,9 +81,43 @@ public class DeviceServiceImpl implements DeviceService {
public PageResult<DeviceDTO> page(PageRequest<Void> pageRequest) {
Page<DeviceDTO> page = new Page(pageRequest.getPageNum(), pageRequest.getPageSize());
QueryWrapper<DeviceDTO> 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<DeviceDTO> result = deviceMapper.selectPage(page, queryWrapper);
return PageResult.of((int) result.getTotal(), (int) pageRequest.getPageSize(), (int) result.getCurrent(), result.getRecords());
}
@Override
public List<DeviceInfo> deviceList() {
LoginUser loginUser = LoginUtil.getLoginUser();
QueryWrapper<DeviceDTO> queryWrapper = Wrappers.query();
Predicate<RoleDTO> predicate1 = r -> r.getKey().equals("manager");
boolean hasManager = loginUser.getRoles().stream().anyMatch(predicate1);
if (hasManager) {
queryWrapper.eq("dept_id", loginUser.getDept().getId());
}
List<DeviceDTO> deviceDTOS = deviceMapper.selectList(queryWrapper);
Set<String> keys = stringRedisTemplate.keys(TRACK_PREFIX_REDIS_KEY);
List<DeviceInfo> deviceInfos = new ArrayList<>();
deviceDTOS.forEach(deviceDTO -> {
DeviceInfo deviceInfo = DeviceMapping.INSTANCE.convertDeviceInfo(deviceDTO);
Optional<String> 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;
}
}

15
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<JobItem> inJob() {
QueryWrapper<JobItem> 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<TrackImageDTO> 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<RoleDTO> predicate1 = r -> r.getKey().equals("manager");
Predicate<RoleDTO> predicate2 = r -> r.getKey().equals("gov");
Predicate<RoleDTO> predicate3 = r -> r.getKey().equals("machinist");

3
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<RegionE> 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());
}

31
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<DeviceDTO> 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);

4
social/src/main/resources/mapper/DeviceMapper.xml

@ -4,7 +4,9 @@
<select id="queryDeviceList" resultType="com.jiagutech.ams.model.response.DeviceInfo">
select d.id as deviceId, d.device_num, d.box_num, d.dept_id, case when j.status = 1 then 1 else 0 end as status
select d.id as deviceId, d.device_num, d.box_num, d.dept_id,
d.name,d.license_plate,
case when j.status = 1 then 1 else 0 end as status
from ams_device_info d
left join ams_job_info j on d.id = j.device_id
where d.dept_id = #{deptId}

40
social/src/main/resources/mapper/JobMapper.xml

@ -9,6 +9,9 @@
j.area,
j.status,
j.device_id,
dd.name as deviceName,
dd.license_plate,
dd.box_num,
j.operator_id,
j.duration,
FROM_UNIXTIME(j.start_time / 1000, '%Y-%m-%d %H:%i:%s') as start_time_str,
@ -27,6 +30,7 @@
left join ams_dept d on j.dept_id = d.id
left join ams_user u1 on j.operator_id = u1.id
left join ams_user u2 on j.farmer_id = u2.id
left join ams_device_info dd on j.device_id = dd.id
</sql>
<sql id="jobItem2">
@ -36,12 +40,16 @@
j.area,
j.status,
j.device_id,
dd.name as deviceName,
dd.license_plate,
dd.box_num,
j.operator_id,
j.duration,
FROM_UNIXTIME(j.start_time / 1000, '%Y-%m-%d %H:%i:%s') as start_time_str,
j.farmer_id,
u2.nick_name as farmer_name,
CONCAT(LEFT(u2.phone, 3), '****', RIGHT(u2.phone, 4)) as farmer_phone,
case u2.phone when null then '' when '' then '' else CONCAT(LEFT(u2.phone, 3), '****', RIGHT(u2.phone, 4)) end as farmer_phone,
case u2.contact_phone when null then '' when '' then '' else CONCAT(LEFT(u2.contact_phone, 3), '****', RIGHT(u2.contact_phone, 4)) end as contact_phone,
u2.region_name,
j.job_type,
t.name as type_name,
@ -51,6 +59,8 @@
left join ams_job_type t on j.job_type = t.id
left join ams_dept d on j.dept_id = d.id
left join ams_user u2 on j.farmer_id = u2.id
left join ams_device_info dd on j.device_id = dd.id
</sql>
<select id="jobPage" resultType="com.jiagutech.ams.model.response.JobItem">
@ -62,6 +72,32 @@
<include refid="jobItem2"></include>
${ew.getCustomSqlSegment} order by j.farmer_id,j.start_time
</select>
<select id="inJob">
select j.id as job_id,
j.start_time,
j.end_time,
j.area,
j.status,
j.device_id,
j.operator_id,
j.duration,
FROM_UNIXTIME(j.start_time / 1000, '%Y-%m-%d %H:%i:%s') as start_time_str,
j.farmer_id,
u2.nick_name as farmer_name,
u2.phone as farmer_phone,
u2.contact_phone as contact_phone,
u2.region_name,
j.job_type,
t.name as type_name,
d.id as dept_id,
d.name as dept_name
from ams_job_info j
left join ams_job_type t on j.job_type = t.id
left join ams_dept d on j.dept_id = d.id
left join ams_user u2 on j.farmer_id = u2.id
${ew.getCustomSqlSegment} order by j.farmer_id,j.start_time
</select>
<select id="jobListCountByFarmer" resultType="com.jiagutech.ams.model.response.JobItem">
select ROUND(sum(j.area), 2) as area,
j.farmer_id,
@ -83,4 +119,6 @@
</select>
</mapper>

14
system/pom.xml

@ -30,7 +30,6 @@
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
@ -52,12 +51,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>1.5.4</version>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot3-starter</artifactId>
@ -75,4 +78,5 @@
</dependencies>
</project>

3
system/src/main/java/com/jiagutech/ams/controller/UserController.java

@ -13,6 +13,7 @@ import com.jiagutech.ams.model.request.UserRequest;
import com.jiagutech.ams.model.response.LoginResponse;
import com.jiagutech.ams.model.UserDetail;
import com.jiagutech.ams.service.UserService;
import com.jiagutech.ams.utils.LoginUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
@ -53,7 +54,7 @@ public class UserController {
@Operation(summary = "获取用户登陆信息")
@GetMapping("/getUserInfo")
public R<LoginUser> getUserInfo() {
return R.ok(StpUtil.getSession().get(UserConstants.SYS_SESSION, new LoginUser()));
return R.ok(LoginUtil.getLoginUser());
}
@Operation(summary = "获取用户详情")

2
system/src/main/java/com/jiagutech/ams/model/request/UserRequest.java

@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.deser.std.NumberDeserializers;
import com.jiagutech.ams.utils.StringToLongDeserializer;
import jakarta.validation.constraints.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
/**
@ -16,6 +17,7 @@ import lombok.NonNull;
* @description:
**/
@Data
@NoArgsConstructor
public class UserRequest {
/**
* 用户ID

3
system/src/main/java/com/jiagutech/ams/service/DeptServcieImpl.java

@ -10,6 +10,7 @@ import com.jiagutech.ams.model.LoginUser;
import com.jiagutech.ams.model.common.PageRequest;
import com.jiagutech.ams.model.common.PageResult;
import com.jiagutech.ams.model.request.DeptPageRequest;
import com.jiagutech.ams.utils.LoginUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@ -29,7 +30,7 @@ public class DeptServcieImpl implements DeptService {
DeptPageRequest requestParam = pageRequest.getRequest();
Page<DeptItem> page = new Page(pageRequest.getPageNum(), pageRequest.getPageSize());
LoginUser loginUser = StpUtil.getSession().get(UserConstants.SYS_SESSION,new LoginUser());
LoginUser loginUser = LoginUtil.getLoginUser();
Page<DeptItem> result = deptMapper.deptPage(page,requestParam!=null ?requestParam.getDeptName():null, loginUser.getRegionPath());
return PageResult.of((int) result.getTotal(), (int) result.getSize(), (int) result.getCurrent(), result.getRecords());

16
system/src/main/java/com/jiagutech/ams/service/UserServiceImpl.java

@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jiagutech.ams.constant.GlobalConstants;
import com.jiagutech.ams.constant.UserConstants;
import com.jiagutech.ams.exception.BizCode;
@ -31,6 +33,7 @@ import com.jiagutech.ams.model.request.PageUserRequest;
import com.jiagutech.ams.model.request.UserFarmerRequest;
import com.jiagutech.ams.model.request.UserRequest;
import com.jiagutech.ams.model.response.LoginResponse;
import com.jiagutech.ams.utils.LoginUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
@ -75,7 +78,7 @@ public class UserServiceImpl implements UserService {
throw new BusinessException(BizCode.USER_NOT_FOUND);
}
Predicate<RoleDTO> predicate = role -> role.getKey().equals("manager") || role.getKey().equals("machinist");
Predicate<RoleDTO> predicate = role -> role.getKey().equals("admin") || role.getKey().equals("manager") || role.getKey().equals("machinist");
if (clientType == 2 && user.getRoles().stream().noneMatch(predicate)) {
throw new BusinessException(BizCode.LOGIN_TYPE_ERROR);
}
@ -85,7 +88,14 @@ public class UserServiceImpl implements UserService {
}
StpUtil.login(user.getUserId());
user.setLoginTime(System.currentTimeMillis());
StpUtil.getSession().set(UserConstants.SYS_SESSION, user);
ObjectMapper objectMapper = new ObjectMapper();
try {
String jsonString = objectMapper.writeValueAsString(user);
StpUtil.getSession().set(UserConstants.SYS_SESSION, jsonString);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
LoginResponse loginVO = new LoginResponse();
loginVO.setAccessToken(StpUtil.getTokenValue());
loginVO.setExpireIn(StpUtil.getTokenTimeout());
@ -204,7 +214,7 @@ public class UserServiceImpl implements UserService {
}
}
LoginUser loginUser = StpUtil.getSession().get(UserConstants.SYS_SESSION, new LoginUser());
LoginUser loginUser = LoginUtil.getLoginUser();
Predicate<RoleDTO> predicate1 = r -> r.getKey().equals("manager");
Predicate<RoleDTO> predicate2 = r -> r.getKey().equals("gov");
Predicate<RoleDTO> predicate3 = r -> r.getKey().equals("machinist");

3
system/src/main/resources/mapper/UserMapper.xml

@ -26,7 +26,8 @@
create_time,
password,
avatar,
region_path
region_path,
region_name
from ams_user
where phone = #{phone}
and del_flag = 0

11
web/pom.xml

@ -10,6 +10,8 @@
</parent>
<artifactId>web</artifactId>
<packaging>jar</packaging>
<name>ams-social</name>
<properties>
<maven.compiler.source>17</maven.compiler.source>
@ -91,7 +93,6 @@
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.3.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
@ -103,6 +104,7 @@
</dependency>
</dependencies>
<build>
<finalName>${project.parent.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
@ -131,16 +133,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>17</source>
<target>17</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.3.Final</version>
</path>
<!-- 添加 Lombok 注解处理器 -->
<path>
<groupId>org.projectlombok</groupId>

2
web/src/main/java/com/jiagutech/ams/SocialApplication.java

@ -2,6 +2,7 @@ package com.jiagutech.ams;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
/**
* @ClassName SocialApplication
@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @Version 1.0
* @description:
**/
@EnableAsync
@SpringBootApplication
public class SocialApplication {
public static void main(String[] args) {

13
web/src/main/java/com/jiagutech/ams/common/RabbitConfig.java

@ -1,6 +1,9 @@
package com.jiagutech.ams.common;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -14,7 +17,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class RabbitConfig {
public static final String EXCHANGE_NAME = "topic.exchange";
public static final String QUEUE_FARM_SORTIE = "queue_amssortie_social";
public static final String QUEUE_FARM_SORTIE = "queue_ams_social_sortie";
@Bean
public Exchange exchange() {
@ -30,7 +33,13 @@ public class RabbitConfig {
@Bean
public Binding bindingFarmSortie() {
return BindingBuilder.bind(farmsortieQueue()).to(exchange()).with("#.farmsortie").noargs();
return BindingBuilder.bind(farmsortieQueue()).to(exchange()).with("ams.sortie.key").noargs();
}
@Bean
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
return rabbitTemplate;
}
}

3
web/src/main/java/com/jiagutech/ams/config/SaPermissionImpl.java

@ -4,6 +4,7 @@ import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import com.jiagutech.ams.constant.UserConstants;
import com.jiagutech.ams.model.LoginUser;
import com.jiagutech.ams.utils.LoginUtil;
import java.util.ArrayList;
@ -30,7 +31,7 @@ public class SaPermissionImpl implements StpInterface {
*/
@Override
public List<String> getRoleList(Object loginId, String loginType) {
LoginUser loginUser = StpUtil.getSession().get(UserConstants.SYS_SESSION, new LoginUser());
LoginUser loginUser = LoginUtil.getLoginUser();
if (loginUser == null || loginUser.getRoles() == null) {
return new ArrayList<>();
}

2
web/src/main/resources/application-dev.yml

@ -12,7 +12,7 @@ spring:
redis:
host: 192.168.10.111
port: 6379
database: 10
database: 11
rabbitmq:
host: 192.168.10.111
port: 5672

28
web/src/main/resources/application-prod.yml

@ -0,0 +1,28 @@
spring:
datasource:
# url: jdbc:mysql://192.168.10.111:23306/ams_social?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
# username: root
# password: 123456
url: jdbc:mysql://192.168.1.200:3306/ams_social?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
username: root
password: Jiagu*2058
data:
redis:
host: 192.168.1.13
port: 6379
database: 11
password: Test123
rabbitmq:
host: 192.168.1.195
port: 5672
username: jiagu
password: jiagu2058
center-track:
client:
url: http://192.168.0.17:11003/iot/farm/track

2
web/src/main/resources/application.yml

@ -1,5 +1,5 @@
server:
port: 8181
port: 8182
spring:
profiles:

Loading…
Cancel
Save