whywhyo
2023-09-17 944a01d60ffd53ca3a3b87ccfcaedc096219aba2
77777
11个文件已修改
3个文件已添加
2个文件已删除
1147 ■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/EsSearchController.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/resources/application-druid.yml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/test/java/com/ruoyi/esTest.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/EsModel.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/EsService.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/esService.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/EsServiceImpl.java 124 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java 107 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZfCleanServiceImpl.java 105 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZfCollectionServiceImpl.java 108 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZfContactServiceImpl.java 99 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java 114 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZfEconomyServiceImpl.java 86 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZfEquipmentServiceImpl.java 106 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZfEventServiceImpl.java 129 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/esServiceImpl.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/EsSearchController.java
New file
@@ -0,0 +1,45 @@
package com.ruoyi.web.controller.zhang;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.EsModel;
import com.ruoyi.service.EsService;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
 * @Author Jinquan_Ou
 * @Description
 * @Date 2023-09-17 16:39
 * @Version 1.0.0
 **/
@RestController
@RequestMapping("/search")
public class EsSearchController {
    @Resource
    EsService esService;
    @GetMapping()
    public AjaxResult search(String keyword){
        List<EsModel> byCondition = esService.findByCondition(keyword);
        return AjaxResult.success(byCondition);
    }
    @DeleteMapping
    public AjaxResult deleteAllData(){
        esService.deleteAllData();
        return AjaxResult.success();
    }
    @GetMapping("/all")
    public AjaxResult getAll(){
        List<EsModel> modelList = esService.getAll();
        return AjaxResult.success(modelList);
    }
}
ruoyi-admin/src/main/resources/application-druid.yml
@@ -6,8 +6,8 @@
        druid:
            # 主库数据源
            master:
                #url: jdbc:mysql://47.93.189.255:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                url: jdbc:mysql://localhost:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                url: jdbc:mysql://47.93.189.255:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
#                url: jdbc:mysql://localhost:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                username: root
                password: ZhangApp123!
#                password: 123456
ruoyi-admin/src/test/java/com/ruoyi/esTest.java
@@ -9,7 +9,7 @@
import com.ruoyi.domain.ZfEvent;
import com.ruoyi.mapper.EsRepository;
import com.ruoyi.service.ZfEventService;
import com.ruoyi.service.esService;
import com.ruoyi.service.EsService;
import org.elasticsearch.client.IndicesClient;
import org.junit.jupiter.api.Test;
@@ -22,7 +22,7 @@
@SpringBootTest
public class esTest {
    @Autowired
    private esService ess;
    private EsService ess;
    @Autowired
    private EsRepository resp;
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/EsModel.java
@@ -66,4 +66,13 @@
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String by5;
    /** 备用6 */
    @Field(index = true,type = FieldType.Text,analyzer = "ik_max_word")
    private String by6;
    /** 备用6 */
    @Field(index = true,type = FieldType.Text,analyzer = "ik_max_word")
    private String by7;
}
zhang-content/src/main/java/com/ruoyi/service/EsService.java
New file
@@ -0,0 +1,23 @@
package com.ruoyi.service;
import com.ruoyi.common.core.domain.entity.EsModel;
import org.springframework.data.elasticsearch.core.SearchHits;
import java.util.List;
public interface EsService {
    //  插入索引
    public int insertTable(EsModel esModel);
    //
    public List<EsModel> findByCondition(String con);
    public EsModel findByCtId(Integer ctId,String ctTableName);
    public void deleteById(String id);
    void deleteAllData();
    List<EsModel> getAll();
}
zhang-content/src/main/java/com/ruoyi/service/esService.java
File was deleted
zhang-content/src/main/java/com/ruoyi/service/impl/EsServiceImpl.java
New file
@@ -0,0 +1,124 @@
package com.ruoyi.service.impl;
import com.ruoyi.common.core.domain.entity.EsModel;
import com.ruoyi.mapper.EsRepository;
import com.ruoyi.service.EsService;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
@Service
public class EsServiceImpl implements EsService {
    @Resource
    private EsRepository esRepository;
    @Resource
    private ElasticsearchRestTemplate elasticsearchRestTemplate;
    @Override
    public int insertTable(EsModel esModel) {
        try {
            esRepository.save(esModel);
           // esRepository.searchSimilar()
        } catch (Exception e) {
            System.out.println(e);
            // throw new Exception("ES数据同步失败,请联系管理员处理!");
        }
        return 0;
    }
    //  全文检索
    @Override
    public List<EsModel> findByCondition(String con) {
        List<EsModel> esm = new ArrayList<>();
       // MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("title", title);
        //多字段进行匹配
//        MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery(con, "ctName", "ctContent","remark",
//                "by1","by2","by3","by4");
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        boolQueryBuilder.should(QueryBuilders.matchQuery("ctName",con));
        boolQueryBuilder.should(QueryBuilders.matchQuery("ctContent",con));
        boolQueryBuilder.should(QueryBuilders.matchQuery("remark",con));
        boolQueryBuilder.should(QueryBuilders.matchQuery("by1",con));
        boolQueryBuilder.should(QueryBuilders.matchQuery("by2",con));
        boolQueryBuilder.should(QueryBuilders.matchQuery("by3",con));
        boolQueryBuilder.should(QueryBuilders.matchQuery("by4",con));
        boolQueryBuilder.should(QueryBuilders.matchQuery("by6",con));
        boolQueryBuilder.should(QueryBuilders.matchQuery("by7",con));
        NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder()
                .withQuery(boolQueryBuilder);
        NativeSearchQuery nativeSearchQuery = nativeSearchQueryBuilder.build();
        // 执行查询
        SearchHits<EsModel> searchHits = elasticsearchRestTemplate.search(nativeSearchQuery,EsModel.class);
        searchHits.getSearchHits().forEach(personSearchHit -> {
            EsModel content = personSearchHit.getContent();
            esm.add(content);
        //    System.out.println(content);
        });
       // articleList.forEach(a-> System.out.println(a))
        return esm;
    }
    //根据mysql中的id查找信息
    @Override
    public EsModel findByCtId(Integer ctId, String ctTableName) {
//        NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
//                .withQuery(QueryBuilders.matchQuery("ctId", ctId)) // 自定义查询条件
//                .withQuery(QueryBuilders.matchQuery("ctTableName", ctTableName)) // 自定义查询条件
//                .build();
        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        boolQueryBuilder.must(QueryBuilders.matchQuery("ctId", ctId));
        boolQueryBuilder.must(QueryBuilders.matchQuery("ctTableName", ctTableName));
        NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder()
                .withQuery(boolQueryBuilder);
        NativeSearchQuery nativeSearchQuery = nativeSearchQueryBuilder.build();
        return Objects.requireNonNull(elasticsearchRestTemplate.searchOne(nativeSearchQuery, EsModel.class)).getContent();
    }
    @Override
    public void deleteById(String id) {
        esRepository.deleteById(id);
    }
    @Override
    public void deleteAllData() {
        esRepository.deleteAll();
    }
    @Override
    public List<EsModel> getAll() {
        ArrayList<EsModel> esModels = new ArrayList<>();
        // 构建查询请求
        SearchHits<EsModel> searchHits = elasticsearchRestTemplate.search(Query.findAll(), EsModel.class,IndexCoordinates.of("allsearchdata"));
        Iterator<SearchHit<EsModel>> iterator = searchHits.stream().iterator();
        while (iterator.hasNext()){
            esModels.add(iterator.next().getContent());
        }
        // 返回查询结果
        return esModels;
    }
}
zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java
@@ -4,6 +4,7 @@
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.core.domain.entity.SysUser;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.SecurityUtils;
@@ -13,17 +14,19 @@
import com.ruoyi.constant.MenuAuthority;
import com.ruoyi.domain.*;
import com.ruoyi.mapper.ZfPropertyMapper;
import com.ruoyi.service.IZfPropertyService;
import com.ruoyi.service.ZAuthorityService;
import com.ruoyi.service.ZInfoUserService;
import com.ruoyi.service.ZfLogService;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
@@ -53,6 +56,12 @@
    @Resource
    ZfPropertyMapper zfPropertyMapper;
    @Resource
    EsService esService;
    @Resource
    RestHighLevelClient restHighLevelClient;
//    private LambdaQueryWrapper<ZfProperty> buildCondition(ZfProperty zfProperty) {
@@ -378,6 +387,23 @@
        }
        if (save(zfProperty)) {
            EsModel esModel = new EsModel();
            Integer inte = zfProperty.getId().intValue();
            String uuid = UUID.randomUUID().toString().replace("-","");
            esModel.setId(uuid);
            esModel.setCtId(Long.valueOf(inte));
            esModel.setCtTableName("家庭资产");
            esModel.setBy1(zfProperty.getType());
            esModel.setBy2(zfProperty.getTitle());
            esModel.setBy3(zfProperty.getLocation());
            esModel.setBy4(zfProperty.getHolder());
            esModel.setBy5("/family/zfProperty");
            esModel.setBy6(zfProperty.getAddress());
            esModel.setRemark(zfProperty.getRemark());
            //这里存储查询详情的路径
            esService.insertTable(esModel);
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
@@ -411,6 +437,66 @@
        zfLogService.save(zfLog);
        if(updateById(zfProperty)){
            //到数据库中查询对应的数据
            ZfProperty dataById = getById(zfProperty.getId());
            //先到es中查询到对应那条数据在es的id
            EsModel esResult = esService.findByCtId(dataById.getId().intValue(), "家庭资产");
            //操作es修改数据
            EsModel newModel = new EsModel();
            if(zfProperty.getType()!=null){
                newModel.setBy1(zfProperty.getType());
            }else {
                newModel.setBy1(dataById.getType());
            }
            if(zfProperty.getTitle()!=null){
                newModel.setBy2(zfProperty.getTitle());
            }else {
                newModel.setBy2(dataById.getTitle());
            }
            if(zfProperty.getLocation()!=null){
                newModel.setBy3(zfProperty.getLocation());
            }else {
                newModel.setBy3(dataById.getLocation());
            }
            if(zfProperty.getHolder()!=null){
                newModel.setBy4(zfProperty.getHolder());
            }else {
                newModel.setBy4(dataById.getHolder());
            }
            if(zfProperty.getAddress()!=null){
                newModel.setBy6(zfProperty.getAddress());
            }else {
                newModel.setBy6(dataById.getAddress());
            }
            if(zfProperty.getRemark()!=null){
                newModel.setRemark(zfProperty.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(),
                    "by6",newModel.getBy6(),
                    "remark",newModel.getRemark()
            );
            try {
                restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
@@ -436,7 +522,20 @@
            }
        }
        List<ZfProperty> zfPropertys = listByIds(Arrays.asList(ids));
        if (zfPropertyService.removeByIds(Arrays.asList(ids))) {
            //删除es中的数据
            zfPropertys.stream().forEach(zfProperty -> {
                EsModel esModel = esService.findByCtId(zfProperty.getId().intValue(), "家庭资产");
                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();
zhang-content/src/main/java/com/ruoyi/service/impl/ZfCleanServiceImpl.java
@@ -5,6 +5,7 @@
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.core.domain.entity.SysUser;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.SecurityUtils;
@@ -14,23 +15,22 @@
import com.ruoyi.domain.ZfClean;
import com.ruoyi.mapper.ZfCleanMapper;
import com.ruoyi.service.ZAuthorityService;
import com.ruoyi.service.ZInfoUserService;
import com.ruoyi.service.ZfCleanService;
import com.ruoyi.service.*;
import com.ruoyi.service.ZfLogService;
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.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.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import static com.ruoyi.constant.MenuAuthority.*;
@@ -58,6 +58,12 @@
    @Resource
    ZfLogService zfLogService;
    @Resource
    EsService esService;
    @Resource
    RestHighLevelClient restHighLevelClient;
    private LambdaQueryWrapper<ZfClean> buildCondition(ZfClean zfClean,List<Long> familyIdList) {
        LambdaQueryWrapper<ZfClean> lqw = new LambdaQueryWrapper<>();
@@ -373,6 +379,22 @@
        }
        if (save(zfClean)) {
            EsModel esModel = new EsModel();
            Integer inte = zfClean.getId().intValue();
            String uuid = UUID.randomUUID().toString().replace("-","");
            esModel.setId(uuid);
            esModel.setCtId(Long.valueOf(inte));
            esModel.setCtTableName("保洁与收纳");
            esModel.setBy1(zfClean.getType());
            esModel.setBy2(zfClean.getMethod());
            esModel.setBy3(zfClean.getPlace());
            esModel.setBy4(zfClean.getSuitable());
            esModel.setBy5("/family/zfClean");
            esModel.setRemark(zfClean.getRemark());
            //这里存储查询详情的路径
            esService.insertTable(esModel);
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
@@ -464,6 +486,60 @@
        if(updateById(zfClean)){
            //到数据库中查询对应的数据
            ZfClean dataById = getById(zfClean.getId());
            //先到es中查询到对应那条数据在es的id
            EsModel esResult = esService.findByCtId(dataById.getId().intValue(), "保洁与收纳");
            //操作es修改数据
            EsModel newModel = new EsModel();
            if(zfClean.getType()!=null){
                newModel.setBy1(zfClean.getType());
            }else {
                newModel.setBy1(dataById.getType());
            }
            if(zfClean.getMethod()!=null){
                newModel.setBy2(zfClean.getMethod());
            }else {
                newModel.setBy2(dataById.getMethod());
            }
            if(zfClean.getPlace()!=null){
                newModel.setBy3(zfClean.getPlace());
            }else {
                newModel.setBy3(dataById.getPlace());
            }
            if(zfClean.getSuitable()!=null){
                newModel.setBy4(zfClean.getSuitable());
            }else {
                newModel.setBy4(dataById.getSuitable());
            }
            if(zfClean.getRemark()!=null){
                newModel.setRemark(zfClean.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();
@@ -489,7 +565,20 @@
            }
        }
        List<ZfClean> zfCleans = listByIds(Arrays.asList(ids));
        if (zfCleanService.removeByIds(Arrays.asList(ids))) {
            //删除es中的数据
            zfCleans.stream().forEach(zfClean -> {
                EsModel esModel = esService.findByCtId(zfClean.getId().intValue(), "保洁与收纳");
                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();
zhang-content/src/main/java/com/ruoyi/service/impl/ZfCollectionServiceImpl.java
@@ -7,6 +7,7 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonParser;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.EsModel;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.SecurityUtils;
@@ -16,17 +17,19 @@
import com.ruoyi.domain.ZfCollection;
import com.ruoyi.domain.ZfCollection;
import com.ruoyi.mapper.ZfCollectionMapper;
import com.ruoyi.service.ZAuthorityService;
import com.ruoyi.service.ZInfoUserService;
import com.ruoyi.service.ZfCollectionService;
import com.ruoyi.service.ZfLogService;
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.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;
@@ -59,6 +62,12 @@
    @Resource
    ZfLogService zfLogService;
    @Resource
    EsService esService;
    @Resource
    RestHighLevelClient restHighLevelClient;
    private LambdaQueryWrapper<ZfCollection> buildCondition(ZfCollection zfCollection,List<Long> familyIdList) {
        LambdaQueryWrapper<ZfCollection> lqw = new LambdaQueryWrapper<>();
@@ -383,6 +392,23 @@
        }
        if (save(zfCollection)) {
            EsModel esModel = new EsModel();
            Integer inte = zfCollection.getId().intValue();
            String uuid = UUID.randomUUID().toString().replace("-","");
            esModel.setId(uuid);
            esModel.setCtId(Long.valueOf(inte));
            esModel.setCtTableName("收藏和荣誉");
            esModel.setBy1(zfCollection.getType());
            esModel.setBy2(zfCollection.getName());
            esModel.setBy3(zfCollection.getSource());
            esModel.setBy4(zfCollection.getOwner());
            esModel.setBy5("/family/zfCollection");
            esModel.setBy6(zfCollection.getLocation());
            esModel.setRemark(zfCollection.getRemark());
            //这里存储查询详情的路径
            esService.insertTable(esModel);
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
@@ -437,6 +463,67 @@
        if(updateById(zfCollection)){
            //到数据库中查询对应的数据
            ZfCollection dataById = getById(zfCollection.getId());
            //先到es中查询到对应那条数据在es的id
            EsModel esResult = esService.findByCtId(dataById.getId().intValue(), "收藏和荣誉");
            //操作es修改数据
            EsModel newModel = new EsModel();
            if(zfCollection.getType()!=null){
                newModel.setBy1(zfCollection.getType());
            }else {
                newModel.setBy1(dataById.getType());
            }
            if(zfCollection.getName()!=null){
                newModel.setBy2(zfCollection.getName());
            }else {
                newModel.setBy2(dataById.getName());
            }
            if(zfCollection.getSource()!=null){
                newModel.setBy3(zfCollection.getSource());
            }else {
                newModel.setBy3(dataById.getSource());
            }
            if(zfCollection.getOwner()!=null){
                newModel.setBy4(zfCollection.getOwner());
            }else {
                newModel.setBy4(dataById.getOwner());
            }
            if(zfCollection.getLocation()!=null){
                newModel.setBy6(zfCollection.getLocation());
            }else {
                newModel.setBy6(dataById.getLocation());
            }
            if(zfCollection.getRemark()!=null){
                newModel.setRemark(zfCollection.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(),
                    "by6",newModel.getBy6(),
                    "remark",newModel.getRemark()
            );
            try {
                restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
@@ -460,7 +547,20 @@
            }
        }
        List<ZfCollection> zfCollections = listByIds(Arrays.asList(ids));
        if (zfCollectionService.removeByIds(Arrays.asList(ids))) {
            //删除es中的数据
            zfCollections.stream().forEach(zfCollection -> {
                EsModel esModel = esService.findByCtId(zfCollection.getId().intValue(), "收藏和荣誉");
                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();
zhang-content/src/main/java/com/ruoyi/service/impl/ZfContactServiceImpl.java
@@ -5,6 +5,7 @@
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.core.domain.entity.SysUser;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.SecurityUtils;
@@ -18,16 +19,18 @@
import com.ruoyi.service.ZfContactService;
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.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.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import static com.ruoyi.constant.MenuAuthority.*;
@@ -51,6 +54,12 @@
    
    @Resource
    ZAuthorityService zAuthorityService;
    @Resource
    EsService esService;
    @Resource
    RestHighLevelClient restHighLevelClient;
    private LambdaQueryWrapper<ZfContact> buildCondition(ZfContact zfContact,List<Long> familyIdList) {
@@ -353,6 +362,21 @@
        }
        if (save(zfContact)) {
            EsModel esModel = new EsModel();
            Integer inte = zfContact.getId().intValue();
            String uuid = UUID.randomUUID().toString().replace("-","");
            esModel.setId(uuid);
            esModel.setCtId(Long.valueOf(inte));
            esModel.setCtTableName("通讯录");
            esModel.setBy1(zfContact.getMyName());
            esModel.setBy2(zfContact.getNickName());
            esModel.setBy3(zfContact.getName());
            esModel.setBy4(zfContact.getWork());
            esModel.setBy5("/family/zfContact");
            esModel.setRemark(zfContact.getRemark());
            //这里存储查询详情的路径
            esService.insertTable(esModel);
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
@@ -458,6 +482,60 @@
        zfLogService.save(zfLog);
        if(updateById(zfContact)){
            //到数据库中查询对应的数据
            ZfContact dataById = getById(zfContact.getId());
            //先到es中查询到对应那条数据在es的id
            EsModel esResult = esService.findByCtId(dataById.getId().intValue(), "通讯录");
            //操作es修改数据
            EsModel newModel = new EsModel();
            if(zfContact.getMyName()!=null){
                newModel.setBy1(zfContact.getMyName());
            }else {
                newModel.setBy1(dataById.getMyName());
            }
            if(zfContact.getNickName()!=null){
                newModel.setBy2(zfContact.getNickName());
            }else {
                newModel.setBy2(dataById.getNickName());
            }
            if(zfContact.getName()!=null){
                newModel.setBy3(zfContact.getName());
            }else {
                newModel.setBy3(dataById.getName());
            }
            if(zfContact.getWork()!=null){
                newModel.setBy4(zfContact.getWork());
            }else {
                newModel.setBy4(dataById.getWork());
            }
            if(zfContact.getRemark()!=null){
                newModel.setRemark(zfContact.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();
@@ -481,7 +559,20 @@
            }
        }
        List<ZfContact> zfContacts = listByIds(Arrays.asList(ids));
        if (zfContactService.removeByIds(Arrays.asList(ids))) {
            //删除es中的数据
            zfContacts.stream().forEach(zfContact -> {
                EsModel esModel = esService.findByCtId(zfContact.getId().intValue(), "通讯录");
                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();
zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java
@@ -5,6 +5,7 @@
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.common.utils.poi.ExcelUtil;
@@ -13,15 +14,18 @@
import com.ruoyi.service.*;
import com.ruoyi.service.ZfDoctorService;
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.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import static com.ruoyi.constant.MenuAuthority.*;
@@ -49,6 +53,12 @@
    @Resource
    ZfDoctorMapper zfDoctorMapper;
    @Resource
    EsService esService;
    @Resource
    private RestHighLevelClient restHighLevelClient;
    @Override
    public AjaxResult selectDoctorList(ZfDoctor zfDoctor, Integer pageNum, Integer pageSize) {
@@ -180,6 +190,22 @@
        }
        if (save(zfDoctor)) {
            EsModel esModel = new EsModel();
            Integer inte = zfDoctor.getId().intValue();
            String uuid = UUID.randomUUID().toString().replace("-","");
            esModel.setId(uuid);
            esModel.setCtId(Long.valueOf(inte));
            esModel.setCtTableName("家庭小医生");
            esModel.setBy1(zfDoctor.getType());
            esModel.setBy2(zfDoctor.getSymptom());
            esModel.setBy3(zfDoctor.getEffect());
            esModel.setBy4(zfDoctor.getSuitable());
            esModel.setBy5("/family/zfDoctor");
            esModel.setBy6(zfDoctor.getCmedical());
            esModel.setBy7(zfDoctor.getWmedical());
            esModel.setRemark(zfDoctor.getRemark());
            //这里存储查询详情的路径
            esService.insertTable(esModel);
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
@@ -213,6 +239,74 @@
        zfLogService.save(zfLog);
        if(updateById(zfDoctor)){
            //到数据库中查询对应的数据
            ZfDoctor dataById = getById(zfDoctor.getId());
            //先到es中查询到对应那条数据在es的id
            EsModel esResult = esService.findByCtId(dataById.getId().intValue(), "家庭小医生");
            //操作es修改数据
            EsModel newModel = new EsModel();
            if(zfDoctor.getType()!=null){
                newModel.setBy1(zfDoctor.getType());
            }else {
                newModel.setBy1(dataById.getType());
            }
            if(zfDoctor.getSymptom()!=null){
                newModel.setBy2(zfDoctor.getSymptom());
            }else {
                newModel.setBy2(dataById.getSymptom());
            }
            if(zfDoctor.getEffect()!=null){
                newModel.setBy3(zfDoctor.getEffect());
            }else {
                newModel.setBy3(dataById.getEffect());
            }
            if(zfDoctor.getSuitable()!=null){
                newModel.setBy4(zfDoctor.getSuitable());
            }else {
                newModel.setBy4(dataById.getSuitable());
            }
            if(zfDoctor.getCmedical()!=null){
                newModel.setBy6(zfDoctor.getCmedical());
            }else {
                newModel.setBy6(dataById.getCmedical());
            }
            if(zfDoctor.getWmedical()!=null){
                newModel.setBy7(zfDoctor.getWmedical());
            }else {
                newModel.setBy7(dataById.getWmedical());
            }
            if(zfDoctor.getRemark()!=null){
                newModel.setRemark(zfDoctor.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(),
                    "by6",newModel.getBy6(),
                    "by7",newModel.getBy7(),
                    "remark",newModel.getRemark()
            );
            try {
                restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
@@ -235,8 +329,20 @@
                throw new RuntimeException("你没有权限操作此家庭的数据");
            }
        }
        List<ZfDoctor> zfDoctors = listByIds(Arrays.asList(ids));
        if (zfDoctorService.removeByIds(Arrays.asList(ids))) {
            //删除es中的数据
            zfDoctors.stream().forEach(zfDoctor -> {
                EsModel esModel = esService.findByCtId(zfDoctor.getId().intValue(), "家庭小医生");
                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();
zhang-content/src/main/java/com/ruoyi/service/impl/ZfEconomyServiceImpl.java
@@ -5,6 +5,7 @@
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.core.domain.entity.SysUser;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.SecurityUtils;
@@ -14,22 +15,21 @@
import com.ruoyi.domain.ZfEconomy;
import com.ruoyi.domain.ZfEconomy;
import com.ruoyi.mapper.ZfEconomyMapper;
import com.ruoyi.service.ZAuthorityService;
import com.ruoyi.service.ZInfoUserService;
import com.ruoyi.service.ZfEconomyService;
import com.ruoyi.service.ZfLogService;
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.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.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import static com.ruoyi.constant.MenuAuthority.*;
@@ -56,6 +56,12 @@
    @Resource
    ZfEconomyMapper zfEconomyMapper;
    @Resource
    EsService esService;
    @Resource
    RestHighLevelClient restHighLevelClient;
    private LambdaQueryWrapper<ZfEconomy> buildCondition(ZfEconomy zfEconomy,List<Long> familyIdList) {
        LambdaQueryWrapper<ZfEconomy> lqw = new LambdaQueryWrapper<>();
@@ -401,6 +407,18 @@
        }
        if (save(zfEconomy)) {
            EsModel esModel = new EsModel();
            Integer inte = zfEconomy.getId().intValue();
            String uuid = UUID.randomUUID().toString().replace("-","");
            esModel.setId(uuid);
            esModel.setCtId(Long.valueOf(inte));
            esModel.setCtTableName("家庭收支台账");
            esModel.setBy1(zfEconomy.getUseFor());
            esModel.setBy2(zfEconomy.getUsePeople());
            esModel.setBy5("/family/zfEconomy");
            esModel.setRemark(zfEconomy.getRemark());
            //这里存储查询详情的路径
            esService.insertTable(esModel);
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
@@ -434,6 +452,46 @@
        zfLogService.save(zfLog);
        if(updateById(zfEconomy)){
            //到数据库中查询对应的数据
            ZfEconomy dataById = getById(zfEconomy.getId());
            //先到es中查询到对应那条数据在es的id
            EsModel esResult = esService.findByCtId(dataById.getId().intValue(), "家庭收支台账");
            //操作es修改数据
            EsModel newModel = new EsModel();
            if(zfEconomy.getUseFor()!=null){
                newModel.setBy1(zfEconomy.getUseFor());
            }else {
                newModel.setBy1(dataById.getUseFor());
            }
            if(zfEconomy.getUsePeople()!=null){
                newModel.setBy2(zfEconomy.getUsePeople());
            }else {
                newModel.setBy2(dataById.getUsePeople());
            }
            if(zfEconomy.getRemark()!=null){
                newModel.setRemark(zfEconomy.getRemark());
            }else {
                newModel.setRemark(dataById.getRemark());
            }
            UpdateRequest updateRequest = new UpdateRequest("allsearchdata", esResult.getId());
            updateRequest.doc(
                    "by1",newModel.getBy1(),
                    "by2",newModel.getBy2(),
                    "remark",newModel.getRemark()
            );
            try {
                restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
@@ -456,8 +514,20 @@
                throw new RuntimeException("你没有权限操作此家庭的数据");
            }
        }
        List<ZfEconomy> zfEconomys = listByIds(Arrays.asList(ids));
        if (zfEconomyService.removeByIds(Arrays.asList(ids))) {
            //删除es中的数据
            zfEconomys.stream().forEach(zfEconomy -> {
                EsModel esModel = esService.findByCtId(zfEconomy.getId().intValue(), "家庭收支台账");
                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();
zhang-content/src/main/java/com/ruoyi/service/impl/ZfEquipmentServiceImpl.java
@@ -5,6 +5,7 @@
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.core.domain.entity.SysUser;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.SecurityUtils;
@@ -13,22 +14,21 @@
import com.ruoyi.domain.*;
import com.ruoyi.domain.ZfEquipment;
import com.ruoyi.mapper.ZfEquipmentMapper;
import com.ruoyi.service.ZAuthorityService;
import com.ruoyi.service.ZInfoUserService;
import com.ruoyi.service.ZfEquipmentService;
import com.ruoyi.service.ZfLogService;
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.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.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import static com.ruoyi.constant.MenuAuthority.*;
@@ -52,6 +52,12 @@
    @Resource
    ZAuthorityService zAuthorityService;
    @Resource
    EsService esService;
    @Resource
    private RestHighLevelClient restHighLevelClient;
    private LambdaQueryWrapper<ZfEquipment> buildCondition(ZfEquipment zfEquipment,List<Long> familyIdList) {
        LambdaQueryWrapper<ZfEquipment> lqw = new LambdaQueryWrapper<>();
@@ -337,6 +343,22 @@
        }
        if (save(zfEquipment)) {
            EsModel esModel = new EsModel();
            Integer inte = zfEquipment.getId().intValue();
            String uuid = UUID.randomUUID().toString().replace("-","");
            esModel.setId(uuid);
            esModel.setCtId(Long.valueOf(inte));
            esModel.setCtTableName("家庭设备");
            esModel.setBy1(zfEquipment.getName());
            esModel.setBy2(zfEquipment.getBuyer());
            esModel.setBy3(zfEquipment.getContent());
            esModel.setBy4(zfEquipment.getLocation());
            esModel.setBy5("/family/zfEquipment");
            esModel.setRemark(zfEquipment.getRemark());
            //这里存储查询详情的路径
            esService.insertTable(esModel);
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
@@ -409,8 +431,6 @@
//    }
    @Override
    @Transactional
    public AjaxResult importExcel(MultipartFile file) {
@@ -459,6 +479,59 @@
        zfLogService.save(zfLog);
        if(updateById(zfEquipment)){
            //到数据库中查询对应的数据
            ZfEquipment dataById = getById(zfEquipment.getId());
            //先到es中查询到对应那条数据在es的id
            EsModel esResult = esService.findByCtId(dataById.getId().intValue(), "家庭设备");
            //操作es修改数据
            EsModel newModel = new EsModel();
            if(zfEquipment.getName()!=null){
                newModel.setBy1(zfEquipment.getName());
            }else {
                newModel.setBy1(dataById.getName());
            }
            if(zfEquipment.getBuyer()!=null){
                newModel.setBy2(zfEquipment.getBuyer());
            }else {
                newModel.setBy2(dataById.getBuyer());
            }
            if(zfEquipment.getContent()!=null){
                newModel.setBy3(zfEquipment.getContent());
            }else {
                newModel.setBy3(dataById.getContent());
            }
            if(zfEquipment.getLocation()!=null){
                newModel.setBy4(zfEquipment.getLocation());
            }else {
                newModel.setBy4(dataById.getLocation());
            }
            if(zfEquipment.getRemark()!=null){
                newModel.setRemark(zfEquipment.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();
@@ -484,7 +557,20 @@
            }
        }
        List<ZfEquipment> zfEquipments = listByIds(Arrays.asList(ids));
        if (zfEquipmentService.removeByIds(Arrays.asList(ids))) {
            //删除es中的数据
            zfEquipments.stream().forEach(zfEquipment -> {
                EsModel esModel = esService.findByCtId(zfEquipment.getId().intValue(), "家庭设备");
                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();
zhang-content/src/main/java/com/ruoyi/service/impl/ZfEventServiceImpl.java
@@ -1,6 +1,7 @@
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;
@@ -18,11 +19,18 @@
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;
@@ -51,7 +59,10 @@
    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);
@@ -313,26 +324,26 @@
    @Override
    public AjaxResult addData(ZfEvent zfEvent) {
//        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 (zfEvent.getFamilyId()!=null && !familyIdList.contains(zfEvent.getFamilyId())) {
//            throw new RuntimeException("你没有权限操作此家庭的数据");
//        }
//
//
//        if(zfEvent.getFamilyId() == null){
//            //默认添加自己家庭的数据
//            zfEvent.setFamilyId(familyId);
//        }
        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 (zfEvent.getFamilyId()!=null && !familyIdList.contains(zfEvent.getFamilyId())) {
            throw new RuntimeException("你没有权限操作此家庭的数据");
        }
        if(zfEvent.getFamilyId() == null){
            //默认添加自己家庭的数据
            zfEvent.setFamilyId(familyId);
        }
        //判断是否有重复数据
        LambdaQueryWrapper<ZfEvent> lqw = uniqueCondition(zfEvent);
@@ -343,20 +354,18 @@
        }
        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("家大事记");
            esModel.setBy1(zfEvent.getAddress());
            esModel.setBy2(zfEvent.getPeople());
            esModel.setBy3(zfEvent.getTitle());
            esModel.setRemark(zfEvent.getRemark());
            //这里存储查询详情的路径
            esModel.setBy5("/family/zfEvent");
            // esModel.setCtTableName("tb_ajk");
            //   esModel.setCtName("大家");
            //  esModel.setCtContent("大家好,才是真的好");//处事由
            esSer.insertTable(esModel);
            return AjaxResult.success();
@@ -425,6 +434,7 @@
    ZfLogService zfLogService;
    @Override
    @Transactional
    public AjaxResult updateData(ZfEvent zfEvent) {
        ZInfoUser myself = zInfoUserService.getMyself();
        Long familyId = myself.getFamilyId();
@@ -447,7 +457,54 @@
        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(), "家大事记");
            //操作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();
@@ -472,7 +529,21 @@
            }
        }
        List<ZfEvent> zfEvents = listByIds(Arrays.asList(ids));
        if (zfEventService.removeByIds(Arrays.asList(ids))) {
            //删除es中的数据
            zfEvents.stream().forEach(zfEvent -> {
                EsModel esModel = esSer.findByCtId(zfEvent.getId(), "家大事记");
                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();
zhang-content/src/main/java/com/ruoyi/service/impl/esServiceImpl.java
File was deleted