zhitong.yu
7 天以前 7fc9c42987a13c1d8d2159591a5803e70518827f
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
package com.hxzk.gps.service.impl.Map;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxzk.gps.controller.Map.Results.MapResult;
import com.hxzk.gps.controller.Map.Results.MarsResult;
import com.hxzk.gps.controller.Map.dto.MapTreeTableDto;
import com.hxzk.gps.entity.Department.TbDepartMentIcon;
import com.hxzk.gps.entity.Department.TbDepartment;
import com.hxzk.gps.entity.Map.TbMap;
import com.hxzk.gps.mapper.Map.TbMapMapper;
import com.hxzk.gps.service.Company.TbCompanyService;
import com.hxzk.gps.service.Map.TbMapService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxzk.gps.util.AuToComplete;
import com.hxzk.gps.util.GetUser.UserInfoUtil;
import com.hxzk.gps.util.MessageUtils.MessageUtils;
import com.hxzk.gps.util.Result.TableDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YuZhiTong
 * @since 2025-05-23
 */
@Service
public class TbMapServiceImpl extends ServiceImpl<TbMapMapper, TbMap> implements TbMapService {
    @Autowired
    TbCompanyService companyService;
    @Value("${upload.dir-IP}")
    private String uploadIp;
    @Override
    public MapResult FindMapInfo(MapTreeTableDto mapTreeTableDto) {
        // 开启分页
        PageHelper.startPage(mapTreeTableDto.getPageNum(), mapTreeTableDto.getPageSize());
        // 创建查询包装器
        QueryWrapper queryWrapperCompany = new QueryWrapper<>();
        // 处理部门 ID 为空的情况
        if ("".equals(mapTreeTableDto.getDepartmentId())) {
            List<Long> list = companyService.getChildCompanyIds(UserInfoUtil.getUserCompanyId());
            queryWrapperCompany.in("companyid", list);
        } else {
            queryWrapperCompany.eq("companyid", mapTreeTableDto.getDepartmentId());
        }
        // 查询二维地图列表
        List<TbMap> maps = baseMapper.selectList(queryWrapperCompany);
        PageInfo<TbMap> info = new PageInfo<>(maps);
        // 封装角色列表
        TableDto tableDto = new TableDto(info.getList(), info.getPageNum(), info.getPageSize(), info.getTotal());
        // 获取成功消息
        String message = MessageUtils.getMessage("Success");
        // 返回结果
        return new MapResult(200, message, tableDto, mapTreeTableDto.getPageNum(), mapTreeTableDto.getPageSize(), info.getTotal());
    }
 
    @Override
    public List<AuToComplete> FindUserCompanyMap() {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company", UserInfoUtil.getUserCompany());
        List<TbMap> mapList = baseMapper.selectList(queryWrapper);
        List<AuToComplete> addCustomerList = mapList.stream()
                .map(map -> {
                    String[] mapname = map.getMapname().split("\\.");
                    AuToComplete addCustomer = new AuToComplete();
                    addCustomer.setLabel(mapname[0]);
                    addCustomer.setValue(mapname[0]);
                    return addCustomer;
                })
                .collect(Collectors.toList());
        return addCustomerList;
    }
 
    @Override
    public Map<String, String> FindUserCompanyMapSelect() {
        QueryWrapper<TbMap> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company", UserInfoUtil.getUserCompany());
        List<TbMap> mapList = baseMapper.selectList(queryWrapper);
 
        // 创建Map,key为地图名称,value为图片URL
        Map<String, String> resultMap = new HashMap<>();
        for (TbMap map : mapList) {
            String[] mapname = map.getMapname().split("\\.");
            resultMap.put(mapname[0], uploadIp+"Map/"+mapname[0]+"."+mapname[1]); // 假设TbMap有getMapUrl方法
        }
 
        return resultMap;
    }
}