package cn.superdesk.uniorder.dubbo.consumer.unified;

import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.security.JwtUtil;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.unified.UnifiedProject;
import cn.superdesk.uniorder.dao.entity.unified.UnifiedProjectTarget;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedProjectTargetAdd;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedProjectTargetVo;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedProjectVo;
import cn.superdesk.uniorder.dubbo.facade.unified.DubboUnifiedProjectService;
import com.alibaba.dubbo.config.annotation.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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


@Slf4j
@Component
public class UnifiedProjectDubboConsumerService {

	@Reference(version = "1.0.0", timeout = 30000, retries = -1)
	private DubboUnifiedProjectService dubboUnifiedProjectService;

	public UnifiedProject updateObj(String token, UnifiedProject model) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		model.setCreateUserId(loginSysUser.getSysUserId());

		return dubboUnifiedProjectService.updateObj(model);
	}

	public UnifiedProjectTarget updateTarget(String token, UnifiedProjectTargetAdd model) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		return dubboUnifiedProjectService.updateTarget(model, loginSysUser);
	}

	public R<List<UnifiedProjectVo>> getDataByPage(String token, Map<String, Object> params, int pageNum, int pageSize) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		return dubboUnifiedProjectService.getDataByPage(params, pageNum, pageSize);
	}

	public R<List<UnifiedProjectTargetVo>> getTargetDataByPage(String token, Map<String, Object> params, int pageNum, int pageSize) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		return dubboUnifiedProjectService.getTargetDataByPage(params, pageNum, pageSize);
	}
}
