Package web.operator.reception

Source Code of web.operator.reception.RemoveReceptionController

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package web.operator.reception;

import java.util.List;
import domain.shedule.SheduleReception;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.servlet.ModelAndView;
import utils.Day;
import utils.DayOfWeek;
import services.ReceptionUpdater;
import web.generic.CH;
import web.generic.GenericAbstractController;
import web.rechelper.ReceptionDTO;
import web.rechelper.ReceptionHelper;
import web.rechelper.Ticket;
import web.rechelper.WeekDay;

/**
* Контроллер отменяет запись на прием
* Обязательные параметры:
*     reception - ID записи на прием
* @author petr
*/
public class RemoveReceptionController extends GenericAbstractController{

    private ReceptionUpdater updater;
    protected static final Logger log = Logger.getLogger(RemoveReceptionController.class);


    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
        String receptionStr = hsr.getParameter("reception");
        if (receptionStr != null && !receptionStr.isEmpty()) {
            try {
                SheduleReception sheduleReception = CH.get(getDao(), SheduleReception.class, receptionStr);

                //Ебём мозг, что б с помощю ресепшн хедлпера нарезать тикеты
                //Готови данные
                ReceptionDTO rdto = new ReceptionDTO();
                rdto.setClient(sheduleReception.getClient());
                rdto.setCollaborator(sheduleReception.getCollaborator());
                rdto.setLpu(sheduleReception.getCollaborator().getLpu());
                rdto.setType(sheduleReception.getWorkType());
                Day day = new Day(sheduleReception.getBegin());
                ReceptionHelper rhBefore = new ReceptionHelper(getDao(), rdto, day.getDate(), day.getEndDate());
                WeekDay weekDay = rhBefore.getModel().get(0);
                List<Ticket> ticketsBefore = weekDay.getTickets();

                getDao().delete(sheduleReception);

                //Ебём мозг 2, нарезаем тикеты после удаления
                ReceptionHelper rhAfter = new ReceptionHelper(getDao(), rdto, day.getDate(), day.getEndDate());
                weekDay = rhAfter.getModel().get(0);
                List<Ticket> ticketsAfter = weekDay.getTickets();

                //Сравниваем списки - получаем свободные тикеты
                ticketsAfter.removeAll(ticketsBefore);
                for (Ticket ticket : ticketsAfter) {
                    updater.addTicketP(rdto.getCollaborator(), rdto.getType(), ticket);
                }
            } catch (Exception ex) {
                log.debug("Удаление не удалось", ex);
            }
        }
        return new ModelAndView("redirect:/operator/reception/receptionsearch.htm");
    }

    public ReceptionUpdater getUpdater() {
        return updater;
    }

    @Required
    public void setUpdater(ReceptionUpdater updater) {
        this.updater = updater;
    }

}
TOP

Related Classes of web.operator.reception.RemoveReceptionController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.