HrmArrangeShiftMaintanceOperation.jsp
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
<%@ page import = "weaver.general.Util" %>
<%@ page import = "java.util.*" %>
<jsp:useBean id = "RecordSet" class = "weaver.conn.RecordSet" scope = "page"/>
<%@page import="weaver.hrm.company.DepartmentComInfo"%>
<%@page import="weaver.hrm.company.SubCompanyComInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file = "/systeminfo/init_wev8.jsp"%>
<%!
public ArrayList<String> getLsResource(weaver.conn.RecordSet rs,String sqlwhere2)throws Exception{
ArrayList<String> lsReource = new ArrayList<String>();
ArrayList<HrmShareType> lsHrmShareType = new ArrayList<HrmShareType>();
HrmShareType hrmShareType = new HrmShareType();
//首先获得范围表中的数据
rs.executeSql(" SELECT sharetype,relatedId,level_from, level_to FROM hrmarrangeshiftset ");
while(rs.next()){
hrmShareType = new HrmShareType();
hrmShareType.setSharetype(rs.getInt("sharetype"));
hrmShareType.setRelatedId(rs.getInt("relatedId"));
hrmShareType.setLevel_from(rs.getInt("level_from"));
hrmShareType.setLevel_to(rs.getInt("level_to"));
lsHrmShareType.add(hrmShareType);
}
for(int i=0;i<lsHrmShareType.size();i++){
hrmShareType = lsHrmShareType.get(i);
if(hrmShareType.getSharetype()==5){
//所有人
rs.executeSql("select id from hrmresource where status in(0,1,2,3) "
+" and seclevel >= "+hrmShareType.getLevel_from() +" and seclevel >= "+hrmShareType.getLevel_to()
+ sqlwhere2 + " order by departmentid ");
while(rs.next()){
lsReource.add(rs.getString("id"));
}
}else if(hrmShareType.getSharetype()==4){
//角色
rs.executeSql("SELECT resourceid FROM HrmRoleMembers WHERE roleid ="+hrmShareType.getRelatedId()
+" and rolelevel>="+hrmShareType.getLevel_from() +" AND rolelevel<="+hrmShareType.getLevel_to());
while(rs.next()){
lsReource.add(rs.getString("id"));
}
}else if(hrmShareType.getSharetype()==3){
//人力资源
lsReource.add(hrmShareType.getRelatedId()+"");
}else if(hrmShareType.getSharetype()==2){
//部门
rs.executeSql("SELECT id FROM hrmresource WHERE departmentid in ("+DepartmentComInfo.getAllChildDepartId(""+hrmShareType.getRelatedId(),""+hrmShareType.getRelatedId())
+") and seclevel>="+hrmShareType.getLevel_from() +" AND seclevel<="+hrmShareType.getLevel_to()+ sqlwhere2 + " order by departmentid");
while(rs.next()){
lsReource.add(rs.getString("id"));
}
}else if(hrmShareType.getSharetype()==1){
//分部
String subComIds = SubCompanyComInfo.getSubCompanyTreeStr(""+hrmShareType.getRelatedId())+hrmShareType.getRelatedId();
rs.executeSql("SELECT id FROM hrmresource WHERE subcompanyid1 in ("+subComIds
+") and seclevel>="+hrmShareType.getLevel_from() +" AND seclevel<="+hrmShareType.getLevel_to()+ sqlwhere2 + " order by departmentid");
while(rs.next()){
lsReource.add(rs.getString("id"));
}
}
}
return lsReource;
}
%>
<%
String operation = Util.null2String(request.getParameter("operation"));
String subcompanyid = Util.fromScreen(request.getParameter("subcompanyid") , user.getLanguage()) ; //分部
String departmentid = Util.fromScreen(request.getParameter("departmentid") , user.getLanguage()) ; //部门
String fromdate = Util.fromScreen(request.getParameter("fromdate") , user.getLanguage()) ; //排班日期从
String enddate = Util.fromScreen(request.getParameter("enddate") , user.getLanguage()) ; //排班日期到
char separator = Util.getSeparator() ;
String procedurepara="" ;
Calendar thedate = Calendar.getInstance() ; //
String currentdate = Util.add0(thedate.get(Calendar.YEAR) , 4) + "-" +
Util.add0(thedate.get(Calendar.MONTH) + 1 , 2) + "-" +
Util.add0(thedate.get(Calendar.DAY_OF_MONTH) , 2) ; // 当天
if(operation.equals("save")) {
String selectdates[] = request.getParameterValues("selectdate") ;
String selectresources[] = request.getParameterValues("selectresource") ;
if( selectdates != null && selectresources != null ) {
String selectresourcestrs = "" ;
String selectdatestrs = "" ;
for(int i = 0 ; i < selectresources.length ; i++) {
String resourceid = selectresources[i] ;
if( resourceid == null ) continue ;
if( selectresourcestrs.equals("") ) selectresourcestrs = resourceid ;
else selectresourcestrs += "," + resourceid ;
}
for(int j = 0 ; j < selectdates.length ; j++) {
String thetempdate = selectdates[j] ;
if( thetempdate == null || Util.dayDiff(currentdate,thetempdate) < -2 ) continue ; // 排班日期小于等于当天的不处理
if( selectdatestrs.equals("") ) selectdatestrs = "'"+thetempdate+"'" ;
else selectdatestrs += ",'" + thetempdate+"'" ;
}
if( !selectresourcestrs.equals("") && !selectdatestrs.equals("") ) {
RecordSet.executeSql("delete HrmArrangeShiftInfo where resourceid in (" + selectresourcestrs + ") and shiftdate in (" + selectdatestrs + ")") ;
}
for(int i = 0 ; i < selectresources.length ; i++) {
String resourceid = selectresources[i] ;
if( resourceid == null ) continue ;
for(int j = 0 ; j < selectdates.length ; j++) {
String thetempdate = selectdates[j] ;
if( thetempdate == null || currentdate.compareTo(thetempdate) > 1 ) continue ; // 排班日期小于等于当天的前一天的不处理
String shiftidstr = request.getParameter(resourceid+"_"+thetempdate);
String shiftids[] = Util.TokenizerString2(shiftidstr,",");
if(shiftids == null) continue ;
for( int k=0 ; k < shiftids.length ; k++ ) {
String shiftid = Util.null2String( shiftids[k] ) ;
if( !shiftid.equals("") ) {
procedurepara = resourceid + separator + thetempdate + separator + shiftid ;
RecordSet.executeProc("HrmArrangeShiftInfo_Insert" , procedurepara) ;
}
}
}
}
}
}else if(operation.equals("process")) {
String resourceid = Util.fromScreen(request.getParameter("multresourceid") , user.getLanguage()) ;
String shiftid = Util.null2String(request.getParameter("shiftname")) ;
String sqlwhere1="";
if(shiftid.equals("")) {
sqlwhere1 += " and shiftdate >='" + fromdate + "'" ;
sqlwhere1 += " and shiftdate <='" + enddate + "'" ;
String sql = " delete from HrmArrangeShiftInfo where resourceid in ( "+ resourceid + " ) " + sqlwhere1 ;
out.print(sql) ;
RecordSet.executeSql(sql) ;
}else {
ArrayList selectdates = new ArrayList() ;
int fromyear = Util.getIntValue(fromdate.substring(0 , 4)) ;
int frommonth = Util.getIntValue(fromdate.substring(5 , 7)) ;
int fromday = Util.getIntValue(fromdate.substring(8 , 10)) ;
String tempdate = fromdate ;
thedate.set(fromyear,frommonth - 1 , fromday) ;
while( tempdate.compareTo(enddate) <= 0 ) {
selectdates.add(tempdate) ;
thedate.add(Calendar.DATE , 1) ;
tempdate = Util.add0(thedate.get(Calendar.YEAR) , 4) + "-" +
Util.add0(thedate.get(Calendar.MONTH) + 1 , 2) + "-" +
Util.add0(thedate.get(Calendar.DAY_OF_MONTH) , 2) ;
}
// 得到按照排班来管理的所有人员
ArrayList<String> reesourceshifts = getLsResource(RecordSet,"");
ArrayList<String> resourceids = Util.TokenizerString(resourceid,",");
for(int i = 0 ; i < resourceids.size() ; i++) {
String resourceid1 = resourceids.get(i) ;
if( resourceid1 ==null || reesourceshifts.indexOf(resourceid1) == -1 ) continue ;
for(int j = 0 ; j < selectdates.size() ; j++) {
String thetempdate = (String)selectdates.get(j) ;
if( thetempdate == null ) continue ;
String[] shiftids = shiftid.split(",");
for( int k=0 ; k < shiftids.length ; k++ ) {
String tmp_shiftid = Util.null2String( shiftids[k] ) ;
if( !tmp_shiftid.equals("") ) {
procedurepara = resourceid1 + separator + thetempdate + separator + tmp_shiftid ;
RecordSet.executeProc("HrmArrangeShiftInfo_Save" , procedurepara) ;
}
}
}
}
}
response.sendRedirect("HrmArrangeShiftProcess.jsp?isclose=1") ;
return;
}
response.sendRedirect("HrmArrangeShiftMaintance.jsp?subcompanyid="+subcompanyid+"&departmentid="+departmentid+"&fromdate="+fromdate+"&enddate="+enddate) ;
%>