package com.hzs.system.home.controller.api;


import cn.hutool.core.collection.CollectionUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.system.ext.HoGlobalCompanyExt;
import com.hzs.system.home.service.IHoGlobalCompanyService;
import com.hzs.system.home.vo.HoGlobalCompanyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 全球分布 前端控制器
 * </p>
 *
 * @author hzs
 * @since 2022-12-08
 */
@RestController
@RequestMapping("/api/ho-global-company")
public class ApiHoGlobalCompanyController extends BaseController {

    @Autowired
    private IHoGlobalCompanyService globalCompanyService;

    /**
     * @description: 全球分布
     * @author: zhang jing
     * @date: 2022/8/30 10:20
     * @param: [globalCompany]
     * @return: com.hzs.common.core.web.page.TableDataInfo
     **/
    @GetMapping("/list")
    public TableDataInfo list(HoGlobalCompanyVO globalCompanyVO) {
        List<HoGlobalCompanyVO> cttList = globalCompanyService.queryGlobalByContinent(globalCompanyVO);
        List<HoGlobalCompanyVO> list = globalCompanyService.queryGlobalCompanyList(globalCompanyVO);
        if (CollectionUtil.isNotEmpty(cttList)) {
            for (HoGlobalCompanyVO ctt : cttList) {
                List<HoGlobalCompanyVO> belowList = new ArrayList<>();
                for (HoGlobalCompanyVO li : list) {
                    if (li.getRegion().equals(ctt.getRegion()) ) {
                        belowList.add(li);
                    }
                }
                ctt.setBelowList(belowList);
            }
        }
        return getDataTable(cttList);
    }

}
