Repository navigation
Expand file tree
/
Copy pathCwAction.java
More file actions
executable file
·347 lines (310 loc) · 8.66 KB
/
Copy pathCwAction.java
File metadata and controls
executable file
·347 lines (310 loc) · 8.66 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
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
package cw;
import java.util.Calendar;
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 cw.Cw;
import cw.Sbinfo;
import second.Second;
import second.SecondService;
import util.Page;
import util.StringHelp;
import com.opensymphony.xwork2.ActionSupport;
import basis.Hfsession;
import basis.ResultUtils;
public class CwAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private Map result;
private String uuid;
private String keyword;
private String scz;
private String year;
private String month;
private Cw cw;
private List<Cw> list;
private Sbinfo sbinfo;
private List<Sbinfo> listss;
private List<Second> lists;
private Page page = new Page();
private int currentPage=1;
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public String getCwList(){
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
Map<String,Object> map = new HashMap<String,Object>();
page.setEveryPage(20);
page.setCurrentPage(1);
Calendar now = Calendar.getInstance();
String year1 = now.get(Calendar.YEAR)+"";
String month1 = (now.get(Calendar.MONTH) + 1)+"";
try {
String hql = "select count(*) from Cw where 1=1 ";
lists = SecondService.getListSecond();
if(keyword != null && !keyword.equals("")){
hql += "and name like :name ";
}
if(StringHelp.isNotEmpty(scz)){
hql += "and scz = :scz ";
}
if(StringHelp.isNotEmpty(year)){
hql += "and year = :year ";
}else{
hql += "and year =" +year1;
}
if(StringHelp.isNotEmpty(month)){
hql += "and month = :month ";
}else{
hql += "and month =" +month1;
}
Query query = session.createQuery(hql);
if(keyword != null && !keyword.equals("")){
query.setParameter("name", "%"+keyword+"%");
}
if(StringHelp.isNotEmpty(scz)){
query.setParameter("scz", scz);
}
if(StringHelp.isNotEmpty(year)){
query.setParameter("year", year);
}
if(StringHelp.isNotEmpty(month)){
query.setParameter("month", month);
}
Long count= (Long)query.uniqueResult();
page.setTotalCount(Integer.parseInt(String.valueOf(count)));
String sql = "from Cw where 1=1 ";
if(keyword != null && !keyword.equals("")){
sql += "and name like :name ";
}
if(StringHelp.isNotEmpty(scz)){
sql += "and scz = :scz ";
}
if(StringHelp.isNotEmpty(year)){
sql += "and year = :year ";
}else{
sql += "and year =" +year1;
}
if(StringHelp.isNotEmpty(month)){
sql += "and month = :month ";
}else{
sql += "and month =" +month1;
}
sql += "ORDER BY createDate DESC";
Query q = session.createQuery(sql);
if(keyword != null && !keyword.equals("")){
q.setParameter("name", "%"+keyword+"%");
}
if(StringHelp.isNotEmpty(scz)){
q.setParameter("scz", scz);
}
if(StringHelp.isNotEmpty(year)){
q.setParameter("year", year);
}else{
year = year1;
}
if(StringHelp.isNotEmpty(month)){
q.setParameter("month", month);
}else{
month = month1;
}
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 sbDetail(){
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
Map<String,Object> map = new HashMap<String,Object>();
page.setEveryPage(20);
page.setCurrentPage(1);
Calendar now = Calendar.getInstance();
String year1 = now.get(Calendar.YEAR)+"";
String month1 = (now.get(Calendar.MONTH) + 1)+"";
try {
String hql = "select count(*) from Sbinfo 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 Sbinfo where 1=1 ";
if(keyword != null && !keyword.equals("")){
sql += "and name like :name ";
}
sql += "ORDER BY createDate DESC";
Query q = session.createQuery(sql);
if(keyword != null && !keyword.equals("")){
q.setParameter("name", "%"+keyword+"%");
}
q.setFirstResult((currentPage-1)*20);
q.setMaxResults(20);
listss = 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 addCw(){
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
Map<String,Object> map = new HashMap<String,Object>();
try {
if(cw.getUuid() == null || "".equals(cw.getUuid())){
cw.setCreateDate(new Date());
//cw.setSecondId(SecondService.getSecondId());
session.save(cw);
}else{
session.update(cw);
}
map.put("statusCode", 200);
ResultUtils.toJson(ServletActionContext.getResponse(), map);
tx.commit();
Hfsession.close();
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
return SUCCESS;
}
public String editCw(){
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
lists = SecondService.getListSecond();
if(!StringHelp.isNotEmpty(uuid)){
return SUCCESS;
}
try {
Query q = session.createQuery("from Cw where uuid =:uuid").setParameter("uuid", uuid);
cw = (Cw)q.uniqueResult();
tx.commit();
Hfsession.close();
if(cw == null){
return ERROR;
}
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
return SUCCESS;
}
public String delCw(){
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
Map<String,Object> map = new HashMap<String,Object>();
try {
Query q = session.createQuery("from Cw where uuid =:uuid").setParameter("uuid", uuid);
cw = (Cw) q.uniqueResult();
session.delete(cw);
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 Cw getCw() {
return cw;
}
public void setCw(Cw cw) {
this.cw = cw;
}
public List<Cw> getList() {
return list;
}
public void setList(List<Cw> 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;
}
public String getScz() {
return scz;
}
public void setScz(String scz) {
this.scz = scz;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public List<Second> getLists() {
return lists;
}
public void setLists(List<Second> lists) {
this.lists = lists;
}
public Sbinfo getSbinfo() {
return sbinfo;
}
public void setSbinfo(Sbinfo sbinfo) {
this.sbinfo = sbinfo;
}
public List<Sbinfo> getListss() {
return listss;
}
public void setListss(List<Sbinfo> listss) {
this.listss = listss;
}
}