1 |
torben |
2838 |
package dk.daoas.adressevedligehold;
|
2 |
|
|
|
3 |
|
|
import java.util.HashMap;
|
4 |
|
|
import java.util.List;
|
5 |
|
|
import java.util.Properties;
|
6 |
|
|
|
7 |
|
|
import javax.mail.Message;
|
8 |
|
|
import javax.mail.MessagingException;
|
9 |
|
|
import javax.mail.Session;
|
10 |
|
|
import javax.mail.Transport;
|
11 |
|
|
import javax.mail.internet.InternetAddress;
|
12 |
|
|
import javax.mail.internet.MimeMessage;
|
13 |
|
|
|
14 |
|
|
import dk.daoas.adressevedligehold.beans.Address;
|
15 |
|
|
import dk.daoas.adressevedligehold.beans.Address.AddressState;
|
16 |
|
|
import dk.daoas.adressevedligehold.util.TimingHelper;
|
17 |
|
|
|
18 |
|
|
public class AddressReport {
|
19 |
|
|
|
20 |
|
|
class NumEntry {
|
21 |
|
|
int open = 0;
|
22 |
|
|
int closed = 0;
|
23 |
|
|
int modified = 0;
|
24 |
|
|
int created = 0;
|
25 |
|
|
|
26 |
|
|
public void updateFromState(AddressState st) {
|
27 |
|
|
if (st == AddressState.OPENED)
|
28 |
|
|
open++;
|
29 |
|
|
if (st == AddressState.MODIFIED)
|
30 |
|
|
modified++;
|
31 |
|
|
if (st == AddressState.CLOSED)
|
32 |
|
|
closed++;
|
33 |
|
|
}
|
34 |
|
|
public void updateFromOther(NumEntry other) {
|
35 |
|
|
this.open += other.open;
|
36 |
|
|
this.modified += other.modified;
|
37 |
|
|
this.closed += other.closed;
|
38 |
|
|
this.created += other.created;
|
39 |
|
|
}
|
40 |
|
|
}
|
41 |
|
|
class WeekEntry {
|
42 |
|
|
NumEntry man = new NumEntry();
|
43 |
|
|
NumEntry tir = new NumEntry();
|
44 |
|
|
NumEntry ons = new NumEntry();
|
45 |
|
|
NumEntry tor = new NumEntry();
|
46 |
|
|
NumEntry fre = new NumEntry();
|
47 |
|
|
NumEntry lor = new NumEntry();
|
48 |
|
|
NumEntry son = new NumEntry();
|
49 |
|
|
|
50 |
|
|
public void incrementFromOther(WeekEntry other) {
|
51 |
|
|
man.updateFromOther(other.man);
|
52 |
|
|
tir.updateFromOther(other.tir);
|
53 |
|
|
ons.updateFromOther(other.ons);
|
54 |
|
|
tor.updateFromOther(other.tor);
|
55 |
|
|
fre.updateFromOther(other.fre);
|
56 |
|
|
lor.updateFromOther(other.lor);
|
57 |
|
|
son.updateFromOther(other.son);
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
public void incrementCreated() {
|
61 |
|
|
man.created++;
|
62 |
|
|
tir.created++;
|
63 |
|
|
ons.created++;
|
64 |
|
|
tor.created++;
|
65 |
|
|
fre.created++;
|
66 |
|
|
lor.created++;
|
67 |
|
|
son.created++;
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
|
71 |
torben |
2839 |
AddressManager addrManager;
|
72 |
torben |
2838 |
List<Address> addressList;
|
73 |
|
|
int entryCount;
|
74 |
|
|
EntryUgedage ugedage;
|
75 |
|
|
AddressSource source;
|
76 |
|
|
TimingHelper timer;
|
77 |
|
|
boolean writeBack;
|
78 |
|
|
|
79 |
|
|
//TODO: Afviste adresser
|
80 |
|
|
public AddressReport(AddressManager addrManager, int entryCount, EntryUgedage ugedage, AddressSource source, TimingHelper timer, boolean writeBack ) {
|
81 |
torben |
2839 |
this.addrManager = addrManager;
|
82 |
torben |
2838 |
addressList = addrManager.getAddressList();
|
83 |
|
|
this.entryCount = entryCount;
|
84 |
|
|
this.ugedage = ugedage;
|
85 |
|
|
this.source = source;
|
86 |
|
|
this.timer = timer;
|
87 |
|
|
this.writeBack = writeBack;
|
88 |
|
|
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
public void sendRapport() {
|
92 |
|
|
System.out.println("Sending mail");
|
93 |
|
|
|
94 |
|
|
String reportData = getReportData();
|
95 |
|
|
String subject = "Indlæsnings rapport for " + source.getDistributor();
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
Properties props = new Properties();
|
99 |
|
|
props.put("mail.smtp.host", "10.30.1.28");
|
100 |
|
|
//props.put("mail.smtp.host", "192.168.12.10");
|
101 |
|
|
|
102 |
|
|
try {
|
103 |
|
|
// create some properties and get the default Session
|
104 |
|
|
Session session = Session.getDefaultInstance(props, null);
|
105 |
|
|
session.setDebug(false);
|
106 |
|
|
|
107 |
|
|
MimeMessage msg = new MimeMessage(session);
|
108 |
|
|
msg.setFrom( new InternetAddress("no-reply@daoas.dk") );
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
msg.setRecipient(Message.RecipientType.TO, new InternetAddress("thn@daoas.dk") );//TODO: mulighed for at ændre modtager mail
|
112 |
|
|
msg.setSubject( subject );
|
113 |
|
|
msg.setContent(reportData, "text/html; charset=utf-8");
|
114 |
|
|
|
115 |
|
|
Transport.send(msg);
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
} catch (MessagingException e) {
|
119 |
|
|
System.out.println("Unable to send report mail " + e.getMessage() );
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
public String getReportData() {
|
126 |
|
|
|
127 |
|
|
WeekEntry total = new WeekEntry();
|
128 |
|
|
HashMap<Short, WeekEntry> postnrEntries = new HashMap<Short,WeekEntry>();
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
int antalUdenKommunekode = 0;
|
132 |
|
|
int antalUdenLatitude = 0;
|
133 |
|
|
int antalUdenDBKBane = 0;
|
134 |
|
|
|
135 |
|
|
// first gather the intel
|
136 |
|
|
for (Address a : addressList) {
|
137 |
|
|
if (a.kommunekode == 0 || a.vejkode == 0) {
|
138 |
|
|
antalUdenKommunekode++;
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
if (a.latitude == 0 || a.longitude == 0) {
|
142 |
|
|
antalUdenLatitude++;
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
if (a.state == AddressState.NOT_CHANGED) {
|
146 |
|
|
continue;
|
147 |
|
|
}
|
148 |
|
|
if (a.dbkBane == 0) {
|
149 |
|
|
antalUdenDBKBane++;
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
WeekEntry weekEntry = postnrEntries.get(a.postnr);
|
153 |
|
|
if (weekEntry == null) {
|
154 |
|
|
weekEntry = new WeekEntry();
|
155 |
|
|
postnrEntries.put(a.postnr, weekEntry);
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
if (a.state == AddressState.CREATED) {
|
160 |
|
|
weekEntry.incrementCreated();
|
161 |
|
|
} else {
|
162 |
|
|
weekEntry.man.updateFromState(a.stateMan);
|
163 |
|
|
weekEntry.tir.updateFromState(a.stateTir);
|
164 |
|
|
weekEntry.ons.updateFromState(a.stateOns);
|
165 |
|
|
weekEntry.tor.updateFromState(a.stateTor);
|
166 |
|
|
weekEntry.fre.updateFromState(a.stateFre);
|
167 |
|
|
weekEntry.lor.updateFromState(a.stateLor);
|
168 |
|
|
weekEntry.son.updateFromState(a.stateSon);
|
169 |
|
|
|
170 |
|
|
}
|
171 |
|
|
}
|
172 |
|
|
for (WeekEntry w : postnrEntries.values()) {
|
173 |
|
|
total.incrementFromOther(w);
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
StringBuilder sb = new StringBuilder();
|
177 |
|
|
|
178 |
|
|
sb.append("<h1>Indlæsnings rapport for " + source.getDistributor() + " </h1>");
|
179 |
|
|
sb.append("Filnavn: ").append( source.getFilename() ).append("<br>");
|
180 |
|
|
sb.append("Tidsforbrug: ").append( timer.getElapsed() ).append("ms. <br>");
|
181 |
|
|
sb.append("Skriv til DB: ").append( writeBack ).append("<br>");
|
182 |
|
|
sb.append("Antal entries: " ).append( entryCount ).append("<br>");
|
183 |
torben |
2839 |
sb.append("Antal afviste: " ).append( addrManager.getAfvistAntal() ).append("<br>");
|
184 |
torben |
2838 |
|
185 |
|
|
sb.append("<h2>Data Mangler</h2>\n");
|
186 |
|
|
sb.append("<pre>");
|
187 |
|
|
sb.append("Mangler kommune/vejkode: ").append(antalUdenKommunekode).append("\n");
|
188 |
|
|
sb.append("Mangler DBK bane: ").append(antalUdenDBKBane).append("\n");
|
189 |
|
|
sb.append("Mangler latitude/longitude: ").append(antalUdenLatitude).append("\n");
|
190 |
|
|
sb.append("</pre>");
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
sb.append("<h2>Ændrings oversigt</h2>\n");
|
195 |
|
|
sb.append("<table>");
|
196 |
|
|
|
197 |
|
|
sb.append("<tr><td> </td><td>Mandag</td><td>Tirsdag</td><td>Onsdag</td><td>Torsdag</td><td>Fredag</td><td>Lørdag</td><td>Søndag</td></tr>");
|
198 |
|
|
sb.append("<tr><td>Oprettet:</td><td>").append(total.man.created).append("</td><td>").append(total.tir.created).append("</td><td>").append(total.ons.created).append("</td><td>").append(total.tor.created).append("</td><td>").append(total.fre.created).append("</td><td>").append(total.lor.created).append("</td><td>").append(total.son.created).append("</td></tr>");
|
199 |
|
|
sb.append("<tr><td>Åbnet:</td><td>").append(total.man.open).append("</td><td>").append(total.tir.open).append("</td><td>").append(total.ons.open).append("</td><td>").append(total.tor.open).append("</td><td>").append(total.fre.open).append("</td><td>").append(total.lor.open).append("</td><td>").append(total.son.open).append("</td></tr>");
|
200 |
|
|
sb.append("<tr><td>Ændret:</td><td>").append(total.man.modified).append("</td><td>").append(total.tir.modified).append("</td><td>").append(total.ons.modified).append("</td><td>").append(total.tor.modified).append("</td><td>").append(total.fre.modified).append("</td><td>").append(total.lor.modified).append("</td><td>").append(total.son.modified).append("</td></tr>");
|
201 |
|
|
sb.append("<tr><td>Lukket:</td><td>").append(total.man.closed).append("</td><td>").append(total.tir.closed).append("</td><td>").append(total.ons.closed).append("</td><td>").append(total.tor.closed).append("</td><td>").append(total.fre.closed).append("</td><td>").append(total.lor.closed).append("</td><td>").append(total.son.closed).append("</td></tr>");
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
sb.append("</table><br>\n");
|
206 |
|
|
|
207 |
|
|
return sb.toString();
|
208 |
|
|
}
|
209 |
|
|
}
|