19 package org.turro.dossier.dw;
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.List;
24 import org.amic.util.date.CheckDate;
25 import org.turro.string.Strings;
26 import org.turro.action.Contacts;
27 import org.turro.dossier.db.DossierPU;
28 import org.turro.dossier.entity.Category;
29 import org.turro.dossier.entity.Dossier;
30 import org.turro.dossier.entity.IssueParticipantRole;
31 import org.turro.dossier.entity.IssueResolution;
32 import org.turro.dossier.entity.IssueStatus;
33 import org.turro.dossier.entity.IssueType;
34 import org.turro.elephant.db.WhereClause;
35 import org.turro.jpa.Dao;
36 import org.turro.plugin.contacts.IContact;
37 import org.turro.util.Chars;
38 import org.zkoss.bind.annotation.BindingParam;
39 import org.zkoss.bind.annotation.Command;
40 import org.zkoss.bind.annotation.Init;
41 import org.zkoss.bind.annotation.NotifyChange;
42 import org.zkoss.zul.SimpleCategoryModel;
43 import org.zkoss.zul.SimplePieModel;
51 private Date start, end;
56 private List<DWChart> charts;
80 this.category = category;
88 this.dossier = dossier;
96 this.contact = contact;
102 start =
new CheckDate().addYears(-5).setDay(1).getDate();
103 end =
new CheckDate().addMonths(1).setDay(31).getDate();
104 charts =
new ArrayList<>();
112 @NotifyChange(
"model")
118 }
else if(entity instanceof
Dossier) {
119 this.dossier = (
Dossier) entity;
120 this.category =
null;
123 this.category =
null;
127 @NotifyChange(
"model")
133 @NotifyChange(
"model")
158 SimpleCategoryModel cm =
new SimpleCategoryModel();
160 wc.
addClause(
"select participantId, resolution, count(distinct issueId)");
162 wc.
addClause(
"where participantRole = :role");
166 addFilter(wc,
"startDate",
null);
168 wc.
addClause(
"group by participantId, resolution");
169 List<Object[]> results = getDao().getResultList(wc);
170 for(Object o[] : results) {
174 cm.setValue(resolution.toString(), participant.
getName(), (Number) o[2]);
183 chart.
setHeight((results.size() * 90 + 40) +
"");
188 SimplePieModel cm =
new SimplePieModel();
190 wc.
addClause(
"select status, count(distinct issueId)");
193 addFilter(wc,
"startDate", role);
195 List<Object[]> results = getDao().getResultList(wc);
196 for(Object o[] : results) {
198 cm.setValue(status.toString(), (Number) o[1]);
210 SimplePieModel cm =
new SimplePieModel();
212 wc.
addClause(
"select type, count(distinct issueId)");
215 addFilter(wc,
"startDate", role);
217 List<Object[]> results = getDao().getResultList(wc);
218 for(Object o[] : results) {
220 cm.setValue(type.toString(), (Number) o[1]);
232 SimplePieModel cm =
new SimplePieModel();
234 wc.
addClause(
"select resolution, count(distinct issueId)");
237 addFilter(wc,
"startDate", role);
239 List<Object[]> results = getDao().getResultList(wc);
240 for(Object o[] : results) {
242 cm.setValue(resolution.toString(), (Number) o[1]);
254 SimpleCategoryModel cm =
new SimpleCategoryModel();
256 wc.
addClause(
"select concat(year(solvedDate), '-', month(solvedDate)), resolution, count(distinct issueId)");
259 addFilter(wc,
"solvedDate", role);
260 wc.
addClause(
"group by concat(year(solvedDate), '-', month(solvedDate)), resolution");
261 wc.
addClause(
"order by concat(year(solvedDate), '-', month(solvedDate))");
262 List<Object[]> results = getDao().getResultList(wc);
263 for(Object o[] : results) {
265 String month = (String) o[0];
266 cm.setValue(resolution.toString(), month, (Number) o[2]);
273 chart.
setWidth((cm.getCategories().size() * 70 + 40) +
"");
278 SimpleCategoryModel cm =
new SimpleCategoryModel();
280 wc.
addClause(
"select concat(year(startDate), '-', month(startDate)), status, count(distinct issueId)");
283 addFilter(wc,
"startDate", role);
284 wc.
addClause(
"group by concat(year(startDate), '-', month(startDate)), status");
285 wc.
addClause(
"order by concat(year(startDate), '-', month(startDate))");
286 List<Object[]> results = getDao().getResultList(wc);
287 for(Object o[] : results) {
289 String month = (String) o[0];
290 cm.setValue(status.toString(), month, (Number) o[2]);
297 chart.
setWidth((cm.getCategories().size() * 70 + 40) +
"");
302 SimpleCategoryModel cm =
new SimpleCategoryModel();
304 wc.
addClause(
"select concat(year(startDate), '-', month(startDate)), type, count(distinct issueId)");
307 addFilter(wc,
"startDate", role);
308 wc.
addClause(
"group by concat(year(startDate), '-', month(startDate)), type");
309 wc.
addClause(
"order by concat(year(startDate), '-', month(startDate))");
310 List<Object[]> results = getDao().getResultList(wc);
311 for(Object o[] : results) {
313 String month = (String) o[0];
314 cm.setValue(type.toString(), month, (Number) o[2]);
321 chart.
setWidth((cm.getCategories().size() * 70 + 40) +
"");
331 private Dao getDao() {
339 private void addFilter(WhereClause wc, String dateField, IssueParticipantRole role) {
340 if(!Strings.isBlank(dateField)) {
341 wc.addClause(
"and " + dateField +
" >= :start");
342 wc.addClause(
"and " + dateField +
" <= :end");
343 wc.addNamedValue(
"start", start);
344 wc.addNamedValue(
"end", end);
346 if(category !=
null) {
347 wc.addClause(
"and (");
348 wc.addClause(
"categoryPath = :fullCatDesc");
349 wc.addClause(
"or categoryPath like concat(:fullCatDesc, '" + Chars.backward().spaced() +
"%')");
353 if(dossier !=
null) {
354 wc.addClause(
"and dossierId = :dossierId");
355 wc.addNamedValue(
"dossierId", dossier.
getId());
357 if(contact !=
null && contact.
isValid()) {
358 wc.addClause(
"and (");
359 wc.addClause(
"participantId = :contactId");
360 wc.addNamedValue(
"contactId", contact.
getId());
362 wc.addClause(
"and participantRole = :contactRole");
363 wc.addNamedValue(
"contactRole", role);
void setModel(AbstractChartModel model)
void setWidth(String width)
void setTitle(String title)
void setType(String type)
void setOrient(String orient)
void setHeight(String height)
static void generateData()
void setStart(Date start)
DWChartEngine getEngine()
void setContact(IContact contact)
DWChart getByType(IssueParticipantRole role)
void setCategory(Category category)
DWChart getTimelineByStatus(IssueParticipantRole role)
DWChart getByStatus(IssueParticipantRole role)
void setDossier(Dossier dossier)
void selectEntity(@BindingParam("entity") Object entity)
List< DWChart > getModel()
void selectReport(@BindingParam("type") DWReportType type)
DWChart getTimelineByResolution(IssueParticipantRole role)
void selectContact(@BindingParam("contact") IContact contact)
DWChart getIssuesByParticipant(IssueParticipantRole role)
DWChart getTimelineByType(IssueParticipantRole role)
DWChart getByResolution(IssueParticipantRole role)
String getFullDescription()
void addClause(String clause)
void addNamedValue(String name, Object value)