Biblioteca Java - Blame information for rev 9
Subversion Repositories:
(root)/Spring/SpringWebMVC/InventoryHibernate/src/main/java/com/linkscreens/inventory/service/InventoryServiceImpl.java
Rev | Author | Line No. | Line |
---|---|---|---|
9 | mihai | 1 | package com.linkscreens.inventory.service; |
2 | |||
3 | import com.linkscreens.inventory.dao.InventoryDao; | ||
4 | import com.linkscreens.inventory.entity.FilterParameters; | ||
5 | import com.linkscreens.inventory.entity.InventoryItem; | ||
6 | import com.linkscreens.inventory.pdfgenerator.PDFGenerator; | ||
7 | import org.springframework.stereotype.Service; | ||
8 | |||
9 | import javax.transaction.Transactional; | ||
10 | import java.io.File; | ||
11 | import java.util.Collections; | ||
12 | import java.util.HashMap; | ||
13 | import java.util.List; | ||
14 | import java.util.Map; | ||
15 | |||
16 | /** | ||
17 | * Service for managing inventory items. | ||
18 | */ | ||
19 | @Service | ||
20 | public class InventoryServiceImpl implements InventoryService { | ||
21 | |||
22 | private InventoryDao inventoryDao; | ||
23 | |||
24 | public void setInventoryDao(InventoryDao inventoryDao) { | ||
25 | this.inventoryDao = inventoryDao; | ||
26 | } | ||
27 | |||
28 | @Transactional | ||
29 | @Override | ||
30 | public void addNewInventoryItem(InventoryItem item) { | ||
31 | inventoryDao.addNewInventoryItem(item); | ||
32 | } | ||
33 | |||
34 | @Transactional | ||
35 | @Override | ||
36 | public InventoryItem getItemById(Long itemId) { | ||
37 | InventoryItem item = inventoryDao.getItemById(itemId); | ||
38 | if (item.getAnLunaAdaugare() != null && !item.getAnLunaAdaugare().isEmpty() && item.getAnLunaAdaugare().contains("/")) { | ||
39 | item.setAnAdaugare(item.getAnLunaAdaugare().split("/")[0]); | ||
40 | item.setLunaAdaugare(item.getAnLunaAdaugare().split("/")[1]); | ||
41 | } else { | ||
42 | item.setAnAdaugare("2010"); | ||
43 | item.setLunaAdaugare("01"); | ||
44 | } | ||
45 | if (item.getAnLunaPrimaRata() != null && !item.getAnLunaPrimaRata().isEmpty() && item.getAnLunaPrimaRata().contains("/")) { | ||
46 | item.setAnPrimaRata(item.getAnLunaPrimaRata().split("/")[0]); | ||
47 | item.setLunaPrimaRata(item.getAnLunaPrimaRata().split("/")[1]); | ||
48 | } else { | ||
49 | item.setAnPrimaRata("2010"); | ||
50 | item.setLunaPrimaRata("01"); | ||
51 | } | ||
52 | return item; | ||
53 | } | ||
54 | |||
55 | @Transactional | ||
56 | @Override | ||
57 | public List<InventoryItem> getAllInventoryItems() { | ||
58 | List<InventoryItem> items = inventoryDao.getAllInventoryItems(); | ||
59 | return items; | ||
60 | } | ||
61 | |||
62 | @Transactional | ||
63 | @Override | ||
64 | public List<InventoryItem> geFilteredInventoryItems(FilterParameters filter) { | ||
65 | // get all inventory items and calculate totals for each cont and general total | ||
66 | List<InventoryItem> items = inventoryDao.geFilteredInventoryItems(filter); | ||
67 | Map<String, InventoryItem> totalsMap = new HashMap<String, InventoryItem>(); | ||
68 | InventoryItem total = new InventoryItem("TOTAL GENERAL", ""); | ||
69 | for (InventoryItem item : items) { | ||
70 | if (totalsMap.get(item.getCont()) == null) { | ||
71 | totalsMap.put(item.getCont(), new InventoryItem("TOTAL CONT " + item.getCont(), item.getCont())); | ||
72 | totalsMap.get(item.getCont()).setAnLunaAdaugare(item.getAnLunaAdaugare()); | ||
73 | totalsMap.get(item.getCont()).setCont(item.getCont()); | ||
74 | } | ||
75 | totalsMap.get(item.getCont()).setValoare(item.getValoare().add(totalsMap.get(item.getCont()).getValoare())); | ||
76 | totalsMap.get(item.getCont()).setAmortizarePrecedenta(item.getAmortizarePrecedenta().add(totalsMap.get(item.getCont()).getAmortizarePrecedenta())); | ||
77 | totalsMap.get(item.getCont()).setAmortizareCurenta(item.getAmortizareCurenta().add(totalsMap.get(item.getCont()).getAmortizareCurenta())); | ||
78 | totalsMap.get(item.getCont()).setAmortizareTotala(item.getAmortizareTotala().add(totalsMap.get(item.getCont()).getAmortizareTotala())); | ||
79 | totalsMap.get(item.getCont()).setValoareRamasa(item.getValoareRamasa().add(totalsMap.get(item.getCont()).getValoareRamasa())); | ||
80 | total.setValoare(total.getValoare().add(item.getValoare())); | ||
81 | total.setAmortizarePrecedenta(total.getAmortizarePrecedenta().add(item.getAmortizarePrecedenta())); | ||
82 | total.setAmortizareCurenta(total.getAmortizareCurenta().add(item.getAmortizareCurenta())); | ||
83 | total.setAmortizareTotala(total.getAmortizareTotala().add(item.getAmortizareTotala())); | ||
84 | total.setValoareRamasa(total.getValoareRamasa().add(item.getValoareRamasa())); | ||
85 | } | ||
86 | for (String key : totalsMap.keySet()) { | ||
87 | items.add(totalsMap.get(key)); | ||
88 | } | ||
89 | items.add(total); | ||
90 | Collections.sort(items); | ||
91 | return items; | ||
92 | } | ||
93 | |||
94 | @Transactional | ||
95 | @Override | ||
96 | public String generatePDFFile(FilterParameters filter, File filePath, boolean isFull) { | ||
97 | List<InventoryItem> items = geFilteredInventoryItems(filter); | ||
98 | if (items != null && !items.isEmpty()) { | ||
99 | String fileName = filePath.getAbsolutePath() + "\\" | ||
100 | + filter.getStartYear() + "_" + filter.getStartMonth() + "_" + String.valueOf(System.currentTimeMillis() + ".pdf"); | ||
101 | PDFGenerator.createPDF(fileName, items, isFull); | ||
102 | return fileName; | ||
103 | } | ||
104 | return null; | ||
105 | } | ||
106 | |||
107 | @Transactional | ||
108 | @Override | ||
109 | public void updateInventoryItem(InventoryItem updatedItem) { | ||
110 | if (updatedItem.getAnPrimaRata() != null && updatedItem.getLunaPrimaRata() != null) { | ||
111 | updatedItem.setAnLunaPrimaRata(updatedItem.getAnPrimaRata() + "/" + updatedItem.getLunaPrimaRata()); | ||
112 | } | ||
113 | if (updatedItem.getAnAdaugare() != null && updatedItem.getLunaAdaugare() != null) { | ||
114 | updatedItem.setAnLunaAdaugare(updatedItem.getAnAdaugare() + "/" + updatedItem.getLunaAdaugare()); | ||
115 | } | ||
116 | inventoryDao.updateInventoryItem(updatedItem); | ||
117 | } | ||
118 | |||
119 | @Transactional | ||
120 | @Override | ||
121 | public void deleteItem(Long itemId) { | ||
122 | inventoryDao.deleteItem(itemId); | ||
123 | } | ||
124 | } |