123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package com.bowintek.practice.services.impl;
- import com.bowintek.practice.filter.exception.BaseException;
- import com.bowintek.practice.mapper.EsIndexMapper;
- import com.bowintek.practice.mapper.EsIndexfieldMapper;
- import com.bowintek.practice.mapper.cquery.EsIndexCquery;
- import com.bowintek.practice.model.*;
- import com.bowintek.practice.services.service.EsIndexService;
- import com.bowintek.practice.services.service.system.DictionaryService;
- import com.bowintek.practice.util.Constant;
- import com.bowintek.practice.util.StringUtils;
- import com.bowintek.practice.vo.EsIndexVo;
- import com.bowintek.practice.vo.EsIndexfieldVo;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.Date;
- import java.util.List;
- import java.util.UUID;
- import java.util.stream.Collectors;
- @Service("EsIndexService")
- public class EsIndexServiceImpl implements EsIndexService {
- @Autowired
- private EsIndexCquery esIndexCquery;
- @Autowired
- private StringUtils stringUtils;
- @Autowired
- private DictionaryService dictionaryService;
- @Autowired
- private EsIndexMapper esIndexMapper;
- @Autowired
- private EsIndexfieldMapper esIndexfieldMapper;
- @Override
- public PageInfo<EsIndexVo> getList(Integer page, Integer rows,
- String indexName, String indexCode, List<String> idList) {
- PageHelper.startPage(page, rows);
- List<EsIndexVo> dataList = esIndexCquery.getList(indexName, indexCode, stringUtils.ListToInSql(idList));
- PageInfo<EsIndexVo> result = new PageInfo(dataList);
- return result;
- }
- @Override
- public EsIndexVo getEsIndex(String indexId) {
- EsIndexVo esIndex = esIndexCquery.getList(null, null, indexId).get(0);
- return esIndex;
- }
- @Override
- public int saveEsIndex(EsIndexVo model, List<EsIndexfieldVo> fieldList, String userId, String userName) {
- EsIndex dbData = esIndexMapper.selectByPrimaryKey(model.getIndexId());
- int result = 0;
- if (dbData == null) {
- model.setIndexId(UUID.randomUUID().toString());
- model.setStatus(1);
- model.setCreatedBy(userId);
- model.setCreateTime(new Date());
- model.setModiTime(new Date());
- model.setCreatedName(userName);
- result = esIndexMapper.insert(model);
- } else {
- model.setModiTime(new Date());
- result = esIndexMapper.updateByPrimaryKey(model);
- }
- if (fieldList != null && fieldList.size() > 0) {
- EsIndexfieldExample example = new EsIndexfieldExample();
- EsIndexfieldExample.Criteria criteria = example.or();
- criteria.andIndexIdEqualTo(model.getIndexId());
- List<EsIndexfield> dbList = esIndexfieldMapper.selectByExample(example);
- if (dbList.size() > 0) {
- List<String> ids = fieldList.stream().map(x -> x.getFieldId()).collect(Collectors.toList());
- criteria.andFieldIdNotIn(ids);
- esIndexfieldMapper.deleteByExample(example);
- }
- fieldList.stream().forEach(x -> {
- long count = dbList.stream().filter(f -> f.getFieldId().equals(x.getFieldId())).count();
- if (count > 0) {
- esIndexfieldMapper.updateByPrimaryKeySelective(x);
- } else {
- x.setIndexId(model.getIndexId());
- x.setFieldId(UUID.randomUUID().toString());
- esIndexfieldMapper.insertSelective(x);
- }
- if (x.getChildFields() != null && x.getChildFields().size() > 0) {
- x.getChildFields().forEach(child -> {
- child.setParentId(x.getFieldId());
- child.setIndexId(model.getIndexId());
- child.setFieldId(UUID.randomUUID().toString());
- esIndexfieldMapper.insertSelective(child);
- });
- }
- });
- }
- return result;
- }
- @Override
- public List<EsIndexfieldVo> getFieldList(String indexId, String parentId) {
- List<EsIndexfieldVo> dbList = esIndexCquery.getFieldList(indexId, parentId);
- dbList.forEach(x -> {
- x.setChildFields(esIndexCquery.getFieldList(indexId, x.getFieldId()));
- });
- return dbList;
- }
- @Override
- public int delete(List<String> idList) {
- try {
- EsIndexfieldExample example = new EsIndexfieldExample();
- EsIndexfieldExample.Criteria criteria = example.or();
- criteria.andIndexIdIn(idList);
- esIndexfieldMapper.deleteByExample(example);
- EsIndexExample subExp = new EsIndexExample();
- subExp.or().andIndexIdIn(idList);
- esIndexMapper.deleteByExample(subExp);
- } catch (Exception e) {
- return 0;
- }
- return 1;
- }
- @Override
- public List<EsIndexfieldVo> importData(List<EsIndexfieldVo> dataList) {
- if (dataList.size() <= 0)
- throw new BaseException("", "请添加导入数据!");
- List<SysDictionaryItem> dicQueryTypeList = dictionaryService.getDictionaryItemList("queryType");
- dataList.forEach(item -> {
- String errorInfo = "";
- SysDictionaryItem dicQueryType = dicQueryTypeList.stream().filter(e -> e.getName().equals(item.getQueryTypeName())).findFirst().orElse(null);
- if (stringUtils.IsNullOrEmpty(item.getFieldCode()))
- errorInfo += "请填写字段编码!";
- if (stringUtils.IsNullOrEmpty(item.getFieldName()))
- errorInfo += "请填写字段名称!";
- if (stringUtils.IsNullOrEmpty(item.getDataType()))
- errorInfo += "请填写数据类型!";
- if (dicQueryType == null)
- errorInfo += "查询类型不在支持范围!";
- if (stringUtils.IsNullOrEmpty(errorInfo)) {
- item.setQueryTypeId(dicQueryType.getValue());
- item.setIsSearchField(Constant.YES.equals(item.getIsSearchFieldText()) ? 1 : 0);
- item.setIsDisplay(Constant.YES.equals(item.getIsDisplayText()) ? 1 : 0);
- }
- item.setErrorMessage(errorInfo);
- });
- return dataList;
- }
- }
|