package com.thinkgem.jeesite.modules.yudengjipush.service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import com.google.common.collect.Maps;
import com.itextpdf.text.log.SysoLogger;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.SendMailUtil;
import com.thinkgem.jeesite.modules.flight.entity.Detail;
import com.thinkgem.jeesite.modules.flight.entity.FlightIndexBean;
import com.thinkgem.jeesite.modules.flight.entity.FlightInfoList;
import com.thinkgem.jeesite.modules.flight.entity.FlightList;
import com.thinkgem.jeesite.modules.flight.entity.PriceDeatil;
import com.thinkgem.jeesite.modules.flight.entity.ProductList;
import com.thinkgem.jeesite.modules.flight.service.FlightService;
import com.thinkgem.jeesite.modules.hotel.dao.HotelDao;
import com.thinkgem.jeesite.modules.hotel.entity.Hotel;
import com.thinkgem.jeesite.modules.sys.entity.BaseArea;
import com.thinkgem.jeesite.modules.sys.service.BaseAreaService;
import com.thinkgem.jeesite.modules.yudengjipush.dao.YuDengJiPushDao;
import com.thinkgem.jeesite.modules.yudengjipush.entity.YuDengJiPush;
/**
* 详情页面意向登记 Service 类
*
* @author Administrator
*
*/
@Service
@Scope
public class YuDengJiPushService extends CrudService<YuDengJiPushDao, YuDengJiPush> {
private static final String beijing = "BJS";// 北京三字码
private static final String shanghai = "SHA";// 上海三字码
private static final String guangzhou = "CAN";// 广州三字码
private static final String hongkong = "HKG";// 香港三字码
@Autowired
YuDengJiPushDao yuDengJiPushDao;
@Autowired
FlightService flightService;
@Autowired
BaseAreaService baseAreaService;
@Autowired
HotelDao hotelDao;
/**
* 查询参观预登记要推送的信息
*
* @param yuDengJiPush
* @throws ParseException
*/
public void queryYuDengJiPush() {
String takeoffDate = flightService.getDateTime(28, "yyyy-MM-dd");// 飞机起飞时间
String returnDate = flightService.getDateTime(37, "yyyy-MM-dd");// 飞机返程日期为展览开展时间的后7天
String launchTime = flightService.getDateTime(30, "yyyy-MM-dd");// 展会举办时间
YuDengJiPush yuDengJiPush = new YuDengJiPush();
yuDengJiPush.setJuBanTime(launchTime);
Hotel ht = new Hotel();
List<YuDengJiPush> yuDengJiPushList = yuDengJiPushDao.findList(yuDengJiPush);
Map<String, Object> map = Maps.newHashMap();
try {
if (yuDengJiPushList != null && yuDengJiPushList.size() > 0) {
for (YuDengJiPush yp : yuDengJiPushList) {
if ("".equals(yp.getCityAdd()) || yp.getCityAdd() == null) {
yp.setCityAdd("北京");
}
// 获取展会所在城市的酒店信息
if (!"".equals(yp.getZhanGuanId()) && yp.getZhanGuanId() != null) {
ht.setZhanGuanId(Integer.parseInt(yp.getZhanGuanId()));
List<Hotel> hotelTop4 = hotelDao.findHotelTop4(ht);
if(hotelTop4.size()>0 && hotelTop4 !=null){
for(int i=0;i<hotelTop4.size();i++){
if(hotelTop4.get(i)!=null){
map.put("hotel"+String.valueOf(i), hotelTop4.get(i));
}else{
map.put("hotel"+String.valueOf(i), null);}
}
}
}
List<FlightList> flightList = queryFlightList(yp.getZhanGuanId(), yp.getCityAdd(), takeoffDate, returnDate);
if (flightList != null && flightList.size() > 0) {
for(int i=0;i<4;i++){
FlightIndexBean ftBean = new FlightIndexBean();
FlightList ft = flightList.get(i);
List<FlightInfoList> flightInfoList = ft.getFlightInfoList();//综合信息
List<ProductList> productList = ft.getProductList();//机票价格信息
if(flightInfoList !=null && flightInfoList.size()>0){
FlightInfoList takeoffList = flightInfoList.get(0);//起飞时的航程信息
FlightInfoList arrivalList = flightInfoList.get(flightInfoList.size()-1);//降落时的航程信息
if(takeoffList !=null){
ftBean.setAirName(takeoffList.getAirName());// 航空公司
ftBean.setEquipment(takeoffList.getEquipment());// 机型
String takeoffTime = takeoffList.getTakeoffTime();
if(takeoffTime.length()>=5){
ftBean.setTakeoffTime(takeoffTime.substring(0, takeoffTime.length()-5));// 起飞时间
}
ftBean.setTakeoffCity(takeoffList.getTakeoffCity());// 出发城市名称
ftBean.setTakeoffAirportName(takeoffList.getTakeoffAirportName());//起飞时机场名称
ftBean.setTakeoffTerminal(takeoffList.getTakeoffTerminal());// 出发航站楼
}
if(arrivalList !=null){
String arrivalTime = arrivalList.getArrivalTime();
if(arrivalTime.length()>=5){
ftBean.setArrivalTime(arrivalTime.substring(0, arrivalTime.length()-5));// 着陆点时间
}
ftBean.setArrivalCity(arrivalList.getArrivalCity());// 着陆点城市
ftBean.setArrivalAirportName(arrivalList.getArrivalAirportName());//着陆点机场名称
ftBean.setArrivalTerminal(arrivalList.getArrivalTerminal());// 着陆点航站楼
ftBean.setArrivalEquipment(arrivalList.getEquipment());//终点站时机型
}
}
if(productList !=null && productList.size()>0){
for(ProductList p : productList){
List<PriceDeatil> priceDeatilList = p.getPriceDeatil();
if(priceDeatilList !=null && priceDeatilList.size()>0){
for(PriceDeatil pd : priceDeatilList){
Detail detail = pd.getDetail();
ftBean.setSalePrice(detail.getSalePrice());
}
}
}
}
map.put("ftBean"+String.valueOf(i), ftBean);
}
}
map.put("yp", yp);
SendMailUtil.sendFtlMail(yp.getMail(), "参观预登记提示", "canGuanYuDengJi.ftl", map);// 发送邮件
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*
* @param zhanGuanId
* 展馆的ID
* @param cityAdd
* 参观预登记下单人所在的城市
* @param takeoffDate
* 起飞时间
* @return
*/
/*
* public Integer getTicketPrice(String zhanGuanId, String cityAdd, String
* takeoffDate) { int Price = 0; String takeoffSZM = beijing;//
* 默认当前下单用户起飞城市是北京 BaseArea ba = new BaseArea();
* ba.setZhanGuanId(Integer.parseInt(zhanGuanId)); ba =
* baseAreaService.getsanZiMa(ba); if ("".equals(ba.getSanZiMa()) ||
* ba.getSanZiMa() == null) { return Price; } if ("广州".equals(cityAdd)) {
* takeoffSZM = guangzhou; } else if ("上海".equals(cityAdd)) { takeoffSZM =
* shanghai; } else if ("香港".equals(cityAdd)) { takeoffSZM = hongkong; }
* FlightIndexBean flightIndexBean =
* flightService.queryYuDengJiPushFlight(takeoffSZM, ba.getSanZiMa(),
* takeoffDate); if (flightIndexBean != null &&
* flightIndexBean.getSalePrice() != null) { Price =
* Integer.parseInt(flightIndexBean.getSalePrice()); } return Price; }
*/
/**
*
* @param zhanGuanId 展馆的ID
* @param cityAdd 参观预登记下单人所在的城市
* @param takeoffDate 起飞时间
* @param returnDate 返程时间
* @return List<FlightList>
*/
public List<FlightList> queryFlightList(String zhanGuanId, String cityAdd, String takeoffDate, String returnDate) {
String takeoffCityCode = beijing;// 默认当前下单用户起飞城市是北京
BaseArea ba = new BaseArea();
ba.setZhanGuanId(Integer.parseInt(zhanGuanId));
ba = baseAreaService.getsanZiMa(ba);
if ("".equals(ba.getSanZiMa()) || ba.getSanZiMa() == null) {
return null;
}
if ("广州".equals(cityAdd)) {
takeoffCityCode = guangzhou;
} else if ("上海".equals(cityAdd)) {
takeoffCityCode = shanghai;
} else if ("香港".equals(cityAdd)) {
takeoffCityCode = hongkong;
}
return flightService.queryYuDengJiPushList(takeoffCityCode, ba.getSanZiMa(), takeoffDate, returnDate);
}
}