处理ES字段的mapping映射

This commit is contained in:
yangsb
2024-04-11 18:02:31 +08:00
parent c7810570db
commit a452ecc7a5
5 changed files with 62 additions and 36 deletions
@@ -6,8 +6,6 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;
import java.util.Date;
import static com.cf.imes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static com.cf.imes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
import static com.cf.imes.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT; import static com.cf.imes.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT;
@@ -37,8 +37,7 @@ public class ESDocumentServiceImpl implements ESDocumentService {
private Snowflake snowflake = IdUtil.getSnowflake(); private Snowflake snowflake = IdUtil.getSnowflake();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ZoneId utc = ZoneId.of("UTC");
public ESDocumentServiceImpl(ElasticsearchClient elasticsearchClient, ElasticsearchAsyncClient elasticsearchAsyncClient) { public ESDocumentServiceImpl(ElasticsearchClient elasticsearchClient, ElasticsearchAsyncClient elasticsearchAsyncClient) {
this.elasticsearchClient = elasticsearchClient; this.elasticsearchClient = elasticsearchClient;
@@ -47,13 +46,13 @@ public class ESDocumentServiceImpl implements ESDocumentService {
@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 {
LocalDateTime now = LocalDateTime.now(); Date date = new Date();
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
document.setCreator(loginUser.getId()); document.setCreator(loginUser.getId());
document.setUpdater(loginUser.getId()); document.setUpdater(loginUser.getId());
document.setOrganId(loginUser.getOrganId()); document.setOrganId(loginUser.getOrganId());
document.setCreateTime((now.atZone(utc).format(dateTimeFormatter))); document.setCreateTime(simpleDateFormat.format(date));
document.setUpdateTime((now.atZone(utc).format(dateTimeFormatter))); document.setUpdateTime(simpleDateFormat.format(date));
if (StrUtil.isBlank(document.getId())) { if (StrUtil.isBlank(document.getId())) {
document.setId(snowflake.nextIdStr()); document.setId(snowflake.nextIdStr());
} }
@@ -73,12 +72,12 @@ public class ESDocumentServiceImpl implements ESDocumentService {
@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();
LocalDateTime now = LocalDateTime.now(); Date date = new Date();
document.setCreator(loginUser.getId()); document.setCreator(loginUser.getId());
document.setUpdater(loginUser.getId()); document.setUpdater(loginUser.getId());
document.setOrganId(loginUser.getOrganId()); document.setOrganId(loginUser.getOrganId());
document.setCreateTime((now.atZone(utc).format(dateTimeFormatter))); document.setCreateTime(simpleDateFormat.format(date));
document.setUpdateTime((now.atZone(utc).format(dateTimeFormatter))); 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 (StrUtil.isBlank(idxId)) { if (StrUtil.isBlank(idxId)) {
@@ -144,9 +143,10 @@ public class ESDocumentServiceImpl implements ESDocumentService {
esDocument.setId(snowflake.nextIdStr()); esDocument.setId(snowflake.nextIdStr());
} }
esDocument.setCreator(loginUser.getId()); esDocument.setCreator(loginUser.getId());
esDocument.setCreateTime(now.atZone(utc).format(dateTimeFormatter)); esDocument.setCreateTime(simpleDateFormat.format(date));
esDocument.setUpdater(loginUser.getId()); esDocument.setUpdater(loginUser.getId());
esDocument.setUpdateTime(now.atZone(utc).format(dateTimeFormatter));
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().toString()) .id(esDocument.getId().toString())
@@ -15,6 +15,7 @@ import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import javax.validation.*; import javax.validation.*;
import javax.servlet.http.*; import javax.servlet.http.*;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.io.IOException; import java.io.IOException;
@@ -163,6 +164,24 @@ public class PlanController {
iBoardProdInfo.setBrand("xxx"); iBoardProdInfo.setBrand("xxx");
iBoardProdInfo.setSpec("xxxx"); iBoardProdInfo.setSpec("xxxx");
iBoardProdInfo.setGoodType(1); iBoardProdInfo.setGoodType(1);
iBoardProdInfo.setWidth((float) 0.0);
iBoardProdInfo.setHeight((float) 0.0);
iBoardProdInfo.setThickness(5.0);
iBoardProdInfo.setSplitWidth(1);
iBoardProdInfo.setSplitHeight(1);
iBoardProdInfo.setSplitThickness(2);
iBoardProdInfo.setSealUp((float) 0.0);
iBoardProdInfo.setSealLeft((float) 0.0);
iBoardProdInfo.setSealRight((float) 0.0);
iBoardProdInfo.setSealDown((float) 0.0);
iBoardProdInfo.setTexture(1);
iBoardProdInfo.setOpenDoorType(1);
iBoardProdInfo.setTypographicFace(1);
detail.setMultiNum(23);
detail.setDepth(10.0);
detail.setHeight(9.0);
detail.getContourDetail().forEach(e->e.setTypographicFace(1));
detail.getSideModelDetail().forEach(e->e.setTypographicFace(1));
details.add(detail); details.add(detail);
} }
orderInputProcessor.input(details, 999L); orderInputProcessor.input(details, 999L);
@@ -1,7 +1,9 @@
package com.cf.imes.module.executor.service.order; package com.cf.imes.module.executor.service.order;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import co.elastic.clients.elasticsearch.core.BulkResponse;
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.util.json.JsonUtils; import com.cf.imes.framework.common.util.json.JsonUtils;
import com.cf.imes.framework.es.core.service.ESDocumentService; import com.cf.imes.framework.es.core.service.ESDocumentService;
import com.cf.imes.framework.mybatis.core.generator.SnowFlakeGenerator; import com.cf.imes.framework.mybatis.core.generator.SnowFlakeGenerator;
@@ -199,20 +201,20 @@ public class OrderInputProcessor {
.plateNo(e.getIBoardProdInfo().getPlateNo()) .plateNo(e.getIBoardProdInfo().getPlateNo())
//.type(e.getIBoardProdInfo().) //.type(e.getIBoardProdInfo().)
.goodsId(rawGoodsDO.getRawGoodsId()) .goodsId(rawGoodsDO.getRawGoodsId())
.height(e.getIBoardProdInfo().getHeight()) .height(new BigDecimal(e.getIBoardProdInfo().getHeight()))
.width(e.getIBoardProdInfo().getWidth()) .width(new BigDecimal(e.getIBoardProdInfo().getWidth()))
.thickness(new BigDecimal(e.getIBoardProdInfo().getThickness().toString())) .thickness(new BigDecimal(e.getIBoardProdInfo().getThickness().toString()))
.splitHeight(new BigDecimal(e.getIBoardProdInfo().getSplitHeight().toString())) .splitHeight(new BigDecimal(e.getIBoardProdInfo().getSplitHeight()))
.splitWidth(new BigDecimal(e.getIBoardProdInfo().getSplitWidth().toString())) .splitWidth(new BigDecimal(e.getIBoardProdInfo().getSplitWidth()))
.splitThickness(new BigDecimal(e.getIBoardProdInfo().getThickness().toString())) .splitThickness(new BigDecimal(e.getIBoardProdInfo().getThickness().toString()))
.sealLeft(e.getIBoardProdInfo().getSealLeft()) .sealLeft(new BigDecimal(e.getIBoardProdInfo().getSealLeft()))
.sealRight(e.getIBoardProdInfo().getSealRight()) .sealRight(new BigDecimal(e.getIBoardProdInfo().getSealRight()))
.sealUp(e.getIBoardProdInfo().getSealUp()) .sealUp(new BigDecimal(e.getIBoardProdInfo().getSealUp()))
.sealDown(e.getIBoardProdInfo().getSealDown()) .sealDown(new BigDecimal(e.getIBoardProdInfo().getSealDown()))
.area(e.getIBoardProdInfo().getWidth().multiply(e.getIBoardProdInfo().getHeight())) .area(new BigDecimal( String.valueOf(e.getIBoardProdInfo().getWidth())).multiply( new BigDecimal(e.getIBoardProdInfo().getHeight())))
.texture(e.getIBoardProdInfo().getTexture()) .texture(e.getIBoardProdInfo().getTexture())
.type(0) .type(0)
.holeFace(e.getHoleDetail().getFaceType()) .holeFace(0)
.holeArrange(0) .holeArrange(0)
.unregularPointCount(0) .unregularPointCount(0)
.frontHoleCount(0) .frontHoleCount(0)
@@ -309,7 +311,12 @@ public class OrderInputProcessor {
*/ */
public void batchSaveModel(List<OrderModelDO> orderModelDOs) { public void batchSaveModel(List<OrderModelDO> orderModelDOs) {
try { try {
esDocumentService.bulkCreate(ORDER_PLATE_MODEL, orderModelDOs); BulkResponse bulkResponse = esDocumentService.bulkCreate(ORDER_PLATE_MODEL, orderModelDOs);
boolean errors = bulkResponse.errors();
if(errors) {
log.error(bulkResponse.items().toString());
throw new ServiceException(500,"未知异常");
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error(e.getMessage()); log.error(e.getMessage());
+15 -13
View File
@@ -5,7 +5,7 @@
"contourDetail": { "contourDetail": {
"properties": { "properties": {
"depth": { "depth": {
"type": "short" "type": "integer"
}, },
"knifeName": { "knifeName": {
"type": "keyword" "type": "keyword"
@@ -28,7 +28,7 @@
"type": "float" "type": "float"
}, },
"faceType": { "faceType": {
"type": "short" "type": "integer"
}, },
"name": { "name": {
"type": "keyword" "type": "keyword"
@@ -53,7 +53,7 @@
"type": "float" "type": "float"
}, },
"dir": { "dir": {
"type": "short" "type": "integer"
}, },
"holes": { "holes": {
"properties": { "properties": {
@@ -73,7 +73,7 @@
} }
}, },
"knifeRadius": { "knifeRadius": {
"type": "short" "type": "integer"
}, },
"outline": { "outline": {
"properties": { "properties": {
@@ -93,7 +93,7 @@
} }
}, },
"thickness": { "thickness": {
"type": "short" "type": "integer"
} }
} }
}, },
@@ -123,12 +123,13 @@
} }
}, },
"typographicFace": { "typographicFace": {
"type": "short" "type": "integer"
} }
} }
}, },
"createTime": { "createTime": {
"type": "date" "type": "date",
"format": "strict_date_optional_time||yyyy-MM-dd HH:mm:ss||epoch_millis"
}, },
"creator": { "creator": {
"type": "long" "type": "long"
@@ -145,13 +146,13 @@
"type": "float" "type": "float"
}, },
"faceType": { "faceType": {
"type": "short" "type": "integer"
}, },
"holeId": { "holeId": {
"type": "long" "type": "long"
}, },
"holeType": { "holeType": {
"type": "short" "type": "integer"
}, },
"pointX": { "pointX": {
"type": "float" "type": "float"
@@ -226,13 +227,13 @@
"type": "float" "type": "float"
}, },
"faceType": { "faceType": {
"type": "short" "type": "integer"
}, },
"holeId": { "holeId": {
"type": "long" "type": "long"
}, },
"holeType": { "holeType": {
"type": "short" "type": "integer"
}, },
"pointX": { "pointX": {
"type": "float" "type": "float"
@@ -280,7 +281,7 @@
"type": "float" "type": "float"
}, },
"faceType": { "faceType": {
"type": "short" "type": "integer"
}, },
"name": { "name": {
"type": "keyword" "type": "keyword"
@@ -380,7 +381,8 @@
} }
}, },
"updateTime": { "updateTime": {
"type": "date" "type": "date",
"format": "strict_date_optional_time||yyyy-MM-dd HH:mm:ss||epoch_millis"
}, },
"updater": { "updater": {
"type": "long" "type": "long"