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
package com.vci.server.framework.systemConfig.stafforgmanage.combination;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.hibernate.HibernateException;
import org.hibernate.type.Type;
 
import com.vci.server.base.persistence.dao.BaseService;
import com.vci.server.base.persistence.dao.HibernateCallback;
import com.vci.server.base.persistence.dao.HibernateTemplate;
import com.vci.server.framework.systemConfig.stafforgmanage.passwordStrategy.PasswordStrategyDaoImpl;
import com.vci.server.framework.systemConfig.stafforgmanage.role.RoleDAOImpl;
 
public class CombinationService extends BaseService {
    /**
     * 获取所有密码组合方式
     * <p>Description: </p>
     * 
     * @author wangxl
     * @time 2013-1-3
     * @return
     */
    @SuppressWarnings("rawtypes")
    public List getAllList() {
        return (List)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                CombinationDAOImpl impl = new CombinationDAOImpl();
                return impl.loadAll();
            }
        });
    }
    @SuppressWarnings("rawtypes")
    public List fetchCombinationsByPstId(final String pstId) {
        return (List)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                CombinationDAOImpl impl = new CombinationDAOImpl();
                String sql = "select c.* from PLCOMBINATION c where c.PLUID in " +
                        "(select t.PLCOMBINATIONUID " +
                        "from PLCOMBINATIONPASSWORDSTRATEGY t " +
                        "where t.PLPASSWORDSTRATEGYUID = '"+pstId+"')";
                Object[] values = new Object[0];
                List<Combination> list = impl.findEntites(sql, values, "c", Combination.class);
                return list;
            }
        });
    }
    /**
     * 分页查询组合方式
     */
    
    public List fetchCombinationsToPage(final int pageIndex, final int pageSize){
        return (List)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                CombinationDAOImpl impl = new CombinationDAOImpl();
                String hsql = "select * from plcombination p order by p.PLNAME";
                String sql = getPageSQL(hsql,pageSize,pageIndex);
                Object [] o = {};
                return impl.findEntites(sql,o, "", Combination.class);
                //return impl.loadAll();
            }
        });
        
        
    }
    public List getCombinationsObjById(final String id) {
        return (List)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                PasswordStrategyDaoImpl impl = new PasswordStrategyDaoImpl();
                String sql = " select * from plcombination u where u.pluid = '"+id+"' ";                
                Object [] o = {};
                return impl.findEntites(sql,o, "", Combination.class);
            }
        });
    }
    /**
     * 添加密码组合方式
     * <p>Description: </p>
     * 
     * @author wangxl
     * @time 2013-1-3
     * @param comb
     */
    public void saveCombination(final Combination comb){
        new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                CombinationDAOImpl impl = new CombinationDAOImpl();
                comb.setUserEntity(userEntity);
                impl.save(comb);
                return comb;
            }
        });
    }
 
    public boolean updateCombination(final Combination comb){
        return (Boolean)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                CombinationDAOImpl impl = new CombinationDAOImpl();
                Combination cComb = impl.getById(comb.getId());
                if (cComb == null) {
                    comb.setUserEntity(userEntity);
                    impl.saveOrUpdate(comb);
                } else {
                    cComb.setName(comb.getName());
                    cComb.setDesc(comb.getDesc());
                    cComb.setUpdateTime(comb.getUpdateTime() );
                    cComb.setUpdateUser(comb.getUpdateUser());
                    cComb.setUserEntity(userEntity);
                    impl.saveOrUpdate(cComb);
                }
                return true;
            }
        });
    }
    public boolean deleteCombinationByMQL(final String[] ids) {
        return (Boolean)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                int len = ids.length;
                String inStr = "";
                for (int i = 0; i < len; i++) {
                    inStr += "?";
                    if (i != len - 1) {
                        inStr += ",";
                    }
                }
                CombinationDAOImpl impl = new CombinationDAOImpl();
                String hql = "delete Combination c where c.id in (" + inStr + ")";
                impl.deleteQueryObject(hql, ids, userEntity);
                
                CombinationValueDAOImpl valIImpl = new CombinationValueDAOImpl();
                String shql = "delete CombinationValue cv where cv.parentId in (" + inStr + ")";
                valIImpl.deleteQueryObject(shql, ids, userEntity);
                return true;
            }
        });
    }
    //分页查询
    public String getPageSQL(String sql, int pageSize, int pageIndex ){
        if(pageIndex <= 0){
            pageIndex = 1;
        }
        int startRownum = (pageIndex - 1) * pageSize + 1;
        int endRownum = pageIndex * pageSize;
        String partionSql = "" +
                "SELECT * FROM( " + 
                "    SELECT A.*,ROWNUM RN FROM( " +
                sql +
                "    ) A " +
                ") WHERE RN <= " + String.valueOf(endRownum) + " AND RN >= " + String.valueOf(startRownum);
        return partionSql;
    }
    
    public int checkCombinationIsquotedCount(final String id ){
        return (Integer)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                int count = 0;
                RoleDAOImpl impl = new RoleDAOImpl();
                String hsql = "select count(*) from plcombinationpasswordstrategy u where u.PLCOMBINATIONUID = '"+id+"'" ;
                List list = new ArrayList();
                Object[] values = new Object[0];
                Map<String,Type> map = new HashMap<String,Type>();
                list = impl.findEntitesBySQL(hsql, values,map);
                if (list != null){
                    count = Integer.valueOf(String.valueOf(list.get(0))).intValue();
                }
                return count;
            }
        });
    }
}