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 implements LiveStreamingBackService { @Resource private EsService esSer; @Resource private RestHighLevelClient restHighLevelClient; private LambdaQueryWrapper buildCondition(LiveStreaming liveStreaming) { LambdaQueryWrapper 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 authority = zAuthorityService.getAuthority(); // List 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 lqw = buildCondition(liveStreaming); Page liveStreamingPage = new Page<>(pageNum, pageSize); Page pageResult = page(liveStreamingPage, lqw); List beanRecords = pageResult.getRecords();//得到查询出来的数据 // List dtoResult = markOwnData(familyId, beanRecords); HashMap data = MapUtils.getResult(pageResult, beanRecords); return AjaxResult.success(data); } @Override public List selectByIds(Long[] ids) { List list = new ArrayList<>(); if (ids.length != 0) list = listByIds(Arrays.asList(ids)); else list = list(); return list; } @Override public AjaxResult deleteData(Long[] ids) { // List dataList = meetingService.listByIds(Arrays.asList(ids)); // // ZInfoUser myself = zInfoUserService.getMyself(); // Long familyId = myself.getFamilyId(); // // List authority = zAuthorityService.getAuthority(); // List 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 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(); } } }