mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
elasticsearch移除
This commit is contained in:
+212
-212
@@ -1,212 +1,212 @@
|
|||||||
package com.cf.imes.framework.es.config;
|
//package com.cf.imes.framework.es.config;
|
||||||
|
//
|
||||||
import cn.hutool.core.io.file.PathUtil;
|
//import cn.hutool.core.io.file.PathUtil;
|
||||||
import cn.hutool.core.text.CharSequenceUtil;
|
//import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
//import cn.hutool.core.util.ObjectUtil;
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
|
//import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
//import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||||
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
|
//import co.elastic.clients.json.jackson.JacksonJsonpMapper;
|
||||||
import co.elastic.clients.transport.rest_client.RestClientTransport;
|
//import co.elastic.clients.transport.rest_client.RestClientTransport;
|
||||||
import com.cf.imes.framework.common.util.encrypt.AesUtils;
|
//import com.cf.imes.framework.common.util.encrypt.AesUtils;
|
||||||
import com.cf.imes.framework.es.core.service.ESDocumentService;
|
//import com.cf.imes.framework.es.core.service.ESDocumentService;
|
||||||
import com.cf.imes.framework.es.core.service.ESDocumentServiceImpl;
|
//import com.cf.imes.framework.es.core.service.ESDocumentServiceImpl;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.http.HttpHost;
|
//import org.apache.http.HttpHost;
|
||||||
import org.apache.http.auth.AuthScope;
|
//import org.apache.http.auth.AuthScope;
|
||||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
//import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
import org.apache.http.client.CredentialsProvider;
|
//import org.apache.http.client.CredentialsProvider;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
//import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
//import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
//import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||||
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
|
//import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
|
||||||
import org.apache.http.impl.nio.reactor.IOReactorConfig;
|
//import org.apache.http.impl.nio.reactor.IOReactorConfig;
|
||||||
import org.apache.http.message.BasicHeader;
|
//import org.apache.http.message.BasicHeader;
|
||||||
import org.apache.http.ssl.SSLContextBuilder;
|
//import org.apache.http.ssl.SSLContextBuilder;
|
||||||
import org.apache.http.ssl.SSLContexts;
|
//import org.apache.http.ssl.SSLContexts;
|
||||||
import org.elasticsearch.client.RestClient;
|
//import org.elasticsearch.client.RestClient;
|
||||||
import org.elasticsearch.client.RestClientBuilder;
|
//import org.elasticsearch.client.RestClientBuilder;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
//import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
//import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
//import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.util.StringUtils;
|
//import org.springframework.util.StringUtils;
|
||||||
|
//
|
||||||
import javax.net.ssl.SSLContext;
|
//import javax.net.ssl.SSLContext;
|
||||||
import java.io.IOException;
|
//import java.io.IOException;
|
||||||
import java.io.InputStream;
|
//import java.io.InputStream;
|
||||||
import java.nio.file.Path;
|
//import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
//import java.nio.file.Paths;
|
||||||
import java.security.KeyManagementException;
|
//import java.security.KeyManagementException;
|
||||||
import java.security.KeyStore;
|
//import java.security.KeyStore;
|
||||||
import java.security.KeyStoreException;
|
//import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
//import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.cert.CertificateException;
|
//import java.security.cert.CertificateException;
|
||||||
import java.time.Duration;
|
//import java.time.Duration;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author there
|
// * @author there
|
||||||
*/
|
// */
|
||||||
@AutoConfiguration
|
//@AutoConfiguration
|
||||||
@ConditionalOnClass(ElasticsearchClient.class)
|
//@ConditionalOnClass(ElasticsearchClient.class)
|
||||||
@EnableConfigurationProperties(EsProperties.class)
|
//@EnableConfigurationProperties(EsProperties.class)
|
||||||
@Slf4j
|
//@Slf4j
|
||||||
public class ChenfengElasticsearchAutoConfiguration {
|
//public class ChenfengElasticsearchAutoConfiguration {
|
||||||
|
//
|
||||||
@Value("${chenfeng.encrypt.publicKey:}")
|
// @Value("${chenfeng.encrypt.publicKey:}")
|
||||||
private String publicKey;
|
// private String publicKey;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 同步方式
|
// * 同步方式
|
||||||
*
|
// *
|
||||||
*/
|
// */
|
||||||
@Bean
|
// @Bean
|
||||||
public ElasticsearchClient elasticsearchClient(RestClientTransport transport) {
|
// public ElasticsearchClient elasticsearchClient(RestClientTransport transport) {
|
||||||
return new ElasticsearchClient(transport);
|
// return new ElasticsearchClient(transport);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 异步方式
|
// * 异步方式
|
||||||
*
|
// *
|
||||||
*/
|
// */
|
||||||
@Bean
|
// @Bean
|
||||||
public ElasticsearchAsyncClient elasticsearchAsyncClient(RestClientTransport transport) {
|
// public ElasticsearchAsyncClient elasticsearchAsyncClient(RestClientTransport transport) {
|
||||||
return new ElasticsearchAsyncClient(transport);
|
// return new ElasticsearchAsyncClient(transport);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
@Bean
|
// @Bean
|
||||||
public ESDocumentService esDocumentService(ElasticsearchClient elasticsearchClient, ElasticsearchAsyncClient elasticsearchAsyncClient) {
|
// public ESDocumentService esDocumentService(ElasticsearchClient elasticsearchClient, ElasticsearchAsyncClient elasticsearchAsyncClient) {
|
||||||
return new ESDocumentServiceImpl(elasticsearchClient, elasticsearchAsyncClient);
|
// return new ESDocumentServiceImpl(elasticsearchClient, elasticsearchAsyncClient);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 获取客户端 RestClientTransport
|
// * 获取客户端 RestClientTransport
|
||||||
*/
|
// */
|
||||||
@Bean
|
// @Bean
|
||||||
public RestClientTransport getTransport(RestClient client){
|
// public RestClientTransport getTransport(RestClient client){
|
||||||
return new RestClientTransport(client, new JacksonJsonpMapper());
|
// return new RestClientTransport(client, new JacksonJsonpMapper());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 获取客户端RestClient
|
// * 获取客户端RestClient
|
||||||
* chenfeng.encrypt.enable:true
|
// * chenfeng.encrypt.enable:true
|
||||||
*
|
// *
|
||||||
* @param properties es配置
|
// * @param properties es配置
|
||||||
*/
|
// */
|
||||||
@Bean
|
// @Bean
|
||||||
@ConditionalOnProperty(name = "chenfeng.encrypt.enable", havingValue = "true")
|
// @ConditionalOnProperty(name = "chenfeng.encrypt.enable", havingValue = "true")
|
||||||
public RestClient getAuthRestClient(EsProperties properties) {
|
// public RestClient getAuthRestClient(EsProperties properties) {
|
||||||
return getRestClient(properties, true);
|
// return getRestClient(properties, true);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 获取客户端RestClient(默认)
|
// * 获取客户端RestClient(默认)
|
||||||
* chenfeng.encrypt.enable:false或者缺省
|
// * chenfeng.encrypt.enable:false或者缺省
|
||||||
*
|
// *
|
||||||
* @param properties es配置
|
// * @param properties es配置
|
||||||
*/
|
// */
|
||||||
@Bean
|
// @Bean
|
||||||
@ConditionalOnProperty(name = "chenfeng.encrypt.enable", havingValue = "false", matchIfMissing = true)
|
// @ConditionalOnProperty(name = "chenfeng.encrypt.enable", havingValue = "false", matchIfMissing = true)
|
||||||
public RestClient getRestClient(EsProperties properties) {
|
// public RestClient getRestClient(EsProperties properties) {
|
||||||
return getRestClient(properties, false);
|
// return getRestClient(properties, false);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 动态获取es client连接
|
// * 动态获取es client连接
|
||||||
*
|
// *
|
||||||
* @param properties 配置
|
// * @param properties 配置
|
||||||
* @param needDecrypt 敏感信息是否需要解密
|
// * @param needDecrypt 敏感信息是否需要解密
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
private RestClient getRestClient(EsProperties properties, boolean needDecrypt) {
|
// private RestClient getRestClient(EsProperties properties, boolean needDecrypt) {
|
||||||
// 配置账号密码
|
// // 配置账号密码
|
||||||
CredentialsProvider credentialsProvider;
|
// CredentialsProvider credentialsProvider;
|
||||||
String username = properties.getUsername();
|
// String username = properties.getUsername();
|
||||||
String password = properties.getPassword();
|
// String password = properties.getPassword();
|
||||||
if (CharSequenceUtil.isAllNotEmpty(username, password)) {
|
// if (CharSequenceUtil.isAllNotEmpty(username, password)) {
|
||||||
credentialsProvider = new BasicCredentialsProvider();
|
// credentialsProvider = new BasicCredentialsProvider();
|
||||||
credentialsProvider.setCredentials(AuthScope.ANY,
|
// credentialsProvider.setCredentials(AuthScope.ANY,
|
||||||
new UsernamePasswordCredentials(needDecrypt ? AesUtils.decrypt(username, publicKey) : username, needDecrypt ? AesUtils.decrypt(password, publicKey) : password));
|
// new UsernamePasswordCredentials(needDecrypt ? AesUtils.decrypt(username, publicKey) : username, needDecrypt ? AesUtils.decrypt(password, publicKey) : password));
|
||||||
} else {
|
// } else {
|
||||||
credentialsProvider = null;
|
// credentialsProvider = null;
|
||||||
}
|
// }
|
||||||
RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback = httpClientBuilder -> {
|
// RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback = httpClientBuilder -> {
|
||||||
// 设置账号密码、连接信息
|
// // 设置账号密码、连接信息
|
||||||
HttpAsyncClientBuilder httpAsyncClientBuilder = httpClientBuilder
|
// HttpAsyncClientBuilder httpAsyncClientBuilder = httpClientBuilder
|
||||||
.setDefaultRequestConfig(RequestConfig.custom()
|
// .setDefaultRequestConfig(RequestConfig.custom()
|
||||||
.setConnectTimeout((int) properties.getConnectionTimeout().toMillis())
|
// .setConnectTimeout((int) properties.getConnectionTimeout().toMillis())
|
||||||
.setSocketTimeout((int) properties.getSocketTimeout().toMillis())
|
// .setSocketTimeout((int) properties.getSocketTimeout().toMillis())
|
||||||
.setConnectionRequestTimeout((int) properties.getConnectionRequestTimeout().toMillis())
|
// .setConnectionRequestTimeout((int) properties.getConnectionRequestTimeout().toMillis())
|
||||||
// 启用数据压缩
|
// // 启用数据压缩
|
||||||
.setContentCompressionEnabled(true)
|
// .setContentCompressionEnabled(true)
|
||||||
.build());
|
// .build());
|
||||||
if (ObjectUtil.isNotNull(credentialsProvider)) {
|
// if (ObjectUtil.isNotNull(credentialsProvider)) {
|
||||||
httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
|
// httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
|
||||||
}
|
// }
|
||||||
if (properties.isSecurityHttpSslEnable()) {
|
// if (properties.isSecurityHttpSslEnable()) {
|
||||||
// 开启ssl配置连接证书
|
// // 开启ssl配置连接证书
|
||||||
httpAsyncClientBuilder.setSSLContext(buildSSLContext(properties)).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
|
// httpAsyncClientBuilder.setSSLContext(buildSSLContext(properties)).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
|
||||||
}
|
// }
|
||||||
// 手动开启keepalive
|
// // 手动开启keepalive
|
||||||
httpAsyncClientBuilder.setDefaultIOReactorConfig(IOReactorConfig.custom().setSoKeepAlive(true).build());
|
// httpAsyncClientBuilder.setDefaultIOReactorConfig(IOReactorConfig.custom().setSoKeepAlive(true).build());
|
||||||
httpAsyncClientBuilder.setDefaultHeaders(List.of(new BasicHeader("Accept-Encoding", "gzip")));
|
// httpAsyncClientBuilder.setDefaultHeaders(List.of(new BasicHeader("Accept-Encoding", "gzip")));
|
||||||
// 手动设置保活时长
|
// // 手动设置保活时长
|
||||||
httpAsyncClientBuilder.setKeepAliveStrategy(((response, context) -> Duration.ofMinutes(5).toMillis()));
|
// httpAsyncClientBuilder.setKeepAliveStrategy(((response, context) -> Duration.ofMinutes(5).toMillis()));
|
||||||
return httpAsyncClientBuilder;
|
// return httpAsyncClientBuilder;
|
||||||
};
|
// };
|
||||||
return RestClient.builder(toHttpHost(properties.getUris(), properties.isSecurityHttpSslEnable())).setHttpClientConfigCallback(httpClientConfigCallback).build();
|
// return RestClient.builder(toHttpHost(properties.getUris(), properties.isSecurityHttpSslEnable())).setHttpClientConfigCallback(httpClientConfigCallback).build();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 构建ssl请求信息
|
// * 构建ssl请求信息
|
||||||
*
|
// *
|
||||||
* @param properties es配置
|
// * @param properties es配置
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
private SSLContext buildSSLContext(EsProperties properties) {
|
// private SSLContext buildSSLContext(EsProperties properties) {
|
||||||
SSLContext sslContext = null;
|
// SSLContext sslContext = null;
|
||||||
try {
|
// try {
|
||||||
Path trustStorePath = Paths.get(properties.getCertificatePath());
|
// Path trustStorePath = Paths.get(properties.getCertificatePath());
|
||||||
KeyStore trustStore = KeyStore.getInstance("pkcs12");
|
// KeyStore trustStore = KeyStore.getInstance("pkcs12");
|
||||||
try (InputStream is = PathUtil.getInputStream(trustStorePath)) {
|
// try (InputStream is = PathUtil.getInputStream(trustStorePath)) {
|
||||||
trustStore.load(is, properties.getPassword().toCharArray());
|
// trustStore.load(is, properties.getPassword().toCharArray());
|
||||||
}
|
// }
|
||||||
SSLContextBuilder sslContextBuilder = SSLContexts.custom()
|
// SSLContextBuilder sslContextBuilder = SSLContexts.custom()
|
||||||
.loadTrustMaterial(trustStore, null);
|
// .loadTrustMaterial(trustStore, null);
|
||||||
sslContext = sslContextBuilder.build();
|
// sslContext = sslContextBuilder.build();
|
||||||
} catch (CertificateException | IOException | KeyStoreException | NoSuchAlgorithmException |
|
// } catch (CertificateException | IOException | KeyStoreException | NoSuchAlgorithmException |
|
||||||
KeyManagementException e) {
|
// KeyManagementException e) {
|
||||||
log.error("ES连接认证失败", e);
|
// log.error("ES连接认证失败", e);
|
||||||
}
|
// }
|
||||||
return sslContext;
|
// return sslContext;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 解析域名
|
// * 解析域名
|
||||||
*
|
// *
|
||||||
* @param hosts 域名字符串
|
// * @param hosts 域名字符串
|
||||||
* @param isSslEnable 是否开启ssl
|
// * @param isSslEnable 是否开启ssl
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
private HttpHost[] toHttpHost(String hosts, boolean isSslEnable) {
|
// private HttpHost[] toHttpHost(String hosts, boolean isSslEnable) {
|
||||||
if (!StringUtils.hasLength(hosts)) {
|
// if (!StringUtils.hasLength(hosts)) {
|
||||||
throw new IllegalArgumentException("invalid elasticsearch configuration. elasticsearch.hosts不能为空!");
|
// throw new IllegalArgumentException("invalid elasticsearch configuration. elasticsearch.hosts不能为空!");
|
||||||
}
|
// }
|
||||||
// 多个IP逗号隔开
|
// // 多个IP逗号隔开
|
||||||
String[] hostArray = hosts.split(",");
|
// String[] hostArray = hosts.split(",");
|
||||||
HttpHost[] httpHosts = new HttpHost[hostArray.length];
|
// HttpHost[] httpHosts = new HttpHost[hostArray.length];
|
||||||
HttpHost httpHost;
|
// HttpHost httpHost;
|
||||||
for (int i = 0; i < hostArray.length; i++) {
|
// for (int i = 0; i < hostArray.length; i++) {
|
||||||
String[] strings = hostArray[i].split(":");
|
// String[] strings = hostArray[i].split(":");
|
||||||
httpHost = new HttpHost(strings[0], Integer.parseInt(strings[1]), isSslEnable ? "https" : "http");
|
// httpHost = new HttpHost(strings[0], Integer.parseInt(strings[1]), isSslEnable ? "https" : "http");
|
||||||
httpHosts[i] = httpHost;
|
// httpHosts[i] = httpHost;
|
||||||
}
|
// }
|
||||||
return httpHosts;
|
// return httpHosts;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
package com.cf.imes.framework.es.core.dal;
|
package com.cf.imes.framework.es.core.dal;
|
||||||
|
|
||||||
|
|
||||||
import com.cf.imes.framework.es.core.valid.UpdateGroup;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
@@ -14,7 +13,7 @@ import static com.cf.imes.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class ESDocument {
|
public class ESDocument {
|
||||||
@NotBlank(groups = UpdateGroup.class, message = "文档ID不能空")
|
@NotBlank(message = "文档ID不能空")
|
||||||
public String id;
|
public String id;
|
||||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
|
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
|
||||||
|
|||||||
+91
-103
@@ -1,112 +1,100 @@
|
|||||||
package com.cf.imes.framework.es.core.service;
|
package com.cf.imes.framework.es.core.service;
|
||||||
|
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import co.elastic.clients.elasticsearch._types.ElasticsearchException;
|
|
||||||
import co.elastic.clients.elasticsearch._types.Result;
|
|
||||||
import co.elastic.clients.elasticsearch.core.BulkResponse;
|
|
||||||
import co.elastic.clients.elasticsearch.core.IndexResponse;
|
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 公用es服务接口
|
* 公用es服务接口
|
||||||
*/
|
*/
|
||||||
public interface ESDocumentService {
|
public interface ESDocumentService {
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 新增一个文档,此种方式若发现没有索引,会自动创建一个索引
|
// * 新增一个文档,此种方式若发现没有索引,会自动创建一个索引
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param idxId 索引id
|
// * @param idxId 索引id
|
||||||
* @param document 文档对象
|
// * @param document 文档对象
|
||||||
*/
|
// */
|
||||||
<T> IndexResponse createByFluentDSL(String idxName, String idxId, ESDocument document) throws Exception;
|
// <T> IndexResponse createByFluentDSL(String idxName, String idxId, ESDocument document) throws Exception;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 新增一个文档,此种方式若发现没有索引,会自动创建一个索引
|
// * 新增一个文档,此种方式若发现没有索引,会自动创建一个索引
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param idxId 索引id
|
// * @param idxId 索引id
|
||||||
* @param document 文档对象
|
// * @param document 文档对象
|
||||||
*/
|
// */
|
||||||
<T> IndexResponse createByBuilderPattern(String idxName, String idxId, ESDocument document) throws Exception;
|
// <T> IndexResponse createByBuilderPattern(String idxName, String idxId, ESDocument document) throws Exception;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 用JSON字符串创建文档,此种方式若发现没有索引,会自动创建一个索引
|
// * 用JSON字符串创建文档,此种方式若发现没有索引,会自动创建一个索引
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param idxId 索引id
|
// * @param idxId 索引id
|
||||||
* @param jsonContent json字符串
|
// * @param jsonContent json字符串
|
||||||
*/
|
// */
|
||||||
IndexResponse createByJson(String idxName, String idxId, String jsonContent) throws Exception;
|
// IndexResponse createByJson(String idxName, String idxId, String jsonContent) throws Exception;
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 异步新增文档,此种方式若发现没有索引,会自动创建一个索引
|
// * 异步新增文档,此种方式若发现没有索引,会自动创建一个索引
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param idxId 索引id
|
// * @param idxId 索引id
|
||||||
* @param document 文档
|
// * @param document 文档
|
||||||
* @param action 操作
|
// * @param action 操作
|
||||||
*/
|
// */
|
||||||
<T> void createAsync(String idxName, String idxId, T document, BiConsumer<IndexResponse, Throwable> action);
|
// <T> void createAsync(String idxName, String idxId, T document, BiConsumer<IndexResponse, Throwable> action);
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 批量增加文档
|
// * 批量增加文档
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param documents 要增加的对象集合
|
// * @param documents 要增加的对象集合
|
||||||
* @return 批量操作的结果
|
// * @return 批量操作的结果
|
||||||
*/
|
// */
|
||||||
<T> BulkResponse bulkCreate(String idxName, List<?extends ESDocument> documents) throws IOException, ElasticsearchException;
|
// <T> BulkResponse bulkCreate(String idxName, List<?extends ESDocument> documents) throws IOException, ElasticsearchException;
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 批量更新文档
|
// * 批量更新文档
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param documents 要更新的对象集合
|
// * @param documents 要更新的对象集合
|
||||||
* @return 批量更新的结果
|
// * @return 批量更新的结果
|
||||||
*/
|
// */
|
||||||
<T> BulkResponse bulkUpdate(String idxName, List<?extends ESDocument> documents) throws Exception;
|
// <T> BulkResponse bulkUpdate(String idxName, List<?extends ESDocument> documents) throws Exception;
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 根据文档id查找文档
|
// * 根据文档id查找文档
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param docId 文档id
|
// * @param docId 文档id
|
||||||
* @return Object类型的查找结果
|
// * @return Object类型的查找结果
|
||||||
*/
|
// */
|
||||||
<T> T getById(String idxName, String docId ,Class<T> tClass) throws IOException;
|
// <T> T getById(String idxName, String docId ,Class<T> tClass) throws IOException;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
*
|
// *
|
||||||
* @param idxName 索引名称
|
// * @param idxName 索引名称
|
||||||
* @param docId 文档id
|
// * @param docId 文档id
|
||||||
* @param tClass 返回的类型
|
// * @param tClass 返回的类型
|
||||||
* @param map 修改内容的map
|
// * @param map 修改内容的map
|
||||||
*/
|
// */
|
||||||
<T> Result updateById(String idxName, String docId, Class<T> tClass, Map<String,Object> map) throws IOException, ElasticsearchException;
|
// <T> Result updateById(String idxName, String docId, Class<T> tClass, Map<String,Object> map) throws IOException, ElasticsearchException;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 根据文档id查找文档,返回类型是ObjectNode
|
// * 根据文档id查找文档,返回类型是ObjectNode
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param docId 文档id
|
// * @param docId 文档id
|
||||||
* @return ObjectNode类型的查找结果
|
// * @return ObjectNode类型的查找结果
|
||||||
*/
|
// */
|
||||||
JSONObject getObjectNodeById(String idxName, String docId) throws IOException;
|
// JSONObject getObjectNodeById(String idxName, String docId) throws IOException;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 根据文档id删除文档
|
// * 根据文档id删除文档
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param docId 文档id
|
// * @param docId 文档id
|
||||||
* @return Object类型的查找结果
|
// * @return Object类型的查找结果
|
||||||
*/
|
// */
|
||||||
Boolean deleteById(String idxName, String docId) throws IOException;
|
// Boolean deleteById(String idxName, String docId) throws IOException;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 批量删除文档
|
// * 批量删除文档
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param docIds 要删除的文档id集合
|
// * @param docIds 要删除的文档id集合
|
||||||
*/
|
// */
|
||||||
BulkResponse bulkDeleteByIds(String idxName, List<String> docIds) throws Exception;
|
// BulkResponse bulkDeleteByIds(String idxName, List<String> docIds) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
+237
-259
@@ -1,267 +1,245 @@
|
|||||||
package com.cf.imes.framework.es.core.service;
|
package com.cf.imes.framework.es.core.service;
|
||||||
|
|
||||||
import cn.hutool.core.lang.Snowflake;
|
|
||||||
import cn.hutool.core.text.CharSequenceUtil;
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
|
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
||||||
import co.elastic.clients.elasticsearch._types.ElasticsearchException;
|
|
||||||
import co.elastic.clients.elasticsearch._types.Result;
|
|
||||||
import co.elastic.clients.elasticsearch.core.*;
|
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
import com.cf.imes.framework.security.core.LoginUser;
|
|
||||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author there
|
* @author there
|
||||||
*/
|
*/
|
||||||
public class ESDocumentServiceImpl implements ESDocumentService {
|
public class ESDocumentServiceImpl implements ESDocumentService {
|
||||||
//同步客户端
|
// //同步客户端
|
||||||
private final ElasticsearchClient elasticsearchClient;
|
// private final ElasticsearchClient elasticsearchClient;
|
||||||
|
//
|
||||||
// 异步客户端
|
// // 异步客户端
|
||||||
private final ElasticsearchAsyncClient elasticsearchAsyncClient;
|
// private final ElasticsearchAsyncClient elasticsearchAsyncClient;
|
||||||
|
//
|
||||||
private Snowflake snowflake = IdUtil.getSnowflake();
|
// private Snowflake snowflake = IdUtil.getSnowflake();
|
||||||
|
//
|
||||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
//
|
||||||
public ESDocumentServiceImpl(ElasticsearchClient elasticsearchClient, ElasticsearchAsyncClient elasticsearchAsyncClient) {
|
// public ESDocumentServiceImpl(ElasticsearchClient elasticsearchClient, ElasticsearchAsyncClient elasticsearchAsyncClient) {
|
||||||
this.elasticsearchClient = elasticsearchClient;
|
// this.elasticsearchClient = elasticsearchClient;
|
||||||
this.elasticsearchAsyncClient = elasticsearchAsyncClient;
|
// this.elasticsearchAsyncClient = elasticsearchAsyncClient;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public <T> IndexResponse createByFluentDSL(String idxName, String idxId, ESDocument document) throws Exception {
|
// public <T> IndexResponse createByFluentDSL(String idxName, String idxId, ESDocument document) throws Exception {
|
||||||
Date date = new Date();
|
// Date date = new Date();
|
||||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
// LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||||
document.setCreator(loginUser.getNickname());
|
// document.setCreator(loginUser.getNickname());
|
||||||
document.setUpdater(loginUser.getNickname());
|
// document.setUpdater(loginUser.getNickname());
|
||||||
document.setOrganId(loginUser.getOrganId());
|
// document.setOrganId(loginUser.getOrganId());
|
||||||
document.setCreateTime(simpleDateFormat.format(date));
|
// document.setCreateTime(simpleDateFormat.format(date));
|
||||||
document.setUpdateTime(simpleDateFormat.format(date));
|
// document.setUpdateTime(simpleDateFormat.format(date));
|
||||||
|
//
|
||||||
if (CharSequenceUtil.isBlank(document.getId())) {
|
// if (CharSequenceUtil.isBlank(document.getId())) {
|
||||||
document.setId(snowflake.nextIdStr());
|
// document.setId(snowflake.nextIdStr());
|
||||||
}
|
// }
|
||||||
return elasticsearchClient.index(idx -> idx
|
// return elasticsearchClient.index(idx -> idx
|
||||||
.index(idxName)
|
// .index(idxName)
|
||||||
.id(document.getId())
|
// .id(document.getId())
|
||||||
.document(document));
|
// .document(document));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* BuilderPattern 方式创建文档
|
// * BuilderPattern 方式创建文档
|
||||||
*
|
// *
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param idxId 索引id
|
// * @param idxId 索引id
|
||||||
* @param document 文档对象
|
// * @param document 文档对象
|
||||||
*/
|
// */
|
||||||
@Override
|
// @Override
|
||||||
public <T> IndexResponse createByBuilderPattern(String idxName, String idxId, ESDocument document) throws Exception {
|
// public <T> IndexResponse createByBuilderPattern(String idxName, String idxId, ESDocument document) throws Exception {
|
||||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
// LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||||
Date date = new Date();
|
// Date date = new Date();
|
||||||
document.setCreator(loginUser.getNickname());
|
// document.setCreator(loginUser.getNickname());
|
||||||
document.setUpdater(loginUser.getNickname());
|
// document.setUpdater(loginUser.getNickname());
|
||||||
document.setOrganId(loginUser.getOrganId());
|
// document.setOrganId(loginUser.getOrganId());
|
||||||
document.setCreateTime(simpleDateFormat.format(date));
|
// document.setCreateTime(simpleDateFormat.format(date));
|
||||||
document.setUpdateTime(simpleDateFormat.format(date));
|
// document.setUpdateTime(simpleDateFormat.format(date));
|
||||||
IndexRequest.Builder<Object> indexReqBuilder = new IndexRequest.Builder<>();
|
// IndexRequest.Builder<Object> indexReqBuilder = new IndexRequest.Builder<>();
|
||||||
indexReqBuilder.index(idxName);
|
// indexReqBuilder.index(idxName);
|
||||||
if (CharSequenceUtil.isBlank(idxId)) {
|
// if (CharSequenceUtil.isBlank(idxId)) {
|
||||||
idxId = snowflake.nextIdStr();
|
// idxId = snowflake.nextIdStr();
|
||||||
}
|
// }
|
||||||
indexReqBuilder.id(idxId);
|
// indexReqBuilder.id(idxId);
|
||||||
indexReqBuilder.document(document);
|
// indexReqBuilder.document(document);
|
||||||
return elasticsearchClient.index(indexReqBuilder.build());
|
// return elasticsearchClient.index(indexReqBuilder.build());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* json方式创建文档
|
// * json方式创建文档
|
||||||
*
|
// *
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param idxId 索引id
|
// * @param idxId 索引id
|
||||||
* @param jsonContent json字符串
|
// * @param jsonContent json字符串
|
||||||
*/
|
// */
|
||||||
@Override
|
// @Override
|
||||||
public IndexResponse createByJson(String idxName, String idxId, String jsonContent) throws Exception {
|
// public IndexResponse createByJson(String idxName, String idxId, String jsonContent) throws Exception {
|
||||||
if (CharSequenceUtil.isBlank(idxId)) {
|
// if (CharSequenceUtil.isBlank(idxId)) {
|
||||||
idxId = snowflake.nextIdStr();
|
// idxId = snowflake.nextIdStr();
|
||||||
}
|
// }
|
||||||
String finalIdxId = idxId;
|
// String finalIdxId = idxId;
|
||||||
return elasticsearchClient.index(i -> i
|
// return elasticsearchClient.index(i -> i
|
||||||
.index(idxName)
|
// .index(idxName)
|
||||||
.id(finalIdxId)
|
// .id(finalIdxId)
|
||||||
.withJson(new StringReader(jsonContent))
|
// .withJson(new StringReader(jsonContent))
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 异步方式创建文档
|
// * 异步方式创建文档
|
||||||
*
|
// *
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param idxId 索引id
|
// * @param idxId 索引id
|
||||||
* @param document 文档
|
// * @param document 文档
|
||||||
* @param action 操作
|
// * @param action 操作
|
||||||
*/
|
// */
|
||||||
@Override
|
// @Override
|
||||||
public <T> void createAsync(String idxName, String idxId, T document, BiConsumer<IndexResponse, Throwable> action) {
|
// public <T> void createAsync(String idxName, String idxId, T document, BiConsumer<IndexResponse, Throwable> action) {
|
||||||
elasticsearchAsyncClient.index(idx -> idx
|
// elasticsearchAsyncClient.index(idx -> idx
|
||||||
.index(idxName)
|
// .index(idxName)
|
||||||
.id(idxId)
|
// .id(idxId)
|
||||||
.document(document)
|
// .document(document)
|
||||||
).whenComplete(action);
|
// ).whenComplete(action);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 批量方式创建文档
|
// * 批量方式创建文档
|
||||||
*
|
// *
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param documents 要增加的对象集合
|
// * @param documents 要增加的对象集合
|
||||||
*/
|
// */
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public <T> BulkResponse bulkCreate(String idxName, List<? extends ESDocument> documents) throws IOException, ElasticsearchException {
|
// public <T> BulkResponse bulkCreate(String idxName, List<? extends ESDocument> documents) throws IOException, ElasticsearchException {
|
||||||
BulkRequest.Builder br = new BulkRequest.Builder();
|
// BulkRequest.Builder br = new BulkRequest.Builder();
|
||||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
// LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||||
Date date = new Date();
|
// Date date = new Date();
|
||||||
LocalDateTime now = LocalDateTime.now();
|
// LocalDateTime now = LocalDateTime.now();
|
||||||
documents.forEach(esDocument -> {
|
// documents.forEach(esDocument -> {
|
||||||
if (CharSequenceUtil.isBlank(esDocument.getId())) {
|
// if (CharSequenceUtil.isBlank(esDocument.getId())) {
|
||||||
esDocument.setId(snowflake.nextIdStr());
|
// esDocument.setId(snowflake.nextIdStr());
|
||||||
}
|
// }
|
||||||
esDocument.setCreator(loginUser.getNickname());
|
// esDocument.setCreator(loginUser.getNickname());
|
||||||
esDocument.setCreateTime(simpleDateFormat.format(date));
|
// esDocument.setCreateTime(simpleDateFormat.format(date));
|
||||||
esDocument.setUpdater(loginUser.getNickname());
|
// esDocument.setUpdater(loginUser.getNickname());
|
||||||
esDocument.setOrganId(loginUser.getOrganId());
|
// esDocument.setOrganId(loginUser.getOrganId());
|
||||||
|
//
|
||||||
esDocument.setUpdateTime(simpleDateFormat.format(date));
|
// esDocument.setUpdateTime(simpleDateFormat.format(date));
|
||||||
br.operations(op -> op.index(idx -> idx
|
// br.operations(op -> op.index(idx -> idx
|
||||||
.index(idxName)
|
// .index(idxName)
|
||||||
.id(esDocument.getId())
|
// .id(esDocument.getId())
|
||||||
.document(esDocument)));
|
// .document(esDocument)));
|
||||||
});
|
// });
|
||||||
return elasticsearchClient.bulk(br.build());
|
// return elasticsearchClient.bulk(br.build());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 批量方式更新文档
|
// * 批量方式更新文档
|
||||||
*
|
// *
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param documents 要更新的对象集合
|
// * @param documents 要更新的对象集合
|
||||||
*/
|
// */
|
||||||
@Override
|
// @Override
|
||||||
public <T> BulkResponse bulkUpdate(String idxName, List<? extends ESDocument> documents) throws Exception {
|
// public <T> BulkResponse bulkUpdate(String idxName, List<? extends ESDocument> documents) throws Exception {
|
||||||
BulkRequest.Builder br = new BulkRequest.Builder();
|
// BulkRequest.Builder br = new BulkRequest.Builder();
|
||||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
// LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||||
Date date = new Date();
|
// Date date = new Date();
|
||||||
documents.forEach(esDocument -> {
|
// documents.forEach(esDocument -> {
|
||||||
|
//
|
||||||
esDocument.setCreator(loginUser.getNickname());
|
// esDocument.setCreator(loginUser.getNickname());
|
||||||
esDocument.setUpdater(loginUser.getNickname());
|
// esDocument.setUpdater(loginUser.getNickname());
|
||||||
esDocument.setOrganId(loginUser.getOrganId());
|
// esDocument.setOrganId(loginUser.getOrganId());
|
||||||
esDocument.setUpdateTime(simpleDateFormat.format(date));
|
// esDocument.setUpdateTime(simpleDateFormat.format(date));
|
||||||
|
//
|
||||||
br.operations(op -> op.index(idx -> idx
|
// br.operations(op -> op.index(idx -> idx
|
||||||
.index(idxName)
|
// .index(idxName)
|
||||||
.id(esDocument.getId())
|
// .id(esDocument.getId())
|
||||||
.document(esDocument)));
|
// .document(esDocument)));
|
||||||
});
|
// });
|
||||||
return elasticsearchClient.bulk(br.build());
|
// return elasticsearchClient.bulk(br.build());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* @param idxName 索引名称
|
// * @param idxName 索引名称
|
||||||
* @param docId 文档id
|
// * @param docId 文档id
|
||||||
* @param tClass 返回的类型
|
// * @param tClass 返回的类型
|
||||||
* @param map 修改内容的map
|
// * @param map 修改内容的map
|
||||||
* Map<String, Object> map = new HashMap<>();
|
// * Map<String, Object> map = new HashMap<>();
|
||||||
* map.put("age", 35);
|
// * map.put("age", 35);
|
||||||
* 把年龄改成35
|
// * 把年龄改成35
|
||||||
*/
|
// */
|
||||||
@Override
|
// @Override
|
||||||
public <T> Result updateById(String idxName, String docId, Class<T> tClass, Map<String, Object> map) throws IOException, ElasticsearchException {
|
// public <T> Result updateById(String idxName, String docId, Class<T> tClass, Map<String, Object> map) throws IOException, ElasticsearchException {
|
||||||
UpdateResponse<T> response = elasticsearchClient.update(e -> e.index(idxName).id(docId).doc(map), tClass);
|
// UpdateResponse<T> response = elasticsearchClient.update(e -> e.index(idxName).id(docId).doc(map), tClass);
|
||||||
return response.result();
|
// return response.result();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 文档id查询信息
|
// * 文档id查询信息
|
||||||
*
|
// *
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param docId 文档id
|
// * @param docId 文档id
|
||||||
*/
|
// */
|
||||||
@Override
|
// @Override
|
||||||
public <T> T getById(String idxName, String docId, Class<T> tClass) throws IOException {
|
// public <T> T getById(String idxName, String docId, Class<T> tClass) throws IOException {
|
||||||
GetResponse<T> response = elasticsearchClient.get(g -> g
|
// GetResponse<T> response = elasticsearchClient.get(g -> g
|
||||||
.index(idxName)
|
// .index(idxName)
|
||||||
.id(docId),
|
// .id(docId),
|
||||||
tClass);
|
// tClass);
|
||||||
return response.found() ? response.source() : null;
|
// return response.found() ? response.source() : null;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 根据索引名称和文档id查询ObjectNode
|
// * 根据索引名称和文档id查询ObjectNode
|
||||||
*
|
// *
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param docId 文档id
|
// * @param docId 文档id
|
||||||
*/
|
// */
|
||||||
@Override
|
// @Override
|
||||||
public JSONObject getObjectNodeById(String idxName, String docId) throws IOException {
|
// public JSONObject getObjectNodeById(String idxName, String docId) throws IOException {
|
||||||
GetResponse<JSONObject> response = elasticsearchClient.get(g -> g
|
// GetResponse<JSONObject> response = elasticsearchClient.get(g -> g
|
||||||
.index(idxName)
|
// .index(idxName)
|
||||||
.id(docId),
|
// .id(docId),
|
||||||
JSONObject.class);
|
// JSONObject.class);
|
||||||
|
//
|
||||||
return response.found() ? response.source() : null;
|
// return response.found() ? response.source() : null;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 单条输出
|
// * 单条输出
|
||||||
*
|
// *
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param docId 文档id
|
// * @param docId 文档id
|
||||||
*/
|
// */
|
||||||
@Override
|
// @Override
|
||||||
public Boolean deleteById(String idxName, String docId) throws IOException {
|
// public Boolean deleteById(String idxName, String docId) throws IOException {
|
||||||
DeleteResponse delete = elasticsearchClient.delete(d -> d
|
// DeleteResponse delete = elasticsearchClient.delete(d -> d
|
||||||
.index(idxName)
|
// .index(idxName)
|
||||||
.id(docId));
|
// .id(docId));
|
||||||
return delete.forcedRefresh();
|
// return delete.forcedRefresh();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 批量删除
|
// * 批量删除
|
||||||
*
|
// *
|
||||||
* @param idxName 索引名
|
// * @param idxName 索引名
|
||||||
* @param docIds 要删除的文档id集合
|
// * @param docIds 要删除的文档id集合
|
||||||
*/
|
// */
|
||||||
@Override
|
// @Override
|
||||||
public BulkResponse bulkDeleteByIds(String idxName, List<String> docIds) throws Exception {
|
// public BulkResponse bulkDeleteByIds(String idxName, List<String> docIds) throws Exception {
|
||||||
BulkRequest.Builder br = new BulkRequest.Builder();
|
// BulkRequest.Builder br = new BulkRequest.Builder();
|
||||||
// 将每一个对象都放入builder中
|
// // 将每一个对象都放入builder中
|
||||||
docIds.forEach(id -> br
|
// docIds.forEach(id -> br
|
||||||
.operations(op -> op
|
// .operations(op -> op
|
||||||
.delete(d -> d
|
// .delete(d -> d
|
||||||
.index(idxName)
|
// .index(idxName)
|
||||||
.id(id))));
|
// .id(id))));
|
||||||
return elasticsearchClient.bulk(br.build());
|
// return elasticsearchClient.bulk(br.build());
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -1 +0,0 @@
|
|||||||
com.cf.imes.framework.es.config.ChenfengElasticsearchAutoConfiguration
|
|
||||||
@@ -48,17 +48,6 @@
|
|||||||
<groupId>com.cf.imes</groupId>
|
<groupId>com.cf.imes</groupId>
|
||||||
<artifactId>cf-spring-boot-starter-redis</artifactId>
|
<artifactId>cf-spring-boot-starter-redis</artifactId>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>jakarta.json</groupId>
|
<groupId>jakarta.json</groupId>
|
||||||
@@ -220,10 +209,6 @@
|
|||||||
<groupId>com.cf.imes</groupId>
|
<groupId>com.cf.imes</groupId>
|
||||||
<artifactId>cf-spring-boot-starter-biz-organ</artifactId>
|
<artifactId>cf-spring-boot-starter-biz-organ</artifactId>
|
||||||
</include>
|
</include>
|
||||||
<include>
|
|
||||||
<groupId>com.cf.imes</groupId>
|
|
||||||
<artifactId>cf-spring-boot-starter-elasticsearch</artifactId>
|
|
||||||
</include>
|
|
||||||
<include>
|
<include>
|
||||||
<groupId>com.cf.imes</groupId>
|
<groupId>com.cf.imes</groupId>
|
||||||
<artifactId>cf-spring-boot-starter-excel</artifactId>
|
<artifactId>cf-spring-boot-starter-excel</artifactId>
|
||||||
|
|||||||
-57
@@ -1,15 +1,8 @@
|
|||||||
package com.cf.imes.module.executor.api.plan;
|
package com.cf.imes.module.executor.api.plan;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
||||||
import co.elastic.clients.elasticsearch._types.FieldValue;
|
|
||||||
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
||||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
||||||
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.cf.imes.framework.common.exception.ServiceException;
|
|
||||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||||
import com.cf.imes.framework.common.util.json.JsonUtils;
|
import com.cf.imes.framework.common.util.json.JsonUtils;
|
||||||
import com.cf.imes.module.executor.api.plan.vo.OrderGroupRespVO;
|
import com.cf.imes.module.executor.api.plan.vo.OrderGroupRespVO;
|
||||||
@@ -47,7 +40,6 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
|
|
||||||
import static com.cf.imes.framework.common.util.json.JsonUtils.toJsonString;
|
import static com.cf.imes.framework.common.util.json.JsonUtils.toJsonString;
|
||||||
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
|
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
|
||||||
import static com.cf.imes.module.executor.enums.EsIndexEnum.*;
|
import static com.cf.imes.module.executor.enums.EsIndexEnum.*;
|
||||||
@@ -91,9 +83,6 @@ public class OrderPlanApiImpl implements OrderPlanApi{
|
|||||||
@Resource
|
@Resource
|
||||||
private OrderPartsMapper orderPartsMapper;
|
private OrderPartsMapper orderPartsMapper;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ElasticsearchClient elasticsearchClient;
|
|
||||||
|
|
||||||
|
|
||||||
public static final String SEPARATE = "select";
|
public static final String SEPARATE = "select";
|
||||||
|
|
||||||
@@ -465,67 +454,21 @@ public class OrderPlanApiImpl implements OrderPlanApi{
|
|||||||
|
|
||||||
|
|
||||||
private List<OrderPartsRemark> buildOrderPartsByOrderId(List<Long> orderIds, String index, Integer size) {
|
private List<OrderPartsRemark> buildOrderPartsByOrderId(List<Long> orderIds, String index, Integer size) {
|
||||||
|
|
||||||
List<FieldValue> fieldValues = orderIds.stream().map(FieldValue::of).toList();
|
|
||||||
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
||||||
builder.index(index);
|
|
||||||
builder.size(size);
|
|
||||||
builder.query(q -> q.terms(b -> b.field("orderId").terms(e -> e.value(fieldValues))));
|
|
||||||
try {
|
|
||||||
SearchResponse<OrderPartsRemark> search = elasticsearchClient.search(builder.build(), OrderPartsRemark.class);
|
|
||||||
List<Hit<OrderPartsRemark>> hits = search.hits().hits();
|
|
||||||
if (CollUtil.isNotEmpty(hits)) {
|
|
||||||
return hits.stream().map(Hit::source).toList();
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e.getMessage());
|
|
||||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private List<OptimizeBoardModelDO> buildBoardByPlanId(Long planId, String index, Integer size) {
|
private List<OptimizeBoardModelDO> buildBoardByPlanId(Long planId, String index, Integer size) {
|
||||||
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
||||||
builder.index(index);
|
|
||||||
builder.size(size);
|
|
||||||
builder.query(q -> q.term(b -> b.field("planId").value(planId)));
|
|
||||||
try {
|
|
||||||
SearchResponse<OptimizeBoardModelDO> search = elasticsearchClient.search(builder.build(), OptimizeBoardModelDO.class);
|
|
||||||
List<Hit<OptimizeBoardModelDO>> hits = search.hits().hits();
|
|
||||||
if (CollUtil.isNotEmpty(hits)) {
|
|
||||||
return hits.stream().map(Hit::source).toList();
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e.getMessage());
|
|
||||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private List<OrderModelDO> buildBoardByPlateIds(Collection<Long> plateIds, String index, Integer size) {
|
private List<OrderModelDO> buildBoardByPlateIds(Collection<Long> plateIds, String index, Integer size) {
|
||||||
List<FieldValue> fieldValues = plateIds.stream().map(FieldValue::of).toList();
|
|
||||||
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
||||||
builder.index(index);
|
|
||||||
builder.size(size);
|
|
||||||
builder.query(q -> q.terms(b -> b.field("plateId").terms(e -> e.value(fieldValues))));
|
|
||||||
try {
|
|
||||||
SearchResponse<OrderModelDO> search = elasticsearchClient.search(builder.build(), OrderModelDO.class);
|
|
||||||
List<Hit<OrderModelDO>> hits = search.hits().hits();
|
|
||||||
if (CollUtil.isNotEmpty(hits)) {
|
|
||||||
return hits.stream().map(Hit::source).toList();
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e.getMessage());
|
|
||||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
-17
@@ -23,7 +23,6 @@ import com.cf.imes.module.executor.dal.mysql.order.OrderMapper;
|
|||||||
import com.cf.imes.module.executor.enums.CategoryEnum;
|
import com.cf.imes.module.executor.enums.CategoryEnum;
|
||||||
import com.cf.imes.module.executor.enums.OrderDeletedEnum;
|
import com.cf.imes.module.executor.enums.OrderDeletedEnum;
|
||||||
import com.cf.imes.module.executor.enums.OrderStatusEnum;
|
import com.cf.imes.module.executor.enums.OrderStatusEnum;
|
||||||
import com.cf.imes.module.executor.service.order.OrderInputProcessor;
|
|
||||||
import com.cf.imes.module.executor.service.order.OrderService;
|
import com.cf.imes.module.executor.service.order.OrderService;
|
||||||
import com.cf.imes.module.executor.util.ExcelWriterUtil;
|
import com.cf.imes.module.executor.util.ExcelWriterUtil;
|
||||||
import com.cf.imes.module.executor.util.fileConversion.admin.api.webcad.ApiDataAchieve;
|
import com.cf.imes.module.executor.util.fileConversion.admin.api.webcad.ApiDataAchieve;
|
||||||
@@ -106,9 +105,6 @@ public class OrderController {
|
|||||||
@Resource
|
@Resource
|
||||||
private RedisLockUtil redisLockUtil;
|
private RedisLockUtil redisLockUtil;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private OrderInputProcessor orderInputProcessor;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ChenfengCacheProperties chenfengCacheProperties;
|
private ChenfengCacheProperties chenfengCacheProperties;
|
||||||
|
|
||||||
@@ -246,12 +242,6 @@ public class OrderController {
|
|||||||
|
|
||||||
return success(String.valueOf(id));
|
return success(String.valueOf(id));
|
||||||
} catch (CompletionException | ExecutionException | InterruptedException e) {
|
} catch (CompletionException | ExecutionException | InterruptedException e) {
|
||||||
// 进行判断,为空,写入时出现了错误,数据库数据回滚,此时删除 ES 里的数据
|
|
||||||
OrderDO orderDO = orderMapper.selectById(orderId);
|
|
||||||
if (orderDO == null) {
|
|
||||||
orderInputProcessor.deleteByOrderId(orderId, ORDER_PLATE_MODEL.getIndex());
|
|
||||||
orderInputProcessor.deleteByOrderId(orderId, ORDER_PARTS_REMARK_MODEL.getIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
Throwable cause = e.getCause();
|
Throwable cause = e.getCause();
|
||||||
return error((ServiceException) cause);
|
return error((ServiceException) cause);
|
||||||
@@ -397,13 +387,6 @@ public class OrderController {
|
|||||||
XMLUtil.writeErr(response, xmlStr, " order_add_xml_err.xml");
|
XMLUtil.writeErr(response, xmlStr, " order_add_xml_err.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 进行判断,为空,写入时出现了错误,数据库数据回滚,此时删除 ES 里的数据
|
|
||||||
if (ObjectUtil.isNotNull(orderDO) && ObjectUtil.isNotNull(orderMapper.selectById(orderDO.getId()))) {
|
|
||||||
Long deleteOrderId = orderDO.getId();
|
|
||||||
orderInputProcessor.deleteByOrderId(deleteOrderId, ORDER_PLATE_MODEL.getIndex());
|
|
||||||
orderInputProcessor.deleteByOrderId(deleteOrderId, ORDER_PARTS_REMARK_MODEL.getIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
// 导入锁解锁
|
// 导入锁解锁
|
||||||
redisLockUtil.releaseLock(importLockKey, importLockValue);
|
redisLockUtil.releaseLock(importLockKey, importLockValue);
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
package com.cf.imes.module.executor.controller.admin.orderParts.vo;
|
package com.cf.imes.module.executor.controller.admin.orderParts.vo;
|
||||||
|
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -12,7 +11,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class OrderPartsRemark extends ESDocument {
|
public class OrderPartsRemark {
|
||||||
|
|
||||||
@Schema(description = "配件 ID")
|
@Schema(description = "配件 ID")
|
||||||
private Long partsId;
|
private Long partsId;
|
||||||
|
|||||||
+2
-4
@@ -4,8 +4,6 @@ import com.cf.imes.framework.common.pojo.CommonResult;
|
|||||||
import com.cf.imes.framework.common.pojo.PageParam;
|
import com.cf.imes.framework.common.pojo.PageParam;
|
||||||
import com.cf.imes.framework.common.pojo.PageResult;
|
import com.cf.imes.framework.common.pojo.PageResult;
|
||||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
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.excel.core.util.ExcelUtils;
|
import com.cf.imes.framework.excel.core.util.ExcelUtils;
|
||||||
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
|
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
|
||||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderRespVO;
|
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderRespVO;
|
||||||
@@ -44,7 +42,7 @@ public class PlanController {
|
|||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建排单")
|
@Operation(summary = "创建排单")
|
||||||
// @PreAuthorize("@ss.hasPermission('manage:un-order-olan:create')")
|
// @PreAuthorize("@ss.hasPermission('manage:un-order-olan:create')")
|
||||||
public CommonResult<Boolean> createPlan(@Validated(CreateGroup.class) @RequestBody PlanSaveReqVO createReqVO) {
|
public CommonResult<Boolean> createPlan(@RequestBody PlanSaveReqVO createReqVO) {
|
||||||
planService.createPlan(createReqVO);
|
planService.createPlan(createReqVO);
|
||||||
return success(Boolean.TRUE);
|
return success(Boolean.TRUE);
|
||||||
}
|
}
|
||||||
@@ -52,7 +50,7 @@ public class PlanController {
|
|||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "更新排单")
|
@Operation(summary = "更新排单")
|
||||||
@PreAuthorize("@ss.hasAnyPermissions('placeorder:update','manage:order-plan:insert-plate','manage:order-plan:remove-plate')")
|
@PreAuthorize("@ss.hasAnyPermissions('placeorder:update','manage:order-plan:insert-plate','manage:order-plan:remove-plate')")
|
||||||
public CommonResult<Boolean> updatePlan(@Validated(UpdateGroup.class) @RequestBody PlanSaveReqVO updateReqVO) {
|
public CommonResult<Boolean> updatePlan(@RequestBody PlanSaveReqVO updateReqVO) {
|
||||||
planService.updatePlan(updateReqVO);
|
planService.updatePlan(updateReqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
package com.cf.imes.module.executor.controller.admin.plan.saveOptimize;
|
package com.cf.imes.module.executor.controller.admin.plan.saveOptimize;
|
||||||
|
|
||||||
|
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -16,7 +15,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class ProcessSchemeModelDO extends ESDocument {
|
public class ProcessSchemeModelDO {
|
||||||
|
|
||||||
|
|
||||||
@Schema(description = "排单ID")
|
@Schema(description = "排单ID")
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
package com.cf.imes.module.executor.controller.admin.plan.saveOptimize;
|
package com.cf.imes.module.executor.controller.admin.plan.saveOptimize;
|
||||||
|
|
||||||
|
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -16,7 +14,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class SaveProcessSchemeModelDO extends ESDocument {
|
public class SaveProcessSchemeModelDO {
|
||||||
|
|
||||||
|
|
||||||
@Schema(description = "排单ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "排单ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
|||||||
+3
-6
@@ -1,8 +1,5 @@
|
|||||||
package com.cf.imes.module.executor.controller.admin.plan.vo;
|
package com.cf.imes.module.executor.controller.admin.plan.vo;
|
||||||
|
|
||||||
|
|
||||||
import com.cf.imes.framework.es.core.valid.CreateGroup;
|
|
||||||
import com.cf.imes.framework.es.core.valid.UpdateGroup;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -30,15 +27,15 @@ public class BranchingPlanSaveReqVO {
|
|||||||
public static class Item {
|
public static class Item {
|
||||||
|
|
||||||
@Schema(description = "订单的商品id")
|
@Schema(description = "订单的商品id")
|
||||||
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败",groups = {UpdateGroup.class, CreateGroup.class})
|
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "订单id")
|
@Schema(description = "订单id")
|
||||||
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败",groups = {UpdateGroup.class, CreateGroup.class})
|
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败")
|
||||||
private Long orderId;
|
private Long orderId;
|
||||||
|
|
||||||
@Schema(description = "板材库大板id")
|
@Schema(description = "板材库大板id")
|
||||||
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败",groups = {UpdateGroup.class, CreateGroup.class})
|
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败")
|
||||||
private String goodsId;
|
private String goodsId;
|
||||||
|
|
||||||
@Schema(description = "余料板ID")
|
@Schema(description = "余料板ID")
|
||||||
|
|||||||
+5
-7
@@ -1,7 +1,5 @@
|
|||||||
package com.cf.imes.module.executor.controller.admin.plan.vo;
|
package com.cf.imes.module.executor.controller.admin.plan.vo;
|
||||||
|
|
||||||
import com.cf.imes.framework.es.core.valid.CreateGroup;
|
|
||||||
import com.cf.imes.framework.es.core.valid.UpdateGroup;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -41,15 +39,15 @@ public class SavePlanPlateList {
|
|||||||
public static class PlateItemList {
|
public static class PlateItemList {
|
||||||
|
|
||||||
@Schema(description = "订单id")
|
@Schema(description = "订单id")
|
||||||
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败",groups = {UpdateGroup.class, CreateGroup.class})
|
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败")
|
||||||
private Long plateId;
|
private Long plateId;
|
||||||
|
|
||||||
@Schema(description = "订单的商品id")
|
@Schema(description = "订单的商品id")
|
||||||
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败",groups = {UpdateGroup.class, CreateGroup.class})
|
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "订单id")
|
@Schema(description = "订单id")
|
||||||
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败",groups = {UpdateGroup.class, CreateGroup.class})
|
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败")
|
||||||
private Long orderId;
|
private Long orderId;
|
||||||
|
|
||||||
|
|
||||||
@@ -61,12 +59,12 @@ public class SavePlanPlateList {
|
|||||||
|
|
||||||
|
|
||||||
@Schema(description = "订单的商品id")
|
@Schema(description = "订单的商品id")
|
||||||
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败",groups = {UpdateGroup.class, CreateGroup.class})
|
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
|
||||||
@Schema(description = "板材库大板id-这个在新版还是需要的")
|
@Schema(description = "板材库大板id-这个在新版还是需要的")
|
||||||
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败",groups = {UpdateGroup.class, CreateGroup.class})
|
@NotNull(message = "订单数据错误,请检查订单数据或重新导入,排单创建失败")
|
||||||
private String goodsId;
|
private String goodsId;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
package com.cf.imes.module.executor.dal.dataobject.goods;
|
package com.cf.imes.module.executor.dal.dataobject.goods;
|
||||||
|
|
||||||
|
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
import com.cf.imes.module.executor.controller.admin.plan.saveOptimize.ActualGoodsList;
|
import com.cf.imes.module.executor.controller.admin.plan.saveOptimize.ActualGoodsList;
|
||||||
import com.cf.imes.module.executor.controller.admin.plan.saveOptimize.RemainBoardList;
|
import com.cf.imes.module.executor.controller.admin.plan.saveOptimize.RemainBoardList;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
@@ -21,7 +20,7 @@ import java.util.List;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Schema(description = "优化后的大板信息")
|
@Schema(description = "优化后的大板信息")
|
||||||
public class OptimizeBoardModelDO extends ESDocument {
|
public class OptimizeBoardModelDO {
|
||||||
|
|
||||||
@Schema(description = "排单ID")
|
@Schema(description = "排单ID")
|
||||||
private Long planId;
|
private Long planId;
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
package com.cf.imes.module.executor.dal.dataobject.goods;
|
package com.cf.imes.module.executor.dal.dataobject.goods;
|
||||||
|
|
||||||
|
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -15,7 +13,7 @@ import java.math.BigDecimal;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Schema(description = "混单选择的实际的大板信息")
|
@Schema(description = "混单选择的实际的大板信息")
|
||||||
public class PlanActualGoodsModelDO extends ESDocument {
|
public class PlanActualGoodsModelDO {
|
||||||
|
|
||||||
|
|
||||||
@Schema(description = "排单ID")
|
@Schema(description = "排单ID")
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
package com.cf.imes.module.executor.dal.dataobject.ordermodel;
|
package com.cf.imes.module.executor.dal.dataobject.ordermodel;
|
||||||
|
|
||||||
|
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -16,7 +14,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class OrderModelCompressDO extends ESDocument {
|
public class OrderModelCompressDO {
|
||||||
|
|
||||||
@Schema(description = "订单id")
|
@Schema(description = "订单id")
|
||||||
private Long orderId;
|
private Long orderId;
|
||||||
|
|||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
package com.cf.imes.module.executor.dal.dataobject.ordermodel;
|
package com.cf.imes.module.executor.dal.dataobject.ordermodel;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
import com.cf.imes.module.executor.util.deviseData.structure.*;
|
import com.cf.imes.module.executor.util.deviseData.structure.*;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
@@ -23,7 +22,7 @@ import java.util.Map;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class OrderModelDO extends ESDocument {
|
public class OrderModelDO {
|
||||||
|
|
||||||
@Schema(description = "订单id")
|
@Schema(description = "订单id")
|
||||||
private Long orderId;
|
private Long orderId;
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
package com.cf.imes.module.executor.dal.dataobject.ordermodel;
|
package com.cf.imes.module.executor.dal.dataobject.ordermodel;
|
||||||
|
|
||||||
|
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -15,7 +13,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class OrderPlateModel extends ESDocument {
|
public class OrderPlateModel {
|
||||||
|
|
||||||
@Schema(description = "订单id")
|
@Schema(description = "订单id")
|
||||||
private Long orderId;
|
private Long orderId;
|
||||||
|
|||||||
+10
-302
@@ -4,22 +4,6 @@ import cn.hutool.core.bean.BeanUtil;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.PageUtil;
|
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
||||||
import co.elastic.clients.elasticsearch._types.ElasticsearchException;
|
|
||||||
import co.elastic.clients.elasticsearch._types.FieldValue;
|
|
||||||
import co.elastic.clients.elasticsearch._types.SortOrder;
|
|
||||||
import co.elastic.clients.elasticsearch._types.aggregations.Aggregate;
|
|
||||||
import co.elastic.clients.elasticsearch.core.CountRequest;
|
|
||||||
import co.elastic.clients.elasticsearch.core.CountResponse;
|
|
||||||
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
||||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
||||||
import co.elastic.clients.elasticsearch.core.UpdateByQueryRequest;
|
|
||||||
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
||||||
import co.elastic.clients.elasticsearch.sql.TranslateRequest;
|
|
||||||
import co.elastic.clients.elasticsearch.sql.TranslateResponse;
|
|
||||||
import co.elastic.clients.json.JsonData;
|
|
||||||
import co.elastic.clients.json.JsonpMappingException;
|
|
||||||
import com.alibaba.cloud.commons.lang.StringUtils;
|
import com.alibaba.cloud.commons.lang.StringUtils;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
@@ -36,9 +20,7 @@ import com.cf.imes.framework.common.enums.PlanTypeEnum;
|
|||||||
import com.cf.imes.framework.common.exception.ServiceException;
|
import com.cf.imes.framework.common.exception.ServiceException;
|
||||||
import com.cf.imes.framework.common.pojo.PageResult;
|
import com.cf.imes.framework.common.pojo.PageResult;
|
||||||
import com.cf.imes.framework.common.util.Assert.AssertUtils;
|
import com.cf.imes.framework.common.util.Assert.AssertUtils;
|
||||||
import com.cf.imes.framework.common.util.json.JsonUtils;
|
|
||||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
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.query.LambdaUpdateWrapperX;
|
import com.cf.imes.framework.mybatis.core.query.LambdaUpdateWrapperX;
|
||||||
import com.cf.imes.framework.mybatis.core.query.QueryWrapperX;
|
import com.cf.imes.framework.mybatis.core.query.QueryWrapperX;
|
||||||
import com.cf.imes.module.executor.controller.admin.plan.bo.OrderIds;
|
import com.cf.imes.module.executor.controller.admin.plan.bo.OrderIds;
|
||||||
@@ -64,19 +46,14 @@ import com.cf.imes.module.executor.dal.dataobject.remainplaten.RemainPlateDO;
|
|||||||
import com.cf.imes.module.executor.dal.mysql.goods.GoodsMapper;
|
import com.cf.imes.module.executor.dal.mysql.goods.GoodsMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.order.OrderMapper;
|
import com.cf.imes.module.executor.dal.mysql.order.OrderMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.orderGroup.OrderGroupMapper;
|
import com.cf.imes.module.executor.dal.mysql.orderGroup.OrderGroupMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.orderParts.OrderPartsMapper;
|
|
||||||
import com.cf.imes.module.executor.dal.mysql.plan.PlanMapper;
|
import com.cf.imes.module.executor.dal.mysql.plan.PlanMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.planitem.PlanItemMapper;
|
import com.cf.imes.module.executor.dal.mysql.planitem.PlanItemMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.plate.PlateGoodMapper;
|
import com.cf.imes.module.executor.dal.mysql.plate.PlateGoodMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.plate.PlateMapper;
|
import com.cf.imes.module.executor.dal.mysql.plate.PlateMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.remainplaten.RemainPlateMapper;
|
import com.cf.imes.module.executor.dal.mysql.remainplaten.RemainPlateMapper;
|
||||||
import com.cf.imes.module.executor.enums.ErrorCodeConstants;
|
|
||||||
import com.cf.imes.module.executor.enums.plan.FlowProcessStatus;
|
import com.cf.imes.module.executor.enums.plan.FlowProcessStatus;
|
||||||
import com.cf.imes.module.executor.service.plan.PlanService;
|
import com.cf.imes.module.executor.service.plan.PlanService;
|
||||||
import com.cf.imes.module.executor.util.elasticsearch.EsUtils;
|
|
||||||
import com.cf.imes.module.system.api.dataSource.DataSourceApi;
|
import com.cf.imes.module.system.api.dataSource.DataSourceApi;
|
||||||
import com.cf.imes.module.system.api.machine.MachineApi;
|
|
||||||
import com.cf.imes.module.system.api.permission.PermissionApi;
|
|
||||||
import com.cf.imes.module.system.api.systemconfig.SystemConfigApi;
|
import com.cf.imes.module.system.api.systemconfig.SystemConfigApi;
|
||||||
import com.cf.imes.module.system.api.systemconfig.dto.ProcessSchemeDTO;
|
import com.cf.imes.module.system.api.systemconfig.dto.ProcessSchemeDTO;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
@@ -96,7 +73,6 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.DATA_DATA_ERROR;
|
|
||||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.ES_DATA_ERROR;
|
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.ES_DATA_ERROR;
|
||||||
import static com.cf.imes.framework.common.util.json.JsonUtils.*;
|
import static com.cf.imes.framework.common.util.json.JsonUtils.*;
|
||||||
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
|
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
|
||||||
@@ -129,30 +105,9 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
@Resource
|
@Resource
|
||||||
private OrderMapper orderMapper;
|
private OrderMapper orderMapper;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ElasticsearchClient elasticsearchClient;
|
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MachineApi machineApi;
|
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SystemConfigApi systemConfigApi;
|
private SystemConfigApi systemConfigApi;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private PermissionApi permissionApi;
|
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private EsUtils esUtils;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ESDocumentService esDocumentService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private OrderPartsMapper orderPartsMapper;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private OrderGroupMapper orderGroupMapper;
|
private OrderGroupMapper orderGroupMapper;
|
||||||
|
|
||||||
@@ -236,7 +191,7 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
|
|
||||||
|
|
||||||
// 查询优化信息
|
// 查询优化信息
|
||||||
List<OptimizeBoardModelDO> optimizeBoardModelDOS = esUtils.getEsDocument(FIELD_PLAN_CONFIG_ID,FIELD_PLAN_ID,planConfigId, planId, ORDER_OPTIMIZE_PLATE_MODEL.getIndex(), OptimizeBoardModelDO.class);
|
List<OptimizeBoardModelDO> optimizeBoardModelDOS = new ArrayList<>();
|
||||||
|
|
||||||
AssertUtils.notEmpty(optimizeBoardModelDOS,ORDER_PLAN_OPTIMIZE_ERROR);
|
AssertUtils.notEmpty(optimizeBoardModelDOS,ORDER_PLAN_OPTIMIZE_ERROR);
|
||||||
|
|
||||||
@@ -478,7 +433,7 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
|
|
||||||
|
|
||||||
// 兼容数据,后期可删除
|
// 兼容数据,后期可删除
|
||||||
List<OptimizeBoardModelDO> document = esUtils.getEsDocument(FIELD_PLAN_ID, planId, ORDER_OPTIMIZE_PLATE_MODEL.getIndex(), OptimizeBoardModelDO.class);
|
List<OptimizeBoardModelDO> document = new ArrayList<>();
|
||||||
if(CollUtil.isNotEmpty(document)){
|
if(CollUtil.isNotEmpty(document)){
|
||||||
OptimizeBoardModelDO optimizeBoardModelDO = document.get(0);
|
OptimizeBoardModelDO optimizeBoardModelDO = document.get(0);
|
||||||
processId = optimizeBoardModelDO.getProcessId();
|
processId = optimizeBoardModelDO.getProcessId();
|
||||||
@@ -502,10 +457,9 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
// 保存排单对应的方案组的配置信息
|
// 保存排单对应的方案组的配置信息
|
||||||
getPlanProcessSchemeConfig(planDO.getProcessId(),planId);
|
getPlanProcessSchemeConfig(planDO.getProcessId(),planId);
|
||||||
|
|
||||||
esUtils.deleteEsDocument(FIELD_PLAN_ID, planId, ORDER_OPTIMIZE_PLATE_MODEL.getIndex());
|
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
esUtils.deleteEsDocument(FIELD_PLAN_ID, FIELD_PLAN_CONFIG_ID, planId, boardModelDO.getPlanConfigId(), ORDER_OPTIMIZE_PLATE_MODEL.getIndex());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -517,23 +471,12 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
|
|
||||||
|
|
||||||
if(req.getPlanConfigId() != null && req.getProcessId() == null){
|
if(req.getPlanConfigId() != null && req.getProcessId() == null){
|
||||||
esUtils.deleteEsDocument(FIELD_PLAN_ID, FIELD_PLAN_CONFIG_ID, planId, req.getPlanConfigId(), ORDER_OPTIMIZE_PLATE_MODEL.getIndex());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boardModelDO.setIsNewInsertPlate(Boolean.FALSE);
|
boardModelDO.setIsNewInsertPlate(Boolean.FALSE);
|
||||||
|
|
||||||
|
|
||||||
// 保存优化后的大板数据
|
|
||||||
esUtils.saveEsDocument(ORDER_OPTIMIZE_PLATE_MODEL.getIndex(), Collections.singletonList(boardModelDO));
|
|
||||||
|
|
||||||
|
|
||||||
// ES文档数据刷新
|
|
||||||
esUtils.refresh(ORDER_OPTIMIZE_PLATE_MODEL.getIndex());
|
|
||||||
|
|
||||||
|
|
||||||
if (processId == null) {
|
if (processId == null) {
|
||||||
|
|
||||||
esUtils.deleteEsDocument(FIELD_PLAN_ID, planId, ORDER_OPTIMIZE_PLATE_MODEL.getIndex());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -581,20 +524,11 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
|
|
||||||
planMapper.updateById(planDO.setProcessId(processId));
|
planMapper.updateById(planDO.setProcessId(processId));
|
||||||
|
|
||||||
// 修改方案组,删除全部的方案组的优化信息
|
|
||||||
esUtils.deleteEsDocument(FIELD_PLAN_ID,planId,PLAN_PROCESS_SCHEME_OPTIMIZE_MODEL.getIndex());
|
|
||||||
|
|
||||||
// 删除全部的生产优化信息
|
|
||||||
esUtils.deleteEsDocument(FIELD_PLAN_ID,planId,ORDER_OPTIMIZE_PLATE_MODEL.getIndex());
|
|
||||||
|
|
||||||
// 保存此时的方案组的优化信息
|
|
||||||
esUtils.saveEsDocument(PLAN_PROCESS_SCHEME_OPTIMIZE_MODEL.getIndex(),schemeModelDOS);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ProcessSchemeModelDO> processSchemeModelDOS = esUtils.getEsDocument(FIELD_PLAN_ID, planId, PLAN_PROCESS_SCHEME_CONFIG.getIndex(), ProcessSchemeModelDO.class);
|
List<ProcessSchemeModelDO> processSchemeModelDOS = new ArrayList<>();
|
||||||
|
|
||||||
// 保存排单对应的加工方案组的配置信息
|
// 保存排单对应的加工方案组的配置信息
|
||||||
if(CollUtil.isEmpty(processSchemeModelDOS)){
|
if(CollUtil.isEmpty(processSchemeModelDOS)){
|
||||||
@@ -603,10 +537,6 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
esUtils.deleteEsDocument(FIELD_PLAN_ID,FIELD_PLAN_CONFIG_ID,planId,planConfigIds,PLAN_PROCESS_SCHEME_OPTIMIZE_MODEL.getIndex());
|
|
||||||
|
|
||||||
esUtils.saveEsDocument(PLAN_PROCESS_SCHEME_OPTIMIZE_MODEL.getIndex(),schemeModelDOS);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -617,8 +547,6 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
@Override
|
@Override
|
||||||
public PlanProcessSchemeList getProcessSchemeConfig(Long processId,Long planId) {
|
public PlanProcessSchemeList getProcessSchemeConfig(Long processId,Long planId) {
|
||||||
|
|
||||||
esUtils.refresh(PLAN_PROCESS_SCHEME_OPTIMIZE_MODEL.getIndex());
|
|
||||||
|
|
||||||
PlanProcessSchemeList planProcessSchemeList = new PlanProcessSchemeList();
|
PlanProcessSchemeList planProcessSchemeList = new PlanProcessSchemeList();
|
||||||
|
|
||||||
PlanDO planDO = validatePlanExists(planId);
|
PlanDO planDO = validatePlanExists(planId);
|
||||||
@@ -629,7 +557,7 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
List<ProcessSchemeDTO> schemeDTOList;
|
List<ProcessSchemeDTO> schemeDTOList;
|
||||||
|
|
||||||
// 获取排单对应的方案组的配置信息
|
// 获取排单对应的方案组的配置信息
|
||||||
List<ProcessSchemeModelDO> schemeModelDOS = esUtils.getEsDocument(FIELD_PLAN_ID, planId, PLAN_PROCESS_SCHEME_CONFIG.getIndex(), ProcessSchemeModelDO.class);
|
List<ProcessSchemeModelDO> schemeModelDOS = new ArrayList<>();
|
||||||
|
|
||||||
if(CollUtil.isNotEmpty(schemeModelDOS)){
|
if(CollUtil.isNotEmpty(schemeModelDOS)){
|
||||||
|
|
||||||
@@ -653,13 +581,13 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
|
|
||||||
|
|
||||||
// 查询排单对应的方案组信息
|
// 查询排单对应的方案组信息
|
||||||
List<SaveProcessSchemeModelDO> saveProcessSchemeReqVOS = esUtils.getEsDocument(FIELD_PLAN_ID, planId, PLAN_PROCESS_SCHEME_OPTIMIZE_MODEL.getIndex(), SaveProcessSchemeModelDO.class);
|
List<SaveProcessSchemeModelDO> saveProcessSchemeReqVOS = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
if(CollUtil.isNotEmpty(saveProcessSchemeReqVOS)){
|
if(CollUtil.isNotEmpty(saveProcessSchemeReqVOS)){
|
||||||
|
|
||||||
// 查询排单对应的优化信息
|
// 查询排单对应的优化信息
|
||||||
List<OptimizeBoardModelDO> optimizeBoardModelDOS = esUtils.getEsDocument(FIELD_PLAN_ID, planId, schemeDTOList.size(), ORDER_OPTIMIZE_PLATE_MODEL.getIndex(), OptimizeBoardModelDO.class);
|
List<OptimizeBoardModelDO> optimizeBoardModelDOS = new ArrayList<>();
|
||||||
|
|
||||||
if(CollUtil.isNotEmpty(optimizeBoardModelDOS)){
|
if(CollUtil.isNotEmpty(optimizeBoardModelDOS)){
|
||||||
|
|
||||||
@@ -743,7 +671,7 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
@Override
|
@Override
|
||||||
public List<OrderModelDO> getPlateModel(Long orderId) {
|
public List<OrderModelDO> getPlateModel(Long orderId) {
|
||||||
|
|
||||||
return esUtils.getEsDocumentByScroll(FIELD_ORDER_ID,orderId,1000,"imes_order_plate_model",OrderModelDO.class);
|
return new ArrayList<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -907,93 +835,6 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页获取订单ids下的es.orderModels数据
|
|
||||||
*
|
|
||||||
* @param orderIds
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private List<OrderModelDO> getOrderModels(List<Long> orderIds, List<Long> orderGoodsIds) {
|
|
||||||
List<OrderModelDO> results = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
// 查询总数
|
|
||||||
CountRequest countRequest = new CountRequest.Builder()
|
|
||||||
.index(ORDER_PLATE_MODEL.getIndex())
|
|
||||||
.query(q -> q.bool(b -> b
|
|
||||||
.filter(f -> f.terms(t -> t
|
|
||||||
.field(FIELD_ORDER_ID)
|
|
||||||
.terms(e -> e.value(orderIds.stream().map(FieldValue::of).toList()))
|
|
||||||
))
|
|
||||||
.filter(f -> f.terms(t -> t
|
|
||||||
.field("plateGoodsId")
|
|
||||||
.terms(e -> e.value(orderGoodsIds.stream().map(FieldValue::of).toList()))
|
|
||||||
))
|
|
||||||
))
|
|
||||||
.build();
|
|
||||||
CountResponse totalResponse = elasticsearchClient.count(countRequest);
|
|
||||||
long total = totalResponse.count();
|
|
||||||
|
|
||||||
// 分页查询
|
|
||||||
int pageNum = PageUtil.totalPage(total, 1000);
|
|
||||||
|
|
||||||
List<FieldValue> searchAfterSortValues = null;
|
|
||||||
for (int page = 1; page <= pageNum; page++) {
|
|
||||||
SearchRequest.Builder searchBuilder = new SearchRequest.Builder()
|
|
||||||
.index(ORDER_PLATE_MODEL.getIndex())
|
|
||||||
.size(1000)
|
|
||||||
.sort(s -> s.field(f -> f.field("id.keyword").order(SortOrder.Asc)))
|
|
||||||
.query(q -> q.bool(b -> b
|
|
||||||
.filter(f -> f.terms(t -> t.field(FIELD_ORDER_ID).terms(e -> e.value(orderIds.stream().map(FieldValue::of).toList()))))
|
|
||||||
.filter(f -> f.terms(t -> t.field("plateGoodsId").terms(e -> e.value(orderGoodsIds.stream().map(FieldValue::of).toList()))))
|
|
||||||
))
|
|
||||||
.source(s -> s
|
|
||||||
.filter(f -> f
|
|
||||||
.includes("holeDetail", "sideHoleDetail", "contourDetail", "sideDetail", "id", FIELD_PLATE_ID, "pointDetail",
|
|
||||||
"rawPointDetail", "splitLength", "splitWidth", "offsetX", "offsetY")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.trackTotalHits(t -> t.enabled(false));
|
|
||||||
|
|
||||||
// 设置 search_after,非第一页时才需要
|
|
||||||
if (searchAfterSortValues != null) {
|
|
||||||
searchBuilder.searchAfter(searchAfterSortValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
SearchResponse<OrderModelDO> response = elasticsearchClient.search(searchBuilder.build(), OrderModelDO.class);
|
|
||||||
|
|
||||||
List<Hit<OrderModelDO>> hits = response.hits().hits();
|
|
||||||
|
|
||||||
for (Hit<OrderModelDO> hit : hits) {
|
|
||||||
results.add(hit.source());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果没有更多结果,终止循环
|
|
||||||
if (hits.isEmpty()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取最后一条记录的 sort 值,用于下一页的 search_after
|
|
||||||
searchAfterSortValues = hits.get(hits.size() - 1).sort();
|
|
||||||
|
|
||||||
// 防止 sort 信息缺失导致死循环
|
|
||||||
if (searchAfterSortValues == null || searchAfterSortValues.isEmpty()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
|
|
||||||
} catch (JsonpMappingException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
throw new ServiceException(ORDER_DATA_ERROR);
|
|
||||||
} catch (IOException | ElasticsearchException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
throw new ServiceException(DATA_DATA_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<OrderRespVOCopy> getOrderPlateDataFilter(FilterDataPageReqVO pageReqVO) {
|
public PageResult<OrderRespVOCopy> getOrderPlateDataFilter(FilterDataPageReqVO pageReqVO) {
|
||||||
@@ -1095,7 +936,7 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
@Override
|
@Override
|
||||||
public Boolean getNewPlanPlate(Long planId) {
|
public Boolean getNewPlanPlate(Long planId) {
|
||||||
|
|
||||||
List<OptimizeBoardModelDO> optimizeBoardModelDOS = esUtils.getEsDocument(FIELD_PLAN_ID, planId, ORDER_OPTIMIZE_PLATE_MODEL.getIndex(), OptimizeBoardModelDO.class);
|
List<OptimizeBoardModelDO> optimizeBoardModelDOS = new ArrayList<>();
|
||||||
|
|
||||||
if(CollUtil.isNotEmpty(optimizeBoardModelDOS)){
|
if(CollUtil.isNotEmpty(optimizeBoardModelDOS)){
|
||||||
List<OptimizeBoardModelDO> modelDOS = optimizeBoardModelDOS.stream().filter(f ->Boolean.TRUE.equals(f.getIsNewInsertPlate())).toList();
|
List<OptimizeBoardModelDO> modelDOS = optimizeBoardModelDOS.stream().filter(f ->Boolean.TRUE.equals(f.getIsNewInsertPlate())).toList();
|
||||||
@@ -1112,38 +953,6 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
@Override
|
@Override
|
||||||
public void updateProcessSchemeConfig(PlanSchemeConfigReqVO reqVO) {
|
public void updateProcessSchemeConfig(PlanSchemeConfigReqVO reqVO) {
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
UpdateByQueryRequest.Builder builder = new UpdateByQueryRequest.Builder();
|
|
||||||
|
|
||||||
builder.index(PLAN_PROCESS_SCHEME_CONFIG.getIndex())
|
|
||||||
.query(qb -> qb.bool(bq -> bq
|
|
||||||
.must(mq -> mq.term(t->t.field(FIELD_PLAN_ID).value(reqVO.getPlanId())))
|
|
||||||
.must(mq -> mq.match(mtq -> mtq.field(FIELD_PLAN_CONFIG_ID).query(reqVO.getPlanConfigId())))
|
|
||||||
))
|
|
||||||
.script(s -> s.inline(i -> i
|
|
||||||
.source("""
|
|
||||||
ctx._source.processLineConfig = params.processLineConfig;
|
|
||||||
ctx._source.optimizationConfig = params.optimizationConfig;
|
|
||||||
ctx._source.analyzer = params.analyzer;
|
|
||||||
""")
|
|
||||||
.params("processLineConfig", JsonData.of(reqVO.getProcessLineConfig()))
|
|
||||||
.params("optimizationConfig", JsonData.of(reqVO.getOptimizationConfig()))
|
|
||||||
.params("analyzer", JsonData.of(reqVO.getAnalyzer()))
|
|
||||||
));
|
|
||||||
|
|
||||||
UpdateByQueryRequest request = builder.build();
|
|
||||||
|
|
||||||
// 执行更新操作
|
|
||||||
elasticsearchClient.updateByQuery(request);
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
log.error(e.getMessage());
|
|
||||||
throw new ServiceException(ES_DATA_ERROR);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1261,68 +1070,9 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
String logicalOperator,
|
String logicalOperator,
|
||||||
String config,
|
String config,
|
||||||
FilterDataPageReqVO pageReqVO, String field) {
|
FilterDataPageReqVO pageReqVO, String field) {
|
||||||
try {
|
|
||||||
|
|
||||||
// < 去重后查询到的总数量 , 查询到的板材造型数据 >
|
// < 去重后查询到的总数量 , 查询到的板材造型数据 >
|
||||||
Map<Long,List<OrderPlateModel>> orderModelMap = new HashMap<>();
|
return new HashMap<>();
|
||||||
|
|
||||||
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
||||||
|
|
||||||
builder.index(ORDER_PLATE_MODEL.getIndex());
|
|
||||||
|
|
||||||
|
|
||||||
// 生成查询 SQL
|
|
||||||
String filterSql = generateSql(orderIdList, goodsIdList, logicalOperator, config);
|
|
||||||
|
|
||||||
|
|
||||||
TranslateRequest.Builder builderTranslate = new TranslateRequest.Builder();
|
|
||||||
|
|
||||||
builderTranslate.query(filterSql);
|
|
||||||
|
|
||||||
TranslateResponse translate = elasticsearchClient.sql().translate(builderTranslate.build());
|
|
||||||
|
|
||||||
builder.query(q->q.constantScore(c->c.filter(translate.query())));
|
|
||||||
|
|
||||||
|
|
||||||
// 排序
|
|
||||||
builder.sort(s->s.field(f->f.field("createTime").order(SortOrder.Desc)));
|
|
||||||
|
|
||||||
|
|
||||||
// 只查询一个字段
|
|
||||||
builder.source(q->q.filter(f->f.includes(field)));
|
|
||||||
|
|
||||||
|
|
||||||
// 去重
|
|
||||||
builder.collapse(q->q.field(field));
|
|
||||||
|
|
||||||
|
|
||||||
// 分页
|
|
||||||
builder.from(((pageReqVO.getPageNo() -1) * pageReqVO.getPageSize()));
|
|
||||||
builder.size(pageReqVO.getPageSize());
|
|
||||||
|
|
||||||
|
|
||||||
// 获取去重后的总数量
|
|
||||||
builder.aggregations("distinct_count",agg->agg.cardinality(c->c.field(field)));
|
|
||||||
|
|
||||||
|
|
||||||
// 执行查询
|
|
||||||
SearchResponse<OrderPlateModel> search = elasticsearchClient.search(builder.build(), OrderPlateModel.class);
|
|
||||||
|
|
||||||
Map<String, Aggregate> aggregations = search.aggregations();
|
|
||||||
|
|
||||||
// 获取总数量
|
|
||||||
long value = aggregations.get("distinct_count").cardinality().value();
|
|
||||||
|
|
||||||
List<Hit<OrderPlateModel>> hits = search.hits().hits();
|
|
||||||
if (CollUtil.isNotEmpty(hits)) {
|
|
||||||
orderModelMap.put(value,hits.stream().map(Hit::source).toList());
|
|
||||||
}
|
|
||||||
return orderModelMap;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(ES_ORDER_MODEL_DATA_ERROR+e.getMessage());
|
|
||||||
throw new ServiceException(DATA_DATA_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String conversion(String filed) {
|
private String conversion(String filed) {
|
||||||
@@ -1451,33 +1201,6 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
|
|
||||||
private void updatePlanProcessScheme(Long planId,Long planConfigId,Boolean isLock) {
|
private void updatePlanProcessScheme(Long planId,Long planConfigId,Boolean isLock) {
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
UpdateByQueryRequest.Builder builder = new UpdateByQueryRequest.Builder();
|
|
||||||
|
|
||||||
builder.index(ORDER_OPTIMIZE_PLATE_MODEL.getIndex())
|
|
||||||
.query(qb -> qb.bool(bq -> bq.filter(f->{
|
|
||||||
f.term(t->t.field(FIELD_PLAN_ID).value(planId));
|
|
||||||
f.term(t->t.field(FIELD_PLAN_CONFIG_ID).value(planConfigId));
|
|
||||||
return f;
|
|
||||||
})
|
|
||||||
))
|
|
||||||
.script(s -> s.inline(i -> i
|
|
||||||
.source("ctx._source.isLock = params.new_value")
|
|
||||||
.params("new_value", JsonData.of(isLock))
|
|
||||||
));
|
|
||||||
|
|
||||||
UpdateByQueryRequest request = builder.build();
|
|
||||||
|
|
||||||
// 执行更新操作
|
|
||||||
elasticsearchClient.updateByQuery(request);
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
log.error(e.getMessage());
|
|
||||||
throw new ServiceException(ES_DATA_ERROR);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1610,14 +1333,6 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
updateData.put("cutedBlockNumber", optimizeBoardModelDO.getCutedBlockNumber());
|
updateData.put("cutedBlockNumber", optimizeBoardModelDO.getCutedBlockNumber());
|
||||||
updateData.put("remainBoardInfo", toJsonString(remainBoardInfos));
|
updateData.put("remainBoardInfo", toJsonString(remainBoardInfos));
|
||||||
updateData.put(FIELD_UPDATETIME, simpleDateFormat.format(date));
|
updateData.put(FIELD_UPDATETIME, simpleDateFormat.format(date));
|
||||||
|
|
||||||
try {
|
|
||||||
esDocumentService.updateById(ORDER_OPTIMIZE_PLATE_MODEL.getIndex(), optimizeBoardModelDO.getId(), HashMap.class, updateData);
|
|
||||||
|
|
||||||
} catch (IOException | ElasticsearchException e) {
|
|
||||||
log.error("Failed to sync with Elasticsearch: {}", e.getMessage());
|
|
||||||
throw new ServiceException(ES_DATA_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1786,13 +1501,6 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
|
|||||||
f.setProcessId(processId);
|
f.setProcessId(processId);
|
||||||
f.setPlanId(planId);
|
f.setPlanId(planId);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 删除旧的排单对应的加工方案组的配置信息
|
|
||||||
esUtils.deleteEsDocument(FIELD_PLAN_ID,planId,PLAN_PROCESS_SCHEME_CONFIG.getIndex());
|
|
||||||
|
|
||||||
// 保存新的排单对应的加工方案组的配置信息
|
|
||||||
esUtils.saveEsDocument(PLAN_PROCESS_SCHEME_CONFIG.getIndex(),modelDOS);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+267
-267
@@ -1,274 +1,274 @@
|
|||||||
package com.cf.imes.module.executor.service.order;
|
//package com.cf.imes.module.executor.service.order;
|
||||||
|
//
|
||||||
import cn.hutool.core.collection.CollUtil;
|
//import cn.hutool.core.collection.CollUtil;
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
//import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||||
import co.elastic.clients.elasticsearch._types.ElasticsearchException;
|
//import co.elastic.clients.elasticsearch._types.ElasticsearchException;
|
||||||
import co.elastic.clients.elasticsearch._types.FieldValue;
|
//import co.elastic.clients.elasticsearch._types.FieldValue;
|
||||||
import co.elastic.clients.elasticsearch.core.*;
|
//import co.elastic.clients.elasticsearch.core.*;
|
||||||
import co.elastic.clients.elasticsearch.core.search.Hit;
|
//import co.elastic.clients.elasticsearch.core.search.Hit;
|
||||||
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
//import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||||
import com.cf.imes.framework.common.exception.ServiceException;
|
//import com.cf.imes.framework.common.exception.ServiceException;
|
||||||
import com.cf.imes.framework.es.core.service.ESDocumentService;
|
//import com.cf.imes.framework.es.core.service.ESDocumentService;
|
||||||
import com.cf.imes.module.executor.controller.admin.orderParts.vo.OrderPartsRemark;
|
//import com.cf.imes.module.executor.controller.admin.orderParts.vo.OrderPartsRemark;
|
||||||
import com.cf.imes.module.executor.dal.dataobject.goods.GoodsDO;
|
//import com.cf.imes.module.executor.dal.dataobject.goods.GoodsDO;
|
||||||
import com.cf.imes.module.executor.dal.dataobject.orderBody.OrderBodyDO;
|
//import com.cf.imes.module.executor.dal.dataobject.orderBody.OrderBodyDO;
|
||||||
import com.cf.imes.module.executor.dal.dataobject.orderGroup.OrderGroupDO;
|
//import com.cf.imes.module.executor.dal.dataobject.orderGroup.OrderGroupDO;
|
||||||
import com.cf.imes.module.executor.dal.dataobject.orderItem.OrderItemDO;
|
//import com.cf.imes.module.executor.dal.dataobject.orderItem.OrderItemDO;
|
||||||
import com.cf.imes.module.executor.dal.dataobject.orderParts.OrderPartsDO;
|
//import com.cf.imes.module.executor.dal.dataobject.orderParts.OrderPartsDO;
|
||||||
import com.cf.imes.module.executor.dal.dataobject.orderParts.PartsDO;
|
//import com.cf.imes.module.executor.dal.dataobject.orderParts.PartsDO;
|
||||||
import com.cf.imes.module.executor.dal.dataobject.ordermodel.OrderModelDO;
|
//import com.cf.imes.module.executor.dal.dataobject.ordermodel.OrderModelDO;
|
||||||
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
|
//import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
|
||||||
import com.cf.imes.module.executor.dal.dataobject.plate.PlateGoodDO;
|
//import com.cf.imes.module.executor.dal.dataobject.plate.PlateGoodDO;
|
||||||
import com.cf.imes.module.executor.dal.dataobject.rawgoods.RawGoodsDO;
|
//import com.cf.imes.module.executor.dal.dataobject.rawgoods.RawGoodsDO;
|
||||||
import com.cf.imes.module.executor.dal.mysql.goods.GoodsMapper;
|
//import com.cf.imes.module.executor.dal.mysql.goods.GoodsMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.order.OrderMapper;
|
//import com.cf.imes.module.executor.dal.mysql.order.OrderMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.orderBody.OrderBodyMapper;
|
//import com.cf.imes.module.executor.dal.mysql.orderBody.OrderBodyMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.orderGroup.OrderGroupMapper;
|
//import com.cf.imes.module.executor.dal.mysql.orderGroup.OrderGroupMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.orderItem.OrderItemMapper;
|
//import com.cf.imes.module.executor.dal.mysql.orderItem.OrderItemMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.orderParts.OrderPartsMapper;
|
//import com.cf.imes.module.executor.dal.mysql.orderParts.OrderPartsMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.orderParts.PartsMapper;
|
//import com.cf.imes.module.executor.dal.mysql.orderParts.PartsMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.plate.PlateGoodMapper;
|
//import com.cf.imes.module.executor.dal.mysql.plate.PlateGoodMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.plate.PlateMapper;
|
//import com.cf.imes.module.executor.dal.mysql.plate.PlateMapper;
|
||||||
import com.cf.imes.module.executor.dal.mysql.rawgoods.RawGoodsMapper;
|
//import com.cf.imes.module.executor.dal.mysql.rawgoods.RawGoodsMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
//import org.springframework.transaction.annotation.Transactional;
|
||||||
|
//
|
||||||
import jakarta.annotation.Resource;
|
//import jakarta.annotation.Resource;
|
||||||
import java.io.IOException;
|
//import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
//import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
//import java.util.Collection;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
import java.util.function.BiConsumer;
|
//import java.util.function.BiConsumer;
|
||||||
import java.util.stream.Collectors;
|
//import java.util.stream.Collectors;
|
||||||
|
//
|
||||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
|
//import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
|
||||||
import static com.cf.imes.module.executor.enums.EsIndexEnum.*;
|
//import static com.cf.imes.module.executor.enums.EsIndexEnum.*;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author Beal
|
// * @author Beal
|
||||||
* 订单入库处理器
|
// * 订单入库处理器
|
||||||
*/
|
// */
|
||||||
@Slf4j
|
//@Slf4j
|
||||||
@Component
|
////@Component
|
||||||
public class OrderInputProcessor {
|
//public class OrderInputProcessor {
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private IdentifierGenerator identifierGenerator;
|
// private IdentifierGenerator identifierGenerator;
|
||||||
/*private IdentifierGenerator identifierGenerator = new SnowFlakeGenerator(0, 0);*/
|
// /*private IdentifierGenerator identifierGenerator = new SnowFlakeGenerator(0, 0);*/
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private OrderMapper orderMapper;
|
// private OrderMapper orderMapper;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private RawGoodsMapper rawGoodsMapper;
|
// private RawGoodsMapper rawGoodsMapper;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private OrderBodyMapper orderBodyMapper;
|
// private OrderBodyMapper orderBodyMapper;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private OrderGroupMapper orderGroupMapper;
|
// private OrderGroupMapper orderGroupMapper;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private OrderPartsMapper orderPartsMapper;
|
// private OrderPartsMapper orderPartsMapper;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private PlateMapper plateMapper;
|
// private PlateMapper plateMapper;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private OrderItemMapper orderItemMapper;
|
// private OrderItemMapper orderItemMapper;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private GoodsMapper goodsMapper;
|
// private GoodsMapper goodsMapper;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private PlateGoodMapper plateGoodMapper;
|
// private PlateGoodMapper plateGoodMapper;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private ESDocumentService esDocumentService;
|
// private ESDocumentService esDocumentService;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private PartsMapper partsMapper;
|
// private PartsMapper partsMapper;
|
||||||
|
//
|
||||||
@Resource
|
// @Resource
|
||||||
private ElasticsearchClient elasticsearchClient;
|
// private ElasticsearchClient elasticsearchClient;
|
||||||
|
//
|
||||||
private static final String FIELD_ORDER_ID = "orderId";
|
// private static final String FIELD_ORDER_ID = "orderId";
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 批量保存订单小板五金数据
|
// * 批量保存订单小板五金数据
|
||||||
*
|
// *
|
||||||
* @param rawGoodsDOS
|
// * @param rawGoodsDOS
|
||||||
* @param orderBodyDOS
|
// * @param orderBodyDOS
|
||||||
* @param orderGroupDOS
|
// * @param orderGroupDOS
|
||||||
* @param orderPartsDOS
|
// * @param orderPartsDOS
|
||||||
* @param plateDOS
|
// * @param plateDOS
|
||||||
* @param itemDOS
|
// * @param itemDOS
|
||||||
*/
|
// */
|
||||||
@Transactional(rollbackFor = Exception.class)
|
// @Transactional(rollbackFor = Exception.class)
|
||||||
public void batchInsert(Collection<RawGoodsDO> rawGoodsDOS,
|
// public void batchInsert(Collection<RawGoodsDO> rawGoodsDOS,
|
||||||
Collection<OrderBodyDO> orderBodyDOS,
|
// Collection<OrderBodyDO> orderBodyDOS,
|
||||||
Collection<OrderGroupDO> orderGroupDOS,
|
// Collection<OrderGroupDO> orderGroupDOS,
|
||||||
Collection<OrderPartsDO> orderPartsDOS,
|
// Collection<OrderPartsDO> orderPartsDOS,
|
||||||
Collection<PlateDO> plateDOS,
|
// Collection<PlateDO> plateDOS,
|
||||||
Collection<OrderItemDO> itemDOS,
|
// Collection<OrderItemDO> itemDOS,
|
||||||
Collection<GoodsDO> goodsDOS,
|
// Collection<GoodsDO> goodsDOS,
|
||||||
Collection<PlateGoodDO> plateGoodDOS,
|
// Collection<PlateGoodDO> plateGoodDOS,
|
||||||
Collection<PartsDO> partsDOS) {
|
// Collection<PartsDO> partsDOS) {
|
||||||
|
//
|
||||||
|
//
|
||||||
// if (rawGoodsDOS != null)
|
//// if (rawGoodsDOS != null)
|
||||||
// for (int i = 0; i < rawGoodsDOS.size(); i += 1000) {
|
//// for (int i = 0; i < rawGoodsDOS.size(); i += 1000) {
|
||||||
// rawGoodsMapper.insertBatch(rawGoodsDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
//// rawGoodsMapper.insertBatch(rawGoodsDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
||||||
|
//// }
|
||||||
|
//// if (orderBodyDOS != null)
|
||||||
|
//// for (int i = 0; i < orderBodyDOS.size(); i += 1000) {
|
||||||
|
//// orderBodyMapper.insertBatch(orderBodyDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
||||||
|
//// }
|
||||||
|
//// if (orderGroupDOS != null)
|
||||||
|
//// for (int i = 0; i < orderGroupDOS.size(); i += 1000) {
|
||||||
|
//// orderGroupMapper.insertBatch(orderGroupDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
||||||
|
//// }
|
||||||
|
//// if (orderPartsDOS != null)
|
||||||
|
//// for (int i = 0; i < orderPartsDOS.size(); i += 1000) {
|
||||||
|
//// orderPartsMapper.insertBatch(orderPartsDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
||||||
|
//// }
|
||||||
|
//// if (plateDOS != null)
|
||||||
|
//// for (int i = 0; i < plateDOS.size(); i += 1000) {
|
||||||
|
//// plateMapper.insertBatch(plateDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
||||||
|
//// }
|
||||||
|
//// if (itemDOS != null) {
|
||||||
|
//// for (int i = 0; i < itemDOS.size(); i += 1000) {
|
||||||
|
//// orderItemMapper.insertBatch(itemDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
||||||
|
//// }
|
||||||
|
//// }
|
||||||
|
//// if (goodsDOS != null) {
|
||||||
|
//// for (int i = 0; i < itemDOS.size(); i += 1000) {
|
||||||
|
//// goodsMapper.insertBatch(goodsDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
||||||
|
//// }
|
||||||
|
//// }
|
||||||
|
//// if (plateGoodDOS != null) {
|
||||||
|
//// for (int i = 0; i < itemDOS.size(); i += 1000) {
|
||||||
|
//// plateGoodMapper.insertBatch(plateGoodDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
||||||
|
//// }
|
||||||
|
//// }
|
||||||
|
//
|
||||||
|
// insertInBatches(rawGoodsDOS, 1000, (batch, index) -> rawGoodsMapper.insertBatch((Collection<RawGoodsDO>) batch));
|
||||||
|
// insertInBatches(orderBodyDOS, 1000, (batch, index) -> orderBodyMapper.insertBatch((Collection<OrderBodyDO>) batch));
|
||||||
|
// insertInBatches(orderGroupDOS, 1000, (batch, index) -> orderGroupMapper.insertBatch((Collection<OrderGroupDO>) batch));
|
||||||
|
// insertInBatches(orderPartsDOS, 1000, (batch, index) -> orderPartsMapper.insertBatch((Collection<OrderPartsDO>) batch));
|
||||||
|
// insertInBatches(plateDOS, 1000, (batch, index) -> plateMapper.insertBatch((Collection<PlateDO>) batch));
|
||||||
|
// insertInBatches(itemDOS, 1000, (batch, index) -> orderItemMapper.insertBatch((Collection<OrderItemDO>) batch));
|
||||||
|
// insertInBatches(goodsDOS, 1000, (batch, index) -> goodsMapper.insertBatch((Collection<GoodsDO>) batch));
|
||||||
|
//// insertInBatches(plateGoodDOS, 1000, (batch, index) -> plateGoodMapper.insertBatch((Collection<PlateGoodDO>) batch));
|
||||||
|
// insertInBatches(partsDOS, 1000, (batch, index) -> partsMapper.insertBatch((Collection<PartsDO>) batch));
|
||||||
// }
|
// }
|
||||||
// if (orderBodyDOS != null)
|
//
|
||||||
// for (int i = 0; i < orderBodyDOS.size(); i += 1000) {
|
// private void insertInBatches(Collection<?> entities, int batchSize, BiConsumer<Collection<?>, Integer> insertFunction) {
|
||||||
// orderBodyMapper.insertBatch(orderBodyDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
// if (entities != null) {
|
||||||
// }
|
// int total = entities.size();
|
||||||
// if (orderGroupDOS != null)
|
// for (int i = 0; i < total; i += batchSize) {
|
||||||
// for (int i = 0; i < orderGroupDOS.size(); i += 1000) {
|
// Collection<?> batch = entities.stream()
|
||||||
// orderGroupMapper.insertBatch(orderGroupDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
// .skip(i)
|
||||||
// }
|
// .limit(batchSize)
|
||||||
// if (orderPartsDOS != null)
|
// .collect(Collectors.toList());
|
||||||
// for (int i = 0; i < orderPartsDOS.size(); i += 1000) {
|
// insertFunction.accept(batch, i);
|
||||||
// orderPartsMapper.insertBatch(orderPartsDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
|
||||||
// }
|
|
||||||
// if (plateDOS != null)
|
|
||||||
// for (int i = 0; i < plateDOS.size(); i += 1000) {
|
|
||||||
// plateMapper.insertBatch(plateDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
|
||||||
// }
|
|
||||||
// if (itemDOS != null) {
|
|
||||||
// for (int i = 0; i < itemDOS.size(); i += 1000) {
|
|
||||||
// orderItemMapper.insertBatch(itemDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// if (goodsDOS != null) {
|
// }
|
||||||
// for (int i = 0; i < itemDOS.size(); i += 1000) {
|
//
|
||||||
// goodsMapper.insertBatch(goodsDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
// /**
|
||||||
|
// * 保存订单造型数据
|
||||||
|
// *
|
||||||
|
// * @param orderModelDOs
|
||||||
|
// */
|
||||||
|
// public void batchSaveModel(List<OrderModelDO> orderModelDOs) {
|
||||||
|
// try {
|
||||||
|
// BulkResponse bulkResponse = esDocumentService.bulkCreate(ORDER_PLATE_MODEL.getIndex(), orderModelDOs);
|
||||||
|
// boolean errors = bulkResponse.errors();
|
||||||
|
// if (errors) {
|
||||||
|
// log.error(bulkResponse.items().toString());
|
||||||
|
// throw new ServiceException(500, "未知异常");
|
||||||
|
// }
|
||||||
|
// } catch (IOException | ElasticsearchException e) {
|
||||||
|
// log.error(e.getMessage(), e);
|
||||||
|
// throw new RuntimeException(e);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 保存订单配件备注数据
|
||||||
|
// *
|
||||||
|
// * @param orderPartsRemarks
|
||||||
|
// */
|
||||||
|
// public void batchSaveOrderPartsModel(List<OrderPartsRemark> orderPartsRemarks) {
|
||||||
|
// try {
|
||||||
|
// BulkResponse bulkResponse = esDocumentService.bulkCreate(ORDER_PARTS_REMARK_MODEL.getIndex(), orderPartsRemarks);
|
||||||
|
// boolean errors = bulkResponse.errors();
|
||||||
|
// if (errors) {
|
||||||
|
// log.error(bulkResponse.items().toString());
|
||||||
|
// throw new ServiceException(500, "未知异常");
|
||||||
|
// }
|
||||||
|
// } catch (IOException | ElasticsearchException e) {
|
||||||
|
// log.error(e.getMessage(), e);
|
||||||
|
// throw new RuntimeException(e);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 订单Id删除
|
||||||
|
// */
|
||||||
|
// public void deleteByOrderId(Long orderId, String index) {
|
||||||
|
// try {
|
||||||
|
// // 查文档_id
|
||||||
|
// SearchResponse<Void> search = elasticsearchClient.search(s -> s
|
||||||
|
// .index(index)
|
||||||
|
// .size(1) // 只取一条
|
||||||
|
// .query(q -> q.term(t -> t.field("orderId").value(orderId)))
|
||||||
|
// .source(src -> src.fetch(false)), // 不拉取 _source
|
||||||
|
// Void.class
|
||||||
|
// );
|
||||||
|
// List<Hit<Void>> hits = search.hits().hits();
|
||||||
|
// if (hits.isEmpty()) {
|
||||||
|
// log.warn("No document found for orderId: {}", orderId);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// String docId = hits.get(0).id();
|
||||||
|
//
|
||||||
|
// // 按 _id 删除
|
||||||
|
// elasticsearchClient.delete(d -> d.index(index).id(docId));
|
||||||
|
// log.info("Successfully deleted document with orderId={} (docId={})", orderId, docId);
|
||||||
|
// } catch (IOException | ElasticsearchException e) {
|
||||||
|
// log.error("Error deleting documents with orderId {}: {}", orderId, e);
|
||||||
|
// throw new ServiceException(INTERNAL_SERVER_ERROR);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// if (plateGoodDOS != null) {
|
//
|
||||||
// for (int i = 0; i < itemDOS.size(); i += 1000) {
|
// /**
|
||||||
// plateGoodMapper.insertBatch(plateGoodDOS.stream().skip(i).limit(1000).collect(Collectors.toList()));
|
// * 批量删除
|
||||||
|
// */
|
||||||
|
// public void deleteByOrderId(List<Long> orderIds, String index) {
|
||||||
|
// List<FieldValue> fieldValues = orderIds.stream().map(FieldValue::of).toList();
|
||||||
|
//
|
||||||
|
// DeleteByQueryRequest.Builder builder = new DeleteByQueryRequest.Builder();
|
||||||
|
// builder.index(index);
|
||||||
|
//
|
||||||
|
// builder.query(q -> q.terms(b -> b.field(FIELD_ORDER_ID).terms(e -> e.value(fieldValues))));
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// DeleteByQueryResponse response = elasticsearchClient.deleteByQuery(builder.build());
|
||||||
|
// log.info("Deleted {} documents with planId {}", response.deleted(), orderIds);
|
||||||
|
// } catch (IOException | ElasticsearchException e) {
|
||||||
|
// log.error("Error deleting documents with planId {}: {}", orderIds, e);
|
||||||
|
// throw new ServiceException(INTERNAL_SERVER_ERROR);
|
||||||
|
// }
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
insertInBatches(rawGoodsDOS, 1000, (batch, index) -> rawGoodsMapper.insertBatch((Collection<RawGoodsDO>) batch));
|
|
||||||
insertInBatches(orderBodyDOS, 1000, (batch, index) -> orderBodyMapper.insertBatch((Collection<OrderBodyDO>) batch));
|
|
||||||
insertInBatches(orderGroupDOS, 1000, (batch, index) -> orderGroupMapper.insertBatch((Collection<OrderGroupDO>) batch));
|
|
||||||
insertInBatches(orderPartsDOS, 1000, (batch, index) -> orderPartsMapper.insertBatch((Collection<OrderPartsDO>) batch));
|
|
||||||
insertInBatches(plateDOS, 1000, (batch, index) -> plateMapper.insertBatch((Collection<PlateDO>) batch));
|
|
||||||
insertInBatches(itemDOS, 1000, (batch, index) -> orderItemMapper.insertBatch((Collection<OrderItemDO>) batch));
|
|
||||||
insertInBatches(goodsDOS, 1000, (batch, index) -> goodsMapper.insertBatch((Collection<GoodsDO>) batch));
|
|
||||||
// insertInBatches(plateGoodDOS, 1000, (batch, index) -> plateGoodMapper.insertBatch((Collection<PlateGoodDO>) batch));
|
|
||||||
insertInBatches(partsDOS, 1000, (batch, index) -> partsMapper.insertBatch((Collection<PartsDO>) batch));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void insertInBatches(Collection<?> entities, int batchSize, BiConsumer<Collection<?>, Integer> insertFunction) {
|
|
||||||
if (entities != null) {
|
|
||||||
int total = entities.size();
|
|
||||||
for (int i = 0; i < total; i += batchSize) {
|
|
||||||
Collection<?> batch = entities.stream()
|
|
||||||
.skip(i)
|
|
||||||
.limit(batchSize)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
insertFunction.accept(batch, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存订单造型数据
|
|
||||||
*
|
|
||||||
* @param orderModelDOs
|
|
||||||
*/
|
|
||||||
public void batchSaveModel(List<OrderModelDO> orderModelDOs) {
|
|
||||||
try {
|
|
||||||
BulkResponse bulkResponse = esDocumentService.bulkCreate(ORDER_PLATE_MODEL.getIndex(), orderModelDOs);
|
|
||||||
boolean errors = bulkResponse.errors();
|
|
||||||
if (errors) {
|
|
||||||
log.error(bulkResponse.items().toString());
|
|
||||||
throw new ServiceException(500, "未知异常");
|
|
||||||
}
|
|
||||||
} catch (IOException | ElasticsearchException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存订单配件备注数据
|
|
||||||
*
|
|
||||||
* @param orderPartsRemarks
|
|
||||||
*/
|
|
||||||
public void batchSaveOrderPartsModel(List<OrderPartsRemark> orderPartsRemarks) {
|
|
||||||
try {
|
|
||||||
BulkResponse bulkResponse = esDocumentService.bulkCreate(ORDER_PARTS_REMARK_MODEL.getIndex(), orderPartsRemarks);
|
|
||||||
boolean errors = bulkResponse.errors();
|
|
||||||
if (errors) {
|
|
||||||
log.error(bulkResponse.items().toString());
|
|
||||||
throw new ServiceException(500, "未知异常");
|
|
||||||
}
|
|
||||||
} catch (IOException | ElasticsearchException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单Id删除
|
|
||||||
*/
|
|
||||||
public void deleteByOrderId(Long orderId, String index) {
|
|
||||||
try {
|
|
||||||
// 查文档_id
|
|
||||||
SearchResponse<Void> search = elasticsearchClient.search(s -> s
|
|
||||||
.index(index)
|
|
||||||
.size(1) // 只取一条
|
|
||||||
.query(q -> q.term(t -> t.field("orderId").value(orderId)))
|
|
||||||
.source(src -> src.fetch(false)), // 不拉取 _source
|
|
||||||
Void.class
|
|
||||||
);
|
|
||||||
List<Hit<Void>> hits = search.hits().hits();
|
|
||||||
if (hits.isEmpty()) {
|
|
||||||
log.warn("No document found for orderId: {}", orderId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String docId = hits.get(0).id();
|
|
||||||
|
|
||||||
// 按 _id 删除
|
|
||||||
elasticsearchClient.delete(d -> d.index(index).id(docId));
|
|
||||||
log.info("Successfully deleted document with orderId={} (docId={})", orderId, docId);
|
|
||||||
} catch (IOException | ElasticsearchException e) {
|
|
||||||
log.error("Error deleting documents with orderId {}: {}", orderId, e);
|
|
||||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量删除
|
|
||||||
*/
|
|
||||||
public void deleteByOrderId(List<Long> orderIds, String index) {
|
|
||||||
List<FieldValue> fieldValues = orderIds.stream().map(FieldValue::of).toList();
|
|
||||||
|
|
||||||
DeleteByQueryRequest.Builder builder = new DeleteByQueryRequest.Builder();
|
|
||||||
builder.index(index);
|
|
||||||
|
|
||||||
builder.query(q -> q.terms(b -> b.field(FIELD_ORDER_ID).terms(e -> e.value(fieldValues))));
|
|
||||||
|
|
||||||
try {
|
|
||||||
DeleteByQueryResponse response = elasticsearchClient.deleteByQuery(builder.build());
|
|
||||||
log.info("Deleted {} documents with planId {}", response.deleted(), orderIds);
|
|
||||||
} catch (IOException | ElasticsearchException e) {
|
|
||||||
log.error("Error deleting documents with planId {}: {}", orderIds, e);
|
|
||||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+3
-23
@@ -81,7 +81,6 @@ import com.cf.imes.module.executor.service.orderImport.factory.OrderImportHandle
|
|||||||
import com.cf.imes.module.executor.service.ordercomponent.OrderComponentService;
|
import com.cf.imes.module.executor.service.ordercomponent.OrderComponentService;
|
||||||
import com.cf.imes.module.executor.util.deviseData.structure.FieldConstants;
|
import com.cf.imes.module.executor.util.deviseData.structure.FieldConstants;
|
||||||
import com.cf.imes.module.executor.util.deviseData.structure.PlateDetail;
|
import com.cf.imes.module.executor.util.deviseData.structure.PlateDetail;
|
||||||
import com.cf.imes.module.executor.util.elasticsearch.EsUtils;
|
|
||||||
import com.cf.imes.module.executor.util.fileConversion.admin.api.webcad.ApiDataTypeVo;
|
import com.cf.imes.module.executor.util.fileConversion.admin.api.webcad.ApiDataTypeVo;
|
||||||
import com.cf.imes.module.infra.api.file.FileApi;
|
import com.cf.imes.module.infra.api.file.FileApi;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -111,7 +110,6 @@ import java.util.stream.IntStream;
|
|||||||
import static com.cf.imes.framework.common.util.json.JsonUtils.unzipString;
|
import static com.cf.imes.framework.common.util.json.JsonUtils.unzipString;
|
||||||
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
|
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
|
||||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.*;
|
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.*;
|
||||||
import static com.cf.imes.module.executor.enums.EsIndexEnum.*;
|
|
||||||
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS;
|
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,9 +152,6 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
@Resource
|
@Resource
|
||||||
private OrderItemMapper orderItemMapper;
|
private OrderItemMapper orderItemMapper;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private OrderInputProcessor orderInputProcessor;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PartsMapper partsMapper;
|
private PartsMapper partsMapper;
|
||||||
|
|
||||||
@@ -166,10 +161,6 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
@Resource
|
@Resource
|
||||||
private PlanItemMapper planItemMapper;
|
private PlanItemMapper planItemMapper;
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private EsUtils esUtils;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private OrderComponentService orderComponentService;
|
private OrderComponentService orderComponentService;
|
||||||
|
|
||||||
@@ -693,7 +684,6 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
|
|
||||||
customPlateNoGenerateService.generateCustomPlateNo(order, plateDO, true);
|
customPlateNoGenerateService.generateCustomPlateNo(order, plateDO, true);
|
||||||
orderMapper.insert(order);
|
orderMapper.insert(order);
|
||||||
orderInputProcessor.batchInsert(rawGoodsDO, bodyDO, groupDO, partsDO, plateDO, itemDO, goodsDO, plateGoodDOS, partsDOS);
|
|
||||||
List<OrderModelDO> orderModelDOs = BeanUtils.toBean(plateDetail, OrderModelDO.class);
|
List<OrderModelDO> orderModelDOs = BeanUtils.toBean(plateDetail, OrderModelDO.class);
|
||||||
|
|
||||||
if (orderModelDOs != null && !orderModelDOs.isEmpty()) {
|
if (orderModelDOs != null && !orderModelDOs.isEmpty()) {
|
||||||
@@ -701,12 +691,8 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
orderModelDOs.forEach(orderModelDO -> orderModelDO.setOrderId(order.getId()));
|
orderModelDOs.forEach(orderModelDO -> orderModelDO.setOrderId(order.getId()));
|
||||||
// 保存大板的分类和实际ID和未优化
|
// 保存大板的分类和实际ID和未优化
|
||||||
saveOrderPlateModel(plateDO,goodsDO,orderModelDOs);
|
saveOrderPlateModel(plateDO,goodsDO,orderModelDOs);
|
||||||
orderInputProcessor.batchSaveModel(orderModelDOs);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!partsRemark.isEmpty()) {
|
|
||||||
orderInputProcessor.batchSaveOrderPartsModel(partsRemark);
|
|
||||||
}
|
|
||||||
|
|
||||||
return order == null ? 0 : order.getId();
|
return order == null ? 0 : order.getId();
|
||||||
}
|
}
|
||||||
@@ -770,18 +756,13 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
|
|
||||||
customPlateNoGenerateService.generateCustomPlateNo(orderDO, plateDO, index == 0);
|
customPlateNoGenerateService.generateCustomPlateNo(orderDO, plateDO, index == 0);
|
||||||
insertOrder(orderDO, index);
|
insertOrder(orderDO, index);
|
||||||
orderInputProcessor.batchInsert(rawGoodsDO, bodyDO, groupDO, partsDO, plateDO, itemDO, goodsDO, plateGoodDOS, partsDOList);
|
|
||||||
|
|
||||||
if (plateDetail != null && !plateDetail.isEmpty()){
|
if (plateDetail != null && !plateDetail.isEmpty()){
|
||||||
List<OrderModelDO> orderModelDOs = BeanUtils.toBean(plateDetail, OrderModelDO.class);
|
List<OrderModelDO> orderModelDOs = BeanUtils.toBean(plateDetail, OrderModelDO.class);
|
||||||
|
|
||||||
saveOrderPlateModel(plateDO,goodsDO,orderModelDOs);
|
saveOrderPlateModel(plateDO,goodsDO,orderModelDOs);
|
||||||
orderInputProcessor.batchSaveModel(orderModelDOs);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (orderPartsRemarks != null && !orderPartsRemarks.isEmpty()) {
|
|
||||||
orderInputProcessor.batchSaveOrderPartsModel(orderPartsRemarks);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1600,7 +1581,6 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
f.setActualGoodsId(goodsDO.stream().filter(g->g.getId().equals(f.getGoodsId())).map(GoodsDO::getGoodsId).toList().get(0))
|
f.setActualGoodsId(goodsDO.stream().filter(g->g.getId().equals(f.getGoodsId())).map(GoodsDO::getGoodsId).toList().get(0))
|
||||||
);
|
);
|
||||||
orderModelDOs.forEach(f->{
|
orderModelDOs.forEach(f->{
|
||||||
f.setId(f.getPlateId().toString());
|
|
||||||
f.setGoodsId(orderGoodsPlateIds.stream().filter(fo->fo.getId().equals(f.getPlateId())).map(OrderGoodsPlateIds::getActualGoodsId).toList().get(0));
|
f.setGoodsId(orderGoodsPlateIds.stream().filter(fo->fo.getId().equals(f.getPlateId())).map(OrderGoodsPlateIds::getActualGoodsId).toList().get(0));
|
||||||
f.setPlateGoodsId(orderGoodsPlateIds.stream().filter(fo->fo.getId().equals(f.getPlateId())).map(OrderGoodsPlateIds::getGoodsId).toList().get(0));
|
f.setPlateGoodsId(orderGoodsPlateIds.stream().filter(fo->fo.getId().equals(f.getPlateId())).map(OrderGoodsPlateIds::getGoodsId).toList().get(0));
|
||||||
|
|
||||||
@@ -1663,7 +1643,7 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
List<Long> plateIdList = labelOrderPlateData.stream().map(LabelOrderPlateData::getPlateId).distinct().toList();
|
List<Long> plateIdList = labelOrderPlateData.stream().map(LabelOrderPlateData::getPlateId).distinct().toList();
|
||||||
|
|
||||||
// 小板造型信息
|
// 小板造型信息
|
||||||
orderModelDOS = esUtils.getEsDocument("orderId","plateId", orderIds,plateIdList, plateIdList.size(), ORDER_PLATE_MODEL.getIndex(), OrderModelDO.class);
|
orderModelDOS = new ArrayList<>();
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
|
|
||||||
@@ -1675,7 +1655,7 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
// 板材信息
|
// 板材信息
|
||||||
labelOrderPlateData = plateMapper.selectLabelOrderPlateDataByOrderId(orderId,organId);
|
labelOrderPlateData = plateMapper.selectLabelOrderPlateDataByOrderId(orderId,organId);
|
||||||
|
|
||||||
orderModelDOS = esUtils.getEsDocumentByScroll("orderId", orderIds,1000, ORDER_PLATE_MODEL.getIndex(), OrderModelDO.class);
|
orderModelDOS = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1716,7 +1696,7 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
// 补充实际选择的大板信息-即生产的信息
|
// 补充实际选择的大板信息-即生产的信息
|
||||||
if(CollUtil.isNotEmpty(planIdList)){
|
if(CollUtil.isNotEmpty(planIdList)){
|
||||||
|
|
||||||
List<PlanActualGoodsModelDO> actualGoodsModelDOS = esUtils.getEsDocument("planId", planIdList, planIdList.size(), PLAN_ACTUAL_GOODS_MODEL.getIndex(), PlanActualGoodsModelDO.class);
|
List<PlanActualGoodsModelDO> actualGoodsModelDOS = new ArrayList<>();
|
||||||
|
|
||||||
if(CollUtil.isNotEmpty(actualGoodsModelDOS)) {
|
if(CollUtil.isNotEmpty(actualGoodsModelDOS)) {
|
||||||
labelOrderPlateData.forEach(f -> {
|
labelOrderPlateData.forEach(f -> {
|
||||||
|
|||||||
-32
@@ -2,15 +2,6 @@ package com.cf.imes.module.executor.service.order;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
||||||
import co.elastic.clients.elasticsearch._types.FieldValue;
|
|
||||||
import co.elastic.clients.elasticsearch._types.SortOrder;
|
|
||||||
import co.elastic.clients.elasticsearch._types.aggregations.Aggregate;
|
|
||||||
import co.elastic.clients.elasticsearch._types.aggregations.CalendarInterval;
|
|
||||||
import co.elastic.clients.elasticsearch._types.aggregations.DateHistogramAggregation;
|
|
||||||
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
||||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
||||||
import co.elastic.clients.util.NamedValue;
|
|
||||||
import com.cf.imes.framework.common.enums.OrderStatusEnum;
|
import com.cf.imes.framework.common.enums.OrderStatusEnum;
|
||||||
import com.cf.imes.framework.common.enums.StatisticsUnit;
|
import com.cf.imes.framework.common.enums.StatisticsUnit;
|
||||||
import com.cf.imes.framework.common.util.date.LocalDateTimeUtils;
|
import com.cf.imes.framework.common.util.date.LocalDateTimeUtils;
|
||||||
@@ -35,7 +26,6 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import java.io.IOException;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
@@ -48,7 +38,6 @@ import static com.cf.imes.framework.common.constants.StatisticsConstants.DATELIS
|
|||||||
import static com.cf.imes.framework.common.constants.StatisticsConstants.SERIES_FIELD_NAME;
|
import static com.cf.imes.framework.common.constants.StatisticsConstants.SERIES_FIELD_NAME;
|
||||||
import static com.cf.imes.framework.common.util.time.StatisticsChangeUtils.generateDateRangeAxis;
|
import static com.cf.imes.framework.common.util.time.StatisticsChangeUtils.generateDateRangeAxis;
|
||||||
import static com.cf.imes.framework.common.util.time.StatisticsChangeUtils.getDateList;
|
import static com.cf.imes.framework.common.util.time.StatisticsChangeUtils.getDateList;
|
||||||
import static com.cf.imes.module.executor.enums.EsIndexEnum.ORDER_OPTIMIZE_PLATE_MODEL;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gqr
|
* @author Gqr
|
||||||
@@ -74,9 +63,6 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
|||||||
@Resource
|
@Resource
|
||||||
private PlateGoodMapper plateGoodMapper;
|
private PlateGoodMapper plateGoodMapper;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ElasticsearchClient client;
|
|
||||||
|
|
||||||
// 常用的字段key
|
// 常用的字段key
|
||||||
private static final String ORDER_REMAIN_PLATE_MODEL_CREATE_TIME_FIELDNAME = "createTime";
|
private static final String ORDER_REMAIN_PLATE_MODEL_CREATE_TIME_FIELDNAME = "createTime";
|
||||||
private static final String ORDER_REMAIN_PLATE_MODEL_GOODS_GROUP_NAME = "goods_group";
|
private static final String ORDER_REMAIN_PLATE_MODEL_GOODS_GROUP_NAME = "goods_group";
|
||||||
@@ -556,24 +542,6 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据统计维度获取es分组的dateHistogram
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private DateHistogramAggregation.Builder getDateHistogram(Integer unit, DateHistogramAggregation.Builder builder) {
|
|
||||||
switch (StatisticsUnit.fromValue(unit)) {
|
|
||||||
case QUARTER:
|
|
||||||
return builder.calendarInterval(CalendarInterval.Quarter).format("yyyy-Q");
|
|
||||||
case MONTH:
|
|
||||||
return builder.calendarInterval(CalendarInterval.Month).format(DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH);
|
|
||||||
case DAY, WEEK:
|
|
||||||
default:
|
|
||||||
return builder.calendarInterval(CalendarInterval.Day).format(DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH_DAY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 年月日转年月周
|
* 年月日转年月周
|
||||||
*
|
*
|
||||||
|
|||||||
+1
-131
@@ -5,10 +5,6 @@ import cn.hutool.core.collection.CollUtil;
|
|||||||
import cn.hutool.core.collection.ListUtil;
|
import cn.hutool.core.collection.ListUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
||||||
import co.elastic.clients.elasticsearch._types.FieldValue;
|
|
||||||
import co.elastic.clients.elasticsearch.core.UpdateByQueryRequest;
|
|
||||||
import co.elastic.clients.json.JsonData;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
@@ -61,7 +57,6 @@ import com.cf.imes.module.executor.dal.mysql.remainplaten.RemainPlateMapper;
|
|||||||
import com.cf.imes.module.executor.enums.ErrorCodeConstants;
|
import com.cf.imes.module.executor.enums.ErrorCodeConstants;
|
||||||
import com.cf.imes.module.executor.enums.OrderPlanQueryTypeEnum;
|
import com.cf.imes.module.executor.enums.OrderPlanQueryTypeEnum;
|
||||||
import com.cf.imes.module.executor.enums.OrderStatusEnum;
|
import com.cf.imes.module.executor.enums.OrderStatusEnum;
|
||||||
import com.cf.imes.module.executor.util.elasticsearch.EsUtils;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.aop.framework.AopContext;
|
import org.springframework.aop.framework.AopContext;
|
||||||
@@ -79,7 +74,6 @@ import java.util.*;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.DATA_DATA_ERROR;
|
|
||||||
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static com.cf.imes.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
|
import static com.cf.imes.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
|
||||||
import static com.cf.imes.framework.common.util.json.JsonUtils.parseArray;
|
import static com.cf.imes.framework.common.util.json.JsonUtils.parseArray;
|
||||||
@@ -128,12 +122,6 @@ public class PlanServiceImpl implements PlanService {
|
|||||||
@Resource
|
@Resource
|
||||||
private IdentifierGenerator identifierGenerator;
|
private IdentifierGenerator identifierGenerator;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ElasticsearchClient elasticsearchClient;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private EsUtils esUtils;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private OrderGroupMapper orderGroupMapper;
|
private OrderGroupMapper orderGroupMapper;
|
||||||
|
|
||||||
@@ -1057,7 +1045,7 @@ public class PlanServiceImpl implements PlanService {
|
|||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<OptimizeBoardModelDO> boardModelDOS = esUtils.getEsDocument(FIELD_PLANID, planId, ORDER_OPTIMIZE_PLATE_MODEL.getIndex(), OptimizeBoardModelDO.class);
|
List<OptimizeBoardModelDO> boardModelDOS = new ArrayList<>();
|
||||||
|
|
||||||
if(CollUtil.isNotEmpty(boardModelDOS)) {
|
if(CollUtil.isNotEmpty(boardModelDOS)) {
|
||||||
|
|
||||||
@@ -1599,124 +1587,6 @@ public class PlanServiceImpl implements PlanService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void updateProcessSchemeStatus(List<Long> planIds) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
UpdateByQueryRequest.Builder builder = new UpdateByQueryRequest.Builder();
|
|
||||||
|
|
||||||
List<FieldValue> fieldValues = planIds.stream().map(FieldValue::of).toList();
|
|
||||||
|
|
||||||
builder.index(PLAN_PROCESS_SCHEME_OPTIMIZE_MODEL.getIndex())
|
|
||||||
.query(qb -> qb.bool(bq -> bq
|
|
||||||
.filter(mq -> mq.terms(tq -> tq.field(FIELD_PLANID).terms(t->t.value(fieldValues))))
|
|
||||||
.filter(mq -> mq.match(mtq -> mtq.field("machineType").query(MachineTypeEnum.CUTTING.getType())))
|
|
||||||
))
|
|
||||||
.script(s -> s.inline(i -> i
|
|
||||||
.source("ctx._source.isOptimized = params.new_value")
|
|
||||||
.params(ES_FIELD_NEWVALUE, JsonData.of(false))
|
|
||||||
));
|
|
||||||
|
|
||||||
UpdateByQueryRequest request = builder.build();
|
|
||||||
|
|
||||||
// 执行更新操作
|
|
||||||
elasticsearchClient.updateByQuery(request);
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
log.error(ORDER_PLAN_PROCESS_SCHEME_STATUS_UPDATE_ERROR_MSG + e.getMessage(), e);
|
|
||||||
throw new ServiceException(DATA_DATA_ERROR);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void insertPlateModelPlanId(List<Long> orderIds,List<Long> plateIds,Long planId) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
UpdateByQueryRequest.Builder builder = new UpdateByQueryRequest.Builder();
|
|
||||||
|
|
||||||
List<FieldValue> fieldValues1 = orderIds.stream().map(FieldValue::of).toList();
|
|
||||||
List<FieldValue> fieldValues2 = plateIds.stream().map(FieldValue::of).toList();
|
|
||||||
|
|
||||||
builder.index(ORDER_PLATE_MODEL.getIndex())
|
|
||||||
.query(qb -> qb.bool(bq -> bq
|
|
||||||
.filter(f->f.terms(t->t.field("orderId").terms(ts->ts.value(fieldValues1))))
|
|
||||||
.filter(f->f.terms(t->t.field("plateId").terms(ts->ts.value(fieldValues2))))
|
|
||||||
))
|
|
||||||
.script(s -> s.inline(i -> i
|
|
||||||
.source("ctx._source.planId = params.new_value")
|
|
||||||
.params(ES_FIELD_NEWVALUE, JsonData.of(planId))
|
|
||||||
));
|
|
||||||
|
|
||||||
UpdateByQueryRequest request = builder.build();
|
|
||||||
|
|
||||||
// 执行更新操作
|
|
||||||
elasticsearchClient.updateByQuery(request);
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
log.error(ORDER_PLAN_PROCESS_SCHEME_STATUS_UPDATE_ERROR_MSG + e.getMessage(), e);
|
|
||||||
throw new ServiceException(DATA_DATA_ERROR);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void removePlateModelPlanId(List<Long> orderIds,List<Long> planIds,List<Long> plateIds) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
UpdateByQueryRequest.Builder builder = new UpdateByQueryRequest.Builder();
|
|
||||||
|
|
||||||
List<FieldValue> fieldValues1 = orderIds.stream().map(FieldValue::of).toList();
|
|
||||||
|
|
||||||
List<FieldValue> fieldValues2 = planIds.stream().map(FieldValue::of).toList();
|
|
||||||
|
|
||||||
List<FieldValue> fieldValues3 = plateIds.stream().map(FieldValue::of).toList();
|
|
||||||
|
|
||||||
builder.index(ORDER_PLATE_MODEL.getIndex())
|
|
||||||
.query(qb -> qb.bool(bq -> {
|
|
||||||
bq.filter(f->f.terms(t->t.field("orderId").terms(ts->ts.value(fieldValues1))));
|
|
||||||
bq.filter(f->f.terms(t->t.field(FIELD_PLANID).terms(ts->ts.value(fieldValues2))));
|
|
||||||
|
|
||||||
if(CollUtil.isNotEmpty(plateIds)){
|
|
||||||
bq.filter(f->f.terms(t->t.field("plateId").terms(ts->ts.value(fieldValues3))));
|
|
||||||
}
|
|
||||||
|
|
||||||
return bq;
|
|
||||||
}
|
|
||||||
))
|
|
||||||
.script(s -> s.inline(i -> i
|
|
||||||
.source("ctx._source.planId = params.new_value")
|
|
||||||
.params(ES_FIELD_NEWVALUE, JsonData.of(0))
|
|
||||||
));
|
|
||||||
|
|
||||||
UpdateByQueryRequest request = builder.build();
|
|
||||||
|
|
||||||
// 执行更新操作
|
|
||||||
elasticsearchClient.updateByQuery(request);
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
log.error(ORDER_PLAN_PROCESS_SCHEME_STATUS_UPDATE_ERROR_MSG + e.getMessage(), e);
|
|
||||||
throw new ServiceException(DATA_DATA_ERROR);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单列表匹配到商品上
|
* 订单列表匹配到商品上
|
||||||
*
|
*
|
||||||
|
|||||||
-32
@@ -4,11 +4,6 @@ import cn.hutool.core.bean.BeanUtil;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.lang.Pair;
|
import cn.hutool.core.lang.Pair;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
||||||
import co.elastic.clients.elasticsearch._types.FieldValue;
|
|
||||||
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
||||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
||||||
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
||||||
import com.alibaba.cloud.commons.lang.StringUtils;
|
import com.alibaba.cloud.commons.lang.StringUtils;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
@@ -61,7 +56,6 @@ import com.cf.imes.module.executor.dal.mysql.plate.PlateGoodMapper;
|
|||||||
import com.cf.imes.module.executor.dal.mysql.plate.PlateMapper;
|
import com.cf.imes.module.executor.dal.mysql.plate.PlateMapper;
|
||||||
import com.cf.imes.module.executor.enums.OrderItemType;
|
import com.cf.imes.module.executor.enums.OrderItemType;
|
||||||
import com.cf.imes.module.executor.enums.OrderStatusEnum;
|
import com.cf.imes.module.executor.enums.OrderStatusEnum;
|
||||||
import com.cf.imes.module.executor.service.order.OrderInputProcessor;
|
|
||||||
import com.cf.imes.module.executor.service.order.OrderService;
|
import com.cf.imes.module.executor.service.order.OrderService;
|
||||||
import com.cf.imes.module.executor.service.orderbody.OrderBodyService;
|
import com.cf.imes.module.executor.service.orderbody.OrderBodyService;
|
||||||
import com.cf.imes.module.executor.service.ordercomponent.OrderComponentService;
|
import com.cf.imes.module.executor.service.ordercomponent.OrderComponentService;
|
||||||
@@ -74,14 +68,12 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import java.io.IOException;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
|
|
||||||
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
|
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
|
||||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.*;
|
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.*;
|
||||||
import static com.cf.imes.module.executor.enums.EsIndexEnum.ORDER_PLATE_MODEL;
|
import static com.cf.imes.module.executor.enums.EsIndexEnum.ORDER_PLATE_MODEL;
|
||||||
@@ -124,12 +116,6 @@ public class PlateServiceImpl implements PlateService {
|
|||||||
@Resource
|
@Resource
|
||||||
private SnowflakeIdWorker3rd idWorker;
|
private SnowflakeIdWorker3rd idWorker;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ElasticsearchClient elasticsearchClient;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private OrderInputProcessor orderInputProcessor;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IdentifierGenerator identifierGenerator;
|
private IdentifierGenerator identifierGenerator;
|
||||||
|
|
||||||
@@ -703,8 +689,6 @@ public class PlateServiceImpl implements PlateService {
|
|||||||
updateOrdersPlanPlateNumAndArea(orderPlanPlateNumAndAreaRespVOMap);
|
updateOrdersPlanPlateNumAndArea(orderPlanPlateNumAndAreaRespVOMap);
|
||||||
updateOrderGoodsPlanPlateNumAndArea(orderGoodsPlanPlateNumAndAreaRespVOMap);
|
updateOrderGoodsPlanPlateNumAndArea(orderGoodsPlanPlateNumAndAreaRespVOMap);
|
||||||
|
|
||||||
orderInputProcessor.batchSaveModel(orderPlateModelDOS);
|
|
||||||
|
|
||||||
return insertPlateRespVOS;
|
return insertPlateRespVOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -784,23 +768,7 @@ public class PlateServiceImpl implements PlateService {
|
|||||||
|
|
||||||
|
|
||||||
private List<OrderModelDO> buildRespByPlateIds(Collection<Long> plateIds, String index) {
|
private List<OrderModelDO> buildRespByPlateIds(Collection<Long> plateIds, String index) {
|
||||||
|
|
||||||
List<FieldValue> fieldValues = plateIds.stream().map(FieldValue::of).toList();
|
|
||||||
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
||||||
builder.index(index);
|
|
||||||
builder.query(q -> q.terms(b -> b.field(FIELD_PLATE_ID).terms(e -> e.value(fieldValues))));
|
|
||||||
builder.size(plateIds.size());
|
|
||||||
try {
|
|
||||||
SearchResponse<OrderModelDO> search = elasticsearchClient.search(builder.build(), OrderModelDO.class);
|
|
||||||
List<Hit<OrderModelDO>> hits = search.hits().hits();
|
|
||||||
if (CollUtil.isNotEmpty(hits)) {
|
|
||||||
return hits.stream().map(Hit::source).toList();
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e.getMessage());
|
|
||||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,17 +54,6 @@
|
|||||||
<artifactId>cf-spring-boot-starter-mybatis</artifactId>
|
<artifactId>cf-spring-boot-starter-mybatis</artifactId>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>jakarta.json</groupId>
|
<groupId>jakarta.json</groupId>
|
||||||
<artifactId>jakarta.json-api</artifactId>
|
<artifactId>jakarta.json-api</artifactId>
|
||||||
@@ -205,10 +194,6 @@
|
|||||||
<groupId>com.cf.imes</groupId>
|
<groupId>com.cf.imes</groupId>
|
||||||
<artifactId>cf-spring-boot-starter-mq</artifactId>
|
<artifactId>cf-spring-boot-starter-mq</artifactId>
|
||||||
</include>
|
</include>
|
||||||
<include>
|
|
||||||
<groupId>com.cf.imes</groupId>
|
|
||||||
<artifactId>cf-spring-boot-starter-elasticsearch</artifactId>
|
|
||||||
</include>
|
|
||||||
<include>
|
<include>
|
||||||
<groupId>com.cf.imes</groupId>
|
<groupId>com.cf.imes</groupId>
|
||||||
<artifactId>cf-module-prod-executor-api</artifactId>
|
<artifactId>cf-module-prod-executor-api</artifactId>
|
||||||
@@ -256,7 +241,6 @@
|
|||||||
cf-spring-boot-starter-security,
|
cf-spring-boot-starter-security,
|
||||||
cf-spring-boot-starter-web,
|
cf-spring-boot-starter-web,
|
||||||
cf-spring-boot-starter-mq,
|
cf-spring-boot-starter-mq,
|
||||||
cf-spring-boot-starter-elasticsearch,
|
|
||||||
cf-module-prod-executor-api,
|
cf-module-prod-executor-api,
|
||||||
cf-spring-boot-starter-biz-id,
|
cf-spring-boot-starter-biz-id,
|
||||||
cf-spring-boot-starter-test
|
cf-spring-boot-starter-test
|
||||||
|
|||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
package com.cf.imes.module.plan.dal.dataobject.ordermodel;
|
package com.cf.imes.module.plan.dal.dataobject.ordermodel;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
import com.cf.imes.module.plan.dal.elasticsearch.BasePosition;
|
import com.cf.imes.module.plan.dal.elasticsearch.BasePosition;
|
||||||
import com.cf.imes.module.plan.dal.elasticsearch.HoleDetail;
|
import com.cf.imes.module.plan.dal.elasticsearch.HoleDetail;
|
||||||
import com.cf.imes.module.plan.dal.elasticsearch.ModelDetail;
|
import com.cf.imes.module.plan.dal.elasticsearch.ModelDetail;
|
||||||
@@ -27,7 +26,7 @@ import java.util.Map;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class OrderModelDO extends ESDocument {
|
public class OrderModelDO {
|
||||||
|
|
||||||
@Schema(description = "订单id")
|
@Schema(description = "订单id")
|
||||||
private Long orderId;
|
private Long orderId;
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
package com.cf.imes.module.plan.dal.dataobject.ordermodel;
|
package com.cf.imes.module.plan.dal.dataobject.ordermodel;
|
||||||
|
|
||||||
|
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -15,7 +13,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class OrderPlateModel extends ESDocument {
|
public class OrderPlateModel {
|
||||||
|
|
||||||
@Schema(description = "订单id")
|
@Schema(description = "订单id")
|
||||||
private Long orderId;
|
private Long orderId;
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
package com.cf.imes.module.plan.dal.elasticsearch;
|
package com.cf.imes.module.plan.dal.elasticsearch;
|
||||||
|
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -12,7 +11,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class OrderPartsRemark extends ESDocument {
|
public class OrderPartsRemark {
|
||||||
|
|
||||||
@Schema(description = "配件 ID")
|
@Schema(description = "配件 ID")
|
||||||
private Long partsId;
|
private Long partsId;
|
||||||
|
|||||||
+219
-220
@@ -1,220 +1,219 @@
|
|||||||
package com.cf.imes.module.plan.service.order;
|
//package com.cf.imes.module.plan.service.order;
|
||||||
|
//
|
||||||
import cn.hutool.core.lang.Snowflake;
|
//import cn.hutool.core.lang.Snowflake;
|
||||||
import cn.hutool.core.text.CharSequenceUtil;
|
//import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
//import cn.hutool.core.util.IdUtil;
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
|
//import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
//import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||||
import co.elastic.clients.elasticsearch._types.ElasticsearchException;
|
//import co.elastic.clients.elasticsearch._types.ElasticsearchException;
|
||||||
import co.elastic.clients.elasticsearch.core.BulkRequest;
|
//import co.elastic.clients.elasticsearch.core.BulkRequest;
|
||||||
import co.elastic.clients.elasticsearch.core.BulkResponse;
|
//import co.elastic.clients.elasticsearch.core.BulkResponse;
|
||||||
import co.elastic.clients.elasticsearch.core.DeleteByQueryRequest;
|
//import co.elastic.clients.elasticsearch.core.DeleteByQueryRequest;
|
||||||
import co.elastic.clients.elasticsearch.core.DeleteByQueryResponse;
|
//import co.elastic.clients.elasticsearch.core.DeleteByQueryResponse;
|
||||||
import com.cf.imes.framework.common.exception.ServiceException;
|
//import com.cf.imes.framework.common.exception.ServiceException;
|
||||||
import com.cf.imes.framework.es.core.dal.ESDocument;
|
//import com.cf.imes.framework.es.core.dal.ESDocument;
|
||||||
import com.cf.imes.module.plan.dal.dataobject.ordermodel.OrderModelDO;
|
//import com.cf.imes.module.plan.dal.dataobject.ordermodel.OrderModelDO;
|
||||||
import com.cf.imes.module.plan.dal.elasticsearch.OrderPartsRemark;
|
//import com.cf.imes.module.plan.dal.elasticsearch.OrderPartsRemark;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
//import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
//import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
//import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.stereotype.Component;
|
||||||
|
//
|
||||||
import jakarta.annotation.Resource;
|
//import jakarta.annotation.Resource;
|
||||||
import java.io.IOException;
|
//import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
//import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
//import java.util.Date;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
|
//
|
||||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
|
//import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author Beal
|
// * @author Beal
|
||||||
* 订单入库处理器
|
// * 订单入库处理器
|
||||||
*/
|
// */
|
||||||
@Slf4j
|
//@Slf4j
|
||||||
@Component
|
//public class OrderInputProcessor {
|
||||||
public class OrderInputProcessor {
|
//
|
||||||
|
// @Resource
|
||||||
@Resource
|
// private ElasticsearchClient elasticsearchClient;
|
||||||
private ElasticsearchClient elasticsearchClient;
|
//
|
||||||
|
// @Resource
|
||||||
@Resource
|
// private ElasticsearchAsyncClient elasticsearchAsyncClient;
|
||||||
private ElasticsearchAsyncClient elasticsearchAsyncClient;
|
//
|
||||||
|
// private Snowflake snowflake = IdUtil.getSnowflake();
|
||||||
private Snowflake snowflake = IdUtil.getSnowflake();
|
//
|
||||||
|
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
//
|
||||||
|
// public static final String ORDER_PLATE_MODEL = "imes_order_plate_model";
|
||||||
public static final String ORDER_PLATE_MODEL = "imes_order_plate_model";
|
//
|
||||||
|
// public static final String ORDER_PARTS_REMARK_MODEL = "imes_order_parts_remark_model";
|
||||||
public static final String ORDER_PARTS_REMARK_MODEL = "imes_order_parts_remark_model";
|
//
|
||||||
|
// private static final String FIELD_ORDER_ID = "orderId";
|
||||||
private static final String FIELD_ORDER_ID = "orderId";
|
//
|
||||||
|
// private static final String FIELD_BATCH_ID = "batchId";
|
||||||
private static final String FIELD_BATCH_ID = "batchId";
|
//
|
||||||
|
// private static ObjectMapper objectMapper = new ObjectMapper();
|
||||||
private static ObjectMapper objectMapper = new ObjectMapper();
|
//
|
||||||
|
// static {
|
||||||
static {
|
// objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 跳过 null 字段
|
||||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 跳过 null 字段
|
// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
// objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
|
||||||
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
|
// objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
|
||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
/**
|
// * 保存订单造型数据
|
||||||
* 保存订单造型数据
|
// *
|
||||||
*
|
// * @param orderModelDOs
|
||||||
* @param orderModelDOs
|
// */
|
||||||
*/
|
// public void batchSaveModel(List<OrderModelDO> orderModelDOs) {
|
||||||
public void batchSaveModel(List<OrderModelDO> orderModelDOs) {
|
// try {
|
||||||
try {
|
// BulkResponse bulkResponse = bulkCreate(ORDER_PLATE_MODEL, orderModelDOs);
|
||||||
BulkResponse bulkResponse = bulkCreate(ORDER_PLATE_MODEL, orderModelDOs);
|
// boolean errors = bulkResponse.errors();
|
||||||
boolean errors = bulkResponse.errors();
|
// if (errors) {
|
||||||
if (errors) {
|
// log.error(bulkResponse.items().toString());
|
||||||
log.error(bulkResponse.items().toString());
|
// throw new ServiceException(500, "未知异常");
|
||||||
throw new ServiceException(500, "未知异常");
|
// }
|
||||||
}
|
// } catch (IOException | ElasticsearchException e) {
|
||||||
} catch (IOException | ElasticsearchException e) {
|
// log.error(e.getMessage());
|
||||||
log.error(e.getMessage());
|
// throw new RuntimeException(e);
|
||||||
throw new RuntimeException(e);
|
// }
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
/**
|
// * 异步保存订单造型数据
|
||||||
* 异步保存订单造型数据
|
// *
|
||||||
*
|
// * @param orderModelDOs
|
||||||
* @param orderModelDOs
|
// */
|
||||||
*/
|
// public void batchAsyncSaveModel(List<OrderModelDO> orderModelDOs) {
|
||||||
public void batchAsyncSaveModel(List<OrderModelDO> orderModelDOs) {
|
// try {
|
||||||
try {
|
// bulkAsyncCreate(ORDER_PLATE_MODEL, orderModelDOs);
|
||||||
bulkAsyncCreate(ORDER_PLATE_MODEL, orderModelDOs);
|
// } catch (IOException | ElasticsearchException e) {
|
||||||
} catch (IOException | ElasticsearchException e) {
|
// log.error(e.getMessage(), e);
|
||||||
log.error(e.getMessage(), e);
|
// throw new RuntimeException(e);
|
||||||
throw new RuntimeException(e);
|
// }
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
/**
|
// * 按批次删除订单OrderModels
|
||||||
* 按批次删除订单OrderModels
|
// *
|
||||||
*
|
// * @param orderId 订单id
|
||||||
* @param orderId 订单id
|
// * @param batchId 批次id
|
||||||
* @param batchId 批次id
|
// * @param index
|
||||||
* @param index
|
// */
|
||||||
*/
|
// public void deleteByOrderIdBatch(Long orderId, Long batchId, String index) {
|
||||||
public void deleteByOrderIdBatch(Long orderId, Long batchId, String index) {
|
// DeleteByQueryRequest.Builder builder = new DeleteByQueryRequest.Builder();
|
||||||
DeleteByQueryRequest.Builder builder = new DeleteByQueryRequest.Builder();
|
// builder.index(index);
|
||||||
builder.index(index);
|
// builder.query(q -> q.bool(b -> b
|
||||||
builder.query(q -> q.bool(b -> b
|
// .must(must -> must.term(t -> t.field(FIELD_ORDER_ID).value(orderId)))
|
||||||
.must(must -> must.term(t -> t.field(FIELD_ORDER_ID).value(orderId)))
|
// .must(must -> must.term(t -> t.field(FIELD_BATCH_ID).value(batchId)))
|
||||||
.must(must -> must.term(t -> t.field(FIELD_BATCH_ID).value(batchId)))
|
// ));
|
||||||
));
|
//
|
||||||
|
// try {
|
||||||
try {
|
// DeleteByQueryRequest deleteBuild = builder.build();
|
||||||
DeleteByQueryRequest deleteBuild = builder.build();
|
// // es刚插入有可能无法马上查询删除(默认1s的可见时间),线程每1s删除一次,再删除两次
|
||||||
// es刚插入有可能无法马上查询删除(默认1s的可见时间),线程每1s删除一次,再删除两次
|
// DeleteByQueryResponse response = elasticsearchClient.deleteByQuery(deleteBuild);
|
||||||
DeleteByQueryResponse response = elasticsearchClient.deleteByQuery(deleteBuild);
|
// if (response.deleted() == 0) {
|
||||||
if (response.deleted() == 0) {
|
// for (int i = 0; i < 2; i++) {
|
||||||
for (int i = 0; i < 2; i++) {
|
// response = elasticsearchClient.deleteByQuery(deleteBuild);
|
||||||
response = elasticsearchClient.deleteByQuery(deleteBuild);
|
// // 删除成功,不再继续
|
||||||
// 删除成功,不再继续
|
// if (response.deleted() > 0) {
|
||||||
if (response.deleted() > 0) {
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// try {
|
||||||
try {
|
// Thread.sleep(1000);
|
||||||
Thread.sleep(1000);
|
// } catch (InterruptedException e) {
|
||||||
} catch (InterruptedException e) {
|
// log.error("====================【线程中断异常】====================");
|
||||||
log.error("====================【线程中断异常】====================");
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// log.info("Deleted {} documents with orderId {}", response.deleted(), orderId);
|
||||||
log.info("Deleted {} documents with orderId {}", response.deleted(), orderId);
|
// } catch (IOException | ElasticsearchException e) {
|
||||||
} catch (IOException | ElasticsearchException e) {
|
// log.error("Error deleting documents with orderId {}: {}", orderId, e.getMessage());
|
||||||
log.error("Error deleting documents with orderId {}: {}", orderId, e.getMessage());
|
// throw new ServiceException(INTERNAL_SERVER_ERROR);
|
||||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
/**
|
// * 保存订单配件备注数据
|
||||||
* 保存订单配件备注数据
|
// *
|
||||||
*
|
// * @param orderPartsRemarks
|
||||||
* @param orderPartsRemarks
|
// */
|
||||||
*/
|
// public void batchSaveOrderPartsModel(List<OrderPartsRemark> orderPartsRemarks) {
|
||||||
public void batchSaveOrderPartsModel(List<OrderPartsRemark> orderPartsRemarks) {
|
// try {
|
||||||
try {
|
// BulkResponse bulkResponse = bulkCreate(ORDER_PARTS_REMARK_MODEL, orderPartsRemarks);
|
||||||
BulkResponse bulkResponse = bulkCreate(ORDER_PARTS_REMARK_MODEL, orderPartsRemarks);
|
// boolean errors = bulkResponse.errors();
|
||||||
boolean errors = bulkResponse.errors();
|
// if (errors) {
|
||||||
if (errors) {
|
// log.error(bulkResponse.items().toString());
|
||||||
log.error(bulkResponse.items().toString());
|
// throw new ServiceException(500, "未知异常");
|
||||||
throw new ServiceException(500, "未知异常");
|
// }
|
||||||
}
|
// } catch (IOException | ElasticsearchException e) {
|
||||||
} catch (IOException | ElasticsearchException e) {
|
// e.printStackTrace();
|
||||||
e.printStackTrace();
|
// log.error(e.getMessage());
|
||||||
log.error(e.getMessage());
|
// throw new RuntimeException(e);
|
||||||
throw new RuntimeException(e);
|
// }
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
}
|
//
|
||||||
|
// public <T> BulkResponse bulkCreate(String idxName, List<? extends ESDocument> documents) throws IOException, ElasticsearchException {
|
||||||
public <T> BulkResponse bulkCreate(String idxName, List<? extends ESDocument> documents) throws IOException, ElasticsearchException {
|
// BulkRequest.Builder br = new BulkRequest.Builder();
|
||||||
BulkRequest.Builder br = new BulkRequest.Builder();
|
// Date date = new Date();
|
||||||
Date date = new Date();
|
// documents.forEach(esDocument -> {
|
||||||
documents.forEach(esDocument -> {
|
// if (CharSequenceUtil.isBlank(esDocument.getId())) {
|
||||||
if (CharSequenceUtil.isBlank(esDocument.getId())) {
|
// esDocument.setId(snowflake.nextIdStr());
|
||||||
esDocument.setId(snowflake.nextIdStr());
|
// }
|
||||||
}
|
// esDocument.setCreateTime(simpleDateFormat.format(date));
|
||||||
esDocument.setCreateTime(simpleDateFormat.format(date));
|
//
|
||||||
|
// esDocument.setUpdateTime(simpleDateFormat.format(date));
|
||||||
esDocument.setUpdateTime(simpleDateFormat.format(date));
|
// br.operations(op -> op.index(idx -> idx
|
||||||
br.operations(op -> op.index(idx -> idx
|
// .index(idxName)
|
||||||
.index(idxName)
|
// .id(esDocument.getId())
|
||||||
.id(esDocument.getId())
|
// .document(esDocument)));
|
||||||
.document(esDocument)));
|
// });
|
||||||
});
|
// return elasticsearchClient.bulk(br.build());
|
||||||
return elasticsearchClient.bulk(br.build());
|
// }
|
||||||
}
|
//
|
||||||
|
// public void bulkAsyncCreate(String idxName, List<OrderModelDO> documents) throws IOException, ElasticsearchException {
|
||||||
public void bulkAsyncCreate(String idxName, List<OrderModelDO> documents) throws IOException, ElasticsearchException {
|
// BulkRequest.Builder br = new BulkRequest.Builder();
|
||||||
BulkRequest.Builder br = new BulkRequest.Builder();
|
// Date date = new Date();
|
||||||
Date date = new Date();
|
// // 深拷贝documents
|
||||||
// 深拷贝documents
|
// List<OrderModelDO> deepCopy = objectMapper.readValue(
|
||||||
List<OrderModelDO> deepCopy = objectMapper.readValue(
|
// objectMapper.writeValueAsString(documents),
|
||||||
objectMapper.writeValueAsString(documents),
|
// new TypeReference<>() {
|
||||||
new TypeReference<>() {
|
// }
|
||||||
}
|
// );
|
||||||
);
|
//
|
||||||
|
// deepCopy.forEach(esDocument -> {
|
||||||
deepCopy.forEach(esDocument -> {
|
// if (CharSequenceUtil.isBlank(esDocument.getId())) {
|
||||||
if (CharSequenceUtil.isBlank(esDocument.getId())) {
|
// esDocument.setId(snowflake.nextIdStr());
|
||||||
esDocument.setId(snowflake.nextIdStr());
|
// }
|
||||||
}
|
// esDocument.setCreateTime(simpleDateFormat.format(date));
|
||||||
esDocument.setCreateTime(simpleDateFormat.format(date));
|
//
|
||||||
|
// esDocument.setUpdateTime(simpleDateFormat.format(date));
|
||||||
esDocument.setUpdateTime(simpleDateFormat.format(date));
|
// br.operations(op -> op.index(idx -> idx
|
||||||
br.operations(op -> op.index(idx -> idx
|
// .index(idxName)
|
||||||
.index(idxName)
|
// .id(esDocument.getId())
|
||||||
.id(esDocument.getId())
|
// .document(esDocument)));
|
||||||
.document(esDocument)));
|
// });
|
||||||
});
|
//
|
||||||
|
// elasticsearchAsyncClient.bulk(br.build())
|
||||||
elasticsearchAsyncClient.bulk(br.build())
|
// .whenComplete((response, exception) -> {
|
||||||
.whenComplete((response, exception) -> {
|
// deepCopy.clear();
|
||||||
deepCopy.clear();
|
//
|
||||||
|
// if (exception != null) {
|
||||||
if (exception != null) {
|
// log.error("ES bulk async failed for index: {}, size: {}, error: {}",
|
||||||
log.error("ES bulk async failed for index: {}, size: {}, error: {}",
|
// idxName, documents.size(), exception.getMessage(), exception);
|
||||||
idxName, documents.size(), exception.getMessage(), exception);
|
// } else if (response.errors()) {
|
||||||
} else if (response.errors()) {
|
// log.warn("ES bulk async partially failed for index: {}, size: {}",
|
||||||
log.warn("ES bulk async partially failed for index: {}, size: {}",
|
// idxName, documents.size());
|
||||||
idxName, documents.size());
|
// } else {
|
||||||
} else {
|
// log.debug("ES bulk async success for index: {}, size: {}",
|
||||||
log.debug("ES bulk async success for index: {}, size: {}",
|
// idxName, documents.size());
|
||||||
idxName, documents.size());
|
// }
|
||||||
}
|
// });
|
||||||
});
|
// }
|
||||||
}
|
//}
|
||||||
}
|
|
||||||
|
|||||||
@@ -77,18 +77,6 @@
|
|||||||
<artifactId>cf-spring-boot-starter-redis</artifactId>
|
<artifactId>cf-spring-boot-starter-redis</artifactId>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>jakarta.json</groupId>
|
<groupId>jakarta.json</groupId>
|
||||||
<artifactId>jakarta.json-api</artifactId>
|
<artifactId>jakarta.json-api</artifactId>
|
||||||
@@ -260,10 +248,6 @@
|
|||||||
<groupId>com.cf.imes</groupId>
|
<groupId>com.cf.imes</groupId>
|
||||||
<artifactId>cf-spring-boot-starter-biz-organ</artifactId>
|
<artifactId>cf-spring-boot-starter-biz-organ</artifactId>
|
||||||
</include>
|
</include>
|
||||||
<include>
|
|
||||||
<groupId>com.cf.imes</groupId>
|
|
||||||
<artifactId>cf-spring-boot-starter-elasticsearch</artifactId>
|
|
||||||
</include>
|
|
||||||
<include>
|
<include>
|
||||||
<groupId>com.cf.imes</groupId>
|
<groupId>com.cf.imes</groupId>
|
||||||
<artifactId>cf-spring-boot-starter-env</artifactId>
|
<artifactId>cf-spring-boot-starter-env</artifactId>
|
||||||
|
|||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
package com.cf.imes.module.system.controller.admin.datasource.vo;
|
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -14,7 +13,7 @@ import java.util.List;
|
|||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class MachineDataSourceDO extends ESDocument {
|
public class MachineDataSourceDO {
|
||||||
|
|
||||||
|
|
||||||
@Schema(description = "机台ID")
|
@Schema(description = "机台ID")
|
||||||
|
|||||||
+2
-4
@@ -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.CommonResult;
|
||||||
import com.cf.imes.framework.common.pojo.PageResult;
|
import com.cf.imes.framework.common.pojo.PageResult;
|
||||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
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.framework.operatelog.core.annotations.OperateLog;
|
||||||
import com.cf.imes.module.system.controller.admin.machine.vo.*;
|
import com.cf.imes.module.system.controller.admin.machine.vo.*;
|
||||||
import com.cf.imes.module.system.dal.dataobject.machine.MachineDO;
|
import com.cf.imes.module.system.dal.dataobject.machine.MachineDO;
|
||||||
@@ -41,7 +39,7 @@ public class MachineController {
|
|||||||
@Operation(summary = "创建机台")
|
@Operation(summary = "创建机台")
|
||||||
@PreAuthorize("@ss.hasAnyPermissions('system:machine:create','system:machine:duplet')")
|
@PreAuthorize("@ss.hasAnyPermissions('system:machine:create','system:machine:duplet')")
|
||||||
@OperateLog(logArgs = false,type = CREATE )
|
@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));
|
return success(machineService.createCutting(createReqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +47,7 @@ public class MachineController {
|
|||||||
@Operation(summary = "更新机台")
|
@Operation(summary = "更新机台")
|
||||||
@PreAuthorize("@ss.hasAnyPermissions('system:machine:update','system:machine:submit')")
|
@PreAuthorize("@ss.hasAnyPermissions('system:machine:update','system:machine:submit')")
|
||||||
@OperateLog(logArgs = false,type = UPDATE)
|
@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);
|
machineService.updateCutting(updateReqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -1,8 +1,6 @@
|
|||||||
package com.cf.imes.module.system.controller.admin.machine.vo;
|
package com.cf.imes.module.system.controller.admin.machine.vo;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
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 com.cf.imes.module.system.validation.machine.MachineTypeValid;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -19,7 +17,7 @@ import jakarta.validation.constraints.Size;
|
|||||||
public class CuttingSaveReqVO {
|
public class CuttingSaveReqVO {
|
||||||
|
|
||||||
@Schema(description = "主键", example = "14092")
|
@Schema(description = "主键", example = "14092")
|
||||||
@NotNull(groups = UpdateGroup.class, message = "主键不能空")
|
@NotNull(message = "主键不能空")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||||
@@ -43,7 +41,7 @@ public class CuttingSaveReqVO {
|
|||||||
|
|
||||||
|
|
||||||
@Schema(description = "机台的型号-机台的ID")
|
@Schema(description = "机台的型号-机台的ID")
|
||||||
@NotNull(message = "机台型号不能为空",groups = CreateGroup.class)
|
@NotNull(message = "机台型号不能为空")
|
||||||
private Long machineId;
|
private Long machineId;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
package com.cf.imes.module.system.controller.admin.machine.vo;
|
package com.cf.imes.module.system.controller.admin.machine.vo;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.cf.imes.framework.es.core.valid.UpdateGroup;
|
|
||||||
import com.cf.imes.module.system.validation.machine.MachineTypeValid;
|
import com.cf.imes.module.system.validation.machine.MachineTypeValid;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -16,7 +15,7 @@ import jakarta.validation.constraints.Size;
|
|||||||
@Data
|
@Data
|
||||||
public class CuttingTemplateSaveReqVO {
|
public class CuttingTemplateSaveReqVO {
|
||||||
@Schema(description = "主键", example = "14092")
|
@Schema(description = "主键", example = "14092")
|
||||||
@NotNull(groups = UpdateGroup.class, message = "主键不能空")
|
@NotNull(message = "主键不能空")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
package com.cf.imes.module.system.controller.admin.machine.vo;
|
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 com.cf.imes.module.system.dal.dataobject.machine.DrillSettingDO;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -17,7 +16,7 @@ import jakarta.validation.constraints.NotNull;
|
|||||||
public class DrillSaveReqVO {
|
public class DrillSaveReqVO {
|
||||||
|
|
||||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "14092")
|
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "14092")
|
||||||
@NotNull(groups = UpdateGroup.class, message = "主键不能空")
|
@NotNull(message = "主键不能空")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
package com.cf.imes.module.system.controller.admin.machine.vo;
|
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 com.cf.imes.module.system.dal.dataobject.machinetemplate.DrillTemplateMachineDO;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -16,7 +15,7 @@ import jakarta.validation.constraints.NotNull;
|
|||||||
public class DrillTemplateSaveReqVO {
|
public class DrillTemplateSaveReqVO {
|
||||||
|
|
||||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "14092")
|
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "14092")
|
||||||
@NotNull(groups = UpdateGroup.class, message = "主键不能空")
|
@NotNull(message = "主键不能空")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||||
|
|||||||
-8
@@ -1,13 +1,9 @@
|
|||||||
package com.cf.imes.module.system.controller.admin.oauth2;
|
package com.cf.imes.module.system.controller.admin.oauth2;
|
||||||
|
|
||||||
import cn.hutool.json.JSON;
|
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.CommonResult;
|
||||||
import com.cf.imes.framework.common.pojo.PageResult;
|
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.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.OAuth2ClientPageReqVO;
|
||||||
import com.cf.imes.module.system.controller.admin.oauth2.vo.client.OAuth2ClientRespVO;
|
import com.cf.imes.module.system.controller.admin.oauth2.vo.client.OAuth2ClientRespVO;
|
||||||
import com.cf.imes.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO;
|
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 org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.annotation.security.PermitAll;
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||||
@@ -35,9 +30,6 @@ public class OAuth2ClientController {
|
|||||||
@Resource
|
@Resource
|
||||||
private OAuth2ClientService oAuth2ClientService;
|
private OAuth2ClientService oAuth2ClientService;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ESDocumentService esDocumentService;
|
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建 OAuth2 客户端")
|
@Operation(summary = "创建 OAuth2 客户端")
|
||||||
|
|||||||
-2
@@ -2,12 +2,10 @@ package com.cf.imes.module.system.controller.admin.setting.vo;
|
|||||||
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.cf.imes.framework.es.core.valid.UpdateGroup;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
@Schema(description = "打包配置信息")
|
@Schema(description = "打包配置信息")
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
package com.cf.imes.module.system.dal.dataobject.labelelementproperty;
|
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@@ -11,7 +10,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Data
|
@Data
|
||||||
@Schema(description = "标签元素属性索引")
|
@Schema(description = "标签元素属性索引")
|
||||||
public class LabelElementPropertyDO extends ESDocument {
|
public class LabelElementPropertyDO {
|
||||||
@Schema(description = "标签元素id")
|
@Schema(description = "标签元素id")
|
||||||
private Long elementId;
|
private Long elementId;
|
||||||
private String extra;
|
private String extra;
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
package com.cf.imes.module.system.dal.dataobject.machine;
|
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@@ -11,7 +10,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Data
|
@Data
|
||||||
public class CuttingSettingDO extends ESDocument {
|
public class CuttingSettingDO {
|
||||||
|
|
||||||
@Schema(description = "机台id")
|
@Schema(description = "机台id")
|
||||||
private Long machineId;
|
private Long machineId;
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
package com.cf.imes.module.system.dal.dataobject.machine;
|
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -14,7 +13,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Builder
|
@Builder
|
||||||
@Data
|
@Data
|
||||||
public class DrillSettingDO extends ESDocument {
|
public class DrillSettingDO {
|
||||||
|
|
||||||
@Schema(description = "机台id")
|
@Schema(description = "机台id")
|
||||||
private Long machineId;
|
private Long machineId;
|
||||||
|
|||||||
+1
-4
@@ -1,10 +1,7 @@
|
|||||||
package com.cf.imes.module.system.dal.dataobject.machinetemplate;
|
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 com.cf.imes.module.system.dal.dataobject.machine.CuttingSettingDO;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@@ -15,7 +12,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Schema(description = "管理理后台 - 开料机台模板新增/修改 Request VO")
|
@Schema(description = "管理理后台 - 开料机台模板新增/修改 Request VO")
|
||||||
public class CuttingTemplateMachineDO extends ESDocument {
|
public class CuttingTemplateMachineDO {
|
||||||
|
|
||||||
@Schema(description = "开料机台模板id")
|
@Schema(description = "开料机台模板id")
|
||||||
private Long templateId;
|
private Long templateId;
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
package com.cf.imes.module.system.dal.dataobject.machinetemplate;
|
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -14,7 +13,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Builder
|
@Builder
|
||||||
@Data
|
@Data
|
||||||
public class DrillTemplateMachineDO extends ESDocument {
|
public class DrillTemplateMachineDO {
|
||||||
|
|
||||||
@Schema(description = "机台模板id")
|
@Schema(description = "机台模板id")
|
||||||
private Long templateId;
|
private Long templateId;
|
||||||
|
|||||||
+1
-70
@@ -1,13 +1,8 @@
|
|||||||
package com.cf.imes.module.system.service.datasource;
|
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.enums.MachineTypeEnum;
|
||||||
import com.cf.imes.framework.common.exception.ServiceException;
|
import com.cf.imes.framework.common.exception.ServiceException;
|
||||||
import com.cf.imes.framework.common.pojo.PageResult;
|
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.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import com.cf.imes.module.executor.api.plan.OrderPlanApi;
|
import com.cf.imes.module.executor.api.plan.OrderPlanApi;
|
||||||
import com.cf.imes.module.system.controller.admin.datasource.dataQuery.DataQuery;
|
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 org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
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.framework.common.util.object.BeanUtils.toBean;
|
||||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.DATA_SOURCE_NOT_EXISTS;
|
import static com.cf.imes.module.system.enums.ErrorCodeConstants.DATA_SOURCE_NOT_EXISTS;
|
||||||
|
|
||||||
@@ -51,12 +43,6 @@ public class DataSourceServiceImpl implements DataSourceService {
|
|||||||
@Resource
|
@Resource
|
||||||
private MachineMapper machineMapper;
|
private MachineMapper machineMapper;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ESDocumentService esDocumentService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ElasticsearchClient elasticsearchClient;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private OrderPlanApi orderPlanApi;
|
private OrderPlanApi orderPlanApi;
|
||||||
|
|
||||||
@@ -698,19 +684,6 @@ public class DataSourceServiceImpl implements DataSourceService {
|
|||||||
|
|
||||||
|
|
||||||
public void batchSaveMachineDataSource(List<MachineDataSourceDO> machineDataSourceDOS) {
|
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,查询对应的数据源字段
|
// 根据机台ID和父级ID,查询对应的数据源字段
|
||||||
private List<MachineDataSourceDO> buildMachineDataSourceByParentSourceId(Long machineId,Integer parentSourceId, String index) {
|
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<>();
|
return new ArrayList<>();
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e.getMessage());
|
|
||||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 根据机台ID查询机台对应的数据源字段信息
|
// 根据机台ID查询机台对应的数据源字段信息
|
||||||
private List<MachineDataSourceDO> buildMachineDataSourceByMachineId(Long machineId, String index) {
|
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<>();
|
return new ArrayList<>();
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e.getMessage());
|
|
||||||
throw new ServiceException(INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 根据机台ID删除对应的数据源ES信息
|
// 根据机台ID删除对应的数据源ES信息
|
||||||
public void deleteByMachineId(Long machineId, String index) {
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-37
@@ -1,20 +1,10 @@
|
|||||||
package com.cf.imes.module.system.service.machine;
|
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.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.controller.admin.machine.vo.SettingPageReqVO;
|
||||||
import com.cf.imes.module.system.dal.dataobject.machine.MachineDO;
|
import com.cf.imes.module.system.dal.dataobject.machine.MachineDO;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,34 +13,11 @@ import java.util.List;
|
|||||||
@Service
|
@Service
|
||||||
public class MachineSettingServiceImpl implements MachineSettingService {
|
public class MachineSettingServiceImpl implements MachineSettingService {
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ElasticsearchClient elasticsearchClient;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ESDocumentService esDocumentService;
|
|
||||||
|
|
||||||
public final static String MACHINE_SETTING = "user_machine";
|
public final static String MACHINE_SETTING = "user_machine";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<MachineDO> page(SettingPageReqVO pageReqVO) throws IOException {
|
public PageResult<MachineDO> page(SettingPageReqVO pageReqVO) throws IOException {
|
||||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
return PageResult.empty();
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,16 +37,16 @@ public class MachineSettingServiceImpl implements MachineSettingService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean delete(String id) throws IOException {
|
public Boolean delete(String id) throws IOException {
|
||||||
return esDocumentService.deleteById(MACHINE_SETTING, id).booleanValue();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean batchDelete(List<String> ids) throws Exception {
|
public Boolean batchDelete(List<String> ids) throws Exception {
|
||||||
return !esDocumentService.bulkDeleteByIds(MACHINE_SETTING, ids).errors();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MachineDO get(String id) throws IOException {
|
public MachineDO get(String id) throws IOException {
|
||||||
return esDocumentService.getById(MACHINE_SETTING, id, MachineDO.class);
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-9
@@ -1,7 +1,6 @@
|
|||||||
package com.cf.imes.module.system.service.machine;
|
package com.cf.imes.module.system.service.machine;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||||
import com.cf.imes.framework.common.enums.MachineTypeEnum;
|
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.machinetemplate.MachineTemplateLimitDO;
|
||||||
import com.cf.imes.module.system.dal.dataobject.organ.OrganizationDO;
|
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.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.MachineTemplateLimitMapper;
|
||||||
import com.cf.imes.module.system.dal.mysql.machinetemplate.MachineTemplateMapper;
|
import com.cf.imes.module.system.dal.mysql.machinetemplate.MachineTemplateMapper;
|
||||||
import com.cf.imes.module.system.dal.mysql.organ.OrganMapper;
|
import com.cf.imes.module.system.dal.mysql.organ.OrganMapper;
|
||||||
@@ -45,13 +43,6 @@ import static com.cf.imes.module.system.enums.ErrorCodeConstants.*;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class MachineTemplateServiceImpl implements MachineTemplateService {
|
public class MachineTemplateServiceImpl implements MachineTemplateService {
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private UserMachineMapper userMachineMapper;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ElasticsearchClient elasticsearchClient;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private MachineTemplateMapper machineTemplateMapper;
|
private MachineTemplateMapper machineTemplateMapper;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user