package com.tourism.webadmin.app.website.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.Page;
import com.tourism.common.core.object.MyRelationParam;
import com.tourism.common.core.util.MyModelUtil;
import com.tourism.common.dict.model.GlobalDictItem;
import com.tourism.common.dict.service.GlobalDictItemService;
import com.tourism.webadmin.app.website.service.HouseRentService;
import com.tourism.webadmin.app.website.vo.HouseFilterListsVo;
import com.tourism.webadmin.app.website.vo.HouseMenuVo;
import com.tourism.webadmin.back.dao.TourHouseRentInfoMapper;
import com.tourism.webadmin.back.model.TourHouseAreaMenu;
import com.tourism.webadmin.back.model.TourHouseRentInfo;
import com.tourism.webadmin.back.model.TourHouseSaleInfo;
import com.tourism.webadmin.back.service.TourHouseAreaMenuService;
import com.tourism.webadmin.back.vo.TourHouseAreaMenuVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service("HouseRentService")
public class HouseRentServiceImpl implements HouseRentService {

    @Autowired
    private TourHouseAreaMenuService tourHouseAreaMenuService;
    @Autowired
    private GlobalDictItemService globalDictItemService;
    @Autowired
    private TourHouseRentInfoMapper tourHouseRentInfoMapper;

    @Override
    public HouseFilterListsVo getHouseFilterLists() throws Exception {

        HouseFilterListsVo vo = new HouseFilterListsVo();

        //区域条件
        List<HouseMenuVo> houseMenuTree = tourHouseAreaMenuService.getHouseMenuTree();
        vo.setHouseMenuTree(houseMenuTree);

        //其余条件
        List<String> list = new ArrayList<>();
        //房屋租赁方式
        list.add("HouseRentType");
        //房屋厅式类型
        list.add("OfficeType");
        //房屋朝向
        list.add("Orientation");
        //房屋装修
        list.add("Decoration");
        //房屋楼层类型
        list.add("HouseFloorType");
        List<GlobalDictItem> dictItems = globalDictItemService.list(new LambdaQueryWrapper<GlobalDictItem>()
                .in(GlobalDictItem::getDictCode,list)
                .orderByAsc(GlobalDictItem::getShowOrder)
        );
        Map<String, List<GlobalDictItem>> elseMap = dictItems.stream().collect(Collectors.groupingBy(GlobalDictItem::getDictCode));


        vo.setHouseMenuTree(houseMenuTree);
        vo.setElseMap(elseMap);

        return vo;
    }
}
