Repository navigation
Expand file tree
/
Copy pathSecondAction.java
More file actions
executable file
·189 lines (175 loc) · 4.92 KB
/
Copy pathSecondAction.java
File metadata and controls
executable file
·189 lines (175 loc) · 4.92 KB
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
package second;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.struts2.ServletActionContext;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import basis.Hfsession;
import basis.ResultUtils;
import second.Second;
import second.SecondService;
import util.Page;
import com.opensymphony.xwork2.ActionSupport;
/**
* 生产部 二级权限管理
* @author Administrator
*
*/
public class SecondAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private Map result;
private String uuid;
private String keyword;
private Second second;
private List<Second> list;
private Page page = new Page();
private int currentPage=1;
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public String getSecondList(){
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
Map<String,Object> map = new HashMap<String,Object>();
page.setEveryPage(20);
page.setCurrentPage(1);
try {
String hql = "select count(*) from Second where 1=1 ";
if(keyword != null && !keyword.equals("")){
hql += "and name like :name ";
}
Query query = session.createQuery(hql);
if(keyword != null && !keyword.equals("")){
query.setParameter("name", "%"+keyword+"%");
}
Long count= (Long)query.uniqueResult();
page.setTotalCount(Integer.parseInt(String.valueOf(count)));
String sql = "from Second where 1=1 ";
if(keyword != null && !keyword.equals("")){
sql += "and name like :name ";
}
/*if(orderField != null){
sql += "order by " + orderField +" "+ orderDirection;
}else{*/
sql += "order by secondId desc";
//}
Query q = session.createQuery(sql);
if(keyword != null && !keyword.equals("")){
q.setParameter("name", "%"+keyword+"%");
}
q.setFirstResult((currentPage-1)*20);
q.setMaxResults(20);
list = q.list();
page.setTotalPage((int)Math.ceil(count/20.0));
page.setHasPrePage(currentPage>1);
page.setHasNextPage(currentPage<(int)(Math.ceil(count/20.0)));
tx.commit();
Hfsession.close();
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
public String addSecond(){
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
Map<String,Object> map = new HashMap<String,Object>();
try {
if(second.getUuid() == null || "".equals(second.getUuid())){
second.setCreateDate(new Date());
second.setSecondId(SecondService.getSecondId());
session.save(second);
}else{
session.update(second);
}
map.put("statusCode", 200);
ResultUtils.toJson(ServletActionContext.getResponse(), map);
tx.commit();
Hfsession.close();
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
return SUCCESS;
}
public String editSecond(){
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
try {
Query q = session.createQuery("from Second where uuid =:uuid").setParameter("uuid", uuid);
second = (Second)q.uniqueResult();
tx.commit();
Hfsession.close();
if(second == null){
return ERROR;
}
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
return SUCCESS;
}
public String delSecond(){
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
Map<String,Object> map = new HashMap<String,Object>();
try {
Query q = session.createQuery("from Second where uuid =:uuid").setParameter("uuid", uuid);
second = (Second) q.uniqueResult();
session.delete(second);
map.put("statusCode", 200);
ResultUtils.toJson(ServletActionContext.getResponse(), map);
tx.commit();
Hfsession.close();
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
@Override
public String execute() throws Exception {
return super.execute();
}
public Map getResult() {
return result;
}
public void setResult(Map result) {
this.result = result;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public Second getSecond() {
return second;
}
public void setSecond(Second second) {
this.second = second;
}
public List<Second> getList() {
return list;
}
public void setList(List<Second> list) {
this.list = list;
}
public Page getPage() {
return page;
}
public void setPage(Page page) {
this.page = page;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
}