cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package cn.ksource.web.facade.impl;
 
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import cn.ksource.core.dao.BaseDao;
import cn.ksource.core.dao.SqlParameter;
import cn.ksource.core.util.ConvertUtil;
import cn.ksource.core.util.JsonUtil;
import cn.ksource.core.util.StringUtil;
import cn.ksource.core.web.TreeNode;
import cn.ksource.core.web.WebUtil;
import cn.ksource.web.facade.BmglFacade;
import cn.ksource.web.service.ZzjgService;
 
@Service("bmglFacade")
public class BmglFacadeImpl implements BmglFacade {
 
    @Autowired
    private BaseDao baseDao;
    
    @Autowired
    private ZzjgService zzjgService;
 
    @Override
    public TreeNode getBmTree() {
        return zzjgService.getZzjgTree();
    }
    /**
     * 根据id得到某些部门
     * @param ids
     * @return
     */
    public List getDeptList(String ids){
        return zzjgService.getDeptList(ids);
    }
    
    @Override
    public List<Map> queryBmYjList(HttpServletRequest request) {
        
        Map paramMap = new HashMap();
        String selectSubSql = "SELECT * FROM GG_ZZJG WHERE ZT=1 ORDER BY CENGJ,SXH ";
        List<Map> cates = baseDao.queryForList(selectSubSql,paramMap);
        Map result = new HashMap();
        
        List<Map> resultList = new LinkedList<Map>();
        
        Map<String, Map> yjgnCache = new HashMap<String, Map>();
        Map<String, Map> ejgnCache = new HashMap<String, Map>();
        Map<String, Map> sjgnCache = new HashMap<String, Map>();
        
        for (Map map : cates) {
            String level = map.get("CENGJ").toString();
            String id = map.get("ID").toString();
            
            //一级树
            if (level.equalsIgnoreCase("1")) {
                yjgnCache.put(id, map);
                List<Map> ejgnList = new LinkedList<Map>();
                map.put("ejTree", ejgnList);
                resultList.add(map);
                continue;
            }
            //二级树
            if (level.equalsIgnoreCase("2")) {
                String pId = map.get("SJBH").toString();
                if(yjgnCache.containsKey(pId)) {
                    Map yjgnMap = yjgnCache.get(pId);
                    List<Map> list = (List<Map>)yjgnMap.get("ejTree");
                    map.put("sjTree", new LinkedList<Map>());
                    list.add(map);
                    
                    ejgnCache.put(id, map);
                }
                continue;
            }
            //三级树
            if (level.equalsIgnoreCase("3")) {
                if(null!=map.get("SJBH")){
                    String pId = map.get("SJBH").toString();
                    if(ejgnCache.containsKey(pId)) {
                        Map ejgnMap = ejgnCache.get(map.get("SJBH").toString());
                        List<Map> list = (List<Map>)ejgnMap.get("sjTree");
                        map.put("fjTree", new LinkedList<Map>());
                        list.add(map);
                        sjgnCache.put(id, map);
                    }
                }
            }
        }
        System.out.println(JsonUtil.list2Json(resultList));
        return resultList;
    }
    
    @Override
    public List<Map> bmData(HttpServletRequest request) {
        Map paramMap = new HashMap();
        String pId = request.getParameter("pId");
        StringBuilder builder = new StringBuilder(" SELECT * FROM GG_ZZJG WHERE 1=1 ");
        if(StringUtil.notEmpty(pId)) {
            builder.append(" AND SJBH = :pId ");
            paramMap.put("pId", pId);
        } else {
            builder.append(" AND SJBH IS NULL ");
        }
        
        builder.append(" ORDER BY SXH");
        
        List<Map> bms = baseDao.queryForList(builder.toString(),paramMap);
        return bms;
    }
    
    @Override
    public TreeNode getBmTree(HttpServletRequest request) {
        TreeNode root = new TreeNode("0","部门管理");
        
        String sql = "select * from gg_zzjg where ZT=1 order by CENGJ asc,sxh asc";
        List<Map> xtgnList = baseDao.queryForList(sql);
        Map<String, TreeNode> yjgnCache = new HashMap<String, TreeNode>();
        Map<String, TreeNode> ejgnCache = new HashMap<String, TreeNode>();
        Map<String, TreeNode> sjgnCache = new HashMap<String, TreeNode>();
        
        for (Map map : xtgnList) {
            //一级功能
            if (map.get("CENGJ").toString().equalsIgnoreCase("1")) {
                TreeNode yjTree = new TreeNode(map.get("ID").toString(),map.get("JGMC").toString());
                root.addChild(yjTree);
                yjgnCache.put(ConvertUtil.obj2Str(map.get("ID")), yjTree);
                continue;
            }
            
            
        }
        return root;
    }
    @Override
    public String getBmNameById(String bmId) {
        String sql = new String("SELECT JGMC FROM GG_ZZJG WHERE ID = :bmId");
        return baseDao.queryForString(sql,new SqlParameter("bmId",bmId));
    }
    
    public List<Map> getBmtree() {
        String sql="SELECT * FROM GG_ZZJG WHERE ZT=1 ORDER BY CENGJ,SXH";
        
        List<Map> categoryList = baseDao.queryForList(sql);
        
        List<Map> resultList = new LinkedList<Map>();
        
        Map<String, Map> yjgnCache = new HashMap<String, Map>();
        Map<String, Map> ejgnCache = new HashMap<String, Map>();
        Map<String, Map> sjgnCache = new HashMap<String, Map>();
        
        for (Map map : categoryList) {
            String level = map.get("CENGJ").toString();
            
            //一级树
            if (level.equalsIgnoreCase("1")) {
                yjgnCache.put(map.get("ID").toString(), map);
                List<Map> ejgnList = new LinkedList<Map>();
                map.put("ejTree", ejgnList);
                resultList.add(map);
                continue;
            }
            //二级树
            if (level.equalsIgnoreCase("2")) {
                Map yjgnMap = yjgnCache.get(map.get("SJBH").toString());
                List<Map> list = (List<Map>)yjgnMap.get("ejTree");
                map.put("sjTree", new LinkedList<Map>());
                list.add(map);
                
                ejgnCache.put(map.get("ID").toString(), map);
                continue;
            }
            //三级树
            if (level.equalsIgnoreCase("3")) {
                if(null!=map.get("SJBH")){
                    Map ejgnMap = ejgnCache.get(map.get("SJBH").toString());
                    List<Map> list = (List<Map>)ejgnMap.get("sjTree");
                    list.add(map);
                }
            }
        }
        return resultList;
    }
    
}