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 @@ @@ -62,6 +72,32 @@ ${ew.getCustomSqlSegment} order by j.farmer_id,j.start_time + + + + \ No newline at end of file diff --git a/system/pom.xml b/system/pom.xml index e3f0c39..012fa93 100644 --- a/system/pom.xml +++ b/system/pom.xml @@ -30,7 +30,6 @@ - cn.hutool hutool-core @@ -52,12 +51,16 @@ org.springframework.boot spring-boot-starter-validation - - ma.glasnost.orika - orika-core - 1.5.4 + org.mapstruct + mapstruct + + + org.mapstruct + mapstruct-processor + provided + cn.dev33 sa-token-spring-boot3-starter @@ -75,4 +78,5 @@ + \ No newline at end of file diff --git a/system/src/main/java/com/jiagutech/ams/controller/UserController.java b/system/src/main/java/com/jiagutech/ams/controller/UserController.java index a7f585e..fd51f75 100644 --- a/system/src/main/java/com/jiagutech/ams/controller/UserController.java +++ b/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 getUserInfo() { - return R.ok(StpUtil.getSession().get(UserConstants.SYS_SESSION, new LoginUser())); + return R.ok(LoginUtil.getLoginUser()); } @Operation(summary = "获取用户详情") diff --git a/system/src/main/java/com/jiagutech/ams/model/request/UserRequest.java b/system/src/main/java/com/jiagutech/ams/model/request/UserRequest.java index 52fe691..7598cf1 100644 --- a/system/src/main/java/com/jiagutech/ams/model/request/UserRequest.java +++ b/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 diff --git a/system/src/main/java/com/jiagutech/ams/service/DeptServcieImpl.java b/system/src/main/java/com/jiagutech/ams/service/DeptServcieImpl.java index 4700fa4..270dd26 100644 --- a/system/src/main/java/com/jiagutech/ams/service/DeptServcieImpl.java +++ b/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 page = new Page(pageRequest.getPageNum(), pageRequest.getPageSize()); - LoginUser loginUser = StpUtil.getSession().get(UserConstants.SYS_SESSION,new LoginUser()); + LoginUser loginUser = LoginUtil.getLoginUser(); Page 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()); diff --git a/system/src/main/java/com/jiagutech/ams/service/UserServiceImpl.java b/system/src/main/java/com/jiagutech/ams/service/UserServiceImpl.java index 1f8057b..ccb148c 100644 --- a/system/src/main/java/com/jiagutech/ams/service/UserServiceImpl.java +++ b/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 predicate = role -> role.getKey().equals("manager") || role.getKey().equals("machinist"); + Predicate 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 predicate1 = r -> r.getKey().equals("manager"); Predicate predicate2 = r -> r.getKey().equals("gov"); Predicate predicate3 = r -> r.getKey().equals("machinist"); diff --git a/system/src/main/resources/mapper/UserMapper.xml b/system/src/main/resources/mapper/UserMapper.xml index 08517e0..1e8a73a 100644 --- a/system/src/main/resources/mapper/UserMapper.xml +++ b/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 diff --git a/web/pom.xml b/web/pom.xml index 1c7c09a..2bc9869 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -10,6 +10,8 @@ web + jar + ams-social 17 @@ -91,7 +93,6 @@ org.mapstruct mapstruct - 1.5.3.Final org.springframework.amqp @@ -103,6 +104,7 @@ + ${project.parent.artifactId} src/main/resources @@ -131,16 +133,11 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + ${maven-compiler-plugin.version} 17 17 - - org.mapstruct - mapstruct-processor - 1.5.3.Final - org.projectlombok diff --git a/web/src/main/java/com/jiagutech/ams/SocialApplication.java b/web/src/main/java/com/jiagutech/ams/SocialApplication.java index 24f64ea..0e1069a 100644 --- a/web/src/main/java/com/jiagutech/ams/SocialApplication.java +++ b/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) { diff --git a/web/src/main/java/com/jiagutech/ams/common/RabbitConfig.java b/web/src/main/java/com/jiagutech/ams/common/RabbitConfig.java index 9604bd6..11e14fd 100644 --- a/web/src/main/java/com/jiagutech/ams/common/RabbitConfig.java +++ b/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; } } diff --git a/web/src/main/java/com/jiagutech/ams/config/SaPermissionImpl.java b/web/src/main/java/com/jiagutech/ams/config/SaPermissionImpl.java index 4227c62..aab257d 100644 --- a/web/src/main/java/com/jiagutech/ams/config/SaPermissionImpl.java +++ b/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 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<>(); } diff --git a/web/src/main/resources/application-dev.yml b/web/src/main/resources/application-dev.yml index b5a103f..3c0a93c 100644 --- a/web/src/main/resources/application-dev.yml +++ b/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 diff --git a/web/src/main/resources/application-prod.yml b/web/src/main/resources/application-prod.yml new file mode 100644 index 0000000..b97104e --- /dev/null +++ b/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 + diff --git a/web/src/main/resources/application.yml b/web/src/main/resources/application.yml index faf3d2f..2961fc7 100644 --- a/web/src/main/resources/application.yml +++ b/web/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8181 + port: 8182 spring: profiles: