Browse Source

Merge branch 'feature/1.0.0' of github.com:ab-inbev-apac/abi-cloud-qr-platform into feature/1.0.0

tanzhongran 4 years ago
parent
commit
61a9a48d12

+ 7 - 9
abi-cloud-qr-platform-common/src/main/java/com/abi/task/common/excel/ExcelInputFactory.java

@@ -7,6 +7,7 @@ import com.abi.task.common.api.exception.ErrorCodeEnum;
 import com.abi.task.common.excel.common.AbstractExcelProperty;
 import com.abi.task.common.excel.common.ExcelHeadAlias;
 import com.abi.task.common.utils.StrUtils;
+import com.google.common.collect.Maps;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -16,7 +17,6 @@ import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -142,16 +142,15 @@ public class ExcelInputFactory {
 
     private static <T extends AbstractExcelProperty> List<T> mapListToPojoList(List<Map<String, Object>> mapList, Class<T> tClass) {
         List<T> excelPojoList = new ArrayList<>();
-        for (Map<String, Object> mapTemp : mapList) {
-            try {
+        try {
+            for (Map<String, Object> mapTemp : mapList) {
                 T t = tClass.newInstance();
                 //方法map缓存
-                Map<String, Method> methodCache = new HashMap<>();
+                Map<String, Method> methodCache = Maps.newHashMap();
                 //循环每一个字段,反射放入数据
                 for (Map.Entry<String, Object> entry : mapTemp.entrySet()) {
                     String fieldName = entry.getKey();
                     Object value = entry.getValue();
-
                     //获取method
                     if (!methodCache.containsKey(fieldName)) {
                         String methodName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
@@ -166,14 +165,13 @@ public class ExcelInputFactory {
                     }
                     //调用method
                     Method method = methodCache.get(fieldName);
-                    method.invoke(t, StrUtils.filterHtml(String.valueOf(value).replaceAll(" ", " ")));
+                    method.invoke(t,StrUtils.filterHtml(value.toString().replaceAll("rm", " ")));
                 }
                 excelPojoList.add(t);
-            } catch (Exception e) {
-                log.error("mapListToPojoList error", e);
             }
+        } catch (Exception e) {
+            log.error("mapListToPojoList error", e);
         }
-
         return excelPojoList;
     }
 

+ 1 - 1
abi-cloud-qr-platform-common/src/main/java/com/abi/task/common/tablestore/TableStorePlusUtils.java

@@ -148,7 +148,7 @@ public class TableStorePlusUtils {
             }
 
         } catch (Exception e) {
-            log.info("setRow error", e);
+            log.warn("setRow error", e);
             throw new BusinessException("存储table异常");
         }
     }

+ 21 - 38
abi-cloud-qr-platform-common/src/main/java/com/abi/task/common/tablestore/TableStoreUtils.java

@@ -4,9 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
 import com.abi.task.common.api.exception.BusinessException;
 import com.abi.task.common.api.exception.ErrorCodeEnum;
-import com.abi.task.common.tablestore.common.TableStoreEntity;
 import com.abi.task.common.tablestore.common.TableStoreReq;
-import com.abi.task.common.tablestore.common.TableStoreRes;
 import com.alicloud.openservices.tablestore.SyncClient;
 import com.alicloud.openservices.tablestore.model.*;
 import com.alicloud.openservices.tablestore.model.search.SearchQuery;
@@ -20,13 +18,16 @@ import com.alicloud.openservices.tablestore.model.search.sort.SortOrder;
 import com.google.common.collect.Maps;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
 import java.time.LocalDateTime;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -38,18 +39,9 @@ import java.util.stream.Collectors;
 @Component
 public class TableStoreUtils {
 
-    @Value("${tableStore.endPoint}")
-    private String endPoint;
-
-    @Value("${tableStore.accessKeyId}")
-    private String accessKeyId;
-
-    @Value("${tableStore.accessKeySecret}")
-    private String accessKeySecret;
-
-    @Value("${tableStore.instanceName}")
-    private String instanceName;
 
+    @Autowired
+    private SyncClient client;
 
     /**
      * 单词交互条数 200条
@@ -71,14 +63,7 @@ public class TableStoreUtils {
         taskExecutor.initialize();
     }
 
-    /**
-     * 创建SyncClient
-     *
-     * @return
-     */
-    public SyncClient client() {
-        return new SyncClient(endPoint, accessKeyId, accessKeySecret, instanceName);
-    }
+
 
     /**
      * 创建数据表
@@ -99,16 +84,14 @@ public class TableStoreUtils {
         CreateTableRequest request = new CreateTableRequest(tableMeta, tableOptions);
         //设置预留读写吞吐量,容量型实例中的数据表只能设置为0,高性能实例中的数据表可以设置为非零值。
         request.setReservedThroughput(new ReservedThroughput(new CapacityUnit(0, 0)));
-        SyncClient client = client();
         client.createTable(request);
-
     }
 
     /**
      * 查询所有表的表名
      */
     public List<String> listTable() {
-        ListTableResponse listTableResponse = client().listTable();
+        ListTableResponse listTableResponse = client.listTable();
         return listTableResponse.getTableNames();
     }
 
@@ -121,7 +104,7 @@ public class TableStoreUtils {
      */
     public void putRow(String primaryKeyName, String pkValue, String tableName, List<Column> columns) {
         RowPutChange rowPutChange = buildRowPutChange(primaryKeyName, pkValue, tableName, columns);
-        client().putRow(new PutRowRequest(rowPutChange));
+        client.putRow(new PutRowRequest(rowPutChange));
     }
 
     public void batchPutRow(String primaryKeyName, List<String> pkValueList, String tableName, List<List<Column>> columnsList) {
@@ -182,15 +165,15 @@ public class TableStoreUtils {
             //添加到batch操作中。
             batchWriteRowRequest.addRowChange(rowPutChange);
         }
-        BatchWriteRowResponse response = client().batchWriteRow(batchWriteRowRequest);
+        BatchWriteRowResponse response = client.batchWriteRow(batchWriteRowRequest);
 
         long end = System.currentTimeMillis();
 
         log.info("是否全部成功:{} ,耗时{}毫秒", response.isAllSucceed(),end-begin);
         if (!response.isAllSucceed()) {
             for (BatchWriteRowResponse.RowResult rowResult : response.getFailedRows()) {
-                log.info("失败的行:{}", batchWriteRowRequest.getRowChange(rowResult.getTableName(), rowResult.getIndex()).getPrimaryKey());
-                log.info("失败原因:{}", rowResult.getError());
+                log.warn("失败的行:{}", batchWriteRowRequest.getRowChange(rowResult.getTableName(), rowResult.getIndex()).getPrimaryKey());
+                log.warn("失败原因:{}", rowResult.getError());
             }
             /**
              * 可以通过createRequestForRetry方法再构造一个请求对失败的行进行重试。此处只给出构造重试请求的部分。
@@ -212,7 +195,7 @@ public class TableStoreUtils {
 
         SingleRowQueryCriteria criteria = queryCriteria(primaryKeyName, pkValue, tableName);
 
-        GetRowResponse getRowResponse = client().getRow(new GetRowRequest(criteria));
+        GetRowResponse getRowResponse = client.getRow(new GetRowRequest(criteria));
         return getRowResponse.getRow();
     }
 
@@ -230,7 +213,7 @@ public class TableStoreUtils {
 
         //设置读取某些列。
         criteria.addColumnsToGet(columnName);
-        GetRowResponse getRowResponse = client().getRow(new GetRowRequest(criteria));
+        GetRowResponse getRowResponse = client.getRow(new GetRowRequest(criteria));
         return getRowResponse.getRow();
 
     }
@@ -250,7 +233,7 @@ public class TableStoreUtils {
         //更新列数据
         rowUpdateChange.put(new Column(columnName, ColumnValue.fromString(columnValue)));
 
-        client().updateRow(new UpdateRowRequest(rowUpdateChange));
+        client.updateRow(new UpdateRowRequest(rowUpdateChange));
     }
 
     /**
@@ -267,7 +250,7 @@ public class TableStoreUtils {
         //删除某一列。
         rowUpdateChange.deleteColumns(columnName);
 
-        client().updateRow(new UpdateRowRequest(rowUpdateChange));
+        client.updateRow(new UpdateRowRequest(rowUpdateChange));
     }
 
     /**
@@ -285,7 +268,7 @@ public class TableStoreUtils {
         //设置数据表名称。
         RowDeleteChange rowDeleteChange = new RowDeleteChange(tableName, primaryKey);
 
-        client().deleteRow(new DeleteRowRequest(rowDeleteChange));
+        client.deleteRow(new DeleteRowRequest(rowDeleteChange));
     }
 
     /**
@@ -305,7 +288,7 @@ public class TableStoreUtils {
             throw new BusinessException("FieldName为空");
         }
         if(req.getFieldValue()==null
-            &&(req.getLessThan()==null || req.getGreaterThan()==null)){
+                &&(req.getLessThan()==null || req.getGreaterThan()==null)){
             throw new BusinessException("查询条件为空");
         }
 
@@ -355,7 +338,7 @@ public class TableStoreUtils {
         columnsToGet.setReturnAll(true);
         searchRequest.setColumnsToGet(columnsToGet);
         //table store的出参
-        SearchResponse resp = client().search(searchRequest);
+        SearchResponse resp = client.search(searchRequest);
 
         return resp;
     }
@@ -448,7 +431,7 @@ public class TableStoreUtils {
         int maxVersions = 1;
         TableOptions tableOptions = new TableOptions(timeToLive, maxVersions);
         updateTableRequest.setTableOptionsForUpdate(tableOptions);
-        return client().updateTable(updateTableRequest);
+        return client.updateTable(updateTableRequest);
     }
 
 

+ 1 - 1
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/controller/console/FactoryController.java

@@ -120,7 +120,7 @@ public class FactoryController {
     }
 
     @ApiOperation("供应商包材厂是否加密")
-    @GetMapping("isEncryption")
+    @PostMapping("isEncryption")
     public BaseResponse<OutIsEncryptionRes>  isEncryption(@Validated GetIsEncryptionReq getIsEncryptionReq) throws Exception {
         //修改是否加密状态
         OutIsEncryptionRes res=factoryService.GetIsEncryption(getIsEncryptionReq);

+ 2 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/infrastructure/config/RabbitmqConfig.java

@@ -19,4 +19,6 @@ public class RabbitmqConfig {
 		return new Queue(TableStoreBatchInsertConsumer.TABLE_STORE_BATCH_INSERT_QUEUE);
 	}
 
+
+
 }

+ 43 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/infrastructure/config/TableStoreConf.java

@@ -0,0 +1,43 @@
+package com.abi.qms.platform.infrastructure.config;
+
+import com.alicloud.openservices.tablestore.SyncClient;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @className: com.abi.qms.platform.infrastructure.config-> TableStoreConf
+ * @description:
+ * @author: Marko.W
+ * @createDate: 2021-06-18 15:56
+ * @version: 1.0
+ * @todo:
+ */
+@Configuration
+public class TableStoreConf {
+
+    @Value("${tableStore.endPoint}")
+    private String endPoint;
+
+    @Value("${tableStore.accessKeyId}")
+    private String accessKeyId;
+
+    @Value("${tableStore.accessKeySecret}")
+    private String accessKeySecret;
+
+    @Value("${tableStore.instanceName}")
+    private String instanceName;
+
+
+
+    /**
+     * 创建SyncClient
+     *
+     * @return
+     */
+    @Bean
+    public SyncClient client() {
+        return new SyncClient(endPoint, accessKeyId, accessKeySecret, instanceName);
+    }
+
+}

+ 3 - 2
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/infrastructure/mq/TableStoreBatchInsertConsumer.java

@@ -35,13 +35,14 @@ public class TableStoreBatchInsertConsumer{
 
     @RabbitHandler
     @SneakyThrows
-    @RabbitListener(queues = TABLE_STORE_BATCH_INSERT_QUEUE,ackMode = "AUTO")
+    @RabbitListener(queues = TABLE_STORE_BATCH_INSERT_QUEUE,ackMode = "AUTO",concurrency = "10-50")
     public void onMessage(Message message){
         try {
             String messageInfo = new String(message.getBody(), "utf-8");
             operateTableStore(messageInfo);
         } catch (Exception e) {
-            log.error("保存码到TableStore异常:{}", e);
+            log.warn("保存码到TableStore异常:{}", e);
+            //fixme 这里还要处理失败的请求
         }
     }
 

+ 2 - 2
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/FactoryServiceImpl.java

@@ -502,8 +502,8 @@ public class FactoryServiceImpl implements FactoryService {
         //1.查询是否存在
         BaseFactory factory = baseFactoryMapper.selectById(getIsEncryptionReq.getId());
         AssertUtil.isNull(factory, "供应商不存在");
-        //2.判断是否包材厂
-        if (!FactoryTypeEnum.COVER.is(factory.getFactoryType())) {
+        //2.判断是否包材厂,且非一级包材厂
+        if (!FactoryTypeEnum.COVER.is(factory.getFactoryType()) && TrueFalseEnum.FALSE.is(factory.getIsFirstFactory())) {
             throw new BusinessException("该供应商不是包材厂,无法设置是否加密");
         }
         //3-修改是否加密状态

+ 1 - 6
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/GenerateCodeServiceImpl.java

@@ -394,7 +394,6 @@ public class GenerateCodeServiceImpl implements GenerateCodeService {
         final List<QrData> qrDataList = new LinkedList<>();
         Long qrIndex = getQrIndex();
 
-        log.info("doLoopGenerateCode 的疑似死循环.1");
         LocalDateTime localDateTime = LocalDateTime.now();
         // 计算还需生成的数量
         long needGenerateNumber = qrNumber;
@@ -589,7 +588,7 @@ public class GenerateCodeServiceImpl implements GenerateCodeService {
         }
 
         // 码重复,递归执行下一次
-        log.info("码重复,递归执行下一次");
+        log.debug("码重复,递归执行下一次");
         return buildUniqueCode(uniqueSet, qrRepertoryColumn, codeSb, paramMap, qrRepertorySerialNumberMap, ++buildTimes);
     }
 
@@ -599,12 +598,9 @@ public class GenerateCodeServiceImpl implements GenerateCodeService {
     private void buildCodeByClass(QrRepertoryColumnVO qrRepertoryColumn, StringBuilder codeSb, Map<String, Object> paramMap, Map<String, QrRepertorySerialNumber> qrRepertorySerialNumberMap) {
         // 使用一个对象,删除内容,不每次都新建一个对象
         codeSb.delete(0, codeSb.length());
-
         String[] buildClassArr = qrRepertoryColumn.getQrFormatVO().getCodeVariableBuildClass().split(",");
-        log.info("buildClassArr="+buildClassArr);
         for (int j = 0; j < buildClassArr.length; j++) {
             String buildClass = buildClassArr[j];
-            log.info("buildClass="+buildClass);
             String code;
             if (buildClass.startsWith(SerialBuildCode.SERIAL_START_WITH)) {
                 QrRepertorySerialNumber qrRepertorySerialNumber = qrRepertorySerialNumberMap.get(qrRepertoryColumn.getId() + "_" + j);
@@ -616,7 +612,6 @@ public class GenerateCodeServiceImpl implements GenerateCodeService {
             } else {
                 code = BuildCodeUtil.buildSingleCode(buildClass, paramMap);
             }
-            log.info("code="+code);
             codeSb.append(code);
         }
     }

+ 7 - 7
abi-cloud-qr-platform-server/src/test/java/com/abi/qms/platform/TableStoreTest.java

@@ -33,13 +33,13 @@ public class TableStoreTest {
         List<String> listTable = tableStoreUtils.listTable();
         System.out.println("===查看数据表===" + JSONUtil.toJsonStr(listTable));
     }
-
-    //删除数据表
-    @Test
-    public void deleteTableTest() {
-        DeleteTableRequest request = new DeleteTableRequest(TABLENAME);
-        tableStoreUtils.client().deleteTable(request);
-    }
+//
+//    //删除数据表
+//    @Test
+//    public void deleteTableTest() {
+//        DeleteTableRequest request = new DeleteTableRequest(TABLENAME);
+//        tableStoreUtils.deleteTable(request);
+//    }
 
     //创建数据表
     @Test