| | |
| | | package com.ruoyi.service.impl; |
| | | |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | 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.service.*; |
| | | import com.ruoyi.util.ArraysUtil; |
| | | 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.data.elasticsearch.core.ElasticsearchRestTemplate; |
| | | import org.springframework.security.core.parameters.P; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | ZAuthorityService zAuthorityService; |
| | | //加入到es中 |
| | | @Resource |
| | | private esService esSer; |
| | | private EsService esSer; |
| | | |
| | | @Resource |
| | | private RestHighLevelClient restHighLevelClient; |
| | | private LambdaQueryWrapper<ZfEvent> buildCondition(ZfEvent zfEvent,List<Long> familyIdList) { |
| | | LambdaQueryWrapper<ZfEvent> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.orderByDesc(ZfEvent::getCreateTime); |
| | |
| | | // String secondFamilyIds = listSecondFamilyIds(); |
| | | //要查自己家庭的 |
| | | ZInfoUser myself = zInfoUserService.getMyself(); |
| | | System.out.println("================"); |
| | | |
| | | Long familyId = myself.getFamilyId(); |
| | | |
| | | //也要查别人授权的 |
| | | List<ZAuthority> authority = zAuthorityService.getAuthority(); |
| | | List<Long> idList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(EVENT_LIST)).map(ZAuthority::getFid).collect(Collectors.toList()); |
| | |
| | | public AjaxResult selectDataList(ZfEvent zfEvent, Integer pageNum, Integer pageSize) { |
| | | //要查自己家庭的 |
| | | ZInfoUser myself = zInfoUserService.getMyself(); |
| | | if(myself==null) |
| | | { |
| | | // System.out.println("ssssss"); |
| | | return AjaxResult.success("您没加入到对应的家庭,请联系管理员"); |
| | | } |
| | | Long familyId = myself.getFamilyId(); |
| | | System.out.println("++++++++++++++++"); |
| | | System.out.println(familyId); |
| | | //也要查别人授权的 |
| | | List<ZAuthority> authority = zAuthorityService.getAuthority(); |
| | | List<Long> idList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(EVENT_LIST)).map(ZAuthority::getFid).collect(Collectors.toList()); |
| | | //加上自己家庭的id |
| | | idList.add(familyId); |
| | | System.out.println(idList.size()); |
| | | // String familyIds = listFamilyIds(); |
| | | // String secondFamilyAuthority = listSecondFamilyIds(); |
| | | LambdaQueryWrapper<ZfEvent> lqw = buildCondition(zfEvent, idList); |
| | |
| | | |
| | | List<ZfEvent> beanRecords = pageResult.getRecords();//得到查询出来的数据 |
| | | |
| | | System.out.println(beanRecords); |
| | | System.out.println(beanRecords.size()); |
| | | List<ZfEvent> dtoResult = markOwnData(familyId, beanRecords); |
| | | |
| | | HashMap<String, Object> data = MapUtils.getResult(pageResult, dtoResult); |
| | |
| | | } |
| | | |
| | | if (save(zfEvent)) { |
| | | // 飞 加入 |
| | | EsModel esModel = new EsModel(); |
| | | Integer inte = zfEvent.getId(); |
| | | String uuid = UUID.randomUUID().toString().replace("-",""); |
| | | esModel.setId(uuid); |
| | | esModel.setCtId(Long.valueOf(inte)); |
| | | esModel.setCtName(zfEvent.getTitle()); |
| | | esModel.setCtContent(zfEvent.getAddress()); |
| | | esModel.setBy1(zfEvent.getRemark()); |
| | | |
| | | // esModel.setCtTableName("tb_ajk"); |
| | | // esModel.setCtName("大家"); |
| | | // esModel.setCtContent("大家好,才是真的好");//处事由 |
| | | esModel.setCtTableName("家大事记"); |
| | | esModel.setBy1(zfEvent.getAddress()); |
| | | esModel.setBy2(zfEvent.getPeople()); |
| | | esModel.setBy3(zfEvent.getTitle()); |
| | | esModel.setRemark(zfEvent.getRemark()); |
| | | //这里存储查询详情的路径 |
| | | esModel.setBy5("/family/zfEvent"); |
| | | esModel.setFid(familyId); |
| | | esSer.insertTable(esModel); |
| | | |
| | | return AjaxResult.success(); |
| | | } else { |
| | | return AjaxResult.error(); |
| | |
| | | ZfLogService zfLogService; |
| | | |
| | | @Override |
| | | @Transactional |
| | | public AjaxResult updateData(ZfEvent zfEvent) { |
| | | ZInfoUser myself = zInfoUserService.getMyself(); |
| | | Long familyId = myself.getFamilyId(); |
| | |
| | | zfLog.setUpdater(zInfoUserService.getMyself().getNickName()); |
| | | zfLogService.save(zfLog); |
| | | |
| | | if(updateById(zfEvent)){ |
| | | if(zfEventService.updateById(zfEvent)){ |
| | | //到数据库中查询对应的数据 |
| | | ZfEvent dataById = getById(zfEvent.getId()); |
| | | |
| | | //先到es中查询到对应那条数据在es的id |
| | | EsModel esResult = esSer.findByCtId(dataById.getId(), "家大事记"); |
| | | |
| | | if (esResult == null){ |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | //操作es修改数据 |
| | | EsModel newModel = new EsModel(); |
| | | if(zfEvent.getAddress()!=null){ |
| | | newModel.setBy1(zfEvent.getAddress()); |
| | | }else { |
| | | newModel.setBy1(dataById.getAddress()); |
| | | } |
| | | |
| | | if(zfEvent.getPeople()!=null){ |
| | | newModel.setBy2(zfEvent.getPeople()); |
| | | }else { |
| | | newModel.setBy2(dataById.getPeople()); |
| | | } |
| | | |
| | | if(zfEvent.getTitle()!=null){ |
| | | newModel.setBy3(zfEvent.getTitle()); |
| | | }else { |
| | | newModel.setBy3(dataById.getTitle()); |
| | | } |
| | | |
| | | if(zfEvent.getRemark()!=null){ |
| | | newModel.setRemark(zfEvent.getRemark()); |
| | | }else { |
| | | newModel.setRemark(dataById.getRemark()); |
| | | } |
| | | |
| | | UpdateRequest updateRequest = new UpdateRequest("allsearchdata", esResult.getId()); |
| | | updateRequest.doc( |
| | | "by1",newModel.getBy1(), |
| | | "by2",newModel.getBy2(), |
| | | "by3",newModel.getBy3(), |
| | | "by4",newModel.getBy4(), |
| | | "remark",newModel.getRemark() |
| | | ); |
| | | |
| | | try { |
| | | restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | }else { |
| | | return AjaxResult.error(); |
| | |
| | | } |
| | | } |
| | | |
| | | List<ZfEvent> zfEvents = listByIds(Arrays.asList(ids)); |
| | | |
| | | if (zfEventService.removeByIds(Arrays.asList(ids))) { |
| | | |
| | | //删除es中的数据 |
| | | zfEvents.stream().forEach(zfEvent -> { |
| | | EsModel esModel = esSer.findByCtId(zfEvent.getId(), "家大事记"); |
| | | 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(); |