zqy
2024-11-10 e2e816919caa81711a5bdf6768257c4bb3a9f3af
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
 
package com.ruoyi.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.EsModel;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.TravelCount;
import com.ruoyi.domain.TravelDetail;
import com.ruoyi.domain.ZInfoUser;
import com.ruoyi.domain.ZfDownload;
import com.ruoyi.mapper.ZfDownloadMapper;
import com.ruoyi.service.*;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
 
@Service
@Slf4j
public class TravelCountDownServiceImpl extends ServiceImpl<ZfDownloadMapper,ZfDownload> implements TravelCountDownlService {
    @Resource
    EsService esService;
 
    @Resource
    TravelCountSharService travelCountSharService;
 
    @Resource
    TravelCountService travelCountService;
 
    @Resource
    TravelDetailService travelDetailService;
 
 
    @Resource
    ZInfoUserService zInfoUserService;
 
    @Resource
    private RestHighLevelClient restHighLevelClient;
 
    private LambdaQueryWrapper<ZfDownload> buildCondition(ZfDownload zfDownload, Long userId) {
        LambdaQueryWrapper<ZfDownload> lqw = new LambdaQueryWrapper<>();
        lqw.in(ZfDownload::getDownloadId,userId);
        lqw.orderByDesc(ZfDownload::getDownloadId);
        lqw.like(zfDownload.getDownloadId() != null, ZfDownload::getDownloadId, zfDownload.getDownloadId())
                .like(zfDownload.getDownloadContent() != null, ZfDownload::getDownloadContent, zfDownload.getDownloadContent())
                .eq( ZfDownload::getSysMenuId, zfDownload.getSysMenuId());
        return lqw;
    }
    private LambdaQueryWrapper<ZfDownload> uniqueCondition(ZfDownload zfDownload) {
        LambdaQueryWrapper<ZfDownload> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StringUtils.isNotEmpty(String.valueOf(zfDownload.getDownloadId())), ZfDownload::getDownloadId, zfDownload.getDownloadId())
                .eq(StringUtils.isNotEmpty(String.valueOf(zfDownload.getDownloadContent())), ZfDownload::getDownloadContent, zfDownload.getDownloadContent())
                .eq(ZfDownload::getSysMenuId, zfDownload.getSysMenuId());
        return lqw;
    }
 
    public Long getUserId() {
        ZInfoUser myself = zInfoUserService.getMyself();
        return myself.getUserId();
    }
    @Override
    public AjaxResult addData(ZfDownload zfDownload) {
        zfDownload.setDownloadId(getUserId());
        LambdaQueryWrapper<ZfDownload> lqw = uniqueCondition(zfDownload);
        List<ZfDownload> list = list(lqw);
        if (list.size() > 0) {
            throw new RuntimeException("请勿重复下载数据");
        }
 
        zfDownload.setDownloadId(getUserId());
        zfDownload.setShareId(travelCountSharService.getShareId(zfDownload));
        if (save(zfDownload)) {
            EsModel esModel = new EsModel();
            Integer inte = zfDownload.getId().intValue();
            String uuid = UUID.randomUUID().toString().replace("-", "");
            esModel.setId(uuid);
            esModel.setCtId(Long.valueOf(inte));
            esModel.setCtTableName("旅游");
 
            esModel.setBy1(String.valueOf(zfDownload.getDownloadId()));
            esModel.setBy2(String.valueOf(zfDownload.getDownloadContent()));
            esModel.setBy3(String.valueOf(zfDownload.getShareId()));
            //这里存储查询详情的路径
            esService.insertTable(esModel);
 
 
            TravelDetail travelDetail = new TravelDetail();
            travelDetail.setCid(zfDownload.getDownloadContent());
 
            List<TravelDetail> travelDetails = travelDetailService.getDataByCid(zfDownload.getDownloadContent(),travelDetail);
            System.out.println("cgftfygmjh267/"+travelDetails.size());
            if (travelDetails.size() != 0){
            for (TravelDetail travelDetail1:travelDetails) {
                zfDownload.setId(zfDownload.getId()+1);
                zfDownload.setSysMenuId(2055L);
                zfDownload.setDownloadContent(travelDetail1.getId());
                System.out.println(zfDownload);
                save(zfDownload);
            }}
 
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }
 
    @Override
    public Boolean deleteData(Long[] ids) {
        List<Long> id = new ArrayList<>();
 
        LambdaQueryWrapper<ZfDownload> lqw = new LambdaQueryWrapper<>();
        lqw.in(ids != null, ZfDownload::getDownloadContent,  ids)
                .eq(ZfDownload::getSysMenuId, 2056L);
 
        List<ZfDownload> zfDownloads = list(lqw);
        System.out.println(zfDownloads);
        if (zfDownloads.size() == 0){
            return true;
        }
        for (ZfDownload zfDownload: zfDownloads) {
            id.add(zfDownload.getId());
        }
 
        System.out.println(id);
 
        if (removeByIds(id)) {
 
            //删除es中的数据
            zfDownloads.stream().forEach(zfDoctorDownload -> {
                EsModel esModel = esService.findByCtId(zfDoctorDownload.getId().intValue(), "旅游统计表下载删除");
 
                if (esModel != null) {
                    DeleteRequest deleteRequest = new DeleteRequest("allsearchdata", esModel.getId());
                    try {
                        restHighLevelClient.delete(deleteRequest, RequestOptions.DEFAULT);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
            return true;
        } else {
            return false;
        }
    }
 
    @Override
    public AjaxResult selectDoctorList(ZfDownload zfDownload, Integer pageNo, Integer pageSize) {
        ZInfoUser myself = zInfoUserService.getMyself();
        LambdaQueryWrapper<ZfDownload> lqw = buildCondition(zfDownload,myself.getUserId());
        List<ZfDownload> beanRecords = list(lqw);
        List<TravelCount> bs = new ArrayList<>();
        for (ZfDownload a: beanRecords) {
            if (travelCountService.getById(a.getDownloadContent()) != null) {
                TravelCount ds = travelCountService.getById(a.getDownloadContent());
                ds.setShareId(a.getShareId().intValue());
                bs.add(ds);
            }
        }
        List<TravelCount>  record = bs.stream().skip((pageNo-1)*pageSize).limit(pageSize).collect(Collectors.toList());
 
        int totalPage = (bs.size() -1) / pageSize +1;
 
        Page<TravelCount> travelCountPage = new Page<>(pageNo, pageSize,totalPage);
        HashMap<String, Object> data = MapUtils.getShareResult(travelCountPage, record,bs.size());
        return AjaxResult.success(data);
    }
 
}