package com.yc.education.controller.admin;/**
 * huangpan
 * 2019/10/16
 * energy
 */

import com.github.pagehelper.PageInfo;
import com.yc.education.model.Coom;
import com.yc.education.model.Orders;
import com.yc.education.model.Personnel;
import com.yc.education.service.CoomService;
import com.yc.education.service.CoomclassifyService;
import com.yc.education.service.OrdersService;
import com.yc.education.service.PersonnelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 *@ClassName OrdersController
 *@Description TODO
 *@Author QuZhangJing
 *@Date 2019/10/16 11:27
 *@Version 1.0
 */
@Controller
public class OrdersController {
    @Autowired
    CoomService coomService;
    @Autowired
    CoomclassifyService coomclassifyService;
    @Autowired
    OrdersService ordersService;

    @Autowired
    PersonnelService personnelService;

   /* *//*查询信息*//*
    @RequestMapping("admin/order-list.html")
    public ModelAndView getOrders(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum ,
                                  @RequestParam(value = "pageSize",defaultValue = "12") Integer pageSize){
        ModelAndView modelAndView=new ModelAndView();
        List<Orders> orders = ordersService.getOrders(pageNum,pageSize);
        List<Coom> cooms = coomService.getCooms();
        List<Personnel> personnels = personnelService.getPersonnels();
        modelAndView.addObject("orders", new PageInfo<>(orders));
        modelAndView.addObject("cooms", cooms);
        modelAndView.addObject("personnels", personnels);
        return  modelAndView;
    }*/
    /*取消会议信息*/
    @RequestMapping("admin/deorderById.html")
    @ResponseBody
    public void deldeorderById(Integer id){
        ordersService.delOrderById(id);
    }


    /*根据时间查询*/
    @RequestMapping("admin/sgaoguang.html")
        public ModelAndView gaoguang(String  startTime,
                                     String endTime,
                                 @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum ,
                                 @RequestParam(value = "pageSize",defaultValue = "12" )Integer pageSize,@RequestParam(value = "cidpfid",defaultValue = "0" )Integer cidpfid){
            ModelAndView modelAndView=new ModelAndView("admin/order-list");
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            String format = startTime;
            String format1=endTime;
            String forma=df.format(new Date());
            /*if(format.equals(""))
                format=df.format(new Date());
            if(format1.equals(""))
                format1=df.format(new Date());*/
        List<Orders> coomsCid = ordersService.getCoomsCid(cidpfid, format, format1, pageNum, pageSize);
        List<Coom> cooms = coomService.getCooms();
        List<Personnel> personnels = personnelService.getPersonnels();
        modelAndView.addObject("cooms", cooms);
        modelAndView.addObject("orders",new PageInfo<>(coomsCid) );
        modelAndView.addObject("personnels", personnels);
        modelAndView.addObject("url", "sgaoguang-list.html");
        modelAndView.addObject("format", forma);
        modelAndView.addObject("cid", cidpfid);
        modelAndView.addObject("startTime", format);
        modelAndView.addObject("endTime", format1);
            return modelAndView;
    }
    /*根据人数搜索信息*//*
    @RequestMapping("admin/sgaoguangshike.html")
    public ModelAndView gaoguangshike( @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum ,
                                       @RequestParam(value = "pageSize",defaultValue = "12" )Integer pageSize,Integer cfpid,HttpSession session){

            ModelAndView modelAndView=new ModelAndView("admin/order-list");
            Integer coomcid =(Integer) session.getAttribute("coomcids");*//*会议室*//*
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String startTime =(String) session.getAttribute("startTimes");
            String endTime =(String) session.getAttribute("endTimes");
            if(startTime==null||startTime.equals("")){
                startTime=df.format(new Date());}
            if(endTime==null||endTime.equals("")){
                endTime=df.format(new Date());}
            List<Coom> idNotIn = coomService.getIdNotIn(coomcid, startTime, endTime, pageNum, pageSize, cfpid);
            List<Orders> selOrders=new ArrayList<>();
            for (Coom cf:idNotIn){
                List<Orders> ordersStartEndIds = ordersService.getOrdersStartEndIds(cf.getId(), endTime);
                for (Orders or:ordersStartEndIds){
                    selOrders.add(or);
                }
            }
            List<Coomclassify> coomclassifies=coomclassifyService.getcoomFyId(cfpid);
            List<Coom> coomCids = coomService.getCoomCid(cfpid);
            coomcid=coomCids.get(0).getId();
            modelAndView.addObject("selOrders", selOrders);
            modelAndView.addObject("startTime", startTime);
            modelAndView.addObject("endTime", endTime);
            modelAndView.addObject("cfpid", cfpid);
            modelAndView.addObject("cid", coomcid);
            modelAndView.addObject("coomList", new PageInfo<>(idNotIn));
            modelAndView.addObject("coomL", coomCids);
            modelAndView.addObject("coomFys", coomclassifies);
            modelAndView.addObject("url", "sgaoguangshike,html");
            modelAndView.addObject("pageNums", pageNum);
            session.setAttribute("commcfpids", cfpid);
            return modelAndView;
    }
    *//*根据会议室查询信息*//*
    @RequestMapping("admin/sgaoguangsk.html")
    public ModelAndView gaoguangsk(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum ,
                                   @RequestParam(value = "pageSize",defaultValue = "12" )Integer pageSize,Integer cid,HttpSession session){
        ModelAndView modelAndView=new ModelAndView("admin/order-list");
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Integer commcfpid =(Integer) session.getAttribute("commcfpids");*//*人数*//*
            String startTime =(String) session.getAttribute("startTimes");
            String endTime =(String) session.getAttribute("endTimes");
            if(startTime==null||startTime.equals("")){
                startTime=df.format(new Date());}
            if(endTime==null||endTime.equals("")){
                endTime=df.format(new Date());}
                if (commcfpid==1){
                    endTime=null;
                }
                if (commcfpid==2){
                    startTime=null;
                }
        List<Orders> coomsCid = ordersService.getCoomsCid(cid, startTime, endTime, pageNum, pageSize);
        List<Coom> cooms = coomService.getCooms();
        modelAndView.addObject("cooms", cooms);
        modelAndView.addObject("cid", cid);
        modelAndView.addObject("cfpid", commcfpid);
        if (commcfpid==0){
            modelAndView.addObject("startTime", startTime);
            modelAndView.addObject("endTime", endTime);
        }
        modelAndView.addObject("url", "sgaoguangsk.html");
        session.setAttribute("coomcids", cid);
          *//*  List<Coom> idNotIn = coomService.getIdNotIn(cid, startTime, endTime, pageNum, pageSize, commcfpid);
            List<Orders> selOrders=new ArrayList<>();
            for (Coom cf:idNotIn){
                List<Orders> ordersStartEndIds = ordersService.getOrdersStartEndIds(cf.getId(), endTime);
                for (Orders or:ordersStartEndIds){
                    selOrders.add(or);
                }
            }
            List<Coom> cooms = coomService.selCoomid(cid);
            List<Coomclassify> coomclassifies = coomclassifyService.getcoomFyId(cooms.get(0).getCid());
            modelAndView.addObject("startTime", startTime);
            modelAndView.addObject("endTime", endTime);
            modelAndView.addObject("cfpid", coomclassifies.get(0).getId());
            modelAndView.addObject("selOrders", selOrders);
            modelAndView.addObject("cid", cid);
            modelAndView.addObject("coomList", new PageInfo<>(idNotIn));
            modelAndView.addObject("coomL", cooms);
            modelAndView.addObject("coomFys", coomclassifies);
            modelAndView.addObject("url", "sgaoguangsk,html");
            modelAndView.addObject("pageNums", pageNum);
            session.setAttribute("coomcids", cid);*//*
            return modelAndView;
    }*/
    /*查询所有*/
    @RequestMapping("admin/order-list.html")
    public ModelAndView roomlist(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum ,
                                 @RequestParam(value = "pageSize",defaultValue = "12") Integer pageSize){
        ModelAndView modelAndView=new ModelAndView("admin/order-list");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = df.format(new Date());
        List<Orders> yyy = ordersService.getYyy( pageNum, pageSize);
        List<Coom> cooms = coomService.getCooms();
        List<Personnel> personnels = personnelService.getPersonnels();
        modelAndView.addObject("cooms", cooms);
        modelAndView.addObject("orders",new PageInfo<>(yyy) );
        modelAndView.addObject("personnels", personnels);
        modelAndView.addObject("url", "order-list.html");
        modelAndView.addObject("format", format);
        return modelAndView;
        /* ModelAndView modelAndView=new ModelAndView("admin/order-list");
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String format = df.format(new Date());
            List<Coom> idNotIn = coomService.getIdNotIn(null, format, format, pageNum, pageSize, null);
            List<Orders> selOrders=new ArrayList<>();
            for (Coom cf:idNotIn){
                List<Orders> ordersStartEndIds = ordersService.getOrdersStartEndIds(cf.getId(), format);
                for (Orders or:ordersStartEndIds){
                    selOrders.add(or);
                }
            }
            List<Coom> cooms = coomService.getCooms();
            List<Coomclassify> coomclassifies = coomclassifyService.getCoomFys();
            modelAndView.addObject("startTime", format);
            modelAndView.addObject("endTime", format);
            modelAndView.addObject("coomList", new PageInfo<>(idNotIn));
            modelAndView.addObject("selOrders", selOrders);
            modelAndView.addObject("coomL", cooms);
            modelAndView.addObject("coomFys", coomclassifies);
            modelAndView.addObject("url", "order-list.html");
            modelAndView.addObject("pageNums", pageNum);
            session.removeAttribute("coomcids");
            session.removeAttribute("commcfpids");
            session.removeAttribute("startTimes");
            session.removeAttribute("endTimes");
            return modelAndView;*/
    }
}
