package org.springblade.manager.feign;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import org.springblade.manager.entity.WbsTreePrivate;
import org.springblade.manager.service.IWbsTreePrivateService;
import org.springblade.manager.vo.WbsTreePrivateVO;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@AllArgsConstructor
public class WbsTreePrivateClientImpl implements WbsTreePrivateClient {

    private final IWbsTreePrivateService wbsTreePrivateService;

    @Override
    public List<WbsTreePrivateVO> queryWbsTreePrivateByProjectIdAndId(String projectId, Long id) {
        List<WbsTreePrivate> result =  this.wbsTreePrivateService.list(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getProjectId, projectId).eq(WbsTreePrivate::getParentId, id).eq(WbsTreePrivate::getIsDeleted, 0));
        if(result != null && result.size() != 0){
            //转换vo
            return JSONArray.parseArray(JSONObject.toJSONString(result), WbsTreePrivateVO.class);
        }
        return null;
    }

    @Override
    public WbsTreePrivate queryPeersNodeByProjectIdAndId(String projectId, Long id) {
        return this.wbsTreePrivateService.getOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getProjectId, projectId).eq(WbsTreePrivate::getId, id).eq(WbsTreePrivate::getIsDeleted, 0));

    }
}
