package com.huiju.estateagents.reportCustomerAop;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huiju.estateagents.drainage.entity.TaDrainage;
import com.huiju.estateagents.drainage.mapper.TaDrainageMapper;
import com.huiju.estateagents.entity.*;
import com.huiju.estateagents.mapper.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Slf4j
@Service
public class ReportCustomerImpl extends ServiceImpl<TaPersonMapper, TaPerson> {

    @Autowired
    private TaBuildingMapper taBuildingMapper;

    @Autowired
    private TaNewsMapper taNewsMapper;

    @Autowired
    private TaBuildingDynamicMapper taBuildingDynamicMapper;

    @Autowired
    private HelpActivityMapper helpActivityMapper;

    @Autowired
    private TaShareActivityMapper taShareActivityMapper;

    @Autowired
    private TaLiveActivityMapper taLiveActivityMapper;

    @Autowired
    private TaDrainageMapper taDrainageMapper;

    @Autowired
    private TaSalesBatchMapper taSalesBatchMapper;


    public Map<String, Object> selectActivityBuildingInfo(String targetId){
        Map<String, Object> map = new HashMap<>();

        QueryWrapper<TaBuildingDynamic> taBuildingDynamicQueryWrapper = new QueryWrapper<>();
        taBuildingDynamicQueryWrapper.eq("dynamic_id", targetId);
        TaBuildingDynamic taBuildingDynamic = taBuildingDynamicMapper.selectOne(taBuildingDynamicQueryWrapper);
        map.put("targetName", taBuildingDynamic.getTitle());

        TaBuilding taBuilding = buildingInfo(taBuildingDynamic.getBuildingId());
        map.put("taBuilding", taBuilding);

        return map;
    }

    public Map<String, Object> selectHelpBuildingInfo(String targetId){
        Map<String, Object> map = new HashMap<>();

        QueryWrapper<HelpActivity> helpActivityQueryWrapper = new QueryWrapper<>();
        helpActivityQueryWrapper.eq("help_activity_id", targetId);
        HelpActivity helpActivity = helpActivityMapper.selectOne(helpActivityQueryWrapper);
        map.put("targetName", helpActivity.getTitle());

        TaBuilding taBuilding = buildingInfo(helpActivity.getBuildingId());
        map.put("taBuilding", taBuilding);

        return map;
    }

    public Map<String, Object> selectGroupBuildingInfo(String targetId){
        Map<String, Object> map = new HashMap<>();

        QueryWrapper<TaShareActivity> taShareActivityQueryWrapper = new QueryWrapper<>();
        taShareActivityQueryWrapper.eq("group_activity_id", targetId);
        TaShareActivity taShareActivity = taShareActivityMapper.selectOne(taShareActivityQueryWrapper);
        map.put("targetName", taShareActivity.getActivityName());

        TaBuilding taBuilding = buildingInfo(taShareActivity.getBuildingId());
        map.put("taBuilding", taBuilding);

        return map;
    }

    public Map<String, Object> selectLiveBuildingInfo(String targetId){
        Map<String, Object> map = new HashMap<>();

        QueryWrapper<TaLiveActivity> taLiveActivityQueryWrapper = new QueryWrapper<>();
        taLiveActivityQueryWrapper.eq("live_activity_id", targetId);
        TaLiveActivity taLiveActivity = taLiveActivityMapper.selectOne(taLiveActivityQueryWrapper);
        map.put("targetName", taLiveActivity.getLiveActivityTitle());

        TaBuilding taBuilding = buildingInfo(taLiveActivity.getBuildingId());
        map.put("taBuilding", taBuilding);

        return map;
    }

    public Map<String, Object> selectH5BuildingInfo(String targetId){
        Map<String, Object> map = new HashMap<>();

        QueryWrapper<TaDrainage> taDrainageQueryWrapper = new QueryWrapper<>();
        taDrainageQueryWrapper.eq("drainage_id", targetId);
        TaDrainage taDrainage = taDrainageMapper.selectOne(taDrainageQueryWrapper);
        map.put("targetName", taDrainage.getName());

        TaBuilding taBuilding = buildingInfo(taDrainage.getBuildingId());
        map.put("taBuilding", taBuilding);

        return map;
    }

    public Map<String, Object> selectBuildingInfo(String targetId){
        Map<String, Object> map = new HashMap<>();

        QueryWrapper<TaBuilding> taBuildingQueryWrapper = new QueryWrapper<>();
        taBuildingQueryWrapper.eq("building_id", targetId);
        TaBuilding taBuilding = taBuildingMapper.selectOne(taBuildingQueryWrapper);
        map.put("targetName", taBuilding.getBuildingName());
        map.put("taBuilding", taBuilding);
        return map;
    }

    public Map<String, Object> selectNewsBuildingInfo(String targetId){
        Map<String, Object> map = new HashMap<>();

        QueryWrapper<TaNews> taNewsQueryWrapper = new QueryWrapper<>();
        taNewsQueryWrapper.eq("news_id", targetId);
        TaNews taNews = taNewsMapper.selectOne(taNewsQueryWrapper);
        map.put("targetName", taNews.getNewsName());

        TaBuilding taBuilding = buildingInfo(taNews.getBuildingId());
        map.put("taBuilding", taBuilding);

        return map;
    }

    public TaBuilding buildingInfo(String buildingId){
        QueryWrapper<TaBuilding> taBuildingQueryWrapper = new QueryWrapper<>();
        taBuildingQueryWrapper.eq("building_id", buildingId);
        TaBuilding taBuilding = taBuildingMapper.selectOne(taBuildingQueryWrapper);
        return taBuilding;
    }

    public Map<String, Object> selectHouseBuildingInfo(String targetId){
        Map<String, Object> map = new HashMap<>();

        QueryWrapper<TaSalesBatch> taSalesBatchQueryWrapper = new QueryWrapper<>();
        taSalesBatchQueryWrapper.eq("sales_batch_id", targetId);
        TaSalesBatch taSalesBatch = taSalesBatchMapper.selectOne(taSalesBatchQueryWrapper);
        map.put("targetName", taSalesBatch.getSalesBatchName());

        TaBuilding taBuilding = buildingInfo(taSalesBatch.getBuildingId());
        map.put("taBuilding", taBuilding);

        return map;
    }

    public TaPerson getPerson(String personId){
        return getById(personId);
    }

    public Map<String, Object> selectIndexInfo(String targetId) {
        Map<String, Object> map = new HashMap<>();
        return map;
    }
}
