aix
2024-08-08 39ffdf5754b4ebca682bd3c925f7a500e8a1bbda
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package com.dji.sample.patches.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dji.sample.common.model.Pagination;
import com.dji.sample.common.model.PaginationData;
import com.dji.sample.media.dao.IFileMapper;
import com.dji.sample.media.dao.IMarkMapper;
import com.dji.sample.media.model.MediaFileEntity;
import com.dji.sample.media.model.MediaFileMarkEntity;
import com.dji.sample.patches.dao.GetPatchesMapper;
import com.dji.sample.patches.model.Param.PatchesParam;
import com.dji.sample.patches.model.entity.LotInfo;
import com.dji.sample.patches.service.GetPatchesService;
import com.dji.sample.patches.utils.DistrictCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
@Service
public class GetPatchesServiceImpl implements GetPatchesService {
    @Autowired
    private GetPatchesMapper mapper;
    @Autowired
    private IFileMapper fileMapper;
    @Autowired
    private IMarkMapper markMapper;
 
    /**
     * 分页获取数据的接口实现。
     *
     * @param param 包含分页信息和查询条件的工作空间ID。
     * @return 返回一个包含查询结果和分页信息的PaginationData对象。
     */
    @Override
    public PaginationData<LotInfo> limitGet(PatchesParam param) {
        // 创建分页对象
        Page<LotInfo> page = new Page<>(param.getPage(), param.getPageSize());
 
        // 创建查询条件对象
        LambdaQueryWrapper<LotInfo> queryWrapper = new LambdaQueryWrapper<>();
 
        // 添加查询条件
        queryWrapper.eq(LotInfo::getWorkspaceId, param.getWorkspaceId());
 
        if (param.getDkbh() != null && !param.getDkbh().isEmpty()) {
            queryWrapper.like(LotInfo::getDkbh, param.getDkbh());
        }
        if (param.getInvestigate() != null) {
            queryWrapper.eq(LotInfo::getInvestigate, param.getInvestigate());
        }
        if (param.getDkbh() != null && !param.getDkbh().isEmpty()) {
            queryWrapper.like(LotInfo::getDkbh, param.getDkbh());
        }
        if (param.getXzqdm() != null && !param.getXzqdm().isEmpty()) {
            queryWrapper.like(LotInfo::getXzqdm, param.getXzqdm());
        }
        if (param.getXmc() != null && !param.getXmc().isEmpty()) {
            queryWrapper.like(LotInfo::getXmc, param.getXmc());
        }
        if (param.getBsm() != null && !param.getBsm().isEmpty()) {
            queryWrapper.like(LotInfo::getXmc, param.getBsm());
        }
        if (param.getDkmj()!=null){
            queryWrapper.eq(LotInfo::getDkmj,param.getDkmj());
        }
        if (param.getIsPush() != null) {
            queryWrapper.eq(LotInfo::getIsPush, param.getIsPush());
        }
 
        // 执行分页查询
        Page<LotInfo> resultPage = mapper.selectPage(page, queryWrapper);
 
        // 处理查询结果
        List<LotInfo> records = resultPage.getRecords()
                .stream()
                .peek(lotInfo -> {
                    // 修改 xzqdm 字段的值
                     lotInfo.setXmc(DistrictCodeUtils.codeToName(lotInfo.getXzqdm()));
                })
                .collect(Collectors.toList());
 
        // 返回分页数据
        return new PaginationData<>(records, new Pagination(resultPage));
    }
    @Override
    public int delPatches(String workspaceId) {
        return mapper.delete(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getWorkspaceId,workspaceId));
    }
 
    @Override
    public int deleteOne(int id) {
        return mapper.deleteById(id);
    }
 
    @Override
    public PaginationData getPhoto(PatchesParam param, String dkbh) {
//        LotInfo lotInfo = getLotinfoToDb(dkbh);
//        int statue = lotInfo.getIsPush();
//
//        if (statue == 1) {
//            List<MediaFileMarkEntity> allResults = markMapper.selectList(
//                    new LambdaQueryWrapper<MediaFileMarkEntity>()
//                            .like(MediaFileMarkEntity::getFileName, "%" + dkbh + "~" + "%"));
//
//            // 去重处理
//            Map<String, MediaFileMarkEntity> uniqueFileMap = new LinkedHashMap<>();
//            List<MediaFileMarkEntity> uniqueResults = allResults.stream()
//                    .filter(mediaFile -> uniqueFileMap.putIfAbsent(mediaFile.getFileName(), mediaFile) == null)
//                    .collect(Collectors.toList());
//
//            // 计算分页信息
//            int total = uniqueResults.size();
//            int start = (param.getPage() - 1) * param.getPageSize();
//            int end = Math.min(start + param.getPageSize(), total);
//
//            // 获取当前页的结果
//            List<MediaFileMarkEntity> pageResults = uniqueResults.subList(start, end);
//
//            // 创建临时的 Page 对象
//            Page<MediaFileMarkEntity> resultPage = new Page<>(param.getPage(), param.getPageSize());
//            resultPage.setRecords(pageResults);
//            resultPage.setTotal(total);
//
//            // 返回分页数据
//            return new PaginationData<>(pageResults, new Pagination(resultPage));
//        }
//        else {
            List<MediaFileEntity> allResults = fileMapper.selectList(
                    new LambdaQueryWrapper<MediaFileEntity>()
                            .like(MediaFileEntity::getFileName, "%" + dkbh + "~" + "%"));
 
            // 去重处理
            Map<String, MediaFileEntity> uniqueFileMap = new LinkedHashMap<>();
            List<MediaFileEntity> uniqueResults = allResults.stream()
                    .filter(mediaFile -> uniqueFileMap.putIfAbsent(mediaFile.getFileName(), mediaFile) == null)
                    .collect(Collectors.toList());
 
            // 计算分页信息
            int total = uniqueResults.size();
            int start = (param.getPage() - 1) * param.getPageSize();
            int end = Math.min(start + param.getPageSize(), total);
 
            // 获取当前页的结果
            List<MediaFileEntity> pageResults = uniqueResults.subList(start, end);
 
            // 创建临时的 Page 对象
            Page<MediaFileEntity> resultPage = new Page<>(param.getPage(), param.getPageSize());
            resultPage.setRecords(pageResults);
            resultPage.setTotal(total);
 
            // 返回分页数据
            return new PaginationData<>(pageResults, new Pagination(resultPage));
        }
//    }
 
 
 
    public List<MediaFileEntity> listPohto(String dkbh, String workspaceId) {
        return fileMapper.selectList(new LambdaQueryWrapper<MediaFileEntity>().like(MediaFileEntity::getFileName, "%" + dkbh + "%")
                .eq(MediaFileEntity::getWorkspaceId, workspaceId)
                .eq(MediaFileEntity::getExamine,1));
    }
    public LotInfo getLotinfo(String dkbh, String workspaceId) {
        return mapper.selectOne(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, dkbh)
                .eq(LotInfo::getWorkspaceId, workspaceId));
    }
    public void patchesPushed(String taskId, String dkbh, String workspaceId) {
        LambdaUpdateWrapper<LotInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(LotInfo::getIsPush, 1)
                .eq(LotInfo::getWorkspaceId, workspaceId)
                .eq(LotInfo::getDkbh, dkbh)
                .eq(LotInfo::getTaskId, taskId);
        mapper.update(null, updateWrapper);
    }
    public LotInfo getLotinfoToDb(String dkbh) {
        return mapper.selectOne(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, dkbh));
    }
    public List<LotInfo> getLotInfosByIds(List<Integer> ids) {
        LambdaQueryWrapper<LotInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(LotInfo::getId, ids);
        return mapper.selectList(queryWrapper);
    }
    public List<LotInfo> listLotinfo(String workspaceId) {
        return mapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getWorkspaceId,workspaceId));
    }
    @Override
    public LotInfo getPatchesFromId(String patchesId){
        return mapper.selectOne(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getId,patchesId));
    }
    @Override
    public void insertLotinfo(List<LotInfo> list) {
        for (int i = 0; i < list.size(); i++) {
            mapper.insert(list.get(i));
        }
    }
}