PhotoOperation.jsp
7.54 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
<%@page import="weaver.conn.RecordSetTrans"%>
<%@page import="weaver.hrm.HrmUserVarify"%>
<%@page import="weaver.hrm.User"%>
<%@page import="net.sf.json.JSONObject"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.*,java.sql.*,java.io.*" %>
<%@ page import="weaver.general.*,weaver.album.PhotoSequence,weaver.file.FileManage" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rs2" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rs3" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="p" class="weaver.album.PhotoComInfo" scope="page" />
<%
User user=HrmUserVarify.getUser(request, response);
if(user==null){
out.print("[]");
}
JSONObject jsonObject=new JSONObject();
String sql = "";
String id = Util.null2String (request.getParameter("id"));
if(id.startsWith(",")){
id=id.substring(1);
}
if(id.endsWith (",")){
id=id.substring(0,id.length()-1);
}
String settype = Util.null2String (request.getParameter("settype"));
String operation = Util.null2String(request.getParameter("operation"));
String realPath = GCONST.getRootPath();
realPath = realPath.substring(0,realPath.length()-1);
if(operation.equals("move")){//移动
int fromsubcomid=0;
int tosubcomid=0;
double movedsize=0.0;
int toid = Util.getIntValue(request.getParameter("toid"),0);
String parentsubcom=""+toid;
if(toid>0){//挂在分部的照片
tosubcomid=toid;
}else{
parentsubcom=p.getAncestorId(""+toid);
tosubcomid=Util.getIntValue( parentsubcom,0);
}
sql=" update AlbumPhotos set parentid="+toid+",subcompanyid='"+parentsubcom+"' where id in("+id+")";
rs.executeSql(sql);
//重算被移动相册数量
String[] preparedIds=Util.TokenizerString2(id,",");
for(int i=0;i<preparedIds.length;i++){
if(!"1".equals( p.getIsFolder( preparedIds[i]))){//照片
rs2.executeSql("select photosize from AlbumPhotos where id="+preparedIds[i]);
if(rs2.next()){
movedsize+=Util.getDoubleValue(rs2.getString("photosize"),0.0);
}
int parentId =Util.getIntValue ( p.getParentId(""+preparedIds[i]),0);
if(parentId>0){//分部
fromsubcomid=parentId;
}else{//更新文件夹照片数量
fromsubcomid=Util.getIntValue( p.getAncestorId(preparedIds[i]),0);
String folderId=p.getParentId(preparedIds[i]);
String sql1= "select count(id) from AlbumPhotos where parentId="+folderId+" and isFolder<>'1'";
rs.executeSql(sql1);
rs.next();
int tempcount = Util.getIntValue( rs.getString(1),0);
sql1="update AlbumPhotos set photoCount="+tempcount+" where id="+folderId;
rs.executeSql(sql1);
}
}else{
rs2.executeSql("select sum(photosize) as totalsize from AlbumPhotos where parentid="+preparedIds[i]);
if(rs2.next()){
movedsize+=Util.getDoubleValue(rs2.getString("totalsize"),0.0);
}
fromsubcomid=Util.getIntValue( p.getAncestorId(preparedIds[i]),0);
}
String folderId = p.getAncestorId(""+preparedIds[i]);
}
//重算移动至相册的数量
if(toid>0){//分部
}else if(toid<0){//相册
String sql2= "select count(id) from AlbumPhotos where parentId="+toid+" and isFolder<>'1'";
rs2.executeSql(sql2);
rs2.next();
int tempcount = Util.getIntValue( rs2.getString(1),0);
sql2="update AlbumPhotos set photoCount="+tempcount+" where id="+toid;
rs2.executeSql(sql2);
}
//重算分部使用空间
//System.out.println("fromsubcomid:"+fromsubcomid);
//System.out.println("tosubcomid:"+tosubcomid);
if(fromsubcomid!=tosubcomid&&fromsubcomid>0&&tosubcomid>0){
RecordSetTrans rst=new RecordSetTrans();
try{
rst.setAutoCommit(false);
String sql31="update AlbumSubcompany set albumSizeUsed=albumSizeUsed+"+movedsize+" where subcompanyid="+tosubcomid;
String sql32="update AlbumSubcompany set albumSizeUsed=albumSizeUsed-"+movedsize+" where subcompanyid="+fromsubcomid;
String sql33="update AlbumSubcompany set albumSizeUsed=0 where subcompanyid="+fromsubcomid+" and albumSizeUsed<0";
rst.executeSql(sql31);
rst.executeSql(sql32);
rst.executeSql(sql33);
rst.commit();
}catch(Exception e){
rst.rollback();
}
}
p.removePhotoComInfoCache();
out.print(jsonObject.toString());
}else if(operation.equals("delete")){
String subIds = p.getSubIds(""+id);
subIds = subIds + id;
if(subIds.endsWith(",")) subIds=subIds.substring(0,subIds.length()-1);
sql = "DELETE FROM AlbumPhotos WHERE id IN ("+subIds+")";
rs.executeSql(sql);
//sqlserver使用触发器
String parentId = p.getParentId(""+id);
String ancestorId = p.getAncestorId(""+id);
if(rs.getDBType().equals("oracle")||rs.getDBType().equals("mysql")){
p.updateCountAndSize(ancestorId, parentId);
}
String[] _ids = Util.TokenizerString2(subIds, ",");
for(int i=0;i<_ids.length;i++){
id = _ids[i];
if(!p.getPhotoPath(""+id).equals("/images/xpfolder38_wev8.gif")){//不删除图片文件夹图标
if(p.getPhotoPath(""+id).startsWith("/")){
FileManage.DeleteFile(realPath + File.separator + "album" + File.separator + "UploadFolder" + File.separator + id);
}else{
FileManage.DeleteFile(p.getPhotoPath(""+id));
}
FileManage.DeleteFile(realPath + File.separator + "album" + File.separator + "UploadFolder" + File.separator + "thumbnail" + File.separator + id);
}
}
//p.updatePhotoInfoCache(p.getParentId(String.valueOf(id)));
p.removePhotoComInfoCache();
if(p.getIsFolder(""+id).equals("1")) out.print("reloadTree");
//=======================================================================
}else if(operation.equals("edit")){
String title = Util.null2String(request.getParameter("title"));
title = Util.toHtml6(title);
sql = "UPDATE AlbumPhotos SET photoName='"+title+"' WHERE id="+id+"";
rs.executeSql(sql);
p.updatePhotoInfoCache(""+id);
if(p.getIsFolder(""+id).equals("1")) out.print("reloadTree");
//=======================================================================
}else if(operation.equals("batchdelete")){
String ancestorId = "";
String parentId = "";
String ids = Util.null2String(request.getParameter("ids"));
String[] _ids = Util.TokenizerString2(ids, ",");
for(int i=0;i<_ids.length;i++){
ancestorId = p.getAncestorId(""+_ids[i]);
parentId = p.getParentId(""+_ids[i]);
ids += p.getSubIds(_ids[i]);
}
if(ids.endsWith(",")) ids=ids.substring(0,ids.length()-1);
sql = "DELETE FROM AlbumPhotos WHERE id IN ("+ids+")";
rs.executeSql(sql);
//sqlserver使用触发器
if(rs.getDBType().equals("oracle")||rs.getDBType().equals("mysql")){
p.updateCountAndSize(ancestorId, parentId);
}
String[] idArray = Util.TokenizerString2(ids, ",");
for(int i=0;i<idArray.length;i++){
if(!p.getPhotoPath(""+id).equals("/images/xpfolder38_wev8.gif")){//不删除图片文件夹图标
if(p.getPhotoPath(idArray[i]).startsWith("/")){
FileManage.DeleteFile(realPath + File.separator + "album" + File.separator + "UploadFolder" + File.separator + idArray[i]);
}else{
FileManage.DeleteFile(p.getPhotoPath(idArray[i]));
}
FileManage.DeleteFile(realPath + File.separator + "album" + File.separator + "UploadFolder" + File.separator + "thumbnail" + File.separator + idArray[i]);
}
}
p.removePhotoComInfoCache();
//=======================================================================
}else if(operation.equals("updateAlbumSize")){
double albumSize = Util.getDoubleValue(request.getParameter("albumSize"),0)*1000;
if("1".equals( settype)){
sql = "UPDATE AlbumSubcompany SET albumSize="+albumSize+" ";
}else{
sql = "UPDATE AlbumSubcompany SET albumSize="+albumSize+" WHERE subcompanyId in("+id+") ";
}
rs.executeSql(sql);
out.print( jsonObject.toString() );
//response.sendRedirect("AlbumSubcompany.jsp?id="+id+"");
}
%>