001 | package com.xznu.edu.leave.action; |
007 | import com.opensymphony.xwork2.ActionContext; |
008 | import com.opensymphony.xwork2.ActionSupport; |
009 | import com.opensymphony.xwork2.ModelDriven; |
010 | import com.xznu.edu.leave.model.BookLoan; |
011 | import com.xznu.edu.leave.model.Goods; |
012 | import com.xznu.edu.leave.model.ItemTypeSecondary; |
013 | import com.xznu.edu.leave.model.User; |
014 | import com.xznu.edu.leave.service.*; |
015 | import com.xznu.edu.leave.utils.JsonUtils; |
016 | import com.xznu.edu.leave.utils.Pager; |
017 | import com.xznu.edu.leave.utils.UUIDUtils; |
018 | import com.xznu.edu.leave.utils.UserUtils; |
019 | import net.sf.json.JSONArray; |
020 | import net.sf.json.JSONObject; |
021 | import org.apache.struts2.ServletActionContext; |
022 | import org.springframework.beans.factory.annotation.Autowired; |
023 | import org.springframework.context.annotation.Scope; |
024 | import org.springframework.stereotype.Controller; |
025 | import org.joda.time.DateTime; |
027 | import javax.servlet.http.HttpServletRequest; |
029 | import java.util.Date; |
030 | import java.util.List; |
032 | @Controller ( "goodsAction" ) |
034 | public class GoodsAction extends ActionSupport implements ModelDriven<Goods> { |
036 | private BookLoanService bookLoanService; |
038 | private GoodsService service; |
040 | private UserService userService; |
042 | private ItemTypeSecondaryService itemTypeSecondaryService; |
044 | private List<File> file; |
045 | private List<String> fileFileName; |
046 | private List<String> fileContentType; |
047 | private Integer bookLoanId; |
055 | public String list() throws IOException { |
056 | User user1 = UserUtils.getUser(); |
057 | if (user1 == null || user1.getId() == null ) { |
058 | ActionContext.getContext().put( "login" , 1 ); |
061 | Pager<Goods> pagers = null ; |
062 | if (user1.getRole().getEnName().equals( "admin" )) { |
063 | pagers = service.getList2(goods); |
064 | ActionContext.getContext().put( "pagers" , pagers); |
065 | Pager<ItemTypeSecondary> itemTypelist = itemTypeSecondaryService.getList( null ); |
066 | ActionContext.getContext().put( "itemTypelist" , itemTypelist); |
067 | ActionContext.getContext().put( "user" , user1); |
068 | ActionContext.getContext().put( "bean" , goods); |
071 | goods.setUser(user1); |
072 | pagers = service.getList2(goods); |
073 | ActionContext.getContext().put( "pagers" , pagers); |
074 | Pager<ItemTypeSecondary> itemTypelist = itemTypeSecondaryService.getList( null ); |
075 | ActionContext.getContext().put( "itemTypelist" , itemTypelist); |
076 | ActionContext.getContext().put( "user" , user1); |
077 | ActionContext.getContext().put( "bean" , goods); |
082 | public String tjlist() throws IOException { |
083 | User user1 = UserUtils.getUser(); |
084 | if (user1 == null || user1.getId() == null ) { |
085 | ActionContext.getContext().put( "login" , 1 ); |
088 | Pager<Goods> pagers = null ; |
089 | if (user1.getRole().getEnName().equals( "admin" )) { |
090 | pagers = service.getList2(goods); |
091 | ActionContext.getContext().put( "pagers" , pagers); |
092 | Pager<ItemTypeSecondary> itemTypelist = itemTypeSecondaryService.getList( null ); |
093 | ActionContext.getContext().put( "itemTypelist" , itemTypelist); |
094 | ActionContext.getContext().put( "user" , user1); |
095 | ActionContext.getContext().put( "bean" , goods); |
098 | goods.setUser(user1); |
099 | pagers = service.getList2(goods); |
100 | ActionContext.getContext().put( "pagers" , pagers); |
101 | Pager<ItemTypeSecondary> itemTypelist = itemTypeSecondaryService.getList( null ); |
102 | ActionContext.getContext().put( "itemTypelist" , itemTypelist); |
103 | ActionContext.getContext().put( "user" , user1); |
104 | ActionContext.getContext().put( "bean" , goods); |
109 | public String shlist() throws IOException { |
110 | User user1 = UserUtils.getUser(); |
111 | if (user1 == null || user1.getId() == null ) { |
112 | ActionContext.getContext().put( "login" , 1 ); |
115 | Pager<Goods> pagers = null ; |
116 | if (user1.getRole().getEnName().equals( "admin" )) { |
117 | pagers = service.getList2(goods); |
118 | ActionContext.getContext().put( "pagers" , pagers); |
119 | Pager<ItemTypeSecondary> itemTypelist = itemTypeSecondaryService.getList( null ); |
120 | ActionContext.getContext().put( "itemTypelist" , itemTypelist); |
121 | ActionContext.getContext().put( "user" , user1); |
122 | ActionContext.getContext().put( "bean" , goods); |
132 | public String add() { |
133 | Pager<ItemTypeSecondary> pagers = itemTypeSecondaryService.getList( null ); |
134 | ActionContext.getContext().put( "pagers" , pagers); |
143 | public String edit() { |
144 | Goods bean = service.findById(goods.getId()); |
145 | Pager<ItemTypeSecondary> pagers = itemTypeSecondaryService.getList( null ); |
146 | ActionContext.getContext().put( "pagers" , pagers); |
147 | ActionContext.getContext().put( "bean" , bean); |
156 | public String detail() { |
157 | Goods bean = service.findById(goods.getId()); |
158 | Pager<ItemTypeSecondary> pagers = itemTypeSecondaryService.getList( null ); |
159 | ActionContext.getContext().put( "pagers" , pagers); |
160 | ActionContext.getContext().put( "bean" , bean); |
164 | public void sh() throws IOException { |
165 | Goods bean = service.findById(goods.getId()); |
166 | bean.setIsSh(bean.getIsSh() == 1 ? 0 : 1 ); |
167 | service.update(bean); |
168 | JSONObject jsonObject = new JSONObject(); |
169 | jsonObject.put( "flag" , true ); |
170 | jsonObject.put( "url" , "goods_shlist.do" ); |
171 | JsonUtils.jsonObject(jsonObject); |
179 | public void editSj() throws IOException { |
180 | Goods bean = service.findById(goods.getId()); |
181 | bean.setIsSj(bean.getIsSj() == 1 ? 0 : 1 ); |
182 | service.update(bean); |
183 | JSONObject jsonObject = new JSONObject(); |
184 | jsonObject.put( "flag" , true ); |
185 | jsonObject.put( "url" , "goods_list.do" ); |
186 | JsonUtils.jsonObject(jsonObject); |
194 | public String update() throws IOException { |
195 | ActionContext ac = ActionContext.getContext(); |
196 | HttpServletRequest request = (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST); |
197 | String root = request.getRealPath( "/upload" ); |
199 | for ( int i = 0 ; i < file.size(); i++) { |
200 | InputStream is = new FileInputStream(file.get(i)); |
201 | String f = UUIDUtils.create() + i; |
202 | OutputStream os = new FileOutputStream( new File(root, f)); |
203 | byte [] buffer = new byte [ 500 ]; |
205 | while (- 1 != (length = is.read(buffer, 0 , buffer.length))) { |
211 | goods.setFileName1( "\\upload\\" + f); |
214 | goods.setFileName2( "\\upload\\" + f); |
217 | goods.setFileName3( "\\upload\\" + f); |
220 | goods.setFileName4( "\\upload\\" + f); |
223 | goods.setFileName5( "\\upload\\" + f); |
227 | service.updates(goods); |
228 | ActionContext.getContext().put( "url" , "goods_list.do" ); |
237 | public String save() throws IOException { |
238 | ActionContext ac = ActionContext.getContext(); |
239 | HttpServletRequest request = (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST); |
240 | String root = request.getRealPath( "/upload" ); |
242 | for ( int i = 0 ; i < file.size(); i++) { |
243 | InputStream is = new FileInputStream(file.get(i)); |
244 | String xx = new DateTime().toString(); |
245 | String f = new DateTime().toString( "yyyyMMdd" ); |
246 | f = UUIDUtils.create() + i; |
247 | OutputStream os = new FileOutputStream( new File(root, f)); |
248 | byte [] buffer = new byte [ 500 ]; |
250 | while (- 1 != (length = is.read(buffer, 0 , buffer.length))) { |
256 | goods.setFileName1( "\\upload\\" + f); |
259 | goods.setFileName2( "\\upload\\" + f); |
262 | goods.setFileName3( "\\upload\\" + f); |
265 | goods.setFileName4( "\\upload\\" + f); |
268 | goods.setFileName5( "\\upload\\" + f); |
272 | goods.setUser(UserUtils.getUser()); |
279 | ActionContext.getContext().put( "url" , "goods_list.do" ); |
288 | public String bookloanlist() throws IOException { |
289 | User user1 = UserUtils.getUser(); |
290 | if (user1 == null || user1.getId() == null ) { |
291 | ActionContext.getContext().put( "login" , 1 ); |
294 | BookLoan bookLoan = new BookLoan(); |
295 | Goods goods1 = new Goods(); |
296 | goods1.setUser(user1); |
297 | bookLoan.setGoods(goods1); |
298 | if (goods.getItemTypeSecondary() != null && !goods.getItemTypeSecondary().equals( "" )) { |
299 | goods1.setItemTypeSecondary(goods.getItemTypeSecondary()); |
300 | bookLoan.setGoods(goods1); |
302 | Pager<BookLoan> pagers = bookLoanService.pagers(bookLoan); |
303 | ActionContext.getContext().put( "pagers" , pagers); |
304 | Pager<ItemTypeSecondary> itemTypelist = itemTypeSecondaryService.getList( null ); |
305 | ActionContext.getContext().put( "itemTypelist" , itemTypelist); |
306 | ActionContext.getContext().put( "user" , user1); |
307 | ActionContext.getContext().put( "bean" , goods); |
315 | public void loan() throws IOException { |
316 | User user = UserUtils.getUser(); |
317 | JSONObject jsonObject = new JSONObject(); |
319 | jsonObject.put( "flag" , false ); |
320 | JsonUtils.jsonObject(jsonObject); |
323 | Goods goods1 = service.findById(goods.getId()); |
324 | BookLoan bookLoan = new BookLoan(); |
325 | bookLoan.setIsDelete( 0 ); |
326 | bookLoan.setTime( new Date()); |
327 | bookLoan.setGoods(goods1); |
328 | bookLoan.setJyUser(user); |
330 | bookLoanService.save(bookLoan); |
331 | jsonObject.put( "flag" , true ); |
332 | JsonUtils.jsonObject(jsonObject); |
340 | public void back() throws IOException { |
341 | User user = UserUtils.getUser(); |
342 | JSONObject jsonObject = new JSONObject(); |
344 | jsonObject.put( "flag" , false ); |
345 | JsonUtils.jsonObject(jsonObject); |
348 | Goods goods1 = service.findById(goods.getId()); |
352 | service.update(goods1); |
354 | userService.update(user); |
355 | BookLoan bookLoan = bookLoanService.findById(bookLoanId); |
356 | bookLoan.setIsDelete( 1 ); |
358 | bookLoanService.update(bookLoan); |
359 | jsonObject.put( "flag" , true ); |
360 | jsonObject.put( "url" , "bookloan_list.do" ); |
361 | JsonUtils.jsonObject(jsonObject); |
366 | public void backs() throws IOException { |
367 | User user = UserUtils.getUser(); |
368 | JSONObject jsonObject = new JSONObject(); |
370 | jsonObject.put( "flag" , false ); |
371 | JsonUtils.jsonObject(jsonObject); |
374 | Goods goods1 = service.findById(goods.getId()); |
376 | service.update(goods1); |
378 | userService.update(user); |
379 | jsonObject.put( "flag" , true ); |
380 | jsonObject.put( "url" , "bookloan_list.do" ); |
381 | JsonUtils.jsonObject(jsonObject); |
386 | public void delete() throws IOException { |
387 | goods.setIsDelete( 1 ); |
388 | service.updates(goods); |
389 | JSONObject jsonObject = new JSONObject(); |
390 | jsonObject.put( "flag" , true ); |
391 | jsonObject.put( "url" , "goods_list.do" ); |
392 | JsonUtils.jsonObject(jsonObject); |
396 | public Goods getModel() { |
403 | public List<File> getFile() { |
407 | public void setFile(List<File> file) { |
411 | public List<String> getFileFileName() { |
415 | public void setFileFileName(List<String> fileFileName) { |
416 | this .fileFileName = fileFileName; |
419 | public List<String> getFileContentType() { |
420 | return fileContentType; |
423 | public void setFileContentType(List<String> fileContentType) { |
424 | this .fileContentType = fileContentType; |
427 | public Integer getBookLoanId() { |
431 | public void setBookLoanId(Integer bookLoanId) { |
432 | this .bookLoanId = bookLoanId; |