Package web.operator.workreport

Source Code of web.operator.workreport.WorkReportController

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

package web.operator.workreport;

import domain.Client;
import domain.Collaborator;
import domain.Lpu;
import domain.address.Address;
import domain.editors.Editor;
import domain.shedule.SheduleReception;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Property;
import org.springframework.validation.BindException;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.servlet.ModelAndView;
import utils.Day;
import web.generic.GenericCommandController;
import web.operator.reception.ReceptionGroup;
import web.operator.reception.ReceptionLine;

/**
* Контроллер отчета о проделанной работе оператором за определенную дату
* @author lacoste
*/

public class WorkReportController extends GenericCommandController {

    public WorkReportController() {
        setCommandClass(WorkReportDTO.class);
    }

    @Override
    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
        binder.registerCustomEditor(Collaborator.class, new Editor(getDao(), Collaborator.class));
    }

    @Override
    protected Object getCommand(HttpServletRequest request) throws Exception {
        WorkReportDTO dto = new WorkReportDTO();
        Calendar cal = Calendar.getInstance();
        dto.setYear(cal.get(Calendar.YEAR));
        dto.setMonth(cal.get(Calendar.MONTH));
        dto.setDay(cal.get(Calendar.DAY_OF_MONTH));
        return dto;
    }


    @Override
    protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object command, BindException exception) throws Exception {
        HashMap model = new HashMap();
       
        WorkReportDTO dto = (WorkReportDTO) command;
        model.put("command", dto);

        //STUB
        Collaborator author = getDao().getById(Collaborator.class, getUserInfo().getCurrentCollaboratorId());
        //ENDSTUB

        Day day = new  Day(dto.getYear(), dto.getMonth(), dto.getDay());

        DetachedCriteria queryCriteria = DetachedCriteria.forClass(SheduleReception.class)
                .add(Property.forName("register").ge(day.getDate()))
                .add(Property.forName("register").le(day.getEndDate()))
                .add(Property.forName("author").eq(author))
                .addOrder(Property.forName("begin").asc());

        if (dto.getCollaborator() != null) {
            queryCriteria.add(Property.forName("collaborator").eq(dto.getCollaborator()));
        }

        List<ReceptionGroup> lines = new ArrayList<ReceptionGroup>();
        List<SheduleReception> receptions = getDao().getList(queryCriteria, null, null);

        HashMap<Integer, ReceptionGroup> map = new HashMap<Integer, ReceptionGroup>();
        for (SheduleReception reception : receptions) {
            Client client = reception.getClient();
            Address address = null;
            if (client.getAddressID() != null) {
                address = getDao().getById(Address.class, client.getAddressID());
            }
            ReceptionGroup group = map.get(client.getId());
            if (group == null) {
                group = new ReceptionGroup();
                lines.add(group);
                map.put(client.getId(), group);
                group.client = client;
                group.addressClient = address != null ? address.getAsStringShort() : "";
                group.receptionLines = new ArrayList<ReceptionLine>();
            }

            ReceptionLine receptLine = new ReceptionLine(reception);
            group.receptionLines.add(receptLine);
            Collections.sort(group.receptionLines);
        }

        model.put("lines", lines);

//        queryCriteria = DetachedCriteria.forClass(Collaborator.class)
//                .createCriteria("client")
//                .createCriteria("surname")
//                .addOrder(Property.forName("title").asc());
        List<Collaborator> collabs = getDao().getList(Collaborator.class);
        Collections.sort(collabs);

        model.put("collabs", collabs);
//        model.put("pageBreadcrumb", ReceptionController.initBreadCrumb(null,
//                                                                        null,
//                                                                        null,
//                                                                        dto.getCollaborator(),
//                                                                        0));

        return new ModelAndView("operator/workreport/workreport", model);
    }

}
TOP

Related Classes of web.operator.workreport.WorkReportController

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.