package com.yh.saas.platform.controller;

import com.alipay.sofa.runtime.api.annotation.SofaReference;
import com.winsea.svc.base.plugin.service.ITenantPluginAttributeService;
import com.winsea.svc.base.plugin.service.ITenantPluginService;
import com.winsea.svc.base.security.util.AuthSecurityUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 插件服务共通 - Controller
 * </p>
 *
 * @author ZhangMingYu
 * @since 2019年9月23日10:59:34
 */

@RestController
@RequestMapping("/pluginService")
public class PluginServiceController {

	@SofaReference
	private ITenantPluginAttributeService tenantPluginAttributeService;

	@SofaReference
	private ITenantPluginService tenantPluginService;

	/**
	 * 根据租户id 和 属性服务code 查询是否购买
	 *
	 * @param tenantId      租户id
	 * @param attributeCode 属性服务code
	 * @return 是否购买
	 */
	@GetMapping("/query/attributeService")
	public Boolean attributeService(@RequestParam String tenantId, @RequestParam String attributeCode) {
		return null != tenantPluginAttributeService.findTenantPlugin(tenantId, attributeCode);
	}

	/**
	 * 查询当前租户是否购买当前服务(一级服务||二级服务||三级服务)
	 *
	 * @param serviceCode 服务code
	 * @return 是否购买
	 */
	@GetMapping("/query/findTenantDredgeService")
	public Boolean findTenantDredgeService(@RequestParam String serviceCode) {
		return tenantPluginService.findTenantDredgeService(serviceCode,
				AuthSecurityUtils.getCurrentUserInfo().getTenantId());
	}
}
