/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.delegate.shedule.reception;
import beans.shedule.reception.SheduleReceptionBean;
import beans.shedule.reception.SheduleReceptionBeanRemote;
import clips.delegate.client.ClientLocal;
import cli_fmw.delegate.DelegateSimple;
import cli_fmw.delegate.SharedBean;
import cli_fmw.delegate.cache.DelegateExtraDataRO;
import beans.shedule.reception.SheduleReceptionDetails;
import cli_fmw.main.ClipsException;
import framework.generic.ClipsServerException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author axe
*/
public class SheduleClientReceptionLocal extends DelegateSimple<SheduleReceptionBeanRemote> {
public final static ClientReceptionMode LAST_DAY =
new ClientReceptionMode(0, "Сегодня");
public final static ClientReceptionMode LAST_10DAYS =
new ClientReceptionMode(1, "Последние 10 дней");
public final static ClientReceptionMode LAST_MONTH =
new ClientReceptionMode(2, "Последний месяц");
public final static ClientReceptionMode LAST_YEAR =
new ClientReceptionMode(3, "Последний год");
public final static ClientReceptionMode ALLTIME =
new ClientReceptionMode(4, "Все");
private List<SheduleReceptionData> itemList10Days;
private List<SheduleReceptionData> itemListMonth;
private List<SheduleReceptionData> itemListYear;
private List<SheduleReceptionData> itemListAllTime;
private ClientLocal client;
/**
* Creates new object.
* @param client
* @throws ClipsException
*/
public SheduleClientReceptionLocal(ClientLocal client)
throws ClipsException {
super(SheduleReceptionBean.class.getSimpleName());
initBean();
this.client = client;
}
public List<SheduleReceptionData> selector(ClientReceptionMode mode) throws ClipsException {
Calendar cal = GregorianCalendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, -1);
Date lastDay = cal.getTime();
if(mode == LAST_DAY) {
return load(lastDay, new Date());
} if(mode == LAST_10DAYS) {
if(itemList10Days == null) {
cal.add(Calendar.DAY_OF_YEAR, -9);
itemList10Days = load(cal.getTime(), lastDay);
}
return itemList10Days;
} if(mode == LAST_MONTH) {
if(itemListMonth == null) {
cal.add(Calendar.DAY_OF_YEAR, -29);
itemListMonth = load(cal.getTime(), lastDay);
}
return itemListMonth;
} if(mode == LAST_YEAR) {
if(itemListYear == null) {
cal.add(Calendar.DAY_OF_YEAR, -365);
itemListYear = load(cal.getTime(), lastDay);
}
return itemListYear;
} if(mode == ALLTIME) {
if(itemListAllTime == null) {
cal.add(Calendar.YEAR, -100);
itemListAllTime = load(cal.getTime(), lastDay);
}
return itemListAllTime;
}
throw new IllegalArgumentException("Unknown type");
}
private List<SheduleReceptionData> load(Date begin, Date end) {
List<SheduleReceptionData> receptions = new ArrayList<SheduleReceptionData>();
try {
Iterator<SheduleReceptionDetails> list
= bean().getClientReceptionList(client.getID(), begin, end).iterator();
receptions = new ArrayList<SheduleReceptionData>();
while(list.hasNext()) {
SheduleReceptionDetails details = list.next();
receptions.add(new SheduleReceptionData(client, details));
}
} catch (Exception ex) {
clearBean();
ex.printStackTrace();
}
return receptions;
}
public List<ClientReceptionMode> getModeList() {
List<ClientReceptionMode> list = new ArrayList<ClientReceptionMode>();
list.add(LAST_DAY);
list.add(LAST_10DAYS);
list.add(LAST_MONTH);
list.add(LAST_YEAR);
list.add(ALLTIME);
return list;
}
}