吉安感知网项目-后端
linwei
2026-07-08 442f8cf748c2191213ed93ccdd2633ac4f02e038
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
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.flyer.entity.GdFlyerEntity;
import org.sxkj.gd.flyer.param.GdFlyerPageParam;
import org.sxkj.gd.flyer.vo.GdFlyerVO;
import org.sxkj.gd.flyer.excel.GdFlyerExcel;
import org.sxkj.gd.flyer.mapper.GdFlyerMapper;
import org.sxkj.gd.flyer.service.IGdFlyerService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.sxkj.gd.utils.GdGeoAddressUtil;
import org.sxkj.system.cache.SysCache;
 
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) {
        // 步骤1:执行数据库查询获取飞手列表
        List<GdFlyerVO> gdFlyerVOS = baseMapper.selectGdFlyerPage(page, gdFlyer);
 
        // 步骤2:判断是否有擅长任务类型的查询条件
        if (StringUtil.isNotBlank(gdFlyer.getSkilledTaskType())) {
            // 步骤3:获取查询的任务类型
            String searchTaskType = gdFlyer.getSkilledTaskType();
 
            // 步骤4:对结果进行排序,匹配的记录排在前面
            gdFlyerVOS.sort((vo1, vo2) -> {
                // 步骤5:检查记录1是否包含查询的任务类型
                boolean match1 = containsTaskType(vo1.getSkilledTaskType(), searchTaskType);
                // 步骤6:检查记录2是否包含查询的任务类型
                boolean match2 = containsTaskType(vo2.getSkilledTaskType(), searchTaskType);
                // 步骤7:匹配的记录排在前面(降序排列)
                return Boolean.compare(match2, match1);
            });
        }
 
        return page.setRecords(gdFlyerVOS);
    }
 
    /**
     * 检查任务类型列表中是否包含指定的任务类型
     * @param skilledTaskTypes 擅长的任务类型列表(二维数组)
     * @param searchTaskType 要搜索的任务类型
     * @return 包含返回true,否则返回false
     */
    private boolean containsTaskType(List<List<String>> skilledTaskTypes, String searchTaskType) {
        // 步骤1:校验参数有效性
        if (skilledTaskTypes == null || StringUtil.isBlank(searchTaskType)) {
            return false;
        }
        // 步骤2:遍历二维数组,检查是否包含目标任务类型
        return skilledTaskTypes.stream()
            .anyMatch(innerList -> innerList != null && innerList.contains(searchTaskType));
    }
 
 
    @Override
    public List<GdFlyerExcel> exportGdFlyer(Wrapper<GdFlyerEntity> queryWrapper) {
        List<GdFlyerExcel> gdFlyerList = baseMapper.exportGdFlyer(queryWrapper);
        // gdFlyerList.forEach(gdFlyer -> {
        //    gdFlyer.setTypeName(DictCache.getValue(DictEnum.YES_NO, GdFlyer.getType()));
        //});
        return gdFlyerList;
    }
 
    /**
     * 新增或修改
     * @param convert 飞手实体对象
     * @return 保存或更新成功返回true,失败返回false
     */
    @Override
    public boolean saveOrUpdateFlyer(GdFlyerEntity convert) {
        // 步骤1:校验电话号码是否为空
        if (StringUtil.isNotBlank(convert.getFlyerPhone())) {
            // 步骤2:查询数据库中是否存在相同电话号码的记录
            Long count = baseMapper.selectCount(
                new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<GdFlyerEntity>()
                    .eq(GdFlyerEntity::getFlyerPhone, convert.getFlyerPhone())
                    .ne(convert.getId() != null, GdFlyerEntity::getId, convert.getId())
            );
            // 步骤3:如果存在重复的电话号码,抛出异常
            if (count > 0) {
                throw new RuntimeException("电话号码已存在,请使用其他电话号码");
            }
        }
        convert.setAreaCode(HeaderUtils.processAreaCode(convert.getRegionCode()));
        // 步骤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());
    }
}