| | |
| | | */ |
| | | package org.sxkj.gd.flyer.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.sxkj.common.utils.HeaderUtils; |
| | |
| | | import org.sxkj.gd.utils.GdGeoAddressUtil; |
| | | import org.sxkj.system.cache.SysCache; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 飞手表 服务实现类 |
| | |
| | | * @author lw |
| | | * @since 2026-01-14 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class GdFlyerServiceImpl extends BaseServiceImpl<GdFlyerMapper, GdFlyerEntity> implements IGdFlyerService { |
| | | |
| | | /** |
| | | * 分页查询飞手信息列表 |
| | | * @param page 分页对象 |
| | | * @param gdFlyer 查询参数 |
| | | * @return 分页结果 |
| | | */ |
| | | @Override |
| | | public IPage<GdFlyerVO> selectGdFlyerPage(IPage<GdFlyerVO> page, GdFlyerPageParam gdFlyer) { |
| | | if (!AuthUtil.isAdministrator()) { |
| | | List<Long> deptList = SysCache.getDeptChildIds(Long.valueOf(AuthUtil.getDeptId())); |
| | | gdFlyer.setDeptList(deptList); |
| | | } |
| | | // 通过经纬度获取行政区划 |
| | | if (StringUtil.isNotBlank(gdFlyer.getLongitude()) && StringUtil.isNotBlank(gdFlyer.getLatitude())) { |
| | | String areaCode = GdGeoAddressUtil.getCountyCode(Double.valueOf(gdFlyer.getLongitude()), Double.valueOf(gdFlyer.getLatitude())); |
| | | // 去掉前面三位数字 |
| | | if (areaCode != null && areaCode.length() > 3) { |
| | | areaCode = areaCode.substring(3); |
| | | } |
| | | gdFlyer.setAreaCode(HeaderUtils.fillZero(areaCode)); |
| | | // 步骤1:执行数据库查询获取飞手列表 |
| | | List<GdFlyerVO> gdFlyerVOS = baseMapper.selectGdFlyerPage(page, gdFlyer); |
| | | |
| | | // 步骤2:判断是否有擅长任务类型的查询条件 |
| | | if (StringUtil.isNotBlank(gdFlyer.getSkilledTaskType())) { |
| | | // 步骤3:获取查询的任务类型 |
| | | String searchTaskType = gdFlyer.getSkilledTaskType(); |
| | | |
| | | // 步骤4:遍历结果,设置匹配标识并根据匹配数量排序 |
| | | gdFlyerVOS.forEach(vo -> { |
| | | // 步骤5:计算匹配数量 |
| | | int matchCount = countMatchedTaskTypes(vo.getSkilledTaskType(), searchTaskType); |
| | | // 步骤6:设置匹配标识(匹配数量大于0返回1,否则返回0) |
| | | vo.setTaskTypeMatchFlag(matchCount > 0 ? 1 : 0); |
| | | }); |
| | | |
| | | // 步骤7:对结果进行排序,匹配数量多的排在前面 |
| | | gdFlyerVOS.sort((vo1, vo2) -> { |
| | | // 步骤8:计算记录1匹配的任务类型数量 |
| | | int matchCount1 = countMatchedTaskTypes(vo1.getSkilledTaskType(), searchTaskType); |
| | | // 步骤9:计算记录2匹配的任务类型数量 |
| | | int matchCount2 = countMatchedTaskTypes(vo2.getSkilledTaskType(), searchTaskType); |
| | | // 步骤10:匹配数量多的排在前面(降序排列) |
| | | return Integer.compare(matchCount2, matchCount1); |
| | | }); |
| | | } else { |
| | | // 步骤11:无查询条件时,将所有记录的匹配标识设置为0 |
| | | gdFlyerVOS.forEach(vo -> vo.setTaskTypeMatchFlag(0)); |
| | | } |
| | | |
| | | return page.setRecords(baseMapper.selectGdFlyerPage(page, gdFlyer)); |
| | | return page.setRecords(gdFlyerVOS); |
| | | } |
| | | |
| | | /** |
| | | * 计算任务类型列表中匹配的任务类型数量 |
| | | * @param skilledTaskTypes 擅长的任务类型列表(二维数组) |
| | | * @param searchTaskType 要搜索的任务类型(多个用逗号分隔,如:road4,road5) |
| | | * @return 匹配的任务类型数量 |
| | | */ |
| | | private int countMatchedTaskTypes(List<List<String>> skilledTaskTypes, String searchTaskType) { |
| | | // 步骤1:校验参数有效性 |
| | | if (skilledTaskTypes == null || StringUtil.isBlank(searchTaskType)) { |
| | | return 0; |
| | | } |
| | | // 步骤2:拆分多个任务类型(支持逗号分隔) |
| | | String[] taskTypes = searchTaskType.split(","); |
| | | // 步骤3:计算匹配数量 |
| | | int matchCount = 0; |
| | | for (String taskType : taskTypes) { |
| | | String trimmedTaskType = taskType.trim(); |
| | | // 步骤4:检查二维数组中是否包含该任务类型 |
| | | boolean matched = skilledTaskTypes.stream() |
| | | .anyMatch(innerList -> innerList != null && innerList.contains(trimmedTaskType)); |
| | | if (matched) { |
| | | matchCount++; |
| | | } |
| | | } |
| | | return matchCount; |
| | | } |
| | | |
| | | |
| | |
| | | // 步骤4:执行保存或更新操作 |
| | | return saveOrUpdate(convert); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> selectAllFlyerIds() { |
| | | List<GdFlyerEntity> flyerList = lambdaQuery() |
| | | .eq(GdFlyerEntity::getIsDeleted, 0) |
| | | .select(GdFlyerEntity::getFlyerId) |
| | | .list(); |
| | | return flyerList.stream() |
| | | .map(GdFlyerEntity::getFlyerId) |
| | | .filter(StringUtil::isNotBlank) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | } |
| | | } |