ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
package com.vci.server.portal.service;
 
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
 
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.omg.CORBA.IntHolder;
 
import com.vci.server.base.persistence.dao.BaseService;
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
import com.vci.server.portal.dao.impl.PortalVIEntityDaoImpl;
import com.vci.server.portal.entity.PortalVIEntity;
import com.vci.server.portal.tools.ServerTool;
import com.vci.corba.portal.data.PortalVI;
 
public class PortalVIEntityService extends BaseService{
    private static PortalVIEntityService instance = null;
    
    private PortalVIEntityService(){
        
    }
    
    public static PortalVIEntityService getInstance(){
        if(instance == null){
            instance = new PortalVIEntityService();
        }
        return instance;
    }
    
    /**
     * 新增视图对象
     * @param obj
     * @throws Throwable 
     */
    public boolean savePortalVIEntity(PortalVIEntity obj) throws Throwable {
        try {
            PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
            impl.saveOrUpdate(obj);
            return true;
        } catch (Throwable e) {
            throw e;
        }
    }
    
    public boolean batchSavePortalVIEntity(PortalVIEntity[] objs) throws Throwable {
        try {
            PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
            List<PortalVIEntity> list = new ArrayList<PortalVIEntity>();
            int batchNum = 200;
            for (int i = 0; i < objs.length; i++) {
                list.add(objs[i]);
                if ((i + 1) % batchNum == 0) {
                    impl.saveOrUpdateAll(list);
                    list = new ArrayList<PortalVIEntity>();
                }
            }
            impl.saveOrUpdateAll(list);
            return true;
        } catch (Throwable e) {
            throw e;
        }
    }
    
    /**
     * 更新视图对象
     * @param obj
     * @return
     * @throws Throwable 
     */
    public boolean updatePortalVIEntity(PortalVIEntity obj) throws Throwable{
        try{
            PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
            PortalVIEntity objGet = impl.getById(obj.getId());
            if (objGet == null) {
                impl.saveOrUpdate(obj);
            } else {
                // objGet.setId(obj.getId());
                objGet.setTypeFlag(obj.getTypeFlag());
                objGet.setTypeName(obj.getTypeName());
                objGet.setViName(obj.getViName());
                objGet.setViType(obj.getViType());
                objGet.setPrm(obj.getPrm());
                impl.saveOrUpdate(objGet);
            }
            return true;
        }catch (Throwable e) {
            throw e;
        }
    }
    
    /**
     * 删除视图对象
     * @param obj
     * @return
     * @throws Throwable 
     */
    public boolean deletePortalVIEntity(PortalVIEntity obj) throws Throwable{
        try{
            PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
            impl.delete(obj);
            return true;
        }catch (Throwable e) {
            throw e;
        }
        
    }
 
    /**
     * 根据Id删除指定的对象
     * @param id
     * @return
     * @throws Throwable 
     */
    public boolean deletePortalVIEntityById(String id) throws Throwable{
        try{
            PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
            PortalVIEntity obj = impl.getById(id);
            if (obj != null) {
                impl.delete(obj);
            }
            return true;
        }catch (Throwable e) {
            throw e;
        }
        
    }
    
    /**
     * 获取指定ID的PortalVIEntity
     * @param id
     * @return
     * @throws Throwable 
     */
    public PortalVIEntity getPortalVIEntityById(String id) throws Throwable{
        try{
            PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
            PortalVIEntity obj = impl.getById(id);
            return obj;
        }catch (Throwable e) {
            throw e;
        }
    }
    
    /**
     * 根据标示获取标示对应的定义
     * @param symbol
     * @return
     * @throws Throwable
     */
    public PortalVIEntity getPortalVIBySymbol (String symbol) throws Throwable{
        try{
            try{
                PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
                PortalVIEntity obj = impl.findEntity("from PortalVIEntity where viName = '" + symbol + "'");
                return obj;
            }catch(Throwable e){
                throw e;
            }
        }catch (Throwable e) {
            throw e;
        }
    }
    
    /**
     * 获取指定类型下的所有视图
     * @param typeName
     * @return
     * @throws Throwable 
     */
    public PortalVI[] getPortalVIArrayByTypeName(String typeName) throws Throwable{
        try{
            PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
            List<PortalVIEntity> list = impl.findEntities("select p from PortalVIEntity p where typeName = '" + typeName + "'");
            if(list == null || list.size() < 0){
                return new PortalVI[0];
            }
            List<PortalVI> list_ = new ArrayList<PortalVI>();
            for(int i = 0; i < list.size(); i++){
                PortalVI obj = ServerTool.getPortalVI(list.get(i));
                if(obj != null){
                    list_.add(obj);
                }
            }
            return list_.toArray(new PortalVI[0]);
        }catch (Throwable e) {
            throw e;
        }
    }
    
    public int getPortalVICountByTypeName(String typeName) throws Throwable{
        try{
            String sql = "select count(*) from plportalvi p where typeName = '" + typeName + "'";
            Session session = HibernateSessionFactory.getSession();
            SQLQuery query = session.createSQLQuery(sql);
            List queryList = query.list();
            Object array = (Object)queryList.get(0);
            int count = ((BigDecimal) array).intValue();
            return count;
        }catch (Throwable e) {
            throw e;
        }
    }
    
    public int getPortalVICountByCondition(String typeName, int sheetType,
            String sheetName) throws Throwable{
        try{
            String sql = "select count(*) from plportalvi p where typeName = '" + typeName + "'";
            if (sheetType != -1) {
                sql += " and vitype = " + sheetType;
            }
            if (!sheetName.trim().equals("")) {
                sql += " and viname like '%" + sheetName + "%' "; 
            }
            Session session = HibernateSessionFactory.getSession();
            SQLQuery query = session.createSQLQuery(sql);
            List queryList = query.list();
            Object array = (Object)queryList.get(0);
            int count = ((BigDecimal) array).intValue();
            return count;
        }catch (Throwable e) {
            throw e;
        }
    }
    
    /**
     * 分页查找当前业务类型下的表单和表格
     * @param typeName
     * @param startPage
     * @param endPage
     * @return
     * @throws Throwable
     */
    public PortalVI[] getPagePortalVIArrayByTypeName(String typeName, int startPage, int endPage) throws Throwable{
        try{
            PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
            String sql = "select {c.*} from (select * from (select a.*, rownum rn from (" + 
                    "select * from plportalvi p where typeName = '" + typeName + "') a where rownum < " + endPage + ") b where rn >= " + startPage + ") c";
            List<PortalVIEntity> list = impl.findEntites(sql, new String[0], "c", PortalVIEntity.class);
            
            if(list == null || list.size() < 0){
                return new PortalVI[0];
            }
            List<PortalVI> list_ = new ArrayList<PortalVI>();
            for(int i = 0; i < list.size(); i++){
                PortalVI obj = ServerTool.getPortalVI(list.get(i));
                if(obj != null){
                    list_.add(obj);
                }
            }
            return list_.toArray(new PortalVI[0]);
        }catch (Throwable e) {
            throw e;
        }
    }
    
    /**
     * 分页查找当前业务类型下的表单和表格
     * @param typeName
     * @param startPage
     * @param endPage
     * @return
     * @throws Throwable
     */
    public PortalVI[] getPagePortalVIArrayByCondition(String typeName, int sheetType, String sheetName, int startPage, int endPage) throws Throwable{
        try{
            PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
            String sql = "select {c.*} from (select * from (select a.*, rownum rn from (" + 
                    "select * from plportalvi p where typeName = '" + typeName + "'";
            if (sheetType != -1) {
                sql += " and viType = " + sheetType; 
            }
            if (!sheetName.trim().equals("")) {
                sql += " and viname like '%" + sheetName + "%' "; 
            }
            sql += ") a where rownum < " + endPage + ") b where rn >= " + startPage + ") c";
            List<PortalVIEntity> list = impl.findEntites(sql, new String[0], "c", PortalVIEntity.class);
            
            if(list == null || list.size() < 0){
                return new PortalVI[0];
            }
            List<PortalVI> list_ = new ArrayList<PortalVI>();
            for(int i = 0; i < list.size(); i++){
                PortalVI obj = ServerTool.getPortalVI(list.get(i));
                if(obj != null){
                    list_.add(obj);
                }
            }
            return list_.toArray(new PortalVI[0]);
        }catch (Throwable e) {
            throw e;
        }
    }
 
    public PortalVI[] getPortalVIByQueryInfo(String typeName, int typeFlag,
            String viName, int viType, IntHolder total) {
        //TODO
        return null;
    }
    /**
     * 根据翻页参数返回表单
     * @param typeName 表单所在类型名称
     * @param viName 表单名称 模糊查询
     * @param viType 表单类型 PortalVIType.Table|Form
     * @param viTypeFlag 表单类型标识 PortalVITypeFlag.BtmType|LinkType
     * @param pageIndex 页号
     * @param pageSize 页大小
     * @param total 输出参数总数
     * @return
     * @throws Throwable
     */
    public PortalVI[] getPagePortalVIArrayByPageInfo(String typeName,
            String viName, short viType, short viTypeFlag, long pageIndex,
            long pageSize, IntHolder total) throws Throwable {
        String fromField = "vi.id,vi.typename,vi.viname,vi.vitype,vi.typeflag ";
        String countField = " count(1) count_ ";
        String where = "1=1";
        if(!"".equals(typeName)){
            where += " and vi.typename = '" + typeName + "' ";
        }
        if(!"".equals(viName)){
            where += " and vi.viname like '%" + viName + "%' ";
        }
        if(viType != -1){
            where += " and vi.vitype = " + viType + " ";
        }
        if(viTypeFlag != -1){
            where += " and vi.typeflag = " + viTypeFlag + " ";
        }
        String orderBy = "order by vi.viname";
        long begin = (pageIndex <= 1 ? 1 : ((pageIndex - 1) * pageSize) + 1);
        long end = (pageIndex <= 0 ? pageSize : pageIndex * pageSize);
        String sql = "" +
                "select * from(" +
                "    select row_.*,rownum rownum_ from(" +
                "        select " + fromField + " from plportalvi vi where " + where + " " + orderBy + "" +
                "    ) row_" +
                ") where rownum_ >= " + String.valueOf(begin) + " and rownum_ <= " + String.valueOf(end);
        PortalVI[] res = new PortalVI[0];
        List<PortalVI> vis = new ArrayList<PortalVI>();
        try{
            SQLQuery sqlQuery = HibernateSessionFactory.getSession().createSQLQuery(sql);
            @SuppressWarnings("unchecked")
            List<Object[]> list = sqlQuery.list();
            for(Object[] obj : list){
                vis.add(getPortalVI(obj));
            }
            res = vis.toArray(new PortalVI[0]);
            
            sql = "select " + countField + " from plportalvi vi where " + where + " ";
            
            sqlQuery = HibernateSessionFactory.getSession().createSQLQuery(sql);
            
            List<BigDecimal> temp = sqlQuery.list();
            if (temp.size() > 0 && temp.get(0) != null)
                total.value = temp.get(0).intValue();
            else
                total.value = 0;
            
        }catch(Exception ex){
            ex.printStackTrace();
        }finally{
        }
        return res;
    }
    private PortalVI getPortalVI(Object[] obj) throws SQLException{
        PortalVI vi = new PortalVI();
        vi.id = (String) (obj[0] == null ? "" : obj[0]);
        vi.typeName = (String) (obj[1] == null ? "" : obj[1]);
        vi.viName = (String) (obj[2] == null ? "" : obj[2]);
        vi.viType = Short.valueOf((obj[3] == null ? "0" : obj[3].toString()));
        vi.typeFlag = ((BigDecimal) (obj[4] == null ? "" : obj[4])).shortValue();
        return vi;
    }
 
 
    /**
     * 根据OID级联删除表单
     * @param oids 表单 oids
     * @return
     * @throws Throwable
     */
    public boolean deletePagePortalVIForCascade(String[] oids) throws Throwable {
        //TODO
        return false;
    }
 
    /**
     * 根据类型名和视图名获取视图
     * @param typeName
     * @param viName
     * @return
     * @throws Throwable 
     */
    public PortalVIEntity getPortalVIEntityByTypeNameAndVIName(String typeName,
            String viName) throws Throwable {
        try{
            PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
            
            PortalVIEntity obj = impl.findEntity("from PortalVIEntity where typeName = '" + typeName
                    + "' and viName = '" + viName + "'");
            return obj;
        }catch(Throwable e){
            throw e;
        }
    }
    
    /**
     * 根据业务类型名称和代号模糊查询符合要求的表单定义
     * @param viName
     * @param typeName
     * @return
     * @throws Throwable
     */
    public PortalVI[] getPortalVIBySymbolAndTypeName(String viName,
            String typeName) throws Throwable {
        try{
            PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
            
            List<PortalVIEntity> list = impl.findEntities("from PortalVIEntity where typeName = '" + typeName
                    + "' and viName like '%" + viName + "%'");
            if(list == null || list.size() < 0){
                return new PortalVI[0];
            }
            List<PortalVI> list_ = new ArrayList<PortalVI>();
            for(int i = 0; i < list.size(); i++){
                PortalVI obj = ServerTool.getPortalVI(list.get(i));
                if(obj != null){
                    list_.add(obj);
                }
            }
            return list_.toArray(new PortalVI[0]);
        }catch(Throwable e){
            throw e;
        }
    }
    
    /**
     * @author lmh,20150805
     * 获取所有结果集,缓存使用
     * @return
     */
    public PortalVI[] getAllPortalVI() throws Throwable{
        try{
            PortalVIEntityDaoImpl impl = new PortalVIEntityDaoImpl();
            List<PortalVIEntity> list = impl.findEntities("select p from PortalVIEntity p ");
            if(list == null || list.size() < 0){
                return new PortalVI[0];
            }
            List<PortalVI> list_ = new ArrayList<PortalVI>();
            for(int i = 0; i < list.size(); i++){
                PortalVI obj = ServerTool.getPortalVI(list.get(i));
                if(obj != null){
                    list_.add(obj);
                }
            }
            return list_.toArray(new PortalVI[0]);
        }catch (Throwable e) {
            throw e;
        }
    }
}