feige
2024-11-10 f33f5d962eddbc75f3db8124b14f8a50d93cf625
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
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.LiveStreaming;
import com.ruoyi.domain.Meeting;
import com.ruoyi.mapper.LiveStreamingBackMapper;
import com.ruoyi.service.EsService;
import com.ruoyi.service.LiveStreamingBackService;
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.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
 
@Service
public class LiveStreamingBackServiceImpl extends ServiceImpl<LiveStreamingBackMapper, LiveStreaming> implements LiveStreamingBackService {
 
    @Resource
    private EsService esSer;
 
    @Resource
    private RestHighLevelClient restHighLevelClient;
 
    private LambdaQueryWrapper<LiveStreaming> buildCondition(LiveStreaming liveStreaming) {
        LambdaQueryWrapper<LiveStreaming> lqw = new LambdaQueryWrapper<>();
//        lqw.in(LiveStreaming::getFamilyId,familyIdList);
        lqw.orderByDesc(LiveStreaming::getId);
        lqw.like(StringUtils.isNotEmpty(liveStreaming.getTitle()), LiveStreaming::getTitle, liveStreaming.getTitle())
                .like(StringUtils.isNotEmpty(liveStreaming.getApplyPerson()),LiveStreaming::getApplyPerson,liveStreaming.getApplyPerson())
                .eq(LiveStreaming::getStatus,1)
                .like(StringUtils.isNotEmpty(liveStreaming.getContactPerson()),LiveStreaming::getContactPerson,liveStreaming.getContactPerson());
        lqw.between(liveStreaming.getHappenStartTime() != null && liveStreaming.getHappenEndTime() != null,LiveStreaming::getCreateTime,liveStreaming.getHappenStartTime(),liveStreaming.getHappenEndTime());
 
        return lqw;
    }
 
    @Override
    public AjaxResult selectDataList(LiveStreaming liveStreaming, 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<LiveStreaming> lqw = buildCondition(liveStreaming);
 
 
        Page<LiveStreaming> liveStreamingPage = new Page<>(pageNum, pageSize);
        Page<LiveStreaming> pageResult = page(liveStreamingPage, lqw);
 
        List<LiveStreaming> beanRecords = pageResult.getRecords();//得到查询出来的数据
 
//        List<LiveStreaming> dtoResult = markOwnData(familyId, beanRecords);
 
        HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords);
        return AjaxResult.success(data);
 
    }
 
 
    @Override
    public List<LiveStreaming> selectByIds(Long[] ids) {
        List<LiveStreaming> list = new ArrayList<>();
        if (ids.length != 0)
            list = listByIds(Arrays.asList(ids));
        else
            list = list();
        return list;
    }
 
    @Override
    public AjaxResult deleteData(Long[] ids) {
 
//        List<Meeting> dataList = meetingService.listByIds(Arrays.asList(ids));
//
//        ZInfoUser myself = zInfoUserService.getMyself();
//        Long familyId = myself.getFamilyId();
//
//        List<ZAuthority> authority = zAuthorityService.getAuthority();
//        List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(EVENT_LIST_REMOVE)).map(ZAuthority::getFid).collect(Collectors.toList());
//        familyIdList.add(familyId);
//
//        for (Meeting data : dataList) {
//            if (!familyIdList.contains(data.getFamilyId())){
//                throw new RuntimeException("你没有权限操作此家庭的数据");
//            }
//        }
 
        List<LiveStreaming> liveStreamings = listByIds(Arrays.asList(ids));
 
        if (removeByIds(Arrays.asList(ids))) {
 
            //删除es中的数据
            liveStreamings.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();
        }
 
    }
}