dangsn
2024-06-11 dba1e53cd7652f1b973ffec118e5b3312278c814
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
package com.vci.server.framework.systemConfig.specialchar;
 
 
import java.util.List;
 
import org.hibernate.HibernateException;
 
import com.vci.server.base.persistence.dao.BaseService;
import com.vci.server.base.persistence.dao.HibernateCallback;
import com.vci.server.base.persistence.dao.HibernateTemplate;
 
 
public class SpecialCharService extends BaseService {
    
    //特殊字符 (操作模块)
    private final String SPECIALCHAR = "特殊字符";
 
    /**
     * 
     * <p>Description:保存特殊字符 </p>
     * 
     * @author sunbo
     * @time 2012-5-25
     * @param schar
     */
    public void saveSpecialChar(final SpecialChar schar) {
        new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                SpecialCharDAOImpl impl = new SpecialCharDAOImpl();
                userEntity.setModule(SPECIALCHAR);
                schar.setUserEntity(userEntity);
                impl.save(schar);
                return schar;
            }
        });
    }
    //更新特殊字符
    public void updateSpecialChar(final SpecialChar schar) {
        new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                SpecialCharDAOImpl impl = new SpecialCharDAOImpl();
                SpecialChar curChar = impl.loadById(schar.getId());
                curChar.setValue(schar.getValue());
                userEntity.setModule(SPECIALCHAR);
                curChar.setUserEntity(userEntity);
                impl.saveOrUpdate(curChar);
                return schar;
            }
        });
    }
    //根据ID删除特殊字符
    public boolean deleteSpecialChar(final String id) {
        return (Boolean)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                SpecialCharDAOImpl impl = new SpecialCharDAOImpl();
                SpecialChar curChar = impl.loadById(id);
                userEntity.setModule(SPECIALCHAR);
                curChar.setUserEntity(userEntity);
                impl.delete(curChar);
                return true;
            }
        });
    }
    
    public boolean deleteSpecialCharByParentId(final String id) {
        return (Boolean)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                SpecialCharDAOImpl impl = new SpecialCharDAOImpl();
                String hql = "delete SpecialChar sc where sc.parentId =:id";
                userEntity.setModule(SPECIALCHAR);
                impl.deleteQueryObject(hql, "id", id, userEntity);
                return true;
            }
        });
    }
    
    public boolean deleteSpecialCharByHql(final String[] ids) {
        return (Boolean)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                SpecialCharDAOImpl impl = new SpecialCharDAOImpl();
                String hql = "delete SpecialChar where PLOID in (";
                int len = ids.length;
                for (int i = 0; i < len; i++) {
                    hql += "?";
                    if (i != len - 1) {
                        hql += ",";
                    }
                }
                hql += ")";
                userEntity.setModule(SPECIALCHAR);
                impl.deleteQueryObject(hql, ids, userEntity);
                return true;
            }
        });
    }
    
    //获取所有的特殊字符
    public List getSpecialCharList() {
        return (List)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                SpecialCharDAOImpl impl = new SpecialCharDAOImpl();
                String hsql = "from SpecialChar schar order by schar.value";
                return impl.findEntities(hsql);
            }
        });
    }
    /**
     * 
     * <p>Description:根据分类ID获得特殊字符 </p>
     * 
     * @author sunbo
     * @time 2012-5-25
     * @param id
     * @return
     */
    public List getSepcialCharByClsfId(final String id) {
        return (List)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                SpecialCharDAOImpl impl = new SpecialCharDAOImpl();
                String hsql = "from SpecialChar schar where PLPARENTID = '" + id + "' order by schar.value";
                if(id.equals("")){
                    hsql = "from SpecialChar schar order by schar.value";
                }
                return impl.findEntities(hsql);
            }
        });
    }
    
    /**
     * 获得制定分类下指定值的对象
     * @param id
     * @param val
     * @return
     */
    public SpecialChar getSepcialCharByClsfIdAndVal(final String id, final String val) {
        return (SpecialChar)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                SpecialCharDAOImpl impl = new SpecialCharDAOImpl();
                String hsql = "from SpecialChar schar where PLPARENTID = ? and schar.value = ?";
                String[] values = new String[2];
                values[0] = id;
                values[1] = val;
                return impl.findEntity(hsql, values);
            }
        });
    }
    
    public SpecialChar getSepcialCharById(final String id) {
        return (SpecialChar)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                SpecialCharDAOImpl impl = new SpecialCharDAOImpl();
                return impl.getById(id);
            }
        });
    }
    
 
    /**
     * 获得与已选择特殊字符相同的特殊字符个数
     * @author liujw
     * @param id
     * @param val
     * @return list
     */
    public List getSameValueList(final String Id, final String val) {
        return (List)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                SpecialCharDAOImpl impl = new SpecialCharDAOImpl();
                String hsql = "from SpecialChar schar where schar.parentId = ? and schar.value = ? order by schar.value";
                String[] values = new String[2];
                values[0] = Id;
                values[1] = val;
                return impl.findEntites(hsql, values);
            }
        });
    }
}