From 5268a2b7dfa556bd6f5a2d5e446cea3ea9940c10 Mon Sep 17 00:00:00 2001
From: kimi <kimi42345@gmail.com>
Date: 星期三, 22 四月 2020 11:18:23 +0800
Subject: [PATCH] add 分发     master_author 添加字段   subscribe increment,   添加7个表  master_author_subscribe   master_author_unactive   sys_dispense_config   sys_dispense_logs  sys_view   sys_view_join   sys_view_logic

---
 src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java |  159 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 153 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java b/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java
index d174081..93d8acb 100644
--- a/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java
+++ b/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java
@@ -7,8 +7,11 @@
 import com.highdatas.mdm.entity.Character;
 import com.highdatas.mdm.entity.*;
 import com.highdatas.mdm.mapper.MasterAuthorMapper;
+import com.highdatas.mdm.mapper.TableInfoMapper;
 import com.highdatas.mdm.pojo.ActivitiStatus;
 import com.highdatas.mdm.pojo.MasterAuthorType;
+import com.highdatas.mdm.pojo.Page;
+import com.highdatas.mdm.pojo.kettle.UnBigDataDataSourceInfo;
 import com.highdatas.mdm.service.*;
 import com.highdatas.mdm.util.Constant;
 import com.highdatas.mdm.util.ContentBuilder;
@@ -46,6 +49,56 @@
     IMaintainService maintainService;
     @Autowired
     IFlowsService flowsService;
+    @Autowired
+    UnBigDataDataSourceInfo unBigDataDataSourceInfo;
+    @Autowired
+    IMenuMappingService menuMappingService;
+    @Autowired
+    IMaintainDetailService maintainDetailService;
+    @Autowired
+    MasterDataService masterDataService;
+    @Autowired
+    TableInfoMapper tableInfoMapper;
+
+    @Override
+    public Page getInitPageInfo(MasterAuthor masterAuthor, Maintain maintain, TUser user, boolean getIncrement) {
+        Page page = new Page(0);
+        List<TableSchemaResult> tableField = tableInfoMapper.getTableField(masterAuthor.getTableName());
+
+        List<SysField> fieldByMaintain = fieldService.getFieldByMaintain(maintain.getId());
+        List<String> authorFieldList = fieldByMaintain.stream().map(sysField -> sysField.getField()).collect(Collectors.toList());
+        int totalLength = 0;
+        for (TableSchemaResult tableSchemaResult : tableField) {
+            String fieldName = tableSchemaResult.getFieldName();
+            if (!authorFieldList.contains(fieldName)) {
+                continue;
+            }
+            int length = tableSchemaResult.getLength();
+            totalLength += length;
+        }
+
+        int pageSize = Constant.MaxDispenseSize / totalLength;
+        page.setPageSize(pageSize);
+        long totalCnt;
+        if (getIncrement) {
+            totalCnt = maintainDetailService.selectCount(new EntityWrapper<MaintainDetail>().eq(Constant.PARENT_ID, maintain.getId()));
+        }else {
+            String filter = getFilter(user, maintain.getId());
+            totalCnt = masterDataService.getCountByVersion(user, maintain.getTableName(), filter, maintain.getVersion(), false);
+        }
+        page.setRecordCount(Long.valueOf(totalCnt).intValue());
+        if (totalCnt == 0) {
+            return null;
+        }
+        int pages;
+        if (totalCnt % pageSize == 0) {
+            pages = Long.valueOf(totalCnt/pageSize).intValue();
+        }else  {
+            pages =  (Long.valueOf(totalCnt/pageSize).intValue())  + 1;
+        }
+        page.setPages(pages);
+        return page;
+    }
 
     @Override
     public HashMap<String, MasterAuthor> merageRoleAuthor(Set<String> roleIds) {
@@ -71,6 +124,16 @@
 
     @Override
     public List<SysMenu> getMenu(Character character) {
+        return getMenu(character, false);
+    }
+
+    @Override
+    public List<SysMenu> getMenuUnParent(Character character) {
+        return getMenuUnParent(character, false);
+    }
+
+    @Override
+    public List<SysMenu> getMenuUnParent(Character character, boolean isTableMenu) {
         MasterAuthorType type = character.getType();
         List<MasterAuthor> masterAuthors = null;
         switch (type){
@@ -87,16 +150,63 @@
             return null;
         }
         List<String> menuIds = masterAuthors.stream().map(masterAuthor -> masterAuthor.getMenuId()).collect(Collectors.toList());
-        LinkedHashSet<String> strings = new LinkedHashSet<>(menuIds);
-        LinkedHashSet<String> byParentId = menuService.getByParentId(strings);
-        if (byParentId == null) {
-            return null;
+
+        if (isTableMenu) {
+            List<String> tempList = new ArrayList<>();
+            for (String menuId : menuIds) {
+                String tableNameByMenu = menuMappingService.getTableNameByMenu(menuId);
+                boolean exists = unBigDataDataSourceInfo.checkTableExists(tableNameByMenu);
+                if (exists) {
+                    tempList.add(menuId);
+                }
+            }
+            menuIds = tempList;
         }
-        List<SysMenu> sysMenus = menuService.selectBatchIds(byParentId);
+        List<SysMenu> sysMenus = menuService.selectBatchIds(menuIds);
         return sysMenus;
     }
 
-    private List<MasterAuthor> getUserAuthor(String characterId, MaintainField maintainField) {
+    @Override
+    public List<SysMenu> getMenu(Character character, boolean isTableMenu) {
+        MasterAuthorType type = character.getType();
+        List<MasterAuthor> masterAuthors = null;
+        switch (type){
+            case role:
+                masterAuthors = getRoleAuthors(character.getId(), null);
+                break;
+            case groupInfo:
+                masterAuthors = getOneGroupAuthors(character.getId(), null);
+                break;
+            case user:
+                masterAuthors = getUserAuthor(character.getId(), null);
+        }
+        if (masterAuthors == null || masterAuthors.isEmpty()) {
+            return null;
+        }
+        List<String> menuIds = masterAuthors.stream().map(masterAuthor -> masterAuthor.getMenuId()).collect(Collectors.toList());
+
+        if (isTableMenu) {
+            List<String> tempList = new ArrayList<>();
+            for (String menuId : menuIds) {
+                String tableNameByMenu = menuMappingService.getTableNameByMenu(menuId);
+                boolean exists = unBigDataDataSourceInfo.checkTableExists(tableNameByMenu);
+                if (exists) {
+                    tempList.add(menuId);
+                }
+            }
+            menuIds = tempList;
+        }
+
+        LinkedHashSet<String> strings = new LinkedHashSet<>(menuIds);
+        List<SysMenu> sysMenus = menuService.getMenuByParentId(strings);
+        if (sysMenus == null) {
+            return null;
+        }
+        return sysMenus;
+    }
+
+    @Override
+    public List<MasterAuthor> getUserAuthor(String characterId, MaintainField maintainField) {
         Wrapper<MasterAuthor> userWrapper = new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, characterId);
 
         if (maintainField != null) {
@@ -365,6 +475,9 @@
             builder.append(format);
         }
         String filter = builder.toString();
+        if (StringUtils.isEmpty(filter)) {
+            return Constant.WHERE_DEFAULT;
+        }
         return filter;
     }
 
@@ -384,6 +497,40 @@
         return null;
     }
 
+    @Override
+    public LinkedHashSet<Maintain> getMaintainSet(String tableName, TUser user) {
+        List<MasterAuthor> userAuthor = this.getUserAuthor(user.getUserId(), null);
+        LinkedHashSet<Maintain> maintainSet = new LinkedHashSet<>();
+        Collections.reverse(userAuthor);
+
+        for (MasterAuthor masterAuthor : userAuthor) {
+            String tabName = masterAuthor.getTableName();
+            String maintainFieldId = masterAuthor.getMaintainFieldId();
+            if (StringUtils.isEmpty(tabName) || !tableName.equalsIgnoreCase(tableName) || StringUtils.isEmpty(maintainFieldId)) {
+                continue;
+            }
+            List<Maintain> maintainByMaintainField = maintainFieldService.getMaintainByMaintainField(maintainFieldId, tableName);
+            maintainSet.addAll(maintainByMaintainField);
+        }
+        return maintainSet;
+    }
+
+    public void dealFlow(String maintainId, ActivitiStatus status) {
+        Maintain maintain = maintainService.selectById(maintainId);
+        MaintainField maintainFieldByMaintain = fieldService.getMaintainFieldByMaintain(maintainId);
+        SysMenu menuByTableName = menuMappingService.getMenuByTableName(maintain.getTableName());
+
+        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>()
+                .eq("maintain_field_id", maintainFieldByMaintain.getId())
+                .eq("table_name", maintain.getTableName())
+                .eq("menu_id", menuByTableName.getId())
+                .eq("maintain_auto", true));
+        for (MasterAuthor masterAuthor : masterAuthors) {
+
+        }
+    }
+
+
     private MasterAuthor merage(MasterAuthor preMerageMasterAuthor, MasterAuthor masterAuthor) {
         // table name  masterField 涓�鏍� 鍙湁瀛楁涓嶅悓浜�
         List<MasterAuthorDetail> preFields = preMerageMasterAuthor.getFields();

--
Gitblit v1.8.0