New file |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | 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 |
| | |
| | | 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; |
| | |
| | | @SpringBootTest |
| | | public class esTest { |
| | | @Autowired |
| | | private esService ess; |
| | | private EsService ess; |
| | | |
| | | @Autowired |
| | | private EsRepository resp; |
| | |
| | | @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; |
| | | |
| | | |
| | | } |
New file |
| | |
| | | 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(); |
| | | |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | |
| | | @Resource |
| | | ZfPropertyMapper zfPropertyMapper; |
| | | |
| | | @Resource |
| | | EsService esService; |
| | | |
| | | @Resource |
| | | RestHighLevelClient restHighLevelClient; |
| | | |
| | | |
| | | // private LambdaQueryWrapper<ZfProperty> buildCondition(ZfProperty zfProperty) { |
| | |
| | | } |
| | | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | |
| | | 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.*; |
| | |
| | | |
| | | @Resource |
| | | ZfLogService zfLogService; |
| | | |
| | | @Resource |
| | | EsService esService; |
| | | |
| | | @Resource |
| | | RestHighLevelClient restHighLevelClient; |
| | | |
| | | private LambdaQueryWrapper<ZfClean> buildCondition(ZfClean zfClean,List<Long> familyIdList) { |
| | | LambdaQueryWrapper<ZfClean> lqw = new LambdaQueryWrapper<>(); |
| | |
| | | } |
| | | |
| | | 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(); |
| | |
| | | |
| | | |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | |
| | | @Resource |
| | | ZfLogService zfLogService; |
| | | |
| | | @Resource |
| | | EsService esService; |
| | | |
| | | @Resource |
| | | RestHighLevelClient restHighLevelClient; |
| | | |
| | | private LambdaQueryWrapper<ZfCollection> buildCondition(ZfCollection zfCollection,List<Long> familyIdList) { |
| | | LambdaQueryWrapper<ZfCollection> lqw = new LambdaQueryWrapper<>(); |
| | |
| | | } |
| | | |
| | | 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(); |
| | |
| | | |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | 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.*; |
| | |
| | | |
| | | @Resource |
| | | ZAuthorityService zAuthorityService; |
| | | |
| | | @Resource |
| | | EsService esService; |
| | | |
| | | @Resource |
| | | RestHighLevelClient restHighLevelClient; |
| | | |
| | | |
| | | private LambdaQueryWrapper<ZfContact> buildCondition(ZfContact zfContact,List<Long> familyIdList) { |
| | |
| | | } |
| | | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | 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.*; |
| | |
| | | |
| | | @Resource |
| | | ZfDoctorMapper zfDoctorMapper; |
| | | |
| | | @Resource |
| | | EsService esService; |
| | | |
| | | @Resource |
| | | private RestHighLevelClient restHighLevelClient; |
| | | |
| | | @Override |
| | | public AjaxResult selectDoctorList(ZfDoctor zfDoctor, Integer pageNum, Integer pageSize) { |
| | |
| | | } |
| | | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | 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.*; |
| | |
| | | |
| | | @Resource |
| | | ZfEconomyMapper zfEconomyMapper; |
| | | |
| | | @Resource |
| | | EsService esService; |
| | | |
| | | @Resource |
| | | RestHighLevelClient restHighLevelClient; |
| | | |
| | | private LambdaQueryWrapper<ZfEconomy> buildCondition(ZfEconomy zfEconomy,List<Long> familyIdList) { |
| | | LambdaQueryWrapper<ZfEconomy> lqw = new LambdaQueryWrapper<>(); |
| | |
| | | } |
| | | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | 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.*; |
| | |
| | | |
| | | @Resource |
| | | ZAuthorityService zAuthorityService; |
| | | |
| | | @Resource |
| | | EsService esService; |
| | | |
| | | @Resource |
| | | private RestHighLevelClient restHighLevelClient; |
| | | |
| | | private LambdaQueryWrapper<ZfEquipment> buildCondition(ZfEquipment zfEquipment,List<Long> familyIdList) { |
| | | LambdaQueryWrapper<ZfEquipment> lqw = new LambdaQueryWrapper<>(); |
| | |
| | | } |
| | | |
| | | 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(); |
| | |
| | | // } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public AjaxResult importExcel(MultipartFile file) { |
| | |
| | | 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(); |
| | |
| | | } |
| | | } |
| | | |
| | | 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(); |
| | |
| | | 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); |
| | |
| | | |
| | | @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); |
| | |
| | | } |
| | | |
| | | 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(); |
| | |
| | | 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(), "家大事记"); |
| | | |
| | | //操作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(), "家大事记"); |
| | | 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(); |