package com.base.biz.controller.rpc;

import com.base.api.model.PointRpcDTO;
import com.base.api.model.request.PointListRpcReqDTO;
import com.base.api.model.request.TaskStateNotice;
import com.base.biz.model.dto.PointDTO;
import com.base.biz.model.dto.request.PointListReqDTO;
import com.base.biz.model.entity.PointInfo;
import com.base.biz.service.PointService;
import com.base.orbit.utils.BizUtils;
import com.base.orbit.web.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

@RestController
public class PointRpcController {
    @Resource
    PointService pointService;

    @RequestMapping(value = "/point/list", method = RequestMethod.POST)
    public List<PointRpcDTO> getPointRpcList(@RequestBody PointListRpcReqDTO req) {
        PointListReqDTO pointListReqDTO = new PointListReqDTO();
        BeanUtils.copyProperties(req, pointListReqDTO);
        return BizUtils.copyEntityToDto(PointRpcDTO.class, pointService.getPointDTOList(pointListReqDTO));
    }

    @RequestMapping(value = "/point/add", method = RequestMethod.POST)
    public void addPointList(@RequestBody List<PointRpcDTO> pointRpcDTOS) {
        List<PointInfo> pointDTOS = BizUtils.copyEntityToDto(PointInfo.class, pointRpcDTOS);
        pointService.saveBatch(pointDTOS);
    }
    @PostMapping("/point/delete")
    public Object deletePointDTO(@RequestBody PointListRpcReqDTO pointListRpcReqDTO) {
        pointService.deletePointDTO(pointListRpcReqDTO);
        return Result.success();
    }

    @PostMapping("/point/deleteByIds")
    public boolean deleteByIds(@RequestBody List<String> ids) {
        return pointService.deleteByIds(ids);
    }
}
