package com.gx.web;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.omg.PortableServer.POA;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.google.gson.Gson;
import com.gx.page.Page;
import com.gx.po.AttributePo;
import com.gx.po.CommodityPo;
import com.gx.po.PassengerPo;
import com.gx.po.ReceiveTargetPo;
import com.gx.po.RoomSetPo;
import com.gx.po.StayRegisterPo;
import com.gx.service.AttributeService;
import com.gx.service.CommodityService;
import com.gx.service.PassengerService;
import com.gx.service.ReceiveTargetService;
import com.gx.service.RoomSetService;
import com.gx.service.StayRegisterService;
import com.gx.vo.TeamPayVo;
@Controller
@RequestMapping("/StayRegister")
public class StayRegister {
@Autowired
private AttributeService attributeService;
@Autowired
private RoomSetService roomSetService;
@Autowired
private StayRegisterService stayRegisterService;
@Autowired
private PassengerService passengerService;
@Autowired
private CommodityService commodityService;
@Autowired
private ReceiveTargetService receiveTargetService;
int fangjianId=0;
String lvkeName="";
double zhuDianTianShu=0; //住店天数
double shengZhuDianTianShu=0; //剩住店天数
double zhuDianTianShuOne=0; //住店天数
//散客的list查询
@RequestMapping("/tolist")
public ModelAndView tolist(HttpServletRequest request, Integer currentPage,
String txtname,Integer LvKeLeiXingId,Integer isBillID){
ModelAndView mv=null;
List<StayRegisterPo> listAll=stayRegisterService.selectAll();
Date date=new Date();
DateFormat dformat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置日期格式
Timestamp timestamp=Timestamp.valueOf(dformat.format(date)) ; //将当前时间转为字符串
int id=0;
long xiangChaTianShu;
long days;
long hours;
String zhuSu="";
for (int i = 0; i < listAll.size(); i++) {
id=listAll.get(i).getId(); //获取ID
Timestamp registerTime=listAll.get(i).getRegisterTime(); //获取登记时间
zhuSu=listAll.get(i).getStayNumber(); //获取登记时间
xiangChaTianShu=timestamp.getTime()-registerTime.getTime(); //当前时间-登记时间
days=xiangChaTianShu/(1000 * 60 * 60 * 24); //转化为天
hours=xiangChaTianShu/(1000 * 60 * 60 )-days*24; //转化为小时
if (Long.parseLong(zhuSu)<=days) {
if (hours>0) {
stayRegisterService.updateRemind(id, 1);
}
}
}
List<AttributePo> listOne=attributeService.selectIsPay();
mv=new ModelAndView("/stayregister/list");
if (isBillID==null) {
isBillID=68;
}
if (LvKeLeiXingId==null) {
LvKeLeiXingId=55;
}
if (currentPage==null) {
currentPage=1;
}else if (currentPage==0) {
currentPage=1;
}
Page<StayRegisterPo> vo=new Page<StayRegisterPo>();
vo.setCurrentPage(currentPage);
if(txtname==null)
{
txtname="";
}
vo=this.stayRegisterService.pageFuzzyselectOne(LvKeLeiXingId, isBillID, txtname, vo);
mv.addObject("list",vo);
mv.addObject("listOne",listOne);
mv.addObject("LvKeLeiXingId",LvKeLeiXingId);
mv.addObject("isBillID",isBillID);
mv.addObject("txtname",txtname);
return mv;
}
//团队的list查询
@RequestMapping("/toteamlist")
public ModelAndView toteamlist(HttpServletRequest request, Integer currentPage,
String txtname,Integer LvKeLeiXingId,Integer isBillID,Integer tuanDuiID,
String teamNameId, String teamCodeId, String principalId,
String contactPhoneNUmberId, String registerTimeId){
ModelAndView mv=null;
List<StayRegisterPo> listTeam=null;
List<StayRegisterPo> listAll=stayRegisterService.selectAll();
Date date=new Date();
DateFormat dformat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置日期格式
Timestamp timestamp=Timestamp.valueOf(dformat.format(date)) ; //将当前时间转为字符串
int id=0;
long xiangChaTianShu;
long days;
long hours;
String zhuSu="";
double teamSumConst=0;
for (int i = 0; i < listAll.size(); i++) {
id=listAll.get(i).getId(); //获取ID
Timestamp registerTime=listAll.get(i).getRegisterTime(); //获取登记时间
zhuSu=listAll.get(i).getStayNumber(); //获取登记时间
xiangChaTianShu=timestamp.getTime()-registerTime.getTime(); //当前时间-登记时间
days=xiangChaTianShu/(1000 * 60 * 60 * 24); //转化为天
hours=xiangChaTianShu/(1000 * 60 * 60 )-days*24; //转化为小时
if (Long.parseLong(zhuSu)<=days) {
if (hours>0) {
stayRegisterService.updateRemind(id, 1);
}
}
}
List<AttributePo> listOne=attributeService.selectIsPay();
mv=new ModelAndView("/stayregister/list");
if (isBillID==null) {
isBillID=68;
}
if (LvKeLeiXingId==null) {
LvKeLeiXingId=56;
}
if (tuanDuiID==null) {
listTeam=this.stayRegisterService.selectFormTeamIdTwo(isBillID);
}else {
listTeam=this.stayRegisterService.selectFormTeamId(tuanDuiID, isBillID);
}
if (currentPage==null) {
currentPage=1;
}else if (currentPage==0) {
currentPage=1;
}
for (int i = 0; i < listTeam.size(); i++) {
teamSumConst+=listTeam.get(i).getSumConst();
}
Page<StayRegisterPo> vo=new Page<StayRegisterPo>();
vo.setCurrentPage(currentPage);
if(txtname==null)
{
txtname="";
}
if (tuanDuiID==null) {
vo=this.stayRegisterService.pageFuzzyselectThree(isBillID, txtname, vo);
}else {
vo=this.stayRegisterService.pageFuzzyselectTwo(tuanDuiID, isBillID, txtname, vo);
}
mv.addObject("list",vo);
mv.addObject("listOne",listOne);
mv.addObject("LvKeLeiXingId",LvKeLeiXingId);
mv.addObject("isBillID",isBillID);
mv.addObject("txtname",txtname);
mv.addObject("tuanDui",tuanDuiID);
mv.addObject("teamNameId",teamNameId);
mv.addObject("teamCodeId",teamCodeId);
mv.addObject("principalId",principalId);
mv.addObject("contactPhoneNUmberId",contactPhoneNUmberId);
mv.addObject("registerTimeId",registerTimeId);
mv.addObject("teamSumConst",teamSumConst);
return mv;
}
@ResponseBody
@RequestMapping(value="/ajaxSelectTeamSumcont")
public Object ajaxSelectTeamSumcont(Integer tuanDuiID, Integer isBillID){
double teamSumConst=0;
List<StayRegisterPo> listTeam=this.stayRegisterService.selectFormTeamId(tuanDuiID, isBillID);
for (int i = 0; i < listTeam.size(); i++) {
teamSumConst+=listTeam.get(i).getSumConst();
}
Gson gson=new Gson();
return gson.toJson(teamSumConst);
}
@RequestMapping("/toadd")
public ModelAndView toadd(){
ModelAndView mv=null;
mv=new ModelAndView("/stayregister/add");
return mv;
}
/*--------------------------------------- 登记 start------------------------------------------------------------------*/
//登记
@RequestM