wangting
2025-01-16 18c43123b51a1688ab4ae01fe3d171c7d92e619b
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
package com.vci.server.framework.delegate;
import java.util.List;
 
import org.apache.commons.lang3.StringUtils;
 
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.VCIError;
import com.vci.corba.framework.data.AppConfigCategoryInfo;
import com.vci.corba.common.data.UserEntityInfo;
import com.vci.server.base.delegate.BaseDelegate;
import com.vci.server.framework.appConfig.AppConfigCategory;
import com.vci.server.framework.appConfig.AppConfigCategoryService;
import com.vci.server.framework.appConfig.AppConfigDetail;
import com.vci.server.framework.appConfig.AppConfigDetailService;
/**
* AppConfigCategory Delegate Server
*
*/
public class AppConfigCategoryDelegate extends BaseDelegate {
    AppConfigCategoryService service = null;
    public AppConfigCategoryDelegate(UserEntityInfo userEntityInfo) {
        super(userEntityInfo);
        service = new AppConfigCategoryService(this.getUserEntity());
    }
 
 
    
    /**
    * 添加、保存 AppConfigCategory 对象
    * @param info AppConfigCategoryInfo 对象
    */
    public String saveAppConfigCategory(AppConfigCategoryInfo info) throws VCIError{
        if (StringUtils.isBlank(info.id)) {
            String id = ObjectUtility.getNewObjectID36();
            info.id = id;
        }
        try{
            AppConfigCategory cInfo = service.getAppConfigCategoryByName(info.name);
            if (cInfo != null && !cInfo.getId().equals("")) {
                throw new VCIError("107001", new String[]{});
            }
            service.saveAppConfigCategory(this.convertAppConfigCategoryInfoToAppConfigCategory(info));
            
            
        } catch (VCIError ex) {
            throw ex;
        } catch(Exception ex){
            //TODO 在此处设置正确的错误编码
            throw new VCIError("107002", new String[]{});
        }
        return info.id;
    }
    
    /**
    * 修改、更新  AppConfigCategory 对象
    * @param info AppConfigCategoryInfo 对象
    */
    public boolean updateAppConfigCategory(AppConfigCategoryInfo info) throws VCIError{
        boolean res = false;
        try{
            AppConfigCategory cInfo = service.getAppConfigCategoryByName(info.name);
            if (cInfo != null && !cInfo.getId().equals(info.id)) {
                throw new VCIError("107001", new String[]{});
            }
            res = service.updateAppConfigCategory(this.convertAppConfigCategoryInfoToAppConfigCategory(info));
        }  catch (VCIError ex) {
            throw ex;
        } catch (Exception ex){
            //TODO 在此处设置正确的错误编码
            throw new VCIError("107003", new String[]{});
        }
        return res;
    }
    
    /**
    * 根据 ID 删除 AppConfigCategory 对象(批量)
    * @param ids AppConfigCategory 对象的 ID 列表
    */
    public boolean deleteAppConfigCategory(String[] ids) throws VCIError{
        boolean res = false;
        try{
            AppConfigDetailService aService = new AppConfigDetailService(this.getUserEntity());
            boolean hasDetail = aService.hasAppConfigDetail(ids);
            if (hasDetail) {
                throw new VCIError("107007", new String[]{});
            }
            res = service.deleteAppConfigCategory(ids);
        } catch (VCIError ex) {
            throw ex;
        } catch (Exception ex){
            //TODO 在此处设置正确的错误编码
            throw new VCIError("107004", new String[]{});
        }
        return res;
    }
    
    /**
    * 返回全部的   AppConfigCategory 对象
    */
    public AppConfigCategoryInfo[] getAppConfigCategorys() throws VCIError{
        AppConfigCategoryInfo[] infos = new AppConfigCategoryInfo[0];
        try{
            List<AppConfigCategory> list = service.getAppConfigCategorys();
            AppConfigCategory[] objects = list.toArray(new AppConfigCategory[]{});
            infos = this.convertAppConfigCategorysToAppConfigCategoryInfos(objects);
        }catch(Exception ex){
            //TODO 在此处设置正确的错误编码
            throw new VCIError("107005", new String[]{});
        }
        return infos;
    }
    
    /**
    * 根据 ID 返回  AppConfigCategory 对象
    * @param id AppConfigCategory 
    */
    public AppConfigCategoryInfo getAppConfigCategoryById(String id) throws VCIError{
        AppConfigCategoryInfo info = new AppConfigCategoryInfo();
        try{
            AppConfigCategory object = service.getAppConfigCategoryById(id);
            info = this.convertAppConfigCategoryToAppConfigCategoryInfo(object);
        }catch(Exception ex){
            //TODO 在此处设置正确的错误编码
            throw new VCIError("107006", new String[]{});
        }
        return info;
    }
 
    /************************* CORBA & HIBERNATE CONVERT **************************/
    /**
     * 对象转换(批量),从 Hibernate 对象转换到 Corba 对象
     * @param objects
     */
    public AppConfigCategoryInfo[] convertAppConfigCategorysToAppConfigCategoryInfos(AppConfigCategory[] objects){
        AppConfigCategoryInfo[] infos = new AppConfigCategoryInfo[objects.length];
        int i = 0;
        for(AppConfigCategory obj : objects){
            infos[i++] = this.convertAppConfigCategoryToAppConfigCategoryInfo(obj);
        }
        return infos;
    }
    
    /**
     * 对象转换,从 Hibernate 对象转换到 Corba 对象
     * @param object
     * @return
     */
    public AppConfigCategoryInfo convertAppConfigCategoryToAppConfigCategoryInfo(AppConfigCategory object){
        AppConfigCategoryInfo info = new AppConfigCategoryInfo();
        info.id = object.getId() == null ? "" : object.getId();
        info.name = object.getName() == null ? "" : object.getName();
        info.desc = object.getDesc() == null ? "" : object.getDesc();
        return info;
    }
    
    /**
     * 对象转换(批量),从 Corba 对象转换到 Hibernate 对象
     * @param infos
     * @return
     */
    public AppConfigCategory[] convertAppConfigCategoryInfosToAppConfigCategorys(AppConfigCategoryInfo[] infos){
        AppConfigCategory[] objects = new AppConfigCategory[infos.length];
        int i = 0;
        for(AppConfigCategoryInfo info : infos){
            objects[i++] = this.convertAppConfigCategoryInfoToAppConfigCategory(info);
        }
        return objects;
    }
    
    /**
     * 对象转换,从 Corba 对象转换到 Hibernate 对象
     * @param info
     * @return
     */
    public AppConfigCategory convertAppConfigCategoryInfoToAppConfigCategory(AppConfigCategoryInfo info){
        AppConfigCategory object = new AppConfigCategory();
        object.setId(info.id);
        object.setName(info.name);
        object.setDesc(info.desc);
        return object;
    }
}