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
package com.vci.server.portal.service;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.hibernate.SQLQuery;
import org.hibernate.Session;
 
import com.vci.corba.portal.data.PLTabButton;
import com.vci.server.base.persistence.dao.BaseService;
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
import com.vci.server.portal.dao.impl.PLTabButtonEntityDaoImpl;
import com.vci.server.portal.entity.PLTabButtonEntity;
import com.vci.server.portal.entity.PLTabPageEntity;
 
public class PLTabButtonEntityService extends BaseService{
    private static PLTabButtonEntityService instance = null;
    
    private PLTabButtonEntityService(){
        
    }
    
    public static PLTabButtonEntityService getInstance(){
        if(instance == null){
            instance = new PLTabButtonEntityService();
        }
        return instance;
    }
    
    /**
     * 新增对象
     * XXX 这可是单例模式加锁
     * @param obj
     * @throws Throwable 
     */
    public synchronized boolean savePLTabButtonEntity(PLTabButtonEntity obj) throws Throwable {
        try {
            PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
            //校验页签下编号是否存在
            String sqloid = "select * from pltabbutton t where t.pltableoid = '" 
                    + obj.getPlTableOId() + "' and t.plseq >= " + obj.getPlSeq();
            
            List<PLTabButtonEntity> loadAll = daoImpl.findEntites(sqloid,
                    new Object[0], "", PLTabButtonEntity.class);
            /*if(loadAll != null && !loadAll.isEmpty()) {
                return false;
            }*/
            if(loadAll != null && !loadAll.isEmpty()){
                for (PLTabButtonEntity plTabButtonEntity : loadAll) {
                    int oldSeq=plTabButtonEntity.getPlSeq();
                    plTabButtonEntity.setPlSeq((short)(plTabButtonEntity.getPlSeq()+1));
                    daoImpl.update(plTabButtonEntity);
                    updateButtonAccess(obj.getPlTableOId(),oldSeq,oldSeq+1);
                }
            }
            //..
            PLTabButtonEntity btn = daoImpl.getById(obj.getPlOId());
            if (btn == null) {
                daoImpl.saveOrUpdate(obj);
            } else {
                btn.setPlTableOId(obj.getPlTableOId());
                btn.setPlPageOId(obj.getPlPageOId());
                btn.setPlActionOId(obj.getPlActionOId());
                btn.setPlLabel(obj.getPlLabel());
                btn.setPlDesc(obj.getPlDesc());
                btn.setPlSeq(obj.getPlSeq());
                btn.setPlAreaType(obj.getPlAreaType());
                btn.setPlCreateUser(obj.getPlCreateUser());
                btn.setPlModifyTime(obj.getPlModifyTime());
                btn.setPlModifyUser(obj.getPlModifyUser());
                btn.setPlLicensOrs(obj.getPlLicensOrs());
                btn.setPlParentOid(obj.getPlParentOid());
                btn.setDisplayMode(obj.getDisplayMode());
                btn.setIconPath(obj.getIconPath());
                btn.setAuthorization(obj.getAuthorization());
                
                daoImpl.saveOrUpdate(btn);
            }
            return true;
        }catch(Throwable e){
            throw e;
        }
    }
    
    /**
     * 序号改后,更改按钮权限值,按钮权限是按序号按位授权的
     * @param pltableoid
     * @param oldSeq
     * @param newSeq
     */
    private void updateButtonAccess(String pltableoid, int oldSeq, int newSeq){
        Session session = HibernateSessionFactory.getSession();
        PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
        String sql="select ploid,plrightvalue from plroleright where plfuncoid='"+pltableoid+"'";
        SQLQuery query = session.createSQLQuery(sql);
        List<?> list= query.list();
        if(list.size()>0){
            for(int i=0;i<list.size();i++){
                Object[] row = (Object[]) list.get(i);
                String ploid=(String) row[0];
                BigDecimal value=(BigDecimal) row[1];
                long rightValue = value.longValue();            
                rightValue = rightValue - (long)Math.pow(2, oldSeq) + (long)Math.pow(2, newSeq);
                
                String sql2 = "update plroleright set plrightvalue="+ rightValue +" where ploid = '" + ploid + "'";
                daoImpl.createSQLQuery(sql2);        
            }
            
        }
    }
    public synchronized boolean bacthSavePLTabButtonEntity(PLTabButtonEntity[] objs) throws Throwable {
        try {
            PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
            List<PLTabButtonEntity> list = new ArrayList<PLTabButtonEntity>();
            int batchNum = 200;
            for (int i = 0; i < objs.length; i++) {
                list.add(objs[i]);
                if ((i + 1) % batchNum == 0) {
                    daoImpl.saveOrUpdateAll(list);
                    list = new ArrayList<PLTabButtonEntity>();
                }
            }
            daoImpl.saveOrUpdateAll(list);
            return true;
        }catch(Throwable e){
            throw e;
        }
    }
    
    /**
     * 更新对象
     * XXX 这可是单例模式加锁
     * @param obj
     * @return
     * @throws Throwable 
     */
    public synchronized boolean updatePLTabButtonEntity(PLTabButtonEntity obj) throws Throwable{
        try {
            //System.out.println("=====updatePLTabButtonEntity:" + obj.getPlLabel() + ";SEQ=" + obj.getPlSeq());
            
            PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
            String sql = "select * from pltabbutton t where t.pltableoid = '" 
                    + obj.getPlTableOId() + "' and t.plseq = " + obj.getPlSeq()
                    + " and t.ploid != '" + obj.getPlOId() + "'";
            
            //System.out.println("sql = " + sql);
            
            String sqloid = "select * from pltabbutton t where t.pltableoid = '" 
                    + obj.getPlTableOId() + "' and t.plseq >= " + obj.getPlSeq()
                    + " and t.ploid != '" + obj.getPlOId() + "'";
            //System.out.println("sqloid = " + sqloid);
            
            /*Session session = HibernateSessionFactory.getSession();
            SQLQuery query = session.createSQLQuery(sql);
            query.executeUpdate();
            @SuppressWarnings("rawtypes")
            List queryList = query.list();
            if (queryList != null && queryList.size() > 1) {
                return false;
            }*/
 
            Session session = HibernateSessionFactory.getSession();
            
            String oldsql="select plseq from pltabbutton where ploid='"+obj.getPlOId()+"'";
            SQLQuery query = session.createSQLQuery(oldsql);
            List<?> list= query.list();
            if(list.size()>0){
                BigDecimal value = (BigDecimal) list.get(0);
                
                this.updateButtonAccess(obj.getPlTableOId(), value.intValue(), obj.getPlSeq());
            }
            
            List<PLTabButtonEntity> loadAll = daoImpl.findEntites(sqloid,
                    new Object[0], "", PLTabButtonEntity.class);
            /*if(loadAll != null && !loadAll.isEmpty()) {
                return false;
            }*/
            daoImpl.update(obj);
            if(loadAll != null && !loadAll.isEmpty()){
                for (PLTabButtonEntity plTabButtonEntity : loadAll) {
                    String sqlsec = "select * from pltabbutton t where t.pltableoid = '" 
                            + plTabButtonEntity.getPlTableOId() + "' and t.plseq = " + plTabButtonEntity.getPlSeq()
                            + " and t.ploid != '" + plTabButtonEntity.getPlOId() + "'";
                    
                    //System.out.println("sqlsec = " + sqlsec);
 
                    List<PLTabButtonEntity> loadAlls = daoImpl.findEntites(sqlsec,
                            new Object[0], "", PLTabButtonEntity.class);
                    if(loadAlls.size()!=0){
                        int oldSeq=plTabButtonEntity.getPlSeq();
                        plTabButtonEntity.setPlSeq((short)(plTabButtonEntity.getPlSeq()+1));
                        daoImpl.update(plTabButtonEntity);    
                        this.updateButtonAccess(plTabButtonEntity.getPlTableOId(), oldSeq, oldSeq+1);
                    }
                }
            }
            /*PLTabButtonEntity objGet = daoImpl.getById(obj.getId());
            if (objGet == null) {
                daoImpl.saveOrUpdate(obj);
            } else {
                objGet.setPlTableOId(obj.getPlTableOId());
                objGet.setPlPageOId(obj.getPlPageOId());
                objGet.setPlActionOId(obj.getPlActionOId());
                objGet.setPlLabel(obj.getPlLabel());
                objGet.setPlDesc(obj.getPlDesc());
                objGet.setPlSeq(obj.getPlSeq());
                objGet.setPlAreaType(obj.getPlAreaType());
                objGet.setPlCreateUser(obj.getPlCreateUser());
                objGet.setPlModifyTime(obj.getPlModifyTime());
                objGet.setPlModifyUser(obj.getPlModifyUser());
                objGet.setPlLicensOrs(obj.getPlLicensOrs());
                objGet.setPlParentOid(obj.getPlParentOid());
                objGet.setDisplayMode(obj.getDisplayMode());
                objGet.setIconPath(obj.getIconPath());
                objGet.setAuthorization(obj.getAuthorization());
                daoImpl.saveOrUpdate(objGet);
            }*/
            
            return true;
        }catch(Throwable e){
            throw e;
        }
        
    }
    
    /**
     * 删除对象
     * XXX 这可是单例模式加锁
     * @param obj
     * @return
     * @throws Throwable 
     */
    public synchronized boolean deletePLTabButtonEntity(PLTabButtonEntity obj) throws Throwable{
        try {
            PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
            
            //删除按钮参数
            String sql = "select * from pltabbutton t where t.plparentoid = '" +obj.getPlOId()+"'";
            List<PLTabButtonEntity> loadAll = daoImpl.findEntites(sql,
                    new Object[0], "", PLTabButtonEntity.class);
            if(loadAll != null && !loadAll.isEmpty()) {
                return false;
            }                    
            String sql2 = "delete from plcommandparameter t where t.plcommandoid = '" + obj.getPlOId() + "'";
            daoImpl.createSQLQuery(sql2);            
            daoImpl.delete(obj);
            return true;
        }catch(Throwable e){
            throw e;
        }
        
    }
 
    /**
     * 根据Id删除指定的对象 
     * @param id
     * @return
     * @throws Throwable 
     */
    public boolean deletePLTabButtonEntityById(String id) throws Throwable{
        try {
            PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
            PLTabButtonEntity obj = daoImpl.getById(id);
            if (obj != null) {
                // 删除按钮参数
                String sql = "delete from plcommandparameter t where t.plcommandoid = '" + obj.getPlOId() + "'";
                daoImpl.createSQLQuery(sql);
                daoImpl.flush();
                // 删除按钮定义
                daoImpl.delete(obj);
            }
            return true;
        }catch(Throwable e){
            throw e;
        }
        
    }
 
    /**
     * 根据ID获取指定的PLTabButton
     * @param plOId
     * @return
     * @throws Throwable 
     */
    public PLTabButtonEntity getPLTabButtonEntityById(String plOId) throws Throwable {
        try {
            PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
            return daoImpl.getById(plOId);
        }catch(Throwable e){
            throw e;
        }
        
    }
 
    /**
     * 根据plTableOId获取PLTabButtonArray
     * @param plTableOId
     * @return
     * @throws Throwable 
     */
    public List<PLTabButtonEntity> getPLTabButtonEntitysByTableOId(
            String plTableOId) throws Throwable {
        try {
            PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
            List<PLTabButtonEntity> list = daoImpl.findEntities("from PLTabButtonEntity where plTableOId = '" + plTableOId + "' order by plSeq");
            Map<String, PLTabButtonEntity> mapBtn = new HashMap<String, PLTabButtonEntity>();
            for (PLTabButtonEntity btn : list) {
                mapBtn.put(btn.getPlOId(), btn);
            }
            
            List<PLTabButtonEntity> listNew = new ArrayList<PLTabButtonEntity>();
            for (PLTabButtonEntity btn : list) {
                if (btn.getPlParentOid() == null|| btn.getPlParentOid().equals("")) {
                    listNew.add(btn);
                } else if (mapBtn.containsKey(btn.getPlParentOid())) {
                    listNew.add(btn);
                } else {
                    daoImpl.delete(btn);
                    //System.out.println("删除:" + btn);
                }
            }
            return listNew;
        }catch(Throwable e){
            throw e;
        }
    }
    
    /**
     * 根据plTableOId获取PLTabButtonArray
     * @param plTableOId
     * @return
     * @throws Throwable 
     */
    public List<PLTabButtonEntity> getPLTabButtonEntitysByActionOId(
            String plActionOid) throws Throwable {
        try {
            PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
            List<PLTabButtonEntity> list = daoImpl.findEntities("from PLTabButtonEntity where plActionOId = '" + plActionOid + "' order by plSeq");
            return list;
        }catch(Throwable e){
            throw e;
        }
        
    }
    
    
    /**
     * 根据type和formName判断表单是否能被修改
     * @param type
     * @param name
     * @return
     */
    public boolean judgeUpdateButton(int type, String name, String typeName){
        boolean flag = false;
        Session session = HibernateSessionFactory.getSession();
        String judgeType = "";
        if(type==0){
            judgeType = "showType";
        }else if(type==1){
            judgeType = "linkType";
        }
        StringBuffer sql = new StringBuffer("select t.ploid from plpagedefination t where")
            .append(" dbms_lob.instr(t.pldefination,'<templateId>")
            .append(name)
            .append("</templateId>',1,1 )>0  ")
            .append("and dbms_lob.instr(t.pldefination,'<").append(judgeType)
            .append(">")
            .append(typeName)
            .append("</")
            .append(judgeType)
            .append(">',1,1 )>0 ");
            
        SQLQuery query = session.createSQLQuery(sql.toString());
        List<?> list= query.list();
        if(list!=null&&list.size()>0){
            flag=true;
        }
        return flag;
    }
    
    /**
     * 根据id判断表格是否能被删除
     * @param type
     * @param name
     * @return
     */
    public boolean judgeDeleteButton(String id, String typeName){
        boolean flag = false;
        Session session = HibernateSessionFactory.getSession();
        StringBuffer sql = new StringBuffer("select t.id from plportalvi t where 1=1 ")
        .append("and dbms_lob.instr(t.prm,'<JD_inObj>")
        .append(id)
        .append("</JD_inObj>',1,1 )>0  ")
        .append("and t.typename = '")
        .append(typeName)
        .append("' ");
        
        SQLQuery query = session.createSQLQuery(sql.toString());
        List<?> list= query.list();
        if(list!=null&&list.size()>0){
            flag=true;
        }
        return flag;
    }
    
    /**
     * 获取全量结果集,缓存使用
     * @auther lmh20150728
     * @return
     * @throws Throwable 
     */
    public List<PLTabButtonEntity> getAllPLTabButtonEntitys() throws Throwable {
        try {
            PLTabButtonEntityDaoImpl daoImpl = new PLTabButtonEntityDaoImpl();
            List<PLTabButtonEntity> list = daoImpl.findEntities("from PLTabButtonEntity order by plSeq");
            return list;
        }catch(Throwable e){
            throw e;
        }
        
    }
}