xiejun
2024-09-04 ac3f3629a261770f573f27e5e23f7ec19d096c2a
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
package com.vci.server.framework.delegate;
 
import java.util.ArrayList;
import java.util.List;
 
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Session;
 
import com.vci.common.exception.VciException;
import com.vci.common.log.ServerWithLog4j;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.VCIError;
import com.vci.corba.framework.data.FunctionInfo;
import com.vci.corba.common.data.UserEntityInfo;
import com.vci.server.base.delegate.BaseDelegate;
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
import com.vci.server.framework.funcmng.function.Function;
import com.vci.server.framework.funcmng.function.FunctionService;
 
 
/**
* <p>Title:模块处理</p>
* <p>Description: 后台处理方法的引用</p>
* <p>Copyright: Copyright {c} 2012</p>
* <p>Company: VCI</p>
* @author xf
* @time 2012-5-15
* @version 1.0
*/
public class FunctionDelegate extends BaseDelegate {
    
    private FunctionService service = null;
    
    public FunctionDelegate(UserEntityInfo userEntityInfo) {
        super(userEntityInfo);
        service = new FunctionService(userEntity);
    }
    
    public FunctionDelegate() {
        service = new FunctionService();
    }
    
    public String saveModule(FunctionInfo info) throws VCIError {
        String res = "";
        if (StringUtils.isBlank(info.id)) {
            String id = ObjectUtility.getNewObjectID36();
            info.id = id;
        }
        try{
            res = service.saveModule(changeFuncInfoToEntity(info));
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("0", new String[0]);
        }
        return res;
    }
    
    public String updateModule(FunctionInfo info) throws VCIError {
        String res = "";
        try{
            res = service.updateModule(changeFuncInfoToEntity(info));
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("0", new String[0]);
        }
        return res;
    }
    
    public String deleteModule(String id) throws VCIError {
        String res = "";
        try{
            res = service.deleteModule(id);
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("0", new String[0]);
        }
        return res;
    }
    
//    public FunctionInfo[] getModuleListByParentId(String parentId,boolean isAll) throws VCIError {
//        List<FunctionInfo> functions = null;
//        try{
//            List<Function> list = service.getModuleListByParentId(parentId,isAll);
//            functions = new ArrayList<FunctionInfo>();
//            List<String> filterFunctionNOs = new SpecialRoleDelegate().getFilterFunctionNOs();    
//            if(list.size() > 0){
//                for(int i = 0;i < list.size() ;i++){
//                    Function function = list.get(i);
//                    if(isAll || !filterFunctionNOs.contains(function.getModuleNo() + "")){
//                        functions.add(changeFuncEntityToInfo(list.get(i)));
//                    }
//                }
//            }
//        }catch (Exception e) {
//            e.printStackTrace();
//            throw new VCIError("0", new String[0]);
//        }
//        return functions.toArray(new FunctionInfo[0]);
//    }
    public FunctionInfo[] getModuleListByParentId(String parentId,boolean isAll) throws VCIError {
        FunctionInfo[] functions = null;
        try{
            List<Function> list = service.getModuleListByParentId(parentId,isAll);
            functions = new FunctionInfo[list.size()];
            if(list.size() > 0){
                for(int i = 0;i < list.size() ;i++){
                    functions[i] = changeFuncEntityToInfo(list.get(i));
                }
            }
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("0", new String[0]);
        }
        return functions;
    }
    
    
    /**
     * 根据父节点ID获取其所有的子节点模块
     * 
     * @param parentId
     * @param isAll
     * @return
     * @throws VCIError
     */
    public FunctionInfo[] getChildrenFunctionsByParentId(String parentId, boolean isAll) throws VCIError {
        FunctionInfo[] functions = null;
        try{
            List<Function> list = service.getChildrenFunctionsByParentId(parentId, isAll);
            functions = new FunctionInfo[list.size()];
            if(list.size() > 0){
                for(int i = 0;i < list.size() ;i++){
                    functions[i] = changeFuncEntityToInfo(list.get(i));
                }
            }
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("120701", new String[0]);
        }
        return functions;
    }
    
    public FunctionInfo[] getModuleListByParentIdForBS(String parentId,boolean isAll) throws VCIError {
        FunctionInfo[] functions = null;
        try{
            List<Function> list = service.getModuleListByParentIdForBS(parentId,isAll);
            functions = new FunctionInfo[list.size()];
            if(list.size() > 0){
                for(int i = 0;i < list.size() ;i++){
                    functions[i] = changeFuncEntityToInfo(list.get(i));
                }
            }
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("0", new String[0]);
        }
        return functions;
    }
    public FunctionInfo[] getModuleListByParentIdForCS(String parentId,boolean isAll) throws VCIError {
        FunctionInfo[] functions = null;
        try{
            List<Function> list = service.getModuleListByParentIdForCS(parentId,isAll);
            functions = new FunctionInfo[list.size()];
            if(list.size() > 0){
                for(int i = 0;i < list.size() ;i++){
                    functions[i] = changeFuncEntityToInfo(list.get(i));
                }
            }
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("0", new String[0]);
        }
        return functions;
    }
    
    public FunctionInfo[] getModuleListByRoleRight(String parentId,String userName) throws VCIError {
        FunctionInfo[] functions = null;
        try{
            List<Function> list = service.getModuleListByRoleRight(parentId,userName);
            functions = new FunctionInfo[list.size()];
            if(list.size() > 0){
                for(int i = 0;i < list.size() ;i++){
                    functions[i] = changeFuncEntityToInfo(list.get(i));
                }
            }
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("0", new String[0]);
        }
        return functions;
    }
    public FunctionInfo[] getModuleListByRoleRightForBS(String parentId,String userName) throws VCIError {
        FunctionInfo[] functions = null;
        try{
            List<Function> list = service.getModuleListByRoleRightForBS(parentId,userName);
            functions = new FunctionInfo[list.size()];
            if(list.size() > 0){
                for(int i = 0;i < list.size() ;i++){
                    functions[i] = changeFuncEntityToInfo(list.get(i));
                }
            }
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("0", new String[0]);
        }
        return functions;
    }
    public FunctionInfo getModuleByClass(String classPath) throws VCIError {
        FunctionInfo function = null;
        try{
            Function fun = service.getModuleByClass(classPath);
            function = changeFuncEntityToInfo(fun);
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("200006", new String[0]);
        }
        return function;
    }
    /**
     * 
     * <p>根据模块funcOid信息查询出模块对象的信息</p>
     * 
     * @author xchao
     * @time 2014-6-6
     * @param funcOid
     * @return
     * @throws VciException
     */
    public FunctionInfo getFunctionObjectById(String funcOid) throws VCIError{
        FunctionInfo function = new FunctionInfo();
        try{
            Function fun = service.getFunctionObjectById(funcOid);
            if(fun != null){
                function = changeFuncEntityToInfo(fun);
            }
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("200006", new String[0]);
        }
        return function;
    }
    public FunctionInfo getModuleByName(String moduleName) throws VCIError {
        FunctionInfo function = null;
        try{
            Function fun = service.getModuleByName(moduleName);
            function = changeFuncEntityToInfo(fun);
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("200006", new String[0]);
        }
        return function;
    }
    
//    public int getAutoModuleNo() throws VCIError {
//        int res = 0;
//        try {
//            res = service.getAutoModuleNo();
//        } catch (Exception e) {
//            //e.printStackTrace();
//            ServerWithLog4j.logger.error(e);
//            throw new VCIError("110100", new String[0]);
//        }
//        return res;
//    }
    
    public int checkChildObject(String moduleId) throws VCIError {
        int res = 0;
        try{
            res = service.checkChildObject(moduleId);
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("0", new String[0]);
        }
        return res;
    }
    
    /**
     * <p>Description: corba对象和实体类之间的转换</p>
     *
     *@author xf
     *@time 2012-5-15
     *@return PlFunctionEntity
     * @param info
     * @return
     */
    public Function changeFuncInfoToEntity(FunctionInfo info) throws VCIError{
        Function entity = new Function();
        try {
            entity.setId(info.id);
            //entity.setLayer(info.layer);
            entity.setName(info.name);
            entity.setParentId(info.parentId);
            entity.setResourceC(info.resourceC);
            entity.setSuffixC(info.suffixC);
            entity.setDesc(info.desc);
            entity.setResourceB(info.resourceB);
            entity.setSuffixB(info.suffixB);
            entity.setSequence(info.seq);
            //entity.setModuleNo(info.moduleNo);
            entity.setImage(info.image);
            entity.setIsValid(info.isValid);
            entity.setAliasName(info.aliasName);
            entity.setResourceDotNet(info.resourceDotNet);
            entity.setResourceMobile(info.resourceMobile);
        } catch(Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("110004", new String[0]);//类型转换失败
        }
        return entity;
    }
    
    /**
     * <p>Description: 实体类转换成corba对象</p>
     *
     *@author xf
     *@time 2012-5-15
     *@return FunctionInfo
     * @param entity
     * @return
     */
    public FunctionInfo changeFuncEntityToInfo(Function entity) throws VCIError {
        FunctionInfo info = new FunctionInfo();
        try {
            info.id = entity.getId() == null ?"" : entity.getId();
            //info.layer = entity.getLayer();
            info.name = entity.getName() == null ?"" : entity.getName();
            info.parentId = entity.getParentId() == null ?"" : entity.getParentId();
            info.desc = entity.getDesc() == null ?"" : entity.getDesc();
            info.suffixC = entity.getSuffixC() == null ?"" : entity.getSuffixC();
            info.resourceC = entity.getResourceC() == null ?"" : entity.getResourceC();
            info.resourceB = entity.getResourceB() == null ?"" : entity.getResourceB();
            info.suffixB = entity.getSuffixB() == null ?"" : entity.getSuffixB();
            info.seq = entity.getSequence();
            info.image = entity.getImage() == null ? "" : entity.getImage();
            info.isValid = entity.getIsValid();
            info.aliasName = entity.getAliasName() == null ? "" : entity.getAliasName();
            info.resourceDotNet = entity.getResourceDotNet() == null ? "" : entity.getResourceDotNet();
            info.resourceMobile = entity.getResourceMobile() == null ? "" : entity.getResourceMobile();
        } catch(Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("110004", new String[0]);//类型转换失败
        }
        return info;
    }
 
    /**
     * flag:nonsys删除非系统模块
     * flag:business删除业务模块
     * @throws VCIError 
     */
    public boolean deleteModules(String flag) throws VCIError {
        try{
            String conditionSql = null;
            if(flag.equalsIgnoreCase("nonsys")){
                conditionSql = "where plmoduleno not like '1%'";
            }else if(flag.equalsIgnoreCase("business")){
                conditionSql = "where plmoduleno like '5%' or plmoduleno like '6%' or plmoduleno like '7%' or plmoduleno like '8%' or plmoduleno like '9%'";
            }
            
            if(conditionSql == null){
                return true;
            }
            String delFuncOperation = "delete from plfuncoperation where plfuncoid in (select ploid from plfunction " + conditionSql + " )";
            String delRoleRight = "delete from plroleright where plfuncoid in (select ploid from plfunction " + conditionSql + " )";
            String delFunction = "delete from plfunction " + conditionSql;
            Session session = HibernateSessionFactory.getSession();
            session.createSQLQuery(delFuncOperation).executeUpdate();
            session.createSQLQuery(delRoleRight).executeUpdate();
            session.createSQLQuery(delFunction).executeUpdate();
        }catch(Throwable e){
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("110006", new String[0]);
        }
        
        return true;
    }
    
    /**
     * 
     * 查询"功能模块管理"整个树结构并导出sql
     * add by caill start 2015.12.8
     * */
    public String[][] getAllDatas(int size) throws VCIError {
        String[][] res = new String[size][23];
        try{
            res = service.getAllDatas(size);
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError();
        }
        return res;
    }
    /**
     * 
     * 获取所有操作类型数量
     * add by caill start 2015.12.8
     * */
    public int getAllModelManagementNum() throws VCIError {
        int res = 0;
        try{
            res = service.getAllModelManagementNum();
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError();
        }
        return res;
    }
    //add by caill end
    
    /**
     * 
     * 查询"功能模块管理"整个树结构并导出
     * add by caill start
     * */
    public String[][] checkLevel() throws VCIError {
        String[][] res = new String[3000][23];
        try{
            res = service.checkLevel();
        }catch (Exception e) {
            ///e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("0", new String[0]);
        }
        return res;
    }
    //add by caill end
    
    /**
     * 导入“功能模块管理”数据
     * add by caill start
     * */
    public boolean importModules(FunctionInfo info) throws VCIError {
        String res = "";
        if (StringUtils.isBlank(info.id)) {
            String id = ObjectUtility.getNewObjectID36();
            info.id = id;
        }
        try{
            res = service.importModules(changeFuncInfoToEntity(info));
        }catch (Exception e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
            throw new VCIError("0", new String[0]);
        }
        return true;
    }
    /**
     * 查询“功能模块管理”第一级数据
     * add by caill 
     * */
    public boolean firstLevel(String plName) throws VCIError {
        
        
            return service.firstLevel(plName);
        
        
    }
    /**
     * 覆盖“功能模块管理”第一级重名的数据
     * add by caill 
     * */
    public String changeFirstLevel(FunctionInfo functionInfo,String plName) throws VCIError {
        
        
            return service.changeFirstLevel(changeFuncInfoToEntity(functionInfo), plName);
        
        
    }
    /**
     * 查询“功能模块管理”第二级数据
     * add by caill 
     * */
    public boolean secondLevel(String plName,String fParentId) throws VCIError {
        
        
            return service.secondLevel(plName,fParentId);
        
        
    }
    /**
     * 覆盖“功能模块管理”第二级重名的数据
     * add by caill 
     * */
    public String changeSecondLevel(FunctionInfo functionInfo,String plName,String fParentId) throws VCIError {
        
        
            return service.changeSecondLevel(changeFuncInfoToEntity(functionInfo), plName,fParentId);
        
        
    }
}