package com.upyuns.platform.rs.datacenter.biz;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.upyuns.platform.rs.datacenter.entity.RscpAreaImageTotal;
import com.upyuns.platform.rs.datacenter.entity.RscpAreaInfo;
import com.upyuns.platform.rs.datacenter.entity.RscpImageDataTotal;
import com.upyuns.platform.rs.datacenter.mapper.RscpAreaInfoMapper;
import com.upyuns.platform.rs.datacenter.mapper.RscpImageDataTotalMapper;
import com.upyuns.platform.rs.datacenter.pojo.ImageTotalInputDTO;
import com.upyuns.platform.rs.datacenter.rest.RscpImageDataTotalController;
import com.upyuns.platform.rs.datacenter.vo.ImageInputVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class RscpImageDataTotalBiz extends BaseBiz<RscpImageDataTotalMapper, RscpImageDataTotal> {


    @Autowired
    RscpAreaInfoMapper rscpAreaInfoMapper;

    public List<RscpImageDataTotal> queryDataList(RscpImageDataTotalController.QueryDTO dto) {
        return mapper.queryDataList(dto);
    }

    public List<RscpAreaImageTotal> queryDataAreaList(RscpImageDataTotalController.QueryDTO dto) {
        List<RscpImageDataTotal> list = mapper.queryDataList(dto);
        List<RscpAreaImageTotal> list2 = CollUtil.newArrayList();
        if(CollUtil.isNotEmpty(list)) {
            for(RscpImageDataTotal ridt : list) {
                RscpAreaImageTotal rait = BeanUtil.toBean(ridt, RscpAreaImageTotal.class);
                rait.setBeginTime(ridt.getImageTakeTime());
                list2.add(rait);
            }
        }
        return list2;
    }

    public String getBinNameByGId(ImageTotalInputDTO dto){
//        String param = StrUtil.format("MULTIPOLYGON((({} {}  ,{} {}  , {} {}  ,#{rightTopLon} #{rightTopLat},   #{leftTopLon} #{leftTopLat})))");

        return mapper.getBinNameByGId(dto.getLeftTopLon(), dto.getLeftTopLat(), dto.getLeftBottomLon(), dto.getLeftBottomLat(), dto.getRightBottomLon(), dto.getRightBottomLat(), dto.getRightTopLon(), dto.getRightTopLat());
    }


    public void aaa(ImageInputVO vo) {
        ImageTotalInputDTO dto = BeanUtil.toBean(vo, ImageTotalInputDTO.class);
//        RscpImageDataTotal rscpImageDataTotal = BeanUtil.toBean(vo, RscpImageDataTotal.class);
        dto.setRange(getBinNameByGId(dto));
        List<RscpAreaInfo> imageAreaInfoList = rscpAreaInfoMapper.getIntersectAreaInfo(dto.getRange());
    }
}
