kimi
2020-05-27 2893347bf72477c4d108e8589a0f61e3e97a990c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.highdatas.mdm.service.impl;
 
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.highdatas.mdm.entity.Maintain;
import com.highdatas.mdm.entity.SysMenu;
import com.highdatas.mdm.mapper.SysMenuMapper;
import com.highdatas.mdm.pojo.ActivitiStatus;
import com.highdatas.mdm.service.IMaintainService;
import com.highdatas.mdm.service.IMenuMappingService;
import com.highdatas.mdm.service.ISysMenuService;
import com.highdatas.mdm.util.NoticeClient;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author kimi
 * @since 2019-12-16
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {
    @Autowired
    ISysMenuService menuService;
    @Autowired
    IMaintainService maintainService;
    @Autowired
    IMenuMappingService menuMappingService;
    @Autowired
    NoticeClient noticeClient;
 
    /**
     *
     * @description:  通过子主题获取去重后的父主题
     * @param parentIdSet 子主题id集合
     * @return: 添加了父主题的id集合
     *
     */
    @Override
    public LinkedHashSet<String> getByParentId(LinkedHashSet<String> parentIdSet) {
        if (parentIdSet.size() == 0) {
            return null;
        }
        LinkedHashSet<String> subSet = new LinkedHashSet<>();
        for (String s : parentIdSet) {
            SysMenu sysMenu = menuService.selectById(s);
            if (sysMenu == null) {
                continue;
            }
            String parentId = sysMenu.getParentId();
            if (StringUtils.isEmpty(parentId)) {
                continue;
            }
            subSet.add(parentId);
        }
        LinkedHashSet<String> byParentId = getByParentId(subSet);
        if (byParentId != null) {
            parentIdSet.addAll(byParentId);
        }
 
        return parentIdSet;
    }
    /**
     *
     * @description:  通过子主题获取去重后的父主题
     * @param parentIdSet 子主题id集合
     * @return: 添加了父主题的对象集合
     *
     */
    @Override
    public List<SysMenu> getMenuByParentId(LinkedHashSet<String> parentIdSet) {
        LinkedHashSet<String> byParentId = getByParentId(parentIdSet);
       if (byParentId == null) {
           return new ArrayList<>();
       }
        List<SysMenu> sysMenus = selectBatchIds(byParentId);
        List<SysMenu> result = new ArrayList<SysMenu>();
        for (String s : byParentId) {
            List<SysMenu> collect = sysMenus.stream().filter(sysMenu -> sysMenu.getId().equalsIgnoreCase(s)).collect(Collectors.toList());
            if (!collect.isEmpty()) {
                result.add(collect.get(0));
            }
 
        }
        Collections.reverse(result);
        return result;
    }
    /**
     *
     * @description:  审批通过后的发送消息
     * @param maintainId 版本id
     * @param status 审批状态
     * @param userId 用户id
     * @return:
     *
     */
    @Override
    public void dealFlow(String maintainId, ActivitiStatus status,  String userId) {
        if (!status.equals(ActivitiStatus.open)) {
            return;
        }
        Maintain maintain = maintainService.selectById(maintainId);
        SysMenu menuByTableName = menuMappingService.getMenuByTableName(maintain.getTableName());
        LinkedHashSet<String> parentIdSet = new LinkedHashSet<>();
        parentIdSet.add(menuByTableName.getId());
        LinkedHashSet<String> byParentId = getByParentId(parentIdSet);
        if (byParentId == null) {
            noticeClient.openByAddMenu(menuByTableName, null, userId);
        } else {
            List<SysMenu> sysMenus = menuService.selectBatchIds(byParentId);
            SysMenu menu = sysMenus.get(0);
            noticeClient.openByAddMenu(menuByTableName, menu, userId);
        }
 
 
    }
 
 
}