001package com.xznu.edu.leave.action;
002 
003/**
004 * 用户新增
005 */
006 
007import com.opensymphony.xwork2.ActionContext;
008import com.opensymphony.xwork2.ActionSupport;
009import com.opensymphony.xwork2.ModelDriven;
010import com.xznu.edu.leave.model.BookLoan;
011import com.xznu.edu.leave.model.Goods;
012import com.xznu.edu.leave.model.ItemTypeSecondary;
013import com.xznu.edu.leave.model.User;
014import com.xznu.edu.leave.service.*;
015import com.xznu.edu.leave.utils.JsonUtils;
016import com.xznu.edu.leave.utils.Pager;
017import com.xznu.edu.leave.utils.UUIDUtils;
018import com.xznu.edu.leave.utils.UserUtils;
019import net.sf.json.JSONArray;
020import net.sf.json.JSONObject;
021import org.apache.struts2.ServletActionContext;
022import org.springframework.beans.factory.annotation.Autowired;
023import org.springframework.context.annotation.Scope;
024import org.springframework.stereotype.Controller;
025import org.joda.time.DateTime;
026 
027import javax.servlet.http.HttpServletRequest;
028import java.io.*;
029import java.util.Date;
030import java.util.List;
031 
032@Controller("goodsAction")
033@Scope("prototype")
034public class GoodsAction extends ActionSupport implements ModelDriven<Goods> {
035    @Autowired
036    private BookLoanService bookLoanService;
037    @Autowired
038    private GoodsService service;
039    @Autowired
040    private UserService userService;
041    @Autowired
042    private ItemTypeSecondaryService itemTypeSecondaryService;
043    private Goods goods;
044    private List<File> file;
045    private List<String> fileFileName;
046    private List<String> fileContentType;
047    private Integer bookLoanId;
048 
049 
050    /**
051     * list
052     *
053     * @return
054     */
055    public String list() throws IOException {
056        User user1 = UserUtils.getUser();
057        if (user1 == null || user1.getId() == null) {
058            ActionContext.getContext().put("login", 1);
059            return SUCCESS;
060        }
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);
069            return SUCCESS;
070        } else {
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);
078            return SUCCESS;
079        }
080    }
081 
082    public String tjlist() throws IOException {
083        User user1 = UserUtils.getUser();
084        if (user1 == null || user1.getId() == null) {
085            ActionContext.getContext().put("login", 1);
086            return SUCCESS;
087        }
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);
096            return SUCCESS;
097        } else {
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);
105            return SUCCESS;
106        }
107    }
108 
109    public String shlist() throws IOException {
110        User user1 = UserUtils.getUser();
111        if (user1 == null || user1.getId() == null) {
112            ActionContext.getContext().put("login", 1);
113            return SUCCESS;
114        }
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);
123        }
124        return SUCCESS;
125    }
126 
127    /**
128     * 跳转add
129     *
130     * @return
131     */
132    public String add() {
133        Pager<ItemTypeSecondary> pagers = itemTypeSecondaryService.getList(null);
134        ActionContext.getContext().put("pagers", pagers);
135        return SUCCESS;
136    }
137 
138    /**
139     * 查询修改
140     *
141     * @return
142     */
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);
148        return SUCCESS;
149    }
150 
151    /**
152     * 详情
153     *
154     * @return
155     */
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);
161        return SUCCESS;
162    }
163 
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);
172    }
173 
174    /**
175     * 上架图书
176     *
177     * @return
178     */
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);
187    }
188 
189    /**
190     * 更新
191     *
192     * @return
193     */
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");
198        if (file != null) {
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];
204                int length = 0;
205                while (-1 != (length = is.read(buffer, 0, buffer.length))) {
206                    os.write(buffer);
207                }
208                os.close();
209                is.close();
210                if (i == 0) {
211                    goods.setFileName1("\\upload\\" + f);
212                }
213                if (i == 1) {
214                    goods.setFileName2("\\upload\\" + f);
215                }
216                if (i == 2) {
217                    goods.setFileName3("\\upload\\" + f);
218                }
219                if (i == 3) {
220                    goods.setFileName4("\\upload\\" + f);
221                }
222                if (i == 4) {
223                    goods.setFileName5("\\upload\\" + f);
224                }
225            }
226        }
227        service.updates(goods);
228        ActionContext.getContext().put("url", "goods_list.do");
229        return "redirect";
230    }
231 
232    /**
233     * 保存
234     *
235     * @return
236     */
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");
241        if (file != null) {
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];
249                int length = 0;
250                while (-1 != (length = is.read(buffer, 0, buffer.length))) {
251                    os.write(buffer);
252                }
253                os.close();
254                is.close();
255                if (i == 0) {
256                    goods.setFileName1("\\upload\\" + f);
257                }
258                if (i == 1) {
259                    goods.setFileName2("\\upload\\" + f);
260                }
261                if (i == 2) {
262                    goods.setFileName3("\\upload\\" + f);
263                }
264                if (i == 3) {
265                    goods.setFileName4("\\upload\\" + f);
266                }
267                if (i == 4) {
268                    goods.setFileName5("\\upload\\" + f);
269                }
270            }
271        }
272        goods.setUser(UserUtils.getUser());
273        goods.setCount(0);
274        goods.setIsSj(0);
275        goods.setIsJy(0);
276        goods.setIsSd(0);
277        goods.setIsSh(0);
278        service.save(goods);
279        ActionContext.getContext().put("url", "goods_list.do");
280        return "redirect";
281    }
282 
283    /**
284     * list
285     *
286     * @return
287     */
288    public String bookloanlist() throws IOException {
289        User user1 = UserUtils.getUser();
290        if (user1 == null || user1.getId() == null) {
291            ActionContext.getContext().put("login", 1);
292            return SUCCESS;
293        } else {
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);
301            }
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);
308        }
309        return SUCCESS;
310    }
311 
312    /**
313     * 保存借阅
314     */
315    public void loan() throws IOException {
316        User user = UserUtils.getUser();
317        JSONObject jsonObject = new JSONObject();
318        if (user == null) {
319            jsonObject.put("flag", false);
320            JsonUtils.jsonObject(jsonObject);
321        } else {
322            if (goods != null) {
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);
329                bookLoan.setIsYj(0);
330                bookLoanService.save(bookLoan);
331                jsonObject.put("flag", true);
332                JsonUtils.jsonObject(jsonObject);
333            }
334        }
335    }
336 
337    /**
338     * 归还
339     */
340    public void back() throws IOException {
341        User user = UserUtils.getUser();
342        JSONObject jsonObject = new JSONObject();
343        if (user == null) {
344            jsonObject.put("flag", false);
345            JsonUtils.jsonObject(jsonObject);
346        } else {
347            if (goods != null) {
348                Goods goods1 = service.findById(goods.getId());
349                goods1.setIsJy(0);
350                goods1.setIsSd(0);
351                goods1.setIsSj(0);
352                service.update(goods1);
353                user.setZd(0);
354                userService.update(user);
355                BookLoan bookLoan = bookLoanService.findById(bookLoanId);
356                bookLoan.setIsDelete(1);
357                bookLoan.setIsYj(3);
358                bookLoanService.update(bookLoan);
359                jsonObject.put("flag", true);
360                jsonObject.put("url", "bookloan_list.do");
361                JsonUtils.jsonObject(jsonObject);
362            }
363        }
364    }
365 
366    public void backs() throws IOException {
367        User user = UserUtils.getUser();
368        JSONObject jsonObject = new JSONObject();
369        if (user == null) {
370            jsonObject.put("flag", false);
371            JsonUtils.jsonObject(jsonObject);
372        } else {
373            if (goods != null) {
374                Goods goods1 = service.findById(goods.getId());
375                goods1.setIsSd(1);
376                service.update(goods1);
377                user.setZd(1);
378                userService.update(user);
379                jsonObject.put("flag", true);
380                jsonObject.put("url", "bookloan_list.do");
381                JsonUtils.jsonObject(jsonObject);
382            }
383        }
384    }
385 
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);
393    }
394 
395    @Override
396    public Goods getModel() {
397        if (goods == null) {
398            goods = new Goods();
399        }
400        return goods;
401    }
402 
403    public List<File> getFile() {
404        return file;
405    }
406 
407    public void setFile(List<File> file) {
408        this.file = file;
409    }
410 
411    public List<String> getFileFileName() {
412        return fileFileName;
413    }
414 
415    public void setFileFileName(List<String> fileFileName) {
416        this.fileFileName = fileFileName;
417    }
418 
419    public List<String> getFileContentType() {
420        return fileContentType;
421    }
422 
423    public void setFileContentType(List<String> fileContentType) {
424        this.fileContentType = fileContentType;
425    }
426 
427    public Integer getBookLoanId() {
428        return bookLoanId;
429    }
430 
431    public void setBookLoanId(Integer bookLoanId) {
432        this.bookLoanId = bookLoanId;
433    }
434}
最近下载更多
zolscy  LV24 2024年11月29日
599142776  LV2 2023年12月7日
DarcyLi  LV3 2023年10月9日
18584457462  LV5 2023年9月27日
2131234536546  LV7 2023年9月14日
qfch120  LV8 2023年4月16日
11sdvszb  LV2 2023年4月1日
北方菜  LV11 2023年3月2日
zhaoxiang123456  LV4 2023年2月12日
齐吊大神  LV6 2022年12月20日
最近浏览更多
无异偶  LV3 2024年12月30日
MQ-EQW 2024年12月18日
暂无贡献等级
zolscy  LV24 2024年11月29日
LoveSummer  LV6 2024年10月31日
krispeng  LV14 2024年10月2日
6664146541684  LV7 2024年9月5日
wanxiaoqiao52866414  LV1 2024年7月1日
刘昊然  LV1 2024年7月1日
326402  LV1 2024年6月17日
2267068802  LV1 2024年6月11日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友