HrmScheduleMonthOperation.jsp
12.4 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
<%@ page import="weaver.general.Util,weaver.file.*" %>
<%@ page import="weaver.conn.*" %>
<%@page import="weaver.hrm.common.database.dialect.DialectUtil"%>
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="RecordSet1" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="RecordSet2" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="log" class="weaver.systeminfo.SysMaintenanceLog" scope="page"/>
<jsp:useBean id="SubCompanyComInfo" class="weaver.hrm.company.SubCompanyComInfo" scope="page"/>
<jsp:useBean id="DepartmentComInfo" class="weaver.hrm.company.DepartmentComInfo" scope="page"/>
<jsp:useBean id="ExcelParse" class="weaver.file.ExcelParse" scope="page"/>
<jsp:useBean id="FileManage" class="weaver.file.FileManage" scope="page"/>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="/systeminfo/init_wev8.jsp" %>
<%
String opera = Util.null2String(request.getParameter("operation")); //操作类型
//added by wcd 2014-08-07 start
if (opera.equals("delete")){
String ids = Util.null2String(request.getParameter("ids"));
String subcompanyid = Util.null2String(request.getParameter("subcompanyid"));
String departmentid = Util.null2String(request.getParameter("departmentid"));
String orgtype = "";
if(departmentid.trim().length()>0){
orgtype = "dept";
}else{
orgtype = "com";
}
StringBuffer _sql = new StringBuffer();
if(orgtype.equals("dept")){
_sql.append("select a.theyear,a.themonth,a.subcompanyid1,a.departmentid from (")
.append(" select row_number()over(order by a.theyear,a.themonth) as num, a.theyear,a.themonth,b.subcompanyid1,b.departmentid")
.append(" from hrmschedulemonth a left join hrmresource b on a.hrmid = b.id ")
.append(" group by a.theyear,a.themonth,b.subcompanyid1,b.departmentid ) a ")
.append(" where a.num in (").append(ids).append(")");
}else{
_sql.append("select a.theyear,a.themonth,a.subcompanyid1 from (")
.append(" select row_number()over(order by a.theyear,a.themonth) as num, a.theyear,a.themonth,b.subcompanyid1")
.append(" from hrmschedulemonth a left join hrmresource b on a.hrmid = b.id ")
.append(" group by a.theyear,a.themonth,b.subcompanyid1 ) a ")
.append(" where a.num in (").append(ids).append(")");
}
if(DialectUtil.isMySql(RecordSet.getDBType())){
_sql = new StringBuffer();
if(orgtype.equals("dept")){
_sql.append("select a.theyear,a.themonth,a.subcompanyid1,a.departmentid from (")
.append(" select a.num, a.theyear,a.themonth,b.subcompanyid1,b.departmentid")
.append(" from ( select @rank:=@rank+1 as num,a.* from hrmschedulemonth a,(select @rank:=0) vars order by a.theyear,a.themonth ) a left join hrmresource b on a.hrmid = b.id ")
.append(" group by a.theyear,a.themonth,b.subcompanyid1,b.departmentid ) a ")
.append(" where a.num = ").append(ids);
}else{
_sql.append("select a.theyear,a.themonth,a.subcompanyid1 from (")
.append(" select a.num, a.theyear,a.themonth,b.subcompanyid1")
.append(" from ( select @rank:=@rank+1 as num,a.* from hrmschedulemonth a,(select @rank:=0) vars order by a.theyear,a.themonth ) a left join hrmresource b on a.hrmid = b.id ")
.append(" group by a.theyear,a.themonth,b.subcompanyid1 ) a ")
.append(" where a.num = ").append(ids);
}
}
RecordSet.executeSql(_sql.toString());
while(RecordSet.next()){
StringBuffer dSql = new StringBuffer("delete from hrmschedulemonth")
.append(" where theyear = ").append(Util.null2String(RecordSet.getString("theyear")))
.append(" and themonth = ").append(Util.null2String(RecordSet.getString("themonth")))
.append(" and hrmid in ( select id from HrmResource ")
.append(" where subcompanyid1 = ").append(Util.null2String(RecordSet.getString("subcompanyid1")));
if(orgtype.equals("dept")){
dSql.append(" and departmentid = ").append(Util.null2String(RecordSet.getString("departmentid")));
}
dSql.append(" )");
RecordSet1.executeSql(dSql.toString());
}
response.sendRedirect("HrmScheduleMonth.jsp?subcompanyid="+subcompanyid+"&departmentid="+departmentid);
return;
}
//added by wcd 2014-08-07 end
FileUploadToPath fu = new FileUploadToPath(request); // 非压缩上传
opera = Util.null2String(fu.getParameter("operation")); //操作类型
String theyear = Util.fromScreen(fu.getParameter("theyear"), user.getLanguage()); //简称
String themonth = Util.fromScreen(fu.getParameter("themonth"), user.getLanguage()); //说明
String orgtype = Util.fromScreen(fu.getParameter("type"), user.getLanguage());
String orgid = Util.fromScreen(fu.getParameter("id"), user.getLanguage());
String subcompanyid = Util.fromScreen(fu.getParameter("subcompanyid"), user.getLanguage());
String departmentid = Util.fromScreen(fu.getParameter("departmentid"), user.getLanguage());
String f_flag = Util.fromScreen(fu.getParameter("f_flag"), user.getLanguage());
if (opera.equals("add")) {//新建
if (!HrmUserVarify.checkUserRight("HrmScheduleMaintanceAdd:Add", user)) {
response.sendRedirect("/notice/noright.jsp");
return;
}
String sql1;
if (orgtype.equals("com"))
sql1 = "select * from hrmschedulemonth a,hrmresource b where a.hrmid=b.id and b.subcompanyid1=" + orgid + " and a.theyear='" +
theyear + "' and a.themonth='" + themonth + "'";
else {
String deptids = SubCompanyComInfo.getDepartmentTreeStr(orgid);
deptids = orgid + "," + deptids;
deptids = deptids.substring(0, deptids.length() - 1);
sql1 = "select a.hrmid from hrmschedulemonth a,hrmresource b where a.hrmid=b.id and b.departmentid in(" + deptids + ") and a.theyear='" +
theyear + "' and a.themonth='" + themonth + "'";
}
//System.out.println("sql1"+sql1);
RecordSet.executeSql(sql1);
if (RecordSet.next()) {
response.sendRedirect("HrmScheduleMonthAdd.jsp?msg=19428&isdialog=1&type=" + orgtype + "&id=" + orgid+"&subcompanyid="+subcompanyid+"&departmentid="+departmentid);
return;
}
Enumeration enumt = fu.getParameterNames();
while (enumt.hasMoreElements()) {
String para = (String) enumt.nextElement();
//System.out.println(para);
if (para.indexOf("_") < 1 || para.endsWith("_"))
continue;
String value = fu.getParameter(para);
//System.out.println(value);
if (value == null || value.equals(""))
continue;
String[] splits = Util.TokenizerString2(para, "_");
String sql = "insert into hrmschedulemonth(hrmid,difftype,hours,theyear,themonth) values(" + splits[0] + "," + splits[1] +
"," + value + ",'" + theyear + "','" + themonth + "')";
//System.out.println(sql);
RecordSet.executeSql(sql);
}
/*if (orgtype.equals("com"))
response.sendRedirect("HrmScheduleMonthAdd.jsp?isclose=1&subcompanyid=" + orgid);
else {
response.sendRedirect("HrmScheduleMonthAdd.jsp?isclose=1&departmentid=" + orgid);
}*/
response.sendRedirect("HrmScheduleMonthAdd.jsp?isclose=1&subcompanyid="+subcompanyid+"&departmentid="+departmentid);
}else if (opera.equals("update")) { //保存
if (!HrmUserVarify.checkUserRight("HrmScheduleMaintanceAdd:Add", user)) {
response.sendRedirect("/notice/noright.jsp");
return;
}
Enumeration enumt = request.getParameterNames();
while (enumt.hasMoreElements()) {
String para = (String) enumt.nextElement();
//System.out.println("para:"+para);
if (para.indexOf("_") < 1 || para.endsWith("_"))
continue;
String value = fu.getParameter(para);
//System.out.println(value);
String[] splits = Util.TokenizerString2(para, "_");
String sql = "select * from hrmschedulemonth where hrmid=" + splits[0] + " and difftype=" + splits[1] +
" and theyear='" + theyear + "' and themonth='" + themonth + "'";
//System.out.println(sql);
RecordSet.executeSql(sql);
if (RecordSet.next()) {
if (value == null || value.equals(""))
value = "0";
sql = "update hrmschedulemonth set hours=" + value + " where hrmid=" + splits[0] + " and difftype=" + splits[1] +
" and theyear='" + theyear + "' and themonth='" + themonth + "'";
//System.out.println(sql);
} else {
if (value == null || value.equals(""))
continue;
sql = "insert into hrmschedulemonth(hrmid,difftype,hours,theyear,themonth) values(" + splits[0] + "," + splits[1] +
"," + value + ",'" + theyear + "','" + themonth + "')";
// System.out.println("sql");
}
//System.out.println(sql);
RecordSet.executeSql(sql);
}
response.sendRedirect("HrmScheduleMonthEdit.jsp?isclose=1&year=" + theyear + "&month=" + themonth + "&type=" + orgtype + "&id=" + orgid+"&subcompanyid="+(f_flag.equals("1")?"":subcompanyid)+"&departmentid="+(f_flag.equals("1")?"":departmentid));
}else if (opera.equals("importnew")) {
if (!HrmUserVarify.checkUserRight("HrmScheduleMaintanceAdd:Add", user)) {
response.sendRedirect("/notice/noright.jsp");
return;
}
String sql = "select * from hrmschedulemonth a,hrmresource b where a.hrmid=b.id and b.subcompanyid1=" + orgid + " and a.theyear='" +
theyear + "' and a.themonth='" + themonth + "'";
RecordSet.executeSql(sql);
if (RecordSet.next()) {
response.sendRedirect("HrmScheduleMonthAdd.jsp?isclose=1&msg=19428&type=" + orgtype + "&id=" + orgid);
return;
}
String filename =fu.uploadFiles("excelfile");
if(filename==null||filename.equals("")) {
response.sendRedirect("HrmScheduleMonthAdd.jsp?isclose=1&subcompanyid=" + orgid);
return;
}
String subid = orgid;
String supids = SubCompanyComInfo.getAllSupCompany(subid);
if (supids.endsWith(",")) {
supids = supids.substring(0, supids.length() - 1);
sql = "select * from hrmschedulediff where workflowid=5 and (diffscope=0 or (diffscope>0 and subcompanyid="+subid+") or (diffscope=2 and subcompanyid in("+supids+")))";
} else
sql = "select * from hrmschedulediff where workflowid=5 and (diffscope=0 or (diffscope>0 and subcompanyid=" + subid + "))";
RecordSet.executeSql(sql);
RecordSet1.executeSql("select * from hrmresource where status>-1 and status<4 and subcompanyid1=" + orgid + " order by dsporder,lastname");
if (!filename.equals("")) {
ExcelParse.init(filename);
int recordercount = 0;
while (true) {
recordercount ++;
//标题行
if (recordercount == 1) continue;
String id = Util.null2String(ExcelParse.getValue("1", "" + recordercount, "1")).trim();
String lastname = Util.null2String(ExcelParse.getValue("1", "" + recordercount, "2")).trim();
if (id.equals(""))
break;
RecordSet1.beforFirst();
boolean exist = false;
while (RecordSet1.next()) {
if (id.equals(RecordSet1.getString("id"))) {
exist = true;
break;
}
}
if (!exist)
continue;
RecordSet.beforFirst();
int colcount = 2;
while (RecordSet.next()) {
colcount++;
String hours = Util.null2String(ExcelParse.getValue("1", "" + recordercount, "" + colcount)).trim();
if (hours.equals(""))
continue;
String insertsql = "insert into hrmschedulemonth(hrmid,difftype,hours,theyear,themonth) values(" + id + "," + RecordSet.getString("id") +
"," + hours + ",'" + theyear + "','" + themonth + "')";
RecordSet2.executeSql(insertsql);
}
}
FileManage.DeleteFile(filename);
}
response.sendRedirect("HrmScheduleMonthAdd.jsp?isclose=1&subcompanyid=" + orgid);
}
%>