Quellcode durchsuchen

Merge remote-tracking branch 'origin/feature/1.0.0' into feature/1.0.0

v_KaixiangGuo vor 4 Jahren
Ursprung
Commit
218e99d932

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

@@ -13,8 +13,10 @@ import com.alicloud.openservices.tablestore.model.Column;
 import com.alicloud.openservices.tablestore.model.ColumnValue;
 import com.alicloud.openservices.tablestore.model.PrimaryKeyColumn;
 import com.alicloud.openservices.tablestore.model.Row;
+import com.alicloud.openservices.tablestore.model.search.SearchResponse;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.formula.functions.T;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -185,7 +187,7 @@ public class TableStorePlusUtils {
      * @param <T>
      * @return
      */
-    public <T extends TableStoreEntity> List<T> selectList(TableStoreReq req) {
+    public <T extends TableStoreEntity> TableStoreRes<T> selectList(TableStoreReq<T> req) {
         if(req.getClz()==null){
             throw new BusinessException("印射对象为空");
         }
@@ -200,10 +202,18 @@ public class TableStorePlusUtils {
      * @param <T>
      * @return
      */
-    public <T extends TableStoreEntity> List<T> selectList(Class<T> clz, TableStoreReq req) {
-        TableStoreRes tableStoreRes = tableStoreUtils.listRows(req);
-        List<T> rows = toEntityList(clz, tableStoreRes.getRowList());
-        return rows;
+    public <T extends TableStoreEntity> TableStoreRes<T> selectList(Class<T> clz, TableStoreReq req) {
+        //拿到tablestore出参
+        SearchResponse resp = tableStoreUtils.listRows(req);
+        //构造我们的出参
+        TableStoreRes<T> res = new TableStoreRes<T>();
+        res.setRowList(resp.getRows());
+        res.setTotalCount(resp.getTotalCount());
+        //把rows转entity
+        List<T> entityList = toEntityList(clz, res.getRowList());
+        res.setEntityList(entityList);
+
+        return res;
     }
 
     /**

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

@@ -46,9 +46,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.time.LocalDateTime;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 /**
  * @author: fangxinjian
@@ -260,7 +258,7 @@ public class TableStoreUtils {
      * @param req
      * @return
      */
-    public TableStoreRes listRows(TableStoreReq req){
+    public SearchResponse listRows(TableStoreReq req){
         //0-校验入参合法性
         if(StringUtils.isBlank(req.getTableName())){
             throw new BusinessException("TableName为空");
@@ -324,11 +322,7 @@ public class TableStoreUtils {
         //table store的出参
         SearchResponse resp = client().search(searchRequest);
 
-        //我们自己的出参
-        TableStoreRes res = new TableStoreRes();
-        res.setTotalCount(resp.getTotalCount());
-        res.setRowList(resp.getRows());
-        return res;
+        return resp;
     }
 
 

+ 35 - 33
abi-cloud-qr-platform-common/src/main/java/com/abi/task/common/tablestore/common/TableStoreReq.java

@@ -5,6 +5,7 @@ import com.abi.task.common.utils.IStringUtil;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.formula.functions.T;
+import org.checkerframework.checker.units.qual.K;
 
 import java.lang.reflect.Field;
 
@@ -14,81 +15,78 @@ import java.lang.reflect.Field;
  */
 @Data
 @Slf4j
-public class TableStoreReq {
+public class TableStoreReq<T extends TableStoreEntity> {
 
     /**
      * 表名
      */
-    String tableName;
+    private String tableName;
 
     /**
      * 索引名
      */
-    String indexName;
+    private String indexName;
 
     /**
      * 匹配的字段名
      */
-    String fieldName;
+    private String fieldName;
 
     /**
      * 匹配的字段值
      */
-    Object fieldValue;
+    private Object fieldValue;
 
     /**
      * 大于xxx
      */
-    Object greaterThan;
+    private Object greaterThan;
 
     /**
      * 小于xxx
      */
-    Object lessThan;
+    private Object lessThan;
 
     /**
      * 每页条数
      */
-    Integer pageCount = 10;
+    private Integer pageCount = 10;
 
     /**
      * 第几页
      */
-    Integer pageNo = 1;
+    private Integer pageNo = 1;
 
     /**
      * 需要返回总数量
      */
-    Boolean getTotalCount = false;
+    private Boolean getTotalCount = false;
 
     /**
      * 是否逆序
      */
-    Boolean sortByFieldDesc = false;
+    private Boolean sortByFieldDesc = false;
 
     /**
      * 印射对象类
      */
-    Class clz;
+    private Class clz;
 
     /**
-     * 无参构造函数
+     * 静态创建函数
      */
-    public TableStoreReq(){}
+    public static <T extends TableStoreEntity> TableStoreReq<T> build(Class<T> clzParam, String fieldName){
+        TableStoreReq<T> req = new TableStoreReq<T>();
 
-    /**
-     * 构造函数
-     */
-    public <T extends TableStoreEntity> TableStoreReq(Class<T> clz, String fieldName){
         Field field = null;
         try{
-            field = clz.getDeclaredField(fieldName);
+            field = clzParam.getDeclaredField(fieldName);
         }catch (Exception e){
             log.info("找不到字段",e);
         }
 
         //表名
-        TableStore tableStore = clz.getAnnotation(TableStore.class);
+        TableStore tableStore = clzParam.getAnnotation(TableStore.class);
         String tableName = tableStore.tableName();
         //索引
         TableStoreIndex tableStoreIndex = field.getAnnotation(TableStoreIndex.class);
@@ -96,10 +94,12 @@ public class TableStoreReq {
         //字段名转下划线
         fieldName = IStringUtil.camelToUnderline(fieldName);
 
-        this.tableName = tableName;
-        this.indexName = indexName;
-        this.fieldName = fieldName;
-        this.clz = clz;
+        req.tableName = tableName;
+        req.indexName = indexName;
+        req.fieldName = fieldName;
+        req.clz = clzParam;
+
+        return req;
     }
 
     /**
@@ -108,10 +108,12 @@ public class TableStoreReq {
      * @param indexName 索引名
      * @param fieldName 匹配的字段名
      */
-    public TableStoreReq(String tableName,String indexName,String fieldName){
-        this.tableName = tableName;
-        this.indexName = indexName;
-        this.fieldName = fieldName;
+    public static <T extends TableStoreEntity> TableStoreReq<T> build(String tableName,String indexName,String fieldName){
+        TableStoreReq<T> req = new TableStoreReq<T>();
+        req.tableName = tableName;
+        req.indexName = indexName;
+        req.fieldName = fieldName;
+        return req;
     }
 
     /**
@@ -120,7 +122,7 @@ public class TableStoreReq {
      * @param lessThan
      * @return
      */
-    public TableStoreReq range(Object greaterThan,Object lessThan){
+    public TableStoreReq<T> range(Object greaterThan,Object lessThan){
         this.setGreaterThan(greaterThan);
         this.setLessThan(lessThan);
         return this;
@@ -131,12 +133,12 @@ public class TableStoreReq {
      * @param fieldValue
      * @return
      */
-    public TableStoreReq equal(Object fieldValue){
+    public TableStoreReq<T> eq(Object fieldValue){
         this.setFieldValue(fieldValue);
         return this;
     }
 
-    public TableStoreReq page(Integer pageNo,Integer pageCount){
+    public TableStoreReq<T> page(Integer pageNo,Integer pageCount){
         this.pageNo = pageNo;
         this.pageCount = pageCount;
         return this;
@@ -146,7 +148,7 @@ public class TableStoreReq {
      * 是否逆序
      * @return
      */
-    public TableStoreReq isDesc(){
+    public TableStoreReq<T> isDesc(){
         this.setSortByFieldDesc(true);
         return this;
     }
@@ -155,7 +157,7 @@ public class TableStoreReq {
      * 是否需要总数
      * @return
      */
-    public TableStoreReq isNeedTotalCount(){
+    public TableStoreReq<T> isNeedTotalCount(){
         this.setGetTotalCount(true);
         return this;
     }

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

@@ -12,7 +12,7 @@ import java.util.List;
  */
 @Data
 @ToString
-public class TableStoreRes {
+public class TableStoreRes<T extends TableStoreEntity> {
 
     /**
      * 总行数
@@ -24,4 +24,11 @@ public class TableStoreRes {
      */
     private List<Row> rowList;
 
+    /**
+     * 对象列表
+     */
+    private List<T> entityList;
+
+
+
 }

+ 14 - 21
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/infrastructure/mq/GenerateCodeConsumer.java

@@ -21,6 +21,7 @@ import com.abi.qms.platform.service.QrPackageService;
 import com.abi.task.common.api.exception.BusinessException;
 import com.abi.task.common.tablestore.TableStorePlusUtils;
 import com.abi.task.common.tablestore.common.TableStoreEntity;
+import com.abi.task.common.utils.PojoConverterUtils;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.rabbitmq.client.Channel;
@@ -327,27 +328,19 @@ public class GenerateCodeConsumer {
 	 * 批量新增tableStore,码表
 	 */
 	private void saveTableStore(QrPackageBatch qrPackageBatch, List<QrData> codeList) {
-		List<TableStoreEntity> codeSave = new ArrayList<>();
-		for (QrData qrData:codeList) {
-			List<QrInnerData> innerDataList = qrData.getInnerDataList();
-			for (QrInnerData qrInnerData:innerDataList) {
-				QrCode qrCode = new QrCode();
-				//码
-				qrCode.setCode(qrInnerData.getCode());
-				//批次id
-				qrCode.setBatchNumberId(qrPackageBatch.getId());
-				//码包id
-				qrCode.setPackageId(qrPackageBatch.getPackageId());
-				//创建时间
-				qrCode.setCreateTime(LocalDateTime.now());
-				//已生成码包位置
-				qrCode.setCodeIndex(qrInnerData.getCodeIndex());
-				//生成码库列id
-				qrCode.setQrRepertoryColumnId(qrInnerData.getQrRepertoryColumnId());
-				codeSave.add(qrCode);
-			}
-		}
-		tableStorePlusUtils.putRow(codeSave);
+		List<TableStoreEntity> qrCodes = new ArrayList<>();
+		codeList.forEach(sout-> {
+			List<QrInnerData> innerDataList = sout.getInnerDataList();
+			List<QrCode> qrCodeCope = PojoConverterUtils.copyList(innerDataList, QrCode.class);
+			//			批次号 码包
+			qrCodeCope.forEach(stable->{
+				stable.setBatchNumberId(qrPackageBatch.getId());
+				stable.setPackageId(qrPackageBatch.getPackageId());
+				stable.setCreateTime(LocalDateTime.now());
+			});
+			qrCodes.addAll(qrCodeCope);
+		});
+		tableStorePlusUtils.putRow(qrCodes);
 	}
 
 	/**

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

@@ -86,36 +86,36 @@ public class FactoryServiceImpl implements FactoryService {
         }
 
         //1-声明对象
-        BaseFactory dept = null;
+        BaseFactory factory = null;
         if (req.getId() != null) {
-            dept = baseFactoryMapper.selectById(req.getId());
-            AssertUtil.isNull(dept, "供应商不存在");
+            factory = baseFactoryMapper.selectById(req.getId());
+            AssertUtil.isNull(factory, "供应商不存在");
         } else {
-            dept = new BaseFactory();
+            factory = new BaseFactory();
         }
 
         //2-放入数据
-        dept.setFactoryCode(req.getFactoryCode());
-        dept.setFactoryName(req.getFactoryName());
-        dept.setFactoryType(req.getFactoryType());
-        dept.setDescription(req.getDescription());
+        factory.setFactoryCode(req.getFactoryCode());
+        factory.setFactoryName(req.getFactoryName());
+        factory.setFactoryType(req.getFactoryType());
+        factory.setDescription(req.getDescription());
         if (FactoryTypeEnum.COVER.is(req.getFactoryType())) {
-            dept.setKeymanName(req.getKeymanName());
-            dept.setKeymanMobile(req.getKeymanMobile());
-            dept.setEmail(req.getEmail());
-            dept.setMaxFileCount(req.getMaxFileCount());
-            dept.setFactoryLevel(req.getFactoryLevel());
-            dept.setProvince(req.getProvince());
-            dept.setCity(req.getCity());
-            dept.setDistrict(req.getDistrict());
-            dept.setAddress(req.getAddress());
+            factory.setKeymanName(req.getKeymanName());
+            factory.setKeymanMobile(req.getKeymanMobile());
+            factory.setEmail(req.getEmail());
+            factory.setMaxFileCount(req.getMaxFileCount());
+            factory.setFactoryLevel(req.getFactoryLevel());
+            factory.setProvince(req.getProvince());
+            factory.setCity(req.getCity());
+            factory.setDistrict(req.getDistrict());
+            factory.setAddress(req.getAddress());
         }
 
         //3-新增or修改
         if (req.getId() != null) {
-            baseFactoryMapper.updateById(dept);
+            baseFactoryMapper.updateById(factory);
         } else {
-            baseFactoryMapper.insert(dept);
+            baseFactoryMapper.insert(factory);
         }
 
     }
@@ -300,7 +300,7 @@ public class FactoryServiceImpl implements FactoryService {
         ListPackageFactorySelectRes listPackageFactorySelectRes = new ListPackageFactorySelectRes();
         QueryWrapper<BaseFactory> param = new QueryWrapper<>();
         //数据权限隔离,如果登录账号是包材厂,只能看账号包材厂的数据。否则看全部
-        if (userUtil.getWholeUser().getFactoryId() != null) {
+        if (userUtil.getWholeUser().getFactoryId() != null && userUtil.getWholeUser().getFactoryType() != null && FactoryTypeEnum.COVER.is(userUtil.getWholeUser().getFactoryType()) ) {
             param.eq("id", userUtil.getWholeUser().getFactoryId());
             listPackageFactorySelectRes.setLoginType(LoginTypeEnum.PACKAGE.getCode());
         } else {

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

@@ -2,6 +2,7 @@ package com.abi.qms.platform.service.impl;
 
 import com.abi.qms.platform.dao.entity.QrBoxCodeFormat;
 import com.abi.qms.platform.dao.entity.QrBoxCodeFormatSplit;
+import com.abi.qms.platform.dao.enums.FactoryTypeEnum;
 import com.abi.qms.platform.dao.enums.StateEnum;
 import com.abi.qms.platform.dao.mapper.QrBoxCodeFormatMapper;
 import com.abi.qms.platform.dao.mapper.QrBoxCodeFormatSplitMapper;
@@ -114,7 +115,7 @@ public class QrBoxCodeFormatImpl implements QrBoxCodeFormatService {
     @Override
     public ListBoxCodeFormatRes listBoxCodeFormat(ListBoxCodeFormatReq req) {
         //数据权限隔离,如果登录账号是包材厂,只能看账号包材厂的数据。否则看全部
-        if (userUtil.getWholeUser().getFactoryId() != null) {
+        if (userUtil.getWholeUser().getFactoryId() != null && userUtil.getWholeUser().getFactoryType() != null && FactoryTypeEnum.COVER.is(userUtil.getWholeUser().getFactoryType()) ) {
             req.setFactoryId(userUtil.getWholeUser().getFactoryId());
         }
         //分页查询

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

@@ -340,7 +340,7 @@ public class QrPackageServiceImpl implements QrPackageService {
     @Override
     public ListQrPackageRes listQrPackage(ListQrPackageReq req) {
         //数据权限隔离,如果登录账号是包材厂,只能看账号包材厂的数据。否则看全部
-        if (userUtil.getWholeUser().getFactoryId() != null) {
+        if (userUtil.getWholeUser().getFactoryId() != null && userUtil.getWholeUser().getFactoryType() != null && FactoryTypeEnum.COVER.is(userUtil.getWholeUser().getFactoryType()) ) {
             req.setFactoryCoverId(userUtil.getWholeUser().getFactoryId());
         }
 

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

@@ -1,6 +1,5 @@
 package com.abi.qms.platform.service.impl;
 
-import cn.hutool.core.util.ObjectUtil;
 import com.abi.qms.platform.dao.entity.BaseFactory;
 import com.abi.qms.platform.dao.entity.UserInfo;
 import com.abi.qms.platform.dao.entity.UserMappingInfoRole;
@@ -89,9 +88,11 @@ public class UserManagerServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo
             throw new BusinessException("非ABI用户必须选择供应商");
         }
         //查询供应商
+        Integer factoryType = null;
         if(req.getFactoryId()!=null){
             BaseFactory factory = baseFactoryMapper.selectById(req.getFactoryId());
             AssertUtil.isNull(factory,"供应商不存在");
+            factoryType = factory.getFactoryType();
         }
 
         //操作人
@@ -105,6 +106,8 @@ public class UserManagerServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo
         userInfo.setPassword(req.getPassword());
         userInfo.setIsAbi(req.getIsAbi());
         userInfo.setFactoryId(req.getFactoryId());
+        //添加用户供应商类型的标志
+        userInfo.setFactoryType(factoryType);
         userInfo.setRoleCode(req.getRoleCode());
         userInfo.setPhone(req.getPhone());
         userInfoMapper.insert(userInfo);
@@ -143,7 +146,15 @@ public class UserManagerServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo
         //1-修改主表
         userInfo.setEmail(req.getEmail());
         userInfo.setPhone(req.getPhone());
-        userInfo.setFactoryId(req.getFactoryId());
+        //校验供应商
+        if(Objects.nonNull(req.getFactoryId())) {
+            if(!userInfo.getFactoryId().equals(req.getFactoryId())) {
+                BaseFactory factory = baseFactoryMapper.selectById(req.getFactoryId());
+                AssertUtil.isNull(factory,"供应商不存在");
+                userInfo.setFactoryId(req.getFactoryId());
+                userInfo.setFactoryType(factory.getFactoryType());
+            }
+        }
         userInfo.setRoleCode(req.getRoleCode());
         userInfoMapper.updateById(userInfo);
 

+ 15 - 8
abi-cloud-qr-platform-server/src/test/java/com/abi/qms/platform/TableStorePlusTest.java

@@ -2,7 +2,6 @@ package com.abi.qms.platform;
 
 import com.abi.qms.platform.dao.tablestore.entity.QrCode;
 import com.abi.task.common.tablestore.TableStorePlusUtils;
-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.abi.task.common.tablestore.entity.DemoEntity;
@@ -53,13 +52,15 @@ public class TableStorePlusTest {
     //按索引范围匹配
     @Test
     public void queryRowsRange(){
-        //构造入参
-        TableStoreReq req = new TableStoreReq(QrCode.class,"codeIndex")
+        TableStoreReq<QrCode> req = TableStoreReq.build(QrCode.class,"codeIndex")
                 .range(1,100)
                 .page(1,15)
                 .isDesc();
         //调用查询
-        List<QrCode> qrCodeList = tableStorePlusUtils.selectList(req);
+        TableStoreRes<QrCode> res = tableStorePlusUtils.selectList(req);
+
+        List<QrCode> qrCodeList = res.getEntityList();
+
         //打印
         for(QrCode qrCode:qrCodeList){
             log.info(qrCode.toString());
@@ -69,15 +70,21 @@ public class TableStorePlusTest {
     //按索引精确匹配
     @Test
     public void queryRowsEqual(){
-        TableStoreReq req = new TableStoreReq(QrCode.class,"packageId")
-                .equal("1")
-                .page(1,3);
+        TableStoreReq<QrCode> req = TableStoreReq.build(QrCode.class,"packageId")
+                .eq("1")
+                .page(1,3)
+                .isNeedTotalCount();
+
+        TableStoreRes<QrCode> res = tableStorePlusUtils.selectList(req);
+
+        List<QrCode> qrCodeList = res.getEntityList();
 
-        List<QrCode> qrCodeList = tableStorePlusUtils.selectList(req);
         //打印
         for(QrCode qrCode:qrCodeList){
             log.info(qrCode.toString());
         }
+        log.info("total count----------->");
+        log.info(String.valueOf(res.getTotalCount()));
     }
 
 

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

@@ -97,26 +97,5 @@ public class TableStoreTest {
         tableStoreUtils.deleteRow(PRIMARYKEYNAME,"00002",TABLENAME);
     }
 
-    //按索引范围匹配
-    @Test
-    public void queryRowsRange(){
-        TableStoreReq req = new TableStoreReq("qr_code","index_code_index","code_index")
-                .range(1,9)
-                .isDesc();
-
-        TableStoreRes tableStoreRes = tableStoreUtils.listRows(req);
-        log.info(tableStoreRes.toString());
-    }
-
-    //按索引精确匹配
-    @Test
-    public void queryRowsEqual(){
-        TableStoreReq req = new TableStoreReq("qr_code","index_code_index","code_index")
-                .equal("1")
-                .isNeedTotalCount();
-
-        TableStoreRes tableStoreRes = tableStoreUtils.listRows(req);
-        log.info(tableStoreRes.toString());
-    }
 
 }