19 package org.turro.dossier.dw;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Date;
24 import java.util.EnumMap;
25 import java.util.HashSet;
26 import java.util.List;
28 import org.turro.dossier.db.DossierPU;
29 import org.turro.dossier.dossier.DossierData;
30 import org.turro.dossier.dossier.DossierReportItem;
31 import org.turro.dossier.dossier.DossierValues;
32 import org.turro.dossier.entity.Dossier;
33 import org.turro.dossier.entity.IssueParticipantRole;
34 import org.turro.dossier.entity.IssueResolution;
35 import org.turro.dossier.entity.IssueStatus;
36 import org.turro.dossier.entity.IssueType;
37 import org.turro.dossier.search.DossierIds;
38 import org.turro.elephant.db.WhereClause;
39 import org.turro.i18n.I_;
40 import org.turro.jpa.Dao;
41 import org.turro.math.Round;
42 import org.turro.util.PhraseBuilder;
51 private HashSet<DossierReportItem> items;
52 private String participantId;
54 private Collection<DossierIds> dossierIds;
61 ArrayList al =
new ArrayList();
67 this.participantId = participantId;
69 this.dossierIds = dossierIds;
76 return (
double) getItems().size();
80 if(prevision ==
null) {
83 prevision.
expenses += dri.prevision.expenses;
84 prevision.hours += dri.prevision.hours;
85 prevision.price += dri.prevision.price;
95 reality.
expenses += dri.reality.expenses;
96 reality.hours += dri.reality.hours;
97 reality.price += dri.reality.price;
110 if(dri.type.equals(type)) {
120 if(dri.status.equals(status)) {
130 if(dri.status.isFinished() && dri.resolution.equals(resolution)) {
140 if(dri.status.isFinished() && dri.resolution.isSolved()) {
150 if(dri.status.isFinished() && !(dri.resolution.isSolved()) && !(dri.resolution.isRejected())) {
160 if(dri.status.isFinished()) {
170 if(dri.status.isWorking()) {
180 if(dri.status.isStandBy()) {
188 ArrayList<String> list =
new ArrayList<>();
190 if(
I_.
byKey(dri.type.toString()).equals(type)) {
191 list.add(
"/issue/" + dri.issueId);
198 ArrayList<String> list =
new ArrayList<>();
200 if(
I_.
byKey(dri.status.toString()).equals(status)) {
201 list.add(
"/issue/" + dri.issueId);
208 ArrayList<String> list =
new ArrayList<>();
210 if(
I_.
byKey(dri.resolution.toString()).equals(resolution)) {
211 list.add(
"/issue/" + dri.issueId);
219 Map type =
new EnumMap<>(
IssueType.class);
222 if(d > 0.0) type.put(is, d);
231 if(d > 0.0) status.put(is, d);
240 if(d > 0.0) resolution.put(is, d);
251 double issues = 0, days = 0;
253 if(dri.status.isFinished() && dri.startDate !=
null &&
254 dri.solvedDate !=
null && dri.startDate.before(dri.solvedDate)) {
256 days = (dri.solvedDate.getTime() - dri.startDate.getTime()) / (24 * 60 * 60 * 1000);
259 return new Round(issues > 0 ? days / issues : 0).
decimals(2).value();
262 private String getInValue(Collection<DossierIds> dossierIds) {
263 PhraseBuilder pb =
new PhraseBuilder();
266 pb.addWord(
id.dossierId +
"");
267 pb.addPendingSeparator(
",");
269 pb.cancelSeparator();
271 return pb.toString();
274 private HashSet<DossierReportItem> getItems() {
276 items =
new HashSet<>();
277 init(participantId, role, dossierIds);
282 private void init(String participantId, IssueParticipantRole role, Collection<DossierIds> dossierIds) {
283 Dao dao =
new DossierPU();
284 WhereClause wc =
new WhereClause();
285 wc.addClause(
"select distinct issueId, type, status, resolution,");
286 wc.addClause(
"pexpenses, phours, pprice,");
287 wc.addClause(
"startDate, solvedDate,");
288 wc.addClause(
"commentCount, rexpenses,");
289 wc.addClause(
"rhours, rprice");
290 wc.addClause(
"from DWIssue as issue where 1=1");
291 if(participantId !=
null) {
292 wc.addClause(
"and participantId = :idContact");
293 wc.addClause(
"and participantRole = :role");
294 wc.addNamedValue(
"idContact", participantId);
295 wc.addNamedValue(
"role", role);
297 if(dossierIds !=
null && !dossierIds.isEmpty()) {
298 wc.addClause(
"and issue.dossierId in " + getInValue(dossierIds));
300 wc.addClause(
"and (issue.startDate <= :startDate or issue.startDate is null)");
301 wc.addNamedValue(
"startDate",
new Date());
302 List<Object[]> l = dao.getResultList(wc);
303 for(Object[] result : l) {
304 DossierReportItem dri =
new DossierReportItem();
305 dri.issueId = (Long) result[0];
306 dri.type = (IssueType) result[1];
307 dri.status = (IssueStatus) result[2];
308 dri.resolution = (IssueResolution) result[3];
309 dri.prevision.expenses = (Double) result[4];
310 dri.prevision.hours = (Double) result[5];
311 dri.prevision.price = (Double) result[6];
312 dri.setStartDate((Date) result[7], (Date) result[7]);
313 dri.solvedDate = (Date) result[8];
314 dri.commentCount = result[9] ==
null ? 0 : (Long) result[9];
315 dri.reality.expenses = result[10] ==
null ? 0 : (Double) result[10];
316 dri.reality.hours = result[11] ==
null ? 0 : (Double) result[11];
317 dri.reality.price = result[12] ==
null ? 0 : (Double) result[12];
DossierValues getPrevision()
Collection< String > getIssuesPathByStatus(String status)
Double getDaySpanAverage()
void setReportValues(String participantId, IssueParticipantRole role, Long dossierId)
double getPositivelySolved()
Map< IssueResolution, Double > getIssuesByResolution()
double getIssueCountByType(IssueType type)
void setReportValues(Dossier dossier)
Collection< String > getIssuesPathByType(String type)
double getIssueCountByResolution(IssueResolution resolution)
DossierValues getReality()
Map< IssueStatus, Double > getIssuesByStatus()
double getNegativelySolved()
void setReportValues(String participantId, IssueParticipantRole role, Collection< DossierIds > dossierIds)
Map< IssueType, Double > getIssuesByType()
double getIssueCountByStatus(IssueStatus status)
Collection< String > getIssuesPathByResolution(String resolution)
static String byKey(String key)
Round decimals(int digits)
double perCent(int digits)