feige
2025-06-14 061f8f5f29fbc3c34719be14b6d178a92b636f78
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
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.*;
import com.ruoyi.mapper.MeetingStatisticMapper;
import com.ruoyi.service.*;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.update.UpdateRequest;
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.time.LocalDateTime;
import java.util.*;
 
 
@Slf4j
@Service
public class MeetingStatisticServiceImpl extends ServiceImpl<MeetingStatisticMapper, MeetingStatistic> implements MeetingStatisticService {
 
    @Resource
    ZInfoUserService zInfoUserService;
 
    @Resource
    ZfLogService zfLogService;
 
    @Resource
    private RestHighLevelClient restHighLevelClient;
 
    @Resource
    private EsService esSer;
 
    @Resource
    ZAuthorityService zAuthorityService;
 
    @Resource
    private MeetingStatisticService meetingStatisticService;
 
    private LambdaQueryWrapper<MeetingStatistic> uniqueCondition(MeetingStatistic meetingStatistic){
        LambdaQueryWrapper<MeetingStatistic> lqw = new LambdaQueryWrapper<>();
        lqw.eq(!StringUtils.isEmpty(meetingStatistic.getUseTime()), MeetingStatistic::getUseTime, meetingStatistic.getUseTime());
        lqw.eq(!StringUtils.isEmpty(meetingStatistic.getConferenceRoom()), MeetingStatistic::getConferenceRoom, meetingStatistic.getConferenceRoom());
        lqw.eq(!StringUtils.isEmpty(meetingStatistic.getTitle()), MeetingStatistic::getTitle, meetingStatistic.getTitle());
//        lqw.eq(meetingStatistic.getFamilyId()!=null,MeetingStatistic::getFamilyId,meeting.getFamilyId());
        lqw.eq(!StringUtils.isEmpty(meetingStatistic.getApplyPerson()), MeetingStatistic::getApplyPerson, meetingStatistic.getApplyPerson());
        lqw.eq(!StringUtils.isEmpty(String.valueOf(meetingStatistic.getRatifyPerson())), MeetingStatistic::getRatifyPerson, meetingStatistic.getRatifyPerson());
        lqw.eq(!StringUtils.isEmpty(String.valueOf(meetingStatistic.getStatus())), MeetingStatistic::getStatus, meetingStatistic.getStatus());
        lqw.eq(!StringUtils.isEmpty(String.valueOf(meetingStatistic.getFamilyId())), MeetingStatistic::getFamilyId, meetingStatistic.getFamilyId());
        return lqw;
    }
    public static void getDatePoor(Date endDate, Date nowDate, MeetingStatistic meetingStatistic) {
 
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
         long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
//        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
         long sec = diff % nd % nh % nm / ns;
        System.out.println(hour + "小时" + min + "分钟"+ sec + "秒");
        meetingStatistic.setUseTime(hour + "小时" + min + "分钟" + sec + "秒");
    }
    private LambdaQueryWrapper<MeetingStatistic> buildCondition(MeetingStatistic meetingStatistic) {
        LambdaQueryWrapper<MeetingStatistic> lqw = new LambdaQueryWrapper<>();
        lqw.select(MeetingStatistic::getFamilyId,MeetingStatistic::getCreateTime);
        return lqw;
    }
    @Override
    public AjaxResult selectDataList(MeetingStatistic meetingStatistic, Integer pageNum, Integer pageSize) {
        //要查自己家庭的
        ZInfoUser myself = zInfoUserService.getMyself();
        if(myself==null)
        {
            //   System.out.println("ssssss");
            return AjaxResult.success("您没加入到对应的家庭,请联系管理员");
        }
        Long familyId = myself.getFamilyId();
//        //也要查别人授权的
//        List<ZAuthority> authority = zAuthorityService.getAuthority();
//        List<Long> idList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(DOCTOR_LIST)).map(ZAuthority::getFid).collect(Collectors.toList());
//        //加上自己家庭的id
//        idList.add(familyId);
//        String familyIds = listFamilyIds();
//        String secondFamilyAuthority = listSecondFamilyIds();
        LambdaQueryWrapper<MeetingStatistic> lqw = new LambdaQueryWrapper<>();
//        LambdaQueryWrapper<MeetingStatistic> lqw = buildCondition(meetingStatistic);
 
 
        Page<MeetingStatistic> meetingStatisticPage = new Page<>(pageNum, pageSize);
        Page<MeetingStatistic> pageResult = page(meetingStatisticPage, lqw);
 
        List<MeetingStatistic> beanRecords = pageResult.getRecords();//得到查询出来的数据
        System.out.println("-----------数据库-----------"+beanRecords);
        HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords);
        return AjaxResult.success(data);
    }
    @Override
    public AjaxResult DataList(MeetingStatistic meetingStatistic) {
        LambdaQueryWrapper<MeetingStatistic> lambdaQueryWrapper = buildCondition(meetingStatistic);
        List<MeetingStatistic> beanRecords = list(lambdaQueryWrapper);
        log.info("从数据库中查到的为:{}", beanRecords);
        return  AjaxResult.success(beanRecords);
    }
 
    @Override
    public AjaxResult updateData(MeetingStatistic meetingStatistic) {
        ZfLog zfLog = new ZfLog();
        zfLog.setUpdateTime(LocalDateTime.now());
        zfLog.setModule("会议统计");
        zfLog.setUpdater(zInfoUserService.getMyself().getNickName());
        zfLogService.save(zfLog);
        System.out.println("===================================="+meetingStatistic);
        if(updateById(meetingStatistic)){
            //到数据库中查询对应的数据
            MeetingStatistic dataById = getById(meetingStatistic.getId());
 
            //先到es中查询到对应那条数据在es的id
            EsModel esResult = esSer.findByCtId(dataById.getId().intValue(), "会议统计");
            System.out.println("===================================="+meetingStatistic);
            if (esResult == null){
                return AjaxResult.success();
            }
 
            //操作es修改数据
            EsModel newModel = new EsModel();
//            System.out.println(meeting);
//            System.out.println("=============="+meetingStatistic.getConnPhone());
 
//           if (meetingStatistic.getUseTime()==null){
//                if(meetingStatistic.getHappenEndTime()!=null && meetingStatistic.getHappenStartTime() !=null){
//                  getDatePoor(meetingStatistic.getHappenEndTime(),meetingStatistic.getHappenStartTime(),meetingStatistic);
//                    System.out.println("===============使用时间====================="+meetingStatistic.getUseTime());
//                    newModel.setBy2(meetingStatistic.getUseTime());
//                }else {
//                    newModel.setBy2(dataById.getUseTime());
//                }
//            }
            if (meetingStatistic.getUseTime()==null){
                if(meetingStatistic.getHappenEndTime()!=null && meetingStatistic.getHappenStartTime() !=null){
                    getDatePoor(meetingStatistic.getHappenEndTime(),meetingStatistic.getHappenStartTime(),meetingStatistic);
                    newModel.setBy1(meetingStatistic.getUseTime());
                }
                else {
                    newModel.setBy1(dataById.getUseTime());
                }
            }else {
                newModel.setBy1(dataById.getUseTime());
            }
//            if(meetingStatistic.getConferenceRoom()!=null){
//                newModel.setBy3(meetingStatistic.getConferenceRoom());
//            }else {
//                newModel.setBy3(dataById.getConferenceRoom());
//            }
            if(meetingStatistic.getTitle()!=null){
                newModel.setBy2(meetingStatistic.getTitle());
            }else {
                newModel.setBy2(dataById.getTitle());
            }
//            if(meetingStatistic.getApplyPerson()!=null){
//                newModel.setBy5(meetingStatistic.getApplyPerson());
//            }else {
//                newModel.setBy5(dataById.getApplyPerson());
//            }
//            if(meetingStatistic.getRatifyPerson() == 0){
//                newModel.setBy10(meetingStatistic.getRatifyPerson());
//            }else {
//                newModel.setBy10(dataById.getRatifyPerson());
//            }
//            if(meetingStatistic.getStatus() == 0){
//                newModel.setBy11(meetingStatistic.getStatus());
//            }else {
//                newModel.setBy11(dataById.getStatus());
//            }
            UpdateRequest updateRequest = new UpdateRequest("allsearchdata", esResult.getId());
            updateRequest.doc(
                    "by1",newModel.getBy1(),
                    "by2",newModel.getBy2()
 
            );
 
            LambdaQueryWrapper<MeetingStatistic> lqw = new LambdaQueryWrapper<>();
            List<MeetingStatistic> beanRecords = list(lqw);
            log.info("sss从数据库中查到的为:{}", beanRecords);
 
            try {
                restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
 
 
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
 
    @Override
    public AjaxResult deleteData(Long[] ids) {
        List<MeetingStatistic> meetings = listByIds(Arrays.asList(ids));
        if (meetingStatisticService.removeByIds(Arrays.asList(ids))) {
            //删除es中的数据
            meetings.stream().forEach(meeting -> {
                EsModel esModel = esSer.findByCtId((meeting.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 AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
 
    }
 
    @Override
    public List<MeetingStatistic> selectByIds(Long[] ids) {
        List<MeetingStatistic> list = new ArrayList<>();
        if (ids.length != 0)
            list = listByIds(Arrays.asList(ids));
        else
            list = list();
        return list;
 
    }
    @Override
    public AjaxResult addData(MeetingStatistic meetingStatistic) {
 
        ZInfoUser myself = zInfoUserService.getMyself();
        Long familyId = myself.getFamilyId();
 
//        if(familyId == null){
//            throw new RuntimeException("您还未加入任何家庭");
//        }
//
//        List<ZAuthority> authority = zAuthorityService.getAuthority();
//        List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(EVENT_LIST_ADD)).map(ZAuthority::getFid).collect(Collectors.toList());
//        familyIdList.add(familyId);
//
//        if (meetingStatistic.getFamilyId()!=null && !familyIdList.contains(meetingStatistic.getFamilyId())) {
//            throw new RuntimeException("你没有权限操作此家庭的数据");
//        }
//
//
//        if(meetingStatistic.getFamilyId() == null){
//            //默认添加自己家庭的数据
//            meetingStatistic.setFamilyId(familyId);
//        }
 
        //判断是否有重复数据
        LambdaQueryWrapper<MeetingStatistic> lqw = uniqueCondition(meetingStatistic);
        List<MeetingStatistic> list = list(lqw);
 
        if(list.size()>0){
            throw new RuntimeException("请勿新增重复数据");
        }
 
        if (save(meetingStatistic)) {
            EsModel esModel = new EsModel();
            Long inte = meetingStatistic.getId();
            String uuid = UUID.randomUUID().toString().replace("-","");
            esModel.setId(uuid);
            esModel.setCtId(inte);
            esModel.setCtTableName("会议统计");
            getDatePoor(meetingStatistic.getHappenEndTime(),meetingStatistic.getHappenStartTime(),meetingStatistic);
            System.out.println("===============使用时间2====================="+meetingStatistic.getUseTime());
            esModel.setBy1(meetingStatistic.getUseTime());
            esModel.setBy2(meetingStatistic.getTitle());
//            esModel.setBy5(meetingStatistic.getApplyPerson());
            //这里存储查询详情的路径
            esModel.setBy5("/zMeetingStatistic");
            esModel.setFid(familyId);
            esSer.insertTable(esModel);
 
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }
}