Bladeren bron

新增 参数

lianghanqiang 4 jaren geleden
bovenliggende
commit
b2d1ffce34

+ 1 - 1
framework/pom.xml

@@ -401,7 +401,7 @@
         <dependency>
             <groupId>com.huaweicloud</groupId>
             <artifactId>esdk-obs-java</artifactId>
-            <version>[3.21.4,)</version>
+            <version>3.21.4</version>
         </dependency>
 
         <!--  易宝支付SDK   -->

+ 353 - 121
framework/src/main/java/cn/lili/common/elasticsearch/BaseElasticsearchService.java

@@ -105,6 +105,358 @@ public abstract class BaseElasticsearchService {
 
     public void createMapping(String index) throws Exception {
         String source =
+                "{\n" +
+                        "    \"properties\":{\n" +
+                        "        \"_class\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"attrList\":{\n" +
+                        "            \"type\":\"nested\",\n" +
+                        "            \"properties\":{\n" +
+                        "                \"name\":{\n" +
+                        "                    \"type\":\"keyword\"\n" +
+                        "                },\n" +
+                        "                \"type\":{\n" +
+                        "                    \"type\":\"long\"\n" +
+                        "                },\n" +
+                        "                \"value\":{\n" +
+                        "                    \"type\":\"keyword\"\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"brandId\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fielddata\":true,\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"buyCount\":{\n" +
+                        "            \"type\":\"long\"\n" +
+                        "        },\n" +
+                        "        \"releaseTime\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fielddata\":true,\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"categoryPath\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fielddata\":true,\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"commentNum\":{\n" +
+                        "            \"type\":\"long\"\n" +
+                        "        },\n" +
+                        "        \"goodsId\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"goodsName\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fielddata\":true,\n" +
+                        "            \"analyzer\":\"ik_max_word\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"grade\":{\n" +
+                        "            \"type\":\"float\"\n" +
+                        "        },\n" +
+                        "        \"highPraiseNum\":{\n" +
+                        "            \"type\":\"long\"\n" +
+                        "        },\n" +
+                        "        \"id\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"intro\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"isAuth\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"marketEnable\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fielddata\":true,\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"mobileIntro\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"point\":{\n" +
+                        "            \"type\":\"long\"\n" +
+                        "        },\n" +
+                        "        \"price\":{\n" +
+                        "            \"type\":\"float\"\n" +
+                        "        },\n" +
+                        "        \"salesModel\":{\n" +
+                        "            \"type\":\"keyword\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"recommend\":{\n" +
+                        "            \"type\":\"boolean\"\n" +
+                        "        },\n" +
+                        "        \"selfOperated\":{\n" +
+                        "            \"type\":\"boolean\"\n" +
+                        "        },\n" +
+                        "        \"sellerId\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"sellerName\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fielddata\":true,\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"shopCategoryPath\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fielddata\":true,\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"sn\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"productEnterprise\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"productBitchNo\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"expireDate\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        },\n" +
+                        "        \"thumbnail\":{\n" +
+                        "            \"type\":\"text\",\n" +
+                        "            \"fields\":{\n" +
+                        "                \"keyword\":{\n" +
+                        "                    \"type\":\"keyword\",\n" +
+                        "                    \"ignore_above\":256\n" +
+                        "                }\n" +
+                        "            }\n" +
+                        "        }\n" +
+                        "    }\n" +
+                        "}";
+
+        PutMappingRequest request = new PutMappingRequest(index)
+                        .source(source, XContentType.JSON);
+//       AcknowledgedResponse putMappingResponse = client.indices().putMapping(request,
+//               RequestOptions.DEFAULT);
+//
+//       boolean acknowledged = putMappingResponse.isAcknowledged();
+//       if (acknowledged) {
+//           log.error("Succeed to put mapping");
+//       }
+        CountDownLatch latch = new CountDownLatch(1);
+        AtomicReference response = new AtomicReference<AcknowledgedResponse>();
+        client.indices().putMappingAsync(
+                request,
+                RequestOptions.DEFAULT,
+                new ActionListener<AcknowledgedResponse>() {
+                    @Override
+                    public void onResponse(AcknowledgedResponse r) {
+                        response.set(r);
+                        latch.countDown();
+                    }
+
+                    @Override
+                    public void onFailure(Exception e) {
+                        latch.countDown();
+                    }
+                });
+        latch.await(10, TimeUnit.SECONDS);
+        Assertions.assertThat(((AcknowledgedResponse) response.get()).isAcknowledged()).isTrue();
+    }
+
+    /**
+     * Description: 判断某个index是否存在
+     *
+     * @param index index名
+     * @return boolean
+     * @author fanxb
+     * @date 2019/7/24 14:57
+     */
+    public boolean indexExist(String index) {
+        try {
+            GetIndexRequest request = new GetIndexRequest(index);
+            request.local(false);
+            request.humanReadable(true);
+            request.includeDefaults(false);
+            return client.indices().exists(request, RequestOptions.DEFAULT);
+        } catch (Exception e) {
+            throw new ElasticsearchException("获取索引 {" + index + "} 是否存在失败:" + e.getMessage());
+        }
+    }
+
+    /**
+     * delete elasticsearch index
+     *
+     * @param index elasticsearch index name
+     * @author fxbin
+     */
+    protected void deleteIndexRequest(String index) {
+        DeleteIndexRequest deleteIndexRequest = buildDeleteIndexRequest(index);
+        try {
+            client.indices().delete(deleteIndexRequest, COMMON_OPTIONS);
+        } catch (IOException e) {
+            throw new ElasticsearchException("删除索引 {" + index + "} 失败:" + e.getMessage());
+        }
+    }
+
+    /**
+     * exec updateRequest
+     *
+     * @param index  elasticsearch index name
+     * @param id     Document id
+     * @param object request object
+     * @author fxbin
+     */
+    protected void updateRequest(String index, String id, Object object) {
+        try {
+            UpdateRequest updateRequest = new UpdateRequest(index, id).doc(BeanUtil.beanToMap(object), XContentType.JSON);
+            client.update(updateRequest, COMMON_OPTIONS);
+        } catch (IOException e) {
+            throw new ElasticsearchException("更新索引 {" + index + "} 数据 {" + object + "} 失败: " + e.getMessage());
+        }
+    }
+
+    /**
+     * exec deleteRequest
+     *
+     * @param index elasticsearch index name
+     * @param id    Document id
+     * @author fxbin
+     */
+    protected void deleteRequest(String index, String id) {
+        try {
+            DeleteRequest deleteRequest = new DeleteRequest(index, id);
+            client.delete(deleteRequest, COMMON_OPTIONS);
+        } catch (IOException e) {
+            throw new ElasticsearchException("删除索引 {" + index + "} 数据id {" + id + "} 失败: " + e.getMessage());
+        }
+    }
+
+    /**
+     * search all
+     *
+     * @param index elasticsearch index name
+     * @return {@link SearchResponse}
+     * @author fxbin
+     */
+    protected SearchResponse search(String index) {
+        SearchRequest searchRequest = new SearchRequest(index);
+        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+        searchSourceBuilder.query(QueryBuilders.matchAllQuery());
+        searchRequest.source(searchSourceBuilder);
+        SearchResponse searchResponse = null;
+        try {
+            searchResponse = client.search(searchRequest, COMMON_OPTIONS);
+        } catch (IOException e) {
+            log.error("es 搜索错误",e);
+        }
+        return searchResponse;
+    }
+
+    public static void main(String[] args) {
+        System.out.println(
                 " {\n" +
                         "    \"properties\": {\n" +
                         "      \"_class\": {\n" +
@@ -307,126 +659,6 @@ public abstract class BaseElasticsearchService {
                         "        }\n" +
                         "      }\n" +
                         "    }\n" +
-                        "  }\n";
-
-        PutMappingRequest request = new PutMappingRequest(index)
-                        .source(source, XContentType.JSON);
-//       AcknowledgedResponse putMappingResponse = client.indices().putMapping(request,
-//               RequestOptions.DEFAULT);
-//
-//       boolean acknowledged = putMappingResponse.isAcknowledged();
-//       if (acknowledged) {
-//           log.error("Succeed to put mapping");
-//       }
-        CountDownLatch latch = new CountDownLatch(1);
-        AtomicReference response = new AtomicReference<AcknowledgedResponse>();
-        client.indices().putMappingAsync(
-                request,
-                RequestOptions.DEFAULT,
-                new ActionListener<AcknowledgedResponse>() {
-                    @Override
-                    public void onResponse(AcknowledgedResponse r) {
-                        response.set(r);
-                        latch.countDown();
-                    }
-
-                    @Override
-                    public void onFailure(Exception e) {
-                        latch.countDown();
-                    }
-                });
-        latch.await(10, TimeUnit.SECONDS);
-        Assertions.assertThat(((AcknowledgedResponse) response.get()).isAcknowledged()).isTrue();
+                        "  }\n");
     }
-
-    /**
-     * Description: 判断某个index是否存在
-     *
-     * @param index index名
-     * @return boolean
-     * @author fanxb
-     * @date 2019/7/24 14:57
-     */
-    public boolean indexExist(String index) {
-        try {
-            GetIndexRequest request = new GetIndexRequest(index);
-            request.local(false);
-            request.humanReadable(true);
-            request.includeDefaults(false);
-            return client.indices().exists(request, RequestOptions.DEFAULT);
-        } catch (Exception e) {
-            throw new ElasticsearchException("获取索引 {" + index + "} 是否存在失败:" + e.getMessage());
-        }
-    }
-
-    /**
-     * delete elasticsearch index
-     *
-     * @param index elasticsearch index name
-     * @author fxbin
-     */
-    protected void deleteIndexRequest(String index) {
-        DeleteIndexRequest deleteIndexRequest = buildDeleteIndexRequest(index);
-        try {
-            client.indices().delete(deleteIndexRequest, COMMON_OPTIONS);
-        } catch (IOException e) {
-            throw new ElasticsearchException("删除索引 {" + index + "} 失败:" + e.getMessage());
-        }
-    }
-
-    /**
-     * exec updateRequest
-     *
-     * @param index  elasticsearch index name
-     * @param id     Document id
-     * @param object request object
-     * @author fxbin
-     */
-    protected void updateRequest(String index, String id, Object object) {
-        try {
-            UpdateRequest updateRequest = new UpdateRequest(index, id).doc(BeanUtil.beanToMap(object), XContentType.JSON);
-            client.update(updateRequest, COMMON_OPTIONS);
-        } catch (IOException e) {
-            throw new ElasticsearchException("更新索引 {" + index + "} 数据 {" + object + "} 失败: " + e.getMessage());
-        }
-    }
-
-    /**
-     * exec deleteRequest
-     *
-     * @param index elasticsearch index name
-     * @param id    Document id
-     * @author fxbin
-     */
-    protected void deleteRequest(String index, String id) {
-        try {
-            DeleteRequest deleteRequest = new DeleteRequest(index, id);
-            client.delete(deleteRequest, COMMON_OPTIONS);
-        } catch (IOException e) {
-            throw new ElasticsearchException("删除索引 {" + index + "} 数据id {" + id + "} 失败: " + e.getMessage());
-        }
-    }
-
-    /**
-     * search all
-     *
-     * @param index elasticsearch index name
-     * @return {@link SearchResponse}
-     * @author fxbin
-     */
-    protected SearchResponse search(String index) {
-        SearchRequest searchRequest = new SearchRequest(index);
-        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
-        searchSourceBuilder.query(QueryBuilders.matchAllQuery());
-        searchRequest.source(searchSourceBuilder);
-        SearchResponse searchResponse = null;
-        try {
-            searchResponse = client.search(searchRequest, COMMON_OPTIONS);
-        } catch (IOException e) {
-            log.error("es 搜索错误",e);
-        }
-        return searchResponse;
-    }
-
-
 }

+ 11 - 0
framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java

@@ -202,6 +202,14 @@ public class Goods extends BaseEntity {
     @JsonIgnore
     private String params;
 
+    @ApiModelProperty(value = "生产企业")
+    private String productEnterprise;
+
+    @ApiModelProperty(value = "生产批号")
+    private String productBitchNo;
+
+    @ApiModelProperty(value = "过期时间")
+    private String expireDate;
 
     public Goods() {
     }
@@ -222,6 +230,9 @@ public class Goods extends BaseEntity {
         this.intro = goodsOperationDTO.getIntro();
         this.mobileIntro = goodsOperationDTO.getMobileIntro();
         this.cost = goodsOperationDTO.getCost();
+        this.productEnterprise = goodsOperationDTO.getProductEnterprise();
+        this.productBitchNo = goodsOperationDTO.getProductBitchNo();
+        this.expireDate = goodsOperationDTO.getExpireDate();
         if (goodsOperationDTO.getGoodsParamsDTOList() != null && goodsOperationDTO.getGoodsParamsDTOList().isEmpty()) {
             this.params = JSONUtil.toJsonStr(goodsOperationDTO.getGoodsParamsDTOList());
         }

+ 10 - 0
framework/src/main/java/cn/lili/modules/goods/entity/dos/GoodsSku.java

@@ -164,6 +164,16 @@ public class GoodsSku extends BaseEntity {
     @ApiModelProperty(value = "商品类型", required = true)
     private String goodsType;
 
+    @ApiModelProperty(value = "生产企业")
+    private String productEnterprise;
+
+    @ApiModelProperty(value = "生产批号")
+    private String productBitchNo;
+
+    @ApiModelProperty(value = "过期时间")
+    private String expireDate;
+
+
     public Double getWeight() {
         if (weight == null) {
             return 0d;

+ 10 - 4
framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsOperationDTO.java

@@ -8,10 +8,7 @@ import lombok.ToString;
 import org.hibernate.validator.constraints.Length;
 
 import javax.validation.Valid;
-import javax.validation.constraints.Max;
-import javax.validation.constraints.Min;
-import javax.validation.constraints.NotEmpty;
-import javax.validation.constraints.NotNull;
+import javax.validation.constraints.*;
 import java.io.Serializable;
 import java.util.Date;
 import java.util.List;
@@ -124,5 +121,14 @@ public class GoodsOperationDTO implements Serializable {
     @ApiModelProperty(value = "商品类型")
     private String goodsType;
 
+    @NotBlank
+    @ApiModelProperty(value = "生产企业")
+    private String productEnterprise;
+    @NotBlank
+    @ApiModelProperty(value = "生产批号")
+    private String productBitchNo;
+    @NotBlank
+    @ApiModelProperty(value = "过期时间")
+    private String expireDate;
 
 }

+ 5 - 0
framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java

@@ -204,6 +204,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
                 throw new ServiceException(ResultCode.GOODS_NOT_EXIST);
             }
         }
+
         //获取当前商品的索引信息
         EsGoodsIndex goodsIndex = goodsIndexService.findById(skuId);
         if (goodsIndex == null) {
@@ -212,6 +213,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
         //商品规格
         GoodsSkuVO goodsSkuDetail = this.getGoodsSkuVO(goodsSku);
 
+
         //设置当前商品的促销价格
         if (goodsIndex.getPromotionMap() != null && !goodsIndex.getPromotionMap().isEmpty() && goodsIndex.getPromotionPrice() != null) {
             goodsSkuDetail.setPromotionPrice(goodsIndex.getPromotionPrice());
@@ -527,6 +529,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
                 goodsSku.setSelfOperated(goods.getSelfOperated());
             }
             goodsSku.setGoodsType(goods.getGoodsType());
+            goodsSku.setProductBitchNo(goods.getProductBitchNo());
+            goodsSku.setProductEnterprise(goods.getProductEnterprise());
+            goodsSku.setExpireDate(goods.getExpireDate());
             skus.add(goodsSku);
             stringRedisTemplate.opsForValue().set(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity().toString());
         }