package com.community.huiju.service.impl;

import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.dao.TpHotelImgMapper;
import com.community.huiju.dao.TpHotelMapper;
import com.community.huiju.dao.TpHotelRoomMapper;
import com.community.huiju.model.TpHotel;
import com.community.huiju.model.TpHotelImg;
import com.community.huiju.model.TpHotelRoom;
import com.community.huiju.service.TpHotelServicel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * version V1.0
 * class_name: $METHOD_NAME$
 * param: $METHOD_PARAM$
 * describe: TODO
 * creat_user:fannaixi
 * creat_time: 2019/5/9
 **/
@Service("tpHotelServicel")
@Transactional
public class TpHotelServiceimpl implements TpHotelServicel {
    @Autowired
    private TpHotelMapper tpHotelMapper;

    @Autowired
    private TpHotelImgMapper tpHotelImgMapper;

    @Autowired
    private TpHotelRoomMapper tpHotelRoomMapper;

    @Override
    public ResponseBean getHotel(UserElement userElement) {
       ResponseBean responseBean= new ResponseBean<>();
        // 每个小区只有一个酒店
        TpHotel tpHotel= tpHotelMapper.selectCommunityHotel(userElement.getCommunityId());
        if (null != tpHotel) {
            // 获取当前酒店所有房间
            List<TpHotelRoom> tpHotelRoom = tpHotelRoomMapper.selectHotelRoomList(userElement.getCommunityId(),tpHotel.getId());
            tpHotel.setTpHotelRoomsList(tpHotelRoom);
            // 查询当前酒店所有的banner图
            List<String> img = tpHotelImgMapper.selectHotelImg(tpHotel.getId(), userElement.getCommunityId(),2);
            Map map = new HashMap<>();
            map.put("tpHotel", tpHotel);
            map.put("img", img);
            responseBean.addSuccess(map);
        }
        return responseBean;
    }

    @Override
    public ResponseBean getHotelCommunity(UserElement userElement) {
        ResponseBean response= new ResponseBean<>();
        // 查询当前的酒店是否展示
        TpHotel tpHotel = new TpHotel();
        String img = null;
        String  hotelSetting= tpHotelMapper.hotelSetting(userElement.getCommunityId());
        if (null != hotelSetting){
             tpHotel= tpHotelMapper.selectCommunityHotel(userElement.getCommunityId());
            List<TpHotelRoom> tpHotelRoom = tpHotelRoomMapper.selectHotelRoomList(userElement.getCommunityId(),tpHotel.getId());
            tpHotel.setTpHotelRoomsList(tpHotelRoom);
            img = tpHotelImgMapper.selectHotelImg(tpHotel.getId(), userElement.getCommunityId(),1).get(0);
            tpHotel.setImg(img);
            response.addSuccess(tpHotel);
            return response;
        }
        response.addSuccess(null);
        return response;
    }
}
