Browse Source

根据区域查询农户等功能

master
zhangyeguang 3 months ago
parent
commit
4586158473
  1. 1
      .gitignore
  2. 4
      common/src/main/java/com/jiagutech/ams/mapper/RegionMapper.java
  3. 13
      social/src/main/java/com/jiagutech/ams/controller/RegionController.java
  4. 7
      social/src/main/java/com/jiagutech/ams/listener/JobFinishListener.java
  5. 2
      social/src/main/java/com/jiagutech/ams/model/JobMapping.java
  6. 45
      social/src/main/java/com/jiagutech/ams/model/TrackDataJG.java
  7. 5
      social/src/main/java/com/jiagutech/ams/model/response/JobPolyItem.java
  8. 14
      social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java
  9. 3
      social/src/main/java/com/jiagutech/ams/service/RegionService.java
  10. 20
      social/src/main/java/com/jiagutech/ams/service/RegionServiceImpl.java
  11. 1
      social/src/main/java/com/jiagutech/ams/service/SortieService.java
  12. 1
      social/src/main/resources/mapper/JobMapper.xml
  13. 11
      social/src/main/resources/mapper/RegionMapper.xml
  14. 2
      system/src/main/java/com/jiagutech/ams/model/request/UserRequest.java
  15. 4
      system/src/main/java/com/jiagutech/ams/service/UserServiceImpl.java
  16. 12
      web/src/main/java/com/jiagutech/ams/config/SpringDocConfig.java
  17. 6
      web/src/main/resources/application.yml

1
.gitignore

@ -38,3 +38,4 @@ buildNumber.properties
.mvn/wrapper/maven-wrapper.jar
.idea/
.DS_Store

4
common/src/main/java/com/jiagutech/ams/mapper/RegionMapper.java

@ -2,6 +2,7 @@ package com.jiagutech.ams.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jiagutech.ams.model.LoginUser;
import com.jiagutech.ams.model.RegionE;
import com.jiagutech.ams.model.RegionVO;
import com.jiagutech.ams.model.UserDetail;
import com.jiagutech.ams.model.dto.RegionDTO;
@ -23,4 +24,7 @@ public interface RegionMapper extends BaseMapper<RegionDTO> {
RegionVO getCompleteRegionInfo(@Param("regionCode") long regionCode);
List<RegionE> selectHistoryJobRegions(@Param("deptId")Long deptId);
}

13
social/src/main/java/com/jiagutech/ams/controller/RegionController.java

@ -1,5 +1,8 @@
package com.jiagutech.ams.controller;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.jiagutech.ams.model.RegionE;
import com.jiagutech.ams.model.common.R;
import com.jiagutech.ams.model.dto.RegionDTO;
import com.jiagutech.ams.service.RegionService;
@ -28,12 +31,20 @@ public class RegionController {
private final RegionService regionService;
@SaCheckRole(value = {"manager", "machinist"}, mode = SaMode.OR)
@Operation(summary = "获取下一级的所有区域列表")
@GetMapping("getChildren")
public R<List<RegionDTO>> getChildren(Long regionCode) {
public R<List<RegionDTO>> getChildren(Long regionCode) {
List<RegionDTO> regionDTOList = regionService.getChildren(regionCode);
return R.ok(regionDTOList);
}
@Operation(summary = "从历史作业中获取区域列表")
@GetMapping("getHistoryJobRegions")
public R<List<RegionE>> getHistoryJobRegions() {
List<RegionE> historyJobRegions = regionService.getHistoryJobRegions();
return R.ok(historyJobRegions);
}
}

7
social/src/main/java/com/jiagutech/ams/listener/JobFinishListener.java

@ -26,6 +26,11 @@ public class JobFinishListener {
@EventListener(JobFinishEvent.class)
public void finishJob(JobFinishEvent event) {
log.info("JobFinishListener:{}", event.getJobId());
List<TrackItem> trackList = jobService.getTrackList(event.getJobId());
try {
List<TrackItem> trackList = jobService.getTrackList(event.getJobId());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

2
social/src/main/java/com/jiagutech/ams/model/JobMapping.java

@ -6,6 +6,7 @@ import com.jiagutech.ams.model.response.JobCreateResponse;
import com.jiagutech.ams.model.response.JobItem;
import com.jiagutech.ams.model.response.JobPolyItem;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
@ -16,6 +17,7 @@ public interface JobMapping {
JobDTO jobCreateToJobDTO(JobCreateRequest job);
@Mapping(source = "id", target = "jobId")
JobCreateResponse jobDTOToJobCreateResponse(JobDTO job);
JobPolyItem jobItemToJobPolyItem(JobItem job);

45
social/src/main/java/com/jiagutech/ams/model/TrackDataJG.java

@ -70,51 +70,6 @@ public class TrackDataJG implements Serializable {
*/
private Float roll;
/**
* 本架次起飞后,已飞行的时间单位:
*/
private Integer ftime;
/**
* 本架次起飞后,已喷洒的面积单位:
*/
private Float farea;
/**
* 喷洒流速,单位:/分钟
*/
private Float curFlow;
/**
* 目前接收到的导航卫星的数量
*/
private Integer gpsNum;
/**
* 定位精度类型,1:GPS/BD 单点,2:差分,4:RTK 固定解,5:RTK 浮点解
*/
private Integer posAccur;
private Integer areaCode;
private Integer flying;//1=正在飞 0在地上
//替换 int - long
//private Integer operUserId;
private Long operUserId;
private Float totalArea;//飞控总亩数
private Integer errorCode;
private Integer deviceType;
// 耕深(厘米)[浮点数,最多保留一位小数]
private Double deep;
// 流量(脉冲值)[浮点数,最多保留一位小数]
private Double flow;
// 播种速度 粒/s生成对应的实体类
private Double seeding;
}

5
social/src/main/java/com/jiagutech/ams/model/response/JobPolyItem.java

@ -21,6 +21,8 @@ public class JobPolyItem {
@ExcelProperty(value = "农户手机号")
private String farmerPhone;
@ExcelProperty(value = "作业类型")
private String typeName;
@ExcelProperty(value = "开始作业时间")
private String startTimeStr;
@ -28,8 +30,7 @@ public class JobPolyItem {
@ExcelProperty(value = "作业总面积")
private Float area;
@ExcelProperty(value = "作业类型")
private String typeName;
@ExcelProperty(value = "合作社")
private String deptName;

14
social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java

@ -8,6 +8,8 @@ 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.LoginUser;
@ -22,9 +24,11 @@ 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
@ -50,9 +54,15 @@ public class DeviceServiceImpl implements DeviceService {
deviceInfos.add(deviceInfo1);
if (CollectionUtils.isNotEmpty(keys)) {
List<String> values = stringRedisTemplate.opsForValue().multiGet(keys);
List<TrackDataJG> trackDataJGS = JSON.parseArray(JSON.toJSONString(values), TrackDataJG.class);
if (CollectionUtils.isEmpty(values)) {
return deviceInfos;
}
List<TrackDataJG> trackDataJGS = values.stream().map(s -> JSON.parseObject(s, TrackDataJG.class)).collect(Collectors.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;
}
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());
@ -81,7 +91,7 @@ public class DeviceServiceImpl implements DeviceService {
Page<DeviceDTO> page = new Page(pageRequest.getPageNum(), pageRequest.getPageSize());
QueryWrapper<DeviceDTO> queryWrapper = Wrappers.query();
LoginUser loginUser = StpUtil.getSession().get(UserConstants.SYS_SESSION, new LoginUser());
queryWrapper.eq("dept_id",loginUser.getDept().getId());
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());
}

3
social/src/main/java/com/jiagutech/ams/service/RegionService.java

@ -1,9 +1,12 @@
package com.jiagutech.ams.service;
import com.jiagutech.ams.model.RegionE;
import com.jiagutech.ams.model.dto.RegionDTO;
import java.util.List;
public interface RegionService {
List<RegionDTO> getChildren(Long regionCode);
List<RegionE> getHistoryJobRegions();
}

20
social/src/main/java/com/jiagutech/ams/service/RegionServiceImpl.java

@ -2,11 +2,19 @@ package com.jiagutech.ams.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jiagutech.ams.constant.UserConstants;
import com.jiagutech.ams.mapper.RegionMapper;
import com.jiagutech.ams.model.LoginUser;
import com.jiagutech.ams.model.RegionE;
import com.jiagutech.ams.model.dto.RegionDTO;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@Service
@ -15,10 +23,22 @@ public class RegionServiceImpl implements RegionService {
private final RegionMapper regionMapper;
@Override
public List<RegionDTO> getChildren(Long regionCode) {
QueryWrapper<RegionDTO> query = Wrappers.query();
return regionMapper.selectList(query.eq("parent_code", regionCode).orderByAsc("region_code"));
}
@Override
public List<RegionE> getHistoryJobRegions() {
LoginUser currentUser = StpUtil.getSession().get(UserConstants.SYS_SESSION, new LoginUser());
if (ObjectUtil.isNotNull(currentUser)) {
return regionMapper.selectHistoryJobRegions(currentUser.getDept().getId());
}
return Collections.emptyList();
}
}

1
social/src/main/java/com/jiagutech/ams/service/SortieService.java

@ -3,7 +3,6 @@ package com.jiagutech.ams.service;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
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;

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

@ -53,6 +53,7 @@
left join ams_user u2 on j.farmer_id = u2.id
${ew.getCustomSqlSegment}
group by j.farmer_id,j.job_type,t.name,d.id,d.name,u2.nick_name
order by j.farmer_id,j.job_type
</select>

11
social/src/main/resources/mapper/RegionMapper.xml

@ -44,4 +44,15 @@
GROUP_CONCAT(region_name ORDER BY level SEPARATOR '-') AS regionName
from cte
</select>
<select id="selectHistoryJobRegions" resultType="com.jiagutech.ams.model.RegionE">
select distinct u.region_code,ri.region_name ,u.region_path as region_full_code,u.region_name as
region_full_name from ams_user u
left join region_info ri on u.region_code=ri.region_code
where exists (
SELECT distinct j.farmer_id from ams_job_info j where j.dept_id = #{deptId}
and u.id=j.farmer_id
)
</select>
</mapper>

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

@ -81,4 +81,6 @@ public class UserRequest {
private String roleKey;
private Long regionCode;
private String contactPhone;
}

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

@ -2,6 +2,7 @@ package com.jiagutech.ams.service;
import cn.dev33.satoken.secure.BCrypt;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
@ -96,6 +97,7 @@ public class UserServiceImpl implements UserService {
@Transactional
public void addUser(UserRequest userRequest) {
UserDTO userDTO = UserMapping.INSTANCE.userToUserDTO(userRequest);
userDTO.setId(null);
userDTO.setPassword(BCrypt.hashpw(userRequest.getPassword()));
if (userDTO.getRegionCode() != null && userDTO.getRegionCode() != 0l) {
RegionVO completeRegionInfo = regionMapper.getCompleteRegionInfo(userDTO.getRegionCode());
@ -138,7 +140,7 @@ public class UserServiceImpl implements UserService {
if (StringUtils.isNotBlank(roleKey)) {
userRoleMapper.insertUserRole(user.getId(), roleKey);
}
if (deptId != null) {
if (ObjectUtil.isNotEmpty(deptId) && deptId != 0l) {
UserDeptDTO userDeptDTO = new UserDeptDTO().setUserId(user.getId()).setDeptId(deptId);
userDeptMapper.insert(userDeptDTO);
}

12
web/src/main/java/com/jiagutech/ams/config/SpringDocConfig.java

@ -29,16 +29,16 @@ public class SpringDocConfig {
private Info getApiInfo() {
return new Info()
// 配置文档标题
.title("SpringBoot3集成Swagger3")
.title("贵州农机管理平台-社会化管理平台")
// 配置文档描述
.description("SpringBoot3集成Swagger3示例文档")
.description("社会化管理平台API文档")
// 配置作者信息
.contact(new Contact().name("农机管理-社会化").url("https://www.baidu.com"))
.contact(new Contact().name("Mr Zhang").url("https://www.baidu.com"))
// 配置License许可证信息
.license(new License().name("Apache 2.0").url("https://www.xiezhrspace.cn"))
// .license(new License().name("Apache 2.0").url("https://www.xiezhrspace.cn"))
// 概述信息
.summary("SpringBoot3集成Swagger3示例文档aaa")
.termsOfService("https://www.xiezhrspace.cn")
.summary("社会化管理平台API文档")
.termsOfService("http://www.jiagutech.com")
// 配置版本号
.version("2.0");
}

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

@ -19,9 +19,9 @@ spring:
# 校验超时时间
validationTimeout: 5000
# 空闲连接存活最大时间,默认10分钟
idleTimeout: 600000
idleTimeout: 300000
# 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认30分钟
maxLifetime: 600000
maxLifetime: 1800000
# 多久检查一次连接的活性
keepaliveTime: 60000
connection-test-query: SELECT 1
@ -88,3 +88,5 @@ logging:
springdoc:
api-docs:
enabled: true

Loading…
Cancel
Save