dangsn
2024-12-26 4e9ff2ce6a830bb2340d7c8612c72eea0c5a553e
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
package com.vci.server.framework.funcmng.funcOperation;
 
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
 
import org.hibernate.HibernateException;
 
import com.vci.common.objects.UserEntity;
import com.vci.server.base.persistence.dao.BaseService;
import com.vci.server.base.persistence.dao.HibernateCallback;
import com.vci.server.base.persistence.dao.HibernateCallbackExt;
import com.vci.server.base.persistence.dao.HibernateTemplate;
 
public class FuncOperationService extends BaseService{
    
    public FuncOperationService(UserEntity userEntity){
        super(userEntity);
    }
    
    public FuncOperationService(){
    }
    
    /**
     * 保存
     * @param funcOperation
     * @return
     */
    public boolean saveFuncOperation(final FuncOperation[] funcOperations){
        return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() {
            
            @Override
            public Object execute(Connection connection) throws HibernateException,
                    SQLException {
                String sql = "insert into plfuncoperation values (?,?,?,?,?,?)";
                PreparedStatement pstmt = null;
                ResultSet rs = null;
                connection.setAutoCommit(false);
                String tempSql = "select decode(max(p.plno),null,-1,max(p.plno)) as plno from plfuncoperation p where p.plfuncoid = ?";
                pstmt = connection.prepareStatement(tempSql);
                pstmt.setString(1, funcOperations[0].getFuncoid());
                rs = pstmt.executeQuery();
                int number = 0;
                if(rs.next()){
                    number = rs.getInt("plno");
                }
                rs.close();
                pstmt.close();
                number++;
                for(FuncOperation funcOperation: funcOperations){
                    pstmt = connection.prepareStatement(sql);
                    pstmt.setString(1, funcOperation.getId());
                    pstmt.setString(2, funcOperation.getFuncoid());
                    pstmt.setString(3, funcOperation.getOperoid());
                    pstmt.setInt(4, number++);
                    pstmt.setString(5, funcOperation.getOperAlias());
                    pstmt.setInt(6, funcOperation.getIsValid() ? 1 : 0);
                    pstmt.execute();
                    pstmt.close();
                }
                connection.commit();
                return true;
            }
        });
    }
    public boolean updateFuncOperation(final String id , final String alias, final boolean isSelected){
        return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() {
            @Override
            public Object execute(Connection connection) throws HibernateException,
            SQLException {
                String sql = "update plfuncoperation t set t.plalias = ? , t.PLISVALID = ? where t.ploid = ?";
                PreparedStatement pstmt = null;
                connection.setAutoCommit(false);
                pstmt = connection.prepareStatement(sql);
                pstmt.setString(1, alias);
                pstmt.setInt(2, isSelected ? 1 : 0);
                pstmt.setString(3, id);
                pstmt.executeUpdate();
                connection.commit();
                pstmt.close();
                return true;
            }
        });
    }
    
    /**
     * 获取模块下的操作,如果操作ID为空,则获取模块下的全部操作
     * @param functionId 模块ID
     * @param operateId  操作ID
     * @param onlyIsValid onlyIsValid 参数表示是否仅仅返回是生效的操作 true:是 false :不是(此时返回模块下全部的操作,仅在定义模块下的操作时需要返回全部的操作,其它情况需要均只需要返回生效的操作) 
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<FuncOperation> getFuncOperationByModule(final String functionId,final String operateId, final boolean onlyIsValid){
        return (List<FuncOperation>)new HibernateTemplate().runExt(new HibernateCallbackExt() {
            
            @Override
            public Object execute(Connection connection) throws HibernateException,
                    SQLException {
                StringBuffer sql = new StringBuffer();
                PreparedStatement pstmt = null;
                ResultSet rs = null;
                sql.append("select p.*,o.plname,o.pluniqueflag,o.pldesc from plfuncoperation p,ploperation o where p.plfuncoid = '").append(functionId).append("'");
                if(!"".equals(operateId)){
                    sql.append("and p.ploperoid = '").append(operateId).append("'");
                }
                sql.append(" and o.ploid = p.ploperoid ");
                // update by xchao 2013.06.18 begin
                // 当且仅当 onlyIsValid 为true时,才执行只返回生效的操作
                // old sql.append(" and p.PLISVALID = 1");
                // new 
                if(onlyIsValid){
                     sql.append(" and p.PLISVALID = 1");
                }
                // update by xchao 2013.06.18 begin
                pstmt = connection.prepareStatement(sql.toString());
                rs = pstmt.executeQuery();
                List<FuncOperation> ls = new ArrayList<FuncOperation>();
                while(rs.next()){
                    FuncOperation funcOperation = new FuncOperation();
                    funcOperation.setId(rs.getString("ploid"));
                    funcOperation.setFuncoid(rs.getString("plfuncoid"));
                    funcOperation.setOperoid(rs.getString("ploperoid"));
                    funcOperation.setOperName(rs.getString("plname"));
                    funcOperation.setOperAlias(rs.getString("plalias"));
                    funcOperation.setOperIndntify(rs.getString("pluniqueflag"));
                    funcOperation.setOperDesc(rs.getString("pldesc"));
                    funcOperation.setNumber(rs.getInt("plno"));
                    funcOperation.setIsValid(rs.getInt("PLISVALID") != 0);
                    ls.add(funcOperation);
                }
                rs.close();
                pstmt.close();
                return ls;
            }
        });
    }
    
    /**
     * 通过模块ID和操作标识获取挂接关系
     * @param funcId
     * @param identify
     * @return
     */
    public FuncOperation getFuncOperationByIdentify(final String funcId,final String identify){
        return (FuncOperation) new HibernateTemplate().runExt(new HibernateCallbackExt() {
            
            @Override
            public Object execute(Connection connection) throws HibernateException,
                    SQLException {
                StringBuffer sql = new StringBuffer();
                PreparedStatement pstmt = null;
                ResultSet rs = null;
                sql.append("select p.*,o.plname,o.pluniqueflag,o.pldesc from plfuncoperation p,ploperation o where p.plfuncoid = '").append(funcId).append("'");
                sql.append("and o.pluniqueflag = '").append(identify).append("'");
                sql.append("and o.ploid = p.ploperoid ");
                pstmt = connection.prepareStatement(sql.toString());
                rs = pstmt.executeQuery();
                FuncOperation funcOperation = new FuncOperation();
                if(rs.next()){
                    funcOperation.setId(rs.getString("ploid"));
                    funcOperation.setFuncoid(rs.getString("plfuncoid"));
                    funcOperation.setOperoid(rs.getString("ploperoid"));
                    funcOperation.setOperName(rs.getString("plname"));
                    funcOperation.setOperIndntify(rs.getString("pluniqueflag"));
                    funcOperation.setOperDesc(rs.getString("pldesc"));
                    funcOperation.setNumber(rs.getInt("plno"));
                    funcOperation.setIsValid(rs.getInt("PLISVALID") != 0);
                }
                rs.close();
                pstmt.close();
                return funcOperation;
            }
        });
    }
 
    /**
     * 删除
     * @param funcOperation
     * @return
     */
    public boolean deleteFuncOperation(final FuncOperation funcOperation){
        return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() {
            
            @Override
            public Object execute(Connection connection) throws HibernateException,
                    SQLException {
                String sql = "delete from plfuncoperation where plfuncoid = ? and ploperoid = ? ";
                PreparedStatement pstmt = null;
                pstmt = connection.prepareStatement(sql);
                pstmt.setString(1, funcOperation.getFuncoid());
                pstmt.setString(2, funcOperation.getOperoid());
                pstmt.execute();
                pstmt.close();
                //TODO 此处需删除权限表中该模块下该操作所对应的授权信息
                return true;
            }
        });
    }
    /**
     * 保存对象
     * add by caill start
     * */
    public String saveFunOper(final FuncOperation entity) {
        return (String) new HibernateTemplate().run(new HibernateCallback() {
            @Override
            public Object execute() throws HibernateException {
                FuncOperationDaoImpl impl = new FuncOperationDaoImpl();
                /**校验成功后保存,返回对象ID**/
                //entity.setUserEntity(userEntity);
                impl.save(entity);
                return entity.getId();
            }
        });
    }
    /**
     * 保存操作类型
     * add by aill
     * */
    public boolean saveFuncOperation2(final FuncOperation funcOperation){
        return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() {
            
            @Override
            public Object execute(Connection connection) throws HibernateException,
                    SQLException {
                String sql = "insert into plfuncoperation values (?,?,?,?,?,?)";
                PreparedStatement pstmt = null;
                ResultSet rs = null;
                connection.setAutoCommit(false);
                pstmt = connection.prepareStatement(sql);
                pstmt.setString(1, funcOperation.getId());
                pstmt.setString(2, funcOperation.getFuncoid());
                pstmt.setString(3, funcOperation.getOperoid());
                pstmt.setInt(4, (int)funcOperation.getNumber());
                pstmt.setString(5, funcOperation.getOperAlias());
                pstmt.setInt(6, funcOperation.getIsValid() ? 1 : 0);
                pstmt.execute();
                
                pstmt.close();
                connection.commit();
                return true;
            }
        });
    }
    /**
     * 查询同一模块中是否存在相同的操作类型
     * add by caill
     * */
    public boolean selSameOper(final String dataOperName,final String plFuncOid){
        return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() {
            @Override
            public Object execute(Connection connection) throws HibernateException,
                    SQLException {
                
                boolean same=false;
                PreparedStatement pstmt = null;
                ResultSet rs = null;
                //select ploid from ploperation where plname='"+dataOperName+"'
                String sql="select * from plfuncoperation where ploperoid in (select ploid from ploperation where plname='"+dataOperName+"') and plfuncoid='"+plFuncOid+"'";
                pstmt = connection.prepareStatement(sql);        
                rs = pstmt.executeQuery();
                while(rs.next()){
                    same=true;
                }
                rs.close();    
                pstmt.close();        
                return same;
            }
        });
        
    }
    /**
     * 覆盖操作类型
     * add by caill
     * */
    public boolean updateOperation(final FuncOperation funcOperation,final String dataOperName,final String plFuncOid){
        return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() {
            
            @Override
            public Object execute(Connection connection) throws HibernateException,
                    SQLException {    
                PreparedStatement pstmt = null;
                String sql="update plfuncoperation set plno = ? , plalias = ? , plisvalid = ?   where plfuncoid='"+plFuncOid+"' and ploperoid in (select ploid from ploperation where plname='"+dataOperName+"')";    
                pstmt = connection.prepareStatement(sql);
                pstmt.setInt(1, (int)funcOperation.getNumber());
                pstmt.setString(2, funcOperation.getOperAlias());
                pstmt.setInt(3, funcOperation.getIsValid() ? 1 : 0);
                pstmt.executeUpdate();
                //rs.close();
                pstmt.close();        
                return true;
            }
        });
    }
}