package com.base.biz.service;

import com.base.biz.mapper.SceneTargetPointMapper;
import com.base.biz.model.dto.request.QueryTargetListDTO;
import com.base.biz.model.dto.request.QueryTargetPointBatchDTO;
import com.base.biz.model.dto.response.TargetPointDTO;
import com.base.biz.model.dto.response.SceneTargetPointDTO;
import com.base.biz.model.entity.SceneTargetPoint;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Service
public class SceneTargetPointService {

    @Resource
    SceneTargetPointMapper sceneTargetPointMapper;

    /**
     * 批量导入
     *
     * @param list
     */
    public void batch(List<QueryTargetPointBatchDTO> list) {
        sceneTargetPointMapper.batch(list);
    }

    /**
     * 根据目标id,查询点列表
     *
     * @param targetId 目标id
     * @return 点列表
     */
    public List<SceneTargetPointDTO> getPointListByTargetId(String targetId) {
        List<SceneTargetPointDTO> res = new ArrayList<>();
        List<SceneTargetPoint> list = sceneTargetPointMapper.getPointListByTargetId(targetId);
        for (SceneTargetPoint sceneTargetPoint : list) {
            SceneTargetPointDTO sceneTargetPointDTO = new SceneTargetPointDTO();
            BeanUtils.copyProperties(sceneTargetPoint, sceneTargetPointDTO);
            res.add(sceneTargetPointDTO);
        }
        return res;
    }

    /**
     * 根据目标id,查询点列表
     *
     * @param targetIds 目标id
     * @return 点列表
     */
    public List<SceneTargetPointDTO> getPointListByTargetIds(Set<String> targetIds) {
        List<SceneTargetPointDTO> res = new ArrayList<>();
        List<SceneTargetPoint> list = sceneTargetPointMapper.getPointListByTargetIds(targetIds);

        for (SceneTargetPoint sceneTargetPoint : list) {
            SceneTargetPointDTO sceneTargetPointDTO = new SceneTargetPointDTO();
            BeanUtils.copyProperties(sceneTargetPoint, sceneTargetPointDTO);
            res.add(sceneTargetPointDTO);
        }
        return res;
    }

    public List<TargetPointDTO> getTargetPointDTO(QueryTargetListDTO queryTargetListDTO) {
        return sceneTargetPointMapper.getTargetPointDTO(queryTargetListDTO);
    }
}
