elasticsearch移除

This commit is contained in:
gaoqr
2026-06-17 16:10:58 +08:00
parent 3b41c42951
commit 7c224fe197
47 changed files with 1087 additions and 1910 deletions
@@ -77,18 +77,6 @@
<artifactId>cf-spring-boot-starter-redis</artifactId>
</dependency>
<dependency>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-elasticsearch</artifactId>
<exclusions>
<exclusion>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</exclusion>
</exclusions>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
@@ -260,10 +248,6 @@
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-biz-organ</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-elasticsearch</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-env</artifactId>
@@ -1,7 +1,6 @@
package com.cf.imes.module.system.controller.admin.datasource.vo;
import com.cf.imes.framework.es.core.dal.ESDocument;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
@@ -14,7 +13,7 @@ import java.util.List;
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MachineDataSourceDO extends ESDocument {
public class MachineDataSourceDO {
@Schema(description = "机台ID")
@@ -3,8 +3,6 @@ package com.cf.imes.module.system.controller.admin.machine;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.es.core.valid.CreateGroup;
import com.cf.imes.framework.es.core.valid.UpdateGroup;
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
import com.cf.imes.module.system.controller.admin.machine.vo.*;
import com.cf.imes.module.system.dal.dataobject.machine.MachineDO;
@@ -41,7 +39,7 @@ public class MachineController {
@Operation(summary = "创建机台")
@PreAuthorize("@ss.hasAnyPermissions('system:machine:create','system:machine:duplet')")
@OperateLog(logArgs = false,type = CREATE )
public CommonResult<Long> createCutting(@Validated(CreateGroup.class) @RequestBody CuttingSaveReqVO createReqVO) throws JsonProcessingException {
public CommonResult<Long> createCutting(@RequestBody CuttingSaveReqVO createReqVO) throws JsonProcessingException {
return success(machineService.createCutting(createReqVO));
}
@@ -49,7 +47,7 @@ public class MachineController {
@Operation(summary = "更新机台")
@PreAuthorize("@ss.hasAnyPermissions('system:machine:update','system:machine:submit')")
@OperateLog(logArgs = false,type = UPDATE)
public CommonResult<Boolean> update(@Validated(UpdateGroup.class) @RequestBody CuttingSaveReqVO updateReqVO) {
public CommonResult<Boolean> update(@RequestBody CuttingSaveReqVO updateReqVO) {
machineService.updateCutting(updateReqVO);
return success(true);
}
@@ -1,8 +1,6 @@
package com.cf.imes.module.system.controller.admin.machine.vo;
import com.alibaba.fastjson.JSONObject;
import com.cf.imes.framework.es.core.valid.CreateGroup;
import com.cf.imes.framework.es.core.valid.UpdateGroup;
import com.cf.imes.module.system.validation.machine.MachineTypeValid;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -19,7 +17,7 @@ import jakarta.validation.constraints.Size;
public class CuttingSaveReqVO {
@Schema(description = "主键", example = "14092")
@NotNull(groups = UpdateGroup.class, message = "主键不能空")
@NotNull(message = "主键不能空")
private Long id;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
@@ -43,7 +41,7 @@ public class CuttingSaveReqVO {
@Schema(description = "机台的型号-机台的ID")
@NotNull(message = "机台型号不能为空",groups = CreateGroup.class)
@NotNull(message = "机台型号不能为空")
private Long machineId;
@@ -1,7 +1,6 @@
package com.cf.imes.module.system.controller.admin.machine.vo;
import com.alibaba.fastjson.JSONObject;
import com.cf.imes.framework.es.core.valid.UpdateGroup;
import com.cf.imes.module.system.validation.machine.MachineTypeValid;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -16,7 +15,7 @@ import jakarta.validation.constraints.Size;
@Data
public class CuttingTemplateSaveReqVO {
@Schema(description = "主键", example = "14092")
@NotNull(groups = UpdateGroup.class, message = "主键不能空")
@NotNull(message = "主键不能空")
private Long id;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
@@ -1,6 +1,5 @@
package com.cf.imes.module.system.controller.admin.machine.vo;
import com.cf.imes.framework.es.core.valid.UpdateGroup;
import com.cf.imes.module.system.dal.dataobject.machine.DrillSettingDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -17,7 +16,7 @@ import jakarta.validation.constraints.NotNull;
public class DrillSaveReqVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "14092")
@NotNull(groups = UpdateGroup.class, message = "主键不能空")
@NotNull(message = "主键不能空")
private Long id;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
@@ -1,6 +1,5 @@
package com.cf.imes.module.system.controller.admin.machine.vo;
import com.cf.imes.framework.es.core.valid.UpdateGroup;
import com.cf.imes.module.system.dal.dataobject.machinetemplate.DrillTemplateMachineDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -16,7 +15,7 @@ import jakarta.validation.constraints.NotNull;
public class DrillTemplateSaveReqVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "14092")
@NotNull(groups = UpdateGroup.class, message = "主键不能空")
@NotNull(message = "主键不能空")
private Long id;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
@@ -1,13 +1,9 @@
package com.cf.imes.module.system.controller.admin.oauth2;
import cn.hutool.json.JSON;
import co.elastic.clients.elasticsearch.core.IndexResponse;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.json.JsonUtils;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.es.core.service.ESDocumentService;
import com.cf.imes.framework.mybatis.core.generator.SnowFlake;
import com.cf.imes.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO;
import com.cf.imes.module.system.controller.admin.oauth2.vo.client.OAuth2ClientRespVO;
import com.cf.imes.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO;
@@ -21,7 +17,6 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import jakarta.validation.Valid;
import static com.cf.imes.framework.common.pojo.CommonResult.success;
@@ -35,9 +30,6 @@ public class OAuth2ClientController {
@Resource
private OAuth2ClientService oAuth2ClientService;
@Resource
private ESDocumentService esDocumentService;
@PostMapping("/create")
@Operation(summary = "创建 OAuth2 客户端")
@@ -2,12 +2,10 @@ package com.cf.imes.module.system.controller.admin.setting.vo;
import com.alibaba.fastjson.JSONObject;
import com.cf.imes.framework.es.core.valid.UpdateGroup;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
import jakarta.validation.constraints.NotNull;
@Schema(description = "打包配置信息")
@Data
@@ -1,6 +1,5 @@
package com.cf.imes.module.system.dal.dataobject.labelelementproperty;
import com.cf.imes.framework.es.core.dal.ESDocument;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -11,7 +10,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@Data
@Schema(description = "标签元素属性索引")
public class LabelElementPropertyDO extends ESDocument {
public class LabelElementPropertyDO {
@Schema(description = "标签元素id")
private Long elementId;
private String extra;
@@ -1,6 +1,5 @@
package com.cf.imes.module.system.dal.dataobject.machine;
import com.cf.imes.framework.es.core.dal.ESDocument;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -11,7 +10,7 @@ import java.util.List;
*/
@NoArgsConstructor
@Data
public class CuttingSettingDO extends ESDocument {
public class CuttingSettingDO {
@Schema(description = "机台id")
private Long machineId;
@@ -1,6 +1,5 @@
package com.cf.imes.module.system.dal.dataobject.machine;
import com.cf.imes.framework.es.core.dal.ESDocument;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
@@ -14,7 +13,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@Builder
@Data
public class DrillSettingDO extends ESDocument {
public class DrillSettingDO {
@Schema(description = "机台id")
private Long machineId;
@@ -1,10 +1,7 @@
package com.cf.imes.module.system.dal.dataobject.machinetemplate;
import com.cf.imes.framework.es.core.dal.ESDocument;
import com.cf.imes.module.system.dal.dataobject.machine.CuttingSettingDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -15,7 +12,7 @@ import java.util.List;
*/
@Data
@Schema(description = "管理理后台 - 开料机台模板新增/修改 Request VO")
public class CuttingTemplateMachineDO extends ESDocument {
public class CuttingTemplateMachineDO {
@Schema(description = "开料机台模板id")
private Long templateId;
@@ -1,6 +1,5 @@
package com.cf.imes.module.system.dal.dataobject.machinetemplate;
import com.cf.imes.framework.es.core.dal.ESDocument;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
@@ -14,7 +13,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@Builder
@Data
public class DrillTemplateMachineDO extends ESDocument {
public class DrillTemplateMachineDO {
@Schema(description = "机台模板id")
private Long templateId;
@@ -1,13 +1,8 @@
package com.cf.imes.module.system.service.datasource;
import cn.hutool.core.collection.CollUtil;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.core.*;
import co.elastic.clients.elasticsearch.core.search.Hit;
import com.cf.imes.framework.common.enums.MachineTypeEnum;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.es.core.service.ESDocumentService;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.module.executor.api.plan.OrderPlanApi;
import com.cf.imes.module.system.controller.admin.datasource.dataQuery.DataQuery;
@@ -23,12 +18,9 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.*;
import static com.cf.imes.framework.common.util.object.BeanUtils.toBean;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.DATA_SOURCE_NOT_EXISTS;
@@ -51,12 +43,6 @@ public class DataSourceServiceImpl implements DataSourceService {
@Resource
private MachineMapper machineMapper;
@Resource
private ESDocumentService esDocumentService;
@Resource
private ElasticsearchClient elasticsearchClient;
@Resource
private OrderPlanApi orderPlanApi;
@@ -698,19 +684,6 @@ public class DataSourceServiceImpl implements DataSourceService {
public void batchSaveMachineDataSource(List<MachineDataSourceDO> machineDataSourceDOS) {
try {
BulkResponse bulkResponse = esDocumentService.bulkCreate(MACHINE_DATA_SOURCE, machineDataSourceDOS);
boolean errors = bulkResponse.errors();
if (errors) {
log.error(bulkResponse.items().toString());
throw new ServiceException(500, "未知异常");
}
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
throw new RuntimeException(e);
}
}
@@ -732,63 +705,21 @@ public class DataSourceServiceImpl implements DataSourceService {
// 根据机台ID和父级ID,查询对应的数据源字段
private List<MachineDataSourceDO> buildMachineDataSourceByParentSourceId(Long machineId,Integer parentSourceId, String index) {
SearchRequest.Builder builder = new SearchRequest.Builder();
builder.index(index);
builder.query(q -> q.bool(b -> b
.must(m->m.term(t->t.field(FIELD_MACHINEID).value(machineId)))
.must(m->m.match(t->t.field("dataSource.parentSourceId").query(parentSourceId)))));
try {
SearchResponse<MachineDataSourceDO> search = elasticsearchClient.search(builder.build(), MachineDataSourceDO.class);
List<Hit<MachineDataSourceDO>> hits = search.hits().hits();
if (CollUtil.isNotEmpty(hits)) {
return hits.stream().map(Hit::source).collect(Collectors.toList());
}
return new ArrayList<>();
} catch (IOException e) {
log.error(e.getMessage());
throw new ServiceException(INTERNAL_SERVER_ERROR);
}
return new ArrayList<>();
}
// 根据机台ID查询机台对应的数据源字段信息
private List<MachineDataSourceDO> buildMachineDataSourceByMachineId(Long machineId, String index) {
SearchRequest.Builder builder = new SearchRequest.Builder();
builder.index(index);
builder.query(q -> q.term(b -> b.field(FIELD_MACHINEID).value(machineId)));
try {
SearchResponse<MachineDataSourceDO> search = elasticsearchClient.search(builder.build(), MachineDataSourceDO.class);
List<Hit<MachineDataSourceDO>> hits = search.hits().hits();
if (CollUtil.isNotEmpty(hits)) {
return hits.stream().map(Hit::source).collect(Collectors.toList());
}
return new ArrayList<>();
} catch (IOException e) {
log.error(e.getMessage());
throw new ServiceException(INTERNAL_SERVER_ERROR);
}
return new ArrayList<>();
}
// 根据机台ID删除对应的数据源ES信息
public void deleteByMachineId(Long machineId, String index) {
DeleteByQueryRequest.Builder builder = new DeleteByQueryRequest.Builder();
builder.index(index);
builder.query(q -> q.term(t -> t.field(FIELD_MACHINEID).value(machineId)));
try {
DeleteByQueryResponse response = elasticsearchClient.deleteByQuery(builder.build());
log.info("Deleted {} documents with planId {}", response.deleted(), machineId);
} catch (IOException e) {
log.error("Error deleting documents with planId {}: {}", machineId, e.getMessage());
throw new ServiceException(ES_DATA_ERROR);
}
}
@@ -1,20 +1,10 @@
package com.cf.imes.module.system.service.machine;
import cn.hutool.core.text.CharSequenceUtil;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.query_dsl.*;
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.search.Hit;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.es.core.service.ESDocumentService;
import com.cf.imes.framework.security.core.LoginUser;
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
import com.cf.imes.module.system.controller.admin.machine.vo.SettingPageReqVO;
import com.cf.imes.module.system.dal.dataobject.machine.MachineDO;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
@@ -23,34 +13,11 @@ import java.util.List;
@Service
public class MachineSettingServiceImpl implements MachineSettingService {
@Resource
private ElasticsearchClient elasticsearchClient;
@Resource
private ESDocumentService esDocumentService;
public final static String MACHINE_SETTING = "user_machine";
@Override
public PageResult<MachineDO> page(SettingPageReqVO pageReqVO) throws IOException {
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
List<MachineDO> userMachineDOS = new ArrayList<>();
List<Query> queryList = new ArrayList<>();
if(CharSequenceUtil.isNotEmpty(pageReqVO.getName())) {
MatchQuery query = MatchQuery.of(e -> e.field("name").query(pageReqVO.getName()));
queryList.add(query._toQuery());
}
queryList.add(TermQuery.of(e->e.field("organId").value( loginUser.getOrganId()))._toQuery());
SearchResponse<MachineDO> response = elasticsearchClient.search(s-> s.index(MACHINE_SETTING)
.from((pageReqVO.getPageNo() - 1) * pageReqVO.getPageSize())
.size(pageReqVO.getPageSize())
.query(b -> b.bool( builder -> builder.must(queryList))),
MachineDO.class);
long value = response.hits().total().value();
for (Hit<MachineDO> hit : response.hits().hits()) {
userMachineDOS.add(hit.source());
}
return new PageResult<MachineDO>(userMachineDOS, value);
return PageResult.empty();
}
@@ -70,16 +37,16 @@ public class MachineSettingServiceImpl implements MachineSettingService {
@Override
public Boolean delete(String id) throws IOException {
return esDocumentService.deleteById(MACHINE_SETTING, id).booleanValue();
return true;
}
@Override
public Boolean batchDelete(List<String> ids) throws Exception {
return !esDocumentService.bulkDeleteByIds(MACHINE_SETTING, ids).errors();
return true;
}
@Override
public MachineDO get(String id) throws IOException {
return esDocumentService.getById(MACHINE_SETTING, id, MachineDO.class);
return null;
}
}
@@ -1,7 +1,6 @@
package com.cf.imes.module.system.service.machine;
import cn.hutool.core.util.ObjectUtil;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.enums.MachineTypeEnum;
@@ -18,7 +17,6 @@ import com.cf.imes.module.system.dal.dataobject.machinetemplate.MachineTemplateD
import com.cf.imes.module.system.dal.dataobject.machinetemplate.MachineTemplateLimitDO;
import com.cf.imes.module.system.dal.dataobject.organ.OrganizationDO;
import com.cf.imes.module.system.dal.mysql.machine.MachineBrandMapper;
import com.cf.imes.module.system.dal.mysql.machine.UserMachineMapper;
import com.cf.imes.module.system.dal.mysql.machinetemplate.MachineTemplateLimitMapper;
import com.cf.imes.module.system.dal.mysql.machinetemplate.MachineTemplateMapper;
import com.cf.imes.module.system.dal.mysql.organ.OrganMapper;
@@ -45,13 +43,6 @@ import static com.cf.imes.module.system.enums.ErrorCodeConstants.*;
@Slf4j
public class MachineTemplateServiceImpl implements MachineTemplateService {
@Resource
private UserMachineMapper userMachineMapper;
@Resource
private ElasticsearchClient elasticsearchClient;
@Resource
private MachineTemplateMapper machineTemplateMapper;