DocImgUpload.jsp
8.95 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
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="weaver.file.FileUpload" %>
<%@ page import="weaver.general.*" %>
<%@ page import="weaver.hrm.*" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.systeminfo.*" %>
<%@ page import="weaver.general.DesUtil"%>
<jsp:useBean id="imgManger" class="weaver.docs.docs.DocImageManager" scope="page"/>
<jsp:useBean id="ResourceComInfo" class="weaver.hrm.resource.ResourceComInfo" scope="page"/>
<jsp:useBean id="docDetailLog" class="weaver.docs.DocDetailLog" scope="page"/>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="VersionIdUpdate" class="weaver.docs.docs.VersionIdUpdate" scope="page"/>
<jsp:useBean id="DocManager" class="weaver.docs.docs.DocManager" scope="page" />
<%!
private String getFileExt(String file) {
if (file == null || file.trim().equals("")) {
return "";
} else {
int idx = file.lastIndexOf(".");
if (idx == -1) {
return "";
} else {
if (idx + 1 >= file.length()) {
return "";
} else {
return file.substring(idx + 1);
}
}
}
}
private String getFileType(String fileext){
String docfiletype="2";
if (fileext.equalsIgnoreCase("doc")) {
docfiletype="3";
} else if (fileext.equalsIgnoreCase("xls")) {
docfiletype="4";
} else if (fileext.equalsIgnoreCase("ppt")) {
docfiletype="5";
} else if (fileext.equalsIgnoreCase("wps")) {
docfiletype="6";
} else if (fileext.equalsIgnoreCase("docx")) {
docfiletype="7";
} else if (fileext.equalsIgnoreCase("xlsx")) {
docfiletype="8";
} else if (fileext.equalsIgnoreCase("pptx")) {
docfiletype="9";
}
return docfiletype;
}
private String getFileType2(String docfiletype){
if("7".equals(docfiletype)){
docfiletype="3";
}
if("8".equals(docfiletype)){
docfiletype="4";
}
if("9".equals(docfiletype)){
docfiletype="5";
}
return docfiletype;
}
%>
<%
User login_user_ = HrmUserVarify.getUser (request , response) ;
if(login_user_ == null) return ;
response.setHeader("cache-control", "no-cache");
response.setHeader("pragma", "no-cache");
response.setHeader("expires", "Mon 1 Jan 1990 00:00:00 GMT");
User user = HrmUserVarify.getUser (request , response) ;
FileUpload fu = new FileUpload(request,"utf-8");
String operation=Util.null2String(fu.getParameter("operation"));
int oldVersionId=Util.getIntValue(fu.getParameter("versionId"));
int oldImagefileId=Util.getIntValue(fu.getParameter("imagefileId"));
int imagefileid = Util.getIntValue(fu.uploadFiles("Filedata"));
int docid=Util.getIntValue(fu.getParameter("docid"));
int newVersionId=VersionIdUpdate.getVersionNewId();
if("replacefile".equals(operation)){
if(imagefileid<=0){
out.println("empty,0,0,0,0");
return;
}
String oldimagefilename="";
rs.executeSql("select imagefilename from DocImageFile where docid="+docid+" and versionId="+oldVersionId+" and isextfile=1 order by id desc");
if(rs.next()){
oldimagefilename=Util.null2String(rs.getString("imagefilename"));
}
String oldfileext=getFileExt(oldimagefilename);
boolean oldisExt=Util.isExt(oldfileext);
String olddocfiletype=getFileType(oldfileext);
String olddocfiletype2=getFileType2(olddocfiletype);
String imagefilename="";
rs.executeSql("select imagefilename from imagefile where imagefileid="+imagefileid);
if(rs.next()){
imagefilename=Util.null2String(rs.getString(1));
}
String fileext=getFileExt(imagefilename);
boolean isExt=Util.isExt(fileext);
String docfiletype=getFileType(fileext);
String docfiletype2=getFileType2(docfiletype);
if(docfiletype2.equals(olddocfiletype2)){
rs.executeSql("insert into DocImageFile(id,docid,imagefileid,imagefilename,imagefiledesc,imagefilewidth,imagefileheight,imagefielsize,docfiletype,versionId,versionDetail,isextfile,hasUsedTemplet) select id,docid,"+imagefileid+",'"+imagefilename+"','',imagefilewidth,imagefileheight,imagefielsize,"+docfiletype+","+newVersionId+",'"+Util.toHtml100(SystemEnv.getHtmlLabelName(33029, user.getLanguage()))+"',isextfile,hasUsedTemplet from DocImageFile where docid="+docid+" and versionId="+oldVersionId+" and isextfile=1");
//更新文档修改时间和最后修改人
Calendar today = Calendar.getInstance();
String formatdate = Util.add0(today.get(Calendar.YEAR), 4) + "-"
+ Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-"
+ Util.add0(today.get(Calendar.DAY_OF_MONTH), 2);
String formattime = Util.add0(today.get(Calendar.HOUR_OF_DAY), 2) + ":"
+ Util.add0(today.get(Calendar.MINUTE), 2) + ":" + Util.add0(today.get(Calendar.SECOND), 2);
rs.executeSql("update docdetail set doclastmoddate='"+formatdate+"',doclastmodtime='"+formattime+"',doclastmoduserid='"+user.getUID()+"',docLastModUserType='"+user.getLogintype()+"' where id="+docid);
DocManager.resetParameter();
DocManager.setId(docid);
DocManager.getDocInfoById();
String docCreaterType = DocManager.getDocCreaterType();
int doccreaterid=DocManager.getDoccreaterid();
docDetailLog.resetParameter();
docDetailLog.setDocId(docid);
docDetailLog.setDocSubject(imagefilename);
docDetailLog.setOperateType("2");
docDetailLog.setOperateUserid(user.getUID());
docDetailLog.setUsertype(user.getLogintype());
docDetailLog.setClientAddress(request.getRemoteAddr());
docDetailLog.setDocCreater(doccreaterid);
docDetailLog.setCreatertype(docCreaterType);
docDetailLog.setDocLogInfo();
out.println("success,"+docid+","+isExt+","+newVersionId+","+imagefileid);
} else {
out.println("error,"+docid+","+oldisExt+","+oldVersionId+","+oldImagefileId);
}
return;
}
boolean hasRight = false;
DesUtil desUtil = new DesUtil();
String userid = Util.null2String(fu.getParameter("userid"));
if(!userid.equals("")){
if(Util.getIntValue(desUtil.decrypt(userid))>0){
hasRight = true;
}
}
if(!hasRight) return ;
//String mode=Util.null2String(fu.getParameter("mode"));
//System.out.println("imagefileid:"+imagefileid);
//System.out.println("docid:"+docid);
String imgFilename="";
rs.executeSql("select imagefilename from imagefile where imagefileid="+imagefileid);
if(rs.next()){
imgFilename=rs.getString(1);
}
imgManger.resetParameter();
imgManger.setDocid(docid);
imgManger.setImagefileid(imagefileid);
imgManger.setImagefilename(imgFilename);
imgManger.setIsextfile("1");
String ext = getFileExt(imgFilename);
if (ext.equalsIgnoreCase("doc")) {
imgManger.setDocfiletype("3");
} else if (ext.equalsIgnoreCase("xls")) {
imgManger.setDocfiletype("4");
} else if (ext.equalsIgnoreCase("ppt")) {
imgManger.setDocfiletype("5");
} else if (ext.equalsIgnoreCase("wps")) {
imgManger.setDocfiletype("6");
} else if (ext.equalsIgnoreCase("docx")) {
imgManger.setDocfiletype("7");
} else if (ext.equalsIgnoreCase("xlsx")) {
imgManger.setDocfiletype("8");
} else if (ext.equalsIgnoreCase("pptx")) {
imgManger.setDocfiletype("9");
} else if (ext.equalsIgnoreCase("et")) {
imgManger.setDocfiletype("10");
} else {
imgManger.setDocfiletype("2");
}
imgManger.AddDocImageInfo();
String sql="select count(distinct id) from docimagefile where isextfile = '1' and docid="+docid;
rs.executeSql(sql);
int countImg=0;
while(rs.next()){
countImg=rs.getInt(1);
}
Calendar today = Calendar.getInstance();
String formatdate = Util.add0(today.get(Calendar.YEAR), 4) + "-"
+ Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-"
+ Util.add0(today.get(Calendar.DAY_OF_MONTH), 2);
String formattime = Util.add0(today.get(Calendar.HOUR_OF_DAY), 2) + ":"
+ Util.add0(today.get(Calendar.MINUTE), 2) + ":"
+ Util.add0(today.get(Calendar.SECOND), 2);
sql = "update docdetail set accessorycount="+countImg+",doclastmoddate='"+formatdate+"',doclastmodtime='"+formattime+"',doclastmoduserid='"+user.getUID()+"',docLastModUserType='"+user.getLogintype()+"' where id="+docid;
//System.out.println(sql);
rs.executeSql(sql);
//if("view".equals(mode))
//{
String docsubject = "";
String creatertype = "";
int doccreater = 0;
String selSql = "select docsubject,creatertype, doccreater from DocDetailLog where docid="+ docid + " order by id desc";
//System.out.println("selSql : "+selSql);
rs.executeSql(selSql);
if (rs.next()) {
docsubject = rs.getString(1);
creatertype = rs.getString(2);
doccreater = Util.getIntValue(rs.getString(3));
}
String clientip = request.getRemoteAddr();
String usertype = Util.null2String(fu.getParameter("usertype"));
;
docDetailLog.resetParameter();
docDetailLog.setDocId(docid);
docDetailLog.setDocSubject(docsubject);
docDetailLog.setOperateType("2");
docDetailLog.setOperateUserid( Util.getIntValue(desUtil.decrypt(userid)));
docDetailLog.setUsertype(usertype);
docDetailLog.setClientAddress(clientip);
docDetailLog.setDocCreater(doccreater);
docDetailLog.setCreatertype(creatertype);
docDetailLog.setDocLogInfo();
//}
%>