package com.yh.saas.plugin.operation.controller;

import com.alipay.sofa.rpc.context.RpcInvokeContext;
import com.alipay.sofa.runtime.api.annotation.SofaReference;
import com.winsea.svc.base.base.entity.CommonTenant;
import com.winsea.svc.base.base.service.ICommonTenantService;
import com.winsea.svc.base.plugin.entity.ParameterPlugin;
import com.winsea.svc.base.plugin.service.IParameterPluginService;
import com.winsea.svc.base.plugin.service.IParameterServiceService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

/**
 * <p>
 * 插件服务 - Controller
 * </p>
 *
 * @author ZhangMingYu
 * @since 2019年9月21日11:11:43
 */
@RestController
@RequestMapping("/operationPlugin")
public class OperationParameterPluginController {

    @SofaReference
    private IParameterPluginService parameterPluginService;

    @SofaReference
    private IParameterServiceService parameterServiceService;

    @SofaReference
    private ICommonTenantService tenantService;


    @PostMapping("/api/init")
    public void initPlugin() {
        parameterPluginService.initPlugin();
    }

    /**
     * 租户插件 - 查询
     *
     * @param tenantId 租户id
     * @param status   状态
     * @return 返回list插件信息
     */
    @GetMapping("/query/findPlugin")
    public List<ParameterPlugin> findPlugin(String tenantId, String status) throws ParseException {
        CommonTenant commonTenant = tenantService.findTenantIdInfo(tenantId);
        if (null != commonTenant) {
//            RpcInvokeContext.getContext().putRequestBaggage(RpcContextBaseVariableNames.TENANT_NAME, commonTenant.getTenantName());
        }
        return parameterServiceService.findPlugin(tenantId, status);
    }
}
