package com.base.biz.controller.rpc;


import com.base.api.model.SceneBasisTargetRpcDTO;
import com.base.biz.model.dto.response.SceneBasisTargetDTO;
import com.base.biz.model.entity.SceneBasisTarget;
import com.base.biz.service.SceneBasisTargetService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/target")
public class SceneBasisTargetRpcController {

    @Resource
    private SceneBasisTargetService sceneBasisTargetService;


    @GetMapping("/detail")
    public SceneBasisTargetRpcDTO getTargetByCode(String code){
        SceneBasisTargetDTO sceneBasisTargetDTO=sceneBasisTargetService.getTargetByCode(code);
        SceneBasisTargetRpcDTO sceneBasisTargetRpcDTO=new SceneBasisTargetRpcDTO();
        BeanUtils.copyProperties(sceneBasisTargetDTO, sceneBasisTargetRpcDTO);
        return sceneBasisTargetRpcDTO;
    }
    @PostMapping("/list")
    public List<SceneBasisTargetRpcDTO> getTargetByCodes(@RequestBody List<String> targetCodes){
        List<SceneBasisTargetDTO> list=sceneBasisTargetService.getTargetByCodes(targetCodes);
        List<SceneBasisTargetRpcDTO> res = new ArrayList<>();
        list.forEach(e -> {
            SceneBasisTargetRpcDTO sceneBasisTargetRpcDTO = new SceneBasisTargetRpcDTO();
            BeanUtils.copyProperties(e, sceneBasisTargetRpcDTO);
            res.add(sceneBasisTargetRpcDTO);
        });
        return res;
    }

}
