package com.mosty.base.service.impl;

import com.mosty.base.mapper.GajgSearchMapper;
import com.mosty.base.model.entity.yszx.TbYsGajg;
import com.mosty.base.model.entity.yszx.TbYsGajgGlbm;
import com.mosty.base.model.vo.yszx.TbYsGajgVo;
import com.mosty.base.service.GajgSearchService;
import com.mosty.base.utils.JtsUtils;
import com.mosty.common.token.UserInfo;
import com.mosty.common.token.UserInfoManager;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

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

@Service
@AllArgsConstructor
public class GajgSearchServiceImpl implements GajgSearchService {

    private GajgSearchMapper gajgSearchMapper;

    @Override
    public TbYsGajgVo getGajg() {
        UserInfo user = UserInfoManager.get();
        TbYsGajg gajg = this.gajgSearchMapper.getGajg(String.valueOf(user.getDeptId()));
        if (gajg == null) {
            String gajgId = this.gajgSearchMapper.getGajgFromGlbl(String.valueOf(user.getDeptId()));
            gajg = this.gajgSearchMapper.getGajgById(gajgId);
        }
        if (gajg != null) { // 如果不为空 获取经纬度
            TbYsGajgVo vo = new TbYsGajgVo(); // 给前段传的vo
            BeanUtils.copyProperties(gajg, vo); // 复制属性给vo
            if (gajg.getDtm() != null) { // 如果获取到的dtm[面不为空]
                vo.setDtm(JtsUtils.decodePolygon(gajg.getDtm())); // 把面dtm【polygon】转换成point数组
            }
            return vo; // 返回所有信息
        }
        return null;
    }
}
